Skip to content

Commit cff4ddf

Browse files
committed
[NFC] Adopt new ImportPath types and terminology
# Conflicts: # lib/IDE/CodeCompletion.cpp
1 parent 1ed3cae commit cff4ddf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+371
-357
lines changed

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/Evaluator.h"
2121
#include "swift/AST/GenericSignature.h"
2222
#include "swift/AST/Identifier.h"
23+
#include "swift/AST/Import.h"
2324
#include "swift/AST/SearchPathOptions.h"
2425
#include "swift/AST/Type.h"
2526
#include "swift/AST/Types.h"
@@ -859,12 +860,12 @@ class ASTContext final {
859860
///
860861
/// Note that even if this check succeeds, errors may still occur if the
861862
/// module is loaded in full.
862-
bool canImportModule(Located<Identifier> ModulePath);
863+
bool canImportModule(ImportPath::Element ModulePath);
863864

864865
/// \returns a module with a given name that was already loaded. If the
865866
/// module was not loaded, returns nullptr.
866867
ModuleDecl *getLoadedModule(
867-
ArrayRef<Located<Identifier>> ModulePath) const;
868+
ImportPath::Module ModulePath) const;
868869

869870
ModuleDecl *getLoadedModule(Identifier ModuleName) const;
870871

@@ -874,7 +875,7 @@ class ASTContext final {
874875
/// be returned.
875876
///
876877
/// \returns The requested module, or NULL if the module cannot be found.
877-
ModuleDecl *getModule(ArrayRef<Located<Identifier>> ModulePath);
878+
ModuleDecl *getModule(ImportPath::Module ModulePath);
878879

879880
ModuleDecl *getModuleByName(StringRef ModuleName);
880881

include/swift/AST/Decl.h

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,11 +1461,12 @@ static_assert(sizeof(_GenericContext) + sizeof(DeclContext) ==
14611461
/// import Swift
14621462
/// import typealias Swift.Int
14631463
class ImportDecl final : public Decl,
1464-
private llvm::TrailingObjects<ImportDecl, Located<Identifier>> {
1464+
private llvm::TrailingObjects<ImportDecl, ImportPath::Element> {
14651465
friend TrailingObjects;
14661466
friend class Decl;
14671467
public:
1468-
typedef Located<Identifier> AccessPathElement;
1468+
LLVM_ATTRIBUTE_DEPRECATED(typedef ImportPath::Element AccessPathElement,
1469+
"use ImportPath::Element instead");
14691470

14701471
private:
14711472
SourceLoc ImportLoc;
@@ -1475,13 +1476,13 @@ class ImportDecl final : public Decl,
14751476
ModuleDecl *Mod = nullptr;
14761477

14771478
ImportDecl(DeclContext *DC, SourceLoc ImportLoc, ImportKind K,
1478-
SourceLoc KindLoc, ArrayRef<AccessPathElement> Path);
1479+
SourceLoc KindLoc, ImportPath Path);
14791480

14801481
public:
14811482
static ImportDecl *create(ASTContext &C, DeclContext *DC,
14821483
SourceLoc ImportLoc, ImportKind Kind,
14831484
SourceLoc KindLoc,
1484-
ArrayRef<AccessPathElement> Path,
1485+
ImportPath Path,
14851486
ClangNode ClangN = ClangNode());
14861487

14871488
/// Returns the import kind that is most appropriate for \p VD.
@@ -1496,26 +1497,25 @@ class ImportDecl final : public Decl,
14961497
/// cannot be overloaded, returns None.
14971498
static Optional<ImportKind> findBestImportKind(ArrayRef<ValueDecl *> Decls);
14981499

1499-
ArrayRef<AccessPathElement> getFullAccessPath() const {
1500-
return {getTrailingObjects<AccessPathElement>(),
1501-
static_cast<size_t>(Bits.ImportDecl.NumPathElements)};
1500+
ImportKind getImportKind() const {
1501+
return static_cast<ImportKind>(Bits.ImportDecl.ImportKind);
15021502
}
15031503

1504-
ArrayRef<AccessPathElement> getModulePath() const {
1505-
auto result = getFullAccessPath();
1506-
if (getImportKind() != ImportKind::Module)
1507-
result = result.slice(0, result.size()-1);
1508-
return result;
1504+
ImportPath getImportPath() const {
1505+
return ImportPath({ getTrailingObjects<ImportPath::Element>(),
1506+
static_cast<size_t>(Bits.ImportDecl.NumPathElements) });
15091507
}
15101508

1511-
ArrayRef<AccessPathElement> getDeclPath() const {
1512-
if (getImportKind() == ImportKind::Module)
1513-
return {};
1514-
return getFullAccessPath().back();
1509+
LLVM_ATTRIBUTE_DEPRECATED(
1510+
ArrayRef<ImportPath::Element> getFullAccessPath() const,
1511+
"use getImportPath() instead") { return getImportPath().getRaw(); }
1512+
1513+
ImportPath::Module getModulePath() const {
1514+
return getImportPath().getModulePath(getImportKind());
15151515
}
15161516

1517-
ImportKind getImportKind() const {
1518-
return static_cast<ImportKind>(Bits.ImportDecl.ImportKind);
1517+
ImportPath::Access getDeclPath() const {
1518+
return getImportPath().getAccessPath(getImportKind());
15191519
}
15201520

15211521
bool isExported() const {
@@ -1534,9 +1534,11 @@ class ImportDecl final : public Decl,
15341534
}
15351535

15361536
SourceLoc getStartLoc() const { return ImportLoc; }
1537-
SourceLoc getLocFromSource() const { return getFullAccessPath().front().Loc; }
1537+
SourceLoc getLocFromSource() const {
1538+
return getImportPath().getSourceRange().Start;
1539+
}
15381540
SourceRange getSourceRange() const {
1539-
return SourceRange(ImportLoc, getFullAccessPath().back().Loc);
1541+
return SourceRange(ImportLoc, getImportPath().getSourceRange().End);
15401542
}
15411543
SourceLoc getKindLoc() const { return KindLoc; }
15421544

include/swift/AST/FileUnit.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ class FileUnit : public DeclContext {
8282
/// Find ValueDecls in the module and pass them to the given consumer object.
8383
///
8484
/// This does a simple local lookup, not recursively looking through imports.
85-
virtual void lookupVisibleDecls(ModuleDecl::AccessPathTy accessPath,
85+
virtual void lookupVisibleDecls(ImportPath::Access accessPath,
8686
VisibleDeclConsumer &consumer,
8787
NLKind lookupKind) const {}
8888

8989
/// Finds all class members defined in this file.
9090
///
9191
/// This does a simple local lookup, not recursively looking through imports.
92-
virtual void lookupClassMembers(ModuleDecl::AccessPathTy accessPath,
92+
virtual void lookupClassMembers(ImportPath::Access accessPath,
9393
VisibleDeclConsumer &consumer) const {}
9494

9595
/// Finds class members defined in this file with the given name.
9696
///
9797
/// This does a simple local lookup, not recursively looking through imports.
98-
virtual void lookupClassMember(ModuleDecl::AccessPathTy accessPath,
98+
virtual void lookupClassMember(ImportPath::Access accessPath,
9999
DeclName name,
100100
SmallVectorImpl<ValueDecl*> &results) const {}
101101

include/swift/AST/ImportCache.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ class alignas(ModuleDecl::ImportedModule) ImportCache {
108108
llvm::DenseMap<const DeclContext *, ImportSet *> ImportSetForDC;
109109
llvm::DenseMap<std::tuple<const ModuleDecl *,
110110
const DeclContext *>,
111-
ArrayRef<ModuleDecl::AccessPathTy>> VisibilityCache;
111+
ArrayRef<ImportPath::Access>> VisibilityCache;
112112
llvm::DenseMap<std::tuple<const ModuleDecl *,
113113
const ModuleDecl *,
114114
const DeclContext *>,
115-
ArrayRef<ModuleDecl::AccessPathTy>> ShadowCache;
115+
ArrayRef<ImportPath::Access>> ShadowCache;
116116

117-
ModuleDecl::AccessPathTy EmptyAccessPath;
117+
ImportPath::Access EmptyAccessPath;
118118

119-
ArrayRef<ModuleDecl::AccessPathTy> allocateArray(
119+
ArrayRef<ImportPath::Access> allocateArray(
120120
ASTContext &ctx,
121-
SmallVectorImpl<ModuleDecl::AccessPathTy> &results);
121+
SmallVectorImpl<ImportPath::Access> &results);
122122

123123
ImportSet &getImportSet(ASTContext &ctx,
124124
ArrayRef<ModuleDecl::ImportedModule> topLevelImports);
@@ -132,7 +132,7 @@ class alignas(ModuleDecl::ImportedModule) ImportCache {
132132

133133
/// Returns all access paths into 'mod' that are visible from 'dc',
134134
/// including transitively, via re-exports.
135-
ArrayRef<ModuleDecl::AccessPathTy>
135+
ArrayRef<ImportPath::Access>
136136
getAllVisibleAccessPaths(const ModuleDecl *mod, const DeclContext *dc);
137137

138138
bool isImportedBy(const ModuleDecl *mod,
@@ -142,7 +142,7 @@ class alignas(ModuleDecl::ImportedModule) ImportCache {
142142

143143
/// Returns all access paths in 'mod' that are visible from 'dc' if we
144144
/// subtract imports of 'other'.
145-
ArrayRef<ModuleDecl::AccessPathTy>
145+
ArrayRef<ImportPath::Access>
146146
getAllAccessPathsNotShadowedBy(const ModuleDecl *mod,
147147
const ModuleDecl *other,
148148
const DeclContext *dc);

include/swift/AST/Module.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,18 @@ class ModuleDecl : public DeclContext, public TypeDecl {
203203
friend class DirectPrecedenceGroupLookupRequest;
204204

205205
public:
206-
typedef ArrayRef<Located<Identifier>> AccessPathTy;
206+
LLVM_ATTRIBUTE_DEPRECATED(typedef ArrayRef<Located<Identifier>> AccessPathTy,
207+
"use ImportPath types instead");
207208
/// Convenience struct to keep track of a module along with its access path.
208209
struct alignas(uint64_t) ImportedModule {
209210
/// The access path from an import: `import Foo.Bar` -> `Foo.Bar`.
210-
ModuleDecl::AccessPathTy accessPath;
211+
ImportPath::Access accessPath;
211212
/// The actual module corresponding to the import.
212213
///
213214
/// Invariant: The pointer is non-null.
214215
ModuleDecl *importedModule;
215216

216-
ImportedModule(ModuleDecl::AccessPathTy accessPath,
217+
ImportedModule(ImportPath::Access accessPath,
217218
ModuleDecl *importedModule)
218219
: accessPath(accessPath), importedModule(importedModule) {
219220
assert(this->importedModule);
@@ -225,7 +226,10 @@ class ModuleDecl : public DeclContext, public TypeDecl {
225226
}
226227
};
227228

228-
static bool matchesAccessPath(AccessPathTy AccessPath, DeclName Name) {
229+
LLVM_ATTRIBUTE_DEPRECATED(
230+
static bool matchesAccessPath(AccessPathTy AccessPath, DeclName Name),
231+
"use ImportPath::Access::matches() instead")
232+
{
229233
assert(AccessPath.size() <= 1 && "can only refer to top-level decls");
230234

231235
return AccessPath.empty()
@@ -240,8 +244,8 @@ class ModuleDecl : public DeclContext, public TypeDecl {
240244
if (lhs.importedModule != rhs.importedModule)
241245
return std::less<const ModuleDecl *>()(lhs.importedModule,
242246
rhs.importedModule);
243-
if (lhs.accessPath.data() != rhs.accessPath.data())
244-
return std::less<AccessPathTy::iterator>()(lhs.accessPath.begin(),
247+
if (lhs.accessPath.getRaw().data() != rhs.accessPath.getRaw().data())
248+
return std::less<ImportPath::Raw::iterator>()(lhs.accessPath.begin(),
245249
rhs.accessPath.begin());
246250
return lhs.accessPath.size() < rhs.accessPath.size();
247251
}
@@ -583,7 +587,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
583587
/// Find ValueDecls in the module and pass them to the given consumer object.
584588
///
585589
/// This does a simple local lookup, not recursively looking through imports.
586-
void lookupVisibleDecls(AccessPathTy AccessPath,
590+
void lookupVisibleDecls(ImportPath::Access AccessPath,
587591
VisibleDeclConsumer &Consumer,
588592
NLKind LookupKind) const;
589593

@@ -596,13 +600,13 @@ class ModuleDecl : public DeclContext, public TypeDecl {
596600
/// Finds all class members defined in this module.
597601
///
598602
/// This does a simple local lookup, not recursively looking through imports.
599-
void lookupClassMembers(AccessPathTy accessPath,
603+
void lookupClassMembers(ImportPath::Access accessPath,
600604
VisibleDeclConsumer &consumer) const;
601605

602606
/// Finds class members defined in this module with the given name.
603607
///
604608
/// This does a simple local lookup, not recursively looking through imports.
605-
void lookupClassMember(AccessPathTy accessPath,
609+
void lookupClassMember(ImportPath::Access accessPath,
606610
DeclName name,
607611
SmallVectorImpl<ValueDecl*> &results) const;
608612

@@ -757,7 +761,9 @@ class ModuleDecl : public DeclContext, public TypeDecl {
757761
/// identifiers.
758762
///
759763
/// Source locations are ignored here.
760-
static bool isSameAccessPath(AccessPathTy lhs, AccessPathTy rhs);
764+
LLVM_ATTRIBUTE_DEPRECATED(
765+
static bool isSameAccessPath(AccessPathTy lhs, AccessPathTy rhs),
766+
"use ImportPath::Access::isSameAs() instead");
761767

762768
/// Get the path for the file that this module came from, or an empty
763769
/// string if this is not applicable.
@@ -890,7 +896,7 @@ namespace llvm {
890896
static bool isEqual(const ModuleDecl::ImportedModule &lhs,
891897
const ModuleDecl::ImportedModule &rhs) {
892898
return lhs.importedModule == rhs.importedModule &&
893-
ModuleDecl::isSameAccessPath(lhs.accessPath, rhs.accessPath);
899+
lhs.accessPath.isSameAs(rhs.accessPath);
894900
}
895901
};
896902
}

include/swift/AST/ModuleLoader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_AST_MODULE_LOADER_H
1919

2020
#include "swift/AST/Identifier.h"
21+
#include "swift/AST/Import.h"
2122
#include "swift/Basic/LLVM.h"
2223
#include "swift/Basic/Located.h"
2324
#include "swift/Basic/SourceLoc.h"
@@ -143,7 +144,7 @@ class ModuleLoader {
143144
///
144145
/// Note that even if this check succeeds, errors may still occur if the
145146
/// module is loaded in full.
146-
virtual bool canImportModule(Located<Identifier> named) = 0;
147+
virtual bool canImportModule(ImportPath::Element named) = 0;
147148

148149
/// Import a module with the given module path.
149150
///
@@ -155,8 +156,7 @@ class ModuleLoader {
155156
/// \returns the module referenced, if it could be loaded. Otherwise,
156157
/// emits a diagnostic and returns NULL.
157158
virtual
158-
ModuleDecl *loadModule(SourceLoc importLoc,
159-
ArrayRef<Located<Identifier>> path) = 0;
159+
ModuleDecl *loadModule(SourceLoc importLoc, ImportPath::Module path) = 0;
160160

161161
/// Load extensions to the given nominal type.
162162
///

include/swift/AST/ModuleNameLookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void lookupInModule(const DeclContext *moduleOrFile,
6565
/// reexports, observing proper shadowing rules.
6666
void
6767
lookupVisibleDeclsInModule(const DeclContext *moduleOrFile,
68-
ModuleDecl::AccessPathTy accessPath,
68+
ImportPath::Access accessPath,
6969
SmallVectorImpl<ValueDecl *> &decls,
7070
NLKind lookupKind,
7171
ResolutionKind resolutionKind,

include/swift/AST/SourceFile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ class SourceFile final : public FileUnit {
407407
virtual void lookupValue(DeclName name, NLKind lookupKind,
408408
SmallVectorImpl<ValueDecl*> &result) const override;
409409

410-
virtual void lookupVisibleDecls(ModuleDecl::AccessPathTy accessPath,
410+
virtual void lookupVisibleDecls(ImportPath::Access accessPath,
411411
VisibleDeclConsumer &consumer,
412412
NLKind lookupKind) const override;
413413

414-
virtual void lookupClassMembers(ModuleDecl::AccessPathTy accessPath,
414+
virtual void lookupClassMembers(ImportPath::Access accessPath,
415415
VisibleDeclConsumer &consumer) const override;
416416
virtual void
417-
lookupClassMember(ModuleDecl::AccessPathTy accessPath, DeclName name,
417+
lookupClassMember(ImportPath::Access accessPath, DeclName name,
418418
SmallVectorImpl<ValueDecl*> &results) const override;
419419

420420
void lookupObjCMethods(

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class ClangImporter final : public ClangModuleLoader {
186186
///
187187
/// Note that even if this check succeeds, errors may still occur if the
188188
/// module is loaded in full.
189-
virtual bool canImportModule(Located<Identifier> named) override;
189+
virtual bool canImportModule(ImportPath::Element named) override;
190190

191191
/// Import a module with the given module path.
192192
///
@@ -202,7 +202,7 @@ class ClangImporter final : public ClangModuleLoader {
202202
/// emits a diagnostic and returns NULL.
203203
virtual ModuleDecl *loadModule(
204204
SourceLoc importLoc,
205-
ArrayRef<Located<Identifier>> path)
205+
ImportPath::Module path)
206206
override;
207207

208208
/// Determine whether \c overlayDC is within an overlay module for the
@@ -440,7 +440,7 @@ class ClangImporter final : public ClangModuleLoader {
440440
/// Given the path of a Clang module, collect the names of all its submodules.
441441
/// Calling this function does not load the module.
442442
void collectSubModuleNames(
443-
ArrayRef<Located<Identifier>> path,
443+
ImportPath::Module path,
444444
std::vector<std::string> &names) const;
445445

446446
/// Given a Clang module, decide whether this module is imported already.

include/swift/ClangImporter/ClangModule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ class ClangModuleUnit final : public LoadedFile {
7272
lookupNestedType(Identifier name,
7373
const NominalTypeDecl *baseType) const override;
7474

75-
virtual void lookupVisibleDecls(ModuleDecl::AccessPathTy accessPath,
75+
virtual void lookupVisibleDecls(ImportPath::Access accessPath,
7676
VisibleDeclConsumer &consumer,
7777
NLKind lookupKind) const override;
7878

79-
virtual void lookupClassMembers(ModuleDecl::AccessPathTy accessPath,
79+
virtual void lookupClassMembers(ImportPath::Access accessPath,
8080
VisibleDeclConsumer &consumer) const override;
8181

8282
virtual void
83-
lookupClassMember(ModuleDecl::AccessPathTy accessPath, DeclName name,
83+
lookupClassMember(ImportPath::Access accessPath, DeclName name,
8484
SmallVectorImpl<ValueDecl*> &decls) const override;
8585

8686
void lookupObjCMethods(

0 commit comments

Comments
 (0)