Skip to content

Conversation

@ChingLongTin
Copy link

Call implementation will be after the algorithms for instrumenting functions are completed.

  1. allocating optionNme
    This changed some diff tests (OpenWildcard.mls, Imports.mls, ImportMLs.mls) that imported Option themselves.
    If I allocate optionNme after checking if stageCode is enabled, it fails to link to the file.
    Is there some way to avoid changing the diff tests, or is this fine?

  2. implementing I-Inst
    The current shape for Class C(n:s) includes the field names (n), but the field names are not available in Instantiation.
    The field names are used in sel. If the class is staged using I-Cls, then we can use the staged ClsLikeDefn to retrieve the symbol names, but when do we do when it isn't staged?

class A(a)
staged module B
  class C(a)
  fun f() = 
    new C(1) // ok, C is staged
    new A(1) // not ok, we don't know field names of A after instrumentation

@ChingLongTin ChingLongTin changed the title Instrumentation (without Call) Instrumentation into Block IR Dec 23, 2025
ChingLongTin and others added 5 commits December 23, 2025 20:40
@ChingLongTin ChingLongTin requested a review from LPTK January 23, 2026 17:06
ChingLongTin and others added 4 commits January 28, 2026 00:11
we check if a function is staged through defCtx, so we can substitute the symbol there
_instr function only returns the block IR, whereas _gen functions will include the shape propagation
val debugBlock = debugPrintCode.foldRight(Return(unit, true))(concat)
def debugCont(rest: Block) =
Begin(debugBlock, rest)
val newCtor = impl.transformBlock(companion.ctor)(using new HashMap())(_ => debugCont(End()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far, if we introduce things from #387, it will fail, since we do not consider the mutable features that #387 is using. We probably need to only handle classes inside modules and leave other things untouched.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to bring the classes defined in the module to the next stage, The class C depends on the variable x defined within the module, so the let statement needs to be staged as well.
Will the classes never depend on variables that use mutable features?

module A with
  let x = 1
  fun get() = x
  class C() with
    fun get() = x
  fun add() =
    x = x + 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutation should probably not be allowed in staged modules, I think.

BTW, it should be set x = x + 1 or equivalently set x += 1. OTOH x = x + 1 is an only an initialization statement (and wll be rejected here once we have type checking).


fun concat(b1: Block, b2: Block) = if b1 is
Match(scrut, arms, dflt, rest) then Match(scrut, arms, dflt, concat(rest, b2))
Return(res, implct) then b2 // discard return?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b1 should not be discarded. When we have an early-return, we should discard the rest of the body, i.e., b2.

blockCtor("ClassSymbol", Ls(toValue(sym.nme), paramsOpt), symName)(k)
case t: TermSymbol if t.defn.exists(_.sym.asCls.isDefined) =>
transformSymbol(t.defn.get.sym.asCls.get, symName)(k)
case _ => blockCtor("Symbol", Ls(toValue(sym.nme)), symName)(k)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that the default name of TempSymbol is always tmp, and those symbols will be renamed with a number suffix during codegen. We probably also need to use Scope to avoid name clashes here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants