-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[mlir] Add metadata to Diagnostic. #99398
[mlir] Add metadata to Diagnostic. #99398
Conversation
…eic/add-diagnostic-metadata
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: weiwei chen (weiweichen) ChangesAdd metadata to Diagnostic so that we can do some filtering downstream. Full diff: https://github.com/llvm/llvm-project/pull/99398.diff 1 Files Affected:
diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h
index bb2e1bb183e9b..1ef902ae5439c 100644
--- a/mlir/include/mlir/IR/Diagnostics.h
+++ b/mlir/include/mlir/IR/Diagnostics.h
@@ -271,6 +271,9 @@ class Diagnostic {
return failure();
}
+ /// Returns the current list of diagnostic metadata.
+ SmallVector<DiagnosticArgument, 1>& getMetaData() { return metadata; }
+
private:
Diagnostic(const Diagnostic &rhs) = delete;
Diagnostic &operator=(const Diagnostic &rhs) = delete;
@@ -290,6 +293,9 @@ class Diagnostic {
/// A list of attached notes.
NoteVector notes;
+
+ /// A list of metadata attached to this Diagnostic.
+ SmallVector<DiagnosticArgument, 1> metadata;
};
inline raw_ostream &operator<<(raw_ostream &os, const Diagnostic &diag) {
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
Thanks for the contributions:
- Can you please provide some tests? These also serve as examples for the feature.
- Can you also elaborate on the use-cases in the PR description?
mlir/include/mlir/IR/Diagnostics.h
Outdated
@@ -271,6 +271,9 @@ class Diagnostic { | |||
return failure(); | |||
} | |||
|
|||
/// Returns the current list of diagnostic metadata. | |||
SmallVector<DiagnosticArgument, 1>& getMetaData() { return metadata; } |
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.
SmallVector<DiagnosticArgument, 1>& getMetaData() { return metadata; } | |
SmallVectorImpl<DiagnosticArgument>& getMetaData() { return metadata; } |
mlir/include/mlir/IR/Diagnostics.h
Outdated
@@ -290,6 +293,9 @@ class Diagnostic { | |||
|
|||
/// A list of attached notes. | |||
NoteVector notes; | |||
|
|||
/// A list of metadata attached to this Diagnostic. | |||
SmallVector<DiagnosticArgument, 1> metadata; |
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.
SmallVector<DiagnosticArgument, 1> metadata; | |
SmallVector<DiagnosticArgument, 0> metadata; |
Yep! Added
Yes, updated the PR description with a bit details on the downstream use case we have that needs this upstream change. Thank you very much for the feedback! |
@joker-eph could you please take a look to see if there should be more changes with this PR? Thank you! |
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.
Thanks for adding the test!
Is there some documentation to update as well?
|
||
// CHECK-LABEL: Test 'test' | ||
// CHECK-NEXT: 8:3: error: test diagnostic metadata | ||
// CHECK-NOT: 13:3: error: test diagnostic metadata |
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.
Instead of using FileCheck, can't we use the --verify-diagnostic
mode of mlir-opt?
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.
Ah, yes, I was following what diagnostic-handler-filter.mlir
is done for checking the diagnostics.
-verify-diagnostic
is a much better way, updated the test.
…eic/add-diagnostic-metadata
…eic/add-diagnostic-metadata
Yep, added something to |
Summary: Add metadata to Diagnostic. Motivation: we have a use case where we want to do some filtering in our customized Diagnostic Handler based on some customized info that is not `location` or `severity` or `diagnostic arguments` that are member variables of `Diagnostic`. Specifically, we want to add a unique ID to the `Diagnostic` for the handler to filter in a compiler pass that emits errors in async tasks with multithreading and the diagnostic handling is associated to the task. This patch adds a field of `metadata` to `mlir::Diagnostics` as a general solution. `metadata` is of type `SmallVector<DiagnosticArgument, 0>` to save memory size and reuse existing `DiagnosticArgument` for metadata type. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250607
Add metadata to Diagnostic.
Motivation: we have a use case where we want to do some filtering in our customized Diagnostic Handler based on some customized info that is not
location
orseverity
ordiagnostic arguments
that are member variables ofDiagnostic
. Specifically, we want to add a unique ID to theDiagnostic
for the handler to filter in a compiler pass that emits errors in async tasks with multithreading and the diagnostic handling is associated to the task.This patch adds a field of
metadata
tomlir::Diagnostics
as a general solution.metadata
is of typeSmallVector<DiagnosticArgument, 0>
to save memory size and reuse existingDiagnosticArgument
for metadata type.