Skip to content

NFC: repack misc bits of two SIL types #13368

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 2 commits into from
Dec 11, 2017
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
30 changes: 18 additions & 12 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ class alignas(1 << TypeAlignInBits) TypeBase {
};
NUMBITS(SILFunctionType, NumTypeBaseBits + 12);

struct SILBoxTypeBitfields {
unsigned : NumTypeBaseBits;
unsigned : 32 - NumTypeBaseBits; // unused / padding
unsigned NumGenericArgs : 32;
};
NUMBITS(SILBoxType, 64);

struct AnyMetatypeTypeBitfields {
unsigned : NumTypeBaseBits;
/// The representation of the metatype.
Expand Down Expand Up @@ -379,6 +386,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
TypeVariableTypeBitfields TypeVariableTypeBits;
ArchetypeTypeBitfields ArchetypeTypeBits;
SILFunctionTypeBitfields SILFunctionTypeBits;
SILBoxTypeBitfields SILBoxTypeBits;
AnyMetatypeTypeBitfields AnyMetatypeTypeBits;
ProtocolCompositionTypeBitfields ProtocolCompositionTypeBits;
TupleTypeBitfields TupleTypeBits;
Expand Down Expand Up @@ -2955,7 +2963,7 @@ enum class ParameterConvention {
};
// Check that the enum values fit inside SILFunctionTypeBits.
static_assert(unsigned(ParameterConvention::Direct_Guaranteed) < (1<<3),
"fits in SILFunctionTypeBits");
"fits in SILFunctionTypeBits and SILParameterInfo");

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

/// A parameter type and the rules for passing it.
class SILParameterInfo {
CanType Ty;
ParameterConvention Convention;
llvm::PointerIntPair<CanType, 3, ParameterConvention> TypeAndConvention;
public:
SILParameterInfo() : Ty(), Convention((ParameterConvention)0) {}
SILParameterInfo() = default;//: Ty(), Convention((ParameterConvention)0) {}
SILParameterInfo(CanType type, ParameterConvention conv)
: Ty(type), Convention(conv) {
: TypeAndConvention(type, conv) {
assert(type->isLegalSILType() && "SILParameterInfo has illegal SIL type");
}

CanType getType() const {
return Ty;
return TypeAndConvention.getPointer();
}
ParameterConvention getConvention() const {
return Convention;
return TypeAndConvention.getInt();
}
// Does this parameter convention require indirect storage? This reflects a
// SILFunctionType's formal (immutable) conventions, as opposed to the
Expand Down Expand Up @@ -3089,8 +3096,8 @@ class SILParameterInfo {
}

void profile(llvm::FoldingSetNodeID &id) {
id.AddPointer(Ty.getPointer());
id.AddInteger((unsigned)Convention);
id.AddPointer(getType().getPointer());
id.AddInteger((unsigned)getConvention());
}

void dump() const;
Expand All @@ -3104,7 +3111,7 @@ class SILParameterInfo {
}

bool operator==(SILParameterInfo rhs) const {
return Ty == rhs.Ty && Convention == rhs.Convention;
return getType() == rhs.getType() && getConvention() == rhs.getConvention();
}
bool operator!=(SILParameterInfo rhs) const {
return !(*this == rhs);
Expand Down Expand Up @@ -3807,7 +3814,6 @@ class SILBoxType final : public TypeBase,
friend TrailingObjects;

SILLayout *Layout;
unsigned NumGenericArgs;

static RecursiveTypeProperties
getRecursivePropertiesFromSubstitutions(SubstitutionList Args);
Expand All @@ -3823,7 +3829,7 @@ class SILBoxType final : public TypeBase,
SILLayout *getLayout() const { return Layout; }
SubstitutionList getGenericArgs() const {
return llvm::makeArrayRef(getTrailingObjects<Substitution>(),
NumGenericArgs);
SILBoxTypeBits.NumGenericArgs);
}

// In SILType.h:
Expand Down
11 changes: 4 additions & 7 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4103,10 +4103,8 @@ void SILBoxType::Profile(llvm::FoldingSetNodeID &id, SILLayout *Layout,
SILBoxType::SILBoxType(ASTContext &C,
SILLayout *Layout, SubstitutionList Args)
: TypeBase(TypeKind::SILBox, &C,
getRecursivePropertiesFromSubstitutions(Args)),
Layout(Layout),
NumGenericArgs(Args.size())
{
getRecursivePropertiesFromSubstitutions(Args)), Layout(Layout) {
SILBoxTypeBits.NumGenericArgs = Args.size();
#ifndef NDEBUG
// Check that the generic args are reasonable for the box's signature.
if (Layout->getGenericSignature())
Expand All @@ -4115,9 +4113,8 @@ SILBoxType::SILBoxType(ASTContext &C,
assert(arg.getReplacement()->isCanonical() &&
"box arguments must be canonical types!");
#endif
auto paramsBuf = getTrailingObjects<Substitution>();
for (unsigned i = 0; i < NumGenericArgs; ++i)
::new (paramsBuf + i) Substitution(Args[i]);
std::uninitialized_copy(Args.begin(), Args.end(),
getTrailingObjects<Substitution>());
}

RecursiveTypeProperties SILBoxType::
Expand Down