Skip to content

Commit 537dd2b

Browse files
committed
AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h, which necessitated adding #includes in various other files.
1 parent bfb98d8 commit 537dd2b

Some content is hidden

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

42 files changed

+210
-133
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
//===--- DependencyCollector.h -------------------------------- -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 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 a class for recording incremental dependencies.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_AST_DEPENDENCY_COLLECTOR_H
18+
#define SWIFT_AST_DEPENDENCY_COLLECTOR_H
19+
20+
#include "swift/AST/Identifier.h"
21+
#include "llvm/ADT/DenseMap.h"
22+
#include "llvm/ADT/DenseSet.h"
23+
24+
namespace swift {
25+
26+
class NominalTypeDecl;
27+
28+
namespace evaluator {
29+
30+
struct DependencyRecorder;
31+
32+
/// A \c DependencyCollector defines an abstract write-only buffer of
33+
/// \c Reference objects. References are added to a collector during the write
34+
/// phase of request evaluation (in \c writeDependencySink) with the various
35+
/// \c add* functions below.
36+
///
37+
/// A \c DependencyCollector should not be created directly; instances are
38+
/// vended by the request evaluator infrastructure itself.
39+
struct DependencyCollector {
40+
friend DependencyRecorder;
41+
42+
struct Reference {
43+
public:
44+
enum class Kind {
45+
Empty,
46+
Tombstone,
47+
UsedMember,
48+
PotentialMember,
49+
TopLevel,
50+
Dynamic,
51+
} kind;
52+
53+
NominalTypeDecl *subject;
54+
DeclBaseName name;
55+
56+
private:
57+
Reference(Kind kind, NominalTypeDecl *subject, DeclBaseName name)
58+
: kind(kind), subject(subject), name(name) {}
59+
60+
public:
61+
static Reference empty() {
62+
return {Kind::Empty, llvm::DenseMapInfo<NominalTypeDecl *>::getEmptyKey(),
63+
llvm::DenseMapInfo<DeclBaseName>::getEmptyKey()};
64+
}
65+
66+
static Reference tombstone() {
67+
return {Kind::Tombstone,
68+
llvm::DenseMapInfo<NominalTypeDecl *>::getTombstoneKey(),
69+
llvm::DenseMapInfo<DeclBaseName>::getTombstoneKey()};
70+
}
71+
72+
public:
73+
static Reference usedMember(NominalTypeDecl *subject, DeclBaseName name) {
74+
return {Kind::UsedMember, subject, name};
75+
}
76+
77+
static Reference potentialMember(NominalTypeDecl *subject) {
78+
return {Kind::PotentialMember, subject, DeclBaseName()};
79+
}
80+
81+
static Reference topLevel(DeclBaseName name) {
82+
return {Kind::TopLevel, nullptr, name};
83+
}
84+
85+
static Reference dynamic(DeclBaseName name) {
86+
return {Kind::Dynamic, nullptr, name};
87+
}
88+
89+
public:
90+
struct Info {
91+
static inline Reference getEmptyKey() { return Reference::empty(); }
92+
static inline Reference getTombstoneKey() {
93+
return Reference::tombstone();
94+
}
95+
static inline unsigned getHashValue(const Reference &Val) {
96+
return llvm::hash_combine(Val.kind, Val.subject,
97+
Val.name.getAsOpaquePointer());
98+
}
99+
static bool isEqual(const Reference &LHS, const Reference &RHS) {
100+
return LHS.kind == RHS.kind && LHS.subject == RHS.subject &&
101+
LHS.name == RHS.name;
102+
}
103+
};
104+
};
105+
106+
private:
107+
DependencyRecorder &parent;
108+
109+
public:
110+
explicit DependencyCollector(DependencyRecorder &parent);
111+
~DependencyCollector();
112+
113+
public:
114+
/// Registers a named reference from the current dependency scope to a member
115+
/// defined in the given \p subject type.
116+
///
117+
/// Used member constraints are typically the by-product of direct lookups,
118+
/// where the name being looked up and the target of the lookup are known
119+
/// up front. A used member dependency causes the file to be rebuilt if the
120+
/// definition of that member changes in any way - via
121+
/// deletion, addition, or mutation of a member with that same name.
122+
void addUsedMember(NominalTypeDecl *subject, DeclBaseName name);
123+
/// Registers a reference from the current dependency scope to a
124+
/// "potential member" of the given \p subject type.
125+
///
126+
/// A single potential member dependency can be thought of as many used member
127+
/// dependencies - one for each current member of the subject type, but also
128+
/// one for every member that will be added or removed from the type in the
129+
/// future. As such, these dependencies cause rebuilds when any members are
130+
/// added, removed, or changed in the \p subject type. It also indicates a
131+
/// dependency on the \p subject type's existence, so deleting the \p subject
132+
/// type will also cause a rebuild.
133+
///
134+
/// These dependencies are most appropriate for protocol conformances,
135+
/// superclass constraints, and other requirements involving entire types.
136+
void addPotentialMember(NominalTypeDecl *subject);
137+
/// Registers a reference from the current dependency scope to a given
138+
/// top-level \p name.
139+
///
140+
/// A top level dependency causes a rebuild when another top-level entity with
141+
/// that name is added, removed, or modified.
142+
void addTopLevelName(DeclBaseName name);
143+
/// Registers a reference from the current dependency scope to a given
144+
/// dynamic member \p name.
145+
///
146+
/// A dynamic lookup dependency is a special kind of member dependency on
147+
/// a name that is found by \c AnyObject lookup.
148+
void addDynamicLookupName(DeclBaseName name);
149+
150+
public:
151+
/// Retrieves the dependency recorder that created this dependency collector.
152+
const DependencyRecorder &getRecorder() const { return parent; }
153+
};
154+
155+
} // end namespace evaluator
156+
157+
} // end namespace swift
158+
159+
#endif // SWIFT_AST_DEPENDENCY_COLLECTOR_H

