Skip to content

Commit 66cbff9

Browse files
Merge pull request #4751 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents 89ccf4f + 25d8029 commit 66cbff9

File tree

12 files changed

+200
-12
lines changed

12 files changed

+200
-12
lines changed

include/swift/AST/Decl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,6 +5430,20 @@ class VarDecl : public AbstractStorageDecl {
54305430
/// is provided first.
54315431
llvm::TinyPtrVector<CustomAttr *> getAttachedPropertyWrappers() const;
54325432

5433+
/// Retrieve the outermost property wrapper attribute associated with
5434+
/// this declaration. For example:
5435+
///
5436+
/// \code
5437+
/// @A @B @C var <name>: Bool = ...
5438+
/// \endcode
5439+
///
5440+
/// The outermost attribute in this case is `@A` and it has
5441+
/// complete wrapper type `A<B<C<Bool>>>`.
5442+
CustomAttr *getOutermostAttachedPropertyWrapper() const {
5443+
auto wrappers = getAttachedPropertyWrappers();
5444+
return wrappers.empty() ? nullptr : wrappers.front();
5445+
}
5446+
54335447
/// Whether this property has any attached property wrappers.
54345448
bool hasAttachedPropertyWrapper() const;
54355449

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6532,7 +6532,7 @@ bool VarDecl::hasExternalPropertyWrapper() const {
65326532
return true;
65336533

65346534
// Wrappers with attribute arguments are always implementation-detail.
6535-
if (getAttachedPropertyWrappers().front()->hasArgs())
6535+
if (getOutermostAttachedPropertyWrapper()->hasArgs())
65366536
return false;
65376537

65386538
auto wrapperInfo = getAttachedPropertyWrapperTypeInfo(0);

lib/AST/ProtocolConformance.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,8 +1608,22 @@ bool ProtocolConformance::isCanonical() const {
16081608

16091609
switch (getKind()) {
16101610
case ProtocolConformanceKind::Self:
1611-
case ProtocolConformanceKind::Normal:
1611+
case ProtocolConformanceKind::Normal: {
1612+
return true;
1613+
}
16121614
case ProtocolConformanceKind::Builtin: {
1615+
// Check that the generic signature of the conformance is canonical.
1616+
auto builtinConformance = cast<BuiltinProtocolConformance>(this);
1617+
if (builtinConformance->getGenericSignature()
1618+
&& !builtinConformance->getGenericSignature()->isCanonical()) {
1619+
return false;
1620+
}
1621+
// Check that the satisfied conditional requirements are canonical.
1622+
for (auto &requirement : builtinConformance->getConditionalRequirements()) {
1623+
if (!requirement.isCanonical()) {
1624+
return false;
1625+
}
1626+
}
16131627
return true;
16141628
}
16151629
case ProtocolConformanceKind::Inherited: {
@@ -1638,11 +1652,25 @@ ProtocolConformance *ProtocolConformance::getCanonicalConformance() {
16381652

16391653
switch (getKind()) {
16401654
case ProtocolConformanceKind::Self:
1641-
case ProtocolConformanceKind::Normal:
1642-
case ProtocolConformanceKind::Builtin: {
1655+
case ProtocolConformanceKind::Normal: {
16431656
// Root conformances are always canonical by construction.
16441657
return this;
16451658
}
1659+
case ProtocolConformanceKind::Builtin: {
1660+
// Canonicalize the subject type of the builtin conformance.
1661+
auto &Ctx = getType()->getASTContext();
1662+
auto builtinConformance = cast<BuiltinProtocolConformance>(this);
1663+
SmallVector<Requirement, 4> canonicalRequirements;
1664+
for (auto &reqt : builtinConformance->getConditionalRequirements()) {
1665+
canonicalRequirements.push_back(reqt.getCanonical());
1666+
}
1667+
return Ctx.getBuiltinConformance(
1668+
builtinConformance->getType()->getCanonicalType(),
1669+
builtinConformance->getProtocol(),
1670+
builtinConformance->getGenericSignature().getCanonicalSignature(),
1671+
canonicalRequirements,
1672+
builtinConformance->getBuiltinConformanceKind());
1673+
}
16461674

16471675
case ProtocolConformanceKind::Inherited: {
16481676
auto &Ctx = getType()->getASTContext();

lib/SILOptimizer/Mandatory/FlowIsolation.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,15 @@ void Info::diagnoseAll(AnalysisInfo &info, bool forDeinit,
422422
if (propertyUses.empty())
423423
return;
424424

425+
auto *fn = info.getFunction();
426+
auto &ctx = fn->getASTContext();
427+
428+
// Disable these diagnostics in deinitializers unless complete checking is
429+
// enabled.
430+
if (forDeinit && ctx.LangOpts.StrictConcurrencyLevel
431+
!= StrictConcurrency::Complete)
432+
return;
433+
425434
// Blame that is valid for the first property use is valid for all uses
426435
// in this block.
427436
if (!blame)
@@ -438,7 +447,6 @@ void Info::diagnoseAll(AnalysisInfo &info, bool forDeinit,
438447
}
439448
}
440449

441-
auto *fn = info.getFunction();
442450
auto &diag = fn->getASTContext().Diags;
443451

444452
SILLocation blameLoc = blame->getDebugLocation().getLocation();

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8564,8 +8564,8 @@ static Optional<SolutionApplicationTarget> applySolutionToInitialization(
85648564
wrappedVar, initType->mapTypeOutOfContext());
85658565

85668566
// Record the semantic initializer on the outermost property wrapper.
8567-
wrappedVar->getAttachedPropertyWrappers().front()
8568-
->setSemanticInit(initializer);
8567+
wrappedVar->getOutermostAttachedPropertyWrapper()->setSemanticInit(
8568+
initializer);
85698569

85708570
// If this is a wrapped parameter, we're done.
85718571
if (isa<ParamDecl>(wrappedVar))
@@ -8983,7 +8983,7 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
89838983
return target;
89848984
} else if (auto *wrappedVar = target.getAsUninitializedWrappedVar()) {
89858985
// Get the outermost wrapper type from the solution
8986-
auto outermostWrapper = wrappedVar->getAttachedPropertyWrappers().front();
8986+
auto outermostWrapper = wrappedVar->getOutermostAttachedPropertyWrapper();
89878987
auto backingType = solution.simplifyType(
89888988
solution.getType(outermostWrapper->getTypeExpr()));
89898989

lib/Sema/CSClosure.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,34 @@ class TypeVariableRefFinder : public ASTWalker {
8585
}
8686

8787
inferVariables(type);
88+
return {true, expr};
89+
}
90+
91+
auto var = dyn_cast<VarDecl>(decl);
92+
if (!var)
93+
return {true, expr};
94+
95+
if (auto *wrappedVar = var->getOriginalWrappedProperty()) {
96+
auto outermostWrapperAttr =
97+
wrappedVar->getOutermostAttachedPropertyWrapper();
98+
99+
// If the attribute doesn't have a type it could only mean
100+
// that the declaration was incorrect.
101+
if (!CS.hasType(outermostWrapperAttr->getTypeExpr()))
102+
return {true, expr};
103+
104+
auto wrapperType =
105+
CS.simplifyType(CS.getType(outermostWrapperAttr->getTypeExpr()));
106+
107+
if (var->getName().hasDollarPrefix()) {
108+
// $<name> is the projected value var
109+
CS.setType(var, computeProjectedValueType(wrappedVar, wrapperType));
110+
} else {
111+
// _<name> is the wrapper var
112+
CS.setType(var, computeWrappedValueType(wrappedVar, wrapperType));
113+
}
114+
115+
return {true, expr};
88116
}
89117
}
90118

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3568,7 +3568,7 @@ bool InvalidProjectedValueArgument::diagnoseAsError() {
35683568
if (!param->hasAttachedPropertyWrapper()) {
35693569
param->diagnose(diag::property_wrapper_param_no_wrapper, param->getName());
35703570
} else if (!param->hasImplicitPropertyWrapper() &&
3571-
param->getAttachedPropertyWrappers().front()->hasArgs()) {
3571+
param->getOutermostAttachedPropertyWrapper()->hasArgs()) {
35723572
param->diagnose(diag::property_wrapper_param_attr_arg);
35733573
} else {
35743574
Type backingType;

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9989,7 +9989,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
99899989
wrappedValueType = createTypeVariable(getConstraintLocator(paramDecl),
99909990
TVO_CanBindToHole | TVO_CanBindToLValue);
99919991
} else {
9992-
auto *wrapperAttr = paramDecl->getAttachedPropertyWrappers().front();
9992+
auto *wrapperAttr = paramDecl->getOutermostAttachedPropertyWrapper();
99939993
auto wrapperType = paramDecl->getAttachedPropertyWrapperType(0);
99949994
backingType = replaceInferableTypesWithTypeVars(
99959995
wrapperType, getConstraintLocator(wrapperAttr->getTypeRepr()));

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6327,9 +6327,9 @@ void ConstraintSystem::diagnoseFailureFor(SolutionApplicationTarget target) {
63276327
DE.diagnose(expr->getLoc(), diag::type_of_expression_is_ambiguous)
63286328
.highlight(expr->getSourceRange());
63296329
} else if (auto *wrappedVar = target.getAsUninitializedWrappedVar()) {
6330-
auto *wrapper = wrappedVar->getAttachedPropertyWrappers().back();
6330+
auto *outerWrapper = wrappedVar->getOutermostAttachedPropertyWrapper();
63316331
Type propertyType = wrappedVar->getInterfaceType();
6332-
Type wrapperType = wrapper->getType();
6332+
Type wrapperType = outerWrapper->getType();
63336333

63346334
// Emit the property wrapper fallback diagnostic
63356335
wrappedVar->diagnose(diag::property_wrapper_incompatible_property,

test/Concurrency/flow_isolation_nonstrict.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-frontend -strict-concurrency=targeted -swift-version 5 -parse-as-library -emit-sil -verify %s
22

3+
@_nonSendable
34
class NonSendableType {
45
var x: Int = 0
56
func f() {}
@@ -28,3 +29,14 @@ actor CheckDeinitFromActor {
2829
ns = nil
2930
}
3031
}
32+
33+
@MainActor class X {
34+
var ns: NonSendableType = NonSendableType()
35+
36+
nonisolated func something() { }
37+
38+
deinit {
39+
something()
40+
print(ns)
41+
}
42+
}

0 commit comments

Comments
 (0)