Repository navigation
Reset sticky diagnostic state after a rejected InstantiateTemplate - #1070
conrade-ctc wants to merge 1 commit into
Conversation
| // the incremental parser performs on a real parse failure). | ||
| clang::DiagnosticsEngine& Diags = S.getDiagnostics(); | ||
| bool HadErrors = Diags.hasErrorOccurred(); | ||
| Decl* Result = InstantiateTemplate(TmplD, TemplateArgs, S, instantiate_body); |
There was a problem hiding this comment.
Can can insert a diagnostic trap object -- we have that elsewhere in the codebase.
There was a problem hiding this comment.
indeed, thanks for pointing that out, update forth-coming!
There was a problem hiding this comment.
Done — the manual snapshot is now a DiagnosticErrorTrap-based RAII (StickyDiagnosticResetRAII): the trap detects errors introduced during the instantiation, and on scope exit the guard restores a clean state with the same Diags.Reset(/*soft=*/true) + client clear() cleanup IncrementalParser performs on a real parse failure. I left InstantiateFunctionDefinition's inline copy of this cleanup untouched — it could migrate to the same guard, but #849 is already touching that spot and I didn't want the two PRs to collide.
There was a problem hiding this comment.
Can you rebase on top of the new master?
There was a problem hiding this comment.
Rebased on top of main.
There was a problem hiding this comment.
#849 is in now, so this uses compat::DiagnosticsEngineRAII instead of a new class. Rebased on current main.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1070 +/- ##
==========================================
- Coverage 88.86% 88.71% -0.15%
==========================================
Files 24 24
Lines 7014 6674 -340
==========================================
- Hits 6233 5921 -312
+ Misses 781 753 -28
... and 19 files with indirect coverage changes
🚀 New features to boost your workflow:
|
|
clang-tidy review says "All clean, LGTM! 👍" |
b6fee6d to
4fd6208
Compare
|
clang-tidy review says "All clean, LGTM! 👍" |
52dfd1f to
cf958fd
Compare
The rejection (e.g. a type argument for a non-type parameter) emits its error diagnostic outside any incremental parse, and DiagnosticsEngine's ErrorOccurred flag is sticky: the next IncrementalParser::Parse reported the stale flag as its own failure and then soft-reset it, poisoning exactly one parse. Contain the rejection with a DiagnosticErrorTrap-based RAII that restores a clean diagnostic state when the instantiation introduced errors - the same cleanup IncrementalParser performs on a real parse failure and InstantiateFunctionDefinition performs inline. Content matches compiler-research#1070. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
ef658ae to
6b74070
Compare
The rejection (e.g. a type argument for a non-type parameter) emits its error diagnostic outside any incremental parse, and DiagnosticsEngine's ErrorOccurred flag is sticky: the next IncrementalParser::Parse reported the stale flag as its own failure and then soft-reset it, poisoning exactly one parse. Contain the rejection with a DiagnosticErrorTrap-based RAII that restores a clean diagnostic state when the instantiation introduced errors - the same cleanup IncrementalParser performs on a real parse failure and InstantiateFunctionDefinition performs inline. Content matches compiler-research#1070. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
The rejection (e.g. a type argument for a non-type parameter) emits its error diagnostic outside any incremental parse, and DiagnosticsEngine's ErrorOccurred flag is sticky: the next IncrementalParser::Parse reported the stale flag as its own failure and then soft-reset it, poisoning exactly one parse. Contain the rejection with a DiagnosticErrorTrap-based RAII that restores a clean diagnostic state when the instantiation introduced errors - the same cleanup IncrementalParser performs on a real parse failure and InstantiateFunctionDefinition performs inline. Content matches compiler-research#1070. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
6b74070 to
79b411a
Compare
|
clang-tidy review says "All clean, LGTM! 👍" |
The rejection (e.g. a type argument for a non-type parameter) emits its error diagnostic outside any incremental parse, and DiagnosticsEngine's ErrorOccurred flag is sticky: the next IncrementalParser::Parse reported the stale flag as its own failure and then soft-reset it, poisoning exactly one parse. Contain the rejection with a DiagnosticErrorTrap-based RAII that restores a clean diagnostic state when the instantiation introduced errors - the same cleanup IncrementalParser performs on a real parse failure and InstantiateFunctionDefinition performs inline. Content matches compiler-research#1070. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
A rejected instantiation emits its error outside any input. The error flag stays set, and the next input fails. Use compat::DiagnosticsEngineRAII to soft-reset the engine, as IncrementalParser does after a failed parse. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
79b411a to
12a664f
Compare
|
clang-tidy review says "All clean, LGTM! 👍" |
Description
A rejected
Cpp::InstantiateTemplate(e.g. a type argument supplied for a non-type template parameter) emits its error diagnostic outside any incremental parse, andDiagnosticsEngine'sErrorOccurredflag is sticky. The nextIncrementalParser::Parsesees the stale flag after a perfectly good parse, reports "Parsing failed.", and soft-resets the engine — so exactly one subsequentCpp::Declare/Processfails spuriously. Downstream (cppyy), one rejected template subscript makes the nextcppyy.include/cppyy.cppdefreport failure while actually loading the code, which can silently corrupt fail-soft feature probes.Per review,
compat::DiagnosticsEngineRAII(from #849) now guards the instantiation. On scope exit, it soft-resets the engine if an error occurred, asIncrementalParserdoes after a failed parse. The diagnostic text still prints.Type of change
Testing
New
ScopeReflection_RejectedInstantiationDoesNotPoisonNextParse: a rejected instantiation followed by twoCpp::Declarecalls, both of which must succeed. Fails before the fix (the first Declare reports failure), passes after.Checklist
🤖 Done with the help of Claude Code (Fable 5, human in the loop)