Skip to content

Commit

Permalink
[Truffle] Module#deprecate_constant add profiles/boundaries to Lookup…
Browse files Browse the repository at this point in the history
… nodes
  • Loading branch information
Brandon Fish committed Sep 29, 2016
1 parent 95c3463 commit 6ab74ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
10 changes: 3 additions & 7 deletions truffle/src/main/java/org/jruby/truffle/language/WarnNode.java
Expand Up @@ -10,18 +10,14 @@ public class WarnNode extends RubyBaseNode {

@Child CallDispatchHeadNode warnMethod = CallDispatchHeadNode.createMethodCall();

public Object execute(VirtualFrame frame, Object... arguments) {
public Object execute(VirtualFrame frame, String... arguments) {
final String warningMessage = concatArgumentsToString(arguments);
final DynamicObject warningString = createString(warningMessage.getBytes(), UTF8Encoding.INSTANCE);
return warnMethod.call(frame, getContext().getCoreLibrary().getKernelModule(), "warn", warningString);
}

@TruffleBoundary
private String concatArgumentsToString(Object... arguments) {
String result = "";
for (int i = 0; i < arguments.length; i++) {
result += arguments[i].toString();
}
return result;
private String concatArgumentsToString(String... arguments) {
return String.join("", arguments);
}
}
Expand Up @@ -73,11 +73,13 @@ protected RubyConstant lookupConstant(
@Cached("name") String cachedName,
@Cached("doLookup(cachedModule, cachedName)") RubyConstant constant,
@Cached("isVisible(cachedModule, constant)") boolean isVisible,
@Cached("createBinaryProfile()") ConditionProfile sameNameProfile) {
if (!isVisible) {
@Cached("createBinaryProfile()") ConditionProfile sameNameProfile,
@Cached("createBinaryProfile()") ConditionProfile isVisibleProfile,
@Cached("createBinaryProfile()") ConditionProfile isDeprecatedProfile) {
if (isVisibleProfile.profile(!isVisible)) {
throw new RaiseException(coreExceptions().nameErrorPrivateConstant(module, name, this));
}
if (constant != null && constant.isDeprecated()) {
if (isDeprecatedProfile.profile(constant != null && constant.isDeprecated())) {
warnDeprecatedConstant(frame, name);
}
return constant;
Expand Down Expand Up @@ -124,6 +126,7 @@ protected boolean guardName(String name, String cachedName, ConditionProfile sam
}
}

@TruffleBoundary
protected RubyConstant doLookup(DynamicObject module, String name) {
if (lookInObject) {
return ModuleOperations.lookupConstantAndObject(getContext(), module, name);
Expand All @@ -132,6 +135,7 @@ protected RubyConstant doLookup(DynamicObject module, String name) {
}
}

@TruffleBoundary
protected boolean isVisible(DynamicObject module, RubyConstant constant) {
return ignoreVisibility ||
constant == null ||
Expand Down
Expand Up @@ -17,6 +17,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node.Child;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.core.module.ModuleOperations;
import org.jruby.truffle.language.LexicalScope;
Expand Down Expand Up @@ -48,14 +49,15 @@ public RubyConstant lookupConstant(VirtualFrame frame, Object module, String nam
}

@Specialization(assumptions = "getUnmodifiedAssumption(getModule())")
protected RubyConstant lookupConstant(
VirtualFrame frame,
protected RubyConstant lookupConstant(VirtualFrame frame,
@Cached("doLookup()") RubyConstant constant,
@Cached("isVisible(constant)") boolean isVisible) {
if (!isVisible) {
@Cached("isVisible(constant)") boolean isVisible,
@Cached("createBinaryProfile()") ConditionProfile isVisibleProfile,
@Cached("createBinaryProfile()") ConditionProfile isDeprecatedProfile) {
if (isVisibleProfile.profile(!isVisible)) {
throw new RaiseException(coreExceptions().nameErrorPrivateConstant(getModule(), name, this));
}
if (constant != null && constant.isDeprecated()) {
if (isDeprecatedProfile.profile(constant != null && constant.isDeprecated())) {
warnDeprecatedConstant(frame, name);
}
return constant;
Expand All @@ -77,10 +79,12 @@ public Assumption getUnmodifiedAssumption(DynamicObject module) {
return Layouts.MODULE.getFields(module).getUnmodifiedAssumption();
}

@TruffleBoundary
protected RubyConstant doLookup() {
return ModuleOperations.lookupConstantWithLexicalScope(getContext(), lexicalScope, name);
}

@TruffleBoundary
protected boolean isVisible(RubyConstant constant) {
return constant == null || constant.isVisibleTo(getContext(), lexicalScope, getModule());
}
Expand Down

0 comments on commit 6ab74ed

Please sign in to comment.