Skip to content

Commit 86d56fd

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents dc0e9a6 + 80f4588 commit 86d56fd

File tree

7 files changed

+62
-46
lines changed

7 files changed

+62
-46
lines changed

include/swift/AST/Expr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
447447
return const_cast<Expr *>(this)->getValueProvidingExpr();
448448
}
449449

450+
/// Find the original type of a value, looking through various implicit
451+
/// conversions.
452+
Type findOriginalType() const;
453+
450454
/// If this is a reference to an operator written as a member of a type (or
451455
/// extension thereof), return the underlying operator reference.
452456
DeclRefExpr *getMemberOperatorRef();

include/swift/SIL/SILType.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,9 @@ class SILType {
873873

874874
bool isMarkedAsImmortal() const;
875875

876+
ProtocolConformanceRef conformsToProtocol(SILFunction *fn,
877+
ProtocolDecl *protocol) const;
878+
876879
//
877880
// Accessors for types used in SIL instructions:
878881
//

lib/AST/Expr.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,3 +2789,28 @@ FrontendStatsTracer::getTraceFormatter<const Expr *>() {
27892789
return &TF;
27902790
}
27912791

2792+
Type Expr::findOriginalType() const {
2793+
auto *expr = this;
2794+
do {
2795+
expr = expr->getSemanticsProvidingExpr();
2796+
2797+
if (auto inout = dyn_cast<InOutExpr>(expr)) {
2798+
expr = inout->getSubExpr();
2799+
continue;
2800+
}
2801+
2802+
if (auto ice = dyn_cast<ImplicitConversionExpr>(expr)) {
2803+
expr = ice->getSubExpr();
2804+
continue;
2805+
}
2806+
2807+
if (auto open = dyn_cast<OpenExistentialExpr>(expr)) {
2808+
expr = open->getSubExpr();
2809+
continue;
2810+
}
2811+
2812+
break;
2813+
} while (true);
2814+
2815+
return expr->getType()->getRValueType();
2816+
}

lib/SIL/IR/SILType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,3 +1211,8 @@ SILType SILType::removingMoveOnlyWrapperToBoxedType(const SILFunction *fn) {
12111211
boxTy->getSubstitutions());
12121212
return SILType::getPrimitiveObjectType(newBoxType);
12131213
}
1214+
1215+
ProtocolConformanceRef
1216+
SILType::conformsToProtocol(SILFunction *fn, ProtocolDecl *protocol) const {
1217+
return fn->getParentModule()->conformsToProtocol(getASTType(), protocol);
1218+
}

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
#include "../../Sema/TypeCheckConcurrency.h"
2-
#include "../../Sema/TypeChecker.h"
1+
//===--- SendNonSendable.cpp ----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
313
#include "swift/AST/DiagnosticsSIL.h"
414
#include "swift/AST/Expr.h"
515
#include "swift/AST/Type.h"
@@ -256,18 +266,17 @@ class PartitionOpTranslator {
256266
switch (type.getASTType()->getKind()) {
257267
case TypeKind::BuiltinNativeObject:
258268
case TypeKind::BuiltinRawPointer:
259-
// these are very unsafe... definitely not Sendable
269+
// These are very unsafe... definitely not Sendable.
260270
return true;
261271
default:
262-
// consider caching this if it's a performance bottleneck
263-
return TypeChecker::conformsToProtocol(
264-
type.getASTType(), sendableProtocol, function->getParentModule())
272+
// Consider caching this if it's a performance bottleneck.
273+
return type.conformsToProtocol(function, sendableProtocol)
265274
.hasMissingConformance(function->getParentModule());
266275
}
267276
}
268277

269-
// used to statefully track the instruction currently being translated,
270-
// for insertion into generated PartitionOps
278+
// Used to statefully track the instruction currently being translated, for
279+
// insertion into generated PartitionOps.
271280
SILInstruction *currentInstruction;
272281

273282
// ===========================================================================
@@ -1586,12 +1595,13 @@ class PartitionAnalysis {
15861595
if (!argExpr)
15871596
assert(false && "sourceExpr should be populated for ApplyExpr consumptions");
15881597

1589-
function->getASTContext().Diags.diagnose(
1590-
argExpr->getLoc(), diag::call_site_consumption_yields_race,
1591-
findOriginalValueType(argExpr),
1592-
isolationCrossing.value().getCallerIsolation(),
1593-
isolationCrossing.value().getCalleeIsolation(),
1594-
numDisplayed, numDisplayed != 1, numHidden > 0, numHidden)
1598+
function->getASTContext()
1599+
.Diags
1600+
.diagnose(argExpr->getLoc(), diag::call_site_consumption_yields_race,
1601+
argExpr->findOriginalType(),
1602+
isolationCrossing.value().getCallerIsolation(),
1603+
isolationCrossing.value().getCalleeIsolation(), numDisplayed,
1604+
numDisplayed != 1, numHidden > 0, numHidden)
15951605
.highlight(argExpr->getSourceRange());
15961606
return true;
15971607
}

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,33 +1849,6 @@ static void noteGlobalActorOnContext(DeclContext *dc, Type globalActor) {
18491849
}
18501850
}
18511851

1852-
/// Find the original type of a value, looking through various implicit
1853-
/// conversions.
1854-
Type swift::findOriginalValueType(Expr *expr) {
1855-
do {
1856-
expr = expr->getSemanticsProvidingExpr();
1857-
1858-
if (auto inout = dyn_cast<InOutExpr>(expr)) {
1859-
expr = inout->getSubExpr();
1860-
continue;
1861-
}
1862-
1863-
if (auto ice = dyn_cast<ImplicitConversionExpr>(expr)) {
1864-
expr = ice->getSubExpr();
1865-
continue;
1866-
}
1867-
1868-
if (auto open = dyn_cast<OpenExistentialExpr>(expr)) {
1869-
expr = open->getSubExpr();
1870-
continue;
1871-
}
1872-
1873-
break;
1874-
} while (true);
1875-
1876-
return expr->getType()->getRValueType();
1877-
}
1878-
18791852
bool swift::diagnoseApplyArgSendability(ApplyExpr *apply, const DeclContext *declContext) {
18801853
auto isolationCrossing = apply->getIsolationCrossing();
18811854
if (!isolationCrossing.has_value())
@@ -1916,7 +1889,7 @@ bool swift::diagnoseApplyArgSendability(ApplyExpr *apply, const DeclContext *dec
19161889
// Determine the type of the argument, ignoring any implicit
19171890
// conversions that could have stripped sendability.
19181891
if (Expr *argExpr = arg.getExpr()) {
1919-
argType = findOriginalValueType(argExpr);
1892+
argType = argExpr->findOriginalType();
19201893
}
19211894
}
19221895

lib/Sema/TypeCheckConcurrency.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,6 @@ struct SendableCheckContext {
366366
bool isExplicitSendableConformance() const;
367367
};
368368

369-
/// Find the original type of a value, looking through various implicit
370-
/// conversions.
371-
Type findOriginalValueType(Expr *expr);
372-
373369
/// Diagnose any non-Sendable types that occur within the given type, using
374370
/// the given diagnostic.
375371
///

0 commit comments

Comments
 (0)