Skip to content

Revert "Propagate Clang types through SIL" #29350

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 0 additions & 13 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,6 @@ class ASTContext final {
Type getBridgedToObjC(const DeclContext *dc, Type type,
Type *bridgedValueType = nullptr) const;

private:
void initializeClangTypeConverter();

public:
/// Get the Clang type corresponding to a Swift function type.
///
/// \param params The function parameters.
Expand All @@ -599,15 +595,6 @@ class ASTContext final {
const FunctionType::ExtInfo incompleteExtInfo,
FunctionTypeRepresentation trueRep);

/// Get the canonical Clang type corresponding to a SIL function type.
///
/// SIL analog of \c ASTContext::getClangFunctionType .
const clang::Type *
getCanonicalClangFunctionType(
ArrayRef<SILParameterInfo> params, Optional<SILResultInfo> result,
const SILFunctionType::ExtInfo incompleteExtInfo,
SILFunctionType::Representation trueRep);

/// Determine whether the given Swift type is representable in a
/// given foreign language.
ForeignRepresentationInfo
Expand Down
5 changes: 1 addition & 4 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ struct PrintOptions {
static PrintOptions printDocInterface();

/// Retrieve the set of options suitable for printing SIL functions.
static PrintOptions printSIL(bool printFullConvention = false) {
static PrintOptions printSIL() {
PrintOptions result;
result.PrintLongAttrsOnSeparateLines = true;
result.PrintStorageRepresentationAttrs = true;
Expand All @@ -575,9 +575,6 @@ struct PrintOptions {
result.PrintIfConfig = false;
result.OpaqueReturnTypePrinting =
OpaqueReturnTypePrintingMode::StableReference;
if (printFullConvention)
result.PrintFunctionRepresentationAttrs =
PrintOptions::FunctionRepresentationMode::Full;
return result;
}

Expand Down
3 changes: 0 additions & 3 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class SILOptions {
/// variables by name when we print it out. This eases diffing of SIL files.
bool EmitSortedSIL = false;

/// See \ref FrontendOptions.PrintFullConvention
bool PrintFullConvention = false;

/// Whether to stop the optimization pipeline after serializing SIL.
bool StopOptimizationAfterSerialization = false;

Expand Down
90 changes: 27 additions & 63 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

namespace clang {
class Type;
class FunctionType;
} // namespace clang

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

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

class SILUncommonInfo {
friend class SILFunctionType;

// Invariant: The FunctionType is canonical.
// We store a clang::FunctionType * instead of a clang::CanQualType to
// avoid depending on the Clang AST in this header.
const clang::Type *ClangFunctionType;

bool empty() const { return !ClangFunctionType; }
SILUncommonInfo(const clang::Type *type) : ClangFunctionType(type) {}
SILUncommonInfo(AnyFunctionType::ExtInfo::Uncommon uncommon);

public:
/// Analog of AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType.
void printClangFunctionType(ClangModuleLoader *cml,
llvm::raw_ostream &os) const;
};

/// SILFunctionType - The lowered type of a function value, suitable
/// for use by SIL.
///
Expand All @@ -3943,8 +3925,7 @@ class SILUncommonInfo {
/// function parameter and result types.
class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
private llvm::TrailingObjects<SILFunctionType, SILParameterInfo,
SILResultInfo, SILYieldInfo, CanType,
SILUncommonInfo> {
SILResultInfo, SILYieldInfo, CanType> {
friend TrailingObjects;

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

size_t numTrailingObjects(OverloadToken<SILUncommonInfo>) const {
return Bits.SILFunctionType.HasUncommonInfo ? 1 : 0;
}

public:
using Language = SILFunctionLanguage;
using Representation = SILFunctionTypeRepresentation;
Expand All @@ -3991,31 +3968,27 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,

unsigned Bits; // Naturally sized for speed.

// For symmetry with AnyFunctionType::Uncommon
using Uncommon = SILUncommonInfo;
class Uncommon {
friend ExtInfo;
friend class SILFunctionType;

Uncommon Other;
// Invariant: The FunctionType is canonical.
// We store a clang::FunctionType * instead of a clang::CanQualType to
// avoid depending on the Clang AST in this header.
const clang::FunctionType *ClangFunctionType;

static void assertIsFunctionType(const clang::Type *);
bool empty() const { return !ClangFunctionType; }
Uncommon(const clang::FunctionType *type) : ClangFunctionType(type) {}

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

static constexpr unsigned makeBits(Representation rep,
bool isPseudogeneric,
bool isNoEscape,
DifferentiabilityKind diffKind) {
return ((unsigned) rep)
| (isPseudogeneric ? PseudogenericMask : 0)
| (isNoEscape ? NoEscapeMask : 0)
| (((unsigned)diffKind << DifferentiabilityMaskOffset)
& DifferentiabilityMask);
}
Uncommon Other;

ExtInfo(unsigned Bits, Uncommon Other) : Bits(Bits), Other(Other) {}

friend class SILFunctionType;
public:
Expand All @@ -4025,21 +3998,15 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
// Constructor for polymorphic type.
ExtInfo(Representation rep, bool isPseudogeneric, bool isNoEscape,
DifferentiabilityKind diffKind,
const clang::Type *type)
: ExtInfo(makeBits(rep, isPseudogeneric, isNoEscape, diffKind),
const clang::FunctionType *type)
: ExtInfo(((unsigned) rep)
| (isPseudogeneric ? PseudogenericMask : 0)
| (isNoEscape ? NoEscapeMask : 0)
| (((unsigned)diffKind << DifferentiabilityMaskOffset)
& DifferentiabilityMask),
Uncommon(type)) {
}

ExtInfo(AnyFunctionType::ExtInfo info, bool isPseudogeneric)
: ExtInfo(makeBits(info.getSILRepresentation(),
isPseudogeneric,
info.isNoEscape(),
info.getDifferentiabilityKind()),
info.getUncommonInfo().hasValue()
? Uncommon(info.getUncommonInfo().getValue())
: Uncommon(nullptr)) {
}

static ExtInfo getThin() {
return ExtInfo(Representation::Thin, false, false,
DifferentiabilityKind::NonDifferentiable, nullptr);
Expand Down Expand Up @@ -4126,9 +4093,6 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
return ExtInfo(NoEscape ? (Bits | NoEscapeMask) : (Bits & ~NoEscapeMask),
Other);
}
ExtInfo withClangFunctionType(const clang::Type *type) const {
return ExtInfo(Bits, Uncommon(type));
}

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

const clang::Type *getClangFunctionType() const;
const clang::FunctionType *getClangFunctionType() const;

ExtInfo getExtInfo() const {
return ExtInfo(Bits.SILFunctionType.ExtInfoBits, getClangFunctionType());
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ class FrontendOptions {
/// See the \ref SILOptions.EmitSortedSIL flag.
bool EmitSortedSIL = false;

/// Should we emit the cType when printing @convention(c) or no?
bool PrintFullConvention = false;

/// Indicates whether the dependency tracker should track system
/// dependencies as well.
bool TrackSystemDeps = false;
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Frontend/ModuleInterfaceSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ struct ModuleInterfaceOptions {
/// interface, or should we fully-qualify them?
bool PreserveTypesAsWritten = false;

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

/// Copy of all the command-line flags passed at .swiftinterface
Expand Down
6 changes: 2 additions & 4 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,10 @@ def module_interface_preserve_types_as_written :
HelpText<"When emitting a module interface, preserve types as they were "
"written in the source">;

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

def prebuilt_module_cache_path :
Separate<["-"], "prebuilt-module-cache-path">,
Expand Down
7 changes: 3 additions & 4 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,10 @@ class SILModule {
/// \param ShouldSort If set to true sorts functions, vtables, sil global
/// variables, and witness tables by name to ease diffing.
/// \param PrintASTDecls If set to true print AST decls.
void print(raw_ostream &OS,
ModuleDecl *M = nullptr,
const SILOptions &Opts = SILOptions(),
void print(raw_ostream &OS, bool Verbose = false,
ModuleDecl *M = nullptr, bool ShouldSort = false,
bool PrintASTDecls = true) const {
SILPrintContext PrintCtx(OS, Opts);
SILPrintContext PrintCtx(OS, Verbose, ShouldSort);
print(PrintCtx, M, PrintASTDecls);
}

Expand Down
12 changes: 0 additions & 12 deletions include/swift/SIL/SILPrintContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#ifndef SWIFT_SIL_PRINTCONTEXT_H
#define SWIFT_SIL_PRINTCONTEXT_H

#include "swift/AST/SILOptions.h"
#include "swift/SIL/SILDebugScope.h"
#include "swift/SIL/SILValue.h"
#include "llvm/ADT/DenseMap.h"
Expand Down Expand Up @@ -66,21 +65,13 @@ class SILPrintContext {
/// Print debug locations and scopes.
bool DebugInfo;

/// See \ref FrontendOptions.PrintFullConvention.
bool PrintFullConvention;

public:
/// Constructor with default values for options.
///
/// DebugInfo will be set according to the -sil-print-debuginfo option.
SILPrintContext(llvm::raw_ostream &OS, bool Verbose = false,
bool SortedSIL = false);

/// Constructor based on SILOptions.
///
/// DebugInfo will be set according to the -sil-print-debuginfo option.
SILPrintContext(llvm::raw_ostream &OS, const SILOptions &Opts);

SILPrintContext(llvm::raw_ostream &OS, bool Verbose,
bool SortedSIL, bool DebugInfo);

Expand All @@ -103,9 +94,6 @@ class SILPrintContext {
/// Returns true if debug locations and scopes should be printed.
bool printDebugInfo() const { return DebugInfo; }

/// Returns true if the entire @convention(c, cType: ..) should be printed.
bool printFullConvention() const { return PrintFullConvention; }

SILPrintContext::ID getID(const SILBasicBlock *Block);

SILPrintContext::ID getID(const SILNode *node);
Expand Down
3 changes: 1 addition & 2 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ class SILType {

std::string getAsString() const;
void dump() const;
void print(raw_ostream &OS,
const PrintOptions &PO = PrintOptions::printSIL()) const;
void print(raw_ostream &OS) const;
};

// Statically prevent SILTypes from being directly cast to a type
Expand Down
Loading