@@ -3859,15 +3859,23 @@ namespace Lowering {
3859
3859
// / function parameter and result types.
3860
3860
class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
3861
3861
private llvm::TrailingObjects<SILFunctionType, SILParameterInfo,
3862
- SILResultInfo> {
3862
+ SILResultInfo, SILYieldInfo, CanType > {
3863
3863
friend TrailingObjects;
3864
3864
3865
3865
size_t numTrailingObjects (OverloadToken<SILParameterInfo>) const {
3866
3866
return NumParameters;
3867
3867
}
3868
3868
3869
3869
size_t numTrailingObjects (OverloadToken<SILResultInfo>) const {
3870
- return hasErrorResult () ? 1 : 0 ;
3870
+ return getNumResults () + (hasErrorResult () ? 1 : 0 );
3871
+ }
3872
+
3873
+ size_t numTrailingObjects (OverloadToken<SILYieldInfo>) const {
3874
+ return getNumYields ();
3875
+ }
3876
+
3877
+ size_t numTrailingObjects (OverloadToken<CanType>) const {
3878
+ return hasResultCache () ? 2 : 0 ;
3871
3879
}
3872
3880
3873
3881
public:
@@ -4040,12 +4048,13 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
4040
4048
unsigned NumAnyResults : 16 ; // Not including the ErrorResult.
4041
4049
unsigned NumAnyIndirectFormalResults : 16 ; // Subset of NumAnyResults.
4042
4050
4051
+ // [SILFunctionType-layout]
4043
4052
// The layout of a SILFunctionType in memory is:
4044
4053
// SILFunctionType
4045
4054
// SILParameterInfo[NumParameters]
4046
4055
// SILResultInfo[isCoroutine() ? 0 : NumAnyResults]
4047
- // SILYieldInfo[isCoroutine() ? NumAnyResults : 0]
4048
4056
// SILResultInfo? // if hasErrorResult()
4057
+ // SILYieldInfo[isCoroutine() ? NumAnyResults : 0]
4049
4058
// CanType? // if !isCoro && NumAnyResults > 1, formal result cache
4050
4059
// CanType? // if !isCoro && NumAnyResults > 1, all result cache
4051
4060
@@ -4058,34 +4067,16 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
4058
4067
}
4059
4068
4060
4069
MutableArrayRef<SILResultInfo> getMutableResults () {
4061
- auto *ptr = reinterpret_cast <SILResultInfo *>(getMutableParameters ().end ());
4062
- return {ptr, getNumResults ()};
4070
+ return {getTrailingObjects<SILResultInfo>(), getNumResults ()};
4063
4071
}
4064
4072
4065
4073
MutableArrayRef<SILYieldInfo> getMutableYields () {
4066
- auto *ptr = reinterpret_cast <SILYieldInfo *>(getMutableParameters ().end ());
4067
- return {ptr, getNumYields ()};
4068
- }
4069
-
4070
- // / Return a pointer past the end of the formal results, whether they
4071
- // / are yield-results or normal results.
4072
- void *getEndOfFormalResults () {
4073
- return isCoroutine () ? static_cast <void *>(getMutableYields ().end ())
4074
- : static_cast <void *>(getMutableResults ().end ());
4074
+ return {getTrailingObjects<SILYieldInfo>(), getNumYields ()};
4075
4075
}
4076
4076
4077
4077
SILResultInfo &getMutableErrorResult () {
4078
4078
assert (hasErrorResult ());
4079
- return *reinterpret_cast <SILResultInfo*>(getEndOfFormalResults ());
4080
- }
4081
-
4082
- // / Return a pointer past the end of all of the results, including the
4083
- // / error result if one is present.
4084
- void *getEndOfAllResults () {
4085
- void *end = getEndOfFormalResults ();
4086
- if (hasErrorResult ())
4087
- end = reinterpret_cast <char *>(end) + sizeof (SILResultInfo);
4088
- return end;
4079
+ return *(getTrailingObjects<SILResultInfo>() + getNumResults ());
4089
4080
}
4090
4081
4091
4082
// / Do we have slots for caches of the normal-result tuple type?
@@ -4095,14 +4086,13 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
4095
4086
4096
4087
CanType &getMutableFormalResultsCache () const {
4097
4088
assert (hasResultCache ());
4098
- auto *ptr = const_cast <SILFunctionType *>(this )->getEndOfAllResults ();
4099
- return *reinterpret_cast <CanType*>(ptr);
4089
+ return *const_cast <SILFunctionType *>(this )->getTrailingObjects <CanType>();
4100
4090
}
4101
4091
4102
4092
CanType &getMutableAllResultsCache () const {
4103
4093
assert (hasResultCache ());
4104
- auto *ptr = const_cast <SILFunctionType *>(this )->getEndOfAllResults ();
4105
- return *( reinterpret_cast <CanType *>(ptr) + 1 );
4094
+ return *( const_cast <SILFunctionType *>(this )->getTrailingObjects <CanType>()
4095
+ + 1 );
4106
4096
}
4107
4097
4108
4098
SILFunctionType (GenericSignature genericSig, ExtInfo ext,
0 commit comments