-
Notifications
You must be signed in to change notification settings - Fork 12
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
Utilities to merge associate blocks and restrict depth of associate resolution #388
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e6b3ce3
Transformations: Add `start_depth` argument to resolve_associates
mlange05 33053cc
Transformations: Add `merge_associates` utility
mlange05 c111219
Transformations: Test and partially fix rescoping in merge_associates
mlange05 529310e
Tools: Make CaseInsensitiveDict work with expressions
mlange05 81c1d36
IR: Add test for constructors and scoping behaviour of `Associate`
mlange05 01d8b40
IR: Move local symbol type derivation for `Associates` to ir.nodes
mlange05 5b735e5
Transformations: Re-built symbol table for Associates after merging
mlange05 63b7f9c
IR: Harden Associate map and scoping test checks
mlange05 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,3 +292,35 @@ def test_callstatement(scope, one, i, n, a_i): | |
) | ||
|
||
# TODO: Test pragmas, active and chevron | ||
|
||
|
||
def test_associate(scope, a_i): | ||
""" | ||
Test constructors and scoping bahviour of :any:`Associate`. | ||
""" | ||
b = sym.Scalar(name='b', scope=scope) | ||
b_a = sym.Array(name='a', parent=b, scope=scope) | ||
a = sym.Array(name='a', scope=scope) | ||
assign = ir.Assignment(lhs=a_i, rhs=sym.Literal(42.0)) | ||
assign2 = ir.Assignment(lhs=a_i.clone(parent=b), rhs=sym.Literal(66.6)) | ||
|
||
assoc = ir.Associate(associations=((b_a, a),), body=(assign, assign2), parent=scope) | ||
assert isinstance(assoc.associations, tuple) | ||
assert all(isinstance(n, tuple) and len(n) == 2 for n in assoc.associations) | ||
assert isinstance(assoc.body, tuple) | ||
assert all(isinstance(n, ir.Node) for n in assoc.body) | ||
|
||
# TODO: Check constructor failures, auto-casting and frozen status | ||
|
||
# Check provided symbol maps | ||
assert 'B%a' in assoc.association_map and assoc.association_map['B%a'] == a | ||
assert b_a in assoc.association_map and assoc.association_map[b_a] == a | ||
assert 'a' in assoc.inverse_map and assoc.inverse_map['a'] == b_a | ||
assert a in assoc.inverse_map and assoc.inverse_map[a] == b_a | ||
|
||
# Check rescoping facility | ||
assert assign.lhs.scope == scope | ||
assert assign2.lhs.scope == scope | ||
assoc.rescope_symbols() | ||
assert assign.lhs.scope == assoc | ||
assert assign2.lhs.scope == scope | ||
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. Same here? ( |
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 |
---|---|---|
|
@@ -239,33 +239,41 @@ class CaseInsensitiveDict(OrderedDict): | |
https://stackoverflow.com/questions/2082152/case-insensitive-dictionary | ||
""" | ||
def __setitem__(self, key, value): | ||
super().__setitem__(key.lower(), value) | ||
key = key.lower() if isinstance(key, str) else key | ||
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. Fantastic 😍 This has annoyed me so often but I haven't come around to fixing it... |
||
super().__setitem__(key, value) | ||
|
||
def __getitem__(self, key): | ||
return super().__getitem__(key.lower()) | ||
key = key.lower() if isinstance(key, str) else key | ||
return super().__getitem__(key) | ||
|
||
def get(self, key, default=None): | ||
return super().get(key.lower(), default) | ||
key = key.lower() if isinstance(key, str) else key | ||
return super().get(key, default) | ||
|
||
def __contains__(self, key): | ||
return super().__contains__(key.lower()) | ||
key = key.lower() if isinstance(key, str) else key | ||
return super().__contains__(key) | ||
|
||
|
||
class CaseInsensitiveDefaultDict(defaultdict): | ||
""" | ||
Variant of :any:`collections.defaultdict` that ignores the casing of string keys. | ||
""" | ||
def __setitem__(self, key, value): | ||
super().__setitem__(key.lower(), value) | ||
key = key.lower() if isinstance(key, str) else key | ||
super().__setitem__(key, value) | ||
|
||
def __getitem__(self, key): | ||
return super().__getitem__(key.lower()) | ||
key = key.lower() if isinstance(key, str) else key | ||
return super().__getitem__(key) | ||
|
||
def get(self, key, default=None): | ||
return super().get(key.lower(), default) | ||
key = key.lower() if isinstance(key, str) else key | ||
return super().get(key, default) | ||
|
||
def __contains__(self, key): | ||
return super().__contains__(key.lower()) | ||
key = key.lower() if isinstance(key, str) else key | ||
return super().__contains__(key) | ||
|
||
|
||
def strip_inline_comments(source, comment_char='!', str_delim='"\''): | ||
|
Oops, something went wrong.
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.
Could probably be stricter here and mandate
is
relationship, to establish that there shouldn't be object copies at play?