Skip to content

Commit

Permalink
chore: clean up smallvec usage (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Oct 20, 2024
1 parent 9a02c05 commit e82e7eb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ rustc-hash = "2.0"
scc = "2"
scoped-tls = "1.0"
semver = "1.0"
smallvec = "1"
smallvec = { version = "1", features = ["const_generics", "union"] }
thread_local = "1.1"
tikv-jemallocator = "0.6"
typed-arena = "2.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/data-structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ index_vec.workspace = true
indexmap.workspace = true
parking_lot.workspace = true
rustc-hash.workspace = true
smallvec = { workspace = true, features = ["union"] }
smallvec.workspace = true

[features]
nightly = [
Expand Down
1 change: 1 addition & 0 deletions crates/data-structures/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ macro_rules! base_index {
}

impl fmt::Debug for $name {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.value.fmt(f)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/sema/src/ast_lowering/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use solar_ast::ast;
use solar_data_structures::{
index::{Idx, IndexVec},
map::{FxIndexMap, IndexEntry},
smallvec::{smallvec, SmallVec},
smallvec::SmallVec,
BumpExt,
};
use solar_interface::{
Expand Down Expand Up @@ -1109,16 +1109,16 @@ impl Declarations {
) -> Result<(), Declaration> {
match self.declarations.entry(name) {
IndexEntry::Occupied(entry) => {
if let Some(conflict) = Self::conflicting_declaration(hir, decl, entry.get()) {
let declarations = entry.into_mut();
if let Some(conflict) = Self::conflicting_declaration(hir, decl, declarations) {
return Err(conflict);
}
let declarations = entry.into_mut();
if !declarations.contains(&decl) {
declarations.push(decl);
}
}
IndexEntry::Vacant(entry) => {
entry.insert(smallvec![decl]);
entry.insert(SmallVec::from_buf([decl]));
}
}
Ok(())
Expand Down
5 changes: 5 additions & 0 deletions crates/sema/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl<'hir> Hir<'hir> {
}

/// Returns the item associated with the given ID.
#[inline]
pub fn item(&self, id: impl Into<ItemId>) -> Item<'_, 'hir> {
match id.into() {
ItemId::Contract(id) => Item::Contract(self.contract(id)),
Expand Down Expand Up @@ -289,6 +290,7 @@ pub enum Item<'a, 'hir> {

impl Item<'_, '_> {
/// Returns the name of the item.
#[inline]
pub fn name(self) -> Option<Ident> {
match self {
Item::Contract(c) => Some(c.name),
Expand All @@ -303,6 +305,7 @@ impl Item<'_, '_> {
}

/// Returns the description of the item.
#[inline]
pub fn description(self) -> &'static str {
match self {
Item::Contract(c) => c.kind.to_str(),
Expand All @@ -317,6 +320,7 @@ impl Item<'_, '_> {
}

/// Returns the span of the item.
#[inline]
pub fn span(self) -> Span {
match self {
Item::Contract(c) => c.span,
Expand All @@ -331,6 +335,7 @@ impl Item<'_, '_> {
}

/// Returns the contract ID if this item is part of a contract.
#[inline]
pub fn contract(self) -> Option<ContractId> {
match self {
Item::Contract(_) => None,
Expand Down
2 changes: 1 addition & 1 deletion crates/sema/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ pub fn interface_functions(gcx: _, id: hir::ContractId) -> InterfaceFunctions<'g
gcx.dcx().err(msg).span(c.name.span).span_note(f.span, "first function").span_note(f2.span, "second function").note(full_note).emit();
}

Some(InterfaceFunction{ selector, id: f_id, ty })
Some(InterfaceFunction { selector, id: f_id, ty })
});
let functions = gcx.bump().alloc_from_iter(functions);
let inheritance_start = inheritance_start.expect("linearized_bases did not contain self ID");
Expand Down

0 comments on commit e82e7eb

Please sign in to comment.