Skip to content

Commit a3e3a3d

Browse files
authored
Merge pull request #13368 from davezarzycki/nfc_repack_two_sil_types
2 parents b96731d + 58d1a57 commit a3e3a3d

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

include/swift/AST/Types.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ class alignas(1 << TypeAlignInBits) TypeBase {
339339
};
340340
NUMBITS(SILFunctionType, NumTypeBaseBits + 12);
341341

342+
struct SILBoxTypeBitfields {
343+
unsigned : NumTypeBaseBits;
344+
unsigned : 32 - NumTypeBaseBits; // unused / padding
345+
unsigned NumGenericArgs : 32;
346+
};
347+
NUMBITS(SILBoxType, 64);
348+
342349
struct AnyMetatypeTypeBitfields {
343350
unsigned : NumTypeBaseBits;
344351
/// The representation of the metatype.
@@ -379,6 +386,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
379386
TypeVariableTypeBitfields TypeVariableTypeBits;
380387
ArchetypeTypeBitfields ArchetypeTypeBits;
381388
SILFunctionTypeBitfields SILFunctionTypeBits;
389+
SILBoxTypeBitfields SILBoxTypeBits;
382390
AnyMetatypeTypeBitfields AnyMetatypeTypeBits;
383391
ProtocolCompositionTypeBitfields ProtocolCompositionTypeBits;
384392
TupleTypeBitfields TupleTypeBits;
@@ -2955,7 +2963,7 @@ enum class ParameterConvention {
29552963
};
29562964
// Check that the enum values fit inside SILFunctionTypeBits.
29572965
static_assert(unsigned(ParameterConvention::Direct_Guaranteed) < (1<<3),
2958-
"fits in SILFunctionTypeBits");
2966+
"fits in SILFunctionTypeBits and SILParameterInfo");
29592967

29602968
// Does this parameter convention require indirect storage? This reflects a
29612969
// SILFunctionType's formal (immutable) conventions, as opposed to the transient
@@ -3015,20 +3023,19 @@ inline bool isGuaranteedParameter(ParameterConvention conv) {
30153023

30163024
/// A parameter type and the rules for passing it.
30173025
class SILParameterInfo {
3018-
CanType Ty;
3019-
ParameterConvention Convention;
3026+
llvm::PointerIntPair<CanType, 3, ParameterConvention> TypeAndConvention;
30203027
public:
3021-
SILParameterInfo() : Ty(), Convention((ParameterConvention)0) {}
3028+
SILParameterInfo() = default;//: Ty(), Convention((ParameterConvention)0) {}
30223029
SILParameterInfo(CanType type, ParameterConvention conv)
3023-
: Ty(type), Convention(conv) {
3030+
: TypeAndConvention(type, conv) {
30243031
assert(type->isLegalSILType() && "SILParameterInfo has illegal SIL type");
30253032
}
30263033

30273034
CanType getType() const {
3028-
return Ty;
3035+
return TypeAndConvention.getPointer();
30293036
}
30303037
ParameterConvention getConvention() const {
3031-
return Convention;
3038+
return TypeAndConvention.getInt();
30323039
}
30333040
// Does this parameter convention require indirect storage? This reflects a
30343041
// SILFunctionType's formal (immutable) conventions, as opposed to the
@@ -3089,8 +3096,8 @@ class SILParameterInfo {
30893096
}
30903097

30913098
void profile(llvm::FoldingSetNodeID &id) {
3092-
id.AddPointer(Ty.getPointer());
3093-
id.AddInteger((unsigned)Convention);
3099+
id.AddPointer(getType().getPointer());
3100+
id.AddInteger((unsigned)getConvention());
30943101
}
30953102

30963103
void dump() const;
@@ -3104,7 +3111,7 @@ class SILParameterInfo {
31043111
}
31053112

31063113
bool operator==(SILParameterInfo rhs) const {
3107-
return Ty == rhs.Ty && Convention == rhs.Convention;
3114+
return getType() == rhs.getType() && getConvention() == rhs.getConvention();
31083115
}
31093116
bool operator!=(SILParameterInfo rhs) const {
31103117
return !(*this == rhs);
@@ -3807,7 +3814,6 @@ class SILBoxType final : public TypeBase,
38073814
friend TrailingObjects;
38083815

38093816
SILLayout *Layout;
3810-
unsigned NumGenericArgs;
38113817

38123818
static RecursiveTypeProperties
38133819
getRecursivePropertiesFromSubstitutions(SubstitutionList Args);
@@ -3823,7 +3829,7 @@ class SILBoxType final : public TypeBase,
38233829
SILLayout *getLayout() const { return Layout; }
38243830
SubstitutionList getGenericArgs() const {
38253831
return llvm::makeArrayRef(getTrailingObjects<Substitution>(),
3826-
NumGenericArgs);
3832+
SILBoxTypeBits.NumGenericArgs);
38273833
}
38283834

38293835
// In SILType.h:

lib/AST/Type.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,10 +4103,8 @@ void SILBoxType::Profile(llvm::FoldingSetNodeID &id, SILLayout *Layout,
41034103
SILBoxType::SILBoxType(ASTContext &C,
41044104
SILLayout *Layout, SubstitutionList Args)
41054105
: TypeBase(TypeKind::SILBox, &C,
4106-
getRecursivePropertiesFromSubstitutions(Args)),
4107-
Layout(Layout),
4108-
NumGenericArgs(Args.size())
4109-
{
4106+
getRecursivePropertiesFromSubstitutions(Args)), Layout(Layout) {
4107+
SILBoxTypeBits.NumGenericArgs = Args.size();
41104108
#ifndef NDEBUG
41114109
// Check that the generic args are reasonable for the box's signature.
41124110
if (Layout->getGenericSignature())
@@ -4115,9 +4113,8 @@ SILBoxType::SILBoxType(ASTContext &C,
41154113
assert(arg.getReplacement()->isCanonical() &&
41164114
"box arguments must be canonical types!");
41174115
#endif
4118-
auto paramsBuf = getTrailingObjects<Substitution>();
4119-
for (unsigned i = 0; i < NumGenericArgs; ++i)
4120-
::new (paramsBuf + i) Substitution(Args[i]);
4116+
std::uninitialized_copy(Args.begin(), Args.end(),
4117+
getTrailingObjects<Substitution>());
41214118
}
41224119

41234120
RecursiveTypeProperties SILBoxType::

0 commit comments

Comments
 (0)