Skip to content

Commit c52ee5d

Browse files
mega lint
1 parent 0b32a4a commit c52ee5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1240
-1040
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
/node_modules/
1212
/package-lock.json
1313
/playground/dist/
14-
/.vite/
14+
/.vite/
15+
/.vscode/

build.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
.unwrap();
3737
let fields = contents.contains("pub struct Fields");
3838
let fields_name =
39-
format!("{}_{}_fields", category, opcode).to_case(Case::Pascal);
39+
format!("{category}_{opcode}_fields").to_case(Case::Pascal);
4040
paths.push((
4141
format!(
4242
"{}::{}",
@@ -46,7 +46,7 @@ fn main() {
4646
_ => opcode.to_string(),
4747
}
4848
),
49-
format!("{}_{}", category, opcode,),
49+
format!("{category}_{opcode}",),
5050
fields,
5151
fields_name,
5252
));
@@ -120,7 +120,7 @@ export const imports = {{
120120
format!(
121121
"
122122
/// A list of all instructions.
123-
#[allow(non_camel_case_types)]
123+
#[expect(non_camel_case_types, reason = \"block opcode are snake_case\")]
124124
#[derive(Clone, Debug)]
125125
pub enum IrOpcode {{
126126
{}
@@ -156,7 +156,10 @@ impl IrOpcode {{
156156
}}
157157
}}
158158
pub mod fields {{
159+
#![expect(clippy::wildcard_imports, reason = \"we don't know what we need to import\")]
160+
159161
use super::*;
162+
160163
{}
161164
}}
162165
pub use fields::*;
@@ -170,35 +173,35 @@ pub use fields::*;
170173
}).collect::<Vec<_>>().join(",\n\t"),
171174
paths.iter().map(|(path, id, fields, _)| {
172175
if *fields {
173-
format!("IrOpcode::{}(fields) => {}::acceptable_inputs(fields),", id, path)
176+
format!("Self::{id}(fields) => {path}::acceptable_inputs(fields),")
174177
} else {
175-
format!("IrOpcode::{} => {}::acceptable_inputs(),", id, path)
178+
format!("Self::{id} => {path}::acceptable_inputs(),")
176179
}
177180
}).collect::<Vec<_>>().join("\n\t\t\t"),
178181
paths.iter().map(|(path, id, fields, _)| {
179182
if *fields {
180-
format!("IrOpcode::{}(fields) => {}::wasm(step_func, inputs, fields),", id, path)
183+
format!("Self::{id}(fields) => {path}::wasm(step_func, inputs, fields),")
181184
} else {
182-
format!("IrOpcode::{} => {}::wasm(step_func, inputs),", id, path)
185+
format!("Self::{id} => {path}::wasm(step_func, inputs),")
183186
}
184187
}).collect::<Vec<_>>().join("\n\t\t\t"),
185188
paths.iter().map(|(path, id, fields, _)| {
186189
if *fields {
187-
format!("IrOpcode::{}(fields) => {}::output_type(inputs, fields),", id, path)
190+
format!("Self::{id}(fields) => {path}::output_type(inputs, fields),")
188191
} else {
189-
format!("IrOpcode::{} => {}::output_type(inputs),", id, path)
192+
format!("Self::{id} => {path}::output_type(inputs),")
190193
}
191194
}).collect::<Vec<_>>().join("\n\t\t\t"),
192195
paths.iter().map(|(path, id, fields, _)| {
193196
if *fields {
194-
format!("IrOpcode::{}(_) => {}::REQUESTS_SCREEN_REFRESH,", id, path)
197+
format!("Self::{id}(_) => {path}::REQUESTS_SCREEN_REFRESH,")
195198
} else {
196-
format!("IrOpcode::{} => {}::REQUESTS_SCREEN_REFRESH,", id, path)
199+
format!("Self::{id} => {path}::REQUESTS_SCREEN_REFRESH,")
197200
}
198201
}).collect::<Vec<_>>().join("\n\t\t\t"),
199202
paths.iter().filter(|(_, _, fields, _)| *fields)
200203
.map(|(path, _, _, fields_name)|
201-
format!("pub use {}::Fields as {};", path, fields_name)
204+
format!("pub use {path}::Fields as {fields_name};")
202205
).collect::<Vec<_>>().join("\n\t"),
203206
))
204207
.unwrap();