include/swift/AST/Evaluator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
#include "swift/AST/EvaluatorDependencies.h"
2323
#include "swift/Basic/AnyValue.h"
2424
#include "swift/Basic/Debug.h"
25-
#include "swift/Basic/Defer.h"
25+
#include "swift/Basic/LangOptions.h"
2626
#include "swift/Basic/Statistic.h"
2727
#include "llvm/ADT/DenseMap.h"
28-
#include "llvm/ADT/Optional.h"
2928
#include "llvm/ADT/SetVector.h"
3029
#include "llvm/Support/Error.h"
3130
#include "llvm/Support/PrettyStackTrace.h"

include/swift/AST/EvaluatorDependencies.h

Lines changed: 5 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
#define SWIFT_AST_EVALUATOR_DEPENDENCIES_H
2020

2121
#include "swift/AST/AnyRequest.h"
22-
#include "swift/AST/AttrKind.h"
23-
#include "swift/AST/SourceFile.h"
22+
#include "swift/AST/DependencyCollector.h"
2423
#include "swift/Basic/NullablePtr.h"
25-
#include "llvm/ADT/PointerIntPair.h"
24+
#include "llvm/ADT/DenseMap.h"
25+
#include "llvm/ADT/DenseSet.h"
2626
#include <vector>
2727

