Skip to content
← Back

src/semantic/lookups/innate_symbol_lookup.ghul

1
namespace Semantic.Lookups is
2
use IO.Std
3
use TYPE = System.Type
4
use Symbol = Symbols.Symbol
5
use Type = Types.Type
6
7
// Open so the unit-test assembly can stand in for it. Nothing
8
// outside this compilation implements it otherwise.
9
trait InnateSymbolLookup open is
10
get_enum_type() -> Type
11
get_tuple_type(types: Collections.List[Type], names: Collections.List[string?]?) -> Type
12
get_function_type(types: Collections.List[Type]) -> Type
13
14
// As above; `is_pure` true builds the `pure`-marked shape
15
// (see Types.PURE_FUNCTION). The zero-argument void form has
16
// no pure shape yet and falls back to the plain one.
17
get_function_type(types: Collections.List[Type], is_pure: bool) -> Type
18
19
get_array_type(type: Type) -> Type
20
21
// The value-type `T?` — NULLABLE[type] (System.Nullable[type]).
22
get_optional_type(type: Type) -> Type
23
24
// The unconstrained-T `T?` — `Ghul.MAYBE[type]`, the
25
// runtime struct that carries either an absent or a present
26
// value of `type`. Null when the runtime is unavailable
27
// (compiling `ghul-runtime` itself), mirroring
28
// `get_unspecialized_pipe_type`: the caller
29
// reports a clearer error than the generic
30
// `Ghul.MAYBE not found` would.
31
get_maybe_type(type: Type) -> Type?
32
33
// Whether `definition` is the `Ghul.MAYBE` the compilation declares
34
// from source, as a core library compiled into the program does, so
35
// that a `MAYBE[T]` written by name is the optional carrier a `T?`
36
// over an unconstrained `T` makes. False where the carrier comes
37
// from an assembly, which marks it as it is read.
38
is_maybe_definition(definition: Semantic.Symbols.Classy) -> bool => false
39
40
// `System.Collections.Generic.EqualityComparer[type]`, the
41
// comparer a value-equality test over a bare type parameter
42
// goes through. Null when the type cannot be resolved, leaving
43
// the caller to report the ordinary no-operator error.
44
get_equality_comparer_type(type: Type) -> Type?
45
46
// Whether a target compiles each instantiation of a generic body
47
// on its own, so that `=~` over a bare type parameter compares as
48
// the type argument does, and `=~` over a tuple element by element,
49
// with no comparer type at all.
50
compares_by_instantiation: bool => false
51
52
// `Collections.LIST[type]`, or null where it cannot be reached.
53
get_list_type(type: Type) -> Type?
54
55
// The class `Collections.LIST` declares in a core compiled from
56
// source, or null where there is none.
57
get_list_class() -> Semantic.Symbols.Classy? => null
58
59
// The class `Collections.MAP` declares in a core compiled from
60
// source, or null where there is none.
61
get_map_class() -> Semantic.Symbols.Classy? => null
62
63
// The class `Collections.SET` declares in a core compiled from
64
// source, or null where there is none.
65
get_set_class() -> Semantic.Symbols.Classy? => null
66
67
get_pointer_type(type: Type) -> Type
68
69
get_reference_type(type: Type) -> Type
70
71
get_bool_type() -> Type
72
73
get_char_type() -> Type
74
75
get_byte_type() -> Type
76
77
get_ubyte_type() -> Type
78
79
get_short_type() -> Type
80
81
get_ushort_type() -> Type
82
83
get_int_type() -> Type
84
85
get_uint_type() -> Type
86
87
get_long_type() -> Type
88
89
get_ulong_type() -> Type
90
91
get_word_type() -> Type
92
93
get_uword_type() -> Type
94
95
get_single_type() -> Type
96
97
get_double_type() -> Type
98
99
get_decimal_type() -> Type
100
101
get_bigint_type() -> Type
102
103
get_void_type() -> Type
104
105
get_object_type() -> Type
106
107
get_value_type() -> Type
108
109
get_string_type() -> Type
110
111
get_exception_type() -> Type
112
113
/// The root exception type, or null where the target's core
114
/// library does not declare one. For checks that only need to
115
/// recognise an exception, and so have nothing to report when
116
/// there is none.
117
find_exception_type() -> Type?
118
119
// The two failure kinds a user-defined conversion can report, so
120
// a `cast T?(...)` over one can answer absence for both.
121
get_invalid_cast_exception_type() -> Type
122
123
get_overflow_exception_type() -> Type
124
125
get_type_type() -> Type
126
127
/// The class the target's core library declares for the exception
128
/// `kind`, which compiled code throws for a failure the runtime
129
/// detects, or null where the library declares none.
130
///
131
/// - kind: which failure
132
find_runtime_exception_type(kind: RuntimeException) -> Type?
133
134
/// The type object class, or null where the target's core library
135
/// declares none.
136
find_type_type() -> Type?
137
138
/// The class the runtime's environment is, which holds the program's
139
/// arguments, or null where the target's core library declares none.
140
find_environment_type() -> Type?
141
142
get_unspecialized_iterable_type() -> Type
143
get_unspecialized_list_type() -> Type
144
145
// Collections.LIST, the mutable list, before any type argument
146
// is supplied. A fused collect fills one specialized over the
147
// chain's element type.
148
get_unspecialized_mutable_list_type() -> Type
149
150
// The two range types, or absent where there is no ghul-runtime
151
// assembly to find them in - which is every compilation of the
152
// runtime itself, where they are source symbols in the project.
153
// get_int_range_type and get_int_range_inclusive_type above throw
154
// there; a caller that only wants to recognise a range, and can
155
// do without, asks for these.
156
get_int_range_types() -> (exclusive: Type, inclusive: Type)?
157
158
get_unspecialized_iterator_type() -> Type
159
160
// `Ghul.Pipes.Pipe[T]` — the required return type of a
161
// generator function. Optional because the runtime assembly
162
// is not loadable while the compiler is building it. Null
163
// means "Pipe is unavailable in this compilation" and callers
164
// fall back to the bare Iterable[T] / Iterator[T] element
165
// extraction.
166
get_unspecialized_pipe_type() -> Type?
167
168
// Async-related types are optional for the same reason. Each
169
// call site null-checks before using the result; the function path
170
// returns null up the chain to mean "absent, classify this
171
// function as non-async / skip the state-machine emission".
172
get_unspecialized_task_type() -> Type?
173
174
get_interpolated_string_handler_type() -> Type
175
176
get_idisposable_type() -> Type
177
178
// `System.MulticastDelegate` — the ancestry test that
179
// recognises a .NET delegate type. Null when the type cannot
180
// be resolved, in which case nothing is a named delegate.
181
get_multicast_delegate_type() -> Type?
182
183
// Ghul.BOX[T] — the single-field mutable cell used to
184
// share mutation between a closure body and its enclosing
185
// scope. The compiler's `mark-boxed-locals` pass marks
186
// captured-and-reassigned locals; emission queries this
187
// for the slot type and frame field type.
188
get_box_type(type: Type) -> Type
189
190
// `System.Range`, and the `Ghul.SLICE[E]` that backs the
191
// injected `[System.Range]` indexer.
192
get_range_type() -> Type
193
194
// `Ghul.INT_RANGE` and `Ghul.INT_RANGE_INCLUSIVE`, the types `..`
195
// and `::` produce.
196
get_int_range_type() -> Type
197
get_int_range_inclusive_type() -> Type
198
199
// `Ghul.Pipes.slice`, which an index by a range lowers to.
200
get_slice_functions() -> Symbols.FUNCTION_GROUP?
201
202
// `Ghul.Pipes.join`, which a generator frame's ToString calls
203
// to stringify itself the way the Pipe trait's own default does.
204
get_join_functions() -> Symbols.FUNCTION_GROUP?
205
206
// The runtime's `$`, which renders a value as text. Absent from a
207
// runtime older than the one that introduced it.
208
get_display_functions() -> Symbols.FUNCTION_GROUP?
209
210
// The core library's `Ghul.Internal.ENUM_TEXT.of`, which gives an
211
// enum value's text where the value is held as its integer. Absent
212
// where the core library is older than the one that introduced it,
213
// and on a target whose base class library is .NET's.
214
get_enum_text_functions() -> Symbols.FUNCTION_GROUP?
215
216
// The core library's `System.IFormattable`, which a type implements
217
// to be written in a format an interpolation names. Absent where the
218
// program declares and references none.
219
get_formattable_symbol() -> Symbols.Symbol?
220
221
// `Ghul.Pipes.render_elements`, which renders a sequence as its
222
// elements in brackets. Absent from a runtime older than the one
223
// that introduced it.
224
get_render_elements_functions() -> Symbols.FUNCTION_GROUP?
225
226
// The `Ghul.Pipes` combinators pipe fusion recognises, keyed by
227
// the resolved root Function with the combinator's fusion role
228
// as the value. Empty when the runtime is unavailable, leaving
229
// fusion declining to fire.
230
get_pipes_fusion_functions() -> Collections.MAP[Symbols.Symbol, string]
231
232
// The `Ghul.Pipes` functions whose result never ends.
233
get_pipes_unbounded_sources() -> Collections.SET[Symbols.Symbol]
234
235
// Whether `function` is one of the `Ghul.Pipes` functions.
236
is_pipes_function(function: Symbols.Function) -> bool
237
238
// Whether `function` is a `Ghul.Pipes` function that can stop
239
// reading its source before the source ends.
240
stops_early(function: Symbols.Function) -> bool
241
242
// Whether `function` is a `Ghul.Pipes` stage that reads all of its
243
// source before passing anything on.
244
reads_whole_source(function: Symbols.Function) -> bool
245
246
// Whether a call to `function` returns a sequence that holds a
247
// resource until it is disposed.
248
holds_resource(function: Symbols.Function) -> bool
249
250
// System.Threading.Tasks.Task[T] specialised over `type`.
251
// compile-lambdas uses it to build the inferred return-type
252
// placeholder for `Expressions.FUNCTION`s whose body
253
// contains a `let await` (so the synthesised continuation
254
// lambdas inherit a `Tasks.TASK[?]` context for the
255
// existing `T → TASK[T]` auto-wrap to fire).
256
get_task_type(type: Type) -> Type?
257
258
// The non-generic `System.Threading.Tasks.Task` — used as
259
// the inferred return type of an async lambda that has
260
// no value-returning `return X;` statements (every
261
// `return;` is bare and end-of-body fallthrough produces
262
// a completed Task). Distinct from
263
// `get_unspecialized_task_type` which returns the open
264
// generic `Task`1` used to recognise constructed
265
// `Task[T]` shapes.
266
get_void_task_type() -> Type?
267
268
// `System.Runtime.CompilerServices.AsyncTaskMethodBuilder<T>` —
269
// the builder field type on a value-async state machine.
270
// The state machine's outer method creates the builder via
271
// `AsyncTaskMethodBuilder<T>.Create()`, calls `Start(ref this)`
272
// to begin MoveNext, then returns `.Task`. Each value-async
273
// function reaches here with its result type so the builder
274
// is instantiated correctly.
275
get_async_task_method_builder_type(type: Type) -> Type?
276
277
// The non-generic `System.Runtime.CompilerServices.AsyncTaskMethodBuilder`
278
// for void-async (return type is the non-generic `Tasks.TASK`).
279
get_async_task_method_builder_void_type() -> Type?
280
281
// `System.Runtime.CompilerServices.IAsyncStateMachine` —
282
// the interface the async frame implements (MoveNext +
283
// SetStateMachine).
284
get_async_state_machine_interface_type() -> Type?
285
286
// `System.Runtime.CompilerServices.INotifyCompletion` and
287
// `ICriticalNotifyCompletion` — an awaiter implements one of
288
// them, and which one decides how the continuation is
289
// registered with the builder.
290
get_notify_completion_type() -> Type?
291
292
get_critical_notify_completion_type() -> Type?
293
294
// Gives the built-ins a last chance to take ancestry from what
295
// the compilation declares, once the library's types exist.
296
// The reflected lookup needs nothing: its built-ins carry
297
// their ancestry from the assemblies they came from.
298
wire_declared_ancestry() is si
299
300
// Declares the built-ins again into a `Ghul.Intrinsics` that
301
// clear_symbols has just made afresh, as the same symbols, so
302
// trees kept across the rebuild still name them. The reflected
303
// lookup needs nothing: its built-ins are found through the
304
// assemblies, which a rebuild keeps.
305
redeclare_built_ins() is si
306
307
si
308
si
309
310
namespace Semantic.Lookups is
311
/// A failure compiled code detects and throws an exception for, rather
312
/// than one a program throws itself.
313
enum RuntimeException is
314
NULL_REFERENCE,
315
INVALID_CAST,
316
INVALID_OPERATION,
317
INDEX_OUT_OF_RANGE,
318
DIVIDE_BY_ZERO,
319
OVERFLOW,
320
NOT_IMPLEMENTED,
321
NOT_SUPPORTED,
322
ASSERT_FAILED
323
si
324
325
/// The names the exception classes for runtime failures carry.
326
class RUNTIME_EXCEPTIONS is
327
/// The class's name, without its namespace.
328
///
329
/// - kind: which failure
330
name_of(kind: RuntimeException) -> string static =>
331
case kind
332
when RuntimeException.NULL_REFERENCE then "NullReferenceException"
333
when RuntimeException.INVALID_CAST then "InvalidCastException"
334
when RuntimeException.INVALID_OPERATION then "InvalidOperationException"
335
when RuntimeException.INDEX_OUT_OF_RANGE then "IndexOutOfRangeException"
336
when RuntimeException.DIVIDE_BY_ZERO then "DivideByZeroException"
337
when RuntimeException.OVERFLOW then "OverflowException"
338
when RuntimeException.NOT_IMPLEMENTED then "NotImplementedException"
339
when RuntimeException.NOT_SUPPORTED then "NotSupportedException"
340
when RuntimeException.ASSERT_FAILED then "AssertFailedException"
341
esac
342
si
343
si