@@ -123,53 +123,13 @@ 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) {
@@ -259,6 +219,59 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
259
219
return error (Status::MissingDependency);
260
220
}
261
221
222
+ return Status::Valid;
223
+ }
224
+
225
+ Status ModuleFile::associateWithFileContext (FileUnit *file, SourceLoc diagLoc,
226
+ bool recoverFromIncompatibility) {
227
+ PrettyStackTraceModuleFile stackEntry (*this );
228
+
229
+ assert (!hasError () && " error already detected; should not call this" );
230
+ assert (!FileContext && " already associated with an AST module" );
231
+ FileContext = file;
232
+ Status status = Status::Valid;
233
+
234
+ ModuleDecl *M = file->getParentModule ();
235
+ // The real (on-disk) name of the module should be checked here as that's the
236
+ // actually loaded module. In case module aliasing is used when building the main
237
+ // module, e.g. -module-name MyModule -module-alias Foo=Bar, the loaded module
238
+ // that maps to 'Foo' is actually Bar.swiftmodule|.swiftinterface (applies to swift
239
+ // modules only), which is retrieved via M->getRealName(). If no module aliasing is
240
+ // used, M->getRealName() will return the same value as M->getName(), which is 'Foo'.
241
+ if (M->getRealName ().str () != Core->Name ) {
242
+ return error (Status::NameMismatch);
243
+ }
244
+
245
+ ASTContext &ctx = getContext ();
246
+
247
+ llvm::Triple moduleTarget (llvm::Triple::normalize (Core->TargetTriple ));
248
+ if (!areCompatibleArchitectures (moduleTarget, ctx.LangOpts .Target ) ||
249
+ !areCompatibleOSs (moduleTarget, ctx.LangOpts .Target )) {
250
+ status = Status::TargetIncompatible;
251
+ if (!recoverFromIncompatibility)
252
+ return error (status);
253
+ } else if (ctx.LangOpts .EnableTargetOSChecking && !M->isResilient () &&
254
+ isTargetTooNew (moduleTarget, ctx.LangOpts .Target )) {
255
+ status = Status::TargetTooNew;
256
+ if (!recoverFromIncompatibility)
257
+ return error (status);
258
+ }
259
+
260
+ StringRef SDKPath = ctx.SearchPathOpts .getSDKPath ();
261
+ if (SDKPath.empty () ||
262
+ !Core->ModuleInputBuffer ->getBufferIdentifier ().startswith (SDKPath)) {
263
+ for (const auto &searchPath : Core->SearchPaths ) {
264
+ ctx.addSearchPath (
265
+ ctx.SearchPathOpts .SearchPathRemapper .remapPath (searchPath.Path ),
266
+ searchPath.IsFramework ,
267
+ searchPath.IsSystem );
268
+ }
269
+ }
270
+
271
+ Status res = loadDependenciesForFileContext (file, diagLoc,
272
+ /* forTestable=*/ false );
273
+ if (res != Status::Valid) return res;
274
+
262
275
if (Core->Bits .HasEntryPoint ) {
263
276
FileContext->getParentModule ()->registerEntryPointFile (FileContext,
264
277
SourceLoc (),
0 commit comments