Skip to content

Commit aec0ce1

Browse files
committed
Remove all the unnnecessary diagnostics stuff
1 parent 6881b33 commit aec0ce1

File tree

3 files changed

+11
-135
lines changed

3 files changed

+11
-135
lines changed

mlir/include/mlir/Query/Matcher/Diagnostics.h

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,6 @@ class Diagnostics {
7575
std::vector<std::string> *out;
7676
};
7777

78-
// Context for constructing a matcher or parsing its argument.
79-
struct Context {
80-
enum ConstructMatcherEnum { ConstructMatcher };
81-
Context(ConstructMatcherEnum, Diagnostics *error,
82-
llvm::StringRef matcherName, SourceRange matcherRange);
83-
enum MatcherArgEnum { MatcherArg };
84-
Context(MatcherArgEnum, Diagnostics *error, llvm::StringRef matcherName,
85-
SourceRange matcherRange, int argNumber);
86-
~Context();
87-
88-
private:
89-
Diagnostics *const error;
90-
};
91-
9278
// Add an error message with the specified range and error type.
9379
// Returns an ArgStream object to allow constructing the error message using
9480
// the << operator.
@@ -97,30 +83,9 @@ class Diagnostics {
9783
// Print all error messages to the specified output stream.
9884
void print(llvm::raw_ostream &OS) const;
9985

100-
// Print the full error messages, including the context information, to the
101-
// specified output stream.
102-
void printFull(llvm::raw_ostream &OS) const;
103-
10486
private:
105-
// Parser context types.
106-
enum class ContextType { MatcherArg, MatcherConstruct };
107-
108-
// Context for managing overloaded matcher construction.
109-
struct OverloadContext {
110-
// Construct an overload context with the given error.
111-
OverloadContext(Diagnostics *error);
112-
~OverloadContext();
113-
// Revert all errors that occurred within this context.
114-
void revertErrors();
115-
116-
private:
117-
Diagnostics *const error;
118-
unsigned beginIndex{};
119-
};
120-
12187
// Information stored for one frame of the context.
12288
struct ContextFrame {
123-
ContextType type;
12489
SourceRange range;
12590
std::vector<std::string> args;
12691
};
@@ -139,21 +104,11 @@ class Diagnostics {
139104
// Get an array reference to the error contents.
140105
llvm::ArrayRef<ErrorContent> errors() const { return errorValues; }
141106

142-
llvm::StringRef contextTypeToFormatString(ContextType type) const;
143-
144-
void printContextFrameToStream(const ContextFrame &frame,
145-
llvm::raw_ostream &OS) const;
146-
147-
void printMessageToStream(const ErrorContent::Message &message,
148-
const llvm::Twine Prefix,
149-
llvm::raw_ostream &OS) const;
150-
151-
void printErrorContentToStream(const ErrorContent &content,
152-
llvm::raw_ostream &OS) const;
107+
void printMessage(const ErrorContent::Message &message,
108+
const llvm::Twine Prefix, llvm::raw_ostream &OS) const;
153109

154-
// Push a new context frame onto the context stack with the specified type and
155-
// range.
156-
ArgStream pushContextFrame(ContextType type, SourceRange range);
110+
void printErrorContent(const ErrorContent &content,
111+
llvm::raw_ostream &OS) const;
157112

158113
std::vector<ContextFrame> contextStack;
159114
std::vector<ErrorContent> errorValues;

mlir/lib/Query/Matcher/Diagnostics.cpp

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,6 @@
1010

1111
namespace mlir::query::matcher {
1212

13-
Diagnostics::ArgStream Diagnostics::pushContextFrame(ContextType type,
14-
SourceRange range) {
15-
contextStack.emplace_back();
16-
ContextFrame &data = contextStack.back();
17-
data.type = type;
18-
data.range = range;
19-
return ArgStream(&data.args);
20-
}
21-
22-
Diagnostics::Context::Context(ConstructMatcherEnum, Diagnostics *error,
23-
llvm::StringRef matcherName,
24-
SourceRange matcherRange)
25-
: error(error) {
26-
error->pushContextFrame(ContextType::MatcherConstruct, matcherRange)
27-
<< matcherName;
28-
}
29-
30-
Diagnostics::Context::Context(MatcherArgEnum, Diagnostics *error,
31-
llvm::StringRef matcherName,
32-
SourceRange matcherRange, int argnumber)
33-
: error(error) {
34-
error->pushContextFrame(ContextType::MatcherArg, matcherRange)
35-
<< argnumber << matcherName;
36-
}
37-
38-
Diagnostics::Context::~Context() { error->contextStack.pop_back(); }
39-
40-
Diagnostics::OverloadContext::OverloadContext(Diagnostics *error)
41-
: error(error), beginIndex(error->errorValues.size()) {}
42-
43-
Diagnostics::OverloadContext::~OverloadContext() {
44-
// Merge all errors that happened while in this context.
45-
if (beginIndex < error->errorValues.size()) {
46-
Diagnostics::ErrorContent &dest = error->errorValues[beginIndex];
47-
for (size_t i = beginIndex + 1, e = error->errorValues.size(); i < e; ++i) {
48-
dest.messages.push_back(error->errorValues[i].messages[0]);
49-
}
50-
error->errorValues.resize(beginIndex + 1);
51-
}
52-
}
53-
54-
void Diagnostics::OverloadContext::revertErrors() {
55-
// Revert the errors.
56-
error->errorValues.resize(beginIndex);
57-
}
58-
5913
Diagnostics::ArgStream &
6014
Diagnostics::ArgStream::operator<<(const llvm::Twine &arg) {
6115
out->push_back(arg.str());
@@ -73,17 +27,6 @@ Diagnostics::ArgStream Diagnostics::addError(SourceRange range,
7327
return ArgStream(&last.messages.back().args);
7428
}
7529

76-
llvm::StringRef
77-
Diagnostics::contextTypeToFormatString(Diagnostics::ContextType type) const {
78-
switch (type) {
79-
case Diagnostics::ContextType::MatcherConstruct:
80-
return "Error building matcher $0.";
81-
case Diagnostics::ContextType::MatcherArg:
82-
return "Error parsing argument $0 for matcher $1.";
83-
}
84-
llvm_unreachable("Unknown ContextType value.");
85-
}
86-
8730
static llvm::StringRef errorTypeToFormatString(Diagnostics::ErrorType type) {
8831
switch (type) {
8932
case Diagnostics::ET_RegistryMatcherNotFound:
@@ -151,30 +94,24 @@ static void maybeAddLineAndColumn(SourceRange range, llvm::raw_ostream &OS) {
15194
}
15295
}
15396

154-
void Diagnostics::printContextFrameToStream(
155-
const Diagnostics::ContextFrame &frame, llvm::raw_ostream &OS) const {
156-
maybeAddLineAndColumn(frame.range, OS);
157-
formatErrorString(contextTypeToFormatString(frame.type), frame.args, OS);
158-
}
159-
160-
void Diagnostics::printMessageToStream(
97+
void Diagnostics::printMessage(
16198
const Diagnostics::ErrorContent::Message &message, const llvm::Twine Prefix,
16299
llvm::raw_ostream &OS) const {
163100
maybeAddLineAndColumn(message.range, OS);
164101
OS << Prefix;
165102
formatErrorString(errorTypeToFormatString(message.type), message.args, OS);
166103
}
167104

168-
void Diagnostics::printErrorContentToStream(
169-
const Diagnostics::ErrorContent &content, llvm::raw_ostream &OS) const {
105+
void Diagnostics::printErrorContent(const Diagnostics::ErrorContent &content,
106+
llvm::raw_ostream &OS) const {
170107
if (content.messages.size() == 1) {
171-
printMessageToStream(content.messages[0], "", OS);
108+
printMessage(content.messages[0], "", OS);
172109
} else {
173110
for (size_t i = 0, e = content.messages.size(); i != e; ++i) {
174111
if (i != 0)
175112
OS << "\n";
176-
printMessageToStream(content.messages[i],
177-
"Candidate " + llvm::Twine(i + 1) + ": ", OS);
113+
printMessage(content.messages[i],
114+
"Candidate " + llvm::Twine(i + 1) + ": ", OS);
178115
}
179116
}
180117
}
@@ -183,19 +120,7 @@ void Diagnostics::print(llvm::raw_ostream &OS) const {
183120
for (const ErrorContent &error : errorValues) {
184121
if (&error != &errorValues.front())
185122
OS << "\n";
186-
printErrorContentToStream(error, OS);
187-
}
188-
}
189-
190-
void Diagnostics::printFull(llvm::raw_ostream &OS) const {
191-
for (const ErrorContent &error : errorValues) {
192-
if (&error != &errorValues.front())
193-
OS << "\n";
194-
for (const ContextFrame &frame : error.contextStack) {
195-
printContextFrameToStream(frame, OS);
196-
OS << "\n";
197-
}
198-
printErrorContentToStream(error, OS);
123+
printErrorContent(error, OS);
199124
}
200125
}
201126

mlir/lib/Query/Matcher/Parser.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ bool Parser::parseMatcherArgs(std::vector<ParserValue> &args, MatcherCtor ctor,
339339
}
340340
}
341341

342-
Diagnostics::Context ctx(Diagnostics::Context::MatcherArg, error,
343-
nameToken.text, nameToken.range, args.size() + 1);
344342
ParserValue argValue;
345343
tokenizer->skipNewlines();
346344

@@ -388,8 +386,6 @@ bool Parser::parseMatcherExpressionImpl(const TokenInfo &nameToken,
388386
if (!ctor)
389387
return false;
390388
// Merge the start and end infos.
391-
Diagnostics::Context ctx(Diagnostics::Context::ConstructMatcher, error,
392-
nameToken.text, nameToken.range);
393389
SourceRange matcherRange = nameToken.range;
394390
matcherRange.end = endToken.range.end;
395391
VariantMatcher result =

0 commit comments

Comments
 (0)