Skip to content

Commit c70f493

Browse files
authored
Merge pull request #59825 from DougGregor/preconcurrency-sendable-function-conversion
2 parents 7245f58 + fdd619b commit c70f493

17 files changed

+526
-307
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4553,7 +4553,7 @@ class ApplyExpr : public Expr {
45534553
Bits.ApplyExpr.ShouldApplyDistributedThunk = flag;
45544554
}
45554555

4556-
ValueDecl *getCalledValue() const;
4556+
ValueDecl *getCalledValue(bool skipFunctionConversions = false) const;
45574557

45584558
static bool classof(const Expr *E) {
45594559
return E->getKind() >= ExprKind::First_ApplyExpr &&

include/swift/Sema/ConstraintSystem.h

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,19 @@ struct SelectedOverload {
658658
/// we're referencing a member.
659659
const Type openedFullType;
660660

661+
/// The opened type of the base of the reference to this overload, adjusted
662+
/// for `@preconcurrency` or other contextual type-altering attributes.
663+
const Type adjustedOpenedFullType;
664+
661665
/// The opened type produced by referring to this overload.
662666
const Type openedType;
663667

668+
/// The opened type produced by referring to this overload, adjusted for
669+
/// `@preconcurrency` or other contextual type-altering attributes.
670+
const Type adjustedOpenedType;
671+
664672
/// The type that this overload binds. Note that this may differ from
665-
/// openedType, for example it will include any IUO unwrapping that has taken
673+
/// adjustedOpenedType, for example it will include any IUO unwrapping that has taken
666674
/// place.
667675
const Type boundType;
668676
};
@@ -2515,6 +2523,31 @@ struct GetClosureType {
25152523
Type operator()(const AbstractClosureExpr *expr) const;
25162524
};
25172525

2526+
/// Describes the type produced when referencing a declaration.
2527+
struct DeclReferenceType {
2528+
/// The "opened" type, which is the type of the declaration where any
2529+
/// generic parameters have been replaced with type variables.
2530+
///
2531+
/// The mapping from generic parameters to type variables will have been
2532+
/// recorded by \c recordOpenedTypes when this type is produced.
2533+
Type openedType;
2534+
2535+
/// The opened type, after performing contextual type adjustments such as
2536+
/// removing concurrency-related annotations for a `@preconcurrency`
2537+
/// operation.
2538+
Type adjustedOpenedType;
2539+
2540+
/// The type of the reference, based on the original opened type. This is the
2541+
/// type that the expression used to form the declaration reference would
2542+
/// have if no adjustments had been applied.
2543+
Type referenceType;
2544+
2545+
/// The type of the reference, which is the adjusted opened type after
2546+
/// (e.g.) applying the base of a member access. This is the type of the
2547+
/// expression used to form the declaration reference.
2548+
Type adjustedReferenceType;
2549+
};
2550+
25182551
/// Describes a system of constraints on type variables, the
25192552
/// solution of which assigns concrete types to each of the type variables.
25202553
/// Constraint systems are typically generated given an (untyped) expression.
@@ -4467,10 +4500,11 @@ class ConstraintSystem {
44674500
const OpenedTypeMap &replacements);
44684501

44694502
/// Wrapper over swift::adjustFunctionTypeForConcurrency that passes along
4470-
/// the appropriate closure-type extraction function.
4503+
/// the appropriate closure-type and opening extraction functions.
44714504
AnyFunctionType *adjustFunctionTypeForConcurrency(
44724505
AnyFunctionType *fnType, ValueDecl *decl, DeclContext *dc,
4473-
unsigned numApplies, bool isMainDispatchQueue);
4506+
unsigned numApplies, bool isMainDispatchQueue,
4507+
OpenedTypeMap &replacements);
44744508

