-
Notifications
You must be signed in to change notification settings - Fork 393
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
WIP fix(gnovm): PoC of inter-realm spec #2958
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
(The "review team" label was added by mistake. This PR is opened by a core dev.) |
// PKGPATH: gno.land/r/crossrealm_test | ||
package crossrealm_test | ||
|
||
import ( | ||
"std" | ||
|
||
crossrealm "gno.land/r/demo/tests/crossrealm/func" | ||
) | ||
|
||
var b = 1 | ||
|
||
type Local_S struct { | ||
name string | ||
} | ||
|
||
func main() { | ||
f := func() bool { | ||
c := b | ||
var ls *Local_S | ||
return true | ||
} | ||
crossrealm.SetCallback(f) | ||
println("ok") | ||
} | ||
|
||
// Output: | ||
// ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a FuncValue is associated with an ownership tree, its parent block is persisted during finalization. The main reason for this is that when the FuncValue is executed, it needs to resolve names from its outer blocks.
However, this introduces a side effect: when a FuncValue is associated with an external realm, its "clo", the parent block(the main block in the code above) gets attached to that external realm, is it intended? if yes
, while attaching this block to external realm, it is necessary to check recursively against the objects within this block , to identify if cross-realm happens, iff the block
is un-real
(if it's already real, everything is good), right?
So the FuncLit works similarly as MapLit, StructLit, etc.
↑ are some thoughts about FuncValue behavior in cross-realm situation after last call. @thehowl .
Anyway, will write some tests to explore this. And will appreciate if @jaekwon can help clarify this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon further consideration, if a function(closure) does not reference or capture any variables from outer scopes, it can be considered pure
. As a result, the Closure
field of the FuncValue
is nil. Therefore, when associating this func with the current or an external realm, there is no need to attach its parent block, so this issue is also resolved: #3693, correct?
WIP: adding filetest for inter-realm spec, NOT FINAL.
relate: #2743
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description