Class ObjectSharing

java.lang.Object
org.ek9lang.compiler.support.sharing.ObjectSharing
All Implemented Interfaces:
BiFunction<EK9Parser.IdentifierContext, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol>, List<ObjectSharing.Use>>

public final class ObjectSharing extends Object implements BiFunction<EK9Parser.IdentifierContext, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol>, List<ObjectSharing.Use>>
THE reading of what one occurrence of a name does to the OBJECT the name refers to - for every analysis that remembers what a variable holds (the phase-5 value tracker behind E08086, CompileTimeKnownText behind E08275). Use this; never a second list of "the ways a value can change". This class answers EVERY effect of one occurrence (apply(EK9Parser.IdentifierContext, Function)); the other questions of the same reading are the classes of this package, each held as an instance by the class that asks: ObjectSharingOfSelf (the same for this), MayBeExistingObject, MayBeExistingObjectByShape, MayBeObjectFromOutside, CompoundTargetMayKeep, IsCoalescingOperator, and the D66 "may run the program's own code" family MayRunProgramCode, ReachOfCall, ReachOfIteration, ReachOfInPlaceWrite, IterationRunsProgramCode and RangeRunsProgramCode, whose answer is a Reach.

An EK9 variable refers to an object, and most mutation happens IN PLACE: total += 5, total++, cat items > total change the object and store nothing. So a value can change through any name that refers to the same object, and through any code that is given it (D-1 / C-2 / NEW-2, 2026-10-19: the value tracker saw only assignment statements, and four routes each gave a false "condition is always true").

  • ObjectSharing.Kind.IN_PLACE_WRITE - a write that changes the object rather than storing a new one: a mutating operator (+=, ++, :=:, ...), or the target of a stream (>, >>, tee). Which occurrences write is SymbolWrites.writingOperator, never re-derived here.
  • ObjectSharing.Kind.SHARED - the occurrence makes another name refer to the SAME object: it is the whole right-hand side of a declaration or a plain store (alias <- base, alias := (base)), or an argument of a capture list ((base) is action as function, whose copy shares the object).
  • ObjectSharing.Kind.HANDED_TO_CALL - code that may change the object is given it: a bare argument of a callee that is not pure (except a concrete built-in, which changes only its receiver - the RETAINS declarations say what a built-in KEEPS, never that it changes an argument), or the receiver of a method that is not pure.

D61 added what an occurrence RETAINS: an object kept in a collection or Dict literal, added with a compound assignment, given to a call or constructor that may keep it, or iterated by a for is the same object as the holder's element, so the holder is ObjectSharing.Kind.SHARED with it - or, where nothing nameable keeps it, ObjectSharing.Kind.ESCAPES. A call chain that may return a VIEW of its receiver is followed the same way, and so are the expressions whose value IS an operand (second ?: other, second <? limit, a ternary arm), the elements of a stream's source (kept by its sink, each tee target and what keeps a collect, given to each stage function), and the returning variable of a switch, try, while or for whose value is assigned (holder <- switch ...). An escaped object stays changeable: the value tracker forgets what it learns about it at every later call of the program's own code (MayRunProgramCode) and every in-place change. Deliberately NOT covered: a view obtained from a CALL RESULT that is not a chain on a variable (makeBox().item()).

  • Constructor Details

    • ObjectSharing

      public ObjectSharing(IsThreadSpawningCall isThreadSpawningCall)
      Parameters:
      isThreadSpawningCall - THE calls that hand a value to a runtime thread (over the program's built-in types, new IsThreadSpawningCall(symbolsAndScopes.getEk9Types())): such a value ESCAPES (option B slice C). Every holder gives one, so every reading agrees.
  • Method Details

    • apply

      public List<ObjectSharing.Use> apply(EK9Parser.IdentifierContext occurrence, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recorded)
      EVERY effect of one occurrence: what the occurrence itself does (OccurrenceUse), plus what it RETAINS (D61) - the object put in a collection literal, a Dict value, given to a call or constructor that keeps its argument, added with a compound assignment, or iterated by a for: whatever holds it afterwards shares the object, so an in-place change through the holder (a loop variable, an element, a field) changes it too. THE one place that decides this; callers loop over the result.
      Specified by:
      apply in interface BiFunction<EK9Parser.IdentifierContext, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol>, List<ObjectSharing.Use>>
      Parameters:
      occurrence - the identifier (as RecordedSymbols.Reference.node())
      recorded - the recorded-symbol lookup of the phase asking (symbolsAndScopes or parsedModule)
    • ofTheObjectItself

      public List<ObjectSharing.Use> ofTheObjectItself(EK9Parser.IdentifierContext occurrence, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recorded)
      As apply(EK9Parser.IdentifierContext, Function), without what a call chain on the name does to a VIEW of the object (name.get() handed on is the Optional's ITEM, not the Optional): what the occurrence does to exactly the object the name refers to. For a container whose views are its content and never itself (an Optional, a Result, an Iterator), this is everything that can change it.