-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] fix references of attributes which are not defined earlier #134364
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
Conversation
@llvm/pr-subscribers-mlir Author: None (tdanyluk) ChangesIf an attribute is not defined earlier in the same file, but just referenced from its dialect directly, then currently not the correct check is being emited. What would it emit for this: Full diff: https://github.com/llvm/llvm-project/pull/134364.diff 1 Files Affected:
diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py
index 749bfa13fe734..f15d0fee0ea11 100755
--- a/mlir/utils/generate-test-checks.py
+++ b/mlir/utils/generate-test-checks.py
@@ -145,10 +145,9 @@ def generate_name(self, source_attribute_name):
return attribute_name
# Get the saved substitution name for the given attribute name. If no name
- # has been generated for the given attribute yet, the source attribute name
- # itself is returned.
+ # has been generated for the given attribute yet, None is returned.
def get_name(self, source_attribute_name):
- return self.map[source_attribute_name] if source_attribute_name in self.map else '?'
+ return self.map[source_attribute_name] if source_attribute_name in self.map else None
# Return the number of SSA results in a line of type
# %0, %1, ... = ...
@@ -227,9 +226,9 @@ def process_attribute_references(line, attribute_namer):
components = ATTR_RE.split(line)
for component in components:
m = ATTR_RE.match(component)
- if m:
- output_line += '#[[' + attribute_namer.get_name(m.group(1)) + ']]'
- output_line += component[len(m.group()):]
+ attribute_name = attribute_namer.get_name(m.group(1)) if m else None
+ if attribute_name:
+ output_line += f'#[[{attribute_name}]]{component[len(m.group()):]}'
else:
output_line += component
return output_line
|
e28309f
to
1c81160
Compare
✅ With the latest revision this PR passed the Python code formatter. |
Is there a way to test this? |
1c81160
to
d2f4c5c
Compare
Fair question, but there are currently no tests for generate-test-checks.py and adding them would probably take too much of my working time. If you just want to try this change, you can make a file (test-input.txt):
Earlier version would output:
New version would output:
So the case where the attribute is defined locally is unchanged, but the case where it's not is different. |
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.
Nit: self.map.get(source_attribute_name) is an equivalent (lines 151-153, not sure how the UI lost the context)
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.
LG overall
If an attribute is not defined earlier in the same file, but just referenced from its dialect directly, then currently not the correct check is being emited. What would it emit for #toy.shape<[1, 2, 3]>: Earlier: // CHECK: #[['?']]<[1, 2, 3]> Now: // CHECK: #toy.shape<[1, 2, 3]>
fe10b27
to
fc643cc
Compare
…checks.py (#134327) A few additions: - Lines with `{{`: These can show up if serializing non-MLIR info into string attrs `my.attr = {{proto}, {...}}`. String escape the opening `{{`, given that check lines are generated this has no effect on `{{.*}}` etc in generated lines. - File split line: Normally these are skipped because of their indent level, but if using `--starts_from_scope=0` to generate checks for the `module {...} {` line, and since MLIR opt tools emit file split lines by default, some `CHECK: // -----` lines were emit. - (edit removed this, fixed by #134364) AttrAliases: I'm not sure if I'm missing something for the attribute parser to work correctly, but I was getting many `#[[?]]` for all dialect attrs. Only use the attr aliasing if there's a match.
…erate-test-checks.py (#134327) A few additions: - Lines with `{{`: These can show up if serializing non-MLIR info into string attrs `my.attr = {{proto}, {...}}`. String escape the opening `{{`, given that check lines are generated this has no effect on `{{.*}}` etc in generated lines. - File split line: Normally these are skipped because of their indent level, but if using `--starts_from_scope=0` to generate checks for the `module {...} {` line, and since MLIR opt tools emit file split lines by default, some `CHECK: // -----` lines were emit. - (edit removed this, fixed by llvm/llvm-project#134364) AttrAliases: I'm not sure if I'm missing something for the attribute parser to work correctly, but I was getting many `#[[?]]` for all dialect attrs. Only use the attr aliasing if there's a match.
…checks.py (llvm#134327) A few additions: - Lines with `{{`: These can show up if serializing non-MLIR info into string attrs `my.attr = {{proto}, {...}}`. String escape the opening `{{`, given that check lines are generated this has no effect on `{{.*}}` etc in generated lines. - File split line: Normally these are skipped because of their indent level, but if using `--starts_from_scope=0` to generate checks for the `module {...} {` line, and since MLIR opt tools emit file split lines by default, some `CHECK: // -----` lines were emit. - (edit removed this, fixed by llvm#134364) AttrAliases: I'm not sure if I'm missing something for the attribute parser to work correctly, but I was getting many `#[[?]]` for all dialect attrs. Only use the attr aliasing if there's a match.
If an attribute is not defined earlier in the same file, but just referenced from its dialect directly, then currently not the correct check is being emited.
What would it emit for #toy.shape<[1, 2, 3]>:
Earlier:
// CHECK: #[['?']]<[1, 2, 3]>
Now:
// CHECK: #toy.shape<[1, 2, 3]>