Skip to content

Commit e327848

Browse files
committed
Workaround MSVC overload resolution.
1 parent af6749e commit e327848

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,15 +1250,15 @@ class TypeConverter {
12501250
/// getTypeLowering(AbstractionPattern,Type,TypeExpansionContext).
12511251
void verifyLowering(const TypeLowering &, AbstractionPattern origType,
12521252
Type origSubstType, TypeExpansionContext forExpansion);
1253-
bool visitAggregateLeaves(
1254-
Lowering::AbstractionPattern origType, Type substType,
1255-
TypeExpansionContext context,
1256-
std::function<bool(Type, Lowering::AbstractionPattern,
1257-
Optional<TaggedUnion<ValueDecl *, unsigned>>)>
1258-
isLeafAggregate,
1259-
std::function<bool(Type, Lowering::AbstractionPattern,
1260-
Optional<TaggedUnion<ValueDecl *, unsigned>>)>
1261-
visit);
1253+
bool
1254+
visitAggregateLeaves(Lowering::AbstractionPattern origType, Type substType,
1255+
TypeExpansionContext context,
1256+
std::function<bool(Type, Lowering::AbstractionPattern,
1257+
TaggedUnion<ValueDecl *, unsigned>)>
1258+
isLeafAggregate,
1259+
std::function<bool(Type, Lowering::AbstractionPattern,
1260+
TaggedUnion<ValueDecl *, unsigned>)>
1261+
visit);
12621262
#endif
12631263
};
12641264

