From 466b79a3ff5ffa3fcb7455379df83a9299e2d674 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 15:34:34 +0800 Subject: [PATCH 01/13] Fix handler runtime bugs --- .../src/test/mlscript-compile/Runtime.mjs | 35 ++++++++++++------- .../src/test/mlscript-compile/Runtime.mls | 10 ++++-- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs b/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs index a2a0088df9..d87c09cd60 100644 --- a/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs +++ b/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs @@ -1010,14 +1010,14 @@ lambda3 = (undefined, function (Runtime2, EffectHandle1, value) { } } static handleEffect(cur) { - let prevHandlerFrame, scrut, handlerFrame, saved, old, scrut1, scrut2, scrut3, tmp, tmp1, tmp2, tmp3; + let prevHandlerFrame, scrut, handlerFrame, saved, scrut1, scrut2, old, scrut3, scrut4, scrut5, scrut6, tmp, tmp1, tmp2, tmp3; prevHandlerFrame = cur.contTrace; lbl: while (true) { - let scrut4, scrut5; - scrut4 = prevHandlerFrame.nextHandler !== null; - if (scrut4 === true) { - scrut5 = prevHandlerFrame.nextHandler.handler !== cur.handler; - if (scrut5 === true) { + let scrut7, scrut8; + scrut7 = prevHandlerFrame.nextHandler !== null; + if (scrut7 === true) { + scrut8 = prevHandlerFrame.nextHandler.handler !== cur.handler; + if (scrut8 === true) { prevHandlerFrame = prevHandlerFrame.nextHandler; continue lbl } @@ -1030,6 +1030,14 @@ lambda3 = (undefined, function (Runtime2, EffectHandle1, value) { } handlerFrame = prevHandlerFrame.nextHandler; saved = new Runtime.ContTrace.class(handlerFrame.next, cur.contTrace.last, handlerFrame.nextHandler, cur.contTrace.lastHandler, false); + scrut1 = cur.contTrace.last === handlerFrame; + if (scrut1 === true) { + saved.last = saved; + } + scrut2 = cur.contTrace.lastHandler === handlerFrame; + if (scrut2 === true) { + saved.lastHandler = saved; + } cur.contTrace.last = handlerFrame; cur.contTrace.lastHandler = handlerFrame; handlerFrame.next = null; @@ -1045,16 +1053,19 @@ lambda3 = (undefined, function (Runtime2, EffectHandle1, value) { } finally { Runtime.stackDepth = old; } - scrut1 = Runtime.curEffect !== null; - if (scrut1 === true) { + scrut3 = Runtime.curEffect !== null; + if (scrut3 === true) { cur = Runtime.curEffect; - scrut2 = saved.next !== null; - if (scrut2 === true) { + scrut4 = saved.next !== null; + if (scrut4 === true) { cur.contTrace.last.next = saved.next; + } + scrut5 = saved.last !== saved; + if (scrut5 === true) { cur.contTrace.last = saved.last; } - scrut3 = saved.nextHandler !== null; - if (scrut3 === true) { + scrut6 = saved.nextHandler !== null; + if (scrut6 === true) { cur.contTrace.lastHandler.nextHandler = saved.nextHandler; cur.contTrace.lastHandler = saved.lastHandler; return cur diff --git a/hkmc2/shared/src/test/mlscript-compile/Runtime.mls b/hkmc2/shared/src/test/mlscript-compile/Runtime.mls index e9f0dfdbd8..290d3d99d6 100644 --- a/hkmc2/shared/src/test/mlscript-compile/Runtime.mls +++ b/hkmc2/shared/src/test/mlscript-compile/Runtime.mls @@ -412,6 +412,10 @@ fun handleEffect(cur) = cur.contTrace.lastHandler, false ) + + if cur.contTrace.last === handlerFrame do set saved.last = saved + if cur.contTrace.lastHandler === handlerFrame do set saved.lastHandler = saved + set cur.contTrace.last = handlerFrame cur.contTrace.lastHandler = handlerFrame @@ -425,9 +429,9 @@ fun handleEffect(cur) = set cur = curEffect // relink the saved frames if saved.next !== null do - set - cur.contTrace.last.next = saved.next - cur.contTrace.last = saved.last + set cur.contTrace.last.next = saved.next + if saved.last !== saved do + set cur.contTrace.last = saved.last if saved.nextHandler !== null do set cur.contTrace.lastHandler.nextHandler = saved.nextHandler From 6d310cb0914a8c3ce75ebd6f00af2cea302ead77 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 15:34:56 +0800 Subject: [PATCH 02/13] WIP: Tailrec fixes --- .../main/scala/hkmc2/codegen/TailRecOpt.scala | 86 ++++++++++++------- hkmc2/shared/src/test/mlscript/HkScratch.mls | 13 +++ .../test/mlscript/tailrec/MultiArgLists.mls | 2 +- .../src/test/mlscript/tailrec/TailRecOpt.mls | 60 +++++++++++-- 4 files changed, 123 insertions(+), 38 deletions(-) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala index 23c8ff7ed8..181139009f 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala @@ -249,7 +249,55 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): CallArgsResult.Success(hd.appended(rest)) else CallArgsResult.Success(hd) - + + /** + * Applies a parameter list to an argument list, both of which could contain arbitrary spreads. + * + * @param plist The parameter list to apply. + * @param args The argument list. + * @return A tuple `(Block => Block, List[Path])`, where: + * - The first parameter contains the code that breaks up the arguments into the shape expected by the parameter list, and + * should be applied to the remaining code; + * - The second parameter is a list of paths containing the arguments in order. If there is a spread parameter, it will be + * the last one. + */ + def forceSpread(plist: ParamList, args: List[Arg]): (Block => Block, List[Path]) = + // Forcibly spread the args in an array. + // Assume the lengths are correct + val paramList = plist.params + val restParam = plist.restParam + + val tupleSym = TempSymbol(N, "argList") + + val tupleRes = Tuple(false, args) + + // Main args + def mainArgs(rest: List[Path]) = (0 until paramList.size).toList.foldRight(rest): + case (n, acc) => DynSelect(tupleSym.asSimpleRef, Value.Lit(Tree.IntLit(n)), true) :: acc + + // If the rest param exists, append a slice + val (initialBlk: (Block => Block), pathList: List[Path]) = + if restParam.isDefined then + val sliceResSym = TempSymbol(N, "sliceRes") + // runtime.Tuple.slice(tupleSym, paramList.length, 0) + val sliceRes = Call( + State.runtimeSymbol.asSimpleRef + .sel(Tree.Ident("Tuple"), State.tupleSymbol) + .sel(Tree.Ident("slice"), State.tupleSliceSymbol), + (tupleSym.asSimpleRef.asArg + :: Value.Lit(Tree.IntLit(paramList.length)).asArg + :: Value.Lit(Tree.IntLit(0)).asArg + :: Nil) ne_:: Nil + )(CallMetadata.defaultMlsFun) + val blk = blockBuilder + .assignScoped(tupleSym, tupleRes) + .assignScoped(sliceResSym, sliceRes) + (blk, mainArgs(sliceResSym.asSimpleRef :: Nil)) + else + (blockBuilder.assignScoped(tupleSym, tupleRes), mainArgs(Nil)) + end val + (initialBlk, pathList) + def optScc(scc: SccOfCalls, owner: Opt[InnerSymbol])(using accessInfo: (ScopeData, AccessMap)): (Opt[FunDefn], List[FunDefn]) = // sort the functions so the order is more predictable val funs = scc.funs.sortBy(f => f.dSym.uid) @@ -366,6 +414,10 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): override def applyBlock(b: Block): Block = b match // Note: the args in `c` have already been rewritten to point to the symbols in `paramSyms`. + // We explicitly rewrite *all* fully applied calls to functions within the SCC. Tail calls are rewritten using a + // `continue`, while other calls are rewritten as a call to the merged function. This is to make the tailrec + // optimizer pass idempotent. Without this, the subsequent tailrec optimizer passes could see the merged and wrapper + // functions as an SCC and try to rewrite the wrapper's tail call. case TailCallShape(calleeSym, c) => dSymIds.get(calleeSym) match case None => super.applyBlock(b) case Some(id) => @@ -447,43 +499,13 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): case CallArgsResult.ForceSpread => // Forcibly spread the args in an array. // Assume the lengths are correct - val paramList = ogParamList.params - val restParam = ogParamList.restParam - - val tupleSym = TempSymbol(N, "argList") // We can safely remove all of the symbols from this parameter list from `assignedSyms` at this stage, // because the RHS of every parameter will be computed when spreading them in the tuple, which happens // before any of the param symbols are assigned to. assignedSyms --= thisParamSyms paramRewriter.applyArgs(ogArgs): newArgs => - val tupleRes = Tuple(false, newArgs) - - // Main args - def mainArgs(rest: List[Path]) = (0 until paramList.size).toList.foldRight(rest): - case (n, acc) => DynSelect(tupleSym.asSimpleRef, Value.Lit(Tree.IntLit(n)), true) :: acc - - // If the rest param exists, append a slice - val (initialBlk: (Block => Block), pathList: List[Path]) = - if restParam.isDefined then - val sliceResSym = TempSymbol(N, "sliceRes") - // runtime.Tuple.slice(tupleSym, paramList.length, 0) - val sliceRes = Call( - State.runtimeSymbol.asSimpleRef - .sel(Tree.Ident("Tuple"), State.tupleSymbol) - .sel(Tree.Ident("slice"), State.tupleSliceSymbol), - (tupleSym.asSimpleRef.asArg - :: Value.Lit(Tree.IntLit(paramList.length)).asArg - :: Value.Lit(Tree.IntLit(0)).asArg - :: Nil) ne_:: Nil - )(CallMetadata.defaultMlsFun) - val blk = blockBuilder - .assignScoped(tupleSym, tupleRes) - .assignScoped(sliceResSym, sliceRes) - (blk, mainArgs(sliceResSym.asSimpleRef :: Nil)) - else - (blockBuilder.assignScoped(tupleSym, tupleRes), mainArgs(Nil)) - end val + val (initialBlk, pathList) = forceSpread(ogParamList, newArgs) val paramAssignments = (thisParamSyms zip pathList).foldRight[Block](rest): case ((sym, path), restBlk) => Assign(sym, path, restBlk) diff --git a/hkmc2/shared/src/test/mlscript/HkScratch.mls b/hkmc2/shared/src/test/mlscript/HkScratch.mls index 48d7326643..a2851f5993 100644 --- a/hkmc2/shared/src/test/mlscript/HkScratch.mls +++ b/hkmc2/shared/src/test/mlscript/HkScratch.mls @@ -8,4 +8,17 @@ // :d // :todo +open annotations +:sjs +@inline fun f(x, y, ...z) = [x, y, z] +//│ ————————————| JS (unsanitized) |———————————————————————————————————————————————————————————————————— +//│ let f; f = function f(x, y, ...z) { return globalThis.Object.freeze([ x, y, z ]) }; +//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— + +:sjs +f(1, 2, 3, 4) +//│ ————————————| JS (unsanitized) |———————————————————————————————————————————————————————————————————— +//│ let z; z = [ 3, 4 ]; return globalThis.Object.freeze([ 1, 2, z ]) +//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— +//│ = [1, 2, [3, 4]] diff --git a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls index 2a743d9cbc..bce6dc5719 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls @@ -227,7 +227,7 @@ fun g(n)(m) = //│ return [param5, param6] //│ end //│ 1 => -//│ let tmp, tmp1, tmp2, tmp3, param1_tmp, argList, param0_tmp, inlinedVal, tmp4; +//│ let tmp, tmp1, tmp2, tmp3, param1_tmp, param0_tmp, argList, inlinedVal, tmp4; //│ set tmp = -⁰(param0, 1); //│ set tmp1 = [1, 2]; //│ set tmp2 = [3, 4]; diff --git a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls index fb446d28f6..7731c0a6b1 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls @@ -295,6 +295,56 @@ a.x //│ = 2 //│ a = A(2) +// Make sure the tailrec pass is idempotent +:soir +:noInline +:todo +:silent +fun f(x) = g(x) +fun g(x) = + f(x) + 0 +//│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— +//│ let f_g, f_f_g; +//│ define f_f_g as fun f_f_g⁰(id, param0, param1) { +//│ loop loopLabel: +//│ match id +//│ 0 => +//│ let param0_tmp; +//│ set param0_tmp = param0; +//│ set param0 = 0; +//│ set param1 = param0_tmp; +//│ set id = 1; +//│ continue loopLabel +//│ 1 => +//│ loop loopLabel1: +//│ match param0 +//│ 0 => +//│ set param0 = 1; +//│ continue loopLabel1 +//│ 1 => +//│ do f⁶(param1); +//│ return 0 +//│ else +//│ end +//│ end +//│ end +//│ else +//│ end +//│ end +//│ end +//│ }; +//│ define f_g as fun f_g¹(id, param0) { +//│ return f_f_g⁰(1, id, param0) +//│ }; +//│ define f⁷ as fun f⁶(x) { +//│ return f_f_g⁰(0, x, undefined) +//│ }; +//│ define g⁴ as fun g⁵(x) { return f_g¹(1, x) }; +//│ end +//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— +//│ FAILURE: Unexpected lack of error to fix + // Functions inside module definitions are lifted to the top level. This means they cannot yet be optimized. :lift :fixme @@ -304,10 +354,10 @@ module A with @tailcall g(x - 1) A.f(10000) //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.303: fun g(x) = if x < 0 then 0 else @tailcall f(x) +//│ ║ l.353: fun g(x) = if x < 0 then 0 else @tailcall f(x) //│ ╙── ^^^^ //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.304: @tailcall g(x - 1) +//│ ║ l.354: @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 @@ -334,12 +384,12 @@ class A with fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) (new A).f(10) //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.333: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.383: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ ╔══[COMPILATION ERROR] Class methods may not yet be marked @tailrec. -//│ ║ l.333: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.383: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^ //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.334: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) +//│ ║ l.384: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 From 786ccdb0dec345dc1254a0caa90d59837ce2cf75 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 16:35:10 +0800 Subject: [PATCH 03/13] Tailrec fixes --- .../src/main/scala/hkmc2/codegen/Block.scala | 1 + .../main/scala/hkmc2/codegen/TailRecOpt.scala | 87 +++++++++----- hkmc2/shared/src/test/mlscript/HkScratch.mls | 12 -- .../test/mlscript/tailrec/MultiArgLists.mls | 112 ++++++++++++++++++ .../src/test/mlscript/tailrec/TailRecOpt.mls | 44 ++----- 5 files changed, 184 insertions(+), 72 deletions(-) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala index 7106f6577d..bcc34c550e 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala @@ -682,6 +682,7 @@ final case class FunDefn( lazy val affineInfo: Ls[Int] = annotations.collect: case Annot.Affine(whichParamList) => whichParamList + lazy val paramSyms: Ls[VarSymbol] = params.flatMap(_.paramSyms) // * This deliberately is not a lazy val: its initialization would synchronize on the JVM. // * Computing the summary is pure, and a reference write is atomic, so concurrent traversals may diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala index 181139009f..eadebc7438 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala @@ -13,7 +13,6 @@ import hkmc2.syntax.{Tree, SpreadKind} import hkmc2.ScopeData.* import hkmc2.Lifter.AccessInfo import scala.collection.mutable.{ArrayBuffer, LinkedHashMap} -import java.lang.instrument.ClassDefinition /* @@ -207,11 +206,6 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val x = f(item) if x > l then x else l - def getParamSyms(f: FunDefn) = f.params.flatMap: - case ParamList(_, params, S(rest)) => - params.map(_.sym).appended(rest.sym) - case p => p.params.map(_.sym) - def paramsLen(f: FunDefn): Int = f.params.foldLeft(0): (acc, head) => acc + (if head.restParam.isDefined then 1 + head.params.length else head.params.length) @@ -335,7 +329,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val maxParamLen = maxInt(funs, paramsLen) val paramSyms = if funs.length === 1 then - val syms = getParamSyms(funs.head) + val syms = funs.head.paramSyms if funs.head.params.length === 1 then syms else // Duplicate the params for the internal loop defn (see the doc at the @@ -358,16 +352,24 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val dSymIds = funs.iterator.map(_.dSym).zipWithIndex.toMap val dSymToDefn = funs.iterator.map(f => f.dSym -> f).toMap val bms = - if funsLen === 1 then funs.head.sym + if funsLen === 1 then funs.head.params match + case _ :: Nil => funs.head.sym + case _ => BlockMemberSymbol(funs.head.sym.nme + "$tailrec", Nil, true) else BlockMemberSymbol(funs.iterator.map(_.sym.nme).mkString("_"), Nil, true) val dSym = - if funsLen === 1 then funs.head.dSym + if funsLen === 1 then funs.head.params match + case _ :: Nil => funs.head.dSym + case _ => TermSymbol(syntax.Fun, owner, Tree.Ident(bms.nme)) else TermSymbol(syntax.Fun, owner, Tree.Ident(bms.nme)) val loopSym = LabelSymbol(N, "loopLabel") val curIdSym = VarSymbol(Tree.Ident("id")) + val sel = owner match + case Some(value) => Select(value.asThis, Tree.Ident(bms.nme))(S(dSym))(false) + case None => bms.asMemberRef(dSym) + class FunRewriter(f: FunDefn) extends BlockTransformerShallow(SymbolSubst.Id): - val params = getParamSyms(f) + val params = f.paramSyms val paramsSet = f.params.toSet val paramsIdxes = params.zipWithIndex.toMap @@ -414,10 +416,6 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): override def applyBlock(b: Block): Block = b match // Note: the args in `c` have already been rewritten to point to the symbols in `paramSyms`. - // We explicitly rewrite *all* fully applied calls to functions within the SCC. Tail calls are rewritten using a - // `continue`, while other calls are rewritten as a call to the merged function. This is to make the tailrec - // optimizer pass idempotent. Without this, the subsequent tailrec optimizer passes could see the merged and wrapper - // functions as an SCC and try to rewrite the wrapper's tail call. case TailCallShape(calleeSym, c) => dSymIds.get(calleeSym) match case None => super.applyBlock(b) case Some(id) => @@ -520,6 +518,50 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): // Not a tail call case _ => super.applyBlock(b) + // We explicitly rewrite *all* fully applied calls to functions within the SCC. Tail calls are rewritten using a + // `continue`, while other calls are rewritten as a call to the merged function. This is to make the tailrec + // optimizer pass idempotent. Without this, the subsequent tailrec optimizer passes could see the merged and wrapper + // functions as an SCC and try to rewrite the wrapper's tail call. + override def applyResult(r: Result)(k: Result => Block): Block = r match + case c @ Call(Value.MemberRef(bms, calleeSym: TermSymbol), args) => funsMap.get(calleeSym) match + case Some(callee) if isExactlySaturatedCall(c, callee) => + val calleeParamsMap = paramSymsMap(callee.dSym) + val argListResults = callee.params.zip(c.argss).map: + case (params, args) => (params, params.paramSyms.map(calleeParamsMap), args, rewriteArgsList(callee, params, args)) + // Note: even though the convention right now is to just have the first k_f arguments of the merged function be the arguments + // of each function f, where f has k_f total parameters, we still explicitly find the correct order of arguments without + // using this convention. This is because this assumption may not hold in the future, i.e. when arguments could be assigned + // types for the typed IR. + var pre = blockBuilder + val argsInOrder: List[Path] = argListResults.flatMap: (ogParams, thisParamSyms, args, argsRes) => + argsRes match + case CallArgsResult.Success(res) => res.map: + case r: Path => r + case r: Result => + val newSym = TempSymbol(N) + pre = pre.assignScoped(newSym, r) + newSym.asPath + case CallArgsResult.ForceSpread => + val (initialBlk, paths) = forceSpread(ogParams, args) + pre = pre.chain(initialBlk) + paths + assert(callee.paramSyms.length === argsInOrder.length) + val argsMap = (callee.paramSyms.map(paramSymsMap(callee.dSym)) zip argsInOrder).toMap + val args = paramSyms.map: s => + argsMap.get(s) match + case Some(pth) => Arg(N, pth) + case None => Arg(N, Value.Lit(Tree.UnitLit(false))) + val argsWithId = if funsLen > 1 then Value.Lit(Tree.IntLit(dSymIds(calleeSym))).asArg :: args else args + val call = Call(sel, argsWithId ne_:: Nil)(CallMetadata.defaultMlsFun) + pre.rest(k(call)) + // f.paramSyms + // assert(assignmentsInOrder.length === ) + + + case _ => super.applyResult(r)(k) + case _ => super.applyResult(r)(k) + + def rewrite(b: Block): Block = // Rewrite the result with symbols pointing to the merged function parameters and possibly the copied parameters (see `copiedParams`). val blk = applyBlock(symRewriter.applyBlock(b)) @@ -536,14 +578,10 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val loop = Label(loopSym, true, switch, End()) - val sel = owner match - case Some(value) => Select(value.asThis, Tree.Ident(bms.nme))(S(dSym))(false) - case None => bms.asMemberRef(dSym) - val rewrittenFuns = if funsLen === 1 then Nil else funs.map: f => - val paramArgs = getParamSyms(f).map(s => s.asSimpleRef.asArg) + val paramArgs = f.paramSyms.map(s => s.asSimpleRef.asArg) val args = Value.Lit(Tree.IntLit(dSymIds(f.dSym))).asArg :: paramArgs @@ -566,21 +604,16 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): // original multi-param-list interface and delegates to the flattened internal loop. val params = paramSyms.map(Param.simple(_)) - val loopBms = BlockMemberSymbol(bms.nme + "$tailrec", Nil, true) - val loopDSym = TermSymbol(syntax.Fun, owner, Tree.Ident(loopBms.nme)) val loopAnnots = if f.inline then Annot.Inline :: Annot.Private :: Nil else Annot.Private :: Nil val internalLoopDefn = FunDefn( - owner, loopBms, loopDSym, + owner, bms, dSym, PlainParamList(params) :: Nil, loop)(N, annotations = loopAnnots) - val paramArgs = getParamSyms(f).map(s => s.asSimpleRef.asArg) - val internalSel = owner match - case Some(value) => Select(value.asThis, Tree.Ident(loopBms.nme))(S(loopDSym))(false) - case None => loopBms.asMemberRef(loopDSym) + val paramArgs = f.paramSyms.map(s => s.asSimpleRef.asArg) val wrapperBod = Return( - Call(internalSel, paramArgs ne_:: Nil)(CallMetadata.defaultMlsFun), + Call(sel, paramArgs ne_:: Nil)(CallMetadata.defaultMlsFun), ) val newAnnots = if f.inline then f.annotations else Annot.Inline :: f.annotations val wrapperDefn = FunDefn(f.owner, f.sym, f.dSym, f.params, wrapperBod)( diff --git a/hkmc2/shared/src/test/mlscript/HkScratch.mls b/hkmc2/shared/src/test/mlscript/HkScratch.mls index a2851f5993..ef38e8b363 100644 --- a/hkmc2/shared/src/test/mlscript/HkScratch.mls +++ b/hkmc2/shared/src/test/mlscript/HkScratch.mls @@ -8,17 +8,5 @@ // :d // :todo -open annotations -:sjs -@inline fun f(x, y, ...z) = [x, y, z] -//│ ————————————| JS (unsanitized) |———————————————————————————————————————————————————————————————————— -//│ let f; f = function f(x, y, ...z) { return globalThis.Object.freeze([ x, y, z ]) }; -//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— -:sjs -f(1, 2, 3, 4) -//│ ————————————| JS (unsanitized) |———————————————————————————————————————————————————————————————————— -//│ let z; z = [ 3, 4 ]; return globalThis.Object.freeze([ 1, 2, z ]) -//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— -//│ = [1, 2, [3, 4]] diff --git a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls index bce6dc5719..0634683980 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls @@ -399,3 +399,115 @@ fun f = loop(1000)(0) //│ }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— + +// Ensure the function is inlined +:soir +fun loop(x)(y) = + if y === 0 then 0 + else if x === 0 then 1 + loop(5)(y - 1) + else @tailcall loop(x - 1)(y) +loop(5)(5) +//│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— +//│ let loop$tailrec; +//│ @private +//│ define loop$tailrec as fun loop$tailrec¹(x, y) { +//│ loop loopLabel: +//│ let scrut, scrut1, tmp, tmp1, tmp2; +//│ set scrut = ===⁰(y, 0); +//│ match scrut +//│ true => +//│ return 0 +//│ else +//│ set scrut1 = ===⁰(x, 0); +//│ match scrut1 +//│ true => +//│ set tmp = -⁰(y, 1); +//│ set tmp1 = loop$tailrec¹(5, tmp); +//│ return +⁰(1, tmp1) +//│ else +//│ set tmp2 = -⁰(x, 1); +//│ set x = tmp2; +//│ continue loopLabel +//│ end +//│ end +//│ unreachable /* Rest of abortive labelled block */ +//│ }; +//│ @inline +//│ define loop⁴ as fun loop⁵(x)(y) { return loop$tailrec¹(x, y) }; +//│ return loop$tailrec¹(5, 5) +//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— +//│ = 5 + +fun f(n)(a, b, c, d, ...e)(m) = + if n > 0 then @tailcall g(n)(m + 1) + else [e, m] +fun g(n)(m) = + let res = f(n - 1)(...[1, 2], 3, ...[3, 4], ...[5, n], 7, n)(m) + print("hi!") + res + +:expect [[4, 5, 1, 7, 1], 9] +g(10)(0) +//│ > hi! +//│ > hi! +//│ > hi! +//│ > hi! +//│ > hi! +//│ > hi! +//│ > hi! +//│ > hi! +//│ > hi! +//│ > hi! +//│ = [[4, 5, 1, 7, 1], 9] + +:soir +fun f(n)(a)(...z) = + if n > 0 then f(n - 1)(a)(...z) else if z is + [] then a + [x, ...xs] then + let res = f(n)(a + 1)(...xs) + print("hi!") + res +//│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— +//│ let f$tailrec; +//│ @private +//│ define f$tailrec as fun f$tailrec³(n, a, z) { +//│ loop loopLabel: +//│ let scrut, res, tmp, tmp1; +//│ set scrut = >⁰(n, 0); +//│ match scrut +//│ true => +//│ set tmp = -⁰(n, 1); +//│ set n = tmp; +//│ continue loopLabel +//│ else +//│ match z +//│ Array(0) => +//│ return a +//│ Array(1+) => +//│ let inlinedVal, tmp2; +//│ do runtime⁰.Tuple⁰.get⁰(z, 0); +//│ set tmp2 = -¹(z.length﹖, 0); +//│ set inlinedVal = z.slice﹖(1, tmp2); +//│ set tmp1 = +⁰(a, 1); +//│ set res = f$tailrec³(n, tmp1, inlinedVal); +//│ do Predef⁰.print⁰("hi!"); +//│ return res +//│ else +//│ throw new globalThis⁰.Error⁰("match error") +//│ end +//│ end +//│ unreachable /* Rest of abortive labelled block */ +//│ }; +//│ @inline +//│ define f⁸ as fun f⁹(n)(a)(...z) { return f$tailrec³(n, a, z) }; +//│ end +//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— + +:expect 4 +f(5)(0)(1, 2, 3, 4) +//│ > hi! +//│ > hi! +//│ > hi! +//│ > hi! +//│ = 4 diff --git a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls index 7731c0a6b1..c9f59cc8e7 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls @@ -295,55 +295,33 @@ a.x //│ = 2 //│ a = A(2) -// Make sure the tailrec pass is idempotent +// Make sure the tailrec pass is idempotent by ensuring non-tail calls to functions in the SCC are rewritten as calls to the loop definition. :soir :noInline -:todo -:silent fun f(x) = g(x) fun g(x) = f(x) 0 //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— -//│ let f_g, f_f_g; -//│ define f_f_g as fun f_f_g⁰(id, param0, param1) { +//│ let f_g; +//│ define f_g as fun f_g¹(id, param0) { //│ loop loopLabel: //│ match id //│ 0 => -//│ let param0_tmp; -//│ set param0_tmp = param0; -//│ set param0 = 0; -//│ set param1 = param0_tmp; //│ set id = 1; //│ continue loopLabel //│ 1 => -//│ loop loopLabel1: -//│ match param0 -//│ 0 => -//│ set param0 = 1; -//│ continue loopLabel1 -//│ 1 => -//│ do f⁶(param1); -//│ return 0 -//│ else -//│ end -//│ end -//│ end +//│ do f_g¹(0, param0); +//│ return 0 //│ else //│ end //│ end //│ end //│ }; -//│ define f_g as fun f_g¹(id, param0) { -//│ return f_f_g⁰(1, id, param0) -//│ }; -//│ define f⁷ as fun f⁶(x) { -//│ return f_f_g⁰(0, x, undefined) -//│ }; +//│ define f⁶ as fun f⁷(x) { return f_g¹(0, x) }; //│ define g⁴ as fun g⁵(x) { return f_g¹(1, x) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— -//│ FAILURE: Unexpected lack of error to fix // Functions inside module definitions are lifted to the top level. This means they cannot yet be optimized. :lift @@ -354,10 +332,10 @@ module A with @tailcall g(x - 1) A.f(10000) //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.353: fun g(x) = if x < 0 then 0 else @tailcall f(x) +//│ ║ l.331: fun g(x) = if x < 0 then 0 else @tailcall f(x) //│ ╙── ^^^^ //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.354: @tailcall g(x - 1) +//│ ║ l.332: @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 @@ -384,12 +362,12 @@ class A with fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) (new A).f(10) //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.383: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.361: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ ╔══[COMPILATION ERROR] Class methods may not yet be marked @tailrec. -//│ ║ l.383: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.361: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^ //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.384: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) +//│ ║ l.362: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 From 41e5ff614c263c26caa81795d8effe6f570e992b Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 16:35:26 +0800 Subject: [PATCH 04/13] revert hkscratch --- hkmc2/shared/src/test/mlscript/HkScratch.mls | 1 - 1 file changed, 1 deletion(-) diff --git a/hkmc2/shared/src/test/mlscript/HkScratch.mls b/hkmc2/shared/src/test/mlscript/HkScratch.mls index ef38e8b363..48d7326643 100644 --- a/hkmc2/shared/src/test/mlscript/HkScratch.mls +++ b/hkmc2/shared/src/test/mlscript/HkScratch.mls @@ -9,4 +9,3 @@ // :todo - From 9f39f6c277ab276adfa645a3e067a9e3a254dfbf Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 17:10:11 +0800 Subject: [PATCH 05/13] fix bug and clean up --- .../main/scala/hkmc2/codegen/TailRecOpt.scala | 141 ++--- .../test/mlscript/tailrec/MultiArgLists.mls | 159 +++--- .../src/test/mlscript/tailrec/TailRecOpt.mls | 40 +- .../mlscript/ups/examples/HindleyMilner.mls | 505 +++++++++++++++++- 4 files changed, 656 insertions(+), 189 deletions(-) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala index eadebc7438..f07dc3599a 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala @@ -325,18 +325,28 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): :: msg"It could self-recurse through this call, which is not a tail call." -> reportLoc :: Nil )) - + + val (hasWrapper, bms) = + if funsLen === 1 then funs.head.params match + // Simplest case: One function, one parameter list, no wrapper. + case _ :: Nil => (false, funs.head.sym) + // When a function has multiple param lists, TailRecOpt flattens them into a single + // param list for the internal loop. We need a wrapper function that preserves the + // original multi-param-list interface and delegates to the flattened internal loop. + case _ => (true, BlockMemberSymbol(funs.head.sym.nme + "$tailrec", Nil, true)) + // Multiple functions: Create a wrapper. + else (true, BlockMemberSymbol(funs.iterator.map(_.sym.nme).mkString("_"), Nil, true)) + val dSym = + if bms is funs.head.sym then funs.head.dSym + else TermSymbol(syntax.Fun, owner, Tree.Ident(bms.nme)) + val maxParamLen = maxInt(funs, paramsLen) val paramSyms = - if funs.length === 1 then - val syms = funs.head.paramSyms - if funs.head.params.length === 1 then syms - else - // Duplicate the params for the internal loop defn (see the doc at the - // end of this function), but preserve the names. - syms.map(v => VarSymbol(Tree.Ident(v.id.name))) - else - for i <- 0 until maxParamLen yield VarSymbol(Tree.Ident("param" + i)) + if hasWrapper then + if funsLen === 1 then + funs.head.paramSyms.map(v => VarSymbol(Tree.Ident(v.id.name))) + else for i <- 0 until maxParamLen yield VarSymbol(Tree.Ident("param" + i)) + else funs.head.paramSyms .toList val paramSymsArr = ArrayBuffer.from(paramSyms) // Function -> param -> param symbol in the rewritten function @@ -351,23 +361,27 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val dSymIds = funs.iterator.map(_.dSym).zipWithIndex.toMap val dSymToDefn = funs.iterator.map(f => f.dSym -> f).toMap - val bms = - if funsLen === 1 then funs.head.params match - case _ :: Nil => funs.head.sym - case _ => BlockMemberSymbol(funs.head.sym.nme + "$tailrec", Nil, true) - else BlockMemberSymbol(funs.iterator.map(_.sym.nme).mkString("_"), Nil, true) - val dSym = - if funsLen === 1 then funs.head.params match - case _ :: Nil => funs.head.dSym - case _ => TermSymbol(syntax.Fun, owner, Tree.Ident(bms.nme)) - else TermSymbol(syntax.Fun, owner, Tree.Ident(bms.nme)) + val loopSym = LabelSymbol(N, "loopLabel") val curIdSym = VarSymbol(Tree.Ident("id")) - val sel = owner match + val loopDefnPath = owner match case Some(value) => Select(value.asThis, Tree.Ident(bms.nme))(S(dSym))(false) case None => bms.asMemberRef(dSym) + def rewriteKnownCall(callee: FunDefn, flattenedArgs: List[Path]) = + if !hasWrapper then lastWords("Tried to rewrite a call to a non-existent loop definition.") + if callee.paramSyms.length =/= flattenedArgs.length then lastWords("Incorrect function call arity.") + // Fill in the argument list with the arguments in the correct position by applying the paramSym -> arg map to + // the loop definitions parameter list. + val argsMap = (callee.paramSyms.map(paramSymsMap(callee.dSym)) zip flattenedArgs).toMap + val args = paramSyms.map: s => + argsMap.get(s) match + case Some(pth) => Arg(N, pth) + case None => Arg(N, Value.Lit(Tree.UnitLit(false))) + val argsWithId = if funsLen > 1 then Value.Lit(Tree.IntLit(dSymIds(callee.dSym))).asArg :: args else args + Call(loopDefnPath, argsWithId ne_:: Nil)(CallMetadata.defaultMlsFun) + class FunRewriter(f: FunDefn) extends BlockTransformerShallow(SymbolSubst.Id): val params = f.paramSyms val paramsSet = f.params.toSet @@ -523,7 +537,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): // optimizer pass idempotent. Without this, the subsequent tailrec optimizer passes could see the merged and wrapper // functions as an SCC and try to rewrite the wrapper's tail call. override def applyResult(r: Result)(k: Result => Block): Block = r match - case c @ Call(Value.MemberRef(bms, calleeSym: TermSymbol), args) => funsMap.get(calleeSym) match + case c @ Call(Value.MemberRef(bms, calleeSym: TermSymbol), args) if hasWrapper => funsMap.get(calleeSym) match case Some(callee) if isExactlySaturatedCall(c, callee) => val calleeParamsMap = paramSymsMap(callee.dSym) val argListResults = callee.params.zip(c.argss).map: @@ -533,6 +547,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): // using this convention. This is because this assumption may not hold in the future, i.e. when arguments could be assigned // types for the typed IR. var pre = blockBuilder + // Create the list of flattened args. val argsInOrder: List[Path] = argListResults.flatMap: (ogParams, thisParamSyms, args, argsRes) => argsRes match case CallArgsResult.Success(res) => res.map: @@ -545,18 +560,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val (initialBlk, paths) = forceSpread(ogParams, args) pre = pre.chain(initialBlk) paths - assert(callee.paramSyms.length === argsInOrder.length) - val argsMap = (callee.paramSyms.map(paramSymsMap(callee.dSym)) zip argsInOrder).toMap - val args = paramSyms.map: s => - argsMap.get(s) match - case Some(pth) => Arg(N, pth) - case None => Arg(N, Value.Lit(Tree.UnitLit(false))) - val argsWithId = if funsLen > 1 then Value.Lit(Tree.IntLit(dSymIds(calleeSym))).asArg :: args else args - val call = Call(sel, argsWithId ne_:: Nil)(CallMetadata.defaultMlsFun) - pre.rest(k(call)) - // f.paramSyms - // assert(assignmentsInOrder.length === ) - + pre.rest(k(rewriteKnownCall(callee, argsInOrder))) case _ => super.applyResult(r)(k) case _ => super.applyResult(r)(k) @@ -578,58 +582,31 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val loop = Label(loopSym, true, switch, End()) - val rewrittenFuns = - if funsLen === 1 then Nil - else funs.map: f => - val paramArgs = f.paramSyms.map(s => s.asSimpleRef.asArg) - val args = - Value.Lit(Tree.IntLit(dSymIds(f.dSym))).asArg - :: paramArgs - ::: List.fill(maxParamLen - paramArgs.length)(Value.Lit(Tree.UnitLit(false)).asArg) + if !hasWrapper then + val f = funs.head + val defn = FunDefn( + owner, bms, dSym, + f.params, + loop)(N, annotations = f.annotations) + (N, defn :: Nil) + else + val wrappers = funs.map: f => + val paramArgs = f.paramSyms.map(s => s.asSimpleRef) val newBod = Return( - Call(sel, args ne_:: Nil)(CallMetadata.defaultMlsFun), + rewriteKnownCall(f, paramArgs), ) FunDefn(f.owner, f.sym, f.dSym, f.params, newBod)(N, f.annotations) - - funs match - case (f @ FunDefn(params = _ :: Nil | Nil)) :: Nil => - val defn = FunDefn( - owner, bms, dSym, - f.params, - loop)(N, annotations = f.annotations) - (N, defn :: Nil) - case f :: Nil => - // When a function has multiple param lists, TailRecOpt flattens them into a single - // param list for the internal loop. We need a wrapper function that preserves the - // original multi-param-list interface and delegates to the flattened internal loop. - val params = paramSyms.map(Param.simple(_)) - - val loopAnnots = - if f.inline then Annot.Inline :: Annot.Private :: Nil - else Annot.Private :: Nil - val internalLoopDefn = FunDefn( - owner, bms, dSym, - PlainParamList(params) :: Nil, - loop)(N, annotations = loopAnnots) - val paramArgs = f.paramSyms.map(s => s.asSimpleRef.asArg) - val wrapperBod = Return( - Call(sel, paramArgs ne_:: Nil)(CallMetadata.defaultMlsFun), - ) - val newAnnots = if f.inline then f.annotations else Annot.Inline :: f.annotations - val wrapperDefn = FunDefn(f.owner, f.sym, f.dSym, f.params, wrapperBod)( - f.configOverride, annotations = newAnnots) - (S(internalLoopDefn), wrapperDefn :: Nil) - case _ => - val newParamLists = - val initial = paramSyms.map(Param.simple(_)) + val newParamLists = + val initial = paramSyms.map(Param.simple(_)) + if funsLen > 1 then PlainParamList(Param.simple(curIdSym) :: initial) :: Nil - - val loopDefn = FunDefn( - owner, bms, dSym, - newParamLists, - loop)(N, annotations = Nil) // Q: maybe should be Private? - - (S(loopDefn), rewrittenFuns) + else + PlainParamList(initial) :: Nil + val loopDefn = FunDefn( + owner, bms, dSym, + newParamLists, + loop)(N, annotations = Nil) // Q: maybe should be Private? + (S(loopDefn), wrappers) def optFunctions(fs: List[FunDefn], owner: Opt[InnerSymbol])(using (ScopeData, AccessMap)) = val (newFsOpt, fsOpt) = partFns(fs).map(optScc(_, owner)).foldLeft[(List[FunDefn], List[FunDefn])](Nil, Nil): diff --git a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls index 0634683980..5bbceb2fc3 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls @@ -20,7 +20,6 @@ fun loop(x)(y) = loop(1000)(0) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let loop$tailrec; -//│ @private //│ define loop$tailrec as fun loop$tailrec⁰(x, y) { //│ loop loopLabel: //│ let scrut, tmp, tmp1; @@ -52,7 +51,6 @@ fun count(start)(stop) = count(0)(100) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let count$tailrec, start, stop, inlinedVal; -//│ @private //│ define count$tailrec as fun count$tailrec⁰(start1, stop1) { //│ loop loopLabel: //│ let scrut, tmp; @@ -270,30 +268,32 @@ fun f(a)(...z) = if z is [] then a [x, ...xs] then f(a + 1)(...xs) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— -//│ let f$tailrec; -//│ @private -//│ define f$tailrec as fun f$tailrec⁰(a, z) { -//│ loop loopLabel: -//│ let tmp; -//│ match z -//│ Array(0) => -//│ return a -//│ Array(1+) => -//│ let inlinedVal, tmp1; -//│ do runtime⁰.Tuple⁰.get⁰(z, 0); -//│ set tmp1 = -¹(z.length﹖, 0); -//│ set inlinedVal = z.slice﹖(1, tmp1); -//│ set tmp = +⁰(a, 1); -//│ set a = tmp; -//│ set z = inlinedVal; -//│ continue loopLabel -//│ else -//│ throw new globalThis⁰.Error⁰("match error") -//│ end -//│ unreachable /* Rest of abortive labelled block */ +//│ define f² as fun f³(a)(...z) { +//│ let a1, z1, inlinedVal; +//│ set a1 = a; +//│ set z1 = z; +//│ block inlinedLbl: +//│ loop loopLabel: +//│ let tmp; +//│ match z1 +//│ Array(0) => +//│ set inlinedVal = a1; +//│ break inlinedLbl +//│ Array(1+) => +//│ let inlinedVal1, tmp1; +//│ do runtime⁰.Tuple⁰.get⁰(z1, 0); +//│ set tmp1 = -¹(z1.length﹖, 0); +//│ set inlinedVal1 = z1.slice﹖(1, tmp1); +//│ set tmp = +⁰(a1, 1); +//│ set a1 = tmp; +//│ set z1 = inlinedVal1; +//│ continue loopLabel +//│ else +//│ throw new globalThis⁰.Error⁰("match error") +//│ end +//│ unreachable /* Rest of abortive labelled block */ +//│ return inlinedVal //│ }; -//│ @inline -//│ define f² as fun f³(a)(...z) { return f$tailrec⁰(a, z) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -308,13 +308,20 @@ f(0)(1, 2, 3, 4) fun f(a)(b) = f(a)(b) //│ ————————————| Optimized IR Tree |——————————————————————————————————————————————————————————————————— //│ Program: -//│ main = Scoped(syms = {member:f$tailrec¹}): +//│ main = Scoped(syms = {member:f$tailrec⁰}): //│ body = Define: //│ defn = FunDefn: -//│ sym = member:f$tailrec¹ -//│ dSym = term:f$tailrec² +//│ sym = member:f$tailrec⁰ +//│ dSym = term:f$tailrec¹ //│ params = Ls of -//│ ParamList: ‹empty› +//│ ParamList: +//│ params = Ls of +//│ Param: +//│ sym = a⁰ +//│ modulefulness = Modulefulness of N +//│ Param: +//│ sym = b⁰ +//│ modulefulness = Modulefulness of N //│ body = Label: //│ label = label:loopLabel⁰ //│ loop = true @@ -328,19 +335,23 @@ fun f(a)(b) = f(a)(b) //│ ParamList: //│ params = Ls of //│ Param: -//│ sym = a⁰ +//│ sym = a¹ //│ modulefulness = Modulefulness of N //│ ParamList: //│ params = Ls of //│ Param: -//│ sym = b⁰ +//│ sym = b¹ //│ modulefulness = Modulefulness of N //│ body = Return of Call: -//│ fun = MemberRef{disamb=term:f$tailrec²}: -//│ bms = member:f$tailrec¹ -//│ disamb = term:f$tailrec² +//│ fun = MemberRef{disamb=term:f$tailrec¹}: +//│ bms = member:f$tailrec⁰ +//│ disamb = term:f$tailrec¹ //│ argss = Ls of -//│ Nil +//│ Ls of +//│ Arg: +//│ value = SimpleRef of a¹ +//│ Arg: +//│ value = SimpleRef of b¹ //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -352,51 +363,28 @@ fun loop(x)(y) = else loop(x - 1)(y + x) fun f = loop(1000)(0) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— +//│ let loop$tailrec; +//│ define loop$tailrec as fun loop$tailrec¹(x, y) { +//│ loop loopLabel: +//│ let scrut, tmp, tmp1; +//│ set scrut = Predef⁰.equals⁰(x, 0); +//│ match scrut +//│ true => +//│ return y +//│ else +//│ set tmp = -⁰(x, 1); +//│ set tmp1 = +⁰(y, x); +//│ set x = tmp; +//│ set y = tmp1; +//│ continue loopLabel +//│ end +//│ unreachable /* Rest of abortive labelled block */ +//│ }; //│ @tailrec @inline //│ define loop² as fun loop³(x)(y) { -//│ let x1, y1, inlinedVal; -//│ set x1 = x; -//│ set y1 = y; -//│ block inlinedLbl: -//│ loop loopLabel: -//│ let scrut, tmp, tmp1; -//│ set scrut = Predef⁰.equals⁰(x1, 0); -//│ match scrut -//│ true => -//│ set inlinedVal = y1; -//│ break inlinedLbl -//│ else -//│ set tmp = -⁰(x1, 1); -//│ set tmp1 = +⁰(y1, x1); -//│ set x1 = tmp; -//│ set y1 = tmp1; -//│ continue loopLabel -//│ end -//│ unreachable /* Rest of abortive labelled block */ -//│ return inlinedVal -//│ }; -//│ define f⁶ as fun f⁷() { -//│ let x, y, inlinedVal; -//│ set x = 1000; -//│ set y = 0; -//│ block inlinedLbl: -//│ loop loopLabel: -//│ let scrut, tmp, tmp1; -//│ set scrut = Predef⁰.equals⁰(x, 0); -//│ match scrut -//│ true => -//│ set inlinedVal = y; -//│ break inlinedLbl -//│ else -//│ set tmp = -⁰(x, 1); -//│ set tmp1 = +⁰(y, x); -//│ set x = tmp; -//│ set y = tmp1; -//│ continue loopLabel -//│ end -//│ unreachable /* Rest of abortive labelled block */ -//│ return inlinedVal +//│ return loop$tailrec¹(x, y) //│ }; +//│ define f⁶ as fun f⁷() { return loop$tailrec¹(1000, 0) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -409,8 +397,7 @@ fun loop(x)(y) = loop(5)(5) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let loop$tailrec; -//│ @private -//│ define loop$tailrec as fun loop$tailrec¹(x, y) { +//│ define loop$tailrec as fun loop$tailrec²(x, y) { //│ loop loopLabel: //│ let scrut, scrut1, tmp, tmp1, tmp2; //│ set scrut = ===⁰(y, 0); @@ -422,7 +409,7 @@ loop(5)(5) //│ match scrut1 //│ true => //│ set tmp = -⁰(y, 1); -//│ set tmp1 = loop$tailrec¹(5, tmp); +//│ set tmp1 = loop$tailrec²(5, tmp); //│ return +⁰(1, tmp1) //│ else //│ set tmp2 = -⁰(x, 1); @@ -433,8 +420,8 @@ loop(5)(5) //│ unreachable /* Rest of abortive labelled block */ //│ }; //│ @inline -//│ define loop⁴ as fun loop⁵(x)(y) { return loop$tailrec¹(x, y) }; -//│ return loop$tailrec¹(5, 5) +//│ define loop⁴ as fun loop⁵(x)(y) { return loop$tailrec²(x, y) }; +//│ return loop$tailrec²(5, 5) //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— //│ = 5 @@ -470,8 +457,7 @@ fun f(n)(a)(...z) = res //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let f$tailrec; -//│ @private -//│ define f$tailrec as fun f$tailrec³(n, a, z) { +//│ define f$tailrec as fun f$tailrec²(n, a, z) { //│ loop loopLabel: //│ let scrut, res, tmp, tmp1; //│ set scrut = >⁰(n, 0); @@ -490,7 +476,7 @@ fun f(n)(a)(...z) = //│ set tmp2 = -¹(z.length﹖, 0); //│ set inlinedVal = z.slice﹖(1, tmp2); //│ set tmp1 = +⁰(a, 1); -//│ set res = f$tailrec³(n, tmp1, inlinedVal); +//│ set res = f$tailrec²(n, tmp1, inlinedVal); //│ do Predef⁰.print⁰("hi!"); //│ return res //│ else @@ -499,8 +485,7 @@ fun f(n)(a)(...z) = //│ end //│ unreachable /* Rest of abortive labelled block */ //│ }; -//│ @inline -//│ define f⁸ as fun f⁹(n)(a)(...z) { return f$tailrec³(n, a, z) }; +//│ define f⁸ as fun f⁹(n)(a)(...z) { return f$tailrec²(n, a, z) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— diff --git a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls index c9f59cc8e7..e42a8f9a81 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls @@ -323,6 +323,36 @@ fun g(x) = //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— +// Nothing should be rewritten in the non tail calls +:soir +fun f(n, x, ...y) = + if n === 0 then [x, y] + else + f(0, 1, 2, 3) + f(0, ...[1, 2, 3]) + f(0, 1, 2, 3) +//│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— +//│ define f⁸ as fun f⁹(n, x, ...y) { +//│ loop loopLabel: +//│ let scrut, tmp; +//│ set scrut = ===⁰(n, 0); +//│ match scrut +//│ true => +//│ return [x, y] +//│ else +//│ do f⁹(0, 1, 2, 3); +//│ set tmp = [1, 2, 3]; +//│ do f⁹(0, ...tmp); +//│ set n = 0; +//│ set x = 1; +//│ set y = mut [2, 3]; +//│ continue loopLabel +//│ end +//│ unreachable /* Rest of abortive labelled block */ +//│ }; +//│ end +//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— + // Functions inside module definitions are lifted to the top level. This means they cannot yet be optimized. :lift :fixme @@ -332,10 +362,10 @@ module A with @tailcall g(x - 1) A.f(10000) //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.331: fun g(x) = if x < 0 then 0 else @tailcall f(x) +//│ ║ l.361: fun g(x) = if x < 0 then 0 else @tailcall f(x) //│ ╙── ^^^^ //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.332: @tailcall g(x - 1) +//│ ║ l.362: @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 @@ -362,12 +392,12 @@ class A with fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) (new A).f(10) //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.361: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.391: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ ╔══[COMPILATION ERROR] Class methods may not yet be marked @tailrec. -//│ ║ l.361: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.391: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^ //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.362: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) +//│ ║ l.392: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 diff --git a/hkmc2/shared/src/test/mlscript/ups/examples/HindleyMilner.mls b/hkmc2/shared/src/test/mlscript/ups/examples/HindleyMilner.mls index b71a15d0ed..1fb2c2bd7e 100644 --- a/hkmc2/shared/src/test/mlscript/ups/examples/HindleyMilner.mls +++ b/hkmc2/shared/src/test/mlscript/ups/examples/HindleyMilner.mls @@ -243,15 +243,76 @@ fun infer(env, term)(using gen: Gen) = if term is let tv = gen.fresh let env1 = env.extend(name, Scheme(new Set([]), tv)) infer(env1, body) is [s, t] then [s, TFun(s.apply(tv), t)] +//│ FAILURE: Unexpected exception +//│ /!!!\ Uncaught error: java.lang.AssertionError: assertion failed +//│ at: scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:13) +//│ at: hkmc2.TailRecOpt$FunRewriter$1.applyResult(TailRecOpt.scala:551) +//│ at: hkmc2.codegen.BlockTransformer.applyBlock(BlockTransformer.scala:83) +//│ at: hkmc2.TailRecOpt$FunRewriter$1.applyBlock(TailRecOpt.scala:522) +//│ at: hkmc2.codegen.BlockTransformer.applySubBlock(BlockTransformer.scala:29) +//│ at: hkmc2.codegen.BlockTransformer.applyBlock$$anonfun$4(BlockTransformer.scala:85) +//│ at: hkmc2.codegen.BlockTransformer.applyPath$$anonfun$2(BlockTransformer.scala:190) +//│ at: hkmc2.codegen.BlockTransformer.applyValue(BlockTransformer.scala:196) +//│ at: hkmc2.codegen.BlockTransformer.applyPath(BlockTransformer.scala:191) +//│ at: hkmc2.codegen.BlockTransformer.applyPath(BlockTransformer.scala:188) // Type inference with generalization fun inferTop(env, name, term)(using Gen) = if infer(env, term) is [subst, typ] then... [subst, env.generalize(typ)] +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Right of Scope: +//│ parentOrCfg = Right of Scope: +//│ parentOrCfg = Right of Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:definitionMetadata -> definitionMetadata, tmp:prettyPrint -> prettyPrint, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:option -> option, tmp:block$res -> block$res13, t1 -> t1, t2 -> t2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp2, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ curThis = S of N +//│ bindings = HashMap(env -> env, name -> name, term -> term) +//│ defaultImportBindings = HashMap() +//│ bindings = HashMap( -> tmp30) +//│ defaultImportBindings = HashMap() +//│ bindings = HashMap(tmp:inlinedVal -> inlinedVal4, tmp:element1$ -> element1$, tmp:element0$ -> element0$, tmp:tmp -> tmp31) +//│ defaultImportBindings = HashMap() +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' fun (|-) inferType(env, term) = using Gen = new Gen env.generalize(infer(env, term).1).show +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Right of Scope: +//│ parentOrCfg = Right of Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:definitionMetadata -> definitionMetadata, tmp:prettyPrint -> prettyPrint, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:option -> option, tmp:block$res -> block$res13, t1 -> t1, t2 -> t2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp2, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ curThis = S of N +//│ bindings = HashMap(env -> env, term -> term) +//│ defaultImportBindings = HashMap() +//│ bindings = HashMap(member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:inlinedVal -> inlinedVal4) +//│ defaultImportBindings = HashMap() +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' :silent // Example terms @@ -270,32 +331,268 @@ print of compose.show //│ > λf. λg. λx. f (g x) emptyEnv |- id -//│ = "∀t₀. t₀ -> t₀" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:definitionMetadata -> definitionMetadata, tmp:prettyPrint -> prettyPrint, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:option -> option, tmp:block$res -> block$res13, t1 -> t1, t2 -> t2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp2, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL94:1:197 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) emptyEnv |- const -//│ = "∀t₀, t₁. t₀ -> t₁ -> t₀" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, t1 -> t1, t2 -> t2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp2, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL97:1:207 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) emptyEnv |- apply -//│ = "∀t₁, t₂. (t₁ -> t₂) -> t₁ -> t₂" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL100:1:206 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) emptyEnv |- compose -//│ = "∀t₃, t₄, t₂. (t₃ -> t₄) -> (t₂ -> t₃) -> t₂ -> t₄" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL103:1:208 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) :expect "Int" emptyEnv |- IntLit(42) -//│ = "Int" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL106:1:231 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) +//│ ═══[RUNTIME ERROR] Expected: '"Int"', got: 'undefined' :expect "Bool" emptyEnv |- BoolLit(true) -//│ = "Bool" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL109:1:234 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) +//│ ═══[RUNTIME ERROR] Expected: '"Bool"', got: 'undefined' :expect "Int" emptyEnv |- App(id, IntLit(5)) -//│ = "Int" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL112:1:283 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) +//│ ═══[RUNTIME ERROR] Expected: '"Int"', got: 'undefined' :expect "Int" emptyEnv |- App(id, App(id, IntLit(5))) -//│ = "Int" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL115:1:334 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) +//│ ═══[RUNTIME ERROR] Expected: '"Int"', got: 'undefined' :silent let env1 = emptyEnv.extend of @@ -304,11 +601,73 @@ let env1 = emptyEnv.extend of :expect "Int" env1 |- App(Var("id"), IntLit(5)) -//│ = "Int" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, member:Runtime -> Runtime, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL120:1:329 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) +//│ ═══[RUNTIME ERROR] Expected: '"Int"', got: 'undefined' :expect "Bool" env1 |- App(Var("id"), BoolLit(true)) -//│ = "Bool" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL123:1:333 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) +//│ ═══[RUNTIME ERROR] Expected: '"Bool"', got: 'undefined' :silent let env2 = env1.extend of @@ -316,11 +675,55 @@ let env2 = env1.extend of Scheme(new Set(), TFun(TInt, TFun(TInt, TInt))) env2 |- App(App(Var("add"), IntLit(5)), IntLit(5)) -//│ = "Int" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL128:1:434 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) :re env2 |- App(App(Var("add"), IntLit(5)), BoolLit(true)) -//│ ═══[RUNTIME ERROR] Error: Cannot unify Int with Bool +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:tmp -> tmp94, tmp:tmp -> tmp95, tmp:tmp -> tmp96, tmp:tmp -> tmp97, tmp:tmp -> tmp98, env -> env12, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, member:instance$Ident(Gen) -> instance$Ident$_Gen$_11, tmp:tmp -> tmp99, tmp:tmp -> tmp29, tmp:tmp -> tmp100, tmp:block$res -> block$res22, tmp:inlinedVal -> inlinedVal15, tmp:block$res -> block$res41, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined :silent let env3 = env2.extend of @@ -328,19 +731,91 @@ let env3 = env2.extend of Scheme(new Set(["a"]), TFun(TBool, TFun(TVar("a"), TFun(TVar("a"), TVar("a"))))) env3 |- Var("if") -//│ = "∀t₀. Bool -> t₀ -> t₀ -> t₀" +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:tmp -> tmp94, tmp:tmp -> tmp95, tmp:tmp -> tmp96, tmp:tmp -> tmp97, tmp:tmp -> tmp98, env -> env12, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, member:instance$Ident(Gen) -> instance$Ident$_Gen$_11, tmp:tmp -> tmp99, tmp:tmp -> tmp29, tmp:tmp -> tmp100, tmp:block$res -> block$res22, tmp:inlinedVal -> inlinedVal15, tmp:block$res -> block$res41, member:Gen -> Gen1, env3 -> env31, class:Gen -> Gen, tmp:tmp -> tmp101, tmp:tmp -> tmp102, tmp:tmp -> tmp103, tmp:tmp -> tmp104, tmp:tmp -> tmp105, tmp:tmp -> tmp106, tmp:tmp -> tmp107, class:Term -> Term1, tmp:tmp -> tmp108, tmp:tmp -> tmp109, tmp:block$res -> block$res42, class:Var -> Var, tmp:tmp -> tmp110, env -> env13, member:instance$Ident(Gen) -> instance$Ident$_Gen$_12, tmp:tmp -> tmp111, tmp:tmp -> tmp112, tmp:inlinedVal -> inlinedVal16, tmp:block$res -> block$res43, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL136:1:239 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) :silent let t = App(App(App(Var("if"), BoolLit(true)), App(Var("id"), Var("id"))), Var("id")) print of t.show print of env3 |- t +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:tmp -> tmp94, tmp:tmp -> tmp95, tmp:tmp -> tmp96, tmp:tmp -> tmp97, tmp:tmp -> tmp98, env -> env12, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, member:instance$Ident(Gen) -> instance$Ident$_Gen$_11, tmp:tmp -> tmp99, tmp:tmp -> tmp29, tmp:tmp -> tmp100, tmp:block$res -> block$res22, tmp:inlinedVal -> inlinedVal15, tmp:block$res -> block$res41, member:Gen -> Gen1, env3 -> env31, class:Gen -> Gen, tmp:tmp -> tmp101, tmp:tmp -> tmp102, tmp:tmp -> tmp103, tmp:tmp -> tmp104, tmp:tmp -> tmp105, tmp:tmp -> tmp106, tmp:tmp -> tmp107, class:Term -> Term1, tmp:tmp -> tmp108, tmp:tmp -> tmp109, tmp:block$res -> block$res42, class:Var -> Var, tmp:tmp -> tmp110, env -> env13, member:instance$Ident(Gen) -> instance$Ident$_Gen$_12, tmp:tmp -> tmp111, tmp:tmp -> tmp112, tmp:inlinedVal -> inlinedVal16, tmp:block$res -> block$res43, t -> t, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, tmp:tmp -> tmp113, tmp:tmp -> tmp114, tmp:tmp -> tmp115, tmp:tmp -> tmp116, tmp:tmp -> tmp117, tmp:tmp -> tmp118, tmp:tmp -> tmp119, tmp:tmp -> tmp120, env -> env14, term -> term4, tmp:inlinedVal -> inlinedVal17, member:instance$Ident(Gen) -> instance$Ident$_Gen$_13, tmp:tmp -> tmp121, tmp:tmp -> tmp122, tmp:inlinedVal -> inlinedVal18, tmp:block$res -> block$res44, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' //│ > if true (id id) id -//│ > ∀t₆. t₆ -> t₆ +//│ FAILURE: Unexpected runtime error +//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ at REPL139:1:762 +//│ at ContextifyScript.runInThisContext (node:vm:138:12) +//│ at defaultEval (node:repl:608:24) +//│ at REPLEvalInContext (node:repl:691:9) +//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) +//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) +//│ at REPLServer.onLine (node:repl:828:12) +//│ at REPLServer.emit (node:events:514:20) +//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) +//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) :silent :re let t = App(App(App(Var("if"), BoolLit(true)), App(Var("id"), Var("id"))), Var("add")) print of t.show print of env3 |- t +//│ FAILURE: Unexpected compilation error +//│ FAILURE LOCATION: lookup_! (Scope.scala:136) +//│ FAILURE INFO: Tuple2: +//│ _1 = Tuple2: +//│ _1 = member:infer$tailrec⁰ +//│ _2 = class hkmc2.semantics.BlockMemberSymbol +//│ _2 = Scope: +//│ parentOrCfg = Left of Cfg: +//│ escapeChars = true +//│ useSuperscripts = false +//│ includeZero = false +//│ defaultName = "tmp" +//│ curThis = S of S of globalThis:globalThis⁰ +//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:tmp -> tmp94, tmp:tmp -> tmp95, tmp:tmp -> tmp96, tmp:tmp -> tmp97, tmp:tmp -> tmp98, env -> env12, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, member:instance$Ident(Gen) -> instance$Ident$_Gen$_11, tmp:tmp -> tmp99, tmp:tmp -> tmp29, tmp:tmp -> tmp100, tmp:block$res -> block$res22, tmp:inlinedVal -> inlinedVal15, tmp:block$res -> block$res41, member:Gen -> Gen1, env3 -> env31, class:Gen -> Gen, tmp:tmp -> tmp101, tmp:tmp -> tmp102, tmp:tmp -> tmp103, tmp:tmp -> tmp104, tmp:tmp -> tmp105, tmp:tmp -> tmp106, tmp:tmp -> tmp107, class:Term -> Term1, tmp:tmp -> tmp108, tmp:tmp -> tmp109, tmp:block$res -> block$res42, class:Var -> Var, tmp:tmp -> tmp110, env -> env13, member:instance$Ident(Gen) -> instance$Ident$_Gen$_12, tmp:tmp -> tmp111, tmp:tmp -> tmp112, tmp:inlinedVal -> inlinedVal16, tmp:block$res -> block$res43, t -> t, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, tmp:tmp -> tmp113, tmp:tmp -> tmp114, tmp:tmp -> tmp115, tmp:tmp -> tmp116, tmp:tmp -> tmp117, tmp:tmp -> tmp118, tmp:tmp -> tmp119, tmp:tmp -> tmp120, env -> env14, term -> term4, tmp:inlinedVal -> inlinedVal17, member:instance$Ident(Gen) -> instance$Ident$_Gen$_13, tmp:tmp -> tmp121, tmp:tmp -> tmp122, tmp:inlinedVal -> inlinedVal18, tmp:block$res -> block$res44, t -> t3, member:lambda$ -> lambda$, tmp:tmp -> tmp123, tmp:tmp -> tmp124, tmp:tmp -> tmp125, tmp:tmp -> tmp126, tmp:tmp -> tmp127, tmp:tmp -> tmp128, tmp:tmp -> tmp129, tmp:tmp -> tmp130, env -> env15, term -> term5, tmp:inlinedVal -> inlinedVal19, member:instance$Ident(Gen) -> instance$Ident$_Gen$_14, tmp:tmp -> tmp131, tmp:tmp -> tmp132, tmp:inlinedVal -> inlinedVal20, tmp:block$res -> block$res45, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) +//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) +//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' //│ > if true (id id) add -//│ ═══[RUNTIME ERROR] Error: Cannot unify Int with Int -> Int +//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined From 94e31ba89ded26dfc7877b956d9c4ba90360a903 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 17:14:41 +0800 Subject: [PATCH 06/13] use hasWrapper, update tests --- .../main/scala/hkmc2/codegen/TailRecOpt.scala | 2 +- .../mlscript/ups/examples/HindleyMilner.mls | 505 +----------------- 2 files changed, 16 insertions(+), 491 deletions(-) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala index f07dc3599a..3f643eeb17 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala @@ -337,7 +337,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): // Multiple functions: Create a wrapper. else (true, BlockMemberSymbol(funs.iterator.map(_.sym.nme).mkString("_"), Nil, true)) val dSym = - if bms is funs.head.sym then funs.head.dSym + if !hasWrapper then funs.head.dSym else TermSymbol(syntax.Fun, owner, Tree.Ident(bms.nme)) val maxParamLen = maxInt(funs, paramsLen) diff --git a/hkmc2/shared/src/test/mlscript/ups/examples/HindleyMilner.mls b/hkmc2/shared/src/test/mlscript/ups/examples/HindleyMilner.mls index 1fb2c2bd7e..b71a15d0ed 100644 --- a/hkmc2/shared/src/test/mlscript/ups/examples/HindleyMilner.mls +++ b/hkmc2/shared/src/test/mlscript/ups/examples/HindleyMilner.mls @@ -243,76 +243,15 @@ fun infer(env, term)(using gen: Gen) = if term is let tv = gen.fresh let env1 = env.extend(name, Scheme(new Set([]), tv)) infer(env1, body) is [s, t] then [s, TFun(s.apply(tv), t)] -//│ FAILURE: Unexpected exception -//│ /!!!\ Uncaught error: java.lang.AssertionError: assertion failed -//│ at: scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:13) -//│ at: hkmc2.TailRecOpt$FunRewriter$1.applyResult(TailRecOpt.scala:551) -//│ at: hkmc2.codegen.BlockTransformer.applyBlock(BlockTransformer.scala:83) -//│ at: hkmc2.TailRecOpt$FunRewriter$1.applyBlock(TailRecOpt.scala:522) -//│ at: hkmc2.codegen.BlockTransformer.applySubBlock(BlockTransformer.scala:29) -//│ at: hkmc2.codegen.BlockTransformer.applyBlock$$anonfun$4(BlockTransformer.scala:85) -//│ at: hkmc2.codegen.BlockTransformer.applyPath$$anonfun$2(BlockTransformer.scala:190) -//│ at: hkmc2.codegen.BlockTransformer.applyValue(BlockTransformer.scala:196) -//│ at: hkmc2.codegen.BlockTransformer.applyPath(BlockTransformer.scala:191) -//│ at: hkmc2.codegen.BlockTransformer.applyPath(BlockTransformer.scala:188) // Type inference with generalization fun inferTop(env, name, term)(using Gen) = if infer(env, term) is [subst, typ] then... [subst, env.generalize(typ)] -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Right of Scope: -//│ parentOrCfg = Right of Scope: -//│ parentOrCfg = Right of Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:definitionMetadata -> definitionMetadata, tmp:prettyPrint -> prettyPrint, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:option -> option, tmp:block$res -> block$res13, t1 -> t1, t2 -> t2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp2, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ curThis = S of N -//│ bindings = HashMap(env -> env, name -> name, term -> term) -//│ defaultImportBindings = HashMap() -//│ bindings = HashMap( -> tmp30) -//│ defaultImportBindings = HashMap() -//│ bindings = HashMap(tmp:inlinedVal -> inlinedVal4, tmp:element1$ -> element1$, tmp:element0$ -> element0$, tmp:tmp -> tmp31) -//│ defaultImportBindings = HashMap() -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' fun (|-) inferType(env, term) = using Gen = new Gen env.generalize(infer(env, term).1).show -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Right of Scope: -//│ parentOrCfg = Right of Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:definitionMetadata -> definitionMetadata, tmp:prettyPrint -> prettyPrint, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:option -> option, tmp:block$res -> block$res13, t1 -> t1, t2 -> t2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp2, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ curThis = S of N -//│ bindings = HashMap(env -> env, term -> term) -//│ defaultImportBindings = HashMap() -//│ bindings = HashMap(member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:inlinedVal -> inlinedVal4) -//│ defaultImportBindings = HashMap() -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' :silent // Example terms @@ -331,268 +270,32 @@ print of compose.show //│ > λf. λg. λx. f (g x) emptyEnv |- id -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:definitionMetadata -> definitionMetadata, tmp:prettyPrint -> prettyPrint, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:option -> option, tmp:block$res -> block$res13, t1 -> t1, t2 -> t2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp2, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL94:1:197 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ = "∀t₀. t₀ -> t₀" emptyEnv |- const -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, t1 -> t1, t2 -> t2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp2, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL97:1:207 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ = "∀t₀, t₁. t₀ -> t₁ -> t₀" emptyEnv |- apply -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, tmp:tmp -> tmp5, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL100:1:206 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ = "∀t₁, t₂. (t₁ -> t₂) -> t₁ -> t₂" emptyEnv |- compose -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, tmp:block$res -> block$res2, member:Option -> Option, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL103:1:208 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ = "∀t₃, t₄, t₂. (t₃ -> t₄) -> (t₂ -> t₃) -> t₂ -> t₄" :expect "Int" emptyEnv |- IntLit(42) -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, member:TPrim -> TPrim1, tmp:tmp -> tmp8, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:block$res -> block$res17, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL106:1:231 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) -//│ ═══[RUNTIME ERROR] Expected: '"Int"', got: 'undefined' +//│ = "Int" :expect "Bool" emptyEnv |- BoolLit(true) -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp14, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, tmp:tmp -> tmp19, tmp:inlinedVal -> inlinedVal2, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL109:1:234 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) -//│ ═══[RUNTIME ERROR] Expected: '"Bool"', got: 'undefined' +//│ = "Bool" :expect "Int" emptyEnv |- App(id, IntLit(5)) -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, member:lambda$ -> lambda$, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:block$res -> block$res7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, tmp:tmp -> tmp, tmp:tmp -> tmp24, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, member:applyPattern -> applyPattern, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, tmp:block$res -> block$res11, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:unify -> unify, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:block$res -> block$res25, id -> id, const -> const1, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, apply -> apply, tmp:block$res -> block$res6, tmp:tmp -> tmp29, tmp:block$res -> block$res22, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, member:Gen -> Gen1, class:Gen -> Gen, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, class:Term -> Term1, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, class:Var -> Var, tmp:block$res -> block$res27, env -> env, term -> term, tmp:block$res -> block$res23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, class:IntLit -> IntLit, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, class:BoolLit -> BoolLit, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL112:1:283 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) -//│ ═══[RUNTIME ERROR] Expected: '"Int"', got: 'undefined' +//│ = "Int" :expect "Int" emptyEnv |- App(id, App(id, IntLit(5))) -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:scrut -> scrut3, member:Unify -> Unify1, tmp:block$res -> block$res20, pattern:Unify -> Unify, member:Env -> Env1, class:Env -> Env, member:Iter -> Iter, class:TVar -> TVar, class:TPrim -> TPrim, member:Runtime -> Runtime, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL115:1:334 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) -//│ ═══[RUNTIME ERROR] Expected: '"Int"', got: 'undefined' +//│ = "Int" :silent let env1 = emptyEnv.extend of @@ -601,73 +304,11 @@ let env1 = emptyEnv.extend of :expect "Int" env1 |- App(Var("id"), IntLit(5)) -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, member:Runtime -> Runtime, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL120:1:329 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) -//│ ═══[RUNTIME ERROR] Expected: '"Int"', got: 'undefined' +//│ = "Int" :expect "Bool" env1 |- App(Var("id"), BoolLit(true)) -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, tmp:block$res -> block$res3, TInt -> TInt, TBool -> TBool, tmp:block$res -> block$res4, member:Term -> Term2, member:IntLit -> IntLit1, member:Var -> Var1, member:App -> App1, member:Abs -> Abs1, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL123:1:333 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: processIRBlock (JSBackendDiffMaker.scala:299) -//│ ═══[RUNTIME ERROR] Expected: '"Bool"', got: 'undefined' +//│ = "Bool" :silent let env2 = env1.extend of @@ -675,55 +316,11 @@ let env2 = env1.extend of Scheme(new Set(), TFun(TInt, TFun(TInt, TInt))) env2 |- App(App(Var("add"), IntLit(5)), IntLit(5)) -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, tmp:tmp -> tmp29, tmp:block$res -> block$res22, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL128:1:434 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ = "Int" :re env2 |- App(App(Var("add"), IntLit(5)), BoolLit(true)) -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:tmp -> tmp94, tmp:tmp -> tmp95, tmp:tmp -> tmp96, tmp:tmp -> tmp97, tmp:tmp -> tmp98, env -> env12, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, member:instance$Ident(Gen) -> instance$Ident$_Gen$_11, tmp:tmp -> tmp99, tmp:tmp -> tmp29, tmp:tmp -> tmp100, tmp:block$res -> block$res22, tmp:inlinedVal -> inlinedVal15, tmp:block$res -> block$res41, member:Gen -> Gen1, class:Gen -> Gen, class:Term -> Term1, class:Var -> Var, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ ═══[RUNTIME ERROR] Error: Cannot unify Int with Bool :silent let env3 = env2.extend of @@ -731,91 +328,19 @@ let env3 = env2.extend of Scheme(new Set(["a"]), TFun(TBool, TFun(TVar("a"), TFun(TVar("a"), TVar("a"))))) env3 |- Var("if") -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:tmp -> tmp94, tmp:tmp -> tmp95, tmp:tmp -> tmp96, tmp:tmp -> tmp97, tmp:tmp -> tmp98, env -> env12, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, member:instance$Ident(Gen) -> instance$Ident$_Gen$_11, tmp:tmp -> tmp99, tmp:tmp -> tmp29, tmp:tmp -> tmp100, tmp:block$res -> block$res22, tmp:inlinedVal -> inlinedVal15, tmp:block$res -> block$res41, member:Gen -> Gen1, env3 -> env31, class:Gen -> Gen, tmp:tmp -> tmp101, tmp:tmp -> tmp102, tmp:tmp -> tmp103, tmp:tmp -> tmp104, tmp:tmp -> tmp105, tmp:tmp -> tmp106, tmp:tmp -> tmp107, class:Term -> Term1, tmp:tmp -> tmp108, tmp:tmp -> tmp109, tmp:block$res -> block$res42, class:Var -> Var, tmp:tmp -> tmp110, env -> env13, member:instance$Ident(Gen) -> instance$Ident$_Gen$_12, tmp:tmp -> tmp111, tmp:tmp -> tmp112, tmp:inlinedVal -> inlinedVal16, tmp:block$res -> block$res43, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL136:1:239 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ = "∀t₀. Bool -> t₀ -> t₀ -> t₀" :silent let t = App(App(App(Var("if"), BoolLit(true)), App(Var("id"), Var("id"))), Var("id")) print of t.show print of env3 |- t -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:tmp -> tmp94, tmp:tmp -> tmp95, tmp:tmp -> tmp96, tmp:tmp -> tmp97, tmp:tmp -> tmp98, env -> env12, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, member:instance$Ident(Gen) -> instance$Ident$_Gen$_11, tmp:tmp -> tmp99, tmp:tmp -> tmp29, tmp:tmp -> tmp100, tmp:block$res -> block$res22, tmp:inlinedVal -> inlinedVal15, tmp:block$res -> block$res41, member:Gen -> Gen1, env3 -> env31, class:Gen -> Gen, tmp:tmp -> tmp101, tmp:tmp -> tmp102, tmp:tmp -> tmp103, tmp:tmp -> tmp104, tmp:tmp -> tmp105, tmp:tmp -> tmp106, tmp:tmp -> tmp107, class:Term -> Term1, tmp:tmp -> tmp108, tmp:tmp -> tmp109, tmp:block$res -> block$res42, class:Var -> Var, tmp:tmp -> tmp110, env -> env13, member:instance$Ident(Gen) -> instance$Ident$_Gen$_12, tmp:tmp -> tmp111, tmp:tmp -> tmp112, tmp:inlinedVal -> inlinedVal16, tmp:block$res -> block$res43, t -> t, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, tmp:tmp -> tmp113, tmp:tmp -> tmp114, tmp:tmp -> tmp115, tmp:tmp -> tmp116, tmp:tmp -> tmp117, tmp:tmp -> tmp118, tmp:tmp -> tmp119, tmp:tmp -> tmp120, env -> env14, term -> term4, tmp:inlinedVal -> inlinedVal17, member:instance$Ident(Gen) -> instance$Ident$_Gen$_13, tmp:tmp -> tmp121, tmp:tmp -> tmp122, tmp:inlinedVal -> inlinedVal18, tmp:block$res -> block$res44, member:lambda$ -> lambda$, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' //│ > if true (id id) id -//│ FAILURE: Unexpected runtime error -//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:259) -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined -//│ at REPL139:1:762 -//│ at ContextifyScript.runInThisContext (node:vm:138:12) -//│ at defaultEval (node:repl:608:24) -//│ at REPLEvalInContext (node:repl:691:9) -//│ at AsyncLocalStorage.run (node:internal/async_local_storage/async_context_frame:66:14) -//│ at REPLServer.REPLEval [as eval] (node:repl:690:19) -//│ at REPLServer.onLine (node:repl:828:12) -//│ at REPLServer.emit (node:events:514:20) -//│ at [_onLine] [as _onLine] (node:internal/readline/interface:474:12) -//│ at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:669:18) +//│ > ∀t₆. t₆ -> t₆ :silent :re let t = App(App(App(Var("if"), BoolLit(true)), App(Var("id"), Var("id"))), Var("add")) print of t.show print of env3 |- t -//│ FAILURE: Unexpected compilation error -//│ FAILURE LOCATION: lookup_! (Scope.scala:136) -//│ FAILURE INFO: Tuple2: -//│ _1 = Tuple2: -//│ _1 = member:infer$tailrec⁰ -//│ _2 = class hkmc2.semantics.BlockMemberSymbol -//│ _2 = Scope: -//│ parentOrCfg = Left of Cfg: -//│ escapeChars = true -//│ useSuperscripts = false -//│ includeZero = false -//│ defaultName = "tmp" -//│ curThis = S of S of globalThis:globalThis⁰ -//│ bindings = HashMap(term -> term1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_1, tmp:runtime -> runtime, tmp:block$res -> block$res12, tmp:tmp -> tmp46, tmp:definitionMetadata -> definitionMetadata, tmp:tmp -> tmp47, tmp:prettyPrint -> prettyPrint, tmp:inlinedVal -> inlinedVal5, tmp:Term -> Term, tmp:Block -> Block, tmp:tmp -> tmp1, tmp:block$res -> block$res29, tmp:option -> option, tmp:block$res -> block$res13, env -> env2, term -> term2, t1 -> t1, t2 -> t2, member:instance$Ident(Gen) -> instance$Ident$_Gen$_2, tmp:inlinedVal -> inlinedVal, tmp:tmp -> tmp48, tmp:tmp -> tmp49, tmp:tmp -> tmp2, tmp:inlinedVal -> inlinedVal6, tmp:scrut -> scrut, tmp:block$res -> block$res14, tmp:block$res -> block$res30, env -> env3, term -> term3, tmp:tmp -> tmp3, tmp:tmp -> tmp4, tmp:block$res -> block$res15, member:instance$Ident(Gen) -> instance$Ident$_Gen$_3, tmp:tmp -> tmp50, tmp:tmp -> tmp51, tmp:inlinedVal -> inlinedVal7, tmp:tmp -> tmp5, tmp:block$res -> block$res31, t2 -> t21, tmp:inlinedVal -> inlinedVal1, tmp:tmp -> tmp52, env -> env4, tmp:block$res -> block$res, tmp:tmp -> tmp6, tmp:scrut -> scrut1, tmp:block$res -> block$res1, tmp:block$res -> block$res16, member:instance$Ident(Gen) -> instance$Ident$_Gen$_4, tmp:block$res -> block$res2, tmp:tmp -> tmp53, tmp:tmp -> tmp54, tmp:inlinedVal -> inlinedVal8, member:Option -> Option, tmp:block$res -> block$res32, member:Type -> Type1, member:TVar -> TVar1, member:TFun -> TFun1, tmp:tmp -> tmp7, tmp:tmp -> tmp55, member:TPrim -> TPrim1, tmp:tmp -> tmp8, env -> env5, class:Type -> Type, tmp:tmp -> tmp9, tmp:tmp -> tmp10, tmp:tmp -> tmp11, tmp:tmp -> tmp12, member:instance$Ident(Gen) -> instance$Ident$_Gen$_5, class:TFun -> TFun, tmp:tmp -> tmp13, tmp:tmp -> tmp56, tmp:block$res -> block$res17, tmp:tmp -> tmp57, tmp:inlinedVal -> inlinedVal9, tmp:block$res -> block$res33, tmp:tmp -> tmp58, tmp:tmp -> tmp59, tmp:tmp -> tmp14, env -> env6, tmp:tmp -> tmp15, tmp:tmp -> tmp16, tmp:tmp -> tmp17, tmp:tmp -> tmp18, member:instance$Ident(Gen) -> instance$Ident$_Gen$_6, tmp:tmp -> tmp19, tmp:tmp -> tmp60, tmp:tmp -> tmp61, tmp:inlinedVal -> inlinedVal10, tmp:inlinedVal -> inlinedVal2, tmp:block$res -> block$res34, tmp:tmp -> tmp20, tmp:scrut -> scrut2, tmp:block$res -> block$res18, tmp:tmp -> tmp62, tmp:tmp -> tmp63, tmp:tmp -> tmp64, tmp:block$res -> block$res7, env -> env7, emptySub -> emptySub, tmp:tmp -> tmp21, tmp:tmp -> tmp22, tmp:tmp -> tmp23, member:instance$Ident(Gen) -> instance$Ident$_Gen$_7, tmp:tmp -> tmp, tmp:tmp -> tmp24, tmp:tmp -> tmp65, member:Predef -> Predef, tmp:block$res -> block$res8, tmp:block$res -> block$res19, tmp:tmp -> tmp66, tmp:inlinedVal -> inlinedVal11, member:applyPattern -> applyPattern, tmp:block$res -> block$res35, env1 -> env11, tmp:tmp -> tmp25, tmp:tmp -> tmp26, tmp:tmp -> tmp27, tmp:inlinedVal -> inlinedVal3, tmp:tmp -> tmp67, tmp:tmp -> tmp68, tmp:block$res -> block$res9, tmp:tmp -> tmp28, tmp:tmp -> tmp69, tmp:scrut -> scrut3, tmp:tmp -> tmp70, member:Unify -> Unify1, tmp:block$res -> block$res20, tmp:tmp -> tmp71, pattern:Unify -> Unify, tmp:tmp -> tmp72, tmp:block$res -> block$res36, member:Env -> Env1, class:Env -> Env, tmp:tmp -> tmp73, tmp:tmp -> tmp74, member:Iter -> Iter, tmp:tmp -> tmp75, class:TVar -> TVar, env -> env8, member:instance$Ident(Gen) -> instance$Ident$_Gen$_8, tmp:tmp -> tmp76, tmp:tmp -> tmp77, tmp:inlinedVal -> inlinedVal12, tmp:block$res -> block$res37, class:TPrim -> TPrim, tmp:tmp -> tmp78, member:Runtime -> Runtime, tmp:tmp -> tmp79, tmp:tmp -> tmp80, env -> env9, member:instance$Ident(Gen) -> instance$Ident$_Gen$_9, tmp:tmp -> tmp81, tmp:tmp -> tmp82, tmp:inlinedVal -> inlinedVal13, tmp:block$res -> block$res38, env2 -> env21, tmp:tmp -> tmp83, tmp:tmp -> tmp84, tmp:tmp -> tmp85, tmp:tmp -> tmp86, tmp:block$res -> block$res39, tmp:block$res -> block$res3, tmp:tmp -> tmp87, TInt -> TInt, tmp:tmp -> tmp88, tmp:tmp -> tmp89, TBool -> TBool, tmp:tmp -> tmp90, tmp:tmp -> tmp91, tmp:block$res -> block$res4, env -> env10, member:Term -> Term2, member:IntLit -> IntLit1, member:instance$Ident(Gen) -> instance$Ident$_Gen$_10, member:Var -> Var1, tmp:tmp -> tmp92, member:App -> App1, tmp:tmp -> tmp93, member:Abs -> Abs1, tmp:inlinedVal -> inlinedVal14, member:BoolLit -> BoolLit1, member:ShowTerm -> ShowTerm1, tmp:block$res -> block$res40, pattern:ShowTerm -> ShowTerm, class:Abs -> Abs, tmp:tmp -> tmp94, tmp:tmp -> tmp95, tmp:tmp -> tmp96, tmp:tmp -> tmp97, tmp:tmp -> tmp98, env -> env12, class:App -> App, tmp:block$res -> block$res21, emptyEnv -> emptyEnv, member:instance$Ident(Gen) -> instance$Ident$_Gen$_11, tmp:tmp -> tmp99, tmp:tmp -> tmp29, tmp:tmp -> tmp100, tmp:block$res -> block$res22, tmp:inlinedVal -> inlinedVal15, tmp:block$res -> block$res41, member:Gen -> Gen1, env3 -> env31, class:Gen -> Gen, tmp:tmp -> tmp101, tmp:tmp -> tmp102, tmp:tmp -> tmp103, tmp:tmp -> tmp104, tmp:tmp -> tmp105, tmp:tmp -> tmp106, tmp:tmp -> tmp107, class:Term -> Term1, tmp:tmp -> tmp108, tmp:tmp -> tmp109, tmp:block$res -> block$res42, class:Var -> Var, tmp:tmp -> tmp110, env -> env13, member:instance$Ident(Gen) -> instance$Ident$_Gen$_12, tmp:tmp -> tmp111, tmp:tmp -> tmp112, tmp:inlinedVal -> inlinedVal16, tmp:block$res -> block$res43, t -> t, tmp:block$res -> block$res23, class:IntLit -> IntLit, class:BoolLit -> BoolLit, tmp:tmp -> tmp113, tmp:tmp -> tmp114, tmp:tmp -> tmp115, tmp:tmp -> tmp116, tmp:tmp -> tmp117, tmp:tmp -> tmp118, tmp:tmp -> tmp119, tmp:tmp -> tmp120, env -> env14, term -> term4, tmp:inlinedVal -> inlinedVal17, member:instance$Ident(Gen) -> instance$Ident$_Gen$_13, tmp:tmp -> tmp121, tmp:tmp -> tmp122, tmp:inlinedVal -> inlinedVal18, tmp:block$res -> block$res44, t -> t3, member:lambda$ -> lambda$, tmp:tmp -> tmp123, tmp:tmp -> tmp124, tmp:tmp -> tmp125, tmp:tmp -> tmp126, tmp:tmp -> tmp127, tmp:tmp -> tmp128, tmp:tmp -> tmp129, tmp:tmp -> tmp130, env -> env15, term -> term5, tmp:inlinedVal -> inlinedVal19, member:instance$Ident(Gen) -> instance$Ident$_Gen$_14, tmp:tmp -> tmp131, tmp:tmp -> tmp132, tmp:inlinedVal -> inlinedVal20, tmp:block$res -> block$res45, member:inferTop -> inferTop, tmp:block$res -> block$res5, member:Scheme -> Scheme1, class:Scheme -> Scheme, tmp:block$res -> block$res24, tmp:block$res -> block$res10, member:unify' -> unify$_, member:inferType -> inferType, tmp:block$res -> block$res11, member:unify -> unify, tmp:block$res -> block$res25, id -> id, const -> const1, apply -> apply, tmp:block$res -> block$res6, compose -> compose, member:Subst -> Subst1, class:Subst -> Subst, tmp:tmp -> tmp30, tmp:tmp -> tmp31, tmp:tmp -> tmp32, tmp:tmp -> tmp33, tmp:tmp -> tmp34, tmp:tmp -> tmp35, tmp:tmp -> tmp36, tmp:tmp -> tmp37, tmp:tmp -> tmp38, tmp:tmp -> tmp39, tmp:tmp -> tmp40, tmp:tmp -> tmp41, tmp:tmp -> tmp42, tmp:tmp -> tmp43, tmp:block$res -> block$res26, tmp:block$res -> block$res27, env -> env, term -> term, member:instance$Ident(Gen) -> instance$Ident$_Gen$_, tmp:tmp -> tmp44, tmp:tmp -> tmp45, tmp:inlinedVal -> inlinedVal4, tmp:block$res -> block$res28, env -> env1) -//│ defaultImportBindings = HashMap(/storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Iter.mjs -> Iter, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Option.mjs -> Option, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs -> Runtime, /storage/mark/Repos/mlscript/hkmc2/shared/src/test/mlscript-compile/Predef.mjs -> Predef) -//│ ═══[COMPILATION ERROR] No definition found in scope for member 'infer$tailrec' //│ > if true (id id) add -//│ ═══[RUNTIME ERROR] ReferenceError: infer$tailrec is not defined +//│ ═══[RUNTIME ERROR] Error: Cannot unify Int with Int -> Int From 1dcd822735e1c9c0af3dae01f5110227cdc2f283 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 17:16:37 +0800 Subject: [PATCH 07/13] make wrapper private --- .../main/scala/hkmc2/codegen/TailRecOpt.scala | 2 +- .../test/mlscript/tailrec/MultiArgLists.mls | 43 ++++++++----------- .../src/test/mlscript/tailrec/TailRecOpt.mls | 29 +++++++------ 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala index 3f643eeb17..41125bd45d 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala @@ -605,7 +605,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val loopDefn = FunDefn( owner, bms, dSym, newParamLists, - loop)(N, annotations = Nil) // Q: maybe should be Private? + loop)(N, annotations = Annot.Private :: Nil) (S(loopDefn), wrappers) def optFunctions(fs: List[FunDefn], owner: Opt[InnerSymbol])(using (ScopeData, AccessMap)) = diff --git a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls index 5bbceb2fc3..e869e1248a 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls @@ -20,6 +20,7 @@ fun loop(x)(y) = loop(1000)(0) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let loop$tailrec; +//│ @private //│ define loop$tailrec as fun loop$tailrec⁰(x, y) { //│ loop loopLabel: //│ let scrut, tmp, tmp1; @@ -51,6 +52,7 @@ fun count(start)(stop) = count(0)(100) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let count$tailrec, start, stop, inlinedVal; +//│ @private //│ define count$tailrec as fun count$tailrec⁰(start1, stop1) { //│ loop loopLabel: //│ let scrut, tmp; @@ -95,6 +97,7 @@ fun even(n)(dummy) = if n == 0 then [true, dummy] else odd(n - 1)(dummy + 1) fun odd(n)(dummy) = if n == 0 then [false, dummy] else even(n - 1)(dummy + 1) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let even_odd; +//│ @private //│ define even_odd as fun even_odd⁰(id, param0, param1) { //│ loop loopLabel: //│ match id @@ -167,7 +170,8 @@ fun handleEffect(x) = fun resume(x)(y) = handleEffects(x) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let handleEffects_handleEffect; -//│ define handleEffects_handleEffect as fun handleEffects_handleEffect⁰(id, param0) { +//│ @private +//│ define handleEffects_handleEffect as fun handleEffects_handleEffect⁰(id) { //│ loop loopLabel: //│ match id //│ 0 => @@ -175,7 +179,7 @@ fun resume(x)(y) = handleEffects(x) //│ continue loopLabel //│ 1 => //│ let tmp; -//│ set tmp = resume⁰(param0); +//│ set tmp = resume⁰(undefined); //│ do sink⁰.push﹖(tmp); //│ set id = 0; //│ continue loopLabel @@ -185,10 +189,10 @@ fun resume(x)(y) = handleEffects(x) //│ end //│ }; //│ define handleEffects⁰ as fun handleEffects¹(x) { -//│ return handleEffects_handleEffect⁰(0, x) +//│ return handleEffects_handleEffect⁰(0) //│ }; //│ define handleEffect⁰ as fun handleEffect¹(x) { -//│ return handleEffects_handleEffect⁰(1, x) +//│ return handleEffects_handleEffect⁰(1) //│ }; //│ @inline //│ define resume¹ as fun resume⁰(x)(y) { return handleEffects¹(x) }; @@ -209,7 +213,8 @@ fun g(n)(m) = @tailcall f(n - 1)(...[1, 2], 3, ...[3, 4], ...[5, n], 7, n)(m) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let f_g; -//│ define f_g as fun f_g⁰(id, param0, param1, param2, param3, param4, param5, param6) { +//│ @private +//│ define f_g as fun f_g⁰(id, param0, param1, param5, param6) { //│ loop loopLabel: //│ match id //│ 0 => @@ -250,12 +255,10 @@ fun g(n)(m) = //│ end //│ }; //│ define f⁰ as fun f¹(n)(a, b, c, d, ...e)(m) { -//│ return f_g⁰(0, n, a, b, c, d, e, m) +//│ return f_g⁰(0, n, a, e, m) //│ }; //│ @inline -//│ define g⁰ as fun g¹(n)(m) { -//│ return f_g⁰(1, n, m, undefined, undefined, undefined, undefined, undefined) -//│ }; +//│ define g⁰ as fun g¹(n)(m) { return f_g⁰(1, n, m, undefined, undefined) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -314,14 +317,7 @@ fun f(a)(b) = f(a)(b) //│ sym = member:f$tailrec⁰ //│ dSym = term:f$tailrec¹ //│ params = Ls of -//│ ParamList: -//│ params = Ls of -//│ Param: -//│ sym = a⁰ -//│ modulefulness = Modulefulness of N -//│ Param: -//│ sym = b⁰ -//│ modulefulness = Modulefulness of N +//│ ParamList: ‹empty› //│ body = Label: //│ label = label:loopLabel⁰ //│ loop = true @@ -335,23 +331,19 @@ fun f(a)(b) = f(a)(b) //│ ParamList: //│ params = Ls of //│ Param: -//│ sym = a¹ +//│ sym = a⁰ //│ modulefulness = Modulefulness of N //│ ParamList: //│ params = Ls of //│ Param: -//│ sym = b¹ +//│ sym = b⁰ //│ modulefulness = Modulefulness of N //│ body = Return of Call: //│ fun = MemberRef{disamb=term:f$tailrec¹}: //│ bms = member:f$tailrec⁰ //│ disamb = term:f$tailrec¹ //│ argss = Ls of -//│ Ls of -//│ Arg: -//│ value = SimpleRef of a¹ -//│ Arg: -//│ value = SimpleRef of b¹ +//│ Nil //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -364,6 +356,7 @@ fun loop(x)(y) = fun f = loop(1000)(0) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let loop$tailrec; +//│ @private //│ define loop$tailrec as fun loop$tailrec¹(x, y) { //│ loop loopLabel: //│ let scrut, tmp, tmp1; @@ -397,6 +390,7 @@ fun loop(x)(y) = loop(5)(5) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let loop$tailrec; +//│ @private //│ define loop$tailrec as fun loop$tailrec²(x, y) { //│ loop loopLabel: //│ let scrut, scrut1, tmp, tmp1, tmp2; @@ -457,6 +451,7 @@ fun f(n)(a)(...z) = res //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let f$tailrec; +//│ @private //│ define f$tailrec as fun f$tailrec²(n, a, z) { //│ loop loopLabel: //│ let scrut, res, tmp, tmp1; diff --git a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls index e42a8f9a81..6faa4adefa 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls @@ -19,6 +19,7 @@ fun f(a, b, c) = f(10000, 20000, 0) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let g_f; +//│ @private //│ define g_f as fun g_f⁰(id, param0, param1, param2, param3) { //│ loop loopLabel: //│ match id @@ -152,7 +153,8 @@ fun g(n) = @tailcall f(n, ...[1, 2], 3, ...[3, 4], ...[5, n], 7, n) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let f_g; -//│ define f_g as fun f_g⁰(id, param0, param1, param2, param3, param4, param5) { +//│ @private +//│ define f_g as fun f_g⁰(id, param0, param5) { //│ loop loopLabel: //│ match id //│ 0 => @@ -189,11 +191,9 @@ fun g(n) = //│ end //│ }; //│ define f² as fun f³(n, a, b, c, d, ...e) { -//│ return f_g⁰(0, n, a, b, c, d, e) -//│ }; -//│ define g² as fun g³(n) { -//│ return f_g⁰(1, n, undefined, undefined, undefined, undefined, undefined) +//│ return f_g⁰(0, n, e) //│ }; +//│ define g² as fun g³(n) { return f_g⁰(1, n, undefined) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -304,22 +304,23 @@ fun g(x) = 0 //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let f_g; -//│ define f_g as fun f_g¹(id, param0) { +//│ @private +//│ define f_g as fun f_g¹(id) { //│ loop loopLabel: //│ match id //│ 0 => //│ set id = 1; //│ continue loopLabel //│ 1 => -//│ do f_g¹(0, param0); +//│ do f_g¹(0); //│ return 0 //│ else //│ end //│ end //│ end //│ }; -//│ define f⁶ as fun f⁷(x) { return f_g¹(0, x) }; -//│ define g⁴ as fun g⁵(x) { return f_g¹(1, x) }; +//│ define f⁶ as fun f⁷(x) { return f_g¹(0) }; +//│ define g⁴ as fun g⁵(x) { return f_g¹(1) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -362,10 +363,10 @@ module A with @tailcall g(x - 1) A.f(10000) //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.361: fun g(x) = if x < 0 then 0 else @tailcall f(x) +//│ ║ l.362: fun g(x) = if x < 0 then 0 else @tailcall f(x) //│ ╙── ^^^^ //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.362: @tailcall g(x - 1) +//│ ║ l.363: @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 @@ -392,12 +393,12 @@ class A with fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) (new A).f(10) //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.391: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.392: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ ╔══[COMPILATION ERROR] Class methods may not yet be marked @tailrec. -//│ ║ l.391: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.392: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^ //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.392: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) +//│ ║ l.393: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 From 0f09d301c9b2c7bf1e0336a838749ec1c0644611 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 21:19:04 +0800 Subject: [PATCH 08/13] add back inline annotation --- .../main/scala/hkmc2/codegen/TailRecOpt.scala | 8 +- .../test/mlscript/tailrec/MultiArgLists.mls | 144 +++++++++++------- .../src/test/mlscript/tailrec/TailRecOpt.mls | 18 ++- 3 files changed, 103 insertions(+), 67 deletions(-) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala index 41125bd45d..2b8e7dfe29 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala @@ -595,17 +595,21 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val newBod = Return( rewriteKnownCall(f, paramArgs), ) - FunDefn(f.owner, f.sym, f.dSym, f.params, newBod)(N, f.annotations) + val annots = if f.inline then f.annotations else Annot.Inline :: f.annotations + FunDefn(f.owner, f.sym, f.dSym, f.params, newBod)(N, annots) val newParamLists = val initial = paramSyms.map(Param.simple(_)) if funsLen > 1 then PlainParamList(Param.simple(curIdSym) :: initial) :: Nil else PlainParamList(initial) :: Nil + val annotations = + if funsLen == 1 && funs.head.inline then Annot.Inline :: Annot.Private :: Nil + else Annot.Private :: Nil val loopDefn = FunDefn( owner, bms, dSym, newParamLists, - loop)(N, annotations = Annot.Private :: Nil) + loop)(N, annotations = annotations) (S(loopDefn), wrappers) def optFunctions(fs: List[FunDefn], owner: Opt[InnerSymbol])(using (ScopeData, AccessMap)) = diff --git a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls index e869e1248a..19ffbc2191 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls @@ -188,14 +188,18 @@ fun resume(x)(y) = handleEffects(x) //│ end //│ end //│ }; +//│ @inline //│ define handleEffects⁰ as fun handleEffects¹(x) { //│ return handleEffects_handleEffect⁰(0) //│ }; +//│ @inline //│ define handleEffect⁰ as fun handleEffect¹(x) { //│ return handleEffects_handleEffect⁰(1) //│ }; //│ @inline -//│ define resume¹ as fun resume⁰(x)(y) { return handleEffects¹(x) }; +//│ define resume¹ as fun resume⁰(x)(y) { +//│ return handleEffects_handleEffect⁰(0) +//│ }; //│ set sink⁰ = mut []; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -254,6 +258,7 @@ fun g(n)(m) = //│ end //│ end //│ }; +//│ @inline //│ define f⁰ as fun f¹(n)(a, b, c, d, ...e)(m) { //│ return f_g⁰(0, n, a, e, m) //│ }; @@ -271,32 +276,30 @@ fun f(a)(...z) = if z is [] then a [x, ...xs] then f(a + 1)(...xs) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— -//│ define f² as fun f³(a)(...z) { -//│ let a1, z1, inlinedVal; -//│ set a1 = a; -//│ set z1 = z; -//│ block inlinedLbl: -//│ loop loopLabel: -//│ let tmp; -//│ match z1 -//│ Array(0) => -//│ set inlinedVal = a1; -//│ break inlinedLbl -//│ Array(1+) => -//│ let inlinedVal1, tmp1; -//│ do runtime⁰.Tuple⁰.get⁰(z1, 0); -//│ set tmp1 = -¹(z1.length﹖, 0); -//│ set inlinedVal1 = z1.slice﹖(1, tmp1); -//│ set tmp = +⁰(a1, 1); -//│ set a1 = tmp; -//│ set z1 = inlinedVal1; -//│ continue loopLabel -//│ else -//│ throw new globalThis⁰.Error⁰("match error") -//│ end -//│ unreachable /* Rest of abortive labelled block */ -//│ return inlinedVal +//│ let f$tailrec; +//│ @private +//│ define f$tailrec as fun f$tailrec⁰(a, z) { +//│ loop loopLabel: +//│ let tmp; +//│ match z +//│ Array(0) => +//│ return a +//│ Array(1+) => +//│ let inlinedVal, tmp1; +//│ do runtime⁰.Tuple⁰.get⁰(z, 0); +//│ set tmp1 = -¹(z.length﹖, 0); +//│ set inlinedVal = z.slice﹖(1, tmp1); +//│ set tmp = +⁰(a, 1); +//│ set a = tmp; +//│ set z = inlinedVal; +//│ continue loopLabel +//│ else +//│ throw new globalThis⁰.Error⁰("match error") +//│ end +//│ unreachable /* Rest of abortive labelled block */ //│ }; +//│ @inline +//│ define f² as fun f³(a)(...z) { return f$tailrec⁰(a, z) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -311,11 +314,11 @@ f(0)(1, 2, 3, 4) fun f(a)(b) = f(a)(b) //│ ————————————| Optimized IR Tree |——————————————————————————————————————————————————————————————————— //│ Program: -//│ main = Scoped(syms = {member:f$tailrec⁰}): +//│ main = Scoped(syms = {member:f$tailrec¹}): //│ body = Define: //│ defn = FunDefn: -//│ sym = member:f$tailrec⁰ -//│ dSym = term:f$tailrec¹ +//│ sym = member:f$tailrec¹ +//│ dSym = term:f$tailrec² //│ params = Ls of //│ ParamList: ‹empty› //│ body = Label: @@ -339,9 +342,9 @@ fun f(a)(b) = f(a)(b) //│ sym = b⁰ //│ modulefulness = Modulefulness of N //│ body = Return of Call: -//│ fun = MemberRef{disamb=term:f$tailrec¹}: -//│ bms = member:f$tailrec⁰ -//│ disamb = term:f$tailrec¹ +//│ fun = MemberRef{disamb=term:f$tailrec²}: +//│ bms = member:f$tailrec¹ +//│ disamb = term:f$tailrec² //│ argss = Ls of //│ Nil //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -355,29 +358,51 @@ fun loop(x)(y) = else loop(x - 1)(y + x) fun f = loop(1000)(0) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— -//│ let loop$tailrec; -//│ @private -//│ define loop$tailrec as fun loop$tailrec¹(x, y) { -//│ loop loopLabel: -//│ let scrut, tmp, tmp1; -//│ set scrut = Predef⁰.equals⁰(x, 0); -//│ match scrut -//│ true => -//│ return y -//│ else -//│ set tmp = -⁰(x, 1); -//│ set tmp1 = +⁰(y, x); -//│ set x = tmp; -//│ set y = tmp1; -//│ continue loopLabel -//│ end -//│ unreachable /* Rest of abortive labelled block */ -//│ }; //│ @tailrec @inline //│ define loop² as fun loop³(x)(y) { -//│ return loop$tailrec¹(x, y) +//│ let x1, y1, inlinedVal; +//│ set x1 = x; +//│ set y1 = y; +//│ block inlinedLbl: +//│ loop loopLabel: +//│ let scrut, tmp, tmp1; +//│ set scrut = Predef⁰.equals⁰(x1, 0); +//│ match scrut +//│ true => +//│ set inlinedVal = y1; +//│ break inlinedLbl +//│ else +//│ set tmp = -⁰(x1, 1); +//│ set tmp1 = +⁰(y1, x1); +//│ set x1 = tmp; +//│ set y1 = tmp1; +//│ continue loopLabel +//│ end +//│ unreachable /* Rest of abortive labelled block */ +//│ return inlinedVal +//│ }; +//│ define f⁶ as fun f⁷() { +//│ let x, y, inlinedVal; +//│ set x = 1000; +//│ set y = 0; +//│ block inlinedLbl: +//│ loop loopLabel: +//│ let scrut, tmp, tmp1; +//│ set scrut = Predef⁰.equals⁰(x, 0); +//│ match scrut +//│ true => +//│ set inlinedVal = y; +//│ break inlinedLbl +//│ else +//│ set tmp = -⁰(x, 1); +//│ set tmp1 = +⁰(y, x); +//│ set x = tmp; +//│ set y = tmp1; +//│ continue loopLabel +//│ end +//│ unreachable /* Rest of abortive labelled block */ +//│ return inlinedVal //│ }; -//│ define f⁶ as fun f⁷() { return loop$tailrec¹(1000, 0) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -391,7 +416,7 @@ loop(5)(5) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let loop$tailrec; //│ @private -//│ define loop$tailrec as fun loop$tailrec²(x, y) { +//│ define loop$tailrec as fun loop$tailrec¹(x, y) { //│ loop loopLabel: //│ let scrut, scrut1, tmp, tmp1, tmp2; //│ set scrut = ===⁰(y, 0); @@ -403,7 +428,7 @@ loop(5)(5) //│ match scrut1 //│ true => //│ set tmp = -⁰(y, 1); -//│ set tmp1 = loop$tailrec²(5, tmp); +//│ set tmp1 = loop$tailrec¹(5, tmp); //│ return +⁰(1, tmp1) //│ else //│ set tmp2 = -⁰(x, 1); @@ -414,8 +439,8 @@ loop(5)(5) //│ unreachable /* Rest of abortive labelled block */ //│ }; //│ @inline -//│ define loop⁴ as fun loop⁵(x)(y) { return loop$tailrec²(x, y) }; -//│ return loop$tailrec²(5, 5) +//│ define loop⁴ as fun loop⁵(x)(y) { return loop$tailrec¹(x, y) }; +//│ return loop$tailrec¹(5, 5) //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— //│ = 5 @@ -452,7 +477,7 @@ fun f(n)(a)(...z) = //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let f$tailrec; //│ @private -//│ define f$tailrec as fun f$tailrec²(n, a, z) { +//│ define f$tailrec as fun f$tailrec³(n, a, z) { //│ loop loopLabel: //│ let scrut, res, tmp, tmp1; //│ set scrut = >⁰(n, 0); @@ -471,7 +496,7 @@ fun f(n)(a)(...z) = //│ set tmp2 = -¹(z.length﹖, 0); //│ set inlinedVal = z.slice﹖(1, tmp2); //│ set tmp1 = +⁰(a, 1); -//│ set res = f$tailrec²(n, tmp1, inlinedVal); +//│ set res = f$tailrec³(n, tmp1, inlinedVal); //│ do Predef⁰.print⁰("hi!"); //│ return res //│ else @@ -480,7 +505,8 @@ fun f(n)(a)(...z) = //│ end //│ unreachable /* Rest of abortive labelled block */ //│ }; -//│ define f⁸ as fun f⁹(n)(a)(...z) { return f$tailrec²(n, a, z) }; +//│ @inline +//│ define f⁸ as fun f⁹(n)(a)(...z) { return f$tailrec³(n, a, z) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— diff --git a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls index 6faa4adefa..7bbb308d2e 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls @@ -57,9 +57,11 @@ f(10000, 20000, 0) //│ end //│ end //│ }; +//│ @inline //│ define g⁰ as fun g¹(a, b, c, d) { //│ return g_f⁰(0, a, b, c, d) //│ }; +//│ @inline //│ define f⁰ as fun f¹(a, b, c) { //│ return g_f⁰(1, a, b, c, undefined) //│ }; @@ -190,9 +192,11 @@ fun g(n) = //│ end //│ end //│ }; +//│ @inline //│ define f² as fun f³(n, a, b, c, d, ...e) { //│ return f_g⁰(0, n, e) //│ }; +//│ @inline //│ define g² as fun g³(n) { return f_g⁰(1, n, undefined) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -209,7 +213,7 @@ fun f(x) = @tailcall f(x) @tailcall g() //│ ╔══[COMPILATION ERROR] This call is not in tail position. -//│ ║ l.208: @tailcall f(x) +//│ ║ l.212: @tailcall f(x) //│ ╙── ^^^^ :lift @@ -319,7 +323,9 @@ fun g(x) = //│ end //│ end //│ }; +//│ @inline //│ define f⁶ as fun f⁷(x) { return f_g¹(0) }; +//│ @inline //│ define g⁴ as fun g⁵(x) { return f_g¹(1) }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -363,10 +369,10 @@ module A with @tailcall g(x - 1) A.f(10000) //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.362: fun g(x) = if x < 0 then 0 else @tailcall f(x) +//│ ║ l.368: fun g(x) = if x < 0 then 0 else @tailcall f(x) //│ ╙── ^^^^ //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.363: @tailcall g(x - 1) +//│ ║ l.369: @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 @@ -393,12 +399,12 @@ class A with fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) (new A).f(10) //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.392: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.398: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ ╔══[COMPILATION ERROR] Class methods may not yet be marked @tailrec. -//│ ║ l.392: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.398: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^ //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.393: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) +//│ ║ l.399: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 From 4e2ce1784a6c2c5d0969cbccab1ecbdef5d42191 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 21:26:28 +0800 Subject: [PATCH 09/13] update test comment --- hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls index 19ffbc2191..e969ad47c1 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls @@ -406,7 +406,7 @@ fun f = loop(1000)(0) //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— -// Ensure the function is inlined +// Ensure the non-tail call is calls the loop definition and is correctly handled :soir fun loop(x)(y) = if y === 0 then 0 @@ -444,6 +444,7 @@ loop(5)(5) //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— //│ = 5 +// Ensure the spread args are properly handled fun f(n)(a, b, c, d, ...e)(m) = if n > 0 then @tailcall g(n)(m + 1) else [e, m] From e79bdee7f2480a90232858b0576ec48c647e6d2b Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 23:08:26 +0800 Subject: [PATCH 10/13] address review --- .../src/main/scala/hkmc2/codegen/Block.scala | 2 +- .../main/scala/hkmc2/codegen/TailRecOpt.scala | 22 +++++++++---------- hkmc2/shared/src/test/mlscript/HkScratch.mls | 21 +++++++++++++++++- .../test/mlscript/tailrec/MultiArgLists.mls | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala index bcc34c550e..a1ad82c03d 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala @@ -682,7 +682,7 @@ final case class FunDefn( lazy val affineInfo: Ls[Int] = annotations.collect: case Annot.Affine(whichParamList) => whichParamList - lazy val paramSyms: Ls[VarSymbol] = params.flatMap(_.paramSyms) + lazy val allParamSyms: Ls[VarSymbol] = params.flatMap(_.paramSyms) // * This deliberately is not a lazy val: its initialization would synchronize on the JVM. // * Computing the summary is pure, and a reference write is atomic, so concurrent traversals may diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala index 2b8e7dfe29..3dc209c1c6 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala @@ -250,9 +250,9 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): * @param plist The parameter list to apply. * @param args The argument list. * @return A tuple `(Block => Block, List[Path])`, where: - * - The first parameter contains the code that breaks up the arguments into the shape expected by the parameter list, and + * - The first return value contains the code that breaks up the arguments into the shape expected by the parameter list, and * should be applied to the remaining code; - * - The second parameter is a list of paths containing the arguments in order. If there is a spread parameter, it will be + * - The second return value is a list of paths containing the arguments in order. If there is a spread parameter, it will be * the last one. */ def forceSpread(plist: ParamList, args: List[Arg]): (Block => Block, List[Path]) = @@ -344,9 +344,9 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): val paramSyms = if hasWrapper then if funsLen === 1 then - funs.head.paramSyms.map(v => VarSymbol(Tree.Ident(v.id.name))) + funs.head.allParamSyms.map(v => VarSymbol(Tree.Ident(v.id.name))) else for i <- 0 until maxParamLen yield VarSymbol(Tree.Ident("param" + i)) - else funs.head.paramSyms + else funs.head.allParamSyms .toList val paramSymsArr = ArrayBuffer.from(paramSyms) // Function -> param -> param symbol in the rewritten function @@ -371,10 +371,10 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): def rewriteKnownCall(callee: FunDefn, flattenedArgs: List[Path]) = if !hasWrapper then lastWords("Tried to rewrite a call to a non-existent loop definition.") - if callee.paramSyms.length =/= flattenedArgs.length then lastWords("Incorrect function call arity.") + if callee.allParamSyms.length =/= flattenedArgs.length then lastWords("Incorrect function call arity.") // Fill in the argument list with the arguments in the correct position by applying the paramSym -> arg map to // the loop definitions parameter list. - val argsMap = (callee.paramSyms.map(paramSymsMap(callee.dSym)) zip flattenedArgs).toMap + val argsMap = (callee.allParamSyms.map(paramSymsMap(callee.dSym)) zip flattenedArgs).toMap val args = paramSyms.map: s => argsMap.get(s) match case Some(pth) => Arg(N, pth) @@ -383,7 +383,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): Call(loopDefnPath, argsWithId ne_:: Nil)(CallMetadata.defaultMlsFun) class FunRewriter(f: FunDefn) extends BlockTransformerShallow(SymbolSubst.Id): - val params = f.paramSyms + val params = f.allParamSyms val paramsSet = f.params.toSet val paramsIdxes = params.zipWithIndex.toMap @@ -509,9 +509,6 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): case x => x ret case CallArgsResult.ForceSpread => - // Forcibly spread the args in an array. - // Assume the lengths are correct - // We can safely remove all of the symbols from this parameter list from `assignedSyms` at this stage, // because the RHS of every parameter will be computed when spreading them in the tuple, which happens // before any of the param symbols are assigned to. @@ -535,7 +532,8 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): // We explicitly rewrite *all* fully applied calls to functions within the SCC. Tail calls are rewritten using a // `continue`, while other calls are rewritten as a call to the merged function. This is to make the tailrec // optimizer pass idempotent. Without this, the subsequent tailrec optimizer passes could see the merged and wrapper - // functions as an SCC and try to rewrite the wrapper's tail call. + // functions as an SCC and try to rewrite the wrapper's tail call. Note that selections (and thus calls to + // parameter-less module methods) are not yet supported. override def applyResult(r: Result)(k: Result => Block): Block = r match case c @ Call(Value.MemberRef(bms, calleeSym: TermSymbol), args) if hasWrapper => funsMap.get(calleeSym) match case Some(callee) if isExactlySaturatedCall(c, callee) => @@ -591,7 +589,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): (N, defn :: Nil) else val wrappers = funs.map: f => - val paramArgs = f.paramSyms.map(s => s.asSimpleRef) + val paramArgs = f.allParamSyms.map(s => s.asSimpleRef) val newBod = Return( rewriteKnownCall(f, paramArgs), ) diff --git a/hkmc2/shared/src/test/mlscript/HkScratch.mls b/hkmc2/shared/src/test/mlscript/HkScratch.mls index 48d7326643..b16263b109 100644 --- a/hkmc2/shared/src/test/mlscript/HkScratch.mls +++ b/hkmc2/shared/src/test/mlscript/HkScratch.mls @@ -8,4 +8,23 @@ // :d // :todo - +:sjs +module M with + fun f = g + fun g = f +//│ ————————————| JS (unsanitized) |———————————————————————————————————————————————————————————————————— +//│ let M1; +//│ (class M { +//│ static { +//│ M1 = this +//│ } +//│ static get f() { +//│ return M.g; +//│ } +//│ static get g() { +//│ return M.f; +//│ } +//│ toString() { return runtime.render(this); } +//│ static [definitionMetadata] = ["class", "M"]; +//│ }); +//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— diff --git a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls index e969ad47c1..46040e9699 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls @@ -406,7 +406,7 @@ fun f = loop(1000)(0) //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— -// Ensure the non-tail call is calls the loop definition and is correctly handled +// Ensure the non-tail call is rewritten to call the loop definition and is correctly handled :soir fun loop(x)(y) = if y === 0 then 0 From fedba3f34c6349b0b96dc3f1b6f604a82f6d9371 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 23:12:06 +0800 Subject: [PATCH 11/13] address comment --- .../main/scala/hkmc2/codegen/TailRecOpt.scala | 2 +- .../src/test/mlscript/tailrec/TailRecOpt.mls | 62 +++++++++++++++---- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala index 3dc209c1c6..4f33807906 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala @@ -535,7 +535,7 @@ class TailRecOpt(checkAnnotations: Bool)(using State, TL, Raise): // functions as an SCC and try to rewrite the wrapper's tail call. Note that selections (and thus calls to // parameter-less module methods) are not yet supported. override def applyResult(r: Result)(k: Result => Block): Block = r match - case c @ Call(Value.MemberRef(bms, calleeSym: TermSymbol), args) if hasWrapper => funsMap.get(calleeSym) match + case c @ CallToFun(calleeSym) if hasWrapper => funsMap.get(calleeSym) match case Some(callee) if isExactlySaturatedCall(c, callee) => val calleeParamsMap = paramSymsMap(callee.dSym) val argListResults = callee.params.zip(c.argss).map: diff --git a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls index 7bbb308d2e..5dd1d4b581 100644 --- a/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls +++ b/hkmc2/shared/src/test/mlscript/tailrec/TailRecOpt.mls @@ -301,22 +301,23 @@ a.x // Make sure the tailrec pass is idempotent by ensuring non-tail calls to functions in the SCC are rewritten as calls to the loop definition. :soir -:noInline fun f(x) = g(x) fun g(x) = f(x) + print(x) 0 //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— //│ let f_g; //│ @private -//│ define f_g as fun f_g¹(id) { +//│ define f_g as fun f_g¹(id, param0) { //│ loop loopLabel: //│ match id //│ 0 => //│ set id = 1; //│ continue loopLabel //│ 1 => -//│ do f_g¹(0); +//│ do f_g¹(0, param0); +//│ do Predef⁰.print⁰(param0); //│ return 0 //│ else //│ end @@ -324,9 +325,44 @@ fun g(x) = //│ end //│ }; //│ @inline -//│ define f⁶ as fun f⁷(x) { return f_g¹(0) }; +//│ define f⁶ as fun f⁷(x) { +//│ return f_g¹(0, x) +//│ }; //│ @inline -//│ define g⁴ as fun g⁵(x) { return f_g¹(1) }; +//│ define g⁴ as fun g⁵(x) { return f_g¹(1, x) }; +//│ end +//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— + +:soir +module M with + fun f(x) = g(x) + fun g(x) = + f(x) + print(x) + 0 +//│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— +//│ define M⁰ as class M¹ +//│ module M² { +//│ method f_g² = fun f_g³(id, param0) { +//│ loop loopLabel: +//│ match id +//│ 0 => +//│ set id = 1; +//│ continue loopLabel +//│ 1 => +//│ do M².this.f_g³(0, param0); +//│ do Predef⁰.print⁰(param0); +//│ return 0 +//│ else +//│ end +//│ end +//│ end +//│ } +//│ method f⁸ = fun f⁹(x) { +//│ return M².this.f_g³(0, x) +//│ } +//│ method g⁶ = fun g⁷(x) { return M².this.f_g³(1, x) } +//│ }; //│ end //│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— @@ -339,7 +375,7 @@ fun f(n, x, ...y) = f(0, ...[1, 2, 3]) f(0, 1, 2, 3) //│ ——————————————| Optimized IR |—————————————————————————————————————————————————————————————————————— -//│ define f⁸ as fun f⁹(n, x, ...y) { +//│ define f¹⁰ as fun f¹¹(n, x, ...y) { //│ loop loopLabel: //│ let scrut, tmp; //│ set scrut = ===⁰(n, 0); @@ -347,9 +383,9 @@ fun f(n, x, ...y) = //│ true => //│ return [x, y] //│ else -//│ do f⁹(0, 1, 2, 3); +//│ do f¹¹(0, 1, 2, 3); //│ set tmp = [1, 2, 3]; -//│ do f⁹(0, ...tmp); +//│ do f¹¹(0, ...tmp); //│ set n = 0; //│ set x = 1; //│ set y = mut [2, 3]; @@ -369,10 +405,10 @@ module A with @tailcall g(x - 1) A.f(10000) //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.368: fun g(x) = if x < 0 then 0 else @tailcall f(x) +//│ ║ l.404: fun g(x) = if x < 0 then 0 else @tailcall f(x) //│ ╙── ^^^^ //│ ╔══[COMPILATION ERROR] This tail call exits the current scope and is not optimized. -//│ ║ l.369: @tailcall g(x - 1) +//│ ║ l.405: @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 @@ -399,12 +435,12 @@ class A with fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) (new A).f(10) //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.398: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.434: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^^^^^^^^ //│ ╔══[COMPILATION ERROR] Class methods may not yet be marked @tailrec. -//│ ║ l.398: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) +//│ ║ l.434: @tailrec fun f(x) = if x == 0 then 0 else @tailcall g(x - 1) //│ ╙── ^ //│ ╔══[COMPILATION ERROR] Calls from class methods cannot yet be marked @tailcall. -//│ ║ l.399: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) +//│ ║ l.435: fun g(x) = if x == 0 then 1 else @tailcall f(x - 1) //│ ╙── ^^^^^^^^ //│ = 0 From a8087fd04111e03af9d77528672a2ac101102a17 Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 23:13:00 +0800 Subject: [PATCH 12/13] revert hkscratch --- hkmc2/shared/src/test/mlscript/HkScratch.mls | 22 ++------------------ 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/hkmc2/shared/src/test/mlscript/HkScratch.mls b/hkmc2/shared/src/test/mlscript/HkScratch.mls index b16263b109..ef38e8b363 100644 --- a/hkmc2/shared/src/test/mlscript/HkScratch.mls +++ b/hkmc2/shared/src/test/mlscript/HkScratch.mls @@ -8,23 +8,5 @@ // :d // :todo -:sjs -module M with - fun f = g - fun g = f -//│ ————————————| JS (unsanitized) |———————————————————————————————————————————————————————————————————— -//│ let M1; -//│ (class M { -//│ static { -//│ M1 = this -//│ } -//│ static get f() { -//│ return M.g; -//│ } -//│ static get g() { -//│ return M.f; -//│ } -//│ toString() { return runtime.render(this); } -//│ static [definitionMetadata] = ["class", "M"]; -//│ }); -//│ —————————————————| Output |————————————————————————————————————————————————————————————————————————— + + From 22729210ccfc024a251434c29687da4f3f78bfcb Mon Sep 17 00:00:00 2001 From: CAG2Mark Date: Thu, 27 Aug 2026 23:13:38 +0800 Subject: [PATCH 13/13] revert hkscratch --- hkmc2/shared/src/test/mlscript/HkScratch.mls | 1 - 1 file changed, 1 deletion(-) diff --git a/hkmc2/shared/src/test/mlscript/HkScratch.mls b/hkmc2/shared/src/test/mlscript/HkScratch.mls index ef38e8b363..48d7326643 100644 --- a/hkmc2/shared/src/test/mlscript/HkScratch.mls +++ b/hkmc2/shared/src/test/mlscript/HkScratch.mls @@ -9,4 +9,3 @@ // :todo -