Skip to content
← Back

src/semantic/types/pure_function.ghul

1
namespace Semantic.Types is
2
use Source.LOCATION;
3
4
// A function type whose values are trusted store-free: invoking
5
// one does not drop flow-narrowing facts, and only a value proven
6
// or declared store-free is accepted where the type is expected.
7
// Purity does not participate in type identity or assignability —
8
// a pure function type compares equal to its impure shape — so
9
// interning, LUB and overload resolution are unaffected;
10
// enforcement happens where a value meets a pure-typed slot.
11
// `create` reproduces the pure kind so the flag survives generic
12
// specialization.
13
class PURE_FUNCTION: FUNCTION is
14
is_pure_function: bool => true;
15
16
short_description: string => "{get_short_description(self)} pure";
17
18
init(
19
location: LOCATION,
20
symbol: Symbols.Classy,
21
arguments: Collections.List[Type]
22
) is
23
super.init(location, symbol, arguments);
24
si
25
26
create(
27
location: LOCATION,
28
symbol: Symbols.Classy,
29
arguments: Collections.List[Type]
30
) -> GENERIC =>
31
PURE_FUNCTION(location, symbol, arguments);
32
33
to_string() -> string => short_description;
34
si
35
36
// The void-returning counterpart of PURE_FUNCTION.
37
class PURE_ACTION: ACTION is
38
is_pure_function: bool => true;
39
40
short_description: string => "{get_short_description(self)} pure";
41
42
init(
43
location: LOCATION,
44
symbol: Symbols.Classy,
45
arguments: Collections.List[Type]
46
) is
47
super.init(location, symbol, arguments);
48
si
49
50
create(
51
location: LOCATION,
52
symbol: Symbols.Classy,
53
arguments: Collections.List[Type]
54
) -> GENERIC =>
55
PURE_ACTION(location, symbol, arguments);
56
57
to_string() -> string => short_description;
58
si
59
si