Class SanitizedParameterPrologue

java.lang.Object
org.ek9lang.compiler.phase7.support.SanitizedParameterPrologue

public final class SanitizedParameterPrologue extends Object
THE single source of 'sanitized' parameter cleaning in IR generation - call this, do not re-derive it, and never clean at a call site.

The RECEIVING callable cleans its own parameters: every body the compiler generates (function, method, operator, constructor, program, text method, dynamic function) emits this prologue right after declaring its parameters. Every route into the body - a direct call, an operator, a stream stage, a dispatcher handler, a switch case, a callback from built-in Java code, the command line - therefore arrives cleaned, because there is no route that does not enter the body. Cleaning at call sites could never be complete: a callback from Java has no EK9 call site at all.

For each parameter marked SANITIZED_REQUIRED (the as sanitized String modifier) it emits:

  _tempN = SANITIZE param
  SCOPE_REGISTER _tempN, scope
  STORE param, _tempN

SANITIZE yields the receiver's own copy (+1) of a safe String, or an unset String when a threat is found, so the caller's String is never shared with the callee. The temp is scope-registered, which balances that +1 at scope exit. The parameter is then rebound to the temp with a bare STORE: there is NO RELEASE of the parameter (the caller owns the argument, so releasing it would be a use-after-free on LLVM) and NO RETAIN (the scope registration already owns the copy). This is the only place IR stores to a parameter.

Bodies the compiler synthesises to FORWARD a call (a 'by' delegation, an aspect proxy, a text base, a bodyless dynamic function) must NOT call this: the body they forward to cleans the parameter, and a second prologue would only scan the input twice.

  • Method Details

    • of

      public static List<IRInstr> of(IRGenerationContext stackContext, List<ISymbol> parameters)
      Create the prologue that cleans every SANITIZED_REQUIRED parameter in place, each instruction attributed to the parameter's own declaration. Use this when the body declares the parameters itself. Must be added to the body after the parameters are declared and before anything reads them.
      Parameters:
      stackContext - the IR generation context (temp names + current body scope)
      parameters - the parameters the body declares
      Returns:
      the prologue instructions, empty when no parameter is sanitized
    • of

      public static List<IRInstr> of(IRGenerationContext stackContext, List<ISymbol> parameters, DebugInfo debugInfo)
      Create the prologue with every instruction attributed to debugInfo. Use this when the parameters are declared elsewhere - a dynamic function takes them from its super function, whose declaration may be in another source file (or built in), so its tokens must not become this body's line numbers.
      Parameters:
      stackContext - the IR generation context (temp names + current body scope)
      parameters - the parameters the body declares
      debugInfo - the source location for the prologue
      Returns:
      the prologue instructions, empty when no parameter is sanitized