Skip to content

Commit 8bd3e6e

Browse files
authored
Merge pull request swiftlang#27698 from nkcsgexi/ignore-source-info-file-flag
Front-end: add an option to ignore .swiftsourceinfo file for testing purposes. NFC
2 parents 8743564 + b103997 commit 8bd3e6e

File tree

8 files changed

+47
-25
lines changed

8 files changed

+47
-25
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ class FrontendOptions {
156156
/// Indicates that the input(s) should be parsed as the Swift stdlib.
157157
bool ParseStdlib = false;
158158

159+
/// Ignore .swiftsourceinfo file when trying to get source locations from module imported decls.
160+
bool IgnoreSwiftSourceInfo = false;
161+
159162
/// When true, emitted module files will always contain options for the
160163
/// debugger to use. When unset, the options will only be present if the
161164
/// module appears to not be a public module.

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
134134
ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
135135
DependencyTracker *tracker, ModuleLoadingMode loadMode,
136136
ArrayRef<std::string> PreferInterfaceForModules,
137-
bool RemarkOnRebuildFromInterface)
138-
: SerializedModuleLoaderBase(ctx, tracker, loadMode),
137+
bool RemarkOnRebuildFromInterface, bool IgnoreSwiftSourceInfoFile)
138+
: SerializedModuleLoaderBase(ctx, tracker, loadMode,
139+
IgnoreSwiftSourceInfoFile),
139140
CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
140141
RemarkOnRebuildFromInterface(RemarkOnRebuildFromInterface),
141142
PreferInterfaceForModules(PreferInterfaceForModules)
@@ -161,12 +162,14 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
161162
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
162163
DependencyTracker *tracker, ModuleLoadingMode loadMode,
163164
ArrayRef<std::string> PreferInterfaceForModules = {},
164-
bool RemarkOnRebuildFromInterface = false) {
165+
bool RemarkOnRebuildFromInterface = false,
166+
bool IgnoreSwiftSourceInfoFile = false) {
165167
return std::unique_ptr<ModuleInterfaceLoader>(
166168
new ModuleInterfaceLoader(ctx, cacheDir, prebuiltCacheDir,
167169
tracker, loadMode,
168170
PreferInterfaceForModules,
169-
RemarkOnRebuildFromInterface));
171+
RemarkOnRebuildFromInterface,
172+
IgnoreSwiftSourceInfoFile));
170173
}
171174

172175
/// Append visible module names to \p names. Note that names are possibly

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def emit_module_doc_path
4141
def emit_module_source_info : Flag<["-"], "emit-module-source-info">,
4242
HelpText<"Output module source info file">;
4343

44+
def ignore_module_source_info : Flag<["-"], "ignore-module-source-info">,
45+
HelpText<"Avoid getting source location from .swiftsourceinfo files">;
46+
4447
def merge_modules
4548
: Flag<["-"], "merge-modules">, ModeOpt,
4649
HelpText<"Merge the input modules without otherwise processing them">;

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ class SerializedModuleLoaderBase : public ModuleLoader {
4343
protected:
4444
ASTContext &Ctx;
4545
ModuleLoadingMode LoadMode;
46+
bool IgnoreSwiftSourceInfoFile;
4647
SerializedModuleLoaderBase(ASTContext &ctx, DependencyTracker *tracker,
47-
ModuleLoadingMode LoadMode);
48+
ModuleLoadingMode LoadMode,
49+
bool IgnoreSwiftSourceInfoFile);
4850

