Skip to content

Commit 0f62e68

Browse files
committed
AST: Allow GenericSignatures where all parameters are concrete
Not quite ready to define extensions that make generic parameters concrete, but close.
1 parent 1e4eca8 commit 0f62e68

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,27 @@ class SubstitutionMap;
3535
/// signature and their dependent members.
3636
class GenericSignatureWitnessIterator {
3737
ArrayRef<Requirement> p;
38-
38+
39+
void checkValid() const {
40+
assert(!p.empty() &&
41+
p.front().getKind() == RequirementKind::WitnessMarker);
42+
}
43+
44+
bool shouldSkip() const {
45+
return (!p.empty() &&
46+
p.front().getKind() != RequirementKind::WitnessMarker);
47+
}
48+
3949
public:
4050
GenericSignatureWitnessIterator() = default;
41-
GenericSignatureWitnessIterator(ArrayRef<Requirement> p)
42-
: p(p)
43-
{
44-
assert(p.empty() || p.front().getKind() == RequirementKind::WitnessMarker);
51+
GenericSignatureWitnessIterator(ArrayRef<Requirement> requirements)
52+
: p(requirements) {
53+
while (shouldSkip()) { p = p.slice(1); }
4554
}
4655

4756
GenericSignatureWitnessIterator &operator++() {
48-
do {
49-
p = p.slice(1);
50-
} while (!p.empty()
51-
&& p.front().getKind() != RequirementKind::WitnessMarker);
57+
checkValid();
58+
do { p = p.slice(1); } while (shouldSkip());
5259
return *this;
5360
}
5461

@@ -59,12 +66,12 @@ class GenericSignatureWitnessIterator {
5966
}
6067

6168
Type operator*() const {
62-
assert(p.front().getKind() == RequirementKind::WitnessMarker);
69+
checkValid();
6370
return p.front().getFirstType();
6471
}
6572

6673
Type operator->() const {
67-
assert(p.front().getKind() == RequirementKind::WitnessMarker);
74+
checkValid();
6875
return p.front().getFirstType();
6976
}
7077

@@ -162,7 +169,14 @@ class GenericSignature final : public llvm::FoldingSetNode,
162169
return const_cast<GenericSignature *>(this)->getRequirementsBuffer();
163170
}
164171

165-
// Only allow allocation by doing a placement new.
172+
/// Check if the generic signature makes all generic parameters
173+
/// concrete.
174+
bool areAllParamsConcrete() const {
175+
auto iter = getAllDependentTypes();
176+
return iter.begin() == iter.end();
177+
}
178+
179+
/// Only allow allocation by doing a placement new.
166180
void *operator new(size_t Bytes, void *Mem) {
167181
assert(Mem);
168182
return Mem;

0 commit comments

Comments
 (0)