-
Notifications
You must be signed in to change notification settings - Fork 81
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
Initialize first field in named union constructors #784
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is this variable unused?
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.
No, it's used to tell
render_field_init
that it's rendering fields from a union, and is necessary here to get the behavior we want.Remember that in Perl,
local
variables are dynamically, not lexically, scoped (see What is the difference between my and local in Perl?).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.
It's read here in
render_field_init
but is not set there:df-structures/StructFields.pm
Line 409 in 833a1fd
Probably an oversimplification: I've been thinking of
local
vars as additional context args that get pushed on the stack and get restored when they go "out of scope". Inspecting$is_union
outside of thisemit_block
will show it still set to 0.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.
they're actually pushed into the current block's dynamics symbol table, which remains visible during a subroutine call, so any subroutine called will also see them (unless shadowed). lexically scoped
my
locals, however, are only visible within the lexical block (and any enclosed blocks) in which they're created.it's not so much that they get "restored" but rather that defining a symbol within a block shadows any definition that might exist in a block further up. when the block ends, its symbol tables are disposed (each block effectively has two, one for dynamic scope and one for lexical scope), and any prior definition that was being shadowed is thereby unshadowed and thus once again visible. every block carries with it a pointer to the lexical context in which it was defined (a closure), and the current dynamic symbol context is used to initialize a new dynamic symbol context whenever execution enters a new block.
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.
thank for the explanation. my perl fu is low