-
Notifications
You must be signed in to change notification settings - Fork 38
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
cgen: make .global.
s work more according to spec
#536
cgen: make .global.
s work more according to spec
#536
Conversation
compiler/sem/transf.nim
Outdated
of nkWhen: | ||
# a ``when nimvm`` construct | ||
# XXX: this logic duplciates what ``mirgen`` already does. Maybe | ||
# collecting should happen there? Or procedure-level globals should |
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.
Likely makes sense in sem as a normalization step.
cceca8c
to
b67d177
Compare
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.
Bors r+
Thanks for the detailed explanation, it was really easy to follow.
Merge conflict. |
For the C target, globals defined inside procedures that are resource- like (i.e. have a user-defined or lifted destructor) are now initialized in a module's pre-init procedure, instead of each time control-flow reaches the definition. This mirrors what already happened for non-resource-like globals. In addition, globals defined in `inline` procedures no longer cause linking errors because of duplicated definitions in the generated C code. The globals are extracted before translating the AST to MIR code, making the workaround in `mirgen` (that didn't work anyway) obsolete. In order to work towards unifying the architecture of the back-ends, `vmbackend` now also makes use of the pre-extraction, no longer requiring extra logic in the code-generator. - the destructor injection pass is not run for the initializer expression of globals defined inside procedures - `.global.`s on the JS target still don't work according to specification
b67d177
to
b114b8d
Compare
bors r+ |
Build succeeded: |
Summary
For the C target, globals defined inside procedures that are resource- like (i.e. have a user-defined or lifted destructor) are now initialized in a module's pre-init procedure, instead of each time control-flow reaches the definition. This mirrors what already happened for non-resource-like globals.
In addition, globals defined in
inline
procedures no longer cause linking errors because of duplicated definitions in the generated C code.Details
The globals are extracted before translating the AST to MIR code, making the workaround in
mirgen
(that didn't work anyway) obsolete. In order to work towards unifying the architecture of the back-ends,vmbackend
now also makes use of the pre-extraction, no longer requiring extra logic in the code-generator.Known Issues
.global.
s on the JS target still don't work according to specificationNotes for Reviewers
The PR is meant to unblock #450 with the least amount of work and changes to semantics. I think that the introduced regression (no destructor injection for initializers of procedure-level globals) is acceptable until the implementation gets an overhaul.