Skip to content

fix: avoid to use visit wrapper for __visit_globals #2934

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

Closed

Conversation

HerrCai0907
Copy link
Member

@HerrCai0907 HerrCai0907 commented Jul 10, 2025

If a class is annotated as final, it is impossible to have dynamic dispatch for __visit. So we can call the class's __visit function directly.
For pointee free object, we can even save the call

if (this.runtimeFeatures & RuntimeFeatures.visitMembers) compileVisitMembers(this);
if (this.runtimeFeatures & RuntimeFeatures.visitGlobals) compileVisitGlobals(this);
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this is done so the classReference.visitRef != 0 check in getVisitInstanceName doesn't erroneously evaluate to false (due to ensureVisitMembersOf not being called before compileVisitGlobals if you didn't reorder these two lines).

In that case, maybe add a comment here or in getVisitInstanceName explaining why compileVisitMembers has to be called before compileVisitGlobals...after all, it took me a few minutes of thinking/code searching to make sure that the classReference.visitRef check is safe, and that led me back to this diff.

If a class is annotated as final, it is impossible to have dynamic dispatch for __visit. So we can call the class's __visit function directly.
For string, we can even save the call
@HerrCai0907 HerrCai0907 force-pushed the avoid-visit-final-class branch from 8a06d97 to d21dcfd Compare July 11, 2025 02:56
@HerrCai0907
Copy link
Member Author

I found it is wrong. even global marked as const, it is also possible to be initialized during ~start and point to heap dyn allocated memory.

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