root

dotty.tools.dotc.cc.root
object root

A module defining three kinds of root capabilities

  • cap of kind Global: This is the global root capability. Among others it is used in the types of formal parameters, in type bounds, and in self types. cap does not subsume other capabilities, except in arguments of withCapAsRoot calls.
  • Instances of Fresh(hidden), of kind Fresh. These do subsume other capabilties in scope. They track with hidden sets which other capabilities were subsumed. Hidden sets are inspected by separation checking.
  • Instances of Result(binder), of kind Result. These are existentials associated with the result types of dependent methods. They don't subsume other capabilties.

Representation:

  • cap is just the TermRef scala.caps.cap defined in the caps module
  • Fresh and Result instances are annotated types of scala.caps.cap with a special root.Annot annotation. The symbol of the annotation is annotation.internal.rootCapability. The annotation carries a kind, which provides a hidden set for Fresh instances and a binder method type for Result instances.

Setup:

In the setup phase, cap instances in the result of a dependent function type or method type such as (x: T): C^{cap} are converted to Result(binder) instances, where binder refers to the method type. Most other cap instances are mapped to Fresh instances instead. For example the cap in the result of T => C^{cap} is mapped to a Fresh instance.

If one needs to use a dependent function type yet one still want to map cap to a fresh instance instead an existential root, one can achieve that by the use of a type alias. For instance, the following type creates an existential for ^:

 (x: A) => (C^{x}, D^)

By contrast, this variant creates a fresh instance instead:

 type F[X] = (x: A) => (C^{x}, X)
 F[D^]

The trick is that the argument D^ is mapped to D^{fresh} before the F alias is expanded.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
root.type

Members list

Type members

Classlikes

case class Annot(kind: Kind)(using ictx: Context) extends Annotation

The annotation of a root instance

The annotation of a root instance

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Annotation
trait Showable
class Object
trait Matchable
class Any
Show all
class CapToFresh(owner: Symbol)(using x$2: Context) extends BiTypeMap, FollowAliasesMap

Map each occurrence of cap to a different Fresh instance Exception: CapSet^ stays as it is.

Map each occurrence of cap to a different Fresh instance Exception: CapSet^ stays as it is.

Attributes

Supertypes
trait BiTypeMap
class TypeMap
trait Type => Type
class Object
trait Matchable
class Any
Show all
Self type
object Fresh

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Fresh.type
enum Kind

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Result

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Result.type

Types

The type of fresh references

The type of fresh references

Attributes

The type of existentially bound references

The type of existentially bound references

Attributes

Value members

Concrete methods

def cap(using Context): TermRef
def capToFresh(tp: Type, owner: Symbol)(using Context): Type

Maps cap to fresh

Maps cap to fresh

Attributes

def freshToCap(tp: Type)(using Context): Type

Maps fresh to cap

Maps fresh to cap

Attributes

def printContext(refs: Type | CaptureSet*)(using Context): Context

If refs contains an occurrence of cap or cap.rd, the current context with an added property PrintFresh. This addition causes all occurrences of Fresh to be printed as fresh instead of cap, so that one avoids confusion in error messages.

If refs contains an occurrence of cap or cap.rd, the current context with an added property PrintFresh. This addition causes all occurrences of Fresh to be printed as fresh instead of cap, so that one avoids confusion in error messages.

Attributes

def resultToFresh(tp: Type)(using Context): Type

Map top-level free existential variables one-to-one to Fresh instances

Map top-level free existential variables one-to-one to Fresh instances

Attributes

def toResult(tp: Type, mt: MethodType, fail: Message => Unit)(using Context): Type

Replace all occurrences of cap (or fresh) in parts of this type by an existentially bound variable bound by mt. Stop at function or method types since these have been mapped before.

Replace all occurrences of cap (or fresh) in parts of this type by an existentially bound variable bound by mt. Stop at function or method types since these have been mapped before.

Attributes

def toResultInResults(fail: Message => Unit, keepAliases: Boolean)(using Context): TypeMap

Map global roots in function results to result roots

Map global roots in function results to result roots

Attributes

def unapply(root: CaptureRef)(using Context): Option[Kind]