Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
321e342
Split DCE from Optimizer phase
mattisboeckle May 15, 2025
0536cc9
Add base Mono phase
mattisboeckle May 15, 2025
4107bfa
Implement find constraints for subset
mattisboeckle May 21, 2025
cc76e6c
Merge forward declare
mattisboeckle May 21, 2025
72a2f79
Detect cycles in PolyConstraints
mattisboeckle May 21, 2025
aaed3b0
Fix hasCycle implementation
mattisboeckle May 21, 2025
6847154
Implement solveConstraints
mattisboeckle May 21, 2025
6ed9127
Revert forward declare changes
mattisboeckle May 26, 2025
f549670
Replace symbols.Symbol with Id
mattisboeckle May 22, 2025
d12449a
Simplify findConstraints interface
mattisboeckle Jun 9, 2025
0001362
Add type for solved constraints
mattisboeckle Jun 9, 2025
49cfe83
Emit monomorphized definitions
mattisboeckle Jun 12, 2025
c064a48
Update findConstraints to fit proposed version
mattisboeckle Jun 30, 2025
8a1bce0
Handle BlockLit one level higher
mattisboeckle Jul 10, 2025
3d0aaac
Implement solveConstraints
mattisboeckle Jul 11, 2025
02af077
Monomorphize existing definitions
mattisboeckle Jul 11, 2025
acd3d0b
Handle recursive functions when solving
mattisboeckle Jul 23, 2025
ddc84dc
Test Mono solving
mattisboeckle Jul 23, 2025
3a65080
Monomorphize Declarations
mattisboeckle Jul 25, 2025
094193d
Monomorphize effects
mattisboeckle Jul 28, 2025
a4439d5
wip fix interface implementations
mattisboeckle Aug 9, 2025
b46fd4e
Fix merge of Deadcode eliminination
mattisboeckle Aug 28, 2025
1c1a0b5
Include tparams for Constructors
mattisboeckle Aug 28, 2025
5893519
Fix MonoTests
mattisboeckle Sep 3, 2025
415c0d1
Implement many missing cases
mattisboeckle Sep 3, 2025
f37e62f
Remove unnecessary case
mattisboeckle Sep 4, 2025
a369fa9
Consider vargs and bargs
mattisboeckle Sep 17, 2025
bdc6c27
Handle Function in findConstraints
mattisboeckle Sep 17, 2025
15aacc4
Handle Unbox
mattisboeckle Sep 17, 2025
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
112 changes: 112 additions & 0 deletions effekt/jvm/src/test/scala/effekt/core/MonoTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package effekt
package core


abstract class AbstractMonoTests extends CorePhaseTests(Mono) {
import TypeArg.*

implicit def stringBaseT(name: String): Base = Base(Id(name), List())

val BaseTInt: Base = "Int"
val BaseTString: Base = "String"
val BaseTChar: Base = "Char"
val BaseTBool: Base = "Bool"
val BaseTDouble: Base = "Double"

val fnId: Map[String, FunctionId] = Map(
"a" -> Id("a"),
"b" -> Id("b"),
"c" -> Id("c"),
"d" -> Id("d"),
"e" -> Id("e"),
"f" -> Id("f"),
)
}

class MonoTests extends AbstractMonoTests {

import TypeArg.*

test("simple polymorphic function") {
val constraints = List(
Constraint(Vector(BaseTInt), fnId("a")),
Constraint(Vector(BaseTString), fnId("a"))
)
val expectedSolved: Solution = Map(
fnId("a") -> Set(Vector(BaseTInt), Vector(BaseTString))
)

assertEquals(solveConstraints(constraints), expectedSolved)
}

test("calling other polymorphic function") {
val constraints = List(
Constraint(Vector(Var(fnId("b"), 0)), fnId("a")),
Constraint(Vector(BaseTInt), fnId("a")),
Constraint(Vector(BaseTString), fnId("b")),
)
val expectedSolved: Solution = Map(
fnId("a") -> Set(Vector(BaseTInt), Vector(BaseTString)),
fnId("b") -> Set(Vector(BaseTString)),
)

assertEquals(solveConstraints(constraints), expectedSolved)
}

test("polymorphic function with multiple type args") {
val constraints = List(
Constraint(Vector(BaseTInt, BaseTString), fnId("a")),
Constraint(Vector(BaseTBool, BaseTChar), fnId("a")),
Constraint(Vector(BaseTBool, BaseTString), fnId("a")),
)
val expectedSolved: Solution = Map(
fnId("a") -> Set(
Vector(BaseTInt, BaseTString),
Vector(BaseTBool, BaseTChar),
Vector(BaseTBool, BaseTString),
)
)

assertEquals(solveConstraints(constraints), expectedSolved)
}

test("calling other polymorphic function with type args swapped") {
val constraints = List(
Constraint(Vector(Var(fnId("b"), 1), Var(fnId("b"), 0)), fnId("a")),
Constraint(Vector(BaseTString, BaseTBool), fnId("b")),
)
val expectedSolved: Solution = Map(
fnId("a") -> Set(Vector(BaseTBool, BaseTString)),
fnId("b") -> Set(Vector(BaseTString, BaseTBool)),
)

assertEquals(solveConstraints(constraints), expectedSolved)
}

test("recursive polymorphic function") {
val constraints = List(
Constraint(Vector(Var(fnId("a"), 0)), fnId("a")),
Constraint(Vector(BaseTInt), fnId("a")),
)
val expectedSolved: Solution = Map(
fnId("a") -> Set(Vector(BaseTInt)),
)

assertEquals(solveConstraints(constraints), expectedSolved)
}

test("mutually recursive polymorphic functions") {
val constraints = List(
Constraint(Vector(Var(fnId("b"), 0)), fnId("a")),
Constraint(Vector(Var(fnId("a"), 0)), fnId("b")),
Constraint(Vector(BaseTInt), fnId("a")),
Constraint(Vector(BaseTString), fnId("b")),
)
val expectedSolved: Solution = Map(
fnId("a") -> Set(Vector(BaseTInt), Vector(BaseTString)),
fnId("b") -> Set(Vector(BaseTInt), Vector(BaseTString)),
)

assertEquals(solveConstraints(constraints), expectedSolved)
}
}
20 changes: 20 additions & 0 deletions effekt/shared/src/main/scala/effekt/core/DeadCodeElimination.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package effekt.core

import effekt.PhaseResult.CoreTransformed
import effekt.context.Context
import effekt.core.optimizer.Deadcode
import effekt.Phase

object DeadCodeElimination extends Phase[CoreTransformed, CoreTransformed] {
val phaseName: String = "deadcode-elimination"

def run(input: CoreTransformed)(using Context): Option[CoreTransformed] =
input match {
case CoreTransformed(source, tree, mod, core) =>
val term = Context.ensureMainExists(mod)
val dce = Context.timed("deadcode-elimination", source.name) {
Deadcode.remove(term, core)
}
Some(CoreTransformed(source, tree, mod, dce))
}
}
Loading
Loading