Skip to content

Commit 03c2cb1

Browse files
authored
Merge pull request #13239 from tanishiking/support-new-scala3-modifiers-semanticdb
[SemanticDB]Support new Scala3 modifiers in SemanticDB
2 parents 8bf2183 + e7a641c commit 03c2cb1

File tree

5 files changed

+114
-34
lines changed

5 files changed

+114
-34
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class ExtractSemanticDB extends Phase:
429429
props |= SymbolInformation.Property.FINAL.value
430430
if sym.is(Sealed) then
431431
props |= SymbolInformation.Property.SEALED.value
432-
if sym.isOneOf(GivenOrImplicit) then
432+
if sym.is(Implicit) then
433433
props |= SymbolInformation.Property.IMPLICIT.value
434434
if sym.is(Lazy, butNot=Module) then
435435
props |= SymbolInformation.Property.LAZY.value
@@ -449,6 +449,20 @@ class ExtractSemanticDB extends Phase:
449449
props |= SymbolInformation.Property.STATIC.value
450450
if sym.is(Enum) then
451451
props |= SymbolInformation.Property.ENUM.value
452+
if sym.is(Given) then
453+
props |= SymbolInformation.Property.GIVEN.value
454+
if sym.is(Inline) then
455+
props |= SymbolInformation.Property.INLINE.value
456+
if sym.is(Open) then
457+
props |= SymbolInformation.Property.OPEN.value
458+
if sym.is(Open) then
459+
props |= SymbolInformation.Property.OPEN.value
460+
if sym.is(Transparent) then
461+
props |= SymbolInformation.Property.TRANSPARENT.value
462+
if sym.is(Infix) then
463+
props |= SymbolInformation.Property.INFIX.value
464+
if sym.is(Opaque) then
465+
props |= SymbolInformation.Property.OPAQUE.value
452466
props
453467

454468
private def symbolAccess(sym: Symbol, kind: SymbolInformation.Kind)(using Context): Access =

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ object Scala3:
187187
def isStatic: Boolean = (info.properties & SymbolInformation.Property.STATIC.value) != 0
188188
def isEnum: Boolean = (info.properties & SymbolInformation.Property.ENUM.value) != 0
189189
def isDefault: Boolean = (info.properties & SymbolInformation.Property.DEFAULT.value) != 0
190+
def isGiven: Boolean = (info.properties & SymbolInformation.Property.GIVEN.value) != 0
191+
def isInline: Boolean = (info.properties & SymbolInformation.Property.INLINE.value) != 0
192+
def isOpen: Boolean = (info.properties & SymbolInformation.Property.OPEN.value) != 0
193+
def isTransparent: Boolean = (info.properties & SymbolInformation.Property.TRANSPARENT.value) != 0
194+
def isInfix: Boolean = (info.properties & SymbolInformation.Property.INFIX.value) != 0
195+
def isOpaque: Boolean = (info.properties & SymbolInformation.Property.OPAQUE.value) != 0
190196

191197
def isUnknownKind: Boolean = info.kind.isUnknownKind
192198
def isLocal: Boolean = info.kind.isLocal

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
437437
def isPrimary: _root_.scala.Boolean = false
438438
def isEnum: _root_.scala.Boolean = false
439439
def isDefault: _root_.scala.Boolean = false
440+
def isGiven: _root_.scala.Boolean = false
441+
def isInline: _root_.scala.Boolean = false
442+
def isOpen: _root_.scala.Boolean = false
443+
def isTransparent: _root_.scala.Boolean = false
444+
def isInfix: _root_.scala.Boolean = false
445+
def isOpaque: _root_.scala.Boolean = false
440446

441447
final def asRecognized: _root_.scala.Option[dotty.tools.dotc.semanticdb.SymbolInformation.Property.Recognized] = if (isUnrecognized) _root_.scala.None else _root_.scala.Some(this.asInstanceOf[dotty.tools.dotc.semanticdb.SymbolInformation.Property.Recognized])
442448
}
@@ -549,10 +555,52 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
549555
override def isDefault: _root_.scala.Boolean = true
550556
}
551557

