@@ -2439,83 +2439,74 @@ TypeConverter::getTypeLowering(AbstractionPattern origType,
2439
2439
bool TypeConverter::visitAggregateLeaves (
2440
2440
Lowering::AbstractionPattern origType, Type substType,
2441
2441
TypeExpansionContext context,
2442
- std::function<bool (Type, Lowering::AbstractionPattern,
2443
- TaggedUnion<ValueDecl *, unsigned >)>
2442
+ std::function<bool (Type, Lowering::AbstractionPattern, ValueDecl *,
2443
+ Optional< unsigned >)>
2444
2444
isLeafAggregate,
2445
- std::function<bool(Type, Lowering::AbstractionPattern,
2446
- TaggedUnion<ValueDecl *, unsigned >)>
2445
+ std::function<bool(Type, Lowering::AbstractionPattern, ValueDecl *,
2446
+ Optional< 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
- 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);
2464
2457
if (!visited.insert ({substTy.getPointer (), field, index}).second )
2465
2458
return false ;
2466
2459
worklist.push_back ({substTy.getPointer (), origTy, field, index});
2467
2460
return true ;
2468
2461
};
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 >> {
2472
2464
TypeBase *ty;
2473
2465
AbstractionPattern origTy = AbstractionPattern::getOpaque ();
2474
- TaggedUnion<ValueDecl *, unsigned > either ((ValueDecl *)nullptr );
2475
2466
ValueDecl *field;
2476
- unsigned index = 0 ;
2467
+ unsigned index;
2477
2468
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};
2484
2473
};
2485
2474
auto isAggregate = [](Type ty) {
2486
2475
return ty->is <TupleType>() || ty->getEnumOrBoundGenericEnum () ||
2487
2476
ty->getStructOrBoundGenericStruct ();
2488
2477
};
2489
- insertIntoWorklist (substType, origType, (ValueDecl *) nullptr );
2478
+ insertIntoWorklist (substType, origType, nullptr , llvm::None );
2490
2479
while (!worklist.empty ()) {
2491
2480
Type ty;
2492
2481
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)) {
2496
2486
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 );
2500
2490
auto substElementTy =
2501
- tupleTy->getElementType (index )->getCanonicalType ();
2491
+ tupleTy->getElementType (tupleIndex )->getCanonicalType ();
2502
2492
substElementTy =
2503
2493
computeLoweredRValueType (context, origElementTy, substElementTy);
2504
- insertIntoWorklist (substElementTy, origElementTy,
2505
- TaggedUnion<ValueDecl *, unsigned >(index) );
2494
+ insertIntoWorklist (substElementTy, origElementTy, nullptr ,
2495
+ tupleIndex );
2506
2496
}
2507
2497
} else if (auto *decl = ty->getStructOrBoundGenericStruct ()) {
2508
- for (auto *field : decl->getStoredProperties ()) {
2498
+ for (auto *structField : decl->getStoredProperties ()) {
2509
2499
auto subMap = ty->getContextSubstitutionMap (&M, decl);
2510
2500
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);
2514
2506
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);
2519
2510
}
2520
2511
} else if (auto *decl = ty->getEnumOrBoundGenericEnum ()) {
2521
2512
auto subMap = ty->getContextSubstitutionMap (&M, decl);
@@ -2532,9 +2523,8 @@ bool TypeConverter::visitAggregateLeaves(
2532
2523
element, element->getArgumentInterfaceType ()->getReducedType (
2533
2524
decl->getGenericSignature ()));
2534
2525
2535
- insertIntoWorklist (substElementType, origElementTy,
2536
- TaggedUnion<ValueDecl *, unsigned >(
2537
- static_cast <ValueDecl *>(element)));
2526
+ insertIntoWorklist (substElementType, origElementTy, element,
2527
+ llvm::None);
2538
2528
}
2539
2529
} else {
2540
2530
llvm_unreachable (" unknown aggregate kind!" );
@@ -2543,7 +2533,7 @@ bool TypeConverter::visitAggregateLeaves(
2543
2533
}
2544
2534
2545
2535
// This type is a leaf. Visit it.
2546
- auto success = visit (ty, origTy, path );
2536
+ auto success = visit (ty, origTy, field, index );
2547
2537
if (!success)
2548
2538
return false ;
2549
2539
}
@@ -2567,26 +2557,23 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
2567
2557
bool hasNoNontrivialLexicalLeaf = visitAggregateLeaves (
2568
2558
origType, substType, forExpansion,
2569
2559
/* isLeaf=*/
2570
- [&](auto ty, auto origTy, auto either ) -> bool {
2560
+ [&](auto ty, auto origTy, auto *field, auto index ) -> bool {
2571
2561
// The field's type is an aggregate. Treat it as a leaf if it
2572
2562
// has a lifetime annotation.
2573
2563
2574
2564
// If it's a field of a tuple or the top-level type, there's no value
2575
2565
// decl on which to look for an attribute. It's a leaf iff the type
2576
2566
// has a lifetime annotation.
2577
- if (either.template isa <unsigned >() ||
2578
- either.template get <ValueDecl *>() == nullptr )
2567
+ if (index || !field)
2579
2568
return getLifetimeAnnotation (ty).isSome ();
2580
2569
2581
2570
// It's a field of a struct or an enum. It's a leaf if the type
2582
2571
// or the var decl has a lifetime annotation.
2583
- return either.template get <ValueDecl *>()
2584
- ->getLifetimeAnnotation ()
2585
- .isSome () ||
2572
+ return field->getLifetimeAnnotation ().isSome () ||
2586
2573
getLifetimeAnnotation (ty);
2587
2574
},
2588
2575
/* visit=*/
2589
- [&](auto ty, auto origTy, auto either ) -> bool {
2576
+ [&](auto ty, auto origTy, auto *field, auto index ) -> bool {
2590
2577
// Look at each leaf: if it is non-trivial, verify that it is
2591
2578
// attributed @_eagerMove.
2592
2579
@@ -2605,8 +2592,7 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
2605
2592
// not lexical. The leaf must be annotated @_eagerMove.
2606
2593
// Otherwise, the whole type would be lexical.
2607
2594
2608
- if (either.template isa <unsigned >() ||
2609
- either.template get <ValueDecl *>() == nullptr ) {
2595
+ if (index || !field) {
2610
2596
// There is no field decl that might be annotated @_eagerMove. The
2611
2597
// field is @_eagerMove iff its type is annotated @_eagerMove.
2612
2598
return getLifetimeAnnotation (ty) == LifetimeAnnotation::EagerMove;
@@ -2615,7 +2601,7 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
2615
2601
// The field is non-trivial and the whole type is non-lexical.
2616
2602
// That's fine as long as the field or its type is annotated
2617
2603
// @_eagerMove.
2618
- return either. template get <ValueDecl *>() ->getLifetimeAnnotation () ==
2604
+ return field ->getLifetimeAnnotation () ==
2619
2605
LifetimeAnnotation::EagerMove ||
2620
2606
getLifetimeAnnotation (ty) == LifetimeAnnotation::EagerMove;
2621
2607
});
0 commit comments