Skip to content

Separate the language Type from the ABI halide_type_t#9205

Open
alexreinking wants to merge 4 commits into
mainfrom
alexreinking/type-exploration
Open

Separate the language Type from the ABI halide_type_t#9205
alexreinking wants to merge 4 commits into
mainfrom
alexreinking/type-exploration

Conversation

@alexreinking

Copy link
Copy Markdown
Member
  • ABI halide_type_t drops lanes -> {code, bits, reserved} (still 4 bytes; halide_buffer_t layout unchanged). Halide::Type is decoupled and stores its own fields; must be explicitly erased with as_abi (asserts scalar), Trace event/packet carry their own lanes.
  • Halide::Type is reduced to 8 bytes: the handle_type pointer is replaced by a 4-byte index into a process-wide handle-type intern table.
  • The IR matcher / constant folder uses Halide::Type directly; This keeps handle C++-type metadata fidelity through matcher reconstruction.

Some open problems remain:

  • d3d12 buffer element types treated as scalar (multi-channel texture format selection is a follow-up). @slomp maybe you know something about this? I don't think it's tested at all.
  • Need to audit tutorials and anything else that talks about types, lanes, etc.

Fixes #9202
Fixes #9203

Breaking changes

The Type and halide_type_t arguments have been significantly reworked. This is both an ABI and an API break.

Checklist

  • Tests added or updated (not required for docs, CI config, or typo fixes)
  • Documentation updated (if public API changed)
  • Python bindings updated (if public API changed)
  • Benchmarks are included here if the change is intended to affect performance.
  • Commits include AI attribution where applicable (see Code of Conduct)

@alexreinking alexreinking requested a review from abadams July 13, 2026 22:08
@alexreinking alexreinking force-pushed the alexreinking/type-exploration branch 5 times, most recently from 0bd2e30 to 3f1f8c9 Compare July 13, 2026 22:46
Comment thread src/Type.cpp
Comment on lines +264 to +267
std::scoped_lock lock(handle_type_intern_mutex());
auto &table = handle_type_intern_table();
internal_assert(index <= table.size()) << "invalid handle-type intern index";
return table[index - 1];

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.

Wondering if we need to lock here

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.67045% with 61 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@2e2336b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/IRMatch.h 87.23% 16 Missing and 2 partials ⚠️
src/Type.cpp 67.50% 5 Missing and 8 partials ⚠️
src/Type.h 81.39% 4 Missing and 4 partials ⚠️
src/Callable.h 64.28% 2 Missing and 3 partials ⚠️
src/CodeGen_C.cpp 85.71% 1 Missing and 3 partials ⚠️
src/runtime/HalideRuntime.h 75.00% 4 Missing ⚠️
src/CodeGen_LLVM.cpp 40.00% 2 Missing and 1 partial ⚠️
src/CPlusPlusMangle.cpp 92.00% 1 Missing and 1 partial ⚠️
src/WasmExecutor.cpp 83.33% 2 Missing ⚠️
src/Buffer.h 66.66% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9205   +/-   ##
=======================================
  Coverage        ?   70.37%           
=======================================
  Files           ?      255           
  Lines           ?    78617           
  Branches        ?    18809           
=======================================
  Hits            ?    55323           
  Misses          ?    17742           
  Partials        ?     5552           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexreinking alexreinking force-pushed the alexreinking/type-exploration branch 3 times, most recently from 8c26c6f to 89ab379 Compare July 14, 2026 12:02
alexreinking and others added 3 commits July 14, 2026 09:46
- ABI halide_type_t drops `lanes` -> {code, bits, reserved} (still 4 bytes;
  halide_buffer_t layout unchanged). Halide::Type is decoupled and stores
  its own fields; must be explicitly erased with `as_abi` (asserts scalar),
  Trace event/packet carry their own `lanes`.
- Halide::Type is reduced to 8 bytes: the handle_type pointer is replaced
  by a 4-byte index into a process-wide handle-type intern table.
- The IR matcher / constant folder uses Halide::Type directly; This keeps
  handle C++-type metadata fidelity through matcher reconstruction.
- CodeGen intrinsic tables (ARM/X86/Hexagon/PowerPC/WebAssembly) use
  Halide::Type.
- Added ostream operator<< support for halide_type_t directly.

Some open problems remain:

- d3d12 buffer element types treated as scalar (multi-channel texture format
  selection is a follow-up).
- A few instances call for invalid/uninitialized `Type`s, which goes against
  the overarching goal of making Type always coherent.

Fixes #9202
Fixes #9203

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alexreinking alexreinking force-pushed the alexreinking/type-exploration branch from 89ab379 to cd20a61 Compare July 14, 2026 13:46
@slomp

slomp commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

d3d12 buffer element types treated as scalar

IIRC, the no-scalar buffer formats would only be applicable in specific instances of vectorized inputs/outputs.
I do remember testing the behavior waaay back when, but I don't think actual tests were added to the repository.

@alexreinking

Copy link
Copy Markdown
Member Author

IIRC, the no-scalar buffer formats would only be applicable in specific instances of vectorized inputs/outputs.
I do remember testing the behavior waaay back when, but I don't think actual tests were added to the repository.

I wonder whether they actually work on main... In any case, we'll need a Type-driven (rather than halide_type_t-driven) way of communicating that information to D3D12.

Comment thread src/Type.h
/** Compare ordering of two types so they can be used in certain containers and algorithms */
bool operator<(const Type &other) const {
if (type < other.type) {
if (std::tie(type_code, type_bits, type_lanes) <

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IRMatch drops Handle metadata Runtime buffers' pointer/size arithmetic ignores type.lanes

3 participants