You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
crates/perry-codegen-wasm/src/emit.rs is 9,988 lines with only 12 top-level functions — because almost everything is methods on the WasmModuleEmitter struct (one giant impl block starting at line 616).
Move emit.rs to crates/perry-codegen-wasm/src/emit/:
emit/mod.rs — compile_to_wasm, compile_to_wasm_with_async, WasmModuleEmitter::new, intern_string, get_type_idx, compile, the core type/field/function-index machinery (~533–2175), plus the small free-functions f64_const, f64_const_bits, map_ui_method
WASM codegen issues are tracked in #1081 right now. Hold this refactor until the active stack-balance bug is resolved or coordinate with whoever is currently in this file — don't rebase a 10k-line move on top of in-flight fixes.
Acceptance
Same conventions as #1097. Plus: smoke-test by compiling at least one TypeScript program to --backend wasm before and after.
Part of #1097.
Current state
crates/perry-codegen-wasm/src/emit.rsis 9,988 lines with only 12 top-level functions — because almost everything is methods on theWasmModuleEmitterstruct (one giantimplblock starting at line 616).The two methods that dominate the file are:
emit_stmt— lines 4547 → 4956 (~410 lines — manageable)emit_expr— lines 4956 → 9544 (~4.6k)emit_js_stmt— lines 2413 → 2579 (handles JS-fallback emission, used when WASM can't represent something)emit_js_expr— lines 2579 → 3035 (the JS-fallback expression emitter)collect_strings+collect_strings_in_stmts+collect_strings_in_stmt+collect_strings_in_expr— 3035 → 3993 (~1k)emit_method_call— 4203 → 4529Proposed split
Move
emit.rstocrates/perry-codegen-wasm/src/emit/:emit/mod.rs—compile_to_wasm,compile_to_wasm_with_async,WasmModuleEmitter::new,intern_string,get_type_idx,compile, the core type/field/function-index machinery (~533–2175), plus the small free-functionsf64_const,f64_const_bits,map_ui_methodemit/function.rs—compile_function,compile_closure,compile_class_constructor,compile_class_method,emit_frame_begin,emit_slot_addr,emit_store_arg,emit_store_const,emit_local_or_global_get(~2175–2378, ~4023–4114)emit/string_collection.rs—collect_strings,collect_strings_in_stmts,collect_strings_in_stmt,collect_strings_in_expr(~3035–3993)emit/memcall.rs—emit_memcall,emit_memcall_void,emit_memcall_i32,RuntimeImports::rtaccess helper (~4114–4203)emit/method_call.rs—emit_method_call(~4203–4529)emit/binary.rs—emit_bitwise_binaryemit/stmt.rs—emit_stmt,has_return,expr_has_value(~4547–4956, ~9544+, ~9956+)emit/expr.rs—emit_expr— the 4.6k beast. Once isolated, the natural sub-split is byExpr::*variant the same way chore(codegen): split crates/perry-codegen/src/lower_call.rs (11.8k lines, lower_call + extract_options_fields) #1099 splits the LLVMexpr.rs— but suggest landing the file move first and the within-emit_exprsplit as a follow-up so reviewers can stage the work.emit/js_fallback.rs—emit_js_async_function,emit_js_stmt,emit_js_expr(~2378–3035)emit/closures.rs—collect_closures_from_stmts,collect_closures_from_expr(~9699–9956)emit/locals.rs—collect_locals,collect_module_let_ids,resolve_source_module_idx(~9578–9699)Hot path caveat
WASM codegen issues are tracked in #1081 right now. Hold this refactor until the active stack-balance bug is resolved or coordinate with whoever is currently in this file — don't rebase a 10k-line move on top of in-flight fixes.
Acceptance
Same conventions as #1097. Plus: smoke-test by compiling at least one TypeScript program to
--backend wasmbefore and after.