Skip to content
← Back

src/syntax/process/equality_lowering.ghul

1
namespace Syntax.Process is
2
// How `a =~ b` compares two present operands, decided from their
3
// static types alone.
4
//
5
// One decision serves every place an equality is built - the
6
// operator written in source, the null-safe wrapper around it, a
7
// `case` label, and each member of a synthesized `=~` - so that a
8
// value compares the same way wherever the comparison is spelled.
9
//
10
// Nothing compares two of these, so what the synthesized `=~`
11
// would make of a field whose type declares none does not arise.
12
@suppress("synthesized-equality-fallback")
13
union EqualityLowering is
14
// An operator that answers equality directly: a `=~` the type
15
// declares or inherits, the innate one a scalar, string or enum
16
// carries, or a global one taking both operands.
17
OPERATOR(function: Semantic.Symbols.Function)
18
19
// A `<>` the type declares, read as equality against zero. A
20
// type that defines an ordering has defined equality with it.
21
ORDER(function: Semantic.Symbols.Function)
22
23
// A type that cannot declare an operator - a tuple, or a bare
24
// type parameter - compared through `EqualityComparer[T]`, or,
25
// where the comparer type is absent, as each instantiation's type
26
// argument compares.
27
COMPARER(comparer_type: Semantic.Types.Type?)
28
29
// An array or list, compared by count and then element by
30
// element, each element by its own lowering. The element type
31
// is settled here at the same time, so nesting recurses as far
32
// as the static type does and no further.
33
SEQUENCE(element_type: Semantic.Types.Type, element: EqualityLowering)
34
35
// A class declaring neither operator, compared by reference.
36
IDENTITY
37
si
38
si