changeset 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 0103d237f6c3
children 08db96a633b9
files truffle/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerAsserts.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/ControlFlowException.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java
diffstat 7 files changed, 41 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java	Mon Jun 22 10:15:05 2015 -0700
+++ b/truffle/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java	Mon Jun 22 10:16:27 2015 -0700
@@ -27,12 +27,15 @@
 import java.util.*;
 import java.util.concurrent.*;
 
+import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.nodes.*;
 
 /** Contains utility classes shared across generated DSLNode implementations. */
 public class DSLShare {
 
     public static boolean isExcluded(Node currentNode, DSLMetadata otherMetadata) {
+        CompilerAsserts.neverPartOfCompilation();
+
         assert otherMetadata.getExcludedBy().length > 0 : "At least one exclude must be defined for isIncluded.";
         Node cur = findRoot(currentNode);
         while (cur != null) {
@@ -52,6 +55,8 @@
     }
 
     public static <T extends Node & DSLNode> T rewrite(final Node thisNode, final T newNode, final String message) {
+        CompilerAsserts.neverPartOfCompilation();
+
         return thisNode.atomic(new Callable<T>() {
             public T call() {
                 assert newNode != null;
@@ -72,6 +77,8 @@
 
     @SuppressWarnings("unchecked")
     public static <T extends Node> T findRoot(T node) {
+        CompilerAsserts.neverPartOfCompilation();
+
         Node prev = node;
         Node cur;
         do {
@@ -92,6 +99,8 @@
     }
 
     public static <T extends Node & DSLNode> T rewriteUninitialized(final Node uninitialized, final T newNode) {
+        CompilerAsserts.neverPartOfCompilation();
+
         return uninitialized.atomic(new Callable<T>() {
             public T call() {
                 Node prev = getPrevious(uninitialized);
@@ -108,6 +117,8 @@
 
     public static <T extends Node & DSLNode> T rewriteToPolymorphic(final Node oldNode, final DSLNode uninitializedDSL, final T polymorphic, final DSLNode currentCopy, final DSLNode newNodeDSL,
                     final String message) {
+        CompilerAsserts.neverPartOfCompilation();
+
         return oldNode.atomic(new Callable<T>() {
             public T call() {
                 assert getNext(oldNode) == null;
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerAsserts.java	Mon Jun 22 10:15:05 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerAsserts.java	Mon Jun 22 10:16:27 2015 -0700
@@ -39,7 +39,6 @@
      * directive.
      */
     public static void neverPartOfCompilation() {
-        neverPartOfCompilation("");
     }
 
     /**
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java	Mon Jun 22 10:15:05 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java	Mon Jun 22 10:16:27 2015 -0700
@@ -45,6 +45,7 @@
     }
 
     public FrameDescriptor(Object defaultValue) {
+        CompilerAsserts.neverPartOfCompilation();
         this.defaultValue = defaultValue;
         slots = new ArrayList<>();
         identifierToSlotMap = new HashMap<>();
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/ControlFlowException.java	Mon Jun 22 10:15:05 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/ControlFlowException.java	Mon Jun 22 10:16:27 2015 -0700
@@ -39,9 +39,10 @@
         /*
          * We use the super constructor that initializes the cause to null. Without that, the cause
          * would be this exception itself. This helps escape analysis: it avoids the circle of an
-         * object pointing to itself.
+         * object pointing to itself. We also do not need a message, so we use the constructor that
+         * also allows us to set the message to null.
          */
-        super((Throwable) null);
+        super(null, null);
     }
 
     /**
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Mon Jun 22 10:15:05 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Mon Jun 22 10:16:27 2015 -0700
@@ -363,6 +363,8 @@
      * @return the new copy
      */
     public Node copy() {
+        CompilerAsserts.neverPartOfCompilation();
+
         try {
             return (Node) super.clone();
         } catch (CloneNotSupportedException e) {
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java	Mon Jun 22 10:15:05 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java	Mon Jun 22 10:16:27 2015 -0700
@@ -131,6 +131,7 @@
     }
 
     static Node deepCopyImpl(Node orig) {
+        CompilerAsserts.neverPartOfCompilation();
         final Node clone = orig.copy();
         NodeClass nodeClass = clone.getNodeClass();
 
@@ -168,6 +169,7 @@
     }
 
     public static List<Node> findNodeChildren(Node node) {
+        CompilerAsserts.neverPartOfCompilation();
         List<Node> nodes = new ArrayList<>();
         NodeClass nodeClass = node.getNodeClass();
 
@@ -197,6 +199,7 @@
     }
 
     public static boolean replaceChild(Node parent, Node oldChild, Node newChild) {
+        CompilerAsserts.neverPartOfCompilation();
         NodeClass nodeClass = parent.getNodeClass();
 
         for (NodeFieldAccessor nodeField : nodeClass.getChildFields()) {
@@ -301,6 +304,7 @@
      * @return {@code true} if all children were visited, {@code false} otherwise
      */
     public static boolean forEachChild(Node parent, NodeVisitor visitor) {
+        CompilerAsserts.neverPartOfCompilation();
         Objects.requireNonNull(visitor);
         NodeClass parentNodeClass = parent.getNodeClass();
 
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java	Mon Jun 22 10:15:05 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java	Mon Jun 22 10:16:27 2015 -0700
@@ -29,6 +29,7 @@
 import java.net.*;
 import java.util.*;
 
+import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.instrument.*;
 
 /**
@@ -216,6 +217,7 @@
      * @throws IOException if the file cannot be found
      */
     public static Source fromFileName(CharSequence chars, String fileName) throws IOException {
+        CompilerAsserts.neverPartOfCompilation();
 
         final WeakReference<Source> nameRef = nameToSource.get(fileName);
         Source source = nameRef == null ? null : nameRef.get();
@@ -242,6 +244,8 @@
      * @return a newly created, non-indexed source representation
      */
     public static Source fromText(CharSequence chars, String description) {
+        CompilerAsserts.neverPartOfCompilation();
+
         assert chars != null;
         final LiteralSource source = new LiteralSource(description, chars.toString());
         notifyNewSource(source).tagAs(Tags.FROM_LITERAL);
@@ -256,6 +260,8 @@
      * @return a newly created, non-indexed, initially empty, appendable source representation
      */
     public static Source fromAppendableText(String description) {
+        CompilerAsserts.neverPartOfCompilation();
+
         final Source source = new AppendableLiteralSource(description);
         notifyNewSource(source).tagAs(Tags.FROM_LITERAL);
         return source;
@@ -271,6 +277,8 @@
      * @return a newly created, source representation
      */
     public static Source fromNamedText(CharSequence chars, String name) {
+        CompilerAsserts.neverPartOfCompilation();
+
         final Source source = new LiteralSource(name, chars.toString());
         nameToSource.put(name, new WeakReference<>(source));
         notifyNewSource(source).tagAs(Tags.FROM_LITERAL);
@@ -287,6 +295,8 @@
      * @return a newly created, indexed, initially empty, appendable source representation
      */
     public static Source fromNamedAppendableText(String name) {
+        CompilerAsserts.neverPartOfCompilation();
+
         final Source source = new AppendableLiteralSource(name);
         nameToSource.put(name, new WeakReference<>(source));
         notifyNewSource(source).tagAs(Tags.FROM_LITERAL);
@@ -304,6 +314,8 @@
      * @throws IllegalArgumentException if the specified sub-range is not contained in the base
      */
     public static Source subSource(Source base, int baseCharIndex, int length) {
+        CompilerAsserts.neverPartOfCompilation();
+
         final SubSource subSource = SubSource.create(base, baseCharIndex, length);
         return subSource;
     }
@@ -318,6 +330,8 @@
      * @throws IllegalArgumentException if the index is out of range
      */
     public static Source subSource(Source base, int baseCharIndex) {
+        CompilerAsserts.neverPartOfCompilation();
+
         return subSource(base, baseCharIndex, base.getLength() - baseCharIndex);
     }
 
@@ -330,6 +344,8 @@
      * @throws IOException if reading fails
      */
     public static Source fromURL(URL url, String description) throws IOException {
+        CompilerAsserts.neverPartOfCompilation();
+
         final URLSource source = URLSource.get(url, description);
         notifyNewSource(source).tagAs(Tags.FROM_URL);
         return source;
@@ -344,6 +360,8 @@
      * @throws IOException if reading fails
      */
     public static Source fromReader(Reader reader, String description) throws IOException {
+        CompilerAsserts.neverPartOfCompilation();
+
         final LiteralSource source = new LiteralSource(description, read(reader));
         notifyNewSource(source).tagAs(Tags.FROM_READER);
         return source;
@@ -377,6 +395,8 @@
      * @return a newly created, non-indexed source representation
      */
     public static Source fromBytes(byte[] bytes, int byteIndex, int length, String description, BytesDecoder decoder) {
+        CompilerAsserts.neverPartOfCompilation();
+
         final BytesSource source = new BytesSource(description, bytes, byteIndex, length, decoder);
         notifyNewSource(source).tagAs(Tags.FROM_BYTES);
         return source;