mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-30 18:14:18 +01:00
[wgsl-in]: Correctly compare pointer types.
Treat `TypeInner::ValuePointer` and `TypeInner::Pointer` as equivalent by converting them to a canonical form before comparison. Support `ValuePointer` in WGSL type output. Fixes #1318.
This commit is contained in:
1 parent
6e4401ae96
commit
f3ea2130a4
6 files changed
+148
-9
No files matched your search
+10
-2
@@ -96,7 +96,11 @@ pub fn validate_compose(
|
||||
});
|
||||
}
|
||||
for (index, comp_res) in component_resolutions.enumerate() {
|
||||
if comp_res.inner_with(type_arena) != &type_arena[base].inner {
|
||||
let base_inner = &type_arena[base].inner;
|
||||
let comp_res_inner = comp_res.inner_with(type_arena);
|
||||
// We don't support arrays of pointers, but it seems best not to
|
||||
// embed that assumption here, so use `TypeInner::equivalent`.
|
||||
if !base_inner.equivalent(comp_res_inner, type_arena) {
|
||||
log::error!("Array component[{}] type {:?}", index, comp_res);
|
||||
return Err(ComposeError::ComponentType {
|
||||
index: index as u32,
|
||||
@@ -113,7 +117,11 @@ pub fn validate_compose(
|
||||
}
|
||||
for (index, (member, comp_res)) in members.iter().zip(component_resolutions).enumerate()
|
||||
{
|
||||
if comp_res.inner_with(type_arena) != &type_arena[member.ty].inner {
|
||||
let member_inner = &type_arena[member.ty].inner;
|
||||
let comp_res_inner = comp_res.inner_with(type_arena);
|
||||
// We don't support pointers in structs, but it seems best not to embed
|
||||
// that assumption here, so use `TypeInner::equivalent`.
|
||||
if !comp_res_inner.equivalent(member_inner, type_arena) {
|
||||
log::error!("Struct component[{}] type {:?}", index, comp_res);
|
||||
return Err(ComposeError::ComponentType {
|
||||
index: index as u32,
|
||||
|
||||
+13
-2
@@ -243,7 +243,8 @@ impl super::Validator {
|
||||
let ty = context
|
||||
.resolve_type_impl(expr, &self.valid_expression_set)
|
||||
.map_err(|error| CallError::Argument { index, error })?;
|
||||
if ty != &context.types[arg.ty].inner {
|
||||
let arg_inner = &context.types[arg.ty].inner;
|
||||
if !ty.equivalent(arg_inner, context.types) {
|
||||
return Err(CallError::ArgumentType {
|
||||
index,
|
||||
required: arg.ty,
|
||||
@@ -448,7 +449,17 @@ impl super::Validator {
|
||||
.map(|expr| context.resolve_type(expr, &self.valid_expression_set))
|
||||
.transpose()?;
|
||||
let expected_ty = context.return_type.map(|ty| &context.types[ty].inner);
|
||||
if value_ty != expected_ty {
|
||||
// We can't return pointers, but it seems best not to embed that
|
||||
// assumption here, so use `TypeInner::equivalent` for comparison.
|
||||
let okay = match (value_ty, expected_ty) {
|
||||
(None, None) => true,
|
||||
(Some(value_inner), Some(expected_inner)) => {
|
||||
value_inner.equivalent(expected_inner, context.types)
|
||||
}
|
||||
(_, _) => false,
|
||||
};
|
||||
|
||||
if !okay {
|
||||
log::error!(
|
||||
"Returning {:?} where {:?} is expected",
|
||||
value_ty,
|
||||
|
||||
Reference in new issue
Block a user