Skip to content

Commit 8fde2d8

Browse files
authored
Merge pull request #1890 from swiftwasm/release/5.3
[pull] swiftwasm-release/5.3 from release/5.3
2 parents e91ac1c + 5f803ee commit 8fde2d8

File tree

21 files changed

+343
-40
lines changed

21 files changed

+343
-40
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3937,6 +3937,16 @@ class AssignByWrapperInst
39373937
: public AssignInstBase<SILInstructionKind::AssignByWrapperInst, 4> {
39383938
friend SILBuilder;
39393939

3940+
public:
3941+
/// The assignment destination for the property wrapper
3942+
enum class Destination {
3943+
BackingWrapper,
3944+
WrappedValue,
3945+
};
3946+
3947+
private:
3948+
Destination AssignDest = Destination::WrappedValue;
3949+
39403950
AssignByWrapperInst(SILDebugLocation DebugLoc, SILValue Src, SILValue Dest,
39413951
SILValue Initializer, SILValue Setter,
39423952
AssignOwnershipQualifier Qualifier =
@@ -3951,8 +3961,17 @@ class AssignByWrapperInst
39513961
return AssignOwnershipQualifier(
39523962
SILInstruction::Bits.AssignByWrapperInst.OwnershipQualifier);
39533963
}
3954-
void setOwnershipQualifier(AssignOwnershipQualifier qualifier) {
3964+
3965+
Destination getAssignDestination() const { return AssignDest; }
3966+
3967+
void setAssignInfo(AssignOwnershipQualifier qualifier, Destination dest) {
3968+
using Qualifier = AssignOwnershipQualifier;
3969+
assert(qualifier == Qualifier::Init && dest == Destination::BackingWrapper ||
3970+
qualifier == Qualifier::Reassign && dest == Destination::BackingWrapper ||
3971+
qualifier == Qualifier::Reassign && dest == Destination::WrappedValue);
3972+
39553973
SILInstruction::Bits.AssignByWrapperInst.OwnershipQualifier = unsigned(qualifier);
3974+
AssignDest = dest;
39563975
}
39573976
};
39583977

lib/AST/Expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19431943
body = body->getSemanticsProvidingExpr();
19441944

19451945
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(body)) {
1946-
body = openExistential->getSubExpr();
1946+
body = openExistential->getSubExpr()->getSemanticsProvidingExpr();
19471947
}
19481948

19491949
if (auto *outerCall = dyn_cast<ApplyExpr>(body)) {
@@ -1963,7 +1963,7 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19631963
innerBody = innerBody->getSemanticsProvidingExpr();
19641964

19651965
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(innerBody)) {
1966-
innerBody = openExistential->getSubExpr();
1966+
innerBody = openExistential->getSubExpr()->getSemanticsProvidingExpr();
19671967
if (auto *ICE = dyn_cast<ImplicitConversionExpr>(innerBody))
19681968
innerBody = ICE->getSyntacticSubExpr();
19691969
}

lib/Demangling/Remangler.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,8 +1473,14 @@ void Remangler::mangleImplFunctionType(Node *node) {
14731473
mangle(PatternSubs->getChild(0));
14741474
Buffer << 'y';
14751475
mangleChildNodes(PatternSubs->getChild(1));
1476-
if (PatternSubs->getNumChildren() >= 3)
1477-
mangleRetroactiveConformance(PatternSubs->getChild(2));
1476+
if (PatternSubs->getNumChildren() >= 3) {
1477+
NodePointer retroactiveConf = PatternSubs->getChild(2);
1478+
if (retroactiveConf->getKind() == Node::Kind::TypeList) {
1479+
mangleChildNodes(retroactiveConf);
1480+
} else {
1481+
mangleRetroactiveConformance(retroactiveConf);
1482+
}
1483+
}
14781484
}
14791485

14801486
Buffer << 'I';

lib/SILGen/SILGenThunk.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ SILGenFunction::emitGlobalFunctionRef(SILLocation loc, SILDeclRef constant,
144144
}
145145

146146
auto f = SGM.getFunction(constant, NotForDefinition);
147-
assert(f->getLoweredFunctionTypeInContext(B.getTypeExpansionContext()) ==
148-
constantInfo.SILFnType);
147+
#ifndef NDEBUG
148+
auto constantFnTypeInContext =
149+
SGM.Types.getLoweredType(constantInfo.SILFnType,
150+
B.getTypeExpansionContext())
151+
.castTo<SILFunctionType>();
152+
assert(f->getLoweredFunctionTypeInContext(B.getTypeExpansionContext())
153+
== constantFnTypeInContext);
154+
#endif
149155
if (callPreviousDynamicReplaceableImpl)
150156
return B.createPreviousDynamicFunctionRef(loc, f);
151157
else

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ enum DIUseKind {
254254
/// value.
255255
Assign,
256256

257+
/// The instruction is an assignment of a wrapped value with an already initialized
258+
/// backing property wrapper.
259+
AssignWrappedValue,
260+
257261
/// The instruction is a store to a member of a larger struct value.
258262
PartialStore,
259263

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ LifetimeChecker::LifetimeChecker(const DIMemoryObjectInfo &TheMemory,
533533
case DIUseKind::Escape:
534534
continue;
535535
case DIUseKind::Assign:
536+
case DIUseKind::AssignWrappedValue:
536537
case DIUseKind::IndirectIn:
537538
case DIUseKind::InitOrAssign:
538539
case DIUseKind::InOutArgument:
@@ -750,6 +751,7 @@ void LifetimeChecker::doIt() {
750751
continue;
751752

752753
case DIUseKind::Assign:
754+
case DIUseKind::AssignWrappedValue:
753755
// Instructions classified as assign are only generated when lowering
754756
// InitOrAssign instructions in regions known to be initialized. Since
755757
// they are already known to be definitely init, don't reprocess them.
@@ -1047,16 +1049,15 @@ void LifetimeChecker::handleStoreUse(unsigned UseID) {
10471049
// an initialization or assign in the uses list so that clients know about it.
10481050
if (isFullyUninitialized) {
10491051
Use.Kind = DIUseKind::Initialization;
1052+
} else if (isFullyInitialized && isa<AssignByWrapperInst>(Use.Inst)) {
1053+
// If some fields are uninitialized, re-write assign_by_wrapper to assignment
1054+
// of the backing wrapper. If all fields are initialized, assign to the wrapped
1055+
// value.
1056+
auto allFieldsInitialized =
1057+
getAnyUninitializedMemberAtInst(Use.Inst, 0, TheMemory.getNumElements()) == -1;
1058+
Use.Kind = allFieldsInitialized ? DIUseKind::AssignWrappedValue : DIUseKind::Assign;
10501059
} else if (isFullyInitialized) {
1051-
// Only re-write assign_by_wrapper to assignment if all fields have been
1052-
// initialized.
1053-
if (isa<AssignByWrapperInst>(Use.Inst) &&
1054-
getAnyUninitializedMemberAtInst(Use.Inst, 0,
1055-
TheMemory.getNumElements()) != -1) {
1056-
Use.Kind = DIUseKind::Initialization;
1057-
} else {
1058-
Use.Kind = DIUseKind::Assign;
1059-
}
1060+
Use.Kind = DIUseKind::Assign;
10601061
} else {
10611062
// If it is initialized on some paths, but not others, then we have an
10621063
// inconsistent initialization, which needs dynamic control logic in the
@@ -1909,7 +1910,7 @@ void LifetimeChecker::updateInstructionForInitState(DIMemoryUse &Use) {
19091910
Use.Kind == DIUseKind::SelfInit)
19101911
InitKind = IsInitialization;
19111912
else {
1912-
assert(Use.Kind == DIUseKind::Assign);
1913+
assert(Use.Kind == DIUseKind::Assign || Use.Kind == DIUseKind::AssignWrappedValue);
19131914
InitKind = IsNotInitialization;
19141915
}
19151916

@@ -1958,14 +1959,21 @@ void LifetimeChecker::updateInstructionForInitState(DIMemoryUse &Use) {
19581959
Use.Inst = nullptr;
19591960
NonLoadUses.erase(Inst);
19601961

1961-
if (TheMemory.isClassInitSelf() &&
1962-
Use.Kind == DIUseKind::SelfInit) {
1963-
assert(InitKind == IsInitialization);
1964-
AI->setOwnershipQualifier(AssignOwnershipQualifier::Reinit);
1965-
} else {
1966-
AI->setOwnershipQualifier((InitKind == IsInitialization
1967-
? AssignOwnershipQualifier::Init
1968-
: AssignOwnershipQualifier::Reassign));
1962+
switch (Use.Kind) {
1963+
case DIUseKind::Initialization:
1964+
AI->setAssignInfo(AssignOwnershipQualifier::Init,
1965+
AssignByWrapperInst::Destination::BackingWrapper);
1966+
break;
1967+
case DIUseKind::Assign:
1968+
AI->setAssignInfo(AssignOwnershipQualifier::Reassign,
1969+
AssignByWrapperInst::Destination::BackingWrapper);
1970+
break;
1971+
case DIUseKind::AssignWrappedValue:
1972+
AI->setAssignInfo(AssignOwnershipQualifier::Reassign,
1973+
AssignByWrapperInst::Destination::WrappedValue);
1974+
break;
1975+
default:
1976+
llvm_unreachable("Wrong use kind for assign_by_wrapper");
19691977
}
19701978

19711979
return;

lib/SILOptimizer/Mandatory/RawSILInstLowering.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b,
179179
SILLocation loc = inst->getLoc();
180180
SILBuilderWithScope forCleanup(std::next(inst->getIterator()));
181181

182-
switch (inst->getOwnershipQualifier()) {
183-
case AssignOwnershipQualifier::Init: {
182+
switch (inst->getAssignDestination()) {
183+
case AssignByWrapperInst::Destination::BackingWrapper: {
184184
SILValue initFn = inst->getInitializer();
185185
CanSILFunctionType fTy = initFn->getType().castTo<SILFunctionType>();
186186
SILFunctionConventions convention(fTy, inst->getModule());
@@ -193,15 +193,18 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b,
193193
getAssignByWrapperArgs(args, src, convention, b, forCleanup);
194194
SILValue wrappedSrc = b.createApply(loc, initFn, SubstitutionMap(),
195195
args);
196-
b.createTrivialStoreOr(loc, wrappedSrc, dest,
197-
StoreOwnershipQualifier::Init);
196+
if (inst->getOwnershipQualifier() == AssignOwnershipQualifier::Init ||
197+
inst->getDest()->getType().isTrivial(*inst->getFunction())) {
198+
b.createTrivialStoreOr(loc, wrappedSrc, dest, StoreOwnershipQualifier::Init);
199+
} else {
200+
b.createStore(loc, wrappedSrc, dest, StoreOwnershipQualifier::Assign);
201+
}
198202
}
199203
// TODO: remove the unused setter function, which usually is a dead
200204
// partial_apply.
201205
break;
202206
}
203-
case AssignOwnershipQualifier::Unknown:
204-
case AssignOwnershipQualifier::Reassign: {
207+
case AssignByWrapperInst::Destination::WrappedValue: {
205208
SILValue setterFn = inst->getSetter();
206209
CanSILFunctionType fTy = setterFn->getType().castTo<SILFunctionType>();
207210
SILFunctionConventions convention(fTy, inst->getModule());
@@ -220,8 +223,6 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b,
220223
// partial_apply.
221224
break;
222225
}
223-
case AssignOwnershipQualifier::Reinit:
224-
llvm_unreachable("wrong qualifier for assign_by_wrapper");
225226
}
226227
inst->eraseFromParent();
227228
}

lib/Sema/CSGen.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,35 @@ namespace {
12071207
// `_ = nil`, let's diagnose it here because solver can't
12081208
// attempt any types for it.
12091209
auto *parentExpr = CS.getParentExpr(expr);
1210-
while (parentExpr && isa<ParenExpr>(parentExpr))
1211-
parentExpr = CS.getParentExpr(parentExpr);
1210+
bool hasContextualType = bool(CS.getContextualType(expr));
1211+
1212+
while (parentExpr) {
1213+
if (!isa<IdentityExpr>(parentExpr))
1214+
break;
1215+
1216+
// If there is a parent, use it, otherwise we need
1217+
// to check whether the last parent node in the chain
1218+
// had a contextual type associated with it because
1219+
// in situations like:
1220+
//
1221+
// \code
1222+
// func foo() -> Int? {
1223+
// return (nil)
1224+
// }
1225+
// \endcode
1226+
//
1227+
// parentheses around `nil` are significant.
1228+
if (auto *nextParent = CS.getParentExpr(parentExpr)) {
1229+
parentExpr = nextParent;
1230+
} else {
1231+
hasContextualType |= bool(CS.getContextualType(parentExpr));
1232+
// Since current expression is an identity expr
1233+
// and there are no more parents, let's pretend
1234+
// that `nil` don't have a parent since parens
1235+
// are not semantically significant for further checks.
1236+
parentExpr = nullptr;
1237+
}
1238+
}
12121239

12131240
// In cases like `_ = nil?` AST would have `nil`
12141241
// wrapped in `BindOptionalExpr`.
@@ -1243,7 +1270,7 @@ namespace {
12431270
}
12441271
}
12451272

1246-
if (!parentExpr && !CS.getContextualType(expr)) {
1273+
if (!parentExpr && !hasContextualType) {
12471274
DE.diagnose(expr->getLoc(), diag::unresolved_nil_literal);
12481275
return Type();
12491276
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,13 +2311,16 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
23112311
if (auto FD = dyn_cast<FuncDecl>(witness)) {
23122312
loc = FD->getStaticLoc();
23132313
} else if (auto VD = dyn_cast<VarDecl>(witness)) {
2314-
loc = VD->getParentPatternBinding()->getStaticLoc();
2314+
if (auto PBD = VD->getParentPatternBinding()) {
2315+
loc = PBD->getStaticLoc();
2316+
}
23152317
} else if (auto SD = dyn_cast<SubscriptDecl>(witness)) {
23162318
loc = SD->getStaticLoc();
23172319
} else {
23182320
llvm_unreachable("Unexpected witness");
23192321
}
2320-
diag.fixItRemove(loc);
2322+
if (loc.isValid())
2323+
diag.fixItRemove(loc);
23212324
} else {
23222325
diag.fixItInsert(witness->getAttributeInsertionLoc(true), "static ");
23232326
}

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,11 @@ function(_compile_swift_files
626626
endif()
627627

628628
set(line_directive_tool "${SWIFT_SOURCE_DIR}/utils/line-directive")
629-
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
629+
if(EXISTS "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
630+
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
631+
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME)
632+
set(swift_compiler_tool "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swiftc")
633+
endif()
630634
set(swift_compiler_tool_dep)
631635
if(SWIFT_INCLUDE_TOOLS)
632636
# Depend on the binary itself, in addition to the symlink.

0 commit comments

Comments
 (0)