Skip to content

Commit 4eb5689

Browse files
authored
Merge pull request #31960 from CodaFi/your-references-are-off-the-chain
Delete ReferencedNameTracker
2 parents e2b554d + acbf927 commit 4eb5689

23 files changed

+300
-437
lines changed

include/swift/AST/Evaluator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ class Evaluator {
262262
void registerRequestFunctions(Zone zone,
263263
ArrayRef<AbstractRequestFunction *> functions);
264264

265+
void enumerateReferencesInFile(
266+
const SourceFile *SF,
267+
evaluator::DependencyRecorder::ReferenceEnumerator f) const {
268+
return recorder.enumerateReferencesInFile(SF, f);
269+
}
270+
265271
/// Retrieve the result produced by evaluating a request that can
266272
/// be cached.
267273
template<typename Request,

include/swift/AST/EvaluatorDependencies.h

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ using DependencySource = llvm::PointerIntPair<SourceFile *, 1, DependencyScope>;
110110
struct DependencyRecorder;
111111

112112
struct DependencyCollector {
113+
friend DependencyRecorder;
114+
113115
struct Reference {
114116
public:
115117
enum class Kind {
@@ -123,38 +125,41 @@ struct DependencyCollector {
123125

124126
NominalTypeDecl *subject;
125127
DeclBaseName name;
128+
bool cascades;
126129

127130
private:
128-
Reference(Kind kind, NominalTypeDecl *subject, DeclBaseName name)
129-
: kind(kind), subject(subject), name(name) {}
131+
Reference(Kind kind, NominalTypeDecl *subject, DeclBaseName name,
132+
bool cascades)
133+
: kind(kind), subject(subject), name(name), cascades(cascades) {}
130134

131135
public:
132136
static Reference empty() {
133137
return {Kind::Empty, llvm::DenseMapInfo<NominalTypeDecl *>::getEmptyKey(),
134-
llvm::DenseMapInfo<DeclBaseName>::getEmptyKey()};
138+
llvm::DenseMapInfo<DeclBaseName>::getEmptyKey(), false};
135139
}
136140

137141
static Reference tombstone() {
138-
return {Kind::Empty,
142+
return {Kind::Tombstone,
139143
llvm::DenseMapInfo<NominalTypeDecl *>::getTombstoneKey(),
140-
llvm::DenseMapInfo<DeclBaseName>::getTombstoneKey()};
144+
llvm::DenseMapInfo<DeclBaseName>::getTombstoneKey(), false};
141145
}
142146

143147
public:
144-
static Reference usedMember(NominalTypeDecl *subject, DeclBaseName name) {
145-
return {Kind::UsedMember, subject, name};
148+
static Reference usedMember(NominalTypeDecl *subject, DeclBaseName name,
149+
bool cascades) {
150+
return {Kind::UsedMember, subject, name, cascades};
146151
}
147152

148-
static Reference potentialMember(NominalTypeDecl *subject) {
149-
return {Kind::PotentialMember, subject, DeclBaseName()};
153+
static Reference potentialMember(NominalTypeDecl *subject, bool cascades) {
154+
return {Kind::PotentialMember, subject, DeclBaseName(), cascades};
150155
}
151156

152-
static Reference topLevel(DeclBaseName name) {
153-
return {Kind::TopLevel, nullptr, name};
157+
static Reference topLevel(DeclBaseName name, bool cascades) {
158+
return {Kind::TopLevel, nullptr, name, cascades};
154159
}
155160

156-
static Reference dynamic(DeclBaseName name) {
157-
return {Kind::Dynamic, nullptr, name};
161+
static Reference dynamic(DeclBaseName name, bool cascades) {
162+
return {Kind::Dynamic, nullptr, name, cascades};
158163
}
159164

160165
public:
@@ -174,8 +179,12 @@ struct DependencyCollector {
174179
};
175180
};
176181

182+
public:
183+
using ReferenceSet = llvm::DenseSet<Reference, Reference::Info>;
184+
185+
private:
177186
DependencyRecorder &parent;
178-
llvm::DenseSet<Reference, Reference::Info> scratch;
187+
ReferenceSet scratch;
179188

180189
public:
181190
explicit DependencyCollector(DependencyRecorder &parent) : parent(parent) {}
@@ -226,11 +235,7 @@ struct DependencyCollector {
226235
/// particular \c DependencyScope during the course of request evaluation.
227236
struct DependencyRecorder {
228237
friend DependencyCollector;
229-
private:
230-
/// A stack of dependency sources in the order they were evaluated.
231-
llvm::SmallVector<evaluator::DependencySource, 8> dependencySources;
232238

233-
public:
234239
enum class Mode {
235240
// Enables the current "status quo" behavior of the dependency collector.
236241
//
@@ -244,14 +249,19 @@ struct DependencyRecorder {
244249
// the primary file being acted upon instead of to the destination file.
245250
ExperimentalPrivateDependencies,
246251
};
247-
Mode mode;
248-
llvm::DenseMap<AnyRequest, llvm::DenseSet<DependencyCollector::Reference,
249-
DependencyCollector::Reference::Info>>
252+
253+
private:
254+
/// A stack of dependency sources in the order they were evaluated.
255+
llvm::SmallVector<evaluator::DependencySource, 8> dependencySources;
256+
llvm::DenseMap<SourceFile *, DependencyCollector::ReferenceSet>
257+
fileReferences;
258+
llvm::DenseMap<AnyRequest, DependencyCollector::ReferenceSet>
250259
requestReferences;
260+
Mode mode;
251261
bool isRecording;
252262

253-
explicit DependencyRecorder(Mode mode)
254-
: mode{mode}, requestReferences{}, isRecording{false} {};
263+
public:
264+
explicit DependencyRecorder(Mode mode) : mode{mode}, isRecording{false} {};
255265

256266
private:
257267
void realize(const DependencyCollector::Reference &ref);
@@ -261,6 +271,12 @@ struct DependencyRecorder {
261271
void record(const llvm::SetVector<swift::ActiveRequest> &stack,
262272
llvm::function_ref<void(DependencyCollector &)> rec);
263273

274+
public:
275+
using ReferenceEnumerator =
276+
llvm::function_ref<void(const DependencyCollector::Reference &)>;
277+
void enumerateReferencesInFile(const SourceFile *SF,
278+
ReferenceEnumerator f) const ;
279+
264280
public:
265281
/// Returns the scope of the current active scope.
266282
///
@@ -323,25 +339,6 @@ struct DependencyRecorder {
323339
return dependencySources.front().getPointer();
324340
}
325341

326-
/// If there is an active dependency source, returns its
327-
/// \c ReferencedNameTracker. Else, returns \c nullptr.
328-
ReferencedNameTracker *getActiveDependencyTracker() const {
329-
SourceFile *source = nullptr;
330-
switch (mode) {
331-
case Mode::StatusQuo:
332-
source = getActiveDependencySourceOrNull();
333-
break;
334-
case Mode::ExperimentalPrivateDependencies:
335-
source = getFirstDependencySourceOrNull();
336-
break;
337-
}
338-
339-
if (!source)
340-
return nullptr;
341-
342-
return source->getRequestBasedReferencedNameTracker();
343-
}
344-
345342
/// Returns \c true if the scope of the current active source cascades.
346343
///
347344
/// If there is no active scope, the result always cascades.

include/swift/AST/Module.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "swift/AST/Identifier.h"
2323
#include "swift/AST/LookupKinds.h"
2424
#include "swift/AST/RawComment.h"
25-
#include "swift/AST/ReferencedNameTracker.h"
2625
#include "swift/AST/Type.h"
2726
#include "swift/Basic/Compiler.h"
2827
#include "swift/Basic/OptionSet.h"
@@ -69,7 +68,6 @@ namespace swift {
6968
class ProtocolConformance;
7069
class ProtocolDecl;
7170
struct PrintOptions;
72-
class ReferencedNameTracker;
7371
class Token;
7472
class TupleType;
7573
class Type;

include/swift/AST/ReferencedNameTracker.h

Lines changed: 0 additions & 83 deletions
This file was deleted.

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ class SourceFile final : public FileUnit {
137137
/// This is set during type checking.
138138
TypeRefinementContext *TRC = nullptr;
139139

140-
/// If non-null, used to track name lookups that happen within this file.
141-
Optional<ReferencedNameTracker> RequestReferencedNames;
142-
143140
/// Either the class marked \@NS/UIApplicationMain or the synthesized FuncDecl
144141
/// that calls main on the type marked @main.
145142
Decl *MainDecl = nullptr;
@@ -439,25 +436,6 @@ class SourceFile final : public FileUnit {
439436

440437
virtual bool walk(ASTWalker &walker) override;
441438

442-
ReferencedNameTracker *getRequestBasedReferencedNameTracker() {
443-
return RequestReferencedNames ? RequestReferencedNames.getPointer() : nullptr;
444-
}
445-
const ReferencedNameTracker *getRequestBasedReferencedNameTracker() const {
446-
return RequestReferencedNames ? RequestReferencedNames.getPointer() : nullptr;
447-
}
448-
449-
/// Creates and installs the referenced name trackers in this source file.
450-
///
451-
/// This entrypoint must be called before incremental compilation can proceed,
452-
/// else reference dependencies will not be registered.
453-
void createReferencedNameTracker();
454-
455-
/// Retrieves the appropriate referenced name tracker instance.
456-
///
457-
/// If incremental dependencies tracking is not enabled or \c createReferencedNameTracker()
458-
/// has not been invoked on this source file, the result is \c nullptr.
459-
const ReferencedNameTracker *getConfiguredReferencedNameTracker() const;
460-
461439
/// The buffer ID for the file that was imported, or None if there
462440
/// is no associated buffer.
463441
Optional<unsigned> getBufferID() const {

include/swift/Frontend/DiagnosticVerifier.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ class SourceFile;
3030

3131
// MARK: - DependencyVerifier
3232

33-
bool verifyDependencies(SourceManager &SM, const DependencyTracker &DT,
34-
ArrayRef<FileUnit *> SFs);
35-
bool verifyDependencies(SourceManager &SM, const DependencyTracker &DT,
36-
ArrayRef<SourceFile *> SFs);
33+
bool verifyDependencies(SourceManager &SM, ArrayRef<FileUnit *> SFs);
34+
bool verifyDependencies(SourceManager &SM, ArrayRef<SourceFile *> SFs);
3735

3836
// MARK: - DiagnosticVerifier
3937
struct ExpectedFixIt;

lib/AST/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ add_swift_host_library(swiftAST STATIC
6767
PrettyStackTrace.cpp
6868
ProtocolConformance.cpp
6969
RawComment.cpp
70-
ReferencedNameTracker.cpp
7170
RequirementEnvironment.cpp
7271
SyntaxASTMap.cpp
7372
SILLayout.cpp

0 commit comments

Comments
 (0)