Skip to content

Commit d2415fc

Browse files
committed
Add LifetimeDependence to GenericFunctionType
1 parent 40ff560 commit d2415fc

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

include/swift/AST/Types.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,10 +3866,11 @@ std::string getParamListAsString(ArrayRef<AnyFunctionType::Param> parameters);
38663866
/// on those parameters and dependent member types thereof. The input and
38673867
/// output types of the generic function can be expressed in terms of those
38683868
/// generic parameters.
3869-
class GenericFunctionType final : public AnyFunctionType,
3870-
public llvm::FoldingSetNode,
3871-
private llvm::TrailingObjects<GenericFunctionType, AnyFunctionType::Param,
3872-
Type> {
3869+
class GenericFunctionType final
3870+
: public AnyFunctionType,
3871+
public llvm::FoldingSetNode,
3872+
private llvm::TrailingObjects<GenericFunctionType, AnyFunctionType::Param,
3873+
Type, LifetimeDependenceInfo> {
38733874
friend TrailingObjects;
38743875

38753876
GenericSignature Signature;
@@ -3882,6 +3883,10 @@ class GenericFunctionType final : public AnyFunctionType,
38823883
return hasGlobalActor() + hasThrownError();
38833884
}
38843885

3886+
size_t numTrailingObjects(OverloadToken<LifetimeDependenceInfo>) const {
3887+
return hasLifetimeDependenceInfo() ? 1 : 0;
3888+
}
3889+
38853890
/// Construct a new generic function type.
38863891
GenericFunctionType(GenericSignature sig, ArrayRef<Param> params, Type result,
38873892
llvm::Optional<ExtInfo> info, const ASTContext *ctx,
@@ -3909,7 +3914,17 @@ class GenericFunctionType final : public AnyFunctionType,
39093914
return Type();
39103915
return getTrailingObjects<Type>()[hasGlobalActor()];
39113916
}
3912-
3917+
3918+
LifetimeDependenceInfo getLifetimeDependenceInfo() const {
3919+
if (!hasLifetimeDependenceInfo()) {
3920+
return LifetimeDependenceInfo();
3921+
}
3922+
auto *info = getTrailingObjects<LifetimeDependenceInfo>();
3923+
assert(!info->empty() && "If the LifetimeDependenceInfo was empty, we "
3924+
"shouldn't have stored it.");
3925+
return *info;
3926+
}
3927+
39133928
/// Retrieve the generic signature of this function type.
39143929
GenericSignature getGenericSignature() const {
39153930
return Signature;

lib/AST/ASTContext.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4490,9 +4490,13 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature sig,
44904490
if (globalActor && !sig->isReducedType(globalActor))
44914491
isCanonical = false;
44924492

4493+
bool hasLifetimeDependenceInfo =
4494+
info.has_value() && !info.value().getLifetimeDependenceInfo().empty();
4495+
44934496
unsigned numTypes = (globalActor ? 1 : 0) + (thrownError ? 1 : 0);
4494-
size_t allocSize = totalSizeToAlloc<AnyFunctionType::Param, Type>(
4495-
params.size(), numTypes);
4497+
size_t allocSize =
4498+
totalSizeToAlloc<AnyFunctionType::Param, Type, LifetimeDependenceInfo>(
4499+
params.size(), numTypes, hasLifetimeDependenceInfo ? 1 : 0);
44964500
void *mem = ctx.Allocate(allocSize, alignof(GenericFunctionType));
44974501

44984502
auto properties = getGenericFunctionRecursiveProperties(params, result);
@@ -4522,6 +4526,11 @@ GenericFunctionType::GenericFunctionType(
45224526
}
45234527
if (Type thrownError = info->getThrownError())
45244528
getTrailingObjects<Type>()[thrownErrorIndex] = thrownError;
4529+
4530+
auto lifetimeDependenceInfo = info->getLifetimeDependenceInfo();
4531+
if (!lifetimeDependenceInfo.empty()) {
4532+
*getTrailingObjects<LifetimeDependenceInfo>() = lifetimeDependenceInfo;
4533+
}
45254534
}
45264535
}
45274536

lib/AST/Type.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,8 +4121,7 @@ LifetimeDependenceInfo AnyFunctionType::getLifetimeDependenceInfo() const {
41214121
case TypeKind::Function:
41224122
return cast<FunctionType>(this)->getLifetimeDependenceInfo();
41234123
case TypeKind::GenericFunction:
4124-
// TODO: Handle GenericFunction
4125-
return LifetimeDependenceInfo();
4124+
return cast<GenericFunctionType>(this)->getLifetimeDependenceInfo();
41264125

41274126
default:
41284127
llvm_unreachable("Illegal type kind for AnyFunctionType.");

0 commit comments

Comments
 (0)