Skip to content

Commit

Permalink
Move GlobalCtx into proc module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy committed Apr 1, 2023
1 parent b423dfe commit cf77790
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/back/hlsl/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl crate::TypeInner {
}
}

pub(super) fn size_hlsl(&self, gctx: crate::GlobalCtx) -> u32 {
pub(super) fn size_hlsl(&self, gctx: crate::proc::GlobalCtx) -> u32 {
match *self {
Self::Matrix {
columns,
Expand All @@ -67,7 +67,7 @@ impl crate::TypeInner {
/// Used to generate the name of the wrapped type constructor
pub(super) fn hlsl_type_id<'a>(
base: crate::Handle<crate::Type>,
gctx: crate::GlobalCtx,
gctx: crate::proc::GlobalCtx,
names: &'a crate::FastHashMap<crate::proc::NameKey, String>,
) -> Result<Cow<'a, str>, Error> {
Ok(match gctx.types[base].inner {
Expand Down
2 changes: 1 addition & 1 deletion src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const CLAMPED_LOD_LOAD_PREFIX: &str = "clamped_lod_e";

struct TypeContext<'a> {
handle: Handle<crate::Type>,
gctx: crate::GlobalCtx<'a>,
gctx: proc::GlobalCtx<'a>,
names: &'a FastHashMap<NameKey, String>,
access: crate::StorageAccess,
binding: Option<&'a super::ResolvedBinding>,
Expand Down
4 changes: 2 additions & 2 deletions src/front/spv/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
}

impl<'function> BlockContext<'function> {
pub(super) fn global_ctx(&self) -> crate::GlobalCtx {
crate::GlobalCtx {
pub(super) fn global_ctx(&self) -> crate::proc::GlobalCtx {
crate::proc::GlobalCtx {
types: self.type_arena,
constants: self.const_arena,
const_expressions: self.const_expressions,
Expand Down
2 changes: 1 addition & 1 deletion src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5147,7 +5147,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
}
}

fn resolve_constant(ctx: crate::GlobalCtx, constant: Handle<crate::Constant>) -> Option<u32> {
fn resolve_constant(ctx: crate::proc::GlobalCtx, constant: Handle<crate::Constant>) -> Option<u32> {
match ctx.const_expressions[ctx.constants[constant].init] {
crate::Expression::Literal(crate::Literal::U32(id)) => Some(id),
crate::Expression::Literal(crate::Literal::I32(id)) => Some(id as u32),
Expand Down
2 changes: 1 addition & 1 deletion src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl crate::TypeInner {
/// For example `vec3<f32>`.
///
/// Note: The names of a `TypeInner::Struct` is not known. Therefore this method will simply return "struct" for them.
fn to_wgsl(&self, global_ctx: crate::GlobalCtx) -> String {
fn to_wgsl(&self, global_ctx: crate::proc::GlobalCtx) -> String {
use crate::TypeInner as Ti;

match *self {
Expand Down
7 changes: 0 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1901,10 +1901,3 @@ pub struct Module {
/// Entry points.
pub entry_points: Vec<EntryPoint>,
}

#[derive(Clone, Copy)]
pub struct GlobalCtx<'a> {
pub types: &'a UniqueArena<Type>,
pub constants: &'a Arena<Constant>,
pub const_expressions: &'a Arena<Expression>,
}
2 changes: 1 addition & 1 deletion src/proc/layouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Layouter {
/// constant arenas, and then assume that layouts are available for all
/// types.
#[allow(clippy::or_fun_call)]
pub fn update(&mut self, gctx: crate::GlobalCtx) -> Result<(), LayoutError> {
pub fn update(&mut self, gctx: super::GlobalCtx) -> Result<(), LayoutError> {
use crate::TypeInner as Ti;

for (ty_handle, ty) in gctx.types.iter().skip(self.layouts.len()) {
Expand Down
21 changes: 14 additions & 7 deletions src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl super::TypeInner {
}

/// Get the size of this type.
pub fn size(&self, _gctx: crate::GlobalCtx) -> u32 {
pub fn size(&self, _gctx: GlobalCtx) -> u32 {
match *self {
Self::Scalar { kind: _, width } | Self::Atomic { kind: _, width } => width as u32,
Self::Vector {
Expand Down Expand Up @@ -546,8 +546,8 @@ impl super::ImageClass {
}

impl crate::Module {
pub const fn to_ctx(&self) -> crate::GlobalCtx<'_> {
crate::GlobalCtx {
pub const fn to_ctx(&self) -> GlobalCtx<'_> {
GlobalCtx {
types: &self.types,
constants: &self.constants,
const_expressions: &self.const_expressions,
Expand All @@ -561,9 +561,16 @@ pub(super) enum U32EvalError {
Negative,
}

impl crate::GlobalCtx<'_> {
pub const fn reborrow(&self) -> crate::GlobalCtx<'_> {
crate::GlobalCtx {
#[derive(Clone, Copy)]
pub struct GlobalCtx<'a> {
pub types: &'a crate::UniqueArena<crate::Type>,
pub constants: &'a crate::Arena<crate::Constant>,
pub const_expressions: &'a crate::Arena<crate::Expression>,
}

impl GlobalCtx<'_> {
pub const fn reborrow(&self) -> GlobalCtx<'_> {
GlobalCtx {
types: self.types,
constants: self.constants,
const_expressions: self.const_expressions,
Expand All @@ -580,7 +587,7 @@ impl crate::GlobalCtx<'_> {
arena: Option<&crate::Arena<crate::Expression>>,
) -> Result<u32, U32EvalError> {
fn get(
gctx: crate::GlobalCtx,
gctx: GlobalCtx,
handle: crate::Handle<crate::Expression>,
arena: &crate::Arena<crate::Expression>,
) -> Result<u32, U32EvalError> {
Expand Down
2 changes: 1 addition & 1 deletion src/valid/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum ComposeError {
#[cfg(feature = "validate")]
pub fn validate_compose(
self_ty_handle: Handle<crate::Type>,
gctx: crate::GlobalCtx,
gctx: crate::proc::GlobalCtx,
component_resolutions: impl ExactSizeIterator<Item = TypeResolution>,
) -> Result<(), ComposeError> {
use crate::TypeInner as Ti;
Expand Down
2 changes: 1 addition & 1 deletion src/valid/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl super::Validator {
&self,
handle: Handle<crate::Expression>,
resolve_context: &ResolveContext,
gctx: crate::GlobalCtx,
gctx: crate::proc::GlobalCtx,
mod_info: &mut ModuleInfo,
) -> Result<(), super::ConstExpressionError> {
use crate::Expression as E;
Expand Down
2 changes: 1 addition & 1 deletion src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ impl super::Validator {
fn validate_local_var(
&self,
var: &crate::LocalVariable,
gctx: crate::GlobalCtx,
gctx: crate::proc::GlobalCtx,
mod_info: &ModuleInfo,
) -> Result<(), LocalVariableError> {
log::debug!("var {:?}", var);
Expand Down
2 changes: 1 addition & 1 deletion src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl super::Validator {
pub(super) fn validate_global_var(
&self,
var: &crate::GlobalVariable,
gctx: crate::GlobalCtx,
gctx: crate::proc::GlobalCtx,
mod_info: &ModuleInfo,
) -> Result<(), GlobalVariableError> {
use super::TypeFlags;
Expand Down
2 changes: 1 addition & 1 deletion src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl Validator {
fn validate_constant(
&self,
handle: Handle<crate::Constant>,
gctx: crate::GlobalCtx,
gctx: crate::proc::GlobalCtx,
mod_info: &ModuleInfo,
) -> Result<(), ConstantError> {
let con = &gctx.constants[handle];
Expand Down
2 changes: 1 addition & 1 deletion src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl super::Validator {
pub(super) fn validate_type(
&self,
handle: Handle<crate::Type>,
gctx: crate::GlobalCtx,
gctx: crate::proc::GlobalCtx,
) -> Result<TypeInfo, TypeError> {
use crate::TypeInner as Ti;
Ok(match gctx.types[handle].inner {
Expand Down

0 comments on commit cf77790

Please sign in to comment.