558+
@SerialVersionUID(0L)
559+
case object GIVEN extends Property(65536) with Property.Recognized {
560+
val index = 15
561+
val name = "GIVEN"
562+
override def isGiven: _root_.scala.Boolean = true
563+
}
564+
565+
@SerialVersionUID(0L)
566+
case object INLINE extends Property(131072) with Property.Recognized {
567+
val index = 16
568+
val name = "INLINE"
569+
override def isInline: _root_.scala.Boolean = true
570+
}
571+
572+
@SerialVersionUID(0L)
573+
case object OPEN extends Property(262144) with Property.Recognized {
574+
val index = 17
575+
val name = "OPEN"
576+
override def isOpen: _root_.scala.Boolean = true
577+
}
578+
579+
@SerialVersionUID(0L)
580+
case object TRANSPARENT extends Property(524288) with Property.Recognized {
581+
val index = 18
582+
val name = "TRANSPARENT"
583+
override def isTransparent: _root_.scala.Boolean = true
584+
}
585+
586+
@SerialVersionUID(0L)
587+
case object INFIX extends Property(1048576) with Property.Recognized {
588+
val index = 19
589+
val name = "INFIX"
590+
override def isInfix: _root_.scala.Boolean = true
591+
}
592+
593+
@SerialVersionUID(0L)
594+
case object OPAQUE extends Property(2097152) with Property.Recognized {
595+
val index = 20
596+
val name = "OPAQUE"
597+
override def isOpaque: _root_.scala.Boolean = true
598+
}
599+
552600
@SerialVersionUID(0L)
553601
final case class Unrecognized(unrecognizedValue: _root_.scala.Int) extends Property(unrecognizedValue) with SemanticdbUnrecognizedEnum
554602

555-
lazy val values = scala.collection.immutable.Seq(UNKNOWN_PROPERTY, ABSTRACT, FINAL, SEALED, IMPLICIT, LAZY, CASE, COVARIANT, CONTRAVARIANT, VAL, VAR, STATIC, PRIMARY, ENUM, DEFAULT)
603+
lazy val values = scala.collection.immutable.Seq(UNKNOWN_PROPERTY, ABSTRACT, FINAL, SEALED, IMPLICIT, LAZY, CASE, COVARIANT, CONTRAVARIANT, VAL, VAR, STATIC, PRIMARY, ENUM, DEFAULT, GIVEN, INLINE, OPEN, TRANSPARENT, INFIX, OPAQUE)
556604
def fromValue(__value: _root_.scala.Int): Property = __value match {
557605
case 0 => UNKNOWN_PROPERTY
558606
case 4 => ABSTRACT
@@ -569,6 +617,12 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
569617
case 8192 => PRIMARY
570618
case 16384 => ENUM
571619
case 32768 => DEFAULT
620+
case 65536 => GIVEN
621+
case 131072 => INLINE
622+
case 262144 => OPEN
623+
case 524288 => TRANSPARENT
624+
case 1048576 => INFIX
625+
case 2097152 => OPAQUE
572626
case __other => Unrecognized(__other)
573627
}
574628

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ object Tools:
117117
if info.isPrimary then sb.append("primary ")
118118
if info.isEnum then sb.append("enum ")
119119
if info.isDefault then sb.append("default ")
120+
if info.isGiven then sb.append("given ")
121+
if info.isInline then sb.append("inline ")
122+
if info.isOpen then sb.append("open ")
123+
if info.isTransparent then sb.append("transparent ")
124+
if info.isInfix then sb.append("infix ")
125+
if info.isOpaque then sb.append("opaque ")
120126
info.kind match
121127
case LOCAL => sb.append("local ")
122128
case FIELD => sb.append("field ")

