Skip to content

Commit 212099b

Browse files
committed
RequirementMachine: Move RequirementMachine class to swift::rewriting namespace
1 parent 379359c commit 212099b

File tree

6 files changed

+34
-23
lines changed

6 files changed

+34
-23
lines changed

include/swift/AST/ASTContext.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ namespace swift {
112112
class TupleTypeElt;
113113
class EnumElementDecl;
114114
class ProtocolDecl;
115-
class RequirementMachine;
116115
class SubstitutableType;
117116
class SourceManager;
118117
class ValueDecl;
@@ -135,6 +134,10 @@ namespace namelookup {
135134
class ImportCache;
136135
}
137136

137+
namespace rewriting {
138+
class RequirementMachine;
139+
}
140+
138141
namespace syntax {
139142
class SyntaxArena;
140143
}
@@ -1160,7 +1163,7 @@ class ASTContext final {
11601163

11611164
/// Retrieve or create a term rewriting system for answering queries on
11621165
/// type parameters written against the given generic signature.
1163-
RequirementMachine *getOrCreateRequirementMachine(
1166+
rewriting::RequirementMachine *getOrCreateRequirementMachine(
11641167
CanGenericSignature sig);
11651168

11661169
/// Retrieve a generic signature with a single unconstrained type parameter,

include/swift/AST/GenericSignature.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ namespace swift {
3333
class GenericSignatureBuilder;
3434
class ProtocolConformanceRef;
3535
class ProtocolType;
36-
class RequirementMachine;
3736
class SubstitutionMap;
3837
class GenericEnvironment;
3938

39+
namespace rewriting {
40+
class RequirementMachine;
41+
}
42+
4043
/// An access path used to find a particular protocol conformance within
4144
/// a generic signature.
4245
///
@@ -82,7 +85,7 @@ class ConformanceAccessPath {
8285

8386
friend class GenericSignatureImpl;
8487
friend class GenericSignatureBuilder;
85-
friend class RequirementMachine;
88+
friend class rewriting::RequirementMachine;
8689

8790
public:
8891
typedef const Entry *const_iterator;
@@ -320,7 +323,7 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
320323
GenericSignatureBuilder *getGenericSignatureBuilder() const;
321324

322325
/// Retrieve the requirement machine for the given generic signature.
323-
RequirementMachine *getRequirementMachine() const;
326+
rewriting::RequirementMachine *getRequirementMachine() const;
324327

325328
/// Collects a set of requirements on a type parameter. Used by
326329
/// GenericEnvironment for building archetypes.

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ struct ASTContext::Implementation {
420420
GenericSignatureBuilders;
421421

422422
/// Stored requirement machines for canonical generic signatures.
423-
llvm::DenseMap<GenericSignature, std::unique_ptr<RequirementMachine>>
423+
llvm::DenseMap<GenericSignature,
424+
std::unique_ptr<rewriting::RequirementMachine>>
424425
RequirementMachines;
425426

426427
/// The set of function types.
@@ -1892,8 +1893,8 @@ GenericSignatureBuilder *ASTContext::getOrCreateGenericSignatureBuilder(
18921893
return builder;
18931894
}
18941895

1895-
RequirementMachine *ASTContext::getOrCreateRequirementMachine(
1896-
CanGenericSignature sig) {
1896+
rewriting::RequirementMachine *
1897+
ASTContext::getOrCreateRequirementMachine(CanGenericSignature sig) {
18971898
assert(!sig.hasTypeVariable());
18981899

18991900
auto &rewriteCtx = getImpl().TheRewriteContext;
@@ -1917,7 +1918,7 @@ RequirementMachine *ASTContext::getOrCreateRequirementMachine(
19171918
return machine;
19181919
}
19191920

1920-
auto *machine = new RequirementMachine(*rewriteCtx);
1921+
auto *machine = new rewriting::RequirementMachine(*rewriteCtx);
19211922

19221923
// Store this requirement machine before adding the signature,
19231924
// to catch re-entrant construction via addGenericSignature()

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ GenericSignatureImpl::getGenericSignatureBuilder() const {
191191
CanGenericSignature(this));
192192
}
193193

194-
RequirementMachine *
194+
rewriting::RequirementMachine *
195195
GenericSignatureImpl::getRequirementMachine() const {
196196
// The requirement machine is associated with the canonical signature.
197197
if (!isCanonical())

lib/AST/RequirementMachine/RequirementMachine.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ class raw_ostream;
2121

2222
namespace swift {
2323

24-
namespace rewriting {
25-
class RewriteContext;
26-
}
27-
2824
class ASTContext;
2925
class AssociatedTypeDecl;
3026
class CanType;
@@ -34,17 +30,20 @@ class ProtocolDecl;
3430
class Requirement;
3531
class Type;
3632

33+
namespace rewriting {
34+
class RewriteContext;
35+
3736
/// Wraps a rewrite system with higher-level operations in terms of
3837
/// generic signatures and interface types.
3938
class RequirementMachine final {
40-
friend class ASTContext;
39+
friend class swift::ASTContext;
4140

4241
struct Implementation;
4342

4443
ASTContext &Context;
4544
Implementation *Impl;
4645

47-
explicit RequirementMachine(rewriting::RewriteContext &rewriteCtx);
46+
explicit RequirementMachine(RewriteContext &rewriteCtx);
4847

4948
RequirementMachine(const RequirementMachine &) = delete;
5049
RequirementMachine(RequirementMachine &&) = delete;
@@ -82,6 +81,8 @@ class RequirementMachine final {
8281
void dump(llvm::raw_ostream &out) const;
8382
};
8483

84+
} // end namespace rewriting
85+
8586
} // end namespace swift
8687

8788
#endif

lib/AST/RequirementMachine/RequirementMachineImpl.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626

2727
namespace swift {
2828

29+
namespace rewriting {
30+
2931
/// We use the PIMPL pattern to avoid creeping header dependencies.
3032
struct RequirementMachine::Implementation {
31-
rewriting::RewriteContext &Context;
32-
rewriting::RewriteSystem System;
33-
rewriting::PropertyMap Map;
33+
RewriteContext &Context;
34+
RewriteSystem System;
35+
PropertyMap Map;
3436
CanGenericSignature Sig;
3537
bool Complete = false;
3638

@@ -45,17 +47,18 @@ struct RequirementMachine::Implementation {
4547
std::vector<std::pair<CanType, ConformanceAccessPath>>
4648
CurrentConformanceAccessPaths;
4749

48-
explicit Implementation(rewriting::RewriteContext &ctx)
50+
explicit Implementation(RewriteContext &ctx)
4951
: Context(ctx),
5052
System(Context),
5153
Map(Context, System.getProtocols()) {}
52-
void verify(const rewriting::MutableTerm &term);
54+
void verify(const MutableTerm &term);
5355
void dump(llvm::raw_ostream &out);
5456

55-
rewriting::MutableTerm getLongestValidPrefix(
56-
const rewriting::MutableTerm &term);
57+
MutableTerm getLongestValidPrefix(const MutableTerm &term);
5758
};
5859

5960
}
6061

62+
}
63+
6164
#endif

0 commit comments

Comments
 (0)