@@ -61,7 +61,7 @@ object Synthetics:
61
61
* @param sym The method to transform @pre needsTransform(sym) must hold.
62
62
* @param toCC Whether to transform the type to capture checking or back.
63
63
*/
64
- def transform (sym : SymDenotation , toCC : Boolean )(using Context ): SymDenotation =
64
+ def transform (sym : SymDenotation )(using Context ): SymDenotation =
65
65
66
66
/** Add capture dependencies to the type of the `apply` or `copy` method of a case class.
67
67
* An apply method in a case class like this:
@@ -92,31 +92,18 @@ object Synthetics:
92
92
case _ =>
93
93
info
94
94
95
- /** Drop capture dependencies from the type of `apply` or `copy` method of a case class */
96
- def dropCaptureDeps (tp : Type ): Type = tp match
97
- case tp : MethodOrPoly =>
98
- tp.derivedLambdaType(resType = dropCaptureDeps(tp.resType))
99
- case CapturingType (parent, _) =>
100
- dropCaptureDeps(parent)
101
- case RefinedType (parent, _, _) =>
102
- dropCaptureDeps(parent)
103
- case _ =>
104
- tp
105
-
106
95
/** Add capture information to the type of the default getter of a case class copy method
107
- * if toCC = true, or remove the added info again if toCC = false.
108
96
*/
109
97
def transformDefaultGetterCaptures (info : Type , owner : Symbol , idx : Int )(using Context ): Type = info match
110
98
case info : MethodOrPoly =>
111
99
info.derivedLambdaType(resType = transformDefaultGetterCaptures(info.resType, owner, idx))
112
100
case info : ExprType =>
113
101
info.derivedExprType(transformDefaultGetterCaptures(info.resType, owner, idx))
114
102
case EventuallyCapturingType (parent, _) =>
115
- if toCC then transformDefaultGetterCaptures(parent, owner, idx)
116
- else parent
103
+ transformDefaultGetterCaptures(parent, owner, idx)
117
104
case info @ AnnotatedType (parent, annot) =>
118
105
info.derivedAnnotatedType(transformDefaultGetterCaptures(parent, owner, idx), annot)
119
- case _ if toCC && idx < owner.asClass.paramGetters.length =>
106
+ case _ if idx < owner.asClass.paramGetters.length =>
120
107
val param = owner.asClass.paramGetters(idx)
121
108
val pinfo = param.info
122
109
atPhase(ctx.phase.next) {
@@ -126,49 +113,29 @@ object Synthetics:
126
113
case _ =>
127
114
info
128
115
129
- /** Augment an unapply of type `(x: C): D` to `(x: C^{cap}): D^{x}` if toCC is true,
130
- * or remove the added capture sets again if toCC = false.
131
- */
116
+ /** Augment an unapply of type `(x: C): D` to `(x: C^{cap}): D^{x}` */
132
117
def transformUnapplyCaptures (info : Type )(using Context ): Type = info match
133
118
case info : MethodType =>
134
- if toCC then
135
- val paramInfo :: Nil = info.paramInfos: @ unchecked
136
- val newParamInfo = CapturingType (paramInfo, CaptureSet .universal)
137
- val trackedParam = info.paramRefs.head
138
- def newResult (tp : Type ): Type = tp match
139
- case tp : MethodOrPoly =>
140
- tp.derivedLambdaType(resType = newResult(tp.resType))
141
- case _ =>
142
- CapturingType (tp, CaptureSet (trackedParam))
143
- info.derivedLambdaType(paramInfos = newParamInfo :: Nil , resType = newResult(info.resType))
144
- .showing(i " augment unapply type $info to $result" , capt)
145
- else info.paramInfos match
146
- case CapturingType (oldParamInfo, _) :: Nil =>
147
- def oldResult (tp : Type ): Type = tp match
148
- case tp : MethodOrPoly =>
149
- tp.derivedLambdaType(resType = oldResult(tp.resType))
150
- case CapturingType (tp, _) =>
151
- tp
152
- info.derivedLambdaType(paramInfos = oldParamInfo :: Nil , resType = oldResult(info.resType))
119
+ val paramInfo :: Nil = info.paramInfos: @ unchecked
120
+ val newParamInfo = CapturingType (paramInfo, CaptureSet .universal)
121
+ val trackedParam = info.paramRefs.head
122
+ def newResult (tp : Type ): Type = tp match
123
+ case tp : MethodOrPoly =>
124
+ tp.derivedLambdaType(resType = newResult(tp.resType))
153
125
case _ =>
154
- info
126
+ CapturingType (tp, CaptureSet (trackedParam))
127
+ info.derivedLambdaType(paramInfos = newParamInfo :: Nil , resType = newResult(info.resType))
128
+ .showing(i " augment unapply type $info to $result" , capt)
155
129
case info : PolyType =>
156
130
info.derivedLambdaType(resType = transformUnapplyCaptures(info.resType))
157
131
158
132
def transformComposeCaptures (symd : SymDenotation ) =
159
133
val (pt : PolyType ) = symd.info: @ unchecked
160
134
val (mt : MethodType ) = pt.resType: @ unchecked
161
135
val (enclThis : ThisType ) = symd.owner.thisType: @ unchecked
162
- val mt1 =
163
- if toCC then
164
- MethodType (mt.paramNames)(
165
- mt1 => mt.paramInfos.map(_.capturing(CaptureSet .universal)),
166
- mt1 => CapturingType (mt.resType, CaptureSet (enclThis, mt1.paramRefs.head)))
167
- else
168
- MethodType (mt.paramNames)(
169
- mt1 => mt.paramInfos.map(_.stripCapturing),
170
- mt1 => mt.resType.stripCapturing)
171
- pt.derivedLambdaType(resType = mt1)
136
+ pt.derivedLambdaType(resType = MethodType (mt.paramNames)(
137
+ mt1 => mt.paramInfos.map(_.capturing(CaptureSet .universal)),
138
+ mt1 => CapturingType (mt.resType, CaptureSet (enclThis, mt1.paramRefs.head))))
172
139
173
140
def transformCurriedTupledCaptures (symd : SymDenotation ) =
174
141
val (et : ExprType ) = symd.info: @ unchecked
@@ -179,26 +146,18 @@ object Synthetics:
179
146
defn.FunctionOf (args, mapFinalResult(res, f), isContextual)
180
147
else
181
148
f(tp)
182
- val resType1 =
183
- if toCC then
184
- mapFinalResult(et.resType, CapturingType (_, CaptureSet (enclThis)))
185
- else
186
- et.resType.stripCapturing
187
- ExprType (resType1)
149
+ ExprType (mapFinalResult(et.resType, CapturingType (_, CaptureSet (enclThis))))
188
150
189
151
def transformCompareCaptures =
190
- if toCC then
191
- MethodType (defn.ObjectType .capturing(CaptureSet .universal) :: Nil , defn.BooleanType )
192
- else
193
- defn.methOfAnyRef(defn.BooleanType )
152
+ MethodType (defn.ObjectType .capturing(CaptureSet .universal) :: Nil , defn.BooleanType )
194
153
195
154
sym.copySymDenotation(info = sym.name match
196
155
case DefaultGetterName (nme.copy, n) =>
197
156
transformDefaultGetterCaptures(sym.info, sym.owner, n)
198
157
case nme.unapply =>
199
158
transformUnapplyCaptures(sym.info)
200
159
case nme.apply | nme.copy =>
201
- if toCC then addCaptureDeps(sym.info) else dropCaptureDeps (sym.info)
160
+ addCaptureDeps(sym.info)
202
161
case nme.andThen | nme.compose =>
203
162
transformComposeCaptures(sym)
204
163
case nme.curried | nme.tupled =>
0 commit comments