44754509
/// Retrieve the type of a reference to the given value declaration.
44764510
///
@@ -4480,9 +4514,8 @@ class ConstraintSystem {
44804514
///
44814515
/// \param decl The declarations whose type is being computed.
44824516
///
4483-
/// \returns a pair containing the full opened type (if applicable) and
4484-
/// opened type of a reference to declaration.
4485-
std::pair<Type, Type> getTypeOfReference(
4517+
/// \returns a description of the type of this declaration reference.
4518+
DeclReferenceType getTypeOfReference(
44864519
ValueDecl *decl,
44874520
FunctionRefKind functionRefKind,
44884521
ConstraintLocatorBuilder locator,
@@ -4530,6 +4563,14 @@ class ConstraintSystem {
45304563
return Type();
45314564
});
45324565

4566+
/// Given the opened type and a pile of information about a member reference,
4567+
/// determine the reference type of the member reference.
4568+
Type getMemberReferenceTypeFromOpenedType(
4569+
Type &openedType, Type baseObjTy, ValueDecl *value, DeclContext *outerDC,
4570+
ConstraintLocator *locator, bool hasAppliedSelf,
4571+
bool isStaticMemberRefOnProtocol, bool isDynamicResult,
4572+
OpenedTypeMap &replacements);
4573+
45334574
/// Retrieve the type of a reference to the given value declaration,
45344575
/// as a member with a base of the given type.
45354576
///
@@ -4540,9 +4581,8 @@ class ConstraintSystem {
45404581
/// \param isDynamicResult Indicates that this declaration was found via
45414582
/// dynamic lookup.
45424583
///
4543-
/// \returns a pair containing the full opened type (which includes the opened
4544-
/// base) and opened type of a reference to this member.
4545-
std::pair<Type, Type> getTypeOfMemberReference(
4584+
/// \returns a description of the type of this declaration reference.
4585+
DeclReferenceType getTypeOfMemberReference(
45464586
Type baseTy, ValueDecl *decl, DeclContext *useDC,
45474587
bool isDynamicResult,
45484588
FunctionRefKind functionRefKind,

lib/AST/Expr.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ DictionaryExpr *DictionaryExpr::create(ASTContext &C, SourceLoc LBracketLoc,
14131413
Ty);
14141414
}
14151415

1416-
static ValueDecl *getCalledValue(Expr *E) {
1416+
static ValueDecl *getCalledValue(Expr *E, bool skipFunctionConversions) {
14171417
if (auto *DRE = dyn_cast<DeclRefExpr>(E))
14181418
return DRE->getDecl();
14191419

@@ -1422,11 +1422,16 @@ static ValueDecl *getCalledValue(Expr *E) {
14221422

14231423
// Look through SelfApplyExpr.
14241424
if (auto *SAE = dyn_cast<SelfApplyExpr>(E))
1425-
return SAE->getCalledValue();
1425+
return SAE->getCalledValue(skipFunctionConversions);
1426+
1427+
if (skipFunctionConversions) {
1428+
if (auto fnConv = dyn_cast<FunctionConversionExpr>(E))
1429+
return getCalledValue(fnConv->getSubExpr(), skipFunctionConversions);
1430+
}
14261431

14271432
Expr *E2 = E->getValueProvidingExpr();
14281433
if (E != E2)
1429-
return getCalledValue(E2);
1434+
return getCalledValue(E2, skipFunctionConversions);
14301435

14311436
return nullptr;
14321437
}
@@ -1468,8 +1473,8 @@ Expr *DefaultArgumentExpr::getCallerSideDefaultExpr() const {
14681473
new (ctx) ErrorExpr(getSourceRange(), getType()));
14691474
}
14701475

1471-
ValueDecl *ApplyExpr::getCalledValue() const {
1472-
return ::getCalledValue(Fn);
1476+
ValueDecl *ApplyExpr::getCalledValue(bool skipFunctionConversions) const {
1477+
return ::getCalledValue(Fn, skipFunctionConversions);
14731478
}
14741479

14751480
SubscriptExpr::SubscriptExpr(Expr *base, ArgumentList *argList,
@@ -1909,6 +1914,8 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19091914
auto maybeUnwrapConversions = [](Expr *expr) {
19101915
if (auto *covariantReturn = dyn_cast<CovariantReturnConversionExpr>(expr))
19111916
expr = covariantReturn->getSubExpr();
1917+
if (auto *functionConversion = dyn_cast<FunctionConversionExpr>(expr))
1918+
expr = functionConversion->getSubExpr();
19121919
return expr;
19131920
};
19141921

@@ -1944,7 +1951,8 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19441951
innerBody = maybeUnwrapConversions(innerBody);
19451952

19461953
if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
1947-
if (auto *innerCall = dyn_cast<ApplyExpr>(outerCall->getFn())) {
1954+
auto outerFn = maybeUnwrapConversions(outerCall->getFn());
1955+
if (auto *innerCall = dyn_cast<ApplyExpr>(outerFn)) {
19481956
return innerCall->getFn();
19491957
}
19501958
}

lib/IDE/ArgumentCompletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ SelectedOverloadInfo getSelectedOverloadInfo(const Solution &S,
116116

117117
Result.FuncD = SelectedOverload->choice.getDeclOrNull();
118118
Result.FuncTy =
119-
S.simplifyTypeForCodeCompletion(SelectedOverload->openedType);
119+
S.simplifyTypeForCodeCompletion(SelectedOverload->adjustedOpenedType);
120120

121121
// For completion as the arg in a call to the implicit [keypath: _]
122122
// subscript the solver can't know what kind of keypath is expected without
@@ -141,7 +141,7 @@ SelectedOverloadInfo getSelectedOverloadInfo(const Solution &S,
141141
break;
142142
}
143143
case OverloadChoiceKind::KeyPathDynamicMemberLookup: {
144-
auto *fnType = SelectedOverload->openedType->castTo<FunctionType>();
144+
auto *fnType = SelectedOverload->adjustedOpenedType->castTo<FunctionType>();
145145
assert(fnType->getParams().size() == 1 &&
146146
"subscript always has one argument");
147147
// Parameter type is KeyPath<T, U> where `T` is a root type

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ collectExistentialConformances(ModuleDecl *M, CanType fromType, CanType toType)
183183
SmallVector<ProtocolConformanceRef, 4> conformances;
184184
for (auto proto : protocols) {
185185
auto conformance =
186-
M->lookupConformance(fromType, proto);
186+
M->lookupConformance(fromType, proto, /*allowMissing=*/true);
187187
assert(conformance);
188188
conformances.push_back(conformance);
189189
}

0 commit comments

Comments
 (0)