Skip to content

Commit d0df110

Browse files
Merge pull request #85595 from aschwaighofer/irgen_specialized_metadata_vw_nested_types
IRGen: Detect nested generic types during generation of the vwt of specialized metadata
2 parents 6b118ac + 3292aaa commit d0df110

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

lib/IRGen/GenValueWitness.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,16 +1387,16 @@ static void addValueWitnessesForAbstractType(IRGenModule &IGM,
13871387
// reasons to continue using "generic" value witness table functions i.e the
13881388
// same once used for runtime instantiated generic metadata.
13891389
if (!IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
1390-
if (auto boundGenericType = dyn_cast<BoundGenericType>(abstractType)) {
1390+
auto *nomDecl = abstractType->getNominalOrBoundGenericNominal();
1391+
if (abstractType->isSpecialized() && nomDecl) {
13911392
CanType concreteFormalType = getFormalTypeInPrimaryContext(abstractType);
13921393

13931394
auto concreteLoweredType = IGM.getLoweredType(concreteFormalType);
13941395
const auto *boundConcreteTI = &IGM.getTypeInfo(concreteLoweredType);
13951396
auto packing = boundConcreteTI->getFixedPacking(IGM);
13961397
boundGenericCharacteristics = {concreteLoweredType, boundConcreteTI,
13971398
packing};
1398-
abstractType =
1399-
boundGenericType->getDecl()->getDeclaredType()->getCanonicalType();
1399+
abstractType = nomDecl->getDeclaredType()->getCanonicalType();
14001400
}
14011401
}
14021402
CanType concreteFormalType = getFormalTypeInPrimaryContext(abstractType);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %swift -prespecialize-generic-metadata -target %module-target-future -emit-ir %s | %FileCheck %s -DINT=i%target-ptrsize -DALIGNMENT=%target-alignment
2+
3+
// REQUIRES: VENDOR=apple || OS=linux-gnu
4+
// UNSUPPORTED: CPU=i386 && OS=ios
5+
// UNSUPPORTED: CPU=armv7 && OS=ios
6+
// UNSUPPORTED: CPU=armv7s && OS=ios
7+
8+
@inline(never)
9+
func consume<T>(_ t: T) {
10+
withExtendedLifetime(t) { t in
11+
}
12+
}
13+
14+
struct Container<T> {
15+
struct NonFixed {
16+
17+
init( _ t: T) {
18+
w = t
19+
}
20+
21+
var w: T? = nil
22+
var x = 1
23+
var y = 1
24+
var z = 1
25+
}
26+
}
27+
28+
29+
func doit2() {
30+
consume(Container.NonFixed(5))
31+
}
32+
33+
doit2()
34+
35+
// Make sure we use the generic witness table functions rather than specialized
36+
// ones. We do this for code size.
37+
38+
// CHECK: @"$s10nestedtype9ContainerV8NonFixedVySi_GWV" =
39+
// CHECK-SAME: s10nestedtype9ContainerV8NonFixedVwtk

0 commit comments

Comments
 (0)