Skip to content

Commit 3e61fad

Browse files
authored
Merge pull request #37476 from bnbarham/5.5-cherry-rdar78048470
[5.5][Serialization] Do not assert when inherited type is null
2 parents 38e1c3b + 5d116be commit 3e61fad

File tree

5 files changed

+196
-132
lines changed

5 files changed

+196
-132
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,10 +3066,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
30663066

30673067
SmallVector<TypeID, 8> inheritedAndDependencyTypes;
30683068
for (auto inherited : extension->getInherited()) {
3069-
if (extension->getASTContext().LangOpts.AllowModuleWithCompilerErrors &&
3070-
!inherited.getType())
3071-
continue;
3072-
assert(!inherited.getType()->hasArchetype());
3069+
assert(!inherited.getType() || !inherited.getType()->hasArchetype());
30733070
inheritedAndDependencyTypes.push_back(S.addTypeRef(inherited.getType()));
30743071
}
30753072
size_t numInherited = inheritedAndDependencyTypes.size();
@@ -3307,7 +3304,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
33073304

33083305
SmallVector<TypeID, 4> inheritedAndDependencyTypes;
33093306
for (auto inherited : theStruct->getInherited()) {
3310-
assert(!inherited.getType()->hasArchetype());
3307+
assert(!inherited.getType() || !inherited.getType()->hasArchetype());
33113308
inheritedAndDependencyTypes.push_back(S.addTypeRef(inherited.getType()));
33123309
}
33133310

@@ -3352,7 +3349,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
33523349

33533350
SmallVector<TypeID, 4> inheritedAndDependencyTypes;
33543351
for (auto inherited : theEnum->getInherited()) {
3355-
assert(!inherited.getType()->hasArchetype());
3352+
assert(!inherited.getType() || !inherited.getType()->hasArchetype());
33563353
inheritedAndDependencyTypes.push_back(S.addTypeRef(inherited.getType()));
33573354
}
33583355

@@ -3410,7 +3407,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
34103407

34113408
SmallVector<TypeID, 4> inheritedAndDependencyTypes;
34123409
for (auto inherited : theClass->getInherited()) {
3413-
assert(!inherited.getType()->hasArchetype());
3410+
assert(!inherited.getType() || !inherited.getType()->hasArchetype());
34143411
inheritedAndDependencyTypes.push_back(S.addTypeRef(inherited.getType()));
34153412
}
34163413

@@ -3468,10 +3465,11 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
34683465
llvm::SmallSetVector<Type, 4> dependencyTypes;
34693466

34703467
for (auto element : proto->getInherited()) {
3471-
assert(!element.getType()->hasArchetype());
3472-
inheritedAndDependencyTypes.push_back(S.addTypeRef(element.getType()));
3473-
if (element.getType()->is<ProtocolType>())
3474-
dependencyTypes.insert(element.getType());
3468+
auto elementType = element.getType();
3469+
assert(!elementType || !elementType->hasArchetype());
3470+
inheritedAndDependencyTypes.push_back(S.addTypeRef(elementType));
3471+
if (elementType && elementType->is<ProtocolType>())
3472+
dependencyTypes.insert(elementType);
34753473
}
34763474

