From 38a0d446bf8e2be272a1e2e5624baf528130c934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Thu, 28 Mar 2024 10:00:46 -0700 Subject: [PATCH] Use dense FIR IDs across packages (#1296) This change fixes three things: - It reduces the memory footprint by using dense FIR IDs across packages. This is accomplished by using a new lowerer instance for every package such that IDs for blocks, statements, expressions and pats are reset and start from zero. - It fixes a bug where the debugger would not honor a breakpoint if the statement that mapped to the breakpoint had the ID 0. - As a consequence of changing the way the FIR lowerer is used, the debugger would now randomly and inadvertently break into a core or standard library statement if the statement ID happened to be the same than the statement ID where a breakpoint is set in the user's code. This problem is also addressed by this change. This was done in collaboration with @swernli and @idavis. --------- Co-authored-by: Stefan J. Wernli --- compiler/qsc/benches/rca.rs | 12 +- compiler/qsc/src/interpret.rs | 9 +- compiler/qsc_codegen/src/qir_base.rs | 3 +- compiler/qsc_eval/src/intrinsic/tests.rs | 7 +- compiler/qsc_eval/src/lib.rs | 7 +- compiler/qsc_eval/src/tests.rs | 596 +++++++++++------------ compiler/qsc_rca/tests/test_utils.rs | 11 +- vscode/src/debugger/session.ts | 2 +- 8 files changed, 317 insertions(+), 330 deletions(-) diff --git a/compiler/qsc/benches/rca.rs b/compiler/qsc/benches/rca.rs index e7378b1f51..f566620fda 100644 --- a/compiler/qsc/benches/rca.rs +++ b/compiler/qsc/benches/rca.rs @@ -134,26 +134,22 @@ impl Default for CompilationContext { LanguageFeatures::default(), ) .expect("should be able to create a new compiler"); - let mut lowerer = Lowerer::new(); - let fir_store = lower_hir_package_store(&mut lowerer, compiler.package_store()); + let fir_store = lower_hir_package_store(compiler.package_store()); Self { compiler, - lowerer, + lowerer: Lowerer::new(), fir_store, compute_properties: None, } } } -fn lower_hir_package_store( - lowerer: &mut Lowerer, - hir_package_store: &HirPackageStore, -) -> PackageStore { +fn lower_hir_package_store(hir_package_store: &HirPackageStore) -> PackageStore { let mut fir_store = PackageStore::new(); for (id, unit) in hir_package_store { fir_store.insert( map_hir_package_to_fir(id), - lowerer.lower_package(&unit.package), + Lowerer::new().lower_package(&unit.package), ); } fir_store diff --git a/compiler/qsc/src/interpret.rs b/compiler/qsc/src/interpret.rs index 351f23aaa2..00c2e90835 100644 --- a/compiler/qsc/src/interpret.rs +++ b/compiler/qsc/src/interpret.rs @@ -145,28 +145,25 @@ impl Interpreter { capabilities: RuntimeCapabilityFlags, language_features: LanguageFeatures, ) -> std::result::Result> { - let mut lowerer = qsc_eval::lower::Lowerer::new(); - let mut fir_store = fir::PackageStore::new(); - let compiler = Compiler::new(std, sources, package_type, capabilities, language_features) .map_err(into_errors)?; + let mut fir_store = fir::PackageStore::new(); for (id, unit) in compiler.package_store() { fir_store.insert( map_hir_package_to_fir(id), - lowerer.lower_package(&unit.package), + qsc_eval::lower::Lowerer::new().lower_package(&unit.package), ); } let source_package_id = compiler.source_package_id(); let package_id = compiler.package_id(); - Ok(Self { compiler, lines: 0, capabilities, fir_store, - lowerer, + lowerer: qsc_eval::lower::Lowerer::new(), env: Env::default(), sim: BackendChain::new( SparseSim::new(), diff --git a/compiler/qsc_codegen/src/qir_base.rs b/compiler/qsc_codegen/src/qir_base.rs index ef2d2e6cbb..988b3cce27 100644 --- a/compiler/qsc_codegen/src/qir_base.rs +++ b/compiler/qsc_codegen/src/qir_base.rs @@ -31,12 +31,11 @@ pub fn generate_qir( store: &PackageStore, package: hir::PackageId, ) -> std::result::Result)> { - let mut fir_lowerer = qsc_eval::lower::Lowerer::new(); let mut fir_store = fir::PackageStore::new(); for (id, unit) in store { fir_store.insert( map_hir_package_to_fir(id), - fir_lowerer.lower_package(&unit.package), + qsc_eval::lower::Lowerer::new().lower_package(&unit.package), ); } diff --git a/compiler/qsc_eval/src/intrinsic/tests.rs b/compiler/qsc_eval/src/intrinsic/tests.rs index 2b0544bb99..bf4ce9162f 100644 --- a/compiler/qsc_eval/src/intrinsic/tests.rs +++ b/compiler/qsc_eval/src/intrinsic/tests.rs @@ -146,10 +146,9 @@ impl Backend for CustomSim { } fn check_intrinsic(file: &str, expr: &str, out: &mut impl Receiver) -> Result { - let mut fir_lowerer = crate::lower::Lowerer::new(); let mut core = compile::core(); run_core_passes(&mut core); - let core_fir = fir_lowerer.lower_package(&core.package); + let core_fir = crate::lower::Lowerer::new().lower_package(&core.package); let mut store = PackageStore::new(core); let mut std = compile::std(&store, RuntimeCapabilityFlags::all()); @@ -161,7 +160,7 @@ fn check_intrinsic(file: &str, expr: &str, out: &mut impl Receiver) -> Result Result, val_register: Option, val_stack: Vec>, + source_package: PackageId, package: PackageId, call_stack: CallStack, current_span: Span, @@ -429,6 +430,7 @@ impl State { idx_stack: Vec::new(), val_register: None, val_stack: vec![Vec::new()], + source_package: package, package, call_stack: CallStack::default(), current_span: Span::default(), @@ -547,7 +549,10 @@ impl State { self.idx += 1; self.current_span = globals.get_stmt((self.package, *stmt).into()).span; - if let Some(bp) = breakpoints.iter().find(|&bp| *bp == *stmt) { + if let Some(bp) = breakpoints + .iter() + .find(|&bp| *bp == *stmt && self.package == self.source_package) + { StepResult::BreakpointHit(*bp) } else { if self.current_span == Span::default() { diff --git a/compiler/qsc_eval/src/tests.rs b/compiler/qsc_eval/src/tests.rs index 6a238b0d59..9a3dc44e90 100644 --- a/compiler/qsc_eval/src/tests.rs +++ b/compiler/qsc_eval/src/tests.rs @@ -110,10 +110,9 @@ fn check_partial_eval_stmt( fir_expect: &Expect, result_expect: &Expect, ) { - let mut fir_lowerer = crate::lower::Lowerer::new(); let mut core = compile::core(); run_core_passes(&mut core); - let core_fir = fir_lowerer.lower_package(&core.package); + let core_fir = crate::lower::Lowerer::new().lower_package(&core.package); let mut store = PackageStore::new(core); let mut std = compile::std(&store, RuntimeCapabilityFlags::all()); @@ -125,7 +124,7 @@ fn check_partial_eval_stmt( RuntimeCapabilityFlags::all() ) .is_empty()); - let std_fir = fir_lowerer.lower_package(&std.package); + let std_fir = crate::lower::Lowerer::new().lower_package(&std.package); let std_id = store.insert(std); let sources = SourceMap::new([("test".into(), file.into())], Some(expr.into())); @@ -144,7 +143,7 @@ fn check_partial_eval_stmt( RuntimeCapabilityFlags::all(), ); assert!(pass_errors.is_empty(), "{pass_errors:?}"); - let unit_fir = fir_lowerer.lower_package(&unit.package); + let unit_fir = crate::lower::Lowerer::new().lower_package(&unit.package); fir_expect.assert_eq(&unit_fir.to_string()); let entry = unit_fir.entry_exec_graph.clone(); @@ -3685,29 +3684,29 @@ fn partial_eval_simple_stmt() { check_partial_eval_stmt( "", "{3; {4} 5;}", - &[5011_u32.into()], + &[2_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-11] [Type Unit]: - 5009 - 5010 - 5012 - Block 2098 [4-7] [Type Int]: - 5011 + Block 0 [0-11] [Type Unit]: + 0 + 1 + 3 + Block 1 [4-7] [Type Int]: + 2 Stmts: - Stmt 5009 [1-3]: Semi: 25959 - Stmt 5010 [4-7]: Expr: 25960 - Stmt 5011 [5-6]: Expr: 25961 - Stmt 5012 [8-10]: Semi: 25962 + Stmt 0 [1-3]: Semi: 1 + Stmt 1 [4-7]: Expr: 2 + Stmt 2 [5-6]: Expr: 3 + Stmt 3 [8-10]: Semi: 4 Exprs: - Expr 25958 [0-11] [Type Unit]: Expr Block: 2097 - Expr 25959 [1-2] [Type Int]: Lit: Int(3) - Expr 25960 [4-7] [Type Int]: Expr Block: 2098 - Expr 25961 [5-6] [Type Int]: Lit: Int(4) - Expr 25962 [8-9] [Type Int]: Lit: Int(5) + Expr 0 [0-11] [Type Unit]: Expr Block: 0 + Expr 1 [1-2] [Type Int]: Lit: Int(3) + Expr 2 [4-7] [Type Int]: Expr Block: 1 + Expr 3 [5-6] [Type Int]: Lit: Int(4) + Expr 4 [8-9] [Type Int]: Lit: Int(5) Pats:"#]], &expect!["4"], ); @@ -3718,33 +3717,33 @@ fn partial_eval_stmt_with_bound_variable() { check_partial_eval_stmt( "", "{let x = 3; {x} ()}", - &[5009_u32.into(), 5011_u32.into()], + &[0_u32.into(), 2_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-19] [Type Unit]: - 5009 - 5010 - 5012 - Block 2098 [12-15] [Type Int]: - 5011 + Block 0 [0-19] [Type Unit]: + 0 + 1 + 3 + Block 1 [12-15] [Type Int]: + 2 Stmts: - Stmt 5009 [1-11]: Local (Immutable): - 2896 - 25959 - Stmt 5010 [12-15]: Expr: 25960 - Stmt 5011 [13-14]: Expr: 25961 - Stmt 5012 [16-18]: Expr: 25962 + Stmt 0 [1-11]: Local (Immutable): + 0 + 1 + Stmt 1 [12-15]: Expr: 2 + Stmt 2 [13-14]: Expr: 3 + Stmt 3 [16-18]: Expr: 4 Exprs: - Expr 25958 [0-19] [Type Unit]: Expr Block: 2097 - Expr 25959 [9-10] [Type Int]: Lit: Int(3) - Expr 25960 [12-15] [Type Int]: Expr Block: 2098 - Expr 25961 [13-14] [Type Int]: Var: Local 22 - Expr 25962 [16-18] [Type Unit]: Unit + Expr 0 [0-19] [Type Unit]: Expr Block: 0 + Expr 1 [9-10] [Type Int]: Lit: Int(3) + Expr 2 [12-15] [Type Int]: Expr Block: 1 + Expr 3 [13-14] [Type Int]: Var: Local 0 + Expr 4 [16-18] [Type Unit]: Unit Pats: - Pat 2896 [5-6] [Type Int]: Bind: Ident 22 [5-6] "x""#]], + Pat 0 [5-6] [Type Int]: Bind: Ident 0 [5-6] "x""#]], &expect!["3"], ); } @@ -3754,46 +3753,46 @@ fn partial_eval_stmt_with_mutable_variable_update() { check_partial_eval_stmt( "", "{mutable x = 0; set x += 1; {x} set x = -1;}", - &[5009_u32.into(), 5010_u32.into(), 5012_u32.into()], + &[0_u32.into(), 1_u32.into(), 2_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-44] [Type Unit]: - 5009 - 5010 - 5011 - 5013 - Block 2098 [28-31] [Type Int]: - 5012 + Block 0 [0-44] [Type Unit]: + 0 + 1 + 2 + 4 + Block 1 [28-31] [Type Int]: + 3 Stmts: - Stmt 5009 [1-15]: Local (Mutable): - 2896 - 25959 - Stmt 5010 [16-27]: Semi: 25960 - Stmt 5011 [28-31]: Expr: 25963 - Stmt 5012 [29-30]: Expr: 25964 - Stmt 5013 [32-43]: Semi: 25965 + Stmt 0 [1-15]: Local (Mutable): + 0 + 1 + Stmt 1 [16-27]: Semi: 2 + Stmt 2 [28-31]: Expr: 5 + Stmt 3 [29-30]: Expr: 6 + Stmt 4 [32-43]: Semi: 7 Exprs: - Expr 25958 [0-44] [Type Unit]: Expr Block: 2097 - Expr 25959 [13-14] [Type Int]: Lit: Int(0) - Expr 25960 [16-26] [Type Unit]: AssignOp (Add): - 25961 - 25962 - Expr 25961 [20-21] [Type Int]: Var: Local 22 - Expr 25962 [25-26] [Type Int]: Lit: Int(1) - Expr 25963 [28-31] [Type Int]: Expr Block: 2098 - Expr 25964 [29-30] [Type Int]: Var: Local 22 - Expr 25965 [32-42] [Type Unit]: Assign: - 25966 - 25967 - Expr 25966 [36-37] [Type Int]: Var: Local 22 - Expr 25967 [40-42] [Type Int]: UnOp (Neg): - 25968 - Expr 25968 [41-42] [Type Int]: Lit: Int(1) + Expr 0 [0-44] [Type Unit]: Expr Block: 0 + Expr 1 [13-14] [Type Int]: Lit: Int(0) + Expr 2 [16-26] [Type Unit]: AssignOp (Add): + 3 + 4 + Expr 3 [20-21] [Type Int]: Var: Local 0 + Expr 4 [25-26] [Type Int]: Lit: Int(1) + Expr 5 [28-31] [Type Int]: Expr Block: 1 + Expr 6 [29-30] [Type Int]: Var: Local 0 + Expr 7 [32-42] [Type Unit]: Assign: + 8 + 9 + Expr 8 [36-37] [Type Int]: Var: Local 0 + Expr 9 [40-42] [Type Int]: UnOp (Neg): + 10 + Expr 10 [41-42] [Type Int]: Lit: Int(1) Pats: - Pat 2896 [9-10] [Type Int]: Bind: Ident 22 [9-10] "x""#]], + Pat 0 [9-10] [Type Int]: Bind: Ident 0 [9-10] "x""#]], &expect!["1"], ); } @@ -3803,46 +3802,46 @@ fn partial_eval_stmt_with_mutable_variable_update_out_of_order_works() { check_partial_eval_stmt( "", "{mutable x = 0; set x += 1; {x} set x = -1;}", - &[5009_u32.into(), 5013_u32.into(), 5012_u32.into()], + &[0_u32.into(), 4_u32.into(), 3_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-44] [Type Unit]: - 5009 - 5010 - 5011 - 5013 - Block 2098 [28-31] [Type Int]: - 5012 + Block 0 [0-44] [Type Unit]: + 0 + 1 + 2 + 4 + Block 1 [28-31] [Type Int]: + 3 Stmts: - Stmt 5009 [1-15]: Local (Mutable): - 2896 - 25959 - Stmt 5010 [16-27]: Semi: 25960 - Stmt 5011 [28-31]: Expr: 25963 - Stmt 5012 [29-30]: Expr: 25964 - Stmt 5013 [32-43]: Semi: 25965 + Stmt 0 [1-15]: Local (Mutable): + 0 + 1 + Stmt 1 [16-27]: Semi: 2 + Stmt 2 [28-31]: Expr: 5 + Stmt 3 [29-30]: Expr: 6 + Stmt 4 [32-43]: Semi: 7 Exprs: - Expr 25958 [0-44] [Type Unit]: Expr Block: 2097 - Expr 25959 [13-14] [Type Int]: Lit: Int(0) - Expr 25960 [16-26] [Type Unit]: AssignOp (Add): - 25961 - 25962 - Expr 25961 [20-21] [Type Int]: Var: Local 22 - Expr 25962 [25-26] [Type Int]: Lit: Int(1) - Expr 25963 [28-31] [Type Int]: Expr Block: 2098 - Expr 25964 [29-30] [Type Int]: Var: Local 22 - Expr 25965 [32-42] [Type Unit]: Assign: - 25966 - 25967 - Expr 25966 [36-37] [Type Int]: Var: Local 22 - Expr 25967 [40-42] [Type Int]: UnOp (Neg): - 25968 - Expr 25968 [41-42] [Type Int]: Lit: Int(1) + Expr 0 [0-44] [Type Unit]: Expr Block: 0 + Expr 1 [13-14] [Type Int]: Lit: Int(0) + Expr 2 [16-26] [Type Unit]: AssignOp (Add): + 3 + 4 + Expr 3 [20-21] [Type Int]: Var: Local 0 + Expr 4 [25-26] [Type Int]: Lit: Int(1) + Expr 5 [28-31] [Type Int]: Expr Block: 1 + Expr 6 [29-30] [Type Int]: Var: Local 0 + Expr 7 [32-42] [Type Unit]: Assign: + 8 + 9 + Expr 8 [36-37] [Type Int]: Var: Local 0 + Expr 9 [40-42] [Type Int]: UnOp (Neg): + 10 + Expr 10 [41-42] [Type Int]: Lit: Int(1) Pats: - Pat 2896 [9-10] [Type Int]: Bind: Ident 22 [9-10] "x""#]], + Pat 0 [9-10] [Type Int]: Bind: Ident 0 [9-10] "x""#]], &expect!["-1"], ); } @@ -3852,51 +3851,46 @@ fn partial_eval_stmt_with_mutable_variable_update_repeat_stmts_works() { check_partial_eval_stmt( "", "{mutable x = 0; set x += 1; {x} set x = -1;}", - &[ - 5009_u32.into(), - 5010_u32.into(), - 5010_u32.into(), - 5012_u32.into(), - ], + &[0_u32.into(), 1_u32.into(), 1_u32.into(), 3_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-44] [Type Unit]: - 5009 - 5010 - 5011 - 5013 - Block 2098 [28-31] [Type Int]: - 5012 + Block 0 [0-44] [Type Unit]: + 0 + 1 + 2 + 4 + Block 1 [28-31] [Type Int]: + 3 Stmts: - Stmt 5009 [1-15]: Local (Mutable): - 2896 - 25959 - Stmt 5010 [16-27]: Semi: 25960 - Stmt 5011 [28-31]: Expr: 25963 - Stmt 5012 [29-30]: Expr: 25964 - Stmt 5013 [32-43]: Semi: 25965 + Stmt 0 [1-15]: Local (Mutable): + 0 + 1 + Stmt 1 [16-27]: Semi: 2 + Stmt 2 [28-31]: Expr: 5 + Stmt 3 [29-30]: Expr: 6 + Stmt 4 [32-43]: Semi: 7 Exprs: - Expr 25958 [0-44] [Type Unit]: Expr Block: 2097 - Expr 25959 [13-14] [Type Int]: Lit: Int(0) - Expr 25960 [16-26] [Type Unit]: AssignOp (Add): - 25961 - 25962 - Expr 25961 [20-21] [Type Int]: Var: Local 22 - Expr 25962 [25-26] [Type Int]: Lit: Int(1) - Expr 25963 [28-31] [Type Int]: Expr Block: 2098 - Expr 25964 [29-30] [Type Int]: Var: Local 22 - Expr 25965 [32-42] [Type Unit]: Assign: - 25966 - 25967 - Expr 25966 [36-37] [Type Int]: Var: Local 22 - Expr 25967 [40-42] [Type Int]: UnOp (Neg): - 25968 - Expr 25968 [41-42] [Type Int]: Lit: Int(1) + Expr 0 [0-44] [Type Unit]: Expr Block: 0 + Expr 1 [13-14] [Type Int]: Lit: Int(0) + Expr 2 [16-26] [Type Unit]: AssignOp (Add): + 3 + 4 + Expr 3 [20-21] [Type Int]: Var: Local 0 + Expr 4 [25-26] [Type Int]: Lit: Int(1) + Expr 5 [28-31] [Type Int]: Expr Block: 1 + Expr 6 [29-30] [Type Int]: Var: Local 0 + Expr 7 [32-42] [Type Unit]: Assign: + 8 + 9 + Expr 8 [36-37] [Type Int]: Var: Local 0 + Expr 9 [40-42] [Type Int]: UnOp (Neg): + 10 + Expr 10 [41-42] [Type Int]: Lit: Int(1) Pats: - Pat 2896 [9-10] [Type Int]: Bind: Ident 22 [9-10] "x""#]], + Pat 0 [9-10] [Type Int]: Bind: Ident 0 [9-10] "x""#]], &expect!["2"], ); } @@ -3906,37 +3900,37 @@ fn partial_eval_stmt_with_bool_short_circuit() { check_partial_eval_stmt( "", "{let x = true; { x or false } ();}", - &[5009_u32.into(), 5011_u32.into()], + &[0_u32.into(), 2_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-34] [Type Unit]: - 5009 - 5010 - 5012 - Block 2098 [15-29] [Type Bool]: - 5011 + Block 0 [0-34] [Type Unit]: + 0 + 1 + 3 + Block 1 [15-29] [Type Bool]: + 2 Stmts: - Stmt 5009 [1-14]: Local (Immutable): - 2896 - 25959 - Stmt 5010 [15-29]: Expr: 25960 - Stmt 5011 [17-27]: Expr: 25961 - Stmt 5012 [30-33]: Semi: 25964 + Stmt 0 [1-14]: Local (Immutable): + 0 + 1 + Stmt 1 [15-29]: Expr: 2 + Stmt 2 [17-27]: Expr: 3 + Stmt 3 [30-33]: Semi: 6 Exprs: - Expr 25958 [0-34] [Type Unit]: Expr Block: 2097 - Expr 25959 [9-13] [Type Bool]: Lit: Bool(true) - Expr 25960 [15-29] [Type Bool]: Expr Block: 2098 - Expr 25961 [17-27] [Type Bool]: BinOp (OrL): - 25962 - 25963 - Expr 25962 [17-18] [Type Bool]: Var: Local 22 - Expr 25963 [22-27] [Type Bool]: Lit: Bool(false) - Expr 25964 [30-32] [Type Unit]: Unit + Expr 0 [0-34] [Type Unit]: Expr Block: 0 + Expr 1 [9-13] [Type Bool]: Lit: Bool(true) + Expr 2 [15-29] [Type Bool]: Expr Block: 1 + Expr 3 [17-27] [Type Bool]: BinOp (OrL): + 4 + 5 + Expr 4 [17-18] [Type Bool]: Var: Local 0 + Expr 5 [22-27] [Type Bool]: Lit: Bool(false) + Expr 6 [30-32] [Type Unit]: Unit Pats: - Pat 2896 [5-6] [Type Bool]: Bind: Ident 22 [5-6] "x""#]], + Pat 0 [5-6] [Type Bool]: Bind: Ident 0 [5-6] "x""#]], &expect!["true"], ); } @@ -3946,37 +3940,37 @@ fn partial_eval_stmt_with_bool_no_short_circuit() { check_partial_eval_stmt( "", "{let x = false; { x or true } ();}", - &[5009_u32.into(), 5011_u32.into()], + &[0_u32.into(), 2_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-34] [Type Unit]: - 5009 - 5010 - 5012 - Block 2098 [16-29] [Type Bool]: - 5011 + Block 0 [0-34] [Type Unit]: + 0 + 1 + 3 + Block 1 [16-29] [Type Bool]: + 2 Stmts: - Stmt 5009 [1-15]: Local (Immutable): - 2896 - 25959 - Stmt 5010 [16-29]: Expr: 25960 - Stmt 5011 [18-27]: Expr: 25961 - Stmt 5012 [30-33]: Semi: 25964 + Stmt 0 [1-15]: Local (Immutable): + 0 + 1 + Stmt 1 [16-29]: Expr: 2 + Stmt 2 [18-27]: Expr: 3 + Stmt 3 [30-33]: Semi: 6 Exprs: - Expr 25958 [0-34] [Type Unit]: Expr Block: 2097 - Expr 25959 [9-14] [Type Bool]: Lit: Bool(false) - Expr 25960 [16-29] [Type Bool]: Expr Block: 2098 - Expr 25961 [18-27] [Type Bool]: BinOp (OrL): - 25962 - 25963 - Expr 25962 [18-19] [Type Bool]: Var: Local 22 - Expr 25963 [23-27] [Type Bool]: Lit: Bool(true) - Expr 25964 [30-32] [Type Unit]: Unit + Expr 0 [0-34] [Type Unit]: Expr Block: 0 + Expr 1 [9-14] [Type Bool]: Lit: Bool(false) + Expr 2 [16-29] [Type Bool]: Expr Block: 1 + Expr 3 [18-27] [Type Bool]: BinOp (OrL): + 4 + 5 + Expr 4 [18-19] [Type Bool]: Var: Local 0 + Expr 5 [23-27] [Type Bool]: Lit: Bool(true) + Expr 6 [30-32] [Type Unit]: Unit Pats: - Pat 2896 [5-6] [Type Bool]: Bind: Ident 22 [5-6] "x""#]], + Pat 0 [5-6] [Type Bool]: Bind: Ident 0 [5-6] "x""#]], &expect!["true"], ); } @@ -3986,51 +3980,51 @@ fn partial_eval_stmt_with_loop() { check_partial_eval_stmt( "", "{mutable x = 0; while x < 3 { set x += 1; } {x} ();}", - &[5009_u32.into(), 5010_u32.into(), 5013_u32.into()], + &[0_u32.into(), 1_u32.into(), 4_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-52] [Type Unit]: - 5009 - 5010 - 5012 - 5014 - Block 2098 [28-43] [Type Unit]: - 5011 - Block 2099 [44-47] [Type Int]: - 5013 + Block 0 [0-52] [Type Unit]: + 0 + 1 + 3 + 5 + Block 1 [28-43] [Type Unit]: + 2 + Block 2 [44-47] [Type Int]: + 4 Stmts: - Stmt 5009 [1-15]: Local (Mutable): - 2896 - 25959 - Stmt 5010 [16-43]: Expr: 25960 - Stmt 5011 [30-41]: Semi: 25964 - Stmt 5012 [44-47]: Expr: 25967 - Stmt 5013 [45-46]: Expr: 25968 - Stmt 5014 [48-51]: Semi: 25969 + Stmt 0 [1-15]: Local (Mutable): + 0 + 1 + Stmt 1 [16-43]: Expr: 2 + Stmt 2 [30-41]: Semi: 6 + Stmt 3 [44-47]: Expr: 9 + Stmt 4 [45-46]: Expr: 10 + Stmt 5 [48-51]: Semi: 11 Exprs: - Expr 25958 [0-52] [Type Unit]: Expr Block: 2097 - Expr 25959 [13-14] [Type Int]: Lit: Int(0) - Expr 25960 [16-43] [Type Unit]: While: - 25961 - 2098 - Expr 25961 [22-27] [Type Bool]: BinOp (Lt): - 25962 - 25963 - Expr 25962 [22-23] [Type Int]: Var: Local 22 - Expr 25963 [26-27] [Type Int]: Lit: Int(3) - Expr 25964 [30-40] [Type Unit]: AssignOp (Add): - 25965 - 25966 - Expr 25965 [34-35] [Type Int]: Var: Local 22 - Expr 25966 [39-40] [Type Int]: Lit: Int(1) - Expr 25967 [44-47] [Type Int]: Expr Block: 2099 - Expr 25968 [45-46] [Type Int]: Var: Local 22 - Expr 25969 [48-50] [Type Unit]: Unit + Expr 0 [0-52] [Type Unit]: Expr Block: 0 + Expr 1 [13-14] [Type Int]: Lit: Int(0) + Expr 2 [16-43] [Type Unit]: While: + 3 + 1 + Expr 3 [22-27] [Type Bool]: BinOp (Lt): + 4 + 5 + Expr 4 [22-23] [Type Int]: Var: Local 0 + Expr 5 [26-27] [Type Int]: Lit: Int(3) + Expr 6 [30-40] [Type Unit]: AssignOp (Add): + 7 + 8 + Expr 7 [34-35] [Type Int]: Var: Local 0 + Expr 8 [39-40] [Type Int]: Lit: Int(1) + Expr 9 [44-47] [Type Int]: Expr Block: 2 + Expr 10 [45-46] [Type Int]: Var: Local 0 + Expr 11 [48-50] [Type Unit]: Unit Pats: - Pat 2896 [9-10] [Type Int]: Bind: Ident 22 [9-10] "x""#]], + Pat 0 [9-10] [Type Int]: Bind: Ident 0 [9-10] "x""#]], &expect!["3"], ); } @@ -4044,65 +4038,65 @@ fn partial_eval_stmt_function_calls() { } "}, "{let x = Test.Add1(4); {x} Test.Add1(3)}", - &[5009_u32.into(), 5011_u32.into()], + &[0_u32.into(), 2_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Item 0 [41-102] (Public): - Namespace (Ident 23 [51-55] "Test"): Item 1 + Namespace (Ident 1 [51-55] "Test"): Item 1 Item 1 [62-100] (Public): Parent: 0 Callable 0 [62-100] (function): name: Ident 0 [71-75] "Add1" - input: 2897 + input: 1 output: Int functors: empty set implementation: Spec: SpecImpl: - body: SpecDecl 942 [62-100]: None 2099 + body: SpecDecl 1 [62-100]: None 2 adj: ctl: ctl-adj: Blocks: - Block 2097 [0-40] [Type Int]: - 5009 - 5010 - 5012 - Block 2098 [23-26] [Type Int]: - 5011 - Block 2099 [91-100] [Type Int]: - 5013 + Block 0 [0-40] [Type Int]: + 0 + 1 + 3 + Block 1 [23-26] [Type Int]: + 2 + Block 2 [91-100] [Type Int]: + 4 Stmts: - Stmt 5009 [1-22]: Local (Immutable): - 2896 - 25959 - Stmt 5010 [23-26]: Expr: 25962 - Stmt 5011 [24-25]: Expr: 25963 - Stmt 5012 [27-39]: Expr: 25964 - Stmt 5013 [93-98]: Expr: 25967 + Stmt 0 [1-22]: Local (Immutable): + 0 + 1 + Stmt 1 [23-26]: Expr: 4 + Stmt 2 [24-25]: Expr: 5 + Stmt 3 [27-39]: Expr: 6 + Stmt 4 [93-98]: Expr: 9 Exprs: - Expr 25958 [0-40] [Type Int]: Expr Block: 2097 - Expr 25959 [9-21] [Type Int]: Call: - 25960 - 25961 - Expr 25960 [9-18] [Type (Int -> Int)]: Var: Item 1 - Expr 25961 [19-20] [Type Int]: Lit: Int(4) - Expr 25962 [23-26] [Type Int]: Expr Block: 2098 - Expr 25963 [24-25] [Type Int]: Var: Local 22 - Expr 25964 [27-39] [Type Int]: Call: - 25965 - 25966 - Expr 25965 [27-36] [Type (Int -> Int)]: Var: Item 1 - Expr 25966 [37-38] [Type Int]: Lit: Int(3) - Expr 25967 [93-98] [Type Int]: BinOp (Add): - 25968 - 25969 - Expr 25968 [93-94] [Type Int]: Var: Local 1 - Expr 25969 [97-98] [Type Int]: Lit: Int(1) + Expr 0 [0-40] [Type Int]: Expr Block: 0 + Expr 1 [9-21] [Type Int]: Call: + 2 + 3 + Expr 2 [9-18] [Type (Int -> Int)]: Var: Item 1 + Expr 3 [19-20] [Type Int]: Lit: Int(4) + Expr 4 [23-26] [Type Int]: Expr Block: 1 + Expr 5 [24-25] [Type Int]: Var: Local 0 + Expr 6 [27-39] [Type Int]: Call: + 7 + 8 + Expr 7 [27-36] [Type (Int -> Int)]: Var: Item 1 + Expr 8 [37-38] [Type Int]: Lit: Int(3) + Expr 9 [93-98] [Type Int]: BinOp (Add): + 10 + 11 + Expr 10 [93-94] [Type Int]: Var: Local 1 + Expr 11 [97-98] [Type Int]: Lit: Int(1) Pats: - Pat 2896 [5-6] [Type Int]: Bind: Ident 22 [5-6] "x" - Pat 2897 [76-83] [Type Int]: Bind: Ident 1 [76-77] "x""#]], + Pat 0 [5-6] [Type Int]: Bind: Ident 0 [5-6] "x" + Pat 1 [76-83] [Type Int]: Bind: Ident 1 [76-77] "x""#]], &expect!["5"], ); } @@ -4112,46 +4106,46 @@ fn partial_eval_stmt_function_calls_from_library() { check_partial_eval_stmt( "", "{let x = [1, 2, 3]; {Length(x)} 3}", - &[5009_u32.into(), 5011_u32.into()], + &[0_u32.into(), 2_u32.into()], &expect![[r#" Package: - Entry Expression: 25958 + Entry Expression: 0 Items: Blocks: - Block 2097 [0-34] [Type Int]: - 5009 - 5010 - 5012 - Block 2098 [20-31] [Type Int]: - 5011 + Block 0 [0-34] [Type Int]: + 0 + 1 + 3 + Block 1 [20-31] [Type Int]: + 2 Stmts: - Stmt 5009 [1-19]: Local (Immutable): - 2896 - 25959 - Stmt 5010 [20-31]: Expr: 25963 - Stmt 5011 [21-30]: Expr: 25964 - Stmt 5012 [32-33]: Expr: 25967 + Stmt 0 [1-19]: Local (Immutable): + 0 + 1 + Stmt 1 [20-31]: Expr: 5 + Stmt 2 [21-30]: Expr: 6 + Stmt 3 [32-33]: Expr: 9 Exprs: - Expr 25958 [0-34] [Type Int]: Expr Block: 2097 - Expr 25959 [9-18] [Type (Int)[]]: Array: - 25960 - 25961 - 25962 - Expr 25960 [10-11] [Type Int]: Lit: Int(1) - Expr 25961 [13-14] [Type Int]: Lit: Int(2) - Expr 25962 [16-17] [Type Int]: Lit: Int(3) - Expr 25963 [20-31] [Type Int]: Expr Block: 2098 - Expr 25964 [21-30] [Type Int]: Call: - 25965 - 25966 - Expr 25965 [21-27] [Type ((Int)[] -> Int)]: Var: + Expr 0 [0-34] [Type Int]: Expr Block: 0 + Expr 1 [9-18] [Type (Int)[]]: Array: + 2 + 3 + 4 + Expr 2 [10-11] [Type Int]: Lit: Int(1) + Expr 3 [13-14] [Type Int]: Lit: Int(2) + Expr 4 [16-17] [Type Int]: Lit: Int(3) + Expr 5 [20-31] [Type Int]: Expr Block: 1 + Expr 6 [21-30] [Type Int]: Call: + 7 + 8 + Expr 7 [21-27] [Type ((Int)[] -> Int)]: Var: res: Item 1 (Package 0) generics: Int - Expr 25966 [28-29] [Type (Int)[]]: Var: Local 22 - Expr 25967 [32-33] [Type Int]: Lit: Int(3) + Expr 8 [28-29] [Type (Int)[]]: Var: Local 0 + Expr 9 [32-33] [Type Int]: Lit: Int(3) Pats: - Pat 2896 [5-6] [Type (Int)[]]: Bind: Ident 22 [5-6] "x""#]], + Pat 0 [5-6] [Type (Int)[]]: Bind: Ident 0 [5-6] "x""#]], &expect!["3"], ); } diff --git a/compiler/qsc_rca/tests/test_utils.rs b/compiler/qsc_rca/tests/test_utils.rs index ee16326427..55bb8aaf92 100644 --- a/compiler/qsc_rca/tests/test_utils.rs +++ b/compiler/qsc_rca/tests/test_utils.rs @@ -28,15 +28,14 @@ impl CompilationContext { LanguageFeatures::default(), ) .expect("should be able to create a new compiler"); - let mut lowerer = Lowerer::new(); - let fir_store = lower_hir_package_store(&mut lowerer, compiler.package_store()); + let fir_store = lower_hir_package_store(compiler.package_store()); let analyzer = Analyzer::init(&fir_store); let compute_properties = analyzer.analyze_all(); Self { compiler, fir_store, compute_properties, - lowerer, + lowerer: Lowerer::new(), } } @@ -144,12 +143,10 @@ pub fn check_last_statement_compute_properties( expect.assert_eq(&stmt_compute_properties.to_string()); } -fn lower_hir_package_store( - lowerer: &mut Lowerer, - hir_package_store: &HirPackageStore, -) -> PackageStore { +fn lower_hir_package_store(hir_package_store: &HirPackageStore) -> PackageStore { let mut fir_store = PackageStore::new(); for (id, unit) in hir_package_store { + let mut lowerer = Lowerer::new(); fir_store.insert( map_hir_package_to_fir(id), lowerer.lower_package(&unit.package), diff --git a/vscode/src/debugger/session.ts b/vscode/src/debugger/session.ts index f4780bb647..6bd307e3c5 100644 --- a/vscode/src/debugger/session.ts +++ b/vscode/src/debugger/session.ts @@ -418,7 +418,7 @@ export class QscDebugSession extends LoggingDebugSession { const bps: number[] = []; for (const file_bps of this.breakpoints.values()) { for (const bp of file_bps) { - if (bp && bp.id) { + if (bp?.id != null) { bps.push(bp.id); } }