Skip to content

Conversation

anmonteiro
Copy link
Member

@anmonteiro anmonteiro commented May 19, 2023

  • This change moves pipe-first (foo |. bar / foo->bar) to melange.ppx
  • It also shows how we can incrementally migrate features off of jscomp/frontend to the melange ppx

fixes #568

  • changes:
    • removes bs.deriving {abstract,accessors,jsConverter} in favor of deriving {abstract,accessors,jsConverter}
      • stops supporting the bs.deriving form
    • [@@deriving abstract]:
      • no longer creates a new, abstract type.
      • requires [@bs.optional] types to be annotated with option explicitly.
        • This makes the non-abstract type compatible with the record due to advances in the runtime representation since both were introduced. This effectively unifies the record + <..> Js.t representation for @@deriving abstract.
        • it's also a breaking change that will require changes in some libraries (including reason-react)
    • converts "unused attribute" warnings into errors in the PPX. this makes the FFI a lot stricter.

@anmonteiro anmonteiro changed the title [melange.ppx]: move pipe-first to melange.ppx [melange.ppx]: move the entire PPX frontend to melange.ppx May 20, 2023
@anmonteiro anmonteiro force-pushed the anmonteiro/pipe-to-ppx branch from d3c46a2 to c6d58ca Compare May 21, 2023 06:26
Copy link
Member

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

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

❤️


type xx = < x : int > Js.t
[@@bs.deriving accessors]
(* Not applicable to this type. *)
Copy link
Member

Choose a reason for hiding this comment

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

What happens if the deriving attribute is applied to an invalid type? Unused warning, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yup

@@ -69,7 +69,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params)
match acc with
| Splice2 _ | Splice0 -> assert false
| Splice1 x ->
((Js_op.Lit label, x) :: accs, Ext_list.append new_eff eff, assign)
Copy link
Member

Choose a reason for hiding this comment

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

Is the goal to get rid of Ext_list?

Copy link
Member Author

Choose a reason for hiding this comment

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

I regret doing this mixed with the other changes, but I removed some functions that existed in List. for the OCaml versions that we support.

Comment on lines +18 to +19
// Generated by Melange
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
Copy link
Member

Choose a reason for hiding this comment

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

It is a bit strange to include this in the error output. I understand it is caused by the hack to preserve melc behavior to avoid adding -ppx melppx to dune?

@anmonteiro anmonteiro merged commit 2202fcb into main Jun 1, 2023
@anmonteiro anmonteiro deleted the anmonteiro/pipe-to-ppx branch June 1, 2023 17:49
anmonteiro added a commit that referenced this pull request Jun 1, 2023
@anmonteiro anmonteiro mentioned this pull request Jun 4, 2023
6 tasks
anmonteiro added a commit to anmonteiro/opam-repository that referenced this pull request Sep 14, 2023
CHANGES:

