Is the jit supposed to hoist init type checks this hard? #122605
Unanswered
crystal-rgb
asked this question in
Q&A
Replies: 1 comment
-
|
In practice, a type is often considered touched when a method referencing the type get touched. The timing of static constructor is non-deterministic. It's not suggested to depend on its side effect. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Consider static types A with a method
void OhGodWhyand B with another methodvoid DoWorkand a static constructor (.cctor) .(Note that this isn't a minimal repro as I couldn't isolate the behaviour.)
In Release, depending on the shape of the code, the generated asm for
OhGodWhywill have the first instruction a type initialisation check for type B followed by a conditional jump to said initialisation and a jump back to the first written line of code. This makes the type B.cctoralways run even if we never touch B, by returning early.Is this intended behaviour? And if so then what's causing it? 👀
I would love to learn more about how the JIT reasons, thank you for your time! 🙂
Beta Was this translation helpful? Give feedback.
All reactions