Skip to content

Commit 56c5909

Browse files
committed
Run AppendDiagnostics phase after crossVersionChecks
So that we can add deprecation warnings to SemanticDB
1 parent d2b54c2 commit 56c5909

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Compiler {
3838
List(new CheckUnused.PostTyper) :: // Check for unused elements
3939
List(new YCheckPositions) :: // YCheck positions
4040
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
41-
List(new semanticdb.ExtractSemanticDB.PostTyper) :: // Extract info and attach to the tree of the unit file
41+
List(new semanticdb.ExtractSemanticDB.ExtractSemanticInfo) :: // Extract info and attach to the tree of the unit file
4242
List(new PostTyper) :: // Additional checks and cleanups after type checking
4343
List(new sjs.PrepJSInterop) :: // Additional checks and transformations for Scala.js (Scala.js only)
4444
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
@@ -51,7 +51,6 @@ class Compiler {
5151
List(new Inlining) :: // Inline and execute macros
5252
List(new PostInlining) :: // Add mirror support for inlined code
5353
List(new CheckUnused.PostInlining) :: // Check for unused elements
54-
List(new semanticdb.ExtractSemanticDB.PostInlining) :: // Attach warnings to extracted SemanticDB and write to .semanticdb file
5554
List(new Staging) :: // Check staging levels and heal staged types
5655
List(new Splicing) :: // Replace level 1 splices with holes
5756
List(new PickleQuotes) :: // Turn quoted trees into explicit run-time data structures
@@ -72,6 +71,7 @@ class Compiler {
7271
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
7372
new ElimRepeated, // Rewrite vararg parameters and arguments
7473
new RefChecks) :: // Various checks mostly related to abstract members and overriding
74+
List(new semanticdb.ExtractSemanticDB.AppendDiagnostics) :: // Attach warnings to extracted SemanticDB and write to .semanticdb file
7575
List(new init.Checker) :: // Check initialization of objects
7676
List(new ProtectedAccessors, // Add accessors for protected members
7777
new ExtensionMethods, // Expand methods of value classes with extension methods

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,24 @@ class ExtractSemanticDB private (phaseMode: ExtractSemanticDB.PhaseMode, suffix:
6262
override def isCheckable: Boolean = false
6363

6464
override def runOn(units: List[CompilationUnit])(using ctx: Context): List[CompilationUnit] = {
65-
val appendWarnings = phaseMode == ExtractSemanticDB.PhaseMode.PostInlining
65+
val appendDiagnostics = phaseMode == ExtractSemanticDB.PhaseMode.AppendDiagnostics
6666
val warnings =
67-
if (appendWarnings)
67+
if (appendDiagnostics)
6868
ctx.reporter.allWarnings.groupBy(w => w.pos.source)
6969
else Map.empty
7070

71-
units.asJava.parallelStream().map { unit =>
71+
units.asJava.parallelStream().forEach { unit =>
7272
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
73-
if (appendWarnings)
73+
if (appendDiagnostics)
7474
warnings.get(unit.source).foreach { ws =>
7575
ExtractSemanticDB.appendDiagnostics(unit.source, ws.map(_.toSemanticDiagnostic))
7676
}
7777
else
7878
val extractor = ExtractSemanticDB.Extractor()
7979
extractor.extract(unit.tpdTree)
8080
ExtractSemanticDB.write(unit.source, extractor.occurrences.toList, extractor.symbolInfos.toList, extractor.synthetics.toList)
81-
unit
82-
}.toList().asScala.toList
81+
}
82+
units
8383
}
8484

8585
def run(using Context): Unit = unsupported("run")
@@ -94,12 +94,12 @@ object ExtractSemanticDB:
9494
val description: String = "extract info into .semanticdb files"
9595

9696
enum PhaseMode:
97-
case PostTyper
98-
case PostInlining
97+
case ExtractSemanticInfo
98+
case AppendDiagnostics
9999

100-
class PostTyper extends ExtractSemanticDB(PhaseMode.PostTyper, "PostTyper")
100+
class ExtractSemanticInfo extends ExtractSemanticDB(PhaseMode.ExtractSemanticInfo, "ExtractSemanticInfo")
101101

102-
class PostInlining extends ExtractSemanticDB(PhaseMode.PostInlining, "PostInlining")
102+
class AppendDiagnostics extends ExtractSemanticDB(PhaseMode.AppendDiagnostics, "AppendDiagnostics")
103103

104104
private def semanticdbTarget(using Context): Option[Path] =
105105
Option(ctx.settings.semanticdbTarget.value)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Deprecated/*<-_empty_::Deprecated.*/ {
2+
@deprecated/*->scala::deprecated#*/ def deprecatedMethod/*<-_empty_::Deprecated.deprecatedMethod().*/ = ???/*->scala::Predef.`???`().*/
3+
def main/*<-_empty_::Deprecated.main().*/ = deprecatedMethod/*->_empty_::Deprecated.deprecatedMethod().*/
4+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Deprecated {
2+
@deprecated def deprecatedMethod = ???
3+
def main = deprecatedMethod
4+
}

tests/semanticdb/metac.expect

+28
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,34 @@ Synthetics:
731731
[51:16..51:27):List(1).map => *[Int]
732732
[51:16..51:20):List => *.apply[Int]
733733

734+
expect/Deprecated.scala
735+
-----------------------
736+
737+
Summary:
738+
Schema => SemanticDB v4
739+
Uri => Deprecated.scala
740+
Text => empty
741+
Language => Scala
742+
Symbols => 3 entries
743+
Occurrences => 6 entries
744+
Diagnostics => 1 entries
745+
746+
Symbols:
747+
_empty_/Deprecated. => final object Deprecated extends Object { self: Deprecated.type => +3 decls }
748+
_empty_/Deprecated.deprecatedMethod(). => @deprecated method deprecatedMethod => Nothing
749+
_empty_/Deprecated.main(). => method main => Nothing
750+
751+
Occurrences:
752+
[0:7..0:17): Deprecated <- _empty_/Deprecated.
753+
[1:3..1:13): deprecated -> scala/deprecated#
754+
[1:18..1:34): deprecatedMethod <- _empty_/Deprecated.deprecatedMethod().
755+
[1:37..1:40): ??? -> scala/Predef.`???`().
756+
[2:6..2:10): main <- _empty_/Deprecated.main().
757+
[2:13..2:29): deprecatedMethod -> _empty_/Deprecated.deprecatedMethod().
758+
759+
Diagnostics:
760+
[2:13..2:29): [warning] method deprecatedMethod in object Deprecated is deprecated
761+
734762
expect/Empty.scala
735763
------------------
736764

0 commit comments

Comments
 (0)