Skip to content

Commit 8da4d53

Browse files
[NFC] Use ClangTypeInfo's implicit null state instead of an extra Optional.
1 parent eaac23f commit 8da4d53

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

include/swift/AST/ExtInfo.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ class ASTExtInfoBuilder {
246246
DifferentiabilityKind::NonDifferentiable;
247247
}
248248

249-
/// Get the underlying ClangTypeInfo value if it is not the default value.
250-
Optional<ClangTypeInfo> getClangTypeInfo() const {
251-
return clangTypeInfo.empty() ? Optional<ClangTypeInfo>() : clangTypeInfo;
252-
}
249+
ClangTypeInfo getClangTypeInfo() const { return clangTypeInfo; }
253250

254251
constexpr SILFunctionTypeRepresentation getSILRepresentation() const {
255252
unsigned rawRep = bits & RepresentationMask;
@@ -396,9 +393,7 @@ class ASTExtInfo {
396393

397394
constexpr bool isDifferentiable() const { return builder.isDifferentiable(); }
398395

399-
Optional<ClangTypeInfo> getClangTypeInfo() const {
400-
return builder.getClangTypeInfo();
401-
}
396+
ClangTypeInfo getClangTypeInfo() const { return builder.getClangTypeInfo(); }
402397

403398
constexpr bool hasSelfParam() const { return builder.hasSelfParam(); }
404399

@@ -558,10 +553,8 @@ class SILExtInfoBuilder {
558553
DifferentiabilityKind::NonDifferentiable;
559554
}
560555

561-
/// Get the underlying ClangTypeInfo value if it is not the default value.
562-
Optional<ClangTypeInfo> getClangTypeInfo() const {
563-
return clangTypeInfo.empty() ? Optional<ClangTypeInfo>() : clangTypeInfo;
564-
}
556+
/// Get the underlying ClangTypeInfo value.
557+
ClangTypeInfo getClangTypeInfo() const { return clangTypeInfo; }
565558

566559
constexpr bool hasSelfParam() const {
567560
switch (getRepresentation()) {
@@ -689,9 +682,7 @@ class SILExtInfo {
689682

690683
constexpr bool isDifferentiable() const { return builder.isDifferentiable(); }
691684

692-
Optional<ClangTypeInfo> getClangTypeInfo() const {
693-
return builder.getClangTypeInfo();
694-
}
685+
ClangTypeInfo getClangTypeInfo() const { return builder.getClangTypeInfo(); }
695686

696687
constexpr bool hasSelfParam() const { return builder.hasSelfParam(); }
697688

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ class AnyFunctionType : public TypeBase {
28722872
unsigned NumParams, ExtInfo Info)
28732873
: TypeBase(Kind, CanTypeContext, properties), Output(Output) {
28742874
Bits.AnyFunctionType.ExtInfoBits = Info.getBits();
2875-
Bits.AnyFunctionType.HasClangTypeInfo = Info.getClangTypeInfo().hasValue();
2875+
Bits.AnyFunctionType.HasClangTypeInfo = !Info.getClangTypeInfo().empty();
28762876
Bits.AnyFunctionType.NumParams = NumParams;
28772877
assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!");
28782878
// The use of both assert() and static_assert() is intentional.

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,16 +3131,16 @@ FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
31313131
return funcTy;
31323132
}
31333133

3134-
Optional<ClangTypeInfo> clangTypeInfo = info.getClangTypeInfo();
3134+
auto clangTypeInfo = info.getClangTypeInfo();
31353135

31363136
size_t allocSize = totalSizeToAlloc<AnyFunctionType::Param, ClangTypeInfo>(
3137-
params.size(), clangTypeInfo.hasValue() ? 1 : 0);
3137+
params.size(), clangTypeInfo.empty() ? 0 : 1);
31383138
void *mem = ctx.Allocate(allocSize, alignof(FunctionType), arena);
31393139

31403140
bool isCanonical = isFunctionTypeCanonical(params, result);
3141-
if (clangTypeInfo.hasValue()) {
3141+
if (!clangTypeInfo.empty()) {
31423142
if (ctx.LangOpts.UseClangFunctionTypes)
3143-
isCanonical &= clangTypeInfo->type->isCanonicalUnqualified();
3143+
isCanonical &= clangTypeInfo.getType()->isCanonicalUnqualified();
31443144
else
31453145
isCanonical = false;
31463146
}
@@ -3162,8 +3162,8 @@ FunctionType::FunctionType(ArrayRef<AnyFunctionType::Param> params,
31623162
std::uninitialized_copy(params.begin(), params.end(),
31633163
getTrailingObjects<AnyFunctionType::Param>());
31643164
auto clangTypeInfo = info.getClangTypeInfo();
3165-
if (clangTypeInfo.hasValue())
3166-
*getTrailingObjects<ClangTypeInfo>() = clangTypeInfo.getValue();
3165+
if (!clangTypeInfo.empty())
3166+
*getTrailingObjects<ClangTypeInfo>() = clangTypeInfo;
31673167
}
31683168

31693169
void GenericFunctionType::Profile(llvm::FoldingSetNodeID &ID,

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,7 +3629,7 @@ void printCType(ASTContext &Ctx, ASTPrinter &Printer, ExtInfo &info) {
36293629
auto *cml = Ctx.getClangModuleLoader();
36303630
SmallString<64> buf;
36313631
llvm::raw_svector_ostream os(buf);
3632-
info.getClangTypeInfo().getValue().printType(cml, os);
3632+
info.getClangTypeInfo().printType(cml, os);
36333633
Printer << ", cType: " << QuotedString(os.str());
36343634
}
36353635

@@ -4054,7 +4054,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
40544054
case SILFunctionType::Representation::CFunctionPointer:
40554055
Printer << "c";
40564056
// [TODO: Clang-type-plumbing] Remove the second check.
4057-
if (printNameOnly || !info.getClangTypeInfo().hasValue())
4057+
if (printNameOnly || info.getClangTypeInfo().empty())
40584058
break;
40594059
printCType(Ctx, Printer, info);
40604060
break;
@@ -4120,7 +4120,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41204120
case SILFunctionType::Representation::CFunctionPointer:
41214121
Printer << "c";
41224122
// [TODO: Clang-type-plumbing] Remove the second check.
4123-
if (printNameOnly || !info.getClangTypeInfo().hasValue())
4123+
if (printNameOnly || info.getClangTypeInfo().empty())
41244124
break;
41254125
printCType(Ctx, Printer, info);
41264126
break;

0 commit comments

Comments
 (0)