Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ crossbeam-utils = "0.8.21"
jod-thread = "0.1.2"
libc = "0.2.171"
tracing = "0.1.40"
rustc-hash = "2.1.1"

# local
# we have to make the versions explicit otherwise `cargo publish` won't work
Expand All @@ -89,6 +90,7 @@ doc_markdown = "deny"
manual_let_else = "deny"
explicit_iter_loop = "deny"
too_many_arguments = "allow"
disallowed_types = "deny"

[profile.dev]
debug = 0
Expand Down
4 changes: 4 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
disallowed-types = [
{ path = "std::collections::HashMap", reason = "Use rustc_hash::FxHashMap instead" },
{ path = "std::collections::HashSet", reason = "Use rustc_hash::FxHashSet instead" },
]
1 change: 1 addition & 0 deletions crates/squawk_ide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ la-arena.workspace = true
smallvec.workspace = true
itertools.workspace = true
etcetera.workspace = true
rustc-hash.workspace = true

[dev-dependencies]
insta.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_ide/src/folding_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// NOTE: pretty much copied as is but simplfied a fair bit. I don't use folding
// much so not sure if this is optimal.

use std::collections::HashSet;
use rustc_hash::FxHashSet;

use rowan::{Direction, NodeOrToken, TextRange};
use salsa::Database as Db;
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn folding_ranges(db: &dyn Db, file: File) -> Vec<Fold> {
let parse = parse(db, file);

let mut folds = vec![];
let mut visited_comments = HashSet::default();
let mut visited_comments = FxHashSet::default();

for element in parse.tree().syntax().descendants_with_tokens() {
match &element {
Expand Down Expand Up @@ -166,7 +166,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {

fn contiguous_range_for_comment(
first: ast::Comment,
visited: &mut HashSet<ast::Comment>,
visited: &mut FxHashSet<ast::Comment>,
) -> Option<TextRange> {
visited.insert(first.clone());

Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_ide/src/scope.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use la_arena::Idx;
use std::collections::HashMap;
use rustc_hash::FxHashMap;

use crate::symbols::{Name, SymbolId};

Expand All @@ -9,14 +9,14 @@ pub(crate) type ScopeId = Idx<Scope>;
pub(crate) struct Scope {
#[allow(dead_code)]
pub(crate) parent: Option<ScopeId>,
pub(crate) entries: HashMap<Name, Vec<SymbolId>>,
pub(crate) entries: FxHashMap<Name, Vec<SymbolId>>,
}

impl Scope {
pub(crate) fn with_parent(parent: Option<ScopeId>) -> Self {
Scope {
parent,
entries: HashMap::new(),
entries: FxHashMap::default(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum-iterator.workspace = true
line-index.workspace = true
serde_plain.workspace = true
annotate-snippets.workspace = true

rustc-hash.workspace = true

[lints]
workspace = true
6 changes: 3 additions & 3 deletions crates/squawk_linter/src/ignore.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use rustc_hash::FxHashSet;

use rowan::{NodeOrToken, TextRange, TextSize};
use squawk_syntax::{SyntaxKind, SyntaxNode, SyntaxToken};
Expand All @@ -14,7 +14,7 @@ pub enum IgnoreKind {
#[derive(Debug)]
pub struct Ignore {
pub range: TextRange,
pub violation_names: HashSet<Rule>,
pub violation_names: FxHashSet<Rule>,
pub ignore_all: bool,
pub kind: IgnoreKind,
}
Expand Down Expand Up @@ -79,7 +79,7 @@ pub(crate) fn find_ignores(ctx: &mut Linter, file: &SyntaxNode) {
if token.kind() == SyntaxKind::COMMENT =>
{
if let Some((rule_names, range, kind)) = ignore_rule_info(&token) {
let mut set = HashSet::new();
let mut set = FxHashSet::default();
let mut offset = 0usize;
// We have a specific check instead of going off of empty
// rules in case we have invalid rule names specified in the
Expand Down
15 changes: 7 additions & 8 deletions crates/squawk_linter/src/ignore_index.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use std::{
collections::{HashMap, HashSet},
fmt,
};
use std::fmt;

use rustc_hash::{FxHashMap, FxHashSet};

use line_index::LineIndex;
use rowan::TextRange;

use crate::{Ignore, Rule, ignore::IgnoreKind};

pub(crate) struct IgnoreIndex {
line_to_ignored: HashMap<u32, HashSet<Rule>>,
file_ignored: HashSet<Rule>,
line_to_ignored: FxHashMap<u32, FxHashSet<Rule>>,
file_ignored: FxHashSet<Rule>,
ignore_all: bool,
line_index: LineIndex,
}
Expand All @@ -32,8 +31,8 @@ impl fmt::Debug for IgnoreIndex {
impl IgnoreIndex {
pub(crate) fn new(text: &str, ignores: &[Ignore]) -> Self {
let line_index = LineIndex::new(text);
let mut line_to_ignored: HashMap<u32, HashSet<Rule>> = HashMap::new();
let mut file_ignored: HashSet<Rule> = HashSet::new();
let mut line_to_ignored: FxHashMap<u32, FxHashSet<Rule>> = FxHashMap::default();
let mut file_ignored: FxHashSet<Rule> = FxHashSet::default();
let mut ignore_all = false;
for ignore in ignores {
match ignore.kind {
Expand Down
16 changes: 8 additions & 8 deletions crates/squawk_linter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use rustc_hash::{FxBuildHasher, FxHashSet};
use std::fmt;

use enum_iterator::Sequence;
Expand Down Expand Up @@ -317,7 +317,7 @@ pub struct LinterSettings {
pub struct Linter {
errors: Vec<Violation>,
ignores: Vec<Ignore>,
pub rules: HashSet<Rule>,
pub rules: FxHashSet<Rule>,
pub settings: LinterSettings,
}

Expand Down Expand Up @@ -452,30 +452,30 @@ impl Linter {
}

pub fn with_all_rules() -> Self {
let rules = all::<Rule>().collect::<HashSet<_>>();
let rules = all::<Rule>().collect::<FxHashSet<_>>();
Linter::from(rules)
}

pub fn without_rules(exclude: &[Rule]) -> Self {
let all_rules = all::<Rule>().collect::<HashSet<_>>();
let mut exclude_set = HashSet::with_capacity(exclude.len());
let all_rules = all::<Rule>().collect::<FxHashSet<_>>();
let mut exclude_set = FxHashSet::with_capacity_and_hasher(exclude.len(), FxBuildHasher);
for e in exclude {
exclude_set.insert(e);
}

let rules = all_rules
.into_iter()
.filter(|x| !exclude_set.contains(x))
.collect::<HashSet<_>>();
.collect::<FxHashSet<_>>();

Linter::from(rules)
}

pub fn from(rules: impl Into<HashSet<Rule>>) -> Self {
pub fn from(rules: impl IntoIterator<Item = Rule>) -> Self {
Self {
errors: vec![],
ignores: vec![],
rules: rules.into(),
rules: rules.into_iter().collect(),
settings: Default::default(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/squawk_linter/src/rules/adding_field_with_default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use lazy_static::lazy_static;
use std::collections::HashSet;
use rustc_hash::FxHashSet;

use squawk_syntax::ast::AstNode;
use squawk_syntax::{Parse, SourceFile, SyntaxKind};
Expand All @@ -8,7 +8,7 @@ use squawk_syntax::{ast, identifier::Identifier};
use crate::{Linter, Rule, Version, Violation};

lazy_static! {
static ref NON_VOLATILE_FUNCS: HashSet<Identifier> = {
static ref NON_VOLATILE_FUNCS: FxHashSet<Identifier> = {
NON_VOLATILE_BUILT_IN_FUNCTIONS
.split('\n')
.map(|x| x.trim())
Expand Down
9 changes: 5 additions & 4 deletions crates/squawk_linter/src/rules/adding_not_null_field.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use rustc_hash::{FxHashMap, FxHashSet};

use squawk_syntax::{
Parse, SourceFile,
Expand Down Expand Up @@ -49,11 +49,12 @@ pub(crate) fn adding_not_null_field(ctx: &mut Linter, parse: &Parse<SourceFile>)

let is_pg12_plus = ctx.settings.pg_version >= Version::new(12, None, None);

let mut not_null_constraints: HashMap<Identifier, TableColumn> = HashMap::new();
let mut validated_not_null_columns: HashSet<TableColumn> = HashSet::new();
let mut not_null_constraints: FxHashMap<Identifier, TableColumn> = FxHashMap::default();
let mut validated_not_null_columns: FxHashSet<TableColumn> = FxHashSet::default();
// Tables where VALIDATE CONSTRAINT was seen without a matching ADD CONSTRAINT
// in the same file (cross-migration pattern).
let mut tables_with_external_validated_constraints: HashSet<Identifier> = HashSet::new();
let mut tables_with_external_validated_constraints: FxHashSet<Identifier> =
FxHashSet::default();

for stmt in file.stmts() {
if let ast::Stmt::AlterTable(alter_table) = stmt {
Expand Down
8 changes: 5 additions & 3 deletions crates/squawk_linter/src/rules/ban_char_field.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use rustc_hash::FxHashSet;

use rowan::TextRange;
use squawk_syntax::{
Expand All @@ -13,11 +13,13 @@ use crate::{Edit, Fix, Linter, Rule, Violation};
use lazy_static::lazy_static;

lazy_static! {
static ref CHAR_TYPES: HashSet<Identifier> = HashSet::from([
static ref CHAR_TYPES: FxHashSet<Identifier> = [
Identifier::new("char"),
Identifier::new("character"),
Identifier::new("bpchar"),
]);
]
.into_iter()
.collect();
}

fn is_char_type(x: TokenText<'_>) -> bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use rustc_hash::FxHashSet;

use squawk_syntax::{
Parse, SourceFile,
Expand All @@ -11,8 +11,8 @@ use crate::{Linter, Rule, Violation};
pub fn tables_created_in_transaction(
assume_in_transaction: bool,
file: &ast::SourceFile,
) -> HashSet<Identifier> {
let mut created_table_names = HashSet::new();
) -> FxHashSet<Identifier> {
let mut created_table_names = FxHashSet::default();
let mut inside_transaction = assume_in_transaction;
for stmt in file.stmts() {
match stmt {
Expand Down Expand Up @@ -44,7 +44,7 @@ fn not_valid_validate_in_transaction(
file: &ast::SourceFile,
) {
let mut inside_transaction = assume_in_transaction;
let mut not_valid_names: HashSet<Identifier> = HashSet::new();
let mut not_valid_names: FxHashSet<Identifier> = FxHashSet::default();
for stmt in file.stmts() {
match stmt {
ast::Stmt::AlterTable(alter_table) => {
Expand Down
8 changes: 5 additions & 3 deletions crates/squawk_linter/src/rules/prefer_bigint_over_int.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use rustc_hash::FxHashSet;

use squawk_syntax::ast::AstNode;
use squawk_syntax::{Parse, SourceFile, ast, identifier::Identifier};
Expand All @@ -11,13 +11,15 @@ use crate::visitors::is_not_valid_int_type;
use lazy_static::lazy_static;

lazy_static! {
static ref INT_TYPES: HashSet<Identifier> = HashSet::from([
static ref INT_TYPES: FxHashSet<Identifier> = [
Identifier::new("int"),
Identifier::new("integer"),
Identifier::new("int4"),
Identifier::new("serial"),
Identifier::new("serial4"),
]);
]
.into_iter()
.collect();
}

fn int_to_bigint_replacement(int_type: &str) -> &'static str {
Expand Down
8 changes: 5 additions & 3 deletions crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use rustc_hash::FxHashSet;

use squawk_syntax::ast::AstNode;
use squawk_syntax::{Parse, SourceFile, ast, identifier::Identifier};
Expand All @@ -11,12 +11,14 @@ use crate::visitors::is_not_valid_int_type;
use lazy_static::lazy_static;

lazy_static! {
static ref SMALL_INT_TYPES: HashSet<Identifier> = HashSet::from([
static ref SMALL_INT_TYPES: FxHashSet<Identifier> = [
Identifier::new("smallint"),
Identifier::new("int2"),
Identifier::new("smallserial"),
Identifier::new("serial2"),
]);
]
.into_iter()
.collect();
}

fn smallint_to_bigint(smallint_type: &str) -> &'static str {
Expand Down
8 changes: 5 additions & 3 deletions crates/squawk_linter/src/rules/prefer_identity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use rustc_hash::FxHashSet;

use squawk_syntax::{
Parse, SourceFile,
Expand All @@ -13,14 +13,16 @@ use lazy_static::lazy_static;
use crate::visitors::{check_not_allowed_types, is_not_valid_int_type};

lazy_static! {
static ref SERIAL_TYPES: HashSet<Identifier> = HashSet::from([
static ref SERIAL_TYPES: FxHashSet<Identifier> = [
Identifier::new("serial"),
Identifier::new("serial2"),
Identifier::new("serial4"),
Identifier::new("serial8"),
Identifier::new("smallserial"),
Identifier::new("bigserial"),
]);
]
.into_iter()
.collect();
}

fn replace_serial(serial_type: &str) -> &'static str {
Expand Down
Loading
Loading