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

inference: Don't confuse frames in different interpreters #53627

Merged
merged 2 commits into from
Mar 8, 2024
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented Mar 7, 2024

Diffractor's abstract interpreter sometimes needs to do side queries using the native interpreter. These are pushed onto the regular inference callstack in anticipation of a future where compiler plugins may want to recurse from the native interpreter back into the Diffractor abstract interpreter. However, this introduced a subtle challenge: When the native interpreter is looking at a frame that is currently on the inference stack, it would treat them as the same, incorrectly merging inference across the two abstract interpreters (which have different semantics and may not be confused). The caches for the two abstract interpreters were already different, so once things are inferred, there's no problem (likely because things were already inferred on the native interpreter), but if not, this could cause subtle and hard to debug problems.

Diffractor's abstract interpreter sometimes needs to do side queries
using the native interpreter. These are pushed onto the regular
inference callstack in anticipation of a future where compiler plugins
may want to recurse from the native interpreter back into the Diffractor
abstract interpreter. However, this introduced a subtle challenge:
When the native interpreter is looking at a frame that is currently
on the inference stack, it would treat them as the same, incorrectly
merging inference across the two abstract interpreters (which have
different semantics and may not be confused). The caches for the two
abstract interpreters were already different, so once things are
inferred, there's no problem (likely because things were already
inferred on the native interpreter), but if not, this could cause
subtle and hard to debug problems.
@Keno Keno requested a review from aviatesk March 7, 2024 00:51
@@ -689,6 +689,10 @@ function edge_matches_sv(interp::AbstractInterpreter, frame::AbsIntState,
if callee_method2 !== inf_method2
return false
end
if isa(frame, InferenceState) && frame.interp !== interp
Copy link
Member

@vtjnash vtjnash Mar 7, 2024

Choose a reason for hiding this comment

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

The isa check makes it seem like this is doing something incorrectly. Isn't this actually the is_same_frame query though on the line above here?

Anyways, SGTM as a hack, but I dislike that the NativeInterpreter seems like a gigantic stack object (136 bytes) that now needs to be memcmp on every frame against every other frame here.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's kind of is_same_frame, but on the method. Rather than comparing the interpreter, I think we could compare the cache_owner if you like that better.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, cache_owner does intuitively feel like the right level of abstraction to me

@Keno Keno merged commit 4dcf357 into master Mar 8, 2024
5 of 7 checks passed
@Keno Keno deleted the kf/interpmix branch March 8, 2024 06:26
mkitti pushed a commit to mkitti/julia that referenced this pull request Apr 13, 2024
…53627)

Diffractor's abstract interpreter sometimes needs to do side queries
using the native interpreter. These are pushed onto the regular
inference callstack in anticipation of a future where compiler plugins
may want to recurse from the native interpreter back into the Diffractor
abstract interpreter. However, this introduced a subtle challenge: When
the native interpreter is looking at a frame that is currently on the
inference stack, it would treat them as the same, incorrectly merging
inference across the two abstract interpreters (which have different
semantics and may not be confused). The caches for the two abstract
interpreters were already different, so once things are inferred,
there's no problem (likely because things were already inferred on the
native interpreter), but if not, this could cause subtle and hard to
debug problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants