Skip to content

Commit c1e8529

Browse files
Merge pull request #5311 from swiftwasm/release/5.8
[pull] swiftwasm-release/5.8 from release/5.8
2 parents ea686a4 + b9562e1 commit c1e8529

19 files changed

+489
-46
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ namespace swift {
331331
bool UseMalloc = false;
332332

333333
/// Specifies how strict concurrency checking will be.
334-
StrictConcurrency StrictConcurrencyLevel = StrictConcurrency::Targeted;
334+
StrictConcurrency StrictConcurrencyLevel = StrictConcurrency::Minimal;
335335

336336
/// Enable experimental concurrency model.
337337
bool EnableExperimentalConcurrency = false;

include/swift/Sema/ConstraintSystem.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ class TypeVariableType::Implementation {
486486
/// expression.
487487
bool isCodeCompletionToken() const;
488488

489+
/// Determine whether this type variable represents an opened opaque type.
490+
bool isOpaqueType() const;
491+
489492
/// Retrieve the representative of the equivalence class to which this
490493
/// type variable belongs.
491494
///
@@ -977,6 +980,11 @@ struct AppliedBuilderTransform {
977980
/// converted. Opaque types should be unopened.
978981
Type bodyResultType;
979982

983+
/// If transform is applied to a closure, this type represents
984+
/// contextual type the closure is converted type (e.g. a parameter
985+
/// type or or pattern type).
986+
Type contextualType;
987+
980988
/// The version of the original body with result builder applied
981989
/// as AST transformation.
982990
NullablePtr<BraceStmt> transformedBody;
@@ -5662,7 +5670,7 @@ class ConstraintSystem {
56625670
Optional<TypeMatchResult>
56635671
matchResultBuilder(AnyFunctionRef fn, Type builderType, Type bodyResultType,
56645672
ConstraintKind bodyResultConstraintKind,
5665-
ConstraintLocatorBuilder locator);
5673+
Type contextualType, ConstraintLocatorBuilder locator);
56665674

56675675
/// Matches a wrapped or projected value parameter type to its backing
56685676
/// property wrapper type by applying the property wrapper.

include/swift/Threading/Impl/Darwin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ inline void once_impl(once_t &predicate, void (*fn)(void *), void *context) {
186186
// On Darwin, we want to use the reserved keys
187187
#define SWIFT_THREADING_USE_RESERVED_TLS_KEYS 1
188188

189-
#if !(SWIFT_THREADING_IS_COMPATIBILITY_LIBRARY && __ARM_ARCH_7K__) && __has_include(<pthread/tsd_private.h>)
189+
#if !(SWIFT_THREADING_IS_COMPATIBILITY_LIBRARY && (__ARM_ARCH_7K__ || __ARM64_ARCH_8_32__)) && __has_include(<pthread/tsd_private.h>)
190190
} // namespace threading_impl
191191
} // namespace swift
192192

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
788788
} else if (Args.hasArg(OPT_warn_concurrency)) {
789789
Opts.StrictConcurrencyLevel = StrictConcurrency::Complete;
790790
} else {
791-
// Default to "limited" checking in Swift 5.x.
792-
Opts.StrictConcurrencyLevel = StrictConcurrency::Targeted;
791+
// Default to minimal checking in Swift 5.x.
792+
Opts.StrictConcurrencyLevel = StrictConcurrency::Minimal;
793793
}
794794

795795
Opts.WarnImplicitOverrides =

lib/SILGen/SILGenDistributed.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ static SILValue emitActorPropertyReference(
5454
/// \param value the value to use when initializing the property.
5555
static void initializeProperty(SILGenFunction &SGF, SILLocation loc,
5656
SILValue actorSelf,
57-
VarDecl* prop, SILValue value) {
57+
VarDecl* prop, SILValue value,
58+
IsTake_t isTake) {
5859
Type formalType = SGF.F.mapTypeIntoContext(prop->getInterfaceType());
5960
SILType loweredType = SGF.getLoweredType(formalType);
6061

6162
auto fieldAddr = emitActorPropertyReference(SGF, loc, actorSelf, prop);
6263

6364
if (loweredType.isAddressOnly(SGF.F)) {
64-
SGF.B.createCopyAddr(loc, value, fieldAddr, IsNotTake, IsInitialization);
65+
SGF.B.createCopyAddr(loc, value, fieldAddr, isTake, IsInitialization);
6566
} else {
6667
if (value->getType().isAddress()) {
6768
SGF.emitSemanticLoadInto(loc, value, SGF.F.getTypeLowering(value->getType()),
68-
fieldAddr, SGF.getTypeLowering(loweredType), IsTake, IsInitialization);
69+
fieldAddr, SGF.getTypeLowering(loweredType), isTake, IsInitialization);
6970
} else {
7071
value = SGF.B.emitCopyValueOperation(loc, value);
7172
SGF.B.emitStoreValueOperation(
@@ -152,10 +153,10 @@ static SILArgument *findFirstDistributedActorSystemArg(SILFunction &F) {
152153
/// For the initialization of a local distributed actor instance, emits code to
153154
/// initialize the instance's stored property corresponding to the system.
154155
static void emitActorSystemInit(SILGenFunction &SGF,
155-
ConstructorDecl *ctor,
156-
SILLocation loc,
157-
ManagedValue actorSelf,
158-
SILValue systemValue) {
156+
ConstructorDecl *ctor,
157+
SILLocation loc,
158+
ManagedValue actorSelf,
159+
SILValue systemValue) {
159160
assert(ctor->isImplicit() && "unexpected explicit dist actor init");
160161
assert(ctor->isDesignatedInit());
161162

@@ -166,9 +167,8 @@ static void emitActorSystemInit(SILGenFunction &SGF,
166167
// exactly one ActorSystem-conforming argument to the constructor,
167168
// so we grab the first one from the params.
168169
VarDecl *var = classDecl->getDistributedActorSystemProperty();
169-
assert(var);
170-
171-
initializeProperty(SGF, loc, actorSelf.getValue(), var, systemValue);
170+
171+
initializeProperty(SGF, loc, actorSelf.getValue(), var, systemValue, IsNotTake);
172172
}
173173

174174
/// Emits the distributed actor's identity (`id`) initialization.
@@ -209,7 +209,7 @@ void SILGenFunction::emitDistActorIdentityInit(ConstructorDecl *ctor,
209209
{ temp, selfMetatypeValue });
210210

211211
// --- initialize the property.
212-
initializeProperty(*this, loc, borrowedSelfArg, var, temp);
212+
initializeProperty(*this, loc, borrowedSelfArg, var, temp, IsTake);
213213
}
214214

215215
// TODO(distributed): rename to DistributedActorID
@@ -443,14 +443,16 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) { // TODO(distrib
443443
loc.markAutoGenerated();
444444
auto *dc = fd->getDeclContext();
445445
auto classDecl = dc->getSelfClassDecl();
446-
446+
447447
initializeProperty(*this, loc, remote,
448448
classDecl->getDistributedActorIDProperty(),
449-
idArg);
449+
idArg,
450+
IsNotTake);
450451

451452
initializeProperty(*this, loc, remote,
452453
classDecl->getDistributedActorSystemProperty(),
453-
actorSystemArg);
454+
actorSystemArg,
455+
IsNotTake);
454456

455457
// ==== Branch to return the fully initialized remote instance
456458
B.createBranch(loc, returnBB, {remote});

lib/Sema/BuilderTransform.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,7 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
23112311

23122312
if (auto result = cs.matchResultBuilder(
23132313
func, builderType, resultContextType, resultConstraintKind,
2314+
/*contextualType=*/Type(),
23142315
cs.getConstraintLocator(func->getBody()))) {
23152316
if (result->isFailure())
23162317
return nullptr;
@@ -2398,6 +2399,7 @@ Optional<ConstraintSystem::TypeMatchResult>
23982399
ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
23992400
Type bodyResultType,
24002401
ConstraintKind bodyResultConstraintKind,
2402+
Type contextualType,
24012403
ConstraintLocatorBuilder locator) {
24022404
builderType = simplifyType(builderType);
24032405
auto builder = builderType->getAnyNominal();
@@ -2522,6 +2524,7 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
25222524

25232525
transformInfo.builderType = builderType;
25242526
transformInfo.bodyResultType = bodyResultType;
2527+
transformInfo.contextualType = contextualType;
25252528
transformInfo.transformedBody = transformedBody->second;
25262529

25272530
// Record the transformation.

lib/Sema/CSBindings.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,61 @@ bool BindingSet::favoredOverConjunction(Constraint *conjunction) const {
10711071
if (forClosureResult() || forGenericParameter())
10721072
return false;
10731073
}
1074+
1075+
auto *locator = conjunction->getLocator();
1076+
if (locator->directlyAt<ClosureExpr>()) {
1077+
auto *closure = castToExpr<ClosureExpr>(locator->getAnchor());
1078+
1079+
if (auto transform = CS.getAppliedResultBuilderTransform(closure)) {
1080+
// Conjunctions that represent closures with result builder transformed
1081+
// bodies could be attempted right after their resolution if they meet
1082+
// all of the following criteria:
1083+
//
1084+
// - Builder type doesn't have any unresolved generic parameters;
1085+
// - Closure doesn't have any parameters;
1086+
// - The contextual result type is either concrete or opaque type.
1087+
auto contextualType = transform->contextualType;
1088+
if (!(contextualType && contextualType->is<FunctionType>()))
1089+
return true;
1090+
1091+
auto *contextualFnType =
1092+
CS.simplifyType(contextualType)->castTo<FunctionType>();
1093+
{
1094+
auto resultType = contextualFnType->getResult();
1095+
if (resultType->hasTypeVariable()) {
1096+
auto *typeVar = resultType->getAs<TypeVariableType>();
1097+
// If contextual result type is represented by an opaque type,
1098+
// it's a strong indication that body is self-contained, otherwise
1099+
// closure might rely on external types flowing into the body for
1100+
// disambiguation of `build{Partial}Block` or `buildFinalResult`
1101+
// calls.
1102+
if (!(typeVar && typeVar->getImpl().isOpaqueType()))
1103+
return true;
1104+
}
1105+
}
1106+
1107+
// If some of the closure parameters are unresolved, the conjunction
1108+
// has to be delayed to give them a chance to be inferred.
1109+
if (llvm::any_of(contextualFnType->getParams(), [](const auto &param) {
1110+
return param.getPlainType()->hasTypeVariable();
1111+
}))
1112+
return true;
1113+
1114+
// Check whether conjunction has any unresolved type variables
1115+
// besides the variable that represents the closure.
1116+
//
1117+
// Conjunction could refer to declarations from outer context
1118+
// (i.e. a variable declared in the outer closure) or generic
1119+
// parameters of the builder type), if any of such references
1120+
// are not yet inferred the conjunction has to be delayed.
1121+
auto *closureType = CS.getType(closure)->castTo<TypeVariableType>();
1122+
return llvm::any_of(
1123+
conjunction->getTypeVariables(), [&](TypeVariableType *typeVar) {
1124+
return !(typeVar == closureType || CS.getFixedType(typeVar));
1125+
});
1126+
}
1127+
}
1128+
10741129
return true;
10751130
}
10761131

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10964,7 +10964,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1096410964
if (resultBuilderType) {
1096510965
if (auto result = matchResultBuilder(
1096610966
closure, resultBuilderType, closureType->getResult(),
10967-
ConstraintKind::Conversion, locator)) {
10967+
ConstraintKind::Conversion, contextualType, locator)) {
1096810968
return result->isSuccess();
1096910969
}
1097010970
}

lib/Sema/CSSyntacticElement.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
18911891
NullablePtr<Stmt> transformIf(IfStmt *ifStmt, TypeJoinExpr *join,
18921892
unsigned index) {
18931893
// FIXME: Turn this into a condition once warning is an error.
1894-
(void)diagnoseMissingBuildWithAvailability(ifStmt);
1894+
(void)diagnoseMissingBuildWithAvailability(ifStmt, join);
18951895

18961896
auto *joinVar = join->getVar();
18971897

@@ -1993,7 +1993,8 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
19931993
/// have had the chance to adopt buildLimitedAvailability(), we'll upgrade
19941994
/// this warning to an error.
19951995
LLVM_NODISCARD
1996-
bool diagnoseMissingBuildWithAvailability(IfStmt *ifStmt) {
1996+
bool diagnoseMissingBuildWithAvailability(IfStmt *ifStmt,
1997+
TypeJoinExpr *join) {
19971998
auto findAvailabilityCondition =
19981999
[](StmtCondition stmtCond) -> const StmtConditionElement * {
19992000
for (const auto &cond : stmtCond) {
@@ -2017,27 +2018,10 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
20172018
return false;
20182019

20192020
SourceLoc loc = availabilityCond->getStartLoc();
2020-
Type bodyType;
2021-
if (availabilityCond->getAvailability()->isUnavailability()) {
2022-
BraceStmt *elseBody = nullptr;
2023-
// For #unavailable, we need to check the "else".
2024-
if (auto *innerIf = getAsStmt<IfStmt>(ifStmt->getElseStmt())) {
2025-
elseBody = castToStmt<BraceStmt>(innerIf->getThenStmt());
2026-
} else {
2027-
elseBody = castToStmt<BraceStmt>(ifStmt->getElseStmt());
2028-
}
2029-
2030-
Type elseBodyType =
2031-
solution.simplifyType(solution.getType(elseBody->getLastElement()));
2032-
bodyType = elseBodyType;
2033-
} else {
2034-
auto *thenBody = castToStmt<BraceStmt>(ifStmt->getThenStmt());
2035-
Type thenBodyType =
2036-
solution.simplifyType(solution.getType(thenBody->getLastElement()));
2037-
bodyType = thenBodyType;
2038-
}
2039-
20402021
auto builderType = solution.simplifyType(Transform.builderType);
2022+
// Since all of the branches of `if` statement have to join into the same
2023+
// type we can just use the type of the join variable here.
2024+
Type bodyType = solution.getResolvedType(join->getVar());
20412025

20422026
return bodyType.findIf([&](Type type) {
20432027
auto nominal = type->getAnyNominal();

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ bool TypeVariableType::Implementation::isCodeCompletionToken() const {
154154
return locator && locator->directlyAt<CodeCompletionExpr>();
155155
}
156156

157+
bool TypeVariableType::Implementation::isOpaqueType() const {
158+
if (!locator)
159+
return false;
160+
161+
auto GP = locator->getLastElementAs<LocatorPathElt::GenericParameter>();
162+
if (!GP)
163+
return false;
164+
165+
if (auto *GPT = GP->getType()->getAs<GenericTypeParamType>()) {
166+
auto *decl = GPT->getDecl();
167+
return decl && decl->isOpaqueType();
168+
}
169+
170+
return false;
171+
}
172+
157173
void *operator new(size_t bytes, ConstraintSystem& cs,
158174
size_t alignment) {
159175
return cs.getAllocator().Allocate(bytes, alignment);

0 commit comments

Comments
 (0)