Skip to content

Commit 052ae1f

Browse files
authored
Merge pull request #26818 from slavapestov/misc-cleanups-from-shadowing-change
Misc cleanups from shadowing change
2 parents cac979a + b5b3718 commit 052ae1f

18 files changed

+189
-203
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,6 @@ class ASTContext final {
413413
return true;
414414
}
415415

416-
/// Remove the lazy resolver, if there is one.
417-
///
418-
/// FIXME: We probably don't ever want to do this.
419-
void removeLazyResolver() {
420-
setLazyResolver(nullptr);
421-
}
422-
423416
/// Retrieve the lazy resolver for this context.
424417
LazyResolver *getLazyResolver() const;
425418

include/swift/AST/Module.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,10 @@ class ModuleDecl : public DeclContext, public TypeDecl {
537537
/// \return True if the traversal ran to completion, false if it ended early
538538
/// due to the callback.
539539
bool forAllVisibleModules(AccessPathTy topLevelAccessPath,
540-
llvm::function_ref<bool(ImportedModule)> fn);
540+
llvm::function_ref<bool(ImportedModule)> fn) const;
541541

542542
bool forAllVisibleModules(AccessPathTy topLevelAccessPath,
543-
llvm::function_ref<void(ImportedModule)> fn) {
543+
llvm::function_ref<void(ImportedModule)> fn) const {
544544
return forAllVisibleModules(topLevelAccessPath,
545545
[=](const ImportedModule &import) -> bool {
546546
fn(import);
@@ -550,7 +550,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
550550

551551
template <typename Fn>
552552
bool forAllVisibleModules(AccessPathTy topLevelAccessPath,
553-
Fn &&fn) {
553+
Fn &&fn) const {
554554
using RetTy = typename std::result_of<Fn(ImportedModule)>::type;
555555
llvm::function_ref<RetTy(ImportedModule)> wrapped{std::forward<Fn>(fn)};
556556
return forAllVisibleModules(topLevelAccessPath, wrapped);
@@ -562,7 +562,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
562562

563563
/// Generate the list of libraries needed to link this module, based on its
564564
/// imports.
565-
void collectLinkLibraries(LinkLibraryCallback callback);
565+
void collectLinkLibraries(LinkLibraryCallback callback) const;
566566

567567
/// Returns true if the two access paths contain the same chain of
568568
/// identifiers.
@@ -826,18 +826,20 @@ class FileUnit : public DeclContext {
826826
/// \return True if the traversal ran to completion, false if it ended early
827827
/// due to the callback.
828828
bool
829-
forAllVisibleModules(llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn);
829+
forAllVisibleModules(
830+
llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn) const;
830831

831832
bool
832-
forAllVisibleModules(llvm::function_ref<void(ModuleDecl::ImportedModule)> fn) {
833+
forAllVisibleModules(
834+
llvm::function_ref<void(ModuleDecl::ImportedModule)> fn) const {
833835
return forAllVisibleModules([=](ModuleDecl::ImportedModule import) -> bool {
834836
fn(import);
835837
return true;
836838
});
837839
}
838840

839841
template <typename Fn>
840-
bool forAllVisibleModules(Fn &&fn) {
842+
bool forAllVisibleModules(Fn &&fn) const {
841843
using RetTy = typename std::result_of<Fn(ModuleDecl::ImportedModule)>::type;
842844
llvm::function_ref<RetTy(ModuleDecl::ImportedModule)> wrapped{
843845
std::forward<Fn>(fn)

include/swift/AST/ModuleNameLookup.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//===--- ModuleNameLookup.h - Name lookup within a module -------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines interfaces for performing top-level name lookup into a
14+
// set of imported modules.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_AST_MODULE_NAME_LOOKUP_H
19+
#define SWIFT_AST_MODULE_NAME_LOOKUP_H
20+
21+
#include "llvm/ADT/SmallVector.h"
22+
#include "swift/AST/Identifier.h"
23+
#include "swift/AST/Module.h"
24+
#include "swift/Basic/SourceLoc.h"
25+
26+
namespace swift {
27+
class ValueDecl;
28+
29+
namespace namelookup {
30+
31+
enum class ResolutionKind {
32+
/// Lookup can match any number of decls, as long as they are all
33+
/// overloadable.
34+
///
35+
/// If non-overloadable decls are returned, this indicates ambiguous lookup.
36+
Overloadable,
37+
38+
/// Lookup should match a single decl.
39+
Exact,
40+
41+
/// Lookup should match a single decl that declares a type.
42+
TypesOnly
43+
};
44+
45+
/// Performs a lookup into the given module and, if necessary, its
46+
/// reexports, observing proper shadowing rules.
47+
///
48+
/// \param module The module that will contain the name.
49+
/// \param accessPath The import scope on \p module.
50+
/// \param name The name to look up.
51+
/// \param[out] decls Any found decls will be added to this vector.
52+
/// \param lookupKind Whether this lookup is qualified or unqualified.
53+
/// \param resolutionKind What sort of decl is expected.
54+
/// \param moduleScopeContext The top-level context from which the lookup is
55+
/// being performed, for checking access. This must be either a
56+
/// FileUnit or a Module.
57+
/// \param extraImports Private imports to include in this search.
58+
void lookupInModule(ModuleDecl *module, ModuleDecl::AccessPathTy accessPath,
59+
DeclName name, SmallVectorImpl<ValueDecl *> &decls,
60+
NLKind lookupKind, ResolutionKind resolutionKind,
61+
const DeclContext *moduleScopeContext,
62+
ArrayRef<ModuleDecl::ImportedModule> extraImports = {});
63+
64+
template <typename Fn>
65+
void forAllVisibleModules(const DeclContext *DC, const Fn &fn) {
66+
DeclContext *moduleScope = DC->getModuleScopeContext();
67+
if (auto file = dyn_cast<FileUnit>(moduleScope))
68+
file->forAllVisibleModules(fn);
69+
else
70+
cast<ModuleDecl>(moduleScope)
71+
->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn);
72+
}
73+
74+
/// Performs a qualified lookup into the given module and, if necessary, its
75+
/// reexports, observing proper shadowing rules.
76+
void
77+
lookupVisibleDeclsInModule(ModuleDecl *M, ModuleDecl::AccessPathTy accessPath,
78+
SmallVectorImpl<ValueDecl *> &decls,
79+
NLKind lookupKind,
80+
ResolutionKind resolutionKind,
81+
const DeclContext *moduleScopeContext,
82+
ArrayRef<ModuleDecl::ImportedModule> extraImports = {});
83+
84+
} // end namespace namelookup
85+
86+
} // end namespace swift
87+
88+
#endif

include/swift/AST/NameLookup.h

Lines changed: 71 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -27,80 +27,77 @@
2727
#include "swift/Basic/SourceLoc.h"
2828

2929
namespace swift {
30-
class ASTContext;
31-
class DeclContext;
32-
class DeclName;
33-
class Expr;
34-
class GenericSignatureBuilder;
35-
class TupleType;
36-
class Type;
37-
class TypeDecl;
38-
class ValueDecl;
39-
struct SelfBounds;
40-
class NominalTypeDecl;
41-
42-
namespace ast_scope {
43-
class ASTSourceFileScope;
44-
class ASTScopeImpl;
45-
} // namespace ast_scope
46-
47-
/// LookupResultEntry - One result of unqualified lookup.
48-
struct LookupResultEntry {
49-
private:
50-
/// The declaration context through which we found \c Value. For instance,
51-
/// \code
52-
/// class BaseClass {
53-
/// func foo() {}
54-
/// }
55-
///
56-
/// class DerivedClass : BaseClass {
57-
/// func bar() {}
58-
/// }
59-
/// \endcode
60-
///
61-
/// When finding \c foo() from the body of \c DerivedClass, \c BaseDC is \c
62-
/// DerivedClass.
63-
///
64-
/// Another example:
65-
/// \code
66-
/// class BaseClass {
67-
/// func bar() {}
68-
/// func foo() {}
69-
/// }
70-
/// \endcode
71-
///
72-
/// When finding \c bar() from the function body of \c foo(), \c BaseDC is
73-
/// the method \c foo().
74-
///
75-
/// \c BaseDC will be the method if \c self is needed for the lookup,
76-
/// and will be the type if not.
77-
/// In other words: If \c baseDC is a method, it means you found an instance
78-
/// member and you should add an implicit 'self.' (Each method has its own
79-
/// implicit self decl.) There's one other kind of non-method context that
80-
/// has a 'self.' -- a lazy property initializer, which unlike a non-lazy
81-
/// property can reference \c self) Hence: \code
82-
/// class Outer {
83-
///   static func s()
84-
///   func i()
85-
/// class Inner {
86-
///   static func ss()
87-
///   func ii() {
88-
///   func F() {
89-
///   ii() // OK! implicitly self.ii; BaseDC is the method
90-
///   s()  // OK! s() is defined in an outer type; BaseDC is the type
91-
///   ss() // error: must write /Inner.ss() here since its static
92-
///   i() // error: there's no outer 'self.'
93-
///   }
94-
///   }
95-
/// \endcode
96-
///
97-
/// To sum up: The distinction is whether you need to know the run-time
98-
/// value of \c self. It might be clearer if \code baseDC was always a type,
99-
/// and there was an additional \c ParamDecl field in \c LookupResult which
100-
/// would store the implicit self, if any. \c BaseDC is always one of your
101-
/// outer DCs. if you're inside a type it should never be an extension of
102-
/// that type. And if you're inside an extension it will always be an
103-
/// extension (if it found something at that level).
30+
class ASTContext;
31+
class DeclName;
32+
class GenericSignatureBuilder;
33+
class Type;
34+
class TypeDecl;
35+
class ValueDecl;
36+
struct SelfBounds;
37+
class NominalTypeDecl;
38+
39+
namespace ast_scope {
40+
class ASTSourceFileScope;
41+
class ASTScopeImpl;
42+
} // namespace ast_scope
43+
44+
/// LookupResultEntry - One result of unqualified lookup.
45+
struct LookupResultEntry {
46+
private:
47+
/// The declaration context through which we found \c Value. For instance,
48+
/// \code
49+
/// class BaseClass {
50+
/// func foo() {}
51+
/// }
52+
///
53+
/// class DerivedClass : BaseClass {
54+
/// func bar() {}
55+
/// }
56+
/// \endcode
57+
///
58+
/// When finding \c foo() from the body of \c DerivedClass, \c BaseDC is \c
59+
/// DerivedClass.
60+
///
61+
/// Another example:
62+
/// \code
63+
/// class BaseClass {
64+
/// func bar() {}
65+
/// func foo() {}
66+
/// }
67+
/// \endcode
68+
///
69+
/// When finding \c bar() from the function body of \c foo(), \c BaseDC is
70+
/// the method \c foo().
71+
///
72+
/// \c BaseDC will be the method if \c self is needed for the lookup,
73+
/// and will be the type if not.
74+
/// In other words: If \c baseDC is a method, it means you found an instance
75+
/// member and you should add an implicit 'self.' (Each method has its own
76+
/// implicit self decl.) There's one other kind of non-method context that
77+
/// has a 'self.' -- a lazy property initializer, which unlike a non-lazy
78+
/// property can reference \c self) Hence: \code
79+
/// class Outer {
80+
///   static func s()
81+
///   func i()
82+
/// class Inner {
83+
///   static func ss()
84+
///   func ii() {
85+
///   func F() {
86+
///   ii() // OK! implicitly self.ii; BaseDC is the method
87+
///   s()  // OK! s() is defined in an outer type; BaseDC is the type
88+
///   ss() // error: must write /Inner.ss() here since its static
89+
///   i() // error: there's no outer 'self.'
90+
///   }
91+
///   }
92+
/// \endcode
93+
///
94+
/// To sum up: The distinction is whether you need to know the run-time
95+
/// value of \c self. It might be clearer if \code baseDC was always a type,
96+
/// and there was an additional \c ParamDecl field in \c LookupResult which
97+
/// would store the implicit self, if any. \c BaseDC is always one of your
98+
/// outer DCs. if you're inside a type it should never be an extension of
99+
/// that type. And if you're inside an extension it will always be an
100+
/// extension (if it found something at that level).
104101
DeclContext *BaseDC;
105102

106103
/// The declaration corresponds to the given name; i.e. the decl we are
@@ -407,48 +404,6 @@ void lookupVisibleMemberDecls(VisibleDeclConsumer &Consumer,
407404
GenericSignatureBuilder *GSB = nullptr);
408405

409406
namespace namelookup {
410-
enum class ResolutionKind {
411-
/// Lookup can match any number of decls, as long as they are all
412-
/// overloadable.
413-
///
414-
/// If non-overloadable decls are returned, this indicates ambiguous lookup.
415-
Overloadable,
416-
417-
/// Lookup should match a single decl.
418-
Exact,
419-
420-
/// Lookup should match a single decl that declares a type.
421-
TypesOnly
422-
};
423-
424-
/// Performs a lookup into the given module and, if necessary, its
425-
/// reexports, observing proper shadowing rules.
426-
///
427-
/// \param module The module that will contain the name.
428-
/// \param accessPath The import scope on \p module.
429-
/// \param name The name to look up.
430-
/// \param[out] decls Any found decls will be added to this vector.
431-
/// \param lookupKind Whether this lookup is qualified or unqualified.
432-
/// \param resolutionKind What sort of decl is expected.
433-
/// \param moduleScopeContext The top-level context from which the lookup is
434-
/// being performed, for checking access. This must be either a
435-
/// FileUnit or a Module.
436-
/// \param extraImports Private imports to include in this search.
437-
void lookupInModule(ModuleDecl *module, ModuleDecl::AccessPathTy accessPath,
438-
DeclName name, SmallVectorImpl<ValueDecl *> &decls,
439-
NLKind lookupKind, ResolutionKind resolutionKind,
440-
const DeclContext *moduleScopeContext,
441-
ArrayRef<ModuleDecl::ImportedModule> extraImports = {});
442-
443-
template <typename Fn>
444-
void forAllVisibleModules(const DeclContext *DC, const Fn &fn) {
445-
DeclContext *moduleScope = DC->getModuleScopeContext();
446-
if (auto file = dyn_cast<FileUnit>(moduleScope))
447-
file->forAllVisibleModules(fn);
448-
else
449-
cast<ModuleDecl>(moduleScope)
450-
->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn);
451-
}
452407

453408
/// Once name lookup has gathered a set of results, perform any necessary
454409
/// steps to prune the result set before returning it to the caller.
@@ -495,16 +450,6 @@ SelfBounds getSelfBoundsFromWhereClause(
495450

496451
namespace namelookup {
497452

498-
/// Performs a qualified lookup into the given module and, if necessary, its
499-
/// reexports, observing proper shadowing rules.
500-
void
501-
lookupVisibleDeclsInModule(ModuleDecl *M, ModuleDecl::AccessPathTy accessPath,
502-
SmallVectorImpl<ValueDecl *> &decls,
503-
NLKind lookupKind,
504-
ResolutionKind resolutionKind,
505-
const DeclContext *moduleScopeContext,
506-
ArrayRef<ModuleDecl::ImportedModule> extraImports = {});
507-
508453
/// Searches through statements and patterns for local variable declarations.
509454
class FindLocalVal : public StmtVisitor<FindLocalVal> {
510455
friend class ASTVisitor<FindLocalVal>;

include/swift/ClangImporter/ClangImporter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,6 @@ class ClangImporter final : public ClangModuleLoader {
331331

332332
void verifyAllModules() override;
333333

334-
void setTypeResolver(LazyResolver &resolver);
335-
void clearTypeResolver();
336-
337334
clang::TargetInfo &getTargetInfo() const;
338335
clang::ASTContext &getClangASTContext() const override;
339336
clang::Preprocessor &getClangPreprocessor() const override;

0 commit comments

Comments
 (0)