Skip to content

Commit 413ac95

Browse files
Fix lowering symbol
1 parent 8c04952 commit 413ac95

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

hkmc2/shared/src/main/scala/hkmc2/codegen/Lowering.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
194194
final def term(t: st, inStmtPos: Bool = false)(k: Result => Block)(using Subst): Block =
195195
tl.log(s"Lowering.term ${t.showDbg.truncate(100, "[...]")}${
196196
if inStmtPos then " (in stmt)" else ""}${
197-
t.symbol.fold("")(" – symbol " + _)}")
197+
t.resolvedSymbol.fold("")(" – symbol " + _)}")
198198

199199
def warnStmt = if inStmtPos then
200200
raise:
@@ -306,7 +306,7 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
306306
End("error")
307307
case st.TyApp(f, ts) => term(f)(k) // * Type arguments are erased
308308
case st.App(f, arg) =>
309-
val isMlsFun = f.symbol.fold(f.isInstanceOf[st.Lam]):
309+
val isMlsFun = f.resolvedSymbol.fold(f.isInstanceOf[st.Lam]):
310310
case _: sem.BuiltinSymbol => true
311311
case sym: sem.BlockMemberSymbol =>
312312
sym.trmImplTree.fold(sym.clsTree.isDefined)(_.k is syntax.Fun)
@@ -320,17 +320,17 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
320320
subTerm_nonTail(arg): ar =>
321321
k(Call(fr, Arg(spread = true, ar) :: Nil)(isMlsFun, true).withLocOf(t))
322322
f match
323-
case t if t.symbol.isDefined && (t.symbol.get is ctx.builtins.js.try_catch) =>
323+
case t if t.resolvedSymbol.isDefined && (t.resolvedSymbol.get is ctx.builtins.js.try_catch) =>
324324
conclude(Value.Ref(State.runtimeSymbol).selN(Tree.Ident("try_catch")))
325-
case t if t.symbol.isDefined && (t.symbol.get is ctx.builtins.debug.printStack) =>
325+
case t if t.resolvedSymbol.isDefined && (t.resolvedSymbol.get is ctx.builtins.debug.printStack) =>
326326
if !config.effectHandlers.exists(_.debug) then
327327
raise(ErrorReport(
328328
msg"Debugging functions are not enabled" ->
329329
t.toLoc :: Nil,
330330
source = Diagnostic.Source.Compilation))
331331
return End("error")
332332
conclude(Value.Ref(State.runtimeSymbol).selSN("raisePrintStackEffect").withLocOf(f))
333-
case t if t.symbol.isDefined && (t.symbol.get is ctx.builtins.debug.getLocals) =>
333+
case t if t.resolvedSymbol.isDefined && (t.resolvedSymbol.get is ctx.builtins.debug.getLocals) =>
334334
if !config.effectHandlers.exists(_.debug) then
335335
raise(ErrorReport(
336336
msg"Debugging functions are not enabled" ->

hkmc2/shared/src/test/mlscript-compile/Runtime.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ let Runtime1;
311311
tmp = runtime.safeCall(f());
312312
res = tmp;
313313
if (res instanceof Runtime.EffectSig.class) {
314-
return Runtime.EffectHandle(res)
314+
return runtime.safeCall(Runtime.EffectHandle(res))
315315
} else {
316316
return res
317317
}

hkmc2/shared/src/test/mlscript/codegen/OpenWildcard.mls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ val Option = "Oops"
5858
:sjs
5959
Some(123)
6060
//│ JS (unsanitized):
61-
//│ Option.Some(123)
61+
//│ runtime.safeCall(Option.Some(123))
6262
//│ = Some(123)
6363

6464
module Option with

hkmc2/shared/src/test/mlscript/codegen/SanityChecks.mls

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ if M.A(1).y is
260260
//│ }
261261
//│ static toString() { return "M"; }
262262
//│ });
263-
//│ tmp5 = runtime.checkCall(M1.A(1));
263+
//│ tmp5 = runtime.safeCall(M1.A(1));
264264
//│ selRes2 = tmp5.y;
265265
//│ discarded1 = tmp5.y$__checkNotMethod;
266266
//│ if (selRes2 === undefined) {
@@ -289,7 +289,7 @@ M.A(1).y
289289
//│ if (selRes3 === undefined) {
290290
//│ throw new this.Error("Access to required field 'console' yielded 'undefined'");
291291
//│ }
292-
//│ tmp6 = runtime.checkCall(M1.A(1));
292+
//│ tmp6 = runtime.safeCall(M1.A(1));
293293
//│ selRes4 = tmp6.y;
294294
//│ discarded2 = tmp6.y$__checkNotMethod;
295295
//│ if (selRes4 === undefined) {
@@ -306,7 +306,9 @@ M.A(1).y
306306
M.A(1).y
307307
console.log()
308308
//│ JS:
309-
//│ tmp7 = M1.A(1); block$res15 = runtime.safeCall(this.console.log(tmp7.y)); undefined
309+
//│ tmp7 = runtime.safeCall(M1.A(1));
310+
//│ block$res15 = runtime.safeCall(this.console.log(tmp7.y));
311+
//│ undefined
310312
//│ > undefined
311313

312314
:noSanityCheck
@@ -322,15 +324,15 @@ M.A(2).y > 1
322324
:ssjs
323325
M.A(1).g(0)
324326
//│ JS:
325-
//│ tmp10 = runtime.checkCall(M1.A(1)); block$res18 = runtime.safeCall(tmp10.g(0)); undefined
327+
//│ tmp10 = runtime.safeCall(M1.A(1)); block$res18 = runtime.safeCall(tmp10.g(0)); undefined
326328
//│ ═══[RUNTIME ERROR] TypeError: tmp10.g is not a function
327329

328330

329331

330332
:ssjs
331333
M.A(1).f(0)
332334
//│ JS:
333-
//│ tmp11 = runtime.checkCall(M1.A(1)); block$res19 = runtime.safeCall(tmp11.f(0)); undefined
335+
//│ tmp11 = runtime.safeCall(M1.A(1)); block$res19 = runtime.safeCall(tmp11.f(0)); undefined
334336
//│ = 1
335337

336338

hkmc2/shared/src/test/mlscript/lifter/ModulesObjects.mls

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ M.A().get
170170
//│ }
171171
//│ toString() { return "A(" + "" + ")"; }
172172
//│ };
173-
//│ scrut = M14.A();
173+
//│ scrut = runtime.safeCall(M14.A());
174174
//│ if (scrut instanceof M14.A.class) {
175175
//│ tmp4 = 2;
176176
//│ } else {
@@ -180,7 +180,7 @@ M.A().get
180180
//│ }
181181
//│ static toString() { return "M"; }
182182
//│ });
183-
//│ tmp3 = M15.A();
183+
//│ tmp3 = runtime.safeCall(M15.A());
184184
//│ tmp3.get
185185
//│ = 4
186186

@@ -237,7 +237,7 @@ M.A(2).newB.newA_B(3).newB.get
237237
//│ return this.A$instance$0.x;
238238
//│ }
239239
//│ newA_B(y) {
240-
//│ return M19.A(y)
240+
//│ return runtime.safeCall(M19.A(y))
241241
//│ }
242242
//│ toString() { return "B(" + "" + ")"; }
243243
//│ };
@@ -253,7 +253,7 @@ M.A(2).newB.newA_B(3).newB.get
253253
//│ this.x = x;
254254
//│ }
255255
//│ get newA() {
256-
//│ return M18.A();
256+
//│ return runtime.safeCall(M18.A());
257257
//│ }
258258
//│ get newB() {
259259
//│ return B$(this);
@@ -269,7 +269,7 @@ M.A(2).newB.newA_B(3).newB.get
269269
//│ }
270270
//│ static toString() { return "M"; }
271271
//│ });
272-
//│ tmp5 = M19.A(2);
272+
//│ tmp5 = runtime.safeCall(M19.A(2));
273273
//│ tmp6 = runtime.safeCall(tmp5.newB.newA_B(3));
274274
//│ tmp6.newB.get
275275
//│ = 3

0 commit comments

Comments
 (0)