Skip to content

Commit 4ed3665

Browse files
committed
[Diagnostics] Provide anchors on demand instead of storing in FailureDiagnostic
This decouples `FailureDiagnostic` from expression.
1 parent ec9afec commit 4ed3665

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool FailureDiagnostic::diagnoseAsNote() {
5050
return false;
5151
}
5252

53-
Expr *FailureDiagnostic::computeAnchor() const {
53+
Expr *FailureDiagnostic::getAnchor() const {
5454
auto &cs = getConstraintSystem();
5555

5656
auto *locator = getLocator();

lib/Sema/CSDiagnostics.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@ class FailureDiagnostic {
4141
const Solution &S;
4242
ConstraintLocator *Locator;
4343

44-
/// The original anchor before any simplification.
45-
Expr *RawAnchor;
46-
/// Simplified anchor associated with the given locator.
47-
Expr *Anchor;
48-
4944
public:
5045
FailureDiagnostic(const Solution &solution, ConstraintLocator *locator)
51-
: S(solution), Locator(locator), RawAnchor(locator->getAnchor()),
52-
Anchor(computeAnchor()) {}
46+
: S(solution), Locator(locator) {}
5347

5448
FailureDiagnostic(const Solution &solution, Expr *anchor)
5549
: FailureDiagnostic(solution, solution.getConstraintLocator(anchor)) {}
@@ -83,9 +77,9 @@ class FailureDiagnostic {
8377
/// e.g. ambiguity error.
8478
virtual bool diagnoseAsNote();
8579

86-
Expr *getRawAnchor() const { return RawAnchor; }
80+
Expr *getRawAnchor() const { return Locator->getAnchor(); }
8781

88-
virtual Expr *getAnchor() const { return Anchor; }
82+
virtual Expr *getAnchor() const;
8983

9084
ConstraintLocator *getLocator() const { return Locator; }
9185

@@ -201,10 +195,6 @@ class FailureDiagnostic {
201195
Type type,
202196
llvm::function_ref<void(GenericTypeParamType *, Type)> substitution =
203197
[](GenericTypeParamType *, Type) {});
204-
205-
private:
206-
/// Compute anchor expression associated with current diagnostic.
207-
Expr *computeAnchor() const;
208198
};
209199

210200
/// Base class for all of the diagnostics related to generic requirement

0 commit comments

Comments
 (0)