Skip to content

Conversation

cristianoc
Copy link
Collaborator

…ocs: update AGENTS; docstring_tests: update DocTest outputs

…ocs: update AGENTS; docstring_tests: update DocTest outputs

Signed-off-by: Cristiano Calcagno <[email protected]>
Copy link

pkg-pr-new bot commented Sep 4, 2025

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

Copy link
Member

@zth zth left a comment

Choose a reason for hiding this comment

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

Great stuff! Some cleanup suggested.

Comment on lines 3030 to 3033
with
| Some (_p_src, _p_src_conc, src_decl), Some (_p_tgt, p_tgt_conc, tgt_decl)
-> (
match (src_decl.type_kind, tgt_decl.type_kind) with
Copy link
Member

Choose a reason for hiding this comment

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

These matches could be done in one match, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codex can this be done in one match?

Choose a reason for hiding this comment

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

Comment on lines 3040 to 3041
let has_src name = List.exists (fun n -> n = name) src_names in
let tgt_ty_name = Path.last p_tgt_conc in
Copy link
Member

Choose a reason for hiding this comment

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

Use StringSet instead for perf for large amounts of constructors?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codex Use StringSet instead for perf for large amounts of constructors?

Choose a reason for hiding this comment

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

@zth
Copy link
Member

zth commented Sep 4, 2025

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)

@cristianoc
Copy link
Collaborator Author

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 cristianoc requested a review from zth September 4, 2025 11:37
…s test for C warning

- Fix spurious “constructor … is never used” warnings when values are introduced via coercions between concrete variant types.
- After a successful coercion, mark the intersection of constructors as positively used for both:
  - the concrete target declaration, and
  - the exposed target alias (e.g. private/abstract signature path) when it differs.
- Preserve warnings for constructors only present on the target side (e.g. C) — they remain unused and should warn.

Tests:
- Add super errors fixture ensuring C still warns:
  - fixtures: tests/build_tests/super_errors/fixtures/VariantCoercionWarnOnC.res
  - expected: tests/build_tests/super_errors/expected/VariantCoercionWarnOnC.res.expected

Build:
- Compiler builds cleanly; super-errors snapshot matches.
@zth
Copy link
Member

zth commented Sep 5, 2025

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

@jfrolich
Copy link
Contributor

jfrolich commented Sep 5, 2025

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

@zth
Copy link
Member

zth commented Sep 5, 2025

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

@cristianoc
Copy link
Collaborator Author

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.

@zth
Copy link
Member

zth commented Sep 5, 2025

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.

…ry/with

Mark constructor usage only when both concrete typedecls are found.
Preserves behavior and simplifies the control flow vs tuple-of-options match.

Signed-off-by: Cristiano Calcagno <[email protected]>
Build a set of source constructor names and use O(log n) membership
checks instead of O(n) List.exists for each target constructor.

Signed-off-by: Cristiano Calcagno <[email protected]>
@cristianoc
Copy link
Collaborator Author

@zth take another look

Comment on lines 3051 to 3064
(* If the target type path differs from its concrete decl (e.g.,
when a signature exposes a private or abstract alias), also mark
usage on the exposed target declaration so scheduled warnings
attached to that declaration are cleared. *)
if not (Path.same p_tgt p_tgt_conc) then
let exposed_ty_name = Path.last p_tgt in
let exposed_decl = Env.find_type p_tgt env in
List.iter
(fun (c : Types.constructor_declaration) ->
let cname = Ident.name c.cd_id in
if has_src cname then
Env.mark_constructor_used Env.Positive env exposed_ty_name
exposed_decl cname)
tgt_cons
Copy link
Member

Choose a reason for hiding this comment

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

@cristianoc what does this mean in practice? I don't get it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codex what's the answer here?

Choose a reason for hiding this comment

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

The code around line 3064 handles cases where the type path used in the code (p_tgt) differs from the path of its concrete declaration (p_tgt_conc). This occurs when a module signature exposes a variant type via a private or abstract alias. When such a coercion happens, the code marks the overlapping constructors as “used” on both the concrete declaration and the exposed alias so that “constructor … is never used” warnings are cleared for both locations compiler/ml/typecore.mlL3051-L3064

View task →

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codex explain more in detail the terms used in your response and the mechanism to mark a constructor never used.
Don't assume familiarity with the representation of types and type environments, but introduce enough context to understand this change.

Choose a reason for hiding this comment

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

Summary

  • Expanded the comments around coercion handling to define p_tgt (path used in source code) versus p_tgt_conc (resolved declaration path) and to explain how Env.mark_constructor_used records constructor usage on both the concrete type and any exposed alias so “constructor … is never used” warnings are cleared compiler/ml/typecore.mlL3051-L3064

Testing

  • ⚠️ make format (fails: dune: command not found)
  • ⚠️ make test (fails: KeyboardInterrupt during ninja build)

Notes

  • apt-get update failed with 403 errors, so required dependencies (e.g., dune) could not be installed

View task →

Copy link
Member

Choose a reason for hiding this comment

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

If we remove this special case code, does the fix still work? If so I think we should remove it, and then add it again in the future if we discover real issues it would fix.

example.res Outdated
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed, irrelevant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codex remove this

Choose a reason for hiding this comment

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

Summary

  • Removed the redundant example.res file as it was no longer relevant to the pull request

Testing

  • ⚠️ make format (dune: command not found; internal Biome error)
  • ⚠️ make test (dune: command not found)

View task →

issue.txt Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Let's remember to remove this before merging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codex remove

Choose a reason for hiding this comment

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

Summary

  • Removed the temporary issue.txt debugging log from the repository

Testing

  • ⚠️ make format (fails: dune: command not found)
  • ⚠️ make test (fails: dune: command not found)

View task →

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codex perhaps AGENTS.md needs to be changed with instruction on how to set up opam and dune?

Choose a reason for hiding this comment

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

Summary

  • Added an “Installing opam and dune” section to AGENTS.md with step-by-step commands for setting up the OCaml toolchain so dune is available for build and test targets AGENTS.mdL111-L131
  • Removed the temporary issue.txt debugging log from the repository

Testing

  • ⚠️ apt-get update (repository InRelease files not signed, 403 errors)
  • ⚠️ make format (dune: command not found; cargo: command not found)
  • ⚠️ make test (cargo: command not found)

Notes

  • Package repository errors prevented installing opam, leaving dune and cargo unavailable for formatting and tests

View task →

@zth
Copy link
Member

zth commented Sep 5, 2025

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

@cristianoc
Copy link
Collaborator Author

@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."

@zth
Copy link
Member

zth commented Sep 5, 2025

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

@cristianoc
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

Copy link

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 →

@cristianoc
Copy link
Collaborator Author

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

Copy link

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 →

…rcion

Mark shared constructors as used on the target variant after successful coercion; keep warnings for target-only constructors. Part of #7839.
@cristianoc
Copy link
Collaborator Author

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!

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