Skip to content
← Back

src/syntax/process/pipe_consumer_kind.ghul

1
namespace Syntax.Process is
2
// Which terminal pipe consumer a call names, if any.
3
//
4
// `role` is the combinator's fusion role, looked up from the call's
5
// resolved target symbol rather than read off a rendered name — a
6
// rename in the runtime library changes what fuses only through the
7
// role list the innate lookup resolves from.
8
//
9
// The returned kind is what `FUSED_CONSUMER` switches on, and is
10
// not always the role - `collect_mutable` and `collect_list` fuse as `collect`.
11
class PIPE_CONSUMER_KIND is
12
of(name: string?, argument_count: int) -> string? static is
13
if !name? then
14
return null
15
fi
16
17
if name =~ "count" /\ argument_count == 0 then
18
return "count"
19
elif name =~ "any" /\ argument_count == 1 then
20
return "any"
21
elif name =~ "all" /\ argument_count == 1 then
22
return "all"
23
elif name =~ "each" /\ argument_count == 1 then
24
return "each"
25
elif name =~ "reduce" /\ argument_count == 2 then
26
return "reduce"
27
elif name =~ "find" /\ argument_count == 1 then
28
return "find"
29
elif name =~ "first" /\ argument_count == 0 then
30
return "first"
31
elif (name =~ "collect_list" \/ name =~ "collect_mutable") /\ argument_count == 0 then
32
return "collect"
33
elif (name =~ "collect" \/ name =~ "collect_array") /\ argument_count == 0 then
34
return "collect_array"
35
elif name =~ "sum" /\ argument_count == 0 then
36
return "sum"
37
elif name =~ "sum_by" /\ argument_count == 1 then
38
return "sum_by"
39
elif name =~ "join" /\ (argument_count == 0 \/ argument_count == 1) then
40
return "join"
41
fi
42
43
return null
44
si
45
46
// Whether `role` names a fusible chain stage rather than a
47
// consumer of one. A stage is never a consumption site, so the
48
// pipe-fusion study leaves stage calls out of its site records.
49
is_stage_role(role: string?) -> bool static =>
50
role =~ "map" \/ role =~ "filter" \/ role =~ "take" \/
51
role =~ "skip" \/ role =~ "memo" \/ role =~ "index"
52
53
// A consumer that takes a function argument, and so needs the
54
// fused loop to invoke it per element.
55
takes_function(consumer_kind: string?) -> bool static =>
56
consumer_kind =~ "any" \/ consumer_kind =~ "all" \/
57
consumer_kind =~ "each" \/ consumer_kind =~ "find" \/
58
consumer_kind =~ "sum_by"
59
60
// A consumer that produces no value.
61
is_void(consumer_kind: string?) -> bool static =>
62
consumer_kind =~ "each"
63
si
64
si