@@ -23,8 +23,6 @@ import scala.reflect.TypeTest
23
23
24
24
object QuotesImpl {
25
25
26
- type ScopeId = Int
27
-
28
26
def apply ()(using Context ): Quotes =
29
27
new QuotesImpl
30
28
@@ -34,11 +32,6 @@ object QuotesImpl {
34
32
if ctx.settings.color.value == " always" then TreeAnsiCode .show(tree)
35
33
else TreeCode .show(tree)
36
34
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
-
42
35
}
43
36
44
37
class QuotesImpl private (using val ctx : Context ) extends Quotes , QuoteUnpickler , QuoteMatching :
@@ -81,10 +74,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
81
74
end CompilationInfo
82
75
83
76
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
88
78
end extension
89
79
90
80
type Tree = tpd.Tree
@@ -105,7 +95,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
105
95
case _ => false
106
96
def asExpr : scala.quoted.Expr [Any ] =
107
97
if self.isExpr then
108
- new ExprImpl (self, QuotesImpl . this .hashCode )
98
+ new ExprImpl (self, SpliceScope .getCurrent )
109
99
else self match
110
100
case TermTypeTest (self) => throw new Exception (" Expected an expression. This is a partially applied Term. Try eta-expanding the term first." )
111
101
case _ => throw new Exception (" Expected a Term but was: " + self)
@@ -372,11 +362,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
372
362
given TermMethods : TermMethods with
373
363
extension (self : Term )
374
364
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 )
376
366
else throw new Exception (" Cannot seal a partially applied Term. Try eta-expanding the term first." )
377
367
378
368
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 ))
380
370
else None
381
371
382
372
def tpe : TypeRepr = self.tpe
@@ -1670,7 +1660,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
1670
1660
def seal : scala.quoted.Type [_] = self.asType
1671
1661
1672
1662
def asType : scala.quoted.Type [? ] =
1673
- new TypeImpl (Inferred (self), QuotesImpl . this .hashCode )
1663
+ new TypeImpl (Inferred (self), SpliceScope .getCurrent )
1674
1664
1675
1665
def =:= (that : TypeRepr ): Boolean = self =:= that
1676
1666
def <:< (that : TypeRepr ): Boolean = self <:< that
@@ -2894,11 +2884,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
2894
2884
2895
2885
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 ] =
2896
2886
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 ]]
2898
2888
2899
2889
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 ] =
2900
2890
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 ]]
2902
2892
2903
2893
object ExprMatch extends ExprMatchModule :
2904
2894
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
2965
2955
}
2966
2956
}
2967
2957
2968
- private [this ] val hash = QuotesImpl .scopeId(using ctx)
2969
- override def hashCode : Int = hash
2970
-
2971
2958
end QuotesImpl
0 commit comments