{"record":{"id":"59355c422d31c421","repo":"slint-ui/slint","slug":"rust-code-generation-failed","errorCode":null,"errorMessage":"Rust code generation failed","messagePattern":"Rust code generation failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compiler/benches/semantic_analysis.rs","lineNumber":370,"sourceCode":"/// Benchmark simulating the proc-macro pipeline (compile + Rust code generation).\n///\n/// This module measures the full cost of processing a slint! macro invocation,\n/// providing a baseline for tracking down slow proc-macro expansion in rust-analyzer.\nmod proc_macro_simulation {\n    use super::*;\n\n    /// Compile and generate Rust code (simulates what the slint! proc-macro does)\n    fn compile_to_rust(source: &str) -> (proc_macro2::TokenStream, BuildDiagnostics) {\n        let diagnostics = BuildDiagnostics::default();\n        let node = parse_source(source);\n\n        let config = CompilerConfiguration::new(i_slint_compiler::generator::OutputFormat::Rust);\n\n        let (doc, diag, loader) =\n            spin_on::spin_on(i_slint_compiler::compile_syntax_node(node, diagnostics, config));\n\n        let rust_code = i_slint_compiler::generator::rust::generate(&doc, &loader.compiler_config)\n            .expect(\"Rust code generation failed\");\n\n        (rust_code, diag)\n    }\n\n    /// Baseline benchmark: empty component through full proc-macro pipeline.\n    /// This measures the minimum overhead of proc-macro expansion.\n    #[divan::bench]\n    fn empty_component() {\n        divan::black_box(compile_to_rust(EMPTY_COMPONENT));\n    }\n}\n\n/// Detailed phase benchmarks to identify hotspots in compilation.\nmod phase_breakdown {\n    use super::*;\n    use std::cell::RefCell;\n    use std::rc::Rc;\n","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/compiler/benches/semantic_analysis.rs#L352-L388","documentation":"The `compile_to_rust` benchmark helper compiles a parsed .slint syntax tree and generates Rust code via `i_slint_compiler::generator::rust::generate`. Code generation is expected to succeed for valid benchmarks; if it returns `None`, generation failed and the benchmark panics.","triggerScenarios":"Benchmarking a .slint snippet that fails Rust code generation: unsupported language features in the benchmark source, type errors not caught by the earlier diagnostics check, or an internal compiler limitation triggered by the fixture.","commonSituations":"Editing benchmark fixtures with new syntax the generator does not support; running benches on a compiler in a partially-broken state; fixture drift after compiler changes.","solutions":["Run the snippet through the slint compiler (slint-viewer or a test) and print `diag` to find the actual generation failure","Simplify or update the benchmark fixture to use fully supported language features","Rebuild after `cargo build` to rule out a stale mixed compiler build; update to latest compiler if the feature is newly unsupported"],"exampleFix":"// before\nlet rust_code = generate(&doc, &config).expect(\"Rust code generation failed\");\n// after\nlet rust_code = generate(&doc, &config)\n    .unwrap_or_else(|| panic!(\"codegen failed: {:#?}\", diagnostics)); // surface real diagnostics","handlingStrategy":"validation","validationCode":"// validate the fixture compiles before benchmarking\nlet mut diags = Default::default();\nlet (doc, diag, loader) = spin_on::spin_on(compile_syntax_node(node, &mut diags, config));\nassert!(diag.is_empty(), \"fixture has errors: {:#?}\", diag);","typeGuard":null,"tryCatchPattern":"generate(&doc, &config).unwrap_or_else(|| {\n    panic!(\"Rust codegen failed for benchmark fixture: {:#?}\", diag)\n})","preventionTips":["Run the fixture through slint-viewer or a compile test before adding it to a bench","Keep benchmark fixtures limited to fully supported language features","Rebuild cleanly after compiler changes to avoid stale-artifact failures"],"tags":["compiler","codegen","benchmark","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}