Skip to content

Commit 888bffa

Browse files
Merge pull request #4830 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents d7c0356 + 4c347d2 commit 888bffa

File tree

5 files changed

+88
-5
lines changed

5 files changed

+88
-5
lines changed

lib/IDE/CodeCompletionResultType.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
194194
return USRBasedType::null(Arena);
195195
}
196196

197+
// ParameterizedProtocolType should always be wrapped in ExistentialType and
198+
// cannot be mangled on its own.
199+
// But ParameterizedProtocolType can currently occur in 'typealias'
200+
// declarations. rdar://99176683
201+
// To avoid crashing in USR generation, simply return a null type until the
202+
// underlying issue has been fixed.
203+
if (Ty->is<ParameterizedProtocolType>()) {
204+
return USRBasedType::null(Arena);
205+
}
206+
197207
SmallString<32> USR;
198208
llvm::raw_svector_ostream OS(USR);
199209
printTypeUSR(Ty, OS);

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,23 @@ swift::determineClosureActorIsolation(AbstractClosureExpr *closure) {
30553055
return checker.determineClosureIsolation(closure);
30563056
}
30573057

3058+
/// Determine whethere there is an explicit isolation attribute
3059+
/// of any kind.
3060+
static bool hasExplicitIsolationAttribute(const Decl *decl) {
3061+
if (auto nonisolatedAttr =
3062+
decl->getAttrs().getAttribute<NonisolatedAttr>()) {
3063+
if (!nonisolatedAttr->isImplicit())
3064+
return true;
3065+
}
3066+
3067+
if (auto globalActorAttr = decl->getGlobalActorAttr()) {
3068+
if (!globalActorAttr->first->isImplicit())
3069+
return true;
3070+
}
3071+
3072+
return false;
3073+
}
3074+
30583075
/// Determine actor isolation solely from attributes.
30593076
///
30603077
/// \returns the actor isolation determined from attributes alone (with no
@@ -4025,8 +4042,7 @@ bool swift::contextRequiresStrictConcurrencyChecking(
40254042
} else if (auto decl = dc->getAsDecl()) {
40264043
// If any isolation attributes are present, we're using concurrency
40274044
// features.
4028-
if (getIsolationFromAttributes(
4029-
decl, /*shouldDiagnose=*/false, /*onlyExplicit=*/true))
4045+
if (hasExplicitIsolationAttribute(decl))
40304046
return true;
40314047

40324048
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
@@ -4037,9 +4053,7 @@ bool swift::contextRequiresStrictConcurrencyChecking(
40374053
// If we're in an accessor declaration, also check the storage
40384054
// declaration.
40394055
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
4040-
if (getIsolationFromAttributes(
4041-
accessor->getStorage(), /*shouldDiagnose=*/false,
4042-
/*onlyExplicit=*/true))
4056+
if (hasExplicitIsolationAttribute(accessor->getStorage()))
40434057
return true;
40444058
}
40454059
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %empty-directory(%t/split)
2+
// RUN: %empty-directory(%t/build)
3+
// RUN: %{python} %utils/split_file.py -o %t/split %s
4+
5+
// RUN: %target-swift-frontend -emit-module -o %t/build %t/split/pck.swift
6+
7+
// RUN: %target-swift-ide-test -code-completion -source-filename %t/split/test.swift -I %t/build -code-completion-token=COMPLETE | %FileCheck %s
8+
9+
// BEGIN pck.swift
10+
11+
public protocol Foo<Bar> {
12+
associatedtype Bar
13+
}
14+
15+
public typealias Problem = Foo<String>
16+
17+
public protocol EmptyProto {}
18+
public typealias ConstrainedBar<T: EmptyProto> = Foo<T>
19+
20+
// BEGIN test.swift
21+
22+
import pck
23+
24+
#^COMPLETE^#
25+
26+
// CHECK: Begin completions
27+
// CHECK-DAG: Decl[Protocol]/OtherModule[pck]/Flair[RareType]: Foo[#Foo#];
28+
// CHECK-DAG: Decl[TypeAlias]/OtherModule[pck]: Problem[#Foo<String>#];
29+
// CHECK-DAG: Decl[TypeAlias]/OtherModule[pck]: ConstrainedBar[#Foo<T>#];
30+
// CHECK: End completions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Testing that these requests don't crash
2+
3+
public protocol Foo<Bar> {
4+
associatedtype Bar
5+
}
6+
// RUN: %sourcekitd-test -req=cursor -pos=%(line+1):11 %s -- %s
7+
typealias Problem = Foo<String>
8+
9+
protocol EmptyProto {}
10+
// RUN: %sourcekitd-test -req=cursor -pos=%(line+1):11 %s -- %s
11+
typealias ConstrainedBar<T: EmptyProto> = Foo<T>
12+
// RUN: %sourcekitd-test -req=cursor -pos=%(line+1):11 %s -- %s
13+
typealias ConstrainedBarMetatype<T: P> = Foo<T>.Type

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,22 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
948948
}
949949
Symbol.TypeName = copyAndClearString(Allocator, Buffer);
950950

951+
// ParameterizedProtocolType should always be wrapped in ExistentialType and
952+
// cannot be mangled on its own.
953+
// But ParameterizedProtocolType can currently occur in 'typealias'
954+
// declarations. rdar://99176683
955+
// To avoid crashing in USR generation, return an error for now.
956+
if (auto Ty = DInfo.VD->getInterfaceType()) {
957+
while (auto MetaTy = Ty->getAs<MetatypeType>()) {
958+
Ty = MetaTy->getInstanceType();
959+
}
960+
if (Ty && Ty->getCanonicalType()->is<ParameterizedProtocolType>()) {
961+
return llvm::createStringError(
962+
llvm::inconvertibleErrorCode(),
963+
"Cannot mangle USR for ParameterizedProtocolType without 'any'.");
964+
}
965+
}
966+
951967
SwiftLangSupport::printDeclTypeUSR(DInfo.VD, OS);
952968
Symbol.TypeUSR = copyAndClearString(Allocator, Buffer);
953969

0 commit comments

Comments
 (0)