@@ -25,11 +25,6 @@ trait SetupAPI:
25
25
def postCheck ()(using Context ): Unit
26
26
27
27
object Setup :
28
- case class Box (t : Type ) extends UncachedGroundType , TermType :
29
- override def fallbackToText (printer : Printer ): Text =
30
- Str (" Box(" ) ~ printer.toText(t) ~ " )"
31
- def derivedBox (t1 : Type ): Type =
32
- if t1 eq t then this else Box (t1)
33
28
34
29
/** Recognizer for `res $throws exc`, returning `(res, exc)` in case of success */
35
30
object throwsAlias :
@@ -125,9 +120,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
125
120
case tp @ CapturingType (parent, refs) =>
126
121
if tp.isBoxed then tp else tp.boxed
127
122
case tp @ AnnotatedType (parent, ann) =>
128
- if ann.symbol == defn.RetainsAnnot then
129
- ann.tree.putAttachment(NeedsBox , ())
130
- tp
123
+ if ann.symbol == defn.RetainsAnnot
124
+ then CapturingType (parent, ann.tree.toCaptureSet, boxed = true )
131
125
else tp.derivedAnnotatedType(box(parent), ann)
132
126
case tp1 @ AppliedType (tycon, args) if defn.isNonRefinedFunction(tp1) =>
133
127
val res = args.last
@@ -237,8 +231,6 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
237
231
tp.derivedLambdaType(
238
232
paramInfos = tp.paramInfos.mapConserve(_.dropAllRetains.bounds),
239
233
resType = this (tp.resType))
240
- case Box (tp1) =>
241
- box(this (tp1))
242
234
case _ =>
243
235
mapOver(tp)
244
236
addVar(addCaptureRefinements(normalizeCaptures(tp1)), ctx.owner)
@@ -259,22 +251,23 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
259
251
* expands to
260
252
* (erased x$0: CanThrow[E1]) ?-> (erased x$1: CanThrow[E1]) ?->{x$0} T
261
253
*/
262
- private def expandThrowsAlias (tp : Type , encl : List [MethodType ] = Nil ): Type = tp match
263
- case throwsAlias(res, exc) =>
264
- val paramType = AnnotatedType (
265
- defn.CanThrowClass .typeRef.appliedTo(exc),
266
- Annotation (defn.ErasedParamAnnot , defn.CanThrowClass .span))
267
- val isLast = throwsAlias.unapply(res).isEmpty
268
- val paramName = nme.syntheticParamName(encl.length)
269
- val mt = ContextualMethodType (paramName :: Nil )(
254
+ private def expandThrowsAlias (res : Type , exc : Type , encl : List [MethodType ]): Type =
255
+ val paramType = AnnotatedType (
256
+ defn.CanThrowClass .typeRef.appliedTo(exc),
257
+ Annotation (defn.ErasedParamAnnot , defn.CanThrowClass .span))
258
+ val resDecomposed = throwsAlias.unapply(res)
259
+ val paramName = nme.syntheticParamName(encl.length)
260
+ val mt = ContextualMethodType (paramName :: Nil )(
270
261
_ => paramType :: Nil ,
271
- mt => if isLast then res else expandThrowsAlias(res, mt :: encl))
272
- val fntpe = defn.PolyFunctionOf (mt)
273
- if ! encl.isEmpty && isLast then
274
- val cs = CaptureSet (encl.map(_.paramRefs.head)* )
275
- CapturingType (fntpe, cs, boxed = false )
276
- else fntpe
277
- case _ => tp
262
+ mt => resDecomposed match
263
+ case Some ((res1, exc1)) => expandThrowsAlias(res1, exc1, mt :: encl)
264
+ case _ => res
265
+ )
266
+ val fntpe = defn.PolyFunctionOf (mt)
267
+ if ! encl.isEmpty && resDecomposed.isEmpty then
268
+ val cs = CaptureSet (encl.map(_.paramRefs.head)* )
269
+ CapturingType (fntpe, cs, boxed = false )
270
+ else fntpe
278
271
279
272
/** Map references to capability classes C to C^ */
280
273
private def expandCapabilityClass (tp : Type ): Type =
@@ -290,48 +283,30 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
290
283
private def recur (t : Type ): Type = normalizeCaptures(mapOver(t))
291
284
292
285
def apply (t : Type ) =
293
- val t1 = expandThrowsAlias(t)
294
- if t1 ne t then return this (t1)
295
- val t2 = expandCapabilityClass(t)
296
- if t2 ne t then return t2
297
286
t match
298
- case t @ AppliedType (tycon : TypeProxy , args) =>
299
- tycon.underlying match
300
- case TypeAlias (aliasTycon) =>
301
- val args1 =
302
- if defn.isFunctionClass(t.dealias.typeSymbol) then args
303
- else args.map(Box (_))
304
- val alias = aliasTycon.applyIfParameterized(args1)
305
- val transformed = this (alias)
306
- if transformed ne alias then
307
- // println(i"APP ALIAS $t / $alias / $transformed")
308
- transformed
309
- else
310
- // println(i"NO ALIAS $t / $alias / $transformed")
311
- recur(t)
312
- case _ =>
313
- recur(t)
314
287
case t @ CapturingType (parent, refs) =>
315
288
checkQualifiedRoots(t.annot.tree) // TODO: NEEDED?
316
289
t.derivedCapturingType(this (parent), refs)
317
290
case t @ AnnotatedType (parent, ann) =>
291
+ val parent1 = this (parent)
318
292
if ann.symbol == defn.RetainsAnnot then
319
- val parent1 = this (parent)
320
293
for tpt <- tptToCheck do
321
294
checkQualifiedRoots(ann.tree)
322
295
checkWellformedLater(parent1, ann.tree, tpt)
323
- CapturingType (parent1, ann.tree.toCaptureSet, boxed = ann.tree.hasAttachment( NeedsBox ) )
296
+ CapturingType (parent1, ann.tree.toCaptureSet)
324
297
else
325
- t.derivedAnnotatedType(this (parent) , ann)
326
- case Box (t1 ) =>
327
- box( this (t1 ))
298
+ t.derivedAnnotatedType(parent1 , ann)
299
+ case throwsAlias(res, exc ) =>
300
+ this (expandThrowsAlias(res, exc, Nil ))
328
301
case t : LazyRef =>
329
302
val t1 = this (t.ref)
330
303
if t1 ne t.ref then t1 else t
331
304
case t : TypeVar =>
332
305
this (t.underlying)
333
- case _ =>
334
- recur(t)
306
+ case t =>
307
+ if t.isCapabilityClassRef
308
+ then CapturingType (t, defn.expandedUniversalSet, boxed = false )
309
+ else recur(t)
335
310
end expandAliases
336
311
337
312
val tp1 = expandAliases(tp) // TODO: Do we still need to follow aliases?
@@ -342,11 +317,11 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
342
317
/** Transform type of type tree, and remember the transformed type as the type the tree */
343
318
private def transformTT (tree : TypeTree , boxed : Boolean , exact : Boolean )(using Context ): Unit =
344
319
if ! tree.hasRememberedType then
345
- val tp = if boxed then Box (tree.tpe) else tree.tpe
346
- tree.rememberType(
320
+ val transformed =
347
321
if tree.isInstanceOf [InferredTypeTree ] && ! exact
348
- then transformInferredType(tp)
349
- else transformExplicitType(tp, tptToCheck = Some (tree)))
322
+ then transformInferredType(tree.tpe)
323
+ else transformExplicitType(tree.tpe, tptToCheck = Some (tree))
324
+ tree.rememberType(if boxed then box(transformed) else transformed)
350
325
351
326
/** Substitute parameter symbols in `from` to paramRefs in corresponding
352
327
* method or poly types `to`. We use a single BiTypeMap to do everything.
0 commit comments