{"record":{"id":"d619474d20f39f79","repo":"FuelLabs/sway","slug":"stack-size-too-big-for-these-many-arguments-canno","errorCode":null,"errorMessage":"Stack size too big for these many arguments, cannot handle.","messagePattern":"Stack size too big for these many arguments, cannot handle\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sway-core/src/asm_generation/fuel/functions.rs","lineNumber":101,"sourceCode":"                    arg_reg,\n                    format!(\"[call: {fn_name}]: pass argument {idx}\"),\n                    self.md_mgr.val_to_span(self.context, *arg_val),\n                ));\n            }\n        } else {\n            // Register ARG_REGS[NUM_ARG_REGISTERS-1] must contain LocalsBase + locals_size\n            // so that the callee can index the stack arguments from there.\n            // It's also useful for us to save the arguments to the stack next.\n            if self.locals_size_bytes() <= TWELVE_BITS {\n                self.cur_bytecode.push(Op {\n                    opcode: Either::Left(VirtualOp::ADDI(\n                        VirtualRegister::Constant(\n                            ConstantRegister::ARG_REGS\n                                [(compiler_constants::NUM_ARG_REGISTERS - 1) as usize],\n                        ),\n                        VirtualRegister::Constant(ConstantRegister::LocalsBase),\n                        VirtualImmediate12::try_new(self.locals_size_bytes(), Span::dummy())\n                            .expect(\"Stack size too big for these many arguments, cannot handle.\"),\n                    )),\n                    comment: format!(\"[call: {fn_name}]: save address of stack arguments in last argument register\"),\n                    owning_span: self.md_mgr.val_to_span(self.context, *instr_val),\n                });\n            } else {\n                self.cur_bytecode.push(Op {\n                    opcode: Either::Left(VirtualOp::MOVI(\n                        VirtualRegister::Constant(\n                            ConstantRegister::ARG_REGS\n                                [(compiler_constants::NUM_ARG_REGISTERS - 1) as usize],\n                        ),\n                        VirtualImmediate18::try_new(self.locals_size_bytes(), Span::dummy())\n                            .expect(\"Stack size too big for these many arguments, cannot handle.\"),\n                    )),\n                    comment: format!(\n                        \"[call: {fn_name}]: temporarily save locals size to add up next\"\n                    ),\n                    owning_span: self.md_mgr.val_to_span(self.context, *instr_val),","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/sway-core/src/asm_generation/fuel/functions.rs#L83-L119","documentation":"In call-sequence codegen, when a function's locals fit in 12 bits the compiler stores LocalsBase + locals_size into the last argument register via ADDI with a VirtualImmediate12. This branch is guarded by `locals_size_bytes() <= TWELVE_BITS`, the very bound VirtualImmediate12 enforces, so the expect is an internal invariant assert that should be unreachable. If it fires, TWELVE_BITS and the immediate's actual width have diverged — an internal compiler error (ICE), not a user-code condition.","triggerScenarios":"A fork/refactor of sway-core changes compiler_constants::TWELVE_BITS or the width of VirtualImmediate12 so the guard no longer implies try_new success; essentially unreachable on released compilers regardless of the Sway source compiled.","commonSituations":"Contributing to sway-core asm generation; bisecting a compiler crash that lands here; reviewing changes that touch immediate types or compiler constants.","solutions":["Treat as an ICE: reduce to a minimal .sw case and report at FuelLabs/sway with the compiler version.","If maintaining a fork, verify TWELVE_BITS == 4095 and that VirtualImmediate12::try_new uses the same bound.","Switch back to the last released toolchain (`fuelup default <version>`) to confirm it is fork-specific."],"exampleFix":"// invariant check (compiler_constants)\n// before\npub const TWELVE_BITS: u32 = 8_191;               // diverges from immediate width -> expect fires\n// after\npub const TWELVE_BITS: u32 = 4_095;               // matches VirtualImmediate12 bound","handlingStrategy":"fallback","validationCode":"// fork maintainers: assert the invariant in tests so divergence fails loudly in CI\n#[test]\nfn twelve_bits_matches_immediate() {\n    assert_eq!(compiler_constants::TWELVE_BITS, (1u32 << 12) - 1);\n    assert!(VirtualImmediate12::try_new(compiler_constants::TWELVE_BITS as u64, Span::dummy()).is_ok());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin released fuelup toolchains for production builds; only run fork compilers in CI.","When touching compiler_constants or immediate types, run the full sway-core test suite first.","Capture the minimal .sw input and compiler commit when an ICE appears for upstream reporting."],"tags":["sway","sway-core","compiler","internal-compiler-error","invariant","asm-generation"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}