@@ -23,8 +23,6 @@ import scala.reflect.TypeTest
2323
2424object QuotesImpl {
2525
26- type ScopeId = Int
27-
2826 def apply ()(using Context ): Quotes =
2927 new QuotesImpl
3028
@@ -34,11 +32,6 @@ object QuotesImpl {
3432 if ctx.settings.color.value == " always" then TreeAnsiCode .show(tree)
3533 else TreeCode .show(tree)
3634
37- // TODO Explore more fine grained scope ids.
38- // This id can only differentiate scope extrusion from one compiler instance to another.
39- def scopeId (using Context ): ScopeId =
40- ctx.outersIterator.toList.last.hashCode()
41-
4235}
4336
4437class QuotesImpl private (using val ctx : Context ) extends Quotes , QuoteUnpickler , QuoteMatching :
@@ -81,10 +74,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
8174 end CompilationInfo
8275
8376 extension (expr : Expr [Any ])
84- def asTerm : Term =
85- val exprImpl = expr.asInstanceOf [ExprImpl ]
86- exprImpl.checkScopeId(QuotesImpl .this .hashCode)
87- exprImpl.tree
77+ def asTerm : Term = expr.asInstanceOf [ExprImpl ].tree
8878 end extension
8979
9080 type Tree = tpd.Tree
@@ -105,7 +95,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
10595 case _ => false
10696 def asExpr : scala.quoted.Expr [Any ] =
10797 if self.isExpr then
108- new ExprImpl (self, QuotesImpl . this .hashCode )
98+ new ExprImpl (self, SpliceScope .getCurrent )
10999 else self match
110100 case TermTypeTest (self) => throw new Exception (" Expected an expression. This is a partially applied Term. Try eta-expanding the term first." )
111101 case _ => throw new Exception (" Expected a Term but was: " + self)
@@ -372,11 +362,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
372362 given TermMethods : TermMethods with
373363 extension (self : Term )
374364 def seal : scala.quoted.Expr [Any ] =
375- if self.isExpr then new ExprImpl (self, QuotesImpl . this .hashCode )
365+ if self.isExpr then new ExprImpl (self, SpliceScope .getCurrent )
376366 else throw new Exception (" Cannot seal a partially applied Term. Try eta-expanding the term first." )
377367
378368 def sealOpt : Option [scala.quoted.Expr [Any ]] =
379- if self.isExpr then Some (new ExprImpl (self, QuotesImpl . this .hashCode ))
369+ if self.isExpr then Some (new ExprImpl (self, SpliceScope .getCurrent ))
380370 else None
381371
382372 def tpe : TypeRepr = self.tpe
@@ -1670,7 +1660,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
16701660 def seal : scala.quoted.Type [_] = self.asType
16711661
16721662 def asType : scala.quoted.Type [? ] =
1673- new TypeImpl (Inferred (self), QuotesImpl . this .hashCode )
1663+ new TypeImpl (Inferred (self), SpliceScope .getCurrent )
16741664
16751665 def =:= (that : TypeRepr ): Boolean = self =:= that
16761666 def <:< (that : TypeRepr ): Boolean = self <:< that
@@ -2894,11 +2884,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
28942884
28952885 def unpickleExpr [T ](pickled : String | List [String ], typeHole : (Int , Seq [Any ]) => scala.quoted.Type [? ], termHole : (Int , Seq [Any ], scala.quoted.Quotes ) => scala.quoted.Expr [? ]): scala.quoted.Expr [T ] =
28962886 val tree = PickledQuotes .unpickleTerm(pickled, typeHole, termHole)
2897- new ExprImpl (tree, hash ).asInstanceOf [scala.quoted.Expr [T ]]
2887+ new ExprImpl (tree, SpliceScope .getCurrent ).asInstanceOf [scala.quoted.Expr [T ]]
28982888
28992889 def unpickleType [T <: AnyKind ](pickled : String | List [String ], typeHole : (Int , Seq [Any ]) => scala.quoted.Type [? ], termHole : (Int , Seq [Any ], scala.quoted.Quotes ) => scala.quoted.Expr [? ]): scala.quoted.Type [T ] =
29002890 val tree = PickledQuotes .unpickleTypeTree(pickled, typeHole, termHole)
2901- new TypeImpl (tree, hash ).asInstanceOf [scala.quoted.Type [T ]]
2891+ new TypeImpl (tree, SpliceScope .getCurrent ).asInstanceOf [scala.quoted.Type [T ]]
29022892
29032893 object ExprMatch extends ExprMatchModule :
29042894 def unapply [TypeBindings <: Tuple , Tup <: Tuple ](scrutinee : scala.quoted.Expr [Any ])(using pattern : scala.quoted.Expr [Any ]): Option [Tup ] =
@@ -2965,7 +2955,4 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
29652955 }
29662956 }
29672957
2968- private [this ] val hash = QuotesImpl .scopeId(using ctx)
2969- override def hashCode : Int = hash
2970-
29712958end QuotesImpl
0 commit comments