Semantic Diff

#9292 Remove duplicated helpers across the compiler, analysis and tools

14 commits

00e3f4051379ddd6a8f53272e09d326e8f6b3fb6..pr-9292

7d9ed1bb4 · cknitt + Claude · Nov 10, 2026, 19:33 UTC

Derive a package's namespace in one place

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.

aca40196d · cknitt + Claude · Nov 10, 2026, 20:03 UTC

Print type declarations with one function

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.

12a61fe80 · cknitt + Claude · Nov 10, 2026, 20:03 UTC

Instantiate types in analysis with one type walker

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.

7af08bd09 · cknitt + Claude · Nov 10, 2026, 20:05 UTC

Attach comments around a node with one helper

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.

d764697cc · cknitt + Claude · Nov 10, 2026, 20:25 UTC

Use the standard library for int, bytes and ref helpers

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.

192746c41 · cknitt + Claude · Nov 10, 2026, 20:29 UTC

Use the standard library for string and list helpers

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.

7bdef7a3c · cknitt + Claude · Nov 10, 2026, 20:29 UTC

Use the standard library for analysis's string and list helpers

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.

b2f9dadd5 · cknitt + Claude · Nov 10, 2026, 20:30 UTC

Read @deprecated in analysis as the compiler does

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.

abc975505 · cknitt + Claude · Nov 10, 2026, 20:31 UTC

Look up local value completions with one function

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.

2d205781a · cknitt + Claude · Nov 10, 2026, 20:32 UTC

Print module paths with Printtyp in analysis and tools

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.

d37461f7f · cknitt + Claude · Nov 10, 2026, 21:04 UTC

Keep Ext_string.starts_with, which doesn't allocate

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.

21c0a9048 · cknitt + Claude · Nov 10, 2026, 21:04 UTC

Match the pipe operator by its name in the built-in PPX

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.

3aa41e0f5 · cknitt + Claude · Nov 11, 2026, 14:54 UTC

Stop exporting Printtyp.tree_of_path

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.

2a7d515d8 · cknitt + Claude · Nov 12, 2026, 20:45 UTC

Test analysis's by-name instantiation and @deprecated reading

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.