Skip to content

Commit 8231b3a

Browse files
committed
[IRGen & Runtime] Remove prefab'ed VWT for reference storage types
The prefab'ed value witness tables for reference storage types are a premature optimization. Not all scenarios are covered, and those that are "look suspect" according to John McCall.
1 parent 834ad9e commit 8231b3a

File tree

5 files changed

+46
-116
lines changed

5 files changed

+46
-116
lines changed

include/swift/Demangling/ManglingMacros.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@
6666
#define VALUE_WITNESS_SYM(Ty) \
6767
MANGLE_SYM(MANGLING_CONCAT2(Ty, WV))
6868

69-
#define UNOWNED_VALUE_WITNESS_SYM(Ty) \
70-
MANGLE_SYM(MANGLING_CONCAT3(Ty, Xo, WV))
71-
72-
#define WEAK_VALUE_WITNESS_SYM(Ty) \
73-
MANGLE_SYM(MANGLING_CONCAT3(OPTIONAL_MANGLING(Ty), Xw, WV))
74-
7569
#define METATYPE_VALUE_WITNESS_SYM(Ty) \
7670
MANGLE_SYM(MANGLING_CONCAT3(Ty, METATYPE_MANGLING, WV))
7771

include/swift/Runtime/Metadata.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,6 @@ const ValueWitnessTable VALUE_WITNESS_SYM(Bi512_); // Builtin.Int512
239239
// pointer types.
240240
SWIFT_RUNTIME_EXPORT
241241
const ExtraInhabitantsValueWitnessTable VALUE_WITNESS_SYM(Bo); // Builtin.NativeObject
242-
SWIFT_RUNTIME_EXPORT
243-
const ExtraInhabitantsValueWitnessTable UNOWNED_VALUE_WITNESS_SYM(Bo); // unowned Builtin.NativeObject
244-
SWIFT_RUNTIME_EXPORT
245-
const ValueWitnessTable WEAK_VALUE_WITNESS_SYM(Bo); // weak Builtin.NativeObject?
246242

247243
SWIFT_RUNTIME_EXPORT
248244
const ExtraInhabitantsValueWitnessTable VALUE_WITNESS_SYM(Bb); // Builtin.BridgeObject
@@ -254,10 +250,6 @@ const ExtraInhabitantsValueWitnessTable VALUE_WITNESS_SYM(Bp); // Builtin.RawPoi
254250
// The ObjC-pointer table can be used for arbitrary ObjC pointer types.
255251
SWIFT_RUNTIME_EXPORT
256252
const ExtraInhabitantsValueWitnessTable VALUE_WITNESS_SYM(BO); // Builtin.UnknownObject
257-
SWIFT_RUNTIME_EXPORT
258-
const ExtraInhabitantsValueWitnessTable UNOWNED_VALUE_WITNESS_SYM(BO); // unowned Builtin.UnknownObject
259-
SWIFT_RUNTIME_EXPORT
260-
const ValueWitnessTable WEAK_VALUE_WITNESS_SYM(BO); // weak Builtin.UnknownObject?
261253
#endif
262254

263255
// The () -> () table can be used for arbitrary function types.

lib/IRGen/MetadataRequest.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,70 +2310,6 @@ namespace {
23102310
DynamicMetadataRequest request) {
23112311
return visitAnyClassType(type->getClassOrBoundGenericClass(), request);
23122312
}
2313-
2314-
llvm::Value *visitReferenceStorageType(CanReferenceStorageType type,
2315-
DynamicMetadataRequest request) {
2316-
// Other reference storage types all have the same layout for their
2317-
// storage qualification and the reference counting of their underlying
2318-
// object.
2319-
2320-
auto &C = IGF.IGM.Context;
2321-
CanType referent = type.getReferentType();
2322-
CanType underlyingTy = referent;
2323-
if (auto Ty = referent.getOptionalObjectType())
2324-
underlyingTy = Ty;
2325-
2326-
// Reference storage types with witness tables need open-coded layouts.
2327-
// TODO: Maybe we could provide prefabs for 1 witness table.
2328-
if (underlyingTy.isExistentialType()) {
2329-
auto layout = underlyingTy.getExistentialLayout();
2330-
for (auto *protoTy : layout.getProtocols()) {
2331-
auto *protoDecl = protoTy->getDecl();
2332-
if (IGF.getSILTypes().protocolRequiresWitnessTable(protoDecl))
2333-
return visitType(type, request);
2334-
}
2335-
}
2336-
2337-
// Unmanaged references are plain pointers with extra inhabitants,
2338-
// which look like thick metatypes.
2339-
//
2340-
// FIXME: This sounds wrong, an Objective-C tagged pointer could be
2341-
// stored in an unmanaged reference for instance.
2342-
if (type->getOwnership() == ReferenceOwnership::Unmanaged) {
2343-
auto metatype = CanMetatypeType::get(C.TheNativeObjectType);
2344-
return emitFromValueWitnessTable(metatype);
2345-
}
2346-
2347-
CanType valueWitnessReferent;
2348-
switch (getReferenceCountingForType(IGF.IGM, underlyingTy)) {
2349-
case ReferenceCounting::Unknown:
2350-
case ReferenceCounting::Block:
2351-
case ReferenceCounting::ObjC:
2352-
valueWitnessReferent = C.TheUnknownObjectType;
2353-
break;
2354-
2355-
case ReferenceCounting::Native:
2356-
valueWitnessReferent = C.TheNativeObjectType;
2357-
break;
2358-
2359-
case ReferenceCounting::Bridge:
2360-
valueWitnessReferent = C.TheBridgeObjectType;
2361-
break;
2362-
2363-
case ReferenceCounting::Error:
2364-
llvm_unreachable("shouldn't be possible");
2365-
}
2366-
2367-
// Get the reference storage type of the builtin object whose value
2368-
// witness we can borrow.
2369-
if (referent->getOptionalObjectType())
2370-
valueWitnessReferent = OptionalType::get(valueWitnessReferent)
2371-
->getCanonicalType();
2372-
2373-
auto valueWitnessType = CanReferenceStorageType::get(valueWitnessReferent,
2374-
type->getOwnership());
2375-
return emitFromValueWitnessTable(valueWitnessType);
2376-
}
23772313
};
23782314

