Skip to content

SIL: Remove default arguments from resilience expansion parameters #23110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ class SILBuilder {
SILModule &getModule() const { return C.Module; }
ASTContext &getASTContext() const { return getModule().getASTContext(); }
const Lowering::TypeLowering &getTypeLowering(SILType T) const {
return getModule().getTypeLowering(T);
// FIXME: Expansion
return getModule().Types.getTypeLowering(T,
ResilienceExpansion::Minimal);
}

void setOpenedArchetypesTracker(SILOpenedArchetypesTracker *Tracker) {
Expand Down Expand Up @@ -2155,13 +2157,15 @@ class SILBuilder {
if (!SILModuleConventions(M).useLoweredAddresses())
return true;

// FIXME: Just call getTypeLowering() here, and move this code there

auto expansion = ResilienceExpansion::Maximal;
// If there's no current SILFunction, we're inserting into a global
// variable initializer.
if (F)
expansion = F->getResilienceExpansion();

return M.getTypeLowering(Ty, expansion).isLoadable();
return M.Types.getTypeLowering(Ty, expansion).isLoadable();
}

void appendOperandTypeName(SILType OpdTy, llvm::SmallString<16> &Name) {
Expand Down
7 changes: 0 additions & 7 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,6 @@ class SILModule {
/// This converts Swift types to SILTypes.
mutable Lowering::TypeConverter Types;

/// Look up the TypeLowering for a SILType.
const Lowering::TypeLowering &
getTypeLowering(SILType t, ResilienceExpansion expansion =
ResilienceExpansion::Minimal) {
return Types.getTypeLowering(t, expansion);
}

/// Invalidate cached entries in SIL Loader.
void invalidateSILLoaderCaches();

Expand Down
58 changes: 37 additions & 21 deletions include/swift/SIL/TypeLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,29 @@ class TypeLowering {
};

private:
friend class TypeConverter;

/// The SIL type of values with this Swift type.
SILType LoweredType;

RecursiveProperties Properties;
unsigned ReferenceCounted : 1;

public:
/// The resilience expansion for this type lowering.
/// If the type is not resilient at all, this is always Minimal.
ResilienceExpansion forExpansion = ResilienceExpansion::Minimal;
unsigned ForExpansion : 1;

/// A single linked list of lowerings for different resilience expansions.
/// The first lowering is always for ResilientExpansion::Minimal.
mutable const TypeLowering *nextExpansion = nullptr;
mutable const TypeLowering *NextExpansion = nullptr;

protected:
TypeLowering(SILType type, RecursiveProperties properties,
IsReferenceCounted_t isRefCounted)
IsReferenceCounted_t isRefCounted,
ResilienceExpansion forExpansion)
: LoweredType(type), Properties(properties),
ReferenceCounted(isRefCounted) {}
ReferenceCounted(isRefCounted),
ForExpansion(unsigned(forExpansion)) {}

public:
TypeLowering(const TypeLowering &) = delete;
Expand All @@ -247,12 +250,22 @@ class TypeLowering {
/// convention?
///
/// This is independent of whether the SIL argument is address type.
bool isFormallyPassedIndirectly() const { return isAddressOnly(); }
bool isFormallyPassedIndirectly() const {
assert(!isResilient() ||
getResilienceExpansion() == ResilienceExpansion::Minimal &&
"calling convention uses minimal resilience expansion");
return isAddressOnly();
}

/// Are r-values of this type returned indirectly by formal convention?
///
/// This is independent of whether the SIL result is address type.
bool isFormallyReturnedIndirectly() const { return isAddressOnly(); }
bool isFormallyReturnedIndirectly() const {
assert(!isResilient() ||
getResilienceExpansion() == ResilienceExpansion::Minimal &&
"calling convention uses minimal resilience expansion");
return isAddressOnly();
}

RecursiveProperties getRecursiveProperties() const {
return Properties;
Expand Down Expand Up @@ -306,6 +319,10 @@ class TypeLowering {
return Properties.isResilient();
}

ResilienceExpansion getResilienceExpansion() const {
return ResilienceExpansion(ForExpansion);
}

/// Produce an exact copy of the value in the given address as a
/// scalar. The caller is responsible for destroying this value,
/// e.g. by releasing it.
Expand Down Expand Up @@ -748,8 +765,7 @@ class TypeConverter {
/// Lowers a Swift type to a SILType, and returns the SIL TypeLowering
/// for that type.
const TypeLowering &
getTypeLowering(Type t, ResilienceExpansion forExpansion =
ResilienceExpansion::Minimal) {
getTypeLowering(Type t, ResilienceExpansion forExpansion) {
AbstractionPattern pattern(getCurGenericContext(), t->getCanonicalType());
return getTypeLowering(pattern, t, forExpansion);
}
Expand All @@ -758,33 +774,28 @@ class TypeConverter {
/// patterns of the given original type.
const TypeLowering &getTypeLowering(AbstractionPattern origType,
Type substType,
ResilienceExpansion forExpansion =
ResilienceExpansion::Minimal);
ResilienceExpansion forExpansion);

/// Returns the SIL TypeLowering for an already lowered SILType. If the
/// SILType is an address, returns the TypeLowering for the pointed-to
/// type.
const TypeLowering &
getTypeLowering(SILType t, ResilienceExpansion forExpansion =
ResilienceExpansion::Minimal);
getTypeLowering(SILType t, ResilienceExpansion forExpansion);

// Returns the lowered SIL type for a Swift type.
SILType getLoweredType(Type t, ResilienceExpansion forExpansion
= ResilienceExpansion::Minimal) {
SILType getLoweredType(Type t, ResilienceExpansion forExpansion) {
return getTypeLowering(t, forExpansion).getLoweredType();
}

// Returns the lowered SIL type for a Swift type.
SILType getLoweredType(AbstractionPattern origType, Type substType,
ResilienceExpansion forExpansion =
ResilienceExpansion::Minimal) {
ResilienceExpansion forExpansion) {
return getTypeLowering(origType, substType, forExpansion)
.getLoweredType();
}

SILType getLoweredLoadableType(Type t,
ResilienceExpansion forExpansion =
ResilienceExpansion::Minimal) {
ResilienceExpansion forExpansion) {
const TypeLowering &ti = getTypeLowering(t, forExpansion);
assert(
(ti.isLoadable() || !SILModuleConventions(M).useLoweredAddresses()) &&
Expand All @@ -793,11 +804,16 @@ class TypeConverter {
}

CanType getLoweredRValueType(Type t) {
return getLoweredType(t).getASTType();
// We're ignoring the category (object vs address), so the resilience
// expansion does not matter.
return getLoweredType(t, ResilienceExpansion::Minimal).getASTType();
}

CanType getLoweredRValueType(AbstractionPattern origType, Type substType) {
return getLoweredType(origType, substType).getASTType();
// We're ignoring the category (object vs address), so the resilience
// expansion does not matter.
return getLoweredType(origType, substType,
ResilienceExpansion::Minimal).getASTType();
}

AbstractionPattern getAbstractionPattern(AbstractStorageDecl *storage,
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenKeyPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ emitKeyPathComponent(IRGenModule &IGM,
case KeyPathPatternComponent::Kind::TupleElement:
assert(baseTy->is<TupleType>() && "not a tuple");

SILType loweredTy = IGM.getSILTypes().getLoweredType(baseTy);
SILType loweredTy = IGM.getLoweredType(baseTy);

// Tuple with fixed layout
//
Expand Down
8 changes: 6 additions & 2 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1434,12 +1434,16 @@ const TypeInfo &IRGenFunction::getTypeInfo(SILType T) {

/// Return the SIL-lowering of the given type.
SILType IRGenModule::getLoweredType(AbstractionPattern orig, Type subst) {
return getSILTypes().getLoweredType(orig, subst);
// FIXME: Expansion
return getSILTypes().getLoweredType(orig, subst,
ResilienceExpansion::Minimal);
}

/// Return the SIL-lowering of the given type.
SILType IRGenModule::getLoweredType(Type subst) {
return getSILTypes().getLoweredType(subst);
// FIXME: Expansion
return getSILTypes().getLoweredType(subst,
ResilienceExpansion::Minimal);
}

/// Get a pointer to the storage type for the given type. Note that,
Expand Down
18 changes: 12 additions & 6 deletions lib/SIL/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ class DestructureResults {
return;
}

auto &substResultTL = M.Types.getTypeLowering(origType, substType);
auto &substResultTL = M.Types.getTypeLowering(origType, substType,
ResilienceExpansion::Minimal);

// Determine the result convention.
ResultConvention convention;
Expand Down Expand Up @@ -590,7 +591,8 @@ class DestructureInputs {

unsigned origParamIndex = NextOrigParamIndex++;

auto &substTL = M.Types.getTypeLowering(origType, substType);
auto &substTL = M.Types.getTypeLowering(origType, substType,
ResilienceExpansion::Minimal);
ParameterConvention convention;
if (ownership == ValueOwnership::InOut) {
convention = ParameterConvention::Indirect_Inout;
Expand Down Expand Up @@ -627,10 +629,10 @@ class DestructureInputs {
return false;

auto foreignErrorTy =
M.Types.getLoweredType(Foreign.Error->getErrorParameterType());
M.Types.getLoweredRValueType(Foreign.Error->getErrorParameterType());

// Assume the error parameter doesn't have interesting lowering.
Inputs.push_back(SILParameterInfo(foreignErrorTy.getASTType(),
Inputs.push_back(SILParameterInfo(foreignErrorTy,
ParameterConvention::Direct_Unowned));
NextOrigParamIndex++;
return true;
Expand Down Expand Up @@ -748,8 +750,11 @@ lowerCaptureContextParameters(SILModule &M, AnyFunctionRef function,
auto type = VD->getInterfaceType();
auto canType = type->getCanonicalType(origGenericSig);

// FIXME: Could be changed to Maximal at some point without impacting ABI,
// as long as we make sure all call sites are non inlinable.
auto &loweredTL =
Types.getTypeLowering(AbstractionPattern(genericSig, canType), canType);
Types.getTypeLowering(AbstractionPattern(genericSig, canType), canType,
ResilienceExpansion::Minimal);
auto loweredTy = loweredTL.getLoweredType();
switch (Types.getDeclCaptureKind(capture)) {
case CaptureKind::None:
Expand Down Expand Up @@ -806,7 +811,8 @@ static void destructureYieldsForReadAccessor(SILModule &M,
return;
}

auto &tl = M.Types.getTypeLowering(origType, valueType);
auto &tl = M.Types.getTypeLowering(origType, valueType,
ResilienceExpansion::Minimal);
auto convention = [&] {
if (isFormallyPassedIndirectly(M, origType, valueType, tl))
return ParameterConvention::Indirect_In_Guaranteed;
Expand Down
13 changes: 9 additions & 4 deletions lib/SIL/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ SILType SILType::getSILTokenType(const ASTContext &C) {
}

bool SILType::isTrivial(SILModule &M) const {
return M.getTypeLowering(*this).isTrivial();
return M.Types.getTypeLowering(*this,
ResilienceExpansion::Minimal)
.isTrivial();
}

bool SILType::isReferenceCounted(SILModule &M) const {
return M.getTypeLowering(*this).isReferenceCounted();
return M.Types.getTypeLowering(*this,
ResilienceExpansion::Minimal)
.isReferenceCounted();
}

bool SILType::isNoReturnFunction() const {
Expand Down Expand Up @@ -187,11 +191,12 @@ bool SILType::isLoadableOrOpaque(SILFunction *inFunction) const {
/// address-only. For example, it could be a resilient struct or something of
/// unknown size.
bool SILType::isAddressOnly(SILModule &M) const {
return M.getTypeLowering(*this).isAddressOnly();
return M.Types.getTypeLowering(*this, ResilienceExpansion::Minimal)
.isAddressOnly();
}

bool SILType::isAddressOnly(SILFunction *inFunction) const {
return inFunction->getModule().getTypeLowering(*this,
return inFunction->getModule().Types.getTypeLowering(*this,
inFunction->getResilienceExpansion()).isAddressOnly();
}

Expand Down
14 changes: 7 additions & 7 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ void verifyKeyPathComponent(SILModule &M,
bool forPropertyDescriptor,
bool hasIndices) {
auto &C = M.getASTContext();


auto opaque = AbstractionPattern::getOpaque();
auto loweredBaseTy =
M.Types.getLoweredType(AbstractionPattern::getOpaque(), baseTy);
M.Types.getLoweredType(opaque, baseTy, expansion);
auto componentTy = component.getComponentType().subst(patternSubs)
->getCanonicalType();
auto loweredComponentTy =
M.Types.getLoweredType(AbstractionPattern::getOpaque(), componentTy);
M.Types.getLoweredType(opaque, componentTy, expansion);

auto checkIndexEqualsAndHash = [&]{
if (!component.getSubscriptIndices().empty()) {
Expand Down Expand Up @@ -386,15 +387,14 @@ void verifyKeyPathComponent(SILModule &M,
require(loweredBaseTy.is<TupleType>(),
"invalid baseTy, should have been a TupleType");

auto tupleTy = loweredBaseTy.getAs<TupleType>();
auto tupleTy = loweredBaseTy.castTo<TupleType>();
auto eltIdx = component.getTupleIndex();

require(eltIdx < tupleTy->getNumElements(),
"invalid element index, greater than # of tuple elements");

auto eltTy = tupleTy->getElementType(eltIdx)
->getReferenceStorageReferent()
->getCanonicalType();
auto eltTy = tupleTy.getElementType(eltIdx)
.getReferenceStorageReferent();

require(eltTy == componentTy,
"tuple element type should match the type of the component");
Expand Down
Loading