Skip to content

Add DiagnosticRelatedInformation to compiler's interface #16677

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
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
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.interfaces.Diagnostic.{ERROR, INFO, WARNING}
import dotty.tools.dotc.util.SourcePosition

import java.util.Optional
import java.util.{Collections, Optional, List => JList}
import scala.util.chaining._
import core.Decorators.toMessage

Expand Down Expand Up @@ -100,6 +100,8 @@ class Diagnostic(
if (pos.exists && pos.source.exists) Optional.of(pos) else Optional.empty()
override def message: String =
msg.message.replaceAll("\u001B\\[[;\\d]*m", "")
override def diagnosticRelatedInformation: JList[interfaces.DiagnosticRelatedInformation] =
Collections.emptyList()

override def toString: String = s"$getClass at $pos: $message"
override def getMessage(): String = message
Expand Down
4 changes: 4 additions & 0 deletions interfaces/src/dotty/tools/dotc/interfaces/Diagnostic.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotty.tools.dotc.interfaces;

import java.util.Optional;
import java.util.List;

/** A diagnostic is a message emitted during the compilation process.
*
Expand All @@ -23,4 +24,7 @@ public interface Diagnostic {
/** @return The position in a source file of the code that caused this diagnostic
* to be emitted. */
Optional<SourcePosition> position();

/** @return A list of additional messages together with their code positions */
List<DiagnosticRelatedInformation> diagnosticRelatedInformation();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dotty.tools.dotc.interfaces;

public interface DiagnosticRelatedInformation {
SourcePosition position();
String message();
}
3 changes: 2 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ object Build {
settings(commonJavaSettings).
settings(commonMiMaSettings).
settings(
versionScheme := Some("semver-spec")
versionScheme := Some("semver-spec"),
mimaBinaryIssueFilters ++= MiMaFilters.Interfaces
)

/** Find an artifact with the given `name` in `classpath` */
Expand Down
4 changes: 4 additions & 0 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ object MiMaFilters {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.caps.unsafeUnbox"),
)
val TastyCore: Seq[ProblemFilter] = Seq()
val Interfaces: Seq[ProblemFilter] = Seq(
ProblemFilters.exclude[MissingClassProblem]("dotty.tools.dotc.interfaces.DiagnosticRelatedInformation"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("dotty.tools.dotc.interfaces.Diagnostic.diagnosticRelatedInformation")
)
Comment on lines +10 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary, since the baseVersion is 3.3.0-RC1, mima is set to run in backwards mode which lets us add new APIs without having to filter them, I checked that scala3-interfaces/mimaReportBinaryIssues did not fail if I removed this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me this fails with

[error] scala3-interfaces: Failed binary compatibility check against org.scala-lang:scala3-interfaces:3.2.2! Found 1 potential problems
[error]  * abstract method diagnosticRelatedInformation()java.util.List in interface dotty.tools.dotc.interfaces.Diagnostic is present only in current version
[error]    filter with: ProblemFilters.exclude[ReversedMissingMethodProblem]("dotty.tools.dotc.interfaces.Diagnostic.diagnosticRelatedInformation")
[error] java.lang.RuntimeException: Failed binary compatibility check against org.scala-lang:scala3-interfaces:3.2.2! Found 1 potential problems
[error]         at scala.sys.package$.error(package.scala:30)
[error]         at com.typesafe.tools.mima.plugin.SbtMima$.reportModuleErrors(SbtMima.scala:89)
[error]         at com.typesafe.tools.mima.plugin.MimaPlugin$.$anonfun$projectSettings$2(MimaPlugin.scala:36)
[error]         at com.typesafe.tools.mima.plugin.MimaPlugin$.$anonfun$projectSettings$2$adapted(MimaPlugin.scala:26)
[error]         at scala.collection.Iterator.foreach(Iterator.scala:943)
[error]         at scala.collection.Iterator.foreach$(Iterator.scala:943)
[error]         at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
[error]         at com.typesafe.tools.mima.plugin.MimaPlugin$.$anonfun$projectSettings$1(MimaPlugin.scala:26)
[error]         at com.typesafe.tools.mima.plugin.MimaPlugin$.$anonfun$projectSettings$1$adapted(MimaPlugin.scala:25)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]         at sbt.Execute.work(Execute.scala:291)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)

And this also failed in the CI. That's why I added these exceptions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does show scala3-interfaces/mimaCheckDirection outputs backward? If not, you may need to reload the sbt build / rebase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does. And I did run reload before running scala3-interfaces/mimaReportBinaryIssues. Does this mean there's a bug in MiMa checks? Anyway that doesn't seem to be a problem for this PR as the MiMa exceptions can be removed just after 3.3.0 gets a stable release

}
4 changes: 3 additions & 1 deletion tests/pos-with-compiler-cc/dotc/reporting/Diagnostic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.interfaces.Diagnostic.{ERROR, INFO, WARNING}
import dotty.tools.dotc.util.SourcePosition

import java.util.Optional
import java.util.{Collections, Optional, List => JList}
import scala.util.chaining._
import core.Decorators.toMessage
import language.experimental.pureFunctions
Expand Down Expand Up @@ -101,6 +101,8 @@ class Diagnostic(
if (pos.exists && pos.source.exists) Optional.of(pos) else Optional.empty()
override def message: String =
msg.message.replaceAll("\u001B\\[[;\\d]*m", "")
override def diagnosticRelatedInformation: JList[interfaces.DiagnosticRelatedInformation] =
Collections.emptyList()

override def toString: String = s"$getClass at $pos: $message"
override def getMessage(): String = message
Expand Down