mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[NFC] Delete ReferencedNameTracker
This commit is contained in:
@@ -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"
|
||||
@@ -69,7 +68,6 @@ namespace swift {
|
||||
class ProtocolConformance;
|
||||
class ProtocolDecl;
|
||||
struct PrintOptions;
|
||||
class ReferencedNameTracker;
|
||||
class Token;
|
||||
class TupleType;
|
||||
class Type;
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
//===--- ReferencedNameTracker.h - Records looked-up names ------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_REFERENCEDNAMETRACKER_H
|
||||
#define SWIFT_REFERENCEDNAMETRACKER_H
|
||||
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/Basic/ReferenceDependencyKeys.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace swift {
|
||||
|
||||
class NominalTypeDecl;
|
||||
class DependencyTracker;
|
||||
|
||||
class ReferencedNameTracker {
|
||||
public:
|
||||
using EnumerateUsedDecl = function_ref<void(
|
||||
fine_grained_dependencies::NodeKind kind, StringRef context,
|
||||
StringRef name, bool isCascadingUse)>;
|
||||
|
||||
private:
|
||||
#define TRACKED_SET(KIND, NAME) \
|
||||
private: \
|
||||
llvm::DenseMap<KIND, bool> NAME##s; \
|
||||
\
|
||||
public: \
|
||||
void add##NAME(KIND new##NAME, bool isCascadingUse) { \
|
||||
NAME##s[new##NAME] |= isCascadingUse; \
|
||||
} \
|
||||
/* make private once ReferenceDependencies.cpp is gone */ \
|
||||
const decltype(NAME##s) &get##NAME##s() const { return NAME##s; }
|
||||
|
||||
TRACKED_SET(DeclBaseName, TopLevelName)
|
||||
TRACKED_SET(DeclBaseName, DynamicLookupName)
|
||||
|
||||
using MemberPair = std::pair<const NominalTypeDecl *, DeclBaseName>;
|
||||
TRACKED_SET(MemberPair, UsedMember)
|
||||
|
||||
#undef TRACKED_SET
|
||||
public:
|
||||
// Pushing the DependencyTracker through unifies external dependency
|
||||
// enumeration.
|
||||
void enumerateAllUses(bool includeIntrafileDeps,
|
||||
const DependencyTracker &depTracker,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const;
|
||||
|
||||
private:
|
||||
template <fine_grained_dependencies::NodeKind kind>
|
||||
void enumerateSimpleUses(llvm::DenseMap<DeclBaseName, bool> cascadesByName,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const;
|
||||
|
||||
void enumerateExternalUses(const DependencyTracker &,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const;
|
||||
|
||||
void enumerateCompoundUses(bool includeIntrafileDeps,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const;
|
||||
|
||||
std::unordered_set<std::string>
|
||||
computeHoldersOfCascadingMembers(bool includeIntrafileDeps) const;
|
||||
|
||||
void enumerateNominalUses(
|
||||
bool includeIntrafileDeps,
|
||||
const std::unordered_set<std::string> &&holdersOfCascadingMembers,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const;
|
||||
|
||||
void enumerateMemberUses(EnumerateUsedDecl enumerateUsedDecl) const;
|
||||
};
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif // LLVM_SWIFT_REFERENCEDNAMETRACKER_H
|
||||
@@ -137,9 +137,6 @@ private:
|
||||
/// 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;
|
||||
@@ -439,25 +436,6 @@ public:
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -67,7 +67,6 @@ add_swift_host_library(swiftAST STATIC
|
||||
PrettyStackTrace.cpp
|
||||
ProtocolConformance.cpp
|
||||
RawComment.cpp
|
||||
ReferencedNameTracker.cpp
|
||||
RequirementEnvironment.cpp
|
||||
SyntaxASTMap.cpp
|
||||
SILLayout.cpp
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include "swift/AST/PrettyStackTrace.h"
|
||||
#include "swift/AST/PrintOptions.h"
|
||||
#include "swift/AST/ProtocolConformance.h"
|
||||
#include "swift/AST/ReferencedNameTracker.h"
|
||||
#include "swift/AST/SourceFile.h"
|
||||
#include "swift/AST/SynthesizedFileUnit.h"
|
||||
#include "swift/AST/TypeCheckRequests.h"
|
||||
@@ -2638,16 +2637,6 @@ void SourceFile::setTypeRefinementContext(TypeRefinementContext *Root) {
|
||||
TRC = Root;
|
||||
}
|
||||
|
||||
void SourceFile::createReferencedNameTracker() {
|
||||
assert(!RequestReferencedNames && "This file already has a name tracker.");
|
||||
RequestReferencedNames.emplace(ReferencedNameTracker());
|
||||
}
|
||||
|
||||
const ReferencedNameTracker *
|
||||
SourceFile::getConfiguredReferencedNameTracker() const {
|
||||
return getRequestBasedReferencedNameTracker();
|
||||
}
|
||||
|
||||
ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {
|
||||
for (auto *vd : UnvalidatedDeclsWithOpaqueReturnTypes.takeVector()) {
|
||||
if (auto opaqueDecl = vd->getOpaqueResultTypeDecl()) {
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "swift/AST/ModuleNameLookup.h"
|
||||
#include "swift/AST/NameLookupRequests.h"
|
||||
#include "swift/AST/ParameterList.h"
|
||||
#include "swift/AST/ReferencedNameTracker.h"
|
||||
#include "swift/AST/SourceFile.h"
|
||||
#include "swift/Basic/Debug.h"
|
||||
#include "swift/Basic/SourceManager.h"
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
//===---------------------------- ReferencedNameTracker.cpp ---------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
///
|
||||
/// This file implements unqualified lookup, which searches for an identifier
|
||||
/// from a given context.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/ReferencedNameTracker.h"
|
||||
|
||||
#include "swift/AST/ASTContext.h"
|
||||
#include "swift/AST/ASTMangler.h"
|
||||
#include "swift/AST/Decl.h"
|
||||
#include "swift/AST/DiagnosticEngine.h"
|
||||
#include "swift/AST/DiagnosticsFrontend.h"
|
||||
#include "swift/AST/FineGrainedDependencies.h"
|
||||
#include "swift/AST/Module.h"
|
||||
#include "swift/AST/ModuleLoader.h"
|
||||
#include "swift/AST/NameLookup.h"
|
||||
#include "swift/AST/SourceFile.h"
|
||||
#include "swift/AST/Types.h"
|
||||
#include "swift/Basic/FileSystem.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Basic/ReferenceDependencyKeys.h"
|
||||
#include "swift/Demangling/Demangle.h"
|
||||
#include "swift/Frontend/FrontendOptions.h"
|
||||
#include "llvm/ADT/MapVector.h"
|
||||
#include "llvm/ADT/SetVector.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
|
||||
using namespace swift;
|
||||
using NodeKind = fine_grained_dependencies::NodeKind;
|
||||
using EnumerateUsedDecl = ReferencedNameTracker::EnumerateUsedDecl;
|
||||
using DependencyKey = fine_grained_dependencies::DependencyKey;
|
||||
|
||||
void ReferencedNameTracker::enumerateAllUses(
|
||||
bool includeIntrafileDeps, const DependencyTracker &depTracker,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const {
|
||||
enumerateSimpleUses<NodeKind::topLevel>(getTopLevelNames(),
|
||||
enumerateUsedDecl);
|
||||
enumerateSimpleUses<NodeKind::dynamicLookup>(getDynamicLookupNames(),
|
||||
enumerateUsedDecl);
|
||||
enumerateExternalUses(depTracker, enumerateUsedDecl);
|
||||
enumerateCompoundUses(includeIntrafileDeps, enumerateUsedDecl);
|
||||
}
|
||||
|
||||
template <NodeKind kind>
|
||||
void ReferencedNameTracker::enumerateSimpleUses(
|
||||
llvm::DenseMap<DeclBaseName, bool> cascadesByName,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const {
|
||||
for (const auto &p : cascadesByName)
|
||||
enumerateUsedDecl(kind, "", p.getFirst().userFacingName(), p.getSecond());
|
||||
}
|
||||
|
||||
void ReferencedNameTracker::enumerateExternalUses(
|
||||
const DependencyTracker &depTracker,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const {
|
||||
// external dependencies always cascade
|
||||
for (StringRef s : depTracker.getDependencies())
|
||||
enumerateUsedDecl(NodeKind::externalDepend, "", s, true);
|
||||
}
|
||||
|
||||
void ReferencedNameTracker::enumerateCompoundUses(
|
||||
bool includeIntrafileDeps, EnumerateUsedDecl enumerateUsedDecl) const {
|
||||
enumerateNominalUses(
|
||||
includeIntrafileDeps,
|
||||
std::move(computeHoldersOfCascadingMembers(includeIntrafileDeps)),
|
||||
enumerateUsedDecl);
|
||||
enumerateMemberUses(enumerateUsedDecl);
|
||||
}
|
||||
|
||||
std::unordered_set<std::string>
|
||||
ReferencedNameTracker::computeHoldersOfCascadingMembers(
|
||||
const bool includeIntrafileDeps) const {
|
||||
std::unordered_set<std::string> holdersOfCascadingMembers;
|
||||
for (const auto &p : getUsedMembers()) {
|
||||
{
|
||||
bool isPrivate = p.getFirst().first->isPrivateToEnclosingFile();
|
||||
if (isPrivate && !includeIntrafileDeps)
|
||||
continue;
|
||||
}
|
||||
std::string context =
|
||||
DependencyKey::computeContextForProvidedEntity<NodeKind::nominal>(
|
||||
p.getFirst().first);
|
||||
bool isCascading = p.getSecond();
|
||||
if (isCascading)
|
||||
holdersOfCascadingMembers.insert(context);
|
||||
}
|
||||
return holdersOfCascadingMembers;
|
||||
}
|
||||
|
||||
void ReferencedNameTracker::enumerateNominalUses(
|
||||
const bool includeIntrafileDeps,
|
||||
const std::unordered_set<std::string> &&holdersOfCascadingMembers,
|
||||
EnumerateUsedDecl enumerateUsedDecl) const {
|
||||
for (const auto &p : getUsedMembers()) {
|
||||
{
|
||||
bool isPrivate = p.getFirst().first->isPrivateToEnclosingFile();
|
||||
if (isPrivate && !includeIntrafileDeps)
|
||||
continue;
|
||||
}
|
||||
|
||||
const NominalTypeDecl *nominal = p.getFirst().first;
|
||||
|
||||
std::string context =
|
||||
DependencyKey::computeContextForProvidedEntity<NodeKind::nominal>(
|
||||
nominal);
|
||||
const bool isCascadingUse = holdersOfCascadingMembers.count(context) != 0;
|
||||
enumerateUsedDecl(NodeKind::nominal, context, "", isCascadingUse);
|
||||
}
|
||||
}
|
||||
|
||||
void ReferencedNameTracker::enumerateMemberUses(
|
||||
EnumerateUsedDecl enumerateUsedDecl) const {
|
||||
for (const auto &p : getUsedMembers()) {
|
||||
const NominalTypeDecl *nominal = p.getFirst().first;
|
||||
const auto rawName = p.getFirst().second;
|
||||
const bool isPotentialMember = rawName.empty();
|
||||
const bool isCascadingUse = p.getSecond();
|
||||
if (isPotentialMember) {
|
||||
std::string context = DependencyKey::computeContextForProvidedEntity<
|
||||
NodeKind::potentialMember>(nominal);
|
||||
enumerateUsedDecl(NodeKind::potentialMember, context, "", isCascadingUse);
|
||||
} else {
|
||||
std::string context =
|
||||
DependencyKey::computeContextForProvidedEntity<NodeKind::member>(
|
||||
nominal);
|
||||
std::string name = rawName.userFacingName().str();
|
||||
enumerateUsedDecl(NodeKind::member, context, name, isCascadingUse);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "swift/AST/NameLookup.h"
|
||||
#include "swift/AST/NameLookupRequests.h"
|
||||
#include "swift/AST/ParameterList.h"
|
||||
#include "swift/AST/ReferencedNameTracker.h"
|
||||
#include "swift/AST/SourceFile.h"
|
||||
#include "swift/Basic/Debug.h"
|
||||
#include "swift/Basic/STLExtras.h"
|
||||
|
||||
@@ -893,7 +893,6 @@ SourceFile *CompilerInstance::createSourceFileForMainModule(
|
||||
if (isPrimary) {
|
||||
PrimarySourceFiles.push_back(inputFile);
|
||||
inputFile->enableInterfaceHash();
|
||||
inputFile->createReferencedNameTracker();
|
||||
}
|
||||
|
||||
if (bufferID == SourceMgr.getCodeCompletionBufferID()) {
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include "swift/AST/IRGenRequests.h"
|
||||
#include "swift/AST/NameLookup.h"
|
||||
#include "swift/AST/ASTMangler.h"
|
||||
#include "swift/AST/ReferencedNameTracker.h"
|
||||
#include "swift/AST/TypeRefinementContext.h"
|
||||
#include "swift/Basic/Dwarf.h"
|
||||
#include "swift/Basic/Edit.h"
|
||||
@@ -692,11 +691,25 @@ static void countStatsPostSema(UnifiedStatsReporter &Stats,
|
||||
}
|
||||
|
||||
for (auto SF : Instance.getPrimarySourceFiles()) {
|
||||
if (auto *R = SF->getConfiguredReferencedNameTracker()) {
|
||||
C.NumReferencedTopLevelNames += R->getTopLevelNames().size();
|
||||
C.NumReferencedDynamicNames += R->getDynamicLookupNames().size();
|
||||
C.NumReferencedMemberNames += R->getUsedMembers().size();
|
||||
}
|
||||
auto &Ctx = SF->getASTContext();
|
||||
Ctx.evaluator.enumerateReferencesInFile(SF, [&C](const auto &ref) {
|
||||
using NodeKind = evaluator::DependencyCollector::Reference::Kind;
|
||||
switch (ref.kind) {
|
||||
case NodeKind::Empty:
|
||||
case NodeKind::Tombstone:
|
||||
llvm_unreachable("Cannot enumerate dead dependency!");
|
||||
case NodeKind::TopLevel:
|
||||
C.NumReferencedTopLevelNames += 1;
|
||||
return;
|
||||
case NodeKind::Dynamic:
|
||||
C.NumReferencedDynamicNames += 1;
|
||||
return;
|
||||
case NodeKind::PotentialMember:
|
||||
case NodeKind::UsedMember:
|
||||
C.NumReferencedMemberNames += 1;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!Instance.getPrimarySourceFiles().empty()) {
|
||||
@@ -2169,11 +2182,10 @@ int swift::performFrontend(ArrayRef<const char *> Args,
|
||||
if (Invocation.getFrontendOptions().EnableIncrementalDependencyVerifier) {
|
||||
if (!Instance->getPrimarySourceFiles().empty()) {
|
||||
HadError |= swift::verifyDependencies(Instance->getSourceMgr(),
|
||||
*Instance->getDependencyTracker(),
|
||||
Instance->getPrimarySourceFiles());
|
||||
} else {
|
||||
HadError |= swift::verifyDependencies(
|
||||
Instance->getSourceMgr(), *Instance->getDependencyTracker(),
|
||||
Instance->getSourceMgr(),
|
||||
Instance->getMainModule()->getFiles());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "swift/AST/PrettyStackTrace.h"
|
||||
#include "swift/AST/PropertyWrappers.h"
|
||||
#include "swift/AST/ProtocolConformance.h"
|
||||
#include "swift/AST/ReferencedNameTracker.h"
|
||||
#include "swift/AST/SourceFile.h"
|
||||
#include "swift/AST/TypeWalker.h"
|
||||
#include "swift/Basic/Statistic.h"
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
#include "swift/AST/PrettyStackTrace.h"
|
||||
#include "swift/AST/PropertyWrappers.h"
|
||||
#include "swift/AST/ProtocolConformance.h"
|
||||
#include "swift/AST/ReferencedNameTracker.h"
|
||||
#include "swift/AST/SourceFile.h"
|
||||
#include "swift/AST/TypeWalker.h"
|
||||
#include "swift/Basic/Statistic.h"
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include "swift/AST/ParameterList.h"
|
||||
#include "swift/AST/PrettyStackTrace.h"
|
||||
#include "swift/AST/ProtocolConformance.h"
|
||||
#include "swift/AST/ReferencedNameTracker.h"
|
||||
#include "swift/AST/TypeCheckRequests.h"
|
||||
#include "swift/AST/TypeDeclFinder.h"
|
||||
#include "swift/AST/TypeMatcher.h"
|
||||
|
||||
Reference in New Issue
Block a user