Skip to content

refactor: unify naming and style across the library - #193

Merged
gouyt13 merged 3 commits into
mainfrom
refactor/style-unification
Oct 31, 2026
Merged

gouyt13 merged 3 commits into
mainfrom
refactor/style-unification

Conversation

@gouyt13

@gouyt13 gouyt13 commented Oct 31, 2026

Copy link
Copy Markdown
Member

Summary

Make naming and style consistent across the library and let the tools enforce it. Three commits, best reviewed separately:

  1. style: brace every control statement body: enables clang-format's InsertBraces and reformats first-party sources. Formatting only (about 1270 bodies were already braced, about 50 were not).
  2. refactor: unify naming and style across the library: one convention per concept in core, SIMD, FastScan, HNSW, IVF, SymphonyQG, clustering, utils and the bindings, following the role names in docs/development.md:
    • role names such as internal_id, assignments/cluster_id, num_threads (requested) vs num_workers (resolved), batch_size/num_points, lookup_table/accumulated_values, *_bytes/*_offset;
    • HNSW's hnswlib-style private names, the empty-graph sentinel (kPidMax), and fixed-width link counts;
    • parameter names agree between declarations, definitions and backends; PascalCase template parameters; anonymous namespaces for file-local helpers; internal linkage for headers compiled under several ISA flags;
    • error messages read "<Component> <text>";
    • test suites follow <Module><Area>Test, with the CI filters and tests/README.md updated.
  3. chore(tidy): enforce identifier naming and declaration parameter names: extends readability-identifier-naming to every identifier kind, lists the public spellings kept for compatibility, makes naming findings blocking, and enables Strict parameter-name checking. docs/development.md gains a library-wide conventions section.

Compatibility

  • No public API, Python keyword, default, saved-index format or numerical change. Public names that break the conventions are kept and listed in .clang-tidy.
  • Python-visible message text changes: HNSW messages drop the colon after HNSW; QuantizedGraph messages start with QuantizedGraph; an unknown metric reports metric must be 'l2' or 'ip'; SymqgIndex.save before build reports ... must be built or loaded before save; two IVF messages name IVF. The untrained k-means error is now std::runtime_error (Python RuntimeError before and after).
  • Detail-header changes (no stability promise): VisitedListPool → VisitedSetPool with acquire()/release(), rabitqkmeans::detail::RaBitQAssigner → RaBitQAssignment, pipnn_impl folded into symqg::detail, the unused hnsw::detail::search_knn adapter removed.

Testing

Linux x86-64 (Xeon Gold 6418H), GCC 14.3 and Clang 23, RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF.

  • CTest (Release with samples and benchmarks, --no-tests=error): 443 passed, 1 skipped (OpenMP placement). The first commit alone: 427 passed.
  • Test inventory: 389 GoogleTest cases, the same set as before apart from renames; every CI --gtest_filter and -R pattern still selects tests.
  • Equivalence (checked during the change by independent reviewers against main):
    • HNSW and IVF saved files byte-identical across 12 and 24 save/load cases;
    • 2,400 HNSW search results identical;
    • core quantization and estimation outputs byte-identical over dims 32–1000 and ex_bits 0–8;
    • core, SIMD and FastScan object code identical apart from names.
  • Static analysis: check-format.sh, full check-tidy.sh with clang-tidy 23 (bindings on; 0 findings under the new rules), ShellCheck, git diff --check.
  • Python (package rebuilt and installed): check-python.sh; pytest tests/python 812 passed, 2 skipped; tests/test_pyright.py and tests/test_mypy.py pass.
  • Not run locally: NEON (compiled for aarch64 with Clang in review, not executed), Windows/MSVC, and AVX2-only execution; CI covers them.

Enable clang-format's InsertBraces and reformat first-party sources. About 1270 bodies were already braced and about 50 were not; the formatter now keeps them consistent. Formatting only.
Apply one convention per concept across core, SIMD, FastScan, HNSW, IVF, SymphonyQG, clustering, utils and the bindings, following the role names in docs/development.md. No public API, Python keyword, saved-format or numerical change; object code is unchanged except where internal names or linkage moved.

- Role names: internal_id for graph slots, assignments/cluster_id for centroid IDs, num_threads (requested) vs num_workers (resolved), batch_size vs num_points, lookup_table/accumulated_values, estimated_distances/lower_bounds, *_bytes/*_offset.
- HNSW: hnswlib-style private names (get_bindata_by_internalid, get_linklist0, datal, ...) renamed; empty-graph sentinel unified on kPidMax; private Candidate replaced by AnnCandidate; link counts use uint16_t/uint32_t with unchanged widths.
- Parameter names agree between declarations, definitions and every backend; template parameters are PascalCase; file-local helpers use anonymous namespaces; headers compiled under several ISA flags keep internal linkage.
- Error messages read "<Component> <text>". Python-visible text changes: HNSW messages drop the colon after "HNSW", QuantizedGraph messages start with "QuantizedGraph", an unknown metric reports "metric must be 'l2' or 'ip'", SymqgIndex.save reports "must be built or loaded before save", and two IVF messages name IVF. Exception types are unchanged except the untrained k-means error, now std::runtime_error (Python RuntimeError either way).
- Detail-header renames (no stability promise): VisitedListPool -> VisitedSetPool with acquire()/release(), clustering RaBitQAssigner -> RaBitQAssignment, pipnn_impl folded into symqg::detail, the unused detail::search_knn adapter removed.
- Test suites follow <Module><Area>Test; the CI GoogleTest filters and tests/README.md use the new names.
Extend readability-identifier-naming to functions, methods, types, enums, template parameters, constants, namespaces, public and protected members and macros, list the public spellings kept for compatibility, and make naming findings blocking. Enable Strict for readability-inconsistent-declaration-parameter-name. The tree has no findings under the new rules.

docs/development.md gains a library-wide conventions section (identifiers, linkage, namespaces, error messages, comments, tests), records the Python vocabulary kept for compatibility, and names assignments/cluster_id for clustering.
@github-actions github-actions Bot added the release:maintenance Release category managed from the PR title label Oct 31, 2026
@gouyt13
gouyt13 merged commit ddb6ac4 into main Oct 31, 2026
49 checks passed
@gouyt13
gouyt13 deleted the refactor/style-unification branch October 31, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:maintenance Release category managed from the PR title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant