Skip to content

Commit

Permalink
Merge branch 'master' into feature/string-interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdvgt committed Jan 24, 2025
2 parents 111fcd8 + 10973e4 commit 1aa898d
Show file tree
Hide file tree
Showing 68 changed files with 3,018 additions and 265 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/acme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Check every stdlib module is compiled (acme)

on:
pull_request:
paths:
- 'libraries/common/**'

jobs:
check-stdlib-sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Generate acme and test for differences
id: generate-acme
shell: bash
run: |
# Function to convert file path to module import path
path_to_module() {
local filepath="$1"
# Remove libraries/common/ prefix and .effekt suffix
local module_path="${filepath#libraries/common/}"
module_path="${module_path%.effekt}"
echo "$module_path"
}
# Find all .effekt files in libraries/common, excluding acme.effekt
MODULES=$(find libraries/common -type f -name "*.effekt" | sort | while read -r file; do
path_to_module "$file"
done)
# Create the new acme.effekt content
{
echo "/// This module is auto-generated and checked in CI."
echo "/// It imports **every** stdlib module: ACME = All Common Modules in Effekt"
echo "module acme"
echo ""
for module in $MODULES; do
echo "import $module"
done
echo ""
echo "def main() = ()"
} > generated-acme.effekt
# Compare files, ignoring whitespace, blank lines, and line ending differences
if ! diff -Bbq examples/stdlib/acme.effekt generated-acme.effekt; then
echo "::error::The stdlib import file (examples/stdlib/acme.effekt) is out of sync with the modules in libraries/common."
echo "Differences found:"
diff -Bu examples/stdlib/acme.effekt generated-acme.effekt
exit 1
fi
1 change: 1 addition & 0 deletions effekt/js/src/main/scala/effekt/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package effekt
class Backend {
val compiler = generator.js.JavaScriptWeb()
val runner = ()
val name = "js-web"
}
8 changes: 3 additions & 5 deletions effekt/js/src/main/scala/effekt/context/VirtualModuleDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ trait VirtualModuleDB extends ModuleDB { self: Context =>
* used by Namer to resolve FFI includes
*/
override def contentsOf(path: String): Option[String] = {
val f = file(module.source.name).parent / path
if (!f.exists) {
None
} else {
Some(f.read)
val parent = file(module.source.name).parent
(parent :: config.includes().map(file)).collectFirst {
case base if (base / path).exists => (base / path).read
}
}

Expand Down
8 changes: 3 additions & 5 deletions effekt/jvm/src/main/scala/effekt/context/IOModuleDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ trait IOModuleDB extends ModuleDB { self: Context =>
* used by Namer to resolve FFI includes
*/
override def contentsOf(path: String): Option[String] = {
val includeFile = file(module.source.name).parent / path
if (!includeFile.exists) {
None
} else {
Some(FileSource(includeFile.toString).content)
val parent = file(module.source.name).parent
(parent :: config.includes().map(file)).collectFirst {
case base if (base / path).exists => FileSource((base / path).toString).content
}
}

Expand Down
8 changes: 7 additions & 1 deletion effekt/jvm/src/test/scala/effekt/StdlibTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class StdlibJavaScriptTests extends StdlibTests {
abstract class StdlibChezTests extends StdlibTests {
override def ignored: List[File] = List(
// Not implemented yet
examplesDir / "stdlib" / "bytearray",
examplesDir / "stdlib" / "io",
examplesDir / "stdlib" / "stream" / "characters.effekt",
examplesDir / "stdlib" / "stream" / "fuse_newlines.effekt"
Expand All @@ -47,5 +46,12 @@ class StdlibLLVMTests extends StdlibTests {

// Conditional jump or move depends on uninitialised value(s)
examplesDir / "stdlib" / "io" / "filesystem" / "wordcount.effekt",

// String comparison using `<`, `<=`, `>`, `>=` is not implemented yet on LLVM
examplesDir / "stdlib" / "string" / "compare.effekt",

// Wrong codegen for negative types, see #801
examplesDir / "stdlib" / "json.effekt",
examplesDir / "stdlib" / "buffer.effekt",
)
}
2 changes: 1 addition & 1 deletion effekt/jvm/src/test/scala/effekt/core/OptimizerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OptimizerTests extends CoreTests {
def normalize(input: String, expected: String)(using munit.Location) =
assertTransformsTo(input, expected) { tree =>
val anfed = BindSubexpressions.transform(tree)
val normalized = Normalizer.normalize(Set(mainSymbol), anfed, 50)
val normalized = Normalizer.normalize(Set(mainSymbol), anfed, 50, false)
Deadcode.remove(mainSymbol, normalized)
}

Expand Down
135 changes: 124 additions & 11 deletions effekt/jvm/src/test/scala/effekt/core/VMTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class VMTests extends munit.FunSuite {
dynamicDispatches = 0,
patternMatches = 400,
branches = 1487,
pushedFrames = 1352,
pushedFrames = 1185,
poppedFrames = 1409,
allocations = 54,
closures = 0,
Expand All @@ -549,7 +549,7 @@ class VMTests extends munit.FunSuite {
dynamicDispatches = 0,
patternMatches = 0,
branches = 210,
pushedFrames = 379,
pushedFrames = 378,
poppedFrames = 377,
allocations = 0,
closures = 0,
Expand Down Expand Up @@ -613,7 +613,7 @@ class VMTests extends munit.FunSuite {
dynamicDispatches = 0,
patternMatches = 4,
branches = 701,
pushedFrames = 874,
pushedFrames = 702,
poppedFrames = 880,
allocations = 4,
closures = 0,
Expand Down Expand Up @@ -660,27 +660,75 @@ class VMTests extends munit.FunSuite {

examplesDir / "casestudies" / "scheduler.effekt.md" -> Some(Summary(
staticDispatches = 60,
dynamicDispatches = 8,
dynamicDispatches = 7,
patternMatches = 95,
branches = 41,
pushedFrames = 106,
pushedFrames = 105,
poppedFrames = 106,
allocations = 73,
closures = 8,
closures = 7,
variableReads = 29,
variableWrites = 18,
resets = 1,
shifts = 7,
resumes = 7
)),

examplesDir / "casestudies" / "lexer.effekt.md" -> Some(Summary(
staticDispatches = 245,
dynamicDispatches = 18,
patternMatches = 298,
branches = 405,
pushedFrames = 703,
poppedFrames = 703,
allocations = 202,
closures = 27,
variableReads = 164,
variableWrites = 51,
resets = 31,
shifts = 11,
resumes = 11
)),

examplesDir / "casestudies" / "parser.effekt.md" -> Some(Summary(
staticDispatches = 8845,
dynamicDispatches = 783,
patternMatches = 13502,
branches = 14892,
pushedFrames = 28210,
poppedFrames = 28186,
allocations = 7923,
closures = 521,
variableReads = 6742,
variableWrites = 1901,
resets = 778,
shifts = 229,
resumes = 213
)),

examplesDir / "casestudies" / "anf.effekt.md" -> Some(Summary(
staticDispatches = 4775,
dynamicDispatches = 443,
patternMatches = 7272,
branches = 8110,
pushedFrames = 16101,
poppedFrames = 16088,
allocations = 4317,
closures = 358,
variableReads = 4080,
variableWrites = 1343,
resets = 458,
shifts = 322,
resumes = 306
)),

examplesDir / "casestudies" / "inference.effekt.md" -> Some(Summary(
staticDispatches = 1457444,
dynamicDispatches = 3201452,
patternMatches = 1474290,
branches = 303298,
pushedFrames = 7574480,
poppedFrames = 6709185,
pushedFrames = 7574476,
poppedFrames = 6709181,
allocations = 4626007,
closures = 865541,
variableReads = 2908620,
Expand All @@ -689,13 +737,80 @@ class VMTests extends munit.FunSuite {
shifts = 297723,
resumes = 9275
)),

examplesDir / "pos" / "raytracer.effekt" -> Some(Summary(
staticDispatches = 79696,
dynamicDispatches = 0,
patternMatches = 795964,
branches = 71995,
pushedFrames = 223269,
poppedFrames = 223269,
allocations = 103221,
closures = 0,
variableReads = 77886,
variableWrites = 26904,
resets = 0,
shifts = 0,
resumes = 0
)),
)

val other: Seq[(File, Option[Summary])] = Seq(
examplesDir / "benchmarks" / "other" / "emit.effekt" -> Some(Summary(
staticDispatches = 11,
dynamicDispatches = 0,
patternMatches = 0,
branches = 11,
pushedFrames = 92,
poppedFrames = 92,
allocations = 0,
closures = 0,
variableReads = 61,
variableWrites = 30,
resets = 0,
shifts = 0,
resumes = 0
)),

examplesDir / "benchmarks" / "other" / "church_exponentiation.effekt" -> Some(Summary(
staticDispatches = 7,
dynamicDispatches = 797188,
patternMatches = 0,
branches = 5,
pushedFrames = 531467,
poppedFrames = 531467,
allocations = 0,
closures = 26,
variableReads = 0,
variableWrites = 0,
resets = 0,
shifts = 0,
resumes = 0
)),

examplesDir / "benchmarks" / "other" / "variadic_combinators.effekt" -> Some(Summary(
staticDispatches = 27057,
dynamicDispatches = 9009,
patternMatches = 30052,
branches = 3003,
pushedFrames = 54105,
poppedFrames = 54105,
allocations = 24060,
closures = 12030,
variableReads = 24048,
variableWrites = 18036,
resets = 0,
shifts = 0,
resumes = 0
)),
)

val testFiles: Seq[(File, Option[Summary])] =
are_we_fast_yet ++
duality_of_compilation ++
effect_handlers_bench ++
casestudies
casestudies ++
other

def runTest(f: File, expectedSummary: Option[Summary]): Unit =
val path = f.getPath
Expand All @@ -711,6 +826,4 @@ class VMTests extends munit.FunSuite {
}

testFiles.foreach(runTest)


}
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@ object PolymorphismBoxing extends Phase[CoreTransformed, CoreTransformed] {
Stmt.Alloc(id, transform(init), region, transform(body))
case Stmt.Var(id, init, cap, body) =>
Stmt.Var(id, transform(init), cap, transform(body))
case Stmt.Reset(body) =>
Stmt.Reset(transform(body))
case Stmt.Reset(BlockLit(tps, cps, vps, prompt :: Nil, body)) =>
Stmt.Reset(BlockLit(tps, cps, vps, prompt :: Nil, coerce(transform(body), stmt.tpe)))
case Stmt.Reset(body) => ???
case Stmt.Shift(prompt, body) =>
Stmt.Shift(prompt, transform(body))
case Stmt.Resume(k, body) =>
Expand Down
21 changes: 13 additions & 8 deletions effekt/shared/src/main/scala/effekt/core/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ object PrettyPrinter extends ParenPrettyPrinter {
/// TODO
hsep(t.args.map(toDoc), comma)

def toDoc(b: Block): Doc = b match {
def toDoc(b: Block, preventBraces: Boolean = false): Doc = b match {
case BlockVar(id, _, _) => toDoc(id)
case BlockLit(tps, cps, vps, bps, body) =>
braces { space <> paramsToDoc(tps, vps, bps) <+> "=>" <+> nest(line <> toDocStmts(body)) <> line }
val doc = space <> paramsToDoc(tps, vps, bps) <+> "=>" <+> nest(line <> toDocStmts(body)) <> line
if preventBraces then doc else braces { doc }
case Unbox(e) => parens("unbox" <+> toDoc(e))
case New(handler) => "new" <+> toDoc(handler)
}
Expand Down Expand Up @@ -108,13 +109,17 @@ object PrettyPrinter extends ParenPrettyPrinter {
def argsToDoc(targs: List[core.ValueType], vargs: List[core.Pure], bargs: List[core.Block]): Doc =
val targsDoc = if targs.isEmpty then emptyDoc else brackets(targs.map(toDoc))
//val cargsDoc = if cargs.isEmpty then emptyDoc else brackets(cargs.map(toDoc))
val vargsDoc = vargs.map(toDoc)
val bargsDoc = bargs.map(toDoc)
targsDoc <> parens(vargsDoc ++ bargsDoc)
val vargsDoc = if vargs.isEmpty && !bargs.isEmpty then emptyDoc else parens(vargs.map(toDoc))

// Wrap in braces individually, then concat with a space between. Force BlockLits to not add a layer of braces on top.
val bargsDoc = if bargs.isEmpty then emptyDoc else hcat { bargs.map { b => braces(toDoc(b, preventBraces = true)) } }
targsDoc <> vargsDoc <> bargsDoc

def paramsToDoc(tps: List[symbols.Symbol], vps: List[ValueParam], bps: List[BlockParam]): Doc = {
val tpsDoc = if (tps.isEmpty) emptyDoc else brackets(tps.map(toDoc))
tpsDoc <> parens(hsep(vps map toDoc, comma)) <> hcat(bps map toDoc)
val tpsDoc = if tps.isEmpty then emptyDoc else brackets(tps.map(toDoc))
val vpsDoc = if vps.isEmpty && !bps.isEmpty then emptyDoc else parens(vps.map(toDoc))
val bpsDoc = if bps.isEmpty then emptyDoc else hcat(bps.map(toDoc)) // already are in braces!
tpsDoc <> vpsDoc <> bpsDoc
}

def toDoc(instance: Implementation): Doc = {
Expand Down Expand Up @@ -155,7 +160,7 @@ object PrettyPrinter extends ParenPrettyPrinter {
case Toplevel.Def(id, block) =>
"def" <+> toDoc(id) <+> "=" <+> toDoc(block)
case Toplevel.Val(id, _, binding) =>
"vet" <+> toDoc(id) <+> "=" <+> toDoc(binding)
"let" <+> toDoc(id) <+> "=" <+> toDoc(binding)
}

def toDoc(s: Stmt): Doc = s match {
Expand Down
Loading

0 comments on commit 1aa898d

Please sign in to comment.