Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ContainsTest.java @ 16922:0ea0c4133b78
Truffle-DSL: fixed polymorphic to monomorphic transition. It remained polymorphic in some cases.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 25 Aug 2014 16:30:40 +0200 |
parents | d834f85ac8a1 |
children | c88ab4f1f04a |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ContainsTest.java Mon Aug 25 15:56:32 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ContainsTest.java Mon Aug 25 16:30:40 2014 +0200 @@ -23,6 +23,8 @@ package com.oracle.truffle.api.dsl.test; import static com.oracle.truffle.api.dsl.test.TestHelper.*; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; import org.junit.*; @@ -32,6 +34,7 @@ import com.oracle.truffle.api.dsl.test.ContainsTestFactory.Contains2Factory; import com.oracle.truffle.api.dsl.test.ContainsTestFactory.Contains3Factory; import com.oracle.truffle.api.dsl.test.ContainsTestFactory.Contains4Factory; +import com.oracle.truffle.api.dsl.test.ContainsTestFactory.PolymorphicToMonomorphic0Factory; import com.oracle.truffle.api.dsl.test.TestHelper.ExecutionListener; import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; @@ -600,4 +603,41 @@ } } + @Test + public void testPolymorphicToMonomorphic0() { + TestRootNode<PolymorphicToMonomorphic0> root = createRoot(PolymorphicToMonomorphic0Factory.getInstance()); + assertThat((int) executeWith(root, 1), is(1)); + assertThat((int) executeWith(root, 2), is(2)); + assertThat((int) executeWith(root, 3), is(3)); + assertThat(root.getNode().getCost(), is(NodeCost.MONOMORPHIC)); + } + + @NodeChild("a") + static class PolymorphicToMonomorphic0 extends ValueNode { + + boolean isOne(int a) { + return a == 1; + } + + boolean isTwo(int a) { + return a == 2; + } + + @Specialization(guards = "isOne") + int do1(int a) { + return a; + } + + @Specialization(guards = "isTwo") + int do2(int a) { + return a; + } + + @Specialization(contains = {"do1", "do2"}) + int do3(int a) { + return a; + } + + } + }