From 90daa9edfe9468db96ee6444395b71ea225465fc Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sun, 14 Nov 2021 12:05:29 -0800 Subject: [PATCH] Forbid specializable constants as array lengths. Only the SPIR-V front end can produce such array types, and it seems that our back ends don't support this case well. --- src/valid/type.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/valid/type.rs b/src/valid/type.rs index a180831dff..c052fa9b21 100644 --- a/src/valid/type.rs +++ b/src/valid/type.rs @@ -89,6 +89,8 @@ pub enum TypeError { InvalidArrayBaseType(Handle), #[error("The constant {0:?} can not be used for an array size")] InvalidArraySizeConstant(Handle), + #[error("The constant {0:?} is specialized, and cannot be used as an array size")] + UnsupportedSpecializedArrayLength(Handle), #[error("Array type {0:?} must have a length of one or more")] NonPositiveArrayLength(Handle), #[error("Array stride {stride} is smaller than the base element size {base_size}")] @@ -350,6 +352,19 @@ impl super::Validator { let sized_flag = match size { crate::ArraySize::Constant(const_handle) => { let length_is_positive = match constants.try_get(const_handle) { + Some(&crate::Constant { + specialization: Some(_), + .. + }) => { + // Many of our back ends don't seem to support + // specializable array lengths. If you want to try to make + // this work, be sure to address all uses of + // `Constant::to_array_length`, which ignores + // specialization. + return Err(TypeError::UnsupportedSpecializedArrayLength( + const_handle, + )); + } Some(&crate::Constant { inner: crate::ConstantInner::Scalar {