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
10 changes: 4 additions & 6 deletions crates/perry-codegen-arkts/src/emit_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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')",
Expand Down Expand Up @@ -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(),
}
}
5 changes: 2 additions & 3 deletions crates/perry-codegen-arkts/src/widgets/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion crates/perry-codegen-js/src/emit/exprs_more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions crates/perry-codegen-wasm/src/emit/locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/perry-codegen/src/codegen/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions crates/perry-codegen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1663,15 +1663,15 @@ pub fn compile_module(hir: &HirModule, opts: CompileOptions) -> Result<Vec<u8>>
// 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;
}
Expand Down
9 changes: 2 additions & 7 deletions crates/perry-codegen/src/codegen/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/perry-codegen/src/codegen/string_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions crates/perry-codegen/src/collectors/clamp_detect.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions crates/perry-codegen/src/collectors/closures.rs
Original file line number Diff line number Diff line change
@@ -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<perry_types::FuncId>,
Expand Down
11 changes: 4 additions & 7 deletions crates/perry-codegen/src/collectors/escape_arrays.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use perry_hir::{BinaryOp, Expr, Function, Stmt};
use std::collections::{HashMap, HashSet};

use super::*;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions crates/perry-codegen/src/collectors/escape_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion crates/perry-codegen/src/collectors/escape_objects.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use perry_hir::{BinaryOp, Expr, Function, Stmt};
use std::collections::{HashMap, HashSet};

use super::*;
Expand Down
1 change: 0 additions & 1 deletion crates/perry-codegen/src/collectors/i32_locals.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use perry_hir::{BinaryOp, Expr, Function, Stmt};
use std::collections::HashSet;

use super::*;
Expand Down
3 changes: 0 additions & 3 deletions crates/perry-codegen/src/collectors/i64_emit.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
1 change: 0 additions & 1 deletion crates/perry-codegen/src/collectors/index_uses.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use perry_hir::{BinaryOp, Expr, Function, Stmt};
use std::collections::HashSet;

use super::*;
Expand Down
25 changes: 8 additions & 17 deletions crates/perry-codegen/src/collectors/integer_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down
51 changes: 10 additions & 41 deletions crates/perry-codegen/src/collectors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
31 changes: 10 additions & 21 deletions crates/perry-codegen/src/collectors/mutation.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
_ => {}
}
Expand Down
Loading
Loading