Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4417,10 +4417,14 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
if (derivedClass->getSuperclass().isNull())
return nullptr;

if (baseGenericCtx->getGenericSignature().isNull() ||
derivedGenericCtx->getGenericSignature().isNull())
auto baseGenericSig = baseGenericCtx->getGenericSignature();
auto derivedGenericSig = derivedGenericCtx->getGenericSignature();
if (derivedGenericSig.isNull())
return nullptr;

if (baseGenericSig.isNull())
return derivedGenericSig;

auto baseClassSig = baseClass->getGenericSignature();
auto subMap = derivedClass->getSuperclass()->getContextSubstitutionMap(
derivedClass->getModuleContext(), baseClass);
Expand Down
17 changes: 17 additions & 0 deletions test/SILGen/vtable_thunks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ class Noot : Aap {
override func map() -> (S?) -> () -> Noot {}
}

// rdar://problem/59669591
class Base {
func returnsOptional() -> Int? { return nil }
}

class Derived<Foo> : Base {
// The thunk here needs to be generic.
override func returnsOptional() -> Int { return 0 }
}

// CHECK-LABEL: sil private [thunk] [ossa] @$s13vtable_thunks3BarC3foo{{[_0-9a-zA-Z]*}}FTV : $@convention(method) (@guaranteed @callee_guaranteed (Int) -> Int, @guaranteed Bar) -> @owned Optional<@callee_guaranteed (Int) -> Int>
// CHECK: [[IMPL:%.*]] = function_ref @$s13vtable_thunks3BarC3foo{{[_0-9a-zA-Z]*}}F
// CHECK: apply [[IMPL]]
Expand Down Expand Up @@ -257,6 +267,8 @@ class Noot : Aap {
// CHECK: [[OUTER:%.*]] = convert_function [[INNER]] : $@callee_guaranteed () -> @owned Noot to $@callee_guaranteed () -> @owned Optional<Aap>
// CHECK: return [[OUTER]]

// CHECK-LABEL: sil private [thunk] [ossa] @$s13vtable_thunks7DerivedC15returnsOptionalSiyFAA4BaseCADSiSgyFTV : $@convention(method) <τ_0_0> (@guaranteed Derived<τ_0_0>) -> Optional<Int> {

// CHECK-LABEL: sil_vtable D {
// CHECK: #B.iuo!1: {{.*}} : @$s13vtable_thunks1D{{[A-Z0-9a-z_]*}}FTV
// CHECK: #B.f!1: {{.*}} : @$s13vtable_thunks1D{{[A-Z0-9a-z_]*}}F
Expand Down Expand Up @@ -321,3 +333,8 @@ class Noot : Aap {
// CHECK-LABEL: sil_vtable NoThrowVariance {
// CHECK: #ThrowVariance.mightThrow!1: {{.*}} : @$s13vtable_thunks{{[A-Z0-9a-z_]*}}F

// CHECK-LABEL: sil_vtable Base {
// CHECK: #Base.returnsOptional!1: (Base) -> () -> Int? : @$s13vtable_thunks4BaseC15returnsOptionalSiSgyF

// CHECK-LABEL: sil_vtable Derived {
// CHECK: #Base.returnsOptional!1: (Base) -> () -> Int? : @$s13vtable_thunks7DerivedC15returnsOptionalSiyFAA4BaseCADSiSgyFTV [override]