From: Hannu Niemistö Date: Thu, 15 Feb 2018 09:13:09 +0000 (+0200) Subject: (refs #7771) Fixed invalid inline X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b5fe6cb785524ed852ec23c125a50fea34b4c6f5;p=simantics%2Fplatform.git (refs #7771) Fixed invalid inline Change-Id: I7b28d6915e792bc9fe858c701d1138f9082dcea3 (cherry picked from commit cc611d5d42a8d44c967dccdc201e0569b692e0c9) --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java index 209c92a64..0a608a3d3 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java @@ -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; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/statements/LetApply.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/statements/LetApply.java index 210e3ded3..2733868cf 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/statements/LetApply.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/statements/LetApply.java @@ -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); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SSASimplificationContext.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SSASimplificationContext.java index 2740a7866..aea1c033b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SSASimplificationContext.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SSASimplificationContext.java @@ -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; diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java index 6c1783027..82dd0fc07 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java @@ -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 index 000000000..e4ab0919e --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/InlineBug.scl @@ -0,0 +1,25 @@ +import "Prelude" +import "Vector" +import "File" + +@private +copyDir2 :: File -> () +copyDir2 sourceDir = iter copyDir $ vectorToList $ listFiles sourceDir + +@private +copyDir :: File -> File -> () +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