Module Checker.Type
the module holding the definition of semantic types, and various operations on them
module L = Location
type typ
=
|
T_Int
|
T_Tuple of typ list
|
T_IBorrow of Location.abstract_loc * typ
|
T_MBorrow of Location.abstract_loc * typ * typ
|
T_Function of typ list * typ
the abstract syntax of semantic types. Note that:
- borrow types are always annotated with a plain
L.abstract_loc
without any path mutable borrow types are of the form
MBorrow(aloc, typ_read, typ_write)
, wheretyp_read
is the type for reading from the mutable borrow, andtyp_write
is the type for writing to the mutable borrow. It should always be the case that:typ_write
is a subtype oftyp_read
typ_read
andtyp_write
have the same shape (differ only in abstract lactions)
- borrow types are always annotated with a plain
type function_typ
=
{
params : typ list;
ret : typ;
constrs : Location.ConstrSet.t;
}
the type of top-level functions
val read_path : L.path -> typ -> Syntax.permission * typ * typ
read_path path typ
select thepath
part of the typetyp
, returning a triple(permission, typ_read, typ_write)
where:permission
is the permission allowed to accesspath
intyp
typ_read
is the type for reading frompath
intyp
typ_write
is the type for writing topath
intyp
val write_path : L.path -> typ -> typ -> typ
val get_borrows : only_toplevel:bool -> typ -> (L.path * Syntax.mutability * L.abstract_loc) Stdlib.Seq.t
get_borrows ~only_toplevel typ
collect and return all borrows intyp
. Every triple(path, mt, aloc)
in the result indicatespath
attyp
is a borrow type (IBorrow
ifmt = Imm
orMBorrow
ifmt = Mut
), with annotated abstract locationaloc
.If
only_toplevel
istrue
, then only borrows types that are not behind another borrow type is returned.
val subtyp : L.ConstrSet.t -> typ -> typ -> L.ConstrSet.t
subtyp cset sub sup
makessub
a sub type ofsup
by adding constraints tocset
, and returns the new constraint set. Ifsub
andsup
don't have the same shape,TypeMismatch
is raised.
val fresh_subtyp : L.ConstrSet.t -> typ -> typ * L.ConstrSet.t
fresh_subtyp cset typ
creates a typetyp'
that is a sub type oftyp
. To maketyp'
a sub type oftyp
, some new constraints are added tocset
and the new constraint set is returned together withtyp'
val fresh_suptyp : L.ConstrSet.t -> typ -> typ * L.ConstrSet.t
fresh_suptyp cset typ
creates a typetyp'
that is a super type oftyp
. To maketyp'
a super type oftyp
, some new constraints are added tocset
and the new constraint set is returned together withtyp'
val smallest_common_suptyp : L.ConstrSet.t -> typ list -> typ * L.ConstrSet.t
smallest_common_suptyp cset typs
creates a typetyp'
that is a super type of every type intyps
. Necessary new constraints are added tocset
and returned together withtyp'
val greatest_common_subtyp : L.ConstrSet.t -> typ list -> typ * L.ConstrSet.t
greatest_common_subtyp cset typs
creates a typetyp'
that is a sub type of every type intyps
. Necessary new constraints are added tocset
and returned together withtyp'
val instantiate_function : L.ConstrSet.t -> function_typ -> typ * L.ConstrSet.t
instantiate_function ctx func_typ
instantiates top-level function typefunc_typ
by substituting every abstract location infunc_typ
with new fresh abstract locations
val from_syntactic_typ : Syntax.typ -> typ
generate a fresh semantic type from a syntactic type