2828
namespace swift {
2929

30+
class SourceFile;
31+
3032
namespace evaluator {
3133

3234
namespace detail {
@@ -42,131 +44,6 @@ template <typename...> using void_t = void;
4244
// of individual contexts.
4345
using DependencySource = swift::NullablePtr<SourceFile>;
4446

45-
struct DependencyRecorder;
46-
47-
/// A \c DependencyCollector defines an abstract write-only buffer of
48-
/// \c Reference objects. References are added to a collector during the write
49-
/// phase of request evaluation (in \c writeDependencySink) with the various
50-
/// \c add* functions below.
51-
///
52-
/// A \c DependencyCollector should not be created directly; instances are
53-
/// vended by the request evaluator infrastructure itself.
54-
struct DependencyCollector {
55-
friend DependencyRecorder;
56-
57-
struct Reference {
58-
public:
59-
enum class Kind {
60-
Empty,
61-
Tombstone,
62-
UsedMember,
63-
PotentialMember,
64-
TopLevel,
65-
Dynamic,
66-
} kind;
67-
68-
NominalTypeDecl *subject;
69-
DeclBaseName name;
70-
71-
private:
72-
Reference(Kind kind, NominalTypeDecl *subject, DeclBaseName name)
73-
: kind(kind), subject(subject), name(name) {}
74-
75-
public:
76-
static Reference empty() {
77-
return {Kind::Empty, llvm::DenseMapInfo<NominalTypeDecl *>::getEmptyKey(),
78-
llvm::DenseMapInfo<DeclBaseName>::getEmptyKey()};
79-
}
80-
81-
static Reference tombstone() {
82-
return {Kind::Tombstone,
83-
llvm::DenseMapInfo<NominalTypeDecl *>::getTombstoneKey(),
84-
llvm::DenseMapInfo<DeclBaseName>::getTombstoneKey()};
85-
}
86-
87-
public:
88-
static Reference usedMember(NominalTypeDecl *subject, DeclBaseName name) {
89-
return {Kind::UsedMember, subject, name};
90-
}
91-
92-
static Reference potentialMember(NominalTypeDecl *subject) {
93-
return {Kind::PotentialMember, subject, DeclBaseName()};
94-
}
95-
96-
static Reference topLevel(DeclBaseName name) {
97-
return {Kind::TopLevel, nullptr, name};
98-
}
99-
100-
static Reference dynamic(DeclBaseName name) {
101-
return {Kind::Dynamic, nullptr, name};
102-
}
103-
104-
public:
105-
struct Info {
106-
static inline Reference getEmptyKey() { return Reference::empty(); }
107-
static inline Reference getTombstoneKey() {
108-
return Reference::tombstone();
109-
}
110-
static inline unsigned getHashValue(const Reference &Val) {
111-
return llvm::hash_combine(Val.kind, Val.subject,
112-
Val.name.getAsOpaquePointer());
113-
}
114-
static bool isEqual(const Reference &LHS, const Reference &RHS) {
115-
return LHS.kind == RHS.kind && LHS.subject == RHS.subject &&
116-
LHS.name == RHS.name;
117-
}
118-
};
119-
};
120-
121-
private:
122-
DependencyRecorder &parent;
123-
124-
public:
125-
explicit DependencyCollector(DependencyRecorder &parent);
126-
~DependencyCollector();
127-
128-
public:
129-
/// Registers a named reference from the current dependency scope to a member
130-
/// defined in the given \p subject type.
131-
///
132-
/// Used member constraints are typically the by-product of direct lookups,
133-
/// where the name being looked up and the target of the lookup are known
134-
/// up front. A used member dependency causes the file to be rebuilt if the
135-
/// definition of that member changes in any way - via
136-
/// deletion, addition, or mutation of a member with that same name.
137-
void addUsedMember(NominalTypeDecl *subject, DeclBaseName name);
138-
/// Registers a reference from the current dependency scope to a
139-
/// "potential member" of the given \p subject type.
140-
///
141-
/// A single potential member dependency can be thought of as many used member
142-
/// dependencies - one for each current member of the subject type, but also
143-
/// one for every member that will be added or removed from the type in the
144-
/// future. As such, these dependencies cause rebuilds when any members are
145-
/// added, removed, or changed in the \p subject type. It also indicates a
146-
/// dependency on the \p subject type's existence, so deleting the \p subject
147-
/// type will also cause a rebuild.
148-
///
149-
/// These dependencies are most appropriate for protocol conformances,
150-
/// superclass constraints, and other requirements involving entire types.
151-
void addPotentialMember(NominalTypeDecl *subject);
152-
/// Registers a reference from the current dependency scope to a given
153-
/// top-level \p name.
154-
///
155-
/// A top level dependency causes a rebuild when another top-level entity with
156-
/// that name is added, removed, or modified.
157-
void addTopLevelName(DeclBaseName name);
158-
/// Registers a reference from the current dependency scope to a given
159-
/// dynamic member \p name.
160-
///
161-
/// A dynamic lookup dependency is a special kind of member dependency on
162-
/// a name that is found by \c AnyObject lookup.
163-
void addDynamicLookupName(DeclBaseName name);
164-
165-
public:
166-
/// Retrieves the dependency recorder that created this dependency collector.
167-
const DependencyRecorder &getRecorder() const { return parent; }
168-
};
169-
17047
/// A \c DependencyRecorder is an aggregator of named references discovered in a
17148
/// particular \c DependencyScope during the course of request evaluation.
17249
struct DependencyRecorder {

include/swift/AST/IRGenRequests.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Target/TargetMachine.h"
2626

2727
namespace swift {
28+
class FileUnit;
2829
class SourceFile;
2930
class IRGenOptions;
3031
class SILModule;
@@ -36,6 +37,10 @@ namespace irgen {
3637
class IRGenModule;
3738
};
3839

40+
namespace Lowering {
41+
class TypeConverter;
42+
};
43+
3944
}; // namespace swift
4045

4146
namespace llvm {

include/swift/AST/ParseRequests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/EvaluatorDependencies.h"
2121
#include "swift/AST/SimpleRequest.h"
2222
#include "swift/Basic/Fingerprint.h"
23+
#include "swift/Parse/Token.h"
2324
#include "swift/Syntax/SyntaxNodes.h"
2425

2526
namespace swift {

include/swift/AST/SILGenRequests.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
#include "swift/AST/ASTTypeIDs.h"
2121
#include "swift/AST/EvaluatorDependencies.h"
2222
#include "swift/AST/SimpleRequest.h"
23+
#include "swift/AST/SourceFile.h"
2324
#include "swift/SIL/SILDeclRef.h"
2425

2526
namespace swift {
2627

27-
class FileUnit;
2828
class LangOptions;
2929
class ModuleDecl;
3030
class SILModule;
3131
class SILOptions;
32-
class SourceFile;
3332

3433
namespace Lowering {
3534
class TypeConverter;

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "swift/AST/TypeCheckRequests.h"
4646
#include "swift/AST/TypeLoc.h"
4747
#include "swift/AST/SwiftNameTranslation.h"
48+
#include "swift/Basic/Defer.h"
4849
#include "swift/Parse/Lexer.h" // FIXME: Bad dependency
4950
#include "clang/Lex/MacroInfo.h"
5051
#include "llvm/ADT/SmallPtrSet.h"

lib/AST/OperatorNameLookup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/DiagnosticsSema.h"
2121
#include "swift/AST/ImportCache.h"
2222
#include "swift/AST/NameLookupRequests.h"
23+
#include "swift/AST/SourceFile.h"
2324

2425
#define DEBUG_TYPE "operator-name-lookup"
2526

lib/AST/SubstitutionMap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "swift/AST/Module.h"
3232
#include "swift/AST/ProtocolConformance.h"
3333
#include "swift/AST/Types.h"
34+
#include "swift/Basic/Defer.h"
3435
#include "llvm/Support/Debug.h"
3536

3637
using namespace swift;

0 commit comments

Comments
 (0)