-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
RyuJIT: Extend "cns".Length optimization to support static readonly fields #42087
Comments
@EgorBo, would it happen on post-materialization phase and would it also cover tricky cases like someone is using reflection to update the value of static readonly field? |
Reflection stack disallows this because there's existing codegen optimizations that rely on them being immutable. One can still break this (because nothing prevents e.g. re-running the static constructor and depending on what the static constructor does we might end up with a different value), but those are mostly academic scenarios. |
Maybe it should be prevented to re-run the static constructor. |
@BrianBohe oops, didn't notice you self assigned this, I filed a PR that fixed a different thing but as a side effect it fixes this too |
It's okay don't worry. I assigned it to me but I wasn't able to start it. |
#1378 introduced an optimization to fold
"const str".Length
into a const int. It probably makes sense to extend it to also supportstatic readonly string
fields, e.g:Prototype: master...EgorBo:static-readonly-string-fields-opts
(it extends the existing jit-vm API
getStringLiteral
to accept a field reference).jit-diff (--pmi --cctors) is not as exciting as I hoped:
so feel free to close it if you think it's not worth the effort.
category:cq
theme:basic-cq
skill-level:beginner
cost:small
The text was updated successfully, but these errors were encountered: