Repository navigation
vector types: a vector through a reference, in a struct field and in a Vec - #4565
Merged
Merged
Conversation
…a Vec A `<4 x f64>` can now go through memory, as a number can: - A `&mut <4 x f64>` parameter, a reference to a vector field and a local reference read and write the vector. - A struct can have fields of vector types. - `Vec`, `Box` and the other std containers hold vectors, and structs with vector fields. The checker treats a vector as `Copy`, as it treats a number, so `Vec::get` takes one. The borrow checker needed no other change. The code generators load and store vectors through pointers and fields: - The legacy one stored a vector through a pointer or into a field with `vector.store`, which takes only a memref. It also took the slot of one vector, `memref<vector<4xf64>>`, for a tensor, because the type text has an `x`. - The flat one gives an `llvm.alloca` to a vector that `&v` borrows. - Both gave `sizeof` of a vector 8 bytes, so a `Vec` buffer was too small. A load or store of a whole `<4 x f64>` needs an address that is a multiple of 32, but the containers allocated at 16. `std::alloc::heap_align<T>()` gives the alignment of `T`, and at least 16. Vx has no `alignof<T>()`, so it measures the padding before a `T` that comes after one byte. Each container allocates with it, and `vec_alloc` and `vec_grow` take it. Left for later (#485): an `extern "C"` function that takes or returns a vector, or a struct with a vector field, is not refused yet. Fixes: #4381 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Dec 3, 2026
Four compile_time_of_ifs_in_a_row tests fail on main: the Vx solver cannot prove their ensures
#4567
Closed
This was referenced Dec 4, 2026
hiraditya
added a commit
that referenced
this pull request
Dec 4, 2026
Both code generators decide some facts about an MLIR type from its printed form. #4565 added more of these tests. This commit removes them, and the older tests that they extended. The AST code generator: - `has_extents` read the text of a memref type to find its rank. It is gone. `one_value_memref_element` asks melior for the rank and the element type. - `is_scalar_memref` uses the same query. The places that repeated its three text tests now call it. - A load through `&mut` cut the type text at byte 7 and parsed the rest back into a type. Now it takes the element of the memref type. The flat code generator: - Five tables for each register gave the kind of slot of a local. One `Slot` enum replaces them. A `Store` and a `SlotLoad` now have two forms, one for a memref slot and one for an `llvm.alloca` slot. - A field load found a vector field by the text `vector<`. Now it uses the type of its result. - `elem_of_gid` and `vector_of_gid` hashed up to 242 types to find the type of a type ID. Now a lookup table gives it. - The `imm` of an `Alloca` for a local that `&x` borrows is the named constant `IMM_ADDRESS_TAKEN`, not a bare 1. Issue: #388 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4381.
A
<4 x f64>can now go through memory, as a number can. The three programs of the issue compile with both code generators and print the right answer:&mut <4 x f64>parameter.Vec<<4 x f64>>.The choice
The request was to keep the change small, and to use MLIR or
unsafewhere a checker change looked large. No checker change was large. The borrow checker already tracks a reference to a vector as a reference to a number. It refuses the same conflicts (E4002, E4004). The checker needed one change: a vector isCopy, soVec::gettakes it. So a program needs nounsafeand nomlir!block. The work is in the code generators, which load and store a vector through a pointer withllvm.loadandllvm.store.Alignment
A load or store of a whole
<4 x f64>needs an address that is a multiple of 32. The std containers allocated at 16. With the code generator fixes alone,Vec<<4 x f64>>::pushcrashed with SIGSEGV: LLVM uses an aligned move, because vxc compiles with-mcpu=native.std::alloc::heap_align<T>()gives the alignment ofT, and at least 16. Vx has noalignof<T>()yet, so it measures the padding before aTthat comes after one byte.Vec,Box,RefArena,HashMap, the channels,broadcastandwatchallocate with it. A type that needs 16 or less allocates as before.vec_allocandvec_growtake the alignment. So the 14 tests that match thevec_growcall have one more argument, and so has the test that calls the privatevec_grow.Tests
One test for each case of the issue, in
tests/backend/pass/. Each runs with both code generators, and the flat one must not fall back. I broke each part of the change and ran every RUN line:has_extents)parameterparameter,field,local, structfield,reference,vecsizes,bodiessizeofof a vectorvecllvm.allocaBox<<4 x f64>>CopyvecVecallocates at 16vec,bodies, in 3 of 3 runsBoxallocates at 16box, in 3 of 3 runsheap_aligngives 16heap_alignA check after the first failing one does not run. I checked such a line with a copy of the test that keeps only its case.
cargo test --no-fail-fastpassed here, except four tests incompile_time_of_ifs_in_a_row. They fail on main too. For their programs, the solver written in Vx (#4557) takes about 10 s in a debug build, and z3 takes 0.4 s.Left for later
extern "C"signature. This PR does not add that refusal, and the checker accepts such a signature.alignof<T>()could replace the measurement inheap_align.Generated With Claude Code