Skip to content

Commit 6dfdb7b

Browse files
[NFC] Clean up construction of ExtInfo(Builder).
1 parent abce3de commit 6dfdb7b

File tree

6 files changed

+51
-75
lines changed

6 files changed

+51
-75
lines changed

include/swift/AST/ExtInfo.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ class ASTExtInfoBuilder {
275275
: bits(bits), clangTypeInfo(clangTypeInfo) {}
276276

277277
public:
278-
// Constructor with all defaults.
278+
/// An ExtInfoBuilder for a typical Swift function: @convention(swift),
279+
/// @escaping, non-throwing, non-differentiable.
279280
ASTExtInfoBuilder()
280281
: ASTExtInfoBuilder(Representation::Swift, false, false,
281282
DifferentiabilityKind::NonDifferentiable, nullptr) {}
@@ -447,6 +448,8 @@ class ASTExtInfo {
447448
};
448449

449450
public:
451+
/// An ExtInfo for a typical Swift function: @convention(swift), @escaping,
452+
/// non-throwing, non-differentiable.
450453
ASTExtInfo() : builder() { builder.checkInvariants(); };
451454

452455
/// Create a builder with the same state as \c this.
@@ -598,17 +601,22 @@ class SILExtInfoBuilder {
598601
}
599602

600603
public:
601-
// Constructor with all defaults.
602-
SILExtInfoBuilder() : SILExtInfoBuilder(0, ClangTypeInfo(nullptr)) {}
604+
/// An ExtInfoBuilder for a typical Swift function: thick, @escaping,
605+
/// non-pseudogeneric, non-differentiable.
606+
SILExtInfoBuilder()
607+
: SILExtInfoBuilder(makeBits(SILFunctionTypeRepresentation::Thick, false,
608+
false, false,
609+
DifferentiabilityKind::NonDifferentiable),
610+
ClangTypeInfo(nullptr)) {}
603611

604-
// Constructor for polymorphic type.
605612
SILExtInfoBuilder(Representation rep, bool isPseudogeneric, bool isNoEscape,
606613
bool isAsync, DifferentiabilityKind diffKind,
607614
const clang::Type *type)
608615
: SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape, isAsync,
609616
diffKind),
610617
ClangTypeInfo(type)) {}
611618

