diff --git a/spec/checker/src/form/bridge.rs b/spec/checker/src/form/bridge.rs index 14ba48c0..c6140a06 100644 --- a/spec/checker/src/form/bridge.rs +++ b/spec/checker/src/form/bridge.rs @@ -576,6 +576,26 @@ impl Built { Ok(s) } + /// The source of a `let` or `var` initial. + /// + /// A literal already built in this region is that node. A capture of the + /// same bits is not: it is the parent's value, often the dummy initial of + /// a branch output. This binding is a different value. Sharing them would + /// move the arm's empty text onto the parent's dummy, and the schedule + /// would not read back as the same form. An operand still shares a + /// capture, so a domain test and the operation it guards stay one value. + fn bind_atom(&self, sc: &mut Scope, a: &Atom) -> Result { + let Atom::K(t, l) = a else { + return self.src_atom(sc, a); + }; + if let Some(s) = lit_in_region(sc, t, l) { + return Ok(s); + } + let s = self.lit_node(sc, t, l)?; + sc.lits.push((t.clone(), l.clone(), s)); + Ok(s) + } + /// A value of `t` the test of a loop overwrites before the body reads it. /// The body receives the test's output, so this initial is not an operand /// of the computation. An owned initial is dropped when the test's result @@ -1121,13 +1141,13 @@ impl Built { match s { Stmt::Let(a) => { let local = self.stmt_local(s); - let src = self.src_atom(sc, a)?; + let src = self.bind_atom(sc, a)?; sc.env.insert(local, src); i += 1; } Stmt::Var(_, a) => { let local = self.stmt_local(s); - let src = self.src_atom(sc, a)?; + let src = self.bind_atom(sc, a)?; sc.env.insert(local, src); i += 1; } diff --git a/spec/checker/tests/break_fg8_witness.rs b/spec/checker/tests/break_fg8_witness.rs index b7a53e88..793b1d3e 100644 --- a/spec/checker/tests/break_fg8_witness.rs +++ b/spec/checker/tests/break_fg8_witness.rs @@ -370,11 +370,28 @@ fn corpus_baseline_on_50294e05() { assert_eq!(programs, 60, "spec/examples gained or lost a program"); assert_eq!( whole, - ["09_generics.rce", "35_nested_if.rce"], - "census whole, measured on 410bfd40" + [ + "08_traits.rce", + "09_generics.rce", + "18_while_bound.rce", + "24_lambda.rce", + "27_bitops.rce", + "35_nested_if.rce", + ], + "census whole" ); assert_eq!(entry_only, ["09_generics.rce"], "whole-entry-only"); - assert_eq!(with_user, ["35_nested_if.rce"], "whole-with-user"); + assert_eq!( + with_user, + [ + "08_traits.rce", + "18_while_bound.rce", + "24_lambda.rce", + "27_bitops.rce", + "35_nested_if.rce", + ], + "whole-with-user" + ); assert_eq!( construct_ok, [ @@ -410,9 +427,23 @@ fn corpus_baseline_on_50294e05() { ], "the syntactic floor moved" ); - assert!( - semantic.is_empty(), - "an example was admitted only as a body-break rewrite: {semantic:?}" + assert_eq!( + semantic, + [ + "03_fib_loop.rce", + "08_traits.rce", + "18_while_bound.rce", + "21_maps.rce", + "24_lambda.rce", + "25_labels.rce", + "27_bitops.rce", + "36_multiline_brackets.rce", + "43_simd_lanes.rce", + "45_byte_text.rce", + "46_u64.rce", + "49_loop_limit.rce", + ], + "option B: the flag form matches its schedule" ); let names = |tag: &str| root_tags.get(tag).map(|v| v.as_slice()).unwrap_or(&[]); assert_eq!( @@ -453,30 +484,22 @@ fn corpus_baseline_on_50294e05() { assert_eq!(names("exit"), ["02_hello_main.rce", "31_inventory.rce"]); assert_eq!( names("defect"), - ["06_option.rce", "07_error_union.rce", "20_strings.rce"] + [ + "06_option.rce", + "07_error_union.rce", + "20_strings.rce", + "22_tuples.rce", + ] ); assert_eq!( names("round-trip"), [ - "03_fib_loop.rce", - "08_traits.rce", "10_comptime.rce", "11_arena.rce", - "18_while_bound.rce", "19_floats.rce", - "21_maps.rce", - "22_tuples.rce", - "24_lambda.rce", - "25_labels.rce", - "27_bitops.rce", "28_slices.rce", "33_in_operator.rce", - "36_multiline_brackets.rce", "41_arena_bound_wrapping.rce", - "43_simd_lanes.rce", - "45_byte_text.rce", - "46_u64.rce", - "49_loop_limit.rce", ] ); assert_eq!( @@ -564,13 +587,9 @@ fn corpus_baseline_on_50294e05() { tagged("round-trip"), [ "03_fib_loop.rce", - "08_traits.rce", "11_arena.rce", "12_borrow.rce", - "18_while_bound.rce", - "24_lambda.rce", "25_labels.rce", - "27_bitops.rce", "28_slices.rce", "36_multiline_brackets.rce", "40_extern.rce", @@ -637,13 +656,14 @@ fn freq_search_break_stores_a_fresh_false() { let s = bridge::schedule(&f).unwrap_or_else(|e| panic!("mfind schedule: {}", e.line())); let back = bridge::construct(&s).unwrap_or_else(|e| panic!("mfind schedule construct: {}", e.line())); assert_eq!(fir::encode(&f), fir::encode(&back), "mfind construct(schedule(F)) is not F"); - // `fn freq` calls `mfind`. Its closure constructs, and the schedule - // constructs, so the file is not FG8. Byte identity of that whole - // closure is a separate spelling of the decimal helpers' empty text. + // `fn freq` calls `mfind` and the decimal helpers. The helpers' empty + // text is a `var` in the arm. It is not the branch output's dummy, + // which has the same bits. The closure round-trips. let freq = bridge::closure(&maps, "fn freq").expect("fn freq"); let ff = bridge::construct(&freq).unwrap_or_else(|e| panic!("fn freq: {}", e.line())); let fs = bridge::schedule(&ff).unwrap_or_else(|e| panic!("fn freq schedule: {}", e.line())); - bridge::construct(&fs).unwrap_or_else(|e| panic!("fn freq schedule construct: {}", e.line())); + let back = bridge::construct(&fs).unwrap_or_else(|e| panic!("fn freq schedule construct: {}", e.line())); + assert_eq!(fir::encode(&ff), fir::encode(&back), "fn freq construct(schedule(F)) is not F"); } #[test] diff --git a/spec/checker/tests/form_bridge.rs b/spec/checker/tests/form_bridge.rs index 4659dd1f..5597d793 100644 --- a/spec/checker/tests/form_bridge.rs +++ b/spec/checker/tests/form_bridge.rs @@ -1254,7 +1254,7 @@ fn whole_census( "node. A read of `fuel` outside the frame stays refused. Constant".to_string(), "flags are memo cells, not folded constants, and those reads stay".to_string(), "refused. `out` is in no whole-module set. The exact set global is 3.".to_string(), - "whole stays 2.".to_string(), + "whole is 6: 1 entry-only and 5 whose core contains a user function.".to_string(), String::new(), format!("programs\t{programs}"), format!("floor\t{covered}"), @@ -1481,13 +1481,15 @@ fn examples_are_covered_or_require_change() { assert_eq!(entry_only + with_user, whole, "whole split does not add up"); // Was 18, all entry-only: the core held only `entry`. Putting each // library function and each unobserved δ into the core drops that to - // 2, of which 1 still has no user function and 1 contains user code. + // 2. A `var` or `let` of a literal is now its own node, not a capture + // of a dummy with the same bits, so four more modules schedule back: + // 08_traits, 18_while_bound, 24_lambda, 27_bitops. whole is 6. assert_eq!( - whole, 2, + whole, 6, "the number of whole examples that construct changed; raise this floor and check the trace" ); assert_eq!(entry_only, 1, "entry-only whole cores"); - assert_eq!(with_user, 1, "whole cores that contain a user function"); + assert_eq!(with_user, 5, "whole cores that contain a user function"); assert_eq!( covered, 5, "the number of examples whose program functions round-trip changed; raise the ratchet, do not lower it" diff --git a/spec/checker/tests/form_bridge_census.txt b/spec/checker/tests/form_bridge_census.txt index 006b7c90..69d34acd 100644 --- a/spec/checker/tests/form_bridge_census.txt +++ b/spec/checker/tests/form_bridge_census.txt @@ -30,19 +30,19 @@ limit of the run, not a field of the module, so that frame is not a node. A read of `fuel` outside the frame stays refused. Constant flags are memo cells, not folded constants, and those reads stay refused. `out` is in no whole-module set. The exact set global is 3. -whole stays 2. +whole is 6: 1 entry-only and 5 whose core contains a user function. programs 60 floor 5 -semantic 0 -whole 2 +semantic 12 +whole 6 whole-entry-only 1 -whole-with-user 1 +whole-with-user 5 whole modules, top 10 by modules unblocked (one tag, or a pair) unblocks set 15 break -15 round-trip +11 round-trip 8 lowering 5 break,exit 3 global @@ -55,11 +55,11 @@ unblocks set whole modules, every exact set modules set 15 break -15 round-trip +11 round-trip 8 lowering +6 clear 5 break,exit 3 global -2 clear 2 defect 2 defect,exit,loop 2 exit @@ -73,15 +73,15 @@ modules set program roots, every exact set modules set 17 break -17 round-trip +17 clear 8 lowering -5 clear -2 defect -2 defect,round-trip +5 round-trip +3 defect 2 exit 2 no-root 1 break,defect 1 break,round-trip +1 defect,round-trip 1 global 1 global,loop 1 loop @@ -90,12 +90,12 @@ modules module whole roots user global-sites 01_counter.rce break break user 02_hello_main.rce exit exit user -03_fib_loop.rce round-trip round-trip user +03_fib_loop.rce round-trip clear user 04_bank_account.rce break break user 05_kind_match.rce break break user 06_option.rce break,defect break,defect user 07_error_union.rce defect,exit,loop defect user -08_traits.rce round-trip round-trip user +08_traits.rce clear clear user 09_generics.rce clear no-root entry-only 10_comptime.rce global round-trip user entry: global: g6 is not part of the working context ω holds 11_arena.rce round-trip round-trip user @@ -105,15 +105,15 @@ module whole roots user global-sites 15_actor.rce lowering lowering lowering not covered by the lowering: the type chan i64 16_multi_region.rce break,exit break user 17_traffic_light.rce break break user -18_while_bound.rce round-trip round-trip user +18_while_bound.rce clear clear user 19_floats.rce break round-trip user 20_strings.rce defect,exit,loop defect user -21_maps.rce exit round-trip user -22_tuples.rce defect defect,round-trip user +21_maps.rce exit clear user +22_tuples.rce defect defect user 23_patterns.rce break break user -24_lambda.rce round-trip round-trip user -25_labels.rce round-trip round-trip user -27_bitops.rce round-trip round-trip user +24_lambda.rce clear clear user +25_labels.rce round-trip clear user +27_bitops.rce clear clear user 28_slices.rce round-trip round-trip user 29_nested_kind.rce lowering lowering lowering not covered by the lowering: a recursive type 30_state_machine_guarded.rce break break user @@ -122,20 +122,20 @@ module whole roots user global-sites 33_in_operator.rce defect defect,round-trip user 34_chan_types.rce lowering lowering lowering not covered by the lowering: the type chan (u64, text) 35_nested_if.rce clear clear user -36_multiline_brackets.rce round-trip round-trip user +36_multiline_brackets.rce round-trip clear user 37_actor_spawn.rce lowering lowering lowering not covered by the lowering: the type chan u64 38_hex_bin.rce break no-root entry-only 39_structural_recursion.rce lowering lowering lowering not covered by the lowering: a recursive type 40_extern.rce round-trip clear user 41_arena_bound_wrapping.rce round-trip round-trip user 42_f32.rce bound,break clear user -43_simd_lanes.rce round-trip round-trip user +43_simd_lanes.rce round-trip clear user 44_device_region.rce break break user -45_byte_text.rce exit,global round-trip user check 7: global: g3 is not part of the working context ω holds -46_u64.rce global round-trip user check 10: global: g3 is not part of the working context ω holds | check 14: global: g3 is not part of the working context ω holds | check 7: global: g3 is not part of the working context ω holds | check 8: global: g3 is not part of the working context ω holds | check 9: global: g3 is not part of the working context ω holds +45_byte_text.rce exit,global clear user check 7: global: g3 is not part of the working context ω holds +46_u64.rce global clear user check 10: global: g3 is not part of the working context ω holds | check 14: global: g3 is not part of the working context ω holds | check 7: global: g3 is not part of the working context ω holds | check 8: global: g3 is not part of the working context ω holds | check 9: global: g3 is not part of the working context ω holds 47_select_fair.rce lowering lowering lowering not covered by the lowering: the type chan u64 48_linear_handle.rce round-trip clear user -49_loop_limit.rce round-trip round-trip user +49_loop_limit.rce round-trip clear user 50_iterators.rce global,loop global,loop user check 27: global: g3 is not part of the working context ω holds | entry: global: g3 is not part of the working context ω holds | gen iter evens(int{u64}[0, 18446744073709551615]): global: g3 is not part of the working context ω holds | gen iter naturals(): global: g3 is not part of the working context ω holds 51_refined_input.rce break,defect,exit break user 52_context_text.rce break,exit break user