Skip to content

Commit 231dfd3

Browse files
authored
Merge pull request #30775 from aschwaighofer/irgen_fix_broken_ast_5.2
[5.2] IRGen: Deal with broken AST from batch mode
2 parents 960408c + 190289b commit 231dfd3

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,11 @@ static bool isDependentConformance(
904904

905905
auto assocConformance =
906906
conformance->getAssociatedConformance(req.getFirstType(), assocProtocol);
907+
908+
// We migh be presented with a broken AST.
909+
if (assocConformance.isInvalid())
910+
return false;
911+
907912
if (assocConformance.isAbstract() ||
908913
isDependentConformance(IGM,
909914
assocConformance.getConcrete()

lib/IRGen/GenType.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,9 +1754,12 @@ const TypeInfo *TypeConverter::convertType(CanType ty) {
17541754
PrettyStackTraceType stackTrace(IGM.Context, "converting", ty);
17551755

17561756
switch (ty->getKind()) {
1757-
case TypeKind::Error:
1758-
llvm_unreachable("found an ErrorType in IR-gen");
1759-
1757+
case TypeKind::Error: {
1758+
// We might see error types if type checking has failed.
1759+
// Try to do something graceful and return an zero sized type.
1760+
auto &ctx = ty->getASTContext();
1761+
return convertTupleType(cast<TupleType>(ctx.TheEmptyTupleType));
1762+
}
17601763
#define UNCHECKED_TYPE(id, parent) \
17611764
case TypeKind::id: \
17621765
llvm_unreachable("found a " #id "Type in IR-gen");
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
3+
@objc
4+
protocol SomeProto {
5+
func conform()
6+
}
7+
8+
class AnotherClass {}
9+
10+
class SomeClass {
11+
// Intentionally referencing the wrong class name.
12+
var x : AnotherClass2? = nil
13+
}
14+
15+
protocol P {}
16+
protocol WithAssoc {
17+
associatedtype AssocType : P
18+
}
19+
20+
struct BuggyConformer : WithAssoc {
21+
typealias AssocType = Int
22+
}

test/IRGen/batchmode_ast_errors.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: not %target-swift-frontend -primary-file %s %S/Inputs/batchmode_errors.swift -emit-ir 2>&1 | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// Verify that we don't crash (in IRGen).
6+
7+
// CHECK-NOT: Stack dump
8+
9+
extension SomeClass : SomeProto {
10+
func conform() {}
11+
}
12+
13+
func genericParam<T: WithAssoc>(_ t: T) {
14+
}
15+
16+
func testBuggyGenericParam() {
17+
genericParam(BuggyConformer())
18+
}

0 commit comments

Comments
 (0)