tests/semanticdb/metac.expect

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Occurrences => 5 entries
343343
Symbols:
344344
angiven/AnonymousGiven$package. => final package object angiven
345345
angiven/AnonymousGiven$package.bar(). => method bar
346-
angiven/AnonymousGiven$package.bar().(x$1) => implicit param x$1
346+
angiven/AnonymousGiven$package.bar().(x$1) => given param x$1
347347
angiven/Foo# => trait Foo
348348
angiven/Foo#`<init>`(). => primary ctor <init>
349349

@@ -437,7 +437,7 @@ classes/C10#s. => private[this] val method s
437437
classes/C11# => class C11
438438
classes/C11#`<init>`(). => primary ctor <init>
439439
classes/C11#foo(). => macro foo
440-
classes/C11#foo(). => macro foo
440+
classes/C11#foo(). => inline macro foo
441441
classes/C12# => class C12
442442
classes/C12#Context# => class Context
443443
classes/C12#Context#Expr# => type Expr
@@ -935,7 +935,7 @@ _empty_/Enums.Suits.Clubs. => case val static enum method Clubs
935935
_empty_/Enums.Suits.Diamonds. => case val static enum method Diamonds
936936
_empty_/Enums.Suits.Hearts. => case val static enum method Hearts
937937
_empty_/Enums.Suits.Spades. => case val static enum method Spades
938-
_empty_/Enums.Suits.derived$CanEqual. => implicit lazy val method derived$CanEqual
938+
_empty_/Enums.Suits.derived$CanEqual. => lazy val given method derived$CanEqual
939939
_empty_/Enums.Suits.fromOrdinal(). => method fromOrdinal
940940
_empty_/Enums.Suits.fromOrdinal().(ordinal) => param ordinal
941941
_empty_/Enums.Suits.isBlack(). => method isBlack
@@ -994,13 +994,13 @@ _empty_/Enums.`<:<`.Refl.toString(). => method toString
994994
_empty_/Enums.`<:<`.Refl.unapply(). => method unapply
995995
_empty_/Enums.`<:<`.Refl.unapply().(x$1) => param x$1
996996
_empty_/Enums.`<:<`.Refl.unapply().[C] => typeparam C
997-
_empty_/Enums.`<:<`.`given_<:<_T_T`(). => final implicit method given_<:<_T_T
997+
_empty_/Enums.`<:<`.`given_<:<_T_T`(). => final given method given_<:<_T_T
998998
_empty_/Enums.`<:<`.`given_<:<_T_T`().[T] => typeparam T
999999
_empty_/Enums.`<:<`.fromOrdinal(). => method fromOrdinal
10001000
_empty_/Enums.`<:<`.fromOrdinal().(ordinal) => param ordinal
10011001
_empty_/Enums.some1. => val method some1
10021002
_empty_/Enums.unwrap(). => method unwrap
1003-
_empty_/Enums.unwrap().(ev) => implicit param ev
1003+
_empty_/Enums.unwrap().(ev) => given param ev
10041004
_empty_/Enums.unwrap().(opt) => param opt
10051005
_empty_/Enums.unwrap().[A] => typeparam A
10061006
_empty_/Enums.unwrap().[B] => typeparam B
@@ -1445,16 +1445,16 @@ a/b/Givens.Monoid#combine().(x) => param x
14451445
a/b/Givens.Monoid#combine().(y) => param y
14461446
a/b/Givens.Monoid#empty(). => abstract method empty
14471447
a/b/Givens.foo(). => method foo
1448-
a/b/Givens.foo().(A) => implicit param A
1448+
a/b/Givens.foo().(A) => given param A
14491449
a/b/Givens.foo().[A] => typeparam A
1450-
a/b/Givens.given_Monoid_String. => final implicit object given_Monoid_String
1450+
a/b/Givens.given_Monoid_String. => final given object given_Monoid_String
14511451
a/b/Givens.given_Monoid_String.combine(). => method combine
14521452
a/b/Givens.given_Monoid_String.combine().(x) => param x
14531453
a/b/Givens.given_Monoid_String.combine().(y) => param y
14541454
a/b/Givens.given_Monoid_String.empty(). => method empty
14551455
a/b/Givens.goodbye1. => val method goodbye1
14561456
a/b/Givens.hello1. => val method hello1
1457-
a/b/Givens.int2String(). => final implicit macro int2String
1457+
a/b/Givens.int2String(). => final given inline macro int2String
14581458
a/b/Givens.sayGoodbye(). => method sayGoodbye
14591459
a/b/Givens.sayGoodbye().(any) => param any
14601460
a/b/Givens.sayGoodbye().[B] => typeparam B
@@ -1748,37 +1748,37 @@ Occurrences => 72 entries
17481748