23792315
} // end anonymous namespace

stdlib/public/runtime/KnownMetadata.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ const ValueWitnessTable swift::VALUE_WITNESS_SYM(Bi512_) =
6767
const ExtraInhabitantsValueWitnessTable swift::VALUE_WITNESS_SYM(Bo) =
6868
ValueWitnessTableForBox<SwiftRetainableBox>::table;
6969

70-
/// The basic value-witness table for Swift unowned pointers.
71-
const ExtraInhabitantsValueWitnessTable swift::UNOWNED_VALUE_WITNESS_SYM(Bo) =
72-
ValueWitnessTableForBox<SwiftUnownedRetainableBox>::table;
73-
74-
/// The basic value-witness table for Swift weak pointers.
75-
const ValueWitnessTable swift::WEAK_VALUE_WITNESS_SYM(Bo) =
76-
ValueWitnessTableForBox<SwiftWeakRetainableBox>::table;
77-
7870
/// The value-witness table for pointer-aligned unmanaged pointer types.
7971
const ExtraInhabitantsValueWitnessTable swift::METATYPE_VALUE_WITNESS_SYM(Bo) =
8072
ValueWitnessTableForBox<PointerPointerBox>::table;
@@ -103,14 +95,6 @@ static const ValueWitnessTable VALUE_WITNESS_SYM(BB) =
10395
const ExtraInhabitantsValueWitnessTable swift::VALUE_WITNESS_SYM(BO) =
10496
ValueWitnessTableForBox<ObjCRetainableBox>::table;
10597

106-
/// The basic value-witness table for ObjC unowned pointers.
107-
const ExtraInhabitantsValueWitnessTable swift::UNOWNED_VALUE_WITNESS_SYM(BO) =
108-
ValueWitnessTableForBox<ObjCUnownedRetainableBox>::table;
109-
110-
/// The basic value-witness table for ObjC weak pointers.
111-
const ValueWitnessTable swift::WEAK_VALUE_WITNESS_SYM(BO) =
112-
ValueWitnessTableForBox<ObjCWeakRetainableBox>::table;
113-
11498
#endif
11599

116100
/*** Functions ***************************************************************/

test/IRGen/type_layout_reference_storage.swift

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,44 @@ struct ReferenceStorageTypeLayout<T, Native : C, Unknown : AnyObject> {
1111
var z: T
1212

1313
// -- Known-Swift-refcounted type
14-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBoXoWV", i32 8)
15-
unowned(safe) var cs: C
16-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBomWV", i32 8)
14+
// CHECK-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_[[REF_XI:[0-9a-f][0-9a-f][0-9a-f]+]]_pod, i32 0, i32 0)
15+
// CHECK-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_[[REF_XI:[0-9a-f][0-9a-f][0-9a-f]+]]_pod, i32 0, i32 0)
1716
unowned(unsafe) var cu: C
18-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBoSgXwWV", i32 8)
17+
// CHECK-native-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_[[REF_XI]]_bt, i32 0, i32 0)
18+
// CHECK-objc-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_1_bt, i32 0, i32 0)
19+
// CHECK-native-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_[[REF_XI]]_bt, i32 0, i32 0)
20+
// CHECK-objc-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_1_bt, i32 0, i32 0)
21+
unowned(safe) var cs: C
22+
// CHECK-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
23+
// CHECK-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
1924
weak var cwo: C?
20-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBoSgXwWV", i32 8)
25+
// CHECK-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
26+
// CHECK-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
2127
weak var cwi: C!
2228

2329
// -- Known-Swift-refcounted archetype
24-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBoXoWV", i32 8)
25-
unowned(safe) var nc: Native
26-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBomWV", i32 8)
30+
// CHECK-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_[[REF_XI]]_pod, i32 0, i32 0)
31+
// CHECK-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_[[REF_XI]]_pod, i32 0, i32 0)
2732
unowned(unsafe) var nu: Native
28-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBoSgXwWV", i32 8)
33+
// CHECK-native-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_[[REF_XI]]_bt, i32 0, i32 0)
34+
// CHECK-objc-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_1_bt, i32 0, i32 0)
35+
// CHECK-native-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_[[REF_XI]]_bt, i32 0, i32 0)
36+
// CHECK-objc-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_1_bt, i32 0, i32 0)
37+
unowned(safe) var nc: Native
38+
// CHECK-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
39+
// CHECK-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
2940
weak var nwo: Native?
30-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBoSgXwWV", i32 8)
41+
// CHECK-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
42+
// CHECK-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
3143
weak var nwi: Native!
3244

3345
// -- Open-code layout for protocol types with witness tables. Note:
3446
// 1) The layouts for unowned(safe) references are only bitwise takable
3547
// when ObjC interop is disabled.
3648
// 2) 0x7fffffff is the max extra inhabitant count, but not all types in
3749
// all scenarios.
38-
// CHECK-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_16_8_[[REF_XI:[0-9a-f][0-9a-f][0-9a-f]+]]_pod, i32 0, i32 0)
39-
// CHECK-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_4_[[REF_XI:[0-9a-f][0-9a-f][0-9a-f]+]]_pod, i32 0, i32 0)
50+
// CHECK-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_16_8_[[REF_XI]]_pod, i32 0, i32 0)
51+
// CHECK-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_4_[[REF_XI]]_pod, i32 0, i32 0)
4052
unowned(unsafe) var pu: P
4153
// CHECK-native-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_16_8_[[REF_XI]]_bt, i32 0, i32 0)
4254
// CHECK-objc-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_16_8_7fffffff, i32 0, i32 0)
@@ -81,23 +93,35 @@ struct ReferenceStorageTypeLayout<T, Native : C, Unknown : AnyObject> {
8193
weak var pqcwi: (P & Q & C)!
8294

8395
// -- Unknown-refcounted existential without witness tables.
84-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$S[[UNKNOWN:B[Oo]]]XoWV", i32 8)
85-
unowned(safe) var aos: AnyObject
86-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBomWV", i32 8)
96+
// CHECK-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_[[REF_XI]]_pod, i32 0, i32 0)
97+
// CHECK-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_[[REF_XI]]_pod, i32 0, i32 0)
8798
unowned(unsafe) var aou: AnyObject
88-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$S[[UNKNOWN]]SgXwWV", i32 8)
99+
// CHECK-native-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_[[REF_XI]]_bt, i32 0, i32 0)
100+
// CHECK-objc-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
101+
// CHECK-native-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_[[REF_XI]]_bt, i32 0, i32 0)
102+
// CHECK-objc-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
103+
unowned(safe) var aos: AnyObject
104+
// CHECK-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
105+
// CHECK-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
89106
weak var aowo: AnyObject?
90-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$S[[UNKNOWN]]SgXwWV", i32 8)
107+
// CHECK-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
108+
// CHECK-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
91109
weak var aowi: AnyObject!
92110

93111
// -- Unknown-refcounted archetype
94-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$S[[UNKNOWN:B[Oo]]]XoWV", i32 8)
95-
unowned(safe) var us: Unknown
96-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$SBomWV", i32 8)
112+
// CHECK-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_[[REF_XI]]_pod, i32 0, i32 0)
113+
// CHECK-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_[[REF_XI]]_pod, i32 0, i32 0)
97114
unowned(unsafe) var uu: Unknown
98-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$S[[UNKNOWN]]SgXwWV", i32 8)
115+
// CHECK-native-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_[[REF_XI]]_bt, i32 0, i32 0)
116+
// CHECK-objc-64: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_8_8_1, i32 0, i32 0)
117+
// CHECK-native-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_[[REF_XI]]_bt, i32 0, i32 0)
118+
// CHECK-objc-32: store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @type_layout_4_4_1, i32 0, i32 0)
119+
unowned(safe) var us: Unknown
120+
// CHECK-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
121+
// CHECK-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
99122
weak var uwo: Unknown?
100-
// CHECK: store i8** getelementptr inbounds (i8*, i8** @"$S[[UNKNOWN]]SgXwWV", i32 8)
123+
// CHECK-64: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_8_8_0, i32 0, i32 0)
124+
// CHECK-32: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @type_layout_4_4_0, i32 0, i32 0)
101125
weak var uwi: Unknown!
102126
}
103127

0 commit comments

Comments
 (0)