Skip to content

Account for exact references in indirect call effects#8807

Open
stevenfontanella wants to merge 2 commits into
mainfrom
exact-effects
Open

Account for exact references in indirect call effects#8807
stevenfontanella wants to merge 2 commits into
mainfrom
exact-effects

Conversation

@stevenfontanella

Copy link
Copy Markdown
Member

Part of #8615. Allows us to ignore effects from func subtypes when we have an indirect call to an exact reference.

@stevenfontanella stevenfontanella marked this pull request as ready for review June 5, 2026 21:25
@stevenfontanella stevenfontanella requested a review from a team as a code owner June 5, 2026 21:25
@stevenfontanella stevenfontanella requested review from tlively and removed request for a team June 5, 2026 21:25

@tlively tlively left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Something I realized we're probably not handling correctly (but tell me if I'm wrong) is inexact function imports. When I import a function inexactly with type $super, take a reference to it somewhere, and then somewhere else do an indirect call to $sub, it's possible that I end up calling the import. That's because the reference to the imported function reference can be cast to $sub, and that cast might succeed depending on the function that was supplied at instantiation time.

But this is probably a pre-existing bug. I only thought about it because I was considering exactness. It probably makes sense to fix separately.

Comment thread src/ir/linear-execution.h Outdated
Comment thread src/ir/type-updating.cpp Outdated
@stevenfontanella

Copy link
Copy Markdown
Member Author

Something I realized we're probably not handling correctly (but tell me if I'm wrong) is inexact function imports. When I import a function inexactly with type $super, take a reference to it somewhere, and then somewhere else do an indirect call to $sub, it's possible that I end up calling the import. That's because the reference to the imported function reference can be cast to $sub, and that cast might succeed depending on the function that was supplied at instantiation time.

But this is probably a pre-existing bug. I only thought about it because I was considering exactness. It probably makes sense to fix separately.

I see, even in closed-world mode the import is basically acting as an alias and can redefine the function as a supertype of its real type.

Would something like #8811 be enough to fix it? This PR makes a similar mistake here, so maybe I'd try to fix this more generally before submitting this PR.

@tlively

tlively commented Jun 8, 2026

Copy link
Copy Markdown
Member

Would something like #8811 be enough to fix it? This PR makes a similar mistake here, so maybe I'd try to fix this more generally before submitting this PR.

The type on the Function should already be correct. We just need to make sure we're handling it correctly in the effects analysis.

@stevenfontanella

Copy link
Copy Markdown
Member Author

I don't understand, there's a TODO for the type field in Function which suggests that it's not correct today, and I also thought that it's not correct based on what you said. If we have

  (import "" "" (func $f (type $super)))

then it looks like the current code will have exact $super as the type for this which I think is wrong.

To fix this PR, I think I'd want to merge #8811 and then use caller->type.getExactness() here instead of Exact. Does that sound correct to you?

@tlively

tlively commented Jun 8, 2026

Copy link
Copy Markdown
Member

I think that TODO is stale. We're already careful to set the exactness correctly in the binary parser and in the text parser.

@tlively

tlively commented Jun 8, 2026

Copy link
Copy Markdown
Member

and then use caller->type.getExactness() here instead of Exact. Does that sound correct to you?

I'm not sure it's sufficient. Normally we flow effects up the subtype hierarchy so that effects in referenced functions of type $f are included in indirect calls to all supertypes of $f. But here if we have a function import of type $f, we need to include the "calls an import" effects in indirect calls to all subtypes of $f as well.

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