17491749
Symbols:
17501750
givens/InventedNames$package. => final package object givens
1751-
givens/InventedNames$package.`* *`. => final implicit lazy val method * *
1751+
givens/InventedNames$package.`* *`. => final lazy val given method * *
17521752
givens/InventedNames$package.a. => val method a
17531753
givens/InventedNames$package.b. => val method b
17541754
givens/InventedNames$package.c. => val method c
17551755
givens/InventedNames$package.d. => val method d
17561756
givens/InventedNames$package.e. => val method e
17571757
givens/InventedNames$package.f. => val method f
17581758
givens/InventedNames$package.g. => val method g
1759-
givens/InventedNames$package.given_Char. => final implicit lazy val method given_Char
1760-
givens/InventedNames$package.given_Double(). => final implicit method given_Double
1761-
givens/InventedNames$package.given_Double().(x$1) => implicit param x$1
1762-
givens/InventedNames$package.given_Float. => final implicit lazy val method given_Float
1763-
givens/InventedNames$package.given_List_T(). => final implicit method given_List_T
1759+
givens/InventedNames$package.given_Char. => final lazy val given method given_Char
1760+
givens/InventedNames$package.given_Double(). => final given method given_Double
1761+
givens/InventedNames$package.given_Double().(x$1) => given param x$1
1762+
givens/InventedNames$package.given_Float. => final lazy val given method given_Float
1763+
givens/InventedNames$package.given_List_T(). => final given method given_List_T
17641764
givens/InventedNames$package.given_List_T().[T] => typeparam T
1765-
givens/InventedNames$package.given_String. => final implicit lazy val method given_String
1766-
givens/InventedNames$package.given_X. => final implicit object given_X
1765+
givens/InventedNames$package.given_String. => final lazy val given method given_String
1766+
givens/InventedNames$package.given_X. => final given object given_X
17671767
givens/InventedNames$package.given_X.doX(). => method doX
17681768
givens/InventedNames$package.given_Y# => class given_Y
17691769
givens/InventedNames$package.given_Y#`<init>`(). => primary ctor <init>
1770-
givens/InventedNames$package.given_Y#`<init>`().(x$1) => implicit val param x$1
1770+
givens/InventedNames$package.given_Y#`<init>`().(x$1) => val given param x$1
17711771
givens/InventedNames$package.given_Y#doY(). => method doY
1772-
givens/InventedNames$package.given_Y#x$1. => protected implicit val method x$1
1773-
givens/InventedNames$package.given_Y(). => final implicit method given_Y
1774-
givens/InventedNames$package.given_Y().(x$1) => implicit param x$1
1772+
givens/InventedNames$package.given_Y#x$1. => protected val given method x$1
1773+
givens/InventedNames$package.given_Y(). => final given method given_Y
1774+
givens/InventedNames$package.given_Y().(x$1) => given param x$1
17751775
givens/InventedNames$package.given_Z_T# => class given_Z_T
17761776
givens/InventedNames$package.given_Z_T#[T] => typeparam T
17771777
givens/InventedNames$package.given_Z_T#`<init>`(). => primary ctor <init>
17781778
givens/InventedNames$package.given_Z_T#doZ(). => method doZ
1779-
givens/InventedNames$package.given_Z_T(). => final implicit method given_Z_T
1779+
givens/InventedNames$package.given_Z_T(). => final given method given_Z_T
17801780
givens/InventedNames$package.given_Z_T().[T] => typeparam T
1781-
givens/InventedNames$package.intValue. => final implicit lazy val method intValue
1781+
givens/InventedNames$package.intValue. => final lazy val given method intValue
17821782
givens/InventedNames$package.x. => val method x
17831783
givens/InventedNames$package.y. => val method y
17841784
givens/InventedNames$package.z. => val method z
@@ -2575,8 +2575,8 @@ Occurrences => 4 entries
25752575

