comparison graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java @ 16921:f5541b01f374

Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
author Christian Humer <christian.humer@gmail.com>
date Mon, 25 Aug 2014 15:56:32 +0200
parents 90984ae0eaa8
children 0ea0c4133b78
comparison
equal deleted inserted replaced
16920:77981382473e 16921:f5541b01f374
94 } else { 94 } else {
95 return appendPolymorphic(uninitialized, newNode); 95 return appendPolymorphic(uninitialized, newNode);
96 } 96 }
97 } 97 }
98 98
99 public static <T extends Node & DSLNode> T rewriteToPolymorphic(Node oldNode, DSLNode uninitialized, T polymorphic, DSLNode currentCopy, DSLNode newNode, String message) { 99 public static <T extends Node & DSLNode> T rewriteToPolymorphic(Node oldNode, DSLNode uninitializedDSL, T polymorphic, DSLNode currentCopy, DSLNode newNodeDSL, String message) {
100 assert getNext(oldNode) == null; 100 assert getNext(oldNode) == null;
101 assert getPrevious(oldNode) == null; 101 assert getPrevious(oldNode) == null;
102 102
103 Node uninitialized = (Node) uninitializedDSL;
104 Node newNode = (Node) newNodeDSL;
103 polymorphic.adoptChildren0(oldNode, (Node) currentCopy); 105 polymorphic.adoptChildren0(oldNode, (Node) currentCopy);
104 106
107 updateSourceSection(oldNode, uninitialized);
105 if (newNode == null) { 108 if (newNode == null) {
106 // fallback 109 // fallback
107 currentCopy.adoptChildren0(null, (Node) uninitialized); 110 currentCopy.adoptChildren0(null, uninitialized);
108 } else { 111 } else {
109 // new specialization 112 // new specialization
110 newNode.adoptChildren0(null, (Node) uninitialized); 113 updateSourceSection(oldNode, newNode);
111 currentCopy.adoptChildren0(null, (Node) newNode); 114 newNodeDSL.adoptChildren0(null, uninitialized);
115 currentCopy.adoptChildren0(null, newNode);
112 } 116 }
113 117
114 oldNode.replace(polymorphic, message); 118 oldNode.replace(polymorphic, message);
115 119
116 assert polymorphic.getNext0() == currentCopy; 120 assert polymorphic.getNext0() == currentCopy;
117 assert newNode != null ? currentCopy.getNext0() == newNode : currentCopy.getNext0() == uninitialized; 121 assert newNode != null ? currentCopy.getNext0() == newNode : currentCopy.getNext0() == uninitialized;
118 assert uninitialized.getNext0() == null; 122 assert uninitializedDSL.getNext0() == null;
119 return polymorphic; 123 return polymorphic;
124 }
125
126 private static void updateSourceSection(Node oldNode, Node newNode) {
127 if (newNode.getSourceSection() == null) {
128 newNode.assignSourceSection(oldNode.getSourceSection());
129 }
120 } 130 }
121 131
122 private static Class<?>[] mergeTypes(DSLNode node, Class<?>[] types) { 132 private static Class<?>[] mergeTypes(DSLNode node, Class<?>[] types) {
123 Class<?>[] specializedTypes = node.getMetadata0().getSpecializedTypes(); 133 Class<?>[] specializedTypes = node.getMetadata0().getSpecializedTypes();
124 if (specializedTypes.length == 0) { 134 if (specializedTypes.length == 0) {
152 prev = cur; 162 prev = cur;
153 cur = getPrevious(cur); 163 cur = getPrevious(cur);
154 } 164 }
155 assert prev.getCost() == NodeCost.POLYMORPHIC; 165 assert prev.getCost() == NodeCost.POLYMORPHIC;
156 166
167 updateSourceSection(prev, newNode);
157 if (depth == 0) { 168 if (depth == 0) {
158 newNode.adoptChildren0(prev, null); 169 newNode.adoptChildren0(prev, null);
159 return prev.replace(newNode, "Polymorphic to monomorphic."); 170 return prev.replace(newNode, "Polymorphic to monomorphic.");
160 } else { 171 } else {
161 newNode.adoptChildren0(null, uninitialized); 172 newNode.adoptChildren0(null, uninitialized);