diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala index 99378f0ea37c..988b7f45a08b 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala @@ -85,7 +85,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext: extension [T](tree: Tree) def asExprOf(using scala.quoted.Type[T])(using QuoteContext): scala.quoted.Expr[T] = if tree.isExpr then - new scala.internal.quoted.Expr(tree, compilerId).asExprOf[T] + new scala.internal.quoted.Expr(tree, QuoteContextImpl.this.hashCode).asExprOf[T] else tree match case TermTypeTest(tree) => throw new Exception("Expected an expression. This is a partially applied Term. Try eta-expanding the term first.") case _ => throw new Exception("Expected a Term but was: " + tree) @@ -313,11 +313,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext: object TermMethodsImpl extends TermMethods: extension (self: Term): def seal: scala.quoted.Expr[Any] = - if self.isExpr then new scala.internal.quoted.Expr(self, compilerId) + if self.isExpr then new scala.internal.quoted.Expr(self, QuoteContextImpl.this.hashCode) else throw new Exception("Cannot seal a partially applied Term. Try eta-expanding the term first.") def sealOpt: Option[scala.quoted.Expr[Any]] = - if self.isExpr then Some(new scala.internal.quoted.Expr(self, compilerId)) + if self.isExpr then Some(new scala.internal.quoted.Expr(self, QuoteContextImpl.this.hashCode)) else None def tpe: Type = self.tpe @@ -1594,7 +1594,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext: new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showType(self) def seal: scala.quoted.Type[_] = - new scala.internal.quoted.Type(Inferred(self), compilerId) + new scala.internal.quoted.Type(Inferred(self), QuoteContextImpl.this.hashCode) def =:=(that: Type): Boolean = self =:= that def <:<(that: Type): Boolean = self <:< that @@ -2668,8 +2668,9 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext: def Definitions_InternalQuotedPatterns_patternHole: Symbol = dotc.core.Symbols.defn.InternalQuotedPatterns_patternHole def Definitions_InternalQuotedPatterns_higherOrderHole: Symbol = dotc.core.Symbols.defn.InternalQuotedPatterns_higherOrderHole - def compilerId: Int = rootContext.outersIterator.toList.last.hashCode() - end tasty + private[this] val hash = QuoteContextImpl.scopeId(using ctx) + override def hashCode: Int = hash + end QuoteContextImpl diff --git a/library/src-bootstrapped/scala/internal/quoted/Expr.scala b/library/src-bootstrapped/scala/internal/quoted/Expr.scala index f95528529124..962e7f85a600 100644 --- a/library/src-bootstrapped/scala/internal/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/internal/quoted/Expr.scala @@ -20,7 +20,7 @@ import scala.internal.tasty.CompilerInterface.quoteContextWithCompilerInterface } def unseal(using qctx: QuoteContext): qctx.tasty.Term = - if (quoteContextWithCompilerInterface(qctx).tasty.compilerId != scopeId) + if (qctx.hashCode != scopeId) throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`") tree.asInstanceOf[qctx.tasty.Term] diff --git a/library/src-bootstrapped/scala/internal/quoted/Type.scala b/library/src-bootstrapped/scala/internal/quoted/Type.scala index 16bc18f41f4e..11253e24982b 100644 --- a/library/src-bootstrapped/scala/internal/quoted/Type.scala +++ b/library/src-bootstrapped/scala/internal/quoted/Type.scala @@ -15,7 +15,7 @@ final class Type[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quote /** View this expression `quoted.Type[T]` as a `TypeTree` */ def unseal(using qctx: QuoteContext): qctx.tasty.TypeTree = - if (quoteContextWithCompilerInterface(qctx).tasty.compilerId != scopeId) + if (qctx.hashCode != scopeId) throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`") typeTree.asInstanceOf[qctx.tasty.TypeTree] diff --git a/library/src-bootstrapped/scala/internal/quoted/Unpickler.scala b/library/src-bootstrapped/scala/internal/quoted/Unpickler.scala index 4df71318f4b4..ee508b4f370c 100644 --- a/library/src-bootstrapped/scala/internal/quoted/Unpickler.scala +++ b/library/src-bootstrapped/scala/internal/quoted/Unpickler.scala @@ -15,7 +15,7 @@ object Unpickler { def unpickleExpr[T](repr: PickledQuote, args: PickledArgs): QuoteContext ?=> Expr[T] = val qctx = quoteContextWithCompilerInterface(summon[QuoteContext]) val tree = qctx.tasty.unpickleExpr(repr, args) - new scala.internal.quoted.Expr(tree, qctx.tasty.compilerId).asInstanceOf[Expr[T]] + new scala.internal.quoted.Expr(tree, qctx.hashCode).asInstanceOf[Expr[T]] /** Unpickle `repr` which represents a pickled `Type` tree, * replacing splice nodes with `args` @@ -23,6 +23,6 @@ object Unpickler { def unpickleType[T](repr: PickledQuote, args: PickledArgs): QuoteContext ?=> Type[T] = val qctx = quoteContextWithCompilerInterface(summon[QuoteContext]) val tree = qctx.tasty.unpickleType(repr, args) - new scala.internal.quoted.Type(tree, qctx.tasty.compilerId).asInstanceOf[Type[T]] + new scala.internal.quoted.Type(tree, qctx.hashCode).asInstanceOf[Type[T]] } diff --git a/library/src-non-bootstrapped/scala/internal/quoted/Expr.scala b/library/src-non-bootstrapped/scala/internal/quoted/Expr.scala index 313aa3cd176f..43509960a17e 100644 --- a/library/src-non-bootstrapped/scala/internal/quoted/Expr.scala +++ b/library/src-non-bootstrapped/scala/internal/quoted/Expr.scala @@ -20,7 +20,7 @@ import scala.internal.tasty.CompilerInterface.quoteContextWithCompilerInterface } def unseal(using qctx: QuoteContext): qctx.tasty.Term = - if (quoteContextWithCompilerInterface(qctx).tasty.compilerId != scopeId) + if (qctx.hashCode != scopeId) throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`") tree.asInstanceOf[qctx.tasty.Term] diff --git a/library/src-non-bootstrapped/scala/internal/quoted/Type.scala b/library/src-non-bootstrapped/scala/internal/quoted/Type.scala index 4d64d7247d2f..3aef9c347602 100644 --- a/library/src-non-bootstrapped/scala/internal/quoted/Type.scala +++ b/library/src-non-bootstrapped/scala/internal/quoted/Type.scala @@ -15,7 +15,7 @@ final class Type[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quote /** View this expression `quoted.Type[T]` as a `TypeTree` */ def unseal(using qctx: QuoteContext): qctx.tasty.TypeTree = - if (quoteContextWithCompilerInterface(qctx).tasty.compilerId != scopeId) + if (qctx.hashCode != scopeId) throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`") typeTree.asInstanceOf[qctx.tasty.TypeTree] diff --git a/library/src/scala/internal/tasty/CompilerInterface.scala b/library/src/scala/internal/tasty/CompilerInterface.scala index cf465ce4e6d8..a8925a0ab3b9 100644 --- a/library/src/scala/internal/tasty/CompilerInterface.scala +++ b/library/src/scala/internal/tasty/CompilerInterface.scala @@ -51,17 +51,11 @@ trait CompilerInterface { self: scala.tasty.Reflection => */ def typeTreeMatch(scrutinee: TypeTree, pattern: TypeTree): Option[Tuple] - // - // TYPES - // - /** Symbol of scala.internal.quoted.Patterns.patternHole */ - def Definitions_InternalQuotedPatterns_patternHole: Symbol + def Definitions_InternalQuotedPatterns_patternHole: Symbol // TODO remove /** Symbol of scala.internal.quoted.Patterns.higherOrderHole */ - def Definitions_InternalQuotedPatterns_higherOrderHole: Symbol - - def compilerId: Int + def Definitions_InternalQuotedPatterns_higherOrderHole: Symbol // TODO remove }