Skip to content

Finish the LONG_IS_A_DISTINCT_TYPE conversion, and fix it for wasm64 - #112866

Merged
alexey-milovidov merged 7 commits into
masterfrom
unsigned-long-distinct-type
Aug 6, 2026
Merged

alexey-milovidov merged 7 commits into
masterfrom
unsigned-long-distinct-type

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

base/defines.h names the two conditions under which long and size_t are types of their own, distinct from every fixed-width integer type, and base/itoa.h and Common/iota.h already use them. Two places still spelled the same thing OS_DARWIN: the Field::safeGet<unsigned long> instantiation and the ColumnVector<T>::indexImpl<size_t> ones. base/defines.h is now included outright in both files rather than relied on transitively, since the #if would silently evaluate false if it ever stopped arriving — and on Linux that is also the correct answer, so nothing would notice until a Darwin build failed to link.

While converting them, one of the two macros turned out to be wrong.

LONG_IS_A_DISTINCT_TYPE tests !defined(__LP64__), which does not hold for wasm64: that target is LP64, so long is 64 bits wide, but its uint64_t is unsigned long long, so long is still not one of the fixed-width types. The macro therefore said "not distinct" while SIZE_T_IS_A_DISTINCT_TYPE said "distinct" — and since size_t is unsigned long there, the two contradicted each other, despite one being documented as strictly narrower than the other. The symptom is that itoa(size_t) becomes ambiguous, a long way from anything that mentions either macro.

So: name WebAssembly explicitly, state the implication between the two macros as an #error, and give base/itoa.h the self-check that Common/iota.h already has, so the condition cannot drift from the types it describes again.

No change on any platform that builds today — __LP64__ is defined and __wasm__ is not, so LONG_IS_A_DISTINCT_TYPE is unset exactly as before, and the two new static_asserts and the #error all hold.

Checked with Emscripten 6.0.5: -sMEMORY64=1 confirms __LP64__ is defined, size_t is unsigned long and uint64_t is unsigned long long; itoa(size_t) resolves after this change and does not before. On the host both static_asserts hold, and the #error fires when the macros are forced out of agreement.

Related: #112911

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

`base/defines.h` names the two conditions under which `long` and `size_t` are
types of their own, distinct from every fixed-width integer type, and
`base/itoa.h` and `Common/iota.h` already use them. Two places still spell the
same thing `OS_DARWIN`: the `Field::safeGet<unsigned long>` instantiation and
the `ColumnVector<T>::indexImpl<size_t>` ones.

No behaviour change on any platform - both macros are defined exactly when
`OS_DARWIN` is - but the named conditions say why the instantiation is there,
and cover the other platforms where it is needed. `base/defines.h` is now
included outright in both files rather than relied on transitively, since the
`#if` would silently evaluate false if it ever stopped arriving.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5d1e55d]

Summary: ✅


AI Review

Summary

This PR finishes the LONG_IS_A_DISTINCT_TYPE / SIZE_T_IS_A_DISTINCT_TYPE conversion by moving the remaining OS_DARWIN checks to the named predicates, fixing the LONG_IS_A_DISTINCT_TYPE definition for WebAssembly, and adding a compile-time self-check in base/itoa.h so the predicate cannot silently drift from the overload set again. I did not find a remaining contract violation in the touched code: the updated predicates are consistent with the existing itoa / iota explicit instantiations, the Field::safeGet<unsigned long> and ColumnVector<T>::indexImpl<size_t> specializations now follow the same invariant, and the documented WebAssembly build modes used in this repository are compatible with the new conditions.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.80% 78.80% +0.00%

Changed lines: Changed C/C++ lines covered: 0/0 (nothing coverable) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 1, 2026
…each other

`LONG_IS_A_DISTINCT_TYPE` tests `!defined(__LP64__)`, which is wrong for `wasm64`: that
target is LP64, so `long` is 64 bits wide, but its `uint64_t` is `unsigned long long`, so
`long` is still not one of the fixed-width types. The macro therefore said "not distinct"
while `SIZE_T_IS_A_DISTINCT_TYPE` said "distinct" - and since `size_t` is `unsigned long`
there, the two contradicted each other. The symptom is that `itoa(size_t)` becomes
ambiguous, far from anything that mentions either macro.

Name WebAssembly explicitly, and state the implication between the two macros as an
`#error`, since one is documented as strictly narrower than the other. `base/itoa.h` also
gains the self-check that `Common/iota.h` already has, so the condition cannot silently
drift from the types it is describing.

