Repository navigation
Remove duplicated helpers across the compiler, analysis and tools - #9292
Conversation
Ext_namespace, rewatch-ocaml's Config_decode and genType each had a copy of the package-name-to-namespace rule. genType's dropped `_`, unlike the build system, so it didn't recognize the namespace module of a scoped dependency like `@my_org/lib` (My_orgLib). All three now use Ext_namespace.namespace_of_package_name; a gentype ounit test covers the underscore case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
print_type_declaration, used for `with type` constraints, was a copy of
print_type_declaration2 that took the name and the `=`/`:=` sign as
parameters and lacked the empty-record case. The copy is now the only
implementation, and print_type_declaration2 computes the name and passes
`=`. Output is unchanged: `with type t = {}` parses as an object type.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe
Signed-off-by: Christoph Knittel <ck@cca.io>
instantiate_type and instantiate_type2 were 55-line copies of the same type walker that differed only in how a variable is substituted (by identity or by name). Both now use map_type_vars with their own substitution. The by-name one returned the whole type being instantiated for a variable that isn't a parameter; it now keeps the variable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
The comments table spelled out "attach the comments before a node, walk it with those inside, attach those after" 50 times; walk_around now does it. walk_mod_expr_parameter and walk_mod_type_parameter were identical and are now walk_functor_parameter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
Ext_pervasives.min_int/max_int, Ext_int.compare/equal, Ext_bytes.unsafe_blit_string and Ext_ref.protect copied Int.min/max, Int.compare/equal, Bytes.unsafe_blit_string and Fun.protect. Their callers use the standard library now; Ext_bytes and Ext_ref are gone. Ext_pervasives.finally stays: unlike Fun.protect it re-raises an exception from the cleanup unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
Ext_string.starts_with, for_all, equal, is_empty, single_colon and uncapitalize_ascii, and Ext_list.has_string, init and find_opt (a find_map) copied String and List functions; callers use those now. Three ounit cases only tested the removed copies. Ext_list.nth_opt (no raise on a negative index), assoc_by_string (default or assert) and is_empty (List.is_empty needs OCaml 5.1) stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
Utils.starts_with, ends_with, find and filter_map copied String.starts_with, String.ends_with, List.find_map and List.filter_map; their 37 callers use the standard library now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
Process_attributes.find_deprecated_attribute parsed the attribute itself and disagreed with the compiler on malformed payloads: a record without `reason` showed as deprecated with an empty message although the compiler doesn't warn. It now takes the message from Builtin_attributes.deprecated_of_attrs_with_migrate, which the interface exports for this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
find_local_completions_for_values_and_constructors and find_local_completions_for_values differed only in the constructor steps; find_local_completions_for_values now takes ~constructors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
createInterface and rescript-tools each printed an out_ident with their own copy of Printtyp.string_of_out_ident; they use Printtyp's now, which the interface exports for this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
Changelog🐛 Bug fix
💅 Polish
Semantic Diff14 commits · Full page Derive a package's namespace in one place7d9ed1b · cknitt + Claude · Nov 10, 2026, 19:33 UTC Ext_namespace, rewatch-ocaml's Config_decode and genType each had a copy of the package-name-to-namespace rule. genType's dropped Print type declarations with one functionaca4019 · cknitt + Claude · Nov 10, 2026, 20:03 UTC print_type_declaration, used for Instantiate types in analysis with one type walker12a61fe · cknitt + Claude · Nov 10, 2026, 20:03 UTC instantiate_type and instantiate_type2 were 55-line copies of the same type walker that differed only in how a variable is substituted (by identity or by name). Both now use map_type_vars with their own substitution. The by-name one returned the whole type being instantiated for a variable that isn't a parameter; it now keeps the variable. Attach comments around a node with one helper7af08bd · cknitt + Claude · Nov 10, 2026, 20:05 UTC The comments table spelled out "attach the comments before a node, walk it with those inside, attach those after" 50 times; walk_around now does it. walk_mod_expr_parameter and walk_mod_type_parameter were identical and are now walk_functor_parameter. Use the standard library for int, bytes and ref helpersd764697 · cknitt + Claude · Nov 10, 2026, 20:25 UTC Ext_pervasives.min_int/max_int, Ext_int.compare/equal, Ext_bytes.unsafe_blit_string and Ext_ref.protect copied Int.min/max, Int.compare/equal, Bytes.unsafe_blit_string and Fun.protect. Their callers use the standard library now; Ext_bytes and Ext_ref are gone. Ext_pervasives.finally stays: unlike Fun.protect it re-raises an exception from the cleanup unchanged. Use the standard library for string and list helpers192746c · cknitt + Claude · Nov 10, 2026, 20:29 UTC Ext_string.starts_with, for_all, equal, is_empty, single_colon and uncapitalize_ascii, and Ext_list.has_string, init and find_opt (a find_map) copied String and List functions; callers use those now. Three ounit cases only tested the removed copies. Ext_list.nth_opt (no raise on a negative index), assoc_by_string (default or assert) and is_empty (List.is_empty needs OCaml 5.1) stay. Use the standard library for analysis's string and list helpers7bdef7a · cknitt + Claude · Nov 10, 2026, 20:29 UTC Utils.starts_with, ends_with, find and filter_map copied String.starts_with, String.ends_with, List.find_map and List.filter_map; their 37 callers use the standard library now. Read
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #9292 +/- ##
==========================================
+ Coverage 81.97% 82.07% +0.09%
==========================================
Files 456 455 -1
Lines 65671 65360 -311
==========================================
- Hits 53836 53642 -194
+ Misses 11835 11718 -117
🚀 New features to boost your workflow:
|
✅ Compiler benchmarksAllocated wordsIn total: 640,764,338 → 640,780,622 (±0.00%). Generated projects: 920,848,686 → 920,879,594 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,211,262,577 → 9,209,653,365 (-0.02%).
7 more changes
Output sizeIn total: 25,842,868 → 25,838,530 (-0.02%).
Pull request 2a7d515 compared with base 469d677 in this run. |
String.starts_with allocates a closure for its local loop on every call, and is_package_relative_path calls it twice for every external: the benchmarks showed +163 words on Stdlib_Symbol. Ext_string.starts_with loops without allocating; it is back, with a comment saying why, for the compiler's two callers and its ounit case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
view_as_app checked every applied identifier against a one-element list with List.mem, which compares through the generic structural compare; its only caller passed ["->"]. view_as_pipe matches the constant "->" in the pattern, a direct string comparison. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
638e458 to
21c0a90
Compare
createInterface was its last user outside Printtyp and prints the path with Printtyp.string_of_path now, so the dead-code check reported the export. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9292 |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3aa41e0f53
ℹ️ 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".
Codex review: the two analysis behavior fixes had no tests. ounit_analysis_types_tests checks that instantiate_type2 substitutes a parameter and keeps a variable that isn't one, and that find_deprecated_attribute reads a string, a record with a reason, and a record without one (not deprecated) as the compiler does. Both fail against the previous behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe Signed-off-by: Christoph Knittel <ck@cca.io>
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Removes duplicated helpers found in the cleanup survey, one commit each. Two of them also fix small inconsistencies.
Ext_namespace, rewatch-ocaml'sConfig_decodeand genType each derived a namespace from a package name. genType's copy dropped_, unlike the build system, so it didn't recognize the namespace module of a scoped dependency like@my_org/lib(My_orgLib). All three now callExt_namespace.namespace_of_package_name; a new gentype ounit test covers the underscore case (fix fragment).print_type_declaration(forwith typeconstraints) was a copy ofprint_type_declaration2with the name and=/:=as parameters; it is now the only implementation. Output is unchanged.instantiate_typeandinstantiate_type2were 55-line copies that differed only in how a variable is substituted; both now usemap_type_vars. The by-name version returned the whole type being instantiated for a variable that isn't a parameter; it now keeps the variable.walk_aroundin the comments table. "Attach the comments before a node, walk it with those inside, attach those after" was spelled out 50 times; the two identical functor-parameter walkers are now one. The syntax snapshots are unchanged.Ext_pervasives.min_int/max_int,Ext_int.compare/equal,Ext_bytes,Ext_ref, fiveExt_stringand threeExt_listhelpers, and analysis'sUtils.starts_with/ends_with/find/filter_map. Kept on purpose, because they aren't exact copies:Ext_pervasives.finally(re-raises a cleanup exception unchanged);Ext_string.starts_with(String.starts_withallocates a closure per call);Ext_list.nth_opt(no exception on a negative index);Ext_list.assoc_by_string(default or assert);Ext_list.is_empty(List.is_emptyneeds OCaml 5.1).@deprecatedread as the compiler does. Analysis parsed the attribute itself and disagreed with the compiler on malformed payloads, e.g. a record withoutreasonshowed as deprecated although the compiler doesn't warn. It now usesBuiltin_attributes.deprecated_of_attrs_with_migrate(polish fragment).~constructors.Printtyp.string_of_out_identreplaces the copies in createInterface and rescript-tools.Allocations and instructions. The stdlib's
String.starts_withallocates a closure for its local loop on every call (no flambda), andis_package_relative_pathcalls it for every external: the benchmarks showed +163 words onStdlib_Symbol.Ext_string.starts_withloops without allocating, so it stays, with a comment saying why. The built-in PPX also checked every applied identifier against["->"]withList.mem, which goes through the generic compare;view_as_pipenow matches"->"in the pattern.Stdlib_Symbolis back to master within 7 words (Fun.protect's closures, once per file).Not done: reanalyze's and genType's
find_source_filelook alike but differ (genType resolves paths against the compiler request's directory and returns absolute paths), so merging them would change reanalyze's output.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe