{"record":{"id":"f6fd2debe6d21fbd","repo":"diem/diem","slug":"target-locals-out-contains-new-local","errorCode":null,"errorMessage":"Target locals out contains new local","messagePattern":"Target locals out contains new local","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"language/testing-infra/test-generation/src/bytecode_generator.rs","lineNumber":707,"sourceCode":"                    && *current_availability == BorrowState::Available\n                {\n                    state = self.apply_instruction(\n                        fn_context,\n                        state,\n                        &mut bytecode,\n                        Bytecode::MoveLoc(*i as u8),\n                        true,\n                    )?;\n                    state = self.apply_instruction(\n                        fn_context,\n                        state,\n                        &mut bytecode,\n                        Bytecode::Pop,\n                        true,\n                    )?;\n                }\n            } else {\n                unreachable!(\"Target locals out contains new local\");\n            }\n        }\n        // Update the module to be the module that we've been building in our abstract state\n        Some((bytecode, state))\n    }\n\n    /// Generate the body of a function definition given a set of starting `locals` and a target\n    /// return `signature`. The sequence should contain at least `target_min` and at most\n    /// `target_max` instructions.\n    pub fn generate(\n        &mut self,\n        fn_context: &mut FunctionGenerationContext,\n        locals: &[SignatureToken],\n        fh: &FunctionHandle,\n        acquires_global_resources: &[StructDefinitionIndex],\n        module: &mut CompiledModule,\n        call_graph: &mut CallGraph,\n    ) -> Option<Vec<Bytecode>> {","sourceCodeStart":689,"sourceCodeEnd":725,"githubUrl":"https://github.com/diem/diem/blob/fc4714a8ea273b6efe8b13dbce72ea60aad9a16c/language/testing-infra/test-generation/src/bytecode_generator.rs#L689-L725","documentation":"This unreachable!() fires inside generate_block in the test-generation bytecode generator. The generator tracks an 'abstract state' of locals; after emitting bytecode for a block it verifies that the target locals output introduced no locals that were not already known to the state. Hitting this panic means the local-tracking logic produced an inconsistent local assignment, which the generator assumes is impossible.","triggerScenarios":"Running the Move test generator (proptest-driven bytecode generation) on a generated program whose generated instructions create a new local in the target locals out-set instead of only reusing/merging existing ones; typically a generator bug after adding a new bytecode variant that writes to a fresh local index.","commonSituations":"Developers extending the test generator with new instruction kinds, or changing local index allocation in AbstractState, run randomized generation and hit this panic on some seed.","solutions":["Inspect the failing seed and the generated instruction sequence to find which bytecode writes a new local index","Fix the AbstractState join/merge so target locals only contain locals already present in the state, or remap the new local to an existing slot","If the instruction legitimately creates a local, update generate_block to handle it instead of relying on the unreachable arm","Add a regression proptest case with the failing seed"],"exampleFix":"// before\n} else {\n    unreachable!(\"Target locals out contains new local\");\n}\n// after\n} else if let Some(existing) = state.local_index_for(&new_local) {\n    state.remap_target_local(existing);\n} else {\n    unreachable!(\"Target locals out contains new local\");\n}","handlingStrategy":"validation","validationCode":"assert!(target_out.iter().all(|l| state.locals().contains_key(l)), \"target locals out introduces unknown local\");","typeGuard":"fn locals_known(state: &AbstractState, out: &BTreeSet<LocalIndex>) -> bool {\n    out.iter().all(|l| state.local_exists(*l))\n}","tryCatchPattern":null,"preventionTips":["Unit-test AbstractState merge for all new bytecode variants","Keep local index allocation centralized in one module","Run the proptest suite with shrinking enabled to capture failing seeds"],"tags":["rust","panic","test-generation","bytecode"],"backgroundTag":"unreachable-panic","analyzedSha":"fc4714a8ea273b6efe8b13dbce72ea60aad9a16c","analyzedAt":"2026-09-04T21:07:05.890Z","contentChangedAt":"2026-09-04T21:07:05.890Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}