25762576
Symbols:
25772577
_empty_/NewModifiers. => final object NewModifiers
2578-
_empty_/NewModifiers.A# => type A
2579-
_empty_/NewModifiers.foo. => val method foo
2578+
_empty_/NewModifiers.A# => opaque type A
2579+
_empty_/NewModifiers.foo. => val inline method foo
25802580

25812581
Occurrences:
25822582
[0:7..0:19): NewModifiers <- _empty_/NewModifiers.
@@ -3574,8 +3574,8 @@ Occurrences => 12 entries
35743574

35753575
Symbols:
35763576
inlinedefs/FakePredef. => final object FakePredef
3577-
inlinedefs/FakePredef.assert(). => final macro assert
3578-
inlinedefs/FakePredef.assert().(assertion) => param assertion
3577+
inlinedefs/FakePredef.assert(). => final inline transparent macro assert
3578+
inlinedefs/FakePredef.assert().(assertion) => inline param assertion
35793579

35803580
Occurrences:
35813581
[0:8..0:18): inlinedefs <- inlinedefs/
@@ -3637,9 +3637,9 @@ local5 => val local Nat_this
36373637
local6 => val local Nat_this
36383638
recursion/Nats. => final object Nats
36393639
recursion/Nats.Nat# => sealed trait Nat
3640-
recursion/Nats.Nat#`++`(). => macro ++
3641-
recursion/Nats.Nat#`+`(). => macro +
3642-
recursion/Nats.Nat#`+`().(that) => param that
3640+
recursion/Nats.Nat#`++`(). => inline transparent macro ++
3641+
recursion/Nats.Nat#`+`(). => inline transparent macro +
3642+
recursion/Nats.Nat#`+`().(that) => inline param that
36433643
recursion/Nats.Nat#`<init>`(). => primary ctor <init>
36443644
recursion/Nats.Succ# => case class Succ
36453645
recursion/Nats.Succ#[N] => typeparam N
@@ -3662,8 +3662,8 @@ recursion/Nats.Succ.unapply().(x$1) => param x$1
36623662
recursion/Nats.Succ.unapply().[N] => typeparam N
36633663
recursion/Nats.Zero. => final case object Zero
36643664
recursion/Nats.j31. => val method j31
3665-
recursion/Nats.toIntg(). => macro toIntg
3666-
recursion/Nats.toIntg().(n) => param n
3665+
recursion/Nats.toIntg(). => inline transparent macro toIntg
3666+
recursion/Nats.toIntg().(n) => inline param n
36673667

36683668
Occurrences:
36693669
[1:8..1:17): recursion <- recursion/
@@ -4385,7 +4385,7 @@ _empty_/MyProgram#main().(args) => param args
43854385
_empty_/toplevel$package. => final package object _empty_
43864386
_empty_/toplevel$package.MyProgram(). => method MyProgram
43874387
_empty_/toplevel$package.MyProgram().(times) => param times
4388-
_empty_/toplevel$package.a. => val method a
4388+
_empty_/toplevel$package.a. => val inline method a
43894389
_empty_/toplevel$package.combine(). => method combine
43904390
_empty_/toplevel$package.combine().(x) => param x
43914391
_empty_/toplevel$package.combine().(y) => param y

0 commit comments

Comments
 (0)