Skip to content

Commit bac7e6b

Browse files
committed
Add some helpers to the SILFunctionType component types.
1 parent eea07b3 commit bac7e6b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

include/swift/AST/Types.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,6 +3834,11 @@ class SILParameterInfo {
38343834
return SILParameterInfo(type, getConvention(), getDifferentiability());
38353835
}
38363836

3837+
/// Return a version of this parameter info with the convention replaced.
3838+
SILParameterInfo getWithConvention(ParameterConvention c) const {
3839+
return SILParameterInfo(getInterfaceType(), c, getDifferentiability());
3840+
}
3841+
38373842
/// Transform this SILParameterInfo by applying the user-provided
38383843
/// function to its type.
38393844
///
@@ -3849,6 +3854,15 @@ class SILParameterInfo {
38493854
->getCanonicalType());
38503855
}
38513856

3857+
/// Treating this parameter info as a component of the given function
3858+
/// type, apply any substitutions from the function type to it to
3859+
/// get a substituted version of it, as you would get from
3860+
/// SILFunctionType::getUnsubstitutedType.
3861+
SILParameterInfo getUnsubstituted(SILModule &M,
3862+
const SILFunctionType *fnType) const {
3863+
return getWithInterfaceType(getArgumentType(M, fnType));
3864+
}
3865+
38523866
void profile(llvm::FoldingSetNodeID &id) {
38533867
id.AddPointer(getInterfaceType().getPointer());
38543868
id.AddInteger((unsigned)getConvention());
@@ -3951,6 +3965,11 @@ class SILResultInfo {
39513965
return SILResultInfo(type, getConvention());
39523966
}
39533967

3968+
/// Return a version of this result info with the convention replaced.
3969+
SILResultInfo getWithConvention(ResultConvention c) const {
3970+
return SILResultInfo(getInterfaceType(), c);
3971+
}
3972+
39543973
// Does this result convention require indirect storage? This reflects a
39553974
// SILFunctionType's formal (immutable) conventions, as opposed to the
39563975
// transient SIL conventions that dictate SILValue types.
@@ -3976,6 +3995,15 @@ class SILResultInfo {
39763995
->getCanonicalType());
39773996
}
39783997

3998+
/// Treating this result info as a component of the given function
3999+
/// type, apply any substitutions from the function type to it to
4000+
/// get a substituted version of it, as you would get from
4001+
/// SILFunctionType::getUnsubstitutedType.
4002+
SILResultInfo getUnsubstituted(SILModule &M,
4003+
const SILFunctionType *fnType) const {
4004+
return getWithInterfaceType(getReturnValueType(M, fnType));
4005+
}
4006+
39794007
void profile(llvm::FoldingSetNodeID &id) {
39804008
id.AddPointer(TypeAndConvention.getOpaqueValue());
39814009
}
@@ -4016,6 +4044,11 @@ class SILYieldInfo : public SILParameterInfo {
40164044
return SILYieldInfo(type, getConvention());
40174045
}
40184046

4047+
/// Return a version of this yield info with the convention replaced.
4048+
SILYieldInfo getWithConvention(YieldConvention c) const {
4049+
return SILYieldInfo(getInterfaceType(), c);
4050+
}
4051+
40194052
template<typename F>
40204053
SILYieldInfo map(const F &fn) const {
40214054
return getWithInterfaceType(fn(getInterfaceType()));
@@ -4025,6 +4058,20 @@ class SILYieldInfo : public SILParameterInfo {
40254058
return getWithInterfaceType(getInterfaceType()->mapTypeOutOfContext()
40264059
->getCanonicalType());
40274060
}
4061+
4062+
CanType getYieldValueType(SILModule &M,
4063+
const SILFunctionType *fnType) const {
4064+
return getArgumentType(M, fnType);
4065+
}
4066+
4067+
/// Treating this yield info as a component of the given function
4068+
/// type, apply any substitutions from the function type to it to
4069+
/// get a substituted version of it, as you would get from
4070+
/// SILFunctionType::getUnsubstitutedType.
4071+
SILYieldInfo getUnsubstituted(SILModule &M,
4072+
const SILFunctionType *fnType) const {
4073+
return getWithInterfaceType(getYieldValueType(M, fnType));
4074+
}
40284075
};
40294076

40304077
/// SILCoroutineKind - What kind of coroutine is this SILFunction?

0 commit comments

Comments
 (0)