Class ApplicationClose

java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.ApplicationClose

public final class ApplicationClose extends AbstractGenerator
THE application close (Steve, 2026-10-26, closeable matrix Q3 / row H2): an application closes every component it registered that has an operator close, when the program ends. It is the application's - "if you hold it, you close it" - and an injected x as T! is only a borrow of it (CloseSteps).

It is built into the application's _decommission, which the program ALWAYS runs: on a normal return, on a returned exit code and on an uncaught failure alike (the entry point's protected region). _decommission already takes each registration out of the _Application registry in REVERSE registration order and drops it; for a closeable one the close goes between the two, so the last registered closes first (the Contract 14 order). A component registered once is one object however many places it is injected, so it is closed once.

The close is ResourceCloser's - shape B, Contract 3: each _close() in its own protected region, so one that throws never stops the others; the FIRST EK9 Exception is rethrown from _decommission once every component has been closed and dropped, later ones suppressed onto it; a Panic aborts the closes that remain. Nothing is emitted for an application none of whose components is closeable (isCloseable(RegistrationData)).

Which type is closed through: the type the component is registered AS when that has a close (virtual, so the runtime component's own override runs); otherwise the implementation, reached by a CAST (it is what was constructed). A component registered with aspects is a generated proxy of the registered-as type - not an instance of the implementation - so it is closed through the registered-as type when that has a close, otherwise through the Closeable trait (the generated proxy implements it); either way the proxy forwards close to the delegate, unadvised.

  • Constructor Details

  • Method Details

    • isCloseable

      public static boolean isCloseable(RegistrationData registration)
      True when the application closes this registration at program end.
    • anyCloseable

      public static boolean anyCloseable(List<RegistrationData> registrations)
      True when any of the registrations is closed at program end.
    • newFirstFailure

      public ResourceCloser.FirstFailure newFirstFailure()
      The first-failure slot the closes record into, declared before the first close. Make it where its owner scope is the current one.
    • declare

      public IRInstr declare(ResourceCloser.FirstFailure firstFailure, DebugInfo debugInfo)
    • closeOwned

      public void closeOwned(IRInstructionBuilder builder, String taken, RegistrationData registration, ResourceCloser.FirstFailure firstFailure, DebugInfo debugInfo)
      The close of one registered component that has been taken out of the registry into taken, inside the registration's OWN scope (the caller's IRInstructionBuilder.inNewScope(DebugInfo, Consumer)): that scope owns the component across the close and drops it at its exit, so it is released whether the close returns, records a failure or the region is left by a Panic (V-A: never live and unowned across a call). The close is skipped if the component is absent (a registration that never ran), otherwise CALL taken._close() runs in its own protected region. When it is reached through a CAST the cast takes the count (V-D), so the cast result is what the scope owns and what is closed.
      Parameters:
      builder - the builder whose current scope owns the component
      taken - the variable holding the component the registry gave up
      registration - the registration it came from
      firstFailure - the slot the first close failure is recorded in
      debugInfo - where the close is attributed
    • rethrow

      public List<IRInstr> rethrow(ResourceCloser.FirstFailure firstFailure, DebugInfo debugInfo)
      After every registration has been closed and dropped: rethrow the first close failure, if any.