Skip to content

Commit 8468c14

Browse files
committed
RequirementMachine: Add overload of PropertyMap::lookUpProperties() that takes a pair of iterators
1 parent fa30159 commit 8468c14

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

lib/AST/RequirementMachine/InterfaceType.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ AssociatedTypeDecl *RewriteContext::getAssociatedTypeForSymbol(Symbol symbol) {
211211
/// If the root type is specified, we wrap it in a series of
212212
/// DependentMemberTypes. Otherwise, the root is computed from
213213
/// the first symbol of the range.
214-
template<typename Iter>
215-
Type getTypeForSymbolRange(Iter begin, Iter end, Type root,
216-
TypeArrayView<GenericTypeParamType> genericParams,
217-
const PropertyMap &map) {
214+
static Type
215+
getTypeForSymbolRange(const Symbol *begin, const Symbol *end, Type root,
216+
TypeArrayView<GenericTypeParamType> genericParams,
217+
const PropertyMap &map) {
218218
auto &ctx = map.getRewriteContext();
219219
Type result = root;
220220

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,26 @@ PropertyMap::~PropertyMap() {
235235
clear();
236236
}
237237

238-
/// Look for a property bag corresponding to a suffix of the given key.
238+
/// Look for a property bag corresponding to a suffix of the given range.
239239
///
240240
/// Returns nullptr if no information is known about this key.
241241
PropertyBag *
242-
PropertyMap::lookUpProperties(const MutableTerm &key) const {
243-
if (auto result = Trie.find(key.rbegin(), key.rend()))
242+
PropertyMap::lookUpProperties(std::reverse_iterator<const Symbol *> begin,
243+
std::reverse_iterator<const Symbol *> end) const {
244+
if (auto result = Trie.find(begin, end))
244245
return *result;
245246

246247
return nullptr;
247248
}
248249

250+
/// Look for a property bag corresponding to a suffix of the given key.
251+
///
252+
/// Returns nullptr if no information is known about this key.
253+
PropertyBag *
254+
PropertyMap::lookUpProperties(const MutableTerm &key) const {
255+
return lookUpProperties(key.rbegin(), key.rend());
256+
}
257+
249258
/// Look for a property bag corresponding to the given key, creating a new
250259
/// property bag if necessary.
251260
///

lib/AST/RequirementMachine/PropertyMap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ class PropertyMap {
212212

213213
~PropertyMap();
214214

215+
PropertyBag *lookUpProperties(std::reverse_iterator<const Symbol *> begin,
216+
std::reverse_iterator<const Symbol *> end) const;
215217
PropertyBag *lookUpProperties(const MutableTerm &key) const;
216218

217219
std::pair<CompletionResult, unsigned>

lib/AST/RequirementMachine/Term.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ struct Term::Storage final
5151

5252
size_t Term::size() const { return Ptr->Size; }
5353

54-
ArrayRef<Symbol>::iterator Term::begin() const {
54+
const Symbol *Term::begin() const {
5555
return Ptr->getElements().begin();
5656
}
5757

58-
ArrayRef<Symbol>::iterator Term::end() const {
58+
const Symbol *Term::end() const {
5959
return Ptr->getElements().end();
6060
}
6161

62-
ArrayRef<Symbol>::reverse_iterator Term::rbegin() const {
62+
std::reverse_iterator<const Symbol *> Term::rbegin() const {
6363
return Ptr->getElements().rbegin();
6464
}
6565

66-
ArrayRef<Symbol>::reverse_iterator Term::rend() const {
66+
std::reverse_iterator<const Symbol *> Term::rend() const {
6767
return Ptr->getElements().rend();
6868
}
6969

@@ -121,19 +121,16 @@ bool Term::containsUnresolvedSymbols() const {
121121
return false;
122122
}
123123

124-
namespace {
125-
126124
/// Shortlex order on symbol ranges.
127125
///
128126
/// First we compare length, then perform a lexicographic comparison
129127
/// on symbols if the two ranges have the same length.
130128
///
131129
/// This is used to implement Term::compare() and MutableTerm::compare()
132130
/// below.
133-
template<typename Iter>
134-
int shortlexCompare(Iter lhsBegin, Iter lhsEnd,
135-
Iter rhsBegin, Iter rhsEnd,
136-
RewriteContext &ctx) {
131+
static int shortlexCompare(const Symbol *lhsBegin, const Symbol *lhsEnd,
132+
const Symbol *rhsBegin, const Symbol *rhsEnd,
133+
RewriteContext &ctx) {
137134
unsigned lhsSize = (lhsEnd - lhsBegin);
138135
unsigned rhsSize = (rhsEnd - rhsBegin);
139136
if (lhsSize != rhsSize)
@@ -158,8 +155,6 @@ int shortlexCompare(Iter lhsBegin, Iter lhsEnd,
158155
return 0;
159156
}
160157

161-
}
162-
163158
/// Shortlex order on terms.
164159
int Term::compare(Term other, RewriteContext &ctx) const {
165160
return shortlexCompare(begin(), end(), other.begin(), other.end(), ctx);
@@ -170,14 +165,11 @@ int MutableTerm::compare(const MutableTerm &other, RewriteContext &ctx) const {
170165
return shortlexCompare(begin(), end(), other.begin(), other.end(), ctx);
171166
}
172167

173-
/// Replace the subterm in the range [from,to) with \p rhs.
168+
/// Replace the subterm in the range [from,to) with \p rhs. The subrange must
169+
/// be part of this term itself.
174170
///
175-
/// Note that \p rhs must precede [from,to) in the linear
176-
/// order on terms.
177-
void MutableTerm::rewriteSubTerm(
178-
decltype(MutableTerm::Symbols)::iterator from,
179-
decltype(MutableTerm::Symbols)::iterator to,
180-
Term rhs) {
171+
/// Note that \p rhs must precede [from,to) in the linear order on terms.
172+
void MutableTerm::rewriteSubTerm(Symbol *from, Symbol *to, Term rhs) {
181173
auto oldSize = size();
182174
unsigned lhsLength = (unsigned)(to - from);
183175
assert(rhs.size() <= lhsLength);

lib/AST/RequirementMachine/Term.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class Term final {
5050
public:
5151
size_t size() const;
5252

53-
ArrayRef<Symbol>::iterator begin() const;
54-
ArrayRef<Symbol>::iterator end() const;
53+
const Symbol *begin() const;
54+
const Symbol *end() const;
5555

56-
ArrayRef<Symbol>::reverse_iterator rbegin() const;
57-
ArrayRef<Symbol>::reverse_iterator rend() const;
56+
std::reverse_iterator<const Symbol *> rbegin() const;
57+
std::reverse_iterator<const Symbol *> rend() const;
5858

5959
Symbol back() const;
6060

@@ -115,8 +115,8 @@ class MutableTerm final {
115115
/// to become valid.
116116
MutableTerm() {}
117117

118-
explicit MutableTerm(decltype(Symbols)::const_iterator begin,
119-
decltype(Symbols)::const_iterator end)
118+
explicit MutableTerm(const Symbol *begin,
119+
const Symbol *end)
120120
: Symbols(begin, end) {}
121121

122122
explicit MutableTerm(llvm::SmallVector<Symbol, 3> &&symbols)
@@ -140,8 +140,7 @@ class MutableTerm final {
140140
Symbols.append(other.begin(), other.end());
141141
}
142142

143-
void append(decltype(Symbols)::const_iterator from,
144-
decltype(Symbols)::const_iterator to) {
143+
void append(const Symbol *from, const Symbol *to) {
145144
Symbols.append(from, to);
146145
}
147146

@@ -155,17 +154,17 @@ class MutableTerm final {
155154
return begin()->getRootProtocols();
156155
}
157156

158-
decltype(Symbols)::const_iterator begin() const { return Symbols.begin(); }
159-
decltype(Symbols)::const_iterator end() const { return Symbols.end(); }
157+
const Symbol *begin() const { return Symbols.begin(); }
158+
const Symbol *end() const { return Symbols.end(); }
160159

161-
decltype(Symbols)::iterator begin() { return Symbols.begin(); }
162-
decltype(Symbols)::iterator end() { return Symbols.end(); }
160+
Symbol *begin() { return Symbols.begin(); }
161+
Symbol *end() { return Symbols.end(); }
163162

164-
decltype(Symbols)::const_reverse_iterator rbegin() const { return Symbols.rbegin(); }
165-
decltype(Symbols)::const_reverse_iterator rend() const { return Symbols.rend(); }
163+
std::reverse_iterator<const Symbol *> rbegin() const { return Symbols.rbegin(); }
164+
std::reverse_iterator<const Symbol *> rend() const { return Symbols.rend(); }
166165

167-
decltype(Symbols)::reverse_iterator rbegin() { return Symbols.rbegin(); }
168-
decltype(Symbols)::reverse_iterator rend() { return Symbols.rend(); }
166+
std::reverse_iterator<Symbol *> rbegin() { return Symbols.rbegin(); }
167+
std::reverse_iterator<Symbol *> rend() { return Symbols.rend(); }
169168

170169
Symbol back() const {
171170
return Symbols.back();
@@ -183,9 +182,7 @@ class MutableTerm final {
183182
return Symbols[index];
184183
}
185184

186-
void rewriteSubTerm(decltype(Symbols)::iterator from,
187-
decltype(Symbols)::iterator to,
188-
Term rhs);
185+
void rewriteSubTerm(Symbol *from, Symbol *to, Term rhs);
189186

190187
void dump(llvm::raw_ostream &out) const;
191188

0 commit comments

Comments
 (0)