Repository navigation
Conversation
jfrolich
force-pushed
the
macros-repl
branch
from
November 12, 2026 21:06
17b931b to
b216421
Compare
Why:
The engine was asked for the module that is the first part of the
name at the use. That is not the file of the macro when the name goes
through an alias (`module D = Debug`, then `%D.dbg(x)`) or names a
module of an opened file: the macro was reported as needing a module
that is not available at compile time.
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
A loop compiles each input as a file of its own with the earlier inputs opened (`CompilerOptions::open_modules`), and runs its JavaScript once. The module `repl` adds the two things a compilation did not give: - `repl::prepare` binds a last item that is an expression to `it`, and lists the top-level opens, which the loop keeps open. - With `capture_intermediates`, the result has `signature_description`: every item the file defines as an interface declares it, and for a value the run-time shape of its type. A JavaScript value does not say what it is in ReScript (`Some(3)` is `3`, a constructor with a payload an object tagged `TAG`); the shape does. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
`engine.replStart` and `engine.replEval` keep a session: an input is the file `Repl<n>.res`, compiled by the new `compile_input` with the files of the earlier inputs opened, and run once. What it defined is printed with its type and its value, written as the ReScript that makes it (`src/repl-format.js`, by the shape the compiler gives). An input can await at the top level, an open stays open, a diagnostic is shown for the input as it was written, and an input that raises defines nothing. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
The block between `<!-- repl -->` and `<!-- /repl -->` of the RFC is a session: Enter runs an input (or continues one that is not finished), the arrows walk the earlier inputs, and each answer can show the expansion and the JavaScript of its input. The macro modules of the examples and the standard library are loaded. It opens with a session that was run when the site was built (`examples/repl.json`), so the page reads without the compiler; the compiler runs that session again when it is loaded. The loop has a worker of its own: an input that does not end is stopped after 20 seconds without stopping the examples. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
The RFC shows the opening session of the read-eval-print loop as text. `npm run smoke` runs that session and the inputs the page offers, and fails when the text is not what the loop says. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Why:
The loop was the first part of the tour, three screens down, and was
missed. It is now the section "Try it" before "Why", the header has a
link "REPL" to it, and the title has a chip that goes there. The
section that says how to build the site is "Building it".
A link to a heading from another page is followed once the page has
rendered: the heading does not exist before that.
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
`%Sql.query` of the database example reads schema.sql in a session too: the last input the loop offers defines a module with the type of the rows and a function with a labelled argument per parameter. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
The compiler has no completion of its own. `src/complete.js` gets what can be written at a place by compiling small files: - the members of a module are what a file `include Path` defines; - the names in scope are what the file up to the item being written defines, with the members of what it opens; - the type of the expression before a `.` or a `->` is what the compiler says it has when the expression is given a type it cannot have, in its place. Function parameters and other local names have their types that way. The type gives the fields of a record, and for a pipe the functions that take it first. After `%` and `@` a module offers what returns code, a type, a pattern or declarations. `engine.complete` answers for an input of a session and for a file of a project; `npm run smoke` asks for the completions listed in `examples/repl.json`. The file up to the item being written is compiled as a module with a new name each time it changes: the compiler keeps what it knows of a module given in `open_modules` by its name. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
The input of the read-eval-print loop, the editors of the examples and the editor of the playground offer what the compiler says can be written (`engine.complete`): members of a module, fields of a record, functions for a pipe, macros after `%` and `@`, and the names in scope. In the loop Enter and the arrows stay the loop's: with the list open they choose from it, and Enter runs the input when the chosen completion is what is written already. Tab takes a completion everywhere. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Why:
Every input had a console of its own, which stopped collecting when
the input finished. A function of an earlier input kept that console,
so what it printed when a later input called it was shown as late
output, below the answer of the input, or not with it at all.
Before:
> let shout = text => Console.log(text ++ "!")
let shout: string => unit = <fun>
> shout("hi")
- : unit = ()
hi!
After:
> shout("hi")
hi!
- : unit = ()
A session has one console. What is printed while an input runs is that
input's output; what is printed between inputs (a timer, a promise) is
still shown on a line of its own.
The names of the input modules are not used a second time by a later
session of the same compiler instance: the compiler keeps what it knows
of an opened module by its name, and the second session saw the first
one's `Repl1`. `npm run smoke` runs a second session to check both.
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://os.submodule.nl/session/os-01a1caab-4faf-7817-951e-2b3f9a5dae19
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
jfrolich
force-pushed
the
macros-repl
branch
from
November 13, 2026 09:38
b35dad5 to
171f40f
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a read-eval-print loop to the RFC page of the compile-time macros, and completion to every editor of the site (stacked on #90).
What it is
A session in the first section of the page, "Try it", with a link "REPL" in the header. Each input is compiled as a file of its own with the earlier inputs opened, and run once, so names, types, modules and macros of one input are there for the next.
itis the value of the last expression. The macro modules of the examples and the whole standard library are loaded.Some(None),Blue(3),list{1, 2}, records with optional fields, unboxed variants), not as JavaScript.awaitworks, anopenstays open, output of timers appears when it is printed.Completion
The input of the loop, the editors of the examples and the playground's editor offer what can be written, as the compiler sees it:
Json.the members of the module, with their types; after%Debug.and@Enum.its macros;user.the fields of the record, with their types;users->the functions that take an array first (Array.map), and functions in scope that take the type;The compiler has no completion of its own.
playground/src/complete.jscompiles small files:include Pathfor the members of a module, and the expression before a.or->with a type it cannot have, in its place, for its type. That way a function parameter completes like a top-level name (users->Array.map(u => u.offers the fields ofuser). No change to the compiler was needed.Changes
module D = Debug,%D.dbg(x)) and for a module of an opened file.repl::preparebinds a last expression toitand lists the opens. Withcapture_intermediates, a compilation also describes what the file defines: each item as an interface declares it, and the run-time shape of each value's type.engine.replStart/engine.replEval,compile_inputandprepare_inputin the wasm crate, and the value printer.npm run smokefails when it is not what the loop prints.%Sql.queryof the database example, in a session.src/complete.js,engine.complete, and the checks innpm run smoke.Checked
cargo test --test repl --test macros --test macro_errorsand therepl::unit tests ofcompiler-rust.npm run smokeinplayground(all examples, the session, and the transcript in the RFC).%, in the loop, in an example (main file and macro file) and in the playground.Not in this change: completion of labelled arguments, of the fields of an inline record, and of names inside a string or a quote; JSX in an input (the loop has no JSX configuration), and Belt (not part of the page's standard library bundle).
Started by Jaap Frolich in this Assistant session