@@ -579,6 +579,7 @@ class EffectsHandlingWalker : public ASTWalker {
579
579
recurse = asImpl ().checkDeclRef (declRef,
580
580
declRef->getDeclRef (),
581
581
declRef->getLoc (),
582
+ /* isEvaluated=*/ true ,
582
583
declRef->isImplicitlyAsync ().has_value (),
583
584
declRef->isImplicitlyThrows ());
584
585
} else if (auto interpolated = dyn_cast<InterpolatedStringLiteralExpr>(E)) {
@@ -593,18 +594,22 @@ class EffectsHandlingWalker : public ASTWalker {
593
594
recurse = asImpl ().checkWithConformances (E, EE->getConformances ());
594
595
} else if (auto *OCD = dyn_cast<OtherConstructorDeclRefExpr>(E)) {
595
596
recurse = asImpl ().checkDeclRef (OCD, OCD->getDeclRef (), OCD->getLoc (),
597
+ /* isEvaluated=*/ true ,
596
598
/* isImplicitlyAsync=*/ false ,
597
599
/* isImplicitlyThrows=*/ false );
598
600
} else if (auto *ME = dyn_cast<MacroExpansionExpr>(E)) {
599
601
recurse = asImpl ().checkDeclRef (ME, ME->getMacroRef (), ME->getLoc (),
602
+ /* isEvaluated=*/ false ,
600
603
/* isImplicitlyAsync=*/ false ,
601
604
/* isImplicitlyThrows=*/ false );
602
605
} else if (auto *LE = dyn_cast<LiteralExpr>(E)) {
603
606
recurse = asImpl ().checkDeclRef (LE, LE->getInitializer (), LE->getLoc (),
607
+ /* isEvaluated=*/ false ,
604
608
/* isImplicitlyAsync=*/ false ,
605
609
/* isImplicitlyThrows=*/ false );
606
610
} else if (auto *CE = dyn_cast<CollectionExpr>(E)) {
607
611
recurse = asImpl ().checkDeclRef (CE, CE->getInitializer (), CE->getLoc (),
612
+ /* isEvaluated=*/ false ,
608
613
/* isImplicitlyAsync=*/ false ,
609
614
/* isImplicitlyThrows=*/ false );
610
615
} else if (auto ECE = dyn_cast<ExplicitCastExpr>(E)) {
@@ -620,6 +625,7 @@ class EffectsHandlingWalker : public ASTWalker {
620
625
case KeyPathExpr::Component::Kind::Subscript: {
621
626
(void )asImpl ().checkDeclRef (KPE, component.getDeclRef (),
622
627
component.getLoc (),
628
+ /* isEvaluated=*/ false ,
623
629
/* isImplicitlyAsync=*/ false ,
624
630
/* isImplicitlyThrows=*/ false );
625
631
break ;
@@ -1188,11 +1194,13 @@ class Classification {
1188
1194
// / "unsafe" uses.
1189
1195
static Classification forType (Type type, SourceLoc loc) {
1190
1196
Classification result;
1191
- diagnoseUnsafeType (type->getASTContext (), loc, type, [&](Type unsafeType) {
1192
- result.recordUnsafeUse (
1193
- UnsafeUse::forReferenceToUnsafe (
1194
- nullptr , /* isCall=*/ false , unsafeType, loc));
1195
- });
1197
+ if (type) {
1198
+ diagnoseUnsafeType (type->getASTContext (), loc, type, [&](Type unsafeType) {
1199
+ result.recordUnsafeUse (
1200
+ UnsafeUse::forReferenceToUnsafe (
1201
+ nullptr , /* isCall=*/ false , unsafeType, loc));
1202
+ });
1203
+ }
1196
1204
return result;
1197
1205
}
1198
1206
@@ -1932,12 +1940,16 @@ class ApplyClassifier {
1932
1940
}
1933
1941
ShouldRecurse_t checkDeclRef (Expr *expr,
1934
1942
ConcreteDeclRef declRef, SourceLoc loc,
1943
+ bool isEvaluated,
1935
1944
bool isImplicitlyAsync,
1936
1945
bool isImplicitlyThrows) {
1937
- classification.merge (
1938
- Self.classifyDeclRef (
1939
- declRef, loc, isImplicitlyAsync, isImplicitlyThrows
1940
- ).onlyThrowing ());
1946
+ if (isEvaluated) {
1947
+ classification.merge (
1948
+ Self.classifyDeclRef (
1949
+ declRef, loc, isImplicitlyAsync, isImplicitlyThrows
1950
+ ).onlyThrowing ());
1951
+ }
1952
+
1941
1953
return ShouldRecurse;
1942
1954
}
1943
1955
ShouldRecurse_t checkAsyncLet (PatternBindingDecl *patternBinding) {
@@ -2060,13 +2072,16 @@ class ApplyClassifier {
2060
2072
}
2061
2073
ShouldRecurse_t checkDeclRef (Expr *expr,
2062
2074
ConcreteDeclRef declRef, SourceLoc loc,
2075
+ bool isEvaluated,
2063
2076
bool isImplicitlyAsync,
2064
2077
bool isImplicitlyThrows) {
2065
- if (isImplicitlyAsync) {
2066
- AsyncKind = ConditionalEffectKind::Always;
2067
- } else if (auto getter = getEffectfulGetOnlyAccessor (declRef)) {
2068
- if (cast<AccessorDecl>(getter.getDecl ())->hasAsync ())
2078
+ if (isEvaluated) {
2079
+ if (isImplicitlyAsync) {
2069
2080
AsyncKind = ConditionalEffectKind::Always;
2081
+ } else if (auto getter = getEffectfulGetOnlyAccessor (declRef)) {
2082
+ if (cast<AccessorDecl>(getter.getDecl ())->hasAsync ())
2083
+ AsyncKind = ConditionalEffectKind::Always;
2084
+ }
2070
2085
}
2071
2086
2072
2087
return ShouldRecurse;
@@ -3684,10 +3699,15 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
3684
3699
3685
3700
ShouldRecurse_t checkDeclRef (Expr *expr,
3686
3701
ConcreteDeclRef declRef, SourceLoc loc,
3702
+ bool isEvaluated,
3687
3703
bool isImplicitlyAsync,
3688
3704
bool isImplicitlyThrows) {
3689
3705
if (auto classification = getApplyClassifier ().classifyDeclRef (
3690
3706
declRef, loc, isImplicitlyAsync, isImplicitlyThrows)) {
3707
+ // If we aren't evaluating the reference, we only care about 'unsafe'.
3708
+ if (!isEvaluated)
3709
+ classification = classification.onlyUnsafe ();
3710
+
3691
3711
auto throwDest = checkEffectSite (
3692
3712
expr, classification.hasThrows (), classification);
3693
3713
0 commit comments