Skip to content

Compiler: no longer split blocks at fun call to propagate location #1407

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

Merged
merged 14 commits into from
Feb 22, 2023

Conversation

hhugo
Copy link
Member

@hhugo hhugo commented Feb 11, 2023

Trying to address https://discuss.ocaml.org/t/dune-build-vs-makefile/11394/9.

It should also help with #1300
and fix #747

@vouillon, the PR is not ready yet but what do you think of this approach ?

@pmwhite, this could improve your compilation time significantly.

@vouillon
Copy link
Member

Maybe we should use this instead of adding a field to every constructors of type instr?

type block =
  { params : Var.t list
  ; body : (instr * loc) list
  ; branch : last * loc
  }

@hhugo
Copy link
Member Author

hhugo commented Feb 13, 2023

Maybe we should use this instead of adding a field to every constructors of type instr?

type block =
  { params : Var.t list
  ; body : (instr * loc) list
  ; branch : last * loc
  }

Yeah, probably. Ill do the change and run a quick benchmark to make sure there performance profile is the same.

@vouillon
Copy link
Member

There is a mismatch between where OCaml put events, and where the JavaScript debuggers might stop. I'm not sure what to do about that.

@hhugo
Copy link
Member Author

hhugo commented Feb 13, 2023

Note that I'm still exploring the design space of this change. I'm not really happy with the mapping between debug event and instructions.

@hhugo
Copy link
Member Author

hhugo commented Feb 13, 2023

Building the toplevel with sourcemaps goes from 37.6s to 28.2s

@hhugo
Copy link
Member Author

hhugo commented Feb 13, 2023

There is a mismatch between where OCaml put events, and where the JavaScript debuggers might stop. I'm not sure what to do about that.

Can you give more details ? are you just referring to the fact debugger is a statement ?

@hhugo
Copy link
Member Author

hhugo commented Feb 14, 2023

I've cleaned up the code a little and recovered few locations that initially disappeared. I'm still trying find a better way to map event to instruction.

@hhugo hhugo requested a review from vouillon February 14, 2023 10:15
@hhugo hhugo marked this pull request as ready for review February 14, 2023 10:15
@hhugo
Copy link
Member Author

hhugo commented Feb 14, 2023

@pmwhite, would you be able to test this and report on both compilation time and size of generated sourcemap.
This PR both add and remove locations. I'd be curious to see if how the size of sourcemap is affected.

@hhugo hhugo added this to the 5.1 milestone Feb 14, 2023
@vouillon vouillon closed this Feb 14, 2023
@vouillon vouillon reopened this Feb 14, 2023
@vouillon
Copy link
Member

There is a mismatch between where OCaml put events, and where the JavaScript debuggers might stop. I'm not sure what to do about that.

Can you give more details ? are you just referring to the fact debugger is a statement ?

What I mean is that when we single-step in a JavaScript we may stop at some locations that do not correspond to OCaml events. For instance, there is no event after an array access a.(x).
So, to build accurate sourcemaps, we need to understand where the JavaScript debuggers expects locations, and where Ocaml inserts events (and what information is provided by each event).

@hhugo
Copy link
Member Author

hhugo commented Feb 14, 2023

The PR seems to fix two issues already

  • remove some completely unrelated location
  • fix a compilation time issue when debug is enabled

Maybe this PR should be only do the right think to existing well understood scenario: events after a call and event before tail calls

@hhugo hhugo force-pushed the fast-sm branch 2 times, most recently from 6139e33 to c630f98 Compare February 15, 2023 01:00
@hhugo
Copy link
Member Author

hhugo commented Feb 15, 2023

@vouillon, can I request another round of review from you ?

@hhugo hhugo force-pushed the fast-sm branch 2 times, most recently from a8fbab9 to 328c6dd Compare February 18, 2023 12:53
@hhugo hhugo merged commit cb62933 into master Feb 22, 2023
@hhugo hhugo deleted the fast-sm branch February 22, 2023 00:57
hhugo pushed a commit to hhugo/opam-repository that referenced this pull request Mar 7, 2023
…s_of_ocaml-ppx_deriving_json, js_of_ocaml-ppx, js_of_ocaml-lwt and js_of_ocaml-compiler (5.1.0)

CHANGES:

## Features/Changes
* Lib: Added support for KeyboardEvent.getModifierState
* Misc: bump min ocaml version to 4.08
* Misc: remove some old runtime files to support some external libs
* Misc: switch to dune 3.7
* Effects: partial CPS transformation, resulting in much better performances, lower compilation time and smaller generated code
* Compiler: separate compilation can now drops unused units when linking (similar to ocamlc). (ocsigen/js_of_ocaml#1378)
* Compiler: specialize string to js-string conversion for all valid utf8 strings (previously just ascii)
* Compiler: JavaScript files generated by `js_of_ocaml` are now UTF-8 encoded.
* Compiler: use identifier for object literals when possible
* Compiler: Cache function arity (the length prop of a function is slow with v8)
* Compiler: The js lexer is now utf8 aware, recognize and emit utf8 ident
* Compiler: Update the js lexer with new number literal syntax
* Compiler: update js parser to support most es6 feature (ocsigen/js_of_ocaml#1391)
* Compiler: stop parsing the builtin js runtime if not necessary
* Compiler: improve js pretty printer (ocsigen/js_of_ocaml#1405)
* Compiler: improve debug location and speedup compilation (ocsigen/js_of_ocaml#1407)
* Toplevel: Enable separate compilation of toplevels
* Runtime: js backtrace recording controled by OCAMLRUNPARAM
* Runtime: support for zstd decompression of marshalled data (ocaml.5.1) (ocsigen/js_of_ocaml#12006)
* Runtime: stub out custom runtime events symbols for OCaml 5.1 (ocsigen/js_of_ocaml#1414)

## Bug fixes
* Effects: fix Js.export and Js.export_all to work with functions (ocsigen/js_of_ocaml#1417,ocsigen/js_of_ocaml#1377)
* Sourcemap: fix incorrect sourcemap with separate compilation
* Compiler: fix control flow analysis; some annotions were wrong in the runtime
* Compiler: js backtrace recording respected in the js runtime and when using effects
* Compiler: no longer fail on invalid source file (when the file is a directory)
* Runtime: fix the compilation of some mutually recursive functions
hhugo pushed a commit to hhugo/opam-repository that referenced this pull request Mar 7, 2023
…s_of_ocaml-ppx_deriving_json, js_of_ocaml-ppx, js_of_ocaml-lwt and js_of_ocaml-compiler (5.1.0)

CHANGES:

## Features/Changes
* Lib: Added support for KeyboardEvent.getModifierState
* Misc: bump min ocaml version to 4.08
* Misc: remove some old runtime files to support some external libs
* Misc: switch to dune 3.7
* Effects: partial CPS transformation, resulting in much better performances, lower compilation time and smaller generated code
* Compiler: separate compilation can now drops unused units when linking (similar to ocamlc). (ocsigen/js_of_ocaml#1378)
* Compiler: specialize string to js-string conversion for all valid utf8 strings (previously just ascii)
* Compiler: JavaScript files generated by `js_of_ocaml` are now UTF-8 encoded.
* Compiler: use identifier for object literals when possible
* Compiler: Cache function arity (the length prop of a function is slow with v8)
* Compiler: The js lexer is now utf8 aware, recognize and emit utf8 ident
* Compiler: Update the js lexer with new number literal syntax
* Compiler: update js parser to support most es6 feature (ocsigen/js_of_ocaml#1391)
* Compiler: stop parsing the builtin js runtime if not necessary
* Compiler: improve js pretty printer (ocsigen/js_of_ocaml#1405)
* Compiler: improve debug location and speedup compilation (ocsigen/js_of_ocaml#1407)
* Toplevel: Enable separate compilation of toplevels
* Runtime: js backtrace recording controled by OCAMLRUNPARAM
* Runtime: support for zstd decompression of marshalled data (ocaml.5.1) (ocsigen/js_of_ocaml#12006)
* Runtime: stub out custom runtime events symbols for OCaml 5.1 (ocsigen/js_of_ocaml#1414)

## Bug fixes
* Effects: fix Js.export and Js.export_all to work with functions (ocsigen/js_of_ocaml#1417,ocsigen/js_of_ocaml#1377)
* Sourcemap: fix incorrect sourcemap with separate compilation
* Compiler: fix control flow analysis; some annotions were wrong in the runtime
* Compiler: js backtrace recording respected in the js runtime and when using effects
* Compiler: no longer fail on invalid source file (when the file is a directory)
* Runtime: fix the compilation of some mutually recursive functions
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.

[BUG] debug locations sometime wrong, affecting sourcemaps
2 participants