Skip to content

Commit 0c785aa

Browse files
committed
[NameBinding] Remove BoundImport
This was only required to represent an import that hadn't yet had its scope validated. Now that the validation has been requestified, we can directly record the resulting `ImportedModuleDesc` instead.
1 parent ab9b6d7 commit 0c785aa

File tree

1 file changed

+10
-47
lines changed

1 file changed

+10
-47
lines changed

lib/Sema/NameBinding.cpp

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,6 @@ namespace {
159159
Diag<Identifier> diagID);
160160
};
161161

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-
181162
class NameBinder final : public DeclVisitor<NameBinder> {
182163
friend DeclVisitor<NameBinder>;
183164

@@ -188,8 +169,8 @@ namespace {
188169
/// cross-imports found.
189170
SmallVector<UnboundImport, 4> unboundImports;
190171

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;
193174

194175
/// All imported modules, including by re-exports, and including submodules.
195176
llvm::DenseSet<ImportedModuleDesc> visibleModules;
@@ -211,9 +192,10 @@ namespace {
211192
: SF(SF), ctx(SF.getASTContext())
212193
{ }
213194

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+
}
217199

218200
private:
219201
// Special behavior for these decls:
@@ -231,11 +213,11 @@ namespace {
231213
return ctx.Diags.diagnose(std::forward<ArgTypes>(Args)...);
232214
}
233215

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,
235217
/// and add its cross-import overlays to \c unboundImports.
236218
void bindImport(UnboundImport &&I);
237219

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.
239221
void addImport(const UnboundImport &I, ModuleDecl *M);
240222

241223
/// Adds \p desc and everything it re-exports to \c visibleModules using
@@ -298,13 +280,7 @@ void swift::performNameBinding(SourceFile &SF) {
298280
for (auto D : SF.getTopLevelDecls())
299281
Binder.visit(D);
300282

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());
308284

309285
SF.ASTStage = SourceFile::NameBound;
310286
verify(SF);
@@ -408,9 +384,8 @@ void NameBinder::bindImport(UnboundImport &&I) {
408384

409385
void NameBinder::addImport(const UnboundImport &I, ModuleDecl *M) {
410386
auto importDesc = I.makeDesc(M);
411-
412387
addVisibleModules(importDesc);
413-
unvalidatedImports.emplace_back(I, importDesc, M);
388+
boundImports.push_back(importDesc);
414389
}
415390

416391
//===----------------------------------------------------------------------===//
@@ -655,18 +630,6 @@ void UnboundImport::diagnoseInvalidAttr(DeclAttrKind attrKind,
655630
// MARK: Scoped imports
656631
//===----------------------------------------------------------------------===//
657632

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-
670633
/// Returns true if a decl with the given \p actual kind can legally be
671634
/// imported via the given \p expected kind.
672635
static bool isCompatibleImportKind(ImportKind expected, ImportKind actual) {

0 commit comments

Comments
 (0)