{"record":{"id":"3936739b6c9440e1","repo":"FuelLabs/sway","slug":"data-id-references-data-non-existent-in-the-data","errorCode":null,"errorMessage":"`data_id` references data non-existent in the data section","messagePattern":"`data_id` references data non-existent in the data section","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sway-core/src/asm_generation/fuel/programs/final.rs","lineNumber":67,"sourceCode":"        // Word-align the data section by appending NOOPs if needed.\n        let mut offset_to_data_section_in_bytes: u64 =\n            ops.iter().map(|op| op.size_in_bytes(&data_section)).sum();\n        if !offset_to_data_section_in_bytes.is_multiple_of(8) {\n            ops.push(AllocatedOp {\n                opcode: AllocatedInstruction::NOOP,\n                comment: \"word-align the data section\".into(),\n                owning_span: None,\n            });\n            offset_to_data_section_in_bytes += 4;\n        }\n\n        // Fill the reserved pointer slots.\n        let mut offset_from_instr_start = 0;\n        for op in &ops {\n            if let AllocatedInstruction::LoadDataId(_reg, data_id) = &op.opcode {\n                if !data_section\n                    .has_copy_type(data_id)\n                    .expect(\"`data_id` references data non-existent in the data section\")\n                {\n                    // A non-copy load loads a pointer to its target entry instead of\n                    // the entry itself. The pointer is stored in one of the reserved\n                    // pointer slots, and its value is relative to the load\n                    // instruction: the realized load adds `$pc` to it.\n                    let offset_bytes = data_section.data_id_to_offset(data_id) as u64;\n                    // The -4 is because $pc is added in the *next* instruction.\n                    let pointer_offset_from_current_instr =\n                        offset_to_data_section_in_bytes - offset_from_instr_start + offset_bytes\n                            - 4;\n                    data_section.append_pointer(pointer_offset_from_current_instr);\n                }\n            }\n            offset_from_instr_start += op.size_in_bytes(&data_section);\n        }\n\n        FinalizedAsm {\n            data_section,","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/FuelLabs/sway/blob/dad95cc42b0383b4e3bacdeda9766565aa584a92/sway-core/src/asm_generation/fuel/programs/final.rs#L49-L85","documentation":"In finalize, after freezing the data section layout, the compiler walks the allocated ops to fill reserved pointer slots for non-copy LoadDataId instructions. Determining whether a load is non-copy calls has_copy_type(data_id), which returns None when the DataId has no matching entry in the data section. The panic indicates a load instruction references data that is absent from the data section at finalization time — an internal compiler invariant violation, typically caused by a lowering or optimization pass that dropped or never registered the referenced entry.","triggerScenarios":"Thrown at sway-core/src/asm_generation/fuel/programs/final.rs:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure every pass that emits LoadDataId also registers its target entry in the data section before finalize runs","Check data-section pruning/dedup passes for removing entries still referenced by emitted loads","Trace the failing DataId (idx, region) back through lowering to find the pass that dropped the entry"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"dad95cc42b0383b4e3bacdeda9766565aa584a92","analyzedAt":"2026-09-04T20:02:14.068Z","contentChangedAt":"2026-09-04T20:02:14.068Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}