No change on any platform that builds today: `__LP64__` is defined and `__wasm__` is not,
so `LONG_IS_A_DISTINCT_TYPE` is unset exactly as before, and the two static_asserts and the
`#error` all hold.

Checked with Emscripten 6.0.5: `-sMEMORY64=1` confirms `__LP64__` is defined, `size_t` is
`unsigned long` and `uint64_t` is `unsigned long long`, and `itoa(size_t)` resolves after
this change and does not before. On the host both static_asserts hold and the `#error`
fires when the macros are forced out of agreement.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov alexey-milovidov changed the title Finish the LONG_IS_A_DISTINCT_TYPE conversion Finish the LONG_IS_A_DISTINCT_TYPE conversion, and fix it for wasm64 Aug 1, 2026
The `#else` branch of the new self-check spells `long` in a `std::is_same_v`
comparison, and clang-tidy asks to replace it with `int64` - which is exactly
the thing the assertion is there to rule out, so the suggestion cannot be
followed. Wrap the whole conditional in `NOLINTBEGIN`/`NOLINTEND` for
`google-runtime-int`; the `#if` branch instantiates `long` and `unsigned long`
for the same reason and would hit it on Darwin and `wasm64`.

Failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112866&sha=ada63397799cda5d8ce97f24627363d536e01b2b&name_0=PR&name_1=Build%20%28arm_tidy%29
#112866
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only CI red was Stress test (arm_msan) → Logical error: Cannot capture column A because it has incompatible type: got B, but C is expected. (STID: 3293-4e7f), an AST-fuzzer logical error in ColumnFunction::appendArgument reached through the analyzer. It is unrelated to this PR, which only changes the LONG_IS_A_DISTINCT_TYPE / SIZE_T_IS_A_DISTINCT_TYPE predicates and the corresponding explicit instantiations. A fix is already in progress: #111993 (fix-3293-4e7f-lambda-qualified-asterisk-jun).

Merged master and re-ran CI.

pull Bot pushed a commit to weiyilai/ClickHouse that referenced this pull request Aug 4, 2026
The test needs INSERT analysis to serve a stale schema while the sink
force-reads the latest one. It built that by warming the server-global
Iceberg metadata files cache and relying on the entry surviving to the
INSERT. That cache is SLRU-bounded at 1000 entries and shared with every
other test on the server, so a cache left at its bound by earlier tests
evicts the entry: the INSERT reads fresh, both views agree, and the
rejection correctly does not fire.

A second defect made that silent. Both oracles were
`grep -oF "INCORRECT_DATA"`, which prints nothing for a successful INSERT
and nothing for a different error code, so the reference diff could not
distinguish a wrong error code from no error at all, and in the opposite
cache state the test passed vacuously.

Clear the cache immediately before each warm-up SELECT so the test owns
the state it depends on, and report the actual outcome for every outcome
(the error code name, or NO_ERROR). The reference file is unchanged, so
the rejection must still fire in both scenarios; a run that stops
exercising it now fails and names what happened instead of passing.

no-parallel is kept, and its comment now states the real reason: the
test issues a server-global cache clear, so it must be alone on the
server. That is the same pairing 03272_prewarm_mark_cache_add_column.sql
uses for the mark cache.

Validation: with the cache bound lowered to 40 and pre-filled to 40/40
occupancy (measured via IcebergMetadataFilesCacheFiles), the old form
fails with a stdout diff byte-identical to the CI failure and the new
form passes on that same injected state. 50/50 randomized runs pass.
The only other tests using iceberg_metadata_staleness_ms, 04214 and
04337, are not exposed to residual occupancy and are unchanged.

Failed 7 times on Stateless tests (arm_asan_ubsan, targeted) across two
unrelated PRs, ClickHouse#113010 and ClickHouse#112866.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (clean, no conflicts; pushed a4f029a5239) — this pulls in #113232, which fixes the flaky 04329_iceberg_insert_stale_schema_field_id_107268 stateless failure. The remaining reds, Stress test (arm_msan) and AST fuzzer (arm_asan_ubsan), are both the known unrelated Logical error: ColumnBLOB should be converted to a regular column before usage, tracked in #113165 with a fix in progress in #111997. The three TUs this PR touches (base/itoa.cpp, Core/Field.cpp, Columns/ColumnVector.cpp) build clean after the merge.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Aug 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 5, 2026
Merged via the queue into master with commit 45d3f18 Aug 6, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the unsigned-long-distinct-type branch August 6, 2026 00:24
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants