Skip to content

Conversation

@hhugo
Copy link
Member

@hhugo hhugo commented Nov 2, 2022

Currently

--toplevel and --dynlink are very similar and should probably be merged or at least refactored and documented better.

Runtime files toplevel.js and dynlink.js are always necessary when building a toplevel or using Dynlink.
These files could be added to the default runtime or added automatically when --toplevel is used.

  • --toplevel alone is equivalent to --toplevel --dynlink. It is necessary for building a toplevel or using the Dynlink module.
    • It exports the jsoo runtime (forcing --linkall), into a jsoo_runtime js object
    • It makes sure that all toplevel modules are exported.
    • It exports a bunch of values to be used by the toplevel/dynlink runtime (prim_count, SYMB and PRIM bytecode sections, ..)
    • It embed cmis into the jsoo in-memory filesystem.
  • --dynlink alone has a very limited usage. It can be used to dynlink jsoo-generated js files without having to include the toplevel/dynlink logic.
    • It exports the jsoo runtime (forcing --linkall), into a jsoo_runtime js object
    • It makes sure that all toplevel modules are exported.

This PR

  • toplevel runtimes files added automatically when needed (partially address [BUG] Instructions for compiling toplevels ? #1299)
  • repurpose the --dynlink flags to perform the necessary steps for using the Dynlink module
  • change the semantic of --linkall to export all compilation units in addition to runtime primitives

Also:

  • move initialization of Toplevel and Dynlink inside js_of_ocaml-compiler.dynlink
  • add more example for --linkall, --dynlink and --toplevel
  • update the dynlink example to not depend on js_of_ocaml-toplevel

@dbuenzli
Copy link
Contributor

dbuenzli commented Nov 2, 2022

Well if it's always possible to figure out when these are needed you can forget about my comment about defining libraries for them in #1323

@hhugo hhugo force-pushed the cleanup-toplevel branch 3 times, most recently from eed36ad to 6b96bae Compare November 7, 2022 15:32
@hhugo hhugo changed the title Compiler: toplevel runtimes files added automatically when needed Compiler: toplevel and dynlink, some cleanup Nov 7, 2022
@hhugo
Copy link
Member Author

hhugo commented Nov 7, 2022

@dbuenzli, this PR contains small refactoring, some documentation and example regarding the compilation of toplevel and Dynlink. review welcome.

Copy link
Contributor

@dbuenzli dbuenzli left a comment

Choose a reason for hiding this comment

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

At the moment the whole thing got me rather confused. I think it's partly due to the fact that I don't think that dynlink is what I thought it was (i.e. it's not about the Dynlink module). I think it would be good to make it clearer what these things are.

@hhugo hhugo force-pushed the cleanup-toplevel branch 5 times, most recently from 3fe911f to 63e2e7e Compare November 8, 2022 10:18
@hhugo
Copy link
Member Author

hhugo commented Nov 10, 2022

@dbuenzli, do you have more to comment on this PR ?

@hhugo hhugo merged commit 8464de2 into master Nov 14, 2022
@hhugo hhugo deleted the cleanup-toplevel branch November 14, 2022 12:11
hhugo added a commit that referenced this pull request Nov 14, 2022
This logic was broken due to #1324
which made the it run before the toplevel/dynlink was initialized.

These generated primitives where never used in practice because the generated
code always uses jsoo_runtime to access primitives.
#480
hhugo added a commit that referenced this pull request Nov 14, 2022
This logic was broken due to #1324
which made the it run before the toplevel/dynlink was initialized.

These generated primitives where never used in practice because the generated
code always uses jsoo_runtime to access primitives.
#480
hhugo pushed a commit to hhugo/opam-repository that referenced this pull request Nov 15, 2022
…s_of_ocaml-ppx_deriving_json, js_of_ocaml-ppx, js_of_ocaml-lwt and js_of_ocaml-compiler (4.1.0)

CHANGES:

## Features/Changes
* Compiler: initial support for OCaml 5 (ocsigen/js_of_ocaml#1265,ocsigen/js_of_ocaml#1303)
* Compiler: bump magic number to match the 5.0.0~alpha0 release (ocsigen/js_of_ocaml#1288)
* Compiler: complain when runtime and compiler built-in primitives disagree (ocsigen/js_of_ocaml#1312)
* Compiler: more efficient implementation of Js_traverse.freevar
* Compiler: more efficient implementation of Js_traverse.rename_variable
* Compiler: --linkall now export all compilation units in addition to primitives (ocsigen/js_of_ocaml#1324)
* Compiler: improve --dynlink, one no longer need to pass --toplevel to use Dynlink (ocsigen/js_of_ocaml#1324)
* Compiler: toplevel runtime files "+toplevel.js" and "+dynlink.js" are added automatically (ocsigen/js_of_ocaml#1324)
* Misc: switch to cmdliner.1.1.0
* Misc: remove old binaries jsoo_link, jsoo_fs
* Misc: remove uchar dep
* Misc: use 4.14 in the CI
* Misc: switch to dune 3
* Lib: add missing options for Intl.DateTimeFormat
* Lib: add missing options for Intl.NumberFormat
* Lib: wheel event binding
* Lib: add normalize in js_string (ES6)
* Lib: more complete transition event bindings
* Lib: remove support for old browser-specific transition events
* Runtime: Implement weak semantic for weak and ephemeron
* Runtime: Implement Gc.finalise_last
* Runtime: Implement buffer for in_channels
* Runtime: add support for unix_opendir, unix_readdir, unix_closedir, win_findfirst, win_findnext, win_findclose
* Runtime: Dont use require when target-env is browser
* Runtime: Implements Parsing.set_trace (ocsigen/js_of_ocaml#1308)
* Test: track external used in the stdlib and unix

## Bug fixes
* Compiler: fix quadratic behavior of dominance frontier (fix ocsigen/js_of_ocaml#1300)
* Compiler: fix rewriter bug in share_constant (fix ocsigen/js_of_ocaml#1247)
* Compiler: fix miscompilation of mutually recursive functions in loop (ocsigen/js_of_ocaml#1321)
* Compiler: fix bug while minifying/renaming try-catch blocks
* Compiler: no dead code elimination for caml_js_get
* Runtime: fix ocamlyacc parse engine (ocsigen/js_of_ocaml#1307)
* Runtime: fix Out_channel.is_buffered, set_buffered
* Runtime: fix format wrt alternative
* Runtime: fix Digest.channel
* Runtime: sync channel seek / pos with the native runtime
* Misc: fix installation with dune 3 without opam
* Node: Only write small chunks to stdout/stderr so they flush
* Deriving: fix for nested polymorphic variants
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.

3 participants