Skip to content

Commit 8f6f198

Browse files
committed
Change the unit-testing specifier DSL to use demangle nodes.
Creating a mangle-node tree is annoying, but it's much better than trying to reproduce the mangling logic exactly. Also, add support for mangling some existential types. The specifier for parameterized protocol types has been future-proofed against the coming change to include the associated type names in the mangling.
1 parent ecb42f5 commit 8f6f198

File tree

3 files changed

+207
-101
lines changed

3 files changed

+207
-101
lines changed

unittests/runtime/ExtendedExistential.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ static const ModuleContextDescriptor *module() {
2323
});
2424
}
2525

26-
template <unsigned N>
27-
static ProtocolSpecifier globalProtocol() {
26+
static ProtocolSpecifier P() {
2827
return protocol(buildGlobalProtocolDescriptor(module(), [] {
29-
std::ostringstream str;
30-
str << "Anonymous" << N;
31-
return str.str();
28+
return "P";
29+
}));
30+
}
31+
32+
static ProtocolSpecifier Q() {
33+
return protocol(buildGlobalProtocolDescriptor(module(), [] {
34+
return "Q";
3235
}));
3336
}
3437

@@ -209,32 +212,32 @@ TEST(TestExtendedExistential, shapeUniquing) {
209212
return shape(
210213
genSig(param()),
211214
reqSig(param(),
212-
conforms(reqParam(0), globalProtocol<0>()),
213-
sameType(member(reqParam(0), "Element"), genParam(0)))
215+
conforms(reqParam(0), P()),
216+
sameType(member(reqParam(0), P(), "Element"), genParam(0)))
214217
);
215218
});
216219
auto shape1 = buildGlobalNonUniqueShape(567, []{
217220
return shape(
218221
genSig(param()),
219222
reqSig(param(),
220-
conforms(reqParam(0), globalProtocol<0>()),
221-
sameType(member(reqParam(0), "Element"), genParam(0)))
223+
conforms(reqParam(0), P()),
224+
sameType(member(reqParam(0), P(), "Element"), genParam(0)))
222225
);
223226
});
224227
auto shape2 = buildGlobalNonUniqueShape(1123, []{
225228
return shape(
226229
genSig(param()),
227230
reqSig(param(),
228-
conforms(reqParam(0), globalProtocol<1>()),
229-
sameType(member(reqParam(0), "Element"), genParam(0)))
231+
conforms(reqParam(0), Q()),
232+
sameType(member(reqParam(0), Q(), "Element"), genParam(0)))
230233
);
231234
});
232235
auto shape3 = buildGlobalNonUniqueShape(1123, []{
233236
return shape(
234237
genSig(param()),
235238
reqSig(param(),
236-
conforms(reqParam(0), globalProtocol<1>()),
237-
sameType(member(reqParam(0), "Element"), genParam(0)))
239+
conforms(reqParam(0), Q()),
240+
sameType(member(reqParam(0), Q(), "Element"), genParam(0)))
238241
);
239242
});
240243

@@ -265,7 +268,7 @@ TEST(TestExtendedExistential, nullaryMetadata) {
265268
auto shape1 = buildGlobalShape([]{
266269
return shape(
267270
reqSig(param(),
268-
conforms(reqParam(0), globalProtocol<0>()))
271+
conforms(reqParam(0), P()))
269272
);
270273
});
271274
auto metadata1 = swift_getExtendedExistentialTypeMetadata_unique(shape1, nullptr);
@@ -281,14 +284,14 @@ TEST(TestExtendedExistential, unaryMetadata) {
281284
return shape(
282285
genSig(param()),
283286
reqSig(param(),
284-
conforms(reqParam(0), globalProtocol<0>()))
287+
conforms(reqParam(0), P()))
285288
);
286289
});
287290
auto shape2 = buildGlobalShape([]{
288291
return shape(
289292
genSig(param()),
290293
reqSig(param(),
291-
conforms(reqParam(0), globalProtocol<1>()))
294+
conforms(reqParam(0), Q()))
292295
);
293296
});
294297

@@ -328,7 +331,7 @@ TEST(TestExtendedExistential, binaryMetadata) {
328331
return shape(
329332
genSig(param(), param()),
330333
reqSig(param(),
331-
conforms(reqParam(0), globalProtocol<0>()))
334+
conforms(reqParam(0), P()))
332335
);
333336
});
334337

@@ -396,7 +399,7 @@ TEST(TestExtendedExistential, defaultOpaqueValueWitnessses) {
396399
auto shape1 = buildGlobalShape([]{
397400
return shape(
398401
reqSig(param(),
399-
conforms(reqParam(0), globalProtocol<0>()))
402+
conforms(reqParam(0), P()))
400403
);
401404
});
402405
auto metadata1 = swift_getExtendedExistentialTypeMetadata_unique(shape1, nullptr);
@@ -408,8 +411,8 @@ TEST(TestExtendedExistential, defaultOpaqueValueWitnessses) {
408411
auto shape2 = buildGlobalShape([]{
409412
return shape(
410413
reqSig(param(),
411-
conforms(reqParam(0), globalProtocol<0>()),
412-
conforms(reqParam(0), globalProtocol<1>()))
414+
conforms(reqParam(0), P()),
415+
conforms(reqParam(0), Q()))
413416
);
414417
});
415418
auto metadata2 = swift_getExtendedExistentialTypeMetadata_unique(shape2, nullptr);
@@ -438,7 +441,7 @@ TEST(TestExtendedExistential, defaultClassValueWitnessses) {
438441
return shape(
439442
special(SpecialKind::Class),
440443
reqSig(param(),
441-
conforms(reqParam(0), globalProtocol<0>()))
444+
conforms(reqParam(0), P()))
442445
);
443446
});
444447
auto metadata1 = swift_getExtendedExistentialTypeMetadata_unique(shape1, nullptr);
@@ -451,8 +454,8 @@ TEST(TestExtendedExistential, defaultClassValueWitnessses) {
451454
return shape(
452455
special(SpecialKind::Class),
453456
reqSig(param(),
454-
conforms(reqParam(0), globalProtocol<0>()),
455-
conforms(reqParam(0), globalProtocol<1>()))
457+
conforms(reqParam(0), P()),
458+
conforms(reqParam(0), Q()))
456459
);
457460
});
458461
auto metadata2 = swift_getExtendedExistentialTypeMetadata_unique(shape2, nullptr);
@@ -481,7 +484,7 @@ TEST(TestExtendedExistential, defaultMetatypeValueWitnessses) {
481484
return shape(
482485
special(SpecialKind::Metatype),
483486
reqSig(param(),
484-
conforms(reqParam(0), globalProtocol<0>()))
487+
conforms(reqParam(0), P()))
485488
);
486489
});
487490
auto metadata1 = swift_getExtendedExistentialTypeMetadata_unique(shape1, nullptr);
@@ -494,8 +497,8 @@ TEST(TestExtendedExistential, defaultMetatypeValueWitnessses) {
494497
return shape(
495498
special(SpecialKind::Metatype),
496499
reqSig(param(),
497-
conforms(reqParam(0), globalProtocol<0>()),
498-
conforms(reqParam(0), globalProtocol<1>()))
500+
conforms(reqParam(0), P()),
501+
conforms(reqParam(0), Q()))
499502
);
500503
});
501504
auto metadata2 = swift_getExtendedExistentialTypeMetadata_unique(shape2, nullptr);

unittests/runtime/MetadataObjectBuilder.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ inline void addProtocolDescriptor(AnyObjectBuilder &builder,
7676

7777
ObjectRef<const char> selfType;
7878
if (!baseProtocols.empty()) {
79-
auto subbuilder = builder.createSubobject<const char>(/*align*/ 2);
80-
mangleGenericParamType(subbuilder, 0, 0);
81-
selfType = subbuilder.ref();
79+
selfType = createMangledTypeString(builder, typeParam(0, 0));
8280
}
8381

8482
// Requirement signature requirement descriptors

0 commit comments

Comments
 (0)