]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7771) Fixed invalid inline 76/1476/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 15 Feb 2018 09:13:09 +0000 (11:13 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 16 Feb 2018 13:44:24 +0000 (15:44 +0200)
Change-Id: I7b28d6915e792bc9fe858c701d1138f9082dcea3
(cherry picked from commit cc611d5d42a8d44c967dccdc201e0569b692e0c9)

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/statements/LetApply.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SSASimplificationContext.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/InlineBug.scl [new file with mode: 0644]

index 209c92a64af4016687339f559e6639369093a7bb..0a608a3d342adf6a9253fd400892475ce6b45131 100644 (file)
@@ -26,8 +26,12 @@ import org.simantics.scl.compiler.internal.codegen.utils.ValRefVisitor;
 import org.simantics.scl.compiler.types.TVar;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public final class SSAFunction extends SSAClosure {
+    private static final Logger LOGGER = LoggerFactory.getLogger(SSAFunction.class);
+
     TVar[] typeParameters;
     Type effect;
     SSABlock firstBlock;
index 210e3ded3243fc20755dd4553dd19bd309f0d0ba..2733868cf06d312ac82f0a687840b4ca4a2420ff 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.scl.compiler.internal.codegen.ssa.SSAExit;
 import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
 import org.simantics.scl.compiler.internal.codegen.ssa.SSAStatement;
 import org.simantics.scl.compiler.internal.codegen.ssa.binders.BoundVarBinder;
+import org.simantics.scl.compiler.internal.codegen.ssa.binders.ClosureBinder;
 import org.simantics.scl.compiler.internal.codegen.ssa.binders.ValRefBinder;
 import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump;
 import org.simantics.scl.compiler.internal.codegen.ssa.exits.Switch;
@@ -30,8 +31,12 @@ import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.util.MultiFunction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class LetApply extends LetStatement implements ValRefBinder {
+    private static final Logger LOGGER = LoggerFactory.getLogger(LetApply.class);
+    
     private ValRef function;
     private ValRef[] parameters;
     Type effect;
@@ -356,8 +361,17 @@ public class LetApply extends LetStatement implements ValRefBinder {
                
         SSABlock headBlock = getParent();
         SSAFunction thisFunction = headBlock.getParent();
-        if(thisFunction == function)
-            return;
+        {
+            SSAFunction curParent=thisFunction;
+            while(true) {
+                if(curParent == function)
+                    return;
+                ClosureBinder binder = curParent.getParent();
+                if(binder == null)
+                    break;
+                curParent = binder.getParentFunction();
+            }
+        }
                
         /*System.out.println("--- INLINING -------------------------------");
         System.out.println(thisFunction);
index 2740a7866732e4435ff20c8c57cb7ccd718e9d91..aea1c033b8f71e73866d6c3eb00230ac18ea461b 100644 (file)
@@ -5,8 +5,12 @@ import org.simantics.scl.compiler.constants.SCLConstant;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.internal.codegen.ssa.SSAModule;
 import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SSASimplificationContext {
+    private static final Logger LOGGER = LoggerFactory.getLogger(SSASimplificationContext.class);
+
     SSAModule module;
     Environment environment;
     boolean modified = false;
index 6c17830273c43eed42ab7688cd93e2512437050b..82dd0fc07fcd7b13b67c8b3325359e313315064c 100644 (file)
@@ -110,6 +110,7 @@ public class ModuleRegressionTests extends TestBase {
     @Test public void IndentationAndParenthesis() { test(); }
     @Test public void Index() { test(); }
     @Test public void Inline1() { test(); }
+    @Test public void InlineBug() { test(); }
     @Test public void InstanceHierarchy() { test(); }
     @Test public void InstanceIsTypoedAsClass() { test(); }
     @Test public void InvalidClass1() { test(); }
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/InlineBug.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/InlineBug.scl
new file mode 100644 (file)
index 0000000..e4ab091
--- /dev/null
@@ -0,0 +1,25 @@
+import "Prelude"
+import "Vector"
+import "File"
+
+@private
+copyDir2 :: File -> <Proc> ()
+copyDir2 sourceDir = iter copyDir $ vectorToList $ listFiles sourceDir
+
+@private
+copyDir :: File -> File -> <Proc> ()
+copyDir sourceDir targetDir = do
+  makeDirs targetDir
+  files = vectorToList $ listFiles sourceDir
+  iter (\sourceFile -> do
+    targetFile = childFile targetDir $ nameOfFile sourceFile
+    if isDirectory sourceFile then
+      copyDir sourceFile targetFile
+    else
+      copyFile sourceFile targetFile
+  ) files
+  ()
+  
+main = "OK"
+----
+OK