comparison truffle/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java @ 21966:5023b913e2ba

Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
author Christian Wimmer <christian.wimmer@oracle.com>
date Mon, 22 Jun 2015 10:16:27 -0700
parents 9c8c0937da41
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21965:0103d237f6c3 21966:5023b913e2ba
25 package com.oracle.truffle.api.dsl.internal; 25 package com.oracle.truffle.api.dsl.internal;
26 26
27 import java.util.*; 27 import java.util.*;
28 import java.util.concurrent.*; 28 import java.util.concurrent.*;
29 29
30 import com.oracle.truffle.api.*;
30 import com.oracle.truffle.api.nodes.*; 31 import com.oracle.truffle.api.nodes.*;
31 32
32 /** Contains utility classes shared across generated DSLNode implementations. */ 33 /** Contains utility classes shared across generated DSLNode implementations. */
33 public class DSLShare { 34 public class DSLShare {
34 35
35 public static boolean isExcluded(Node currentNode, DSLMetadata otherMetadata) { 36 public static boolean isExcluded(Node currentNode, DSLMetadata otherMetadata) {
37 CompilerAsserts.neverPartOfCompilation();
38
36 assert otherMetadata.getExcludedBy().length > 0 : "At least one exclude must be defined for isIncluded."; 39 assert otherMetadata.getExcludedBy().length > 0 : "At least one exclude must be defined for isIncluded.";
37 Node cur = findRoot(currentNode); 40 Node cur = findRoot(currentNode);
38 while (cur != null) { 41 while (cur != null) {
39 Class<?> curClass = cur.getClass(); 42 Class<?> curClass = cur.getClass();
40 if (curClass == otherMetadata.getSpecializationClass()) { 43 if (curClass == otherMetadata.getSpecializationClass()) {
50 private static boolean includes(Node oldNode, DSLNode newNode) { 53 private static boolean includes(Node oldNode, DSLNode newNode) {
51 return containsClass(newNode.getMetadata0().getIncludes(), oldNode); 54 return containsClass(newNode.getMetadata0().getIncludes(), oldNode);
52 } 55 }
53 56
54 public static <T extends Node & DSLNode> T rewrite(final Node thisNode, final T newNode, final String message) { 57 public static <T extends Node & DSLNode> T rewrite(final Node thisNode, final T newNode, final String message) {
58 CompilerAsserts.neverPartOfCompilation();
59
55 return thisNode.atomic(new Callable<T>() { 60 return thisNode.atomic(new Callable<T>() {
56 public T call() { 61 public T call() {
57 assert newNode != null; 62 assert newNode != null;
58 if (getNext(thisNode) != null || getPrevious(thisNode) != null) { 63 if (getNext(thisNode) != null || getPrevious(thisNode) != null) {
59 // already polymorphic -> append 64 // already polymorphic -> append
70 }); 75 });
71 } 76 }
72 77
73 @SuppressWarnings("unchecked") 78 @SuppressWarnings("unchecked")
74 public static <T extends Node> T findRoot(T node) { 79 public static <T extends Node> T findRoot(T node) {
80 CompilerAsserts.neverPartOfCompilation();
81
75 Node prev = node; 82 Node prev = node;
76 Node cur; 83 Node cur;
77 do { 84 do {
78 cur = prev; 85 cur = prev;
79 prev = getPrevious(cur); 86 prev = getPrevious(cur);
90 } while (next != null); 97 } while (next != null);
91 return cur; 98 return cur;
92 } 99 }
93 100
94 public static <T extends Node & DSLNode> T rewriteUninitialized(final Node uninitialized, final T newNode) { 101 public static <T extends Node & DSLNode> T rewriteUninitialized(final Node uninitialized, final T newNode) {
102 CompilerAsserts.neverPartOfCompilation();
103
95 return uninitialized.atomic(new Callable<T>() { 104 return uninitialized.atomic(new Callable<T>() {
96 public T call() { 105 public T call() {
97 Node prev = getPrevious(uninitialized); 106 Node prev = getPrevious(uninitialized);
98 if (prev == null) { 107 if (prev == null) {
99 newNode.adoptChildren0(uninitialized, null); 108 newNode.adoptChildren0(uninitialized, null);
106 115
107 } 116 }
108 117
109 public static <T extends Node & DSLNode> T rewriteToPolymorphic(final Node oldNode, final DSLNode uninitializedDSL, final T polymorphic, final DSLNode currentCopy, final DSLNode newNodeDSL, 118 public static <T extends Node & DSLNode> T rewriteToPolymorphic(final Node oldNode, final DSLNode uninitializedDSL, final T polymorphic, final DSLNode currentCopy, final DSLNode newNodeDSL,
110 final String message) { 119 final String message) {
120 CompilerAsserts.neverPartOfCompilation();
121
111 return oldNode.atomic(new Callable<T>() { 122 return oldNode.atomic(new Callable<T>() {
112 public T call() { 123 public T call() {
113 assert getNext(oldNode) == null; 124 assert getNext(oldNode) == null;
114 assert getPrevious(oldNode) == null; 125 assert getPrevious(oldNode) == null;
115 assert newNodeDSL != null; 126 assert newNodeDSL != null;