Skip to content
← Back

src/semantic/symbols/function.ghul

1
namespace Semantic.Symbols is
2
use IO.Std
3
4
use System.Exception
5
use System.NotImplementedException
6
use System.Text.StringBuilder
7
8
use Collections.Iterable
9
10
use IoC
11
use Logging
12
use Source
13
14
use IR.Values.Value
15
16
use Types.Type
17
18
use Ghul.Pipes
19
20
class Function: ScopedWithEnclosingScope, Types.Typed abstract is
21
// Whether the method emitted for this function takes a receiver.
22
// Usually the same question as `is_instance`, but a closure
23
// answers the two differently: it is not an instance member of
24
// anything the language can see, while the method emitted for it
25
// does take the frame holding its captures. Everything about the
26
// emitted method — its flags, its signature's calling
27
// convention, and the slot each argument occupies — has to agree
28
// on this, and disagreeing produces a static method whose body
29
// reads argument 0 as a receiver.
30
is_emitted_with_receiver: bool => is_instance
31
32
_arguments: Collections.List[Type]
33
34
_declaring_arguments: bool
35
_override_class: METHOD_OVERRIDE_CLASS?
36
37
override_class: METHOD_OVERRIDE_CLASS is
38
if !_override_class? then
39
// arguments is empty when resolve-explicit-variable-types
40
// never visited this function (e.g. a partially-recovered
41
// parse left the symbol orphaned from current_function),
42
// giving that case a zero-arg override class — partial
43
// symbols don't meaningfully participate in override
44
// resolution anyway.
45
_override_class = METHOD_OVERRIDE_CLASS(arguments, generic_arguments)
46
fi
47
48
return _override_class
49
si
50
51
_overriders: Collections.MutableList[Symbol]?
52
_overridees: Collections.MutableList[Symbol]?
53
54
// Whether a call to this function is trusted not to store to
55
// any pre-existing heap location, without the body being seen:
56
// declared `pure` — including on a body-less trait member the
57
// analysis never walks — a curated store-free import, or a
58
// synthesized backing-field read. Answerable at any point in
59
// the build, and never stale, because every contributor is
60
// settled by declaration shape rather than inferred from a
61
// body. What was actually proven is EFFECTS.is_store_free,
62
// which is only answerable once expressions are compiled, and
63
// which takes the union with this.
64
is_store_free: bool is
65
let rsf = root_specialized_from
66
67
if rsf != self then
68
return (cast Function?(rsf)!).is_store_free
69
fi
70
71
return _is_declared_pure \/ _is_trusted_import \/ _is_trusted_backing_read \/ _is_unreaching_static_import
72
si
73
74
// Set when this function was synthesized as the read accessor
75
// of an auto property: its body is a read of the backing
76
// field, by construction, so it stores nothing without any
77
// analysis being needed.
78
_is_backing_read: bool
79
80
mark_backing_read() is
81
let rsf = root_specialized_from
82
83
if rsf != self then
84
(cast Function?(rsf)!).mark_backing_read()
85
return
86
fi
87
88
_is_backing_read = true
89
si
90
91
// A backing read is only trusted at a call site when the call
92
// is bound to reach it: an in-assembly overrider, or a
93
// possible override outside the assembly behind an open
94
// class, could stand behind the call and store.
95
_is_trusted_backing_read: bool =>
96
_is_backing_read /\ has_no_overriders /\ !is_openly_dispatchable
97
98
// Whether an override outside this compilation could stand
99
// behind a call to this function: an instance method of
100
// anything but a closed class, and of a closed class too when
101
// a later cell of a session can extend it. Mirrors the
102
// dispatch-shadow rule the store-free solvers apply.
103
is_openly_dispatchable: bool is
104
if isa STRUCT_METHOD(self) then
105
return false
106
fi
107
108
if !isa INSTANCE_METHOD(self) then
109
return false
110
fi
111
112
let owner = self.owner
113
114
if !owner? \/ !isa Classy(owner) then
115
return true
116
fi
117
118
let owner_classy = cast Classy(owner)
119
120
return owner_classy.is_open \/ owner_classy.open_to_a_later_cell
121
si
122
123
// Written back by the store-free solve once expressions have
124
// compiled: the body, and everything it can reach, was proven
125
// to store nothing. Read where the answer is surfaced rather
126
// than relied on — hover's pure prefix and the pure
127
// function-type shape — so a stale answer in analysis mode
128
// costs a momentarily wrong display, never a wrong judgement;
129
// the crossing discharge and the pure-slot check read EFFECTS instead,
130
// inside the round that solved it. Kept in the id-keyed
131
// STORE_FREE_BITS so it survives an incremental edit that
132
// replaces the symbol object under an adopted id.
133
is_proven_store_free: bool is
134
let rsf = root_specialized_from
135
136
if rsf != self then
137
return (cast Function?(rsf)!).is_proven_store_free
138
fi
139
140
return is_store_free \/ STORE_FREE_BITS.is_proven_store_free(id)
141
si
142
143
set_proven_store_free(value: bool) is
144
let rsf = root_specialized_from
145
146
if rsf != self then
147
(cast Function?(rsf)!).set_proven_store_free(value)
148
return
149
fi
150
151
STORE_FREE_BITS.set_proven_store_free(id, value)
152
si
153
154
// Set while a literal's body compiles if it performed any
155
// heap-visible operation — a crossing-recording call, a heap
156
// store, or any local reassignment (a reassigned local can be
157
// a captured one, which is a frame-field store; own-local
158
// reassignment is conservatively included). Consulted where
159
// the compiled literal takes its value's type: a clean body
160
// surfaces at the pure shape. Meaningless for named
161
// functions — the store-free solve covers those.
162
literal_body_impure: bool public
163
164
// A curated store-free import is trusted at query time, not
165
// only when a named body's fixpoint happens to reach it as a
166
// callee edge. A call in a function-literal body or a
167
// string-interpolation fragment never becomes such an edge, so
168
// without this an otherwise store-free import reads as
169
// state-changing purely by where it was called from — the same
170
// import trusted in a named body goes untrusted in a lambda.
171
// Gated on has_no_overriders so a virtual entry with an
172
// in-assembly override still falls to the fixpoint's
173
// dispatch-shadow check rather than being trusted blind.
174
_is_trusted_import: bool =>
175
has_no_overriders /\ _is_whitelisted_import
176
177
// Whitelist membership is fixed at import from the function's
178
// own name and owner, so it is derived once and cached.
179
_whitelisted_import_cache: bool?
180
181
_is_whitelisted_import: bool is
182
if !_whitelisted_import_cache? then
183
_whitelisted_import_cache = is_reflected /\ STORE_FREE_IMPORTS.is_store_free(self)
184
fi
185
186
return _whitelisted_import_cache \/ is_trusted_store_free_declared
187
si
188
189
// Written @trusted_store_free() in a library source, or read back from
190
// the attribute that carries it: the body is trusted store-free on
191
// the same terms as a member on the curated import list, so an
192
// override is judged by the solve rather than held to a contract.
193
_is_trusted_store_free_declared: bool
194
195
is_trusted_store_free_declared: bool is
196
let rsf = root_specialized_from
197
198
if rsf != self then
199
return (cast Function?(rsf)!).is_trusted_store_free_declared
200
fi
201
202
return _is_trusted_store_free_declared
203
si
204
205
mark_trusted_store_free() is
206
let rsf = root_specialized_from
207
208
if rsf != self then
209
(cast Function?(rsf)!).mark_trusted_store_free()
210
return
211
fi
212
213
_is_trusted_store_free_declared = true
214
si
215
216
// Weaker than store-free: a call to this function can write
217
// its own receiver's internal state, but nothing else, and can
218
// reach no user code on the way. The call transfer applies the
219
// heap-store rule instead of the full kill for one of these,
220
// so field facts survive it and property facts do not.
221
//
222
// Store-free implies it, so a caller can ask this one question
223
// and get the weaker answer whenever the stronger one holds.
224
// Gated on has_no_overriders for the same reason the trusted
225
// store-free imports are: a virtual entry with an in-assembly
226
// override could dispatch to a body that stores anything.
227
writes_only_receiver_interior: bool is
228
let rsf = root_specialized_from
229
230
if rsf != self then
231
return (cast Function?(rsf)!).writes_only_receiver_interior
232
fi
233
234
return is_store_free \/ (has_no_overriders /\ _is_receiver_interior_import) \/ _is_unreaching_instance_import
235
si
236
237
// Fixed at import from the function's own name, owner and
238
// parameter types, so it is derived once and cached.
239
_receiver_interior_import_cache: bool?
240
241
_is_receiver_interior_import: bool is
242
if !_receiver_interior_import_cache? then
243
_receiver_interior_import_cache =
244
is_reflected /\ RECEIVER_INTERIOR_IMPORTS.writes_only_receiver_interior(self)
245
fi
246
247
return _receiver_interior_import_cache
248
si
249
250
// A member of a generic owner declines alongside a generic
251
// method: the owner's type parameters can carry constraints,
252
// and the body can dispatch through one into code declared
253
// outside the import, which neither the parameters nor the
254
// dispatch stamp vouch for. `LIST[T].sort` runs the element
255
// type's comparer this way.
256
_owner_is_generic: bool is
257
if let o: Classy = owner?.unspecialized_symbol then
258
return o.is_generic
259
fi
260
261
return false
262
si
263
264
// An imported BCL static whose parameters hand it no way to
265
// name code declared here or to reach storage that existed
266
// before the call. It has no receiver and no overridable
267
// parameter types, so whatever it writes lands only in its
268
// own fresh storage or in state no ghūl member can address,
269
// and a call to one is trusted store-free on the same footing
270
// as the curated import lists. Generic methods and members of
271
// generic owners decline: a body can dispatch through such a
272
// type parameter, which a parameter-only reading cannot see.
273
//
274
// Restricted to `STATIC_METHOD` - a global function imported
275
// from another ghūl assembly is arbitrary ghūl source, not a
276
// BCL surface: it can write its own assembly's globals and
277
// dispatch into this assembly through an object stored there,
278
// which a parameter-only reading cannot see either. `pure` is
279
// the way such a function earns this trust.
280
//
281
// A BCL static can still route through mutable ambient state
282
// invisible to its parameters - `Console.write_line(s)`
283
// dispatches through whatever `TextWriter` `Console.set_out`
284
// last installed, which can be a ghūl-implemented override
285
// that stores. This tier accepts that gap deliberately rather
286
// than declining every string-taking static or curating one
287
// away: redirecting a stream this pervasive into something
288
// that mutates state a live narrowing depends on is a
289
// vanishingly unrealistic thing for real code to do, and
290
// guarding against it would cost the tier its main value -
291
// trusting BCL statics without a curated list - for a
292
// hazard no program is likely to hit.
293
294
_unreaching_static_import_cache: bool?
295
296
_is_unreaching_static_import: bool is
297
if !_unreaching_static_import_cache? then
298
_unreaching_static_import_cache =
299
is_reflected /\
300
!is_generic /\
301
!_owner_is_generic /\
302
IMPORT_ARGUMENTS.all_arguments_scalar(self) /\
303
!isa STATIC_CONSTRUCTOR(self) /\
304
isa STATIC_METHOD(self) /\
305
!(cast STATIC_METHOD?(self)!).is_static_interface_virtual
306
fi
307
308
return _unreaching_static_import_cache
309
si
310
311
// The instance counterpart: an imported method the CLR binds
312
// statically (`cannot_be_overridden`), so that no override in
313
// any assembly can stand behind the call, with parameters that
314
// reach nothing pre-existing or user code. Everything such a
315
// method can write is therefore its own receiver's interior,
316
// which makes it receiver-interior by construction rather than
317
// by curation. Generic methods and members of generic owners
318
// decline, as they do for the static tier.
319
// A delegate's members decline however their parameters read.
320
// `Invoke` takes whatever the delegate's own shape takes and
321
// runs arbitrary code, so a shape-only reading of it - sealed
322
// owner, scalar parameters, bound statically - vouches for
323
// nothing. Recognised by walking to `System.MulticastDelegate`
324
// by symbol identity rather than by matching a member name.
325
_owner_is_delegate: bool is
326
if let owner_classy: Classy = owner?.unspecialized_symbol then
327
return owner_classy.is_delegate
328
fi
329
330
return false
331
si
332
333
_unreaching_instance_import_cache: bool?
334
335
_is_unreaching_instance_import: bool is
336
if !_unreaching_instance_import_cache? then
337
_unreaching_instance_import_cache =
338
is_reflected /\
339
!is_generic /\
340
!_owner_is_generic /\
341
!_owner_is_delegate /\
342
IMPORT_ARGUMENTS.all_arguments_scalar(self) /\
343
isa Method(self) /\
344
(cast Method?(self)!).cannot_be_overridden
345
fi
346
347
return _unreaching_instance_import_cache
348
si
349
350
// Whether this function is a constructor. Overridden on the
351
// method that carries the `.ctor` IL name; false everywhere
352
// else, so callers can ask any function without a cast.
353
is_constructor: bool => false
354
355
// Whether this is an imported .NET member that only its declaring
356
// type and that type's subclasses can use. The import leaves access
357
// to the runtime; completion reads this to keep such a member off
358
// the list after an ordinary dot.
359
is_imported_protected: bool => _is_imported_protected
360
361
_is_imported_protected: bool
362
363
mark_imported_protected() is
364
_is_imported_protected = true
365
si
366
367
// A constructor is trusted to write no pre-existing heap slot
368
// *given its receiver is fresh* — the case a `NEW` presents.
369
// Only the structural tiers answer here; a constructor that
370
// writes its own instance fields is proven harmless by the
371
// solve instead, and the crossing its construction records is
372
// discharged against EFFECTS.constructs_store_free.
373
constructs_store_free: bool is
374
let rsf = root_specialized_from
375
376
if rsf != self then
377
return (cast Function?(rsf)!).constructs_store_free
378
fi
379
380
return is_store_free \/ _is_unreaching_import_construction
381
si
382
383
// An imported constructor whose parameters hand it no way to
384
// name code declared here. Its receiver did not exist before
385
// the call, so nothing pre-existing is reachable through it
386
// either, and the two routes together are the whole of what
387
// the constructor can address. That leaves construction of an
388
// imported type harmless without any per-member curation,
389
// which is what keeps a `Collections.MAP()` from ending every
390
// fact live around it.
391
//
392
// A write reached through a static field an earlier call
393
// populated is outside the argument, and is accepted on the
394
// same footing as the equals-and-hash contract the curated
395
// import lists already rest on.
396
_unreaching_import_construction_cache: bool?
397
398
_is_unreaching_import_construction: bool is
399
if !_unreaching_import_construction_cache? then
400
_unreaching_import_construction_cache =
401
is_reflected /\ is_constructor /\ IMPORT_ARGUMENTS.all_arguments_scalar(self)
402
fi
403
404
return _unreaching_import_construction_cache
405
si
406
407
// Declared `pure` in source: the function is trusted
408
// effectively store-free without its body being provable.
409
// Feeds the store-free bit unconditionally after the
410
// fixpoint, and obliges every override or trait
411
// implementation to be pure itself — declared or proven.
412
_is_declared_pure: bool
413
414
is_declared_pure: bool is
415
let rsf = root_specialized_from
416
417
if rsf != self then
418
return (cast Function?(rsf)!).is_declared_pure
419
fi
420
421
return _is_declared_pure
422
si
423
424
mark_declared_pure() is
425
let rsf = root_specialized_from
426
427
if rsf != self then
428
(cast Function?(rsf)!).mark_declared_pure()
429
return
430
fi
431
432
_is_declared_pure = true
433
si
434
435
// The read accessor of a property declared `stable`: two
436
// adjacent reads with nothing between them agree on presence
437
// and runtime type. Trusted, not verified — the same standing
438
// as `pure` — and orthogonal to it: a memoiser is impure and
439
// stable. A fact narrowed through the property counts as
440
// backed even when the getter's body is not provably
441
// self-stable, and every override must honour the contract.
442
// Carried across assemblies by STABLE_ATTRIBUTE.
443
_is_declared_stable: bool
444
445
is_declared_stable: bool is
446
let rsf = root_specialized_from
447
448
if rsf != self then
449
return (cast Function?(rsf)!).is_declared_stable
450
fi
451
452
return _is_declared_stable
453
si
454
455
mark_declared_stable() is
456
let rsf = root_specialized_from
457
458
if rsf != self then
459
(cast Function?(rsf)!).mark_declared_stable()
460
return
461
fi
462
463
_is_declared_stable = true
464
si
465
466
// The operation named by an `INTRINSIC_ATTRIBUTE` on this
467
// declaration, or null. Set for a source declaration only: the
468
// declaration is emitted so consumers can reflect it, and a
469
// separate innate is registered from it once signatures resolve.
470
intrinsic_operation: string? public
471
472
// Set on a constructor the language supplies for a collection type
473
// that has none of its own for the argument: the runtime's static
474
// method a call to it lowers to, in place of a newobj.
475
constructor_target: Function? public
476
477
// Set on a constructor the language supplies for a scalar type from
478
// another scalar: it converts its argument exactly as `cast` to the
479
// constructed type would.
480
is_scalar_conversion: bool public
481
482
// Set on the entry point synthesised from a file's top-level
483
// statements. Only this function's statements run in textual
484
// order, so TOP_LEVEL_VARIABLE checks it to report a use above
485
// the variable's `let`, and analysis mode routes edits to files
486
// carrying it to the full rebuild.
487
is_top_level_entry: bool public
488
489
// Set by select-entry-point on the one function this assembly
490
// enters at. Emission reads it rather than re-deriving the choice
491
// from the name, so every candidate is ranked against the others
492
// before any IL is written.
493
is_entry_point: bool public
494
495
// No more-derived override exists. In a closed-by-default,
496
// wholly-compiled assembly this means the method is effectively
497
// final — the only body a call can reach is this one.
498
has_no_overriders: bool => !_overriders? \/ _overriders.count == 0
499
500
span: LOCATION
501
502
// Incremental body re-walk override: also shift the declaration
503
// span when the retained interface symbol is relocated.
504
set_span(span_location: LOCATION) is
505
span = span_location
506
si
507
508
type: Type? public
509
return_type: Type? public
510
511
// True when this function was declared without an explicit
512
// return-type annotation (so the return type starts as
513
// INFERRED_RETURN_TYPE and is set by walking return statements
514
// / expression bodies). Used by the compile pass to drive LUB
515
// widening across multiple return statements: when a later
516
// return produces a type that's neither assignable to nor
517
// from the current binding, widening to the LUB is the right
518
// answer for an inferred return type, but a declared return
519
// type with the same shape is a genuine type error.
520
return_type_was_inferred: bool public
521
522
// Set by compile-expressions when a `return null` is reached
523
// while the return type is still inferred. A null says a value
524
// can be absent without saying what it holds when present, so it
525
// settles nothing on its own: what it records is that whatever
526
// the return settles at has to be optional, and that a body
527
// whose every return is null takes its type from the slot the
528
// literal goes into rather than from itself.
529
returned_genuine_null: bool public
530
531
// Set by compile-lambdas when the AST FUNCTION had
532
// `contains_let_await` set by declare-symbols. When settling
533
// an inferred return type from the body's value, wrap a
534
// bare-T value as `Tasks.TASK[T]` so the closure's signature
535
// matches its async-state-machine emission shape. Body
536
// values already typed Task[?] are left untouched.
537
wrap_inferred_return_as_task: bool public
538
539
// Set by compile-lambdas when the literal's slot returns `U?` over
540
// an unconstrained U. An inferred return settles as `MAYBE[T]`
541
// over what the body produced, so the literal's delegate has the
542
// shape the slot binds against.
543
wrap_inferred_return_as_maybe: bool public
544
545
// Set by compile-lambdas to the slot's return type when that is a
546
// reference type and the literal's own return is inferred. A body
547
// producing a value type settles the return here rather than at
548
// what it produced, so the conversion to the slot's type is made
549
// inside the literal. Reaching the slot's type by assigning the
550
// delegate instead would need the return covariance a value-type
551
// instantiation does not have, and nothing checks that at run
552
// time. A body producing a reference type keeps its own, which is
553
// the more precise type and converts by assignment soundly.
554
pin_inferred_return_at: Types.Type? public
555
556
// Set on the closure of a literal synthesised to adapt a named
557
// function reference to a formal it differs from only in an
558
// optional position's carrier. Such a literal exists to present
559
// the formal's own shape, so a settled slot return is adopted
560
// rather than inferred from the body it wraps.
561
is_carrier_adapter: bool public
562
563
// Set by compile-lambdas when the AST FUNCTION had
564
// `is_void_async` set by declare-symbols — i.e., body
565
// contains `await` but no value-returning `return X;`
566
// statements. Read by the async state machine setup to pick
567
// the non-generic Tasks.TASK over Tasks.TASK[T].
568
is_void_async: bool public
569
570
// Set by compile-lambdas when the slot an async closure goes
571
// into names a generic task-like other than Task, with the
572
// result argument still to be inferred from the body. The
573
// inferred return type is then built from this symbol rather
574
// than from Task, so `spawn[T](body: () -> COROUTINE[T])`
575
// infers T from the closure's returns.
576
async_task_like_template: Classy? public
577
578
// True once the argument list has been supplied — by
579
// resolve-explicit-variable-types for source functions, at import
580
// for reflected ones, or at synthesis. Distinguishes a
581
// not-yet-declared function from a declared zero-argument one:
582
// both have an empty arguments list, but only the declared one
583
// may participate in arity-based overload filtering.
584
_are_arguments_declared: bool
585
586
are_arguments_declared: bool => _are_arguments_declared
587
588
arguments: Collections.List[Type] public => _arguments,
589
= value is
590
assert value |> all(a => a?) else "setting an argument to null for {name}"
591
592
_arguments = value
593
_are_arguments_declared = true
594
si
595
596
generic_arguments: Collections.List[Type] public
597
generic_argument_names: Collections.List[string] public
598
unspecialized_arguments: Collections.List[Type]? public
599
600
// Parallel to `arguments`: whether each formal was declared to
601
// take an argument pack spread out - `f: T.. -> U` - rather than
602
// as the tuple the pack binds to. Empty for the great majority
603
// of functions, which mention no pack at all.
604
argument_is_pack: Collections.List[bool] public
605
606
// Parallel to `argument_is_pack`: how many returns into the
607
// formal's own type the marked function type sits. Zero is the
608
// formal's own type - `f: T.. -> U` - and one is the function
609
// its own return names, as `f: X -> T.. -> U` does.
610
argument_pack_depth: Collections.List[int] public
611
612
// Index of the formal declared to absorb the call's remaining
613
// arguments into the pack's tuple - `v: T..` - and -1 for the
614
// great majority of functions, which declare no such formal.
615
spread_argument_index: int public
616
617
// How many returns into the declared return type the marked
618
// function type sits - `-> T.. -> U` is zero, `-> X -> T.. -> U`
619
// is one - and -1 for the great majority of functions, whose
620
// return type carries no pack marker. The declared return type
621
// itself still names the tuple-in shape; a call that binds the
622
// pack to a concrete tuple presents its result as the
623
// corresponding N-ary function instead.
624
return_pack_depth: int public
625
unspecialized_return_type: Type? public
626
627
// Parallel to generic_argument_names: kind / `init` / type-bound
628
// constraints per method-level type parameter. Populated at
629
// import for .NET methods, whose parameter symbols are not
630
// declared into the function's scope and so can't be reached
631
// via find_direct. ghūl-declared methods leave these empty and
632
// carry the same information on the parameter symbol.
633
generic_argument_constraint_kinds: Collections.List[TypeParameterConstraintKind] public
634
generic_argument_has_constructor_constraint: Collections.List[bool] public
635
generic_argument_type_bounds: Collections.List[Collections.List[Type]] public
636
637
argument_names: Collections.List[string] public
638
639
// Parallel to `argument_names`: the declared default of each
640
// parameter, or null when the parameter has no default and so
641
// cannot be omitted from a named call. A ghūl-source `= _`
642
// parameter is stored as "default"; a literal default
643
// (reflected methods only) is stored as its text.
644
argument_defaults: Collections.List[string?] public
645
646
// Parallel to `argument_names`: per-parameter by-ref direction,
647
// derived from reflected `IsIn`/`IsOut` and populated only for
648
// reflected methods that have a non-plain by-ref slot. Null
649
// elsewhere, where a by-ref parameter defaults to plain `ref`
650
// — both read and written. `reads` gates the must-be-assigned-
651
// before check; `writes` gates definite assignment of the
652
// argument. Held on the unspecialized function so specializations
653
// observe them through `root_specialized_from`.
654
_argument_reads: Collections.List[bool]?
655
_argument_writes: Collections.List[bool]?
656
657
set_argument_directions(reads: Collections.List[bool], writes: Collections.List[bool]) is
658
let rsf = root_specialized_from
659
660
if rsf != self then
661
(cast Function?(rsf)!).set_argument_directions(reads, writes)
662
return
663
fi
664
665
_argument_reads = reads
666
_argument_writes = writes
667
si
668
669
// Whether the callee reads the incoming value of argument `i`.
670
// True for every by-ref slot except a pure `out`, and the
671
// conservative default when no reflected direction is recorded.
672
argument_reads(i: int) -> bool is
673
let rsf = root_specialized_from
674
675
if rsf != self then
676
return (cast Function?(rsf)!).argument_reads(i)
677
fi
678
679
if _argument_reads? /\ i < _argument_reads.count then
680
return _argument_reads[i]
681
fi
682
683
return true
684
si
685
686
// Whether the callee writes argument `i`, so passing it by `ref`
687
// definitely assigns the target. True for every by-ref slot
688
// except a pure `in`, and the conservative default.
689
argument_writes(i: int) -> bool is
690
let rsf = root_specialized_from
691
692
if rsf != self then
693
return (cast Function?(rsf)!).argument_writes(i)
694
fi
695
696
if _argument_writes? /\ i < _argument_writes.count then
697
return _argument_writes[i]
698
fi
699
700
return true
701
si
702
703
symbol_kind: SymbolKind => SymbolKind.FUNCTION
704
completion_kind: CompletionKind => CompletionKind.FUNCTION
705
706
is_function: bool => true
707
is_generic: bool public
708
709
// Excluded as a candidate when a binary operator expression
710
// resolves. Set on a reflected operator-named member of a type
711
// whose operator is innate — `int`'s `<>` from
712
// `IComparable[int].CompareTo` — so `a < b` keeps lowering to
713
// the comparison opcode while the member remains reachable
714
// every other way: it satisfies its trait, resolves by name,
715
// and converts to a delegate.
716
is_hidden_from_operator_resolution: bool public
717
is_abstract: bool => false
718
719
// Whether the source declared this method without a body. A
720
// `DllImport` needs one that was: the call it stands for is the
721
// library's, so a body of its own would be dead code.
722
is_declared_without_body: bool public
723
724
// What this method's `DllImport` says, for a method declared
725
// with no body that calls into a shared library. Absent on
726
// every ordinary method.
727
@IF.dotnet()
728
pinvoke: Semantic.PINVOKE_IMPORT? public
729
730
// Whether this method calls into a shared library, and so has no
731
// body of its own.
732
@IF.dotnet()
733
is_pinvoke: bool => pinvoke?
734
735
@IF.not.dotnet()
736
is_pinvoke: bool => false
737
738
// What this method's `MethodImpl` says. The runtime reads these
739
// from the method row rather than from a custom attribute, so
740
// they reach the emitter as flags and the attribute itself is
741
// never carried.
742
@IF.dotnet()
743
method_impl_attributes: System.Reflection.MethodImplAttributes public
744
745
// Only a body-less class method that overrides an implemented
746
// one carries a throwing body; every other function has one of
747
// its own, so this asks nothing of them.
748
throws_unimplemented: bool => false
749
750
mark_throws_unimplemented() is si
751
752
// A synthesized `reset` a type never declared: its body is a
753
// throw rather than anything the source asked for.
754
throws_not_supported: bool => false
755
756
mark_throws_not_supported() is si
757
is_virtual: bool => false
758
is_default_trait_method: bool => false
759
is_capture_context: bool => true
760
is_workspace_visible: bool => !name.starts_with('_')
761
is_recursive: bool => false // only applicable if a closure
762
763
// An indexer's accessors carry the CLR-required names `get_Item`
764
// and `set_Item`, which are not spellable in ghūl source. Rendered
765
// as a plain call they read as a member the language does not
766
// have, so they take the declaration's own shape instead - the
767
// same shape `to_string` gives them, with short type descriptions.
768
short_description: string =>
769
if is_indexer_accessor then
770
render_indexer_shape(
771
get_short_argument_description(0),
772
indexer_value_type!.short_description
773
)
774
else
775
"{name}{generic_argument_descriptions}({short_argument_descriptions}) -> {_return_type_description(true)}"
776
fi
777
778
search_description: string => short_description
779
780
// Prefixes the description's trailing kind comment when the
781
// function is proven store-free — diagnostic surfacing only,
782
// deliberately inside the comment so it does not read as
783
// source syntax.
784
pure_prefix: string => if is_proven_store_free then "pure " else "" fi
785
786
argument_descriptions: string =>
787
(0..arguments.count) |> map(i => get_argument_description(i)) |> join() ?? ""
788
789
short_argument_descriptions: string =>
790
(0..arguments.count) |> map(i => get_short_argument_description(i)) |> join() ?? ""
791
792
generic_argument_descriptions: string is
793
if generic_arguments.count == 0 then
794
return ""
795
fi
796
797
let result = System.Text.StringBuilder()
798
799
result.append('[')
800
801
let seen_any mut = false
802
803
for i in 0..generic_arguments.count do
804
if seen_any then
805
result.append(',')
806
fi
807
808
result.append(generic_arguments[i])
809
810
// The `..` bound belongs to the declaration, so it is
811
// written here rather than by the type's own rendering,
812
// which also answers wherever the parameter is used.
813
if generic_arguments[i].symbol.is_argument_pack then
814
result.append("..")
815
fi
816
817
seen_any = true
818
od
819
820
result.append(']')
821
822
return result.to_string()
823
si
824
825
// Sets the `..` on each type parameter a pack marker names. A
826
// reflected function carries its markers on formals and return
827
// only; the declaration's own `[T..]` is what they name, rebuilt
828
// here from them.
829
mark_pack_type_parameters() is
830
for i in 0..arguments.count do
831
if i < argument_is_pack.count /\ argument_is_pack[i] then
832
let depth = if i < argument_pack_depth.count then argument_pack_depth[i] else 0 fi
833
834
_mark_pack_slot(Semantic.ARGUMENT_PACK.marked_slot(arguments[i], depth))
835
elif i == spread_argument_index then
836
_mark_pack_parameter(arguments[i])
837
fi
838
od
839
840
if return_pack_depth >= 0 then
841
_mark_pack_slot(Semantic.ARGUMENT_PACK.marked_slot(return_type, return_pack_depth))
842
fi
843
si
844
845
_mark_pack_slot(slot: Type?) is
846
if slot? then
847
_mark_pack_parameter(slot.arguments[0])
848
fi
849
si
850
851
_mark_pack_parameter(type: Type?) is
852
if type? /\ type.is_function_generic_argument then
853
type.symbol.set_is_argument_pack(true)
854
fi
855
si
856
857
// Shared body for the concrete Function kinds. Reproduces the
858
// signature shape `{qname}{[gen,args]}({name}: {type}, …)` +
859
// optional ` -> {return_type}` — no trailing classifier; that
860
// lives on `describe_kind`. The `(...)` argument list is a
861
// WRAPPABLE so the DOC hover renderer can break it across
862
// lines; the generic `[]` bracket is not wrappable.
863
_describe_function(
864
context: DESCRIBE_CONTEXT,
865
include_return_type: bool
866
) -> SignaturePart is
867
let parts = Collections.LIST[SignaturePart]()
868
parts.add(PARTS.name(self))
869
parts.add(_describe_generic_arguments())
870
parts.add(_describe_arguments(context))
871
if include_return_type /\ return_type? then
872
parts.add(PARTS.literal(" -> "))
873
parts.add(_describe_return_type())
874
fi
875
return SignaturePart.SEQUENCE(parts)
876
si
877
878
_describe_generic_arguments() -> SignaturePart is
879
if generic_arguments.count == 0 then
880
return PARTS.nil()
881
fi
882
let items = Collections.LIST[SignaturePart]()
883
for t in generic_arguments do
884
// The `..` marker belongs to the declaration, so it is
885
// written here rather than by the type's own rendering,
886
// which also answers wherever the parameter is used.
887
if t.symbol.is_argument_pack then
888
items.add(PARTS.sequence([PARTS.type_ref(t), PARTS.literal("..")]))
889
else
890
items.add(PARTS.type_ref(t))
891
fi
892
od
893
return SignaturePart.WRAPPABLE("[", ",", true, "]", items)
894
si
895
896
_describe_arguments(context: DESCRIBE_CONTEXT) -> SignaturePart is
897
let items = Collections.LIST[SignaturePart]()
898
for i in 0..arguments.count do
899
items.add(PARTS.sequence([
900
PARTS.literal("{argument_names[i]}: "),
901
_describe_argument_type(i)
902
]))
903
od
904
return SignaturePart.WRAPPABLE("(", ",", false, ")", items)
905
si
906
907
// A formal declared to take an argument pack spread out is
908
// written `f: T.. -> U`, and the marker sits on the parameter of
909
// its own function type - which the type's own rendering knows
910
// nothing about, so the two halves are written out here.
911
_describe_argument_type(index: int) -> SignaturePart is
912
if !get_argument_is_pack(index) then
913
return PARTS.type_ref(arguments[index])
914
fi
915
916
return _describe_pack_marked_type(arguments[index], get_argument_pack_depth(index))
917
si
918
919
// A return type that carries the marker reads the same way.
920
_describe_return_type() -> SignaturePart is
921
if return_pack_depth < 0 then
922
return PARTS.type_ref(return_type!)
923
fi
924
925
return _describe_pack_marked_type(return_type!, return_pack_depth)
926
si
927
928
_describe_pack_marked_type(type: Type, depth: int) -> SignaturePart is
929
let slot = Semantic.ARGUMENT_PACK.marked_slot(type, depth)
930
931
if !slot? then
932
return PARTS.type_ref(type)
933
fi
934
935
let parts = Collections.LIST[SignaturePart]()
936
937
// The hops the marker sits behind read as they always do;
938
// only the one it was written on carries the marker.
939
let hop mut = type
940
941
for _ in 0..depth do
942
parts.add(_describe_function_parameters(hop))
943
parts.add(PARTS.literal(" -> "))
944
945
hop = hop.arguments[hop.arguments.count - 1]
946
od
947
948
// The pack is the last parameter; any before it are the
949
// function type's own, and the list is parenthesised as it is
950
// written.
951
let fixed = Semantic.ARGUMENT_PACK.fixed_count(slot)
952
953
if fixed > 0 then
954
parts.add(PARTS.literal("("))
955
956
for i in 0..fixed do
957
parts.add(PARTS.type_ref(slot.arguments[i]))
958
parts.add(PARTS.literal(", "))
959
od
960
fi
961
962
parts.add(PARTS.type_ref(slot.arguments[fixed]))
963
parts.add(PARTS.literal(if fixed > 0 then "..) -> " else ".. -> " fi))
964
965
if slot.is_action then
966
parts.add(PARTS.literal("void"))
967
else
968
parts.add(PARTS.type_ref(slot.arguments[fixed + 1]))
969
fi
970
971
if slot.is_pure_function then
972
parts.add(PARTS.literal(" pure"))
973
fi
974
975
return SignaturePart.SEQUENCE(parts)
976
si
977
978
// The parameter half of a function type, parenthesised wherever
979
// it is not the single parameter that needs no parentheses.
980
_describe_function_parameters(type: Type) -> SignaturePart is
981
let count =
982
if type.is_action then
983
type.arguments.count
984
else
985
type.arguments.count - 1
986
fi
987
988
let items = Collections.LIST[SignaturePart]()
989
990
for i in 0..count do
991
items.add(PARTS.type_ref(type.arguments[i]))
992
od
993
994
if count == 1 then
995
return items[0]
996
fi
997
998
return SignaturePart.WRAPPABLE("(", ",", false, ")", items)
999
si
1000
1001
overriders: Collections.Iterable[Symbol]? => _overriders
1002
overridees: Collections.Iterable[Symbol]? => _overridees
1003
1004
has_overridees: bool => _overridees? /\ _overridees.count > 0
1005
1006
// Attribute pragmas resolved onto a parameter (`@Foo() name: T`).
1007
// A parameter's own symbol is a member of its owning function's
1008
// scope regardless of function kind, so this reaches it the
1009
// same way for a named function, a delegate/anon-func closure,
1010
// or a frame-boxed capturing closure.
1011
// argument_defaults is supplied by whichever route declared the
1012
// function - reflection for an imported one, resolve-explicit-
1013
// types for one written in source.
1014
@suppress("field-definite-assignment")
1015
init(location: LOCATION, span: LOCATION, owner: Scope, name: string, enclosing_scope: Scope) is
1016
super.init(location, owner, name, enclosing_scope)
1017
1018
self.span = span
1019
1020
_arguments = Collections.LIST[Type](0)
1021
argument_names = Collections.LIST[string](0)
1022
generic_arguments = Collections.LIST[Type](0)
1023
generic_argument_names = Collections.LIST[string](0)
1024
generic_argument_constraint_kinds = Collections.LIST[TypeParameterConstraintKind](0)
1025
generic_argument_has_constructor_constraint = Collections.LIST[bool](0)
1026
argument_is_pack = Collections.LIST[bool](0)
1027
argument_pack_depth = Collections.LIST[int](0)
1028
spread_argument_index = -1
1029
return_pack_depth = -1
1030
generic_argument_type_bounds = Collections.LIST[Collections.LIST[Type]](0)
1031
1032
// A type's `=~` maps to .NET `Equals` for interop, and is
1033
// matched to what it overrides by that name. A global `=~`
1034
// operator keeps its own name, or it comes back from
1035
// reflection as `equals` and no longer resolves.
1036
if name =~ "=~" /\ isa Classy(owner) then
1037
il_name_override = "Equals"
1038
fi
1039
1040
type = Types.NAMED(self)
1041
si
1042
1043
set_arguments(argument_names: Collections.List[string], argument_types: Collections.List[Type]) is
1044
self.arguments = argument_types
1045
1046
assert argument_names |> all(a => a?) else "setting an argument name to null for {name} (B)"
1047
1048
self.argument_names = argument_names
1049
si
1050
1051
add_overrider(overrider: Symbol mut) is
1052
let rsf = root_specialized_from
1053
if rsf != self then
1054
rsf.add_overrider(overrider)
1055
return
1056
fi
1057
1058
let overriders mut = _overriders
1059
1060
if !overriders? then
1061
overriders = Collections.LIST[Symbol]()
1062
_overriders = overriders
1063
fi
1064
1065
overrider = overrider.root_specialized_from
1066
1067
if overriders.contains(overrider) then
1068
return
1069
fi
1070
1071
overriders.add(overrider)
1072
1073
if let journal = INHERITANCE_JOURNAL.current then
1074
journal.record(InheritanceOp.FUNCTION_OVERRIDER_ADDED(self, overrider))
1075
fi
1076
si
1077
1078
remove_overrider(overrider: Symbol) is
1079
let rsf = root_specialized_from
1080
if rsf != self then
1081
rsf.remove_overrider(overrider)
1082
return
1083
fi
1084
1085
let overriders = _overriders
1086
1087
if overriders? then
1088
overriders.remove(overrider.root_specialized_from)
1089
fi
1090
si
1091
1092
add_overridee(overridee: Symbol mut) is
1093
let rsf = root_specialized_from
1094
if rsf != self then
1095
rsf.add_overridee(overridee)
1096
return
1097
fi
1098
1099
let overridees mut = _overridees
1100
1101
if !overridees? then
1102
overridees = Collections.LIST[Symbol]()
1103
_overridees = overridees
1104
fi
1105
1106
overridee = overridee.root_specialized_from
1107
1108
if overridees.contains(overridee) then
1109
return
1110
fi
1111
1112
overridees.add(overridee)
1113
1114
if let journal = INHERITANCE_JOURNAL.current then
1115
journal.record(InheritanceOp.FUNCTION_OVERRIDEE_ADDED(self, overridee))
1116
fi
1117
si
1118
1119
remove_overridee(overridee: Symbol) is
1120
let rsf = root_specialized_from
1121
if rsf != self then
1122
rsf.remove_overridee(overridee)
1123
return
1124
fi
1125
1126
let overridees = _overridees
1127
1128
if overridees? then
1129
overridees.remove(overridee.root_specialized_from)
1130
fi
1131
si
1132
1133
load_self(location: LOCATION, loader: SYMBOL_LOADER) -> Value is
1134
IoC.CONTAINER.instance.logger.error(location, "cannot access instance member from non-instance context")
1135
1136
return IR.Values.DUMMY(Types.ERROR(), location)
1137
si
1138
1139
load_outer_self(location: LOCATION, loader: SYMBOL_LOADER) -> Value? is
1140
IoC.CONTAINER.instance.logger.error(location, "cannot access instance member from non-instance context")
1141
1142
return IR.Values.DUMMY(Types.ERROR(), location)
1143
si
1144
1145
load_captured_value(location: LOCATION, symbol: Variable, loader: SYMBOL_LOADER) -> Value => throw NotImplementedException("{get_type()} cannot load captured value: {symbol} from: {location}")
1146
load_outer_captured_value(location: LOCATION, symbol: Variable, loader: SYMBOL_LOADER) -> Value? => throw NotImplementedException("{get_type()} cannot load outer captured value: {symbol} from: {location}")
1147
store_captured_value(location: LOCATION, symbol: Variable, value: Value, loader: SYMBOL_LOADER) -> Value => throw NotImplementedException("{get_type()} cannot store captured value: {symbol} from: {location}")
1148
start_declaring_arguments() is
1149
_declaring_arguments = true
1150
si
1151
1152
end_declaring_arguments() is
1153
_declaring_arguments = false
1154
si
1155
1156
/*
1157
given a set of actual function argument types, try to infer actual generic argument types by pattern matching formal
1158
argument types (which may contain formal generic argument types) against correspinding actual arguments. Arguments
1159
could be unknown (!!! or ***), which match anything and do not contradict any type inferences we make.
1160
1161
map[T,U](from: Iterable[T], mapper: T -> U) -> Iterable[U]
1162
map([1, 2, 3, 4, 5], x => x + 1)
1163
1164
- the type of [1, 2, ... ] is known to be int[]
1165
- prior type inference should figure out the return type of x => x + 1 must be int (because the only overload
1166
resolution possible for !!! + 1 is int + int -> int) so we'll be called with actual argument types of int[]
1167
and !!! -> int that need to be matched against Iterable[T] and T -> U
1168
1169
- int[] implements Iterable[int] which pattern matches Iterable[T], allowing us to infer that T should be int
1170
- !!! -> int pattern matches T -> U. !!! doesn't contradict a type of int for T, and int implies a type of int for U
1171
1172
so we can return a type map of T = int, U = int
1173
*/
1174
// When LUB widening fired during bind (siblings case), the bound
1175
// type may be wider than any individual arg-derived candidate.
1176
// Re-verify each actual arg still conforms to its parameter type
1177
// with the bound type-args substituted in. Without this check a
1178
// call like structured[T](T, Iterable[T]) with (int, string)
1179
// (or the constructor analogue Box[T] with init(item: T, bag:
1180
// Iterable[T]) called as Box(1, "hello")) would bind
1181
// T = LUB(int, char) = ValueType and silently accept, even
1182
// though `string` is Iterable[char] which (without ghūl's
1183
// variance handling marking Iterable covariant) is not
1184
// Iterable[ValueType] — yielding an InvalidProgramException
1185
// at JIT for the constructor path, or a runtime cast failure.
1186
//
1187
// Only run when LUB actually fired — pairwise widening is
1188
// monotonic in the wider direction and doesn't need re-checking,
1189
// and skipping the check on the happy path avoids triggering
1190
// premature type evaluation on args that aren't yet ready
1191
// (e.g. function literals being passed to higher-order calls).
1192
check_lub_conformance(results: Types.GENERIC_ARGUMENT_BIND_RESULTS, args: Collections.List[Type]) -> bool is
1193
if !results.is_bound \/ !results.used_lub then
1194
return true
1195
fi
1196
1197
let type_map = results.map
1198
for i in 0..args.count do
1199
let specialized_param = arguments[i].specialize(type_map)
1200
if !specialized_param.is_assignable_from(args[i]) then
1201
return false
1202
fi
1203
od
1204
1205
return true
1206
si
1207
1208
try_bind_generic_arguments(location: Source.LOCATION, args: Collections.List[Type]) -> Types.GENERIC_ARGUMENT_BIND_RESULTS? is
1209
// This method binds the *function's* own generic args
1210
// (use try_bind_owner_generic_arguments for the owning
1211
// class's). When the function isn't generic there is
1212
// nothing here to bind — return null. Without this guard
1213
// a non-generic instance method on a generic class
1214
// (e.g. `Box[T].set(value: T)` called on `Box[?]`) would
1215
// proceed to call check_complete with a null
1216
// generic_arguments and NRE inside check_complete.
1217
if !is_generic then
1218
return null
1219
fi
1220
1221
assert args.count == arguments.count else "expected to bind {arguments.count} arguments in {self} but only {args} supplied"
1222
1223
let results = Types.GENERIC_ARGUMENT_BIND_RESULTS(_bindable_type_arguments())
1224
1225
let all_ok = true
1226
1227
for i in 0..args.count do
1228
if !arguments[i].bind_type_variables(args[i], results) then
1229
return null
1230
fi
1231
od
1232
1233
results.check_complete(location, generic_arguments)
1234
1235
if !results.is_bound then
1236
// A wild optional parameter (`T?`) matched a bare null
1237
// actual, which accepts without pinning the type variable.
1238
// Default any such never-pinned variable to object so the
1239
// selected overload is fully specialized; otherwise it
1240
// would emit with a free type parameter (`!!N`) and fail to
1241
// load at run time.
1242
results.default_null_only_unbound(
1243
generic_arguments,
1244
IoC.CONTAINER.instance.innate_symbol_lookup.get_object_type()
1245
)
1246
1247
results.check_complete(location, generic_arguments)
1248
fi
1249
1250
if !check_lub_conformance(results, args) then
1251
return null
1252
fi
1253
1254
// Bound actuals must not carry a method-level type
1255
// parameter that belongs to a different function: its
1256
// `!!N` index is only meaningful inside that function,
1257
// and emitting it at this call site produces an
1258
// unloadable assembly. The caller's own type parameters
1259
// are allowed — their indices are valid in the enclosing
1260
// method.
1261
let caller = IoC.CONTAINER.instance.symbol_table.current_function
1262
1263
if results.contains_function_generic_argument_foreign_to(caller) then
1264
return null
1265
fi
1266
1267
return results
1268
si
1269
1270
// The type arguments a call to this function may pin: its own,
1271
// plus the declaring type's when those are still open. A static
1272
// generic method reached through its declaring class can have
1273
// both inferred from one argument list; reached through a
1274
// constructed type the declaring half is already supplied, and
1275
// the only type variables left in the formals belong to whoever
1276
// wrote the call.
1277
_bindable_type_arguments() -> Collections.List[Types.Type] is
1278
let result = Collections.LIST[Types.Type](generic_arguments)
1279
1280
if let owner_classy = cast Classy?(owner) then
1281
for name in owner_classy.argument_names do
1282
if let argument = owner_classy.find_direct(name) /\ argument.type? then
1283
result.add(argument.type!)
1284
fi
1285
od
1286
fi
1287
1288
return result
1289
si
1290
1291
try_bind_owner_generic_arguments(location: Source.LOCATION, args: Collections.List[Type]) -> Types.GENERIC_ARGUMENT_BIND_RESULTS? is
1292
let owner_classy = cast Classy?(owner)
1293
1294
if !owner_classy? \/ !owner_classy.is_generic then
1295
return null
1296
fi
1297
1298
let results = Types.GENERIC_ARGUMENT_BIND_RESULTS()
1299
1300
for i in 0..args.count do
1301
if !arguments[i].bind_type_variables(args[i], results) then
1302
return null
1303
fi
1304
od
1305
1306
// An owner type argument that no formal mentions cannot be
1307
// bound by pairing formals with actuals, but an actual whose
1308
// bound instantiates the owner has already pinned it.
1309
OWNER_INSTANTIATION_BINDER.bind_unbound_from_actual_instantiations(owner_classy, args, results)
1310
1311
results.check_complete(location, owner_classy.arguments)
1312
1313
if !check_lub_conformance(results, args) then
1314
return null
1315
fi
1316
1317
let caller = IoC.CONTAINER.instance.symbol_table.current_function
1318
1319
if results.contains_function_generic_argument_foreign_to(caller) then
1320
return null
1321
fi
1322
1323
return results
1324
si
1325
1326
specialize_function(type_map: Collections.Map[Symbol,Type], owner: GENERIC?) -> Function is
1327
let result = cast Function?(memberwise_clone())!
1328
1329
result.specialized_from = self
1330
result._override_class = null
1331
1332
if !return_type? then
1333
IoC.CONTAINER.instance.logger.poison(self.location, "specialized with null return type")
1334
else
1335
result.return_type = return_type.specialize(type_map)
1336
fi
1337
1338
if unspecialized_arguments? then
1339
result.unspecialized_arguments = unspecialized_arguments
1340
else
1341
result.unspecialized_arguments = arguments
1342
fi
1343
1344
// Which formals take a pack spread out is a property of the
1345
// declaration, so it survives specialisation - by which point
1346
// the parameter itself has become the tuple it bound to.
1347
result.argument_is_pack = argument_is_pack
1348
result.argument_pack_depth = argument_pack_depth
1349
result.spread_argument_index = spread_argument_index
1350
result.return_pack_depth = return_pack_depth
1351
1352
if unspecialized_return_type? then
1353
result.unspecialized_return_type = unspecialized_return_type
1354
else
1355
result.unspecialized_return_type = return_type
1356
fi
1357
1358
// Pre-sized empty, filled by add: a LIST(arguments) copy would
1359
// duplicate every element only for the loop to replace them.
1360
let ra = Collections.LIST[Type](arguments.count)
1361
1362
result.arguments = ra
1363
1364
for a in arguments do
1365
ra.add(a.specialize(type_map))
1366
od
1367
1368
if generic_arguments.count > 0 then
1369
let specialized_arguments = Collections.LIST[Type](generic_arguments.count)
1370
1371
for ga in generic_arguments do
1372
specialized_arguments.add(ga.specialize(type_map))
1373
od
1374
1375
result.generic_arguments = specialized_arguments
1376
fi
1377
1378
// owner is absent for owner-less functions
1379
@suppress("presence-test-non-optional")
1380
if owner? then
1381
if result.owner == owner.unspecialized_symbol then
1382
result.owner = owner
1383
elif result.owner != owner then
1384
result.owner = result.owner!.type!.specialize(owner.type_map).symbol
1385
else
1386
Std.error.write_line("{result} is already owned by {owner}")
1387
fi
1388
fi
1389
1390
return result
1391
si
1392
1393
specialize(type_map: Collections.Map[Symbol,Type], owner: GENERIC) -> Symbol =>
1394
specialize_function(type_map, owner)
1395
1396
get_argument_constraint_kind(index: int) -> TypeParameterConstraintKind is
1397
if index >= 0 /\ index < generic_argument_constraint_kinds.count then
1398
return generic_argument_constraint_kinds[index]
1399
fi
1400
1401
if index >= 0 /\ index < generic_argument_names.count then
1402
let argument = find_direct(generic_argument_names[index])
1403
1404
if argument? then
1405
return argument.constraint_kind
1406
fi
1407
fi
1408
1409
return TypeParameterConstraintKind.NONE
1410
si
1411
1412
// Whether the formal at `index` takes an argument pack spread
1413
// out. False for every function that declares no pack.
1414
get_argument_is_pack(index: int) -> bool =>
1415
index >= 0 /\ index < argument_is_pack.count /\ argument_is_pack[index]
1416
1417
// How many returns into the formal at `index` the pack marker
1418
// sits. Zero wherever the depth was never recorded, which is
1419
// the formal's own type and what every pack meant before the
1420
// marker could be written deeper.
1421
get_argument_pack_depth(index: int) -> int =>
1422
if index >= 0 /\ index < argument_pack_depth.count then
1423
argument_pack_depth[index]
1424
else
1425
0
1426
fi
1427
1428
// Whether this function absorbs a call's remaining arguments
1429
// into a pack's tuple.
1430
has_spread_argument: bool => spread_argument_index >= 0
1431
1432
get_argument_has_constructor_constraint(index: int) -> bool is
1433
if index >= 0 /\ index < generic_argument_has_constructor_constraint.count then
1434
return generic_argument_has_constructor_constraint[index]
1435
fi
1436
1437
if index >= 0 /\ index < generic_argument_names.count then
1438
let argument = find_direct(generic_argument_names[index])
1439
1440
if argument? then
1441
return argument.has_constructor_constraint
1442
fi
1443
fi
1444
1445
return false
1446
si
1447
1448
// The bounds (`[T: A /\ B]`) of the method-level type parameter at
1449
// `index`, empty when unbounded. Imported methods carry them in
1450
// `generic_argument_type_bounds`; ghūl-declared methods carry them
1451
// on the parameter symbol as its ancestors, with the meaningless
1452
// `object` default bound dropped.
1453
get_argument_type_bounds(index: int) -> Collections.List[Type] is
1454
if index >= 0 /\ index < generic_argument_type_bounds.count then
1455
return generic_argument_type_bounds[index]
1456
fi
1457
1458
if index >= 0 /\ index < generic_argument_names.count then
1459
let argument = find_direct(generic_argument_names[index])
1460
1461
if argument? /\ argument.is_type_variable then
1462
let result = Collections.LIST[Type](0)
1463
1464
for ancestor in argument.ancestors do
1465
if !ancestor.is_object then
1466
result.add(ancestor)
1467
fi
1468
od
1469
1470
return result
1471
fi
1472
fi
1473
1474
return Collections.LIST[Type](0)
1475
si
1476
1477
try_specialize(
1478
location: LOCATION,
1479
logger: Logger,
1480
actual_type_arguments: Collections.List[Type]
1481
) -> Symbol? is
1482
if !is_generic then
1483
logger.error(location, "cannot explicitly specialize non-generic type")
1484
return null
1485
elif actual_type_arguments.count != generic_argument_names.count then
1486
logger.error(location, "expected {generic_argument_names.count} explicit generic type arguments")
1487
return null
1488
fi
1489
1490
GENERIC_CONSTRAINT_CHECKER().check_arguments(
1491
location,
1492
logger,
1493
self,
1494
generic_argument_names,
1495
actual_type_arguments
1496
)
1497
1498
return specialize(actual_type_arguments)
1499
si
1500
1501
// The declared type parameter at `index`. A function's own
1502
// formals are written in terms of these symbols, so a
1503
// substitution map has to be keyed on them. A reflected generic
1504
// method declares none into its scope and carries them
1505
// positionally instead, where the mapped type's symbol is the
1506
// same one its formals mention.
1507
_type_parameter_at(index: int) -> GenericArgument? is
1508
if index < 0 \/ index >= generic_argument_names.count then
1509
return null
1510
fi
1511
1512
if let declared = find_direct(generic_argument_names[index]) then
1513
return cast GenericArgument?(declared)
1514
fi
1515
1516
if index < generic_arguments.count then
1517
return cast GenericArgument?(generic_arguments[index].symbol)
1518
fi
1519
1520
return null
1521
si
1522
1523
specialize(actual_type_arguments: Collections.List[Type]) -> Symbol is
1524
assert is_generic else "trying to specialize non generic function {qualified_name}"
1525
1526
let type_map = Collections.MAP[Symbol,Type]()
1527
1528
for (index, value) in actual_type_arguments |> index() do
1529
let parameter = _type_parameter_at(index)
1530
1531
assert parameter? else
1532
"function '{qualified_name}' has no type parameter at {index}"
1533
1534
type_map[parameter] = value
1535
od
1536
1537
let result = specialize_function(type_map, null)
1538
1539
if result.is_generic then
1540
result.is_generic = false
1541
fi
1542
1543
return result
1544
si
1545
1546
set_void_return_type() is
1547
return_type = IoC.CONTAINER.instance.innate_symbol_lookup.get_void_type()
1548
si
1549
1550
set_return_type(rt: Type?) is
1551
return_type = rt
1552
1553
if rt? /\ are_arguments_declared then
1554
if arguments.count > Lookups.INNATE_TYPE_LIMITS.MAX_FUNCTION_PARAMETERS then
1555
IoC.CONTAINER.instance.logger.error(
1556
location,
1557
"a function literal cannot have more than {Lookups.INNATE_TYPE_LIMITS.MAX_FUNCTION_PARAMETERS} parameters")
1558
1559
type = Types.ERROR()
1560
else
1561
type = IoC.CONTAINER.instance.innate_symbol_lookup.get_function_type(
1562
arguments |> cat([rt]) |> collect_mutable()
1563
)
1564
fi
1565
else
1566
type = Types.ERROR()
1567
fi
1568
1569
type_updated(type!)
1570
si
1571
1572
type_updated(type: Type) is
1573
// override me
1574
si
1575
1576
get_full_type(innate_symbol_lookup: Lookups.InnateSymbolLookup) -> Types.Type is
1577
if arguments.count > Lookups.INNATE_TYPE_LIMITS.MAX_FUNCTION_PARAMETERS then
1578
IoC.CONTAINER.instance.logger.error(
1579
location,
1580
"a function with more than {Lookups.INNATE_TYPE_LIMITS.MAX_FUNCTION_PARAMETERS} parameters cannot be used as a value")
1581
1582
return Types.ERROR()
1583
fi
1584
1585
let types = Collections.LIST[Type](arguments.count + 1)
1586
1587
types.add_range(arguments)
1588
types.add(return_type!)
1589
1590
// A store-free function referred to as a value is a value
1591
// of the pure shape of its type — the property belongs to
1592
// the function, not to the slot it is being read into.
1593
let is_pure = is_proven_store_free
1594
1595
// A proof still to come can change this answer; see
1596
// KILL_LEDGER.record_purity_read.
1597
if !is_store_free /\ !is_reflected then
1598
Syntax.Process.KILL_LEDGER.record_purity_read(self, is_pure)
1599
fi
1600
1601
return innate_symbol_lookup.get_function_type(types, is_pure)
1602
si
1603
1604
try_override(into: Classy, function: Function, logger: Logger) is
1605
logger.error(location, "cannot override {function}", function.location, "declared here")
1606
si
1607
1608
try_instance_override_me(into: Classy, function: Function, logger: Logger) is
1609
logger.error(function.location, "cannot be overridden by {function}", location, "overridden declaration")
1610
si
1611
1612
try_struct_override_me(into: Classy, function: Function, logger: Logger) is
1613
logger.error(function.location, "cannot be overridden by {function}", location, "overridden declaration")
1614
si
1615
1616
try_abstract_override_me(into: Classy, function: Function, logger: Logger) is
1617
logger.error(function.location, "cannot be overridden by {function}", location, "overridden declaration")
1618
si
1619
1620
// What every cell does once it has decided the declaration in
1621
// front of it really is an override of this member: check what
1622
// an implementation is held to, and record the relation both
1623
// ways so everything downstream - the contracts, the editor,
1624
// the covariant-return slot - can see it.
1625
record_implementing_override(into: Classy, overrider: Function, logger: Logger) is
1626
let return_type_matches = overrider.ensure_return_type_matches(into, self, false, logger)
1627
1628
overrider.ensure_arguments_accept_optionals(into, self, false, logger)
1629
1630
let il_name_matches = overrider.ensure_il_name_matches(into, self, "implement", logger)
1631
1632
overrider.add_overridee(self)
1633
self.add_overrider(overrider)
1634
si
1635
1636
inheritance_warn(logger: Logger, into: Classy, code: string, message: string) is
1637
if owner == into then
1638
logger.warn(location, code, message)
1639
else
1640
logger.warn(into.location, code, "{self} {message}")
1641
fi
1642
si
1643
1644
inheritance_error(logger: Logger, into: Classy, message: string) is
1645
if owner == into then
1646
logger.error(location, message)
1647
else
1648
logger.error(into.location, "{self} {message}")
1649
fi
1650
si
1651
1652
// Whether this function's return type is a narrower reference type
1653
// than the one it overrides or implements. Such a member takes the
1654
// overridden slot even though its emitted signature differs, so a
1655
// caller holding the declaring type reaches it. Only references
1656
// qualify: a value type differs in representation from the type it
1657
// narrows, so no one method can answer both signatures.
1658
has_covariant_return_over(overridee: Function) -> bool is
1659
let own = return_type
1660
let overridden = _return_type_of(overridee)
1661
1662
if !own? \/ !overridden? then
1663
return false
1664
fi
1665
1666
if own.matches(overridden) then
1667
return false
1668
fi
1669
1670
if
1671
own.is_value_type \/ overridden.is_value_type \/
1672
own.is_type_variable \/ overridden.is_type_variable
1673
then
1674
return false
1675
fi
1676
1677
return overridden.is_assignable_from(own)
1678
si
1679
1680
// What `overridee` returns, read in this function's own type
1681
// parameters: two declarations of one generic method name the
1682
// same position by different symbols.
1683
_return_type_of(overridee: Function) -> Types.Type? is
1684
if let overridden = overridee.return_type then
1685
return
1686
GENERIC_PARAMETER_ALIGNMENT.rewrite(
1687
overridden, generic_arguments, overridee.generic_arguments)
1688
fi
1689
1690
return null
1691
si
1692
1693
/// Whether this function's return type lets it override `overridee`:
1694
/// the same type, or a narrower reference type.
1695
///
1696
/// - overridee: the inherited member
1697
has_overriding_return_type(overridee: Function) -> bool =>
1698
if let own = return_type, overridden = _return_type_of(overridee) then
1699
own.matches(overridden) \/ has_covariant_return_over(overridee)
1700
else
1701
true
1702
fi
1703
1704
ensure_return_type_matches(into: Classy, overridee: Function, want_override: bool, logger: Logger) -> bool is
1705
if !into.is_reflected then
1706
if
1707
!return_type!.matches(_return_type_of(overridee)!) /\
1708
!has_covariant_return_over(overridee)
1709
then
1710
inheritance_error(logger, into, "does not {override_verb(want_override)} {overridee} due to different return type {return_type}")
1711
1712
return false
1713
fi
1714
1715
// Optionality is not part of the emitted signature, so a
1716
// method whose return type differs from its overridee's
1717
// only in optionality overrides it at run time regardless.
1718
// Widening the return to optional would let null reach
1719
// callers typed by the overridee. Internal functions are
1720
// property accessors, reported at the property level;
1721
// reflected overriders are imported declarations the user
1722
// cannot change, so they are not reported at all.
1723
if !is_internal /\ !is_reflected /\ return_type!.is_optional /\ !overridee.return_type!.is_optional then
1724
inheritance_error(logger, into, "cannot {override_verb(want_override)} {overridee} with optional return type {return_type}")
1725
fi
1726
fi
1727
1728
return true
1729
si
1730
1731
// Arguments compare optionality-blind for override matching, so an
1732
// overriding method can redeclare an optional argument as
1733
// non-optional - but it still receives callers' optional values
1734
// through the overridden signature, so that narrowing is unsound.
1735
ensure_arguments_accept_optionals(into: Classy, overridee: Function, want_override: bool, logger: Logger) is
1736
if into.is_reflected \/ is_reflected \/ is_internal \/ arguments.count != overridee.arguments.count then
1737
return
1738
fi
1739
1740
// The equality and order operators are exempt: an absent
1741
// operand is answered by the null checks the operator's
1742
// own lowering writes around the call, so a body declared
1743
// non-optional is only handed present values however the
1744
// overridden member spells its parameter. That makes the
1745
// non-optional spelling honest for an implementation, and
1746
// lets one implementation shape satisfy Ghul.Equatable
1747
// and Ghul.Comparable however their type argument renders.
1748
if name =~ "=~" \/ name =~ "<>" then
1749
return
1750
fi
1751
1752
for i in 0..arguments.count do
1753
// An optional type variable is exempt: an unconstrained
1754
// type parameter cannot be spelled optional in source, so
1755
// the signature this would demand is unwritable. Reflected
1756
// generic interfaces declare such arguments routinely
1757
// (IComparer, IEqualityComparer).
1758
if
1759
overridee.arguments[i].is_optional /\
1760
!overridee.arguments[i].is_type_variable /\
1761
!arguments[i].is_optional
1762
then
1763
inheritance_error(logger, into, "cannot {override_verb(want_override)} {overridee}: argument {i + 1} must be optional")
1764
fi
1765
od
1766
si
1767
1768
override_verb(want_override: bool) -> string static =>
1769
if want_override then "override" else "implement" fi
1770
1771
ensure_il_name_matches(into: Classy, overridee: Function, override_type: string, logger: Logger) -> bool is
1772
if il_name !~ overridee.il_name then
1773
if il_name_override? then
1774
logger.warn(
1775
location,
1776
"override-mismatch-il-name",
1777
"does not {override_type} {overridee} due to inconsistent IL names ({il_name} vs {overridee.il_name})",
1778
overridee.location,
1779
"overridden member declared here")
1780
return false
1781
else
1782
il_name_override = overridee.il_name
1783
1784
if let journal = INHERITANCE_JOURNAL.current then
1785
journal.record(InheritanceOp.IL_NAME_SET(self))
1786
fi
1787
fi
1788
fi
1789
1790
return true
1791
si
1792
1793
declare_type(location: LOCATION, name: string, index: int, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is
1794
let result = FUNCTION_GENERIC_ARGUMENT(location, self, name, index)
1795
1796
declare(location, result, symbol_definition_listener)
1797
1798
return result
1799
si
1800
1801
declare_closure_symbol(location: LOCATION, result: Closure) -> Symbol is
1802
declare(location, result, null)
1803
1804
return result
1805
si
1806
1807
declare_variable(location: LOCATION, name: string, is_static: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is
1808
let result: Variable =
1809
if _declaring_arguments then
1810
Symbols.LOCAL_ARGUMENT(location, self, name)
1811
else
1812
Symbols.LOCAL_VARIABLE(location, self, name)
1813
fi
1814
1815
declare(location, result, symbol_definition_listener)
1816
1817
return result
1818
si
1819
1820
declare_function(location: LOCATION, span: LOCATION, name: string, is_static: bool, is_private: bool, has_body: bool, is_property_accessor: bool, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is
1821
let result = Symbols.GLOBAL_FUNCTION(location, span, self, name, enclosing)
1822
1823
declare_function_group(location, result, symbol_definition_listener)
1824
1825
return result
1826
si
1827
1828
get_argument_description(index: int) -> string is
1829
let result = System.Text.StringBuilder()
1830
1831
result
1832
.append(argument_names[index])
1833
.append(": ")
1834
.append(_argument_type_description(index, false))
1835
1836
return result.to_string()
1837
si
1838
1839
// A formal declared to take an argument pack spread out is
1840
// written `f: T.. -> U`, and the marker sits on the parameter of
1841
// its own function type - which the type's own rendering knows
1842
// nothing about, so the two halves are written out here.
1843
_argument_type_description(index: int, short: bool) -> string is
1844
let type = arguments[index]
1845
1846
if !get_argument_is_pack(index) then
1847
return if short then type.short_description else "{type}" fi
1848
fi
1849
1850
return _pack_marked_type_description(type, get_argument_pack_depth(index), short)
1851
si
1852
1853
_return_type_description(short: bool) -> string is
1854
let type = return_type!
1855
1856
if return_pack_depth < 0 then
1857
return if short then type.short_description else "{type}" fi
1858
fi
1859
1860
return _pack_marked_type_description(type, return_pack_depth, short)
1861
si
1862
1863
_pack_marked_type_description(type: Type, depth: int, short: bool) -> string is
1864
let slot = Semantic.ARGUMENT_PACK.marked_slot(type, depth)
1865
1866
if !slot? then
1867
return if short then type.short_description else "{type}" fi
1868
fi
1869
1870
let result = System.Text.StringBuilder()
1871
1872
let hop mut = type
1873
1874
for _ in 0..depth do
1875
result.append(_function_parameters_description(hop, short)).append(" -> ")
1876
1877
hop = hop.arguments[hop.arguments.count - 1]
1878
od
1879
1880
// The pack is the last parameter; any before it are the
1881
// formal's own, and the list is parenthesised as it is written.
1882
let fixed = Semantic.ARGUMENT_PACK.fixed_count(slot)
1883
1884
let parameter = slot.arguments[fixed]
1885
1886
let returns =
1887
if slot.is_action then
1888
"void"
1889
elif short then
1890
slot.arguments[fixed + 1].short_description
1891
else
1892
"{slot.arguments[fixed + 1]}"
1893
fi
1894
1895
let purity = if slot.is_pure_function then " pure" else "" fi
1896
1897
if fixed > 0 then
1898
result.append("(")
1899
1900
for i in 0..fixed do
1901
let leading = slot.arguments[i]
1902
1903
result.append(if short then leading.short_description else "{leading}" fi).append(", ")
1904
od
1905
fi
1906
1907
result.append(if short then parameter.short_description else "{parameter}" fi)
1908
result.append("..")
1909
1910
if fixed > 0 then
1911
result.append(")")
1912
fi
1913
1914
result.append(" -> ").append(returns).append(purity)
1915
1916
return result.to_string()
1917
si
1918
1919
_function_parameters_description(type: Type, short: bool) -> string is
1920
let count =
1921
if type.is_action then
1922
type.arguments.count
1923
else
1924
type.arguments.count - 1
1925
fi
1926
1927
let result = System.Text.StringBuilder()
1928
1929
if count != 1 then
1930
result.append("(")
1931
fi
1932
1933
for i in 0..count do
1934
if i > 0 then
1935
result.append(", ")
1936
fi
1937
1938
let argument = type.arguments[i]
1939
1940
result.append(if short then argument.short_description else "{argument}" fi)
1941
od
1942
1943
if count != 1 then
1944
result.append(")")
1945
fi
1946
1947
return result.to_string()
1948
si
1949
1950
get_short_argument_description(index: int) -> string is
1951
let result = System.Text.StringBuilder()
1952
1953
result
1954
.append(argument_names[index])
1955
.append(": ")
1956
.append(_argument_type_description(index, true))
1957
1958
return result.to_string()
1959
si
1960
1961
is_indexer_accessor: bool => INDEXER_NAMES.is_canonical(name)
1962
1963
// The element type an indexer reads or writes: the return type of
1964
// the read accessor, and the value parameter of the write one,
1965
// whose own return type is void.
1966
indexer_value_type: Type? =>
1967
if name =~ INDEXER_NAMES.assign then
1968
if arguments.count > 1 then arguments[1] else null fi
1969
else
1970
return_type
1971
fi
1972
1973
// `OWNER[index: I]: E`, with `= value` on the write accessor. The
1974
// caller supplies both renderings so the long and short forms
1975
// differ only in how their types are described.
1976
render_indexer_shape(index_description: string, value_description: string) -> string is
1977
let result = "{_display_owner_name}[{index_description}]: {value_description}"
1978
1979
if name =~ INDEXER_NAMES.assign /\ argument_names.count > 1 then
1980
return "{result} = {argument_names[1]}"
1981
fi
1982
1983
return result
1984
si
1985
1986
_display_owner_name: string is
1987
let o = owner
1988
1989
if isa Symbol(o) then
1990
return IoC.CONTAINER.instance.name_display.name_for(o)
1991
fi
1992
1993
return o!.qualified_name
1994
si
1995
1996
to_string() -> string is
1997
let result = System.Text.StringBuilder()
1998
1999
try
2000
if name.starts_with("$get_") then
2001
result
2002
.append(_display_owner_name)
2003
.append(".")
2004
.append(name.substring(5))
2005
.append(": ")
2006
.append(return_type)
2007
elif name.starts_with("$set_") then
2008
result
2009
.append(_display_owner_name)
2010
.append(".")
2011
.append(name.substring(5))
2012
.append(": ")
2013
.append(return_type)
2014
.append(" = ")
2015
.append(argument_names[0])
2016
elif is_indexer_accessor then
2017
result
2018
.append(
2019
render_indexer_shape(
2020
"{argument_names[0]}: {arguments[0]}",
2021
"{indexer_value_type}"
2022
)
2023
)
2024
else
2025
result
2026
.append(IoC.CONTAINER.instance.name_display.name_for(self))
2027
.append(generic_argument_descriptions)
2028
.append("(")
2029
.append(short_argument_descriptions)
2030
.append(") -> ")
2031
.append(_return_type_description(false))
2032
fi
2033
2034
return result.to_string()
2035
catch ex: Exception
2036
return "[garbled function: {result}]"
2037
yrt
2038
si
2039
si
2040
2041
class GLOBAL_FUNCTION: Function is
2042
is_public_readable: bool => !emit_assembly
2043
2044
describe(context: DESCRIBE_CONTEXT) -> SignaturePart =>
2045
_describe_function(context, true)
2046
2047
describe_kind(context: DESCRIBE_CONTEXT) -> string? =>
2048
"{pure_prefix}global function"
2049
2050
// Set by the .NET importer when the symbol is read back from a
2051
// referenced assembly: the carrier class the method is a static
2052
// member of, which a call site's methodref hangs off. A namespace
2053
// can have several carriers, so the carrier is recorded rather
2054
// than derived from the namespace.
2055
il_carrier: Classy? public
2056
2057
// Set for an underscore-prefixed global (or the accessor of an
2058
// underscore-prefixed global property) under the private/protected
2059
// policy: emit assembly rather than public so it is hidden from other
2060
// assemblies while staying reachable within this one. Globals live on
2061
// the synthetic $globals class, so declaring-class-private is
2062
// meaningless for them; assembly-internal is the whole effect.
2063
emit_assembly: bool public
2064
2065
init(location: LOCATION, span: LOCATION, owner: Scope, name: string, enclosing_scope: Scope) is
2066
super.init(location, span, owner, name, enclosing_scope)
2067
si
2068
2069
declare_closure(location: LOCATION, name: string, owner: Scope, enclosing: Scope, is_recursive: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol =>
2070
declare_closure_symbol(location, Symbols.GLOBAL_CLOSURE(location, owner, name, enclosing, is_recursive))
2071
2072
declare_async_closure(location: LOCATION, name: string, owner: Scope, enclosing: Scope, is_recursive: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol =>
2073
declare_closure_symbol(location, Symbols.GLOBAL_ASYNC_CLOSURE(location, owner, name, enclosing, is_recursive))
2074
2075
2076
declare_generator_closure(location: LOCATION, name: string, owner: Scope, enclosing: Scope, is_recursive: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol =>
2077
declare_closure_symbol(location, Symbols.GLOBAL_GENERATOR_CLOSURE(location, owner, name, enclosing, is_recursive))
2078
2079
load(location: LOCATION, from: IR.Values.Value?, loader: SYMBOL_LOADER) -> IR.Values.Value is
2080
if from? /\ from.is_consumable then
2081
IoC.CONTAINER.instance.logger.poison(location, "global function load shouldn't have a left expression")
2082
fi
2083
2084
return loader.load_global_function(self)
2085
si
2086
2087
call(location: Source.LOCATION, from: IR.Values.Value?, arguments: Collections.List[IR.Values.Value], type: Type?, caller: FUNCTION_CALLER) -> IR.Values.Value is
2088
if from? /\ from.is_consumable then
2089
IoC.CONTAINER.instance.logger.poison(location, "global function call shouldn't have a left expression")
2090
fi
2091
2092
return caller.call_global_function(self, arguments, self.arguments, type)
2093
si
2094
si
2095
si