Skip to content

Commit 18d5fdb

Browse files
committed
IRGen: Don't attempt to emit debug info for type-erased generic params.
Fixes a crash when emitting debug info for ObjC generic extensions. Part of rdar://problem/26867815.
1 parent ff1875f commit 18d5fdb

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ static bool isTypeErasedGenericClassType(CanType type) {
267267
}
268268

269269
// Get the type that exists at runtime to represent a compile-time type.
270-
static CanType
271-
getRuntimeReifiedType(IRGenModule &IGM, CanType type) {
270+
CanType
271+
irgen::getRuntimeReifiedType(IRGenModule &IGM, CanType type) {
272272
return CanType(type.transform([&](Type t) -> Type {
273273
if (isTypeErasedGenericClassType(CanType(t))) {
274274
return t->getAnyNominal()->getDeclaredType()->getCanonicalType();

lib/IRGen/GenMeta.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ namespace irgen {
8585
CanType type,
8686
SymbolReferenceKind refKind);
8787

88+
/// Get the type as it exists in Swift's runtime type system, removing any
89+
/// erased generic parameters.
90+
CanType getRuntimeReifiedType(IRGenModule &IGM, CanType type);
91+
8892
/// Emit a reference to a compile-time constant piece of heap metadata, or
8993
/// return a null pointer if the type's heap metadata cannot be represented
9094
/// by a constant.

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,10 @@ class IRGenSILFunction :
747747
// Force all archetypes referenced by the type to be bound by this point.
748748
// TODO: just make sure that we have a path to them that the debug info
749749
// can follow.
750-
if (!IGM.IRGen.Opts.Optimize && Ty.getType()->hasArchetype())
751-
Ty.getType()->getCanonicalType().visit([&](Type t) {
750+
auto runtimeTy = getRuntimeReifiedType(IGM,
751+
Ty.getType()->getCanonicalType());
752+
if (!IGM.IRGen.Opts.Optimize && runtimeTy->hasArchetype())
753+
runtimeTy.visit([&](Type t) {
752754
if (auto archetype = dyn_cast<ArchetypeType>(CanType(t)))
753755
emitTypeMetadataRef(archetype);
754756
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -emit-ir -g -verify
3+
4+
// REQUIRES: objc_interop
5+
6+
import Swift
7+
import Foundation
8+
import objc_generics
9+
10+
extension GenericClass {
11+
func method() {}
12+
class func classMethod() {}
13+
}

0 commit comments

Comments
 (0)