Skip to content

Commit

Permalink
remove linear lookup of lids in gamma_sig
Browse files Browse the repository at this point in the history
  • Loading branch information
nikswamy committed Oct 16, 2024
1 parent 33499bc commit 09f51ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 106 deletions.
91 changes: 14 additions & 77 deletions ocaml/fstar-lib/generated/FStarC_TypeChecker_Env.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 9 additions & 29 deletions src/typechecker/FStarC.TypeChecker.Env.fst
Original file line number Diff line number Diff line change
Expand Up @@ -460,31 +460,15 @@ let lookup_qname env (lid:lident) : qninfo =
if cur_mod <> No
then match BU.smap_try_find (gamma_cache env) (string_of_lid lid) with
| None ->
BU.catch_opt
(BU.find_map env.gamma (function
| Binding_lid(l, (us_names, t)) when lid_equals lid l->
(* A recursive definition.
* We must return the exact set of universes on which
* it is being defined, and not instantiate it.
* TODO: could we cache this? *)
let us = List.map U_name us_names in
Some (Inl (us, t), Ident.range_of_lid l)
| _ -> None))
(fun () -> BU.find_map env.gamma_sig (function
| (_, { sigel = Sig_bundle {ses} }) ->
BU.find_map ses (fun se ->
if lids_of_sigelt se |> BU.for_some (lid_equals lid)
then cache (Inr (se, None), U.range_of_sigelt se)
else None)
| (lids, s) ->
let maybe_cache t = match s.sigel with
| Sig_declare_typ _ -> Some t
| _ -> cache t
in
begin match List.tryFind (lid_equals lid) lids with
| None -> None
| Some l -> maybe_cache (Inr (s, None), Ident.range_of_lid l)
end))
(BU.find_map env.gamma (function
| Binding_lid(l, (us_names, t)) when lid_equals lid l->
(* A recursive definition.
* We must return the exact set of universes on which
* it is being defined, and not instantiate it.
* TODO: could we cache this? *)
let us = List.map U_name us_names in
Some (Inl (us, t), Ident.range_of_lid l)
| _ -> None))
| se -> se
else None
in
Expand Down Expand Up @@ -1791,10 +1775,6 @@ let clear_expected_typ (env_: env): env & option (typ & bool) =
let finish_module =
let empty_lid = lid_of_ids [id_of_text ""] in
fun env m ->
let sigs =
if lid_equals m.name Const.prims_lid
then env.gamma_sig |> List.map snd |> List.rev
else m.declarations in
{env with
curmodule=empty_lid;
gamma=[];
Expand Down

0 comments on commit 09f51ec

Please sign in to comment.