Skip to content

Commit

Permalink
Merge branch 'master' into wgsl-in-statement-context-local-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy authored Oct 23, 2023
2 parents f557340 + 946745d commit 02676f4
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 453 deletions.
7 changes: 2 additions & 5 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ pub struct Handle<T> {

impl<T> Clone for Handle<T> {
fn clone(&self) -> Self {
Handle {
index: self.index,
marker: self.marker,
}
*self
}
}

Expand All @@ -60,7 +57,7 @@ impl<T> Eq for Handle<T> {}

impl<T> PartialOrd for Handle<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.index.partial_cmp(&other.index)
Some(self.cmp(other))
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub enum Error<'a> {
},
FunctionReturnsVoid(Span),
InvalidWorkGroupUniformLoad(Span),
Other,
Internal(&'static str),
ExpectedConstExprConcreteIntegerScalar(Span),
ExpectedNonNegative(Span),
ExpectedPositiveArrayLength(Span),
Expand Down Expand Up @@ -667,10 +667,10 @@ impl<'a> Error<'a> {
labels: vec![(span, "".into())],
notes: vec!["passed type must be a workgroup pointer".into()],
},
Error::Other => ParseError {
message: "other error".to_string(),
Error::Internal(message) => ParseError {
message: "internal WGSL front end error".to_string(),
labels: vec![],
notes: vec![],
notes: vec![message.into()],
},
Error::ExpectedConstExprConcreteIntegerScalar(span) => ParseError {
message: "must be a const-expression that resolves to a concrete integer scalar (u32 or i32)".to_string(),
Expand Down
49 changes: 23 additions & 26 deletions src/front/wgsl/lower/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum ConcreteConstructor<'a> {
}

impl ConcreteConstructorHandle {
fn to_error_string(&self, ctx: ExpressionContext) -> String {
fn to_error_string(&self, ctx: &mut ExpressionContext) -> String {
match *self {
Self::PartialVector { size } => {
format!("vec{}<?>", size as u32,)
Expand Down Expand Up @@ -143,15 +143,15 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
constructor: &ast::ConstructorType<'source>,
ty_span: Span,
components: &[Handle<ast::Expression<'source>>],
mut ctx: ExpressionContext<'source, '_, '_>,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<Handle<crate::Expression>, Error<'source>> {
let constructor_h = self.constructor(constructor, ctx.reborrow())?;
let constructor_h = self.constructor(constructor, ctx)?;

let components_h = match *components {
[] => ComponentsHandle::None,
[component] => {
let span = ctx.ast_expressions.get_span(component);
let component = self.expression(component, ctx.reborrow())?;
let component = self.expression(component, ctx)?;
let ty = super::resolve!(ctx, component);

ComponentsHandle::One {
Expand All @@ -162,12 +162,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
[component, ref rest @ ..] => {
let span = ctx.ast_expressions.get_span(component);
let component = self.expression(component, ctx.reborrow())?;
let component = self.expression(component, ctx)?;

let components = std::iter::once(Ok(component))
.chain(
rest.iter()
.map(|&component| self.expression(component, ctx.reborrow())),
.map(|&component| self.expression(component, ctx)),
)
.collect::<Result<_, _>>()?;
let spans = std::iter::once(span)
Expand Down Expand Up @@ -239,20 +239,16 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
(
Components::One {
component,
ty_inner:
&crate::TypeInner::Vector {
size: src_size,
kind: src_kind,
..
},
ty_inner: &crate::TypeInner::Vector { size: src_size, .. },
..
},
ConcreteConstructor::PartialVector { size: dst_size },
) if dst_size == src_size => crate::Expression::As {
expr: component,
kind: src_kind,
convert: None,
},
) if dst_size == src_size => {
// This is a trivial conversion: the sizes match, and a Partial
// constructor doesn't specify a scalar type, so nothing can
// possibly happen.
return Ok(component);
}

// Matrix conversion (matrix -> matrix)
(
Expand Down Expand Up @@ -296,11 +292,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
columns: dst_columns,
rows: dst_rows,
},
) if dst_columns == src_columns && dst_rows == src_rows => crate::Expression::As {
expr: component,
kind: crate::ScalarKind::Float,
convert: None,
},
) if dst_columns == src_columns && dst_rows == src_rows => {
// This is a trivial conversion: the sizes match, and a Partial
// constructor doesn't specify a scalar type, so nothing can
// possibly happen.
return Ok(component);
}

// Vector constructor (splat) - infer type
(
Expand Down Expand Up @@ -491,7 +488,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
return Err(Error::BadTypeCast {
span,
from_type,
to_type: constructor_h.to_error_string(ctx.reborrow()),
to_type: constructor_h.to_error_string(ctx),
});
}

Expand Down Expand Up @@ -548,7 +545,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
fn constructor<'out>(
&mut self,
constructor: &ast::ConstructorType<'source>,
mut ctx: ExpressionContext<'source, '_, 'out>,
ctx: &mut ExpressionContext<'source, '_, 'out>,
) -> Result<ConcreteConstructorHandle, Error<'source>> {
let c = match *constructor {
ast::ConstructorType::Scalar { width, kind } => {
Expand Down Expand Up @@ -579,8 +576,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
ast::ConstructorType::PartialArray => ConcreteConstructorHandle::PartialArray,
ast::ConstructorType::Array { base, size } => {
let base = self.resolve_ast_type(base, ctx.as_global())?;
let size = self.array_size(size, ctx.as_global())?;
let base = self.resolve_ast_type(base, &mut ctx.as_global())?;
let size = self.array_size(size, &mut ctx.as_global())?;

self.layouter.update(ctx.module.to_ctx()).unwrap();
let stride = self.layouter[base].to_stride();
Expand Down
Loading

0 comments on commit 02676f4

Please sign in to comment.