Skip to content

Commit

Permalink
Rework Optimizer (#695)
Browse files Browse the repository at this point in the history
Co-authored-by: dvdvgt <[email protected]>
Co-authored-by: effekt-updater[bot] <181701480+effekt-updater[bot]@users.noreply.github.com>
Co-authored-by: Jiří Beneš <[email protected]>
Co-authored-by: Philipp Schuster <[email protected]>
Co-authored-by: Serkan Muhcu <[email protected]>
Co-authored-by: Marvin <[email protected]>
Co-authored-by: Jakub <[email protected]>
Co-authored-by: Marcial Gaißert <[email protected]>
Co-authored-by: Can <[email protected]>
  • Loading branch information
10 people authored Jan 4, 2025
1 parent 08f97ec commit 40c0706
Show file tree
Hide file tree
Showing 28 changed files with 1,059 additions and 599 deletions.
10 changes: 8 additions & 2 deletions effekt/jvm/src/test/scala/effekt/StdlibTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ class StdlibLLVMTests extends StdlibTests {
override def debug = sys.env.get("EFFEKT_DEBUG").nonEmpty

override def ignored: List[File] = List(
// Toplevel let-bindings (for ANSI-color-codes in output) not supported
examplesDir / "stdlib" / "test" / "test.effekt",
// segfaults
examplesDir / "stdlib" / "stream" / "fuse_newlines.effekt",

// valgrind
examplesDir / "stdlib" / "list" / "modifyat.effekt",
examplesDir / "stdlib" / "list" / "updateat.effekt",

// Syscall param write(buf) points to uninitialised byte(s)
examplesDir / "stdlib" / "io" / "filesystem" / "files.effekt",
examplesDir / "stdlib" / "io" / "filesystem" / "async_file_io.effekt",

// Conditional jump or move depends on uninitialised value(s)
examplesDir / "stdlib" / "io" / "filesystem" / "wordcount.effekt",
)
Expand Down
38 changes: 14 additions & 24 deletions effekt/jvm/src/test/scala/effekt/core/OptimizerTests.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package effekt
package core

import effekt.core.optimizer.*

import effekt.symbols

class OptimizerTests extends CoreTests {
Expand Down Expand Up @@ -30,15 +33,11 @@ class OptimizerTests extends CoreTests {
Deadcode.remove(Set(mainSymbol), tree)
}

def inlineOnce(input: String, expected: String)(using munit.Location) =
assertTransformsTo(input, expected) { tree =>
val (result, count) = Inline.once(Set(mainSymbol), tree, 50)
result
}

def inlineFull(input: String, expected: String)(using munit.Location) =
def normalize(input: String, expected: String)(using munit.Location) =
assertTransformsTo(input, expected) { tree =>
Inline.full(Set(mainSymbol), tree, 50)
val anfed = BindSubexpressions.transform(tree)
val normalized = Normalizer.normalize(Set(mainSymbol), anfed, 50)
Deadcode.remove(mainSymbol, normalized)
}

test("toplevel"){
Expand Down Expand Up @@ -155,11 +154,10 @@ class OptimizerTests extends CoreTests {
|""".stripMargin

val expected =
""" def foo = { () => return 42 }
| def main = { () => return 42 }
""" def main = { () => return 42 }
|""".stripMargin

inlineOnce(input, expected)
normalize(input, expected)
}

test("inline with argument"){
Expand All @@ -169,11 +167,10 @@ class OptimizerTests extends CoreTests {
|""".stripMargin

val expected =
""" def foo = { (n: Int) => return n:Int }
| def main = { () => return 42 }
""" def main = { () => return 42 }
|""".stripMargin

inlineOnce(input, expected)
normalize(input, expected)
}

test("inline higher order function"){
Expand All @@ -188,17 +185,10 @@ class OptimizerTests extends CoreTests {
|""".stripMargin

val expected =
""" def foo = { (n: Int) => return n:Int }
| def hof = { (){f : (Int) => Int} =>
| (f : (Int) => Int @ {f})(1)
| }
| def main = { () =>
| def local(n: Int) = return n:Int
| (local : (Int) => Int @ {})(1)
| }
""" def main = { () => return 1 }
|""".stripMargin

inlineOnce(input, expected)
normalize(input, expected)
}

test("fully inline higher order function"){
Expand All @@ -216,7 +206,7 @@ class OptimizerTests extends CoreTests {
""" def main = { () => return 1 }
|""".stripMargin

inlineFull(input, expected)
normalize(input, expected)
}

}
284 changes: 0 additions & 284 deletions effekt/shared/src/main/scala/effekt/core/Inline.scala

This file was deleted.

Loading

0 comments on commit 40c0706

Please sign in to comment.