Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e48469d
[NFC] Add missing invariant checks for ExtInfoBuilders.
varungandhi-apple Sep 1, 2020
5e9bf1f
[SIL] Store ClangTypeInfo in SILFunctionType.
varungandhi-apple Sep 8, 2020
983399c
[Printer] Conditionally print Clang types in emitted SIL.
varungandhi-apple Sep 1, 2020
f97e803
[Diagnostics] Allow "unknown base" fix to be diagnosed in ambiguity s…
xedin Sep 21, 2020
fa4f7dd
Parse: Don't create PatternBindingDecls with overlapping source ranges
slavapestov Sep 22, 2020
51a4a91
Sema: Mark a PatternBindingDecl as implicit in the builder transform
slavapestov Sep 22, 2020
85ae227
ASTScope: Remove hacks for PatternBindingDecls with invalid source ra…
slavapestov Sep 22, 2020
c662c10
ASTScope: Use visitParsedAccessors() instead of getAllAccessors()
slavapestov Sep 22, 2020
ed96cf4
Avoid using extra-cmake-options in the stdlib standalone presets (#34…
kubamracek Sep 22, 2020
007c814
Merge pull request #34021 from slavapestov/astscope-invalid-pbds
slavapestov Sep 22, 2020
7b967a8
Merge pull request #33085 from varungandhi-apple/vg-clang-types-in-si…
varungandhi-apple Sep 22, 2020
fb86fb3
[SR-10251] Add test case for a bug that's already been fixed.
DougGregor Sep 22, 2020
e0dbba5
[Dependency Scanner] Add option to execute an import prescan
artemcm Sep 22, 2020
20be565
Update CMark branch to main
shahmishal Sep 22, 2020
d5449bf
[Dependency Scanner] Add import-prescan handling to batch scanning
artemcm Sep 22, 2020
9af195c
[NFC] Remove a typealias from SILInstruction.h that's unused in noass…
hborla Sep 22, 2020
65764c6
Update the branch to main for swift-llbuild
shahmishal Sep 22, 2020
e7d7847
Update the branch to main for swift-tools-support-core
shahmishal Sep 22, 2020
657017c
Merge pull request #34016 from xedin/rdar-66891544
xedin Sep 22, 2020
0b9793e
Update swiftpm branch to main
shahmishal Sep 22, 2020
6aa0572
Merge pull request #34030 from DougGregor/sr-10251-testcase
DougGregor Sep 22, 2020
12c356b
Merge pull request #34028 from artemcm/dependencies-prescan
artemcm Sep 22, 2020
41f91d5
Add a SWIFT_FREESTANDING_MODULE_NAME CMake option (#34018)
kubamracek Sep 22, 2020
f523bda
Update the aliases for main branch
shahmishal Sep 22, 2020
5921a4b
Update swift-driver branch to main
shahmishal Sep 22, 2020
5dcc764
Update swift-syntax branch to main
shahmishal Sep 22, 2020
ff23125
ARCSequenceOpts: Enable loop support (#33818)
meg-gupta Sep 23, 2020
55144ab
Merge pull request #34031 from hborla/unused-typealias-warning
hborla Sep 23, 2020
38926bd
Update swift-stress-tester to use main
shahmishal Sep 23, 2020
6d600b4
Update swift-corelibs-xctest to main branch
shahmishal Sep 23, 2020
93b4c9f
Merge remote-tracking branch 'apple/master' into katei/merge-master-2…
kateinoigakukun Sep 23, 2020
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
5 changes: 4 additions & 1 deletion cmake/modules/DarwinSDKs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ if(swift_build_freestanding)
"Which SDK to use when building the FREESTANDING stdlib")
set(SWIFT_FREESTANDING_TRIPLE_NAME "" CACHE STRING
"Which triple name (e.g. 'none-macho') to use when building the FREESTANDING stdlib")
set(SWIFT_FREESTANDING_MODULE_NAME "" CACHE STRING
"Which .swiftmodule name (e.g. 'freestanding') to use when building the FREESTANDING stdlib")
set(SWIFT_FREESTANDING_ARCHS "" CACHE STRING
"Which architectures to build when building the FREESTANDING stdlib")
configure_sdk_darwin(
FREESTANDING "FREESTANDING" ""
"${SWIFT_FREESTANDING_SDK}" freestanding "${SWIFT_FREESTANDING_TRIPLE_NAME}" freestanding "${SWIFT_FREESTANDING_ARCHS}")
"${SWIFT_FREESTANDING_SDK}" freestanding
"${SWIFT_FREESTANDING_TRIPLE_NAME}" "${SWIFT_FREESTANDING_MODULE_NAME}" "${SWIFT_FREESTANDING_ARCHS}")
set(SWIFT_SDK_FREESTANDING_LIB_SUBDIR "freestanding")
configure_target_variant(FREESTANDING-DA "FREESTANDING Debug+Asserts" FREESTANDING DA "Debug+Asserts")
configure_target_variant(FREESTANDING-RA "FREESTANDING Release+Asserts" FREESTANDING RA "Release+Asserts")
Expand Down
114 changes: 106 additions & 8 deletions include/swift/AST/ExtInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FunctionType;
class SILExtInfo;
class SILExtInfoBuilder;
class SILFunctionType;
enum class SILFunctionTypeRepresentation : uint8_t;
} // namespace swift

