Skip to content

Commit 8dfa72f

Browse files
Merge commit '3b62296170a' into swiftwasm-release/5.5
2 parents 3db2940 + 3b62296 commit 8dfa72f

File tree

68 files changed

+2321
-1359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2321
-1359
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,6 +4385,12 @@ ERROR(global_actor_from_nonactor_context,none,
43854385
"%0 %1 isolated to global actor %2 can not be %select{referenced|mutated|used 'inout'}4"
43864386
" from %select{this|a non-isolated}3%select{| synchronous}5 context",
43874387
(DescriptiveDeclKind, DeclName, Type, bool, unsigned, bool))
4388+
ERROR(actor_isolated_call,none,
4389+
"call to %0 function in a synchronous %1 context",
4390+
(ActorIsolation, ActorIsolation))
4391+
ERROR(actor_isolated_call_decl,none,
4392+
"call to %0 %1 %2 in a synchronous %3 context",
4393+
(ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
43884394
ERROR(actor_isolated_partial_apply,none,
43894395
"actor-isolated %0 %1 can not be partially applied",
43904396
(DescriptiveDeclKind, DeclName))

include/swift/AST/Stmt.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,15 +1110,19 @@ class SwitchStmt final : public LabeledStmt,
11101110
friend TrailingObjects;
11111111

11121112
SourceLoc SwitchLoc, LBraceLoc, RBraceLoc;
1113+
/// The location of the last token in the 'switch' statement. For valid
1114+
/// 'switch' statements this is the same as \c RBraceLoc. If the '}' is
1115+
/// missing this points to the last token before the '}' was expected.
1116+
SourceLoc EndLoc;
11131117
Expr *SubjectExpr;
11141118

11151119
SwitchStmt(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc, Expr *SubjectExpr,
11161120
SourceLoc LBraceLoc, unsigned CaseCount, SourceLoc RBraceLoc,
1117-
Optional<bool> implicit = None)
1121+
SourceLoc EndLoc, Optional<bool> implicit = None)
11181122
: LabeledStmt(StmtKind::Switch, getDefaultImplicitFlag(implicit, SwitchLoc),
11191123
LabelInfo),
11201124
SwitchLoc(SwitchLoc), LBraceLoc(LBraceLoc), RBraceLoc(RBraceLoc),
1121-
SubjectExpr(SubjectExpr) {
1125+
EndLoc(EndLoc), SubjectExpr(SubjectExpr) {
11221126
Bits.SwitchStmt.CaseCount = CaseCount;
11231127
}
11241128

@@ -1129,6 +1133,7 @@ class SwitchStmt final : public LabeledStmt,
11291133
SourceLoc LBraceLoc,
11301134
ArrayRef<ASTNode> Cases,
11311135
SourceLoc RBraceLoc,
1136+
SourceLoc EndLoc,
11321137
ASTContext &C);
11331138

11341139
/// Get the source location of the 'switch' keyword.
@@ -1141,8 +1146,8 @@ class SwitchStmt final : public LabeledStmt,
11411146
SourceLoc getLoc() const { return SwitchLoc; }
11421147

11431148
SourceLoc getStartLoc() const { return getLabelLocOrKeywordLoc(SwitchLoc); }
1144-
SourceLoc getEndLoc() const { return RBraceLoc; }
1145-
1149+
SourceLoc getEndLoc() const { return EndLoc; }
1150+
11461151
/// Get the subject expression of the switch.
11471152
Expr *getSubjectExpr() const { return SubjectExpr; }
11481153
void setSubjectExpr(Expr *e) { SubjectExpr = e; }

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ namespace swift {
274274
bool EnableInferPublicSendable = false;
275275

276276
/// Disable the implicit import of the _Concurrency module.
277-
bool DisableImplicitConcurrencyModuleImport = false;
277+
bool DisableImplicitConcurrencyModuleImport =
278+
!SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY;
278279

279280
/// Should we check the target OSs of serialized modules to see that they're
280281
/// new enough?

include/swift/Config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88

99
#cmakedefine HAVE_PROC_PID_RUSAGE 1
1010

11+
#cmakedefine01 SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
12+
1113
#endif // SWIFT_CONFIG_H

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,11 +3075,13 @@ DynamicSelfType *DynamicSelfType::get(Type selfType, const ASTContext &ctx) {
30753075

30763076
static RecursiveTypeProperties
30773077
getFunctionRecursiveProperties(ArrayRef<AnyFunctionType::Param> params,
3078-
Type result) {
3078+
Type result, Type globalActor) {
30793079
RecursiveTypeProperties properties;
30803080
for (auto param : params)
30813081
properties |= param.getPlainType()->getRecursiveProperties();
30823082
properties |= result->getRecursiveProperties();
3083+
if (globalActor)
3084+
properties |= globalActor->getRecursiveProperties();
30833085
properties &= ~RecursiveTypeProperties::IsLValue;
30843086
return properties;
30853087
}
@@ -3274,7 +3276,11 @@ void FunctionType::Profile(llvm::FoldingSetNodeID &ID,
32743276

32753277
FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
32763278
Type result, Optional<ExtInfo> info) {
3277-
auto properties = getFunctionRecursiveProperties(params, result);
3279+
Type globalActor;
3280+
if (info.hasValue())
3281+
globalActor = info->getGlobalActor();
3282+
3283+
auto properties = getFunctionRecursiveProperties(params, result, globalActor);
32783284
auto arena = getArena(properties);
32793285

32803286
llvm::FoldingSetNodeID id;
@@ -3296,10 +3302,6 @@ FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
32963302
bool hasClangInfo =
32973303
info.hasValue() && !info.getValue().getClangTypeInfo().empty();
32983304

3299-
Type globalActor;
3300-
if (info.hasValue())
3301-
globalActor = info->getGlobalActor();
3302-
33033305
size_t allocSize = totalSizeToAlloc<
33043306
AnyFunctionType::Param, ClangTypeInfo, Type
33053307
>(params.size(), hasClangInfo ? 1 : 0, globalActor ? 1 : 0);
@@ -3393,7 +3395,7 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature sig,
33933395
if (info.hasValue())
33943396
globalActor = info->getGlobalActor();
33953397

3396-
if (globalActor && !globalActor->isCanonical())
3398+
if (globalActor && !sig->isCanonicalTypeInContext(globalActor))
33973399
isCanonical = false;
33983400

33993401
size_t allocSize = totalSizeToAlloc<AnyFunctionType::Param, Type>(

lib/AST/DiagnosticEngine.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,18 @@ static Type getAkaTypeForDisplay(Type type) {
475475
});
476476
}
477477

478+
/// Determine whether this is the main actor type.
479+
static bool isMainActor(Type type) {
480+
if (auto nominal = type->getAnyNominal()) {
481+
if (nominal->getName().is("MainActor") &&
482+
nominal->getParentModule()->getName() ==
483+
nominal->getASTContext().Id_Concurrency)
484+
return true;
485+
}
486+
487+
return false;
488+
}
489+
478490
/// Format a single diagnostic argument and write it to the given
479491
/// stream.
480492
static void formatDiagnosticArgument(StringRef Modifier,
@@ -710,18 +722,21 @@ static void formatDiagnosticArgument(StringRef Modifier,
710722
break;
711723

712724
case ActorIsolation::GlobalActor:
713-
case ActorIsolation::GlobalActorUnsafe:
714-
Out << "global actor " << FormatOpts.OpeningQuotationMark
715-
<< isolation.getGlobalActor().getString()
716-
<< FormatOpts.ClosingQuotationMark << "-isolated";
725+
case ActorIsolation::GlobalActorUnsafe: {
726+
Type globalActor = isolation.getGlobalActor();
727+
if (isMainActor(globalActor)) {
728+
Out << "main actor-isolated";
729+
} else {
730+
Out << "global actor " << FormatOpts.OpeningQuotationMark
731+
<< globalActor.getString()
732+
<< FormatOpts.ClosingQuotationMark << "-isolated";
733+
}
717734
break;
735+
}
718736

719737
case ActorIsolation::Independent:
720-
Out << "actor-independent";
721-
break;
722-
723738
case ActorIsolation::Unspecified:
724-
Out << "unspecified";
739+
Out << "nonisolated";
725740
break;
726741
}
727742
}

lib/AST/Stmt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ SwitchStmt *SwitchStmt::create(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc,
482482
SourceLoc LBraceLoc,
483483
ArrayRef<ASTNode> Cases,
484484
SourceLoc RBraceLoc,
485+
SourceLoc EndLoc,
485486
ASTContext &C) {
486487
#ifndef NDEBUG
487488
for (auto N : Cases)
@@ -494,7 +495,8 @@ SwitchStmt *SwitchStmt::create(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc,
494495
alignof(SwitchStmt));
495496
SwitchStmt *theSwitch = ::new (p) SwitchStmt(LabelInfo, SwitchLoc,
496497
SubjectExpr, LBraceLoc,
497-
Cases.size(), RBraceLoc);
498+
Cases.size(), RBraceLoc,
499+
EndLoc);
498500

499501
std::uninitialized_copy(Cases.begin(), Cases.end(),
500502
theSwitch->getTrailingObjects<ASTNode>());

lib/AST/Type.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,15 +3181,12 @@ operator()(SubstitutableType *maybeOpaqueType) const {
31813181
// archetype in question. This will map the inner generic signature of the
31823182
// opaque type to its outer signature.
31833183
auto partialSubstTy = archetype->getInterfaceType().subst(*subs);
3184-
// Then apply the substitutions from the root opaque archetype, to specialize
3185-
// for its type arguments.
3186-
auto substTy = partialSubstTy.subst(opaqueRoot->getSubstitutions());
31873184

31883185
// Check that we are allowed to substitute the underlying type into the
31893186
// context.
31903187
auto inContext = this->inContext;
31913188
auto isContextWholeModule = this->isContextWholeModule;
3192-
if (substTy.findIf(
3189+
if (partialSubstTy.findIf(
31933190
[inContext, substitutionKind, isContextWholeModule](Type t) -> bool {
31943191
if (!canSubstituteTypeInto(t, inContext, substitutionKind,
31953192
isContextWholeModule))
@@ -3198,6 +3195,12 @@ operator()(SubstitutableType *maybeOpaqueType) const {
31983195
}))
31993196
return maybeOpaqueType;
32003197

3198+
// Then apply the substitutions from the root opaque archetype, to specialize
3199+
// for its type arguments. We perform this substitution after checking for
3200+
// visibility, since we do not want the result of the visibility check to
3201+
// depend on the substitutions previously applied.
3202+
auto substTy = partialSubstTy.subst(opaqueRoot->getSubstitutions());
3203+
32013204
// If the type changed, but still contains opaque types, recur.
32023205
if (!substTy->isEqual(maybeOpaqueType) && substTy->hasOpaqueArchetype()) {
32033206
return ::substOpaqueTypesWithUnderlyingTypes(
@@ -3264,18 +3267,12 @@ operator()(CanType maybeOpaqueType, Type replacementType,
32643267
// archetype in question. This will map the inner generic signature of the
32653268
// opaque type to its outer signature.
32663269
auto partialSubstTy = archetype->getInterfaceType().subst(*subs);
3267-
auto partialSubstRef =
3268-
abstractRef.subst(archetype->getInterfaceType(), *subs);
3269-
3270-
// Then apply the substitutions from the root opaque archetype, to specialize
3271-
// for its type arguments.
3272-
auto substTy = partialSubstTy.subst(opaqueRoot->getSubstitutions());
32733270

32743271
// Check that we are allowed to substitute the underlying type into the
32753272
// context.
32763273
auto inContext = this->inContext;
32773274
auto isContextWholeModule = this->isContextWholeModule;
3278-
if (substTy.findIf(
3275+
if (partialSubstTy.findIf(
32793276
[inContext, substitutionKind, isContextWholeModule](Type t) -> bool {
32803277
if (!canSubstituteTypeInto(t, inContext, substitutionKind,
32813278
isContextWholeModule))
@@ -3284,6 +3281,14 @@ operator()(CanType maybeOpaqueType, Type replacementType,
32843281
}))
32853282
return abstractRef;
32863283

3284+
// Then apply the substitutions from the root opaque archetype, to specialize
3285+
// for its type arguments. We perform this substitution after checking for
3286+
// visibility, since we do not want the result of the visibility check to
3287+
// depend on the substitutions previously applied.
3288+
auto substTy = partialSubstTy.subst(opaqueRoot->getSubstitutions());
3289+
3290+
auto partialSubstRef =
3291+
abstractRef.subst(archetype->getInterfaceType(), *subs);
32873292
auto substRef =
32883293
partialSubstRef.subst(partialSubstTy, opaqueRoot->getSubstitutions());
32893294

@@ -4879,6 +4884,17 @@ case TypeKind::Id:
48794884
if (resultTy.getPointer() != function->getResult().getPointer())
48804885
isUnchanged = false;
48814886

4887+
// Transform the global actor.
4888+
Type globalActorType;
4889+
if (Type origGlobalActorType = function->getGlobalActor()) {
4890+
globalActorType = origGlobalActorType.transformRec(fn);
4891+
if (!globalActorType)
4892+
return Type();
4893+
4894+
if (globalActorType.getPointer() != origGlobalActorType.getPointer())
4895+
isUnchanged = false;
4896+
}
4897+
48824898
if (auto genericFnType = dyn_cast<GenericFunctionType>(base)) {
48834899
#ifndef NDEBUG
48844900
// Check that generic parameters won't be trasnformed.
@@ -4895,15 +4911,17 @@ case TypeKind::Id:
48954911
if (!function->hasExtInfo())
48964912
return GenericFunctionType::get(genericSig, substParams, resultTy);
48974913
return GenericFunctionType::get(genericSig, substParams, resultTy,
4898-
function->getExtInfo());
4914+
function->getExtInfo()
4915+
.withGlobalActor(globalActorType));
48994916
}
49004917

49014918
if (isUnchanged) return *this;
49024919

49034920
if (!function->hasExtInfo())
49044921
return FunctionType::get(substParams, resultTy);
49054922
return FunctionType::get(substParams, resultTy,
4906-
function->getExtInfo());
4923+
function->getExtInfo()
4924+
.withGlobalActor(globalActorType));
49074925
}
49084926

49094927
case TypeKind::ArraySlice: {

lib/Index/Index.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/Comment.h"
1717
#include "swift/AST/Decl.h"
1818
#include "swift/AST/Expr.h"
19+
#include "swift/AST/GenericParamList.h"
1920
#include "swift/AST/Module.h"
2021
#include "swift/AST/ParameterList.h"
2122
#include "swift/AST/ProtocolConformance.h"
@@ -439,6 +440,57 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
439440
return true;
440441
}
441442

443+
/// Extensions redeclare all generic parameters of their extended type to add
444+
/// their additional restrictions. There are two issues with this model for
445+
/// indexing:
446+
/// - The generic paramter declarations of the extension are implicit so we
447+
/// wouldn't report them in the index. Any usage of the generic param in
448+
/// the extension references this implicit declaration so we don't include
449+
/// it in the index either.
450+
/// - The implicit re-declarations have their own USRs so any usage of a
451+
/// generic parameter inside an extension would use a different USR than
452+
/// declaration of the param in the extended type.
453+
///
454+
/// To fix these issues, we replace the reference to the implicit generic
455+
/// parameter defined in the extension by a reference to the generic paramter
456+
/// defined in the extended type.
457+
///
458+
/// \returns the canonicalized replaced generic param decl if it can be found
459+
/// or \p GenParam otherwise.
460+
ValueDecl *
461+
canonicalizeGenericTypeParamDeclForIndex(GenericTypeParamDecl *GenParam) {
462+
auto Extension = dyn_cast_or_null<ExtensionDecl>(
463+
GenParam->getDeclContext()->getAsDecl());
464+
if (!Extension) {
465+
// We are not referencing a generic paramter defined in an extension.
466+
// Nothing to do.
467+
return GenParam;
468+
}
469+
assert(GenParam->isImplicit() &&
470+
"Generic param decls in extension should always be implicit and "
471+
"shadow a generic param in the extended type.");
472+
assert(Extension->getExtendedNominal() &&
473+
"The implict generic types on the extension should only be created "
474+
"if the extended type was found");
475+
476+
auto ExtendedTypeGenSig =
477+
Extension->getExtendedNominal()->getGenericSignature();
478+
assert(ExtendedTypeGenSig && "Extension is generic but extended type not?");
479+
480+
// The generic parameter in the extension has the same depths and index
481+
// as the one in the extended type.
482+
for (auto ExtendedTypeGenParam : ExtendedTypeGenSig->getGenericParams()) {
483+
if (ExtendedTypeGenParam->getIndex() == GenParam->getIndex() &&
484+
ExtendedTypeGenParam->getDepth() == GenParam->getDepth()) {
485+
assert(ExtendedTypeGenParam->getDecl() &&
486+
"The generic parameter defined on the extended type cannot be "
487+
"implicit.");
488+
return ExtendedTypeGenParam->getDecl();
489+
}
490+
}
491+
llvm_unreachable("Can't find the generic parameter in the extended type");
492+
}
493+
442494
bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
443495
TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef, Type T,
444496
ReferenceMetaData Data) override {
@@ -455,6 +507,11 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
455507
if (CtorTyRef)
456508
if (!reportRef(CtorTyRef, Loc, Info, Data.AccKind))
457509
return false;
510+
511+
if (auto *GenParam = dyn_cast<GenericTypeParamDecl>(D)) {
512+
D = canonicalizeGenericTypeParamDeclForIndex(GenParam);
513+
}
514+
458515
if (!reportRef(D, Loc, Info, Data.AccKind))
459516
return false;
460517

0 commit comments

Comments
 (0)