Skip to content

Commit ff82551

Browse files
Merge pull request #33117 from varungandhi-apple/vg-rename-Uncommon-type
[NFC] Rename ExtInfo::Uncommon to ExtInfo::ClangTypeInfo.
2 parents 81d455d + aeda622 commit ff82551

File tree

4 files changed

+50
-52
lines changed

4 files changed

+50
-52
lines changed

include/swift/AST/Types.h

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
345345
/// Extra information which affects how the function is called, like
346346
/// regparm and the calling convention.
347347
ExtInfoBits : NumAFTExtInfoBits,
348-
HasUncommonInfo : 1,
348+
HasClangTypeInfo : 1,
349349
: NumPadBits,
350350
NumParams : 16
351351
);
@@ -368,7 +368,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
368368

369369
SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+2+1+1,
370370
ExtInfoBits : NumSILExtInfoBits,
371-
HasUncommonInfo : 1,
371+
HasClangTypeInfo : 1,
372372
CalleeConvention : 3,
373373
HasErrorResult : 1,
374374
CoroutineKind : 2,
@@ -2990,7 +2990,7 @@ class AnyFunctionType : public TypeBase {
29902990
unsigned Bits; // Naturally sized for speed.
29912991

29922992
public:
2993-
class Uncommon {
2993+
class ClangTypeInfo {
29942994
friend ExtInfo;
29952995
friend class AnyFunctionType;
29962996
friend class FunctionType;
@@ -2999,27 +2999,26 @@ class AnyFunctionType : public TypeBase {
29992999
// 2. The actual type being stored is [ignoring sugar] either a
30003000
// clang::PointerType, a clang::BlockPointerType, or a
30013001
// clang::ReferenceType which points to a clang::FunctionType.
3002-
const clang::Type *ClangFunctionType;
3002+
const clang::Type *type;
30033003

3004-
bool empty() const { return !ClangFunctionType; }
3005-
Uncommon(const clang::Type *type) : ClangFunctionType(type) {}
3004+
bool empty() const { return !type; }
3005+
ClangTypeInfo(const clang::Type *type) : type(type) {}
30063006

30073007
public:
30083008
/// Use the ClangModuleLoader to print the Clang type as a string.
3009-
void printClangFunctionType(ClangModuleLoader *cml,
3010-
llvm::raw_ostream &os);
3009+
void printType(ClangModuleLoader *cml, llvm::raw_ostream &os) const;
30113010
};
30123011

30133012
private:
3014-
Uncommon Other;
3013+
ClangTypeInfo Other;
30153014

30163015
static void assertIsFunctionType(const clang::Type *);
30173016

3018-
ExtInfo(unsigned Bits, Uncommon Other) : Bits(Bits), Other(Other) {
3017+
ExtInfo(unsigned Bits, ClangTypeInfo Other) : Bits(Bits), Other(Other) {
30193018
// [TODO: Clang-type-plumbing] Assert that the pointer is non-null.
30203019
auto Rep = Representation(Bits & RepresentationMask);
3021-
if ((Rep == Representation::CFunctionPointer) && Other.ClangFunctionType)
3022-
assertIsFunctionType(Other.ClangFunctionType);
3020+
if ((Rep == Representation::CFunctionPointer) && Other.type)
3021+
assertIsFunctionType(Other.type);
30233022
}
30243023

30253024
friend AnyFunctionType;
@@ -3048,7 +3047,7 @@ class AnyFunctionType : public TypeBase {
30483047
| (Throws ? ThrowsMask : 0)
30493048
| (((unsigned)DiffKind << DifferentiabilityMaskOffset)
30503049
& DifferentiabilityMask),
3051-
Uncommon(type)) {
3050+
ClangTypeInfo(type)) {
30523051
}
30533052

30543053
bool isNoEscape() const { return Bits & NoEscapeMask; }
@@ -3068,9 +3067,9 @@ class AnyFunctionType : public TypeBase {
30683067
return Representation(rawRep);
30693068
}
30703069

3071-
/// Return the underlying Uncommon value if it is not the default value.
3072-
Optional<Uncommon> getUncommonInfo() const {
3073-
return Other.empty() ? Optional<Uncommon>() : Other;
3070+
/// Get the underlying ClangTypeInfo value if it is not the default value.
3071+
Optional<ClangTypeInfo> getClangTypeInfo() const {
3072+
return Other.empty() ? Optional<ClangTypeInfo>() : Other;
30743073
}
30753074

30763075
bool hasSelfParam() const {
@@ -3127,7 +3126,7 @@ class AnyFunctionType : public TypeBase {
31273126
}
31283127
LLVM_NODISCARD
31293128
ExtInfo withClangFunctionType(const clang::Type *type) const {
3130-
return ExtInfo(Bits, Uncommon(type));
3129+
return ExtInfo(Bits, ClangTypeInfo(type));
31313130
}
31323131
LLVM_NODISCARD
31333132
ExtInfo
@@ -3139,7 +3138,7 @@ class AnyFunctionType : public TypeBase {
31393138
}
31403139

31413140
std::pair<unsigned, const void *> getFuncAttrKey() const {
3142-
return std::make_pair(Bits, Other.ClangFunctionType);
3141+
return std::make_pair(Bits, Other.type);
31433142
}
31443143

31453144
/// Put a SIL representation in the ExtInfo.
@@ -3169,13 +3168,13 @@ class AnyFunctionType : public TypeBase {
31693168
/// Create an AnyFunctionType.
31703169
///
31713170
/// Subclasses are responsible for storing and retrieving the
3172-
/// ExtInfo::Uncommon value if one is present.
3171+
/// ExtInfo::ClangTypeInfo value if one is present.
31733172
AnyFunctionType(TypeKind Kind, const ASTContext *CanTypeContext,
31743173
Type Output, RecursiveTypeProperties properties,
31753174
unsigned NumParams, ExtInfo Info)
31763175
: TypeBase(Kind, CanTypeContext, properties), Output(Output) {
31773176
Bits.AnyFunctionType.ExtInfoBits = Info.Bits;
3178-
Bits.AnyFunctionType.HasUncommonInfo = Info.getUncommonInfo().hasValue();
3177+
Bits.AnyFunctionType.HasClangTypeInfo = Info.getClangTypeInfo().hasValue();
31793178
Bits.AnyFunctionType.NumParams = NumParams;
31803179
assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!");
31813180
// The use of both assert() and static_assert() is intentional.
@@ -3219,7 +3218,7 @@ class AnyFunctionType : public TypeBase {
32193218
GenericSignature getOptGenericSignature() const;
32203219

32213220
bool hasClangFunctionType() const {
3222-
return Bits.AnyFunctionType.HasUncommonInfo;
3221+
return Bits.AnyFunctionType.HasClangTypeInfo;
32233222
}
32243223

32253224
const clang::Type *getClangFunctionType() const;
@@ -3438,15 +3437,15 @@ inline AnyFunctionType::CanYield AnyFunctionType::Yield::getCanonical() const {
34383437
class FunctionType final : public AnyFunctionType,
34393438
public llvm::FoldingSetNode,
34403439
private llvm::TrailingObjects<FunctionType, AnyFunctionType::Param,
3441-
AnyFunctionType::ExtInfo::Uncommon> {
3440+
AnyFunctionType::ExtInfo::ClangTypeInfo> {
34423441
friend TrailingObjects;
34433442

34443443

34453444
size_t numTrailingObjects(OverloadToken<AnyFunctionType::Param>) const {
34463445
return getNumParams();
34473446
}
34483447

3449-
size_t numTrailingObjects(OverloadToken<ExtInfo::Uncommon>) const {
3448+
size_t numTrailingObjects(OverloadToken<ExtInfo::ClangTypeInfo>) const {
34503449
return hasClangFunctionType() ? 1 : 0;
34513450
}
34523451

@@ -3463,7 +3462,7 @@ class FunctionType final : public AnyFunctionType,
34633462
const clang::Type *getClangFunctionType() const {
34643463
if (!hasClangFunctionType())
34653464
return nullptr;
3466-
auto *type = getTrailingObjects<ExtInfo::Uncommon>()->ClangFunctionType;
3465+
auto *type = getTrailingObjects<ExtInfo::ClangTypeInfo>()->type;
34673466
assert(type && "If the pointer was null, we shouldn't have stored it.");
34683467
return type;
34693468
}
@@ -4221,7 +4220,7 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
42214220

42224221
unsigned Bits; // Naturally sized for speed.
42234222

4224-
class Uncommon {
4223+
class ClangTypeInfo {
42254224
friend ExtInfo;
42264225
friend class SILFunctionType;
42274226

@@ -4231,22 +4230,21 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
42314230
const clang::FunctionType *ClangFunctionType;
42324231

42334232
bool empty() const { return !ClangFunctionType; }
4234-
Uncommon(const clang::FunctionType *type) : ClangFunctionType(type) {}
4233+
ClangTypeInfo(const clang::FunctionType *type) : ClangFunctionType(type) {}
42354234

42364235
public:
4237-
/// Analog of AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType.
4238-
void printClangFunctionType(ClangModuleLoader *cml,
4239-
llvm::raw_ostream &os) const;
4236+
/// Analog of AnyFunctionType::ExtInfo::ClangTypeInfo::printType.
4237+
void printType(ClangModuleLoader *cml, llvm::raw_ostream &os) const;
42404238
};
42414239

4242-
Uncommon Other;
4240+
ClangTypeInfo Other;
42434241

4244-
ExtInfo(unsigned Bits, Uncommon Other) : Bits(Bits), Other(Other) {}
4242+
ExtInfo(unsigned Bits, ClangTypeInfo Other) : Bits(Bits), Other(Other) {}
42454243

42464244
friend class SILFunctionType;
42474245
public:
42484246
// Constructor with all defaults.
4249-
ExtInfo() : Bits(0), Other(Uncommon(nullptr)) { }
4247+
ExtInfo() : Bits(0), Other(ClangTypeInfo(nullptr)) { }
42504248

42514249
// Constructor for polymorphic type.
42524250
ExtInfo(Representation rep, bool isPseudogeneric, bool isNoEscape,
@@ -4257,7 +4255,7 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
42574255
| (isNoEscape ? NoEscapeMask : 0)
42584256
| (((unsigned)diffKind << DifferentiabilityMaskOffset)
42594257
& DifferentiabilityMask),
4260-
Uncommon(type)) {
4258+
ClangTypeInfo(type)) {
42614259
}
42624260

42634261
static ExtInfo getThin() {
@@ -4290,9 +4288,9 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
42904288
return getSILFunctionLanguage(getRepresentation());
42914289
}
42924290

4293-
/// Return the underlying Uncommon value if it is not the default value.
4294-
Optional<Uncommon> getUncommonInfo() const {
4295-
return Other.empty() ? Optional<Uncommon>() : Other;
4291+
/// Get the underlying ClangTypeInfo value if it is not the default value.
4292+
Optional<ClangTypeInfo> getClangTypeInfo() const {
4293+
return Other.empty() ? Optional<ClangTypeInfo>() : Other;
42964294
}
42974295

42984296
bool hasSelfParam() const {

lib/AST/ASTContext.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,17 +3082,17 @@ FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
30823082
return funcTy;
30833083
}
30843084

3085-
Optional<ExtInfo::Uncommon> uncommon = info.getUncommonInfo();
3085+
Optional<ExtInfo::ClangTypeInfo> clangTypeInfo = info.getClangTypeInfo();
30863086

30873087
size_t allocSize =
3088-
totalSizeToAlloc<AnyFunctionType::Param, ExtInfo::Uncommon>(
3089-
params.size(), uncommon.hasValue() ? 1 : 0);
3088+
totalSizeToAlloc<AnyFunctionType::Param, ExtInfo::ClangTypeInfo>(
3089+
params.size(), clangTypeInfo.hasValue() ? 1 : 0);
30903090
void *mem = ctx.Allocate(allocSize, alignof(FunctionType), arena);
30913091

30923092
bool isCanonical = isFunctionTypeCanonical(params, result);
3093-
if (uncommon.hasValue()) {
3093+
if (clangTypeInfo.hasValue()) {
30943094
if (ctx.LangOpts.UseClangFunctionTypes)
3095-
isCanonical &= uncommon->ClangFunctionType->isCanonicalUnqualified();
3095+
isCanonical &= clangTypeInfo->type->isCanonicalUnqualified();
30963096
else
30973097
isCanonical = false;
30983098
}
@@ -3113,9 +3113,9 @@ FunctionType::FunctionType(ArrayRef<AnyFunctionType::Param> params,
31133113
output, properties, params.size(), info) {
31143114
std::uninitialized_copy(params.begin(), params.end(),
31153115
getTrailingObjects<AnyFunctionType::Param>());
3116-
Optional<ExtInfo::Uncommon> uncommon = info.getUncommonInfo();
3117-
if (uncommon.hasValue())
3118-
*getTrailingObjects<ExtInfo::Uncommon>() = uncommon.getValue();
3116+
auto clangTypeInfo = info.getClangTypeInfo();
3117+
if (clangTypeInfo.hasValue())
3118+
*getTrailingObjects<ExtInfo::ClangTypeInfo>() = clangTypeInfo.getValue();
31193119
}
31203120

31213121
void GenericFunctionType::Profile(llvm::FoldingSetNodeID &ID,
@@ -3208,7 +3208,7 @@ ArrayRef<Requirement> GenericFunctionType::getRequirements() const {
32083208
return Signature->getRequirements();
32093209
}
32103210

3211-
void SILFunctionType::ExtInfo::Uncommon::printClangFunctionType(
3211+
void SILFunctionType::ExtInfo::ClangTypeInfo::printType(
32123212
ClangModuleLoader *cml, llvm::raw_ostream &os) const {
32133213
cml->printClangType(ClangFunctionType, os);
32143214
}
@@ -3272,7 +3272,7 @@ SILFunctionType::SILFunctionType(
32723272

32733273
Bits.SILFunctionType.HasErrorResult = errorResult.hasValue();
32743274
Bits.SILFunctionType.ExtInfoBits = ext.Bits;
3275-
Bits.SILFunctionType.HasUncommonInfo = false;
3275+
Bits.SILFunctionType.HasClangTypeInfo = false;
32763276
Bits.SILFunctionType.HasPatternSubs = (bool) patternSubs;
32773277
Bits.SILFunctionType.HasInvocationSubs = (bool) invocationSubs;
32783278
// The use of both assert() and static_assert() below is intentional.

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,7 +3598,7 @@ void printCType(ASTContext &Ctx, ASTPrinter &Printer, ExtInfo &info) {
35983598
auto *cml = Ctx.getClangModuleLoader();
35993599
SmallString<64> buf;
36003600
llvm::raw_svector_ostream os(buf);
3601-
info.getUncommonInfo().getValue().printClangFunctionType(cml, os);
3601+
info.getClangTypeInfo().getValue().printType(cml, os);
36023602
Printer << ", cType: " << QuotedString(os.str());
36033603
}
36043604

@@ -4020,7 +4020,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
40204020
case SILFunctionType::Representation::CFunctionPointer:
40214021
Printer << "c";
40224022
// [TODO: Clang-type-plumbing] Remove the second check.
4023-
if (printNameOnly || !info.getUncommonInfo().hasValue())
4023+
if (printNameOnly || !info.getClangTypeInfo().hasValue())
40244024
break;
40254025
printCType(Ctx, Printer, info);
40264026
break;
@@ -4086,7 +4086,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
40864086
case SILFunctionType::Representation::CFunctionPointer:
40874087
Printer << "c";
40884088
// [TODO: Clang-type-plumbing] Remove the second check.
4089-
if (printNameOnly || !info.getUncommonInfo().hasValue())
4089+
if (printNameOnly || !info.getClangTypeInfo().hasValue())
40904090
break;
40914091
printCType(Ctx, Printer, info);
40924092
break;

lib/AST/Type.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,9 +3369,9 @@ Type ProtocolCompositionType::get(const ASTContext &C,
33693369
return build(C, CanTypes, HasExplicitAnyObject);
33703370
}
33713371

3372-
void AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType(
3373-
ClangModuleLoader *cml, llvm::raw_ostream &os) {
3374-
cml->printClangType(ClangFunctionType, os);
3372+
void AnyFunctionType::ExtInfo::ClangTypeInfo::printType(
3373+
ClangModuleLoader *cml, llvm::raw_ostream &os) const {
3374+
cml->printClangType(type, os);
33753375
}
33763376

33773377
void

0 commit comments

Comments
 (0)