Class Monomorphisation

java.lang.Object
org.ek9lang.compiler.phase7.generation.Monomorphisation

public final class Monomorphisation extends Object
THE Scenario-3 monomorphisation state of one IR generation context (IR tidy W3.9, INFRA-14) - the type-parameter mapping in force, the dynamic-construct copies made for it, and THE resolution of a (possibly conceptual) type to the concrete type a monomorphised body emits. Every IR generation context owns one; generators reach it through IRGenerationContext.monomorphisation(), and every emitted type through the context's IRGenerationContext.resolveType(ISymbol) / IRGenerationContext.resolveTypeName(ISymbol) facades, which delegate here. Never hold a second mapping or a second resolve cache anywhere else.

Scenario 3 generates a parameterised type's method BODIES by walking the GENERIC type's AST (there is only one AST, shared by every parameterisation), so every symbol recorded against that AST carries TEMPLATE types - a bare T, or a dependent parameterisation such as List of T and the Iterator of T that its iterator() returns. Each must be re-pointed at its concrete counterpart before it is emitted. Signatures and fields need none of this: those come from the parameterised symbol itself, already substituted by phase 6.

Outside a monomorphisation (within(PositionalConceptualLookupMapping.Mapping, Supplier) not running) every resolution is the identity, so nothing outside a generic body moves.

  • Constructor Details

    • Monomorphisation

      Monomorphisation(IRContext irContext)
  • Method Details

    • within

      public <R> R within(PositionalConceptualLookupMapping.Mapping mapping, Supplier<R> work)
      Run work with the Scenario 3 substitution of one parameterised type in force, then clear it (with the dynamic-construct copies) whatever happens.

      The mapping pairs the generic type's conceptual 'type parameters' with the concrete 'type arguments' it was parameterised with, positionally and by symbol - the SAME PositionalConceptualLookupMapping.Mapping phase 6 TypeSubstitution uses, so both phases substitute identically.

      Parameters:
      mapping - The conceptual to concrete mapping of the parameterised type being generated
      work - The generation to run under it
      Returns:
      what work returns
    • continueFrom

      public void continueFrom(Monomorphisation outer)
      Continue the monomorphisation of outer here (in a fresh context): the same conceptual-to-concrete mapping and the same dynamic-construct copies. A dynamic function or class declared inside a generic body is generated in a context of its own (counter isolation); without this its body and signature would be emitted with the template's 'T' - a class no back-end ever writes. The resolve cache is not shared (it is only a cache).
      Parameters:
      outer - The monomorphisation of the context generating the body the dynamic construct is declared in
    • mapping

      The conceptual-to-concrete mapping of the monomorphisation in progress, or empty outside one.
    • recordDynamicConstructCopy

      public void recordDynamicConstructCopy(ISymbol template, ISymbol monomorph)
      Record the copy made of a dynamic construct for the monomorphisation in progress; from now on every reference to the construct (its own body, its constructor call, a nested construct) resolves to the copy.
      Parameters:
      template - The dynamic construct as declared in the generic body
      monomorph - The copy re-typed for this parameterisation
    • dynamicConstructCopyOf

      public Optional<ISymbol> dynamicConstructCopyOf(ISymbol template)
      The copy already made of a dynamic construct for the monomorphisation in progress, if any.
    • resolveType

      public ISymbol resolveType(ISymbol typeSymbol)
      The concrete type a (possibly conceptual) type resolves to under the monomorphisation in progress; outside one the symbol is returned unchanged. See IRGenerationContext.resolveType(ISymbol) for the rule.
      Parameters:
      typeSymbol - The (possibly conceptual) type symbol
      Returns:
      The concrete type symbol to emit or reason about
    • resolveTypeName

      public String resolveTypeName(ISymbol typeSymbol)
      The name form of resolveType(ISymbol).
    • resolveScopeTypeName

      public String resolveScopeTypeName(IScope scope)
      resolveTypeName(ISymbol) for an owning SCOPE that is usually - but not always - a symbol.