34773475
for (Requirement req : proto->getRequirementSignature()) {

test/Frontend/allow-errors.swift

Lines changed: 6 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,11 @@
11
// RUN: %empty-directory(%t)
22

3-
// The module should be generated regardless of errors and diagnostic should still be output
4-
// RUN: %target-swift-frontend -verify -emit-module -o %t/errors.swiftmodule -emit-reference-dependencies-path %t/errors.swiftdeps -emit-dependencies-path %t/errors.d -experimental-allow-module-with-compiler-errors -D ERROR_MODULE -primary-file %s
3+
// The module should be generated regardless of errors, including .swiftdeps, .d,
4+
// .swiftsourceinfo, etc. Diagnostics should still be output as well
5+
6+
// RUN: %target-swift-frontend -verify -emit-module -o %t/errors.swiftmodule -emit-module-source-info -emit-module-doc -emit-reference-dependencies-path %t/errors.swiftdeps -emit-dependencies-path %t/errors.d -experimental-allow-module-with-compiler-errors -primary-file %s
57
// RUN: llvm-bcanalyzer %t/errors.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
8+
// RUN: ls %t/errors.swiftdeps %t/errors.d %t/errors.swiftsourceinfo %t/errors.swiftdoc
69
// CHECK-BC-NOT: UnknownCode
7-
// RUN: ls %t/errors.swiftdeps
8-
// RUN: ls %t/errors.d
9-
10-
#if ERROR_MODULE
11-
public struct ValidStructInvalidMember {
12-
public var member: String
13-
public let memberMissingType: undefined // expected-error {{cannot find type 'undefined'}}
14-
15-
public var memberMissingTypeValidSets: undefined { // expected-error {{cannot find type 'undefined'}}
16-
willSet {
17-
print("Setting value \(newValue)")
18-
}
19-
didSet {
20-
print("Set value \(oldValue)")
21-
}
22-
}
23-
public var memberInvalidSets: Int {
24-
willSet {
25-
undefined // expected-error {{cannot find 'undefined'}}
26-
}
27-
didSet {
28-
undefined // expected-error {{cannot find 'undefined'}}
29-
}
30-
}
31-
32-
public lazy var lazyMemberMissingTypeValidBody: undefined = { // expected-error {{cannot find type 'undefined'}}
33-
return ""
34-
}()
35-
public lazy var lazyMemberInvalidBody: String = {
36-
return undefined // expected-error {{cannot find 'undefined'}}
37-
}()
38-
39-
public var memberMissingTypeValidGetSets: String {
40-
get { member }
41-
set { member = "" }
42-
}
43-
public var memberInvalidGetSet: String {
44-
get { undefined } // expected-error {{cannot find 'undefined'}}
45-
set { undefined = "" } // expected-error {{cannot find 'undefined'}}
46-
}
47-
48-
public func funcBadArg(_ arg: undefined? = nil) {} // expected-error {{cannot find type 'undefined'}}
49-
}
50-
51-
public func validFunc() -> String { "" }
52-
53-
public func invalidFuncBody() -> ValidStructInvalidMember {
54-
ret // expected-error {{cannot find 'ret'}}
55-
}
56-
57-
public func invalidFunc() -> undefined {} // expected-error {{cannot find type 'undefined'}}
58-
59-
extension undefined: undefined {} // expected-error {{cannot find type 'undefined'}}
60-
61-
class GenericClass<T> {}
62-
class InvalidSuperclass: GenericClass<undefined> {} // expected-error {{cannot find type 'undefined'}}
63-
#endif
64-
65-
// RUN: %target-swift-frontend -emit-module -o %t/validUses.swiftmodule -experimental-allow-module-with-compiler-errors -I%t -D VALID_USES %s 2>&1 | %FileCheck -check-prefix=CHECK-VALID %s
66-
// RUN: llvm-bcanalyzer %t/validUses.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
67-
#if VALID_USES
68-
import errors
69-
func test(s: ValidStructInvalidMember) {
70-
print(s.member)
71-
print(validFunc())
72-
print(invalidFuncBody())
73-
}
74-
75-
// Check SIL diagnostics are still output (no reason not to output SIL since
76-
// there were no errors)
77-
func other() -> Int {}
78-
// CHECK-VALID: allow-errors.swift:[[@LINE-1]]:22: error: missing return in a function expected to return 'Int'
79-
func other2() -> Bool {}
80-
// CHECK-VALID: allow-errors.swift:[[@LINE-1]]:24: error: missing return in a function expected to return 'Bool'
81-
#endif
82-
83-
// All invalid uses should have no errors in the file itself, all referenced
84-
// invalid declarations should have an error elsewhere (but we don't care what
85-
// that location is)
86-
87-
// RUN: %target-swift-frontend -emit-module -o %t/invalidTopUse.swiftmodule -experimental-allow-module-with-compiler-errors -I%t -D INVALID_TOP_LEVEL_USE %s 2>&1 | %FileCheck -check-prefix=CHECK-INVALID-TOP %s
88-
// RUN: llvm-bcanalyzer %t/invalidTopUse.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
89-
#if INVALID_TOP_LEVEL_USE
90-
import errors
91-
func test() {
92-
invalidFunc()
93-
}
94-
// CHECK-INVALID-TOP-NOT: allow-errors.swift:{{.*}} error:
95-
// CHECK-INVALID-TOP: error: allowing deserialization of error type '<null>' in module 'errors'
96-
// CHECK-INVALID-TOP: error: allowing deserialization of invalid declaration 'invalidFunc()' (global function) in module 'errors'
97-
// CHECK-INVALID-TOP-NOT: allow-errors.swift:{{.*}} error:
98-
#endif
99-
100-
// RUN: %target-swift-frontend -emit-module -o %t/invalidMemberUse.swiftmodule -experimental-allow-module-with-compiler-errors -I%t -D INVALID_MEMBER_USE %s 2>&1 | %FileCheck -check-prefix=CHECK-INVALID-MEMBER %s
101-
// RUN: llvm-bcanalyzer %t/invalidMemberUse.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
102-
#if INVALID_MEMBER_USE
103-
import errors
104-
func test(s: ValidStructInvalidMember) {
105-
print(s.memberMissingType)
106-
}
107-
// CHECK-INVALID-MEMBER-NOT: allow-errors.swift:{{.*}} error:
108-
// CHECK-INVALID-MEMBER: error: allowing deserialization of error type '<null>' in module 'errors'
109-
// CHECK-INVALID-MEMBER: error: allowing deserialization of invalid declaration '_' (getter) in module 'errors'
110-
// CHECK-INVALID-MEMBER: error: allowing deserialization of invalid declaration 'memberMissingType' (property) in module 'errors'
111-
// CHECK-INVALID-MEMBER-NOT: allow-errors.swift:{{.*}} error:
112-
#endif
11310

114-
// RUN: %target-swift-frontend -emit-module -o %t/invalidMethodUse.swiftmodule -experimental-allow-module-with-compiler-errors -I%t -D INVALID_METHOD_USE %s 2>&1 | %FileCheck -check-prefix=CHECK-INVALID-METHOD %s
115-
// RUN: llvm-bcanalyzer %t/invalidMethodUse.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
116-
#if INVALID_METHOD_USE
117-
import errors
118-
func test(s: ValidStructInvalidMember) {
119-
s.funcBadArg()
120-
}
121-
// CHECK-INVALID-METHOD-NOT: allow-errors.swift:{{.*}} error:
122-
// CHECK-INVALID-METHOD: error: allowing deserialization of error type '<null>' in module 'errors'
123-
// CHECK-INVALID-METHOD: error: allowing deserialization of invalid declaration 'arg' (parameter) in module 'errors'
124-
// CHECK-INVALID-METHOD: error: allowing deserialization of invalid declaration 'funcBadArg' (instance method) in module 'errors'
125-
// CHECK-INVALID-METHOD-NOT: allow-errors.swift:{{.*}} error:
126-
#endif
11+
public func invalid() -> undefined {} // expected-error {{cannot find type 'undefined'}}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/mods)
3+
4+
// RUN: touch %t/empty.swift
5+
// RUN: %{python} %utils/split_file.py -o %t %s
6+
7+
// Errors often only occur during merging, hence creating an empty module here
8+
// RUN: %target-swift-frontend -verify -module-name errors -emit-module -o %t/mods/errorsmain.partial.swiftmodule -experimental-allow-module-with-compiler-errors %t/errors.swift
9+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsempty.partial.swiftmodule %t/empty.swift
10+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule -experimental-allow-module-with-compiler-errors %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule
11+
12+
// RUN: %target-swift-frontend -emit-module -o %t/mods/uses.swiftmodule -experimental-allow-module-with-compiler-errors -I %t/mods %t/uses.swift 2>&1 | %FileCheck -check-prefix=CHECK-USES %s
13+
14+
// BEGIN errors.swift
15+
public protocol SomeProto: undefined {} // expected-error {{cannot find type 'undefined'}}
16+
public class SomeClass: undefined {} // expected-error {{cannot find type 'undefined'}}
17+
public struct SomeStruct: undefined {} // expected-error {{cannot find type 'undefined'}}
18+
public enum SomeEnum: undefined { // expected-error {{cannot find type 'undefined'}}
19+
case a
20+
}
21+
22+
public class GenericClass<T> {}
23+
public class InvalidGenericSuperclass: GenericClass<undefined> {} // expected-error {{cannot find type 'undefined'}}
24+
25+
extension SomeClass: undefined {} // expected-error {{cannot find type 'undefined'}}
26+
extension SomeStruct: undefined {} // expected-error {{cannot find type 'undefined'}}
27+
extension SomeEnum: undefined {} // expected-error {{cannot find type 'undefined'}}
28+
29+
extension undefined {} // expected-error {{cannot find type 'undefined'}}
30+
extension undefined: undefined {} // expected-error {{cannot find type 'undefined'}}
31+
extension undefined: SomeProto {} // expected-error {{cannot find type 'undefined'}}
32+
33+
public extension undefined { // expected-error {{cannot find type 'undefined' in scope}}
34+
protocol SomeProtoInner: undefined {} // expected-error {{cannot find type 'undefined' in scope}}
35+
// TODO: Why don't these have errors?
36+
class SomeClassInner: undefined {}
37+
struct SomeStructInner: undefined {}
38+
enum SomeEnumInner: undefined { // expected-error {{cannot find type 'undefined' in scope}}
39+
case a
40+
}
41+
class InvalidGenericSuperclassInner: GenericClass<undefined> {} // expected-error {{cannot find type 'undefined' in scope}}
42+
}
43+
44+
45+
// BEGIN uses.swift
46+
import errors
47+
func test(p: SomeProto, c: SomeClass, s: SomeStruct, e: SomeEnum, g: InvalidGenericSuperclass) {}
48+
// CHECK-USES-NOT: cannot find type 'SomeProto' in scope
49+
// CHECK-USES-NOT: cannot find type 'SomeClass' in scope
50+
// CHECK-USES-NOT: cannot find type 'SomeStruct' in scope
51+
// CHECK-USES-NOT: cannot find type 'SomeEnum' in scope
52+
// CHECK-USES-NOT: cannot find type 'InvalidGenericSuperclass' in scope
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/mods)
3+
4+
// RUN: touch %t/empty.swift
5+
// RUN: %{python} %utils/split_file.py -o %t %s
6+
7+
// Errors often only occur during merging, hence creating an empty module here
8+
// RUN: %target-swift-frontend -verify -module-name errors -emit-module -o %t/mods/errorsmain.partial.swiftmodule -experimental-allow-module-with-compiler-errors %t/errors.swift
9+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsempty.partial.swiftmodule %t/empty.swift
10+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule -experimental-allow-module-with-compiler-errors %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule
11+
12+
// RUN: %target-swift-frontend -emit-module -o %t/mods/uses.swiftmodule -experimental-allow-module-with-compiler-errors -I %t/mods %t/uses.swift 2>&1 | %FileCheck -check-prefix=CHECK-USES %s
13+
14+
// BEGIN errors.swift
15+
public struct ValidStructInvalidMember {
16+
public var member: String
17+
public let memberMissingType: undefined // expected-error {{cannot find type 'undefined'}}
18+
19+
public var memberMissingTypeValidSets: undefined { // expected-error {{cannot find type 'undefined'}}
20+
willSet {
21+
print("Setting value \(newValue)")
22+
}
23+
didSet {
24+
print("Set value \(oldValue)")
25+
}
26+
}
27+
public var memberInvalidSets: Int {
28+
willSet {
29+
undefined // expected-error {{cannot find 'undefined'}}
30+
}
31+
didSet {
32+
undefined // expected-error {{cannot find 'undefined'}}
33+
}
34+
}
35+
36+
public lazy var lazyMemberMissingTypeValidBody: undefined = { // expected-error {{cannot find type 'undefined'}}
37+
return ""
38+
}()
39+
public lazy var lazyMemberInvalidBody: String = {
40+
return undefined // expected-error {{cannot find 'undefined'}}
41+
}()
42+
43+
public var memberMissingTypeValidGetSets: String {
44+
get { member }
45+
set { member = "" }
46+
}
47+
public var memberInvalidGetSet: String {
48+
get { undefined } // expected-error {{cannot find 'undefined'}}
49+
set { undefined = "" } // expected-error {{cannot find 'undefined'}}
50+
}
51+
52+
public func someFunc() {}
53+
public func funcBadArg(_ arg: undefined? = nil) {} // expected-error {{cannot find type 'undefined'}}
54+
}
55+
56+
57+
// BEGIN uses.swift
58+
import errors
59+
60+
func test(s: ValidStructInvalidMember) {
61+
s.someFunc()
62+
s.BOOOP()
63+
print(s.member)
64+
65+
s.funcBadArg()
66+
print(s.memberMissingType)
67+
}
68+
69+
// CHECK-USES-NOT: has no member 'someFunc'
70+
// CHECK-USES-NOT: has no member 'member'
71+
// CHECK-USES-NOT: has no member 'funcBadArg'
72+
// CHECK-USES-NOT: has no member 'memberMissingType'
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/mods)
3+
4+
// RUN: touch %t/empty.swift
5+
// RUN: %{python} %utils/split_file.py -o %t %s
6+
7+
// Errors often only occur during merging, hence creating an empty module here
8+
// RUN: %target-swift-frontend -verify -module-name errors -emit-module -o %t/mods/errorsmain.partial.swiftmodule -experimental-allow-module-with-compiler-errors %t/errors.swift
9+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsempty.partial.swiftmodule %t/empty.swift
10+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule -experimental-allow-module-with-compiler-errors %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule
11+
12+
// RUN: %target-swift-frontend -emit-module -o %t/mods/validUses.swiftmodule -experimental-allow-module-with-compiler-errors -I%t/mods %t/valid-uses.swift 2>&1 | %FileCheck -check-prefix=CHECK-VALID %s
13+
14+
// RUN: %target-swift-frontend -emit-module -o %t/mods/invalidUses.swiftmodule -experimental-allow-module-with-compiler-errors -I%t/mods %t/invalid-uses.swift 2>&1 | %FileCheck -check-prefix=CHECK-INVALID %s
15+
16+
// BEGIN errors.swift
17+
public struct ValidType {}
18+
19+
public func validFunc() -> ValidType { return ValidType() }
20+
21+
public func invalidFuncBody() -> ValidType {
22+
ret // expected-error {{cannot find 'ret'}}
23+
}
24+
25+
public func invalidFuncRet() -> undefined {} // expected-error {{cannot find type 'undefined'}}
26+
27+
28+
// BEGIN valid-uses.swift
29+
import errors
30+
31+
func test(s: ValidType) {
32+
print(validFunc())
33+
print(invalidFuncBody())
34+
}
35+
36+
// Check SIL diagnostics are still output (no reason not to output SIL since
37+
// there were no errors)
38+
func other() -> Int {}
39+
// CHECK-VALID: valid-uses.swift:10:22: error: missing return
40+
func other2() -> Bool {}
41+
// CHECK-VALID: valid-uses.swift:12:24: error: missing return
42+
43+
44+
// BEGIN invalid-uses.swift
45+
import errors
46+
47+
func test() {
48+
invalidFuncRet()
49+
}
50+
51+
// All invalid uses should have no errors in the file itself - all referenced
52+
// invalid declarations should have an error elsewhere (but we don't care what
53+
// that location is)
54+
// CHECK-INVALID-NOT: invalid-uses.swift:{{.*}} error:
55+
// CHECK-INVALID: error: allowing deserialization of error type '<null>' in module 'errors'
56+
// CHECK-INVALID: error: allowing deserialization of invalid declaration 'invalidFuncRet()' (global function) in module 'errors'
57+
// CHECK-INVALID-NOT: invalid-uses.swift:{{.*}} error:

0 commit comments

Comments
 (0)