Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo finer-grained inline constant cache invalidation #5716

Merged

Conversation

kddnewton
Copy link
Contributor

@kddnewton kddnewton commented Mar 25, 2022

Brings back the constant invalidation code from https://bugs.ruby-lang.org/issues/18589, now that the underlying BIN comparison bug is fixed by #5741.

@kddnewton kddnewton closed this Mar 25, 2022
@kddnewton kddnewton reopened this Mar 25, 2022
@kddnewton kddnewton force-pushed the revert-5715-revert-5433-constant-invalidation branch 2 times, most recently from fce6d41 to f836cfa Compare March 25, 2022 16:09
@kddnewton kddnewton closed this Mar 25, 2022
@kddnewton kddnewton reopened this Mar 25, 2022
@kddnewton kddnewton force-pushed the revert-5715-revert-5433-constant-invalidation branch 15 times, most recently from 1f0e3ed to 546c456 Compare March 31, 2022 15:17
include/ruby/backward.h Outdated Show resolved Hide resolved
iseq.c Outdated Show resolved Hide resolved
vm_insnhelper.c Outdated Show resolved Hide resolved
class.c Outdated Show resolved Hide resolved
tenderlove and others added 2 commits April 1, 2022 12:32
Some of the symbols had changed names and the script was no longer
finding them.
This commit reintroduces finer-grained constant cache invalidation.
After 8008fb7 got merged, it was causing issues on token-threaded
builds (such as on Windows).

The issue was that when you're iterating through instruction sequences
and using the translator functions to get back the instruction structs,
you're either using `rb_vm_insn_null_translator` or
`rb_vm_insn_addr2insn2` depending if it's a direct-threading build.
`rb_vm_insn_addr2insn2` does some normalization to always return to
you the non-trace version of whatever instruction you're looking at.
`rb_vm_insn_null_translator` does not do that normalization.

This means that when you're looping through the instructions if you're
trying to do an opcode comparison, it can change depending on the type
of threading that you're using. This can be very confusing. So, this
commit creates a new translator function
`rb_vm_insn_normalizing_translator` to always return the non-trace
version so that opcode comparisons don't have to worry about different
configurations.

[Feature #18589]
@kddnewton kddnewton force-pushed the revert-5715-revert-5433-constant-invalidation branch from 546c456 to 5b223bf Compare April 1, 2022 16:33
@XrXr XrXr merged commit 6068da8 into ruby:master Apr 1, 2022
Comment on lines +103 to +108
begin
Container.private_constant :CONST1, :CONST2
rescue NameError
end

const1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If :CONST1 and :CONST2 have the positions inverted, const1 in line 108 will return 1.

Copy link
Member

@XrXr XrXr Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, CONST2 doesn't exist, so when it's reversed private_constant raises NameError before changing the visibility of CONST1. On Ruby 3.1 private_constant behaves like this too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Thank you for the explanation.

@kddnewton kddnewton deleted the revert-5715-revert-5433-constant-invalidation branch April 4, 2022 19:09
@hsbt
Copy link
Member

hsbt commented Oct 6, 2022

@kddnewton @XrXr /cc @tenderlove Can you update NEWS.md about this change? At least, We should add entry for incompatibility of RubyVM.stat(:global_constant_state) removing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants