text
stringlengths
0
601k
let eval con = lift_ev @@ Sem . eval con
let eval_tp tp = lift_ev @@ Sem . eval_tp tp
let quote_con tp con = lift_qu @@ Qu . quote_con tp con
let quote_tp tp = lift_qu @@ Qu . quote_tp tp
let quote_sign sign = lift_qu @@ Qu . quote_sign sign
let quote_cut cut = lift_qu @@ Qu . quote_cut cut
let quote_cof cof = lift_qu @@ Qu . quote_cof cof
let quote_dim con = lift_qu @@ Qu . quote_dim con
let trap_conversion_err ( m : unit m ) : [ ` Ok | ` Err of Conversion . Error . t ] m = trap m |>> function | Error ( Conversion . ConversionError err ) -> ret @@ ` Err err | Error exn -> throw exn | Ok _ -> ret ` Ok
let equate tp l r = trap_conversion_err @@ lift_conv_ @@ Conv . equate_con tp l r |>> function | ` Ok -> ret ( ) | ` Err err -> let * env = read in let * ttp = quote_tp tp in let * tl = quote_con tp l in let * tr = quote_con tp r in refine_err @@ Err . ExpectedEqual ( Env . pp_env env , ttp , tl , tr , err )
let equate_tp tp tp ' = trap_conversion_err @@ lift_conv_ @@ Conv . equate_tp tp tp ' |>> function | ` Ok -> ret ( ) | ` Err err -> let * env = read in let * ttp = quote_tp tp in let * ttp ' = quote_tp tp ' in refine_err @@ Err . ExpectedEqualTypes ( Env . pp_env env , ttp , ttp ' , err )
let with_pp k = let * env = read in k @@ Env . pp_env env
let expected_connective conn tp = with_pp @@ fun ppenv -> let * ttp = quote_tp tp in refine_err @@ Err . ExpectedConnective ( conn , ppenv , ttp )
let expected_field sign con lbl = with_pp @@ fun ppenv -> let * tsign = quote_sign sign in refine_err @@ Err . ExpectedField ( ppenv , tsign , con , lbl )
let field_names_mismatch ~ expected ~ actual = refine_err @@ Err . FieldNameMismatches ( expected , actual )
let abstract nm tp k = let rho env = let con = D . mk_var tp @@ Env . size env in Env . append_con nm con tp env in scope rho @@ k @<< get_local 0
let update_span loc = scope @@ Env . set_location loc
module MU = Monad . Util ( RM )
type ( ' a , ' b ) quantifier = ' a -> Ident . t * ( T . var -> ' b ) -> ' b
type ' a telescope = | Bind of Ident . user * ' a * ( T . var -> ' a telescope ) | Done
module GlobalUtil : sig val destruct_cells : Env . cell list -> ( Ident . t * S . tp ) list m val multi_pi : Env . cell list -> S . tp m -> S . tp m val multi_ap : Env . cell bwd -> D . cut -> D . cut struct let rec destruct_cells = function | [ ] -> RM . ret [ ] | cell :: cells -> let ctp , _ = Env . Cell . contents c...
module Probe : sig val probe_chk : string option -> T . Chk . tac -> T . Chk . tac val probe_boundary : T . Chk . tac -> T . Chk . tac -> T . Chk . tac val probe_syn : string option -> T . Syn . tac -> T . Syn . tac struct let print_state lbl tp : unit m = let * env = RM . read in let cells = Env . locals env in RM . g...
module Hole : sig val silent_hole : string option -> T . Chk . tac val unleash_hole : string option -> T . Chk . tac val unleash_syn_hole : string option -> T . Syn . tac struct let assert_hole_possible tp = RM . lift_cmp @@ Sem . whnf_tp_ ~ style ` : UnfoldAll tp |>> function | D . TpDim | D . TpCof | D . TpPrf _ -> l...
module Sub = struct let formation ( tac_base : T . Tp . tac ) ( tac_phi : T . Chk . tac ) ( tac_tm : T . var -> T . Chk . tac ) : T . Tp . tac = T . Tp . rule ~ name " : Sub . formation " @@ let * base = T . Tp . run tac_base in let * vbase = RM . lift_ev @@ Sem . eval_tp base in let * phi = T . Chk . run tac_phi D . T...
module Dim = struct let formation : T . Tp . tac = T . Tp . virtual_rule ~ name " : Dim . formation " @@ RM . ret S . TpDim let dim0 : T . Chk . tac = T . Chk . rule ~ name " : Dim . dim0 " @@ function | D . TpDim -> RM . ret S . Dim0 | tp -> RM . expected_connective ` Dim tp let dim1 : T . Chk . tac = T . Chk . rule ~...
module Cof = struct let formation : T . Tp . tac = T . Tp . virtual_rule ~ name " : Cof . formation " @@ RM . ret S . TpCof let expected_cof = RM . expected_connective ` Cof let eq tac0 tac1 = T . Chk . rule ~ name " : Cof . eq " @@ function | D . TpCof -> let + r0 = T . Chk . run tac0 D . TpDim and + r1 = T . Chk . ru...
module Prf = struct let formation tac_phi = T . Tp . virtual_rule ~ name " : Prf . formation " @@ let + phi = T . Chk . run tac_phi D . TpCof in S . TpPrf phi let intro = T . Chk . brule ~ name " : Prf . intro " @@ function | D . TpPrf phi , _ , _ -> let + ( ) = Cof . assert_true phi in S . Prf | tp , _ , _ -> RM . exp...
module Pi = struct let formation : ( T . Tp . tac , T . Tp . tac ) quantifier = fun tac_base ( nm , tac_fam ) -> T . Tp . rule ~ name " : Pi . formation " @@ let * base = T . Tp . run_virtual tac_base in let * vbase = RM . lift_ev @@ Sem . eval_tp base in let + fam = T . abstract ~ ident : nm vbase @@ fun var -> T . Tp...
module Sg = struct let formation : ( T . Tp . tac , T . Tp . tac ) quantifier = fun tac_base ( nm , tac_fam ) -> T . Tp . rule ~ name " : Sg . formation " @@ let * base = T . Tp . run tac_base in let * vbase = RM . lift_ev @@ Sem . eval_tp base in let + fam = T . abstract ~ ident : nm vbase @@ fun var -> T . Tp . run @...
module Univ = struct let formation : T . Tp . tac = T . Tp . rule ~ name " : Univ . formation " @@ RM . ret S . Univ let univ_tac : string -> ( D . tp -> S . t RM . m ) -> T . Chk . tac = fun nm m -> T . Chk . rule ~ name : nm @@ function | D . Univ -> m D . Univ | tp -> RM . expected_connective ` Univ tp let univ : T ...
module Signature = struct let formation ( tacs : T . Tp . tac telescope ) : T . Tp . tac = let rec form_fields tele = function | Bind ( lbl , tac , tacs ) -> let * tp = T . Tp . run tac in let * vtp = RM . lift_ev @@ Sem . eval_tp tp in T . abstract ~ ident ( : lbl :> Ident . t ) vtp @@ fun var -> form_fields ( Snoc ( ...
module El = struct let formation tac = T . Tp . rule ~ name " : El . formation " @@ let + tm = T . Chk . run tac D . Univ in S . El tm let dest_el tp = match tp with | D . ElStable con -> RM . lift_cmp @@ Sem . unfold_el con | _ -> RM . expected_connective ` El tp let intro tac = T . Chk . brule ~ name " : El . intro "...
module ElV = struct let intro ( tac_part : T . Chk . tac ) ( tac_tot : T . Chk . tac ) : T . Chk . tac = T . Chk . brule ~ name " : ElV . intro " @@ function | D . ElUnstable ( ` V ( r , pcode , code , pequiv ) ) , phi , clo -> let * part = let * tp_part = RM . lift_cmp @@ Sem . splice_tp @@ Splice . con pcode @@ fun p...
module ElHCom = struct let intro ( tac_walls : T . Chk . tac ) ( tac_cap : T . Chk . tac ) : T . Chk . tac = T . Chk . brule ~ name " : ElHCom . intro " @@ function | D . ElUnstable ( ` HCom ( r , r ' , phi , bdy ) ) , psi , psi_clo -> let * twalls = let * tp_walls = RM . lift_cmp @@ Sem . splice_tp @@ Splice . cof phi...
module Structural = struct let lookup_var id : T . Syn . tac = T . Syn . rule ~ name " : Structural . lookup_var " @@ let * res = RM . resolve id in match res with | ` Local ix -> let + tp = RM . get_local_tp ix in S . Var ix , tp | ` Global sym -> let + tp , _ = RM . get_global sym in S . Global sym , tp | ` Unbound -...
module Nat = struct let formation = T . Tp . rule ~ name " : Nat . formation " @@ RM . ret S . Nat let assert_nat = function | D . Nat -> RM . ret ( ) | tp -> RM . expected_connective ` Nat tp let rec int_to_term = function | 0 -> S . Zero | n -> S . Suc ( int_to_term ( n - 1 ) ) let literal n : T . Chk . tac = T . Chk...
module Circle = struct let formation = T . Tp . rule ~ name " : Circle . formation " @@ RM . ret S . Circle let assert_circle = function | D . Circle -> RM . ret ( ) | tp -> RM . expected_connective ` Circle tp let base = T . Chk . rule ~ name " : Circle . base " @@ fun tp -> let + ( ) = assert_circle tp in S . Base le...
module IDMap = Map . Make ( CodeUnitID )
type t = { lib : Bantorra . Manager . library ; unit_id : CodeUnitID . t ; scopes : Global . t Scopes . t ; num_holes : int ; cof_thy : CofThy . Disj . t ; units : CodeUnit . t IDMap . t ; exports : ( Global . t Namespace . t * CofThy . Disj . t ) IDMap . t ; }
let init lib = let unit_id = CodeUnitID . top_level in { lib ; unit_id ; scopes = Scopes . init Scope . empty ; num_holes = 0 ; cof_thy = CofThy . Disj . empty ; units = IDMap . singleton unit_id ( CodeUnit . create unit_id ) ; exports = IDMap . empty ; }
let get_lib st = st . lib
let get_num_holes st = st . num_holes
let inc_num_holes st = { st with num_holes = st . num_holes + 1 }
let modify_scopes f st = { st with scopes = f st . scopes }
let begin_section st = modify_scopes Scopes . begin_ st
let modify_scopes f st = let open Result in let + scopes = f st . scopes in { st with scopes }
let transform_view ~ shadowing pattern = modify_scopes ( Scopes . transform_view ~ shadowing ~ pp : Global . pp pattern )
let transform_export ~ shadowing pattern = modify_scopes ( Scopes . transform_export ~ shadowing ~ pp : Global . pp pattern )
let export_view ~ shadowing pattern = modify_scopes ( Scopes . export_view ~ shadowing ~ pp : Global . pp pattern )
let end_section ~ shadowing ~ prefix = modify_scopes ( Scopes . end_ ~ shadowing ~ prefix )
let get_unit id st = IDMap . find id st . units
let resolve_global id st = Scopes . resolve id st . scopes
let add_global ~ shadowing ident tp ocon st = let open Result in let unit = get_unit st . unit_id st in let ( sym , unit ) = CodeUnit . add_global ident tp ocon unit in let cof_thy = match tp with | D . TpPrf phi -> CofThy . Disj . assume st . cof_thy [ phi ] | _ -> st . cof_thy in let + scopes = Scopes . add ~ shadowi...
let get_global sym st = CodeUnit . get_global sym @@ get_unit ( CodeUnit . origin sym ) st
let get_global_cof_thy st = st . cof_thy
let begin_unit lib unit_id st = { lib ; unit_id ; scopes = Scopes . init Scope . empty ; num_holes = 0 ; cof_thy = CofThy . Disj . empty ; units = IDMap . add unit_id ( CodeUnit . create unit_id ) st . units ; exports = st . exports ; }
let end_unit ~ parent ~ child = { lib = parent . lib ; unit_id = parent . unit_id ; num_holes = parent . num_holes ; scopes = parent . scopes ; cof_thy = parent . cof_thy ; units = child . units ; exports = IDMap . add child . unit_id ( Scopes . export_top child . scopes , child . cof_thy ) child . exports ; }
let import ~ shadowing pat unit_id st = let open Result in let ns , cof_thy = IDMap . find unit_id st . exports in let * ns = Namespace . transform ~ shadowing ~ pp : Global . pp pat ns in let cof_thy = CofThy . Disj . meet2 st . cof_thy cof_thy in let + scopes = Scopes . import ~ shadowing ns st . scopes in { st with ...
let loading_status unit_id st = if IDMap . mem unit_id st . exports then ` Loaded else if IDMap . mem unit_id st . exports then ` Loading else ` Unloaded
module Ocaml_attributes = struct type ( ' a , ' arity , ' b ) typed_attribute_kind += | Attribute_doc : ( ' a , ' arity , string ) typed_attribute_kind end
let print_loc buf ( _ , _ ) = bprintf buf " loc "
let print_list f buf l = bprintf buf " [ " ; List . iter ( fun x -> bprintf buf " % a ; \ n " f x ) l ; bprintf buf " ] "
let print_opt f buf o = match o with None -> bprintf buf " None " | Some x -> bprintf buf " Some ( % a ) " f x
let print_qstring buf s = bprintf buf " % S " s
let print_prop_list buf l = print_list ( fun buf ( s , ( loc , o ) ) -> bprintf buf " ( % S , ( % a , % a ) ) " s print_loc loc ( print_opt print_qstring ) o ) buf l
let print_annot_list buf l = print_list ( fun buf ( s , ( loc , l ) ) -> bprintf buf " ( % S , ( % a , % a ) ) " s print_loc loc print_prop_list l ) buf l
let rec print_type_expr buf ( x : Ast . type_expr ) = match x with | Sum ( loc , variant_list , annot_list ) -> bprintf buf " ` Sum ( % a , % a , % a ) " print_loc loc ( print_list print_variant ) variant_list print_annot_list annot_list | Record ( loc , field_list , annot_list ) -> bprintf buf " ` Record ( % a , % a ,...
let print_module_item buf ( Ast . Type ( loc , ( name , param , a ) , x ) ) = bprintf buf " ` Type ( % a , ( % S , % a , % a ) , % a ) " print_loc loc name ( print_list print_qstring ) param print_annot_list a print_type_expr x
let print_module_body buf l = bprintf buf " [ \ n " ; List . iter ( fun x -> print_module_item buf x ; bprintf buf " ; \ n " ) l ; bprintf buf " ] \ n "
let print_module_body_def buf name l = bprintf buf " \
let % s_body : Ast . module_body = let loc = Ast . dummy_loc in % a
let % s = % s_body " name print_module_body l name name
let print_module_head_def buf name an = bprintf buf " \
let % s_head : Ast . module_head = let loc = Ast . dummy_loc in ( loc , % a ) " name print_annot_list an
let print_full_module_def buf name ( ( _ , an ) , l ) = print_module_head_def buf name an ; print_module_body_def buf name l ; bprintf buf " \
let % s_full : Ast . full_module = ( % s_head , % s_body ) " name name name
module Rule = struct type t = { id : Rule . Id . t ; dir : Path . Build . t ; deps : Dep . Set . t ; expanded_deps : Path . Set . t ; targets : Targets . Validated . t ; context : Build_context . t option ; action : Action . t } end
module Rule_top_closure = Top_closure . Make ( Non_evaluated_rule . Id . Set ) ( Memo )
module rec Expand : sig val alias : Alias . t -> Path . Set . t Memo . t val deps : Dep . Set . t -> Path . Set . t Memo . t let alias = let memo = Memo . create " expand - alias " ~ input ( : module Alias ) ( fun alias -> let * l = Load_rules . get_alias_definition alias >>= Memo . parallel_map ~ f ( : fun ( loc , def...
let evaluate_rule = let memo = Memo . create " evaluate - rule " ~ input ( : module Non_evaluated_rule ) ( fun rule -> let * action , deps = Action_builder . run rule . action Lazy in let * expanded_deps = Expand . deps deps in Memo . return { Rule . id = rule . id ; dir = rule . dir ; deps ; expanded_deps ; targets = ...
let eval ~ recursive ~ request = let rules_of_deps deps = Expand . deps deps >>| Path . Set . to_list >>= Memo . parallel_map ~ f ( : fun p -> Load_rules . get_rule p >>= function | None -> Memo . return None | Some rule -> evaluate_rule rule >>| Option . some ) >>| List . filter_map ~ f : Fun . id in let * ( ) , deps ...
let copyline input output = let rec copy ( ) = match input_char input with | exception End_of_file -> output_string output " < end of file >\ n " | char -> output_char output char ; if char ' =\ n ' then ( ) else copy ( ) in copy ( ) ; flush output
let output_endline output str = output_string output str ; output_char output ' \ n ' ; flush output
let output_env_var output env_var = let value = match Sys . getenv_opt env_var with | None -> " < no such variable " > | Some v -> v in output_endline stdout value
let options = [ ( " - i2o " , Arg . Unit ( fun ( ) -> ( copyline stdin stdout ) ) , " copy one line from stdin to stdout " ) ; ( " - i2e " , Arg . Unit ( fun ( ) -> ( copyline stdin stderr ) ) , " copy one line from stdin to stderr " ) ; ( " - o " , Arg . String ( output_endline stdout ) , " - o < txt > write < txt > p...
let report_bad_argument _arg = output_endline stderr " < bad argument " >
let ( ) = set_binary_mode_in stdin true ; set_binary_mode_out stdout true ; set_binary_mode_out stderr true ; Arg . parse options report_bad_argument " "
type ' a t = ' a list ref
let empty ( ) = ref [ ]
let is_empty x = match ! x with | [ ] -> true | _ -> false
let of_list l = ref l
let to_list rl = ! rl
let copy ~ dst ~ src = dst := ! src
let copy_list ~ dst ~ src = dst := src
let add rl item = rl := List . append ! rl [ item ] item
let push rl item = rl := item ::! rl
let clear rl = rl := [ ]
let length rl = List . length ! rl
let hd rl = try List . hd ! rl with _ -> raise Empty_list
let tl rl = try ref ( List . tl ! rl ) rl with _ -> raise Empty_list