@@ -123,56 +123,19 @@ bool ModuleFile::allowCompilerErrors() const {
123
123
return getContext ().LangOpts .AllowModuleWithCompilerErrors ;
124
124
}
125
125
126
- Status ModuleFile::associateWithFileContext (FileUnit *file, SourceLoc diagLoc,
127
- bool recoverFromIncompatibility) {
128
- PrettyStackTraceModuleFile stackEntry (*this );
129
-
130
- assert (!hasError () && " error already detected; should not call this" );
131
- assert (!FileContext && " already associated with an AST module" );
132
- FileContext = file;
133
- Status status = Status::Valid;
134
-
135
- ModuleDecl *M = file->getParentModule ();
136
- // The real (on-disk) name of the module should be checked here as that's the
137
- // actually loaded module. In case module aliasing is used when building the main
138
- // module, e.g. -module-name MyModule -module-alias Foo=Bar, the loaded module
139
- // that maps to 'Foo' is actually Bar.swiftmodule|.swiftinterface (applies to swift
140
- // modules only), which is retrieved via M->getRealName(). If no module aliasing is
141
- // used, M->getRealName() will return the same value as M->getName(), which is 'Foo'.
142
- if (M->getRealName ().str () != Core->Name ) {
143
- return error (Status::NameMismatch);
144
- }
145
-
126
+ Status
127
+ ModuleFile::loadDependenciesForFileContext (const FileUnit *file,
128
+ SourceLoc diagLoc,
129
+ bool forTestable) {
146
130
ASTContext &ctx = getContext ();
147
-
148
- llvm::Triple moduleTarget (llvm::Triple::normalize (Core->TargetTriple ));
149
- if (!areCompatibleArchitectures (moduleTarget, ctx.LangOpts .Target ) ||
150
- !areCompatibleOSs (moduleTarget, ctx.LangOpts .Target )) {
151
- status = Status::TargetIncompatible;
152
- if (!recoverFromIncompatibility)
153
- return error (status);
154
- } else if (ctx.LangOpts .EnableTargetOSChecking && !M->isResilient () &&
155
- isTargetTooNew (moduleTarget, ctx.LangOpts .Target )) {
156
- status = Status::TargetTooNew;
157
- if (!recoverFromIncompatibility)
158
- return error (status);
159
- }
160
-
161
- StringRef SDKPath = ctx.SearchPathOpts .getSDKPath ();
162
- if (SDKPath.empty () ||
163
- !Core->ModuleInputBuffer ->getBufferIdentifier ().startswith (SDKPath)) {
164
- for (const auto &searchPath : Core->SearchPaths ) {
165
- ctx.addSearchPath (
166
- ctx.SearchPathOpts .SearchPathRemapper .remapPath (searchPath.Path ),
167
- searchPath.IsFramework ,
168
- searchPath.IsSystem );
169
- }
170
- }
171
-
172
131
auto clangImporter = static_cast <ClangImporter *>(ctx.getClangModuleLoader ());
132
+ ModuleDecl *M = file->getParentModule ();
173
133
174
134
bool missingDependency = false ;
175
135
for (auto &dependency : Dependencies) {
136
+ if (forTestable && dependency.isLoaded ())
137
+ continue ;
138
+
176
139
assert (!dependency.isLoaded () && " already loaded?" );
177
140
178
141
if (dependency.isHeader ()) {
@@ -196,7 +159,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
196
159
}
197
160
198
161
ModuleLoadingBehavior transitiveBehavior =
199
- getTransitiveLoadingBehavior (dependency);
162
+ getTransitiveLoadingBehavior (dependency, forTestable );
200
163
201
164
if (ctx.LangOpts .EnableModuleLoadingRemarks ) {
202
165
ctx.Diags .diagnose (diagLoc,
@@ -259,6 +222,59 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
259
222
return error (Status::MissingDependency);
260
223
}
261
224
225
+ return Status::Valid;
226
+ }
227
+
228
+ Status ModuleFile::associateWithFileContext (FileUnit *file, SourceLoc diagLoc,
229
+ bool recoverFromIncompatibility) {
230
+ PrettyStackTraceModuleFile stackEntry (*this );
231
+
232
+ assert (!hasError () && " error already detected; should not call this" );
233
+ assert (!FileContext && " already associated with an AST module" );
234
+ FileContext = file;
235
+ Status status = Status::Valid;
236
+
237
+ ModuleDecl *M = file->getParentModule ();
238
+ // The real (on-disk) name of the module should be checked here as that's the
239
+ // actually loaded module. In case module aliasing is used when building the main
240
+ // module, e.g. -module-name MyModule -module-alias Foo=Bar, the loaded module
241
+ // that maps to 'Foo' is actually Bar.swiftmodule|.swiftinterface (applies to swift
242
+ // modules only), which is retrieved via M->getRealName(). If no module aliasing is
243
+ // used, M->getRealName() will return the same value as M->getName(), which is 'Foo'.
244
+ if (M->getRealName ().str () != Core->Name ) {
245
+ return error (Status::NameMismatch);
246
+ }
247
+
248
+ ASTContext &ctx = getContext ();
249
+
250
+ llvm::Triple moduleTarget (llvm::Triple::normalize (Core->TargetTriple ));
251
+ if (!areCompatibleArchitectures (moduleTarget, ctx.LangOpts .Target ) ||
252
+ !areCompatibleOSs (moduleTarget, ctx.LangOpts .Target )) {
253
+ status = Status::TargetIncompatible;
254
+ if (!recoverFromIncompatibility)
255
+ return error (status);
256
+ } else if (ctx.LangOpts .EnableTargetOSChecking && !M->isResilient () &&
257
+ isTargetTooNew (moduleTarget, ctx.LangOpts .Target )) {
258
+ status = Status::TargetTooNew;
259
+ if (!recoverFromIncompatibility)
260
+ return error (status);
261
+ }
262
+
263
+ StringRef SDKPath = ctx.SearchPathOpts .getSDKPath ();
264
+ if (SDKPath.empty () ||
265
+ !Core->ModuleInputBuffer ->getBufferIdentifier ().startswith (SDKPath)) {
266
+ for (const auto &searchPath : Core->SearchPaths ) {
267
+ ctx.addSearchPath (
268
+ ctx.SearchPathOpts .SearchPathRemapper .remapPath (searchPath.Path ),
269
+ searchPath.IsFramework ,
270
+ searchPath.IsSystem );
271
+ }
272
+ }
273
+
274
+ Status res = loadDependenciesForFileContext (file, diagLoc,
275
+ /* forTestable=*/ false );
276
+ if (res != Status::Valid) return res;
277
+
262
278
if (Core->Bits .HasEntryPoint ) {
263
279
FileContext->getParentModule ()->registerEntryPointFile (FileContext,
264
280
SourceLoc (),
@@ -269,7 +285,8 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
269
285
}
270
286
271
287
ModuleLoadingBehavior
272
- ModuleFile::getTransitiveLoadingBehavior (const Dependency &dependency) const {
288
+ ModuleFile::getTransitiveLoadingBehavior (const Dependency &dependency,
289
+ bool forTestable) const {
273
290
ASTContext &ctx = getContext ();
274
291
ModuleDecl *mod = FileContext->getParentModule ();
275
292
@@ -280,7 +297,8 @@ ModuleFile::getTransitiveLoadingBehavior(const Dependency &dependency) const {
280
297
return Core->getTransitiveLoadingBehavior (dependency.Core ,
281
298
ctx.LangOpts .DebuggerSupport ,
282
299
isPartialModule,
283
- ctx.LangOpts .PackageName );
300
+ ctx.LangOpts .PackageName ,
301
+ forTestable);
284
302
}
285
303
286
304
bool ModuleFile::mayHaveDiagnosticsPointingAtBuffer () const {
0 commit comments