Class ReturnRetention
CommonValues.RETAINS declaration. Use this wherever a check must know whether the value a call hands back
can be a view of something else; never parse the RETAINS text again.
The built-ins DECLARE it (@Ek9Retains, stamped at bootstrap by OperationFactory); phase 5
DERIVES the same marker, with the same meaning, for a user method or operator that returns one of its own
properties or a view of one (phase5/ReceiverInteriorReturns), so built-ins and user code follow one rule.
The derived value is RECEIVER_INTERIOR, exactly the text a built-in declares.
A result MAY ALIAS when its callee declares any of:
return <- receiver-interior- a view of the receiver (JSON.get,DictEntry.value,Iterator.next);return <- <parameter>- possibly an argument itself (List.getOrDefault'sreturn <- defaultValue; a user function or method that returns a parameter, DERIVED by phase 5 inphase5/ReceiverInteriorReturns);unknown- the inexpressible-retention opt-out, so nothing may be assumed.
It also answers the ARGUMENT half a caller needs: whether the callee may keep one of its arguments
(retainsArgument(ScopedSymbol, int), e.g. List.+='s receiver <- item). Every rule is read through
RetentionRule, which names a parameter by its declared EK9 name - so the rules are matched by FORM,
never by a literal parameter name.
A member of a parameterised type is a substituted copy that may have been made before phase 5 derived the
marker, so the generic's own member is read too (GenericTemplateMember); likewise a parameterised generic
FUNCTION reads the generic function's own marker.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe RETAINS rule saying a call's result is (part of) the object it was called on.static final StringThe DESTINATION of the keep rule of an abstract declaration nothing implements (unimplemented <- item): which implementation will run cannot be known, so it MAY keep the argument - never DEFINITELY (D80 item 3, Steve 2026-10-26). -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<ScopedSymbol> calleeOf(EK9Parser.ExpressionContext expression, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recorded) The method, operator or function an expression CALLS when the whole expression is that call -a.get(k),first(),a + b,(a.get(k))- so its value is whatever the call handed back.static Optional<ScopedSymbol> The method or function a recorded symbol CALLS, when it is a call that hands back a value made elsewhere: a method, operator or function call - never a constructor, whose result is always fresh.static booleandefinitelyKeepsArgument(ScopedSymbol callee, int parameterIndex) Doescalleesay, by an EXPLICIT rule - declared by a built-in or derived for a user callable - that it keeps the argument it is given atparameterIndexsomewhere other than its result? The narrower question thankeepsArgumentBeyondResult(ScopedSymbol, int), which also counts the inexpressibleunknownopt-out: an unnamed closeable given to a callee that DEFINITELY keeps it is E81072; one given to a callee that may is handed on.static booleandefinitelyKeepsReceiver(ScopedSymbol callee) Doescalleesay, by an EXPLICIT rule - declared by a built-in (readyHandler <- receiver) or derived for a user method - that it keeps the object it is called ON beyond the call: stores it in an argument or where nothing here can name it? The receiver's half ofdefinitelyKeepsArgument(ScopedSymbol, int): an unnamed closeable that is the RECEIVER of such a call is E81072 (D80 follow-up, 2026-10-21:Tracked("r").registerIn(kept), whose body isitems += this, closed the receiver and then the list held a closed object).static booleanhandsBackArgument(ScopedSymbol callee, int parameterIndex) May the call hand the argument it is given atparameterIndexback as (part of) its result -return <- <that parameter>? The narrower question thanretainsArgument(ScopedSymbol, int), which also counts an argument kept anywhere else (receiver <- item) and theunknownopt-out: the closeable ownership decision reports a hand-back (E81072) and treats any other keeping as handed on.static booleanisDerived(ScopedSymbol callee) Was the callee's retention DERIVED by phase 5 (a user callable) rather than DECLARED (a built-in's@Ek9Retains)? The closeable ownership decision treats the two differently: a derived link is honoured only where the return type may hold a borrowed view (BorrowedViewReturn).static booleankeepsArgumentBeyondResult(ScopedSymbol callee, int parameterIndex) Maycalleekeep the argument it is given atparameterIndexsomewhere other than its result - into its receiver, another argument, or anywhere (receiver <- item,unknown)? The question a constructor passing its own parameter on asks to know whether the parameter outlives the construction.static booleanMaycalleekeep its receiver beyond the call - an explicit rule, or theunknownopt-out?static voidmarkKeepsParameter(ScopedSymbol callable, String destination, String parameterName) Record, on a user method, operator or function, that the argument given forparameterNamemay be kept beyond the call -<destination> <- parameterName, exactly the text a built-in declares: the destination isreceiver(stored in a property of the object), another parameter's name (added to the object that argument refers to) orambient(held where nothing here can name it: a capture, a returned closure, a call that keeps it).static voidmarkKeepsReceiver(ScopedSymbol callable, String destination) Record, on a user method or operator, that the object it is called on may be kept beyond the call -<destination> <- receiver, exactly the text a built-in declares (HTTP.whenReady'sreadyHandler <- receiver): the destination is another parameter's name (the receiver is stored in what that argument refers to) orambient(held where nothing here can name it: a capture, a returned closure, a call that keeps it).static voidmarkMayKeepEachParameter(ScopedSymbol callable) Record that an abstract declaration nothing implements MAY keep each of its arguments (unimplemented <- <parameter>,UNIMPLEMENTED); the keep counterpart ofmarkReturnsEachParameter(ScopedSymbol).static booleanmarkOverriddenBy(ScopedSymbol declaration, ScopedSymbol override) THE dispatch union (Steve, 2026-10-21, D61): a call throughdeclarationmay runoverride- a method that overrides it, or a function (dynamic functions included) whose super function it is - so the declaration also returns whatever the override does, and keeps whatever the override keeps (the lane callee-keep, 2026-10-21:receiver <- item,<otherParam> <- item,ambient <- item).static voidmarkReturnsEachParameter(ScopedSymbol callable) An abstract declaration no program code implements: which implementation runs cannot be known, so its result may be any of its arguments -return <- <each parameter>.static voidmarkReturnsParameter(ScopedSymbol callable, String parameterName) Record, on a user method, operator or function, that what it returns may be the argument given for the parameterparameterName-return <- parameterName, exactly the text a built-in declares (List.getOrDefault'sreturn <- defaultValue).static voidRecord, on a user method or operator, that what it returns is (part of) its receiver.static booleanmayAlias(ScopedSymbol callee) Does whatcalleereturns possibly share an object with its receiver or an argument.static booleanmayKeepArgument(ScopedSymbol callee, int parameterIndex) The MAY half ofdefinitelyKeepsArgument(ScopedSymbol, int): doescalleesay, by an EXPLICIT rule, that it keeps the argument - or is it an abstract declaration nothing implements, which MAY keep any argument (UNIMPLEMENTED)? An unnamed closeable given to such a callee is E81072 (nothing could close it); a named try resource given to it is allowed.static intparameterIndex(ScopedSymbol callee, String parameterName) The index of the parameterparameterNameofcallee; -1 when it declares none of that name.parametersOf(ScopedSymbol callee) The declared parameters of a method, operator or function; none for anything else.receiverKeptInto(ScopedSymbol callee) The parameterscalleestores its receiver INTO by an explicit rule (items <- receiver, declared or derived): the names of the arguments that end up holding the object it is called on.static booleanretainsArgument(ScopedSymbol callee, int parameterIndex) Maycalleekeep (a reference to) the argument it is given atparameterIndex- into its receiver, another argument, its result or anywhere else (receiver <- item,return <- other, orunknown)? An argument the callee keeps is no longer the caller's alone.static List<org.ek9lang.tooling.construct.RetentionRule> returnRules(ScopedSymbol callee) THE rules saying whatcalleeRETURNS (everyreturn <- sourceit declares or has derived, the generic's own for a parameterisation or a member of one) - for a caller that must map each source back onto the receiver or the argument it names (phase5/ReturnSourceKind.origins).static booleanreturnsReceiverInterior(ScopedSymbol callee) Does whatcalleereturns possibly share an object with its RECEIVER.
-
Field Details
-
RECEIVER_INTERIOR
The RETAINS rule saying a call's result is (part of) the object it was called on.- See Also:
-
UNIMPLEMENTED
The DESTINATION of the keep rule of an abstract declaration nothing implements (unimplemented <- item): which implementation will run cannot be known, so it MAY keep the argument - never DEFINITELY (D80 item 3, Steve 2026-10-26).mayKeepArgument(ScopedSymbol, int)counts it,definitelyKeepsArgument(ScopedSymbol, int)does not, so an unnamed closeable given to it is E81072 (may-keep suffices: nothing could close it) while a named try resource is allowed (E81075 needs a callee that definitely keeps it). Once an implementation exists the rule is not written, and the union over every override (D61) decides.- See Also:
-
-
Method Details
-
calleeOf
The method or function a recorded symbol CALLS, when it is a call that hands back a value made elsewhere: a method, operator or function call - never a constructor, whose result is always fresh. -
calleeOf
public static Optional<ScopedSymbol> calleeOf(EK9Parser.ExpressionContext expression, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recorded) The method, operator or function an expression CALLS when the whole expression is that call -a.get(k),first(),a + b,(a.get(k))- so its value is whatever the call handed back. Empty for a literal, an identifier, a constructor, a dynamic function, a list or dict literal and the control forms.- Parameters:
expression- the expression, as the compiler parsed itrecorded- the recorded-symbol lookup of the phase asking (symbolsAndScopes or parsedModule)
-
mayAlias
Does whatcalleereturns possibly share an object with its receiver or an argument. -
returnsReceiverInterior
Does whatcalleereturns possibly share an object with its RECEIVER. -
retainsArgument
Maycalleekeep (a reference to) the argument it is given atparameterIndex- into its receiver, another argument, its result or anywhere else (receiver <- item,return <- other, orunknown)? An argument the callee keeps is no longer the caller's alone. -
returnRules
THE rules saying whatcalleeRETURNS (everyreturn <- sourceit declares or has derived, the generic's own for a parameterisation or a member of one) - for a caller that must map each source back onto the receiver or the argument it names (phase5/ReturnSourceKind.origins). Theunknownopt-out has no rule to map, so it contributes none. -
parameterIndex
The index of the parameterparameterNameofcallee; -1 when it declares none of that name. -
parametersOf
The declared parameters of a method, operator or function; none for anything else. -
isDerived
Was the callee's retention DERIVED by phase 5 (a user callable) rather than DECLARED (a built-in's@Ek9Retains)? The closeable ownership decision treats the two differently: a derived link is honoured only where the return type may hold a borrowed view (BorrowedViewReturn). -
markReturnsReceiverInterior
Record, on a user method or operator, that what it returns is (part of) its receiver. -
markReturnsParameter
Record, on a user method, operator or function, that what it returns may be the argument given for the parameterparameterName-return <- parameterName, exactly the text a built-in declares (List.getOrDefault'sreturn <- defaultValue). -
markOverriddenBy
THE dispatch union (Steve, 2026-10-21, D61): a call throughdeclarationmay runoverride- a method that overrides it, or a function (dynamic functions included) whose super function it is - so the declaration also returns whatever the override does, and keeps whatever the override keeps (the lane callee-keep, 2026-10-21:receiver <- item,<otherParam> <- item,ambient <- item). Every rule of the override is recorded on the declaration, a parameter named by the declaration's own parameter at the same position. Marks only add.- Returns:
- true when the declaration gained a rule
-
markReturnsEachParameter
An abstract declaration no program code implements: which implementation runs cannot be known, so its result may be any of its arguments -return <- <each parameter>. -
handsBackArgument
May the call hand the argument it is given atparameterIndexback as (part of) its result -return <- <that parameter>? The narrower question thanretainsArgument(ScopedSymbol, int), which also counts an argument kept anywhere else (receiver <- item) and theunknownopt-out: the closeable ownership decision reports a hand-back (E81072) and treats any other keeping as handed on. -
keepsArgumentBeyondResult
Maycalleekeep the argument it is given atparameterIndexsomewhere other than its result - into its receiver, another argument, or anywhere (receiver <- item,unknown)? The question a constructor passing its own parameter on asks to know whether the parameter outlives the construction. -
markKeepsParameter
public static void markKeepsParameter(ScopedSymbol callable, String destination, String parameterName) Record, on a user method, operator or function, that the argument given forparameterNamemay be kept beyond the call -<destination> <- parameterName, exactly the text a built-in declares: the destination isreceiver(stored in a property of the object), another parameter's name (added to the object that argument refers to) orambient(held where nothing here can name it: a capture, a returned closure, a call that keeps it). Derived byphase5/CloseableArgumentKeeping, read bykeepsArgumentBeyondResult(ScopedSymbol, int)anddefinitelyKeepsArgument(ScopedSymbol, int). -
definitelyKeepsArgument
Doescalleesay, by an EXPLICIT rule - declared by a built-in or derived for a user callable - that it keeps the argument it is given atparameterIndexsomewhere other than its result? The narrower question thankeepsArgumentBeyondResult(ScopedSymbol, int), which also counts the inexpressibleunknownopt-out: an unnamed closeable given to a callee that DEFINITELY keeps it is E81072; one given to a callee that may is handed on. -
mayKeepArgument
The MAY half ofdefinitelyKeepsArgument(ScopedSymbol, int): doescalleesay, by an EXPLICIT rule, that it keeps the argument - or is it an abstract declaration nothing implements, which MAY keep any argument (UNIMPLEMENTED)? An unnamed closeable given to such a callee is E81072 (nothing could close it); a named try resource given to it is allowed. Still narrower thankeepsArgumentBeyondResult(ScopedSymbol, int): the inexpressibleunknownopt-out does not answer here. -
markMayKeepEachParameter
Record that an abstract declaration nothing implements MAY keep each of its arguments (unimplemented <- <parameter>,UNIMPLEMENTED); the keep counterpart ofmarkReturnsEachParameter(ScopedSymbol). -
definitelyKeepsReceiver
Doescalleesay, by an EXPLICIT rule - declared by a built-in (readyHandler <- receiver) or derived for a user method - that it keeps the object it is called ON beyond the call: stores it in an argument or where nothing here can name it? The receiver's half ofdefinitelyKeepsArgument(ScopedSymbol, int): an unnamed closeable that is the RECEIVER of such a call is E81072 (D80 follow-up, 2026-10-21:Tracked("r").registerIn(kept), whose body isitems += this, closed the receiver and then the list held a closed object). Theunknownopt-out is not enough: the receiver is then only handed on. A rule storing the receiver in its own property (receiver <- receiver) is not a keep, and the receiver handed back isreturnsReceiverInterior(ScopedSymbol). -
receiverKeptInto
The parameterscalleestores its receiver INTO by an explicit rule (items <- receiver, declared or derived): the names of the arguments that end up holding the object it is called on. Theambientdestination (held where nothing can name it) names no argument and is not listed. A try resource that is the receiver of such a call is asked where that argument was declared (E81075, matrix G14). -
keepsReceiverBeyondResult
Maycalleekeep its receiver beyond the call - an explicit rule, or theunknownopt-out? -
markKeepsReceiver
Record, on a user method or operator, that the object it is called on may be kept beyond the call -<destination> <- receiver, exactly the text a built-in declares (HTTP.whenReady'sreadyHandler <- receiver): the destination is another parameter's name (the receiver is stored in what that argument refers to) orambient(held where nothing here can name it: a capture, a returned closure, a call that keeps it). Derived byphase5/CloseableArgumentKeeping.
-