Class IsFreshValueExpression

java.lang.Object
org.ek9lang.compiler.support.IsFreshValueExpression
All Implemented Interfaces:
Predicate<EK9Parser.ExpressionContext>

public final class IsFreshValueExpression extends Object implements Predicate<EK9Parser.ExpressionContext>
THE "fresh value" predicate: true iff an expression evaluates to a NEW object - one nothing else holds a reference to. Use this wherever a check needs "fresh"; do not write a second definition (the IR's uniqueness lattice, RAILS D.4, is its twin and must keep the same meaning).

Every reading accepts:

  • Literal — string, integer, boolean, etc.
  • Constructor call — a call whose resolved target is a constructor; the call creates a new instance.
  • Either of those in parentheses.

The closeable-return reading (R5, E81057) also accepts a call of a method, operator or function whose DECLARED return type is closeable and whose RETAINS does not say its result may alias its receiver or an argument (ReturnRetention.mayAlias(ScopedSymbol)). Such a callable is itself bound by R5 to return a new instance, so its declaration is the proof - no fixpoint over callees is needed.

The MutexLock reading (E08257, IsFreshValueExpression(SymbolsAndScopes)) stays strict: a call result there is not fresh, because nothing binds an arbitrary callee to hand back a new payload. Anything else (bare identifier, property access, other call results, pipeline results) is not fresh.

  • Constructor Details

    • IsFreshValueExpression

      public IsFreshValueExpression(SymbolsAndScopes symbolsAndScopes)
      The strict reading: a literal or a constructor call (E08257's MutexLock argument).
  • Method Details

    • forCloseableReturns

      public static IsFreshValueExpression forCloseableReturns(Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recorded)
      The closeable-return reading (R5): also a call whose callee DECLARES a closeable return type and does not declare (or have derived) a result that may alias.
      Parameters:
      recorded - the recorded-symbol lookup of the phase asking (symbolsAndScopes or parsedModule)
    • test

      public boolean test(EK9Parser.ExpressionContext exprCtx)
      Specified by:
      test in interface Predicate<EK9Parser.ExpressionContext>