- Build executables for bytecode-only platforms too
  ([melange-re/melange#596](melange-re/melange#596))
- Move the entire builtin PPX to `melange.ppx`. Preprocessing with
  `melange.ppx` will needed in most cases going forward, as it's responsible
  for processing `external` declarations, `@deriving` attributes and more,
  compared to the previous release where `melange.ppx` just processed AST
  extension nodes ([melange-re/melange#583](melange-re/melange#583))
- Remove old BuckleScript-style conditional compilation
  ([melange-re/melange#605](melange-re/melange#605))
- Don't emit JS import / require paths with `foo/./bar.js`
  ([melange-re/melange#598](melange-re/melange#598),
  [melange-re/melange#612](melange-re/melange#612))
- Wrap the melange runtime
  ([melange-re/melange#624](melange-re/melange#624),
  [melange-re/melange#637](melange-re/melange#637)). After this change,
  Melange exposes fewer toplevel modules. Melange runtime / stdlib modules are
  now wrapped under:
    - `Caml*` / `Curry` modules are part of the runtime and keep being exposed
      as before
    - `Js.*` contains all the modules previously accessible via `Js_*`, e.g.
      `Js_int` -> `Js.Int`
    - `Belt.*` wraps all the `Belt` modules; `Belt_List` etc. are not exposed
      anymore, but rather nested under `Belt`, e.g. `Belt.List`
    - `Node.*`: we now ship a `melange.node` library that includes the modules
      containing Node.js bindings. After this change, users will have to depend
      on `melange.node` explicitly in order to use the `Node.*` modules
    - `Dom.*`: we now ship a `melange.dom` library that includes the modules
      containing Node.js bindings. This library is included by default so the
      `Dom` module will always be available in Melange projects.
- Disable warning 61 (`unboxable-type-in-prim-decl`) for externals generated by
  Melange ([melange-re/melange#641](melange-re/melange#641),
  [melange-re/melange#643](melange-re/melange#643))
- Add `--rectypes` ([melange-re/melange#644](melange-re/melange#644)) to
  enable [recursive
  types](https://v2.ocaml.org/releases/5.0/htmlman/types.html#sss:typexpr-aliased-recursive)
- [melange.ppx]: Deprecate `bs.*` attributes in favor of `mel.*`
  ([melange-re/melange#566](melange-re/melange#566),
  [melange-re/melange#662](melange-re/melange#662),
  [melange-re/melange#663](melange-re/melange#663))
- [melange]: Fix field access code generation when `open`in inline functor
  applications ([melange-re/melange#661](melange-re/melange#661),
  [melange-re/melange#664](melange-re/melange#664))
- [melange]: Upgrade the OCaml typechecker version to 5.1
  ([melange-re/melange#668](melange-re/melange#668))
- [melange.ppx]: Deprecate `[@@mel.val]` and suggest its removal. This
  attribute is redundant and unnecessary
  ([melange-re/melange#675](melange-re/melange#675),
  [melange-re/melange#678](melange-re/melange#678))
- [melange]: remove old, unused CLI flags: `-bs-ns`, `-bs-cmi`, `-bs-cmj`,
  `-bs-no-builtin-ppx`, `-bs-super-errors`
  ([melange-re/melange#686](melange-re/melange#686)).
- [melange]: generate correct code for types with the `option` shape
  ([melange-re/melange#700](melange-re/melange#700)).
- [melange]: stop exporting `$$default` in the generated JavaScript when using
  ES6 default exports `let default = ..`
  ([melange-re/melange#708](melange-re/melange#708)).
- [melange]: allow exporting invalid OCaml identifiers in the resulting
  JavaScript with `@mel.as`
  ([melange-re/melange#714](melange-re/melange#714), fixes
  [melange-re/melange#713](melange-re/melange#713)).
- [melange]: Allow using `@mel.as` in external declarations without explicitly
  annotating `@mel.{string,int}`
  ([melange-re/melange#722](melange-re/melange#722), fixes
  [melange-re/melange#578](melange-re/melange#578)).
- [melange]: Allow using `@mel.unwrap` in external declarations with `@mel.obj`
  ([melange-re/melange#724](melange-re/melange#724), fixes
  [melange-re/melange#679](melange-re/melange#679)).
- [melange]: Support renaming fields in inline records / record extensions with
  `@mel.as` ([melange-re/melange#732](melange-re/melange#732), fixes
  [melange-re/melange#730](melange-re/melange#730)).
mseri pushed a commit to ocaml/opam-repository that referenced this pull request Sep 16, 2023
CHANGES:

- Build executables for bytecode-only platforms too
  ([melange-re/melange#596](melange-re/melange#596))
- Move the entire builtin PPX to `melange.ppx`. Preprocessing with
  `melange.ppx` will needed in most cases going forward, as it's responsible
  for processing `external` declarations, `@deriving` attributes and more,
  compared to the previous release where `melange.ppx` just processed AST
  extension nodes ([melange-re/melange#583](melange-re/melange#583))
- Remove old BuckleScript-style conditional compilation
  ([melange-re/melange#605](melange-re/melange#605))
- Don't emit JS import / require paths with `foo/./bar.js`
  ([melange-re/melange#598](melange-re/melange#598),
  [melange-re/melange#612](melange-re/melange#612))
- Wrap the melange runtime
  ([melange-re/melange#624](melange-re/melange#624),
  [melange-re/melange#637](melange-re/melange#637)). After this change,
  Melange exposes fewer toplevel modules. Melange runtime / stdlib modules are
  now wrapped under:
    - `Caml*` / `Curry` modules are part of the runtime and keep being exposed
      as before
    - `Js.*` contains all the modules previously accessible via `Js_*`, e.g.
      `Js_int` -> `Js.Int`
    - `Belt.*` wraps all the `Belt` modules; `Belt_List` etc. are not exposed
      anymore, but rather nested under `Belt`, e.g. `Belt.List`
    - `Node.*`: we now ship a `melange.node` library that includes the modules
      containing Node.js bindings. After this change, users will have to depend
      on `melange.node` explicitly in order to use the `Node.*` modules
    - `Dom.*`: we now ship a `melange.dom` library that includes the modules
      containing Node.js bindings. This library is included by default so the
      `Dom` module will always be available in Melange projects.
- Disable warning 61 (`unboxable-type-in-prim-decl`) for externals generated by
  Melange ([melange-re/melange#641](melange-re/melange#641),
  [melange-re/melange#643](melange-re/melange#643))
- Add `--rectypes` ([melange-re/melange#644](melange-re/melange#644)) to
  enable [recursive
  types](https://v2.ocaml.org/releases/5.0/htmlman/types.html#sss:typexpr-aliased-recursive)
- [melange.ppx]: Deprecate `bs.*` attributes in favor of `mel.*`
  ([melange-re/melange#566](melange-re/melange#566),
  [melange-re/melange#662](melange-re/melange#662),
  [melange-re/melange#663](melange-re/melange#663))
- [melange]: Fix field access code generation when `open`in inline functor
  applications ([melange-re/melange#661](melange-re/melange#661),
  [melange-re/melange#664](melange-re/melange#664))
- [melange]: Upgrade the OCaml typechecker version to 5.1
  ([melange-re/melange#668](melange-re/melange#668))
- [melange.ppx]: Deprecate `[@@mel.val]` and suggest its removal. This
  attribute is redundant and unnecessary
  ([melange-re/melange#675](melange-re/melange#675),
  [melange-re/melange#678](melange-re/melange#678))
- [melange]: remove old, unused CLI flags: `-bs-ns`, `-bs-cmi`, `-bs-cmj`,
  `-bs-no-builtin-ppx`, `-bs-super-errors`
  ([melange-re/melange#686](melange-re/melange#686)).
- [melange]: generate correct code for types with the `option` shape
  ([melange-re/melange#700](melange-re/melange#700)).
- [melange]: stop exporting `$$default` in the generated JavaScript when using
  ES6 default exports `let default = ..`
  ([melange-re/melange#708](melange-re/melange#708)).
- [melange]: allow exporting invalid OCaml identifiers in the resulting
  JavaScript with `@mel.as`
  ([melange-re/melange#714](melange-re/melange#714), fixes
  [melange-re/melange#713](melange-re/melange#713)).
- [melange]: Allow using `@mel.as` in external declarations without explicitly
  annotating `@mel.{string,int}`
  ([melange-re/melange#722](melange-re/melange#722), fixes
  [melange-re/melange#578](melange-re/melange#578)).
- [melange]: Allow using `@mel.unwrap` in external declarations with `@mel.obj`
  ([melange-re/melange#724](melange-re/melange#724), fixes
  [melange-re/melange#679](melange-re/melange#679)).
- [melange]: Support renaming fields in inline records / record extensions with
  `@mel.as` ([melange-re/melange#732](melange-re/melange#732), fixes
  [melange-re/melange#730](melange-re/melange#730)).
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

- Build executables for bytecode-only platforms too
  ([melange-re/melange#596](melange-re/melange#596))
- Move the entire builtin PPX to `melange.ppx`. Preprocessing with
  `melange.ppx` will needed in most cases going forward, as it's responsible
  for processing `external` declarations, `@deriving` attributes and more,
  compared to the previous release where `melange.ppx` just processed AST
  extension nodes ([melange-re/melange#583](melange-re/melange#583))
- Remove old BuckleScript-style conditional compilation
  ([melange-re/melange#605](melange-re/melange#605))
- Don't emit JS import / require paths with `foo/./bar.js`
  ([melange-re/melange#598](melange-re/melange#598),
  [melange-re/melange#612](melange-re/melange#612))
- Wrap the melange runtime
  ([melange-re/melange#624](melange-re/melange#624),
  [melange-re/melange#637](melange-re/melange#637)). After this change,
  Melange exposes fewer toplevel modules. Melange runtime / stdlib modules are
  now wrapped under:
    - `Caml*` / `Curry` modules are part of the runtime and keep being exposed
      as before
    - `Js.*` contains all the modules previously accessible via `Js_*`, e.g.
      `Js_int` -> `Js.Int`
    - `Belt.*` wraps all the `Belt` modules; `Belt_List` etc. are not exposed
      anymore, but rather nested under `Belt`, e.g. `Belt.List`
    - `Node.*`: we now ship a `melange.node` library that includes the modules
      containing Node.js bindings. After this change, users will have to depend
      on `melange.node` explicitly in order to use the `Node.*` modules
    - `Dom.*`: we now ship a `melange.dom` library that includes the modules
      containing Node.js bindings. This library is included by default so the
      `Dom` module will always be available in Melange projects.
- Disable warning 61 (`unboxable-type-in-prim-decl`) for externals generated by
  Melange ([melange-re/melange#641](melange-re/melange#641),
  [melange-re/melange#643](melange-re/melange#643))
- Add `--rectypes` ([melange-re/melange#644](melange-re/melange#644)) to
  enable [recursive
  types](https://v2.ocaml.org/releases/5.0/htmlman/types.html#sss:typexpr-aliased-recursive)
- [melange.ppx]: Deprecate `bs.*` attributes in favor of `mel.*`
  ([melange-re/melange#566](melange-re/melange#566),
  [melange-re/melange#662](melange-re/melange#662),
  [melange-re/melange#663](melange-re/melange#663))
- [melange]: Fix field access code generation when `open`in inline functor
  applications ([melange-re/melange#661](melange-re/melange#661),
  [melange-re/melange#664](melange-re/melange#664))
- [melange]: Upgrade the OCaml typechecker version to 5.1
  ([melange-re/melange#668](melange-re/melange#668))
- [melange.ppx]: Deprecate `[@@mel.val]` and suggest its removal. This
  attribute is redundant and unnecessary
  ([melange-re/melange#675](melange-re/melange#675),
  [melange-re/melange#678](melange-re/melange#678))
- [melange]: remove old, unused CLI flags: `-bs-ns`, `-bs-cmi`, `-bs-cmj`,
  `-bs-no-builtin-ppx`, `-bs-super-errors`
  ([melange-re/melange#686](melange-re/melange#686)).
- [melange]: generate correct code for types with the `option` shape
  ([melange-re/melange#700](melange-re/melange#700)).
- [melange]: stop exporting `$$default` in the generated JavaScript when using
  ES6 default exports `let default = ..`
  ([melange-re/melange#708](melange-re/melange#708)).
- [melange]: allow exporting invalid OCaml identifiers in the resulting
  JavaScript with `@mel.as`
  ([melange-re/melange#714](melange-re/melange#714), fixes
  [melange-re/melange#713](melange-re/melange#713)).
- [melange]: Allow using `@mel.as` in external declarations without explicitly
  annotating `@mel.{string,int}`
  ([melange-re/melange#722](melange-re/melange#722), fixes
  [melange-re/melange#578](melange-re/melange#578)).
- [melange]: Allow using `@mel.unwrap` in external declarations with `@mel.obj`
  ([melange-re/melange#724](melange-re/melange#724), fixes
  [melange-re/melange#679](melange-re/melange#679)).
- [melange]: Support renaming fields in inline records / record extensions with
  `@mel.as` ([melange-re/melange#732](melange-re/melange#732), fixes
  [melange-re/melange#730](melange-re/melange#730)).
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.

move pipe-first to melange.ppx
2 participants