Skip to content

Commit 7ed3d75

Browse files
committed
[Serialization] Allow unbound generic types to cross-reference typealias decls
Ideally `UnboundGenericType` should never be serialized but it is currently allowed to make generic `typealias` declarations without specifying generic parameters, so it should be allowed to cross reference typealias decls in such types as well because `NameAliasType` can't be used until generic parameters are resolved. This is only a temporary fix and more comprehensive solution is still pending here, most likely such declarations should not produce `UnboundGenericType` but instead should copy generic parameters from underlying type and produce proper `NameAliasType`. Resolves: rdar://problem/37384120
1 parent a53cf99 commit 7ed3d75

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3943,7 +3943,9 @@ void Serializer::writeType(Type ty) {
39433943

39443944
unsigned abbrCode = DeclTypeAbbrCodes[UnboundGenericTypeLayout::Code];
39453945
UnboundGenericTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
3946-
addDeclRef(generic->getDecl()),
3946+
addDeclRef(generic->getDecl(),
3947+
/*forceSerialization*/false,
3948+
/*allowTypeAliasXRef*/true),
39473949
addTypeRef(generic->getParent()));
39483950
break;
39493951
}

test/Serialization/Inputs/alias.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ public struct Outer { public typealias G<T> = T }
3636
public typealias GG = Outer.G
3737

3838
public typealias GInt = Outer.G<Int>
39+
40+
public struct UnboundStruct<T> {}
41+
public typealias UnboundAlias<T: Comparable> = UnboundStruct<T>

test/Serialization/typealias.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-build-swift -module-name alias -emit-module -o %t %S/Inputs/alias.swift
3+
// RUN: %target-build-swift -I %t %s -module-name typealias -emit-module-path %t/typealias.swiftmodule -o %t/typealias.o
34
// RUN: llvm-bcanalyzer %t/alias.swiftmodule | %FileCheck %s
45
// RUN: %target-build-swift -I %t %s -o %t/a.out
56
// RUN: %target-run %t/a.out | %FileCheck -check-prefix=OUTPUT %s
@@ -53,3 +54,5 @@ func check(_: BaseAlias) {
5354

5455
let x: GG<Int> = 0
5556
let x2: GInt = 1
57+
58+
public typealias TestUnbound = UnboundAlias

0 commit comments

Comments
 (0)