Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest.java @ 11320:80de3bbfa8b9
Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 16 Aug 2013 14:00:17 +0200 |
parents | 79041ab43660 |
children | e5b5a5cb0ac7 |
comparison
equal
deleted
inserted
replaced
11310:9f317a663366 | 11320:80de3bbfa8b9 |
---|---|
29 | 29 |
30 import com.oracle.truffle.api.dsl.*; | 30 import com.oracle.truffle.api.dsl.*; |
31 import com.oracle.truffle.api.dsl.test.BinaryNodeTest.BinaryNode; | 31 import com.oracle.truffle.api.dsl.test.BinaryNodeTest.BinaryNode; |
32 import com.oracle.truffle.api.dsl.test.PolymorphicTestFactory.Node1Factory; | 32 import com.oracle.truffle.api.dsl.test.PolymorphicTestFactory.Node1Factory; |
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; | 33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | |
34 import com.oracle.truffle.api.nodes.*; | 35 import com.oracle.truffle.api.nodes.*; |
35 import com.oracle.truffle.api.nodes.NodeInfo.Kind; | 36 import com.oracle.truffle.api.nodes.NodeInfo.Kind; |
36 | 37 |
37 public class PolymorphicTest { | 38 public class PolymorphicTest { |
38 | 39 |
42 assertEquals("(int,int)", executeWith(node, 42, 42)); | 43 assertEquals("(int,int)", executeWith(node, 42, 42)); |
43 assertEquals("(boolean,boolean)", executeWith(node, false, false)); | 44 assertEquals("(boolean,boolean)", executeWith(node, false, false)); |
44 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 45 assertEquals("(int,boolean)", executeWith(node, 42, false)); |
45 assertEquals("(boolean,int)", executeWith(node, false, 42)); | 46 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
46 assertEquals(Kind.SPECIALIZED, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 47 assertEquals(Kind.SPECIALIZED, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
48 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | |
49 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | |
47 } | 50 } |
48 | 51 |
49 @Test | 52 @Test |
50 public void testPolymorphic2() { | 53 public void testPolymorphic2() { |
51 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 54 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
52 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 55 assertEquals("(int,boolean)", executeWith(node, 42, false)); |
53 assertEquals("(int,int)", executeWith(node, 42, 42)); | 56 assertEquals("(int,int)", executeWith(node, 42, 42)); |
54 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 57 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
58 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | |
59 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | |
55 } | 60 } |
56 | 61 |
57 @Test | 62 @Test |
58 public void testPolymorphic3() { | 63 public void testPolymorphic3() { |
59 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 64 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
60 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 65 assertEquals("(int,boolean)", executeWith(node, 42, false)); |
61 assertEquals("(boolean,boolean)", executeWith(node, true, false)); | 66 assertEquals("(boolean,boolean)", executeWith(node, true, false)); |
62 assertEquals("(int,int)", executeWith(node, 42, 42)); | 67 assertEquals("(int,int)", executeWith(node, 42, 42)); |
63 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 68 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
69 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | |
70 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | |
64 } | 71 } |
65 | 72 |
66 @Test | 73 @Test |
67 public void testGenericLimitReached() { | 74 public void testGenericLimitReached() { |
68 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 75 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
69 assertEquals("(boolean,int)", executeWith(node, false, 42)); | 76 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
70 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 77 assertEquals("(int,boolean)", executeWith(node, 42, false)); |
71 assertEquals("(boolean,boolean)", executeWith(node, true, false)); | 78 assertEquals("(boolean,boolean)", executeWith(node, true, false)); |
72 assertEquals("(int,int)", executeWith(node, 42, 42)); | 79 assertEquals("(int,int)", executeWith(node, 42, 42)); |
73 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 80 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
81 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | |
82 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | |
74 } | 83 } |
75 | 84 |
76 @Test | 85 @Test |
77 public void testGenericInitial() { | 86 public void testGenericInitial() { |
78 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 87 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
79 assertEquals("(generic,generic)", executeWith(node, "", "")); | 88 assertEquals("(generic,generic)", executeWith(node, "", "")); |
80 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 89 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
90 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | |
91 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | |
81 } | 92 } |
82 | 93 |
83 @Test | 94 @Test |
84 public void testGenericPolymorphic() { | 95 public void testGenericPolymorphic1() { |
85 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 96 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
86 assertEquals("(boolean,int)", executeWith(node, false, 42)); | 97 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
87 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 98 assertEquals("(boolean,boolean)", executeWith(node, false, false)); |
88 assertEquals("(generic,generic)", executeWith(node, "", "")); | 99 assertEquals("(generic,generic)", executeWith(node, "", "")); |
89 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 100 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
101 /* Assertions for bug GRAAL-425 */ | |
102 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | |
103 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | |
90 } | 104 } |
91 | 105 |
92 @SuppressWarnings("unused") | 106 @SuppressWarnings("unused") |
93 @PolymorphicLimit(3) | 107 @PolymorphicLimit(3) |
94 abstract static class Node1 extends BinaryNode { | 108 abstract static class Node1 extends BinaryNode { |
109 | |
110 public abstract ValueNode getLeft(); | |
111 | |
112 public abstract ValueNode getRight(); | |
95 | 113 |
96 @Specialization(order = 1) | 114 @Specialization(order = 1) |
97 String add(int left, int right) { | 115 String add(int left, int right) { |
98 return "(int,int)"; | 116 return "(int,int)"; |
99 } | 117 } |