Skip to content
← Back

src/semantic/symbols/captured_constraint_mirror.ghul

1
namespace Semantic.Symbols is
2
use Types.Type
3
4
use Ghul.Pipes
5
6
// Copies the constraints of the type parameters a state machine
7
// frame captures onto the parameters it declares to mirror them.
8
// The kinds are copied as each mirror is declared; a bound can name
9
// any captured parameter, so the bounds are held until every mirror
10
// exists and are then rewritten through `rewrite`.
11
class CAPTURED_CONSTRAINT_MIRROR(rewrite: (Type) -> Type) is
12
_pending: Collections.LIST[(mirror: GenericArgument, bounds: Collections.List[Type])]
13
14
init(..) is
15
_pending =
16
Collections.LIST[
17
(mirror: GenericArgument, bounds: Collections.List[Type])]()
18
si
19
20
// `source` is the symbol declaring the captured parameter - the
21
// frame's owning class or its owning function - and `index` the
22
// parameter's position in that symbol's own list.
23
capture(mirror: Symbol, source: Symbol, index: int) is
24
if let argument: GenericArgument = mirror then
25
argument.set_constraint_kind(
26
source.get_argument_constraint_kind(index))
27
28
argument.set_has_constructor_constraint(
29
source.get_argument_has_constructor_constraint(index))
30
31
_pending.add(
32
(
33
mirror = argument,
34
bounds = source.get_argument_type_bounds(index)))
35
fi
36
si
37
38
apply_bounds() is
39
for (mirror, bounds) in _pending do
40
if bounds.count > 0 then
41
mirror.set_ancestor_types(
42
bounds |> map(bound => rewrite(bound)) |> collect())
43
fi
44
od
45
si
46
si
47
si