From 753b3c485ad58df323cb781a41aac3b7564e61f3 Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Wed, 11 Aug 2021 15:37:05 +0900 Subject: [PATCH 1/9] Add implicit or context param apply to synthetics Support following synthetics - implicit and context parameters application - Anonymous context param name - Invented given Also convert TypeVar to stripped type, which may appear in synthetics --- .../dotc/semanticdb/ExtractSemanticDB.scala | 43 ++++-- .../dotty/tools/dotc/semanticdb/PPrint.scala | 125 ++++++++++++++++-- .../dotty/tools/dotc/semanticdb/Scala3.scala | 26 +++- .../dotc/semanticdb/SyntheticsExtractor.scala | 92 +++++++++++++ .../dotty/tools/dotc/semanticdb/Tools.scala | 23 ++-- .../dotty/tools/dotc/semanticdb/TypeOps.scala | 5 +- .../semanticdb/expect/Synthetic.expect.scala | 11 ++ tests/semanticdb/expect/Synthetic.scala | 11 ++ tests/semanticdb/metac.expect | 87 +++++++++++- 9 files changed, 385 insertions(+), 38 deletions(-) create mode 100644 compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index 3925ab2d4132..3d65a9a81c19 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -16,7 +16,6 @@ import NameOps._ import util.Spans.Span import util.{SourceFile, SourcePosition} import transform.SymUtils._ -import SymbolInformation.{Kind => k} import scala.jdk.CollectionConverters._ import scala.collection.mutable @@ -46,12 +45,13 @@ class ExtractSemanticDB extends Phase: val unit = ctx.compilationUnit val extractor = Extractor() extractor.extract(unit.tpdTree) - ExtractSemanticDB.write(unit.source, extractor.occurrences.toList, extractor.symbolInfos.toList) + ExtractSemanticDB.write(unit.source, extractor.occurrences.toList, extractor.symbolInfos.toList, extractor.synthetics.toList) /** Extractor of symbol occurrences from trees */ class Extractor extends TreeTraverser: - given s.SemanticSymbolBuilder = s.SemanticSymbolBuilder() - val converter = s.TypeOps() + given builder: s.SemanticSymbolBuilder = s.SemanticSymbolBuilder() + val synth = SyntheticsExtractor() + given converter: s.TypeOps = s.TypeOps() /** The bodies of synthetic locals */ private val localBodies = mutable.HashMap[Symbol, Tree]() @@ -62,6 +62,8 @@ class ExtractSemanticDB extends Phase: /** The extracted symbol infos */ val symbolInfos = new mutable.ListBuffer[SymbolInformation]() + val synthetics = new mutable.ListBuffer[s.Synthetic]() + /** A cache of localN names */ val localNames = new mutable.HashSet[String]() @@ -155,11 +157,22 @@ class ExtractSemanticDB extends Phase: tree match case tree: DefDef => tree.paramss.foreach(_.foreach(param => registerSymbolSimple(param.symbol))) - case tree: ValDef if tree.symbol.is(Given) => traverse(tree.tpt) + case tree: ValDef if tree.symbol.is(Given) => + synth.tryFindSynthetic(tree).foreach { synth => + synthetics += synth + } + traverse(tree.tpt) case _ => if !tree.symbol.isGlobal then localBodies(tree.symbol) = tree.rhs // ignore rhs + + // `given Int` (syntax sugar of `given given_Int: Int`) + case tree: ValDef if tree.symbol.isInventedGiven => + synth.tryFindSynthetic(tree).foreach { synth => + synthetics += synth + } + traverse(tree.tpt) case PatternValDef(pat, rhs) => traverse(rhs) PatternValDef.collectPats(pat).foreach(traverse) @@ -192,6 +205,10 @@ class ExtractSemanticDB extends Phase: case tree: Apply => @tu lazy val genParamSymbol: Name => String = tree.fun.symbol.funParamSymbol traverse(tree.fun) + synth.tryFindSynthetic(tree).foreach { synth => + synthetics += synth + } + for arg <- tree.args do arg match case tree @ NamedArg(name, arg) => @@ -277,12 +294,6 @@ class ExtractSemanticDB extends Phase: end PatternValDef - private def range(span: Span, treeSource: SourceFile)(using Context): Option[Range] = - def lineCol(offset: Int) = (treeSource.offsetToLine(offset), treeSource.column(offset)) - val (startLine, startCol) = lineCol(span.start) - val (endLine, endCol) = lineCol(span.end) - Some(Range(startLine, startCol, endLine, endCol)) - private def registerSymbol(sym: Symbol, symkinds: Set[SymbolKind])(using Context): Unit = val sname = sym.symbolName @@ -448,7 +459,12 @@ object ExtractSemanticDB: val name: String = "extractSemanticDB" - def write(source: SourceFile, occurrences: List[SymbolOccurrence], symbolInfos: List[SymbolInformation])(using Context): Unit = + def write( + source: SourceFile, + occurrences: List[SymbolOccurrence], + symbolInfos: List[SymbolInformation], + synthetics: List[Synthetic], + )(using Context): Unit = def absolutePath(path: Path): Path = path.toAbsolutePath.normalize val semanticdbTarget = val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value @@ -470,7 +486,8 @@ object ExtractSemanticDB: text = "", md5 = internal.MD5.compute(String(source.content)), symbols = symbolInfos, - occurrences = occurrences + occurrences = occurrences, + synthetics = synthetics, ) val docs = TextDocuments(List(doc)) val out = Files.newOutputStream(outpath) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/PPrint.scala b/compiler/src/dotty/tools/dotc/semanticdb/PPrint.scala index 48ff5d885187..03fd0175c4f3 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/PPrint.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/PPrint.scala @@ -5,8 +5,8 @@ import dotty.tools.dotc.{semanticdb => s} import scala.collection.mutable import dotty.tools.dotc.semanticdb.Scala3.{_, given} import SymbolInformation.Kind._ - -class SymbolInfomationPrinter (symtab: PrinterSymtab): +import dotty.tools.dotc.util.SourceFile +class SymbolInformationPrinter (symtab: PrinterSymtab): val notes = InfoNotes() val infoPrinter = InfoPrinter(notes) @@ -28,8 +28,9 @@ class SymbolInfomationPrinter (symtab: PrinterSymtab): val displayName = if sym.isGlobal then sym.desc.value else sym SymbolInformation(symbol = sym, displayName = displayName) } + end InfoNotes - class InfoPrinter(notes: InfoNotes) { + class InfoPrinter(notes: InfoNotes): private enum SymbolStyle: case Reference, Definition def pprint(info: SymbolInformation): String = @@ -78,7 +79,7 @@ class SymbolInfomationPrinter (symtab: PrinterSymtab): private def pprintDef(info: SymbolInformation) = notes.enter(info) pprint(info.symbol, SymbolStyle.Definition) - private def pprintRef(sym: String): String = pprint(sym, SymbolStyle.Reference) + def pprintRef(sym: String): String = pprint(sym, SymbolStyle.Reference) private def pprintDef(sym: String): String = pprint(sym, SymbolStyle.Definition) private def pprint(sym: String, style: SymbolStyle): String = val info = notes.visit(sym) @@ -134,7 +135,7 @@ class SymbolInfomationPrinter (symtab: PrinterSymtab): case _ => "" - private def pprint(tpe: Type): String = { + protected def pprint(tpe: Type): String = { def prefix(tpe: Type): String = tpe match case TypeRef(pre, sym, args) => val preStr = pre match { @@ -201,7 +202,7 @@ class SymbolInfomationPrinter (symtab: PrinterSymtab): case tpe => s"@${pprint(tpe)}" } - private def pprint(const: Constant): String = const match { + protected def pprint(const: Constant): String = const match { case Constant.Empty => "" case UnitConstant() => @@ -242,7 +243,6 @@ class SymbolInfomationPrinter (symtab: PrinterSymtab): s"private[${ssym}] " case ProtectedWithinAccess(ssym) => s"protected[${ssym}] " - extension (scope: Scope) private def infos: List[SymbolInformation] = if (scope.symlinks.nonEmpty) @@ -255,8 +255,8 @@ class SymbolInfomationPrinter (symtab: PrinterSymtab): case Some(s) => s.infos case None => Nil } - } -end SymbolInfomationPrinter + end InfoPrinter +end SymbolInformationPrinter extension (info: SymbolInformation) def prefixBeforeTpe: String = { @@ -277,3 +277,110 @@ object PrinterSymtab: new PrinterSymtab { override def info(symbol: String): Option[SymbolInformation] = map.get(symbol) } + +def processRange(sb: StringBuilder, range: Range): Unit = + sb.append('[') + .append(range.startLine).append(':').append(range.startCharacter) + .append("..") + .append(range.endLine).append(':').append(range.endCharacter) + .append("):") + + + +class SyntheticPrinter(symtab: PrinterSymtab, source: SourceFile) extends SymbolInformationPrinter(symtab): + + def pprint(synth: Synthetic): String = + val sb = new StringBuilder() + val notes = InfoNotes() + val treePrinter = TreePrinter(source, synth.range, notes) + + synth.range match + case Some(range) => + processRange(sb, range) + sb.append(source.substring(range)) + case None => + sb.append("[):") + sb.append(" => ") + sb.append(treePrinter.pprint(synth.tree)) + sb.toString + + extension (source: SourceFile) + private def substring(range: Option[s.Range]): String = + range match + case Some(range) => source.substring(range) + case None => "" + private def substring(range: s.Range): String = + /** get the line length of a given line */ + def lineLength(line: Int): Int = + val isLastLine = source.lineToOffsetOpt(line).nonEmpty && source.lineToOffsetOpt(line + 1).isEmpty + if isLastLine then source.content.length - source.lineToOffset(line) - 1 + else source.lineToOffset(line + 1) - source.lineToOffset(line) - 1 // -1 for newline char + + val start = source.lineToOffset(range.startLine) + + math.min(range.startCharacter, lineLength(range.startLine)) + val end = source.lineToOffset(range.endLine) + + math.min(range.endCharacter, lineLength(range.endLine)) + new String(source.content, start, end - start) + + + // def pprint(tree: s.Tree, range: Option[Range]): String = + class TreePrinter(source: SourceFile, originalRange: Option[Range], notes: InfoNotes) extends InfoPrinter(notes): + def pprint(tree: Tree): String = + val sb = new StringBuilder() + processTree(tree)(using sb) + sb.toString + + + private def rep[T](xs: Seq[T], seq: String)(f: T => Unit)(using sb: StringBuilder): Unit = + xs.zipWithIndex.foreach { (x, i) => + if i != 0 then sb.append(seq) + f(x) + } + + private def processTree(tree: Tree)(using sb: StringBuilder): Unit = + tree match { + case tree: ApplyTree => + processTree(tree.function) + sb.append("(") + rep(tree.arguments, ", ")(processTree) + sb.append(")") + case tree: FunctionTree => + sb.append("{") + sb.append("(") + rep(tree.parameters, ", ")(processTree) + sb.append(") =>") + processTree(tree.body) + sb.append("}") + case tree: IdTree => + sb.append(pprintRef(tree.symbol)) + case tree: LiteralTree => + sb.append(pprint(tree.constant)) + case tree: MacroExpansionTree => + sb.append("(`macro-expandee` : `") + sb.append(pprint(tree.tpe)) + sb.append(")") + case tree: OriginalTree => + if (tree.range == originalRange && originalRange.nonEmpty) then + sb.append("*") + else + sb.append("orig(") + sb.append(source.substring(tree.range)) + sb.append(")") + case tree: SelectTree => + processTree(tree.qualifier) + sb.append(".") + tree.id match + case Some(tree) => processTree(tree) + case None => () + case tree: TypeApplyTree => + processTree(tree.function) + sb.append("[") + rep(tree.typeArguments, ", ")((t) => sb.append(pprint(t))) + sb.append("]") + + case _ => + sb.append("") + } + + +end SyntheticPrinter diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala index 6ca728616cda..81275a87a4ef 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala @@ -10,6 +10,10 @@ import core.Flags._ import core.NameKinds import core.StdNames.nme import SymbolInformation.{Kind => k} +import dotty.tools.dotc.util.SourceFile +import dotty.tools.dotc.util.Spans.Span +import dotty.tools.dotc.ast.tpd +import dotty.tools.dotc.{semanticdb => s} import java.lang.Character.{isJavaIdentifierPart, isJavaIdentifierStart} @@ -26,6 +30,12 @@ object Scala3: private val WILDCARDTypeName = nme.WILDCARD.toTypeName + def range(span: Span, treeSource: SourceFile)(using Context): Option[Range] = + def lineCol(offset: Int) = (treeSource.offsetToLine(offset), treeSource.column(offset)) + val (startLine, startCol) = lineCol(span.start) + val (endLine, endCol) = lineCol(span.end) + Some(Range(startLine, startCol, endLine, endCol)) + sealed trait FakeSymbol { private[Scala3] var sname: Option[String] = None } @@ -220,6 +230,12 @@ object Scala3: def isSyntheticWithIdent(using Context): Boolean = sym.is(Synthetic) && !sym.isAnonymous && !sym.name.isEmptyNumbered + /** 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(using Context): Boolean = + sym.is(Given) && sym.name.startsWith("given_") + /** The semanticdb name of the given symbol */ def symbolName(using builder: SemanticSymbolBuilder)(using Context): String = builder.symbolName(sym) @@ -419,9 +435,7 @@ object Scala3: def hasLength = range.endLine > range.startLine || range.endCharacter > range.startCharacter end RangeOps - /** Sort symbol occurrences by their start position. */ - given OccurrenceOrdering: Ordering[SymbolOccurrence] = (x, y) => - x.range -> y.range match + private def compareRange(x: Option[Range], y: Option[Range]): Int = x -> y match case None -> _ | _ -> None => 0 case Some(a) -> Some(b) => val byLine = Integer.compare(a.startLine, b.startLine) @@ -429,10 +443,14 @@ object Scala3: byLine else // byCharacter Integer.compare(a.startCharacter, b.startCharacter) - end OccurrenceOrdering + + /** Sort symbol occurrences by their start position. */ + given Ordering[SymbolOccurrence] = (x, y) => compareRange(x.range, y.range) given Ordering[SymbolInformation] = Ordering.by[SymbolInformation, String](_.symbol)(IdentifierOrdering()) + given Ordering[Synthetic] = (x, y) => compareRange(x.range, y.range) + /** * A comparator for identifier like "Predef" or "Function10". * diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala new file mode 100644 index 000000000000..ccc33aba63f9 --- /dev/null +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -0,0 +1,92 @@ +package dotty.tools.dotc.semanticdb + +import dotty.tools.dotc.ast.tpd._ +import dotty.tools.dotc.core.Contexts._ +import dotty.tools.dotc.core.Flags._ +import dotty.tools.dotc.core.StdNames.nme +import dotty.tools.dotc.{semanticdb => s} + +import scala.collection.mutable + +class SyntheticsExtractor: + import Scala3.{_, given} + + def tryFindSynthetic(tree: Tree)(using Context, SemanticSymbolBuilder, TypeOps): Option[s.Synthetic] = + extension (synth: s.Synthetic) + def toOpt: Some[s.Synthetic] = Some(synth) + + if tree.span.isSynthetic || tree.symbol.isInventedGiven then + tree match + case tree: Apply if isForSynthetic(tree) => + None // not yet supported (for synthetics) + case tree: Apply + if tree.args.nonEmpty && + tree.args.forall(arg => + arg.symbol.isOneOf(GivenOrImplicit) && + arg.span.isSynthetic + ) => + s.Synthetic( + range(tree.span, tree.source), + s.ApplyTree( + tree.fun.toSemanticOriginal, + tree.args.map(_.toSemanticTree) + ) + ).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 + + private given TreeOps: AnyRef with + extension (tree: Tree) + def toSemanticTree(using Context, SemanticSymbolBuilder, TypeOps): s.Tree = + tree match + case tree: Apply => + s.ApplyTree( + tree.fun.toSemanticQualifierTree, + tree.args.map(_.toSemanticTree) + ) + case tree: TypeApply => + s.TypeApplyTree( + tree.fun.toSemanticQualifierTree, + tree.args.map { targ => + targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren) + } + ) + case tree: Ident => tree.toSemanticId + case tree: Select => tree.toSemanticId + case _ => s.Tree.defaultInstance + + def toSemanticQualifierTree(using Context, SemanticSymbolBuilder): s.Tree = tree match + case sel @ Select(qual, _) if sel.symbol.owner != qual.symbol => + s.SelectTree(qual.toSemanticId, Some(sel.toSemanticId)) + case fun => fun.toSemanticId + + def toSemanticId(using Context, SemanticSymbolBuilder) = + s.IdTree(tree.symbol.symbolName) + + def toSemanticOriginal(using Context) = + s.OriginalTree(range(tree.span, tree.source)) + end TreeOps + + + private def isForSynthetic(tree: Tree): Boolean = + def isForComprehensionSyntheticName(select: Select): Boolean = + select.span.toSynthetic == select.qualifier.span.toSynthetic && ( + select.name == nme.map || + select.name == nme.flatMap || + select.name == nme.withFilter || + select.name == nme.foreach + ) + tree match + case Apply(fun, _) => isForSynthetic(fun) + case TypeApply(fun, _) => isForSynthetic(fun) + case select: Select => isForComprehensionSyntheticName(select) + case _ => false + +end SyntheticsExtractor diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala b/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala index a7bfdcefc047..45965b5ebb90 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala @@ -48,9 +48,10 @@ object Tools: def metac(doc: TextDocument, realPath: Path)(using sb: StringBuilder): StringBuilder = val symtab = PrinterSymtab.fromTextDocument(doc) - val symPrinter = SymbolInfomationPrinter(symtab) + val symPrinter = SymbolInformationPrinter(symtab) val realURI = realPath.toString - given SourceFile = SourceFile.virtual(doc.uri, doc.text) + given sourceFile: SourceFile = SourceFile.virtual(doc.uri, doc.text) + val synthPrinter = SyntheticPrinter(symtab, sourceFile) sb.append(realURI).nl sb.append("-" * realURI.length).nl sb.nl @@ -61,6 +62,8 @@ object Tools: sb.append("Language => ").append(languageString(doc.language)).nl sb.append("Symbols => ").append(doc.symbols.length).append(" entries").nl sb.append("Occurrences => ").append(doc.occurrences.length).append(" entries").nl + if doc.synthetics.nonEmpty then + sb.append("Synthetics => ").append(doc.synthetics.length).append(" entries").nl sb.nl sb.append("Symbols:").nl doc.symbols.sorted.foreach(s => processSymbol(s, symPrinter)) @@ -68,6 +71,11 @@ object Tools: sb.append("Occurrences:").nl doc.occurrences.sorted.foreach(processOccurrence) sb.nl + if doc.synthetics.nonEmpty then + sb.append("Synthetics:").nl + doc.synthetics.sorted.foreach(s => processSynth(s, synthPrinter)) + sb.nl + sb end metac private def schemaString(schema: Schema) = @@ -87,17 +95,16 @@ object Tools: case UNKNOWN_LANGUAGE | Unrecognized(_) => "unknown" end languageString - private def processSymbol(info: SymbolInformation, printer: SymbolInfomationPrinter)(using sb: StringBuilder): Unit = + private def processSymbol(info: SymbolInformation, printer: SymbolInformationPrinter)(using sb: StringBuilder): Unit = sb.append(printer.pprintSymbolInformation(info)).nl + private def processSynth(synth: Synthetic, printer: SyntheticPrinter)(using sb: StringBuilder): Unit = + sb.append(printer.pprint(synth)).nl + private def processOccurrence(occ: SymbolOccurrence)(using sb: StringBuilder, sourceFile: SourceFile): Unit = occ.range match case Some(range) => - sb.append('[') - .append(range.startLine).append(':').append(range.startCharacter) - .append("..") - .append(range.endLine).append(':').append(range.endCharacter) - .append("):") + processRange(sb, range) if range.endLine == range.startLine && range.startCharacter != range.endCharacter && !(occ.symbol.isConstructor && occ.role.isDefinition) then diff --git a/compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala b/compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala index b71327b4c28a..963a153388a3 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala @@ -215,7 +215,7 @@ class TypeOps: } loop(tpe) - private def toSemanticType(sym: Symbol)(using LinkMode, SemanticSymbolBuilder, Context): s.Type = + def toSemanticType(sym: Symbol)(using LinkMode, SemanticSymbolBuilder, Context): s.Type = import ConstantOps._ def loop(tpe: Type): s.Type = tpe match { case t if t.isFromJavaObject => @@ -409,6 +409,9 @@ class TypeOps: case _: MatchType => s.Type.Empty + case tvar: TypeVar => + loop(tvar.stripped) + case _ => s.Type.Empty } diff --git a/tests/semanticdb/expect/Synthetic.expect.scala b/tests/semanticdb/expect/Synthetic.expect.scala index 271d3013c0ae..b6b14fe6de81 100644 --- a/tests/semanticdb/expect/Synthetic.expect.scala +++ b/tests/semanticdb/expect/Synthetic.expect.scala @@ -47,4 +47,15 @@ class Synthetic/*<-example::Synthetic#*/ { if a/*->local8*/ scala::Int#`<`(+3).*/ b/*->local9*/ } yield a/*->local8*/ + object Contexts/*<-example::Synthetic#Contexts.*/ { + def foo/*<-example::Synthetic#Contexts.foo().*/(x/*<-example::Synthetic#Contexts.foo().(x)*/: Int/*->scala::Int#*/)(using Int/*->scala::Int#*/) = ???/*->scala::Predef.`???`().*/ + def m1/*<-example::Synthetic#Contexts.m1().*/(using Int/*->scala::Int#*/) = foo/*->example::Synthetic#Contexts.foo().*/(0) + def m2/*<-example::Synthetic#Contexts.m2().*/(using x/*<-example::Synthetic#Contexts.m2().(x)*/: Int/*->scala::Int#*/) = foo/*->example::Synthetic#Contexts.foo().*/(0) + def m3/*<-example::Synthetic#Contexts.m3().*/ = + given x/*<-local10*/: Int/*->scala::Int#*/ = 1 + foo/*->example::Synthetic#Contexts.foo().*/(x/*->local10*/) + def m4/*<-example::Synthetic#Contexts.m4().*/ = + given Int/*->scala::Int#*/ = 1 + foo/*->example::Synthetic#Contexts.foo().*/(0) + } } diff --git a/tests/semanticdb/expect/Synthetic.scala b/tests/semanticdb/expect/Synthetic.scala index 484e07098877..10d13e936468 100644 --- a/tests/semanticdb/expect/Synthetic.scala +++ b/tests/semanticdb/expect/Synthetic.scala @@ -47,4 +47,15 @@ class Synthetic { if a < b } yield a + object Contexts { + def foo(x: Int)(using Int) = ??? + def m1(using Int) = foo(0) + def m2(using x: Int) = foo(0) + def m3 = + given x: Int = 1 + foo(x) + def m4 = + given Int = 1 + foo(0) + } } diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 7c431ae29972..fd5b1ee2f81b 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -356,6 +356,7 @@ 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 } @@ -370,6 +371,9 @@ 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 -------------------- @@ -1222,6 +1226,7 @@ Text => empty Language => Scala Symbols => 26 entries Occurrences => 50 entries +Synthetics => 2 entries Symbols: ext/Extension$package. => final package object ext extends Object { self: ext.type => +6 decls } @@ -1303,6 +1308,10 @@ Occurrences: [17:48..17:49): F -> ext/Functor#[F] [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 ----------------------------- @@ -1679,6 +1688,7 @@ Text => empty Language => Scala Symbols => 45 entries Occurrences => 61 entries +Synthetics => 7 entries Symbols: givens/InventedNames$package. => final package object givens extends Object { self: givens.type => +24 decls } @@ -1790,6 +1800,15 @@ Occurrences: [41:8..41:17): given_Z_T -> givens/InventedNames$package.given_Z_T(). [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 +[17:0..17:28):given given_Char: Char = '?' => given_Char +[18:0..18:32):given `given_Float`: Float = 3.0 => given_Float +[24:13..24:14):X => x$1 +[34:8..34:20):given_Double => *(intValue) +[40:8..40:15):given_Y => *(given_X) + expect/Issue1749.scala ---------------------- @@ -1800,6 +1819,7 @@ Text => empty Language => Scala Symbols => 7 entries Occurrences => 22 entries +Synthetics => 2 entries Symbols: example/Issue1749# => class Issue1749 extends Object { self: Issue1749 => +3 decls } @@ -1834,6 +1854,10 @@ Occurrences: [13:49..13:55): String -> scala/Predef.String# [14:2..14:5): map -> example/Issue1854#map. +Synthetics: +[8:2..8:10):(x1, x1) => *(Tuple2(Int, Int)) +[8:10..8:10): => *(Int, Int) + expect/Local.scala ------------------ @@ -1986,6 +2010,7 @@ Text => empty Language => Scala Symbols => 3 entries Occurrences => 80 entries +Synthetics => 1 entries Symbols: example/MethodUsages# => class MethodUsages extends Object { self: MethodUsages => +2 decls } @@ -2074,6 +2099,9 @@ Occurrences: [34:4..34:7): m20 -> example/Methods#m20(+2). [34:8..34:9): m -> example/Methods#m17.m(). +Synthetics: +[13:2..13:26):m.m7(m, new m.List[Int]) => *(Int) + expect/Methods.scala -------------------- @@ -2647,6 +2675,7 @@ Text => empty Language => Scala Symbols => 65 entries Occurrences => 103 entries +Synthetics => 1 entries Symbols: example/C# => class C extends Object { self: C => +3 decls } @@ -2820,6 +2849,9 @@ Occurrences: [32:49..32:56): pickOne -> example/SpecialRefinement#pickOne(). [32:57..32:59): as -> example/PickOneRefinement_1#run().(as) +Synthetics: +[15:23..15:34):elems.toMap => *(refl[Tuple2[String, Any]]) + expect/RightAssociativeExtension.scala -------------------------------------- @@ -2905,11 +2937,22 @@ Schema => SemanticDB v4 Uri => Synthetic.scala Text => empty Language => Scala -Symbols => 40 entries -Occurrences => 112 entries +Symbols => 52 entries +Occurrences => 133 entries +Synthetics => 9 entries Symbols: -example/Synthetic# => class Synthetic extends Object { self: Synthetic => +21 decls } +example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls } +example/Synthetic#Contexts. => final object Contexts extends Object { self: Contexts.type => +6 decls } +example/Synthetic#Contexts.foo(). => method foo (param x: Int)(implicit given param x$2: Int): Nothing +example/Synthetic#Contexts.foo().(x$2) => implicit given param x$2: Int +example/Synthetic#Contexts.foo().(x) => param x: Int +example/Synthetic#Contexts.m1(). => method m1 (implicit given param x$1: Int): Nothing +example/Synthetic#Contexts.m1().(x$1) => implicit given param x$1: Int +example/Synthetic#Contexts.m2(). => method m2 (implicit given param x: Int): Nothing +example/Synthetic#Contexts.m2().(x) => implicit given param x: Int +example/Synthetic#Contexts.m3(). => method m3 => Nothing +example/Synthetic#Contexts.m4(). => method m4 => Nothing example/Synthetic#F# => class F extends Object { self: F => +1 decls } example/Synthetic#F#``(). => primary ctor (): F example/Synthetic#J# => class J [typeparam T ] extends Object { self: J[T] => +4 decls } @@ -2949,6 +2992,8 @@ local6 => param a: Int local7 => param b: Int local8 => param a: Int local9 => param b: Int +local10 => final implicit lazy val given local x: Int +local11 => final implicit lazy val given local given_Int: Int Occurrences: [0:8..0:15): example <- example/ @@ -3063,6 +3108,38 @@ Occurrences: [46:9..46:10): < -> scala/Int#`<`(+3). [46:11..46:12): b -> local9 [47:10..47:11): a -> local8 +[49:9..49:17): Contexts <- example/Synthetic#Contexts. +[50:8..50:11): foo <- example/Synthetic#Contexts.foo(). +[50:12..50:13): x <- example/Synthetic#Contexts.foo().(x) +[50:15..50:18): Int -> scala/Int# +[50:26..50:29): Int -> scala/Int# +[50:33..50:36): ??? -> scala/Predef.`???`(). +[51:8..51:10): m1 <- example/Synthetic#Contexts.m1(). +[51:17..51:20): Int -> scala/Int# +[51:24..51:27): foo -> example/Synthetic#Contexts.foo(). +[52:8..52:10): m2 <- example/Synthetic#Contexts.m2(). +[52:17..52:18): x <- example/Synthetic#Contexts.m2().(x) +[52:20..52:23): Int -> scala/Int# +[52:27..52:30): foo -> example/Synthetic#Contexts.foo(). +[53:8..53:10): m3 <- example/Synthetic#Contexts.m3(). +[54:12..54:13): x <- local10 +[54:15..54:18): Int -> scala/Int# +[55:6..55:9): foo -> example/Synthetic#Contexts.foo(). +[55:10..55:11): x -> local10 +[56:8..56:10): m4 <- example/Synthetic#Contexts.m4(). +[57:12..57:15): Int -> scala/Int# +[58:6..58:9): foo -> example/Synthetic#Contexts.foo(). + +Synthetics: +[32:35..32:49):Array.empty[T] => *(evidence$1) +[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 ------------------- @@ -4472,6 +4549,7 @@ Text => empty Language => Scala Symbols => 19 entries Occurrences => 34 entries +Synthetics => 1 entries Symbols: _empty_/MyProgram# => final class MyProgram extends Object { self: MyProgram => +2 decls } @@ -4530,3 +4608,6 @@ Occurrences: [6:4..6:10): fooRef <- _empty_/toplevel$package.fooRef(). [6:30..6:33): foo -> _empty_/toplevel$package.foo(). +Synthetics: +[5:0..5:0): => *(given_FromString_Int) + From d1a0eacd01facce51dced6206f76fc787f4ebbcd Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Wed, 11 Aug 2021 20:01:20 +0900 Subject: [PATCH 2/9] Support implicit conversion for Synthetics --- .../dotc/semanticdb/SyntheticsExtractor.scala | 12 ++++++ tests/semanticdb/metac.expect | 40 +++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala index ccc33aba63f9..6753e7ba01a7 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -33,6 +33,18 @@ class SyntheticsExtractor: ) ).toOpt + case tree: Apply if tree.fun.symbol.is(Implicit) => + val pos = range(tree.span, tree.source) + s.Synthetic( + pos, + s.ApplyTree( + tree.fun.toSemanticTree, + arguments = List( + s.OriginalTree(pos) + ) + ) + ).toOpt + // Anonymous context parameter case tree: ValDef if tree.symbol.is(Given) => s.Synthetic( diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index fd5b1ee2f81b..0bdab175dc43 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -50,6 +50,7 @@ Text => empty Language => Scala Symbols => 46 entries Occurrences => 101 entries +Synthetics => 3 entries Symbols: advanced/C# => class C [typeparam T ] extends Object { self: C[T] => +3 decls } @@ -202,6 +203,11 @@ Occurrences: [48:37..48:38): x -> advanced/HKClass#foo().(x) [48:39..48:47): toString -> scala/Tuple2#toString(). +Synthetics: +[26:12..26:16):s.s1 => reflectiveSelectable(*) +[28:12..28:16):s.s2 => reflectiveSelectable(*) +[30:12..30:16):s.s3 => reflectiveSelectable(*) + expect/Annotations.scala ------------------------ @@ -1508,6 +1514,7 @@ Text => empty Language => Scala Symbols => 23 entries Occurrences => 48 entries +Synthetics => 6 entries Symbols: example/ImplicitConversion# => class ImplicitConversion extends Object { self: ImplicitConversion => +9 decls } @@ -1584,6 +1591,16 @@ Occurrences: [34:56..34:57): + -> java/lang/String#`+`(). [34:58..34:63): other -> example/ImplicitConversion.newAny2stringadd#`+`().(other) +Synthetics: +[15:2..15:9):message => augmentString(*) +[17:2..17:7):tuple => newAny2stringadd[Tuple2[Int, Int]](*) +[20:15..20:22):message => string2Number(*) +[24:2..26:16):s"""Hello + |$message + |$number""" => augmentString(*) +[28:15..28:19):char => char2int(*) +[29:16..29:20):char => char2long(*) + expect/Imports.scala -------------------- @@ -1819,7 +1836,7 @@ Text => empty Language => Scala Symbols => 7 entries Occurrences => 22 entries -Synthetics => 2 entries +Synthetics => 3 entries Symbols: example/Issue1749# => class Issue1749 extends Object { self: Issue1749 => +3 decls } @@ -1855,6 +1872,7 @@ Occurrences: [14:2..14:5): map -> example/Issue1854#map. Synthetics: +[8:2..8:10):(x1, x1) => orderingToOrdered[Tuple2[Int, Int]](*) [8:2..8:10):(x1, x1) => *(Tuple2(Int, Int)) [8:10..8:10): => *(Int, Int) @@ -2939,7 +2957,7 @@ Text => empty Language => Scala Symbols => 52 entries Occurrences => 133 entries -Synthetics => 9 entries +Synthetics => 24 entries Symbols: example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls } @@ -3131,7 +3149,22 @@ Occurrences: [58:6..58:9): foo -> example/Synthetic#Contexts.foo(). Synthetics: +[6:2..6:18):Array.empty[Int] => intArrayOps(*) +[7:2..7:8):"fooo" => augmentString(*) +[10:13..10:24):"name:(.*)" => augmentString(*) +[13:8..13:28):2 #:: LazyList.empty => toDeferrer[Int](*) +[13:14..13:28):LazyList.empty => toDeferrer[Nothing](*) +[17:18..17:38):2 #:: LazyList.empty => toDeferrer[Int](*) +[17:24..17:38):LazyList.empty => toDeferrer[Nothing](*) +[19:12..19:13):1 => intWrapper(*) +[19:26..19:27):0 => intWrapper(*) +[19:46..19:47):x => ArrowAssoc[Int](*) +[20:12..20:13):1 => intWrapper(*) +[20:26..20:27):0 => intWrapper(*) +[21:12..21:13):1 => intWrapper(*) +[21:26..21:27):0 => intWrapper(*) [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 @@ -4549,7 +4582,7 @@ Text => empty Language => Scala Symbols => 19 entries Occurrences => 34 entries -Synthetics => 1 entries +Synthetics => 2 entries Symbols: _empty_/MyProgram# => final class MyProgram extends Object { self: MyProgram => +2 decls } @@ -4610,4 +4643,5 @@ Occurrences: Synthetics: [5:0..5:0): => *(given_FromString_Int) +[5:41..5:42):1 => intWrapper(*) From d2fd229490b558ff48f5b7c0ae6462d72d55b2af Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Fri, 13 Aug 2021 03:13:49 +0900 Subject: [PATCH 3/9] Exclude named given from synthetics (when name starts with `given_`) --- .../dotc/semanticdb/ExtractSemanticDB.scala | 28 +++------------ .../dotty/tools/dotc/semanticdb/Scala3.scala | 36 +++++++++++++++---- .../dotc/semanticdb/SyntheticsExtractor.scala | 2 +- tests/semanticdb/metac.expect | 4 +-- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index 3d65a9a81c19..43b37bd5195e 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -168,11 +168,11 @@ class ExtractSemanticDB extends Phase: // ignore rhs // `given Int` (syntax sugar of `given given_Int: Int`) - case tree: ValDef if tree.symbol.isInventedGiven => - synth.tryFindSynthetic(tree).foreach { synth => - synthetics += synth - } - traverse(tree.tpt) + case tree: ValDef if isInventedGiven(tree) => + synth.tryFindSynthetic(tree).foreach { synth => + synthetics += synth + } + traverse(tree.tpt) case PatternValDef(pat, rhs) => traverse(rhs) PatternValDef.collectPats(pat).foreach(traverse) @@ -334,24 +334,6 @@ class ExtractSemanticDB extends Phase: if !sym.is(Package) then registerSymbol(sym, symkinds) - private def namePresentInSource(sym: Symbol, span: Span, source:SourceFile)(using Context): Boolean = - if !span.exists then false - else - val content = source.content() - val (start, end) = - if content.lift(span.end - 1).exists(_ == '`') then - (span.start + 1, span.end - 1) - else (span.start, span.end) - val nameInSource = content.slice(start, end).mkString - // for secondary constructors `this` - if sym.isConstructor && nameInSource == nme.THISkw.toString then - true - else - val target = - if sym.isPackageObject then sym.owner - else sym - nameInSource == target.name.stripModuleClassSuffix.lastPart.toString - private def spanOfSymbol(sym: Symbol, span: Span, treeSource: SourceFile)(using Context): Span = val contents = if treeSource.exists then treeSource.content() else Array.empty[Char] val idx = contents.indexOfSlice(sym.name.show, span.start) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala index 81275a87a4ef..3786d91312cc 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala @@ -36,6 +36,24 @@ object Scala3: val (endLine, endCol) = lineCol(span.end) Some(Range(startLine, startCol, endLine, endCol)) + def namePresentInSource(sym: Symbol, span: Span, source:SourceFile)(using Context): Boolean = + if !span.exists then false + else + val content = source.content() + val (start, end) = + if content.lift(span.end - 1).exists(_ == '`') then + (span.start + 1, span.end - 1) + else (span.start, span.end) + val nameInSource = content.slice(start, end).mkString + // for secondary constructors `this` + if sym.isConstructor && nameInSource == nme.THISkw.toString then + true + else + val target = + if sym.isPackageObject then sym.owner + else sym + nameInSource == target.name.stripModuleClassSuffix.lastPart.toString + sealed trait FakeSymbol { private[Scala3] var sname: Option[String] = None } @@ -230,12 +248,6 @@ object Scala3: def isSyntheticWithIdent(using Context): Boolean = sym.is(Synthetic) && !sym.isAnonymous && !sym.name.isEmptyNumbered - /** 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(using Context): Boolean = - sym.is(Given) && sym.name.startsWith("given_") - /** The semanticdb name of the given symbol */ def symbolName(using builder: SemanticSymbolBuilder)(using Context): String = builder.symbolName(sym) @@ -498,4 +510,16 @@ 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 diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala index 6753e7ba01a7..af02b86b4c5d 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -15,7 +15,7 @@ class SyntheticsExtractor: extension (synth: s.Synthetic) def toOpt: Some[s.Synthetic] = Some(synth) - if tree.span.isSynthetic || tree.symbol.isInventedGiven then + if tree.span.isSynthetic || isInventedGiven(tree) then tree match case tree: Apply if isForSynthetic(tree) => None // not yet supported (for synthetics) diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 0bdab175dc43..816fb5ad4f74 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -1705,7 +1705,7 @@ Text => empty Language => Scala Symbols => 45 entries Occurrences => 61 entries -Synthetics => 7 entries +Synthetics => 5 entries Symbols: givens/InventedNames$package. => final package object givens extends Object { self: givens.type => +24 decls } @@ -1820,8 +1820,6 @@ Occurrences: Synthetics: [14:0..14:20):given String = "str" => given_String [15:13..15:16):Int => x$1 -[17:0..17:28):given given_Char: Char = '?' => given_Char -[18:0..18:32):given `given_Float`: Float = 3.0 => given_Float [24:13..24:14):X => x$1 [34:8..34:20):given_Double => *(intValue) [40:8..40:15):given_Y => *(given_X) From 9e6056ec74daed4e34a7cb5e8da260c73bbfe646 Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Mon, 16 Aug 2021 17:32:12 +0900 Subject: [PATCH 4/9] Add TypeApplication synthetics --- .../dotc/semanticdb/ExtractSemanticDB.scala | 5 + .../dotc/semanticdb/SyntheticsExtractor.scala | 37 ++- tests/semanticdb/expect/Example.expect.scala | 6 +- tests/semanticdb/expect/Example.scala | 6 +- tests/semanticdb/metac.expect | 282 ++++++++++++++++-- 5 files changed, 310 insertions(+), 26 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index 43b37bd5195e..fb953da43479 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -248,6 +248,11 @@ class ExtractSemanticDB extends Phase: registerUseGuarded(None, alt.symbol.companionClass, sel.imported.span, tree.source) case tree: Inlined => traverse(tree.call) + case tree: TypeApply => + synth.tryFindSynthetic(tree).foreach { synth => + synthetics += synth + } + traverseChildren(tree) case _ => traverseChildren(tree) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala index af02b86b4c5d..5aaec04df89a 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -19,6 +19,32 @@ class SyntheticsExtractor: tree match case tree: Apply if isForSynthetic(tree) => None // not yet supported (for synthetics) + case tree: TypeApply => + println(tree) + println(tree.args.foreach(arg => println(arg.symbol.flagsString))) + // println("===") + // println(tree) + // println(tree.symbol.flagsString) + // println(tree.fun.symbol.flagsString) + // tree.args.foreach(targ => println(targ.symbol.flagsString)) + val fnTree = tree.fun match + // Something like `List.apply[Int](1,2,3)` + case select @ Select(qual, _) if isSyntheticName(select) => + s.SelectTree( + s.OriginalTree(range(qual.span, tree.source)), + Some(select.toSemanticId) + ) + case _ => + s.OriginalTree( + range(tree.fun.span, tree.source) + ) + val targs = tree.args.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) + s.Synthetic( + range(tree.span, tree.source), + s.TypeApplyTree( + fnTree, targs + ) + ).toOpt case tree: Apply if tree.args.nonEmpty && tree.args.forall(arg => @@ -53,7 +79,6 @@ class SyntheticsExtractor: ).toOpt case _ => None else None - private given TreeOps: AnyRef with extension (tree: Tree) def toSemanticTree(using Context, SemanticSymbolBuilder, TypeOps): s.Tree = @@ -86,6 +111,16 @@ class SyntheticsExtractor: s.OriginalTree(range(tree.span, tree.source)) end TreeOps + private def isSyntheticName(select: Select): Boolean = + select.span.toSynthetic == select.qualifier.span.toSynthetic && ( + select.name == nme.apply || + select.name == nme.update || + select.name == nme.foreach || + select.name == nme.withFilter || + select.name == nme.flatMap || + select.name == nme.map || + select.name == nme.unapplySeq || + select.name == nme.unapply) private def isForSynthetic(tree: Tree): Boolean = def isForComprehensionSyntheticName(select: Select): Boolean = diff --git a/tests/semanticdb/expect/Example.expect.scala b/tests/semanticdb/expect/Example.expect.scala index 5a6513ce1645..bff83979419a 100644 --- a/tests/semanticdb/expect/Example.expect.scala +++ b/tests/semanticdb/expect/Example.expect.scala @@ -4,8 +4,8 @@ import scala.concurrent.Future/*->scala::concurrent::Future.*//*->scala::concurr object Example/*<-example::Example.*/ { self/*<-local0*/ => new scala.collection.mutable.Stack/*->scala::collection::mutable::Stack#*/[Int/*->scala::Int#*/]() - def main/*<-example::Example.main().*/(args/*<-example::Example.main().(args)*/: Array/*->scala::Array#*/[String/*->scala::Predef.String#*/]): Unit/*->scala::Unit#*/ = { - println/*->scala::Predef.println(+1).*/(1) - } + // def main(args: Array[String]): Unit = { + // println(1) + // } val x/*<-example::Example.x.*/ = scala.reflect.classTag/*->scala::reflect::package.classTag().*/[Int/*->scala::Int#*/] } diff --git a/tests/semanticdb/expect/Example.scala b/tests/semanticdb/expect/Example.scala index 794ae807ffeb..47cc508b26e0 100644 --- a/tests/semanticdb/expect/Example.scala +++ b/tests/semanticdb/expect/Example.scala @@ -4,8 +4,8 @@ import scala.concurrent.Future object Example { self => new scala.collection.mutable.Stack[Int]() - def main(args: Array[String]): Unit = { - println(1) - } + // def main(args: Array[String]): Unit = { + // println(1) + // } val x = scala.reflect.classTag[Int] } diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 816fb5ad4f74..2e0f0d81f246 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -50,7 +50,7 @@ Text => empty Language => Scala Symbols => 46 entries Occurrences => 101 entries -Synthetics => 3 entries +Synthetics => 6 entries Symbols: advanced/C# => class C [typeparam T ] extends Object { self: C[T] => +3 decls } @@ -204,8 +204,11 @@ Occurrences: [48:39..48:47): toString -> scala/Tuple2#toString(). Synthetics: +[26:12..26:18):s.s1.x => *[Int] [26:12..26:16):s.s1 => reflectiveSelectable(*) +[28:12..28:18):s.s2.x => *[Int] [28:12..28:16):s.s2 => reflectiveSelectable(*) +[30:12..30:22):s.s3.m(??? => *[Int] [30:12..30:16):s.s3 => reflectiveSelectable(*) expect/Annotations.scala @@ -303,6 +306,7 @@ Text => empty Language => Scala Symbols => 14 entries Occurrences => 30 entries +Synthetics => 2 entries Symbols: example/Anonymous# => class Anonymous extends Object { self: Anonymous & Anonymous => +6 decls } @@ -352,6 +356,10 @@ Occurrences: [18:6..18:9): foo <- example/Anonymous#foo. [18:16..18:19): Foo -> example/Anonymous#Foo# +Synthetics: +[10:2..10:9):locally => *[Unit] +[13:2..13:9):locally => *[Unit] + expect/AnonymousGiven.scala --------------------------- @@ -390,6 +398,7 @@ Text => empty Language => Scala Symbols => 109 entries Occurrences => 113 entries +Synthetics => 2 entries Symbols: classes/C1# => final class C1 extends AnyVal { self: C1 => +2 decls } @@ -617,6 +626,10 @@ Occurrences: [53:4..53:9): local -> local4 [53:10..53:11): + -> scala/Int#`+`(+4). +Synthetics: +[51:16..51:27):List(1).map => *[Int] +[51:16..51:20):List => *.apply[Int] + expect/Empty.scala ------------------ @@ -674,6 +687,7 @@ Text => empty Language => Scala Symbols => 24 entries Occurrences => 37 entries +Synthetics => 2 entries Symbols: endmarkers/Container# => class Container extends Object { self: Container => +5 decls } @@ -740,6 +754,10 @@ Occurrences: [56:6..56:13): TestObj -> endmarkers/TestObj. [58:4..58:14): endmarkers -> endmarkers/ +Synthetics: +[23:7..23:7): => *.apply[Int, Int, Int] +[27:7..27:7): => *.apply[Int, Int, Int] + expect/EndMarkers2.scala ------------------------ @@ -819,6 +837,7 @@ Text => empty Language => Scala Symbols => 181 entries Occurrences => 148 entries +Synthetics => 12 entries Symbols: _empty_/Enums. => final object Enums extends Object { self: Enums.type => +30 decls } @@ -1153,6 +1172,20 @@ Occurrences: [68:9..68:16): Neptune <- _empty_/Enums.Planet.Neptune. [68:25..68:31): Planet -> _empty_/Enums.Planet# +Synthetics: +[42:24..42:32):Tag[Int] => *[Int] +[43:28..43:40):Tag[Boolean] => *[Boolean] +[46:28..46:35):C <:< C => *[C, C] +[49:27..49:31):Refl => *.apply[T] +[52:9..52:13):Refl => *.unapply[Option[B]] +[52:19..52:30):opt.flatMap => *[B] +[52:31..52:50):identity[Option[B]] => *[Function1[A, Option[B]]] +[54:14..54:18):Some => *.apply[Some[Int]] +[54:19..54:23):Some => *.apply[Int] +[54:28..54:34):unwrap => *[Some[Int], Int] +[54:34..54:34): => *[Option[Int]] +[56:52..56:64):Enum[Planet] => *[Planet] + expect/EtaExpansion.scala ------------------------- @@ -1163,6 +1196,7 @@ Text => empty Language => Scala Symbols => 3 entries Occurrences => 8 entries +Synthetics => 5 entries Symbols: example/EtaExpansion# => class EtaExpansion extends Object { self: EtaExpansion => +1 decls } @@ -1179,6 +1213,13 @@ Occurrences: [4:10..4:18): foldLeft -> scala/collection/LinearSeqOps#foldLeft(). [4:25..4:26): + -> java/lang/String#`+`(). +Synthetics: +[3:2..3:13):Some(1).map => *[Int] +[3:2..3:6):Some => *.apply[Int] +[3:14..3:22):identity => *[Int] +[4:2..4:18):List(1).foldLeft => *[String] +[4:2..4:6):List => *.apply[Int] + expect/Example.scala -------------------- @@ -1187,13 +1228,12 @@ Schema => SemanticDB v4 Uri => Example.scala Text => empty Language => Scala -Symbols => 5 entries -Occurrences => 23 entries +Symbols => 3 entries +Occurrences => 17 entries +Synthetics => 3 entries Symbols: -example/Example. => final object Example extends Object { self: Example.type => +3 decls } -example/Example.main(). => method main (param args: Array[String]): Unit -example/Example.main().(args) => param args: Array[String] +example/Example. => final object Example extends Object { self: Example.type => +2 decls } example/Example.x. => val method x ClassTag[Int] local0 => selfparam self: Example.type @@ -1210,18 +1250,17 @@ Occurrences: [5:23..5:30): mutable -> scala/collection/mutable/ [5:31..5:36): Stack -> scala/collection/mutable/Stack# [5:37..5:40): Int -> scala/Int# -[6:6..6:10): main <- example/Example.main(). -[6:11..6:15): args <- example/Example.main().(args) -[6:17..6:22): Array -> scala/Array# -[6:23..6:29): String -> scala/Predef.String# -[6:33..6:37): Unit -> scala/Unit# -[7:4..7:11): println -> scala/Predef.println(+1). [9:6..9:7): x <- example/Example.x. [9:10..9:15): scala -> scala/ [9:16..9:23): reflect -> scala/reflect/ [9:24..9:32): classTag -> scala/reflect/package.classTag(). [9:33..9:36): Int -> scala/Int# +Synthetics: +[5:6..5:41):scala.collection.mutable.Stack[Int] => *[Int] +[5:6..5:41):scala.collection.mutable.Stack[Int] => *[Int] +[9:37..9:37): => *.apply[Int] + expect/Extension.scala ---------------------- @@ -1232,7 +1271,7 @@ Text => empty Language => Scala Symbols => 26 entries Occurrences => 50 entries -Synthetics => 2 entries +Synthetics => 3 entries Symbols: ext/Extension$package. => final package object ext extends Object { self: ext.type => +6 decls } @@ -1315,6 +1354,7 @@ Occurrences: [17:50..17:51): U -> ext/Functor#map().[U] Synthetics: +[4:37..4:37): => *.apply[String, Int] [14:24..14:31):Read[T] => x$2 [14:46..14:61):summon[Read[T]] => *(x$2) @@ -1328,6 +1368,7 @@ Text => empty Language => Scala Symbols => 13 entries Occurrences => 52 entries +Synthetics => 33 entries Symbols: example/ForComprehension# => class ForComprehension extends Object { self: ForComprehension => +1 decls } @@ -1398,6 +1439,73 @@ Occurrences: [40:6..40:7): e -> local9 [41:6..41:7): f -> local10 +Synthetics: +[4:9..4:16):List(1) => *.flatMap[Tuple3[Int, Int, Int]] +[4:9..4:13):List => *.apply[Int] +[5:4..7:13):b <- List(1) + if b > 1 + c = a + b => *.map[Tuple3[Int, Int, Int]] +[5:4..6:12):b <- List(1) + if b > 1 => *.map[Tuple2[Int, Int]] +[5:4..5:4): => *.apply[Int, Int] +[5:4..5:4): => *.unapply[Int, Int] +[5:9..5:13):List => *.apply[Int] +[8:11..8:11): => *.apply[Int, Int, Int] +[10:9..10:16):List(1) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] +[10:9..10:13):List => *.apply[Int] +[11:4..15:15):b <- List(a) + if ( + a, + b + ) == (1, 2) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] +[11:9..11:13):List => *.apply[Int] +[13:6..13:6): => *.apply[Int, Int] +[15:10..15:10): => *.apply[Int, Int] +[16:4..32:24):( + c, + d + ) <- List((a, b)) + if ( + a, + b, + c, + d + ) == (1, 2, 3, 4) + e = ( + a, + b, + c, + d + ) + if e == (1, 2, 3, 4) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] +[16:4..25:21):( + c, + d + ) <- List((a, b)) + if ( + a, + b, + c, + d + ) == (1, 2, 3, 4) => *.map[Tuple2[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]]] +[16:4..16:4): => *.unapply[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]] +[16:4..16:4): => *.unapply[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]] +[17:6..17:6): => *.unapply[Int, Int] +[17:6..17:6): => *.unapply[Int, Int] +[17:6..17:6): => *.unapply[Int, Int] +[17:6..17:6): => *.unapply[Int, Int] +[17:6..17:6): => *.unapply[Int, Int] +[19:9..19:13):List => *.apply[Tuple2[Int, Int]] +[19:15..19:15): => *.apply[Int, Int] +[21:6..21:6): => *.apply[Int, Int, Int, Int] +[25:10..25:10): => *.apply[Int, Int, Int, Int] +[26:4..26:4): => *.apply[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]] +[27:6..27:6): => *.apply[Int, Int, Int, Int] +[32:13..32:13): => *.apply[Int, Int, Int, Int] +[33:9..33:16):List(e) => *.map[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] +[33:9..33:13):List => *.apply[Tuple4[Int, Int, Int, Int]] +[36:6..36:6): => *.apply[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]] + expect/Givens.scala ------------------- @@ -1408,6 +1516,7 @@ Text => empty Language => Scala Symbols => 29 entries Occurrences => 62 entries +Synthetics => 3 entries Symbols: a/b/Givens. => final object Givens extends Object { self: Givens.type => +12 decls } @@ -1504,6 +1613,11 @@ Occurrences: [26:57..26:58): A -> a/b/Givens.foo().(A) [26:59..26:64): empty -> a/b/Givens.Monoid#empty(). +Synthetics: +[12:17..12:25):sayHello => *[Int] +[13:19..13:29):sayGoodbye => *[Int] +[14:18..14:27):saySoLong => *[Int] + expect/ImplicitConversion.scala ------------------------------- @@ -1514,7 +1628,7 @@ Text => empty Language => Scala Symbols => 23 entries Occurrences => 48 entries -Synthetics => 6 entries +Synthetics => 8 entries Symbols: example/ImplicitConversion# => class ImplicitConversion extends Object { self: ImplicitConversion => +9 decls } @@ -1592,7 +1706,9 @@ Occurrences: [34:58..34:63): other -> example/ImplicitConversion.newAny2stringadd#`+`().(other) Synthetics: +[11:15..11:15): => *.apply[Int, Int] [15:2..15:9):message => augmentString(*) +[17:2..17:2): => *[Tuple2[Int, Int]] [17:2..17:7):tuple => newAny2stringadd[Tuple2[Int, Int]](*) [20:15..20:22):message => string2Number(*) [24:2..26:16):s"""Hello @@ -1630,6 +1746,7 @@ Text => empty Language => Scala Symbols => 8 entries Occurrences => 52 entries +Synthetics => 2 entries Symbols: example/InstrumentTyper# => class InstrumentTyper extends Object { self: AnyRef & InstrumentTyper => +5 decls } @@ -1695,6 +1812,10 @@ Occurrences: [24:30..24:36): Option -> scala/Option# [24:37..24:40): Int -> scala/Int# +Synthetics: +[8:12..8:16):List => *.apply[Matchable] +[20:4..20:8):List => *.apply[Nothing] + expect/InventedNames.scala -------------------------- @@ -1834,7 +1955,7 @@ Text => empty Language => Scala Symbols => 7 entries Occurrences => 22 entries -Synthetics => 3 entries +Synthetics => 7 entries Symbols: example/Issue1749# => class Issue1749 extends Object { self: Issue1749 => +3 decls } @@ -1870,9 +1991,13 @@ Occurrences: [14:2..14:5): map -> example/Issue1854#map. Synthetics: +[8:2..8:2): => *[Tuple2[Int, Int]] [8:2..8:10):(x1, x1) => orderingToOrdered[Tuple2[Int, Int]](*) [8:2..8:10):(x1, x1) => *(Tuple2(Int, Int)) +[8:3..8:3): => *.apply[Int, Int] +[8:10..8:10): => *[Int, Int] [8:10..8:10): => *(Int, Int) +[9:14..9:14): => *.apply[Int, Int] expect/Local.scala ------------------ @@ -1884,6 +2009,7 @@ Text => empty Language => Scala Symbols => 6 entries Occurrences => 10 entries +Synthetics => 1 entries Symbols: example/Local# => class Local extends Object { self: Local => +2 decls } @@ -1905,6 +2031,9 @@ Occurrences: [4:25..4:26): a -> local1 [5:4..5:6): id -> local2 +Synthetics: +[5:4..5:6):id => *[Int] + expect/Locals.scala ------------------- @@ -1915,6 +2044,7 @@ Text => empty Language => Scala Symbols => 3 entries Occurrences => 6 entries +Synthetics => 1 entries Symbols: local0 => val local x: Int @@ -1929,6 +2059,9 @@ Occurrences: [5:4..5:8): List -> scala/package.List. [5:9..5:10): x -> local0 +Synthetics: +[5:4..5:8):List => *.apply[Int] + expect/MetacJava.scala ---------------------- @@ -2026,7 +2159,7 @@ Text => empty Language => Scala Symbols => 3 entries Occurrences => 80 entries -Synthetics => 1 entries +Synthetics => 5 entries Symbols: example/MethodUsages# => class MethodUsages extends Object { self: MethodUsages => +2 decls } @@ -2116,7 +2249,11 @@ Occurrences: [34:8..34:9): m -> example/Methods#m17.m(). Synthetics: +[3:14..3:26):Methods[Int] => *[Int] +[11:11..11:22):m.List[Int] => *[Int] +[13:2..13:6):m.m7 => *[Int] [13:2..13:26):m.m7(m, new m.List[Int]) => *(Int) +[13:14..13:25):m.List[Int] => *[Int] expect/Methods.scala -------------------- @@ -2691,7 +2828,7 @@ Text => empty Language => Scala Symbols => 65 entries Occurrences => 103 entries -Synthetics => 1 entries +Synthetics => 4 entries Symbols: example/C# => class C extends Object { self: C => +3 decls } @@ -2866,7 +3003,10 @@ Occurrences: [32:57..32:59): as -> example/PickOneRefinement_1#run().(as) Synthetics: +[15:23..15:34):elems.toMap => *[String, Any] [15:23..15:34):elems.toMap => *(refl[Tuple2[String, Any]]) +[15:34..15:34): => *[Tuple2[String, Any]] +[32:47..32:56):s.pickOne => *[String] expect/RightAssociativeExtension.scala -------------------------------------- @@ -2878,6 +3018,7 @@ Text => empty Language => Scala Symbols => 5 entries Occurrences => 12 entries +Synthetics => 1 entries Symbols: ext/RightAssociativeExtension$package. => final package object ext extends Object { self: ext.type => +3 decls } @@ -2900,6 +3041,9 @@ Occurrences: [5:4..5:5): b <- ext/RightAssociativeExtension$package.b. [5:14..5:17): :*: -> ext/RightAssociativeExtension$package.`:*:`(). +Synthetics: +[3:37..3:37): => *.apply[String, Int] + expect/Selfs.scala ------------------ @@ -2955,7 +3099,7 @@ Text => empty Language => Scala Symbols => 52 entries Occurrences => 133 entries -Synthetics => 24 entries +Synthetics => 61 entries Symbols: example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls } @@ -3147,23 +3291,61 @@ Occurrences: [58:6..58:9): foo -> example/Synthetic#Contexts.foo(). Synthetics: +[5:2..5:13):List(1).map => *[Int] +[5:2..5:6):List => *.apply[Int] [6:2..6:18):Array.empty[Int] => intArrayOps(*) +[6:18..6:18): => *.apply[Int] [7:2..7:8):"fooo" => augmentString(*) [10:13..10:24):"name:(.*)" => augmentString(*) +[11:8..11:11):#:: => *.unapply[Int] +[11:17..11:25):LazyList => *.apply[Int] +[13:4..13:28):#:: 2 #:: LazyList.empty => *[Int] +[13:8..13:8): => *[Int] [13:8..13:28):2 #:: LazyList.empty => toDeferrer[Int](*) +[13:10..13:28):#:: LazyList.empty => *[Int] +[13:14..13:14): => *[Nothing] [13:14..13:28):LazyList.empty => toDeferrer[Nothing](*) +[13:14..13:28):LazyList.empty => *[Nothing] +[15:9..15:12):#:: => *.unapply[Int] +[15:16..15:19):#:: => *.unapply[Int] +[15:25..15:33):LazyList => *.apply[Int] +[17:14..17:38):#:: 2 #:: LazyList.empty => *[Int] +[17:18..17:18): => *[Int] [17:18..17:38):2 #:: LazyList.empty => toDeferrer[Int](*) +[17:20..17:38):#:: LazyList.empty => *[Int] +[17:24..17:24): => *[Nothing] [17:24..17:38):LazyList.empty => toDeferrer[Nothing](*) +[17:24..17:38):LazyList.empty => *[Nothing] +[19:12..19:19):1 to 10 => *.foreach[Unit] [19:12..19:13):1 => intWrapper(*) +[19:26..19:36):0 until 10 => *.foreach[Unit] [19:26..19:27):0 => intWrapper(*) +[19:46..19:50):x -> => *[Int] +[19:46..19:46): => *[Int] [19:46..19:47):x => ArrowAssoc[Int](*) +[20:12..20:19):1 to 10 => *.flatMap[Tuple2[Int, Int]] [20:12..20:13):1 => intWrapper(*) +[20:26..20:36):0 until 10 => *.map[Tuple2[Int, Int]] [20:26..20:27):0 => intWrapper(*) +[20:45..20:45): => *.apply[Int, Int] +[21:12..21:19):1 to 10 => *.flatMap[Tuple2[Int, Int]] [21:12..21:13):1 => intWrapper(*) +[21:21..21:50):j <- 0 until 10 if i % 2 == 0 => *.map[Tuple2[Int, Int]] [21:26..21:27):0 => intWrapper(*) +[21:59..21:59): => *.apply[Int, Int] [32:35..32:49):Array.empty[T] => *(evidence$1) +[36:22..36:22): => *[F] [36:22..36:27):new F => orderingToOrdered[F](*) [36:22..36:27):new F => *(ordering) +[40:9..40:46):scala.concurrent.Future.successful(1) => *.foreach[Unit] +[40:9..40:43):scala.concurrent.Future.successful => *[Int] +[41:9..41:46):scala.concurrent.Future.successful(2) => *.foreach[Unit] +[41:9..41:43):scala.concurrent.Future.successful => *[Int] +[44:9..44:46):scala.concurrent.Future.successful(1) => *.flatMap[Int] +[44:9..44:43):scala.concurrent.Future.successful => *[Int] +[45:4..46:12):b <- scala.concurrent.Future.successful(2) + if a < b => *.map[Int] +[45:9..45:43):scala.concurrent.Future.successful => *[Int] [50:26..50:29):Int => x$2 [51:17..51:20):Int => x$1 [51:24..51:30):foo(0) => *(x$1) @@ -3222,6 +3404,7 @@ Text => empty Language => Scala Symbols => 22 entries Occurrences => 46 entries +Synthetics => 17 entries Symbols: example/ValPattern# => class ValPattern extends Object { self: ValPattern => +14 decls } @@ -3295,6 +3478,25 @@ Occurrences: [39:10..39:17): leftVar -> local3 [40:10..40:18): rightVar -> local4 +Synthetics: +[4:23..4:23): => *.apply[Int, Int] +[5:6..5:10):Some => *.unapply[Int] +[6:4..6:8):Some => *.apply[Int] +[8:6..8:10):List => *.unapplySeq[Nothing] +[8:11..8:15):Some => *.unapply[Nothing] +[10:29..10:29): => *.apply[Int, Int] +[11:6..11:10):Some => *.unapply[Int] +[12:4..12:8):Some => *.apply[Int] +[17:8..17:8): => *.apply[Int, Int, Int, Int, Int, Int] +[25:4..25:11):locally => *[Unit] +[26:27..26:27): => *.apply[Int, Int] +[27:10..27:14):Some => *.unapply[Int] +[28:8..28:12):Some => *.apply[Int] +[30:33..30:33): => *.apply[Int, Int] +[31:10..31:14):Some => *.unapply[Int] +[32:8..32:12):Some => *.apply[Int] +[35:10..35:10): => *.apply[Int, Int, Int, Int, Int, Int] + expect/Vals.scala ----------------- @@ -3662,6 +3864,7 @@ Text => empty Language => Scala Symbols => 24 entries Occurrences => 39 entries +Synthetics => 2 entries Symbols: _empty_/Copy# => trait Copy [typeparam In <: Txn[In], typeparam Out <: Txn[Out]] extends Object { self: Copy[In, Out] => +5 decls } @@ -3730,6 +3933,10 @@ Occurrences: [14:8..14:15): println -> scala/Predef.println(+1). [17:4..17:7): out -> local0 +Synthetics: +[12:5..12:5): => *.apply[Repr[In], Repr[Out]] +[13:12..13:12): => *.unapply[Repr[In], Repr[Out]] + expect/inlineconsume.scala -------------------------- @@ -3794,6 +4001,7 @@ Text => empty Language => Scala Symbols => 3 entries Occurrences => 6 entries +Synthetics => 1 entries Symbols: example/`local-file`# => class local-file extends Object { self: local-file => +1 decls } @@ -3808,6 +4016,9 @@ Occurrences: [5:4..5:9): local -> local0 [5:10..5:11): + -> scala/Int#`+`(+4). +Synthetics: +[3:2..3:9):locally => *[Int] + expect/nullary.scala -------------------- @@ -3818,6 +4029,7 @@ Text => empty Language => Scala Symbols => 16 entries Occurrences => 28 entries +Synthetics => 2 entries Symbols: _empty_/Concrete# => class Concrete extends NullaryTest[Int, List] { self: Concrete => +3 decls } @@ -3867,6 +4079,10 @@ Occurrences: [18:7..18:15): Concrete -> _empty_/Concrete# [18:17..18:25): nullary3 -> _empty_/Concrete#nullary3(). +Synthetics: +[11:23..11:45):NullaryTest[Int, List] => *[Int, List] +[13:17..13:21):List => *.apply[Int] + expect/recursion.scala ---------------------- @@ -3877,6 +4093,7 @@ Text => empty Language => Scala Symbols => 36 entries Occurrences => 45 entries +Synthetics => 6 entries Symbols: local0 => case val method N$1 <: Nat @@ -3963,6 +4180,14 @@ Occurrences: [23:35..23:39): Zero -> recursion/Nats.Zero. [23:40..23:42): ++ -> recursion/Nats.Nat#`++`(). +Synthetics: +[5:50..5:54):Succ => *.apply[Nat.this.type] +[5:50..5:54):Succ => *.apply[Nat.this.type] +[10:13..10:17):Succ => *.unapply[N$1] +[10:13..10:17):Succ => *.unapply[N$1] +[20:11..20:15):Succ => *.unapply[N$2] +[20:11..20:15):Succ => *.unapply[N$2] + expect/semanticdb-Definitions.scala ----------------------------------- @@ -4005,6 +4230,7 @@ Text => empty Language => Scala Symbols => 50 entries Occurrences => 73 entries +Synthetics => 4 entries Symbols: flags/p/package. => final package object p extends Object { self: p.type => +23 decls } @@ -4133,6 +4359,12 @@ Occurrences: [25:27..25:28): t <- local1 [25:33..25:36): ??? -> scala/Predef.`???`(). +Synthetics: +[10:22..10:22): => *[T, U, V] +[11:26..11:26): => *[T, U, V] +[23:6..23:10):List => *.unapplySeq[Nothing] +[24:19..24:23):List => *.unapplySeq[Nothing] + expect/semanticdb-Types.scala ----------------------------- @@ -4143,6 +4375,7 @@ Text => empty Language => Scala Symbols => 144 entries Occurrences => 225 entries +Synthetics => 1 entries Symbols: local0 => abstract method k => Int @@ -4517,6 +4750,9 @@ Occurrences: [119:32..119:38): Option -> scala/Option# [119:39..119:42): Int -> scala/Int# +Synthetics: +[68:20..68:24):@ann => *[Int] + expect/semanticdb-extract.scala ------------------------------- @@ -4527,6 +4763,7 @@ Text => empty Language => Scala Symbols => 18 entries Occurrences => 20 entries +Synthetics => 3 entries Symbols: _empty_/AnObject. => final object AnObject extends Object { self: AnObject.type => +6 decls } @@ -4570,6 +4807,11 @@ Occurrences: [16:17..16:18): x <- _empty_/AnObject.Foo#x. [16:20..16:23): Int -> scala/Int# +Synthetics: +[11:2..11:6):List => *.apply[Int] +[12:2..12:12):List.apply => *[Nothing] +[13:2..13:14):List.`apply` => *[Nothing] + expect/toplevel.scala --------------------- @@ -4580,7 +4822,7 @@ Text => empty Language => Scala Symbols => 19 entries Occurrences => 34 entries -Synthetics => 2 entries +Synthetics => 4 entries Symbols: _empty_/MyProgram# => final class MyProgram extends Object { self: MyProgram => +2 decls } @@ -4640,6 +4882,8 @@ Occurrences: [6:30..6:33): foo -> _empty_/toplevel$package.foo(). Synthetics: +[5:0..5:0): => *[Int] [5:0..5:0): => *(given_FromString_Int) +[5:40..5:60):(1 to times) foreach => *[Unit] [5:41..5:42):1 => intWrapper(*) From 221c490d81c68b43961bc5282407a4b651f49127 Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Mon, 16 Aug 2021 18:35:21 +0900 Subject: [PATCH 5/9] Remove synthetics from scala2x --- .../dotc/semanticdb/SyntheticsExtractor.scala | 6 +-- tests/semanticdb/metac.expect | 46 ++++--------------- 2 files changed, 11 insertions(+), 41 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala index 5aaec04df89a..979ae4485707 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -19,9 +19,9 @@ class SyntheticsExtractor: tree match case tree: Apply if isForSynthetic(tree) => None // not yet supported (for synthetics) - case tree: TypeApply => - println(tree) - println(tree.args.foreach(arg => println(arg.symbol.flagsString))) + case tree: TypeApply if tree.args.forall(arg => !arg.symbol.is(Scala2x)) => + // println(tree) + // println(tree.args.foreach(arg => println(arg.symbol.flagsString))) // println("===") // println(tree) // println(tree.symbol.flagsString) diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 2e0f0d81f246..70fba8452674 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -50,7 +50,7 @@ Text => empty Language => Scala Symbols => 46 entries Occurrences => 101 entries -Synthetics => 6 entries +Synthetics => 3 entries Symbols: advanced/C# => class C [typeparam T ] extends Object { self: C[T] => +3 decls } @@ -204,11 +204,8 @@ Occurrences: [48:39..48:47): toString -> scala/Tuple2#toString(). Synthetics: -[26:12..26:18):s.s1.x => *[Int] [26:12..26:16):s.s1 => reflectiveSelectable(*) -[28:12..28:18):s.s2.x => *[Int] [28:12..28:16):s.s2 => reflectiveSelectable(*) -[30:12..30:22):s.s3.m(??? => *[Int] [30:12..30:16):s.s3 => reflectiveSelectable(*) expect/Annotations.scala @@ -837,7 +834,7 @@ Text => empty Language => Scala Symbols => 181 entries Occurrences => 148 entries -Synthetics => 12 entries +Synthetics => 10 entries Symbols: _empty_/Enums. => final object Enums extends Object { self: Enums.type => +30 decls } @@ -1173,8 +1170,6 @@ Occurrences: [68:25..68:31): Planet -> _empty_/Enums.Planet# Synthetics: -[42:24..42:32):Tag[Int] => *[Int] -[43:28..43:40):Tag[Boolean] => *[Boolean] [46:28..46:35):C <:< C => *[C, C] [49:27..49:31):Refl => *.apply[T] [52:9..52:13):Refl => *.unapply[Option[B]] @@ -1230,7 +1225,6 @@ Text => empty Language => Scala Symbols => 3 entries Occurrences => 17 entries -Synthetics => 3 entries Symbols: example/Example. => final object Example extends Object { self: Example.type => +2 decls } @@ -1256,11 +1250,6 @@ Occurrences: [9:24..9:32): classTag -> scala/reflect/package.classTag(). [9:33..9:36): Int -> scala/Int# -Synthetics: -[5:6..5:41):scala.collection.mutable.Stack[Int] => *[Int] -[5:6..5:41):scala.collection.mutable.Stack[Int] => *[Int] -[9:37..9:37): => *.apply[Int] - expect/Extension.scala ---------------------- @@ -1368,7 +1357,7 @@ Text => empty Language => Scala Symbols => 13 entries Occurrences => 52 entries -Synthetics => 33 entries +Synthetics => 27 entries Symbols: example/ForComprehension# => class ForComprehension extends Object { self: ForComprehension => +1 decls } @@ -1448,7 +1437,6 @@ Synthetics: [5:4..6:12):b <- List(1) if b > 1 => *.map[Tuple2[Int, Int]] [5:4..5:4): => *.apply[Int, Int] -[5:4..5:4): => *.unapply[Int, Int] [5:9..5:13):List => *.apply[Int] [8:11..8:11): => *.apply[Int, Int, Int] [10:9..10:16):List(1) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] @@ -1490,11 +1478,6 @@ Synthetics: ) == (1, 2, 3, 4) => *.map[Tuple2[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]]] [16:4..16:4): => *.unapply[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]] [16:4..16:4): => *.unapply[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]] -[17:6..17:6): => *.unapply[Int, Int] -[17:6..17:6): => *.unapply[Int, Int] -[17:6..17:6): => *.unapply[Int, Int] -[17:6..17:6): => *.unapply[Int, Int] -[17:6..17:6): => *.unapply[Int, Int] [19:9..19:13):List => *.apply[Tuple2[Int, Int]] [19:15..19:15): => *.apply[Int, Int] [21:6..21:6): => *.apply[Int, Int, Int, Int] @@ -2159,7 +2142,7 @@ Text => empty Language => Scala Symbols => 3 entries Occurrences => 80 entries -Synthetics => 5 entries +Synthetics => 2 entries Symbols: example/MethodUsages# => class MethodUsages extends Object { self: MethodUsages => +2 decls } @@ -2249,11 +2232,8 @@ Occurrences: [34:8..34:9): m -> example/Methods#m17.m(). Synthetics: -[3:14..3:26):Methods[Int] => *[Int] -[11:11..11:22):m.List[Int] => *[Int] [13:2..13:6):m.m7 => *[Int] [13:2..13:26):m.m7(m, new m.List[Int]) => *(Int) -[13:14..13:25):m.List[Int] => *[Int] expect/Methods.scala -------------------- @@ -3099,7 +3079,7 @@ Text => empty Language => Scala Symbols => 52 entries Occurrences => 133 entries -Synthetics => 61 entries +Synthetics => 57 entries Symbols: example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls } @@ -3294,10 +3274,8 @@ Synthetics: [5:2..5:13):List(1).map => *[Int] [5:2..5:6):List => *.apply[Int] [6:2..6:18):Array.empty[Int] => intArrayOps(*) -[6:18..6:18): => *.apply[Int] [7:2..7:8):"fooo" => augmentString(*) [10:13..10:24):"name:(.*)" => augmentString(*) -[11:8..11:11):#:: => *.unapply[Int] [11:17..11:25):LazyList => *.apply[Int] [13:4..13:28):#:: 2 #:: LazyList.empty => *[Int] [13:8..13:8): => *[Int] @@ -3306,8 +3284,6 @@ Synthetics: [13:14..13:14): => *[Nothing] [13:14..13:28):LazyList.empty => toDeferrer[Nothing](*) [13:14..13:28):LazyList.empty => *[Nothing] -[15:9..15:12):#:: => *.unapply[Int] -[15:16..15:19):#:: => *.unapply[Int] [15:25..15:33):LazyList => *.apply[Int] [17:14..17:38):#:: 2 #:: LazyList.empty => *[Int] [17:18..17:18): => *[Int] @@ -3404,7 +3380,7 @@ Text => empty Language => Scala Symbols => 22 entries Occurrences => 46 entries -Synthetics => 17 entries +Synthetics => 13 entries Symbols: example/ValPattern# => class ValPattern extends Object { self: ValPattern => +14 decls } @@ -3480,20 +3456,16 @@ Occurrences: Synthetics: [4:23..4:23): => *.apply[Int, Int] -[5:6..5:10):Some => *.unapply[Int] [6:4..6:8):Some => *.apply[Int] [8:6..8:10):List => *.unapplySeq[Nothing] [8:11..8:15):Some => *.unapply[Nothing] [10:29..10:29): => *.apply[Int, Int] -[11:6..11:10):Some => *.unapply[Int] [12:4..12:8):Some => *.apply[Int] [17:8..17:8): => *.apply[Int, Int, Int, Int, Int, Int] [25:4..25:11):locally => *[Unit] [26:27..26:27): => *.apply[Int, Int] -[27:10..27:14):Some => *.unapply[Int] [28:8..28:12):Some => *.apply[Int] [30:33..30:33): => *.apply[Int, Int] -[31:10..31:14):Some => *.unapply[Int] [32:8..32:12):Some => *.apply[Int] [35:10..35:10): => *.apply[Int, Int, Int, Int, Int, Int] @@ -4029,7 +4001,7 @@ Text => empty Language => Scala Symbols => 16 entries Occurrences => 28 entries -Synthetics => 2 entries +Synthetics => 1 entries Symbols: _empty_/Concrete# => class Concrete extends NullaryTest[Int, List] { self: Concrete => +3 decls } @@ -4080,7 +4052,6 @@ Occurrences: [18:17..18:25): nullary3 -> _empty_/Concrete#nullary3(). Synthetics: -[11:23..11:45):NullaryTest[Int, List] => *[Int, List] [13:17..13:21):List => *.apply[Int] expect/recursion.scala @@ -4822,7 +4793,7 @@ Text => empty Language => Scala Symbols => 19 entries Occurrences => 34 entries -Synthetics => 4 entries +Synthetics => 3 entries Symbols: _empty_/MyProgram# => final class MyProgram extends Object { self: MyProgram => +2 decls } @@ -4882,7 +4853,6 @@ Occurrences: [6:30..6:33): foo -> _empty_/toplevel$package.foo(). Synthetics: -[5:0..5:0): => *[Int] [5:0..5:0): => *(given_FromString_Int) [5:40..5:60):(1 to times) foreach => *[Unit] [5:41..5:42):1 => intWrapper(*) From 8a134a5a10d0dd5290fc8548a3c98c15047fe2cf Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Mon, 16 Aug 2021 21:34:20 +0900 Subject: [PATCH 6/9] Exclude if qualifier is zero extent --- .../dotc/semanticdb/SyntheticsExtractor.scala | 4 +- tests/semanticdb/metac.expect | 70 +++---------------- 2 files changed, 12 insertions(+), 62 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala index 979ae4485707..de7ad8077dba 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -19,7 +19,9 @@ class SyntheticsExtractor: tree match case tree: Apply if isForSynthetic(tree) => None // not yet supported (for synthetics) - case tree: TypeApply if tree.args.forall(arg => !arg.symbol.is(Scala2x)) => + case tree: TypeApply + if tree.args.forall(arg => !arg.symbol.is(Scala2x)) && + !tree.span.isZeroExtent => // println(tree) // println(tree.args.foreach(arg => println(arg.symbol.flagsString))) // println("===") diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 70fba8452674..25a871a1f128 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -684,7 +684,6 @@ Text => empty Language => Scala Symbols => 24 entries Occurrences => 37 entries -Synthetics => 2 entries Symbols: endmarkers/Container# => class Container extends Object { self: Container => +5 decls } @@ -751,10 +750,6 @@ Occurrences: [56:6..56:13): TestObj -> endmarkers/TestObj. [58:4..58:14): endmarkers -> endmarkers/ -Synthetics: -[23:7..23:7): => *.apply[Int, Int, Int] -[27:7..27:7): => *.apply[Int, Int, Int] - expect/EndMarkers2.scala ------------------------ @@ -834,7 +829,7 @@ Text => empty Language => Scala Symbols => 181 entries Occurrences => 148 entries -Synthetics => 10 entries +Synthetics => 9 entries Symbols: _empty_/Enums. => final object Enums extends Object { self: Enums.type => +30 decls } @@ -1178,7 +1173,6 @@ Synthetics: [54:14..54:18):Some => *.apply[Some[Int]] [54:19..54:23):Some => *.apply[Int] [54:28..54:34):unwrap => *[Some[Int], Int] -[54:34..54:34): => *[Option[Int]] [56:52..56:64):Enum[Planet] => *[Planet] expect/EtaExpansion.scala @@ -1260,7 +1254,7 @@ Text => empty Language => Scala Symbols => 26 entries Occurrences => 50 entries -Synthetics => 3 entries +Synthetics => 2 entries Symbols: ext/Extension$package. => final package object ext extends Object { self: ext.type => +6 decls } @@ -1343,7 +1337,6 @@ Occurrences: [17:50..17:51): U -> ext/Functor#map().[U] Synthetics: -[4:37..4:37): => *.apply[String, Int] [14:24..14:31):Read[T] => x$2 [14:46..14:61):summon[Read[T]] => *(x$2) @@ -1357,7 +1350,7 @@ Text => empty Language => Scala Symbols => 13 entries Occurrences => 52 entries -Synthetics => 27 entries +Synthetics => 14 entries Symbols: example/ForComprehension# => class ForComprehension extends Object { self: ForComprehension => +1 decls } @@ -1436,9 +1429,7 @@ Synthetics: c = a + b => *.map[Tuple3[Int, Int, Int]] [5:4..6:12):b <- List(1) if b > 1 => *.map[Tuple2[Int, Int]] -[5:4..5:4): => *.apply[Int, Int] [5:9..5:13):List => *.apply[Int] -[8:11..8:11): => *.apply[Int, Int, Int] [10:9..10:16):List(1) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [10:9..10:13):List => *.apply[Int] [11:4..15:15):b <- List(a) @@ -1447,8 +1438,6 @@ Synthetics: b ) == (1, 2) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [11:9..11:13):List => *.apply[Int] -[13:6..13:6): => *.apply[Int, Int] -[15:10..15:10): => *.apply[Int, Int] [16:4..32:24):( c, d @@ -1476,18 +1465,9 @@ Synthetics: c, d ) == (1, 2, 3, 4) => *.map[Tuple2[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]]] -[16:4..16:4): => *.unapply[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]] -[16:4..16:4): => *.unapply[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]] [19:9..19:13):List => *.apply[Tuple2[Int, Int]] -[19:15..19:15): => *.apply[Int, Int] -[21:6..21:6): => *.apply[Int, Int, Int, Int] -[25:10..25:10): => *.apply[Int, Int, Int, Int] -[26:4..26:4): => *.apply[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]] -[27:6..27:6): => *.apply[Int, Int, Int, Int] -[32:13..32:13): => *.apply[Int, Int, Int, Int] [33:9..33:16):List(e) => *.map[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [33:9..33:13):List => *.apply[Tuple4[Int, Int, Int, Int]] -[36:6..36:6): => *.apply[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]] expect/Givens.scala ------------------- @@ -1611,7 +1591,7 @@ Text => empty Language => Scala Symbols => 23 entries Occurrences => 48 entries -Synthetics => 8 entries +Synthetics => 6 entries Symbols: example/ImplicitConversion# => class ImplicitConversion extends Object { self: ImplicitConversion => +9 decls } @@ -1689,9 +1669,7 @@ Occurrences: [34:58..34:63): other -> example/ImplicitConversion.newAny2stringadd#`+`().(other) Synthetics: -[11:15..11:15): => *.apply[Int, Int] [15:2..15:9):message => augmentString(*) -[17:2..17:2): => *[Tuple2[Int, Int]] [17:2..17:7):tuple => newAny2stringadd[Tuple2[Int, Int]](*) [20:15..20:22):message => string2Number(*) [24:2..26:16):s"""Hello @@ -1938,7 +1916,7 @@ Text => empty Language => Scala Symbols => 7 entries Occurrences => 22 entries -Synthetics => 7 entries +Synthetics => 3 entries Symbols: example/Issue1749# => class Issue1749 extends Object { self: Issue1749 => +3 decls } @@ -1974,13 +1952,9 @@ Occurrences: [14:2..14:5): map -> example/Issue1854#map. Synthetics: -[8:2..8:2): => *[Tuple2[Int, Int]] [8:2..8:10):(x1, x1) => orderingToOrdered[Tuple2[Int, Int]](*) [8:2..8:10):(x1, x1) => *(Tuple2(Int, Int)) -[8:3..8:3): => *.apply[Int, Int] -[8:10..8:10): => *[Int, Int] [8:10..8:10): => *(Int, Int) -[9:14..9:14): => *.apply[Int, Int] expect/Local.scala ------------------ @@ -2808,7 +2782,7 @@ Text => empty Language => Scala Symbols => 65 entries Occurrences => 103 entries -Synthetics => 4 entries +Synthetics => 3 entries Symbols: example/C# => class C extends Object { self: C => +3 decls } @@ -2985,7 +2959,6 @@ Occurrences: Synthetics: [15:23..15:34):elems.toMap => *[String, Any] [15:23..15:34):elems.toMap => *(refl[Tuple2[String, Any]]) -[15:34..15:34): => *[Tuple2[String, Any]] [32:47..32:56):s.pickOne => *[String] expect/RightAssociativeExtension.scala @@ -2998,7 +2971,6 @@ Text => empty Language => Scala Symbols => 5 entries Occurrences => 12 entries -Synthetics => 1 entries Symbols: ext/RightAssociativeExtension$package. => final package object ext extends Object { self: ext.type => +3 decls } @@ -3021,9 +2993,6 @@ Occurrences: [5:4..5:5): b <- ext/RightAssociativeExtension$package.b. [5:14..5:17): :*: -> ext/RightAssociativeExtension$package.`:*:`(). -Synthetics: -[3:37..3:37): => *.apply[String, Int] - expect/Selfs.scala ------------------ @@ -3079,7 +3048,7 @@ Text => empty Language => Scala Symbols => 52 entries Occurrences => 133 entries -Synthetics => 57 entries +Synthetics => 49 entries Symbols: example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls } @@ -3278,18 +3247,14 @@ Synthetics: [10:13..10:24):"name:(.*)" => augmentString(*) [11:17..11:25):LazyList => *.apply[Int] [13:4..13:28):#:: 2 #:: LazyList.empty => *[Int] -[13:8..13:8): => *[Int] [13:8..13:28):2 #:: LazyList.empty => toDeferrer[Int](*) [13:10..13:28):#:: LazyList.empty => *[Int] -[13:14..13:14): => *[Nothing] [13:14..13:28):LazyList.empty => toDeferrer[Nothing](*) [13:14..13:28):LazyList.empty => *[Nothing] [15:25..15:33):LazyList => *.apply[Int] [17:14..17:38):#:: 2 #:: LazyList.empty => *[Int] -[17:18..17:18): => *[Int] [17:18..17:38):2 #:: LazyList.empty => toDeferrer[Int](*) [17:20..17:38):#:: LazyList.empty => *[Int] -[17:24..17:24): => *[Nothing] [17:24..17:38):LazyList.empty => toDeferrer[Nothing](*) [17:24..17:38):LazyList.empty => *[Nothing] [19:12..19:19):1 to 10 => *.foreach[Unit] @@ -3297,20 +3262,16 @@ Synthetics: [19:26..19:36):0 until 10 => *.foreach[Unit] [19:26..19:27):0 => intWrapper(*) [19:46..19:50):x -> => *[Int] -[19:46..19:46): => *[Int] [19:46..19:47):x => ArrowAssoc[Int](*) [20:12..20:19):1 to 10 => *.flatMap[Tuple2[Int, Int]] [20:12..20:13):1 => intWrapper(*) [20:26..20:36):0 until 10 => *.map[Tuple2[Int, Int]] [20:26..20:27):0 => intWrapper(*) -[20:45..20:45): => *.apply[Int, Int] [21:12..21:19):1 to 10 => *.flatMap[Tuple2[Int, Int]] [21:12..21:13):1 => intWrapper(*) [21:21..21:50):j <- 0 until 10 if i % 2 == 0 => *.map[Tuple2[Int, Int]] [21:26..21:27):0 => intWrapper(*) -[21:59..21:59): => *.apply[Int, Int] [32:35..32:49):Array.empty[T] => *(evidence$1) -[36:22..36:22): => *[F] [36:22..36:27):new F => orderingToOrdered[F](*) [36:22..36:27):new F => *(ordering) [40:9..40:46):scala.concurrent.Future.successful(1) => *.foreach[Unit] @@ -3380,7 +3341,7 @@ Text => empty Language => Scala Symbols => 22 entries Occurrences => 46 entries -Synthetics => 13 entries +Synthetics => 7 entries Symbols: example/ValPattern# => class ValPattern extends Object { self: ValPattern => +14 decls } @@ -3455,19 +3416,13 @@ Occurrences: [40:10..40:18): rightVar -> local4 Synthetics: -[4:23..4:23): => *.apply[Int, Int] [6:4..6:8):Some => *.apply[Int] [8:6..8:10):List => *.unapplySeq[Nothing] [8:11..8:15):Some => *.unapply[Nothing] -[10:29..10:29): => *.apply[Int, Int] [12:4..12:8):Some => *.apply[Int] -[17:8..17:8): => *.apply[Int, Int, Int, Int, Int, Int] [25:4..25:11):locally => *[Unit] -[26:27..26:27): => *.apply[Int, Int] [28:8..28:12):Some => *.apply[Int] -[30:33..30:33): => *.apply[Int, Int] [32:8..32:12):Some => *.apply[Int] -[35:10..35:10): => *.apply[Int, Int, Int, Int, Int, Int] expect/Vals.scala ----------------- @@ -3836,7 +3791,6 @@ Text => empty Language => Scala Symbols => 24 entries Occurrences => 39 entries -Synthetics => 2 entries Symbols: _empty_/Copy# => trait Copy [typeparam In <: Txn[In], typeparam Out <: Txn[Out]] extends Object { self: Copy[In, Out] => +5 decls } @@ -3905,10 +3859,6 @@ Occurrences: [14:8..14:15): println -> scala/Predef.println(+1). [17:4..17:7): out -> local0 -Synthetics: -[12:5..12:5): => *.apply[Repr[In], Repr[Out]] -[13:12..13:12): => *.unapply[Repr[In], Repr[Out]] - expect/inlineconsume.scala -------------------------- @@ -4201,7 +4151,7 @@ Text => empty Language => Scala Symbols => 50 entries Occurrences => 73 entries -Synthetics => 4 entries +Synthetics => 2 entries Symbols: flags/p/package. => final package object p extends Object { self: p.type => +23 decls } @@ -4331,8 +4281,6 @@ Occurrences: [25:33..25:36): ??? -> scala/Predef.`???`(). Synthetics: -[10:22..10:22): => *[T, U, V] -[11:26..11:26): => *[T, U, V] [23:6..23:10):List => *.unapplySeq[Nothing] [24:19..24:23):List => *.unapplySeq[Nothing] From 53c42c0a35809dc95a312c64a9478a01106363f1 Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Mon, 16 Aug 2021 22:16:59 +0900 Subject: [PATCH 7/9] Tuple.apply[Int, Int](*) --- .../dotc/semanticdb/SyntheticsExtractor.scala | 146 ++++++++++-------- tests/semanticdb/metac.expect | 90 +++++++++-- 2 files changed, 164 insertions(+), 72 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala index de7ad8077dba..addddb586e2c 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -11,76 +11,100 @@ import scala.collection.mutable class SyntheticsExtractor: import Scala3.{_, given} + val visited = collection.mutable.HashSet[Tree]() + def tryFindSynthetic(tree: Tree)(using Context, SemanticSymbolBuilder, TypeOps): Option[s.Synthetic] = extension (synth: s.Synthetic) def toOpt: Some[s.Synthetic] = Some(synth) - if tree.span.isSynthetic || isInventedGiven(tree) then - tree match - case tree: Apply if isForSynthetic(tree) => - None // not yet supported (for synthetics) - case tree: TypeApply - if tree.args.forall(arg => !arg.symbol.is(Scala2x)) && - !tree.span.isZeroExtent => - // println(tree) - // println(tree.args.foreach(arg => println(arg.symbol.flagsString))) - // println("===") - // println(tree) - // println(tree.symbol.flagsString) - // println(tree.fun.symbol.flagsString) - // tree.args.foreach(targ => println(targ.symbol.flagsString)) - val fnTree = tree.fun match - // Something like `List.apply[Int](1,2,3)` - case select @ Select(qual, _) if isSyntheticName(select) => - s.SelectTree( - s.OriginalTree(range(qual.span, tree.source)), - Some(select.toSemanticId) + // println(s"${tree.span.isSynthetic}: ${tree}") + if visited.contains(tree) then None + else + if tree.span.isSynthetic || isInventedGiven(tree) then + tree match + case tree: Apply if isForSynthetic(tree) => + None // not yet supported (for synthetics) + case tree: TypeApply + if tree.args.forall(arg => !arg.symbol.is(Scala2x)) && + !tree.span.isZeroExtent => + // println(tree) + // println(tree.args.foreach(arg => println(arg.symbol.flagsString))) + // println("===") + // println(tree) + // println(tree.symbol.flagsString) + // println(tree.fun.symbol.flagsString) + // tree.args.foreach(targ => println(targ.symbol.flagsString)) + visited.add(tree) + val fnTree = tree.fun match + // Something like `List.apply[Int](1,2,3)` + case select @ Select(qual, _) if isSyntheticName(select) => + s.SelectTree( + s.OriginalTree(range(qual.span, tree.source)), + Some(select.toSemanticId) + ) + case _ => + s.OriginalTree( + range(tree.fun.span, tree.source) + ) + val targs = tree.args.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) + s.Synthetic( + range(tree.span, tree.source), + s.TypeApplyTree( + fnTree, targs ) - case _ => - s.OriginalTree( - range(tree.fun.span, tree.source) + ).toOpt + case tree: Apply + if tree.args.nonEmpty && + tree.args.forall(arg => + arg.symbol.isOneOf(GivenOrImplicit) && + arg.span.isSynthetic + ) => + s.Synthetic( + range(tree.span, tree.source), + s.ApplyTree( + tree.fun.toSemanticOriginal, + tree.args.map(_.toSemanticTree) ) - val targs = tree.args.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) - s.Synthetic( - range(tree.span, tree.source), - s.TypeApplyTree( - fnTree, targs - ) - ).toOpt - case tree: Apply - if tree.args.nonEmpty && - tree.args.forall(arg => - arg.symbol.isOneOf(GivenOrImplicit) && - arg.span.isSynthetic - ) => - s.Synthetic( - range(tree.span, tree.source), - s.ApplyTree( - tree.fun.toSemanticOriginal, - tree.args.map(_.toSemanticTree) - ) - ).toOpt + ).toOpt - case tree: Apply if tree.fun.symbol.is(Implicit) => - val pos = range(tree.span, tree.source) - s.Synthetic( - pos, - s.ApplyTree( - tree.fun.toSemanticTree, - arguments = List( - s.OriginalTree(pos) + case tree: Apply if tree.fun.symbol.is(Implicit) => + val pos = range(tree.span, tree.source) + s.Synthetic( + pos, + s.ApplyTree( + tree.fun.toSemanticTree, + arguments = List( + s.OriginalTree(pos) + ) ) - ) - ).toOpt + ).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 + tree match + case tree @ Apply(tapp @ TypeApply(select: Select, targs), args) if !visited.contains(tapp) => + val pos = range(tree.span, tree.source) + val stargs = targs.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) + s.Synthetic( + pos, + s.ApplyTree( + s.TypeApplyTree( + select.toSemanticQualifierTree, + stargs, + ), + List( + s.OriginalTree(pos) + ) + ) + ).toOpt + case _ => None - // 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 private given TreeOps: AnyRef with extension (tree: Tree) def toSemanticTree(using Context, SemanticSymbolBuilder, TypeOps): s.Tree = diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 25a871a1f128..9e66a4819ebd 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -684,6 +684,7 @@ Text => empty Language => Scala Symbols => 24 entries Occurrences => 37 entries +Synthetics => 2 entries Symbols: endmarkers/Container# => class Container extends Object { self: Container => +5 decls } @@ -750,6 +751,10 @@ Occurrences: [56:6..56:13): TestObj -> endmarkers/TestObj. [58:4..58:14): endmarkers -> endmarkers/ +Synthetics: +[23:6..23:13):(1,2,3) => Tuple3.apply[Int, Int, Int](*) +[27:6..27:13):(4,5,6) => Tuple3.apply[Int, Int, Int](*) + expect/EndMarkers2.scala ------------------------ @@ -1254,7 +1259,7 @@ Text => empty Language => Scala Symbols => 26 entries Occurrences => 50 entries -Synthetics => 2 entries +Synthetics => 3 entries Symbols: ext/Extension$package. => final package object ext extends Object { self: ext.type => +6 decls } @@ -1337,6 +1342,7 @@ Occurrences: [17:50..17:51): U -> ext/Functor#map().[U] Synthetics: +[4:36..4:42):(s, i) => Tuple2.apply[String, Int](*) [14:24..14:31):Read[T] => x$2 [14:46..14:61):summon[Read[T]] => *(x$2) @@ -1350,7 +1356,7 @@ Text => empty Language => Scala Symbols => 13 entries Occurrences => 52 entries -Synthetics => 14 entries +Synthetics => 23 entries Symbols: example/ForComprehension# => class ForComprehension extends Object { self: ForComprehension => +1 decls } @@ -1430,6 +1436,7 @@ Synthetics: [5:4..6:12):b <- List(1) if b > 1 => *.map[Tuple2[Int, Int]] [5:9..5:13):List => *.apply[Int] +[8:10..8:19):(a, b, c) => Tuple3.apply[Int, Int, Int](*) [10:9..10:16):List(1) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [10:9..10:13):List => *.apply[Int] [11:4..15:15):b <- List(a) @@ -1438,6 +1445,11 @@ Synthetics: b ) == (1, 2) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [11:9..11:13):List => *.apply[Int] +[12:7..15:5):( + a, + b + ) => Tuple2.apply[Int, Int](*) +[15:9..15:15):(1, 2) => Tuple2.apply[Int, Int](*) [16:4..32:24):( c, d @@ -1466,8 +1478,31 @@ Synthetics: d ) == (1, 2, 3, 4) => *.map[Tuple2[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]]] [19:9..19:13):List => *.apply[Tuple2[Int, Int]] +[19:14..19:20):(a, b) => Tuple2.apply[Int, Int](*) +[20:7..25:5):( + a, + b, + c, + d + ) => Tuple4.apply[Int, Int, Int, Int](*) +[25:9..25:21):(1, 2, 3, 4) => Tuple4.apply[Int, Int, Int, Int](*) +[26:8..31:5):( + a, + b, + c, + d + ) => Tuple4.apply[Int, Int, Int, Int](*) +[32:12..32:24):(1, 2, 3, 4) => Tuple4.apply[Int, Int, Int, Int](*) [33:9..33:16):List(e) => *.map[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [33:9..33:13):List => *.apply[Tuple4[Int, Int, Int, Int]] +[35:4..42:5):( + a, + b, + c, + d, + e, + f + ) => Tuple6.apply[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]](*) expect/Givens.scala ------------------- @@ -1591,7 +1626,7 @@ Text => empty Language => Scala Symbols => 23 entries Occurrences => 48 entries -Synthetics => 6 entries +Synthetics => 7 entries Symbols: example/ImplicitConversion# => class ImplicitConversion extends Object { self: ImplicitConversion => +9 decls } @@ -1669,6 +1704,7 @@ Occurrences: [34:58..34:63): other -> example/ImplicitConversion.newAny2stringadd#`+`().(other) Synthetics: +[11:14..11:20):(1, 2) => Tuple2.apply[Int, Int](*) [15:2..15:9):message => augmentString(*) [17:2..17:7):tuple => newAny2stringadd[Tuple2[Int, Int]](*) [20:15..20:22):message => string2Number(*) @@ -1916,7 +1952,7 @@ Text => empty Language => Scala Symbols => 7 entries Occurrences => 22 entries -Synthetics => 3 entries +Synthetics => 5 entries Symbols: example/Issue1749# => class Issue1749 extends Object { self: Issue1749 => +3 decls } @@ -1953,8 +1989,10 @@ Occurrences: Synthetics: [8:2..8:10):(x1, x1) => orderingToOrdered[Tuple2[Int, Int]](*) +[8:2..8:10):(x1, x1) => Tuple2.apply[Int, Int](*) [8:2..8:10):(x1, x1) => *(Tuple2(Int, Int)) [8:10..8:10): => *(Int, Int) +[9:13..9:21):(x2, x2) => Tuple2.apply[Int, Int](*) expect/Local.scala ------------------ @@ -2971,6 +3009,7 @@ Text => empty Language => Scala Symbols => 5 entries Occurrences => 12 entries +Synthetics => 1 entries Symbols: ext/RightAssociativeExtension$package. => final package object ext extends Object { self: ext.type => +3 decls } @@ -2993,6 +3032,9 @@ Occurrences: [5:4..5:5): b <- ext/RightAssociativeExtension$package.b. [5:14..5:17): :*: -> ext/RightAssociativeExtension$package.`:*:`(). +Synthetics: +[3:36..3:42):(s, i) => Tuple2.apply[String, Int](*) + expect/Selfs.scala ------------------ @@ -3048,7 +3090,7 @@ Text => empty Language => Scala Symbols => 52 entries Occurrences => 133 entries -Synthetics => 49 entries +Synthetics => 51 entries Symbols: example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls } @@ -3267,10 +3309,12 @@ Synthetics: [20:12..20:13):1 => intWrapper(*) [20:26..20:36):0 until 10 => *.map[Tuple2[Int, Int]] [20:26..20:27):0 => intWrapper(*) +[20:44..20:50):(i, j) => Tuple2.apply[Int, Int](*) [21:12..21:19):1 to 10 => *.flatMap[Tuple2[Int, Int]] [21:12..21:13):1 => intWrapper(*) [21:21..21:50):j <- 0 until 10 if i % 2 == 0 => *.map[Tuple2[Int, Int]] [21:26..21:27):0 => intWrapper(*) +[21:58..21:64):(i, j) => Tuple2.apply[Int, Int](*) [32:35..32:49):Array.empty[T] => *(evidence$1) [36:22..36:27):new F => orderingToOrdered[F](*) [36:22..36:27):new F => *(ordering) @@ -3341,7 +3385,7 @@ Text => empty Language => Scala Symbols => 22 entries Occurrences => 46 entries -Synthetics => 7 entries +Synthetics => 13 entries Symbols: example/ValPattern# => class ValPattern extends Object { self: ValPattern => +14 decls } @@ -3416,13 +3460,33 @@ Occurrences: [40:10..40:18): rightVar -> local4 Synthetics: +[4:22..4:28):(1, 2) => Tuple2.apply[Int, Int](*) [6:4..6:8):Some => *.apply[Int] [8:6..8:10):List => *.unapplySeq[Nothing] [8:11..8:15):Some => *.unapply[Nothing] +[10:28..10:34):(1, 2) => Tuple2.apply[Int, Int](*) [12:4..12:8):Some => *.apply[Int] +[16:6..23:7):( + number1, + left, + right, + number1Var, + leftVar, + rightVar + ) => Tuple6.apply[Int, Int, Int, Int, Int, Int](*) [25:4..25:11):locally => *[Unit] +[26:26..26:32):(1, 2) => Tuple2.apply[Int, Int](*) [28:8..28:12):Some => *.apply[Int] +[30:32..30:38):(1, 2) => Tuple2.apply[Int, Int](*) [32:8..32:12):Some => *.apply[Int] +[34:8..41:9):( + number1, + left, + right, + number1Var, + leftVar, + rightVar + ) => Tuple6.apply[Int, Int, Int, Int, Int, Int](*) expect/Vals.scala ----------------- @@ -3791,6 +3855,7 @@ Text => empty Language => Scala Symbols => 24 entries Occurrences => 39 entries +Synthetics => 2 entries Symbols: _empty_/Copy# => trait Copy [typeparam In <: Txn[In], typeparam Out <: Txn[Out]] extends Object { self: Copy[In, Out] => +5 decls } @@ -3859,6 +3924,10 @@ Occurrences: [14:8..14:15): println -> scala/Predef.println(+1). [17:4..17:7): out -> local0 +Synthetics: +[11:14..11:32):copyImpl[Repr](in) => copyImpl[Repr](*) +[12:4..12:13):(in, out) => Tuple2.apply[Repr[In], Repr[Out]](*) + expect/inlineconsume.scala -------------------------- @@ -4014,7 +4083,7 @@ Text => empty Language => Scala Symbols => 36 entries Occurrences => 45 entries -Synthetics => 6 entries +Synthetics => 3 entries Symbols: local0 => case val method N$1 <: Nat @@ -4103,11 +4172,8 @@ Occurrences: Synthetics: [5:50..5:54):Succ => *.apply[Nat.this.type] -[5:50..5:54):Succ => *.apply[Nat.this.type] -[10:13..10:17):Succ => *.unapply[N$1] [10:13..10:17):Succ => *.unapply[N$1] [20:11..20:15):Succ => *.unapply[N$2] -[20:11..20:15):Succ => *.unapply[N$2] expect/semanticdb-Definitions.scala ----------------------------------- @@ -4151,7 +4217,7 @@ Text => empty Language => Scala Symbols => 50 entries Occurrences => 73 entries -Synthetics => 2 entries +Synthetics => 4 entries Symbols: flags/p/package. => final package object p extends Object { self: p.type => +23 decls } @@ -4281,6 +4347,8 @@ Occurrences: [25:33..25:36): ??? -> scala/Predef.`???`(). Synthetics: +[10:17..10:36):this(???, ???, ???) => [T, U, V](*) +[11:21..11:38):this(t, ???, ???) => [T, U, V](*) [23:6..23:10):List => *.unapplySeq[Nothing] [24:19..24:23):List => *.unapplySeq[Nothing] From d108b48e0d5a9ddc45a81621a748326dfbe0f1c2 Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Tue, 17 Aug 2021 03:32:37 +0900 Subject: [PATCH 8/9] Exclude for synthetics --- .../dotc/semanticdb/SyntheticsExtractor.scala | 6 ++ tests/semanticdb/metac.expect | 55 +------------------ 2 files changed, 8 insertions(+), 53 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala index addddb586e2c..6ef7b54d6797 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -24,6 +24,8 @@ class SyntheticsExtractor: tree match case tree: Apply if isForSynthetic(tree) => None // not yet supported (for synthetics) + case tree: TypeApply if isForSynthetic(tree) => + None // not yet supported (for synthetics) case tree: TypeApply if tree.args.forall(arg => !arg.symbol.is(Scala2x)) && !tree.span.isZeroExtent => @@ -88,6 +90,10 @@ class SyntheticsExtractor: case _ => None else tree match + case tree: Apply if isForSynthetic(tree) => + None // not yet supported (for synthetics) + case tree: TypeApply if isForSynthetic(tree) => + None // not yet supported (for synthetics) case tree @ Apply(tapp @ TypeApply(select: Select, targs), args) if !visited.contains(tapp) => val pos = range(tree.span, tree.source) val stargs = targs.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 9e66a4819ebd..6191444ae597 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -1356,7 +1356,7 @@ Text => empty Language => Scala Symbols => 13 entries Occurrences => 52 entries -Synthetics => 23 entries +Synthetics => 15 entries Symbols: example/ForComprehension# => class ForComprehension extends Object { self: ForComprehension => +1 decls } @@ -1428,55 +1428,16 @@ Occurrences: [41:6..41:7): f -> local10 Synthetics: -[4:9..4:16):List(1) => *.flatMap[Tuple3[Int, Int, Int]] [4:9..4:13):List => *.apply[Int] -[5:4..7:13):b <- List(1) - if b > 1 - c = a + b => *.map[Tuple3[Int, Int, Int]] -[5:4..6:12):b <- List(1) - if b > 1 => *.map[Tuple2[Int, Int]] [5:9..5:13):List => *.apply[Int] [8:10..8:19):(a, b, c) => Tuple3.apply[Int, Int, Int](*) -[10:9..10:16):List(1) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [10:9..10:13):List => *.apply[Int] -[11:4..15:15):b <- List(a) - if ( - a, - b - ) == (1, 2) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [11:9..11:13):List => *.apply[Int] [12:7..15:5):( a, b ) => Tuple2.apply[Int, Int](*) [15:9..15:15):(1, 2) => Tuple2.apply[Int, Int](*) -[16:4..32:24):( - c, - d - ) <- List((a, b)) - if ( - a, - b, - c, - d - ) == (1, 2, 3, 4) - e = ( - a, - b, - c, - d - ) - if e == (1, 2, 3, 4) => *.flatMap[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] -[16:4..25:21):( - c, - d - ) <- List((a, b)) - if ( - a, - b, - c, - d - ) == (1, 2, 3, 4) => *.map[Tuple2[Tuple2[Int, Int], Tuple4[Int, Int, Int, Int]]] [19:9..19:13):List => *.apply[Tuple2[Int, Int]] [19:14..19:20):(a, b) => Tuple2.apply[Int, Int](*) [20:7..25:5):( @@ -1493,7 +1454,6 @@ Synthetics: d ) => Tuple4.apply[Int, Int, Int, Int](*) [32:12..32:24):(1, 2, 3, 4) => Tuple4.apply[Int, Int, Int, Int](*) -[33:9..33:16):List(e) => *.map[Tuple6[Int, Int, Int, Int, Tuple4[Int, Int, Int, Int], Tuple4[Int, Int, Int, Int]]] [33:9..33:13):List => *.apply[Tuple4[Int, Int, Int, Int]] [35:4..42:5):( a, @@ -3090,7 +3050,7 @@ Text => empty Language => Scala Symbols => 52 entries Occurrences => 133 entries -Synthetics => 51 entries +Synthetics => 41 entries Symbols: example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls } @@ -3299,33 +3259,22 @@ Synthetics: [17:20..17:38):#:: LazyList.empty => *[Int] [17:24..17:38):LazyList.empty => toDeferrer[Nothing](*) [17:24..17:38):LazyList.empty => *[Nothing] -[19:12..19:19):1 to 10 => *.foreach[Unit] [19:12..19:13):1 => intWrapper(*) -[19:26..19:36):0 until 10 => *.foreach[Unit] [19:26..19:27):0 => intWrapper(*) [19:46..19:50):x -> => *[Int] [19:46..19:47):x => ArrowAssoc[Int](*) -[20:12..20:19):1 to 10 => *.flatMap[Tuple2[Int, Int]] [20:12..20:13):1 => intWrapper(*) -[20:26..20:36):0 until 10 => *.map[Tuple2[Int, Int]] [20:26..20:27):0 => intWrapper(*) [20:44..20:50):(i, j) => Tuple2.apply[Int, Int](*) -[21:12..21:19):1 to 10 => *.flatMap[Tuple2[Int, Int]] [21:12..21:13):1 => intWrapper(*) -[21:21..21:50):j <- 0 until 10 if i % 2 == 0 => *.map[Tuple2[Int, Int]] [21:26..21:27):0 => intWrapper(*) [21:58..21:64):(i, j) => Tuple2.apply[Int, Int](*) [32:35..32:49):Array.empty[T] => *(evidence$1) [36:22..36:27):new F => orderingToOrdered[F](*) [36:22..36:27):new F => *(ordering) -[40:9..40:46):scala.concurrent.Future.successful(1) => *.foreach[Unit] [40:9..40:43):scala.concurrent.Future.successful => *[Int] -[41:9..41:46):scala.concurrent.Future.successful(2) => *.foreach[Unit] [41:9..41:43):scala.concurrent.Future.successful => *[Int] -[44:9..44:46):scala.concurrent.Future.successful(1) => *.flatMap[Int] [44:9..44:43):scala.concurrent.Future.successful => *[Int] -[45:4..46:12):b <- scala.concurrent.Future.successful(2) - if a < b => *.map[Int] [45:9..45:43):scala.concurrent.Future.successful => *[Int] [50:26..50:29):Int => x$2 [51:17..51:20):Int => x$1 From 5777e2d60103a4f5e3286ce9ca6896324018f0fe Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Tue, 17 Aug 2021 03:59:33 +0900 Subject: [PATCH 9/9] Refactor --- .../dotc/semanticdb/SyntheticsExtractor.scala | 174 +++++++++--------- tests/semanticdb/metac.expect | 6 +- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala index 6ef7b54d6797..fc2d66329762 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SyntheticsExtractor.scala @@ -17,99 +17,99 @@ class SyntheticsExtractor: extension (synth: s.Synthetic) def toOpt: Some[s.Synthetic] = Some(synth) + val forSynthetic = tree match // not yet supported (for synthetics) + case tree: Apply if isForSynthetic(tree) => true + case tree: TypeApply if isForSynthetic(tree) => true + case _ => false + // println(s"${tree.span.isSynthetic}: ${tree}") - if visited.contains(tree) then None + if visited.contains(tree) || forSynthetic then None else - if tree.span.isSynthetic || isInventedGiven(tree) then - tree match - case tree: Apply if isForSynthetic(tree) => - None // not yet supported (for synthetics) - case tree: TypeApply if isForSynthetic(tree) => - None // not yet supported (for synthetics) - case tree: TypeApply - if tree.args.forall(arg => !arg.symbol.is(Scala2x)) && - !tree.span.isZeroExtent => - // println(tree) - // println(tree.args.foreach(arg => println(arg.symbol.flagsString))) - // println("===") - // println(tree) - // println(tree.symbol.flagsString) - // println(tree.fun.symbol.flagsString) - // tree.args.foreach(targ => println(targ.symbol.flagsString)) - visited.add(tree) - val fnTree = tree.fun match - // Something like `List.apply[Int](1,2,3)` - case select @ Select(qual, _) if isSyntheticName(select) => - s.SelectTree( - s.OriginalTree(range(qual.span, tree.source)), - Some(select.toSemanticId) - ) - case _ => - s.OriginalTree( - range(tree.fun.span, tree.source) - ) - val targs = tree.args.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) - s.Synthetic( - range(tree.span, tree.source), - s.TypeApplyTree( - fnTree, targs + tree match + case tree: TypeApply + if tree.span.isSynthetic && + tree.args.forall(arg => !arg.symbol.is(Scala2x)) && + !tree.span.isZeroExtent => + // println(tree) + // println(tree.args.foreach(arg => println(arg.symbol.flagsString))) + // println("===") + // println(tree) + // println(tree.symbol.flagsString) + // println(tree.fun.symbol.flagsString) + // tree.args.foreach(targ => println(targ.symbol.flagsString)) + visited.add(tree) + val fnTree = tree.fun match + // Something like `List.apply[Int](1,2,3)` + case select @ Select(qual, _) if isSyntheticName(select) => + s.SelectTree( + s.OriginalTree(range(qual.span, tree.source)), + Some(select.toSemanticId) ) - ).toOpt - case tree: Apply - if tree.args.nonEmpty && - tree.args.forall(arg => - arg.symbol.isOneOf(GivenOrImplicit) && - arg.span.isSynthetic - ) => - s.Synthetic( - range(tree.span, tree.source), - s.ApplyTree( - tree.fun.toSemanticOriginal, - tree.args.map(_.toSemanticTree) + case _ => + s.OriginalTree( + range(tree.fun.span, tree.source) ) - ).toOpt - - case tree: Apply if tree.fun.symbol.is(Implicit) => - val pos = range(tree.span, tree.source) - s.Synthetic( - pos, - s.ApplyTree( - tree.fun.toSemanticTree, - arguments = List( - s.OriginalTree(pos) - ) + val targs = tree.args.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) + s.Synthetic( + range(tree.span, tree.source), + s.TypeApplyTree( + fnTree, targs + ) + ).toOpt + + case tree: Apply + if tree.args.nonEmpty && + tree.args.forall(arg => + arg.symbol.isOneOf(GivenOrImplicit) && + arg.span.isSynthetic + ) => + s.Synthetic( + range(tree.span, tree.source), + s.ApplyTree( + tree.fun.toSemanticOriginal, + tree.args.map(_.toSemanticTree) + ) + ).toOpt + + case tree: Apply if tree.fun.symbol.is(Implicit) && tree.fun.span.isSynthetic => + val pos = range(tree.span, tree.source) + s.Synthetic( + pos, + s.ApplyTree( + tree.fun.toSemanticTree, + arguments = List( + s.OriginalTree(pos) ) - ).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 - tree match - case tree: Apply if isForSynthetic(tree) => - None // not yet supported (for synthetics) - case tree: TypeApply if isForSynthetic(tree) => - None // not yet supported (for synthetics) - case tree @ Apply(tapp @ TypeApply(select: Select, targs), args) if !visited.contains(tapp) => - val pos = range(tree.span, tree.source) - val stargs = targs.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) - s.Synthetic( - pos, - s.ApplyTree( - s.TypeApplyTree( - select.toSemanticQualifierTree, - stargs, - ), - List( - s.OriginalTree(pos) - ) + ) + ).toOpt + + // Anonymous context parameter + case tree: ValDef if tree.symbol.is(Given) || isInventedGiven(tree) => + s.Synthetic( + range(tree.span, tree.source), + tree.toSemanticId + ).toOpt + + // (1, 2) => Tuple.apply((1, 2)) + case tree @ Apply(tapp @ TypeApply(select: Select, targs), args) + if !visited.contains(tapp) && + tapp.span.isSynthetic && + tree.span.isSourceDerived => + val pos = range(tree.span, tree.source) + val stargs = targs.map(targ => targ.tpe.toSemanticType(targ.symbol)(using LinkMode.SymlinkChildren)) + s.Synthetic( + pos, + s.ApplyTree( + s.TypeApplyTree( + select.toSemanticQualifierTree, + stargs, + ), + List( + s.OriginalTree(pos) ) - ).toOpt - case _ => None + ) + ).toOpt + case _ => None private given TreeOps: AnyRef with extension (tree: Tree) diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 6191444ae597..8fb4a7e2e9ac 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -834,7 +834,7 @@ Text => empty Language => Scala Symbols => 181 entries Occurrences => 148 entries -Synthetics => 9 entries +Synthetics => 10 entries Symbols: _empty_/Enums. => final object Enums extends Object { self: Enums.type => +30 decls } @@ -1176,6 +1176,7 @@ Synthetics: [52:19..52:30):opt.flatMap => *[B] [52:31..52:50):identity[Option[B]] => *[Function1[A, Option[B]]] [54:14..54:18):Some => *.apply[Some[Int]] +[54:14..54:34):Some(Some(1)).unwrap => *(given_<:<_T_T[Option[Int]]) [54:19..54:23):Some => *.apply[Int] [54:28..54:34):unwrap => *[Some[Int], Int] [56:52..56:64):Enum[Planet] => *[Planet] @@ -3804,7 +3805,7 @@ Text => empty Language => Scala Symbols => 24 entries Occurrences => 39 entries -Synthetics => 2 entries +Synthetics => 1 entries Symbols: _empty_/Copy# => trait Copy [typeparam In <: Txn[In], typeparam Out <: Txn[Out]] extends Object { self: Copy[In, Out] => +5 decls } @@ -3874,7 +3875,6 @@ Occurrences: [17:4..17:7): out -> local0 Synthetics: -[11:14..11:32):copyImpl[Repr](in) => copyImpl[Repr](*) [12:4..12:13):(in, out) => Tuple2.apply[Repr[In], Repr[Out]](*) expect/inlineconsume.scala