619+
// Constructor for polymorphic type.
612620
SILExtInfoBuilder(ASTExtInfoBuilder info, bool isPseudogeneric)
613621
: SILExtInfoBuilder(makeBits(info.getSILRepresentation(), isPseudogeneric,
614622
info.isNoEscape(), info.isAsync(),
@@ -686,25 +694,30 @@ class SILExtInfoBuilder {
686694

687695
// Note that we don't have setters. That is by design, use
688696
// the following with methods instead of mutating these objects.
697+
LLVM_NODISCARD
689698
SILExtInfoBuilder withRepresentation(Representation rep) const {
690699
return SILExtInfoBuilder((bits & ~RepresentationMask) | (unsigned)rep,
691700
shouldStoreClangType(rep) ? clangTypeInfo
692701
: ClangTypeInfo());
693702
}
703+
LLVM_NODISCARD
694704
SILExtInfoBuilder withIsPseudogeneric(bool isPseudogeneric = true) const {
695705
return SILExtInfoBuilder(isPseudogeneric ? (bits | PseudogenericMask)
696706
: (bits & ~PseudogenericMask),
697707
clangTypeInfo);
698708
}
709+
LLVM_NODISCARD
699710
SILExtInfoBuilder withNoEscape(bool noEscape = true) const {
700711
return SILExtInfoBuilder(noEscape ? (bits | NoEscapeMask)
701712
: (bits & ~NoEscapeMask),
702713
clangTypeInfo);
703714
}
715+
LLVM_NODISCARD
704716
SILExtInfoBuilder withAsync(bool isAsync = true) const {
705717
return SILExtInfoBuilder(isAsync ? (bits | AsyncMask) : (bits & ~AsyncMask),
706718
clangTypeInfo);
707719
}
720+
LLVM_NODISCARD
708721
SILExtInfoBuilder
709722
withDifferentiabilityKind(DifferentiabilityKind differentiability) const {
710723
return SILExtInfoBuilder(
@@ -750,13 +763,16 @@ class SILExtInfo {
750763
};
751764

752765
public:
766+
/// An ExtInfo for a typical Swift function: thick, @escaping,
767+
/// non-pseudogeneric, non-differentiable.
753768
SILExtInfo() : builder() { builder.checkInvariants(); };
754769

755770
SILExtInfo(ASTExtInfo info, bool isPseudogeneric)
756771
: builder(info.intoBuilder(), isPseudogeneric) {
757772
builder.checkInvariants();
758773
}
759774

775+
/// A default ExtInfo but with a Thin convention.
760776
static SILExtInfo getThin() {
761777
return SILExtInfoBuilder(SILExtInfoBuilder::Representation::Thin, false,
762778
false, false,

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,7 @@ SILGenModule::getKeyPathProjectionCoroutine(bool isReadAccess,
411411
: ParameterConvention::Indirect_In_Guaranteed },
412412
};
413413

414-
auto extInfo =
415-
SILFunctionType::ExtInfoBuilder(SILFunctionTypeRepresentation::Thin,
416-
/*pseudogeneric*/ false,
417-
/*non-escaping*/ false,
418-
/*async*/ false,
419-
DifferentiabilityKind::NonDifferentiable,
420-
/*clangFunctionType*/ nullptr)
421-
.build();
414+
auto extInfo = SILFunctionType::ExtInfo::getThin();
422415

423416
auto functionTy = SILFunctionType::get(sig, extInfo,
424417
SILCoroutineKind::YieldOnce,

lib/SILGen/SILGenFunction.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,10 @@ void SILGenFunction::emitArtificialTopLevel(Decl *mainDecl) {
696696
};
697697
auto NSApplicationMainType = SILFunctionType::get(
698698
nullptr,
699-
SILFunctionType::ExtInfoBuilder()
700-
// Should be C calling convention, but NSApplicationMain
701-
// has an overlay to fix the type of argv.
702-
.withRepresentation(SILFunctionType::Representation::Thin)
703-
.build(),
704-
SILCoroutineKind::None, ParameterConvention::Direct_Unowned, argTypes,
699+
// Should be C calling convention, but NSApplicationMain
700+
// has an overlay to fix the type of argv.
701+
SILFunctionType::ExtInfo::getThin(), SILCoroutineKind::None,
702+
ParameterConvention::Direct_Unowned, argTypes,
705703
/*yields*/ {},
706704
SILResultInfo(argc->getType().getASTType(), ResultConvention::Unowned),
707705
/*error result*/ None, SubstitutionMap(), SubstitutionMap(),

lib/SILOptimizer/Transforms/Outliner.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,7 @@ CanSILFunctionType BridgedProperty::getOutlinedFunctionType(SILModule &M) {
295295
Results.push_back(SILResultInfo(
296296
switchInfo.Br->getArg(0)->getType().getASTType(),
297297
ResultConvention::Owned));
298-
auto ExtInfo = SILFunctionType::ExtInfoBuilder(
299-
SILFunctionType::Representation::Thin,
300-
/*pseudogeneric*/ false, /*noescape*/ false,
301-
/*async*/ false, DifferentiabilityKind::NonDifferentiable,
302-
/*clangFunctionType*/ nullptr)
303-
.build();
298+
auto ExtInfo = SILFunctionType::ExtInfo::getThin();
304299
auto FunctionType = SILFunctionType::get(
305300
nullptr, ExtInfo, SILCoroutineKind::None,
306301
ParameterConvention::Direct_Unowned, Parameters, /*yields*/ {},
@@ -1177,14 +1172,7 @@ CanSILFunctionType ObjCMethodCall::getOutlinedFunctionType(SILModule &M) {
11771172
++OrigSigIdx;
11781173
}
11791174

1180-
auto ExtInfo =
1181-
SILFunctionType::ExtInfoBuilder(SILFunctionType::Representation::Thin,
1182-
/*pseudogeneric*/ false,
1183-
/*noescape*/ false,
1184-
/*async*/ false,
1185-
DifferentiabilityKind::NonDifferentiable,
1186-
/*clangFunctionType*/ nullptr)
1187-
.build();
1175+
auto ExtInfo = SILFunctionType::ExtInfo::getThin();
11881176

11891177
SmallVector<SILResultInfo, 4> Results;
11901178
// If we don't have a bridged return we changed from @autoreleased to @owned

lib/SILOptimizer/UtilityPasses/BugReducerTester.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,10 @@ class BugReducerTester : public SILFunctionTransform {
8383
ResultInfoArray.push_back(
8484
SILResultInfo(EmptyTupleCanType, ResultConvention::Unowned));
8585
auto FuncType = SILFunctionType::get(
86-
nullptr,
87-
SILFunctionType::ExtInfoBuilder(
88-
SILFunctionType::Representation::Thin, false /*isPseudoGeneric*/,
89-
false /*noescape*/, false /*async*/,
90-
DifferentiabilityKind::NonDifferentiable,
91-
nullptr /*clangFunctionType*/)
92-
.build(),
93-
SILCoroutineKind::None, ParameterConvention::Direct_Unowned,
94-
ArrayRef<SILParameterInfo>(), ArrayRef<SILYieldInfo>(), ResultInfoArray,
95-
None, SubstitutionMap(), SubstitutionMap(),
96-
getFunction()->getModule().getASTContext());
86+
nullptr, SILFunctionType::ExtInfo::getThin(), SILCoroutineKind::None,
87+
ParameterConvention::Direct_Unowned, ArrayRef<SILParameterInfo>(),
88+
ArrayRef<SILYieldInfo>(), ResultInfoArray, None, SubstitutionMap(),
89+
SubstitutionMap(), getFunction()->getModule().getASTContext());
9790

9891
SILOptFunctionBuilder FunctionBuilder(*this);
9992
SILFunction *F = FunctionBuilder.getOrCreateSharedFunction(

lib/Sema/ConstraintSystem.cpp

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,27 +1889,21 @@ static std::pair<Type, Type> getTypeOfReferenceWithSpecialTypeCheckingSemantics(
18891889
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
18901890
TVO_CanBindToNoEscape);
18911891
FunctionType::Param arg(escapeClosure);
1892-
auto bodyClosure = FunctionType::get(
1893-
arg, result,
1894-
FunctionType::ExtInfoBuilder(FunctionType::Representation::Swift,
1895-
/*noescape*/ true,
1896-
/*throws*/ true,
1897-
DifferentiabilityKind::NonDifferentiable,
1898-
/*clangFunctionType*/ nullptr)
1899-
.build());
1892+
auto bodyClosure = FunctionType::get(arg, result,
1893+
FunctionType::ExtInfoBuilder()
1894+
.withNoEscape(true)
1895+
.withThrows(true)
1896+
.build());
19001897
FunctionType::Param args[] = {
19011898
FunctionType::Param(noescapeClosure),
19021899
FunctionType::Param(bodyClosure, CS.getASTContext().getIdentifier("do")),
19031900
};
19041901

1905-
auto refType = FunctionType::get(
1906-
args, result,
1907-
FunctionType::ExtInfoBuilder(FunctionType::Representation::Swift,
1908-
/*noescape*/ false,
1909-
/*throws*/ true,
1910-
DifferentiabilityKind::NonDifferentiable,
1911-
/*clangFunctionType*/ nullptr)
1912-
.build());
1902+
auto refType = FunctionType::get(args, result,
1903+
FunctionType::ExtInfoBuilder()
1904+
.withNoEscape(false)
1905+
.withThrows(true)
1906+
.build());
19131907
return {refType, refType};
19141908
}
19151909
case DeclTypeCheckingSemantics::OpenExistential: {
@@ -1928,26 +1922,20 @@ static std::pair<Type, Type> getTypeOfReferenceWithSpecialTypeCheckingSemantics(
19281922
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
19291923
TVO_CanBindToNoEscape);
19301924
FunctionType::Param bodyArgs[] = {FunctionType::Param(openedTy)};
1931-
auto bodyClosure = FunctionType::get(
1932-
bodyArgs, result,
1933-
FunctionType::ExtInfoBuilder(FunctionType::Representation::Swift,
1934-
/*noescape*/ true,
1935-
/*throws*/ true,
1936-
DifferentiabilityKind::NonDifferentiable,
1937-
/*clangFunctionType*/ nullptr)
1938-
.build());
1925+
auto bodyClosure = FunctionType::get(bodyArgs, result,
1926+
FunctionType::ExtInfoBuilder()
1927+
.withNoEscape(true)
1928+
.withThrows(true)
1929+
.build());
19391930
FunctionType::Param args[] = {
19401931
FunctionType::Param(existentialTy),
19411932
FunctionType::Param(bodyClosure, CS.getASTContext().getIdentifier("do")),
19421933
};
1943-
auto refType = FunctionType::get(
1944-
args, result,
1945-
FunctionType::ExtInfoBuilder(FunctionType::Representation::Swift,
1946-
/*noescape*/ false,
1947-
/*throws*/ true,
1948-
DifferentiabilityKind::NonDifferentiable,
1949-
/*clangFunctionType*/ nullptr)
1950-
.build());
1934+
auto refType = FunctionType::get(args, result,
1935+
FunctionType::ExtInfoBuilder()
1936+
.withNoEscape(false)
1937+
.withThrows(true)
1938+
.build());
19511939
return {refType, refType};
19521940
}
19531941
}

0 commit comments

Comments
 (0)