Skip to content

Commit

Permalink
Revert invented givens and anonymous using params for the time being
Browse files Browse the repository at this point in the history
We have a discussion how to express the invented variable names in
SemanticDB.
We'll discuss the design of the tree in the issue and come back in the
future.
  • Loading branch information
tanishiking committed Aug 27, 2021
1 parent fd67b6e commit aef23bc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,11 @@ class ExtractSemanticDB extends Phase:
case tree: DefDef if tree.symbol.isConstructor => // ignore typeparams for secondary ctors
tree.trailingParamss.foreach(_.foreach(traverse))
traverse(tree.rhs)
case tree: (DefDef | ValDef) if tree.symbol.isSyntheticWithIdent || isInventedGiven(tree) =>
case tree: (DefDef | ValDef) if tree.symbol.isSyntheticWithIdent =>
tree match
case tree: DefDef =>
tree.paramss.foreach(_.foreach(param => registerSymbolSimple(param.symbol)))
case tree: ValDef if tree.symbol.is(Given) =>
synth.tryFindSynthetic(tree).foreach(synthetics.addOne)
traverse(tree.tpt)
case _ =>
if !tree.symbol.isGlobal then
Expand Down
12 changes: 0 additions & 12 deletions compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,4 @@ object Scala3:

end IdentifierOrdering

/** Check if the symbol is invented by Desugar.inventGivenOrExtensionName
* return true if the symbol is defined as `given Int = ...` and name is invented as "given_Int"
*/
def isInventedGiven(tree: tpd.Tree)(using Context): Boolean =
tree match
case tree: tpd.ValDef =>
val sym = tree.symbol
sym.is(Given) &&
sym.name.startsWith("given_") &&
!namePresentInSource(sym, tree.nameSpan, tree.source)
case _ => false

end Scala3
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SyntheticsExtractor:
extension (synth: s.Synthetic)
def toOpt: Some[s.Synthetic] = Some(synth)

if tree.span.isSynthetic || isInventedGiven(tree) then
if tree.span.isSynthetic then
tree match
case tree: Apply if isForSynthetic(tree) =>
None // not yet supported (for synthetics)
Expand Down Expand Up @@ -45,12 +45,6 @@ class SyntheticsExtractor:
)
).toOpt

// Anonymous context parameter
case tree: ValDef if tree.symbol.is(Given) =>
s.Synthetic(
range(tree.span, tree.source),
tree.toSemanticId
).toOpt
case _ => None
else None

Expand Down
17 changes: 3 additions & 14 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ Text => empty
Language => Scala
Symbols => 5 entries
Occurrences => 4 entries
Synthetics => 1 entries

Symbols:
angiven/AnonymousGiven$package. => final package object angiven extends Object { self: angiven.type => +2 decls }
Expand All @@ -383,9 +382,6 @@ Occurrences:
[4:4..4:7): bar <- angiven/AnonymousGiven$package.bar().
[4:14..4:17): Foo -> angiven/Foo#

Synthetics:
[4:14..4:17):Foo => x$1

expect/Classes.scala
--------------------

Expand Down Expand Up @@ -1238,7 +1234,7 @@ Text => empty
Language => Scala
Symbols => 26 entries
Occurrences => 50 entries
Synthetics => 2 entries
Synthetics => 1 entries

Symbols:
ext/Extension$package. => final package object ext extends Object { self: ext.type => +6 decls }
Expand Down Expand Up @@ -1321,7 +1317,6 @@ Occurrences:
[17:50..17:51): U -> ext/Functor#map().[U]

Synthetics:
[14:24..14:31):Read[T] => x$2
[14:46..14:61):summon[Read[T]] => *(x$2)

expect/ForComprehension.scala
Expand Down Expand Up @@ -1711,7 +1706,7 @@ Text => empty
Language => Scala
Symbols => 45 entries
Occurrences => 61 entries
Synthetics => 5 entries
Synthetics => 2 entries

Symbols:
givens/InventedNames$package. => final package object givens extends Object { self: givens.type => +24 decls }
Expand Down Expand Up @@ -1824,9 +1819,6 @@ Occurrences:
[41:18..41:24): String -> scala/Predef.String#

Synthetics:
[14:0..14:20):given String = "str" => given_String
[15:13..15:16):Int => x$1
[24:13..24:14):X => x$1
[34:8..34:20):given_Double => *(intValue)
[40:8..40:15):given_Y => *(given_X)

Expand Down Expand Up @@ -2972,7 +2964,7 @@ Text => empty
Language => Scala
Symbols => 52 entries
Occurrences => 133 entries
Synthetics => 24 entries
Synthetics => 21 entries

Symbols:
example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls }
Expand Down Expand Up @@ -3181,12 +3173,9 @@ Synthetics:
[32:35..32:49):Array.empty[T] => *(evidence$1)
[36:22..36:27):new F => orderingToOrdered[F](*)
[36:22..36:27):new F => *(ordering)
[50:26..50:29):Int => x$2
[51:17..51:20):Int => x$1
[51:24..51:30):foo(0) => *(x$1)
[52:27..52:33):foo(0) => *(x)
[55:6..55:12):foo(x) => *(x)
[57:6..57:19):given Int = 1 => given_Int
[58:6..58:12):foo(0) => *(given_Int)

expect/Traits.scala
Expand Down

0 comments on commit aef23bc

Please sign in to comment.