Skip to content

Commit

Permalink
Rename UniqueArena methods to more closely resemble HashSet.
Browse files Browse the repository at this point in the history
`UniqueArena::fetch_or_append` becomes `insert`.

`UniqueArena::try_get` becomes `get_handle`, by analogy with `get`, that takes a
type as a key.
  • Loading branch information
jimblandy committed Sep 24, 2021
1 parent 0f6509d commit 9da14b6
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ impl<T: Eq + hash::Hash> UniqueArena<T> {
///
/// [`Handle<T>`]: Handle
/// [`get_span`]: UniqueArena::get_span
pub fn fetch_or_append(&mut self, value: T, span: Span) -> Handle<T> {
pub fn insert(&mut self, value: T, span: Span) -> Handle<T> {
let (index, added) = self.set.insert_full(value);

#[cfg(feature = "span")]
Expand All @@ -503,7 +503,7 @@ impl<T: Eq + hash::Hash> UniqueArena<T> {
}

/// Return this arena's value at `handle`, if that is a valid handle.
pub fn try_get(&self, handle: Handle<T>) -> Option<&T> {
pub fn get_handle(&self, handle: Handle<T>) -> Option<&T> {
self.set.get_index(handle.index())
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/front/glsl/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Module {
let mut parameters_info = Vec::with_capacity(args.len());

for arg in args {
parameters.push(self.types.fetch_or_append(
parameters.push(self.types.insert(
Type {
name: None,
inner: arg,
Expand Down Expand Up @@ -1224,7 +1224,7 @@ fn inject_common_builtin(
_ => Some(VectorSize::Quad),
};

let ty = module.types.fetch_or_append(
let ty = module.types.insert(
Type {
name: None,
inner: match size {
Expand Down Expand Up @@ -1937,7 +1937,7 @@ pub fn sampled_to_depth(
arrayed,
} => match class {
ImageClass::Sampled { multi, .. } => {
*ty = module.types.fetch_or_append(
*ty = module.types.insert(
Type {
name: None,
inner: TypeInner::Image {
Expand Down
10 changes: 5 additions & 5 deletions src/front/glsl/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'a> ConstantSolver<'a> {
let ty = match self.constants[value_constant].inner {
ConstantInner::Scalar { ref value, width } => {
let kind = value.scalar_kind();
self.types.fetch_or_append(
self.types.insert(
Type {
name: None,
inner: TypeInner::Vector { size, kind, width },
Expand Down Expand Up @@ -127,7 +127,7 @@ impl<'a> ConstantSolver<'a> {
kind,
width,
} => {
let dst_ty = self.types.fetch_or_append(
let dst_ty = self.types.insert(
Type {
name: None,
inner: crate::TypeInner::Vector { size, kind, width },
Expand Down Expand Up @@ -542,7 +542,7 @@ mod tests {
let mut expressions = Arena::new();
let mut constants = Arena::new();

let vec_ty = types.fetch_or_append(
let vec_ty = types.insert(
Type {
name: None,
inner: TypeInner::Vector {
Expand Down Expand Up @@ -720,7 +720,7 @@ mod tests {
let mut expressions = Arena::new();
let mut constants = Arena::new();

let matrix_ty = types.fetch_or_append(
let matrix_ty = types.insert(
Type {
name: None,
inner: TypeInner::Matrix {
Expand All @@ -732,7 +732,7 @@ mod tests {
Default::default(),
);

let vec_ty = types.fetch_or_append(
let vec_ty = types.insert(
Type {
name: None,
inner: TypeInner::Vector {
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl Context {

if qualifier.is_lhs() {
let span = parser.module.types.get_span(arg.ty);
arg.ty = parser.module.types.fetch_or_append(
arg.ty = parser.module.types.insert(
Type {
name: None,
inner: TypeInner::Pointer {
Expand Down Expand Up @@ -818,7 +818,7 @@ impl Context {
self.add_expression(Expression::Splat { size, value: right }, meta, body);

if let Some(cols) = columns {
let ty = parser.module.types.fetch_or_append(
let ty = parser.module.types.insert(
Type {
name: None,
inner: ty_inner,
Expand Down
8 changes: 4 additions & 4 deletions src/front/glsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Parser {
// value is used to initialize all the values along the diagonal of
// the matrix; the rest are given zeros.
let mut components = Vec::with_capacity(columns as usize);
let vector_ty = self.module.types.fetch_or_append(
let vector_ty = self.module.types.insert(
Type {
name: None,
inner: TypeInner::Vector {
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Parser {
}
}

let ty = self.module.types.fetch_or_append(
let ty = self.module.types.insert(
Type {
name: None,
inner: TypeInner::Vector {
Expand Down Expand Up @@ -555,7 +555,7 @@ impl Parser {
if let TypeInner::Vector { size, kind, width } =
*self.resolve_type(ctx, handle, meta)?
{
let ty = self.module.types.fetch_or_append(
let ty = self.module.types.insert(
Type {
name: None,
inner: TypeInner::Vector { size, kind, width },
Expand Down Expand Up @@ -900,7 +900,7 @@ impl Parser {
}

let (ty, value) = if !components.is_empty() {
let ty = self.module.types.fetch_or_append(
let ty = self.module.types.insert(
Type {
name: None,
inner: TypeInner::Struct {
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn calculate_offset(
};

let ty_span = types.get_span(ty);
ty = types.fetch_or_append(
ty = types.insert(
Type {
name,
inner: TypeInner::Array {
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn calculate_offset(
span = align_up(span, align);

let ty_span = types.get_span(ty);
ty = types.fetch_or_append(
ty = types.insert(
Type {
name,
inner: TypeInner::Struct {
Expand Down
2 changes: 1 addition & 1 deletion src/front/glsl/parser/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl<'source> ParsingContext<'source> {
let span = self.parse_struct_declaration_list(parser, &mut members, layout)?;
self.expect(parser, TokenValue::RightBrace)?;

let mut ty = parser.module.types.fetch_or_append(
let mut ty = parser.module.types.insert(
Type {
name: Some(ty_name),
inner: TypeInner::Struct {
Expand Down
2 changes: 1 addition & 1 deletion src/front/glsl/parser/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'source> ParsingContext<'source> {
},
Span::default(),
);
handle = parser.module.types.fetch_or_append(
handle = parser.module.types.insert(
Type {
name: None,
inner: TypeInner::Array {
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'source> ParsingContext<'source> {
let token = self.bump(parser)?;
let handle = match token.value {
TokenValue::Void => None,
TokenValue::TypeName(ty) => Some(parser.module.types.fetch_or_append(ty, token.meta)),
TokenValue::TypeName(ty) => Some(parser.module.types.insert(ty, token.meta)),
TokenValue::Struct => {
let mut meta = token.meta;
let ty_name = self.expect_ident(parser)?.0;
Expand All @@ -47,7 +47,7 @@ impl<'source> ParsingContext<'source> {
self.parse_struct_declaration_list(parser, &mut members, StructLayout::Std140)?;
let end_meta = self.expect(parser, TokenValue::RightBrace)?.meta;
meta.subsume(end_meta);
let ty = parser.module.types.fetch_or_append(
let ty = parser.module.types.insert(
Type {
name: Some(ty_name.clone()),
inner: TypeInner::Struct {
Expand Down
2 changes: 1 addition & 1 deletion src/front/glsl/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Parser {
array_specifier
.map(|(size, size_meta)| {
meta.subsume(size_meta);
self.module.types.fetch_or_append(
self.module.types.insert(
Type {
name: None,
inner: TypeInner::Array {
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Parser {
data: BuiltInData,
meta: Span,
) -> Option<VariableReference> {
let ty = self.module.types.fetch_or_append(
let ty = self.module.types.insert(
Type {
name: None,
inner: data.inner,
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Parser {
storage: StorageQualifier::Output,
},
"gl_ClipDistance" | "gl_CullDistance" => {
let base = self.module.types.fetch_or_append(
let base = self.module.types.insert(
Type {
name: None,
inner: TypeInner::Scalar {
Expand Down
2 changes: 1 addition & 1 deletion src/front/spv/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl<I: Iterator<Item = u32>> super::Parser<I> {
let span = crate::Span::total_span(
components.iter().map(|h| function.expressions.get_span(*h)),
);
let ty = module.types.fetch_or_append(
let ty = module.types.insert(
crate::Type {
name: None,
inner: crate::TypeInner::Struct {
Expand Down
2 changes: 1 addition & 1 deletion src/front/spv/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub(super) fn patch_comparison_type(
};

let name = original_ty.name.clone();
var.ty = arena.fetch_or_append(
var.ty = arena.insert(
crate::Type {
name,
inner: ty_inner,
Expand Down
28 changes: 14 additions & 14 deletions src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3388,7 +3388,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
self.lookup_type.insert(
id,
LookupType {
handle: module.types.fetch_or_append(
handle: module.types.insert(
crate::Type {
name: self.future_decor.remove(&id).and_then(|dec| dec.name),
inner,
Expand Down Expand Up @@ -3423,7 +3423,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
self.lookup_type.insert(
id,
LookupType {
handle: module.types.fetch_or_append(
handle: module.types.insert(
crate::Type {
name: self.future_decor.remove(&id).and_then(|dec| dec.name),
inner,
Expand Down Expand Up @@ -3453,7 +3453,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
self.lookup_type.insert(
id,
LookupType {
handle: module.types.fetch_or_append(
handle: module.types.insert(
crate::Type {
name: self.future_decor.remove(&id).and_then(|dec| dec.name),
inner,
Expand Down Expand Up @@ -3490,7 +3490,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
self.lookup_type.insert(
id,
LookupType {
handle: module.types.fetch_or_append(
handle: module.types.insert(
crate::Type {
name: self.future_decor.remove(&id).and_then(|dec| dec.name),
inner,
Expand Down Expand Up @@ -3529,7 +3529,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
self.lookup_type.insert(
id,
LookupType {
handle: module.types.fetch_or_append(
handle: module.types.insert(
crate::Type {
name: decor.and_then(|dec| dec.name),
inner,
Expand Down Expand Up @@ -3593,7 +3593,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
base_lookup_ty.clone()
} else {
LookupType {
handle: module.types.fetch_or_append(
handle: module.types.insert(
crate::Type {
name: decor.and_then(|dec| dec.name),
inner: crate::TypeInner::Pointer {
Expand Down Expand Up @@ -3636,7 +3636,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
self.lookup_type.insert(
id,
LookupType {
handle: module.types.fetch_or_append(
handle: module.types.insert(
crate::Type {
name: decor.name,
inner,
Expand Down Expand Up @@ -3673,7 +3673,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
self.lookup_type.insert(
id,
LookupType {
handle: module.types.fetch_or_append(
handle: module.types.insert(
crate::Type {
name: decor.name,
inner,
Expand Down Expand Up @@ -3775,7 +3775,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
members,
};

let ty_handle = module.types.fetch_or_append(
let ty_handle = module.types.insert(
crate::Type {
name: parent_decor.and_then(|dec| dec.name),
inner,
Expand Down Expand Up @@ -3823,7 +3823,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
let decor = self.future_decor.remove(&id).unwrap_or_default();

// ensure there is a type for texture coordinate without extra components
module.types.fetch_or_append(
module.types.insert(
crate::Type {
name: None,
inner: {
Expand Down Expand Up @@ -3860,7 +3860,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
arrayed: is_array,
};

let handle = module.types.fetch_or_append(
let handle = module.types.insert(
crate::Type {
name: decor.name,
inner,
Expand Down Expand Up @@ -3903,7 +3903,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
inst.expect(2)?;
let id = self.next()?;
let decor = self.future_decor.remove(&id).unwrap_or_default();
let handle = module.types.fetch_or_append(
let handle = module.types.insert(
crate::Type {
name: decor.name,
inner: crate::TypeInner::Sampler { comparison: false },
Expand Down Expand Up @@ -4149,7 +4149,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
class: crate::ImageClass::Storage { format, access },
},
};
effective_ty = module.types.fetch_or_append(ty, Default::default());
effective_ty = module.types.insert(ty, Default::default());
}

let ext_class = match self.lookup_storage_buffer_types.get(&effective_ty) {
Expand Down Expand Up @@ -4213,7 +4213,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
) {
unsigned_ty = module
.types
.fetch_or_append(crate::Type { name: None, inner }, Default::default());
.insert(crate::Type { name: None, inner }, Default::default());
}
}

Expand Down
Loading

0 comments on commit 9da14b6

Please sign in to comment.