Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested struct sort order #3321

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn type_collect_standalone_nested(
td: metadata::TypeDef,
set: &mut std::collections::BTreeSet<metadata::Type>,
) {
for nested in td.reader().nested_types(td) {
for (_, nested) in td.reader().nested_types(td) {
type_collect_standalone_nested(writer, nested, set);

for field in nested.fields() {
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn gen_struct_with_name(
});
}

for (index, nested_type) in writer.reader.nested_types(def).enumerate() {
for (index, nested_type) in writer.reader.nested_types(def) {
let nested_name = format!("{struct_name}_{index}");
tokens.combine(&gen_struct_with_name(
writer,
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl Writer {
}
fn scoped_name(&self, def: metadata::TypeDef) -> String {
if let Some(enclosing_type) = def.enclosing_type() {
for (index, nested_type) in self.reader.nested_types(enclosing_type).enumerate() {
for (index, nested_type) in self.reader.nested_types(enclosing_type) {
if nested_type.name() == def.name() {
return format!("{}_{index}", &self.scoped_name(enclosing_type));
}
Expand Down
13 changes: 5 additions & 8 deletions crates/libs/metadata/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Item {
pub struct Reader {
items: BTreeMap<&'static str, BTreeMap<&'static str, Vec<Item>>>,

nested: HashMap<TypeDef, BTreeMap<&'static str, TypeDef>>,
nested: HashMap<TypeDef, BTreeMap<&'static str, (usize, TypeDef)>>,

// The reader needs to store the filter since standalone code generation needs more than just the filtered items
// in order to chase dependencies automatically. This is why `Reader::filter` can't just filter everything up front.
Expand Down Expand Up @@ -85,11 +85,8 @@ impl Reader {

for key in file.table::<NestedClass>() {
let inner = key.inner();
reader
.nested
.entry(key.outer())
.or_default()
.insert(inner.name(), inner);
let types = reader.nested.entry(key.outer()).or_default();
types.insert(inner.name(), (types.len(), inner));
}
}

Expand Down Expand Up @@ -203,7 +200,7 @@ impl Reader {
})
}

pub fn nested_types(&self, type_def: TypeDef) -> impl Iterator<Item = TypeDef> + '_ {
pub fn nested_types(&self, type_def: TypeDef) -> impl Iterator<Item = (usize, TypeDef)> + '_ {
self.nested
.get(&type_def)
.map(|map| map.values().copied())
Expand Down Expand Up @@ -262,7 +259,7 @@ impl Reader {
// TODO: this needs to be deferred via a TypeName's optional nested type name?
if let Some(outer) = enclosing {
if full_name.namespace().is_empty() {
let Some(inner) = self
let Some((_, inner)) = self
.nested
.get(&outer)
.and_then(|nested| nested.get(full_name.name()))
Expand Down
168 changes: 84 additions & 84 deletions crates/libs/sys/src/Windows/Wdk/Foundation/mod.rs

Large diffs are not rendered by default.

128 changes: 64 additions & 64 deletions crates/libs/sys/src/Windows/Wdk/Graphics/Direct3D/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2254,9 +2254,9 @@ pub struct D3DDDI_ALLOCATIONINFO2 {
pub pPrivateDriverData: *mut core::ffi::c_void,
pub PrivateDriverDataSize: u32,
pub VidPnSourceId: u32,
pub Flags: D3DDDI_ALLOCATIONINFO2_2,
pub Flags: D3DDDI_ALLOCATIONINFO2_1,
pub GpuVirtualAddress: u64,
pub Anonymous2: D3DDDI_ALLOCATIONINFO2_1,
pub Anonymous2: D3DDDI_ALLOCATIONINFO2_2,
pub Reserved: [usize; 5],
}
#[repr(C)]
Expand All @@ -2267,19 +2267,19 @@ pub union D3DDDI_ALLOCATIONINFO2_0 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union D3DDDI_ALLOCATIONINFO2_1 {
pub union D3DDDI_ALLOCATIONINFO2_2 {
pub Priority: u32,
pub Unused: usize,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union D3DDDI_ALLOCATIONINFO2_2 {
pub Anonymous: D3DDDI_ALLOCATIONINFO2_2_0,
pub union D3DDDI_ALLOCATIONINFO2_1 {
pub Anonymous: D3DDDI_ALLOCATIONINFO2_1_0,
pub Value: u32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_ALLOCATIONINFO2_2_0 {
pub struct D3DDDI_ALLOCATIONINFO2_1_0 {
pub _bitfield: u32,
}
#[repr(C)]
Expand Down Expand Up @@ -2725,13 +2725,13 @@ pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO {
#[repr(C)]
#[derive(Clone, Copy)]
pub union D3DDDI_SYNCHRONIZATIONOBJECTINFO_0 {
pub SynchronizationMutex: D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_2,
pub SynchronizationMutex: D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_0,
pub Semaphore: D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_1,
pub Reserved: D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_0,
pub Reserved: D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_2,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_0 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_2 {
pub Reserved: [u32; 16],
}
#[repr(C)]
Expand All @@ -2742,7 +2742,7 @@ pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_1 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_2 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO_0_0 {
pub InitialState: super::super::super::Win32::Foundation::BOOL,
}
#[repr(C)]
Expand All @@ -2756,27 +2756,27 @@ pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2 {
#[repr(C)]
#[derive(Clone, Copy)]
pub union D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0 {
pub SynchronizationMutex: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_6,
pub Semaphore: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_5,
pub Fence: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_1,
pub CPUNotification: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_0,
pub MonitoredFence: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_2,
pub PeriodicMonitoredFence: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_3,
pub Reserved: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_4,
pub SynchronizationMutex: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_0,
pub Semaphore: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_1,
pub Fence: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_2,
pub CPUNotification: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_3,
pub MonitoredFence: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_4,
pub PeriodicMonitoredFence: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_5,
pub Reserved: D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_6,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_0 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_3 {
pub Event: super::super::super::Win32::Foundation::HANDLE,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_1 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_2 {
pub FenceValue: u64,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_2 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_4 {
pub InitialFenceValue: u64,
pub FenceValueCPUVirtualAddress: *mut core::ffi::c_void,
pub FenceValueGPUVirtualAddress: u64,
Expand All @@ -2785,7 +2785,7 @@ pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_2 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_3 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_5 {
pub hAdapter: u32,
pub VidPnTargetId: u32,
pub Time: u64,
Expand All @@ -2796,18 +2796,18 @@ pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_3 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_4 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_6 {
pub Reserved: [u64; 8],
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_5 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_1 {
pub MaxCount: u32,
pub InitialCount: u32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_6 {
pub struct D3DDDI_SYNCHRONIZATIONOBJECTINFO2_0_0 {
pub InitialState: super::super::super::Win32::Foundation::BOOL,
}
#[repr(C)]
Expand Down Expand Up @@ -2889,14 +2889,14 @@ pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION {
#[repr(C)]
#[derive(Clone, Copy)]
pub union D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0 {
pub Map: D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_2,
pub Map: D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_0,
pub MapProtect: D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_1,
pub Unmap: D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_3,
pub Copy: D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_0,
pub Unmap: D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_2,
pub Copy: D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_3,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_0 {
pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_3 {
pub SourceAddress: u64,
pub SizeInBytes: u64,
pub DestAddress: u64,
Expand All @@ -2914,7 +2914,7 @@ pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_1 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_2 {
pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_0 {
pub BaseAddress: u64,
pub SizeInBytes: u64,
pub hAllocation: u32,
Expand All @@ -2923,7 +2923,7 @@ pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_2 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_3 {
pub struct D3DDDI_UPDATEGPUVIRTUALADDRESS_OPERATION_0_2 {
pub BaseAddress: u64,
pub SizeInBytes: u64,
pub Protection: D3DDDIGPUVIRTUALADDRESS_PROTECTION_TYPE,
Expand Down Expand Up @@ -7345,25 +7345,25 @@ pub struct D3DKMT_VIDMM_ESCAPE {
#[repr(C)]
#[derive(Clone, Copy)]
pub union D3DKMT_VIDMM_ESCAPE_0 {
pub SetFault: D3DKMT_VIDMM_ESCAPE_0_9,
pub Evict: D3DKMT_VIDMM_ESCAPE_0_4,
pub EvictByNtHandle: D3DKMT_VIDMM_ESCAPE_0_3,
pub GetVads: D3DKMT_VIDMM_ESCAPE_0_6,
pub SetBudget: D3DKMT_VIDMM_ESCAPE_0_8,
pub SuspendProcess: D3DKMT_VIDMM_ESCAPE_0_11,
pub ResumeProcess: D3DKMT_VIDMM_ESCAPE_0_7,
pub GetBudget: D3DKMT_VIDMM_ESCAPE_0_5,
pub SetTrimIntervals: D3DKMT_VIDMM_ESCAPE_0_10,
pub SetFault: D3DKMT_VIDMM_ESCAPE_0_0,
pub Evict: D3DKMT_VIDMM_ESCAPE_0_1,
pub EvictByNtHandle: D3DKMT_VIDMM_ESCAPE_0_2,
pub GetVads: D3DKMT_VIDMM_ESCAPE_0_3,
pub SetBudget: D3DKMT_VIDMM_ESCAPE_0_4,
pub SuspendProcess: D3DKMT_VIDMM_ESCAPE_0_5,
pub ResumeProcess: D3DKMT_VIDMM_ESCAPE_0_6,
pub GetBudget: D3DKMT_VIDMM_ESCAPE_0_7,
pub SetTrimIntervals: D3DKMT_VIDMM_ESCAPE_0_8,
pub EvictByCriteria: D3DKMT_EVICTION_CRITERIA,
pub Wake: D3DKMT_VIDMM_ESCAPE_0_13,
pub Defrag: D3DKMT_VIDMM_ESCAPE_0_0,
pub DelayExecution: D3DKMT_VIDMM_ESCAPE_0_1,
pub Wake: D3DKMT_VIDMM_ESCAPE_0_9,
pub Defrag: D3DKMT_VIDMM_ESCAPE_0_10,
pub DelayExecution: D3DKMT_VIDMM_ESCAPE_0_11,
pub VerifyIntegrity: D3DKMT_VIDMM_ESCAPE_0_12,
pub DelayedEvictionConfig: D3DKMT_VIDMM_ESCAPE_0_2,
pub DelayedEvictionConfig: D3DKMT_VIDMM_ESCAPE_0_13,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_0 {
pub struct D3DKMT_VIDMM_ESCAPE_0_10 {
pub Operation: D3DKMT_DEFRAG_ESCAPE_OPERATION,
pub SegmentId: u32,
pub TotalCommitted: u64,
Expand All @@ -7373,45 +7373,45 @@ pub struct D3DKMT_VIDMM_ESCAPE_0_0 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_1 {
pub struct D3DKMT_VIDMM_ESCAPE_0_11 {
pub hPagingQueue: u32,
pub PhysicalAdapterIndex: u32,
pub Milliseconds: u32,
pub PagingFenceValue: u64,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_2 {
pub struct D3DKMT_VIDMM_ESCAPE_0_13 {
pub TimerValue: i64,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_3 {
pub struct D3DKMT_VIDMM_ESCAPE_0_2 {
pub NtHandle: u64,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_4 {
pub struct D3DKMT_VIDMM_ESCAPE_0_1 {
pub ResourceHandle: u32,
pub AllocationHandle: u32,
pub hProcess: super::super::super::Win32::Foundation::HANDLE,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_5 {
pub struct D3DKMT_VIDMM_ESCAPE_0_7 {
pub NumBytesToTrim: u64,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_6 {
pub Anonymous: D3DKMT_VIDMM_ESCAPE_0_6_0,
pub struct D3DKMT_VIDMM_ESCAPE_0_3 {
pub Anonymous: D3DKMT_VIDMM_ESCAPE_0_3_0,
pub Command: D3DKMT_VAD_ESCAPE_COMMAND,
pub Status: super::super::super::Win32::Foundation::NTSTATUS,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union D3DKMT_VIDMM_ESCAPE_0_6_0 {
pub GetNumVads: D3DKMT_VIDMM_ESCAPE_0_6_0_0,
pub union D3DKMT_VIDMM_ESCAPE_0_3_0 {
pub GetNumVads: D3DKMT_VIDMM_ESCAPE_0_3_0_0,
pub GetVad: D3DKMT_VAD_DESC,
pub GetVadRange: D3DKMT_VA_RANGE_DESC,
pub GetGpuMmuCaps: D3DKMT_GET_GPUMMU_CAPS,
Expand All @@ -7420,46 +7420,46 @@ pub union D3DKMT_VIDMM_ESCAPE_0_6_0 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_6_0_0 {
pub struct D3DKMT_VIDMM_ESCAPE_0_3_0_0 {
pub NumVads: u32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_7 {
pub struct D3DKMT_VIDMM_ESCAPE_0_6 {
pub hProcess: super::super::super::Win32::Foundation::HANDLE,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_8 {
pub struct D3DKMT_VIDMM_ESCAPE_0_4 {
pub LocalMemoryBudget: u64,
pub SystemMemoryBudget: u64,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_9 {
pub Anonymous: D3DKMT_VIDMM_ESCAPE_0_9_0,
pub struct D3DKMT_VIDMM_ESCAPE_0_0 {
pub Anonymous: D3DKMT_VIDMM_ESCAPE_0_0_0,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union D3DKMT_VIDMM_ESCAPE_0_9_0 {
pub Anonymous: D3DKMT_VIDMM_ESCAPE_0_9_0_0,
pub union D3DKMT_VIDMM_ESCAPE_0_0_0 {
pub Anonymous: D3DKMT_VIDMM_ESCAPE_0_0_0_0,
pub Value: u32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_9_0_0 {
pub struct D3DKMT_VIDMM_ESCAPE_0_0_0_0 {
pub _bitfield: u32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_10 {
pub struct D3DKMT_VIDMM_ESCAPE_0_8 {
pub MinTrimInterval: u32,
pub MaxTrimInterval: u32,
pub IdleTrimInterval: u32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_11 {
pub struct D3DKMT_VIDMM_ESCAPE_0_5 {
pub hProcess: super::super::super::Win32::Foundation::HANDLE,
pub bAllowWakeOnSubmission: super::super::super::Win32::Foundation::BOOL,
}
Expand All @@ -7470,7 +7470,7 @@ pub struct D3DKMT_VIDMM_ESCAPE_0_12 {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct D3DKMT_VIDMM_ESCAPE_0_13 {
pub struct D3DKMT_VIDMM_ESCAPE_0_9 {
pub bFlush: super::super::super::Win32::Foundation::BOOL,
}
#[repr(C)]
Expand Down
Loading