lib/SIL/IR/TypeLowering.cpp

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,65 +2440,57 @@ bool TypeConverter::visitAggregateLeaves(
24402440
Lowering::AbstractionPattern origType, Type substType,
24412441
TypeExpansionContext context,
24422442
std::function<bool(Type, Lowering::AbstractionPattern,
2443-
Optional<TaggedUnion<ValueDecl *, unsigned>>)>
2443+
TaggedUnion<ValueDecl *, unsigned>)>
24442444
isLeafAggregate,
24452445
std::function<bool(Type, Lowering::AbstractionPattern,
2446-
Optional<TaggedUnion<ValueDecl *, unsigned>>)>
2446+
TaggedUnion<ValueDecl *, 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;
24522452
auto insertIntoWorklist =
2453-
[&visited,
2454-
&worklist](Type substTy, AbstractionPattern origTy,
2455-
Optional<TaggedUnion<ValueDecl *, unsigned>> either) -> bool {
2453+
[&visited, &worklist](Type substTy, AbstractionPattern origTy,
2454+
TaggedUnion<ValueDecl *, unsigned> either) -> bool {
24562455
ValueDecl *field;
24572456
unsigned index;
2458-
if (either) {
2459-
if (either->isa<ValueDecl *>()) {
2460-
field = either->get<ValueDecl *>();
2461-
index = UINT_MAX;
2462-
} else {
2463-
field = nullptr;
2464-
index = either->get<unsigned>();
2465-
}
2457+
if (either.isa<ValueDecl *>()) {
2458+
field = either.get<ValueDecl *>();
2459+
index = UINT_MAX;
24662460
} else {
24672461
field = nullptr;
2468-
index = UINT_MAX;
2462+
index = either.get<unsigned>();
24692463
}
24702464
if (!visited.insert({substTy.getPointer(), field, index}).second)
24712465
return false;
24722466
worklist.push_back({substTy.getPointer(), origTy, field, index});
24732467
return true;
24742468
};
2475-
auto popFromWorklist = [&worklist]()
2476-
-> std::tuple<Type, AbstractionPattern,
2477-
Optional<TaggedUnion<ValueDecl *, unsigned>>> {
2469+
auto popFromWorklist =
2470+
[&worklist]() -> std::tuple<Type, AbstractionPattern,
2471+
TaggedUnion<ValueDecl *, unsigned>> {
24782472
TypeBase *ty;
24792473
AbstractionPattern origTy = AbstractionPattern::getOpaque();
2480-
Optional<TaggedUnion<ValueDecl *, unsigned>> either;
2474+
TaggedUnion<ValueDecl *, unsigned> either((ValueDecl *)nullptr);
24812475
ValueDecl *field;
24822476
unsigned index = 0;
24832477
std::tie(ty, origTy, field, index) = worklist.pop_back_val();
2484-
if (field) {
2485-
either = TaggedUnion<ValueDecl *, unsigned>(field);
2486-
} else if (index != UINT_MAX) {
2478+
if (index != UINT_MAX) {
24872479
either = TaggedUnion<ValueDecl *, unsigned>(index);
24882480
} else {
2489-
either = llvm::None;
2481+
either = TaggedUnion<ValueDecl *, unsigned>(field);
24902482
}
24912483
return {ty->getCanonicalType(), origTy, either};
24922484
};
24932485
auto isAggregate = [](Type ty) {
24942486
return ty->is<TupleType>() || ty->getEnumOrBoundGenericEnum() ||
24952487
ty->getStructOrBoundGenericStruct();
24962488
};
2497-
insertIntoWorklist(substType, origType, llvm::None);
2489+
insertIntoWorklist(substType, origType, (ValueDecl *)nullptr);
24982490
while (!worklist.empty()) {
24992491
Type ty;
25002492
AbstractionPattern origTy = AbstractionPattern::getOpaque();
2501-
Optional<TaggedUnion<ValueDecl *, unsigned>> path;
2493+
TaggedUnion<ValueDecl *, unsigned> path((ValueDecl *)nullptr);
25022494
std::tie(ty, origTy, path) = popFromWorklist();
25032495
if (isAggregate(ty) && !isLeafAggregate(ty, origTy, path)) {
25042496
if (auto tupleTy = ty->getAs<TupleType>()) {
@@ -2579,15 +2571,16 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
25792571
// The field's type is an aggregate. Treat it as a leaf if it
25802572
// has a lifetime annotation.
25812573

2582-
// If it's the top-level type or a field of a tuple, there's no var
2574+
// If it's a field of a tuple or the top-level type, there's no value
25832575
// decl on which to look for an attribute. It's a leaf iff the type
25842576
// has a lifetime annotation.
2585-
if (!either || either->template isa<unsigned>())
2577+
if (either.template isa<unsigned>() ||
2578+
either.template get<ValueDecl *>() == nullptr)
25862579
return getLifetimeAnnotation(ty).isSome();
25872580

25882581
// It's a field of a struct or an enum. It's a leaf if the type
25892582
// or the var decl has a lifetime annotation.
2590-
return either->template get<ValueDecl *>()
2583+
return either.template get<ValueDecl *>()
25912584
->getLifetimeAnnotation()
25922585
.isSome() ||
25932586
getLifetimeAnnotation(ty);
@@ -2612,7 +2605,8 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
26122605
// not lexical. The leaf must be annotated @_eagerMove.
26132606
// Otherwise, the whole type would be lexical.
26142607

2615-
if (!either || either->template isa<unsigned>()) {
2608+
if (either.template isa<unsigned>() ||
2609+
either.template get<ValueDecl *>() == nullptr) {
26162610
// There is no field decl that might be annotated @_eagerMove. The
26172611
// field is @_eagerMove iff its type is annotated @_eagerMove.
26182612
return getLifetimeAnnotation(ty) == LifetimeAnnotation::EagerMove;
@@ -2621,7 +2615,7 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
26212615
// The field is non-trivial and the whole type is non-lexical.
26222616
// That's fine as long as the field or its type is annotated
26232617
// @_eagerMove.
2624-
return either->template get<ValueDecl *>()->getLifetimeAnnotation() ==
2618+
return either.template get<ValueDecl *>()->getLifetimeAnnotation() ==
26252619
LifetimeAnnotation::EagerMove ||
26262620
getLifetimeAnnotation(ty) == LifetimeAnnotation::EagerMove;
26272621
});

0 commit comments

Comments
 (0)