@@ -159,25 +159,6 @@ namespace {
159
159
Diag<Identifier> diagID);
160
160
};
161
161
162
- // / Represents an import whose options have been checked and module has been
163
- // / loaded, but its scope (if it's a scoped import) has not been validated
164
- // / and it has not been added to \c SF.
165
- struct BoundImport {
166
- // / The \c UnboundImport we bound to produce this import. Used to avoid
167
- // / duplicating its fields.
168
- UnboundImport unbound;
169
-
170
- // / The \c ImportedModuleDesc that should be added to the source file for
171
- // / this import.
172
- ImportedModuleDesc desc;
173
-
174
- // / The module we bound \c unbound to.
175
- ModuleDecl *module ;
176
-
177
- BoundImport (UnboundImport unbound, ImportedModuleDesc desc,
178
- ModuleDecl *module );
179
- };
180
-
181
162
class NameBinder final : public DeclVisitor<NameBinder> {
182
163
friend DeclVisitor<NameBinder>;
183
164
@@ -188,8 +169,8 @@ namespace {
188
169
// / cross-imports found.
189
170
SmallVector<UnboundImport, 4 > unboundImports;
190
171
191
- // / Imports which still need their scoped imports validated .
192
- SmallVector<BoundImport , 16 > unvalidatedImports ;
172
+ // / The list of fully bound imports.
173
+ SmallVector<ImportedModuleDesc , 16 > boundImports ;
193
174
194
175
// / All imported modules, including by re-exports, and including submodules.
195
176
llvm::DenseSet<ImportedModuleDesc> visibleModules;
@@ -211,9 +192,10 @@ namespace {
211
192
: SF(SF), ctx(SF.getASTContext())
212
193
{ }
213
194
214
- // / Postprocess the imports this NameBinder has bound and collect them into
215
- // / \p imports.
216
- void finishImports (SmallVectorImpl<ImportedModuleDesc> &imports);
195
+ // / Retrieve the finalized imports.
196
+ ArrayRef<ImportedModuleDesc> getFinishedImports () const {
197
+ return boundImports;
198
+ }
217
199
218
200
private:
219
201
// Special behavior for these decls:
@@ -231,11 +213,11 @@ namespace {
231
213
return ctx.Diags .diagnose (std::forward<ArgTypes>(Args)...);
232
214
}
233
215
234
- // / Check a single unbound import, bind it, add it to \c unvalidatedImports ,
216
+ // / Check a single unbound import, bind it, add it to \c boundImports ,
235
217
// / and add its cross-import overlays to \c unboundImports.
236
218
void bindImport (UnboundImport &&I);
237
219
238
- // / Adds \p I and \p M to \c unvalidatedImports and \c visibleModules.
220
+ // / Adds \p I and \p M to \c boundImports and \c visibleModules.
239
221
void addImport (const UnboundImport &I, ModuleDecl *M);
240
222
241
223
// / Adds \p desc and everything it re-exports to \c visibleModules using
@@ -298,13 +280,7 @@ void swift::performNameBinding(SourceFile &SF) {
298
280
for (auto D : SF.getTopLevelDecls ())
299
281
Binder.visit (D);
300
282
301
- // Validate all scoped imports. We defer this until now because a scoped
302
- // import of a cross-import overlay's declaring module can select declarations
303
- // in the overlay, and we don't know all of the overlays we're loading until
304
- // we've bound all imports in the file.
305
- SmallVector<ImportedModuleDesc, 8 > ImportedModules;
306
- Binder.finishImports (ImportedModules);
307
- SF.addImports (ImportedModules);
283
+ SF.addImports (Binder.getFinishedImports ());
308
284
309
285
SF.ASTStage = SourceFile::NameBound;
310
286
verify (SF);
@@ -408,9 +384,8 @@ void NameBinder::bindImport(UnboundImport &&I) {
408
384
409
385
void NameBinder::addImport (const UnboundImport &I, ModuleDecl *M) {
410
386
auto importDesc = I.makeDesc (M);
411
-
412
387
addVisibleModules (importDesc);
413
- unvalidatedImports. emplace_back (I, importDesc, M );
388
+ boundImports. push_back ( importDesc);
414
389
}
415
390
416
391
// ===----------------------------------------------------------------------===//
@@ -655,18 +630,6 @@ void UnboundImport::diagnoseInvalidAttr(DeclAttrKind attrKind,
655
630
// MARK: Scoped imports
656
631
// ===----------------------------------------------------------------------===//
657
632
658
- BoundImport::BoundImport (UnboundImport unbound, ImportedModuleDesc desc,
659
- ModuleDecl *module )
660
- : unbound(unbound), desc(desc), module(module ) {
661
- assert (module && " Can't have an import bound to nothing" );
662
- }
663
-
664
- void NameBinder::finishImports (SmallVectorImpl<ImportedModuleDesc> &imports) {
665
- for (auto &unvalidated : unvalidatedImports) {
666
- imports.push_back (unvalidated.desc );
667
- }
668
- }
669
-
670
633
// / Returns true if a decl with the given \p actual kind can legally be
671
634
// / imported via the given \p expected kind.
672
635
static bool isCompatibleImportKind (ImportKind expected, ImportKind actual) {
0 commit comments