Fix incorrect analysis report for optional function args#8321
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57f9dd1a65
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if posTo.pos_fname <> posFrom.pos_fname then | ||
| match Declarations.find_opt_builder decls posTo with | ||
| | Some {declKind = Value {ownsOptionalArgs; optionalArgs}} -> | ||
| ownsOptionalArgs && not (OptionalArgs.isEmpty optionalArgs) |
There was a problem hiding this comment.
Check source ownership for cross-file function refs
The cross-file branch only validates posTo, so it still records function references whose posFrom is a non-owning alias/value with optionalArgs = empty. In this commit, that empty source state is then merged in compute_optional_args_state via OptionalArgs.combine_pair (which intersects states), so a live cross-file alias like let g = A.f can erase f’s optional-arg state and suppress legitimate optional-argument diagnostics on the real declaration.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6969ec07c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not (List.mem locFrom !callee_locs) then | ||
| suppressOptionalArgs locTo.loc_start) |
There was a problem hiding this comment.
Stop erasing optional args on non-call identifier refs
The new collectExpr path clears a declaration’s optionalArgs whenever it sees a Texp_ident that is not in callee_locs, which includes ordinary aliasing like let alias = f. This mutates f before optional-arg state is computed, so later direct calls to f start from an empty optional-arg set and DeadOptionalArgs.check can no longer report real unused/always-supplied optional arguments; even dead aliases can suppress diagnostics for the original function.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c7342857a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| match Declarations.find_opt_builder decls posTo with | ||
| | Some {declKind = Value {optionalArgs}} -> | ||
| not (OptionalArgs.isEmpty optionalArgs) | ||
| | _ -> false |
There was a problem hiding this comment.
Record optional calls even when target decl isn't built yet
The same-file guard in addReferences drops a call unless Declarations.find_opt_builder decls posTo already has a non-empty optional-arg declaration. In a let rec ... and ... group, expressions are traversed per binding before later bindings are added, so a call from an earlier binding to a later optional-arg function can hit None here and never be recorded. This undercounts real calls and can produce wrong optional-argument diagnostics (e.g., reporting an arg as unused/redundant when it is used through mutual recursion).
Useful? React with 👍 / 👎.
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
cristianoc
left a comment
There was a problem hiding this comment.
Are the tests OK? Seems like no new warnings reported, and I guess that's the intention?
I had this looked at, some changes here seem similar.
Though I remember some fundamental issue that aliasing cannot really be tracked.
It would be useful to generate a detailed explanation of the code changes.
|
@cristianoc Thanks!
Yes, exactly.
Will add that. However, another (local) Codex review found an issue that still needs to be fixed:
Will set this to draft in the meantime. |
|
Any update on this? |
|
@cknitt Not to bother you, but would be so nice to be able to have reanalyze work as expected in ci/cd pipelines to not loose track of any dead code |
|
Also waiting for this one |
|
Its my birthday soon, would be a great present getting this fixed :)) |
|
Also waiting for this one @cknitt! |
|
I recently tried to rebase and finish it, but ran into more and more issues / edge cases with each change + Codex review. I am not really the expert on reanalyze, it may take @cristianoc to finish this I am afraid. I will push may rebased attempt. |
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #8321 +/- ##
==========================================
- Coverage 74.66% 74.66% -0.01%
==========================================
Files 457 457
Lines 62110 62174 +64
==========================================
+ Hits 46373 46420 +47
- Misses 15737 15754 +17
🚀 New features to boost your workflow:
|
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-8321 |
Fixes #8302
@cristianoc This was done by Codex, can you check if it makes sense?