Mercurial > hg > truffle
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/SpecializationData.java @ 19291:f4792a544170
Truffle-DSL: implement new assumptions semantics.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 12:13:44 +0100 |
parents | 62c43fcf5be2 |
children | 21b9b9941775 |
comparison
equal
deleted
inserted
replaced
19290:bf166845c7d8 | 19291:f4792a544170 |
---|---|
44 private final List<SpecializationThrowsData> exceptions; | 44 private final List<SpecializationThrowsData> exceptions; |
45 private List<GuardExpression> guards = Collections.emptyList(); | 45 private List<GuardExpression> guards = Collections.emptyList(); |
46 private List<CacheExpression> caches = Collections.emptyList(); | 46 private List<CacheExpression> caches = Collections.emptyList(); |
47 private List<AssumptionExpression> assumptionExpressions = Collections.emptyList(); | 47 private List<AssumptionExpression> assumptionExpressions = Collections.emptyList(); |
48 private List<ShortCircuitData> shortCircuits; | 48 private List<ShortCircuitData> shortCircuits; |
49 private List<String> assumptions = Collections.emptyList(); | |
50 private final Set<SpecializationData> contains = new TreeSet<>(); | 49 private final Set<SpecializationData> contains = new TreeSet<>(); |
51 private final Set<String> containsNames = new TreeSet<>(); | 50 private final Set<String> containsNames = new TreeSet<>(); |
52 private final Set<SpecializationData> excludedBy = new TreeSet<>(); | 51 private final Set<SpecializationData> excludedBy = new TreeSet<>(); |
53 private String insertBeforeName; | 52 private String insertBeforeName; |
54 private SpecializationData insertBefore; | 53 private SpecializationData insertBefore; |
157 sinks.addAll(guards); | 156 sinks.addAll(guards); |
158 } | 157 } |
159 if (caches != null) { | 158 if (caches != null) { |
160 sinks.addAll(caches); | 159 sinks.addAll(caches); |
161 } | 160 } |
161 if (assumptionExpressions != null) { | |
162 sinks.addAll(assumptionExpressions); | |
163 } | |
162 return sinks; | 164 return sinks; |
163 } | 165 } |
164 | 166 |
165 public boolean hasRewrite(ProcessorContext context) { | 167 public boolean hasRewrite(ProcessorContext context) { |
166 if (!getExceptions().isEmpty()) { | 168 if (!getExceptions().isEmpty()) { |
167 return true; | 169 return true; |
168 } | 170 } |
169 if (!getGuards().isEmpty()) { | 171 if (!getGuards().isEmpty()) { |
170 return true; | 172 return true; |
171 } | 173 } |
172 if (!getAssumptions().isEmpty()) { | 174 if (!getAssumptionExpressions().isEmpty()) { |
173 return true; | 175 return true; |
174 } | 176 } |
175 | 177 |
176 for (Parameter parameter : getSignatureParameters()) { | 178 for (Parameter parameter : getSignatureParameters()) { |
177 NodeChildData child = parameter.getSpecification().getExecution().getChild(); | 179 NodeChildData child = parameter.getSpecification().getExecution().getChild(); |
256 this.shortCircuits = shortCircuits; | 258 this.shortCircuits = shortCircuits; |
257 } | 259 } |
258 | 260 |
259 public List<ShortCircuitData> getShortCircuits() { | 261 public List<ShortCircuitData> getShortCircuits() { |
260 return shortCircuits; | 262 return shortCircuits; |
261 } | |
262 | |
263 public List<String> getAssumptions() { | |
264 return assumptions; | |
265 } | |
266 | |
267 public void setAssumptions(List<String> assumptions) { | |
268 this.assumptions = assumptions; | |
269 } | 263 } |
270 | 264 |
271 public SpecializationData findNextSpecialization() { | 265 public SpecializationData findNextSpecialization() { |
272 List<SpecializationData> specializations = node.getSpecializations(); | 266 List<SpecializationData> specializations = node.getSpecializations(); |
273 for (int i = 0; i < specializations.size() - 1; i++) { | 267 for (int i = 0; i < specializations.size() - 1; i++) { |
315 } | 309 } |
316 } | 310 } |
317 } | 311 } |
318 } | 312 } |
319 } | 313 } |
320 | |
321 return false; | 314 return false; |
322 | |
323 } | 315 } |
324 | 316 |
325 public boolean isReachableAfter(SpecializationData prev) { | 317 public boolean isReachableAfter(SpecializationData prev) { |
326 if (!prev.isSpecialized()) { | 318 if (!prev.isSpecialized()) { |
327 return true; | 319 return true; |
347 if (!currentType.isImplicitSubtypeOf(prevType)) { | 339 if (!currentType.isImplicitSubtypeOf(prevType)) { |
348 return true; | 340 return true; |
349 } | 341 } |
350 } | 342 } |
351 | 343 |
352 for (String prevAssumption : prev.getAssumptions()) { | 344 if (!prev.getAssumptionExpressions().isEmpty()) { |
353 if (!getAssumptions().contains(prevAssumption)) { | 345 // TODO: chumer: we could at least check reachability after trivial assumptions |
354 return true; | 346 // not sure if this is worth it. |
355 } | 347 return true; |
356 } | 348 } |
357 | 349 |
358 Iterator<GuardExpression> prevGuards = prev.getGuards().iterator(); | 350 Iterator<GuardExpression> prevGuards = prev.getGuards().iterator(); |
359 Iterator<GuardExpression> currentGuards = getGuards().iterator(); | 351 Iterator<GuardExpression> currentGuards = getGuards().iterator(); |
360 while (prevGuards.hasNext()) { | 352 while (prevGuards.hasNext()) { |