Skip to content

Commit 3103b5c

Browse files
committed
Frontend: set up output file .swiftsourceinfo
This patch will focus on teaching driver and frontend to emit this file. The actual content and de-serialization parts will come later. More details: https://forums.swift.org/t/proposal-emitting-source-information-file-during-compilation/28794
1 parent 4e476ff commit 3103b5c

21 files changed

+146
-8
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ function(_compile_swift_files
310310
set(module_base "${module_dir}/${SWIFTFILE_MODULE_NAME}")
311311
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
312312
set(specific_module_dir "${module_base}.swiftmodule")
313+
set(specific_module_private_dir "${specific_module_dir}/Private")
313314
set(module_base "${module_base}.swiftmodule/${SWIFTFILE_ARCHITECTURE}")
314315
else()
315316
set(specific_module_dir)
317+
set(specific_module_private_dir)
316318
endif()
317319
set(module_file "${module_base}.swiftmodule")
318320
set(module_doc_file "${module_base}.swiftdoc")
@@ -490,6 +492,7 @@ function(_compile_swift_files
490492
COMMAND
491493
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
492494
${specific_module_dir}
495+
${specific_module_private_dir}
493496
COMMAND
494497
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
495498
"${swift_compiler_tool}" "-emit-module" "-o" "${module_file}"

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ ERROR(error_mode_cannot_emit_module,none,
124124
"this mode does not support emitting modules", ())
125125
ERROR(error_mode_cannot_emit_module_doc,none,
126126
"this mode does not support emitting module documentation files", ())
127+
ERROR(error_mode_cannot_emit_module_source_info,none,
128+
"this mode does not support emitting module source info files", ())
127129
ERROR(error_mode_cannot_emit_interface,none,
128130
"this mode does not support emitting module interface files", ())
129131

include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ TYPE("autolink", AutolinkFile, "autolink", "")
5050
TYPE("swiftmodule", SwiftModuleFile, "swiftmodule", "")
5151
TYPE("swiftdoc", SwiftModuleDocFile, "swiftdoc", "")
5252
TYPE("swiftinterface", SwiftModuleInterfaceFile, "swiftinterface", "")
53+
TYPE("swiftsourceinfo", SwiftSourceInfoFile, "swiftsourceinfo", "")
5354
TYPE("assembly", Assembly, "s", "")
5455
TYPE("raw-sil", RawSIL, "sil", "")
5556
TYPE("raw-sib", RawSIB, "sib", "")

include/swift/Basic/SupplementaryOutputPaths.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ struct SupplementaryOutputPaths {
4141
/// \sa swift::serialize
4242
std::string ModuleOutputPath;
4343

44+
/// The path to which we should emit a module source information file.
45+
/// It is valid whenever there are any inputs.
46+
///
47+
/// This binary format stores source locations and other information about the
48+
/// declarations in a module.
49+
///
50+
/// \sa swift::serialize
51+
std::string ModuleSourceInfoOutputPath;
52+
4453
/// The path to which we should emit a module documentation file.
4554
/// It is valid whenever there are any inputs.
4655
///
@@ -132,7 +141,8 @@ struct SupplementaryOutputPaths {
132141
ModuleDocOutputPath.empty() && DependenciesFilePath.empty() &&
133142
ReferenceDependenciesFilePath.empty() &&
134143
SerializedDiagnosticsPath.empty() && LoadedModuleTracePath.empty() &&
135-
TBDPath.empty() && ModuleInterfaceOutputPath.empty();
144+
TBDPath.empty() && ModuleInterfaceOutputPath.empty() &&
145+
ModuleSourceInfoOutputPath.empty();
136146
}
137147
};
138148
} // namespace swift

include/swift/Driver/Driver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ class Driver {
354354
StringRef workingDirectory,
355355
CommandOutput *Output) const;
356356

357+
void choosePrivateOutputFilePath(Compilation &C,
358+
const TypeToPathMap *OutputMap,
359+
StringRef workingDirectory,
360+
CommandOutput *Output,
361+
file_types::ID fileID) const;
362+
357363
void chooseModuleInterfacePath(Compilation &C, const JobAction *JA,
358364
StringRef workingDirectory,
359365
llvm::SmallString<128> &buffer,

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class FrontendInputsAndOutputs {
235235
bool hasLoadedModuleTracePath() const;
236236
bool hasModuleOutputPath() const;
237237
bool hasModuleDocOutputPath() const;
238+
bool hasModuleSourceInfoOutputPath() const;
238239
bool hasModuleInterfaceOutputPath() const;
239240
bool hasTBDPath() const;
240241

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ def emit_module_doc_path
3838
: Separate<["-"], "emit-module-doc-path">, MetaVarName<"<path>">,
3939
HelpText<"Output module documentation file <path>">;
4040

41+
def emit_module_source_info : Flag<["-"], "emit-module-source-info">,
42+
HelpText<"Output module source info file">;
43+
def emit_module_source_info_path : Separate<["-"], "emit-module-source-info-path">,
44+
HelpText<"Output module source info file to <path>">;
45+
4146
def merge_modules
4247
: Flag<["-"], "merge-modules">, ModeOpt,
4348
HelpText<"Merge the input modules without otherwise processing them">;

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace swift {
2929

3030
const char *OutputPath = nullptr;
3131
const char *DocOutputPath = nullptr;
32+
const char *SourceInfoOutputPath = nullptr;
3233

3334
StringRef GroupInfoPath;
3435
StringRef ImportedHeader;

include/swift/Subsystems.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ namespace swift {
282282
const SerializationOptions &opts,
283283
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
284284
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
285+
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
285286
const SILModule *M = nullptr);
286287

287288
/// Get the CPU, subtarget feature options, and triple to use when emitting code.

lib/Basic/FileTypes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ bool file_types::isTextual(ID Id) {
8989
case file_types::TY_RawSIB:
9090
case file_types::TY_SwiftModuleFile:
9191
case file_types::TY_SwiftModuleDocFile:
92+
case file_types::TY_SwiftSourceInfoFile:
9293
case file_types::TY_LLVM_BC:
9394
case file_types::TY_SerializedDiagnostics:
9495
case file_types::TY_ClangModuleFile:
@@ -128,6 +129,7 @@ bool file_types::isAfterLLVM(ID Id) {
128129
case file_types::TY_RawSIB:
129130
case file_types::TY_SwiftModuleFile:
130131
case file_types::TY_SwiftModuleDocFile:
132+
case file_types::TY_SwiftSourceInfoFile:
131133
case file_types::TY_SerializedDiagnostics:
132134
case file_types::TY_ClangModuleFile:
133135
case file_types::TY_SwiftDeps:
@@ -169,6 +171,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
169171
case file_types::TY_SwiftModuleFile:
170172
case file_types::TY_SwiftModuleDocFile:
171173
case file_types::TY_SwiftModuleInterfaceFile:
174+
case file_types::TY_SwiftSourceInfoFile:
172175
case file_types::TY_SerializedDiagnostics:
173176
case file_types::TY_ClangModuleFile:
174177
case file_types::TY_SwiftDeps:

0 commit comments

Comments
 (0)