Skip to content

wasm: Miscellaneous cleanup#408

Merged
LPTK merged 26 commits intohkust-taco:hkmc2from
Derppening:misc/formatting-cleanup
Mar 11, 2026
Merged

wasm: Miscellaneous cleanup#408
LPTK merged 26 commits intohkust-taco:hkmc2from
Derppening:misc/formatting-cleanup

Conversation

@Derppening
Copy link
Copy Markdown
Contributor

Cleanup the wasm backend by updating binaryen, adding missing whitespace to some lines, applying scalafmt, and performing minor code simplification.

scalafmt.conf reference:

version = "3.10.7"
runner.dialect = scala213
maxColumn = 100
project {
  includePaths = ["glob:**/hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/**"]
}
fileOverride {
  "glob:**/hkmc2/shared/src/main/scala/**" {
    runner.dialect = scala3
    align.preset = none
    align.stripMargin = false
    docstrings.style = Asterisk
    newlines.source = keep
    rewrite.trailingCommas.style = always
    rewrite.scala3.convertToNewSyntax = true
    rewrite.scala3.removeOptionalBraces = true
  }
}

No functional changes.

@Derppening Derppening requested a review from LPTK March 9, 2026 08:30
@LPTK
Copy link
Copy Markdown
Contributor

LPTK commented Mar 9, 2026

One test fails.

@Derppening
Copy link
Copy Markdown
Contributor Author

I suspect the test failure has to do with some nondeterminism. I tried running hkmc2MostTests/test 5 times and was hit with that test failure only 3 times.

//│ FAILURE: Unexpected runtime error
//│ FAILURE LOCATION: mkQuery (JSBackendDiffMaker.scala:172)
//│ ═══[RUNTIME ERROR] Error: MLscript call unexpectedly returned `undefined`, the forbidden value.
//│     at Runtime.checkCall (file:///home/david/programming/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs:621:41)
//│     at $_stack$_safe$_body$_15 (REPL65:1:5671)
//│     at Runtime.enterHandleBlock (file:///home/david/programming/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs:953:28)
//│     at Runtime.runStackSafe (file:///home/david/programming/mlscript/hkmc2/shared/src/test/mlscript-compile/Runtime.mjs:1125:28)
//│     at REPL65:1:5722
//│     at ContextifyScript.runInThisContext (node:vm:137:12)
//│     at REPLServer.defaultEval (node:repl:600:22)
//│     at bound (node:domain:433:15)
//│     at REPLServer.runBound [as eval] (node:domain:444:12)
//│     at REPLServer.onLine (node:repl:935:10)

I also didn't change anything that is remotely related to effect handlers, so I don't think this is specific to the changes made in this branch.

Indeed, when I try to run hkmc2MostTests/test on 28cc546 (the latest commit in hkmc2) that particular test also fails 3/5 times.

@LPTK
Copy link
Copy Markdown
Contributor

LPTK commented Mar 9, 2026

Whoops, some conflicts now.

Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Ctx.scala
@Derppening
Copy link
Copy Markdown
Contributor Author

At least the nondeterminism seems to be gone now, running the tests back-to-back a few times doesn't trigger the test failure anymore 👍

Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala Outdated
@LPTK
Copy link
Copy Markdown
Contributor

LPTK commented Mar 9, 2026

Why not commit the scalafmt.conf? You already made it apply only to a subdirectory for now.

maxColumn = 100

Normally I am for ~120. 100 Feels a bit too tight.

align.stripMargin = false

Oh, so they added the option!

@Derppening
Copy link
Copy Markdown
Contributor Author

Why not commit the scalafmt.conf? You already made it apply only to a subdirectory for now.

Added in 1819aa9.

maxColumn = 100

Normally I am for ~120. 100 Feels a bit too tight.

Included in the scalafmt.conf and reflowed all lines in db11595.

align.stripMargin = false

Oh, so they added the option!

Actually that option affects .stripMargin calls on interpolated/string literals... From Scalafmt docs:

"If align.stripMargin is true, they will align with the opening triple-quote """ in interpolated and raw string literals. Otherwise, they will be indented relative to the start of the opening line."

@Derppening
Copy link
Copy Markdown
Contributor Author

Seems like I messed up merging hkmc2 into this branch...

Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Ctx.scala Outdated
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Ctx.scala
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Ctx.scala Outdated
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Ctx.scala Outdated
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Ctx.scala Outdated
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Wasm.scala
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Wasm.scala
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Wasm.scala Outdated
@LPTK LPTK force-pushed the hkmc2 branch 2 times, most recently from 46c5ce1 to 414cf0c Compare March 10, 2026 15:42
@LPTK
Copy link
Copy Markdown
Contributor

LPTK commented Mar 10, 2026

Argh that stupid StackSafety.mls test is still flaky. I think I'll just disable it for now.

Copy link
Copy Markdown
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

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

Ok, otherwise LGTM now!

@Derppening
Copy link
Copy Markdown
Contributor Author

I think I have addressed all of the whitespace changes.

@LPTK LPTK merged commit 6b206b2 into hkust-taco:hkmc2 Mar 11, 2026
1 check passed
@LPTK LPTK deleted the misc/formatting-cleanup branch March 11, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants