1mod analyzer;
6mod compose;
7mod expression;
8mod function;
9mod handles;
10mod interface;
11mod r#type;
12
13use alloc::{boxed::Box, string::String, vec, vec::Vec};
14use core::ops;
15
16use bit_set::BitSet;
17
18use crate::{
19 arena::{Handle, HandleSet},
20 proc::{ExpressionKindTracker, LayoutError, Layouter, TypeResolution},
21 FastHashSet,
22};
23
24use crate::span::{AddSpan as _, WithSpan};
28pub use analyzer::{ExpressionInfo, FunctionInfo, GlobalUse, Uniformity, UniformityRequirements};
29pub use compose::ComposeError;
30pub use expression::{check_literal_value, LiteralError};
31pub use expression::{ConstExpressionError, ExpressionError};
32pub use function::{CallError, FunctionError, LocalVariableError, SubgroupError};
33pub use interface::{EntryPointError, GlobalVariableError, VaryingError};
34pub use r#type::{Disalignment, ImmediateError, TypeError, TypeFlags, WidthError};
35
36use self::handles::InvalidHandleError;
37
38pub const MAX_TYPE_SIZE: u32 = 0x4000_0000; bitflags::bitflags! {
42 #[cfg_attr(feature = "serialize", derive(serde::Serialize))]
56 #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
57 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
58 pub struct ValidationFlags: u8 {
59 const EXPRESSIONS = 0x1;
61 const BLOCKS = 0x2;
63 const CONTROL_FLOW_UNIFORMITY = 0x4;
65 const STRUCT_LAYOUTS = 0x8;
67 const CONSTANTS = 0x10;
69 const BINDINGS = 0x20;
71 }
72}
73
74impl Default for ValidationFlags {
75 fn default() -> Self {
76 Self::all()
77 }
78}
79
80bitflags::bitflags! {
81 #[must_use]
83 #[cfg_attr(feature = "serialize", derive(serde::Serialize))]
84 #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
85 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
86 pub struct Capabilities: u64 {
87 const IMMEDIATES = 1 << 0;
91 const FLOAT64 = 1 << 1;
93 const PRIMITIVE_INDEX = 1 << 2;
97 const TEXTURE_AND_SAMPLER_BINDING_ARRAY = 1 << 3;
99 const BUFFER_BINDING_ARRAY = 1 << 4;
101 const STORAGE_TEXTURE_BINDING_ARRAY = 1 << 5;
103 const STORAGE_BUFFER_BINDING_ARRAY = 1 << 6;
105 const CLIP_DISTANCE = 1 << 7;
109 const CULL_DISTANCE = 1 << 8;
113 const STORAGE_TEXTURE_16BIT_NORM_FORMATS = 1 << 9;
115 const MULTIVIEW = 1 << 10;
119 const EARLY_DEPTH_TEST = 1 << 11;
121 const MULTISAMPLED_SHADING = 1 << 12;
126 const RAY_QUERY = 1 << 13;
128 const DUAL_SOURCE_BLENDING = 1 << 14;
130 const CUBE_ARRAY_TEXTURES = 1 << 15;
132 const SHADER_INT64 = 1 << 16;
134 const SUBGROUP = 1 << 17;
145 const SUBGROUP_BARRIER = 1 << 18;
149 const SUBGROUP_VERTEX_STAGE = 1 << 19;
155 const SHADER_INT64_ATOMIC_MIN_MAX = 1 << 20;
165 const SHADER_INT64_ATOMIC_ALL_OPS = 1 << 21;
167 const SHADER_FLOAT32_ATOMIC = 1 << 22;
176 const TEXTURE_ATOMIC = 1 << 23;
178 const TEXTURE_INT64_ATOMIC = 1 << 24;
180 const RAY_HIT_VERTEX_POSITION = 1 << 25;
182 const SHADER_FLOAT16 = 1 << 26;
184 const TEXTURE_EXTERNAL = 1 << 27;
186 const SHADER_FLOAT16_IN_FLOAT32 = 1 << 28;
189 const SHADER_BARYCENTRICS = 1 << 29;
191 const MESH_SHADER = 1 << 30;
193 const MESH_SHADER_POINT_TOPOLOGY = 1 << 31;
195 const TEXTURE_AND_SAMPLER_BINDING_ARRAY_NON_UNIFORM_INDEXING = 1 << 32;
197 const BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING = 1 << 33;
199 const STORAGE_TEXTURE_BINDING_ARRAY_NON_UNIFORM_INDEXING = 1 << 34;
201 const STORAGE_BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING = 1 << 35;
203 const COOPERATIVE_MATRIX = 1 << 36;
205 const PER_VERTEX = 1 << 37;
207 const RAY_TRACING_PIPELINE = 1 << 38;
209 const DRAW_INDEX = 1 << 39;
211 const ACCELERATION_STRUCTURE_BINDING_ARRAY = 1 << 40;
213 const MEMORY_DECORATION_COHERENT = 1 << 41;
215 const MEMORY_DECORATION_VOLATILE = 1 << 42;
217 }
218}
219
220impl Capabilities {
221 #[cfg(feature = "wgsl-in")]
225 #[doc(hidden)]
226 pub const fn extension(&self) -> Option<crate::front::wgsl::ImplementedEnableExtension> {
227 use crate::front::wgsl::ImplementedEnableExtension as Ext;
228 match *self {
229 Self::DUAL_SOURCE_BLENDING => Some(Ext::DualSourceBlending),
230 Self::SHADER_FLOAT16 => Some(Ext::F16),
232 Self::CLIP_DISTANCE => Some(Ext::ClipDistances),
233 Self::MESH_SHADER => Some(Ext::WgpuMeshShader),
234 Self::RAY_QUERY => Some(Ext::WgpuRayQuery),
235 Self::RAY_HIT_VERTEX_POSITION => Some(Ext::WgpuRayQueryVertexReturn),
236 Self::COOPERATIVE_MATRIX => Some(Ext::WgpuCooperativeMatrix),
237 Self::RAY_TRACING_PIPELINE => Some(Ext::WgpuRayTracingPipeline),
238 _ => None,
239 }
240 }
241}
242
243impl Default for Capabilities {
244 fn default() -> Self {
245 Self::MULTISAMPLED_SHADING | Self::CUBE_ARRAY_TEXTURES
246 }
247}
248
249bitflags::bitflags! {
250 #[cfg_attr(feature = "serialize", derive(serde::Serialize))]
252 #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
253 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
254 pub struct SubgroupOperationSet: u8 {
255 const BASIC = 1 << 0;
261 const VOTE = 1 << 1;
263 const ARITHMETIC = 1 << 2;
265 const BALLOT = 1 << 3;
267 const SHUFFLE = 1 << 4;
269 const SHUFFLE_RELATIVE = 1 << 5;
271 const QUAD_FRAGMENT_COMPUTE = 1 << 7;
276 }
279}
280
281impl super::SubgroupOperation {
282 const fn required_operations(&self) -> SubgroupOperationSet {
283 use SubgroupOperationSet as S;
284 match *self {
285 Self::All | Self::Any => S::VOTE,
286 Self::Add | Self::Mul | Self::Min | Self::Max | Self::And | Self::Or | Self::Xor => {
287 S::ARITHMETIC
288 }
289 }
290 }
291}
292
293impl super::GatherMode {
294 const fn required_operations(&self) -> SubgroupOperationSet {
295 use SubgroupOperationSet as S;
296 match *self {
297 Self::BroadcastFirst | Self::Broadcast(_) => S::BALLOT,
298 Self::Shuffle(_) | Self::ShuffleXor(_) => S::SHUFFLE,
299 Self::ShuffleUp(_) | Self::ShuffleDown(_) => S::SHUFFLE_RELATIVE,
300 Self::QuadBroadcast(_) | Self::QuadSwap(_) => S::QUAD_FRAGMENT_COMPUTE,
301 }
302 }
303}
304
305bitflags::bitflags! {
306 #[cfg_attr(feature = "serialize", derive(serde::Serialize))]
308 #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
309 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
310 pub struct ShaderStages: u16 {
311 const VERTEX = 0x1;
312 const FRAGMENT = 0x2;
313 const COMPUTE = 0x4;
314 const MESH = 0x8;
315 const TASK = 0x10;
316 const RAY_GENERATION = 0x20;
317 const ANY_HIT = 0x40;
318 const CLOSEST_HIT = 0x80;
319 const MISS = 0x100;
320 const COMPUTE_LIKE = Self::COMPUTE.bits() | Self::TASK.bits() | Self::MESH.bits();
321 }
322}
323
324#[derive(Debug, Clone, Default)]
325#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
326#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
327pub struct ModuleInfo {
328 type_flags: Vec<TypeFlags>,
329 functions: Vec<FunctionInfo>,
330 entry_points: Vec<FunctionInfo>,
331 const_expression_types: Box<[TypeResolution]>,
332}
333
334impl ops::Index<Handle<crate::Type>> for ModuleInfo {
335 type Output = TypeFlags;
336 fn index(&self, handle: Handle<crate::Type>) -> &Self::Output {
337 &self.type_flags[handle.index()]
338 }
339}
340
341impl ops::Index<Handle<crate::Function>> for ModuleInfo {
342 type Output = FunctionInfo;
343 fn index(&self, handle: Handle<crate::Function>) -> &Self::Output {
344 &self.functions[handle.index()]
345 }
346}
347
348impl ops::Index<Handle<crate::Expression>> for ModuleInfo {
349 type Output = TypeResolution;
350 fn index(&self, handle: Handle<crate::Expression>) -> &Self::Output {
351 &self.const_expression_types[handle.index()]
352 }
353}
354
355#[derive(Debug)]
356pub struct Validator {
357 flags: ValidationFlags,
358 capabilities: Capabilities,
359 subgroup_stages: ShaderStages,
360 subgroup_operations: SubgroupOperationSet,
361 types: Vec<r#type::TypeInfo>,
362 layouter: Layouter,
363 location_mask: BitSet,
364 ep_resource_bindings: FastHashSet<crate::ResourceBinding>,
365 switch_values: FastHashSet<crate::SwitchValue>,
366 valid_expression_list: Vec<Handle<crate::Expression>>,
367 valid_expression_set: HandleSet<crate::Expression>,
368 override_ids: FastHashSet<u16>,
369
370 overrides_resolved: bool,
373
374 needs_visit: HandleSet<crate::Expression>,
393
394 trace_rays_vertex_return: TraceRayVertexReturnState,
398
399 trace_rays_payload_type: Option<Handle<crate::Type>>,
402}
403
404#[derive(Debug)]
405enum TraceRayVertexReturnState {
406 NoTraceRays,
408 #[expect(unused)]
414 NoVertexReturn(crate::Span),
415 VertexReturn,
419}
420
421#[derive(Clone, Debug, thiserror::Error)]
422#[cfg_attr(test, derive(PartialEq))]
423pub enum ConstantError {
424 #[error("Initializer must be a const-expression")]
425 InitializerExprType,
426 #[error("The type doesn't match the constant")]
427 InvalidType,
428 #[error("The type is not constructible")]
429 NonConstructibleType,
430}
431
432#[derive(Clone, Debug, thiserror::Error)]
433#[cfg_attr(test, derive(PartialEq))]
434pub enum OverrideError {
435 #[error("Override name and ID are missing")]
436 MissingNameAndID,
437 #[error("Override ID must be unique")]
438 DuplicateID,
439 #[error("Initializer must be a const-expression or override-expression")]
440 InitializerExprType,
441 #[error("The type doesn't match the override")]
442 InvalidType,
443 #[error("The type is not constructible")]
444 NonConstructibleType,
445 #[error("The type is not a scalar")]
446 TypeNotScalar,
447 #[error("Override declarations are not allowed")]
448 NotAllowed,
449 #[error("Override is uninitialized")]
450 UninitializedOverride,
451 #[error("Constant expression {handle:?} is invalid")]
452 ConstExpression {
453 handle: Handle<crate::Expression>,
454 source: ConstExpressionError,
455 },
456}
457
458#[derive(Clone, Debug, thiserror::Error)]
459#[cfg_attr(test, derive(PartialEq))]
460pub enum ValidationError {
461 #[error(transparent)]
462 InvalidHandle(#[from] InvalidHandleError),
463 #[error(transparent)]
464 Layouter(#[from] LayoutError),
465 #[error("Type {handle:?} '{name}' is invalid")]
466 Type {
467 handle: Handle<crate::Type>,
468 name: String,
469 source: TypeError,
470 },
471 #[error("Constant expression {handle:?} is invalid")]
472 ConstExpression {
473 handle: Handle<crate::Expression>,
474 source: ConstExpressionError,
475 },
476 #[error("Array size expression {handle:?} is not strictly positive")]
477 ArraySizeError { handle: Handle<crate::Expression> },
478 #[error("Constant {handle:?} '{name}' is invalid")]
479 Constant {
480 handle: Handle<crate::Constant>,
481 name: String,
482 source: ConstantError,
483 },
484 #[error("Override {handle:?} '{name}' is invalid")]
485 Override {
486 handle: Handle<crate::Override>,
487 name: String,
488 source: OverrideError,
489 },
490 #[error("Global variable {handle:?} '{name}' is invalid")]
491 GlobalVariable {
492 handle: Handle<crate::GlobalVariable>,
493 name: String,
494 source: GlobalVariableError,
495 },
496 #[error("Function {handle:?} '{name}' is invalid")]
497 Function {
498 handle: Handle<crate::Function>,
499 name: String,
500 source: FunctionError,
501 },
502 #[error("Entry point {name} at {stage:?} is invalid")]
503 EntryPoint {
504 stage: crate::ShaderStage,
505 name: String,
506 source: EntryPointError,
507 },
508 #[error("Module is corrupted")]
509 Corrupted,
510}
511
512impl crate::TypeInner {
513 const fn is_sized(&self) -> bool {
514 match *self {
515 Self::Scalar { .. }
516 | Self::Vector { .. }
517 | Self::Matrix { .. }
518 | Self::CooperativeMatrix { .. }
519 | Self::Array {
520 size: crate::ArraySize::Constant(_),
521 ..
522 }
523 | Self::Atomic { .. }
524 | Self::Pointer { .. }
525 | Self::ValuePointer { .. }
526 | Self::Struct { .. } => true,
527 Self::Array { .. }
528 | Self::Image { .. }
529 | Self::Sampler { .. }
530 | Self::AccelerationStructure { .. }
531 | Self::RayQuery { .. }
532 | Self::BindingArray { .. } => false,
533 }
534 }
535
536 const fn image_storage_coordinates(&self) -> Option<crate::ImageDimension> {
538 match *self {
539 Self::Scalar(crate::Scalar {
540 kind: crate::ScalarKind::Sint | crate::ScalarKind::Uint,
541 ..
542 }) => Some(crate::ImageDimension::D1),
543 Self::Vector {
544 size: crate::VectorSize::Bi,
545 scalar:
546 crate::Scalar {
547 kind: crate::ScalarKind::Sint | crate::ScalarKind::Uint,
548 ..
549 },
550 } => Some(crate::ImageDimension::D2),
551 Self::Vector {
552 size: crate::VectorSize::Tri,
553 scalar:
554 crate::Scalar {
555 kind: crate::ScalarKind::Sint | crate::ScalarKind::Uint,
556 ..
557 },
558 } => Some(crate::ImageDimension::D3),
559 _ => None,
560 }
561 }
562}
563
564impl Validator {
565 pub fn new(flags: ValidationFlags, capabilities: Capabilities) -> Self {
579 let subgroup_operations = if capabilities.contains(Capabilities::SUBGROUP) {
580 use SubgroupOperationSet as S;
581 S::BASIC
582 | S::VOTE
583 | S::ARITHMETIC
584 | S::BALLOT
585 | S::SHUFFLE
586 | S::SHUFFLE_RELATIVE
587 | S::QUAD_FRAGMENT_COMPUTE
588 } else {
589 SubgroupOperationSet::empty()
590 };
591 let subgroup_stages = {
592 let mut stages = ShaderStages::empty();
593 if capabilities.contains(Capabilities::SUBGROUP_VERTEX_STAGE) {
594 stages |= ShaderStages::VERTEX;
595 }
596 if capabilities.contains(Capabilities::SUBGROUP) {
597 stages |= ShaderStages::FRAGMENT | ShaderStages::COMPUTE_LIKE;
598 }
599 stages
600 };
601
602 Validator {
603 flags,
604 capabilities,
605 subgroup_stages,
606 subgroup_operations,
607 types: Vec::new(),
608 layouter: Layouter::default(),
609 location_mask: BitSet::new(),
610 ep_resource_bindings: FastHashSet::default(),
611 switch_values: FastHashSet::default(),
612 valid_expression_list: Vec::new(),
613 valid_expression_set: HandleSet::new(),
614 override_ids: FastHashSet::default(),
615 overrides_resolved: false,
616 needs_visit: HandleSet::new(),
617 trace_rays_vertex_return: TraceRayVertexReturnState::NoTraceRays,
618 trace_rays_payload_type: None,
619 }
620 }
621
622 pub const fn subgroup_stages(&mut self, stages: ShaderStages) -> &mut Self {
624 self.subgroup_stages = stages;
625 self
626 }
627
628 pub const fn subgroup_operations(&mut self, operations: SubgroupOperationSet) -> &mut Self {
630 self.subgroup_operations = operations;
631 self
632 }
633
634 pub fn reset(&mut self) {
636 self.types.clear();
637 self.layouter.clear();
638 self.location_mask.make_empty();
639 self.ep_resource_bindings.clear();
640 self.switch_values.clear();
641 self.valid_expression_list.clear();
642 self.valid_expression_set.clear();
643 self.override_ids.clear();
644 }
645
646 fn validate_constant(
647 &self,
648 handle: Handle<crate::Constant>,
649 gctx: crate::proc::GlobalCtx,
650 mod_info: &ModuleInfo,
651 global_expr_kind: &ExpressionKindTracker,
652 ) -> Result<(), ConstantError> {
653 let con = &gctx.constants[handle];
654
655 let type_info = &self.types[con.ty.index()];
656 if !type_info.flags.contains(TypeFlags::CONSTRUCTIBLE) {
657 return Err(ConstantError::NonConstructibleType);
658 }
659
660 if !global_expr_kind.is_const(con.init) {
661 return Err(ConstantError::InitializerExprType);
662 }
663
664 if !gctx.compare_types(&TypeResolution::Handle(con.ty), &mod_info[con.init]) {
665 return Err(ConstantError::InvalidType);
666 }
667
668 Ok(())
669 }
670
671 fn validate_override(
672 &mut self,
673 handle: Handle<crate::Override>,
674 gctx: crate::proc::GlobalCtx,
675 mod_info: &ModuleInfo,
676 ) -> Result<(), OverrideError> {
677 let o = &gctx.overrides[handle];
678
679 if let Some(id) = o.id {
680 if !self.override_ids.insert(id) {
681 return Err(OverrideError::DuplicateID);
682 }
683 }
684
685 let type_info = &self.types[o.ty.index()];
686 if !type_info.flags.contains(TypeFlags::CONSTRUCTIBLE) {
687 return Err(OverrideError::NonConstructibleType);
688 }
689
690 match gctx.types[o.ty].inner {
691 crate::TypeInner::Scalar(
692 crate::Scalar::BOOL
693 | crate::Scalar::I32
694 | crate::Scalar::U32
695 | crate::Scalar::F16
696 | crate::Scalar::F32
697 | crate::Scalar::F64,
698 ) => {}
699 _ => return Err(OverrideError::TypeNotScalar),
700 }
701
702 if let Some(init) = o.init {
703 if !gctx.compare_types(&TypeResolution::Handle(o.ty), &mod_info[init]) {
704 return Err(OverrideError::InvalidType);
705 }
706 } else if self.overrides_resolved {
707 return Err(OverrideError::UninitializedOverride);
708 }
709
710 Ok(())
711 }
712
713 pub fn validate(
715 &mut self,
716 module: &crate::Module,
717 ) -> Result<ModuleInfo, WithSpan<ValidationError>> {
718 self.overrides_resolved = false;
719 self.validate_impl(module)
720 }
721
722 pub fn validate_resolved_overrides(
730 &mut self,
731 module: &crate::Module,
732 ) -> Result<ModuleInfo, WithSpan<ValidationError>> {
733 self.overrides_resolved = true;
734 self.validate_impl(module)
735 }
736
737 fn validate_impl(
738 &mut self,
739 module: &crate::Module,
740 ) -> Result<ModuleInfo, WithSpan<ValidationError>> {
741 self.reset();
742 self.reset_types(module.types.len());
743
744 Self::validate_module_handles(module).map_err(|e| e.with_span())?;
745
746 self.layouter.update(module.to_ctx()).map_err(|e| {
747 let handle = e.ty;
748 ValidationError::from(e).with_span_handle(handle, &module.types)
749 })?;
750
751 let placeholder = TypeResolution::Value(crate::TypeInner::Scalar(crate::Scalar {
753 kind: crate::ScalarKind::Bool,
754 width: 0,
755 }));
756
757 let mut mod_info = ModuleInfo {
758 type_flags: Vec::with_capacity(module.types.len()),
759 functions: Vec::with_capacity(module.functions.len()),
760 entry_points: Vec::with_capacity(module.entry_points.len()),
761 const_expression_types: vec![placeholder; module.global_expressions.len()]
762 .into_boxed_slice(),
763 };
764
765 for (handle, ty) in module.types.iter() {
766 let ty_info = self
767 .validate_type(handle, module.to_ctx())
768 .map_err(|source| {
769 ValidationError::Type {
770 handle,
771 name: ty.name.clone().unwrap_or_default(),
772 source,
773 }
774 .with_span_handle(handle, &module.types)
775 })?;
776 debug_assert!(
777 ty_info.flags.contains(TypeFlags::CONSTRUCTIBLE)
778 == module.types[handle].inner.is_constructible(&module.types)
779 );
780 mod_info.type_flags.push(ty_info.flags);
781 self.types[handle.index()] = ty_info;
782 }
783
784 {
785 let t = crate::Arena::new();
786 let resolve_context = crate::proc::ResolveContext::with_locals(module, &t, &[]);
787 for (handle, _) in module.global_expressions.iter() {
788 mod_info
789 .process_const_expression(handle, &resolve_context, module.to_ctx())
790 .map_err(|source| {
791 ValidationError::ConstExpression { handle, source }
792 .with_span_handle(handle, &module.global_expressions)
793 })?
794 }
795 }
796
797 let global_expr_kind = ExpressionKindTracker::from_arena(&module.global_expressions);
798
799 if self.flags.contains(ValidationFlags::CONSTANTS) {
800 for (handle, _) in module.global_expressions.iter() {
801 self.validate_const_expression(
802 handle,
803 module.to_ctx(),
804 &mod_info,
805 &global_expr_kind,
806 )
807 .map_err(|source| {
808 ValidationError::ConstExpression { handle, source }
809 .with_span_handle(handle, &module.global_expressions)
810 })?
811 }
812
813 for (handle, constant) in module.constants.iter() {
814 self.validate_constant(handle, module.to_ctx(), &mod_info, &global_expr_kind)
815 .map_err(|source| {
816 ValidationError::Constant {
817 handle,
818 name: constant.name.clone().unwrap_or_default(),
819 source,
820 }
821 .with_span_handle(handle, &module.constants)
822 })?
823 }
824
825 for (handle, r#override) in module.overrides.iter() {
826 self.validate_override(handle, module.to_ctx(), &mod_info)
827 .map_err(|source| {
828 ValidationError::Override {
829 handle,
830 name: r#override.name.clone().unwrap_or_default(),
831 source,
832 }
833 .with_span_handle(handle, &module.overrides)
834 })?;
835 }
836 }
837
838 for (var_handle, var) in module.global_variables.iter() {
839 self.validate_global_var(var, module.to_ctx(), &mod_info, &global_expr_kind)
840 .map_err(|source| {
841 ValidationError::GlobalVariable {
842 handle: var_handle,
843 name: var.name.clone().unwrap_or_default(),
844 source,
845 }
846 .with_span_handle(var_handle, &module.global_variables)
847 })?;
848 }
849
850 for (handle, fun) in module.functions.iter() {
851 match self.validate_function(fun, module, &mod_info, false) {
852 Ok(info) => mod_info.functions.push(info),
853 Err(error) => {
854 return Err(error.and_then(|source| {
855 ValidationError::Function {
856 handle,
857 name: fun.name.clone().unwrap_or_default(),
858 source,
859 }
860 .with_span_handle(handle, &module.functions)
861 }))
862 }
863 }
864 }
865
866 let mut ep_map = FastHashSet::default();
867 for ep in module.entry_points.iter() {
868 if !ep_map.insert((ep.stage, &ep.name)) {
869 return Err(ValidationError::EntryPoint {
870 stage: ep.stage,
871 name: ep.name.clone(),
872 source: EntryPointError::Conflict,
873 }
874 .with_span()); }
876
877 match self.validate_entry_point(ep, module, &mod_info) {
878 Ok(info) => mod_info.entry_points.push(info),
879 Err(error) => {
880 return Err(error.and_then(|source| {
881 ValidationError::EntryPoint {
882 stage: ep.stage,
883 name: ep.name.clone(),
884 source,
885 }
886 .with_span()
887 }));
888 }
889 }
890 }
891
892 Ok(mod_info)
893 }
894}
895
896fn validate_atomic_compare_exchange_struct(
897 types: &crate::UniqueArena<crate::Type>,
898 members: &[crate::StructMember],
899 scalar_predicate: impl FnOnce(&crate::TypeInner) -> bool,
900) -> bool {
901 members.len() == 2
902 && members[0].name.as_deref() == Some("old_value")
903 && scalar_predicate(&types[members[0].ty].inner)
904 && members[1].name.as_deref() == Some("exchanged")
905 && types[members[1].ty].inner == crate::TypeInner::Scalar(crate::Scalar::BOOL)
906}