Skip to content

Delete ReferencedNameTracker #31960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/swift/AST/Evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ class Evaluator {
void registerRequestFunctions(Zone zone,
ArrayRef<AbstractRequestFunction *> functions);

void enumerateReferencesInFile(
const SourceFile *SF,
evaluator::DependencyRecorder::ReferenceEnumerator f) const {
return recorder.enumerateReferencesInFile(SF, f);
}

/// Retrieve the result produced by evaluating a request that can
/// be cached.
template<typename Request,
Expand Down
81 changes: 39 additions & 42 deletions include/swift/AST/EvaluatorDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ using DependencySource = llvm::PointerIntPair<SourceFile *, 1, DependencyScope>;
struct DependencyRecorder;

struct DependencyCollector {
friend DependencyRecorder;

struct Reference {
public:
enum class Kind {
Expand All @@ -123,38 +125,41 @@ struct DependencyCollector {

NominalTypeDecl *subject;
DeclBaseName name;
bool cascades;

private:
Reference(Kind kind, NominalTypeDecl *subject, DeclBaseName name)
: kind(kind), subject(subject), name(name) {}
Reference(Kind kind, NominalTypeDecl *subject, DeclBaseName name,
bool cascades)
: kind(kind), subject(subject), name(name), cascades(cascades) {}

public:
static Reference empty() {
return {Kind::Empty, llvm::DenseMapInfo<NominalTypeDecl *>::getEmptyKey(),
llvm::DenseMapInfo<DeclBaseName>::getEmptyKey()};
llvm::DenseMapInfo<DeclBaseName>::getEmptyKey(), false};
}

static Reference tombstone() {
return {Kind::Empty,
return {Kind::Tombstone,
llvm::DenseMapInfo<NominalTypeDecl *>::getTombstoneKey(),
llvm::DenseMapInfo<DeclBaseName>::getTombstoneKey()};
llvm::DenseMapInfo<DeclBaseName>::getTombstoneKey(), false};
}

public:
static Reference usedMember(NominalTypeDecl *subject, DeclBaseName name) {
return {Kind::UsedMember, subject, name};
static Reference usedMember(NominalTypeDecl *subject, DeclBaseName name,
bool cascades) {
return {Kind::UsedMember, subject, name, cascades};
}

static Reference potentialMember(NominalTypeDecl *subject) {
return {Kind::PotentialMember, subject, DeclBaseName()};
static Reference potentialMember(NominalTypeDecl *subject, bool cascades) {
return {Kind::PotentialMember, subject, DeclBaseName(), cascades};
}

static Reference topLevel(DeclBaseName name) {
return {Kind::TopLevel, nullptr, name};
static Reference topLevel(DeclBaseName name, bool cascades) {
return {Kind::TopLevel, nullptr, name, cascades};
}

static Reference dynamic(DeclBaseName name) {
return {Kind::Dynamic, nullptr, name};
static Reference dynamic(DeclBaseName name, bool cascades) {
return {Kind::Dynamic, nullptr, name, cascades};
}

public:
Expand All @@ -174,8 +179,12 @@ struct DependencyCollector {
};
};

public:
using ReferenceSet = llvm::DenseSet<Reference, Reference::Info>;

private:
DependencyRecorder &parent;
llvm::DenseSet<Reference, Reference::Info> scratch;
ReferenceSet scratch;

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

public:
enum class Mode {
// Enables the current "status quo" behavior of the dependency collector.
//
Expand All @@ -244,14 +249,19 @@ struct DependencyRecorder {
// the primary file being acted upon instead of to the destination file.
ExperimentalPrivateDependencies,
};
Mode mode;
llvm::DenseMap<AnyRequest, llvm::DenseSet<DependencyCollector::Reference,
DependencyCollector::Reference::Info>>

private:
/// A stack of dependency sources in the order they were evaluated.
llvm::SmallVector<evaluator::DependencySource, 8> dependencySources;
llvm::DenseMap<SourceFile *, DependencyCollector::ReferenceSet>
fileReferences;
llvm::DenseMap<AnyRequest, DependencyCollector::ReferenceSet>
requestReferences;
Mode mode;
bool isRecording;

explicit DependencyRecorder(Mode mode)
: mode{mode}, requestReferences{}, isRecording{false} {};
public:
explicit DependencyRecorder(Mode mode) : mode{mode}, isRecording{false} {};

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

public:
using ReferenceEnumerator =
llvm::function_ref<void(const DependencyCollector::Reference &)>;
void enumerateReferencesInFile(const SourceFile *SF,
ReferenceEnumerator f) const ;

public:
/// Returns the scope of the current active scope.
///
Expand Down Expand Up @@ -323,25 +339,6 @@ struct DependencyRecorder {
return dependencySources.front().getPointer();
}

/// If there is an active dependency source, returns its
/// \c ReferencedNameTracker. Else, returns \c nullptr.
ReferencedNameTracker *getActiveDependencyTracker() const {
SourceFile *source = nullptr;
switch (mode) {
case Mode::StatusQuo:
source = getActiveDependencySourceOrNull();
break;
case Mode::ExperimentalPrivateDependencies:
source = getFirstDependencySourceOrNull();
break;
}

if (!source)
return nullptr;

return source->getRequestBasedReferencedNameTracker();
}

/// Returns \c true if the scope of the current active source cascades.
///
/// If there is no active scope, the result always cascades.
Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "swift/AST/Identifier.h"
#include "swift/AST/LookupKinds.h"
#include "swift/AST/RawComment.h"
#include "swift/AST/ReferencedNameTracker.h"
#include "swift/AST/Type.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/OptionSet.h"
Expand Down Expand Up @@ -69,7 +68,6 @@ namespace swift {
class ProtocolConformance;
class ProtocolDecl;
struct PrintOptions;
class ReferencedNameTracker;
class Token;
class TupleType;
class Type;
Expand Down
83 changes: 0 additions & 83 deletions include/swift/AST/ReferencedNameTracker.h

This file was deleted.

22 changes: 0 additions & 22 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ class SourceFile final : public FileUnit {
/// This is set during type checking.
TypeRefinementContext *TRC = nullptr;

/// If non-null, used to track name lookups that happen within this file.
Optional<ReferencedNameTracker> RequestReferencedNames;

/// Either the class marked \@NS/UIApplicationMain or the synthesized FuncDecl
/// that calls main on the type marked @main.
Decl *MainDecl = nullptr;
Expand Down Expand Up @@ -439,25 +436,6 @@ class SourceFile final : public FileUnit {

virtual bool walk(ASTWalker &walker) override;

ReferencedNameTracker *getRequestBasedReferencedNameTracker() {
return RequestReferencedNames ? RequestReferencedNames.getPointer() : nullptr;
}
const ReferencedNameTracker *getRequestBasedReferencedNameTracker() const {
return RequestReferencedNames ? RequestReferencedNames.getPointer() : nullptr;
}

/// Creates and installs the referenced name trackers in this source file.
///
/// This entrypoint must be called before incremental compilation can proceed,
/// else reference dependencies will not be registered.
void createReferencedNameTracker();

/// Retrieves the appropriate referenced name tracker instance.
///
/// If incremental dependencies tracking is not enabled or \c createReferencedNameTracker()
/// has not been invoked on this source file, the result is \c nullptr.
const ReferencedNameTracker *getConfiguredReferencedNameTracker() const;

/// The buffer ID for the file that was imported, or None if there
/// is no associated buffer.
Optional<unsigned> getBufferID() const {
Expand Down
6 changes: 2 additions & 4 deletions include/swift/Frontend/DiagnosticVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class SourceFile;

// MARK: - DependencyVerifier

bool verifyDependencies(SourceManager &SM, const DependencyTracker &DT,
ArrayRef<FileUnit *> SFs);
bool verifyDependencies(SourceManager &SM, const DependencyTracker &DT,
ArrayRef<SourceFile *> SFs);
bool verifyDependencies(SourceManager &SM, ArrayRef<FileUnit *> SFs);
bool verifyDependencies(SourceManager &SM, ArrayRef<SourceFile *> SFs);

// MARK: - DiagnosticVerifier
struct ExpectedFixIt;
Expand Down
1 change: 0 additions & 1 deletion lib/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ add_swift_host_library(swiftAST STATIC
PrettyStackTrace.cpp
ProtocolConformance.cpp
RawComment.cpp
ReferencedNameTracker.cpp
RequirementEnvironment.cpp
SyntaxASTMap.cpp
SILLayout.cpp
Expand Down
Loading