Skip to content

Rdar 29016063 swift 3.1 branch precompile bridging header #6768

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

Merged
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
8 changes: 8 additions & 0 deletions include/swift/AST/DiagnosticsClangImporter.def
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ ERROR(bridging_header_error,Fatal,
WARNING(could_not_rewrite_bridging_header,none,
"failed to serialize bridging header; "
"target may not be debuggable outside of its original project", ())
ERROR(bridging_header_pch_error,Fatal,
"failed to emit PCH file '%0' for bridging header '%1'",
(StringRef, StringRef))

WARNING(invalid_swift_name_method,none,
"too %select{few|many}0 parameters in swift_name attribute (expected %1; "
Expand All @@ -76,6 +79,11 @@ WARNING(unresolvable_clang_decl,none,
"imported declaration '%0' could not be mapped to '%1'",
(StringRef, StringRef))

WARNING(implicit_bridging_header_imported_from_module,none,
"implicit import of bridging header '%0' via module %1 "
"is deprecated and will be removed in a later version of Swift",
(StringRef, Identifier))

#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
# undef DIAG
Expand Down
13 changes: 12 additions & 1 deletion include/swift/ClangImporter/ClangImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,16 @@ class ClangImporter final : public ClangModuleLoader {
/// \param diagLoc A location to attach any diagnostics to if import fails.
/// \param trackParsedSymbols If true, tracks decls and macros that were
/// parsed from the bridging header.
/// \param implicitImport If true, indicates that this import was implicit
/// from a reference in a module file (deprecated behaviour).
///
/// \returns true if there was an error importing the header.
///
/// \sa getImportedHeaderModule
bool importBridgingHeader(StringRef header, ModuleDecl *adapter,
SourceLoc diagLoc = {},
bool trackParsedSymbols = false);
bool trackParsedSymbols = false,
bool implicitImport = false);

/// Returns the module that contains imports and declarations from all loaded
/// Objective-C header files.
Expand All @@ -218,6 +221,14 @@ class ClangImporter final : public ClangModuleLoader {
std::string getBridgingHeaderContents(StringRef headerPath, off_t &fileSize,
time_t &fileModTime);

/// Makes a temporary replica of the ClangImporter's CompilerInstance, reads
/// an Objective-C header file into the replica and emits a PCH file of its
/// content. Delegates to clang for everything except construction of the
/// replica.
///
/// \sa clang::GeneratePCHAction
bool emitBridgingPCH(StringRef headerPath, StringRef outputPCHPath);

const clang::Module *getClangOwningModule(ClangNode Node) const;
bool hasTypedef(const clang::Decl *typeDecl) const;

Expand Down
3 changes: 3 additions & 0 deletions include/swift/ClangImporter/ClangImporterOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class ClangImporterOptions {
/// Equivalent to Clang's -mcpu=.
std::string TargetCPU;

// The bridging header or PCH that will be imported.
std::string BridgingHeader;

/// \see Mode
enum class Modes {
/// Set up Clang for importing modules into Swift and generating IR from
Expand Down
14 changes: 13 additions & 1 deletion include/swift/Driver/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class Action {
REPLJob,
LinkJob,
GenerateDSYMJob,
GeneratePCHJob,

JobFirst=CompileJob,
JobLast=GenerateDSYMJob
JobLast=GeneratePCHJob
};

static const char *getClassName(ActionClass AC);
Expand Down Expand Up @@ -268,6 +269,17 @@ class GenerateDSYMJobAction : public JobAction {
}
};

class GeneratePCHJobAction : public JobAction {
virtual void anchor();
public:
explicit GeneratePCHJobAction(Action *Input)
: JobAction(Action::GeneratePCHJob, Input, types::TY_PCH) {}

static bool classof(const Action *A) {
return A->getKind() == Action::GeneratePCHJob;
}
};

class LinkJobAction : public JobAction {
virtual void anchor();
LinkKind Kind;
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class ToolChain {
constructInvocation(const GenerateDSYMJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const GeneratePCHJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const AutolinkExtractJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
Expand Down
1 change: 1 addition & 0 deletions include/swift/Driver/Types.def
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ TYPE("remap", Remapping, "remap", "")

// Misc types
TYPE("pcm", ClangModuleFile, "pcm", "")
TYPE("pch", PCH, "pch", "")
TYPE("none", Nothing, "", "")

#undef TYPE
2 changes: 2 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class FrontendOptions {
/// Parse, type-check, and dump type refinement context hierarchy
DumpTypeRefinementContexts,

EmitPCH, ///< Emit PCH of imported bridging header

EmitSILGen, ///< Emit raw SIL
EmitSIL, ///< Emit canonical SIL

Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def disable_modules_validate_system_headers : Flag<["-"], "disable-modules-valid
def emit_verbose_sil : Flag<["-"], "emit-verbose-sil">,
HelpText<"Emit locations during SIL emission">;

def emit_pch : Flag<["-"], "emit-pch">,
HelpText<"Emit PCH for imported Objective-C header file">, ModeOpt;

def enable_sil_ownership : Flag<["-"], "enable-sil-ownership">,
HelpText<"Enable the SIL Ownership Model">;

Expand Down
8 changes: 8 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ def disable_swift_bridge_attr : Flag<["-"], "disable-swift-bridge-attr">,
Flags<[FrontendOption, HelpHidden]>,
HelpText<"Disable using the swift bridge attribute">;

def enable_bridging_pch : Flag<["-"], "enable-bridging-pch">,
Flags<[HelpHidden]>,
HelpText<"Enable automatic generation of bridging PCH files">;

def disable_bridging_pch : Flag<["-"], "disable-bridging-pch">,
Flags<[HelpHidden]>,
HelpText<"Disable automatic generation of bridging PCH files">;

// Diagnostic control options
def suppress_warnings : Flag<["-"], "suppress-warnings">,
Flags<[FrontendOption]>,
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace swift {
static const char SERIALIZED_MODULE_EXTENSION[] = "swiftmodule";
/// The extension for serialized documentation comments.
static const char SERIALIZED_MODULE_DOC_EXTENSION[] = "swiftdoc";
/// The extension for PCH files.
static const char PCH_EXTENSION[] = "pch";
/// The extension for SIL files.
static const char SIL_EXTENSION[] = "sil";
/// The extension for SIB files.
Expand Down
Loading