Skip to content

Commit 3af67e3

Browse files
committed
[NFC] Convert this code to use canonical types
1 parent 4be3c18 commit 3af67e3

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,14 +1260,16 @@ class TypeConverter {
12601260
/// Check the result of
12611261
/// getTypeLowering(AbstractionPattern,Type,TypeExpansionContext).
12621262
void verifyLowering(const TypeLowering &, AbstractionPattern origType,
1263-
Type origSubstType, TypeExpansionContext forExpansion);
1263+
CanType origSubstType,
1264+
TypeExpansionContext forExpansion);
12641265
bool
1265-
visitAggregateLeaves(Lowering::AbstractionPattern origType, Type substType,
1266+
visitAggregateLeaves(Lowering::AbstractionPattern origType,
1267+
CanType substType,
12661268
TypeExpansionContext context,
1267-
std::function<bool(Type, Lowering::AbstractionPattern,
1269+
std::function<bool(CanType, Lowering::AbstractionPattern,
12681270
ValueDecl *, Optional<unsigned>)>
12691271
isLeafAggregate,
1270-
std::function<bool(Type, Lowering::AbstractionPattern,
1272+
std::function<bool(CanType, Lowering::AbstractionPattern,
12711273
ValueDecl *, Optional<unsigned>)>
12721274
visit);
12731275
#endif

lib/SIL/IR/TypeLowering.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,74 +2712,76 @@ TypeConverter::getTypeLowering(AbstractionPattern origType,
27122712

27132713
#ifndef NDEBUG
27142714
bool TypeConverter::visitAggregateLeaves(
2715-
Lowering::AbstractionPattern origType, Type substType,
2715+
Lowering::AbstractionPattern origType, CanType substType,
27162716
TypeExpansionContext context,
2717-
std::function<bool(Type, Lowering::AbstractionPattern, ValueDecl *,
2717+
std::function<bool(CanType, Lowering::AbstractionPattern, ValueDecl *,
27182718
Optional<unsigned>)>
27192719
isLeafAggregate,
2720-
std::function<bool(Type, Lowering::AbstractionPattern, ValueDecl *,
2720+
std::function<bool(CanType, Lowering::AbstractionPattern, ValueDecl *,
27212721
Optional<unsigned>)>
27222722
visit) {
2723-
llvm::SmallSet<std::tuple<TypeBase *, ValueDecl *, unsigned>, 16> visited;
2723+
llvm::SmallSet<std::tuple<CanType, ValueDecl *, unsigned>, 16> visited;
27242724
llvm::SmallVector<
2725-
std::tuple<TypeBase *, AbstractionPattern, ValueDecl *, unsigned>, 16>
2725+
std::tuple<CanType, AbstractionPattern, ValueDecl *, unsigned>, 16>
27262726
worklist;
27272727
auto insertIntoWorklist = [&visited,
2728-
&worklist](Type substTy, AbstractionPattern origTy,
2728+
&worklist](CanType substTy,
2729+
AbstractionPattern origTy,
27292730
ValueDecl *field,
27302731
Optional<unsigned> maybeIndex) -> bool {
27312732
unsigned index = maybeIndex.value_or(UINT_MAX);
2732-
if (!visited.insert({substTy.getPointer(), field, index}).second)
2733+
if (!visited.insert({substTy, field, index}).second)
27332734
return false;
2734-
worklist.push_back({substTy.getPointer(), origTy, field, index});
2735+
worklist.push_back({substTy, origTy, field, index});
27352736
return true;
27362737
};
27372738
auto popFromWorklist = [&worklist]()
2738-
-> std::tuple<Type, AbstractionPattern, ValueDecl *, Optional<unsigned>> {
2739-
TypeBase *ty;
2739+
-> std::tuple<CanType, AbstractionPattern, ValueDecl *, Optional<unsigned>> {
2740+
CanType ty;
27402741
AbstractionPattern origTy = AbstractionPattern::getOpaque();
27412742
ValueDecl *field;
27422743
unsigned index;
27432744
std::tie(ty, origTy, field, index) = worklist.pop_back_val();
27442745
Optional<unsigned> maybeIndex;
27452746
if (index != UINT_MAX)
27462747
maybeIndex = {index};
2747-
return {ty->getCanonicalType(), origTy, field, index};
2748+
return {ty, origTy, field, index};
27482749
};
2749-
auto isAggregate = [](Type ty) {
2750-
return ty->is<SILPackType>() || ty->is<TupleType>() || ty->getEnumOrBoundGenericEnum() ||
2751-
ty->getStructOrBoundGenericStruct();
2750+
auto isAggregate = [](CanType ty) {
2751+
return isa<SILPackType>(ty) ||
2752+
isa<TupleType>(ty) ||
2753+
ty.getEnumOrBoundGenericEnum() ||
2754+
ty.getStructOrBoundGenericStruct();
27522755
};
27532756
insertIntoWorklist(substType, origType, nullptr, llvm::None);
27542757
while (!worklist.empty()) {
2755-
Type ty;
2758+
CanType ty;
27562759
AbstractionPattern origTy = AbstractionPattern::getOpaque();
27572760
ValueDecl *field;
27582761
Optional<unsigned> index;
27592762
std::tie(ty, origTy, field, index) = popFromWorklist();
27602763
if (isAggregate(ty) && !isLeafAggregate(ty, origTy, field, index)) {
2761-
if (auto packTy = ty->getAs<SILPackType>()) {
2764+
if (auto packTy = dyn_cast<SILPackType>(ty)) {
27622765
for (auto packIndex : indices(packTy->getElementTypes())) {
27632766
auto origElementTy = origTy.getPackElementType(packIndex);
2764-
auto substElementTy =
2765-
packTy->getElementType(packIndex)->getCanonicalType();
2767+
auto substElementTy = packTy.getElementType(packIndex);
27662768
substElementTy =
27672769
computeLoweredRValueType(context, origElementTy, substElementTy);
27682770
insertIntoWorklist(substElementTy, origElementTy, nullptr,
27692771
packIndex);
27702772
}
2771-
} else if (auto tupleTy = ty->getAs<TupleType>()) {
2773+
} else if (auto tupleTy = dyn_cast<TupleType>(ty)) {
27722774
unsigned tupleIndex = 0;
27732775
origTy.forEachExpandedTupleElement(
2774-
CanTupleType(tupleTy),
2776+
tupleTy,
27752777
[&](auto origElementTy, auto substElementTy, auto element) {
27762778
substElementTy =
27772779
substOpaqueTypesWithUnderlyingTypes(substElementTy, context);
27782780
insertIntoWorklist(substElementTy, origElementTy, nullptr,
27792781
tupleIndex);
27802782
++tupleIndex;
27812783
});
2782-
} else if (auto *decl = ty->getStructOrBoundGenericStruct()) {
2784+
} else if (auto *decl = ty.getStructOrBoundGenericStruct()) {
27832785
for (auto *structField : decl->getStoredProperties()) {
27842786
auto subMap = ty->getContextSubstitutionMap(&M, decl);
27852787
auto substFieldTy =
@@ -2794,7 +2796,7 @@ bool TypeConverter::visitAggregateLeaves(
27942796
insertIntoWorklist(substFieldTy, origFieldType, structField,
27952797
llvm::None);
27962798
}
2797-
} else if (auto *decl = ty->getEnumOrBoundGenericEnum()) {
2799+
} else if (auto *decl = ty.getEnumOrBoundGenericEnum()) {
27982800
auto subMap = ty->getContextSubstitutionMap(&M, decl);
27992801
for (auto *element : decl->getAllElements()) {
28002802
if (!element->hasAssociatedValues())
@@ -2827,16 +2829,17 @@ bool TypeConverter::visitAggregateLeaves(
28272829
}
28282830

28292831
void TypeConverter::verifyLowering(const TypeLowering &lowering,
2830-
AbstractionPattern origType, Type substType,
2832+
AbstractionPattern origType,
2833+
CanType substType,
28312834
TypeExpansionContext forExpansion) {
28322835
// Non-trivial lowerings should always be lexical unless all non-trivial
28332836
// fields are eager move.
28342837
if (!lowering.isTrivial() && !lowering.isLexical()) {
28352838
if (lowering.getRecursiveProperties().isInfinite())
28362839
return;
2837-
auto getLifetimeAnnotation = [](Type ty) -> LifetimeAnnotation {
2840+
auto getLifetimeAnnotation = [](CanType ty) -> LifetimeAnnotation {
28382841
NominalTypeDecl *nominal;
2839-
if (!(nominal = ty->getAnyNominal()))
2842+
if (!(nominal = ty.getAnyNominal()))
28402843
return LifetimeAnnotation::None;
28412844
return nominal->getLifetimeAnnotation();
28422845
};
@@ -2865,7 +2868,7 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
28652868

28662869
// If the leaf is the whole type, verify that it is annotated
28672870
// @_eagerMove.
2868-
if (ty->getCanonicalType() == substType->getCanonicalType())
2871+
if (ty == substType)
28692872
return getLifetimeAnnotation(ty) == LifetimeAnnotation::EagerMove;
28702873

28712874
auto &tyLowering = getTypeLowering(origTy, ty, forExpansion);

0 commit comments

Comments
 (0)