Skip to content

Test semanticdb performance #13285

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private sealed trait XSettings:
val XverifySignatures: Setting[Boolean] = BooleanSetting("-Xverify-signatures", "Verify generic signatures in generated bytecode.")
val XignoreScala2Macros: Setting[Boolean] = BooleanSetting("-Xignore-scala2-macros", "Ignore errors when compiling code that calls Scala2 macros, these will fail at runtime.")
val XimportSuggestionTimeout: Setting[Int] = IntSetting("-Ximport-suggestion-timeout", "Timeout (in ms) for searching for import suggestions when errors are reported.", 8000)
val Xsemanticdb: Setting[Boolean] = BooleanSetting("-Xsemanticdb", "Store information in SemanticDB.", aliases = List("-Ysemanticdb"))
val Xsemanticdb: Setting[Boolean] = BooleanSetting("-Xsemanticdb", "Store information in SemanticDB.", aliases = List("-Ysemanticdb"), initialValue = true)
val Xtarget: Setting[String] = ChoiceSetting("-Xtarget", "target", "Emit bytecode for the specified version of the Java platform. This might produce bytecode that will break at runtime. When on JDK 9+, consider -release as a safer alternative.", ScalaSettings.supportedTargetVersions, "", aliases = List("--Xtarget"))
val XcheckMacros: Setting[Boolean] = BooleanSetting("-Xcheck-macros", "Check some invariants of macro generated code while expanding macros", aliases = List("--Xcheck-macros"))

Expand Down
25 changes: 25 additions & 0 deletions compiler/src/dotty/tools/dotc/semanticdb/ConstantOps.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dotty.tools
package dotc
package semanticdb

import dotty.tools.dotc.{semanticdb => s}

import core.Contexts.Context
import core.Constants._

object ConstantOps:
extension (const: Constant)
def toSemanticConst(using Context): s.Constant = const.tag match {
case UnitTag => s.UnitConstant()
case BooleanTag => s.BooleanConstant(const.booleanValue)
case ByteTag => s.ByteConstant(const.byteValue)
case ShortTag => s.ShortConstant(const.shortValue)
case CharTag => s.CharConstant(const.charValue)
case IntTag => s.IntConstant(const.intValue)
case LongTag => s.LongConstant(const.longValue)
case FloatTag => s.FloatConstant(const.floatValue)
case DoubleTag => s.DoubleConstant(const.doubleValue)
case StringTag => s.StringConstant(const.stringValue)
case NullTag => s.NullConstant()
case _ => throw new Error(s"Constant ${const} can't be converted to Semanticdb Constant.")
}
120 changes: 120 additions & 0 deletions compiler/src/dotty/tools/dotc/semanticdb/Descriptor.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package dotty.tools.dotc.semanticdb

import java.lang.System.{lineSeparator => EOL}
import dotty.tools.dotc.semanticdb.{Descriptor => d}

class DescriptorParser(s: String) {
var i = s.length
def fail() = {
val message = "invalid symbol format"
val caret = " " * i + "^"
sys.error(s"$message$EOL$s$EOL$caret")
}

val BOF = '\u0000'
val EOF = '\u001A'
var currChar = EOF
def readChar(): Char = {
if (i <= 0) {
if (i == 0) {
i -= 1
currChar = BOF
currChar
} else {
fail()
}
} else {
i -= 1
currChar = s(i)
currChar
}
}

def parseValue(): String = {
if (currChar == '`') {
val end = i
while (readChar() != '`') {}
readChar()
s.substring(i + 2, end)
} else {
val end = i + 1
if (!Character.isJavaIdentifierPart(currChar)) fail()
while (Character.isJavaIdentifierPart(readChar()) && currChar != BOF) {}
s.substring(i + 1, end)
}
}

def parseDisambiguator(): String = {
val end = i + 1
if (currChar != ')') fail()
while (readChar() != '(') {}
readChar()
s.substring(i + 1, end)
}

def parseDescriptor(): Descriptor = {
if (currChar == '.') {
readChar()
if (currChar == ')') {
val disambiguator = parseDisambiguator()
val value = parseValue()
d.Method(value, disambiguator)
} else {
d.Term(parseValue())
}
} else if (currChar == '#') {
readChar()
d.Type(parseValue())
} else if (currChar == '/') {
readChar()
d.Package(parseValue())
} else if (currChar == ')') {
readChar()
val value = parseValue()
if (currChar != '(') fail()
else readChar()
d.Parameter(value)
} else if (currChar == ']') {
readChar()
val value = parseValue()
if (currChar != '[') fail()
else readChar()
d.TypeParameter(value)
} else {
fail()
}
}

def entryPoint(): (Descriptor, String) = {
readChar()
val desc = parseDescriptor()
(desc, s.substring(0, i + 1))
}
}

object DescriptorParser {
def apply(symbol: String): (Descriptor, String) = {
val parser = new DescriptorParser(symbol)
parser.entryPoint()
}
}

sealed trait Descriptor {
def isNone: Boolean = this == d.None
def isTerm: Boolean = this.isInstanceOf[d.Term]
def isMethod: Boolean = this.isInstanceOf[d.Method]
def isType: Boolean = this.isInstanceOf[d.Type]
def isPackage: Boolean = this.isInstanceOf[d.Package]
def isParameter: Boolean = this.isInstanceOf[d.Parameter]
def isTypeParameter: Boolean = this.isInstanceOf[d.TypeParameter]
def value: String
}
object Descriptor {
case object None extends Descriptor { def value: String = "" }
final case class Term(value: String) extends Descriptor
final case class Method(value: String, disambiguator: String) extends Descriptor
final case class Type(value: String) extends Descriptor
final case class Package(value: String) extends Descriptor
final case class Parameter(value: String) extends Descriptor
final case class TypeParameter(value: String) extends Descriptor
}
Loading