@@ -2440,65 +2440,57 @@ bool TypeConverter::visitAggregateLeaves(
2440
2440
Lowering::AbstractionPattern origType, Type substType,
2441
2441
TypeExpansionContext context,
2442
2442
std::function<bool (Type, Lowering::AbstractionPattern,
2443
- Optional< TaggedUnion<ValueDecl *, unsigned > >)>
2443
+ TaggedUnion<ValueDecl *, unsigned >)>
2444
2444
isLeafAggregate,
2445
2445
std::function<bool(Type, Lowering::AbstractionPattern,
2446
- Optional< TaggedUnion<ValueDecl *, unsigned > >)>
2446
+ TaggedUnion<ValueDecl *, unsigned >)>
2447
2447
visit) {
2448
2448
llvm::SmallSet<std::tuple<TypeBase *, ValueDecl *, unsigned >, 16 > visited;
2449
2449
llvm::SmallVector<
2450
2450
std::tuple<TypeBase *, AbstractionPattern, ValueDecl *, unsigned >, 16 >
2451
2451
worklist;
2452
2452
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 {
2456
2455
ValueDecl *field;
2457
2456
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;
2466
2460
} else {
2467
2461
field = nullptr ;
2468
- index = UINT_MAX ;
2462
+ index = either. get < unsigned >() ;
2469
2463
}
2470
2464
if (!visited.insert ({substTy.getPointer (), field, index}).second )
2471
2465
return false ;
2472
2466
worklist.push_back ({substTy.getPointer (), origTy, field, index});
2473
2467
return true ;
2474
2468
};
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 >> {
2478
2472
TypeBase *ty;
2479
2473
AbstractionPattern origTy = AbstractionPattern::getOpaque ();
2480
- Optional< TaggedUnion<ValueDecl *, unsigned >> either;
2474
+ TaggedUnion<ValueDecl *, unsigned > either ((ValueDecl *) nullptr ) ;
2481
2475
ValueDecl *field;
2482
2476
unsigned index = 0 ;
2483
2477
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) {
2487
2479
either = TaggedUnion<ValueDecl *, unsigned >(index);
2488
2480
} else {
2489
- either = llvm::None ;
2481
+ either = TaggedUnion<ValueDecl *, unsigned >(field) ;
2490
2482
}
2491
2483
return {ty->getCanonicalType (), origTy, either};
2492
2484
};
2493
2485
auto isAggregate = [](Type ty) {
2494
2486
return ty->is <TupleType>() || ty->getEnumOrBoundGenericEnum () ||
2495
2487
ty->getStructOrBoundGenericStruct ();
2496
2488
};
2497
- insertIntoWorklist (substType, origType, llvm::None );
2489
+ insertIntoWorklist (substType, origType, (ValueDecl *) nullptr );
2498
2490
while (!worklist.empty ()) {
2499
2491
Type ty;
2500
2492
AbstractionPattern origTy = AbstractionPattern::getOpaque ();
2501
- Optional< TaggedUnion<ValueDecl *, unsigned >> path;
2493
+ TaggedUnion<ValueDecl *, unsigned > path ((ValueDecl *) nullptr ) ;
2502
2494
std::tie (ty, origTy, path) = popFromWorklist ();
2503
2495
if (isAggregate (ty) && !isLeafAggregate (ty, origTy, path)) {
2504
2496
if (auto tupleTy = ty->getAs <TupleType>()) {
@@ -2579,15 +2571,16 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
2579
2571
// The field's type is an aggregate. Treat it as a leaf if it
2580
2572
// has a lifetime annotation.
2581
2573
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
2583
2575
// decl on which to look for an attribute. It's a leaf iff the type
2584
2576
// has a lifetime annotation.
2585
- if (!either || either->template isa <unsigned >())
2577
+ if (either.template isa <unsigned >() ||
2578
+ either.template get <ValueDecl *>() == nullptr )
2586
2579
return getLifetimeAnnotation (ty).isSome ();
2587
2580
2588
2581
// It's a field of a struct or an enum. It's a leaf if the type
2589
2582
// or the var decl has a lifetime annotation.
2590
- return either-> template get <ValueDecl *>()
2583
+ return either. template get <ValueDecl *>()
2591
2584
->getLifetimeAnnotation ()
2592
2585
.isSome () ||
2593
2586
getLifetimeAnnotation (ty);
@@ -2612,7 +2605,8 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
2612
2605
// not lexical. The leaf must be annotated @_eagerMove.
2613
2606
// Otherwise, the whole type would be lexical.
2614
2607
2615
- if (!either || either->template isa <unsigned >()) {
2608
+ if (either.template isa <unsigned >() ||
2609
+ either.template get <ValueDecl *>() == nullptr ) {
2616
2610
// There is no field decl that might be annotated @_eagerMove. The
2617
2611
// field is @_eagerMove iff its type is annotated @_eagerMove.
2618
2612
return getLifetimeAnnotation (ty) == LifetimeAnnotation::EagerMove;
@@ -2621,7 +2615,7 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
2621
2615
// The field is non-trivial and the whole type is non-lexical.
2622
2616
// That's fine as long as the field or its type is annotated
2623
2617
// @_eagerMove.
2624
- return either-> template get <ValueDecl *>()->getLifetimeAnnotation () ==
2618
+ return either. template get <ValueDecl *>()->getLifetimeAnnotation () ==
2625
2619
LifetimeAnnotation::EagerMove ||
2626
2620
getLifetimeAnnotation (ty) == LifetimeAnnotation::EagerMove;
2627
2621
});
0 commit comments