Skip to content
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

Ignore best effort settings in repl and update docs #21540

Merged
merged 2 commits into from
Sep 10, 2024
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
15 changes: 14 additions & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,21 @@ class ReplDriver(settings: Array[String],
setupRootCtx(this.settings ++ settings, rootCtx)
}

private val incompatibleOptions: Seq[String] = Seq(
initCtx.settings.YbestEffort.name,
initCtx.settings.YwithBestEffortTasty.name
)

private def setupRootCtx(settings: Array[String], rootCtx: Context) = {
setup(settings, rootCtx) match
val incompatible = settings.intersect(incompatibleOptions)
val filteredSettings =
if !incompatible.isEmpty then
inContext(rootCtx) {
out.println(i"Options incompatible with repl will be ignored: ${incompatible.mkString(", ")}")
}
settings.filter(!incompatible.contains(_))
else settings
setup(filteredSettings, rootCtx) match
case Some((files, ictx)) => inContext(ictx) {
shouldStart = true
if files.nonEmpty then out.println(i"Ignoring spurious arguments: $files%, %")
Expand Down
11 changes: 11 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,17 @@ class ReplCompilerTests extends ReplTest:
assertTrue(last, last.startsWith("val res0: tpolecat.type = null"))
assertTrue(last, last.endsWith("""// result of "res0.toString" is null"""))

@Test def `i21431 filter out best effort options`: Unit =
initially:
run(":settings -Ybest-effort -Ywith-best-effort-tasty")
.andThen:
run("0") // check for crash
val last = lines()
println(last)
assertTrue(last(0), last(0) == ("Options incompatible with repl will be ignored: -Ybest-effort, -Ywith-best-effort-tasty"))
assertTrue(last(1), last(1) == ("val res0: Int = 0"))


object ReplCompilerTests:

private val pattern = Pattern.compile("\\r[\\n]?|\\n");
Expand Down
3 changes: 3 additions & 0 deletions docs/_docs/internals/best-effort-compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ It is composed of two experimental compiler options:
* `-Ywith-best-effort-tasty` allows to read Best Effort TASTy files, and if such file is read from the classpath then
limits compilation to the frontend phases

IMPORTANT: These options are meant to by used by an IDE and should never be used on the user side, in the project definition.
This is why they are hidden behind a private `-Y` option specifier.

This feature aims to force through to the typer phase regardless of errors, and then serialize tasty-like files
obtained from the error trees into the best effort directory (`META-INF/best-effort`) and also serialize semanticdb as normal.

Expand Down
Loading