# HG changeset patch # User Benoit Daloze # Date 1446739548 -3600 # Node ID dbbcd8eb5daeb44f6e8bd6df0763f404ea65587f # Parent 6546703e0c761e4b04398b07406c28dbe60e7803 Truffle DSL: fix algorithm to find guard dependencies on caches diff -r 6546703e0c76 -r dbbcd8eb5dae truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CachedTest.java --- a/truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CachedTest.java Thu Nov 05 16:11:50 2015 +0100 +++ b/truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CachedTest.java Thu Nov 05 17:05:48 2015 +0100 @@ -42,6 +42,7 @@ import com.oracle.truffle.api.dsl.test.CachedTestFactory.TestCacheFieldFactory; import com.oracle.truffle.api.dsl.test.CachedTestFactory.TestCacheMethodFactory; import com.oracle.truffle.api.dsl.test.CachedTestFactory.TestCacheNodeFieldFactory; +import com.oracle.truffle.api.dsl.test.CachedTestFactory.TestCachesOrderFactory; import com.oracle.truffle.api.dsl.test.CachedTestFactory.TestGuardWithCachedAndDynamicParameterFactory; import com.oracle.truffle.api.dsl.test.CachedTestFactory.TestGuardWithJustCachedParameterFactory; import com.oracle.truffle.api.dsl.test.CachedTestFactory.TestMultipleCachesFactory; @@ -309,6 +310,35 @@ } @NodeChild + static class TestCachesOrder extends ValueNode { + + @Specialization(guards = "boundByGuard != 0") + static int do1(int value, // + @Cached("get(value)") int intermediateValue, // + @Cached("transform(intermediateValue)") int boundByGuard, // + @Cached("new()") Object notBoundByGuards) { + return intermediateValue; + } + + protected int get(int i) { + return i * 2; + } + + protected int transform(int i) { + return i * 3; + } + + } + + @Test + public void testCachesOrder() { + CallTarget root = createCallTarget(TestCachesOrderFactory.getInstance()); + assertEquals(42, root.call(21)); + assertEquals(42, root.call(22)); + assertEquals(42, root.call(23)); + } + + @NodeChild static class CachedError1 extends ValueNode { @Specialization static int do1(int value, @ExpectError("Incompatible return type int. The expression type must be equal to the parameter type double.")// diff -r 6546703e0c76 -r dbbcd8eb5dae truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/SpecializationData.java --- a/truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/SpecializationData.java Thu Nov 05 16:11:50 2015 +0100 +++ b/truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/SpecializationData.java Thu Nov 05 17:05:48 2015 +0100 @@ -72,20 +72,21 @@ } public boolean isCacheBoundByGuard(CacheExpression cacheExpression) { + VariableElement cachedVariable = cacheExpression.getParameter().getVariableElement(); + for (GuardExpression expression : getGuards()) { - if (expression.getExpression().findBoundVariableElements().contains(cacheExpression.getParameter().getVariableElement())) { + if (expression.getExpression().findBoundVariableElements().contains(cachedVariable)) { return true; } } - // check all next binding caches if they are bound by guard - Set boundVariables = cacheExpression.getExpression().findBoundVariableElements(); + // check all next binding caches if they are bound to a guard and use this cache variable boolean found = false; for (CacheExpression expression : getCaches()) { if (cacheExpression == expression) { found = true; } else if (found) { - if (boundVariables.contains(expression.getParameter().getVariableElement())) { + if (expression.getExpression().findBoundVariableElements().contains(cachedVariable)) { if (isCacheBoundByGuard(expression)) { return true; }