-
Notifications
You must be signed in to change notification settings - Fork 40
Instrumentation into Block IR #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: hkmc2
Are you sure you want to change the base?
Conversation
…ation during diff testing
…ring Add Block.mls into DiffMaker and prepare the function for lowering Use older Import syntax for now
renaming mlsript/staging to mlscript/block-staging avoids DiffTestRunner excluding the test files using the filter intended to exlude ucs/staging
this removes the check in L218 because evaluation of Scope is now deferred:wq
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())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
Call implementation will be after the algorithms for instrumenting functions are completed.
allocating
optionNmeThis changed some diff tests (
OpenWildcard.mls,Imports.mls,ImportMLs.mls) that imported Option themselves.If I allocate
optionNmeafter checking ifstageCodeis enabled, it fails to link to the file.Is there some way to avoid changing the diff tests, or is this fine?
implementing I-Inst
The current shape for Class
C(n:s)includes the field names (n), but the field names are not available inInstantiation.The field names are used in
sel. If the class is staged using I-Cls, then we can use the stagedClsLikeDefnto retrieve the symbol names, but when do we do when it isn't staged?