Skip to content

Commit fa550b5

Browse files
committed
adjust types for struct members
1 parent 39bf048 commit fa550b5

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

naga/src/compact/mod.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ pub fn compact(module: &mut crate::Module) {
221221
let crate::Comments {
222222
module: _,
223223
types: ref mut comment_types,
224-
struct_members: _,
224+
struct_members: ref mut comment_struct_members,
225225
entry_points: _,
226226
functions: _,
227227
constants: ref mut comment_constants,
228228
global_variables: _,
229229
} = **comments;
230-
log::trace!("adjusting comments types");
230+
log::trace!("adjusting comments for types");
231231
for comment_type_handle in comment_types.keys().cloned().collect::<Vec<_>>() {
232232
if !module_map.types.used(comment_type_handle) {
233233
comment_types.swap_remove(&comment_type_handle);
@@ -240,7 +240,25 @@ pub fn compact(module: &mut crate::Module) {
240240
comment_types.insert(handle_copy, comment);
241241
}
242242
}
243-
log::trace!("adjusting comments constants");
243+
log::trace!("adjusting comments for struct members");
244+
for comment_struct_member_handle in
245+
comment_struct_members.keys().cloned().collect::<Vec<_>>()
246+
{
247+
if !module_map.types.used(comment_struct_member_handle.0) {
248+
comment_struct_members.swap_remove(&comment_struct_member_handle);
249+
continue;
250+
}
251+
let mut handle_copy = comment_struct_member_handle.0;
252+
module_map.types.adjust(&mut handle_copy);
253+
if handle_copy != comment_struct_member_handle.0 {
254+
let comment = comment_struct_members
255+
.swap_remove(&comment_struct_member_handle)
256+
.unwrap();
257+
comment_struct_members
258+
.insert((handle_copy, comment_struct_member_handle.1), comment);
259+
}
260+
}
261+
log::trace!("adjusting comments for constants");
244262
for comment_constant_handle in comment_constants.keys().cloned().collect::<Vec<_>>() {
245263
if !module_map.constants.used(comment_constant_handle) {
246264
comment_constants.swap_remove(&comment_constant_handle);

naga/src/valid/handles.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ impl super::Validator {
293293
}
294294
_ => {
295295
// TODO: internal error ? We should never get here.
296+
// If entering there, it's probably that we forgot to adjust a handle in the compact phase.
296297
return Err(ValidationError::Type {
297298
handle: comment_struct_member_doc.0 .0,
298299
name: struct_type

0 commit comments

Comments
 (0)