Skip to content

Commit

Permalink
Merge pull request #56 from wirthi/master
Browse files Browse the repository at this point in the history
provide bailout messages for usages of CompilerAsserts.neverPartOfCompilation()
  • Loading branch information
Jaroslav Tulach committed Feb 16, 2016
2 parents 831c1bb + 421e272 commit 0f9e4cc
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Object directCallFunctionGuard(VirtualFrame frame, Function function, Obj
}

protected final boolean cacheFunctionTarget(Function function) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not cache function target in compiled code");
if (cachedFunctions != null) {
for (int i = 0; i < cachedFunctions.length; i++) {
Function cachedFunction = cachedFunctions[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class DSLShare {

public static boolean isExcluded(Node currentNode, DSLMetadata otherMetadata) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call DSLShare.isExcluded from compiled code");

assert otherMetadata.getExcludedBy().length > 0 : "At least one exclude must be defined for isIncluded.";
Node cur = findRoot(currentNode);
Expand All @@ -55,7 +55,7 @@ private static boolean includes(Node oldNode, DSLNode newNode) {
}

public static <T extends Node & DSLNode> T rewrite(final Node thisNode, final T newNode, final String message) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call DSLShare.rewrite from compiled code");

return thisNode.atomic(new Callable<T>() {
public T call() {
Expand All @@ -77,7 +77,7 @@ public T call() {

@SuppressWarnings("unchecked")
public static <T extends Node> T findRoot(T node) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call DSLShare.findRoot from compiled code");

Node prev = node;
Node cur;
Expand All @@ -99,7 +99,7 @@ private static Node findUninitialized(Node node) {
}

public static <T extends Node & DSLNode> T rewriteUninitialized(final Node uninitialized, final T newNode) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call DSLShare.rewriteUninitialized from compiled code");

return uninitialized.atomic(new Callable<T>() {
public T call() {
Expand All @@ -117,7 +117,7 @@ public T call() {

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();
CompilerAsserts.neverPartOfCompilation("do not call DSLShare.rewriteToPolymorphic from compiled code");

return oldNode.atomic(new Callable<T>() {
public T call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class ForeignAccess {
private ForeignAccess(Factory faf) {
this.factory = faf;
this.initThread = Thread.currentThread();
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not create a ForeignAccess object from compiled code");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public FrameDescriptor() {
* @param defaultValue to be returned from {@link #getDefaultValue()}
*/
public FrameDescriptor(Object defaultValue) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not create a FrameDescriptor from compiled code");
this.defaultValue = defaultValue;
slots = new ArrayList<>();
identifierToSlotMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public FrameSlot(FrameDescriptor descriptor, Object identifier, Object info, int

/**
* Identifier of the slot.
*
*
* @return value as specified in {@link FrameDescriptor#addFrameSlot(java.lang.Object)}
* parameter
*/
Expand All @@ -70,7 +70,7 @@ public Object getIdentifier() {

/**
* Information about the slot.
*
*
* @return value as specified as second parameter of
* {@link FrameDescriptor#addFrameSlot(java.lang.Object, java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind)}
*/
Expand All @@ -80,7 +80,7 @@ public Object getInfo() {

/**
* Index of the slot in the {@link FrameDescriptor}.
*
*
* @return position of the slot computed after
* {@link FrameDescriptor#addFrameSlot(java.lang.Object, java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind)
* adding} it.
Expand All @@ -94,7 +94,7 @@ public int getIndex() {
* {@link FrameDescriptor#addFrameSlot(java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind)
* creation time} or updated via {@link #setKind(com.oracle.truffle.api.frame.FrameSlotKind)}
* method.
*
*
* @return current kind of this slot
*/
public FrameSlotKind getKind() {
Expand All @@ -105,7 +105,7 @@ public FrameSlotKind getKind() {
* Changes the kind of this slot. Change of the slot kind is done on <em>slow path</em> and
* invalidates assumptions about {@link FrameDescriptor#createVersion() version} of
* {@link #getFrameDescriptor() associated descriptor}.
*
*
* @param kind new kind of the slot
*/
public void setKind(final FrameSlotKind kind) {
Expand All @@ -118,13 +118,13 @@ public void setKind(final FrameSlotKind kind) {

@Override
public String toString() {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call FrameSlot.toString from compiled code");
return "[" + index + "," + identifier + "," + kind + "]";
}

/**
* Frame descriptor this slot is associated with.
*
*
* @return instance of descriptor that {@link FrameDescriptor#addFrameSlot(java.lang.Object)
* created} the slot
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ protected Debugger createDebugger(Object vm, Instrumenter instrumenter) {
@TruffleBoundary
@SuppressWarnings("unused")
protected Closeable executionStart(Object vm, int currentDepth, Debugger debugger, Source s) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Accessor.executionStart from compiled code");
Objects.requireNonNull(vm);
final Object prev = CURRENT_VM.get();
final Closeable debugClose = DEBUG.executionStart(vm, prev == null ? 0 : -1, debugger, s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class Node implements NodeInterface, Cloneable {
}

protected Node() {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not create a Node from compiled code");
this.nodeClass = NodeClass.get(getClass());
if (TruffleOptions.TraceASTJSON) {
JSONHelper.dumpNewNode(this);
Expand Down Expand Up @@ -129,7 +129,7 @@ public NodeCost getCost() {
/**
* @deprecated if your node provides source section, override {@link #getSourceSection()} to
* return it - this method will be removed
*
*
* Clears any previously assigned guest language source code from this node.
*/
@Deprecated
Expand Down Expand Up @@ -306,7 +306,7 @@ public final <T extends Node> T replace(T newNode) {
}

final void replaceHelper(Node newNode, CharSequence reason) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Node.replaceHelper from compiled code");
assert inAtomicBlock();
if (this.getParent() == null) {
throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent.");
Expand Down Expand Up @@ -399,7 +399,7 @@ public Iterator<Node> iterator() {
* @return the new copy
*/
public Node copy() {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Node.copy from compiled code");

try {
return (Node) super.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static <T extends Node> T cloneNode(T orig) {

@SuppressWarnings("deprecation")
static Node deepCopyImpl(Node orig) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Node.deepCopyImpl from compiled code");
final Node clone = orig.copy();
NodeClass nodeClass = clone.getNodeClass();

Expand Down Expand Up @@ -169,7 +169,7 @@ static Node deepCopyImpl(Node orig) {
}

public static List<Node> findNodeChildren(Node node) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Node.findNodeChildren from compiled code");
List<Node> nodes = new ArrayList<>();
NodeClass nodeClass = node.getNodeClass();

Expand Down Expand Up @@ -204,7 +204,7 @@ public static boolean replaceChild(Node parent, Node oldChild, Node newChild) {

@SuppressWarnings("deprecation")
static boolean replaceChild(Node parent, Node oldChild, Node newChild, boolean adopt) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not replace Node child from compiled code");
NodeClass nodeClass = parent.getNodeClass();

for (NodeFieldAccessor nodeField : nodeClass.getChildFields()) {
Expand Down Expand Up @@ -315,7 +315,7 @@ public static boolean isReplacementSafe(Node parent, Node oldChild, Node newChil
* @return {@code true} if all children were visited, {@code false} otherwise
*/
public static boolean forEachChild(Node parent, NodeVisitor visitor) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not iterate over Node children from compiled code");
Objects.requireNonNull(visitor);
NodeClass parentNodeClass = parent.getNodeClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public boolean isCloningAllowed() {
* heuristics can use the loop count to guide compilation and inlining.
*/
public final void reportLoopCount(int count) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call RootNode.reportLoopCount from compiled code");
if (getCallTarget() instanceof LoopCountReceiver) {
((LoopCountReceiver) getCallTarget()).reportLoopCount(count);
}
Expand Down Expand Up @@ -141,7 +141,7 @@ public final void setCallTarget(RootCallTarget callTarget) {
* stack) without prior knowledge of the language it has come from.
*
* Used for instance to determine the language of a <code>RootNode<code>:
*
*
* <pre>
* <code>
* rootNode.getExecutionContext().getLanguageShortName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public abstract class Source {

private static boolean fileCacheEnabled = true;

private static final String NO_FASTPATH_SUBSOURCE_CREATION_MESSAGE = "do not create sub sources from compiled code";

/**
* Locates an existing instance by the name under which it was indexed.
*/
Expand Down Expand Up @@ -195,7 +197,7 @@ public static Source fromFileName(String fileName) throws IOException {
* method matches the file name
*/
public static Source fromFileName(CharSequence chars, String fileName) throws IOException {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Source.fromFileName from compiled code");
assert chars != null;

final WeakReference<Source> nameRef = nameToSource.get(fileName);
Expand Down Expand Up @@ -228,7 +230,7 @@ public static Source fromFileName(CharSequence chars, String fileName) throws IO
* @return a newly created, non-indexed source representation
*/
public static Source fromText(CharSequence chars, String description) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Source.fromText from compiled code");
return new LiteralSource(description, chars.toString());
}

Expand All @@ -240,7 +242,7 @@ public static Source fromText(CharSequence chars, String description) {
* @return a newly created, non-indexed, initially empty, appendable source representation
*/
public static Source fromAppendableText(String description) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Source.fromAppendableText from compiled code");
return new AppendableLiteralSource(description);
}

Expand All @@ -254,7 +256,7 @@ public static Source fromAppendableText(String description) {
* @return a newly created, source representation
*/
public static Source fromNamedText(CharSequence chars, String name) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Source.fromNamedText from compiled code");
final Source source = new LiteralSource(name, chars.toString());
nameToSource.put(name, new WeakReference<>(source));
return source;
Expand All @@ -270,7 +272,7 @@ public static Source fromNamedText(CharSequence chars, String name) {
* @return a newly created, indexed, initially empty, appendable source representation
*/
public static Source fromNamedAppendableText(String name) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Source.fromNamedAppendable from compiled code");
final Source source = new AppendableLiteralSource(name);
nameToSource.put(name, new WeakReference<>(source));
return source;
Expand All @@ -287,7 +289,7 @@ public static Source fromNamedAppendableText(String name) {
* @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();
CompilerAsserts.neverPartOfCompilation(NO_FASTPATH_SUBSOURCE_CREATION_MESSAGE);
final SubSource subSource = SubSource.create(base, baseCharIndex, length);
return subSource;
}
Expand All @@ -302,7 +304,7 @@ public static Source subSource(Source base, int baseCharIndex, int length) {
* @throws IllegalArgumentException if the index is out of range
*/
public static Source subSource(Source base, int baseCharIndex) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation(NO_FASTPATH_SUBSOURCE_CREATION_MESSAGE);

return subSource(base, baseCharIndex, base.getLength() - baseCharIndex);
}
Expand All @@ -316,7 +318,7 @@ public static Source subSource(Source base, int baseCharIndex) {
* @throws IOException if reading fails
*/
public static Source fromURL(URL url, String description) throws IOException {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Source.fromURL from compiled code");
return URLSource.get(url, description);
}

Expand All @@ -329,7 +331,7 @@ public static Source fromURL(URL url, String description) throws IOException {
* @throws IOException if reading fails
*/
public static Source fromReader(Reader reader, String description) throws IOException {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Source.fromReader from compiled code");
return new LiteralSource(description, read(reader));
}

Expand Down Expand Up @@ -361,7 +363,7 @@ public static Source fromBytes(byte[] bytes, String description, Charset charset
* @return a newly created, non-indexed source representation
*/
public static Source fromBytes(byte[] bytes, int byteIndex, int length, String description, Charset charset) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation("do not call Source.fromBytes from compiled code");
return new BytesSource(description, bytes, byteIndex, length, charset);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public abstract class ShapeImpl extends Shape {
protected final Assumption validAssumption;
@CompilationFinal protected volatile Assumption leafAssumption;

public static final String NO_FASTPATH_PROPERTY_ADD_MESSAGE = "don't add object properties in compiled code";

/**
* Shape transition map; lazily initialized.
*
Expand Down Expand Up @@ -390,7 +392,7 @@ public ShapeImpl defineProperty(Object key, Object value, int flags, LocationFac
* @see #addProperty(Property)
*/
private ShapeImpl addPropertyInternal(Property prop, boolean ensureValid) {
CompilerAsserts.neverPartOfCompilation();
CompilerAsserts.neverPartOfCompilation(NO_FASTPATH_PROPERTY_ADD_MESSAGE);
assert prop.isShadow() || !(this.hasProperty(prop.getKey())) : "duplicate property " + prop.getKey();

AddPropertyTransition addTransition = new AddPropertyTransition(prop);
Expand Down

0 comments on commit 0f9e4cc

Please sign in to comment.