Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework global state #1059

Merged
merged 5 commits into from
Nov 25, 2019
Merged

Rework global state #1059

merged 5 commits into from
Nov 25, 2019

Conversation

let-def
Copy link
Contributor

@let-def let-def commented Nov 20, 2019

This changes the way state from the compiler is managed.
It now mimics a much simpler form of dynamic-scoping were bindings cannot be nested and there is a unique "binding point" that snapshots the whole compiler state.

If this doesn't break the cache (in correctness nor performance), it will help further changes (path management that @trefis worked on) and can be the basis of a hypothetical upstreaming of state management.

@trefis trefis changed the base branch from master to initial_env November 20, 2019 10:58
src/kernel/mpipeline.ml Outdated Show resolved Hide resolved

let new_bindings () =
{ refs = [] }
let is_bound = ref false in
{ refs = [F (is_bound, (fun () -> true))]; is_bound }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset (new_bindings ()) sets is_bound to true. I don't understand why.


type typer_state = Local_store.scope

let bound = srefk None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code would be slightly easier to read if this was named current_state.

@@ -29,7 +29,7 @@ module Cache = struct
in
match List.assoc key !cache with
| state ->
cache := List.remove_assoc key !cache;
cache := (key, state) :: List.remove_assoc key !cache;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I can see for doing this is "it's going to be quicker to access next time".
If that's the case, let's perhaps put a comment saying that before the line.

But also: the list seems be limited to a length of 6; is the change really worth it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a quick'n'dirty implementation of a LRU (least recently used) cache: we cache the last 6 recently used instances of the typechecker.

If we didn't move the state to the head of the list, that would implement another caching policy... 🤷‍♂️

@let-def
Copy link
Contributor Author

let-def commented Nov 22, 2019

I implemented the changes you suggested.

I also added a check that we don't create new references after an instance has been created.

@trefis trefis merged commit fb57d0b into initial_env Nov 25, 2019
let-def added a commit to let-def/opam-repository that referenced this pull request Nov 29, 2019
CHANGES:

Fri Nov 29 17:35:58 CET 2019

  + backend
    - support OCaml 4.09 (ocaml/merlin#1055)
    - fix parse errors in 4.08 (ocaml/merlin#1037)
    - update 4.08 support to OCaml 4.08.1 (ocaml/merlin#1053)
    - support `without_cmis`
    - separate reading from caching in file-cache, use caching in
      `Env.check_state_consistency` (ocaml/merlin#1044)
    - simplify compiler state management (ocaml/merlin#1056, ocaml/merlin#1059)
    - fix creation of initial environment, improve compatibility with
      upstream 4.08 (ocaml/merlin#1052)
  + frontend
    - code re-organization (ocaml/merlin#1042)
    - error command: select which kind of errors to show (ocaml/merlin#995)
    - print value types in outline (ocaml/merlin#1014)
    - fix process handling in windows (ocaml/merlin#1005)
  + editor modes
    - emacs
      + bugfixes in merlin-imenu, merlin-xref (ocaml/merlin#1000, ocaml/merlin#1021, ocaml/merlin#1001)
      + show types in merlin-imenu (ocaml/merlin#1013)
      + reset buffer local configurations when resetting server (ocaml/merlin#1004)
      + remove merlin-use-tuareg-imenu
      + fix stack overflow (ocaml/merlin#1024)
      + fix merlin-occurrence (ocaml/merlin#1043)
    - vim
      + display warn-error warnings as errors (ocaml/merlin#1009)
  + testsuite
    - cover file-cache and `check_state_consistency` (ocaml/merlin#1044)
    - check inconsistent assumptions, test server versus single modes (ocaml/merlin#1047)
let-def added a commit to let-def/opam-repository that referenced this pull request Mar 2, 2020
CHANGES:

Fri Nov 29 17:35:58 CET 2019

  + backend
    - support OCaml 4.09 (ocaml/merlin#1055)
    - fix parse errors in 4.08 (ocaml/merlin#1037)
    - update 4.08 support to OCaml 4.08.1 (ocaml/merlin#1053)
    - support `without_cmis`
    - separate reading from caching in file-cache, use caching in
      `Env.check_state_consistency` (ocaml/merlin#1044)
    - simplify compiler state management (ocaml/merlin#1056, ocaml/merlin#1059)
    - fix creation of initial environment, improve compatibility with
      upstream 4.08 (ocaml/merlin#1052)
  + frontend
    - code re-organization (ocaml/merlin#1042)
    - error command: select which kind of errors to show (ocaml/merlin#995)
    - print value types in outline (ocaml/merlin#1014)
    - fix process handling in windows (ocaml/merlin#1005)
  + editor modes
    - emacs
      + bugfixes in merlin-imenu, merlin-xref (ocaml/merlin#1000, ocaml/merlin#1021, ocaml/merlin#1001)
      + show types in merlin-imenu (ocaml/merlin#1013)
      + reset buffer local configurations when resetting server (ocaml/merlin#1004)
      + remove merlin-use-tuareg-imenu
      + fix stack overflow (ocaml/merlin#1024)
      + fix merlin-occurrence (ocaml/merlin#1043)
    - vim
      + display warn-error warnings as errors (ocaml/merlin#1009)
  + testsuite
    - cover file-cache and `check_state_consistency` (ocaml/merlin#1044)
    - check inconsistent assumptions, test server versus single modes (ocaml/merlin#1047)
@trefis trefis deleted the rework-global-state branch January 29, 2021 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants