Skip to content

Commit a51f1e9

Browse files
authored
Merge pull request #29354 from varungandhi-apple/vg-revert-clang-types-in-sil
Revert Clang types in SIL patch
2 parents 13f7ac2 + f6643af commit a51f1e9

28 files changed

+143
-368
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,6 @@ class ASTContext final {
582582
Type getBridgedToObjC(const DeclContext *dc, Type type,
583583
Type *bridgedValueType = nullptr) const;
584584

585-
private:
586-
void initializeClangTypeConverter();
587-
588-
public:
589585
/// Get the Clang type corresponding to a Swift function type.
590586
///
591587
/// \param params The function parameters.
@@ -599,15 +595,6 @@ class ASTContext final {
599595
const FunctionType::ExtInfo incompleteExtInfo,
600596
FunctionTypeRepresentation trueRep);
601597

602-
/// Get the canonical Clang type corresponding to a SIL function type.
603-
///
604-
/// SIL analog of \c ASTContext::getClangFunctionType .
605-
const clang::Type *
606-
getCanonicalClangFunctionType(
607-
ArrayRef<SILParameterInfo> params, Optional<SILResultInfo> result,
608-
const SILFunctionType::ExtInfo incompleteExtInfo,
609-
SILFunctionType::Representation trueRep);
610-
611598
/// Determine whether the given Swift type is representable in a
612599
/// given foreign language.
613600
ForeignRepresentationInfo

include/swift/AST/PrintOptions.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ struct PrintOptions {
564564
static PrintOptions printDocInterface();
565565

566566
/// Retrieve the set of options suitable for printing SIL functions.
567-
static PrintOptions printSIL(bool printFullConvention = false) {
567+
static PrintOptions printSIL() {
568568
PrintOptions result;
569569
result.PrintLongAttrsOnSeparateLines = true;
570570
result.PrintStorageRepresentationAttrs = true;
@@ -575,9 +575,6 @@ struct PrintOptions {
575575
result.PrintIfConfig = false;
576576
result.OpaqueReturnTypePrinting =
577577
OpaqueReturnTypePrintingMode::StableReference;
578-
if (printFullConvention)
579-
result.PrintFunctionRepresentationAttrs =
580-
PrintOptions::FunctionRepresentationMode::Full;
581578
return result;
582579
}
583580

include/swift/AST/SILOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ class SILOptions {
7878
/// variables by name when we print it out. This eases diffing of SIL files.
7979
bool EmitSortedSIL = false;
8080

81-
/// See \ref FrontendOptions.PrintFullConvention
82-
bool PrintFullConvention = false;
83-
8481
/// Whether to stop the optimization pipeline after serializing SIL.
8582
bool StopOptimizationAfterSerialization = false;
8683

include/swift/AST/Types.h

Lines changed: 27 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
namespace clang {
4646
class Type;
47+
class FunctionType;
4748
} // namespace clang
4849

4950
namespace llvm {
@@ -2946,7 +2947,6 @@ class AnyFunctionType : public TypeBase {
29462947
friend ExtInfo;
29472948
friend class AnyFunctionType;
29482949
friend class FunctionType;
2949-
friend class SILUncommonInfo;
29502950
// We preserve a full clang::Type *, not a clang::FunctionType * as:
29512951
// 1. We need to keep sugar in case we need to present an error to the user.
29522952
// 2. The actual type being stored is [ignoring sugar] either a
@@ -2969,7 +2969,7 @@ class AnyFunctionType : public TypeBase {
29692969
static void assertIsFunctionType(const clang::Type *);
29702970

29712971
ExtInfo(unsigned Bits, Uncommon Other) : Bits(Bits), Other(Other) {
2972-
// TODO: [clang-function-type-serialization] Once we start serializing
2972+
// TODO: [store-sil-clang-function-type] Once we start serializing
29732973
// the Clang type, we should also assert that the pointer is non-null.
29742974
auto Rep = Representation(Bits & RepresentationMask);
29752975
if ((Rep == Representation::CFunctionPointer) && Other.ClangFunctionType)
@@ -3917,24 +3917,6 @@ namespace Lowering {
39173917
class TypeConverter;
39183918
};
39193919

3920-
class SILUncommonInfo {
3921-
friend class SILFunctionType;
3922-
3923-
// Invariant: The FunctionType is canonical.
3924-
// We store a clang::FunctionType * instead of a clang::CanQualType to
3925-
// avoid depending on the Clang AST in this header.
3926-
const clang::Type *ClangFunctionType;
3927-
3928-
bool empty() const { return !ClangFunctionType; }
3929-
SILUncommonInfo(const clang::Type *type) : ClangFunctionType(type) {}
3930-
SILUncommonInfo(AnyFunctionType::ExtInfo::Uncommon uncommon);
3931-
3932-
public:
3933-
/// Analog of AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType.
3934-
void printClangFunctionType(ClangModuleLoader *cml,
3935-
llvm::raw_ostream &os) const;
3936-
};
3937-
39383920
/// SILFunctionType - The lowered type of a function value, suitable
39393921
/// for use by SIL.
39403922
///
@@ -3943,8 +3925,7 @@ class SILUncommonInfo {
39433925
/// function parameter and result types.
39443926
class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
39453927
private llvm::TrailingObjects<SILFunctionType, SILParameterInfo,
3946-
SILResultInfo, SILYieldInfo, CanType,
3947-
SILUncommonInfo> {
3928+
SILResultInfo, SILYieldInfo, CanType> {
39483929
friend TrailingObjects;
39493930

39503931
size_t numTrailingObjects(OverloadToken<SILParameterInfo>) const {
@@ -3963,10 +3944,6 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
39633944
return hasResultCache() ? 2 : 0;
39643945
}
39653946

3966-
size_t numTrailingObjects(OverloadToken<SILUncommonInfo>) const {
3967-
return Bits.SILFunctionType.HasUncommonInfo ? 1 : 0;
3968-
}
3969-
39703947
public:
39713948
using Language = SILFunctionLanguage;
39723949
using Representation = SILFunctionTypeRepresentation;
@@ -3991,31 +3968,27 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
39913968

39923969
unsigned Bits; // Naturally sized for speed.
39933970

3994-
// For symmetry with AnyFunctionType::Uncommon
3995-
using Uncommon = SILUncommonInfo;
3971+
class Uncommon {
3972+
friend ExtInfo;
3973+
friend class SILFunctionType;
39963974

3997-
Uncommon Other;
3975+
// Invariant: The FunctionType is canonical.
3976+
// We store a clang::FunctionType * instead of a clang::CanQualType to
3977+
// avoid depending on the Clang AST in this header.
3978+
const clang::FunctionType *ClangFunctionType;
39983979

3999-
static void assertIsFunctionType(const clang::Type *);
3980+
bool empty() const { return !ClangFunctionType; }
3981+
Uncommon(const clang::FunctionType *type) : ClangFunctionType(type) {}
40003982

4001-
ExtInfo(unsigned Bits, Uncommon Other) : Bits(Bits), Other(Other) {
4002-
auto Rep = Representation(Bits & RepresentationMask);
4003-
// TODO: [clang-function-type-serialization] Once we start serializing
4004-
// the Clang type, we should also assert that the pointer is non-null.
4005-
if ((Rep == Representation::CFunctionPointer) && Other.ClangFunctionType)
4006-
assertIsFunctionType(Other.ClangFunctionType);
4007-
}
3983+
public:
3984+
/// Analog of AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType.
3985+
void printClangFunctionType(ClangModuleLoader *cml,
3986+
llvm::raw_ostream &os) const;
3987+
};
40083988

4009-
static constexpr unsigned makeBits(Representation rep,
4010-
bool isPseudogeneric,
4011-
bool isNoEscape,
4012-
DifferentiabilityKind diffKind) {
4013-
return ((unsigned) rep)
4014-
| (isPseudogeneric ? PseudogenericMask : 0)
4015-
| (isNoEscape ? NoEscapeMask : 0)
4016-
| (((unsigned)diffKind << DifferentiabilityMaskOffset)
4017-
& DifferentiabilityMask);
4018-
}
3989+
Uncommon Other;
3990+
3991+
ExtInfo(unsigned Bits, Uncommon Other) : Bits(Bits), Other(Other) {}
40193992

40203993
friend class SILFunctionType;
40213994
public:
@@ -4025,21 +3998,15 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
40253998
// Constructor for polymorphic type.
40263999
ExtInfo(Representation rep, bool isPseudogeneric, bool isNoEscape,
40274000
DifferentiabilityKind diffKind,
4028-
const clang::Type *type)
4029-
: ExtInfo(makeBits(rep, isPseudogeneric, isNoEscape, diffKind),
4001+
const clang::FunctionType *type)
4002+
: ExtInfo(((unsigned) rep)
4003+
| (isPseudogeneric ? PseudogenericMask : 0)
4004+
| (isNoEscape ? NoEscapeMask : 0)
4005+
| (((unsigned)diffKind << DifferentiabilityMaskOffset)
4006+
& DifferentiabilityMask),
40304007
Uncommon(type)) {
40314008
}
40324009

4033-
ExtInfo(AnyFunctionType::ExtInfo info, bool isPseudogeneric)
4034-
: ExtInfo(makeBits(info.getSILRepresentation(),
4035-
isPseudogeneric,
4036-
info.isNoEscape(),
4037-
info.getDifferentiabilityKind()),
4038-
info.getUncommonInfo().hasValue()
4039-
? Uncommon(info.getUncommonInfo().getValue())
4040-
: Uncommon(nullptr)) {
4041-
}
4042-
40434010
static ExtInfo getThin() {
40444011
return ExtInfo(Representation::Thin, false, false,
40454012
DifferentiabilityKind::NonDifferentiable, nullptr);
@@ -4126,9 +4093,6 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
41264093
return ExtInfo(NoEscape ? (Bits | NoEscapeMask) : (Bits & ~NoEscapeMask),
41274094
Other);
41284095
}
4129-
ExtInfo withClangFunctionType(const clang::Type *type) const {
4130-
return ExtInfo(Bits, Uncommon(type));
4131-
}
41324096

41334097
std::pair<unsigned, const void *> getFuncAttrKey() const {
41344098
return std::make_pair(Bits, Other.ClangFunctionType);
@@ -4424,7 +4388,7 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
44244388
return WitnessMethodConformance;
44254389
}
44264390

4427-
const clang::Type *getClangFunctionType() const;
4391+
const clang::FunctionType *getClangFunctionType() const;
44284392

44294393
ExtInfo getExtInfo() const {
44304394
return ExtInfo(Bits.SILFunctionType.ExtInfoBits, getClangFunctionType());

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ class FrontendOptions {
253253
/// See the \ref SILOptions.EmitSortedSIL flag.
254254
bool EmitSortedSIL = false;
255255

256-
/// Should we emit the cType when printing @convention(c) or no?
257-
bool PrintFullConvention = false;
258-
259256
/// Indicates whether the dependency tracker should track system
260257
/// dependencies as well.
261258
bool TrackSystemDeps = false;

include/swift/Frontend/ModuleInterfaceSupport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct ModuleInterfaceOptions {
3131
/// interface, or should we fully-qualify them?
3232
bool PreserveTypesAsWritten = false;
3333

34-
/// See \ref FrontendOptions.PrintFullConvention.
35-
/// FIXME: [clang-function-type-serialization] This flag should go away.
34+
/// Should we emit the cType when printing @convention(c) or no?
35+
/// FIXME: [clang-function-type-serialization] This check should go away.
3636
bool PrintFullConvention = false;
3737

3838
/// Copy of all the command-line flags passed at .swiftinterface

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,10 @@ def module_interface_preserve_types_as_written :
608608
HelpText<"When emitting a module interface, preserve types as they were "
609609
"written in the source">;
610610

611-
// FIXME: [clang-function-type-serialization] Make this a SIL-only option once we
612-
// start unconditionally emitting non-canonical Clang types in swiftinterfaces.
613611
def experimental_print_full_convention :
614612
Flag<["-"], "experimental-print-full-convention">,
615-
HelpText<"When emitting a module interface or SIL, emit additional @convention"
616-
" arguments, regardless of whether they were written in the source">;
613+
HelpText<"When emitting a module interface, emit additional @convention "
614+
"arguments, regardless of whether they were written in the source">;
617615

618616
def prebuilt_module_cache_path :
619617
Separate<["-"], "prebuilt-module-cache-path">,

include/swift/SIL/SILModule.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ class SILModule {
166166
/// Functions, which are dead (and not in the functions list anymore),
167167
/// but kept alive for debug info generation.
168168
FunctionListType zombieFunctions;
169-
169+
170170
/// Stores the names of zombie functions.
171171
llvm::BumpPtrAllocator zombieFunctionNames;
172-
172+
173173
/// Lookup table for SIL vtables from class decls.
174174
llvm::DenseMap<const ClassDecl *, SILVTable *> VTableMap;
175175

@@ -211,7 +211,7 @@ class SILModule {
211211

212212
// The map of SILCoverageMaps in the module.
213213
CoverageMapCollectionType coverageMaps;
214-
214+
215215
// The list of SILProperties in the module.
216216
PropertyListType properties;
217217

@@ -502,7 +502,7 @@ class SILModule {
502502

503503
PropertyListType &getPropertyList() { return properties; }
504504
const PropertyListType &getPropertyList() const { return properties; }
505-
505+
506506
/// Look for a global variable by name.
507507
///
508508
/// \return null if this module has no such global variable
@@ -630,7 +630,7 @@ class SILModule {
630630

631631
/// Pretty-print the module.
632632
void dump(bool Verbose = false) const;
633-
633+
634634
/// Pretty-print the module to a file.
635635
/// Useful for dumping the module when running in a debugger.
636636
/// Warning: no error handling is done. Fails with an assert if the file
@@ -643,8 +643,10 @@ class SILModule {
643643
/// \param M If present, the types and declarations from this module will be
644644
/// printed. The module would usually contain the types and Decls that
645645
/// the SIL module depends on.
646+
/// \param Opts The SIL options, used to determine printing verbosity and
647+
/// and sorting.
646648
/// \param PrintASTDecls If set to true print AST decls.
647-
void print(raw_ostream &OS,
649+
void print(raw_ostream& OS,
648650
ModuleDecl *M = nullptr,
649651
const SILOptions &Opts = SILOptions(),
650652
bool PrintASTDecls = true) const {

include/swift/SIL/SILPrintContext.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ class SILPrintContext {
6666
/// Print debug locations and scopes.
6767
bool DebugInfo;
6868

69-
/// See \ref FrontendOptions.PrintFullConvention.
70-
bool PrintFullConvention;
71-
7269
public:
7370
/// Constructor with default values for options.
7471
///
@@ -103,9 +100,6 @@ class SILPrintContext {
103100
/// Returns true if debug locations and scopes should be printed.
104101
bool printDebugInfo() const { return DebugInfo; }
105102

106-
/// Returns true if the entire @convention(c, cType: ..) should be printed.
107-
bool printFullConvention() const { return PrintFullConvention; }
108-
109103
SILPrintContext::ID getID(const SILBasicBlock *Block);
110104

111105
SILPrintContext::ID getID(const SILNode *node);

include/swift/SIL/SILType.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ class SILType {
581581

582582
std::string getAsString() const;
583583
void dump() const;
584-
void print(raw_ostream &OS,
585-
const PrintOptions &PO = PrintOptions::printSIL()) const;
584+
void print(raw_ostream &OS) const;
586585
};
587586

588587
// Statically prevent SILTypes from being directly cast to a type

0 commit comments

Comments
 (0)