clippy.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
allowed-duplicate-crates = ["syn"]
2+
too-many-lines-threshold = 150
3+
allow-panic-in-tests = true
4+
allow-unwrap-in-tests = true

src/error.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ pub struct HQError {
1313
pub line: u32,
1414
pub column: u32,
1515
}
16-
#[derive(Clone, Debug, PartialEq)] // todo: get rid of this once all expects are gone
16+
#[derive(Clone, Debug, PartialEq, Eq)] // todo: get rid of this once all expects are gone
1717
pub enum HQErrorType {
1818
MalformedProject,
1919
InternalError,
2020
Unimplemented,
2121
}
2222

2323
impl From<HQError> for JsValue {
24-
fn from(val: HQError) -> JsValue {
25-
JsValue::from_str(match val.err_type {
24+
fn from(val: HQError) -> Self {
25+
Self::from_str(match val.err_type {
2626
HQErrorType::Unimplemented => format!("todo: {}<br>at {}:{}:{}<br>this is a bug or missing feature that is known and will be fixed or implemented in a future update", val.msg, val.file, val.line, val.column),
2727
HQErrorType::InternalError => format!("error: {}<br>at {}:{}:{}<br>this is probably a bug with HyperQuark itself. Please report this bug, with this error message, at <a href=\"https://github.com/hyperquark/hyperquark/issues/new\">https://github.com/hyperquark/hyperquark/issues/new</a>", val.msg, val.file, val.line, val.column),
2828
HQErrorType::MalformedProject => format!("error: {}<br>at {}:{}:{}<br>this is probably a problem with the project itself, but if it works in vanilla scratch then this is a bug; please report it, by creating an issue at <a href=\"https://github.com/hyperquark/hyperquark/issues/new\">https://github.com/hyperquark/hyperquark/issues/new</a>, including this error message", val.msg, val.file, val.line, val.column),
@@ -32,7 +32,7 @@ impl From<HQError> for JsValue {
3232

3333
impl From<BorrowError> for HQError {
3434
fn from(_e: BorrowError) -> Self {
35-
HQError {
35+
Self {
3636
err_type: HQErrorType::InternalError,
3737
msg: "couldn't borrow cell".into(),
3838
file: file!().into(),
@@ -44,7 +44,7 @@ impl From<BorrowError> for HQError {
4444

4545
impl From<BorrowMutError> for HQError {
4646
fn from(_e: BorrowMutError) -> Self {
47-
HQError {
47+
Self {
4848
err_type: HQErrorType::InternalError,
4949
msg: "couldn't mutably borrow cell".into(),
5050
file: file!().into(),
@@ -55,6 +55,7 @@ impl From<BorrowMutError> for HQError {
5555
}
5656

5757
#[macro_export]
58+
#[clippy::format_args]
5859
macro_rules! hq_todo {
5960
() => {{
6061
return Err($crate::HQError {
@@ -77,6 +78,7 @@ macro_rules! hq_todo {
7778
}
7879

7980
#[macro_export]
81+
#[clippy::format_args]
8082
macro_rules! hq_bug {
8183
($($args:tt)+) => {{
8284
return Err($crate::HQError {
@@ -90,6 +92,7 @@ macro_rules! hq_bug {
9092
}
9193

9294
#[macro_export]
95+
#[clippy::format_args]
9396
macro_rules! hq_assert {
9497
($expr:expr) => {{
9598
if !($expr) {
@@ -100,7 +103,8 @@ macro_rules! hq_assert {
100103
line: line!(),
101104
column: column!()
102105
});
103-
}
106+
};
107+
assert!($expr);
104108
}};
105109
($expr:expr, $($args:tt)+) => {{
106110
if !($expr) {
@@ -111,11 +115,13 @@ macro_rules! hq_assert {
111115
line: line!(),
112116
column: column!()
113117
});
114-
}
118+
};
119+
assert!($expr);
115120
}};
116121
}
117122

118123
#[macro_export]
124+
#[clippy::format_args]
119125
macro_rules! hq_assert_eq {
120126
($l:expr, $r:expr) => {{
121127
if $l != $r {
@@ -126,7 +132,8 @@ macro_rules! hq_assert_eq {
126132
line: line!(),
127133
column: column!()
128134
});
129-
}
135+
};
136+
assert_eq!($l, $r);
130137
}};
131138
($l:expr, $r:expr, $($args:tt)+) => {{
132139
if $l != $r {
@@ -137,11 +144,13 @@ macro_rules! hq_assert_eq {
137144
line: line!(),
138145
column: column!()
139146
});
140-
}
147+
};
148+
assert_eq!($l, $r);
141149
}};
142150
}
143151

144152
#[macro_export]
153+
#[clippy::format_args]
145154
macro_rules! hq_bad_proj {
146155
($($args:tt)+) => {{
147156
return Err($crate::HQError {
@@ -155,6 +164,7 @@ macro_rules! hq_bad_proj {
155164
}
156165

157166
#[macro_export]
167+
#[clippy::format_args]
158168
macro_rules! make_hq_todo {
159169
($($args:tt)+) => {{
160170
use $crate::alloc::Box<str>::ToBox<str>;
@@ -169,6 +179,7 @@ macro_rules! make_hq_todo {
169179
}
170180

171181
#[macro_export]
182+
#[clippy::format_args]
172183
macro_rules! make_hq_bug {
173184
($($args:tt)+) => {{
174185
$crate::HQError {
@@ -182,6 +193,7 @@ macro_rules! make_hq_bug {
182193
}
183194

184195
#[macro_export]
196+
#[clippy::format_args]
185197
macro_rules! make_hq_bad_proj {
186198
($($args:tt)+) => {{
187199
$crate::HQError {

src/instructions.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
//! Contains information about instructions (roughly anaologus to blocks),
22
//! including input type validation, output type mapping, and WASM generation.
33
4+
#![allow(
5+
clippy::unnecessary_wraps,
6+
reason = "many functions here needlessly return `Result`s in order to keep type signatures consistent"
7+
)]
8+
#![allow(
9+
clippy::needless_pass_by_value,
10+
reason = "there are so many `Rc<T>`s here which I don't want to change"
11+
)]
12+
413
use crate::prelude::*;
514

615
mod control;
@@ -22,14 +31,14 @@ pub use input_switcher::wrap_instruction;
2231
pub use hq::r#yield::YieldMode;
2332

2433
mod prelude {
25-
pub(crate) use crate::ir::Type as IrType;
34+
pub use crate::ir::Type as IrType;
2635
pub use crate::prelude::*;
27-
pub(crate) use crate::wasm::{InternalInstruction, StepFunc};
36+
pub use crate::wasm::{InternalInstruction, StepFunc};
2837
pub use wasm_encoder::{RefType, ValType};
2938
pub use wasm_gen::wasm;
3039

3140
/// Canonical NaN + bit 33, + string pointer in bits 1-32
32-
pub const BOXED_STRING_PATTERN: i64 = 0x7FF80001 << 32;
41+
pub const BOXED_STRING_PATTERN: i64 = 0x7FF8_0001 << 32;
3342
/// Canonical NaN + bit 33, + i32 in bits 1-32
34-
pub const BOXED_INT_PATTERN: i64 = 0x7ff80002 << 32;
43+
pub const BOXED_INT_PATTERN: i64 = 0x7ff8_0002 << 32;
3544
}

src/instructions/control/if_else.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub fn wasm(
1616
branch_else,
1717
}: &Fields,
1818
) -> HQResult<Vec<InternalInstruction>> {
19-
let if_instructions = func.compile_inner_step(Rc::clone(branch_if))?;
20-
let else_instructions = func.compile_inner_step(Rc::clone(branch_else))?;
19+
let if_instructions = func.compile_inner_step(branch_if)?;
20+
let else_instructions = func.compile_inner_step(branch_else)?;
2121
let block_type = func
2222
.registries()
2323
.types()

src/instructions/control/loop.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ pub fn wasm(
2222
flip_if,
2323
}: &Fields,
2424
) -> HQResult<Vec<InternalInstruction>> {
25-
let inner_instructions = func.compile_inner_step(Rc::clone(body))?;
26-
let first_condition_instructions = func.compile_inner_step(Rc::clone(
27-
&first_condition.clone().unwrap_or(Rc::clone(condition)),
28-
))?;
29-
let condition_instructions = func.compile_inner_step(Rc::clone(condition))?;
25+
let inner_instructions = func.compile_inner_step(body)?;
26+
let first_condition_instructions = func.compile_inner_step(
27+
&first_condition
28+
.clone()
29+
.unwrap_or_else(|| Rc::clone(condition)),
30+
)?;
31+
let condition_instructions = func.compile_inner_step(condition)?;
3032
Ok(wasm![Block(BlockType::Empty),]
3133
.into_iter()
3234
.chain(first_condition_instructions)

src/instructions/data/setvariableto.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn wasm(
1111
) -> HQResult<Vec<InternalInstruction>> {
1212
let t1 = inputs[0];
1313
if variable.0.local() {
14-
let local_index: u32 = func.local_variable(RcVar::clone(variable))?;
14+
let local_index: u32 = func.local_variable(variable)?;
1515
if variable.0.possible_types().is_base_type() {
1616
Ok(wasm![LocalSet(local_index)])
1717
} else {
@@ -21,10 +21,7 @@ pub fn wasm(
2121
])
2222
}
2323
} else {
24-
let global_index: u32 = func
25-
.registries()
26-
.variables()
27-
.register(RcVar::clone(variable))?;
24+
let global_index: u32 = func.registries().variables().register(variable)?;
2825
if variable.0.possible_types().is_base_type() {
2926
Ok(wasm![GlobalSet(global_index)])
3027
} else {

src/instructions/data/teevariable.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn wasm(
1313
) -> HQResult<Vec<InternalInstruction>> {
1414
let t1 = inputs[0];
1515
if variable.0.local() {
16-
let local_index: u32 = func.local_variable(RcVar::clone(variable))?;
16+
let local_index: u32 = func.local_variable(variable)?;
1717
if variable.0.possible_types().is_base_type() {
1818
Ok(wasm![LocalTee(local_index)])
1919
} else {
@@ -23,10 +23,7 @@ pub fn wasm(
2323
])
2424
}
2525
} else {
26-
let global_index: u32 = func
27-
.registries()
28-
.variables()
29-
.register(RcVar::clone(variable))?;
26+
let global_index: u32 = func.registries().variables().register(variable)?;
3027
if variable.0.possible_types().is_base_type() {
3128
Ok(wasm![GlobalSet(global_index), GlobalGet(global_index)])
3229
} else {

src/instructions/data/variable.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ pub fn wasm(
1010
Fields(variable): &Fields,
1111
) -> HQResult<Vec<InternalInstruction>> {
1212
if variable.0.local() {
13-
let local_index: u32 = func.local_variable(RcVar::clone(variable))?;
13+
let local_index: u32 = func.local_variable(variable)?;
1414
Ok(wasm![LocalGet(local_index)])
1515
} else {
16-
let global_index: u32 = func
17-
.registries()
18-
.variables()
19-
.register(RcVar::clone(variable))?;
16+
let global_index: u32 = func.registries().variables().register(variable)?;
2017
Ok(wasm![GlobalGet(global_index)])
2118
}
2219
}

src/instructions/hq/cast.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn best_cast_candidate(from: IrType, to: IrType) -> HQResult<IrType> {
99
let Some(from_base) = from.base_type() else {
1010
hq_bug!("from type has no base type")
1111
};
12-
Ok(if to_base_types.contains(&&from_base) {
12+
Ok(if to_base_types.contains(&from_base) {
1313
from_base
1414
} else {
1515
let mut candidates = vec![];
@@ -19,7 +19,7 @@ fn best_cast_candidate(from: IrType, to: IrType) -> HQResult<IrType> {
1919
IrType::String => &[IrType::Float, IrType::QuasiInt] as &[IrType],
2020
_ => unreachable!(),
2121
} {
22-
if to_base_types.contains(&preference) {
22+
if to_base_types.contains(preference) {
2323
candidates.push(preference);
2424
}
2525
}
@@ -96,11 +96,11 @@ pub fn output_type(inputs: Rc<[IrType]>, &Fields(to): &Fields) -> HQResult<Optio
9696
Ok(Some(
9797
inputs[0]
9898
.base_types()
99-
.map(|&from| best_cast_candidate(from, to))
99+
.map(|from| best_cast_candidate(from, to))
100100
.collect::<HQResult<Vec<_>>>()?
101101
.into_iter()
102-
.reduce(|acc, el| acc.or(el))
103-
.ok_or(make_hq_bug!("input was empty"))?,
102+
.reduce(IrType::or)
103+
.ok_or_else(|| make_hq_bug!("input was empty"))?,
104104
))
105105
}
106106

src/instructions/hq/float.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![allow(
2+
clippy::trivially_copy_pass_by_ref,
3+
reason = "Fields should be passed by reference for type signature consistency"
4+
)]
5+
16
use super::super::prelude::*;
27

38
#[derive(Clone, Copy, Debug)]

0 commit comments

Comments
 (0)