forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export diagnostics (including unused warnings) to SemanticDB (scala#1…
…7835) fix scala#17535 ## What this PR does This PR splits `ExtractSemanticDB` to `PostTyper` and `PostInlining` (as `ChechUnused` does). - The `PostTyper` phase - It extracts SemanticDB information such as symbol definitions, symbol occurrences, type information, and synthetics. - ~**This phase does not write the information to a `.semanticdb` file**; instead, it attaches the SemanticDB information to the top-level tree.~ - And write `.semanticdb` file. - The `PostInlining` phase - It extracts diagnostics from `ctx.reporter` and attaches them to the SemanticDB information extracted in the `PostTyper` phase. - Afterwards, it updates the SemanticDB to a `.semanticdb` file (if there's warning in the file). - **We need to run this phase after the `CheckUnused.PostInlining` phase so that we can extract the warnings generated by "-Wunused".** Also, - Reporter now stores `warnings` in addition to `errors` - Tweaked SemanticDBTest to show the generated diagnostics to `metac.expect` ### Concerns - Since we attach the SemanticDB information to the top-level tree, it lives in-memory during the compilation which may leads to more memory usage for compilation - Now, Reporter stores all warnings in addition to errors (to convey the warnings across phases), which also may cause some more memory consumption.
- Loading branch information
Showing
11 changed files
with
325 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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 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
23 changes: 23 additions & 0 deletions
23
compiler/src/dotty/tools/dotc/semanticdb/DiagnosticOps.scala
This file contains 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,23 @@ | ||
package dotty.tools.dotc.semanticdb | ||
|
||
import dotty.tools.dotc.reporting.Diagnostic | ||
import dotty.tools.dotc.{semanticdb => s} | ||
import dotty.tools.dotc.interfaces.Diagnostic.{ERROR, INFO, WARNING} | ||
import dotty.tools.dotc.core.Contexts.Context | ||
import scala.annotation.internal.sharable | ||
|
||
object DiagnosticOps: | ||
@sharable private val asciiColorCodes = "\u001B\\[[;\\d]*m".r | ||
extension (d: Diagnostic) | ||
def toSemanticDiagnostic: s.Diagnostic = | ||
val severity = d.level match | ||
case ERROR => s.Diagnostic.Severity.ERROR | ||
case WARNING => s.Diagnostic.Severity.WARNING | ||
case INFO => s.Diagnostic.Severity.INFORMATION | ||
case _ => s.Diagnostic.Severity.INFORMATION | ||
val msg = asciiColorCodes.replaceAllIn(d.msg.message, m => "") | ||
s.Diagnostic( | ||
range = Scala3.range(d.pos.span, d.pos.source), | ||
severity = severity, | ||
message = msg | ||
) |
This file contains 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 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 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 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 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 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,4 @@ | ||
object Deprecated/*<-_empty_::Deprecated.*/ { | ||
@deprecated/*->scala::deprecated#*/ def deprecatedMethod/*<-_empty_::Deprecated.deprecatedMethod().*/ = ???/*->scala::Predef.`???`().*/ | ||
def main/*<-_empty_::Deprecated.main().*/ = deprecatedMethod/*->_empty_::Deprecated.deprecatedMethod().*/ | ||
} |
Oops, something went wrong.