-
Notifications
You must be signed in to change notification settings - Fork 40
Reach reparsability of core pretty-printer #1181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
21fbb0d
Add initial ReparseTests
timsueberkrueb 168642d
Close to reaching core printer-parser parity
timsueberkrueb 6c12f7d
Towards harmonizing id handling between parser and pretty-printer
timsueberkrueb 8654c3e
Fix wrong scope handling
timsueberkrueb 39ba213
Fix handling of top-level and builtin names
timsueberkrueb 5020255
Move builtins resolution to effekt.symbols.builtins
timsueberkrueb dae88ea
Parity of parsing/printing hole spans
timsueberkrueb 03347e1
Add make to list of keywords
timsueberkrueb 0c04d08
Integer literals can be 64-bit (Long)
timsueberkrueb 195c80c
Print braces around operation bodies
timsueberkrueb 1716644
Ignore some feature-dependent errors
timsueberkrueb 5d11df0
Fix parsing and printing of string literals
timsueberkrueb 684989c
Add simple string (un)escaping
timsueberkrueb b2d1030
Forbid keywords that contain $ to disambiguate from identifiers
timsueberkrueb 0079a32
Ignore some more tests
timsueberkrueb 3868468
Parse exponential notation in double literals
timsueberkrueb 67cc528
Print capture sets in alphabetic (and hence deterministic) order
timsueberkrueb 06eeed5
Improve assertAlphaEquivalent output
timsueberkrueb f312616
Improve toCoreThenReparse output
timsueberkrueb b8eece9
Fix wrong usage of TestRenamer
timsueberkrueb 0367733
Fix Barendregt id handling
timsueberkrueb bf50d1a
Undo some whitespace changes to reduce diff
timsueberkrueb 81c0052
Ignore limitation of TestRenamer wrt renaming captures
timsueberkrueb 1aec2d4
Fix TestRenamerTests
timsueberkrueb 9755de4
Separate core reparse tests
timsueberkrueb 6ced795
Improve name in build.sbt
timsueberkrueb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
effekt/jvm/src/test/scala/effekt/core/ReparseTests.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package effekt.core | ||
|
|
||
| import effekt.* | ||
| import effekt.PhaseResult.CoreTransformed | ||
| import effekt.context.{Context, IOModuleDB} | ||
| import effekt.util.PlainMessaging | ||
| import kiama.output.PrettyPrinterTypes.Document | ||
| import kiama.util.{Source, StringSource} | ||
| import munit.Location | ||
| import sbt.io.* | ||
| import sbt.io.syntax.* | ||
|
|
||
| import java.io.File | ||
|
|
||
| /* | ||
| // * This test suite ensures that the core pretty-printer always produces reparsable code. | ||
| */ | ||
| class ReparseTests extends CoreTests { | ||
| object plainMessaging extends PlainMessaging | ||
| object context extends Context with IOModuleDB { | ||
| val messaging = plainMessaging | ||
|
|
||
| object frontend extends CompileToCore | ||
|
|
||
| override lazy val compiler = frontend.asInstanceOf | ||
| } | ||
|
|
||
| // The sources of all test files are stored here: | ||
| def examplesDir = new File("examples") | ||
|
|
||
| // Test files which are to be ignored (since features are missing or known bugs exist) | ||
| def ignored: Set[File] = Set( | ||
| // Missing include: text/pregexp.scm | ||
| File("examples/pos/simpleparser.effekt"), | ||
| // Cannot find source for unsafe/cont | ||
| File("examples/pos/propagators.effekt"), | ||
| // Bidirectional effects that mention the same effect recursively are not (yet) supported. | ||
| File("examples/pos/bidirectional/selfrecursion.effekt"), | ||
| // FIXME: Wrong number of type arguments | ||
| File("examples/pos/type_omission_op.effekt"), | ||
| // FIXME: There is currently a limitation in TestRenamer in that it does not rename captures. | ||
| // This means, that in this example, captures for State[Int] and State[String] are both printed as "State", | ||
| // leading to a collapse of the capture set {State_1, State_2} to just {State}. | ||
| File("examples/pos/parametrized.effekt") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marzipankaiser this is what I just mentioned in person. |
||
| ) | ||
|
|
||
| def positives: Set[File] = Set( | ||
| examplesDir / "pos", | ||
| examplesDir / "casestudies", | ||
| examplesDir / "benchmarks", | ||
| ) | ||
|
|
||
| def runTests() = positives.foreach(runPositiveTestsIn) | ||
|
|
||
| def runPositiveTestsIn(dir: File): Unit = | ||
| foreachFileIn(dir) { | ||
| // We don't currently test *.effekt.md files | ||
| f => if (!ignored.contains(f) && !f.getName.endsWith(".md")) { | ||
| test(s"${f.getPath}") { | ||
| toCoreThenReparse(f) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def toCoreThenReparse(input: File) = { | ||
| val content = IO.read(input) | ||
| val config = new EffektConfig(Seq("--Koutput", "string")) | ||
| config.verify() | ||
| context.setup(config) | ||
| val (_, _, coreMod: ModuleDecl) = context.frontend.compile(StringSource(content, "input.effekt"))(using context).map { | ||
| case (_, decl) => decl | ||
| }.getOrElse { | ||
| val errors = plainMessaging.formatMessages(context.messaging.buffer) | ||
| sys error errors | ||
| } | ||
| val renamer = TestRenamer(Names(defaultNames)) | ||
| val expectedRenamed = renamer(coreMod) | ||
| val printed = core.PrettyPrinter.format(expectedRenamed).layout | ||
| val reparsed: ModuleDecl = parse(printed)(using Location.empty) | ||
| val reparsedRenamed = renamer(reparsed) | ||
| val reparsedPrinted = core.PrettyPrinter.format(reparsedRenamed).layout | ||
| val expectedPrinted = core.PrettyPrinter.format(expectedRenamed).layout | ||
| assertEquals(reparsedPrinted, expectedPrinted) | ||
| } | ||
|
|
||
| def foreachFileIn(file: File)(test: File => Unit): Unit = | ||
| file match { | ||
| case f if f.isDirectory => | ||
| f.listFiles.foreach(foreachFileIn(_)(test)) | ||
| case f if f.getName.endsWith(".effekt") || f.getName.endsWith(".effekt.md") => | ||
| test(f) | ||
| case _ => () | ||
| } | ||
|
|
||
| runTests() | ||
| } | ||
|
|
||
| /** | ||
| * A "backend" that simply outputs the core module for a given Effekt source program. | ||
| */ | ||
| class CompileToCore extends Compiler[(Id, symbols.Module, ModuleDecl)] { | ||
| def extension = ".effekt-core.ir" | ||
|
|
||
| // Support all the feature flags so that we can test all extern declarations | ||
| override def supportedFeatureFlags: List[String] = List("vm", "js", "jsNode", "chez", "llvm") | ||
|
|
||
| override def prettyIR(source: Source, stage: Stage)(using C: Context): Option[Document] = None | ||
|
|
||
| override def treeIR(source: Source, stage: Stage)(using Context): Option[Any] = None | ||
|
|
||
| override def compile(source: Source)(using C: Context): Option[(Map[String, String], (Id, symbols.Module, ModuleDecl))] = | ||
| Optimized.run(source).map { res => (Map.empty, res) } | ||
|
|
||
| lazy val Core = Phase.cached("core") { | ||
| Frontend andThen Middleend | ||
| } | ||
|
|
||
| lazy val Optimized = allToCore(Core) andThen Aggregate map { | ||
| case input @ CoreTransformed(source, tree, mod, core) => | ||
| val mainSymbol = Context.ensureMainExists(mod) | ||
| (mainSymbol, mod, core) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.