Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
294 changes: 180 additions & 114 deletions hkmc2/shared/src/main/scala/hkmc2/codegen/BlockSimplifier.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,10 @@ class HandlerLowering(paths: HandlerPaths, opt: EffectHandlers)(using TL, Raise,
val ctx = HandlerCtx.TopLevel
val transformed = translateBlock(preTransformed, ctx, Set.empty)
val blk = blockBuilder
.assign(State.noSymbol, Call(paths.resetEffects, Nil ne_:: Nil)(true, false, false))
.staticif(
!opt.doNotInstrumentTopLevelModCtor,
_.assign(State.noSymbol, Call(paths.resetEffects, Nil ne_:: Nil)(true, false, false))
)
.rest(transformed)
(blk, stackSafetyMap)

1 change: 1 addition & 0 deletions hkmc2/shared/src/test/mlscript/opt/BasicVarPropag.mls
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,4 @@ in y + 1
//│ —————————————————| Output |—————————————————————————————————————————————————————————————————————————
//│ = 2


43 changes: 43 additions & 0 deletions hkmc2/shared/src/test/mlscript/opt/PureCallPropagation.mls
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,46 @@ f(3) + f(4)
//│ f = fun


// * Do not propagate an unsaturated call prefix if it mentions a local
// * that has gone out of scope by the later call site.
:soir
fun scopedPrefixFoo(x)(y) = x + y
() =>
let f
if maybe is
false then 0
true then
scope.locally of (
let x = hide(0)
f = scopedPrefixFoo(x)
)
print of
"Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello"
f(2)
//│ ——————————————| Optimized IR |——————————————————————————————————————————————————————————————————————
//│ let scopedPrefixFoo⁰, lambda³;
//│ @inline
//│ define scopedPrefixFoo⁰ as fun scopedPrefixFoo¹(x)(y) {
//│ return +⁰(x, y)
//│ };
//│ @private
//│ define lambda³ as fun lambda⁴() {
//│ let f, scrut;
//│ set scrut = Predef⁰.maybe⁰;
//│ match scrut
//│ false =>
//│ end
//│ true =>
//│ let x;
//│ set x = Predef⁰.hide⁰(0);
//│ set f = scopedPrefixFoo¹(x);
//│ end
//│ else
//│ throw new globalThis⁰.Error⁰("match error")
//│ do Predef⁰.print⁰("Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello");
//│ return f(2)
//│ };
//│ return lambda⁴
//│ —————————————————| Output |—————————————————————————————————————————————————————————————————————————
//│ = fun

37 changes: 37 additions & 0 deletions hkmc2/shared/src/test/mlscript/opt/VarPropagStress.mls
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
:js


// FIXME: Exponential blow up? The time this takes roughly doubles with each additional line (try it with `watcher`)
let x = 0
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
if maybe do set x += 1
// if maybe do set x += 1
// if maybe do set x += 1
// if maybe do set x += 1
// if maybe do set x += 1
// if maybe do set x += 1
x
//│ = 22
//│ x = 22


2 changes: 1 addition & 1 deletion hkmc2Benchmarks/src/test/bench/FingerTreesAsStacks.mls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import "../../../../hkmc2/shared/src/test/mlscript-compile/FingerTreeList.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/Stack.mls"
import "./mlscript-compile/Benchmark.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/Benchmark.mls"

open Benchmark

Expand Down
2 changes: 1 addition & 1 deletion hkmc2Benchmarks/src/test/bench/LazySpreads.mls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "../../../../hkmc2/shared/src/test/mlscript-compile/LazyArray.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/FingerTreeList.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/LazyFingerTree.mls"

import "./mlscript-compile/Benchmark.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/Benchmark.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/Runtime.mls"

open LazyArray
Expand Down
2 changes: 1 addition & 1 deletion hkmc2Benchmarks/src/test/bench/nofibs-bench1.mls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
====================================================================================================


import "./mlscript-compile/Benchmark.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/Benchmark.mls"
open Benchmark


Expand Down
2 changes: 1 addition & 1 deletion hkmc2Benchmarks/src/test/bench/nofibs-bench2.mls
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
====================================================================================================


import "./mlscript-compile/Benchmark.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/Benchmark.mls"
open Benchmark


Expand Down
2 changes: 1 addition & 1 deletion hkmc2Benchmarks/src/test/bench/nofibs-bench3.mls
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
====================================================================================================


import "./mlscript-compile/Benchmark.mls"
import "../../../../hkmc2/shared/src/test/mlscript-compile/Benchmark.mls"
open Benchmark


Expand Down
Loading