@@ -576,7 +576,11 @@ class EffectsHandlingWalker : public ASTWalker {
576
576
} else if (auto lookup = dyn_cast<LookupExpr>(E)) {
577
577
recurse = asImpl ().checkLookup (lookup);
578
578
} else if (auto declRef = dyn_cast<DeclRefExpr>(E)) {
579
- recurse = asImpl ().checkDeclRef (declRef);
579
+ recurse = asImpl ().checkDeclRef (declRef,
580
+ declRef->getDeclRef (),
581
+ declRef->getLoc (),
582
+ declRef->isImplicitlyAsync ().has_value (),
583
+ declRef->isImplicitlyThrows ());
580
584
} else if (auto interpolated = dyn_cast<InterpolatedStringLiteralExpr>(E)) {
581
585
recurse = asImpl ().checkInterpolatedStringLiteral (interpolated);
582
586
} else if (auto macroExpansionExpr = dyn_cast<MacroExpansionExpr>(E)) {
@@ -1363,43 +1367,50 @@ class ApplyClassifier {
1363
1367
return classification;
1364
1368
}
1365
1369
1366
- Classification classifyDeclRef (DeclRefExpr *E) {
1367
- if (!E->getDecl ())
1370
+ Classification classifyDeclRef (ConcreteDeclRef declRef, SourceLoc loc,
1371
+ bool isImplicitlyAsync,
1372
+ bool isImplicitlyThrows) {
1373
+ if (!declRef)
1368
1374
return Classification::forInvalidCode ();
1369
1375
1370
1376
Classification classification;
1371
1377
PotentialEffectReason reason = PotentialEffectReason::forPropertyAccess ();
1372
- ConcreteDeclRef declRef = E->getDeclRef ();
1373
1378
1374
1379
if (auto getter = getEffectfulGetOnlyAccessor (declRef)) {
1375
1380
reason = getKindOfEffectfulProp (declRef);
1376
1381
classification = Classification::forDeclRef (
1377
- getter, ConditionalEffectKind::Always, reason, E-> getLoc () );
1382
+ getter, ConditionalEffectKind::Always, reason, loc );
1378
1383
} else if (isa<VarDecl>(declRef.getDecl ())) {
1379
1384
// Handle async let.
1380
1385
reason = PotentialEffectReason::forAsyncLet ();
1381
1386
classification = Classification::forDeclRef (
1382
- declRef, ConditionalEffectKind::Always, reason, E-> getLoc () );
1387
+ declRef, ConditionalEffectKind::Always, reason, loc );
1383
1388
}
1384
1389
1385
1390
classification.setDowngradeToWarning (
1386
- downgradeAsyncAccessToWarning (E-> getDecl ()));
1391
+ downgradeAsyncAccessToWarning (declRef. getDecl ()));
1387
1392
1388
1393
classification.mergeImplicitEffects (
1389
- E-> getDeclRef () .getDecl ()->getASTContext (),
1390
- E-> isImplicitlyAsync (). has_value (), E-> isImplicitlyThrows () ,
1394
+ declRef .getDecl ()->getASTContext (),
1395
+ isImplicitlyAsync, isImplicitlyThrows,
1391
1396
reason);
1392
1397
1393
1398
if (!classification.hasUnsafe ()) {
1394
1399
classification.merge (
1395
1400
Classification::forDeclRef (
1396
- declRef, ConditionalEffectKind::Always, reason, E-> getLoc () ,
1401
+ declRef, ConditionalEffectKind::Always, reason, loc ,
1397
1402
EffectKind::Unsafe));
1398
1403
}
1399
1404
1400
1405
return classification;
1401
1406
}
1402
1407
1408
+ Classification classifyDeclRef (DeclRefExpr *E) {
1409
+ return classifyDeclRef (
1410
+ E->getDeclRef (), E->getLoc (), E->isImplicitlyAsync ().has_value (),
1411
+ E->isImplicitlyThrows ());
1412
+ }
1413
+
1403
1414
Classification classifyThrow (ThrowStmt *S) {
1404
1415
Expr *thrownValue = S->getSubExpr ();
1405
1416
if (!thrownValue)
@@ -1860,8 +1871,14 @@ class ApplyClassifier {
1860
1871
classification.merge (Self.classifyLookup (E).onlyThrowing ());
1861
1872
return ShouldRecurse;
1862
1873
}
1863
- ShouldRecurse_t checkDeclRef (DeclRefExpr *E) {
1864
- classification.merge (Self.classifyDeclRef (E).onlyThrowing ());
1874
+ ShouldRecurse_t checkDeclRef (Expr *expr,
1875
+ ConcreteDeclRef declRef, SourceLoc loc,
1876
+ bool isImplicitlyAsync,
1877
+ bool isImplicitlyThrows) {
1878
+ classification.merge (
1879
+ Self.classifyDeclRef (
1880
+ declRef, loc, isImplicitlyAsync, isImplicitlyThrows
1881
+ ).onlyThrowing ());
1865
1882
return ShouldNotRecurse;
1866
1883
}
1867
1884
ShouldRecurse_t checkAsyncLet (PatternBindingDecl *patternBinding) {
@@ -1978,10 +1995,13 @@ class ApplyClassifier {
1978
1995
1979
1996
return ShouldRecurse;
1980
1997
}
1981
- ShouldRecurse_t checkDeclRef (DeclRefExpr *E) {
1982
- if (E->isImplicitlyAsync ()) {
1998
+ ShouldRecurse_t checkDeclRef (Expr *expr,
1999
+ ConcreteDeclRef declRef, SourceLoc loc,
2000
+ bool isImplicitlyAsync,
2001
+ bool isImplicitlyThrows) {
2002
+ if (isImplicitlyAsync) {
1983
2003
AsyncKind = ConditionalEffectKind::Always;
1984
- } else if (auto getter = getEffectfulGetOnlyAccessor (E-> getDeclRef () )) {
2004
+ } else if (auto getter = getEffectfulGetOnlyAccessor (declRef )) {
1985
2005
if (cast<AccessorDecl>(getter.getDecl ())->hasAsync ())
1986
2006
AsyncKind = ConditionalEffectKind::Always;
1987
2007
}
@@ -3601,11 +3621,17 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
3601
3621
return ShouldRecurse;
3602
3622
}
3603
3623
3604
- ShouldRecurse_t checkDeclRef (DeclRefExpr *E) {
3605
- if (auto classification = getApplyClassifier ().classifyDeclRef (E)) {
3624
+ ShouldRecurse_t checkDeclRef (Expr *expr,
3625
+ ConcreteDeclRef declRef, SourceLoc loc,
3626
+ bool isImplicitlyAsync,
3627
+ bool isImplicitlyThrows) {
3628
+ if (auto classification = getApplyClassifier ().classifyDeclRef (
3629
+ declRef, loc, isImplicitlyAsync, isImplicitlyThrows)) {
3606
3630
auto throwDest = checkEffectSite (
3607
- E, classification.hasThrows (), classification);
3608
- E->setThrows (throwDest);
3631
+ expr, classification.hasThrows (), classification);
3632
+
3633
+ if (auto declRefExpr = dyn_cast<DeclRefExpr>(expr))
3634
+ declRefExpr->setThrows (throwDest);
3609
3635
}
3610
3636
3611
3637
return ShouldNotRecurse;
0 commit comments