Skip to content

Commit 2eb41a9

Browse files
committed
Introduce SILType::mapTypeOutOfContext.
This does the same thing as taking the AST type and running it through mapTypeOutOfContext, but saves call sites from having to do the unwrap-rewrap dance.
1 parent 7d204ce commit 2eb41a9

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

include/swift/SIL/SILType.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ class SILType {
492492
/// Returns the underlying referent SILType of an @sil_unowned or @sil_weak
493493
/// Type.
494494
SILType getReferentType(SILModule &M) const;
495+
496+
/// Returns a SILType with any archetypes mapped out of context.
497+
SILType mapTypeOutOfContext() const;
495498

496499
/// Given two SIL types which are representations of the same type,
497500
/// check whether they have an abstraction difference.

lib/IRGen/GenHeap.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,10 +1558,7 @@ class FixedBoxTypeInfoBase : public BoxTypeInfo {
15581558
// Allocate a new object using the layout.
15591559
auto boxedInterfaceType = boxedType;
15601560
if (env) {
1561-
boxedInterfaceType = SILType::getPrimitiveType(
1562-
boxedType.getSwiftRValueType()->mapTypeOutOfContext()
1563-
->getCanonicalType(),
1564-
boxedType.getCategory());
1561+
boxedInterfaceType = boxedType.mapTypeOutOfContext();
15651562
}
15661563

15671564
auto boxDescriptor = IGF.IGM.getAddrOfBoxDescriptor(

lib/SIL/SILType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ SILType SILType::getReferentType(SILModule &M) const {
390390
return M.Types.getLoweredType(Ty->getReferentType()->getCanonicalType());
391391
}
392392

393+
SILType SILType::mapTypeOutOfContext() const {
394+
return SILType::getPrimitiveType(getSwiftRValueType()->mapTypeOutOfContext()
395+
->getCanonicalType(),
396+
getCategory());
397+
}
398+
393399
CanType
394400
SILBoxType::getFieldLoweredType(SILModule &M, unsigned index) const {
395401
auto fieldTy = getLayout()->getFields()[index].getLoweredType();

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3764,10 +3764,7 @@ lowerKeyPathSubscriptIndexTypes(
37643764
auto indexLoweredTy = SGM.Types.getLoweredType(
37653765
AbstractionPattern::getOpaque(),
37663766
indexTy);
3767-
indexLoweredTy = SILType::getPrimitiveType(
3768-
indexLoweredTy.getSwiftRValueType()->mapTypeOutOfContext()
3769-
->getCanonicalType(),
3770-
indexLoweredTy.getCategory());
3767+
indexLoweredTy = indexLoweredTy.mapTypeOutOfContext();
37713768
indexPatterns.push_back({indexTy->mapTypeOutOfContext()
37723769
->getCanonicalType(),
37733770
indexLoweredTy});

0 commit comments

Comments
 (0)