treewide: enforce strict clippy check
This commit is contained in:
+7
-11
@@ -1,6 +1,3 @@
|
||||
#![warn(clippy::unwrap_used)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use fix_bytecode::InstructionPtr;
|
||||
use fix_bytecode::disassembler::{Disassembler, DisassemblerContext};
|
||||
use fix_compiler::{CodeState, ExtraScope};
|
||||
@@ -11,7 +8,6 @@ use fix_vm::Vm;
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use string_interner::{DefaultStringInterner, Symbol as _};
|
||||
|
||||
mod derivation;
|
||||
pub mod logging;
|
||||
|
||||
#[global_allocator]
|
||||
@@ -101,12 +97,12 @@ impl VmRuntimeCtx for RuntimeState {
|
||||
StringId(self.strings.get_or_intern(s))
|
||||
}
|
||||
fn resolve_string(&self, id: StringId) -> &str {
|
||||
#[allow(clippy::unwrap_used)]
|
||||
self.strings.resolve(id.0).unwrap()
|
||||
self.strings
|
||||
.resolve(id.0)
|
||||
.expect("interned string id must resolve")
|
||||
}
|
||||
fn get_const(&self, id: u32) -> StaticValue {
|
||||
#[allow(clippy::unwrap_used)]
|
||||
self.constants.get(id).unwrap()
|
||||
self.constants.get(id).expect("const id must be valid")
|
||||
}
|
||||
fn add_const(&mut self, val: StaticValue) -> u32 {
|
||||
self.constants.insert(val)
|
||||
@@ -145,9 +141,9 @@ impl DisassemblerContext for Evaluator {
|
||||
&self.code.bytecode
|
||||
}
|
||||
|
||||
#[allow(clippy::unwrap_used)]
|
||||
fn resolve_string(&self, id: u32) -> &str {
|
||||
let id = string_interner::symbol::SymbolU32::try_from_usize(id as usize).unwrap();
|
||||
self.runtime.strings.resolve(id).unwrap()
|
||||
let id = string_interner::symbol::SymbolU32::try_from_usize(id as usize)
|
||||
.expect("invalid string id");
|
||||
self.runtime.strings.resolve(id).expect("invalid string id")
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -5,7 +5,7 @@ use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
use tracing_subscriber::{EnvFilter, Layer, fmt};
|
||||
|
||||
pub fn init_logging() {
|
||||
pub fn init_logging() -> Result<(), miette::InstallError> {
|
||||
let is_terminal = std::io::stderr().is_terminal();
|
||||
let show_time = env::var("NIX_JS_LOG_TIME")
|
||||
.map(|v| v == "1" || v.to_lowercase() == "true")
|
||||
@@ -32,10 +32,10 @@ pub fn init_logging() {
|
||||
.with(fmt_layer)
|
||||
.init();
|
||||
|
||||
init_miette_handler();
|
||||
init_miette_handler()
|
||||
}
|
||||
|
||||
fn init_miette_handler() {
|
||||
fn init_miette_handler() -> Result<(), miette::InstallError> {
|
||||
let is_terminal = std::io::stderr().is_terminal();
|
||||
miette::set_hook(Box::new(move |_| {
|
||||
Box::new(
|
||||
@@ -46,5 +46,4 @@ fn init_miette_handler() {
|
||||
.build(),
|
||||
)
|
||||
}))
|
||||
.ok();
|
||||
}
|
||||
|
||||
+34
-19
@@ -20,33 +20,49 @@ struct Cli {
|
||||
enum Command {
|
||||
Compile {
|
||||
#[clap(flatten)]
|
||||
source: ExprSource,
|
||||
source: ExprSourceArgs,
|
||||
#[arg(long)]
|
||||
silent: bool,
|
||||
},
|
||||
Eval {
|
||||
#[clap(flatten)]
|
||||
source: ExprSource,
|
||||
source: ExprSourceArgs,
|
||||
},
|
||||
Repl,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
#[group(required = true, multiple = false)]
|
||||
struct ExprSource {
|
||||
struct ExprSourceArgs {
|
||||
#[clap(short, long)]
|
||||
expr: Option<String>,
|
||||
#[clap(short, long)]
|
||||
file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
enum ExprSource {
|
||||
Expr(String),
|
||||
File(PathBuf),
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::unreachable,
|
||||
reason = "clap's arg group guarantees exactly one of --expr/--file is set"
|
||||
)]
|
||||
impl From<ExprSourceArgs> for ExprSource {
|
||||
fn from(args: ExprSourceArgs) -> Self {
|
||||
match (args.expr, args.file) {
|
||||
(Some(expr), None) => ExprSource::Expr(expr),
|
||||
(None, Some(file)) => ExprSource::File(file),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_compile(eval: &mut Evaluator, src: ExprSource, silent: bool) -> Result<()> {
|
||||
let src = if let Some(expr) = src.expr {
|
||||
Source::new_eval(expr)?
|
||||
} else if let Some(file) = src.file {
|
||||
Source::new_file(file)?
|
||||
} else {
|
||||
unreachable!()
|
||||
let src = match src {
|
||||
ExprSource::Expr(expr) => Source::new_eval(expr)?,
|
||||
ExprSource::File(file) => Source::new_file(file)?,
|
||||
};
|
||||
match eval.compile_bytecode(src) {
|
||||
Ok(ip) => {
|
||||
@@ -63,12 +79,9 @@ fn run_compile(eval: &mut Evaluator, src: ExprSource, silent: bool) -> Result<()
|
||||
}
|
||||
|
||||
fn run_eval(eval: &mut Evaluator, src: ExprSource) -> Result<()> {
|
||||
let src = if let Some(expr) = src.expr {
|
||||
Source::new_eval(expr)?
|
||||
} else if let Some(file) = src.file {
|
||||
Source::new_file(file)?
|
||||
} else {
|
||||
unreachable!()
|
||||
let src = match src {
|
||||
ExprSource::Expr(expr) => Source::new_eval(expr)?,
|
||||
ExprSource::File(file) => Source::new_file(file)?,
|
||||
};
|
||||
match eval.eval_deep(src) {
|
||||
Ok(value) => {
|
||||
@@ -93,7 +106,9 @@ fn run_repl(eval: &mut Evaluator) -> Result<()> {
|
||||
if line.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
let _ = rl.add_history_entry(line.as_str());
|
||||
if let Err(err) = rl.add_history_entry(line.as_str()) {
|
||||
eprintln!("[WARN] Failed to add history entry: {err}");
|
||||
}
|
||||
if let Some([Some(_), Some(ident), Some(rest)]) = RE.exec(&line) {
|
||||
if let Some(expr) = rest.strip_prefix('=') {
|
||||
let expr = expr.trim_start();
|
||||
@@ -137,15 +152,15 @@ fn run_repl(eval: &mut Evaluator) -> Result<()> {
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
fix::logging::init_logging();
|
||||
fix::logging::init_logging()?;
|
||||
|
||||
let cli = Cli::parse();
|
||||
|
||||
let mut eval = Evaluator::new();
|
||||
|
||||
match cli.command {
|
||||
Command::Compile { source, silent } => run_compile(&mut eval, source, silent),
|
||||
Command::Eval { source } => run_eval(&mut eval, source),
|
||||
Command::Compile { source, silent } => run_compile(&mut eval, source.into(), silent),
|
||||
Command::Eval { source } => run_eval(&mut eval, source.into()),
|
||||
Command::Repl => run_repl(&mut eval),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user