Skip to content

Commit a2f7a59

Browse files
committed
[GR-24499] Fix deprecations related to removing properties
* We no longer need to use the flag as removeKey() no longer reuses removed locations for shared objects.
1 parent 1c26c8f commit a2f7a59

File tree

6 files changed

+14
-84
lines changed

6 files changed

+14
-84
lines changed

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
import org.truffleruby.language.objects.ObjectIVarGetNode;
108108
import org.truffleruby.language.objects.ObjectIVarSetNode;
109109
import org.truffleruby.language.objects.PropagateTaintNode;
110-
import org.truffleruby.language.objects.PropertyFlags;
111110
import org.truffleruby.language.objects.ReadObjectFieldNode;
112111
import org.truffleruby.language.objects.ReadObjectFieldNodeGen;
113112
import org.truffleruby.language.objects.ShapeCachingGuards;
@@ -1015,8 +1014,7 @@ protected boolean isInstanceVariableDefinedSymbolOrNil(RubySymbol object, String
10151014
@Specialization
10161015
protected boolean isInstanceVariableDefined(DynamicObject object, String name) {
10171016
final String ivar = SymbolTable.checkInstanceVariableName(getContext(), name, object, this);
1018-
final Property property = object.getShape().getProperty(ivar);
1019-
return PropertyFlags.isDefined(property);
1017+
return object.getShape().hasProperty(ivar);
10201018
}
10211019

10221020
}
@@ -1077,26 +1075,17 @@ protected Object removeInstanceVariable(DynamicObject object, String name) {
10771075
removeField(object, name);
10781076
}
10791077
} else {
1080-
if (!object.delete(name)) {
1081-
throw new RaiseException(
1082-
getContext(),
1083-
coreExceptions().nameErrorInstanceVariableNotDefined(name, object, this));
1084-
}
1078+
removeField(object, name);
10851079
}
10861080
return value;
10871081
}
10881082

10891083
private void removeField(DynamicObject object, String name) {
1090-
Shape shape = object.getShape();
1091-
Property property = shape.getProperty(name);
1092-
if (!PropertyFlags.isDefined(property)) {
1084+
if (!DynamicObjectLibrary.getUncached().removeKey(object, name)) {
10931085
throw new RaiseException(
10941086
getContext(),
10951087
coreExceptions().nameErrorInstanceVariableNotDefined(name, object, this));
10961088
}
1097-
1098-
Shape newShape = shape.replaceProperty(property, PropertyFlags.asRemoved(property));
1099-
object.setShapeAndGrow(shape, newShape);
11001089
}
11011090
}
11021091

src/main/java/org/truffleruby/core/support/TypeNodes.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@
3535
import org.truffleruby.core.string.StringNodes;
3636
import org.truffleruby.core.symbol.RubySymbol;
3737
import org.truffleruby.language.NotProvided;
38-
import org.truffleruby.language.library.RubyLibrary;
3938
import org.truffleruby.language.RubyNode;
4039
import org.truffleruby.language.control.RaiseException;
40+
import org.truffleruby.language.library.RubyLibrary;
4141
import org.truffleruby.language.objects.IsANode;
4242
import org.truffleruby.language.objects.LogicalClassNode;
4343
import org.truffleruby.language.objects.ObjectIVarGetNode;
4444
import org.truffleruby.language.objects.ObjectIVarSetNode;
45-
import org.truffleruby.language.objects.PropertyFlags;
4645

