Repository: gfx-rs/wgpu
Pull request #6217 (2024-09-04 23:43:19)

[naga] Make tests compile without the WGSL front end.


Patch:
diff --git a/naga/src/front/wgsl/lower/mod.rs b/naga/src/front/wgsl/lower/mod.rs
index 5731775fa..7586f98dc 100644
--- a/naga/src/front/wgsl/lower/mod.rs
+++ b/naga/src/front/wgsl/lower/mod.rs
@@ -286,7 +286,7 @@ pub enum ExpressionContextType<'temp, 'out> {
     /// We are lowering to an arbitrary runtime expression, to be
     /// included in a function's body.
     ///
-    /// The given [`RuntimeExpressionContext`] holds information about local
+    /// The given [`LocalExpressionContext`] holds information about local
     /// variables, arguments, and other definitions available only to runtime
     /// expressions, not constant or override expressions.
     Runtime(LocalExpressionContext<'temp, 'out>),
diff --git a/naga/src/front/wgsl/parse/ast.rs b/naga/src/front/wgsl/parse/ast.rs
index a133eacec..c4a798411 100644
--- a/naga/src/front/wgsl/parse/ast.rs
+++ b/naga/src/front/wgsl/parse/ast.rs
@@ -484,5 +484,5 @@ pub enum LocalDecl<'a> {
 #[derive(Debug)]
 /// A placeholder for a local variable declaration.
 ///
-/// See [`Function::locals`] for more information.
+/// See [`super::ExpressionContext::locals`] for more information.
 pub struct Local;
diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs
index e5bd0fa7d..0157aa3a7 100644
--- a/naga/src/front/wgsl/parse/mod.rs
+++ b/naga/src/front/wgsl/parse/mod.rs
@@ -31,20 +31,20 @@ struct ExpressionContext<'input, 'temp, 'out> {
 
     /// A map from identifiers in scope to the locals/arguments they represent.
     ///
-    /// The handles refer to the [`Function::locals`] area; see that field's
+    /// The handles refer to the [`locals`] arena; see that field's
     /// documentation for details.
     ///
-    /// [`Function::locals`]: ast::Function::locals
+    /// [`locals`]: ExpressionContext::locals
     local_table: &'temp mut SymbolTable<&'input str, Handle<ast::Local>>,
 
     /// Local variable and function argument arena for the function we're building.
     ///
-    /// Note that the `Local` here is actually a zero-sized type. The AST keeps
-    /// all the detailed information about locals - names, types, etc. - in
-    /// [`LocalDecl`] statements. For arguments, that information is kept in
-    /// [`arguments`]. This `Arena`'s only role is to assign a unique `Handle`
-    /// to each of them, and track their definitions' spans for use in
-    /// diagnostics.
+    /// Note that the [`ast::Local`] here is actually a zero-sized type. This
+    /// `Arena`'s only role is to assign a unique `Handle` to each local
+    /// identifier, and track its definition's span for use in diagnostics. All
+    /// the detailed information about locals - names, types, etc. - is kept in
+    /// the [`LocalDecl`] statements we parsed from their declarations. For
+    /// arguments, that information is kept in [`arguments`].
     ///
     /// In the AST, when an [`Ident`] expression refers to a local variable or
     /// argument, its [`IdentExpr`] holds the referent's `Handle<Local>` in this
@@ -53,14 +53,15 @@ struct ExpressionContext<'input, 'temp, 'out> {
     /// During lowering, [`LocalDecl`] statements add entries to a per-function
     /// table that maps `Handle<Local>` values to their Naga representations,
     /// accessed via [`StatementContext::local_table`] and
-    /// [`RuntimeExpressionContext::local_table`]. This table is then consulted when
+    /// [`LocalExpressionContext::local_table`]. This table is then consulted when
     /// lowering subsequent [`Ident`] expressions.
     ///
-    /// [`LocalDecl`]: StatementKind::LocalDecl
-    /// [`arguments`]: Function::arguments
-    /// [`Ident`]: Expression::Ident
-    /// [`StatementContext::local_table`]: StatementContext::local_table
-    /// [`RuntimeExpressionContext::local_table`]: RuntimeExpressionContext::local_table
+    /// [`LocalDecl`]: ast::StatementKind::LocalDecl
+    /// [`arguments`]: ast::Function::arguments
+    /// [`Ident`]: ast::Expression::Ident
+    /// [`IdentExpr`]: ast::IdentExpr
+    /// [`StatementContext::local_table`]: super::lower::StatementContext::local_table
+    /// [`LocalExpressionContext::local_table`]: super::lower::LocalExpressionContext::local_table
     locals: &'out mut Arena<ast::Local>,
 
     /// Identifiers used by the current global declaration that have no local definition.
diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs
index 313bf813a..d58748ed9 100644
--- a/wgpu-core/src/command/mod.rs
+++ b/wgpu-core/src/command/mod.rs
@@ -82,8 +82,8 @@ pub(crate) enum CommandEncoderStatus {
     ///
     /// When a `CommandEncoder` is left in this state, we have also
     /// returned an error result from the function that encountered
-    /// the problem. Future attempts to use the encoder (that is,
-    /// calls to [`CommandBuffer::get_encoder`]) will also return
+    /// the problem. Future attempts to use the encoder (for example,
+    /// calls to [`CommandBuffer::check_recording`]) will also return
     /// errors.
     ///
     /// Calling [`Global::command_encoder_finish`] in this state


Test patch:
diff --git a/naga/tests/validation.rs b/naga/tests/validation.rs
index c7af7b4c0..f20ae688b 100644
--- a/naga/tests/validation.rs
+++ b/naga/tests/validation.rs
@@ -316,6 +316,8 @@ fn main() {{
 #[cfg(feature = "wgsl-in")]
 #[test]
 fn incompatible_interpolation_and_sampling_types() {
+    use dummy_interpolation_shader::DummyInterpolationShader;
+
     // NOTE: Things we expect to actually compile are in the `interpolate` snapshot test.
     use itertools::Itertools;
 
@@ -396,6 +398,8 @@ fn incompatible_interpolation_and_sampling_types() {
 #[cfg(all(feature = "wgsl-in", feature = "glsl-out"))]
 #[test]
 fn no_flat_first_in_glsl() {
+    use dummy_interpolation_shader::DummyInterpolationShader;
+
     let DummyInterpolationShader {
         source: _,
         module,
@@ -432,44 +436,46 @@ fn no_flat_first_in_glsl() {
     ));
 }
 
-struct DummyInterpolationShader {
-    source: String,
-    module: naga::Module,
-    interpolate_attr: String,
-    entry_point: &'static str,
-}
-
-impl DummyInterpolationShader {
-    fn new(interpolation: naga::Interpolation, sampling: Option<naga::Sampling>) -> Self {
-        // NOTE: If you have to add variants below, make sure to add them to the
-        // `cartesian_product`'d combinations in tests around here!
-        let interpolation_str = match interpolation {
-            naga::Interpolation::Flat => "flat",
-            naga::Interpolation::Linear => "linear",
-            naga::Interpolation::Perspective => "perspective",
-        };
-        let sampling_str = match sampling {
-            None => String::new(),
-            Some(sampling) => format!(
-                ", {}",
-                match sampling {
-                    naga::Sampling::First => "first",
-                    naga::Sampling::Either => "either",
-                    naga::Sampling::Center => "center",
-                    naga::Sampling::Centroid => "centroid",
-                    naga::Sampling::Sample => "sample",
-                }
-            ),
-        };
-        let member_type = match interpolation {
-            naga::Interpolation::Perspective | naga::Interpolation::Linear => "f32",
-            naga::Interpolation::Flat => "u32",
-        };
+#[cfg(all(test, feature = "wgsl-in"))]
+mod dummy_interpolation_shader {
+    pub struct DummyInterpolationShader {
+        pub source: String,
+        pub module: naga::Module,
+        pub interpolate_attr: String,
+        pub entry_point: &'static str,
+    }
 
-        let interpolate_attr = format!("@interpolate({interpolation_str}{sampling_str})");
-        let source = format!(
-            "\
-struct VertexOutput {{
+    impl DummyInterpolationShader {
+        pub fn new(interpolation: naga::Interpolation, sampling: Option<naga::Sampling>) -> Self {
+            // NOTE: If you have to add variants below, make sure to add them to the
+            // `cartesian_product`'d combinations in tests around here!
+            let interpolation_str = match interpolation {
+                naga::Interpolation::Flat => "flat",
+                naga::Interpolation::Linear => "linear",
+                naga::Interpolation::Perspective => "perspective",
+            };
+            let sampling_str = match sampling {
+                None => String::new(),
+                Some(sampling) => format!(
+                    ", {}",
+                    match sampling {
+                        naga::Sampling::First => "first",
+                        naga::Sampling::Either => "either",
+                        naga::Sampling::Center => "center",
+                        naga::Sampling::Centroid => "centroid",
+                        naga::Sampling::Sample => "sample",
+                    }
+                ),
+            };
+            let member_type = match interpolation {
+                naga::Interpolation::Perspective | naga::Interpolation::Linear => "f32",
+                naga::Interpolation::Flat => "u32",
+            };
+
+            let interpolate_attr = format!("@interpolate({interpolation_str}{sampling_str})");
+            let source = format!(
+                "\
+                struct VertexOutput {{
     @location(0) {interpolate_attr} member: {member_type},
 }}
 
@@ -478,14 +484,15 @@ fn main(input: VertexOutput) {{
     // ...
 }}
 "
-        );
-        let module = naga::front::wgsl::parse_str(&source).unwrap();
+            );
+            let module = naga::front::wgsl::parse_str(&source).unwrap();
 
-        Self {
-            source,
-            module,
-            interpolate_attr,
-            entry_point: "main",
+            Self {
+                source,
+                module,
+                interpolate_attr,
+                entry_point: "main",
+            }
         }
     }
 }