Skip to content

Commit

Permalink
[Truffle] Return nil when reading a missing object field.
Browse files Browse the repository at this point in the history
* Propagating null accross the tree usually proves being a bad idea.
  • Loading branch information
eregon committed May 15, 2015
1 parent 83dbfee commit 851477a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class ReadInstanceVariableNode extends RubyNode implements ReadNode {
@Child private ReadHeadObjectFieldNode readNode;
private final boolean isGlobal;

private final BranchProfile nullProfile = BranchProfile.create();
private final BranchProfile primitiveProfile = BranchProfile.create();

public ReadInstanceVariableNode(RubyContext context, SourceSection sourceSection, String name, RubyNode receiver, boolean isGlobal) {
Expand Down Expand Up @@ -85,14 +84,7 @@ public Object execute(VirtualFrame frame) {
final Object receiverObject = receiver.execute(frame);

if (receiverObject instanceof RubyBasicObject) {
Object value = readNode.execute((RubyBasicObject) receiverObject);

if (value == null) {
nullProfile.enter();
value = nil();
}

return value;
return readNode.execute((RubyBasicObject) receiverObject);
} else {
primitiveProfile.enter();
return nil();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Object execute(RubyBasicObject object) {
}

if (object.getDynamicObject().getShape() == objectLayout) {
return null;
return object.getContext().getCoreLibrary().getNilObject();
} else {
return next.execute(object);
}
Expand Down

0 comments on commit 851477a

Please sign in to comment.