Skip to content

Addition to TASTy reflect to semantic DB #5435

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 19 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5bf02b6
Able to consume tasty from semanticdb's tests
poechsel Oct 15, 2018
de3b82a
Start generating some symbols for semanticdb.
poechsel Oct 17, 2018
47d6d54
skeleton code to build symbols while iterating over owners
poechsel Oct 23, 2018
d889975
basic disimbiguator
poechsel Oct 23, 2018
df89463
add namePos to tastyreflect symbol and start generating valid semanticdb
poechsel Oct 23, 2018
11828f2
symbol generations for terms and types
poechsel Oct 28, 2018
a320d6e
add makefile to regenerate test files
poechsel Oct 31, 2018
79e07e7
small update for types
poechsel Oct 31, 2018
9aa3374
import Scala.scala from original implementation of semanticdb
poechsel Nov 6, 2018
39f370b
add companionClass and companionModule to tastyreflect + use them to …
poechsel Nov 6, 2018
6bc7254
fix range for package clause
poechsel Nov 6, 2018
d47ae1e
add special case for ident symbols of packageclause
poechsel Nov 6, 2018
afdabc5
add tests extracted from scalameta
poechsel Nov 11, 2018
e0815a9
fix <init> symbols and add method to distinguish compiler generated c…
poechsel Nov 12, 2018
31ca054
fix build errors due to a bad rebase
poechsel Nov 12, 2018
3f78703
remove companionClass and companionModule. Updated readme. Refactored…
poechsel Nov 15, 2018
eeb6df7
more generic disimbiguator using tastyreflect 'methods' function
poechsel Nov 15, 2018
4a5314d
Remove the makefile and refactored the testsuite
poechsel Nov 20, 2018
4373c10
merged semanticdb/input/build.sbt with project/Build.scala
poechsel Nov 22, 2018
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
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ val `dotty-language-server` = Build.`dotty-language-server`
val `dotty-bench` = Build.`dotty-bench`
val `dotty-bench-bootstrapped` = Build.`dotty-bench-bootstrapped`
val `dotty-semanticdb` = Build.`dotty-semanticdb`
val `dotty-semanticdb-input` = Build.`dotty-semanticdb-input`
val `scala-library` = Build.`scala-library`
val `scala-compiler` = Build.`scala-compiler`
val `scala-reflect` = Build.`scala-reflect`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ trait PositionOpsImpl extends scala.tasty.reflect.PositionOps with CoreImpl {
def start: Int = pos.start
def end: Int = pos.end

def exists: Boolean = pos.exists

def sourceFile: java.nio.file.Path = pos.source.file.jpath

def startLine: Int = pos.startLine
Expand All @@ -14,5 +16,4 @@ trait PositionOpsImpl extends scala.tasty.reflect.PositionOps with CoreImpl {
def startColumn: Int = pos.startColumn
def endColumn: Int = pos.endColumn
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
def name(implicit ctx: Context): String = symbol.name.toString
def fullName(implicit ctx: Context): String = symbol.fullName.toString

def pos(implicit ctx: Context): Position = symbol.pos

def owner(implicit ctx: Context): Symbol = symbol.owner

def localContext(implicit ctx: Context): Context = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w

def TypeTreeDeco(tpt: TypeTree): TypeTreeAPI = new TypeTreeAPI {
def pos(implicit ctx: Context): Position = tpt.pos
def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar
def symbol(implicit ctx: Context): Symbol = tpt.symbol
def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar
}

object IsTypeTree extends IsTypeTreeExtractor {
Expand Down
3 changes: 2 additions & 1 deletion library/src/scala/tasty/reflect/PositionOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ trait PositionOps extends Core {

trait PositionAPI {

/** The path of source file */
def exists: Boolean

def sourceFile: java.nio.file.Path

/** The start index in the source file */
Expand Down
3 changes: 2 additions & 1 deletion library/src/scala/tasty/reflect/SymbolOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ trait SymbolOps extends Core {
/** The full name of this symbol up to the root package. */
def fullName(implicit ctx: Context): String

/** Returns the context within this symbol. */
def pos(implicit ctx: Context): Position

def localContext(implicit ctx: Context): Context

/** Unsafe cast as to PackageSymbol. Use IsPackageSymbol to safly check and cast to PackageSymbol */
Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/reflect/TreeUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ trait TreeUtils
case TypeTree.Block(typedefs, tpt) => foldTypeTree(foldTrees(x, typedefs), tpt)
case TypeTree.MatchType(boundopt, selector, cases) =>
foldTypeCaseDefs(foldTypeTree(boundopt.fold(x)(foldTypeTree(x, _)), selector), cases)
case SyntheticBounds() => x
case TypeBoundsTree(lo, hi) => foldTypeTree(foldTypeTree(x, lo), hi)
}

Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ trait TypeOrBoundsTreeOps extends Core {
val TypeTree: TypeTreeModule
abstract class TypeTreeModule {


/** TypeTree containing an inferred type */
val Synthetic: SyntheticExtractor
abstract class SyntheticExtractor {
Expand Down
12 changes: 9 additions & 3 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ object Build {
baseDirectory in Test := baseDirectory.value / "..",
unmanagedSourceDirectories in Test += baseDirectory.value / "input" / "src" / "main" / "scala",
libraryDependencies ++= List(
("org.scalameta" %% "semanticdb" % "4.0.0" % Test).withDottyCompat(scalaVersion.value),
"com.novocode" % "junit-interface" % "0.11" % Test,
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" % Test
("org.scalameta" %% "semanticdb" % "4.0.0").withDottyCompat(scalaVersion.value),
"com.novocode" % "junit-interface" % "0.11",
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0"
)
)

Expand Down Expand Up @@ -919,6 +919,11 @@ object Build {
lazy val `dotty-bench-bootstrapped` = project.in(file("bench")).asDottyBench(Bootstrapped)

lazy val `dotty-semanticdb` = project.in(file("semanticdb")).asDottySemanticdb(Bootstrapped)
lazy val `dotty-semanticdb-input` = project.in(file("semanticdb/input")).settings(
scalaVersion := "2.12.7",
scalacOptions += "-Yrangepos",
addCompilerPlugin("org.scalameta" % "semanticdb-scalac" % "4.0.0" cross CrossVersion.full)
)

// Depend on dotty-library so that sbt projects using dotty automatically
// depend on the dotty-library
Expand Down Expand Up @@ -1317,6 +1322,7 @@ object Build {
enablePlugins(JmhPlugin)

def asDottySemanticdb(implicit mode: Mode): Project = project.withCommonSettings.
aggregate(`dotty-semanticdb-input`).
dependsOn(dottyCompiler).
settings(semanticdbSettings)

Expand Down
11 changes: 11 additions & 0 deletions semanticdb/input/src/main/scala/example/Access.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package example

class Access {
private def m1 = ???
private[this] def m2 = ???
private[Access] def m3 = ???
protected def m4 = ???
protected[this] def m5 = ???
protected[example] def m6 = ???
def m7 = ???
}
39 changes: 39 additions & 0 deletions semanticdb/input/src/main/scala/example/Advanced.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package example

import scala.language.existentials
import scala.language.higherKinds
import scala.language.reflectiveCalls

class AdvC[T] {
def t: T = ???
}

class Structural {
def s1: { val x: Int } = ???
def s2 = new { val x: Int = ??? }
def s3 = new { def m(x: Int): Int = ??? }
}

class Existential {
def e1: List[_] = ???
}

class AdvD[CC[B]] extends AdvC[CC[B]]

object AdvTest {
val s = new Structural
val s1 = s.s1
val s2 = s.s2
val s3 = s.s3

val e = new Existential
val e1 = e.e1
val e1x = e.e1.head
locally {
(??? : Any) match {
case e3: List[_] =>
val e3x = e3.head
()
}
}
}
18 changes: 18 additions & 0 deletions semanticdb/input/src/main/scala/example/Anonymous.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package example
import scala.language.higherKinds

class Anonymous {
this: Anonymous =>

def m1[T[_], B] = ???
def m2: Map[_, List[_]] = ???
locally {
??? match { case _: List[_] => }
}
locally {
val x: Int => Int = _ => ???
}

trait Foo
var x = new Foo {}
}
33 changes: 33 additions & 0 deletions semanticdb/input/src/main/scala/example/Classes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package example

class C1(val x1: Int) extends AnyVal

class C2(val x2: Int) extends AnyVal
object C2

case class C3(x: Int)

case class C4(x: Int)
object C4

object M {
implicit class C5(x: Int)
}

case class C6(private val x: Int)

class C7(x: Int)

class C8(private[this] val x: Int)

class C9(private[this] var x: Int)

object N {
val anonClass = new C7(42) {
val local = ???
}
val anonFun = List(1).map { i =>
val local = 2
local + 2
}
}
9 changes: 9 additions & 0 deletions semanticdb/input/src/main/scala/example/Empty.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example

class AdvA {
def b: AdvB = ???
}

class AdvB {
def a: AdvA = ???
}
3 changes: 3 additions & 0 deletions semanticdb/input/src/main/scala/example/EmptyObject.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package example

object EmptyObject {}
4 changes: 4 additions & 0 deletions semanticdb/input/src/main/scala/example/Example.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ class Example {
y
)
}

class ExampleInit() {

}
10 changes: 10 additions & 0 deletions semanticdb/input/src/main/scala/example/Example2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package example

import scala.concurrent.Future

object OExample { self =>
def main(args: Array[String]): Unit = {
println(1)
}
val x = scala.reflect.classTag[Int]
}
4 changes: 4 additions & 0 deletions semanticdb/input/src/main/scala/example/Exclude.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package example

// This class should be excluded by semanticdb.
class Exclude
24 changes: 24 additions & 0 deletions semanticdb/input/src/main/scala/example/Flags.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package example

package object p {
private lazy val x = 1
protected implicit var y: Int = 2
def z(pp: Int) = 3
def m[TT] = ???
abstract class C[+T, -U, V](x: T, y: U, z: V) {
def this() = this(???, ???, ???)
def w: Int
}
type T1 = Int
type T2[T] = S[T]
type U <: Int
type V >: Int
case object X
final class Y
sealed trait Z
class AA(x: Int, val y: Int, var z: Int)
class S[@specialized T]
val List(xs1) = ???
??? match { case List(xs2) => ??? }
??? match { case _: List[t] => ??? }
}
1 change: 1 addition & 0 deletions semanticdb/input/src/main/scala/example/Imports.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//import scala.util.control.NonFatal
11 changes: 11 additions & 0 deletions semanticdb/input/src/main/scala/example/Issue1749.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// See https://github.com/scalameta/scalameta/issues/1749
package example

import scala.math.Ordered.orderingToOrdered

class Issue1749 {
val x1 = 42
val x2 = 42
(x1, x1)
.compare((x2, x2))
}
8 changes: 8 additions & 0 deletions semanticdb/input/src/main/scala/example/Locals.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package example

object Test {
val xs = {
val x = 42
List(x)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package example

//@MacroAnnotation
class MacroAnnotations
object MacroAnnotations
33 changes: 33 additions & 0 deletions semanticdb/input/src/main/scala/example/MethodUsages.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package example

class MethodUsages {
val m = new Methods[Int]
m.m1
m.m2()
m.m3(0)
m.m4(0)(0)
m.m5("")
m.m5(0)
m.m6(0)
m.m6(new m.List[Int])
m.m6(Nil)
m.m7a(m, new m.List[Int])
m.m7b(new m.List[Int])
m.`m8().`()
m.m9(null)
m.m10(null)
m.m11(Predef)
m.m11(OExample)
m.m12a(null)
m.m12b(null)
m.m13(0)
m.m15(0)
m.m16(0)
m.m16(0)
m.m17.m()
m.m17(1)
m.m17("")
m.m18.m()
m.m18(1)
m.m18("")
}
38 changes: 38 additions & 0 deletions semanticdb/input/src/main/scala/example/Methods.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package example

import scala.math.Ordering
import scala.language.existentials

class Methods[T] {
class List[T]
type AList[T] = List[T]
def m1 = ???
def m2() = ???
def m3(x: Int) = ???
def m4(x: Int)(y: Int) = ???
def m5(x: String) = ???
def m5(x: Int) = ???
def m6(x: Int) = ???
def m6(x: List[T]) = ???
def m6(x: scala.List[T]) = ???
def m7a[U: Ordering](c: Methods[T], l: List[U]) = ???
def m7b[U <: T](l: List[U]) = ???
def `m8().`() = ???
class `m9().`
def m9(x: `m9().`) = ???
def m10(x: AList[T]) = ???
def m11(x: Predef.type) = ???
def m11(x: OExample.type) = ???
def m12a(x: {}) = ???
def m12b(x: { val x: Int }) = ???
def m13(x: Int @unchecked) = ???
def m15(x: => Int) = ???
def m16(x: Int*) = ???
object m17 { def m() = ??? }
def m17(a: Int) = ???
def m17(b: String) = ???
val m18 = m17
def m18(a: Int) = ???
def m18(b: String) = ???
def m19(x: Int, y: Int = 2)(z: Int = 3) = ???
}
5 changes: 5 additions & 0 deletions semanticdb/input/src/main/scala/example/Objects.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package example

object X {
object Y
}
4 changes: 4 additions & 0 deletions semanticdb/input/src/main/scala/example/Overrides.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package example

trait OveA { def foo: Int }
class OveB() extends OveA { def foo: Int = 2 }
Loading