-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add facility to support with-contexts #3017
Merged
Merged
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4726b16
Begin work on with-lifting
sklam a5e8024
Working on with-lifting
sklam b156339
Extract and bypass with-contexts
sklam 4adebcd
Add EnterWith IR statement
sklam 2fd0705
Add context-manager that bypasses block of code
sklam f9a2205
Remove ir.Metadata
sklam bb88fa8
Fix for py2
sklam 94dfb17
Make bypass context forward variables properly
sklam 05c6e32
Work on with-context that lifts the body as a new function
sklam 2f0a6cc
Finish transformation for calling with-lifted block
sklam cf39c3d
More tests
sklam 326ce89
Fix py2 cyclic import
sklam 3cbc3da
Clean up
sklam 92c4c71
Deduplicate code
sklam 0ffd5f1
Fix comment
sklam 7a3ef96
Merge branch 'master' into enh/withlifting
sklam ebd6c23
Complete TODOs
sklam d55f41e
Fix unicode problem
sklam b985985
Fix py2 cyclic import
sklam 0ea643e
Fix docstrings and remove dead code
sklam 6156380
fix stencil call matching
fe6f776
Merge branch 'master' into enh/withlifting
sklam 8420e5b
Add source locations to error raised
sklam 8b7e40d
Add more loc
sklam f2b760b
Add test on invalid contextmanager
sklam 995fdda
Improve error msg
sklam a0b1f72
Fix test
sklam File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -564,6 +564,31 @@ def list_vars(self): | |
return [self.value] | ||
|
||
|
||
class EnterWith(Stmt): | ||
"""Enter a "with" context | ||
""" | ||
def __init__(self, contextmanager, begin, end, loc): | ||
""" | ||
Parameters | ||
---------- | ||
contextmanager : IR value | ||
begin, end : int | ||
The beginning and the ending offset of the with-body. | ||
loc : int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Source location | ||
""" | ||
self.contextmanager = contextmanager | ||
self.begin = begin | ||
self.end = end | ||
self.loc = loc | ||
|
||
def __str__(self): | ||
return 'enter_with {}'.format(self.contextmanager) | ||
|
||
def list_vars(self): | ||
return [self.contextmanager] | ||
|
||
|
||
class Arg(object): | ||
def __init__(self, name, index, loc): | ||
self.name = name | ||
|
@@ -874,6 +899,8 @@ def __repr__(self): | |
|
||
|
||
class Loop(object): | ||
"""Describes a loop-block | ||
""" | ||
__slots__ = "entry", "exit" | ||
|
||
def __init__(self, entry, exit): | ||
|
@@ -885,6 +912,20 @@ def __repr__(self): | |
return "Loop(entry=%s, exit=%s)" % args | ||
|
||
|
||
class With(object): | ||
"""Describes a with-block | ||
""" | ||
__slots__ = "entry", "exit" | ||
|
||
def __init__(self, entry, exit): | ||
self.entry = entry | ||
self.exit = exit | ||
|
||
def __repr__(self): | ||
args = self.entry, self.exit | ||
return "With(entry=%s, exit=%s)" % args | ||
|
||
|
||
class FunctionIR(object): | ||
|
||
def __init__(self, blocks, is_generator, func_id, loc, | ||
|
@@ -932,7 +973,7 @@ def derive(self, blocks, arg_count=None, arg_names=None, | |
if arg_names is not None: | ||
new_ir.arg_names = arg_names | ||
new_ir._reset_analysis_variables() | ||
|
||
new_ir.func_id = new_ir.func_id.derive() | ||
return new_ir | ||
|
||
def copy(self): | ||
|
Oops, something went wrong.
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.
Perhaps
This enables the resolving of the return type.
?