Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Mar 30, 2023
1 parent 6ad77ae commit 5a3adea
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 130 deletions.
16 changes: 8 additions & 8 deletions src/front/glsl/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ impl<'a> ConstantSolver<'a> {
}
}

fn constant_index(&self, constant: Handle<Expression>) -> Result<usize, ConstantSolvingError> {
match self.const_expressions[constant] {
fn constant_index(&self, expr: Handle<Expression>) -> Result<usize, ConstantSolvingError> {
match self.const_expressions[expr] {
Expression::Literal(Literal::U32(index)) => Ok(index as usize),
_ => Err(ConstantSolvingError::InvalidAccessIndexTy),
}
Expand Down Expand Up @@ -489,14 +489,14 @@ impl<'a> ConstantSolver<'a> {

fn cast(
&mut self,
constant: Handle<Expression>,
expr: Handle<Expression>,
kind: ScalarKind,
target_width: crate::Bytes,
span: crate::Span,
) -> Result<Handle<Expression>, ConstantSolvingError> {
let constant = self.eval_new(constant, span)?;
let expr = self.eval_new(expr, span)?;

let expr = match self.const_expressions[constant] {
let expr = match self.const_expressions[expr] {
Expression::Literal(literal) => {
let literal = match (kind, target_width) {
(ScalarKind::Sint, 4) => Literal::I32(match literal {
Expand Down Expand Up @@ -556,12 +556,12 @@ impl<'a> ConstantSolver<'a> {
fn unary_op(
&mut self,
op: UnaryOperator,
constant: Handle<Expression>,
expr: Handle<Expression>,
span: crate::Span,
) -> Result<Handle<Expression>, ConstantSolvingError> {
let constant = self.eval_new(constant, span)?;
let expr = self.eval_new(expr, span)?;

let expr = match self.const_expressions[constant] {
let expr = match self.const_expressions[expr] {
Expression::Literal(value) => Expression::Literal(match op {
UnaryOperator::Negate => match value {
Literal::I32(v) => Literal::I32(-v),
Expand Down
11 changes: 3 additions & 8 deletions src/front/glsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,9 @@ impl Frontend {
),
) {
match self.module.types[ty].inner {
// TODO: Better error reporting
// right now we just don't walk the array if the size isn't known at
// compile time and let validation catch it
TypeInner::Array {
base,
size: crate::ArraySize::Constant(size),
Expand All @@ -1269,14 +1272,6 @@ impl Frontend {
crate::Binding::BuiltIn(_) => return,
};

// TODO: Better error reporting
// right now we just don't walk the array if the size isn't known at
// compile time and let validation catch it
// let size = match self.module.constants[constant].to_array_length() {
// Some(val) => val,
// None => return f(name, pointer, ty, binding, expressions),
// };

let interpolation =
self.module.types[base]
.inner
Expand Down
23 changes: 0 additions & 23 deletions src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ impl crate::TypeInner {
fn to_wgsl(&self, global_ctx: crate::GlobalCtx) -> String {
use crate::TypeInner as Ti;

// fn get_array_size(
// global_ctx: crate::GlobalCtx,
// size_expr: crate::Handle<crate::Expression>,
// ) -> String {
// match global_ctx.const_expressions[size_expr] {
// crate::Expression::Literal(crate::Literal::U32(size)) => size.to_string(),
// crate::Expression::Literal(crate::Literal::I32(size)) => size.to_string(),
// crate::Expression::Constant(c) => global_ctx.constants[c]
// .name
// .clone()
// .unwrap_or("?".to_string()),
// _ => "?".to_string(),
// }
// }

match *self {
Ti::Scalar { kind, width } => kind.to_wgsl(width),
Ti::Vector { size, kind, width } => {
Expand Down Expand Up @@ -149,10 +134,6 @@ impl crate::TypeInner {
let base = member_type.name.as_deref().unwrap_or("unknown");
match size {
crate::ArraySize::Constant(size) => format!("array<{base}, {size}>"),
// crate::ArraySize::OverrideExpression(size_expr) => {
// let size = get_array_size(global_ctx, size_expr);
// format!("array<{base}, {size}>")
// }
crate::ArraySize::Dynamic => format!("array<{base}>"),
}
}
Expand Down Expand Up @@ -209,10 +190,6 @@ impl crate::TypeInner {
let base = member_type.name.as_deref().unwrap_or("unknown");
match size {
crate::ArraySize::Constant(size) => format!("binding_array<{base}, {size}>"),
// crate::ArraySize::OverrideExpression(size_expr) => {
// let size = get_array_size(global_ctx, size_expr);
// format!("binding_array<{base}, {size}>")
// }
crate::ArraySize::Dynamic => format!("binding_array<{base}>"),
}
}
Expand Down
21 changes: 9 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,8 @@ pub enum ScalarKind {
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub enum ArraySize {
/// The array size is constant.
Constant(std::num::NonZeroU32),
// OverrideConstant(Handle<Constant>),
// /// The array size is constant.
// ///
// /// Expression handle lives in const_expressions and is an override-expression
// OverrideExpression(Handle<Expression>),
/// The array size can change at runtime.
Dynamic,
}
Expand Down Expand Up @@ -1196,9 +1192,11 @@ bitflags::bitflags! {
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub enum Expression {
/// Literal
Literal(Literal),
/// Constant value.
Constant(Handle<Constant>),
/// New expression, creates a new value of the specified type.
New(Handle<Type>),
/// Composite expression.
Compose {
Expand Down Expand Up @@ -1313,9 +1311,7 @@ pub enum Expression {
///
/// For [`TypeInner::Atomic`] the result is a corresponding scalar.
/// For other types behind the `pointer<T>`, the result is `T`.
Load {
pointer: Handle<Expression>,
},
Load { pointer: Handle<Expression> },
/// Sample a point from a sampled or a depth image.
ImageSample {
image: Handle<Expression>,
Expand Down Expand Up @@ -1455,10 +1451,7 @@ pub enum Expression {
/// Result of calling another function.
CallResult(Handle<Function>),
/// Result of an atomic operation.
AtomicResult {
ty: Handle<Type>,
comparison: bool,
},
AtomicResult { ty: Handle<Type>, comparison: bool },
/// Get the length of an array.
/// The expression must resolve to a pointer to an array with a dynamic size.
///
Expand Down Expand Up @@ -1895,6 +1888,10 @@ pub struct Module {
pub constants: Arena<Constant>,
/// Arena for the global variables defined in this module.
pub global_variables: Arena<GlobalVariable>,
/// const/override-expressions used by this module.
///
/// An `Expression` must occur before all other `Expression`s that use its
/// value.
pub const_expressions: Arena<Expression>,
/// Arena for the functions defined in this module.
///
Expand Down
26 changes: 0 additions & 26 deletions src/proc/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,32 +412,6 @@ impl crate::ArraySize {
) -> Result<IndexableLength, IndexableLengthError> {
Ok(match self {
Self::Constant(length) => IndexableLength::Known(length.get()),
// Self::OverrideExpression(k) => {
// let const_expr = &module.const_expressions[k];
// match *const_expr {
// crate::Expression::Constant(c)
// if matches!(
// module.constants[c],
// crate::Constant {
// specialization: crate::Specialization::ByName
// | crate::Specialization::ByNameOrId(_),
// ..
// }
// ) =>
// {
// // Specializable constants are not supported as array lengths.
// // See valid::TypeError::UnsupportedSpecializedArrayLength.
// return Err(IndexableLengthError::InvalidArrayLength(k));
// }
// _ => {
// let length = module
// .to_ctx()
// .to_array_length(k)
// .ok_or(IndexableLengthError::InvalidArrayLength(k))?;
// IndexableLength::Known(length)
// }
// }
// }
Self::Dynamic => IndexableLength::Dynamic,
})
}
Expand Down
3 changes: 0 additions & 3 deletions src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ impl super::TypeInner {
} => {
let count = match size {
super::ArraySize::Constant(count) => count.get(),
// super::ArraySize::OverrideExpression(handle) => {
// gctx.to_array_length(handle).unwrap_or(1)
// }
// A dynamically-sized array has to have at least one element
super::ArraySize::Dynamic => 1,
};
Expand Down
10 changes: 0 additions & 10 deletions src/valid/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ impl super::Validator {
let validate_array_size = |size| -> Result<Handle<crate::Type>, ValidationError> {
match size {
crate::ArraySize::Constant(_) => (),
// crate::ArraySize::OverrideExpression(const_expr) => {
// const_expressions.check_contains_handle(const_expr)?;
// // if !matches!(inner, &crate::ConstantInner::Scalar { .. }) {
// // return Err(ValidationError::Type {
// // handle: this_handle,
// // name: name.clone().unwrap_or_default(),
// // source: TypeError::InvalidArraySizeConstant(const_expr),
// // });
// // }
// }
crate::ArraySize::Dynamic => (),
};
Ok(this_handle)
Expand Down
40 changes: 0 additions & 40 deletions src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,46 +427,6 @@ impl super::Validator {
| TypeFlags::ARGUMENT
| TypeFlags::CONSTRUCTIBLE
}
// crate::ArraySize::OverrideExpression(const_expr) => {
// match gctx.const_expressions[const_expr] {
// crate::Expression::Constant(const_handle)
// if matches!(
// gctx.constants[const_handle],
// crate::Constant {
// specialization: crate::Specialization::ByName
// | crate::Specialization::ByNameOrId(_),
// ..
// }
// ) =>
// {
// // 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,
// ));
// }
// _ => {}
// }

// if let Some(len) = gctx.to_array_length(const_expr) {
// if len == 0 {
// return Err(TypeError::NonPositiveArrayLength(len));
// }
// } else {
// log::warn!("Array size {:?}", const_expr);
// return Err(TypeError::InvalidArraySizeConstant(const_expr));
// }

// TypeFlags::DATA
// | TypeFlags::SIZED
// | TypeFlags::COPY
// | TypeFlags::HOST_SHAREABLE
// | TypeFlags::ARGUMENT
// | TypeFlags::CONSTRUCTIBLE
// }
crate::ArraySize::Dynamic => {
// Non-SIZED types may only appear as the last element of a structure.
// This is enforced by checks for SIZED-ness for all compound types,
Expand Down

0 comments on commit 5a3adea

Please sign in to comment.