Skip to content

Commit

Permalink
[wgsl-in] Delete ComponentsHandle type.
Browse files Browse the repository at this point in the history
In `front:wgsl::lower::construct`, build `Components` values directly,
rather than building a `ComponentsHandle` and then calling its
`borrow` method.
  • Loading branch information
jimblandy committed Oct 23, 2023
1 parent 306c891 commit 96c8824
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 53 deletions.
63 changes: 10 additions & 53 deletions src/front/wgsl/lower/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{Handle, Span};

use crate::front::wgsl::error::Error;
use crate::front::wgsl::lower::{ExpressionContext, Lowerer};
use crate::proc::TypeResolution;

enum ConcreteConstructorHandle {
PartialVector {
Expand Down Expand Up @@ -59,46 +58,6 @@ impl ConcreteConstructorHandle {
}
}

enum ComponentsHandle<'a> {
None,
One {
component: Handle<crate::Expression>,
span: Span,
ty: &'a TypeResolution,
},
Many {
components: Vec<Handle<crate::Expression>>,
spans: Vec<Span>,
first_component_ty: &'a TypeResolution,
},
}

impl<'a> ComponentsHandle<'a> {
fn borrow(self, module: &'a crate::Module) -> Components<'a> {
match self {
Self::None => Components::None,
Self::One {
component,
span,
ty,
} => Components::One {
component,
span,
ty_inner: ty.inner_with(&module.types),
},
Self::Many {
components,
spans,
first_component_ty,
} => Components::Many {
components,
spans,
first_component_ty_inner: first_component_ty.inner_with(&module.types),
},
}
}
}

enum Components<'a> {
None,
One {
Expand Down Expand Up @@ -147,17 +106,17 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
) -> Result<Handle<crate::Expression>, Error<'source>> {
let constructor_h = self.constructor(constructor, ctx)?;

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

ComponentsHandle::One {
Components::One {
component,
span,
ty,
ty_inner,
}
}
[component, ref rest @ ..] => {
Expand All @@ -177,20 +136,18 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
)
.collect();

let ty = super::resolve!(ctx, component);
let first_component_ty_inner = super::resolve_inner!(ctx, component);

ComponentsHandle::Many {
Components::Many {
components,
spans,
first_component_ty: ty,
first_component_ty_inner,
}
}
};

let (components, constructor) = (
components_h.borrow(ctx.module),
constructor_h.borrow(ctx.module),
);
let constructor = constructor_h.borrow(ctx.module);

let expr = match (components, constructor) {
// Empty constructor
(Components::None, dst_ty) => match dst_ty {
Expand Down
1 change: 1 addition & 0 deletions src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ macro_rules! resolve_inner {
$ctx.typifier()[$expr].inner_with(&$ctx.module.types)
}};
}
pub(super) use resolve_inner;

/// Resolves the inner types of two given expressions.
///
Expand Down

0 comments on commit 96c8824

Please sign in to comment.