4746
import com.oracle.truffle.api.CompilerDirectives;
4847
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -131,7 +130,7 @@ protected DynamicObject instanceVariables(DynamicObject object) {
131130

132131
for (Property property : shape.getProperties()) {
133132
Object name = property.getKey();
134-
if (PropertyFlags.isDefined(property) && name instanceof String) {
133+
if (name instanceof String) {
135134
names.add((String) name);
136135
}
137136
}
@@ -187,8 +186,7 @@ public abstract static class ObjectIVarIsDefinedNode extends PrimitiveArrayArgum
187186
@Specialization
188187
protected Object ivarIsDefined(DynamicObject object, RubySymbol name) {
189188
final String ivar = name.getString();
190-
final Property property = object.getShape().getProperty(ivar);
191-
return PropertyFlags.isDefined(property);
189+
return object.getShape().hasProperty(ivar);
192190
}
193191

194192
}

src/main/java/org/truffleruby/language/objects/HasFieldNode.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.oracle.truffle.api.dsl.ReportPolymorphism;
2121
import com.oracle.truffle.api.dsl.Specialization;
2222
import com.oracle.truffle.api.object.DynamicObject;
23-
import com.oracle.truffle.api.object.Property;
2423
import com.oracle.truffle.api.object.Shape;
2524

2625
@ReportPolymorphism
@@ -41,8 +40,8 @@ public static HasFieldNode create() {
4140
protected boolean hasFieldCached(DynamicObject receiver, Object name,
4241
@Cached("receiver.getShape()") Shape cachedShape,
4342
@Cached("name") Object cachedName,
44-
@Cached("getProperty(cachedShape, cachedName)") Property cachedProperty) {
45-
return cachedProperty != null;
43+
@Cached("cachedShape.hasProperty(cachedName)") boolean hasProperty) {
44+
return hasProperty;
4645
}
4746

4847
@Specialization(guards = "updateShape(object)")
@@ -54,17 +53,7 @@ protected boolean updateShapeAndHasField(DynamicObject object, Object name) {
5453
@Specialization(replaces = { "hasFieldCached", "updateShapeAndHasField" })
5554
protected boolean hasFieldUncached(DynamicObject receiver, Object name) {
5655
final Shape shape = receiver.getShape();
57-
final Property property = getProperty(shape, name);
58-
return property != null;
59-
}
60-
61-
@TruffleBoundary
62-
public static Property getProperty(Shape shape, Object name) {
63-
Property property = shape.getProperty(name);
64-
if (!PropertyFlags.isDefined(property)) {
65-
return null;
66-
}
67-
return property;
56+
return shape.hasProperty(name);
6857
}
6958

7059
protected int getCacheLimit() {

src/main/java/org/truffleruby/language/objects/PropertyFlags.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/main/java/org/truffleruby/language/objects/ReadObjectFieldNode.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static ReadObjectFieldNode create() {
4141
protected Object readObjectFieldCached(DynamicObject receiver, Object name, Object defaultValue,
4242
@Cached("receiver.getShape()") Shape cachedShape,
4343
@Cached("name") Object cachedName,
44-
@Cached("getProperty(cachedShape, cachedName)") Property cachedProperty) {
44+
@Cached("cachedShape.getProperty(cachedName)") Property cachedProperty) {
4545
return readOrDefault(receiver, cachedShape, cachedProperty, defaultValue);
4646
}
4747

@@ -54,19 +54,10 @@ protected Object updateShapeAndRead(DynamicObject object, Object name, Object de
5454
@Specialization(replaces = { "readObjectFieldCached", "updateShapeAndRead" })
5555
protected Object readObjectFieldUncached(DynamicObject receiver, Object name, Object defaultValue) {
5656
final Shape shape = receiver.getShape();
57-
final Property property = getProperty(shape, name);
57+
final Property property = shape.getProperty(name);
5858
return readOrDefault(receiver, shape, property, defaultValue);
5959
}
6060

61-
@TruffleBoundary
62-
public static Property getProperty(Shape shape, Object name) {
63-
Property property = shape.getProperty(name);
64-
if (!PropertyFlags.isDefined(property)) {
65-
return null;
66-
}
67-
return property;
68-
}
69-
7061
private static Object readOrDefault(DynamicObject object, Shape shape, Property property, Object defaultValue) {
7162
if (property != null) {
7263
return property.get(object, shape);

src/main/java/org/truffleruby/language/objects/WriteObjectFieldNode.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package org.truffleruby.language.objects;
1111

12-
import com.oracle.truffle.api.object.DynamicObjectLibrary;
1312
import org.truffleruby.RubyContext;
1413
import org.truffleruby.RubyLanguage;
1514
import org.truffleruby.extra.ffi.Pointer;
@@ -28,6 +27,7 @@
2827
import com.oracle.truffle.api.dsl.ReportPolymorphism;
2928
import com.oracle.truffle.api.dsl.Specialization;
3029
import com.oracle.truffle.api.object.DynamicObject;
30+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
3131
import com.oracle.truffle.api.object.FinalLocationException;
3232
import com.oracle.truffle.api.object.IncompatibleLocationException;
3333
import com.oracle.truffle.api.object.Location;
@@ -171,7 +171,7 @@ protected Location getLocation(DynamicObject object, Object name, Object value)
171171
final Shape oldShape = object.getShape();
172172
final Property property = oldShape.getProperty(name);
173173

174-
if (PropertyFlags.isDefined(property) && property.getLocation().canSet(object, value)) {
174+
if (property != null && property.getLocation().canSet(object, value)) {
175175
return property.getLocation();
176176
} else {
177177
return null;
@@ -184,14 +184,7 @@ protected Shape defineProperty(Shape oldShape, Object name, Object value, boolea
184184
if (generalize) {
185185
value = SOME_OBJECT;
186186
}
187-
Property property = oldShape.getProperty(name);
188-
if (property != null && PropertyFlags.isRemoved(property)) {
189-
// Do not reuse location of removed properties
190-
Location location = oldShape.allocator().locationForValue(value);
191-
return oldShape.replaceProperty(property, property.relocate(location).copyWithFlags(0));
192-
} else {
193-
return oldShape.defineProperty(name, value, 0);
194-
}
187+
return oldShape.defineProperty(name, value, 0);
195188
}
196189

197190
protected Location getNewLocation(Object name, Shape newShape) {

0 commit comments

Comments
 (0)