@@ -38,36 +38,33 @@ namespace {
38
38
// / attached near the relevant declaration and takes one of the following forms:
39
39
// /
40
40
// / // expected-provides {{ProvidedName}}
41
- // / // expected-private- member {{some.User.member}}
41
+ // / // expected-member {{some.User.member}}
42
42
// /
43
43
// / An expectation contains additional information about the expectation
44
44
// / \c Kind, which matches one of the few kinds of dependency entry that are
45
- // / currently representable in the dependency graph, and an expectation
46
- // / \c Scope which must either be \c private or \c cascading.
45
+ // / currently representable in the dependency graph.
47
46
// /
48
- // / As not all combinations of scopes and kinds makes sense, and to ease the addition of further
49
- // / combinations of the two, the supported set of expectations is given by the following matrix:
47
+ // / As not all combinations of scopes and kinds makes sense, and to ease the
48
+ // / addition of further combinations of the two, the supported set of
49
+ // / expectations is given by the following matrix:
50
50
// /
51
51
#define EXPECTATION_MATRIX \
52
- MATRIX_ENTRY (" expected-no-dependency" , None, Negative) \
53
- MATRIX_ENTRY (" expected-provides" , None, Provides) \
54
- MATRIX_ENTRY (" expected-private-superclass" , Private, Superclass) \
55
- MATRIX_ENTRY (" expected-cascading-superclass" , Cascading, Superclass) \
56
- MATRIX_ENTRY (" expected-private-conformance" , Private, Conformance) \
57
- MATRIX_ENTRY (" expected-cascading-conformance" , Cascading, Conformance) \
58
- MATRIX_ENTRY (" expected-private-member" , Private, Member) \
59
- MATRIX_ENTRY (" expected-cascading-member" , Cascading, Member) \
60
- MATRIX_ENTRY (" expected-private-dynamic-member" , Private, DynamicMember) \
61
- MATRIX_ENTRY (" expected-cascading-dynamic-member" , Cascading, DynamicMember)
52
+ MATRIX_ENTRY (" expected-no-dependency" , Negative) \
53
+ MATRIX_ENTRY (" expected-provides" , Provides) \
54
+ MATRIX_ENTRY (" expected-superclass" , Superclass) \
55
+ MATRIX_ENTRY (" expected-conformance" , Conformance) \
56
+ MATRIX_ENTRY (" expected-member" , Member) \
57
+ MATRIX_ENTRY (" expected-dynamic-member" , DynamicMember) \
62
58
// /
63
- // / To add a new supported combination, update \c Expectation::Kind and
64
- // / \c Expectation::Scope, then define a new \c MATRIX_ENTRY with the following information:
59
+ // / To add a new supported combination, update \c Expectation::Kind
60
+ // / then define a new \c MATRIX_ENTRY with the following information:
65
61
// /
66
- // / MATRIX_ENTRY(<Expectation-Selector-String>, Expectation::Scope, Expectation:: Kind)
62
+ // / MATRIX_ENTRY(<Expectation-Selector-String>, Expectation::Kind)
67
63
// /
68
- // / Where \c <Expectation-Selector-String> matches the grammar for an expectation. The
69
- // / verifier's parsing routines use this matrix to automatically keep the parser in harmony with the
70
- // / internal representation of the expectation.
64
+ // / Where \c <Expectation-Selector-String> matches the grammar for an
65
+ // / expectation. The verifier's parsing routines use this matrix to
66
+ // / automatically keep the parser in harmony with the internal representation of
67
+ // / the expectation.
71
68
struct Expectation {
72
69
public:
73
70
enum class Kind : uint8_t {
@@ -80,41 +77,25 @@ struct Expectation {
80
77
DynamicMember,
81
78
};
82
79
83
- enum class Scope : uint8_t {
84
- // / There is no scope information associated with this expectation.
85
- // /
86
- // / This is currently only true of negative expectations and provides expectations.
87
- None,
88
- // / The dependency does not cascade.
89
- Private,
90
- // / The dependency cascades.
91
- Cascading,
92
- };
93
-
94
80
// / The full range of the "expected-foo {{}}".
95
81
const char *ExpectedStart, *ExpectedEnd = nullptr ;
96
82
97
83
// / Additional information about the expectation.
98
84
struct {
99
85
Expectation::Kind Kind;
100
- Expectation::Scope Scope;
101
86
} Info;
102
87
103
88
// / The raw input buffer for the message text, the part in the {{...}}
104
89
StringRef MessageRange;
105
90
106
91
public:
107
92
Expectation (const char *estart, const char *eend, Expectation::Kind k,
108
- Expectation::Scope f, StringRef r)
109
- : ExpectedStart(estart), ExpectedEnd(eend), Info{k, f}, MessageRange(r) {
110
- assert (ExpectedStart <= MessageRange.data () &&
111
- " Message range appears before expected start!" );
112
- assert (MessageRange.data ()+MessageRange.size () <= ExpectedEnd &&
113
- " Message range extends beyond expected end!" );
114
- }
115
-
116
- bool isCascading () const {
117
- return Info.Scope == Expectation::Scope::Cascading;
93
+ StringRef r)
94
+ : ExpectedStart(estart), ExpectedEnd(eend), Info{k}, MessageRange(r) {
95
+ assert (ExpectedStart <= MessageRange.data () &&
96
+ " Message range appears before expected start!" );
97
+ assert (MessageRange.data () + MessageRange.size () <= ExpectedEnd &&
98
+ " Message range extends beyond expected end!" );
118
99
}
119
100
};
120
101
@@ -214,43 +195,27 @@ struct Obligation {
214
195
215
196
private:
216
197
StringRef name;
217
- std::pair< Expectation::Kind, Expectation::Scope> info ;
198
+ Expectation::Kind kind ;
218
199
State state;
219
200
220
201
public:
221
- Obligation (StringRef name, Expectation::Kind k, Expectation::Scope f )
222
- : name(name), info{k, f }, state(State::Owed) {
202
+ Obligation (StringRef name, Expectation::Kind k)
203
+ : name(name), kind{k }, state(State::Owed) {
223
204
assert (k != Expectation::Kind::Negative &&
224
205
" Cannot form negative obligation!" );
225
206
}
226
207
227
- Expectation::Scope getScope () const { return info.second ; }
228
- Expectation::Kind getKind () const { return info.first ; }
208
+ Expectation::Kind getKind () const { return kind; }
229
209
StringRef getName () const { return name; }
230
- bool getCascades () const {
231
- return info.second == Expectation::Scope::Cascading;
232
- }
233
- StringRef describeCascade () const {
234
- switch (info.second ) {
235
- case Expectation::Scope::None:
236
- llvm_unreachable (" Cannot describe obligation with no cascade info" );
237
- case Expectation::Scope::Private:
238
- return " non-cascading" ;
239
- case Expectation::Scope::Cascading:
240
- return " cascading" ;
241
- }
242
- llvm_unreachable (" invalid expectation scope" );
243
- }
244
210
245
211
StringRef renderAsFixit (ASTContext &Ctx) const {
246
212
llvm::StringRef selector =
247
- #define MATRIX_ENTRY (SELECTOR, SCOPE, KIND ) \
248
- if (getKind () == Expectation::Kind::KIND && \
249
- getScope () == Expectation::Scope::SCOPE) { \
250
- return SELECTOR; \
251
- }
213
+ #define MATRIX_ENTRY (SELECTOR, KIND ) \
214
+ if (getKind () == Expectation::Kind::KIND) { \
215
+ return SELECTOR; \
216
+ }
252
217
253
- [this ]() -> StringRef {
218
+ [this ]() -> StringRef {
254
219
EXPECTATION_MATRIX
255
220
return " " ;
256
221
}();
@@ -267,8 +232,7 @@ struct Obligation {
267
232
return FullfillmentToken{};
268
233
}
269
234
FullfillmentToken fail () {
270
- assert (state == State::Owed &&
271
- " Cannot fail an obligation more than once!" );
235
+ assert (state == State::Owed && " Cannot fail an obligation more than once!" );
272
236
state = State::Failed;
273
237
return FullfillmentToken{};
274
238
}
@@ -372,19 +336,17 @@ bool DependencyVerifier::parseExpectations(
372
336
const char *DiagnosticLoc = MatchStart.data ();
373
337
374
338
Expectation::Kind ExpectedKind;
375
- Expectation::Scope ExpectedScope;
376
339
{
377
- #define MATRIX_ENTRY (EXPECTATION_SELECTOR, SCOPE, KIND ) \
340
+ #define MATRIX_ENTRY (EXPECTATION_SELECTOR, KIND ) \
378
341
.StartsWith (EXPECTATION_SELECTOR, [&]() { \
379
342
ExpectedKind = Expectation::Kind::KIND; \
380
- ExpectedScope = Expectation::Scope::SCOPE; \
381
343
MatchStart = MatchStart.substr (strlen (EXPECTATION_SELECTOR)); \
382
344
})
383
345
384
346
// clang-format off
385
- llvm::StringSwitch<llvm::function_ref<void (void )>>{MatchStart}
386
- EXPECTATION_MATRIX
387
- .Default ([]() {})();
347
+ llvm::StringSwitch<llvm::function_ref<void (void )>>{MatchStart}
348
+ EXPECTATION_MATRIX
349
+ .Default ([]() {})();
388
350
// clang-format on
389
351
#undef MATRIX_ENTRY
390
352
}
@@ -412,13 +374,11 @@ bool DependencyVerifier::parseExpectations(
412
374
AfterEnd = AfterEnd.substr (AfterEnd.find_first_not_of (" \t " ));
413
375
const char *ExpectedEnd = AfterEnd.data ();
414
376
415
-
416
377
// Strip out the trailing whitespace.
417
378
while (isspace (ExpectedEnd[-1 ]))
418
379
--ExpectedEnd;
419
380
420
- Expectations.emplace_back (DiagnosticLoc, ExpectedEnd,
421
- ExpectedKind, ExpectedScope,
381
+ Expectations.emplace_back (DiagnosticLoc, ExpectedEnd, ExpectedKind,
422
382
MatchStart.slice (2 , End));
423
383
}
424
384
return false ;
@@ -427,50 +387,37 @@ bool DependencyVerifier::parseExpectations(
427
387
bool DependencyVerifier::constructObligations (const SourceFile *SF,
428
388
ObligationMap &Obligations) {
429
389
auto &Ctx = SF->getASTContext ();
430
- Ctx.evaluator .enumerateReferencesInFile (
431
- SF, [&](const auto &reference) {
432
- const auto isCascadingUse = false ;
433
- using NodeKind = evaluator::DependencyCollector::Reference::Kind;
434
- switch (reference.kind ) {
435
- case NodeKind::Empty:
436
- case NodeKind::Tombstone:
437
- llvm_unreachable (" Cannot enumerate dead dependency!" );
438
-
439
- case NodeKind::PotentialMember: {
440
- auto key = copyQualifiedTypeName (Ctx, reference.subject );
441
- Obligations.insert ({Obligation::Key::forPotentialMember (key),
442
- {" " , Expectation::Kind::PotentialMember,
443
- isCascadingUse ? Expectation::Scope::Cascading
444
- : Expectation::Scope::Private}});
445
- }
446
- break ;
447
- case NodeKind::UsedMember: {
448
- auto demContext = copyQualifiedTypeName (Ctx, reference.subject );
449
- auto name = reference.name .userFacingName ();
450
- auto key = Ctx.AllocateCopy ((demContext + " ." + name).str ());
451
- Obligations.insert ({Obligation::Key::forMember (key),
452
- {key, Expectation::Kind::Member,
453
- isCascadingUse ? Expectation::Scope::Cascading
454
- : Expectation::Scope::Private}});
455
- }
456
- break ;
457
- case NodeKind::Dynamic: {
458
- auto key = Ctx.AllocateCopy (reference.name .userFacingName ());
459
- Obligations.insert ({Obligation::Key::forDynamicMember (key),
460
- {" " , Expectation::Kind::DynamicMember,
461
- isCascadingUse ? Expectation::Scope::Cascading
462
- : Expectation::Scope::Private}});
463
- }
464
- break ;
465
- case NodeKind::TopLevel: {
466
- auto key = Ctx.AllocateCopy (reference.name .userFacingName ());
467
- Obligations.insert ({Obligation::Key::forProvides (key),
468
- {key, Expectation::Kind::Provides,
469
- Expectation::Scope::None}});
470
- }
471
- break ;
472
- }
473
- });
390
+ Ctx.evaluator .enumerateReferencesInFile (SF, [&](const auto &reference) {
391
+ using NodeKind = evaluator::DependencyCollector::Reference::Kind;
392
+ switch (reference.kind ) {
393
+ case NodeKind::Empty:
394
+ case NodeKind::Tombstone:
395
+ llvm_unreachable (" Cannot enumerate dead dependency!" );
396
+
397
+ case NodeKind::PotentialMember: {
398
+ auto key = copyQualifiedTypeName (Ctx, reference.subject );
399
+ Obligations.insert ({Obligation::Key::forPotentialMember (key),
400
+ {" " , Expectation::Kind::PotentialMember}});
401
+ } break ;
402
+ case NodeKind::UsedMember: {
403
+ auto demContext = copyQualifiedTypeName (Ctx, reference.subject );
404
+ auto name = reference.name .userFacingName ();
405
+ auto key = Ctx.AllocateCopy ((demContext + " ." + name).str ());
406
+ Obligations.insert (
407
+ {Obligation::Key::forMember (key), {key, Expectation::Kind::Member}});
408
+ } break ;
409
+ case NodeKind::Dynamic: {
410
+ auto key = Ctx.AllocateCopy (reference.name .userFacingName ());
411
+ Obligations.insert ({Obligation::Key::forDynamicMember (key),
412
+ {" " , Expectation::Kind::DynamicMember}});
413
+ } break ;
414
+ case NodeKind::TopLevel: {
415
+ auto key = Ctx.AllocateCopy (reference.name .userFacingName ());
416
+ Obligations.insert ({Obligation::Key::forProvides (key),
417
+ {key, Expectation::Kind::Provides}});
418
+ } break ;
419
+ }
420
+ });
474
421
475
422
return false ;
476
423
}
@@ -480,7 +427,6 @@ bool DependencyVerifier::verifyObligations(
480
427
ObligationMap &OM, llvm::StringMap<Expectation> &NegativeExpectations) {
481
428
auto &diags = SF->getASTContext ().Diags ;
482
429
for (auto &expectation : ExpectedDependencies) {
483
- const bool wantsCascade = expectation.isCascading ();
484
430
if (expectation.Info .Kind == Expectation::Kind::Negative) {
485
431
// We'll verify negative expectations separately.
486
432
NegativeExpectations.insert ({expectation.MessageRange , expectation});
@@ -490,29 +436,14 @@ bool DependencyVerifier::verifyObligations(
490
436
matchExpectationOrFail (
491
437
OM, expectation,
492
438
[&](Obligation &O) {
493
- const auto haveCascade = O.getCascades ();
494
439
switch (expectation.Info .Kind ) {
495
440
case Expectation::Kind::Negative:
496
441
llvm_unreachable (" Should have been handled above!" );
497
442
case Expectation::Kind::Member:
498
- if (haveCascade != wantsCascade) {
499
- diagnose (diags, expectation.MessageRange .begin (),
500
- diag::dependency_cascading_mismatch, wantsCascade,
501
- haveCascade);
502
- return O.fail ();
503
- } else {
504
- return O.fullfill ();
505
- }
443
+ return O.fullfill ();
506
444
case Expectation::Kind::PotentialMember:
507
445
assert (O.getName ().empty ());
508
- if (haveCascade != wantsCascade) {
509
- diagnose (diags, expectation.MessageRange .begin (),
510
- diag::potential_dependency_cascading_mismatch,
511
- wantsCascade, haveCascade);
512
- return O.fail ();
513
- } else {
514
- return O.fullfill ();
515
- }
446
+ return O.fullfill ();
516
447
case Expectation::Kind::Provides:
517
448
case Expectation::Kind::DynamicMember:
518
449
return O.fullfill ();
@@ -564,13 +495,14 @@ bool DependencyVerifier::diagnoseUnfulfilledObligations(
564
495
case Expectation::Kind::Member:
565
496
case Expectation::Kind::DynamicMember:
566
497
case Expectation::Kind::PotentialMember:
567
- diags.diagnose (Loc, diag::unexpected_dependency, p.describeCascade (),
568
- static_cast <uint8_t >(p.getKind ()), key)
569
- .fixItInsert (Loc, p.renderAsFixit (Ctx));
498
+ diags
499
+ .diagnose (Loc, diag::unexpected_dependency,
500
+ static_cast <uint8_t >(p.getKind ()), key)
501
+ .fixItInsert (Loc, p.renderAsFixit (Ctx));
570
502
break ;
571
503
case Expectation::Kind::Provides:
572
504
diags.diagnose (Loc, diag::unexpected_provided_entity, p.getName ())
573
- .fixItInsert (Loc, p.renderAsFixit (Ctx));
505
+ .fixItInsert (Loc, p.renderAsFixit (Ctx));
574
506
break ;
575
507
}
576
508
});
0 commit comments