@@ -210,41 +210,6 @@ Expansion of ^:
210
210
*/
211
211
object Existential :
212
212
213
- type CarrierOLD = RefinedType
214
-
215
- def unapply (tp : CarrierOLD )(using Context ): Option [(TermParamRef , Type )] =
216
- tp.refinedInfo match
217
- case mt : MethodType
218
- if isExistentialMethodOLD(mt) && defn.isNonRefinedFunction(tp.parent) =>
219
- Some (mt.paramRefs.head, mt.resultType)
220
- case _ => None
221
-
222
- /** Create method type in the refinement of an existential type */
223
- private def exMethodTypeOLD (using Context )(
224
- mk : TermParamRef => Type ,
225
- boundName : TermName = ExistentialBinderName .fresh()
226
- ): MethodType =
227
- MethodType (boundName :: Nil )(
228
- mt => defn.Caps_Exists .typeRef :: Nil ,
229
- mt => mk(mt.paramRefs.head))
230
-
231
- /** Create existential */
232
- def applyOLD (mk : TermParamRef => Type )(using Context ): Type =
233
- exMethodTypeOLD(mk).toFunctionType(alwaysDependent = true )
234
-
235
- /** The (super-) type of existentially bound references */
236
- type VarOLD = AnnotatedType
237
-
238
- /** An extractor for existentially bound references of the form ex @existential
239
- * where ex is a TermParamRef of type Exists
240
- */
241
- object VarOLD :
242
- def apply (boundVar : TermParamRef )(using Context ): VarOLD =
243
- AnnotatedType (boundVar, Annotation (defn.ExistentialAnnot , NoSpan ))
244
- def unapply (tp : VarOLD )(using Context ): Option [TermParamRef ] = tp match
245
- case AnnotatedType (bv : TermParamRef , ann) if ann.symbol == defn.ExistentialAnnot => Some (bv)
246
- case _ => None
247
-
248
213
/** The (super-) type of existentially bound references */
249
214
type Vble = AnnotatedType
250
215
@@ -260,44 +225,6 @@ object Existential:
260
225
case _ => None
261
226
case _ => None
262
227
263
- /** Create existential if bound variable appears in result of `mk` */
264
- def wrapOLD (mk : TermParamRef => Type )(using Context ): Type =
265
- val mt = exMethodTypeOLD(mk)
266
- if mt.isResultDependent then mt.toFunctionType() else mt.resType
267
-
268
- extension (tp : CarrierOLD )
269
- def derivedExistentialTypeOLD (core : Type )(using Context ): Type = tp match
270
- case Existential (boundVar, unpacked) =>
271
- if core eq unpacked then tp
272
- else applyOLD(bv => core.substParam(boundVar, bv))
273
- case _ =>
274
- core
275
-
276
- /** Map existentially bound references referring to `boundVar` one-to-one
277
- * to Fresh instances (OLD)
278
- */
279
- def boundVarToCapOLD (boundVar : TermParamRef , tp : Type )(using Context ) =
280
- val subst = new IdempotentCaptRefMap :
281
- val seen = EqHashMap [Annotation , CaptureRef ]()
282
- def apply (t : Type ): Type = t match
283
- case t @ VarOLD (`boundVar`) =>
284
- seen.getOrElseUpdate(t.annot, Fresh (NoSymbol ))
285
- case _ =>
286
- mapOver(t)
287
- subst(tp)
288
-
289
- /** Map existentially bound references referring to `boundVar` one-to-one
290
- * to Fresh instances
291
- */
292
- def toCapOLD (tp : Type )(using Context ): Type = tp.dealiasKeepAnnots match
293
- case Existential (boundVar, unpacked) => // (OLD)
294
- boundVarToCapOLD(boundVar, unpacked)
295
- case tp1 @ CapturingType (parent, refs) =>
296
- tp1.derivedCapturingType(toCap(parent), refs)
297
- case tp1 @ AnnotatedType (parent, ann) =>
298
- tp1.derivedAnnotatedType(toCap(parent), ann)
299
- case _ => tp
300
-
301
228
/** Map top-level free existential variables one-to-one to Fresh instances */
302
229
def toCap (tp : Type , deep : Boolean = false )(using Context ): Type =
303
230
val subst = new IdempotentCaptRefMap :
@@ -320,26 +247,8 @@ object Existential:
320
247
case _ =>
321
248
mapOver(t)
322
249
323
- if ccConfig.newScheme then subst(tp)
324
- else toCapOLD(tp)
325
-
326
- /** Map existentials at the top-level and in all nested result types to `Fresh`
327
- */
328
- def toCapDeeplyOLD (tp : Type )(using Context ): Type = tp.dealiasKeepAnnots match
329
- case Existential (boundVar, unpacked) =>
330
- toCapDeeplyOLD(boundVarToCapOLD(boundVar, unpacked))
331
- case tp1 @ FunctionOrMethod (args, res) =>
332
- val tp2 = tp1.derivedFunctionOrMethod(args, toCapDeeplyOLD(res))
333
- if tp2 ne tp1 then tp2 else tp
334
- case tp1 @ CapturingType (parent, refs) =>
335
- tp1.derivedCapturingType(toCapDeeplyOLD(parent), refs)
336
- case tp1 @ AnnotatedType (parent, ann) =>
337
- tp1.derivedAnnotatedType(toCapDeeplyOLD(parent), ann)
338
- case _ => tp
339
-
340
- def toCapDeeply (tp : Type )(using Context ): Type =
341
- if ccConfig.newScheme then toCap(tp, deep = true )
342
- else toCapDeeplyOLD(tp)
250
+ subst(tp)
251
+ end toCap
343
252
344
253
/** Knowing that `tp` is a function type, is it an alias to a function other
345
254
* than `=>`?
@@ -348,75 +257,6 @@ object Existential:
348
257
case AppliedType (tycon, _) => ! defn.isFunctionSymbol(tycon.typeSymbol)
349
258
case _ => false
350
259
351
- /** Replace all occurrences of `cap` (or fresh) in parts of this type by an existentially bound
352
- * variable. If there are such occurrences, or there might be in the future due to embedded
353
- * capture set variables, create an existential with the variable wrapping the type.
354
- * Stop at function or method types since these have been mapped before.
355
- */
356
- def mapCapOLD (tp : Type , fail : Message => Unit )(using Context ): Type =
357
- var needsWrap = false
358
-
359
- abstract class CapMap extends BiTypeMap :
360
- override def mapOver (t : Type ): Type = t match
361
- case t @ FunctionOrMethod (args, res) if variance > 0 && ! isAliasFun(t) =>
362
- t // `t` should be mapped in this case by a different call to `mapCap`.
363
- case Existential (_, _) =>
364
- t
365
- case t : (LazyRef | TypeVar ) =>
366
- mapConserveSuper(t)
367
- case _ =>
368
- super .mapOver(t)
369
-
370
- class Wrap (boundVar : TermParamRef ) extends CapMap :
371
- private val seen = EqHashMap [CaptureRef , VarOLD ]()
372
-
373
- def apply (t : Type ) = t match
374
- case t : CaptureRef if t.isCapOrFresh =>
375
- if variance > 0 then
376
- needsWrap = true
377
- seen.getOrElseUpdate(t, VarOLD (boundVar))
378
- else
379
- if variance == 0 then
380
- fail(em """ $tp captures the root capability `cap` in invariant position """ )
381
- // we accept variance < 0, and leave the cap as it is
382
- super .mapOver(t)
383
- case t @ CapturingType (parent, refs : CaptureSet .Var ) =>
384
- if variance > 0 then needsWrap = true
385
- super .mapOver(t)
386
- case defn.FunctionNOf (args, res, contextual) if t.typeSymbol.name.isImpureFunction =>
387
- if variance > 0 then
388
- needsWrap = true
389
- super .mapOver:
390
- defn.FunctionNOf (args, res, contextual)
391
- .capturing(VarOLD (boundVar).singletonCaptureSet)
392
- else mapOver(t)
393
- case _ =>
394
- mapOver(t)
395
- // .showing(i"mapcap $t = $result")
396
-
397
- lazy val inverse = new BiTypeMap :
398
- def apply (t : Type ) = t match
399
- case t @ VarOLD (`boundVar`) =>
400
- // do a reverse getOrElseUpdate on `seen` to produce the
401
- // `Fresh` assosicated with `t`
402
- val it = seen.iterator
403
- var ref : CaptureRef | Null = null
404
- while it.hasNext && ref == null do
405
- val (k, v) = it.next
406
- if v.annot eq t.annot then ref = k
407
- if ref == null then
408
- ref = Fresh (NoSymbol )
409
- seen(ref) = t
410
- ref
411
- case _ => mapOver(t)
412
- def inverse = Wrap .this
413
- override def toString = " Wrap.inverse"
414
- end Wrap
415
-
416
- val wrapped = applyOLD(Wrap (_)(tp))
417
- if needsWrap then wrapped else tp
418
- end mapCapOLD
419
-
420
260
/** Replace all occurrences of `cap` (or fresh) in parts of this type by an existentially bound
421
261
* variable bound by `mt`.
422
262
* Stop at function or method types since these have been mapped before.
@@ -486,37 +326,13 @@ object Existential:
486
326
else t
487
327
case t : MethodType if variance > 0 && t.isFreshBinder =>
488
328
val t1 = mapOver(t).asInstanceOf [MethodType ]
489
- t1.derivedLambdaType(resType =
490
- if ccConfig.newScheme then mapCap(t1.resType, t1, fail)
491
- else mapCapOLD(t1.resType, fail))
329
+ t1.derivedLambdaType(resType = mapCap(t1.resType, t1, fail))
492
330
case CapturingType (parent, refs) =>
493
331
t.derivedCapturingType(this (parent), refs)
494
- case Existential (_, _) =>
495
- t
496
332
case t : (LazyRef | TypeVar ) =>
497
333
mapConserveSuper(t)
498
334
case _ =>
499
335
mapFollowingAliases(t)
500
336
end mapCapInResults
501
337
502
- /** Is `mt` a method represnting an existential type when used in a refinement? */
503
- def isExistentialMethodOLD (mt : TermLambda )(using Context ): Boolean = mt.paramInfos match
504
- case (info : TypeRef ) :: rest => info.symbol == defn.Caps_Exists && rest.isEmpty
505
- case _ => false
506
-
507
- /** Is `ref` a TermParamRef representing existentially bound variables? */
508
- def isBinderOLD (ref : CaptureRef )(using Context ) = ref match
509
- case ref : TermParamRef => isExistentialMethodOLD(ref.binder)
510
- case _ => false
511
-
512
- /** An value signalling an out-of-scope existential that should
513
- * lead to a compare failure.
514
- */
515
- def badExistentialOLD (using Context ): TermParamRef =
516
- exMethodTypeOLD(identity, nme.OOS_EXISTENTIAL ).paramRefs.head
517
-
518
- def isBadExistentialOLD (ref : CaptureRef ) = ref match
519
- case ref : TermParamRef => ref.paramName == nme.OOS_EXISTENTIAL
520
- case _ => false
521
-
522
338
end Existential
0 commit comments