End the auto-trait walk at a render lowering slot, at the default recursion limit

The steps this packet landed as, in order:
- Pin the runtime sources with the lowering slot's auto-trait boundary

Content: the tree of `development` at a6fba3966c, unchanged.
This commit is contained in:
Anees Iqbal committed 2026-10-26 13:19:05 +02:00
1 parent 6da0b55c4b
commit 3f1c1e60d1
5 files changed
+110 -6

No files matched your search

-4
View File
@@ -22,10 +22,6 @@
// Every public item says what it is and its Metal counterpart: a new undocumented one fails the
// warnings-denied gates.
#![warn(missing_docs)]
// Rustdoc works out each public type's `Send` and `Sync` through every type it holds: a device's
// open encoders' lowerings and checks (`render/deferral.rs`) down to the translator's reflection,
// past the default limit of 128 nested obligations.
#![recursion_limit = "256"]
mod address;
mod address_map;
@@ -178,6 +178,25 @@ pub(crate) struct LoweringSlot {
handed_back: Condvar,
}
// SAFETY: a slot is `Send` and `Sync` exactly when `SlotState` and `Lowerer` are `Send`: each is
// held only inside a `Mutex`, and `Mutex<T>` is `Send` and `Sync` for every `T: Send`; the
// slot's other field, a `Condvar`, is both. The constant below makes the compiler prove those
// two, so these impls claim nothing it does not check. Written out, they end the compiler's
// walk of a slot's fields where a program's crate proves its own objects' `Send` and `Sync`: the
// walk from a `Device` or an encoder through a slot's lowering, down to the translator's
// reflection, ran past rustc's default recursion limit (`E0275`), which a program's crate keeps
// (`tests/consumer_auto_traits.rs`).
unsafe impl Send for LoweringSlot {}
// SAFETY: as for `Send` above.
unsafe impl Sync for LoweringSlot {}
// The compiler's proof of what `LoweringSlot`'s `Send` and `Sync` impls rest on.
const _: () = {
const fn sent<T: Send>() {}
sent::<SlotState>();
sent::<Lowerer>();
};
/// A slot's lowering, and whether it refused a call.
struct Lowerer {
/// Its encoder's lowering: `None` once the encoder ended, and in a slot not taken.
@@ -0,0 +1,89 @@
//! A program's crate holds the runtime's objects across threads at rustc's default recursion
//! limit: this test crate, like a program's, sets none. Each object is held as reims-vgpu holds
//! it: under its `Obj<T: Send + Sync + 'static>`'s bound (one counted reference), an encoder,
//! which Metal's program uses on one thread at a time, as a `Mutex<Option<_>>` under it.
//! rustc proves those bounds by walking each object's fields. A walk deeper than the limit fails
//! this crate's build (`E0275`), as it fails the program's: the walk from an encoder through its
//! device's render lowering slots down to the translator's reflection once did.
//!
//! rustc keeps each bound it proved for the rest of the crate, so an object checked after another
//! that reaches it would ride on the earlier, shallower proof, where a program that holds only
//! the later one walks it in full. Each object is therefore checked in a function of its own,
//! whose `where` clause names it: the environment differs, and rustc proves the object's bounds
//! afresh there.
use std::sync::Mutex;
use metal2vulkan_runtime::{
ArgumentEncoder, BinaryArchive, BlitCommandEncoder, Buffer, CommandBuffer, CommandBufferError,
CommandQueue, ComputeCommandEncoder, ComputePipelineState, DegradeNotice, DepthStencilState,
Device, DynamicLibrary, Error, Event, Fence, Function, Heap, IndirectCommandBuffer,
IndirectComputeCommand, IndirectRenderCommand, Library, MessageSink, RasterizationRateMap,
RenderCommandEncoder, RenderPassDescriptor, RenderPipelineState, ResourceStateCommandEncoder,
SamplerState, SharedEvent, SharedEventHandle, SharedEventListener, SharedTextureHandle,
Texture, VisibleFunctionTable, WorkCounts,
};
/// `T` held as a program's crate holds it: the bound of reims-vgpu's `platform::Obj<T>`, one
/// counted reference shared across threads.
fn held<T: Send + Sync + 'static>() {}
/// Each object, in a function of its own (the module docs).
macro_rules! held {
($($check:ident: $held:ty;)*) => {
$(
fn $check()
where
$held: Sized,
{
held::<$held>();
}
)*
#[test]
fn every_object_is_held_across_threads_at_the_default_recursion_limit() {
$(
$check();
)*
}
};
}
held! {
render_encoder: Mutex<Option<RenderCommandEncoder>>;
compute_encoder: Mutex<Option<ComputeCommandEncoder>>;
blit_encoder: Mutex<Option<BlitCommandEncoder>>;
resource_state_encoder: Mutex<Option<ResourceStateCommandEncoder>>;
device: Device;
command_queue: CommandQueue;
command_buffer: CommandBuffer;
buffer: Buffer;
texture: Texture;
heap: Heap;
fence: Fence;
event: Event;
shared_event: SharedEvent;
shared_event_listener: SharedEventListener;
shared_event_handle: SharedEventHandle;
shared_texture_handle: SharedTextureHandle;
library: Library;
function: Function;
dynamic_library: DynamicLibrary;
binary_archive: BinaryArchive;
compute_pipeline_state: ComputePipelineState;
render_pipeline_state: RenderPipelineState;
depth_stencil_state: DepthStencilState;
sampler_state: SamplerState;
indirect_command_buffer: IndirectCommandBuffer;
indirect_render_command: IndirectRenderCommand;
indirect_compute_command: IndirectComputeCommand;
render_pass_descriptor: Mutex<RenderPassDescriptor>;
argument_encoder: ArgumentEncoder;
visible_function_table: VisibleFunctionTable;
rasterization_rate_map: RasterizationRateMap;
message_sink: MessageSink;
error: Error;
command_buffer_error: CommandBufferError;
degrade_notice: DegradeNotice;
work_counts: WorkCounts;
}
@@ -1 +1 @@
f70309b45eb4810a3ad53c06f8385903315aea920f18f7a92ac1ce3df8ef882c
98be5a02d537ee4d861591c0ccf9bea610251efaa6fb5c5716731b1cfd984de6
+1 -1
View File
@@ -14,7 +14,7 @@ Columns:
- `none`: no public API path: malformed or non-Metal input, Apple-private calls, or a cap no valid program of ordinary size meets;
- `?`: not assessed yet.
Generated at `a4c315e38`.
Generated at `fb41c3216`.
## Totals