Skip to content

Commit f53e88b

Browse files
committed
Workaround MSVC more.
1 parent e327848 commit f53e88b

File tree

2 files changed

+47
-61
lines changed

2 files changed

+47
-61
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,10 +1254,10 @@ class TypeConverter {
12541254
visitAggregateLeaves(Lowering::AbstractionPattern origType, Type substType,
12551255
TypeExpansionContext context,
12561256
std::function<bool(Type, Lowering::AbstractionPattern,
1257-
TaggedUnion<ValueDecl *, unsigned>)>
1257+
ValueDecl *, Optional<unsigned>)>
12581258
isLeafAggregate,
12591259
std::function<bool(Type, Lowering::AbstractionPattern,
1260-
TaggedUnion<ValueDecl *, unsigned>)>
1260+
ValueDecl *, Optional<unsigned>)>
12611261
visit);
12621262
#endif
12631263
};

lib/SIL/IR/TypeLowering.cpp

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,83 +2439,74 @@ TypeConverter::getTypeLowering(AbstractionPattern origType,
24392439
bool TypeConverter::visitAggregateLeaves(
24402440
Lowering::AbstractionPattern origType, Type substType,
24412441
TypeExpansionContext context,
2442-
std::function<bool(Type, Lowering::AbstractionPattern,
2443-
TaggedUnion<ValueDecl *, unsigned>)>
2442+
std::function<bool(Type, Lowering::AbstractionPattern, ValueDecl *,
2443+
Optional<unsigned>)>
24442444
isLeafAggregate,
2445-
std::function<bool(Type, Lowering::AbstractionPattern,
2446-
TaggedUnion<ValueDecl *, unsigned>)>
2445+
std::function<bool(Type, Lowering::AbstractionPattern, ValueDecl *,
2446+
Optional<unsigned>)>
24472447
visit) {
24482448
llvm::SmallSet<std::tuple<TypeBase *, ValueDecl *, unsigned>, 16> visited;
24492449
llvm::SmallVector<
24502450
std::tuple<TypeBase *, AbstractionPattern, ValueDecl *, unsigned>, 16>
24512451
worklist;
2452-
auto insertIntoWorklist =
2453-
[&visited, &worklist](Type substTy, AbstractionPattern origTy,
2454-
TaggedUnion<ValueDecl *, unsigned> either) -> bool {
2455-
ValueDecl *field;
2456-
unsigned index;
2457-
if (either.isa<ValueDecl *>()) {
2458-
field = either.get<ValueDecl *>();
2459-
index = UINT_MAX;
2460-
} else {
2461-
field = nullptr;
2462-
index = either.get<unsigned>();
2463-
}
2452+
auto insertIntoWorklist = [&visited,
2453+
&worklist](Type substTy, AbstractionPattern origTy,
2454+
ValueDecl *field,
2455+
Optional<unsigned> maybeIndex) -> bool {
2456+
unsigned index = maybeIndex.getValueOr(UINT_MAX);
24642457
if (!visited.insert({substTy.getPointer(), field, index}).second)
24652458
return false;
24662459
worklist.push_back({substTy.getPointer(), origTy, field, index});
24672460
return true;
24682461
};
2469-
auto popFromWorklist =
2470-
[&worklist]() -> std::tuple<Type, AbstractionPattern,
2471-
TaggedUnion<ValueDecl *, unsigned>> {
2462+
auto popFromWorklist = [&worklist]()
2463+
-> std::tuple<Type, AbstractionPattern, ValueDecl *, Optional<unsigned>> {
24722464
TypeBase *ty;
24732465
AbstractionPattern origTy = AbstractionPattern::getOpaque();
2474-
TaggedUnion<ValueDecl *, unsigned> either((ValueDecl *)nullptr);
24752466
ValueDecl *field;
2476-
unsigned index = 0;
2467+
unsigned index;
24772468
std::tie(ty, origTy, field, index) = worklist.pop_back_val();
2478-
if (index != UINT_MAX) {
2479-
either = TaggedUnion<ValueDecl *, unsigned>(index);
2480-
} else {
2481-
either = TaggedUnion<ValueDecl *, unsigned>(field);
2482-
}
2483-
return {ty->getCanonicalType(), origTy, either};
2469+
Optional<unsigned> maybeIndex;
2470+
if (index != UINT_MAX)
2471+
maybeIndex = {index};
2472+
return {ty->getCanonicalType(), origTy, field, index};
24842473
};
24852474
auto isAggregate = [](Type ty) {
24862475
return ty->is<TupleType>() || ty->getEnumOrBoundGenericEnum() ||
24872476
ty->getStructOrBoundGenericStruct();
24882477
};
2489-
insertIntoWorklist(substType, origType, (ValueDecl *)nullptr);
2478+
insertIntoWorklist(substType, origType, nullptr, llvm::None);
24902479
while (!worklist.empty()) {
24912480
Type ty;
24922481
AbstractionPattern origTy = AbstractionPattern::getOpaque();
2493-
TaggedUnion<ValueDecl *, unsigned> path((ValueDecl *)nullptr);
2494-
std::tie(ty, origTy, path) = popFromWorklist();
2495-
if (isAggregate(ty) && !isLeafAggregate(ty, origTy, path)) {
2482+
ValueDecl *field;
2483+
Optional<unsigned> index;
2484+
std::tie(ty, origTy, field, index) = popFromWorklist();
2485+
if (isAggregate(ty) && !isLeafAggregate(ty, origTy, field, index)) {
24962486
if (auto tupleTy = ty->getAs<TupleType>()) {
2497-
for (unsigned index = 0, num = tupleTy->getNumElements(); index < num;
2498-
++index) {
2499-
auto origElementTy = origTy.getTupleElementType(index);
2487+
for (unsigned tupleIndex = 0, num = tupleTy->getNumElements();
2488+
tupleIndex < num; ++tupleIndex) {
2489+
auto origElementTy = origTy.getTupleElementType(tupleIndex);
25002490
auto substElementTy =
2501-
tupleTy->getElementType(index)->getCanonicalType();
2491+
tupleTy->getElementType(tupleIndex)->getCanonicalType();
25022492
substElementTy =
25032493
computeLoweredRValueType(context, origElementTy, substElementTy);
2504-
insertIntoWorklist(substElementTy, origElementTy,
2505-
TaggedUnion<ValueDecl *, unsigned>(index));
2494+
insertIntoWorklist(substElementTy, origElementTy, nullptr,
2495+
tupleIndex);
25062496
}
25072497
} else if (auto *decl = ty->getStructOrBoundGenericStruct()) {
2508-
for (auto *field : decl->getStoredProperties()) {
2498+
for (auto *structField : decl->getStoredProperties()) {
25092499
auto subMap = ty->getContextSubstitutionMap(&M, decl);
25102500
auto substFieldTy =
2511-
field->getInterfaceType().subst(subMap)->getCanonicalType();
2512-
auto sig = field->getDeclContext()->getGenericSignatureOfContext();
2513-
auto interfaceTy = field->getInterfaceType()->getReducedType(sig);
2501+
structField->getInterfaceType().subst(subMap)->getCanonicalType();
2502+
auto sig =
2503+
structField->getDeclContext()->getGenericSignatureOfContext();
2504+
auto interfaceTy =
2505+
structField->getInterfaceType()->getReducedType(sig);
25142506
auto origFieldType =
2515-
origTy.unsafeGetSubstFieldType(field, interfaceTy);
2516-
insertIntoWorklist(substFieldTy, origFieldType,
2517-
TaggedUnion<ValueDecl *, unsigned>(
2518-
static_cast<ValueDecl *>(field)));
2507+
origTy.unsafeGetSubstFieldType(structField, interfaceTy);
2508+
insertIntoWorklist(substFieldTy, origFieldType, structField,
2509+
llvm::None);
25192510
}
25202511
} else if (auto *decl = ty->getEnumOrBoundGenericEnum()) {
25212512
auto subMap = ty->getContextSubstitutionMap(&M, decl);
@@ -2532,9 +2523,8 @@ bool TypeConverter::visitAggregateLeaves(
25322523
element, element->getArgumentInterfaceType()->getReducedType(
25332524
decl->getGenericSignature()));
25342525

2535-
insertIntoWorklist(substElementType, origElementTy,
2536-
TaggedUnion<ValueDecl *, unsigned>(
2537-
static_cast<ValueDecl *>(element)));
2526+
insertIntoWorklist(substElementType, origElementTy, element,
2527+
llvm::None);
25382528
}
25392529
} else {
25402530
llvm_unreachable("unknown aggregate kind!");
@@ -2543,7 +2533,7 @@ bool TypeConverter::visitAggregateLeaves(
25432533
}
25442534

25452535
// This type is a leaf. Visit it.
2546-
auto success = visit(ty, origTy, path);
2536+
auto success = visit(ty, origTy, field, index);
25472537
if (!success)
25482538
return false;
25492539
}
@@ -2567,26 +2557,23 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
25672557
bool hasNoNontrivialLexicalLeaf = visitAggregateLeaves(
25682558
origType, substType, forExpansion,
25692559
/*isLeaf=*/
2570-
[&](auto ty, auto origTy, auto either) -> bool {
2560+
[&](auto ty, auto origTy, auto *field, auto index) -> bool {
25712561
// The field's type is an aggregate. Treat it as a leaf if it
25722562
// has a lifetime annotation.
25732563

25742564
// If it's a field of a tuple or the top-level type, there's no value
25752565
// decl on which to look for an attribute. It's a leaf iff the type
25762566
// has a lifetime annotation.
2577-
if (either.template isa<unsigned>() ||
2578-
either.template get<ValueDecl *>() == nullptr)
2567+
if (index || !field)
25792568
return getLifetimeAnnotation(ty).isSome();
25802569

25812570
// It's a field of a struct or an enum. It's a leaf if the type
25822571
// or the var decl has a lifetime annotation.
2583-
return either.template get<ValueDecl *>()
2584-
->getLifetimeAnnotation()
2585-
.isSome() ||
2572+
return field->getLifetimeAnnotation().isSome() ||
25862573
getLifetimeAnnotation(ty);
25872574
},
25882575
/*visit=*/
2589-
[&](auto ty, auto origTy, auto either) -> bool {
2576+
[&](auto ty, auto origTy, auto *field, auto index) -> bool {
25902577
// Look at each leaf: if it is non-trivial, verify that it is
25912578
// attributed @_eagerMove.
25922579

@@ -2605,8 +2592,7 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
26052592
// not lexical. The leaf must be annotated @_eagerMove.
26062593
// Otherwise, the whole type would be lexical.
26072594

2608-
if (either.template isa<unsigned>() ||
2609-
either.template get<ValueDecl *>() == nullptr) {
2595+
if (index || !field) {
26102596
// There is no field decl that might be annotated @_eagerMove. The
26112597
// field is @_eagerMove iff its type is annotated @_eagerMove.
26122598
return getLifetimeAnnotation(ty) == LifetimeAnnotation::EagerMove;
@@ -2615,7 +2601,7 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
26152601
// The field is non-trivial and the whole type is non-lexical.
26162602
// That's fine as long as the field or its type is annotated
26172603
// @_eagerMove.
2618-
return either.template get<ValueDecl *>()->getLifetimeAnnotation() ==
2604+
return field->getLifetimeAnnotation() ==
26192605
LifetimeAnnotation::EagerMove ||
26202606
getLifetimeAnnotation(ty) == LifetimeAnnotation::EagerMove;
26212607
});

0 commit comments

Comments
 (0)