diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-18 17:01:40 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:43 -0400 |
commit | b74d6563a665f225f182c4921db68852bbb7e1f1 (patch) | |
tree | 14a7131d423549cf1ffc661048e7501d5ce5ae24 /bootstraptest | |
parent | 2e2430564aa32b68f9e2d99e1f1e273bee3defda (diff) |
Extract yjit_force_iv_index and make it work when object is frozen
In an effort to simplify the logic YJIT generates for accessing instance
variable, YJIT ensures that a given name-to-index mapping exists at
compile time. In the case that the mapping doesn't exist, it was created
by using rb_ivar_set() with Qundef on the sample object we see at
compile time. This hack isn't fine if the sample object happens to be
frozen, in which case YJIT would raise a FrozenError unexpectedly.
To deal with this, make a new function that only reserves the mapping
but doesn't touch the object. This is rb_obj_ensure_iv_index_mapping().
This new function superceeds the functionality of rb_iv_index_tbl_lookup()
so it was removed.
Reported by and includes a test case from John Hawthorn <john@hawthorn.email>
Fixes: GH-282
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_yjit.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index a190d8ffb1..765580a030 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -2160,3 +2160,18 @@ assert_equal '[2]', %q{ 5.times.map { default_expression(value: 2) }.uniq } + +# attr_reader on frozen object +assert_equal 'false', %q{ + class Foo + attr_reader :exception + + def failed? + !exception.nil? + end + end + + foo = Foo.new.freeze + foo.failed? + foo.failed? +} |