Skip to content

Commit 47b29b6

Browse files
authored
Merge pull request #61649 from xymus/index-swiftinterfaces
[Index] Force indexing of system modules to read only from swiftinterfaces
2 parents 4ce1ebb + 5d59a8f commit 47b29b6

28 files changed

+268
-50
lines changed

include/swift/AST/ASTContext.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ class ASTContext final {
309309
/// The name of the SwiftShims module "SwiftShims".
310310
Identifier SwiftShimsModuleName;
311311

312+
/// Should we globally ignore swiftmodule files adjacent to swiftinterface
313+
/// files?
314+
bool IgnoreAdjacentModules = false;
315+
312316
// Define the set of known identifiers.
313317
#define IDENTIFIER_WITH_NAME(Name, IdStr) Identifier Id_##Name;
314318
#include "swift/AST/KnownIdentifiers.def"
@@ -1144,9 +1148,12 @@ class ASTContext final {
11441148
///
11451149
/// \param ModulePath The module's \c ImportPath which describes
11461150
/// the name of the module being loaded, possibly including submodules.
1147-
1151+
/// \param AllowMemoryCached Should we allow reuse of an already loaded
1152+
/// module or force reloading from disk, defaults to true.
1153+
///
11481154
/// \returns The requested module, or NULL if the module cannot be found.
1149-
ModuleDecl *getModule(ImportPath::Module ModulePath);
1155+
ModuleDecl *
1156+
getModule(ImportPath::Module ModulePath, bool AllowMemoryCached = true);
11501157

11511158
/// Attempts to load the matching overlay module for the given clang
11521159
/// module into this ASTContext.
@@ -1173,7 +1180,10 @@ class ASTContext final {
11731180
/// in this context.
11741181
void addLoadedModule(ModuleDecl *M);
11751182

1176-
public:
1183+
/// Change the behavior of all loaders to ignore swiftmodules next to
1184+
/// swiftinterfaces.
1185+
void setIgnoreAdjacentModules(bool value);
1186+
11771187
/// Retrieve the current generation number, which reflects the
11781188
/// number of times a module import has caused mass invalidation of
11791189
/// lookup tables.

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ ERROR(error_index_failed_status_check,none,
255255
"failed file status check: %0", (StringRef))
256256
ERROR(error_index_inputs_more_than_outputs,none,
257257
"index output filenames do not match input source files", ())
258+
REMARK(remark_indexing_system_module,none,
259+
"indexing system module at %0"
260+
"%select{|; skipping because of a broken swiftinterface}1",
261+
(StringRef, bool))
258262

259263
ERROR(error_wrong_number_of_arguments,none,
260264
"wrong number of '%0' arguments (expected %1, got %2)",

include/swift/AST/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class ModuleDecl
545545
}
546546

547547
/// Returns true if the module was rebuilt from a module interface instead
548-
/// of being build from the full source.
548+
/// of being built from the full source.
549549
bool isBuiltFromInterface() const {
550550
return Bits.ModuleDecl.IsBuiltFromInterface;
551551
}

include/swift/AST/ModuleLoader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,14 @@ class ModuleLoader {
249249
/// \param path A sequence of (identifier, location) pairs that denote
250250
/// the dotted module name to load, e.g., AppKit.NSWindow.
251251
///
252+
/// \param AllowMemoryCache Enables preserving the loaded module in the
253+
/// in-memory cache for the next loading attempt.
254+
///
252255
/// \returns the module referenced, if it could be loaded. Otherwise,
253256
/// emits a diagnostic and returns NULL.
254257
virtual
255-
ModuleDecl *loadModule(SourceLoc importLoc, ImportPath::Module path) = 0;
258+
ModuleDecl *loadModule(SourceLoc importLoc, ImportPath::Module path,
259+
bool AllowMemoryCache = true) = 0;
256260

257261
/// Load extensions to the given nominal type.
258262
///

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ namespace swift {
216216

217217
/// Emit a remark after loading a module.
218218
bool EnableModuleLoadingRemarks = false;
219+
220+
/// Emit a remark when indexing a system module.
221+
bool EnableIndexingSystemModuleRemarks = false;
219222

220223
/// Emit a remark on early exit in explicit interface build
221224
bool EnableSkipExplicitInterfaceModuleBuildRemarks = false;

include/swift/ClangImporter/ClangImporter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,15 @@ class ClangImporter final : public ClangModuleLoader {
222222
/// \param path A sequence of (identifier, location) pairs that denote
223223
/// the dotted module name to load, e.g., AppKit.NSWindow.
224224
///
225+
/// \param AllowMemoryCache Affects only loading serialized Swift modules,
226+
/// this parameter has no effect in the ClangImporter.
227+
///
225228
/// \returns the module referenced, if it could be loaded. Otherwise,
226229
/// emits a diagnostic and returns NULL.
227230
virtual ModuleDecl *loadModule(
228231
SourceLoc importLoc,
229-
ImportPath::Module path)
232+
ImportPath::Module path,
233+
bool AllowMemoryCache = true)
230234
override;
231235

232236
/// Determine whether \c overlayDC is within an overlay module for the

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
439439
StringRef OutPath, StringRef ABIOutputPath,
440440
bool SerializeDependencyHashes,
441441
bool TrackSystemDependencies, ModuleInterfaceLoaderOptions Opts,
442-
RequireOSSAModules_t RequireOSSAModules);
442+
RequireOSSAModules_t RequireOSSAModules,
443+
bool silenceInterfaceDiagnostics);
443444

444445
/// Unconditionally build \p InPath (a swiftinterface file) to \p OutPath (as
445446
/// a swiftmodule file).

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ def remark_loading_module : Flag<["-"], "Rmodule-loading">,
343343
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
344344
HelpText<"Emit a remark and file path of each loaded module">;
345345

346+
def remark_indexing_system_module : Flag<["-"], "Rindexing-system-module">,
347+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
348+
HelpText<"Emit a remark when indexing a system module">;
349+
346350
def remark_skip_explicit_interface_build : Flag<["-"], "Rskip-explicit-interface-build">,
347351
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
348352
HelpText<"Emit a remark if an explicit module interface invocation has an early exit because the expected output is up-to-date">;

include/swift/Sema/SourceLoader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class SourceLoader : public ModuleLoader {
7373
/// returns NULL.
7474
virtual ModuleDecl *
7575
loadModule(SourceLoc importLoc,
76-
ImportPath::Module path) override;
76+
ImportPath::Module path,
77+
bool AllowMemoryCache) override;
7778

7879
/// Load extensions to the given nominal type.
7980
///

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ class SerializedModuleLoaderBase : public ModuleLoader {
185185
/// emits a diagnostic and returns a FailedImportModule object.
186186
virtual ModuleDecl *
187187
loadModule(SourceLoc importLoc,
188-
ImportPath::Module path) override;
188+
ImportPath::Module path,
189+
bool AllowMemoryCache) override;
189190

190191

191192
virtual void loadExtensions(NominalTypeDecl *nominal,
@@ -294,7 +295,8 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
294295

295296
ModuleDecl *
296297
loadModule(SourceLoc importLoc,
297-
ImportPath::Module path) override;
298+
ImportPath::Module path,
299+
bool AllowMemoryCache = true) override;
298300

299301
/// Register a memory buffer that contains the serialized module for the given
300302
/// access path. This API is intended to be used by LLDB to add swiftmodules

0 commit comments

Comments
 (0)