namespace swift {
Expand All @@ -54,6 +55,7 @@ class ClangTypeInfo {
friend ASTExtInfoBuilder;
friend SILExtInfoBuilder;

// [NOTE: ClangTypeInfo-contents]
// 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
// (for AnyFunctionType).
Expand Down Expand Up @@ -81,6 +83,26 @@ class ClangTypeInfo {
void dump(llvm::raw_ostream &os, const clang::ASTContext &ctx) const;
};

// MARK: - UnexpectedClangTypeError
/// Potential errors when trying to store a Clang type in an ExtInfo.
struct UnexpectedClangTypeError {
enum class Kind {
NullForCOrBlock,
NonnullForNonCOrBlock,
NotBlockPointer,
NotFunctionPointerOrReference,
NonCanonical,
};
const Kind errorKind;
const clang::Type *type;

static Optional<UnexpectedClangTypeError> checkClangType(
SILFunctionTypeRepresentation fnRep, const clang::Type *type,
bool expectNonnullForCOrBlock, bool expectCanonical);

void dump();
};

// MARK: - FunctionTypeRepresentation
/// The representation form of a function.
enum class FunctionTypeRepresentation : uint8_t {
Expand Down Expand Up @@ -146,6 +168,41 @@ enum class SILFunctionTypeRepresentation : uint8_t {
Closure,
};

constexpr SILFunctionTypeRepresentation
convertRepresentation(FunctionTypeRepresentation rep) {
switch (rep) {
case FunctionTypeRepresentation::Swift:
return SILFunctionTypeRepresentation::Thick;
case FunctionTypeRepresentation::Block:
return SILFunctionTypeRepresentation::Block;
case FunctionTypeRepresentation::Thin:
return SILFunctionTypeRepresentation::Thin;
case FunctionTypeRepresentation::CFunctionPointer:
return SILFunctionTypeRepresentation::CFunctionPointer;
}
llvm_unreachable("Unhandled FunctionTypeRepresentation!");
};

inline Optional<FunctionTypeRepresentation>
convertRepresentation(SILFunctionTypeRepresentation rep) {
switch (rep) {
case SILFunctionTypeRepresentation::Thick:
return {FunctionTypeRepresentation::Swift};
case SILFunctionTypeRepresentation::Block:
return {FunctionTypeRepresentation::Block};
case SILFunctionTypeRepresentation::Thin:
return {FunctionTypeRepresentation::Thin};
case SILFunctionTypeRepresentation::CFunctionPointer:
return {FunctionTypeRepresentation::CFunctionPointer};
case SILFunctionTypeRepresentation::Method:
case SILFunctionTypeRepresentation::ObjCMethod:
case SILFunctionTypeRepresentation::WitnessMethod:
case SILFunctionTypeRepresentation::Closure:
return None;
}
llvm_unreachable("Unhandled SILFunctionTypeRepresentation!");
};

/// Can this calling convention result in a function being called indirectly
/// through the runtime.
constexpr bool canBeCalledIndirectly(SILFunctionTypeRepresentation rep) {
Expand All @@ -165,6 +222,25 @@ constexpr bool canBeCalledIndirectly(SILFunctionTypeRepresentation rep) {
llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
}

template <typename Repr> constexpr bool shouldStoreClangType(Repr repr) {
static_assert(std::is_same<Repr, FunctionTypeRepresentation>::value ||
std::is_same<Repr, SILFunctionTypeRepresentation>::value,
"Expected a Representation type as the argument type.");
switch (static_cast<SILFunctionTypeRepresentation>(repr)) {
case SILFunctionTypeRepresentation::CFunctionPointer:
case SILFunctionTypeRepresentation::Block:
return true;
case SILFunctionTypeRepresentation::ObjCMethod:
case SILFunctionTypeRepresentation::Thick:
case SILFunctionTypeRepresentation::Thin:
case SILFunctionTypeRepresentation::Method:
case SILFunctionTypeRepresentation::WitnessMethod:
case SILFunctionTypeRepresentation::Closure:
return false;
}
llvm_unreachable("Unhandled SILFunctionTypeRepresentation.");
}

// MARK: - ASTExtInfoBuilder
/// A builder type for creating an \c ASTExtInfo.
///
Expand Down Expand Up @@ -292,7 +368,8 @@ class ASTExtInfoBuilder {
LLVM_NODISCARD
ASTExtInfoBuilder withRepresentation(Representation rep) const {
return ASTExtInfoBuilder((bits & ~RepresentationMask) | (unsigned)rep,
clangTypeInfo);
shouldStoreClangType(rep) ? clangTypeInfo
: ClangTypeInfo());
}
LLVM_NODISCARD
ASTExtInfoBuilder withNoEscape(bool noEscape = true) const {
Expand Down Expand Up @@ -333,7 +410,8 @@ class ASTExtInfoBuilder {
ASTExtInfoBuilder
withSILRepresentation(SILFunctionTypeRepresentation rep) const {
return ASTExtInfoBuilder((bits & ~RepresentationMask) | (unsigned)rep,
clangTypeInfo);
shouldStoreClangType(rep) ? clangTypeInfo
: ClangTypeInfo());
}

bool isEqualTo(ASTExtInfoBuilder other, bool useClangTypes) const {
Expand All @@ -360,12 +438,16 @@ class ASTExtInfo {

ASTExtInfoBuilder builder;

// Only for use by ASTExtInfoBuilder::build. Don't use it elsewhere!
ASTExtInfo(ASTExtInfoBuilder builder) : builder(builder) {}

ASTExtInfo(unsigned bits, ClangTypeInfo clangTypeInfo)
: builder(bits, clangTypeInfo){};
: builder(bits, clangTypeInfo) {
builder.checkInvariants();
};

public:
ASTExtInfo() : builder(){};
ASTExtInfo() : builder() { builder.checkInvariants(); };

/// Create a builder with the same state as \c this.
ASTExtInfoBuilder intoBuilder() const { return builder; }
Expand Down Expand Up @@ -504,7 +586,7 @@ class SILExtInfoBuilder {
using Representation = SILFunctionTypeRepresentation;

SILExtInfoBuilder(unsigned bits, ClangTypeInfo clangTypeInfo)
: bits(bits), clangTypeInfo(clangTypeInfo) {}
: bits(bits), clangTypeInfo(clangTypeInfo.getCanonical()) {}

static constexpr unsigned makeBits(Representation rep, bool isPseudogeneric,
bool isNoEscape, bool isAsync,
Expand Down Expand Up @@ -606,7 +688,8 @@ class SILExtInfoBuilder {
// the following with methods instead of mutating these objects.
SILExtInfoBuilder withRepresentation(Representation rep) const {
return SILExtInfoBuilder((bits & ~RepresentationMask) | (unsigned)rep,
clangTypeInfo);
shouldStoreClangType(rep) ? clangTypeInfo
: ClangTypeInfo());
}
SILExtInfoBuilder withIsPseudogeneric(bool isPseudogeneric = true) const {
return SILExtInfoBuilder(isPseudogeneric ? (bits | PseudogenericMask)
Expand All @@ -629,6 +712,10 @@ class SILExtInfoBuilder {
((unsigned)differentiability << DifferentiabilityMaskOffset),
clangTypeInfo);
}
LLVM_NODISCARD
SILExtInfoBuilder withClangFunctionType(const clang::Type *type) const {
return SILExtInfoBuilder(bits, ClangTypeInfo(type).getCanonical());
}

bool isEqualTo(SILExtInfoBuilder other, bool useClangTypes) const {
return bits == other.bits &&
Expand All @@ -654,12 +741,21 @@ class SILExtInfo {

SILExtInfoBuilder builder;

// Only for use by SILExtInfoBuilder::build. Don't use it elsewhere!
SILExtInfo(SILExtInfoBuilder builder) : builder(builder) {}

SILExtInfo(unsigned bits, ClangTypeInfo clangTypeInfo)
: builder(bits, clangTypeInfo){};
: builder(bits, clangTypeInfo) {
builder.checkInvariants();
};

public:
SILExtInfo() : builder(){};
SILExtInfo() : builder() { builder.checkInvariants(); };

SILExtInfo(ASTExtInfo info, bool isPseudogeneric)
: builder(info.intoBuilder(), isPseudogeneric) {
builder.checkInvariants();
}

static SILExtInfo getThin() {
return SILExtInfoBuilder(SILExtInfoBuilder::Representation::Thin, false,
Expand Down Expand Up @@ -722,6 +818,8 @@ class SILExtInfo {
constexpr std::pair<unsigned, const void *> getFuncAttrKey() const {
return builder.getFuncAttrKey();
}

Optional<UnexpectedClangTypeError> checkClangType() const;
};

/// Helper function to obtain the useClangTypes parameter for checking equality
Expand Down
5 changes: 4 additions & 1 deletion include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ struct PrintOptions {
static PrintOptions printDocInterface();

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

Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ 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
6 changes: 5 additions & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3888,7 +3888,7 @@ class SILFunctionType final
public llvm::FoldingSetNode,
private llvm::TrailingObjects<SILFunctionType, SILParameterInfo,
SILResultInfo, SILYieldInfo,
SubstitutionMap, CanType> {
SubstitutionMap, CanType, ClangTypeInfo> {
friend TrailingObjects;

size_t numTrailingObjects(OverloadToken<SILParameterInfo>) const {
Expand All @@ -3912,6 +3912,10 @@ class SILFunctionType final
size_t(hasInvocationSubstitutions());
}

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

public:
using ExtInfo = SILExtInfo;
using ExtInfoBuilder = SILExtInfoBuilder;
Expand Down
7 changes: 7 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ class FrontendOptions {
/// output path is configured.
Optional<IntermoduleDepTrackingMode> IntermoduleDependencyTracking;

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

/// Should we serialize the hashes of dependencies (vs. the modification
/// times) when compiling a module interface?
bool SerializeModuleInterfaceDependencyHashes = false;
Expand All @@ -269,6 +272,10 @@ class FrontendOptions {
/// built and given to the compiler invocation.
bool DisableImplicitModules = false;

/// When performing a dependency scanning action, only identify and output all imports
/// of the main Swift module's source files.
bool ImportPrescan = false;

/// The different modes for validating TBD against the LLVM IR.
enum class TBDValidationMode {
Default, ///< Do the default validation for the current platform.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Frontend/ModuleInterfaceSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ModuleInterfaceOptions {
/// interface, or should we fully-qualify them?
bool PreserveTypesAsWritten = false;

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

Expand Down
11 changes: 8 additions & 3 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ def placeholder_dependency_module_map
def batch_scan_input_file
: Separate<["-"], "batch-scan-input-file">, MetaVarName<"<path>">,
HelpText<"Specify a JSON file containing modules to perform batch dependencies scanning">;
}

def import_prescan : Flag<["-"], "import-prescan">,
HelpText<"When performing a dependency scan, only dentify all imports of the main Swift module sources">;

}

// HIDDEN FLAGS
let Flags = [FrontendOption, NoDriverOption, HelpHidden] in {
Expand Down Expand Up @@ -664,10 +667,12 @@ def experimental_spi_imports :
Flag<["-"], "experimental-spi-imports">,
HelpText<"Enable experimental support for SPI imports">;

// [FIXME: Clang-type-plumbing] 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, emit additional @convention "
"arguments, regardless of whether they were written in the source">;
HelpText<"When emitting a module interface or SIL, emit additional @convention"
" arguments, regardless of whether they were written in the source">;

def experimental_one_way_closure_params :
Flag<["-"], "experimental-one-way-closure-params">,
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ class Parser {
ParsedAccessors &accessors,
AbstractStorageDecl *storage,
SourceLoc StaticLoc);
ParserResult<VarDecl> parseDeclVarGetSet(Pattern *pattern,
ParserResult<VarDecl> parseDeclVarGetSet(PatternBindingEntry &entry,
ParseDeclOptions Flags,
SourceLoc StaticLoc,
StaticSpellingKind StaticSpelling,
Expand Down
7 changes: 3 additions & 4 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -3978,10 +3978,9 @@ class AssignByWrapperInst
Destination getAssignDestination() const { return AssignDest; }

void setAssignInfo(AssignOwnershipQualifier qualifier, Destination dest) {
using Qualifier = AssignOwnershipQualifier;
assert(qualifier == Qualifier::Init && dest == Destination::BackingWrapper ||
qualifier == Qualifier::Reassign && dest == Destination::BackingWrapper ||
qualifier == Qualifier::Reassign && dest == Destination::WrappedValue);
assert(qualifier == AssignOwnershipQualifier::Init && dest == Destination::BackingWrapper ||
qualifier == AssignOwnershipQualifier::Reassign && dest == Destination::BackingWrapper ||
qualifier == AssignOwnershipQualifier::Reassign && dest == Destination::WrappedValue);

SILInstruction::Bits.AssignByWrapperInst.OwnershipQualifier = unsigned(qualifier);
AssignDest = dest;
Expand Down
3 changes: 1 addition & 2 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,7 @@ class SILModule {
/// \param Opts The SIL options, used to determine printing verbosity and
/// and sorting.
/// \param PrintASTDecls If set to true print AST decls.
void print(raw_ostream& OS,
ModuleDecl *M = nullptr,
void print(raw_ostream &OS, ModuleDecl *M = nullptr,
const SILOptions &Opts = SILOptions(),
bool PrintASTDecls = true) const {
SILPrintContext PrintCtx(OS, Opts);
Expand Down
Loading