Merge "(refs #7771) Fixed invalid inline"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 15 Feb 2018 10:34:48 +0000 (12:34 +0200)
committerGerrit Code Review <gerrit2@www.simantics.org>
Thu, 15 Feb 2018 10:34:48 +0000 (12:34 +0200)
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 2224cc0546be96e174b42f619c8a4e06da183669..ac2e1a8289866e1b0a528718b4dfadaab6e45670 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