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

Loosen the reentrance rules a bit for parent/child scenarios #62

Merged
merged 1 commit into from
Jul 8, 2022

Conversation

lukewagner
Copy link
Member

This PR loosens the reentrance rules to allow canon lift to be called from inside a component instance such as when a parent component is called by a child component. For example, in this example:

(component
  (core module $Core1 ...)
  (core instance $core1 (instantiate $Core1))
  (func $func1 (canon lift (core func $core1 "func")))
  (component $Child ...)
  (instance $child (instantiate $Child (with "func1" (func $func1))))
  (core func $child_func (canon lower (func $child "func")))
  (core module $Core2 ...)
  (core instance $core2 (instantiate $Core2 (with "child" (instance (export "func" (func $child_func))))))
  (func $func2 (canon lift (core func $core2 "func")))
  (export "func2" (func $func2))
)

as previously written, $func2 would clear may_enter so that $func1 would trap when called by $child. With this PR, the idea is that $func1 wouldn't check may_enter because called_as_export would be False. A more realistic example of when you'd want to do this is that the parent component uses $Core1 and $Core2 to virtualize a filesystem for $Child, including passing preopens into $Child's exports.

One consequence of this relaxation is that same-component-instance lift+lower would be possible and such cases would need to be compiled more pessimistically (although in a way that only impacted this (rare) case). The PR explains more.

Copy link
Collaborator

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me, and to confirm, it's possible to optimize a same-component lift/lower if the linear memories they reference are provably disjoint, right?

@lukewagner
Copy link
Member Author

Yep!

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