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);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).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe RETAINS rule saying a call's result is (part of) the object it was called on. -
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 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 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 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:
-
-
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. -
markReturnsReceiverInterior
Record, on a user method or operator, that what it returns is (part of) its receiver.
-