diff --git a/crates/perry-codegen-arkts/src/emit_widget.rs b/crates/perry-codegen-arkts/src/emit_widget.rs index 0aa8d75338..b680474195 100644 --- a/crates/perry-codegen-arkts/src/emit_widget.rs +++ b/crates/perry-codegen-arkts/src/emit_widget.rs @@ -229,10 +229,9 @@ pub(crate) fn emit_widget( // first arg (handled above). Falling here means the // user used TreeNode in an unsupported position — // emit a comment + placeholder so the build still works. - "TreeNode" => format!( - "// TreeNode used outside TreeView's first arg — not renderable\n\ + "TreeNode" => "// TreeNode used outside TreeView's first arg — not renderable\n\ Text('[TreeNode misplaced]').fontSize(14).fontColor('#888888')" - ), + .to_string(), other => format!( "// unsupported perry/ui widget: {} (Phase 2 v12)\n\ Text('[unsupported: {}]').fontSize(16).fontColor('#888888')", @@ -327,9 +326,8 @@ pub(crate) fn emit_widget( local_hint, ) } - _ => format!( - "// unrecognized body expression (must be a perry/ui widget call)\n\ + _ => "// unrecognized body expression (must be a perry/ui widget call)\n\ Text('[unrecognized body]').fontSize(16).fontColor('#888888')" - ), + .to_string(), } } diff --git a/crates/perry-codegen-arkts/src/widgets/tree.rs b/crates/perry-codegen-arkts/src/widgets/tree.rs index c8f652c758..642e645f69 100644 --- a/crates/perry-codegen-arkts/src/widgets/tree.rs +++ b/crates/perry-codegen-arkts/src/widgets/tree.rs @@ -45,10 +45,9 @@ pub(crate) fn emit_treeview( let Some(root_node) = root else { // Couldn't resolve the root TreeNode call — degrade to a comment // + placeholder so the user can see the gap. - return format!( - "// TreeView: couldn't resolve root TreeNode call (non-literal binding)\n\ + return "// TreeView: couldn't resolve root TreeNode call (non-literal binding)\n\ Text('[TreeView: unresolved root]').fontSize(14).fontColor('#888888')" - ); + .to_string(); }; let field_id = format!("{}", extras.tree_view_instances.len()); diff --git a/crates/perry-codegen-js/src/emit/exprs_more.rs b/crates/perry-codegen-js/src/emit/exprs_more.rs index d264d3cbb3..10fdb0e9d2 100644 --- a/crates/perry-codegen-js/src/emit/exprs_more.rs +++ b/crates/perry-codegen-js/src/emit/exprs_more.rs @@ -1062,7 +1062,7 @@ impl JsEmitter { self.output.push(')'); } Expr::GetAsyncIterator(val) => { - self.output.push_str("("); + self.output.push('('); self.emit_expr(val); self.output.push_str(")[Symbol.asyncIterator]?.() ?? ("); self.emit_expr(val); diff --git a/crates/perry-codegen-wasm/src/emit/locals.rs b/crates/perry-codegen-wasm/src/emit/locals.rs index 13f72c17e0..4d145dd5ee 100644 --- a/crates/perry-codegen-wasm/src/emit/locals.rs +++ b/crates/perry-codegen-wasm/src/emit/locals.rs @@ -81,11 +81,9 @@ pub(super) fn collect_locals( ) { for stmt in stmts { match stmt { - Stmt::Let { id, .. } => { - if !map.contains_key(id) { - map.insert(*id, offset + *count); - *count += 1; - } + Stmt::Let { id, .. } if !map.contains_key(id) => { + map.insert(*id, offset + *count); + *count += 1; } Stmt::If { then_branch, diff --git a/crates/perry-codegen/src/codegen/entry.rs b/crates/perry-codegen/src/codegen/entry.rs index 97ee5260ba..5ea55e2fbb 100644 --- a/crates/perry-codegen/src/codegen/entry.rs +++ b/crates/perry-codegen/src/codegen/entry.rs @@ -395,7 +395,7 @@ pub(super) fn compile_module_entry( func_returns_class: &cross_module.func_returns_class, boxed_vars: main_boxed_vars, prealloc_boxes: std::collections::HashSet::new(), - closure_rest_params: closure_rest_params, + closure_rest_params, local_closure_func_ids: HashMap::new(), local_closure_param_counts: HashMap::new(), option_object_locals: HashMap::new(), @@ -841,7 +841,7 @@ pub(super) fn compile_module_entry( func_returns_class: &cross_module.func_returns_class, boxed_vars: init_boxed_vars, prealloc_boxes: std::collections::HashSet::new(), - closure_rest_params: closure_rest_params, + closure_rest_params, local_closure_func_ids: HashMap::new(), local_closure_param_counts: HashMap::new(), option_object_locals: HashMap::new(), diff --git a/crates/perry-codegen/src/codegen/mod.rs b/crates/perry-codegen/src/codegen/mod.rs index bed5f221c5..1d603d60a6 100644 --- a/crates/perry-codegen/src/codegen/mod.rs +++ b/crates/perry-codegen/src/codegen/mod.rs @@ -37,7 +37,7 @@ use perry_hir::Module as HirModule; use crate::module::LlModule; use crate::runtime_decls; use crate::strings::StringPool; -use crate::types::{LlvmType, DOUBLE, I64, VOID}; +use crate::types::{LlvmType, DOUBLE, I64}; pub(crate) mod arguments; mod artifacts; @@ -1663,15 +1663,15 @@ pub fn compile_module(hir: &HirModule, opts: CompileOptions) -> Result> // by the imported alias resolve to the local definition. for sf_name in &ic.static_field_names { let key = (effective_name.to_string(), sf_name.clone()); - if !static_field_globals.contains_key(&key) { + static_field_globals.entry(key).or_insert_with(|| { let global_name = format!( "perry_static_{}__{}__{}", module_prefix, sanitize_member(&ic.name), sanitize_member(sf_name), ); - static_field_globals.insert(key, global_name); - } + global_name + }); } continue; } diff --git a/crates/perry-codegen/src/codegen/opts.rs b/crates/perry-codegen/src/codegen/opts.rs index eb877a91ed..2c6ab3ce39 100644 --- a/crates/perry-codegen/src/codegen/opts.rs +++ b/crates/perry-codegen/src/codegen/opts.rs @@ -38,8 +38,9 @@ impl Default for AppMetadata { /// `On` and `Fast` currently emit the same per-instruction flag while /// remaining distinct user-facing/cache-key modes. #[repr(u8)] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum FpContractMode { + #[default] Off, On, Fast, @@ -68,12 +69,6 @@ impl FpContractMode { } } -impl Default for FpContractMode { - fn default() -> Self { - Self::Off - } -} - /// Options controlling code generation for a single module. #[derive(Debug, Clone, Default)] pub struct CompileOptions { diff --git a/crates/perry-codegen/src/codegen/string_pool.rs b/crates/perry-codegen/src/codegen/string_pool.rs index c08f7c2dac..6dd7cd03d9 100644 --- a/crates/perry-codegen/src/codegen/string_pool.rs +++ b/crates/perry-codegen/src/codegen/string_pool.rs @@ -255,7 +255,7 @@ pub(super) fn emit_string_pool( named.push((cid, class_name.clone())); } } - named.sort_by(|a, b| a.0.cmp(&b.0)); + named.sort_by_key(|a| a.0); named.dedup_by_key(|(cid, _)| *cid); for (cid, name) in named { let (const_name, byte_len) = llmod.add_string_constant(&name); diff --git a/crates/perry-codegen/src/collectors/clamp_detect.rs b/crates/perry-codegen/src/collectors/clamp_detect.rs index 752f147135..e302760406 100644 --- a/crates/perry-codegen/src/collectors/clamp_detect.rs +++ b/crates/perry-codegen/src/collectors/clamp_detect.rs @@ -1,7 +1,4 @@ use perry_hir::{BinaryOp, Expr, Function, Stmt}; -use std::collections::HashSet; - -use super::*; pub fn detect_clamp3(f: &Function) -> Option<(u32, u32, u32)> { if f.is_async || f.is_generator || f.params.len() != 3 { @@ -209,10 +206,8 @@ fn returns_i32_identity_expr(expr: &Expr, param_id: u32) -> bool { pub fn returns_int_stmts(ss: &[Stmt]) -> bool { for s in ss { match s { - Stmt::Return(Some(e)) => { - if !returns_int_expr(e) { - return false; - } + Stmt::Return(Some(e)) if !returns_int_expr(e) => { + return false; } Stmt::If { then_branch, diff --git a/crates/perry-codegen/src/collectors/closures.rs b/crates/perry-codegen/src/collectors/closures.rs index f831d58d55..e062eb0f38 100644 --- a/crates/perry-codegen/src/collectors/closures.rs +++ b/crates/perry-codegen/src/collectors/closures.rs @@ -1,8 +1,5 @@ -use perry_hir::{BinaryOp, Expr, Function, Stmt}; use std::collections::HashSet; -use super::*; - pub fn collect_closures_in_stmts( stmts: &[perry_hir::Stmt], seen: &mut HashSet, diff --git a/crates/perry-codegen/src/collectors/escape_arrays.rs b/crates/perry-codegen/src/collectors/escape_arrays.rs index 5cb90d8a1a..dfaa4825bb 100644 --- a/crates/perry-codegen/src/collectors/escape_arrays.rs +++ b/crates/perry-codegen/src/collectors/escape_arrays.rs @@ -1,4 +1,3 @@ -use perry_hir::{BinaryOp, Expr, Function, Stmt}; use std::collections::{HashMap, HashSet}; use super::*; @@ -174,12 +173,10 @@ pub fn find_array_candidates( id, init: Some(Expr::Array(elements)), .. - } => { - if !boxed_vars.contains(id) && !module_globals.contains_key(id) { - let n = elements.len(); - if (1..=MAX_SCALAR_ARRAY_LEN).contains(&n) { - candidates.insert(*id, n as u32); - } + } if !boxed_vars.contains(id) && !module_globals.contains_key(id) => { + let n = elements.len(); + if (1..=MAX_SCALAR_ARRAY_LEN).contains(&n) { + candidates.insert(*id, n as u32); } } Stmt::If { diff --git a/crates/perry-codegen/src/collectors/escape_check.rs b/crates/perry-codegen/src/collectors/escape_check.rs index f5c559655c..aa665eab5a 100644 --- a/crates/perry-codegen/src/collectors/escape_check.rs +++ b/crates/perry-codegen/src/collectors/escape_check.rs @@ -24,10 +24,8 @@ pub fn find_new_candidates( id, init: Some(Expr::New { class_name, .. }), .. - } => { - if !boxed_vars.contains(id) && !module_globals.contains_key(id) { - candidates.insert(*id, class_name.clone()); - } + } if !boxed_vars.contains(id) && !module_globals.contains_key(id) => { + candidates.insert(*id, class_name.clone()); } Stmt::If { then_branch, diff --git a/crates/perry-codegen/src/collectors/escape_objects.rs b/crates/perry-codegen/src/collectors/escape_objects.rs index c6d20fbfb2..5d71221926 100644 --- a/crates/perry-codegen/src/collectors/escape_objects.rs +++ b/crates/perry-codegen/src/collectors/escape_objects.rs @@ -1,4 +1,3 @@ -use perry_hir::{BinaryOp, Expr, Function, Stmt}; use std::collections::{HashMap, HashSet}; use super::*; diff --git a/crates/perry-codegen/src/collectors/i32_locals.rs b/crates/perry-codegen/src/collectors/i32_locals.rs index eed59c905e..eaecf08eb6 100644 --- a/crates/perry-codegen/src/collectors/i32_locals.rs +++ b/crates/perry-codegen/src/collectors/i32_locals.rs @@ -1,4 +1,3 @@ -use perry_hir::{BinaryOp, Expr, Function, Stmt}; use std::collections::HashSet; use super::*; diff --git a/crates/perry-codegen/src/collectors/i64_emit.rs b/crates/perry-codegen/src/collectors/i64_emit.rs index 5374e3b194..d89598fc33 100644 --- a/crates/perry-codegen/src/collectors/i64_emit.rs +++ b/crates/perry-codegen/src/collectors/i64_emit.rs @@ -1,7 +1,4 @@ use perry_hir::{BinaryOp, Expr, Function, Stmt}; -use std::collections::HashSet; - -use super::*; /// Emit an i64-specialized function directly as LLVM IR text. pub fn emit_i64_function(llmod: &mut crate::module::LlModule, f: &Function, i64_name: &str) { diff --git a/crates/perry-codegen/src/collectors/index_uses.rs b/crates/perry-codegen/src/collectors/index_uses.rs index 5420b08fb2..5a907eee3f 100644 --- a/crates/perry-codegen/src/collectors/index_uses.rs +++ b/crates/perry-codegen/src/collectors/index_uses.rs @@ -1,4 +1,3 @@ -use perry_hir::{BinaryOp, Expr, Function, Stmt}; use std::collections::HashSet; use super::*; diff --git a/crates/perry-codegen/src/collectors/integer_locals.rs b/crates/perry-codegen/src/collectors/integer_locals.rs index 08d601cc15..9d2ba9025a 100644 --- a/crates/perry-codegen/src/collectors/integer_locals.rs +++ b/crates/perry-codegen/src/collectors/integer_locals.rs @@ -348,13 +348,9 @@ fn int32_producing_deps( }; match e { Expr::Integer(_) => true, - Expr::Update { id, .. } => { - if candidates.contains(id) { - deps.insert(*id); - true - } else { - false - } + Expr::Update { id, .. } if candidates.contains(id) => { + deps.insert(*id); + true } Expr::Binary { op, right, .. } if matches!(op, BinaryOp::BitOr | BinaryOp::UShr) @@ -390,13 +386,9 @@ fn int32_producing_deps( | BinaryOp::Shr | BinaryOp::UShr ), - Expr::LocalGet(id) => { - if candidates.contains(id) { - deps.insert(*id); - true - } else { - false - } + Expr::LocalGet(id) if candidates.contains(id) => { + deps.insert(*id); + true } Expr::Uint8ArrayGet { .. } | Expr::BufferIndexGet { .. } => true, Expr::MathImul(_, _) => true, @@ -436,7 +428,7 @@ pub fn collect_extra_integer_let_ids( id, init: Some(init), .. - } => { + } // Same `>>> 0` exclusion as the syntactic seed in // `collect_integer_let_ids`: u32 values can't round-trip // through an i32 slot. @@ -449,10 +441,9 @@ pub fn collect_extra_integer_let_ids( flat_row_alias_ids, clamp_fn_ids, ) - { + => { out.insert(*id); } - } Stmt::If { then_branch, else_branch, diff --git a/crates/perry-codegen/src/collectors/mod.rs b/crates/perry-codegen/src/collectors/mod.rs index c10ca79531..559bc6ec0b 100644 --- a/crates/perry-codegen/src/collectors/mod.rs +++ b/crates/perry-codegen/src/collectors/mod.rs @@ -33,52 +33,21 @@ pub use i64_emit::emit_i64_function; // Internal-to-crate re-exports — explicit names because globs don't // transitively expose through `pub(crate) use crate::collectors::*`. -pub(crate) use clamp_detect::{i64s_expr, i64s_stmts, returns_int_expr, returns_int_stmts}; pub(crate) use class_accessors::{is_class_getter, is_class_setter}; -pub(crate) use closures::{collect_closures_in_expr, collect_closures_in_stmts}; -pub(crate) use escape_arrays::{ - check_array_escapes_in_expr, check_array_escapes_in_stmts, collect_non_escaping_arrays, - const_index, find_array_candidates, MAX_SCALAR_OBJECT_FIELDS, -}; -pub(crate) use escape_check::{check_escapes_in_expr, check_escapes_in_stmts, find_new_candidates}; -pub(crate) use escape_news::{ - collect_non_escaping_new_used_fields, collect_non_escaping_news, MAX_SCALAR_ARRAY_LEN, -}; -pub(crate) use escape_objects::{ - check_object_literal_escapes_in_expr, check_object_literal_escapes_in_stmts, - collect_non_escaping_object_literals, find_object_literal_candidates, -}; -pub(crate) use hir_facts::{ - collect_hir_facts, collect_native_region_fact_graph, collect_type_facts, NativeRegionFactGraph, -}; -pub(crate) use i32_locals::{ - collect_integer_let_ids, collect_localset_ids_in_expr_filtered, collect_localset_ids_in_stmts, - collect_localset_ids_in_stmts_filtered, collect_strictly_i32_bounded_locals, - collect_unsigned_i32_locals, is_bitwise_expr, is_flat_const_indexget, - is_strictly_i32_bounded_expr, is_ushr_zero, walk_writes_for_strict, - walk_writes_in_expr_for_strict, -}; -pub(crate) use i64_emit::{i64_body, i64_cond, i64_val}; -pub(crate) use index_uses::{ - absorb_writes_in_expr, absorb_writes_into_index_used, collect_index_used_locals, - collect_localsets_in_expr_for_propagate, propagate_index_used_transitive, - walk_index_uses_in_expr, walk_index_uses_in_stmts, -}; -pub(crate) use integer_locals::{ - collect_extra_integer_let_ids, collect_flat_row_aliases, collect_integer_locals, - is_int32_producing_expr, -}; +pub(crate) use closures::collect_closures_in_stmts; +pub(crate) use escape_arrays::MAX_SCALAR_OBJECT_FIELDS; +pub(crate) use escape_check::{check_escapes_in_stmts, find_new_candidates}; +pub(crate) use escape_news::MAX_SCALAR_ARRAY_LEN; +pub(crate) use hir_facts::{collect_native_region_fact_graph, NativeRegionFactGraph}; +pub(crate) use i32_locals::{collect_integer_let_ids, collect_localset_ids_in_stmts, is_ushr_zero}; +pub(crate) use integer_locals::{collect_flat_row_aliases, is_int32_producing_expr}; pub(crate) use local_refs::{expr_contains_local_get, mark_all_candidate_refs_in_expr}; -pub(crate) use mutation::{expr_has_mutation, has_any_mutation, is_local_get_chain}; +pub(crate) use mutation::has_any_mutation; pub(crate) use pointer_locals::collect_pointer_typed_locals; pub(crate) use refs::{ collect_let_ids, collect_ref_ids_in_expr, collect_ref_ids_in_stmts, is_clamp_call, }; pub(crate) use shadow_slots::{ - collect_declared_shadow_locals_in_stmt, collect_declared_shadow_slots_in_stmts, - collect_shadow_slot_clear_points, -}; -pub(crate) use this_as_value::{ - class_chain_extends_builtin_error, class_uses_this_as_value, expr_uses_this_as_value, - stmts_use_this_as_value, + collect_declared_shadow_slots_in_stmts, collect_shadow_slot_clear_points, }; +pub(crate) use this_as_value::{class_chain_extends_builtin_error, class_uses_this_as_value}; diff --git a/crates/perry-codegen/src/collectors/mutation.rs b/crates/perry-codegen/src/collectors/mutation.rs index be06fdd7e3..3ea35244ae 100644 --- a/crates/perry-codegen/src/collectors/mutation.rs +++ b/crates/perry-codegen/src/collectors/mutation.rs @@ -1,8 +1,3 @@ -use perry_hir::{BinaryOp, Expr, Function, Stmt}; -use std::collections::HashSet; - -use super::*; - /// (Issue #50) Return `true` if any statement in `stmts` mutates the local /// `id`. A local is "mutated" if: /// - It's the target of a `LocalSet` or `Update` (reassignment), or @@ -21,20 +16,14 @@ pub fn has_any_mutation(stmts: &[perry_hir::Stmt], id: u32) -> bool { use perry_hir::Stmt; for s in stmts { match s { - Stmt::Expr(e) | Stmt::Throw(e) => { - if expr_has_mutation(e, id) { - return true; - } + Stmt::Expr(e) | Stmt::Throw(e) if expr_has_mutation(e, id) => { + return true; } - Stmt::Return(Some(e)) => { - if expr_has_mutation(e, id) { - return true; - } + Stmt::Return(Some(e)) if expr_has_mutation(e, id) => { + return true; } - Stmt::Let { init: Some(e), .. } => { - if expr_has_mutation(e, id) { - return true; - } + Stmt::Let { init: Some(e), .. } if expr_has_mutation(e, id) => { + return true; } Stmt::If { condition, @@ -123,10 +112,10 @@ pub fn has_any_mutation(stmts: &[perry_hir::Stmt], id: u32) -> bool { } } } - Stmt::Labeled { body, .. } => { - if has_any_mutation(std::slice::from_ref(body.as_ref()), id) { - return true; - } + Stmt::Labeled { body, .. } + if has_any_mutation(std::slice::from_ref(body.as_ref()), id) => + { + return true; } _ => {} } diff --git a/crates/perry-codegen/src/collectors/pointer_locals.rs b/crates/perry-codegen/src/collectors/pointer_locals.rs index d0ae33c8ca..7bddff576f 100644 --- a/crates/perry-codegen/src/collectors/pointer_locals.rs +++ b/crates/perry-codegen/src/collectors/pointer_locals.rs @@ -657,12 +657,12 @@ pub fn collect_pointer_typed_locals( for s in stmts { match s { Stmt::Let { id, ty, .. } - if is_ptr_typed(ty) && !non_pointer_locals.contains(id) => + if is_ptr_typed(ty) + && !non_pointer_locals.contains(id) + && !flat_row_alias_ids.contains(id) => { - if !flat_row_alias_ids.contains(id) { - out.insert(*id, *next_slot); - *next_slot += 1; - } + out.insert(*id, *next_slot); + *next_slot += 1; } Stmt::If { then_branch, diff --git a/crates/perry-codegen/src/collectors/refs.rs b/crates/perry-codegen/src/collectors/refs.rs index 023e4ed412..1a7e7f5898 100644 --- a/crates/perry-codegen/src/collectors/refs.rs +++ b/crates/perry-codegen/src/collectors/refs.rs @@ -1,8 +1,6 @@ -use perry_hir::{BinaryOp, Expr, Function, Stmt, WithSetFallback}; +use perry_hir::WithSetFallback; use std::collections::HashSet; -use super::*; - pub fn collect_let_ids(stmts: &[perry_hir::Stmt], out: &mut HashSet) { for s in stmts { match s { diff --git a/crates/perry-codegen/src/collectors/shadow_slots.rs b/crates/perry-codegen/src/collectors/shadow_slots.rs index e4560703e1..8344566d9c 100644 --- a/crates/perry-codegen/src/collectors/shadow_slots.rs +++ b/crates/perry-codegen/src/collectors/shadow_slots.rs @@ -1,8 +1,3 @@ -use perry_hir::{BinaryOp, Expr, Function, Stmt}; -use std::collections::HashSet; - -use super::*; - pub fn collect_shadow_slot_clear_points( stmts: &[perry_hir::Stmt], shadow_slot_map: &std::collections::HashMap, diff --git a/crates/perry-codegen/src/expr/array_methods.rs b/crates/perry-codegen/src/expr/array_methods.rs index cf555ed7d3..ab6ee94ec8 100644 --- a/crates/perry-codegen/src/expr/array_methods.rs +++ b/crates/perry-codegen/src/expr/array_methods.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/arrays_finds.rs b/crates/perry-codegen/src/expr/arrays_finds.rs index a969c331db..f882db80eb 100644 --- a/crates/perry-codegen/src/expr/arrays_finds.rs +++ b/crates/perry-codegen/src/expr/arrays_finds.rs @@ -533,9 +533,9 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result { // was kept as a reference; it was unreachable code after the // early return above. Removed — the comment block immediately // above this arm documents why the runtime call is required. - return Ok(ctx + Ok(ctx .block() - .call(DOUBLE, "js_number_is_nan", &[(DOUBLE, &v)])); + .call(DOUBLE, "js_number_is_nan", &[(DOUBLE, &v)])) } Expr::FsMkdirSync(p) => { // Phase H fs: call js_fs_mkdir_sync. Node's fs.mkdirSync diff --git a/crates/perry-codegen/src/expr/bigint_set.rs b/crates/perry-codegen/src/expr/bigint_set.rs index 20696bd121..13460ded1b 100644 --- a/crates/perry-codegen/src/expr/bigint_set.rs +++ b/crates/perry-codegen/src/expr/bigint_set.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, Result}; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/binary.rs b/crates/perry-codegen/src/expr/binary.rs index d44284df3b..0f39cf9f80 100644 --- a/crates/perry-codegen/src/expr/binary.rs +++ b/crates/perry-codegen/src/expr/binary.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/buffer_access.rs b/crates/perry-codegen/src/expr/buffer_access.rs index 07204d349a..6bb61219b9 100644 --- a/crates/perry-codegen/src/expr/buffer_access.rs +++ b/crates/perry-codegen/src/expr/buffer_access.rs @@ -369,7 +369,7 @@ fn record_buffer_view( &buffer_value, Some(proof.bounds.clone()), Some(proof.alias.clone()), - Some(proof.access_mode.clone()), + Some(proof.access_mode), None, None, Some(facts), @@ -406,7 +406,7 @@ pub(crate) fn lower_buffer_load( &u8_value, Some(proof.bounds.clone()), Some(proof.alias.clone()), - Some(proof.access_mode.clone()), + Some(proof.access_mode), None, None, Some(facts), @@ -425,7 +425,7 @@ pub(crate) fn lower_buffer_load( &result, Some(proof.bounds.clone()), Some(proof.alias.clone()), - Some(proof.access_mode.clone()), + Some(proof.access_mode), None, None, Some(facts), @@ -465,7 +465,7 @@ pub(crate) fn lower_buffer_store( &stored, Some(proof.bounds.clone()), Some(proof.alias.clone()), - Some(proof.access_mode.clone()), + Some(proof.access_mode), None, None, Some(facts), @@ -595,7 +595,7 @@ pub(crate) fn lower_typed_array_load( &result, Some(proof.bounds.clone()), Some(proof.alias.clone()), - Some(proof.access_mode.clone()), + Some(proof.access_mode), None, None, Some(facts), @@ -718,7 +718,7 @@ pub(crate) fn lower_typed_array_store( &stored, Some(proof.bounds.clone()), Some(proof.alias.clone()), - Some(proof.access_mode.clone()), + Some(proof.access_mode), None, None, Some(facts), diff --git a/crates/perry-codegen/src/expr/call_spread.rs b/crates/perry-codegen/src/expr/call_spread.rs index a58ceb58bc..f4f765b5e9 100644 --- a/crates/perry-codegen/src/expr/call_spread.rs +++ b/crates/perry-codegen/src/expr/call_spread.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/calls.rs b/crates/perry-codegen/src/expr/calls.rs index 147d110755..8d71870d2b 100644 --- a/crates/perry-codegen/src/expr/calls.rs +++ b/crates/perry-codegen/src/expr/calls.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] @@ -315,8 +315,8 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result { // crypto workload) needs the Buffer path — it XORs, hashes, and // base64-encodes raw bytes. Route to _bytes FFI variants when no // encoding was specified. - let want_buffer = digest_args.first().is_none() - || matches!(digest_args.first(), Some(Expr::Undefined)); + let want_buffer = + digest_args.is_empty() || matches!(digest_args.first(), Some(Expr::Undefined)); // The inline `js_crypto_sha256` / `js_crypto_md5` fast path only // produces a hex string (or, for the no-arg form, a raw-byte diff --git a/crates/perry-codegen/src/expr/child_proc.rs b/crates/perry-codegen/src/expr/child_proc.rs index 06e71970cd..2df3169b2d 100644 --- a/crates/perry-codegen/src/expr/child_proc.rs +++ b/crates/perry-codegen/src/expr/child_proc.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/closure.rs b/crates/perry-codegen/src/expr/closure.rs index 8f644b2caf..54a75a5d28 100644 --- a/crates/perry-codegen/src/expr/closure.rs +++ b/crates/perry-codegen/src/expr/closure.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, Result}; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/compare.rs b/crates/perry-codegen/src/expr/compare.rs index 7fafb7d1a7..d550d814d4 100644 --- a/crates/perry-codegen/src/expr/compare.rs +++ b/crates/perry-codegen/src/expr/compare.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/conditional.rs b/crates/perry-codegen/src/expr/conditional.rs index 5849d41449..affeb5e1ce 100644 --- a/crates/perry-codegen/src/expr/conditional.rs +++ b/crates/perry-codegen/src/expr/conditional.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/dyn_extern_i18n.rs b/crates/perry-codegen/src/expr/dyn_extern_i18n.rs index 685d3e202a..f3b7ebb143 100644 --- a/crates/perry-codegen/src/expr/dyn_extern_i18n.rs +++ b/crates/perry-codegen/src/expr/dyn_extern_i18n.rs @@ -227,9 +227,9 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result { &[ (PTR, &msg_bytes_global), (I64, &msg_len_str), - (PTR, &"null".to_string()), - (I64, &"0".to_string()), - (I32, &"0".to_string()), + (PTR, "null"), + (I64, "0"), + (I32, "0"), ], ); blk.unreachable(); diff --git a/crates/perry-codegen/src/expr/env_clones.rs b/crates/perry-codegen/src/expr/env_clones.rs index 36eb1460ce..79621a62c5 100644 --- a/crates/perry-codegen/src/expr/env_clones.rs +++ b/crates/perry-codegen/src/expr/env_clones.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::{bail, Result}; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/fs_await.rs b/crates/perry-codegen/src/expr/fs_await.rs index 3d1b83af08..b09a8c3322 100644 --- a/crates/perry-codegen/src/expr/fs_await.rs +++ b/crates/perry-codegen/src/expr/fs_await.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/index_get.rs b/crates/perry-codegen/src/expr/index_get.rs index 782374c06a..69f17aab34 100644 --- a/crates/perry-codegen/src/expr/index_get.rs +++ b/crates/perry-codegen/src/expr/index_get.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/index_set.rs b/crates/perry-codegen/src/expr/index_set.rs index 4aebefb1e1..2778422b17 100644 --- a/crates/perry-codegen/src/expr/index_set.rs +++ b/crates/perry-codegen/src/expr/index_set.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/instance_misc1.rs b/crates/perry-codegen/src/expr/instance_misc1.rs index 9bd2d5e466..d654bcdd13 100644 --- a/crates/perry-codegen/src/expr/instance_misc1.rs +++ b/crates/perry-codegen/src/expr/instance_misc1.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, Result}; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp, WithSetFallback}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/js_runtime.rs b/crates/perry-codegen/src/expr/js_runtime.rs index 6a4172a037..cceaf82342 100644 --- a/crates/perry-codegen/src/expr/js_runtime.rs +++ b/crates/perry-codegen/src/expr/js_runtime.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/literals_vars.rs b/crates/perry-codegen/src/expr/literals_vars.rs index ee477133f2..8b70f243e5 100644 --- a/crates/perry-codegen/src/expr/literals_vars.rs +++ b/crates/perry-codegen/src/expr/literals_vars.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, Result}; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/logical_collections.rs b/crates/perry-codegen/src/expr/logical_collections.rs index 006cf5d849..0b4b436ab3 100644 --- a/crates/perry-codegen/src/expr/logical_collections.rs +++ b/crates/perry-codegen/src/expr/logical_collections.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::{bail, Result}; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/math_simple.rs b/crates/perry-codegen/src/expr/math_simple.rs index 5ba472cfa5..4160e6c318 100644 --- a/crates/perry-codegen/src/expr/math_simple.rs +++ b/crates/perry-codegen/src/expr/math_simple.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/misc_methods.rs b/crates/perry-codegen/src/expr/misc_methods.rs index 4f4af4868d..28688181db 100644 --- a/crates/perry-codegen/src/expr/misc_methods.rs +++ b/crates/perry-codegen/src/expr/misc_methods.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/mod.rs b/crates/perry-codegen/src/expr/mod.rs index ae39025323..9223e5bdb8 100644 --- a/crates/perry-codegen/src/expr/mod.rs +++ b/crates/perry-codegen/src/expr/mod.rs @@ -8,34 +8,23 @@ //! error so a user running `--backend llvm` on richer TypeScript gets a //! one-line explanation instead of a silent broken binary. -use anyhow::{anyhow, bail, Result}; -use perry_hir::{BinaryOp, Expr, UnaryOp}; +use anyhow::{bail, Result}; +use perry_hir::{BinaryOp, Expr}; use perry_types::Type as HirType; use crate::block::LlBlock; use crate::codegen::AppMetadata; use crate::collectors::NativeRegionFactGraph; use crate::function::LlFunction; -use crate::lower_call::{lower_call, lower_native_method_call, lower_new}; -use crate::lower_conditional::{lower_conditional, lower_logical, lower_truthy}; -use crate::lower_string_method::{ - flatten_string_add_chain, lower_string_coerce_concat, lower_string_concat, - lower_string_concat_chain, lower_string_self_append, -}; -use crate::nanbox::{double_literal, POINTER_MASK_I64}; use crate::native_value::{ AliasState, BoundedBufferIndex, BoundsProof, BoundsState, BufferAccessFacts, BufferAccessMode, - BufferElem, BufferIndexUnit, BufferViewRep, BufferViewSlot, ExpectedNativeRep, - GuardedBufferIndex, LengthSource, LoweredValue, MaterializationReason, NativeAbiTypeRecord, - NativeFactUse, NativeOwnedViewFact, NativeRep, NativeRepRecord, NativeValueState, - PodLayoutManifest, PodRecordViewManifest, ScalarConversionRecord, SemanticKind, + BufferViewSlot, GuardedBufferIndex, LoweredValue, MaterializationReason, NativeAbiTypeRecord, + NativeFactUse, NativeRep, NativeRepRecord, NativeValueState, PodLayoutManifest, + PodRecordViewManifest, ScalarConversionRecord, }; use crate::strings::StringPool; -use crate::type_analysis::{ - compute_auto_captures, is_array_expr, is_bigint_expr, is_bool_expr, is_map_expr, - is_numeric_expr, is_set_expr, is_string_expr, is_url_search_params_expr, receiver_class_name, -}; -use crate::types::{DOUBLE, I1, I32, I64, I8, PTR}; +use crate::type_analysis::is_numeric_expr; +use crate::types::{DOUBLE, I32, I64, PTR}; // Issue #1098: expr.rs split into expr/ submodules. These are pure // mechanical moves of self-contained helper clusters out of this file; @@ -68,13 +57,12 @@ pub(crate) use array_literal::lower_array_literal; pub(crate) use buffer_access::{ access_facts_for_spec, emit_buffer_access_pointer, lower_buffer_access_proof, lower_buffer_load, lower_buffer_store, lower_typed_array_load, lower_typed_array_store, - BufferAccessEmission, BufferAccessSpec, StoreResult, + BufferAccessSpec, }; pub(crate) use buffer_views::{ alias_buffer_view_slot, attach_native_owned_view_fact, buffer_access_materialization_reason, buffer_view_lowered_value, downgrade_buffer_alias, downgrade_buffer_aliases_in_expr, - invalidate_native_owned_views_for_dispose, invalidate_native_owned_views_for_owner, - native_arena_canonical_owner_id, native_owned_fact_for_view, + invalidate_native_owned_views_for_dispose, native_arena_canonical_owner_id, record_native_arena_owner_assignment, update_buffer_view_for_assignment, }; #[allow(unused_imports)] // ChannelReduction kept reachable for surface stability @@ -86,8 +74,8 @@ pub(crate) use helpers::{ array_store_needs_layout_note, array_store_needs_write_barrier, buffer_alias_metadata_suffix, expr_has_numeric_pointer_free_array_layout, expr_produces_non_pointer_bits_by_construction, is_global_this_builtin_function_name, is_global_this_builtin_name, - lower_expr_with_expected_type, lower_js_args_array, proxy_build_args_array, - type_has_numeric_pointer_free_array_layout, unbox_str_handle, unbox_to_i64, + lower_expr_with_expected_type, lower_js_args_array, proxy_build_args_array, unbox_str_handle, + unbox_to_i64, }; pub(crate) use i32_fast_path::{ can_lower_expr_as_i32, is_known_finite, lower_expr_as_i32, lower_expr_native, @@ -105,15 +93,14 @@ pub(crate) use pod_record::{ try_lower_pod_field_get, try_lower_pod_field_set, }; pub(crate) use range_facts::{ - bounds_for_buffer_access, bounds_for_buffer_access_width, effective_alias_state_for_access, + bounds_for_buffer_access_width, effective_alias_state_for_access, guarded_buffer_indices_for_condition, int_range_expr, invalidate_local_write_facts, record_int_facts_for_let, record_int_facts_for_local_set, record_int_facts_for_update, while_condition_range_fact, IntRange, IntRangeFact, }; pub(crate) use strings::emit_string_literal_global; pub(crate) use typed_feedback::{ - emit_typed_feedback_observe_helper_return, emit_typed_feedback_register_site, - native_region_slug, TypedFeedbackContract, TypedFeedbackKind, + emit_typed_feedback_register_site, native_region_slug, TypedFeedbackContract, TypedFeedbackKind, }; pub(crate) use url_helpers::lower_url_string_getter; pub(crate) use v8_interop::{ diff --git a/crates/perry-codegen/src/expr/new_dynamic.rs b/crates/perry-codegen/src/expr/new_dynamic.rs index 63cc59e0f3..37e8af4a43 100644 --- a/crates/perry-codegen/src/expr/new_dynamic.rs +++ b/crates/perry-codegen/src/expr/new_dynamic.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/objects_arrays_lit.rs b/crates/perry-codegen/src/expr/objects_arrays_lit.rs index 06e16fdad2..00c5dcec97 100644 --- a/crates/perry-codegen/src/expr/objects_arrays_lit.rs +++ b/crates/perry-codegen/src/expr/objects_arrays_lit.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/os_uri_dates.rs b/crates/perry-codegen/src/expr/os_uri_dates.rs index 61b372aadc..6f7ea662ce 100644 --- a/crates/perry-codegen/src/expr/os_uri_dates.rs +++ b/crates/perry-codegen/src/expr/os_uri_dates.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/property_get.rs b/crates/perry-codegen/src/expr/property_get.rs index 47c7a0f822..0c2e9ac5ba 100644 --- a/crates/perry-codegen/src/expr/property_get.rs +++ b/crates/perry-codegen/src/expr/property_get.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] @@ -328,11 +328,11 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result { false, Vec::new(), ); - return Ok(crate::native_value::materialize_js_value( + Ok(crate::native_value::materialize_js_value( ctx, lowered, MaterializationReason::FunctionAbi, - )); + )) } // `arr.length` / `str.length` — INLINE. Both ArrayHeader and diff --git a/crates/perry-codegen/src/expr/property_set.rs b/crates/perry-codegen/src/expr/property_set.rs index 14d2739884..d04b6320f7 100644 --- a/crates/perry-codegen/src/expr/property_set.rs +++ b/crates/perry-codegen/src/expr/property_set.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/proxy_reflect.rs b/crates/perry-codegen/src/expr/proxy_reflect.rs index 1ef74c3b95..12ea570dfe 100644 --- a/crates/perry-codegen/src/expr/proxy_reflect.rs +++ b/crates/perry-codegen/src/expr/proxy_reflect.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/static_field_meta.rs b/crates/perry-codegen/src/expr/static_field_meta.rs index 3111573bd8..02e6c29b09 100644 --- a/crates/perry-codegen/src/expr/static_field_meta.rs +++ b/crates/perry-codegen/src/expr/static_field_meta.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/static_method.rs b/crates/perry-codegen/src/expr/static_method.rs index 8a3acd219a..ce0c1fa464 100644 --- a/crates/perry-codegen/src/expr/static_method.rs +++ b/crates/perry-codegen/src/expr/static_method.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::{bail, Result}; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] @@ -283,7 +283,7 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result { lowered.push(lower_expr(ctx, a)?); } let arg_kinds: Vec = - std::iter::repeat(DOUBLE).take(args.len()).collect(); + std::iter::repeat_n(DOUBLE, args.len()).collect(); ctx.pending_declares .push((fn_name.clone(), DOUBLE, arg_kinds)); let arg_slices: Vec<(crate::types::LlvmType, &str)> = diff --git a/crates/perry-codegen/src/expr/string_regex_proc.rs b/crates/perry-codegen/src/expr/string_regex_proc.rs index e21a2f287f..ff83d36e1e 100644 --- a/crates/perry-codegen/src/expr/string_regex_proc.rs +++ b/crates/perry-codegen/src/expr/string_regex_proc.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/super_method.rs b/crates/perry-codegen/src/expr/super_method.rs index b634d39f34..570f87b561 100644 --- a/crates/perry-codegen/src/expr/super_method.rs +++ b/crates/perry-codegen/src/expr/super_method.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, Result}; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/this_super_call.rs b/crates/perry-codegen/src/expr/this_super_call.rs index 118a42510e..d16db80888 100644 --- a/crates/perry-codegen/src/expr/this_super_call.rs +++ b/crates/perry-codegen/src/expr/this_super_call.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] @@ -187,7 +187,7 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result { ¤t_class_name, crate::lower_call::FieldInitMode::SelfOnly, )?; - return Ok(double_literal(f64::from_bits(crate::nanbox::TAG_UNDEFINED))); + Ok(double_literal(f64::from_bits(crate::nanbox::TAG_UNDEFINED))) } // parent is `current_class.extends_name` (Perry uses the string // form for cross-module/late-resolved cases) or diff --git a/crates/perry-codegen/src/expr/unary.rs b/crates/perry-codegen/src/expr/unary.rs index 2316e1af65..93be0ee6df 100644 --- a/crates/perry-codegen/src/expr/unary.rs +++ b/crates/perry-codegen/src/expr/unary.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/url_main.rs b/crates/perry-codegen/src/expr/url_main.rs index 98283deeff..df3ad8287f 100644 --- a/crates/perry-codegen/src/expr/url_main.rs +++ b/crates/perry-codegen/src/expr/url_main.rs @@ -4,7 +4,7 @@ //! Pure mechanical move — match arm bodies are verbatim copies, called from //! `lower_expr`'s outer dispatch. -use anyhow::{anyhow, bail, Result}; +use anyhow::Result; #[allow(unused_imports)] use perry_hir::{BinaryOp, CompareOp, Expr, UnaryOp, UpdateOp}; #[allow(unused_imports)] diff --git a/crates/perry-codegen/src/expr/v8_interop.rs b/crates/perry-codegen/src/expr/v8_interop.rs index c130195839..3e5134b42c 100644 --- a/crates/perry-codegen/src/expr/v8_interop.rs +++ b/crates/perry-codegen/src/expr/v8_interop.rs @@ -60,8 +60,8 @@ pub(crate) fn emit_v8_export_call( lit.push_str("\\00\""); lit }; - let spec_bytes = specifier.as_bytes().len(); - let name_bytes = export_name.as_bytes().len(); + let spec_bytes = specifier.len(); + let name_bytes = export_name.len(); ctx.typed_parse_rodata.push(format!( "@{} = private unnamed_addr constant [{} x i8] {}", spec_global, @@ -157,9 +157,9 @@ pub(crate) fn emit_v8_member_method_call( lit.push_str("\\00\""); lit }; - let spec_bytes = specifier.as_bytes().len(); - let member_bytes = member.as_bytes().len(); - let method_bytes = method.as_bytes().len(); + let spec_bytes = specifier.len(); + let member_bytes = member.len(); + let method_bytes = method.len(); ctx.typed_parse_rodata.push(format!( "@{} = private unnamed_addr constant [{} x i8] {}", spec_global, diff --git a/crates/perry-codegen/src/lower_call/builtin.rs b/crates/perry-codegen/src/lower_call/builtin.rs index 33765c6fb9..dac933676d 100644 --- a/crates/perry-codegen/src/lower_call/builtin.rs +++ b/crates/perry-codegen/src/lower_call/builtin.rs @@ -18,7 +18,7 @@ use perry_hir::Expr; use crate::expr::{lower_array_literal, lower_expr, nanbox_pointer_inline, unbox_to_i64, FnCtx}; use crate::nanbox::double_literal; -use crate::types::{DOUBLE, I32, I64, PTR}; +use crate::types::{DOUBLE, I32, I64}; use super::{build_headers_from_object, extract_options_fields, get_raw_string_ptr}; @@ -1309,7 +1309,7 @@ pub(super) fn lower_builtin_new( let mut start = double_literal(f64::from_bits(crate::nanbox::TAG_UNDEFINED)); let mut transform = double_literal(f64::from_bits(crate::nanbox::TAG_UNDEFINED)); let mut flush = double_literal(f64::from_bits(crate::nanbox::TAG_UNDEFINED)); - let mut hwm = double_literal(1.0); + let hwm = double_literal(1.0); let mut transformer_object = None; if !args.is_empty() { if let Some(props) = extract_options_fields(ctx, &args[0]) { diff --git a/crates/perry-codegen/src/lower_call/closure_analysis.rs b/crates/perry-codegen/src/lower_call/closure_analysis.rs index 04b57e33f6..5096a8ccc3 100644 --- a/crates/perry-codegen/src/lower_call/closure_analysis.rs +++ b/crates/perry-codegen/src/lower_call/closure_analysis.rs @@ -198,10 +198,8 @@ fn find_outer_writes_expr( } find_outer_writes_expr(val, inner_ids, out); } - Expr::Update { id, .. } => { - if !inner_ids.contains(id) { - out.push(*id); - } + Expr::Update { id, .. } if !inner_ids.contains(id) => { + out.push(*id); } Expr::Closure { .. } => { // Stop at nested closure boundary — it has its own scope and diff --git a/crates/perry-codegen/src/lower_call/extern_func.rs b/crates/perry-codegen/src/lower_call/extern_func.rs index 7d9c67f8a7..105c365f64 100644 --- a/crates/perry-codegen/src/lower_call/extern_func.rs +++ b/crates/perry-codegen/src/lower_call/extern_func.rs @@ -1378,7 +1378,7 @@ pub fn try_lower_extern_func_call( let closure_handle = blk.and(I64, &closure_bits, POINTER_MASK_I64); let call_name = format!("js_closure_call{}", lowered_args.len().min(16)); let mut decl_types = vec![I64]; - decl_types.extend(std::iter::repeat(DOUBLE).take(lowered_args.len().min(16))); + decl_types.extend(std::iter::repeat_n(DOUBLE, lowered_args.len().min(16))); ctx.pending_declares .push((call_name.clone(), DOUBLE, decl_types)); let mut call_args: Vec<(crate::types::LlvmType, String)> = vec![(I64, closure_handle)]; diff --git a/crates/perry-codegen/src/lower_call/namespace_call.rs b/crates/perry-codegen/src/lower_call/namespace_call.rs index 6fb209b015..fa6ba65870 100644 --- a/crates/perry-codegen/src/lower_call/namespace_call.rs +++ b/crates/perry-codegen/src/lower_call/namespace_call.rs @@ -321,7 +321,7 @@ pub fn try_lower_namespace_member_call( } } let arg_types: Vec = - std::iter::repeat(DOUBLE).take(lowered.len()).collect(); + std::iter::repeat_n(DOUBLE, lowered.len()).collect(); ctx.pending_declares .push((symbol.clone(), DOUBLE, arg_types)); let arg_slices: Vec<(crate::types::LlvmType, &str)> = diff --git a/crates/perry-codegen/src/lower_call/property_get.rs b/crates/perry-codegen/src/lower_call/property_get.rs index 8561007e62..67c9c6b8f8 100644 --- a/crates/perry-codegen/src/lower_call/property_get.rs +++ b/crates/perry-codegen/src/lower_call/property_get.rs @@ -483,8 +483,8 @@ pub fn try_lower_property_get_method_call( // `.catch(cb)` is sugar for `.then(undefined, cb)`. if matches!(property.as_str(), "then" | "catch" | "finally") && is_promise_expr(ctx, object) { match property.as_str() { - "then" => { - if !args.is_empty() { + "then" + if !args.is_empty() => { // Fused fast path: detect `Promise.resolve().then(cb_f, cb_e?)` // and route to `js_promise_resolved_then`, which skips // the intermediate Promise-#1 allocation when `` @@ -578,9 +578,8 @@ pub fn try_lower_property_get_method_call( ); return Ok(Some(nanbox_pointer_inline(blk, &new_promise))); } - } - "catch" => { - if !args.is_empty() { + "catch" + if !args.is_empty() => { let promise_box = lower_expr(ctx, object)?; let on_rejected_box = lower_expr(ctx, &args[0])?; let blk = ctx.block(); @@ -598,14 +597,13 @@ pub fn try_lower_property_get_method_call( ); return Ok(Some(nanbox_pointer_inline(blk, &new_promise))); } - } - "finally" => { + "finally" // .finally(cb) — per spec: call cb() ignoring its return value, // then propagate the upstream value/reason unchanged. // Routes through js_promise_finally which wraps cb in // fulfill/reject proxy closures that call cb() and then // return the upstream value (or re-throw the upstream reason). - if !args.is_empty() { + if !args.is_empty() => { let promise_box = lower_expr(ctx, object)?; let on_finally_box = lower_expr(ctx, &args[0])?; let blk = ctx.block(); @@ -618,7 +616,6 @@ pub fn try_lower_property_get_method_call( ); return Ok(Some(nanbox_pointer_inline(blk, &new_promise))); } - } _ => {} } } @@ -1091,7 +1088,7 @@ pub fn try_lower_property_get_method_call( &ctx.local_id_to_name, &ctx.local_class_aliases, ctx.func_returns_class, - &ctx.class_ids, + ctx.class_ids, ); if let Some(cls_name) = static_dispatch_cls { // `C.prop(args)` where `prop` is a static ACCESSOR reads the accessor and diff --git a/crates/perry-codegen/src/native_value/mod.rs b/crates/perry-codegen/src/native_value/mod.rs index 5a7755813d..0a8694b2a9 100644 --- a/crates/perry-codegen/src/native_value/mod.rs +++ b/crates/perry-codegen/src/native_value/mod.rs @@ -12,7 +12,7 @@ pub(crate) use artifact::{ }; pub(crate) use buffer::{ AliasState, BoundedBufferIndex, BoundsProof, BoundsState, BufferAccessFacts, BufferAccessMode, - BufferAccessProof, BufferElem, BufferEndian, BufferIndexUnit, BufferViewRep, BufferViewSlot, + BufferAccessProof, BufferElem, BufferEndian, BufferIndexUnit, BufferViewSlot, GuardedBufferIndex, LengthSource, NativeOwnedViewFact, NativeOwnedViewSlot, }; pub(crate) use materialize::{ @@ -27,3 +27,8 @@ pub(crate) use pod::{ }; pub(crate) use rep::{ExpectedNativeRep, LoweredValue, NativeRep, SemanticKind}; pub(crate) use verify::verify_native_rep_records; +// Re-exported for the `verify` test module, which constructs `NativeRep::BufferView` +// records via the `crate::native_value::BufferViewRep` path. Non-test code reaches the +// type through `super::buffer::BufferViewRep` directly, so gate this to the test build. +#[cfg(test)] +pub(crate) use buffer::BufferViewRep; diff --git a/crates/perry-codegen/src/stmt/let_stmt.rs b/crates/perry-codegen/src/stmt/let_stmt.rs index cdecdbfd8f..c8f6c0454d 100644 --- a/crates/perry-codegen/src/stmt/let_stmt.rs +++ b/crates/perry-codegen/src/stmt/let_stmt.rs @@ -26,7 +26,7 @@ fn is_object_literal_init(init: &perry_hir::Expr) -> bool { && matches!( callee.as_ref(), Expr::Closure { params, .. } - if params.first().map_or(false, |p| p.name == "__perry_obj_iife") + if params.first().is_some_and(|p| p.name == "__perry_obj_iife") ) } _ => false, diff --git a/crates/perry-codegen/src/type_analysis.rs b/crates/perry-codegen/src/type_analysis.rs index 7099000697..d9518c6430 100644 --- a/crates/perry-codegen/src/type_analysis.rs +++ b/crates/perry-codegen/src/type_analysis.rs @@ -1064,10 +1064,10 @@ pub(crate) fn scalar_replaced_array_element_is_raw_f64( let Some(k) = constant_array_index(index) else { return false; }; - if !ctx + if ctx .scalar_replaced_arrays .get(id) - .is_some_and(|slots| k < slots.len()) + .is_none_or(|slots| k >= slots.len()) { return false; } @@ -1464,7 +1464,7 @@ pub(crate) fn is_definitely_string_expr(ctx: &FnCtx<'_>, e: &Expr) -> bool { args, } => args .first() - .map_or(false, |arg| is_definitely_string_expr(ctx, arg)), + .is_some_and(|arg| is_definitely_string_expr(ctx, arg)), Expr::StringCoerce(_) | Expr::TypeOf(_) | Expr::ArrayJoin { .. } @@ -1617,7 +1617,7 @@ pub(crate) fn is_string_expr(ctx: &FnCtx<'_>, e: &Expr) -> bool { args, } => args .first() - .map_or(false, |arg| is_definitely_string_expr(ctx, arg)), + .is_some_and(|arg| is_definitely_string_expr(ctx, arg)), // String coerce, JSON.stringify, ArrayJoin, etc. all return // strings. Expr::StringCoerce(_) @@ -2299,7 +2299,7 @@ pub(crate) fn static_type_of(ctx: &FnCtx<'_>, e: &Expr) -> Option { // local) lets `...digest().toString('hex')` / `...digest()[i]` take // the buffer dispatch instead of the Latin-1 string path (#1353). Expr::Call { callee, args, .. } - if args.first().map_or(true, |a| matches!(a, Expr::Undefined)) + if args.first().is_none_or(|a| matches!(a, Expr::Undefined)) && is_crypto_digest_chain(callee) => { Some(HirType::Named("Uint8Array".into()))