rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

compiler: update typecore; tests: add VariantCoercionConstructUsed; d…

Open cristianoc opened this issue 3 months ago • 18 comments

…ocs: update AGENTS; docstring_tests: update DocTest outputs

cristianoc avatar Sep 04 '25 10:09 cristianoc

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7839
@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7839
@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7839
@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7839
@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7839
@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7839
@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7839

commit: 6012c86

pkg-pr-new[bot] avatar Sep 04 '25 10:09 pkg-pr-new[bot]

The example is wrong, it does not trigger the warning. Update the example to be:

// Repro for incorrect "constructor ... is never used" warning with coercions
// This should compile cleanly without warnings when coercing from a -> b.

type a = A | B
module DoNotWarn: {
  let log: a => unit
} = {
  type b =
    | ...a
    | C

  let log = (x: a) => Js.log((x :> b))
}

let _ = DoNotWarn.log(A)

zth avatar Sep 04 '25 11:09 zth

The example is wrong, it does not trigger the warning. Update the example to be:

// Repro for incorrect "constructor ... is never used" warning with coercions
// This should compile cleanly without warnings when coercing from a -> b.

type a = A | B
module DoNotWarn: {
  let log: a => unit
} = {
  type b =
    | ...a
    | C

  let log = (x: a) => Js.log((x :> b))
}

let _ = DoNotWarn.log(A)

Took it from the chat. Let me close this and start again.

cristianoc avatar Sep 04 '25 11:09 cristianoc

@jfrolich can you verify whether the test added to this branch gives the expected warning (warns about 1 constructor)?

zth avatar Sep 05 '25 05:09 zth

Yes it should warn about C, but not about the other constructors!

jfrolich avatar Sep 05 '25 06:09 jfrolich

Great! So @cristianoc it seems the implementation is correct. I think we can move ahead with cleanup.

zth avatar Sep 05 '25 06:09 zth

Great! So @cristianoc it seems the implementation is correct. I think we can move ahead with cleanup.

Any more cases to test? With interfaces? If not, then cleanup.

cristianoc avatar Sep 05 '25 06:09 cristianoc

Great! So @cristianoc it seems the implementation is correct. I think we can move ahead with cleanup.

Any more cases to test? With interfaces? If not, then cleanup.

It only triggers for things with interfaces. I guess for completeness sake we could add an example where the new type is just a spread of the other type, with no new constructors added (but still using coercion), to see that all constructors are marked as being used.

zth avatar Sep 05 '25 06:09 zth

@zth take another look

cristianoc avatar Sep 05 '25 10:09 cristianoc

@cristianoc added a few comments. The changelog text is quite convoluted as well, but I'm not sure I care too much about that.

zth avatar Sep 05 '25 10:09 zth

@zth would you take over the PR? Getting diminishing returns going back and forth for little things later, we can "create an environment for this repo."

cristianoc avatar Sep 05 '25 10:09 cristianoc

Let's close it if so, and someone can use the insights here as the base for fixing this later on.

zth avatar Sep 05 '25 11:09 zth

Let's close it if so, and someone can use the insights here as the base for fixing this later on.

hold on, our assistant is thinking

cristianoc avatar Sep 05 '25 14:09 cristianoc

@codex try to build the compiler and run tests now, report if it worked

cristianoc avatar Sep 05 '25 14:09 cristianoc

Summary

  • Build failed: make terminated while compiling the Rust-based rewatch component, preventing the subsequent dune build step from running
  • Build environment missing dune; direct invocation shows bash: command not found: dune
  • Test suite did not run: make test similarly terminated during the rewatch build phase

Testing

  • make (terminated during rewatch build; could not reach compiler build step)
  • dune build (dune not installed)
  • make test (terminated during rewatch build; tests not executed)

View task →

@codex try again to build the compiler now that internet access is enabled in the sandbox

cristianoc avatar Sep 05 '25 15:09 cristianoc

Summary

  • Bootstrapped and installed Dune 3.17 to satisfy the repository’s required Dune language version.
  • make still failed because opam packages such as flow_parser, yojson, ounit2, cmarkit, and the tool cppo were missing from the environment
  • make test likewise failed for the same missing dependencies, so the test suite could not run

Testing

  • make
  • make test

Notes

  • Access to opam repositories is blocked (HTTP 403), preventing installation of the required OCaml packages and tools.

View task →

CODEX: I reviewed the latest change to mark shared constructors as used after variant→variant coercions. Verified there’s no redundancy in typecore and no leftover duplication; the extra exposed-decl marking was removed and inclusion handles propagation. Tests cover no spurious warning and still warn for target-only constructors. CHANGELOG updated.

@zth Anything else to address here? If not, we’re good to merge. Thanks!

cristianoc avatar Sep 06 '25 03:09 cristianoc