Module Checker.Type
the module holding the definition of semantic types, and various operations on them
module L = Locationtype 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 * typthe abstract syntax of semantic types. Note that:
- borrow types are always annotated with a plain
L.abstract_locwithout any path mutable borrow types are of the form
MBorrow(aloc, typ_read, typ_write), wheretyp_readis the type for reading from the mutable borrow, andtyp_writeis the type for writing to the mutable borrow. It should always be the case that:typ_writeis a subtype oftyp_readtyp_readandtyp_writehave 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 * typread_path path typselect thepathpart of the typetyp, returning a triple(permission, typ_read, typ_write)where:permissionis the permission allowed to accesspathintyptyp_readis the type for reading frompathintyptyp_writeis the type for writing topathintyp
val write_path : L.path -> typ -> typ -> typval get_borrows : only_toplevel:bool -> typ -> (L.path * Syntax.mutability * L.abstract_loc) Stdlib.Seq.tget_borrows ~only_toplevel typcollect and return all borrows intyp. Every triple(path, mt, aloc)in the result indicatespathattypis a borrow type (IBorrowifmt = ImmorMBorrowifmt = Mut), with annotated abstract locationaloc.If
only_toplevelistrue, then only borrows types that are not behind another borrow type is returned.
val subtyp : L.ConstrSet.t -> typ -> typ -> L.ConstrSet.tsubtyp cset sub supmakessuba sub type ofsupby adding constraints tocset, and returns the new constraint set. Ifsubandsupdon't have the same shape,TypeMismatchis raised.
val fresh_subtyp : L.ConstrSet.t -> typ -> typ * L.ConstrSet.tfresh_subtyp cset typcreates a typetyp'that is a sub type oftyp. To maketyp'a sub type oftyp, some new constraints are added tocsetand the new constraint set is returned together withtyp'
val fresh_suptyp : L.ConstrSet.t -> typ -> typ * L.ConstrSet.tfresh_suptyp cset typcreates a typetyp'that is a super type oftyp. To maketyp'a super type oftyp, some new constraints are added tocsetand the new constraint set is returned together withtyp'
val smallest_common_suptyp : L.ConstrSet.t -> typ list -> typ * L.ConstrSet.tsmallest_common_suptyp cset typscreates a typetyp'that is a super type of every type intyps. Necessary new constraints are added tocsetand returned together withtyp'
val greatest_common_subtyp : L.ConstrSet.t -> typ list -> typ * L.ConstrSet.tgreatest_common_subtyp cset typscreates a typetyp'that is a sub type of every type intyps. Necessary new constraints are added tocsetand returned together withtyp'
val instantiate_function : L.ConstrSet.t -> function_typ -> typ * L.ConstrSet.tinstantiate_function ctx func_typinstantiates top-level function typefunc_typby substituting every abstract location infunc_typwith new fresh abstract locations
val from_syntactic_typ : Syntax.typ -> typgenerate a fresh semantic type from a syntactic type