Revert [wgsl-out] Write const named expr as const declarations

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev authored and Jim Blandy committed 2025-04-02 07:53:13 -07:00
1 parent c4b781bdea
commit 6e6675a73c
5 files changed
+5 -22

No files matched your search

+1 -2
View File
@@ -64,7 +64,7 @@ use thiserror::Error;
use crate::{
back::{self, Baked},
common,
proc::{self, ExpressionKindTracker, NameKey},
proc::{self, NameKey},
valid, Handle, ShaderStage, TypeInner,
};
use features::FeaturesManager;
@@ -1678,7 +1678,6 @@ impl<'a, W: Write> Writer<'a, W> {
info,
expressions: &func.expressions,
named_expressions: &func.named_expressions,
expr_kind_tracker: ExpressionKindTracker::from_arena(&func.expressions),
};
self.named_expressions.clear();
+1 -3
View File
@@ -17,7 +17,7 @@ use super::{
use crate::{
back::{self, Baked},
common,
proc::{self, index, ExpressionKindTracker, NameKey},
proc::{self, index, NameKey},
valid, Handle, Module, RayQueryFunction, Scalar, ScalarKind, ShaderStage, TypeInner,
};
@@ -426,7 +426,6 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
info,
expressions: &function.expressions,
named_expressions: &function.named_expressions,
expr_kind_tracker: ExpressionKindTracker::from_arena(&function.expressions),
};
let name = self.names[&NameKey::Function(handle)].clone();
@@ -467,7 +466,6 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
info,
expressions: &ep.function.expressions,
named_expressions: &ep.function.named_expressions,
expr_kind_tracker: ExpressionKindTracker::from_arena(&ep.function.expressions),
};
self.write_wrapped_functions(module, &ctx)?;
-4
View File
@@ -11,8 +11,6 @@ Backend functions that export shader [`Module`](super::Module)s into binary and
use alloc::string::String;
use crate::proc::ExpressionKindTracker;
#[cfg(dot_out)]
pub mod dot;
#[cfg(glsl_out)]
@@ -128,8 +126,6 @@ pub struct FunctionCtx<'a> {
pub expressions: &'a crate::Arena<crate::Expression>,
/// Map of expressions that have associated variable names
pub named_expressions: &'a crate::NamedExpressions,
/// For constness checks
pub expr_kind_tracker: ExpressionKindTracker,
}
impl FunctionCtx<'_> {
+1 -3
View File
@@ -17,7 +17,7 @@ use crate::{
arena::{Handle, HandleSet},
back::{self, Baked},
common,
proc::{self, index, ExpressionKindTracker, NameKey, TypeResolution},
proc::{self, index, NameKey, TypeResolution},
valid, FastHashMap, FastHashSet,
};
@@ -5572,7 +5572,6 @@ template <typename A>
info: &mod_info[fun_handle],
expressions: &fun.expressions,
named_expressions: &fun.named_expressions,
expr_kind_tracker: ExpressionKindTracker::from_arena(&fun.expressions),
};
writeln!(self.out)?;
@@ -5729,7 +5728,6 @@ template <typename A>
info: fun_info,
expressions: &fun.expressions,
named_expressions: &fun.named_expressions,
expr_kind_tracker: ExpressionKindTracker::from_arena(&fun.expressions),
};
self.write_wrapped_functions(module, &ctx)?;
+2 -10
View File
@@ -16,7 +16,7 @@ use crate::{
self,
wgsl::{address_space_str, ToWgsl, TryToWgsl},
},
proc::{self, ExpressionKindTracker, NameKey},
proc::{self, NameKey},
valid, Handle, Module, ShaderStage, TypeInner,
};
@@ -178,7 +178,6 @@ impl<W: Write> Writer<W> {
info: fun_info,
expressions: &function.expressions,
named_expressions: &function.named_expressions,
expr_kind_tracker: ExpressionKindTracker::from_arena(&function.expressions),
};
// Write the function
@@ -207,7 +206,6 @@ impl<W: Write> Writer<W> {
info: info.get_entry_point(index),
expressions: &ep.function.expressions,
named_expressions: &ep.function.named_expressions,
expr_kind_tracker: ExpressionKindTracker::from_arena(&ep.function.expressions),
};
self.write_function(module, &ep.function, &func_ctx)?;
@@ -1029,14 +1027,8 @@ impl<W: Write> Writer<W> {
func_ctx: &back::FunctionCtx,
name: &str,
) -> BackendResult {
// Some functions are marked as const, but are not yet implemented as constant expression
let quantifier = if func_ctx.expr_kind_tracker.is_impl_const(handle) {
"const"
} else {
"let"
};
// Write variable name
write!(self.out, "{quantifier} {name}")?;
write!(self.out, "let {name}")?;
if self.flags.contains(WriterFlags::EXPLICIT_TYPES) {
write!(self.out, ": ")?;
let ty = &func_ctx.info[handle].ty;