diff --git a/compiler/src/scala/quoted/runtime/impl/Matcher.scala b/compiler/src/scala/quoted/runtime/impl/Matcher.scala index d0428eef0623..440ef84eb459 100644 --- a/compiler/src/scala/quoted/runtime/impl/Matcher.scala +++ b/compiler/src/scala/quoted/runtime/impl/Matcher.scala @@ -137,7 +137,7 @@ object Matcher { extension (scrutinees: List[Tree]): /** Check that all trees match with =?= and concatenate the results with &&& */ - private def =?= (patterns: List[Tree])(using Context, Env): Matching = + private def =?= (patterns: List[Tree])(using Env): Matching = matchLists(scrutinees, patterns)(_ =?= _) extension (scrutinee0: Tree): @@ -149,7 +149,7 @@ object Matcher { * @param `summon[Env]` Set of tuples containing pairs of symbols (s, p) where s defines a symbol in `scrutinee` which corresponds to symbol p in `pattern`. * @return `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes. */ - private def =?= (pattern0: Tree)(using Context, Env): Matching = { + private def =?= (pattern0: Tree)(using Env): Matching = { /* Match block flattening */ // TODO move to cases /** Normalize the tree */ @@ -299,7 +299,7 @@ object Matcher { /* Match val */ case (ValDef(_, tpt1, rhs1), ValDef(_, tpt2, rhs2)) if checkValFlags() => def rhsEnv = summon[Env] + (scrutinee.symbol -> pattern.symbol) - tpt1 =?= tpt2 &&& treeOptMatches(rhs1, rhs2)(using summon[Context], rhsEnv) + tpt1 =?= tpt2 &&& treeOptMatches(rhs1, rhs2)(using rhsEnv) /* Match def */ case (DefDef(_, typeParams1, paramss1, tpt1, Some(rhs1)), DefDef(_, typeParams2, paramss2, tpt2, Some(rhs2))) => @@ -348,11 +348,11 @@ object Matcher { private object ClosedPatternTerm { /** Matches a term that does not contain free variables defined in the pattern (i.e. not defined in `Env`) */ - def unapply(term: Term)(using Context, Env): Option[term.type] = + def unapply(term: Term)(using Env): Option[term.type] = if freePatternVars(term).isEmpty then Some(term) else None /** Return all free variables of the term defined in the pattern (i.e. defined in `Env`) */ - def freePatternVars(term: Term)(using ctx: Context, env: Env): Set[Symbol] = + def freePatternVars(term: Term)(using env: Env): Set[Symbol] = val accumulator = new TreeAccumulator[Set[Symbol]] { def foldTree(x: Set[Symbol], tree: Tree)(owner: Symbol): Set[Symbol] = tree match @@ -363,7 +363,7 @@ object Matcher { } private object IdentArgs { - def unapply(args: List[Term])(using Context): Option[List[Ident]] = + def unapply(args: List[Term]): Option[List[Ident]] = args.foldRight(Option(List.empty[Ident])) { case (id: Ident, Some(acc)) => Some(id :: acc) case (Block(List(DefDef("$anonfun", Nil, List(params), Inferred(), Some(Apply(id: Ident, args)))), Closure(Ident("$anonfun"), None)), Some(acc)) @@ -373,7 +373,7 @@ object Matcher { } } - private def treeOptMatches(scrutinee: Option[Tree], pattern: Option[Tree])(using Context, Env): Matching = { + private def treeOptMatches(scrutinee: Option[Tree], pattern: Option[Tree])(using Env): Matching = { (scrutinee, pattern) match { case (Some(x), Some(y)) => x =?= y case (None, None) => matched diff --git a/compiler/src/scala/quoted/runtime/impl/QuoteContextImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuoteContextImpl.scala index 03e3cbe35d6d..5c7732c49aca 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuoteContextImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuoteContextImpl.scala @@ -26,10 +26,10 @@ object QuoteContextImpl { type ScopeId = Int def apply()(using Context): QuoteContext = - new QuoteContextImpl(ctx) + new QuoteContextImpl def showDecompiledTree(tree: tpd.Tree)(using Context): String = { - val qctx: QuoteContextImpl = new QuoteContextImpl(MacroExpansion.context(tree)) + val qctx: QuoteContextImpl = new QuoteContextImpl(using MacroExpansion.context(tree)) if ctx.settings.color.value == "always" then qctx.reflect.TreeMethodsImpl.temporaryShowAnsiColored(tree) else @@ -43,7 +43,7 @@ object QuoteContextImpl { } -class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickler, QuoteMatching: +class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, QuoteUnpickler, QuoteMatching: private val yCheck: Boolean = ctx.settings.Ycheck.value(using ctx).exists(x => x == "all" || x == "macros") @@ -81,10 +81,6 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl object reflect extends Reflection: - def rootContext: Context = ctx - - type Context = dotc.core.Contexts.Context - type Tree = tpd.Tree object Tree extends TreeModule: @@ -2483,7 +2479,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl object Position extends PositionModule: def ofMacroExpansion: dotc.util.SourcePosition = - MacroExpansion.position.getOrElse(dotc.util.SourcePosition(rootContext.source, dotc.util.Spans.NoSpan)) + MacroExpansion.position.getOrElse(dotc.util.SourcePosition(ctx.source, dotc.util.Spans.NoSpan)) end Position object PositionMethodsImpl extends PositionMethods: @@ -2599,11 +2595,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl end reflect def unpickleExpr[T](pickled: String | List[String], typeHole: (Int, Seq[Any]) => scala.quoted.Type[?], termHole: (Int, Seq[Any], scala.quoted.QuoteContext) => scala.quoted.Expr[?]): scala.quoted.Expr[T] = - val tree = PickledQuotes.unpickleTerm(pickled, typeHole, termHole)(using reflect.rootContext) + val tree = PickledQuotes.unpickleTerm(pickled, typeHole, termHole) new ExprImpl(tree, hash).asInstanceOf[scala.quoted.Expr[T]] def unpickleType[T <: AnyKind](pickled: String | List[String], typeHole: (Int, Seq[Any]) => scala.quoted.Type[?], termHole: (Int, Seq[Any], scala.quoted.QuoteContext) => scala.quoted.Expr[?]): scala.quoted.Type[T] = - val tree = PickledQuotes.unpickleTypeTree(pickled, typeHole, termHole)(using reflect.rootContext) + val tree = PickledQuotes.unpickleTypeTree(pickled, typeHole, termHole) new TypeImpl(tree, hash).asInstanceOf[scala.quoted.Type[T]] object ExprMatch extends ExprMatchModule: @@ -2622,7 +2618,6 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl private def treeMatch(scrutinee: reflect.Tree, pattern: reflect.Tree): Option[Tuple] = { import reflect._ - given Context = rootContext def isTypeHoleDef(tree: Tree): Boolean = tree match case tree: TypeDef => diff --git a/library/src/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala index 685e3d4c3988..e1ca3ada62e4 100644 --- a/library/src/scala/quoted/QuoteContext.scala +++ b/library/src/scala/quoted/QuoteContext.scala @@ -170,17 +170,6 @@ trait QuoteContext { self: runtime.QuoteUnpickler & runtime.QuoteMatching => */ trait Reflection { self: reflect.type => - ////////////// - // CONTEXTS // - ////////////// - - /** Context containing information on the current owner */ - type Context <: AnyRef - - /** Context of the macro expansion */ - def rootContext: Context // TODO: Should this be moved to QuoteContext? - given Context = rootContext // TODO: Should be an implicit converion from QuoteContext to Context - /////////////// // TREES // /////////////// diff --git a/scala3doc/src/dotty/dokka/tasty/BasicSupport.scala b/scala3doc/src/dotty/dokka/tasty/BasicSupport.scala index d33fac7752c0..2b59f5ff13f5 100644 --- a/scala3doc/src/dotty/dokka/tasty/BasicSupport.scala +++ b/scala3doc/src/dotty/dokka/tasty/BasicSupport.scala @@ -34,13 +34,13 @@ trait BasicSupport: extension (sym: Symbol): - def documentation(using cxt: Context) = sym.documentation match + def documentation = sym.documentation match case Some(comment) => Map(sourceSet -> parseComment(comment, sym.tree)) case None => Map.empty - def source(using ctx: Context) = + def source = val path = Some(sym.pos.sourceFile.jpath).filter(_ != null).map(_.toAbsolutePath).map(_.toString) path.map(TastyDocumentableSource(_, sym.pos.startLine)) diff --git a/scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala b/scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala index 8a25aa7a86a2..b59fc693f955 100644 --- a/scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala +++ b/scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala @@ -125,9 +125,9 @@ trait ClassLikeSupport: case td: TypeDef if !td.symbol.flags.is(Flags.Synthetic) && (!td.symbol.flags.is(Flags.Case) || !td.symbol.flags.is(Flags.Enum)) => Some(parseTypeDef(td)) - case vd: ValDef if !isSyntheticField(vd.symbol) - && (!vd.symbol.flags.is(Flags.Case) || !vd.symbol.flags.is(Flags.Enum)) - && vd.symbol.isGiven => + case vd: ValDef if !isSyntheticField(vd.symbol) + && (!vd.symbol.flags.is(Flags.Case) || !vd.symbol.flags.is(Flags.Enum)) + && vd.symbol.isGiven => val classDef = Some(vd.tpt.tpe).flatMap(_.classSymbol.map(_.tree.asInstanceOf[ClassDef])) Some(classDef.filter(_.symbol.flags.is(Flags.ModuleClass)).fold[Member](parseValDef(vd))(parseGivenClasslike(_))) @@ -213,12 +213,12 @@ trait ClassLikeSupport: parseMethod(d, constructorWithoutParamLists(c), paramModifierFunc.getOrElse(s => c.getParameterModifier(s))) ) - def parseClasslike(classDef: ClassDef, signatureOnly: Boolean = false)(using ctx: Context): DClass = classDef match + def parseClasslike(classDef: ClassDef, signatureOnly: Boolean = false): DClass = classDef match case c: ClassDef if classDef.symbol.flags.is(Flags.Object) => parseObject(c, signatureOnly) case c: ClassDef if classDef.symbol.flags.is(Flags.Enum) => parseEnum(c, signatureOnly) case clazz => DClass(classDef)(signatureOnly = signatureOnly) - def parseObject(classDef: ClassDef, signatureOnly: Boolean = false)(using ctx: Context): DClass = + def parseObject(classDef: ClassDef, signatureOnly: Boolean = false): DClass = DClass(classDef)( name = classDef.name.stripSuffix("$"), // All objects are final so we do not need final modifer! @@ -227,7 +227,7 @@ trait ClassLikeSupport: ) // TODO check withNewExtras? - def parseEnum(classDef: ClassDef, signatureOnly: Boolean = false)(using ctx: Context): DClass = + def parseEnum(classDef: ClassDef, signatureOnly: Boolean = false): DClass = val extraModifiers = classDef.symbol.getExtraModifiers().filter(_ != Modifier.Sealed).filter(_ != Modifier.Abstract) val companion = classDef.symbol.getCompanionSymbol.map(_.tree.asInstanceOf[ClassDef]).get diff --git a/scala3doc/src/dotty/dokka/tasty/SymOps.scala b/scala3doc/src/dotty/dokka/tasty/SymOps.scala index 6ccafbbdf613..0b36d49b8f47 100644 --- a/scala3doc/src/dotty/dokka/tasty/SymOps.scala +++ b/scala3doc/src/dotty/dokka/tasty/SymOps.scala @@ -15,11 +15,11 @@ class SymOps[Q <: QuoteContext](val q: Q): given Q = q extension (sym: Symbol): - def packageName(using ctx: Context): String = + def packageName: String = if (sym.isPackageDef) sym.fullName else sym.maybeOwner.packageName - def topLevelEntryName(using ctx: Context): Option[String] = if (sym.isPackageDef) None else + def topLevelEntryName: Option[String] = if (sym.isPackageDef) None else if (sym.owner.isPackageDef) Some(sym.name) else sym.owner.topLevelEntryName def getVisibility(): Visibility = @@ -50,7 +50,7 @@ class SymOps[Q <: QuoteContext](val q: Q): // TODO: #49 Remove it after TASTY-Reflect release with published flag Extension def hackIsOpen: Boolean = { import dotty.tools.dotc - given dotc.core.Contexts.Context = qctx.reflect.rootContext.asInstanceOf + given dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val symbol = sym.asInstanceOf[dotc.core.Symbols.Symbol] symbol.is(dotc.core.Flags.Open) } diff --git a/scala3doc/src/dotty/dokka/tasty/SyntheticSupport.scala b/scala3doc/src/dotty/dokka/tasty/SyntheticSupport.scala index 23e2a57b2201..a3f03af65481 100644 --- a/scala3doc/src/dotty/dokka/tasty/SyntheticSupport.scala +++ b/scala3doc/src/dotty/dokka/tasty/SyntheticSupport.scala @@ -14,13 +14,13 @@ trait SyntheticsSupport: def hackIsTupleType(using QuoteContext)(rtpe: qctx.reflect.TypeRepr): Boolean = import dotty.tools.dotc - given ctx as dotc.core.Contexts.Context = qctx.reflect.rootContext.asInstanceOf + given ctx as dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val tpe = rtpe.asInstanceOf[dotc.core.Types.Type] ctx.definitions.isTupleType(tpe) def hackIsCompiletimeAppliedType(using QuoteContext)(rtpe: qctx.reflect.TypeRepr): Boolean = import dotty.tools.dotc - given ctx as dotc.core.Contexts.Context = qctx.reflect.rootContext.asInstanceOf + given ctx as dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val tpe = rtpe.asInstanceOf[dotc.core.Types.Type] ctx.definitions.isCompiletimeAppliedType(tpe.typeSymbol) @@ -55,7 +55,7 @@ trait SyntheticsSupport: def hackIsInfix(using QuoteContext)(rsym: qctx.reflect.Symbol): Boolean = { import qctx.reflect._ import dotty.tools.dotc - given ctx as dotc.core.Contexts.Context = rootContext.asInstanceOf + given ctx as dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol] ctx.definitions.isInfix(sym) } @@ -66,7 +66,7 @@ trait SyntheticsSupport: def hackGetAllMembers(using QuoteContext)(rsym: qctx.reflect.Symbol): List[qctx.reflect.Symbol] = { import qctx.reflect._ import dotty.tools.dotc - given ctx as dotc.core.Contexts.Context = rootContext.asInstanceOf + given ctx as dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol] sym.typeRef.appliedTo(sym.typeParams.map(_.typeRef)).allMembers.iterator.map(_.symbol) .collect { @@ -80,7 +80,7 @@ trait SyntheticsSupport: def hackGetSupertypes(using QuoteContext)(rdef: qctx.reflect.ClassDef) = { import qctx.reflect._ import dotty.tools.dotc - given dotc.core.Contexts.Context = qctx.reflect.rootContext.asInstanceOf + given dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val classdef = rdef.asInstanceOf[dotc.ast.tpd.TypeDef] val ref = classdef.symbol.info.asInstanceOf[dotc.core.Types.ClassInfo].appliedRef val baseTypes: List[(dotc.core.Symbols.Symbol, dotc.core.Types.Type)] = @@ -93,7 +93,7 @@ trait SyntheticsSupport: def typeForClass(c: ClassDef): TypeRepr = import qctx.reflect._ import dotty.tools.dotc - given dotc.core.Contexts.Context = rootContext.asInstanceOf + given dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val cSym = c.symbol.asInstanceOf[dotc.core.Symbols.Symbol] cSym.typeRef.appliedTo(cSym.typeParams.map(_.typeRef)).asInstanceOf[TypeRepr] diff --git a/scala3doc/src/dotty/dokka/tasty/TypesSupport.scala b/scala3doc/src/dotty/dokka/tasty/TypesSupport.scala index 6c885fb466db..600b65a4b2f1 100644 --- a/scala3doc/src/dotty/dokka/tasty/TypesSupport.scala +++ b/scala3doc/src/dotty/dokka/tasty/TypesSupport.scala @@ -37,7 +37,7 @@ trait TypesSupport: given TreeSyntax as AnyRef: extension (tpeTree: Tree): - def dokkaType(using cxt: Context): Bound = + def dokkaType: Bound = val data = tpeTree match case TypeBoundsTree(low, high) => typeBound(low.tpe, low = true) ++ typeBound(high.tpe, low = false) case tpeTree: TypeTree => inner(tpeTree.tpe) @@ -47,7 +47,7 @@ trait TypesSupport: given TypeSyntax as AnyRef: extension (tpe: TypeRepr): - def dokkaType(using ctx: Context): Bound = + def dokkaType: Bound = val data = inner(tpe) val dri = data.collect{ case o: TypeParameter => o @@ -59,7 +59,7 @@ trait TypesSupport: private def texts(str: String): List[JProjection] = List(text(str)) - private def link(symbol: Symbol)(using cxt: Context): List[JProjection] = { + private def link(symbol: Symbol): List[JProjection] = { val suffix = if symbol.isValDef then texts(".type") else Nil (new TypeParameter(symbol.dri, symbol.name, null)) :: suffix } @@ -74,7 +74,7 @@ trait TypesSupport: tpeAnnotation.tpe.typeSymbol.toString == "class Repeated" // TODO #23 add support for all types signatures that makes sense - private def inner(tp: TypeRepr)(using cxt: Context): List[JProjection] = + private def inner(tp: TypeRepr): List[JProjection] = def noSupported(name: String): List[JProjection] = println(s"WARN: Unsupported type: $name: ${tp.show}") List(text(s"Unsupported[$name]")) diff --git a/scala3doc/src/dotty/dokka/tasty/comments/MemberLookup.scala b/scala3doc/src/dotty/dokka/tasty/comments/MemberLookup.scala index f7a92b78c2b2..7757b42932ee 100644 --- a/scala3doc/src/dotty/dokka/tasty/comments/MemberLookup.scala +++ b/scala3doc/src/dotty/dokka/tasty/comments/MemberLookup.scala @@ -62,7 +62,7 @@ trait MemberLookup { private def hackMembersOf(using QuoteContext)(rsym: qctx.reflect.Symbol) = { import qctx.reflect._ import dotty.tools.dotc - given dotc.core.Contexts.Context = rootContext.asInstanceOf + given dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol] val members = sym.info.decls.iterator.filter(_.isCompleted) // println(s"members of ${sym.show} : ${members.map(_.show).mkString(", ")}") @@ -70,9 +70,8 @@ trait MemberLookup { } private def hackIsNotAbsent(using QuoteContext)(rsym: qctx.reflect.Symbol) = { - import qctx.reflect._ import dotty.tools.dotc - given dotc.core.Contexts.Context = rootContext.asInstanceOf + given dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuoteContextImpl].ctx val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol] sym.isCompleted }