|
12 | 12 | import java.util.ArrayList;
|
13 | 13 | import java.util.List;
|
14 | 14 |
|
| 15 | +import com.oracle.truffle.api.dsl.Bind; |
15 | 16 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
16 | 17 | import com.oracle.truffle.api.dsl.GenerateUncached;
|
17 | 18 | import com.oracle.truffle.api.dsl.NeverDefault;
|
|
36 | 37 | import org.truffleruby.core.symbol.RubySymbol;
|
37 | 38 | import org.truffleruby.language.Nil;
|
38 | 39 | import org.truffleruby.language.NotProvided;
|
| 40 | +import org.truffleruby.language.RubyBaseNode; |
39 | 41 | import org.truffleruby.language.RubyDynamicObject;
|
40 | 42 | import org.truffleruby.language.RubyGuards;
|
41 | 43 | import org.truffleruby.language.RubyNode;
|
@@ -109,43 +111,49 @@ protected boolean objectEqual(Object a, Object b,
|
109 | 111 | }
|
110 | 112 | }
|
111 | 113 |
|
112 |
| - @Primitive(name = "object_freeze") |
113 |
| - public abstract static class ObjectFreezeNode extends PrimitiveArrayArgumentsNode { |
114 |
| - @Specialization(limit = "getRubyLibraryCacheLimit()") |
| 114 | + public abstract static class ObjectFreezeNode extends RubyBaseNode { |
| 115 | + |
| 116 | + public abstract Object execute(Object self); |
| 117 | + |
| 118 | + @Specialization(guards = "!isRubyDynamicObject(self)", limit = "getRubyLibraryCacheLimit()") |
115 | 119 | protected Object freeze(Object self,
|
116 | 120 | @CachedLibrary("self") RubyLibrary rubyLibrary) {
|
117 |
| - assert !(self instanceof RubyDynamicObject && ((RubyDynamicObject) self).getMetaClass().isSingleton) |
118 |
| - : "Primitive.object_freeze does not handle instances of singleton classes, see KernelFreezeNode"; |
119 | 121 | rubyLibrary.freeze(self);
|
120 | 122 | return self;
|
121 | 123 | }
|
122 |
| - } |
123 | 124 |
|
124 |
| - @Primitive(name = "object_freeze_with_singleton_class") |
125 |
| - public abstract static class ObjectFreezeWithSingletonClassNode extends PrimitiveArrayArgumentsNode { |
126 |
| - @Specialization(limit = "getRubyLibraryCacheLimit()", guards = "!isRubyDynamicObject(self)") |
127 |
| - protected Object freeze(Object self, |
128 |
| - @CachedLibrary("self") RubyLibrary rubyLibrary) { |
| 125 | + @Specialization(guards = "!metaClass.isSingleton", limit = "getRubyLibraryCacheLimit()") |
| 126 | + protected Object freezeNormalObject(RubyDynamicObject self, |
| 127 | + @CachedLibrary("self") RubyLibrary rubyLibrary, |
| 128 | + @Cached MetaClassNode metaClassNode, |
| 129 | + @Bind("metaClassNode.execute(self)") RubyClass metaClass) { |
129 | 130 | rubyLibrary.freeze(self);
|
130 | 131 | return self;
|
131 | 132 | }
|
132 | 133 |
|
133 |
| - @Specialization(limit = "getRubyLibraryCacheLimit()", guards = "isRubyDynamicObject(self)") |
134 |
| - protected Object freezeDynamicObject(Object self, |
| 134 | + @Specialization(guards = "metaClass.isSingleton", limit = "getRubyLibraryCacheLimit()") |
| 135 | + protected Object freezeSingletonObject(RubyDynamicObject self, |
135 | 136 | @CachedLibrary("self") RubyLibrary rubyLibrary,
|
136 | 137 | @CachedLibrary(limit = "1") RubyLibrary rubyLibraryMetaClass,
|
137 | 138 | @Cached ConditionProfile singletonClassUnfrozenProfile,
|
138 |
| - @Cached MetaClassNode metaClassNode) { |
139 |
| - final RubyClass metaClass = metaClassNode.execute(self); |
140 |
| - if (singletonClassUnfrozenProfile.profile(metaClass.isSingleton && |
141 |
| - !(RubyGuards.isRubyClass(self) && ((RubyClass) self).isSingleton) && |
142 |
| - !rubyLibraryMetaClass.isFrozen(metaClass))) { |
| 139 | + @Cached MetaClassNode metaClassNode, |
| 140 | + @Bind("metaClassNode.execute(self)") RubyClass metaClass) { |
| 141 | + if (singletonClassUnfrozenProfile.profile( |
| 142 | + !RubyGuards.isSingletonClass(self) && !rubyLibraryMetaClass.isFrozen(metaClass))) { |
143 | 143 | rubyLibraryMetaClass.freeze(metaClass);
|
144 | 144 | }
|
145 | 145 | rubyLibrary.freeze(self);
|
146 | 146 | return self;
|
147 | 147 | }
|
| 148 | + } |
148 | 149 |
|
| 150 | + @Primitive(name = "object_freeze") |
| 151 | + public abstract static class ObjectFreezePrimitive extends PrimitiveArrayArgumentsNode { |
| 152 | + @Specialization |
| 153 | + protected Object freeze(Object self, |
| 154 | + @Cached ObjectFreezeNode objectFreezeNode) { |
| 155 | + return objectFreezeNode.execute(self); |
| 156 | + } |
149 | 157 | }
|
150 | 158 |
|
151 | 159 | @Primitive(name = "immediate_value?")
|
|
0 commit comments