Skip to content

Commit

Permalink
coalesce top-level definitions into a map for faster lookup during de…
Browse files Browse the repository at this point in the history
…sugaring (avoiding linear scan)
  • Loading branch information
nikswamy committed Oct 18, 2024
1 parent 7132657 commit bccb5d6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
44 changes: 31 additions & 13 deletions ocaml/fstar-lib/generated/FStarC_Syntax_DsEnv.ml

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

15 changes: 11 additions & 4 deletions src/syntax/FStarC.Syntax.DsEnv.fst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type scope_mod =
| Rec_binding of rec_binding
| Module_abbrev of module_abbrev
| Open_module_or_namespace of open_module_or_namespace
| Top_level_def of ident (* top-level definition for an unqualified identifier x to be resolved as curmodule.x. *)
| Top_level_defs of BU.psmap bool (* top-level definition for an unqualified identifier x to be resolved as curmodule.x. *)
| Record_or_dc of record_or_dc (* to honor interleavings of "open" and record definitions *)

type string_set = RBSet.t string
Expand Down Expand Up @@ -320,8 +320,8 @@ let try_lookup_id''
| None -> Cont_ignore
| Some id -> find_in_module_with_includes eikind find_in_module Cont_ignore env ns id)

| Top_level_def id'
when string_of_id id' = string_of_id id ->
| Top_level_defs ids
when Some? (BU.psmap_try_find ids (string_of_id id)) ->
(* indicates a global definition shadowing previous
"open"s. If the definition is not actually found by the
[lookup_default_id] finder, then it may mean that we are in a
Expand Down Expand Up @@ -1027,12 +1027,19 @@ let push_sigelt' fail_on_dup env s =
let env, lss = match s.sigel with
| Sig_bundle {ses} -> env, List.map (fun se -> (lids_of_sigelt se, se)) ses
| _ -> env, [lids_of_sigelt s, s] in
let push_top_level_def id stack =
match stack with
| Top_level_defs ids :: rest ->
Top_level_defs (BU.psmap_add ids (string_of_id id) true) :: rest
| _ ->
Top_level_defs (BU.psmap_add (BU.psmap_empty()) (string_of_id id) true) :: stack
in
lss |> List.iter (fun (lids, se) ->
lids |> List.iter (fun lid ->
(* the identifier is added into the list of global
declarations, to allow shadowing of definitions that were
formerly reachable by previous "open"s. *)
let () = globals := Top_level_def (ident_of_lid lid) :: !globals in
let () = globals := push_top_level_def (ident_of_lid lid) !globals in
(* the identifier is added into the list of global identifiers
of the corresponding module to shadow any "include" *)
let modul = string_of_lid (lid_of_ids (ns_of_lid lid)) in
Expand Down

0 comments on commit bccb5d6

Please sign in to comment.