4951
void collectVisibleTopLevelModuleNamesImpl(SmallVectorImpl<Identifier> &names,
5052
StringRef extension) const;
@@ -168,8 +170,8 @@ class SerializedModuleLoaderBase : public ModuleLoader {
168170
class SerializedModuleLoader : public SerializedModuleLoaderBase {
169171

170172
SerializedModuleLoader(ASTContext &ctx, DependencyTracker *tracker,
171-
ModuleLoadingMode loadMode)
172-
: SerializedModuleLoaderBase(ctx, tracker, loadMode)
173+
ModuleLoadingMode loadMode, bool IgnoreSwiftSourceInfo)
174+
: SerializedModuleLoaderBase(ctx, tracker, loadMode, IgnoreSwiftSourceInfo)
173175
{}
174176

175177
std::error_code findModuleFilesInDirectory(
@@ -197,9 +199,10 @@ class SerializedModuleLoader : public SerializedModuleLoaderBase {
197199
/// into the given ASTContext.
198200
static std::unique_ptr<SerializedModuleLoader>
199201
create(ASTContext &ctx, DependencyTracker *tracker = nullptr,
200-
ModuleLoadingMode loadMode = ModuleLoadingMode::PreferSerialized) {
202+
ModuleLoadingMode loadMode = ModuleLoadingMode::PreferSerialized,
203+
bool IgnoreSwiftSourceInfo = false) {
201204
return std::unique_ptr<SerializedModuleLoader>{
202-
new SerializedModuleLoader(ctx, tracker, loadMode)
205+
new SerializedModuleLoader(ctx, tracker, loadMode, IgnoreSwiftSourceInfo)
203206
};
204207
}
205208
};
@@ -211,8 +214,10 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
211214

212215
MemoryBufferSerializedModuleLoader(ASTContext &ctx,
213216
DependencyTracker *tracker,
214-
ModuleLoadingMode loadMode)
215-
: SerializedModuleLoaderBase(ctx, tracker, loadMode) {}
217+
ModuleLoadingMode loadMode,
218+
bool IgnoreSwiftSourceInfo)
219+
: SerializedModuleLoaderBase(ctx, tracker, loadMode,
220+
IgnoreSwiftSourceInfo) {}
216221

217222
std::error_code findModuleFilesInDirectory(
218223
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
@@ -253,9 +258,11 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
253258
/// into the given ASTContext.
254259
static std::unique_ptr<MemoryBufferSerializedModuleLoader>
255260
create(ASTContext &ctx, DependencyTracker *tracker = nullptr,
256-
ModuleLoadingMode loadMode = ModuleLoadingMode::PreferSerialized) {
261+
ModuleLoadingMode loadMode = ModuleLoadingMode::PreferSerialized,
262+
bool IgnoreSwiftSourceInfo = false) {
257263
return std::unique_ptr<MemoryBufferSerializedModuleLoader>{
258-
new MemoryBufferSerializedModuleLoader(ctx, tracker, loadMode)};
264+
new MemoryBufferSerializedModuleLoader(ctx, tracker, loadMode,
265+
IgnoreSwiftSourceInfo)};
259266
}
260267
};
261268

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ bool ArgsToFrontendOptionsConverter::convert(
110110

111111
Opts.ParseStdlib |= Args.hasArg(OPT_parse_stdlib);
112112

113+
Opts.IgnoreSwiftSourceInfo |= Args.hasArg(OPT_ignore_module_source_info);
113114
computeHelpOptions();
114115

115116
if (const Arg *A = Args.getLastArg(OPT_verify_generic_signatures)) {

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,11 @@ bool CompilerInstance::setUpModuleLoaders() {
363363
return true;
364364
}
365365
}
366-
366+
auto IgnoreSourceInfoFile =
367+
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo;
367368
if (Invocation.getLangOptions().EnableMemoryBufferImporter) {
368369
auto MemoryBufferLoader = MemoryBufferSerializedModuleLoader::create(
369-
*Context, getDependencyTracker());
370+
*Context, getDependencyTracker(), MLM, IgnoreSourceInfoFile);
370371
this->MemoryBufferLoader = MemoryBufferLoader.get();
371372
Context->addModuleLoader(std::move(MemoryBufferLoader));
372373
}
@@ -390,12 +391,13 @@ bool CompilerInstance::setUpModuleLoaders() {
390391
auto PIML = ModuleInterfaceLoader::create(
391392
*Context, ModuleCachePath, PrebuiltModuleCachePath,
392393
getDependencyTracker(), MLM, FEOpts.PreferInterfaceForModules,
393-
FEOpts.RemarkOnRebuildFromModuleInterface);
394+
FEOpts.RemarkOnRebuildFromModuleInterface, IgnoreSourceInfoFile);
394395
Context->addModuleLoader(std::move(PIML));
395396
}
396397

397398
std::unique_ptr<SerializedModuleLoader> SML =
398-
SerializedModuleLoader::create(*Context, getDependencyTracker(), MLM);
399+
SerializedModuleLoader::create(*Context, getDependencyTracker(), MLM,
400+
IgnoreSourceInfoFile);
399401
this->SML = SML.get();
400402
Context->addModuleLoader(std::move(SML));
401403

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ Optional<bool> forEachModuleSearchPath(
104104

105105
// Defined out-of-line so that we can see ~ModuleFile.
106106
SerializedModuleLoaderBase::SerializedModuleLoaderBase(
107-
ASTContext &ctx, DependencyTracker *tracker, ModuleLoadingMode loadMode)
108-
: ModuleLoader(tracker), Ctx(ctx), LoadMode(loadMode) {}
107+
ASTContext &ctx, DependencyTracker *tracker, ModuleLoadingMode loadMode,
108+
bool IgnoreSwiftSourceInfoFile)
109+
: ModuleLoader(tracker), Ctx(ctx), LoadMode(loadMode),
110+
IgnoreSwiftSourceInfoFile(IgnoreSwiftSourceInfoFile) {}
109111

110112
SerializedModuleLoaderBase::~SerializedModuleLoaderBase() = default;
111113
SerializedModuleLoader::~SerializedModuleLoader() = default;
@@ -326,11 +328,12 @@ std::error_code SerializedModuleLoaderBase::openModuleFiles(
326328
FS.getBufferForFile(ModulePath);
327329
if (!ModuleOrErr)
328330
return ModuleOrErr.getError();
329-
330-
// Open .swiftsourceinfo file if it's present.
331-
openModuleSourceInfoFileIfPresent(ModuleID, ModulePath,
332-
ModuleSourceInfoFileName,
333-
ModuleSourceInfoBuffer);
331+
if (!IgnoreSwiftSourceInfoFile) {
332+
// Open .swiftsourceinfo file if it's present.
333+
openModuleSourceInfoFileIfPresent(ModuleID, ModulePath,
334+
ModuleSourceInfoFileName,
335+
ModuleSourceInfoBuffer);
336+
}
334337
auto ModuleDocErr =
335338
openModuleDocFile(ModuleID, ModuleDocPath, ModuleDocBuffer);
336339
if (ModuleDocErr)

test/lit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ if run_vendor == 'apple':
878878
config.target_sdk_name = xcrun_sdk_name
879879
config.target_ld = "%s ld -L%r" % (xcrun_prefix, make_path(test_resource_dir, config.target_sdk_name))
880880
config.target_swift_frontend = (
881-
"%s -frontend %s -sdk %r %s %s " %
881+
"%s -frontend %s -sdk %r %s %s -ignore-module-source-info" %
882882
(config.swiftc, target_options, config.variant_sdk,
883883
config.swift_test_options, config.swift_frontend_test_options))
884884
subst_target_swift_frontend_mock_sdk = (

0 commit comments

Comments
 (0)