Class StatementOwnedCloseableCalls
java.lang.Object
org.ek9lang.compiler.phase5.StatementOwnedCloseableCalls
- All Implemented Interfaces:
Consumer<org.antlr.v4.runtime.tree.ParseTree>
final class StatementOwnedCloseableCalls
extends Object
implements Consumer<org.antlr.v4.runtime.tree.ParseTree>
THE decision of which calls make a closeable value that the block statement making it OWNS - the unnamed half of
the closeable ownership rule (Steve, 2026-10-05): "A closeable value you never NAME is owned by the statement that
created it and closed when that statement finishes." The named half is
CloseableLocalOrError (E81056).
Given a call site (a call, an operationCall or an operator expression) and the call phase 3
resolved for it - the exact overload - the result is owned by its statement, and the call is marked through
StatementOwnership.mark(CallSymbol), when all of these hold:
- its type is closeable (
CloseableResourceToBeChecked.isManagedCloseableType(ISymbol)); - it runs every time the evaluation that owns it runs (
MustExecutePosition.withinItsEvaluation()): its statement - or, for code in no statement, its returning variable's or property's initialiser, or its text's string - or the nearest CONDITIONALLY evaluated operand it is part of (the right ofand/or/xoror of a coalescing operator, a ternary arm, a laterelse ifcondition, a condition after a guard, the right of:=?, a case expression; Steve, 2026-10-06, lane conditional-closeables: "an unnamed closeable is closed as soon as the evaluation that made it finishes"). When the value IS the result of such a conditional (a ternary arm, either side of a coalescing operator), the test starts from the outermost conditional instead: the arm runs at most once each time it does, and the evaluation that uses the result owns the value, closing it only if it was made; - it is not BORROWED: a constructor's result is always new; otherwise the callee's RETAINS must not say the
result may be its receiver's interior or an argument (
ReturnRetention.mayAlias(ScopedSymbol)), and a callee that cannot be found counts as borrowed; - it is not HANDED ON: stored (declared, assigned, returned, put in a property, a guard or a try resource),
placed in a List or Dict literal, captured by a dynamic function or class, or passed to any constructor (the new
object may keep it - a capture is a constructor argument), or passed as an argument the callee's RETAINS says it
keeps (
ReturnRetention.retainsArgument(ScopedSymbol, int)), or to a callee that cannot be found. A value the statement only CALLS something on - a receiver, an operator's left operand, an interpolated part, a stream source - is not handed on.
The direction is deliberately conservative: anything not recognised counts as handed on, because a value wrongly
kept open is a possible leak and a value wrongly closed is a use-after-close. IR generation only reads the mark
(phase7/generator/StatementOwnedCloseables) and emits the owner and the close; it never decides.
It runs in Walk 3, after ReceiverInteriorReturns has derived the RETAINS of user methods, which the
borrowed test reads.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(org.antlr.v4.runtime.tree.ParseTree callSite) Mark the call made atcallSitewhen its statement owns the closeable value it makes.
-
Constructor Details
-
StatementOwnedCloseableCalls
StatementOwnedCloseableCalls(SymbolsAndScopes symbolsAndScopes)
-
-
Method Details
-
accept
public void accept(org.antlr.v4.runtime.tree.ParseTree callSite) Mark the call made atcallSitewhen its statement owns the closeable value it makes.
-