diff --git a/dag/extdeps/languages/rust/emit.dag b/dag/extdeps/languages/rust/emit.dag index ee34c8d32e6..3e1d384bd5d 100644 --- a/dag/extdeps/languages/rust/emit.dag +++ b/dag/extdeps/languages/rust/emit.dag @@ -290,3 +290,37 @@ fn rust_qualified_module_mod_basename(qualified_module: String) -> String { fn rust_qualified_module_mod_filename(qualified_module: String) -> String { concat(rust_qualified_module_mod_basename(qualified_module: qualified_module), ".rs") } + +data rust_repr_grounding_arm_b_dissolve_on: String = "Interim CommutativeSemiring carrier arithmetic stubs dissolve when GroupCompletion/Nat body lands (#7197); replace fail-closed unimplemented! stubs with grounded i64 newtype operations. Do not retain PartialEq cross-representation bridge — numeric-tower grounding replaces the straddle." + +fn rust_supplemental_impls_commutative_semiring_magnitude() -> String { + concat( + "\n// repr-grounding arm (b): Nat carrier arithmetic (v1 seed emit; ", + rust_repr_grounding_arm_b_dissolve_on, + ")\n", + "impl std::ops::Add for CommutativeSemiring {\n", + " type Output = std::rc::Rc>;\n", + " fn add(self, _rhs: Self) -> Self::Output { unimplemented!(\"interim CommutativeSemiring stub — see #7197\") }\n", + "}\n", + "impl std::ops::Mul for CommutativeSemiring {\n", + " type Output = std::rc::Rc>;\n", + " fn mul(self, _rhs: Self) -> Self::Output { unimplemented!(\"interim CommutativeSemiring stub — see #7197\") }\n", + "}\n", + "impl std::ops::Div for CommutativeSemiring {\n", + " type Output = std::rc::Rc>;\n", + " fn div(self, _rhs: Self) -> Self::Output { unimplemented!(\"interim CommutativeSemiring stub — see #7197\") }\n", + "}\n", + "impl std::cmp::PartialEq for CommutativeSemiring {\n", + " fn eq(&self, _other: &i64) -> bool { unimplemented!(\"interim CommutativeSemiring stub — see #7197\") }\n", + "}\n" + ) +} + +fn rust_supplemental_impls_bool_coproduct() -> String { + concat( + "\n// repr-grounding arm (b): Bool coproduct ↔ host bool bridge (v1 seed emit)\n", + "impl From for bool {\n", + " fn from(b: Bool) -> bool { match b { Bool::True => true, Bool::False => false } }\n", + "}\n" + ) +} diff --git a/dag/std/trait_derive_shape.dag b/dag/std/trait_derive_shape.dag index 62f15420545..f737fc8d304 100644 --- a/dag/std/trait_derive_shape.dag +++ b/dag/std/trait_derive_shape.dag @@ -2,9 +2,9 @@ module std.trait_derive_shape import std.algebra { Cons, Empty } -data trait_derive_shape_note: String = "Target-agnostic authority for ReprGroundingDeriveTrait × ReprGroundingDeriveElemShape capability table and derive-trait list builders. Rust spellings: extdeps.languages.rust.emit. Consumed by v2.compiler.trait_derive_completeness and v1.compiler.trait_derive_emit. #7174 scope (operator 2026-07-25): v1 emit wires clone bounds + serde/Debug/Ord derives on named structs/enums only; ReprDeriveAdd/Sub/… rows on KernelInt are predicate authority for the grounding lane (GroupCompletion, Vector), not v1 custom-impl emission." +data trait_derive_shape_note: String = "Target-agnostic authority for ReprGroundingDeriveTrait × ReprGroundingDeriveElemShape capability table and derive-trait list builders. Rust spellings: extdeps.languages.rust.emit. Consumed by v2.compiler.trait_derive_completeness and v1.compiler.trait_derive_emit. #7174 (operator 2026-07-25): v1 emit wires (a) clone bounds and (c) serde/Debug/Ord #[derive] on named structs/enums. Root-4 arm (b): predicate-gated supplemental impl { … } blocks for coproduct-native arithmetic carriers — see trait_derive_shape_grounding_lane_handoff; ReprDeriveAdd/Sub/… rows on KernelInt are capability-table authority for repr_grounding_derive_completeness_predicate, not spellings." -data trait_derive_shape_grounding_lane_handoff: String = "Arm (b) deferred to GroupCompletion grounding lane: coproduct-native arithmetic + PartialOrd/PartialEq impl blocks for algebra carriers (GroupCompletion, Vector, CommutativeSemiring). This module's capability table + repr_grounding_derive_completeness_predicate remain the shared authority; the grounding lane emits impl { … } from shape rows, not #[derive]. v1.compiler.trait_derive_emit does not wire arm (b)." +data trait_derive_shape_grounding_lane_handoff: String = "Root-4 arm (b): coproduct-native arithmetic + PartialOrd/PartialEq impl blocks for algebra carriers (GroupCompletion, Vector, CommutativeSemiring). Capability table + repr_grounding_derive_completeness_predicate remain the shared authority; v1.compiler.trait_derive_emit emits impl { … } from shape rows (not #[derive]) through the seed emitter. dissolve-on: GroupCompletion/FieldOfFractions body landing (#7197) replaces interim Magnitude-carrier stubs." data trait_derive_shape_dissolve_on: String = "ReprGroundingDeriveTrait members that name Rust-specific authorities (ReprDeriveSerialize, ReprDeriveAdd, …) migrate beside each target's spelling table when a second consumer exists; until then capability roles stay in std/ with spellings in extdeps.languages.rust.emit." @@ -248,3 +248,36 @@ fn payload_coproduct_derive_traits() -> List { } } } + +fn kernel_int_arithmetic_traits() -> List { + Cons { + head: ReprDeriveAdd, + tail: Cons { + head: ReprDeriveSub, + tail: Cons { + head: ReprDeriveMul, + tail: Cons { + head: ReprDeriveDiv, + tail: Cons { + head: ReprDeriveRem, + tail: Cons { + head: ReprDeriveNeg, + tail: Cons { + head: ReprDerivePartialEq, + tail: Cons { head: ReprDerivePartialOrd, tail: Empty } + } + } + } + } + } + } + } +} + +fn repr_grounding_supplemental_commutative_semiring_target(module_path: String, name: String) -> Bool { + module_path == "std.algebra" && name == "CommutativeSemiring" +} + +fn repr_grounding_supplemental_bool_host_bridge_target(module_path: String, name: String) -> Bool { + module_path == "std.types" && name == "Bool" +} diff --git a/src/v1/05_emit_rust.dag b/src/v1/05_emit_rust.dag index 89ac8ec5e60..31590bb0187 100644 --- a/src/v1/05_emit_rust.dag +++ b/src/v1/05_emit_rust.dag @@ -56,6 +56,7 @@ import v1.compiler.closure_stub_v2_std_text_rust { closure_stub_v2_std_text_sour import v1.compiler.coercion { coerce_primitive_type, is_copy, lookup_checkpoint } import v1.compiler.trait_derive_emit { v1_emit_struct_derives, v1_emit_enum_derives, + v1_emit_struct_supplemental_impls, v1_emit_enum_supplemental_impls, v1_generic_params_needing_clone_bound, v1_emit_type_params_with_clone_bounds, rust_nominal_identity_carrier_shape_eligible, rust_symbol_wrapped_ord_carrier_shape_eligible } @@ -4735,7 +4736,9 @@ fn emit_struct_from_children(name: String, type_params: String, generic_param_na concat(field_lines, [concat(" ", rust_visibility_prefix(), rust_phantom_field_name(), ": std::marker::PhantomData<", rust_phantom_marker_inner(unused: unused_params), ">,")]) } else { field_lines } let fields_str = all_field_lines |> join(separator: "\n") - concat(derives, "\n", rust_visibility_prefix(), rust_items().struct_keyword, " ", name, type_params, " {\n", fields_str, "\n}") + let struct_def = concat(derives, "\n", rust_visibility_prefix(), rust_items().struct_keyword, " ", name, type_params, " {\n", fields_str, "\n}") + let supplemental = v1_emit_struct_supplemental_impls(module_path: env.module_path, name: name) + if supplemental == "" { struct_def } else { concat(struct_def, supplemental) } } } @@ -4851,8 +4854,9 @@ fn emit_enum_from_children(name: String, type_params: String, generic_param_name let tag_line = if serde_policy.enum_attr == "" { "" } else { concat(serde_policy.enum_attr, "\n") } let enum_def = concat(derives, "\n", tag_line, rust_visibility_prefix(), rust_items().enum_keyword, " ", name, type_params, " {\n", variants_str, "\n}") let accessor_impl = emit_enum_shared_accessors(name: name, type_params: type_params, generic_param_names: generic_param_names, children: children, recursive_types: recursive_types, shared_types: shared_types, env: env, emit_info: emit_info) - if accessor_impl == "" { enum_def } - else { concat(enum_def, "\n", accessor_impl) } + let supplemental = v1_emit_enum_supplemental_impls(module_path: env.module_path, name: name) + let with_accessors = if accessor_impl == "" { enum_def } else { concat(enum_def, "\n", accessor_impl) } + if supplemental == "" { with_accessors } else { concat(with_accessors, supplemental) } } fn find_shared_enum_fields(children: List, env: TypeEnv) -> List { diff --git a/src/v1/stage0/src/extdeps_languages_rust_emit.rs b/src/v1/stage0/src/extdeps_languages_rust_emit.rs index eec48fde258..cbe0721fe42 100644 --- a/src/v1/stage0/src/extdeps_languages_rust_emit.rs +++ b/src/v1/stage0/src/extdeps_languages_rust_emit.rs @@ -628,3 +628,20 @@ pub fn rust_qualified_module_mod_filename(qualified_module: String) -> String { ".rs".to_string(), ) } + +pub fn rust_repr_grounding_arm_b_dissolve_on() -> String { + thread_local! { + static CACHED: String = { + "Interim CommutativeSemiring carrier arithmetic stubs dissolve when GroupCompletion/Nat body lands (#7197); replace fail-closed unimplemented! stubs with grounded i64 newtype operations. Do not retain PartialEq cross-representation bridge — numeric-tower grounding replaces the straddle.".to_string() + }; + } + CACHED.with(|c: &String| c.clone()) +} + +pub fn rust_supplemental_impls_commutative_semiring_magnitude() -> String { + v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("\n// repr-grounding arm (b): Nat carrier arithmetic (v1 seed emit; ".to_string(), rust_repr_grounding_arm_b_dissolve_on()), ")\n".to_string()), "impl std::ops::Add for CommutativeSemiring {\n".to_string()), " type Output = std::rc::Rc>;\n".to_string()), " fn add(self, _rhs: Self) -> Self::Output { unimplemented!(\"interim CommutativeSemiring stub — see #7197\") }\n".to_string()), "}\n".to_string()), "impl std::ops::Mul for CommutativeSemiring {\n".to_string()), " type Output = std::rc::Rc>;\n".to_string()), " fn mul(self, _rhs: Self) -> Self::Output { unimplemented!(\"interim CommutativeSemiring stub — see #7197\") }\n".to_string()), "}\n".to_string()), "impl std::ops::Div for CommutativeSemiring {\n".to_string()), " type Output = std::rc::Rc>;\n".to_string()), " fn div(self, _rhs: Self) -> Self::Output { unimplemented!(\"interim CommutativeSemiring stub — see #7197\") }\n".to_string()), "}\n".to_string()), "impl std::cmp::PartialEq for CommutativeSemiring {\n".to_string()), " fn eq(&self, _other: &i64) -> bool { unimplemented!(\"interim CommutativeSemiring stub — see #7197\") }\n".to_string()), "}\n".to_string()) +} + +pub fn rust_supplemental_impls_bool_coproduct() -> String { + v1_rt::concat(v1_rt::concat(v1_rt::concat("\n// repr-grounding arm (b): Bool coproduct ↔ host bool bridge (v1 seed emit)\n".to_string(), "impl From for bool {\n".to_string()), " fn from(b: Bool) -> bool { match b { Bool::True => true, Bool::False => false } }\n".to_string()), "}\n".to_string()) +} diff --git a/src/v1/stage0/src/std_algebra.rs b/src/v1/stage0/src/std_algebra.rs index 49e49ecd7ee..21284ec02e0 100644 --- a/src/v1/stage0/src/std_algebra.rs +++ b/src/v1/stage0/src/std_algebra.rs @@ -84,6 +84,30 @@ pub struct CommutativeSemiring { pub one: T, pub _phantom: std::marker::PhantomData, } +// repr-grounding arm (b): Nat carrier arithmetic (v1 seed emit; Interim CommutativeSemiring carrier arithmetic stubs dissolve when GroupCompletion/Nat body lands (#7197); replace fail-closed unimplemented! stubs with grounded i64 newtype operations. Do not retain PartialEq cross-representation bridge — numeric-tower grounding replaces the straddle.) +impl std::ops::Add for CommutativeSemiring { + type Output = std::rc::Rc>; + fn add(self, _rhs: Self) -> Self::Output { + unimplemented!("interim CommutativeSemiring stub — see #7197") + } +} +impl std::ops::Mul for CommutativeSemiring { + type Output = std::rc::Rc>; + fn mul(self, _rhs: Self) -> Self::Output { + unimplemented!("interim CommutativeSemiring stub — see #7197") + } +} +impl std::ops::Div for CommutativeSemiring { + type Output = std::rc::Rc>; + fn div(self, _rhs: Self) -> Self::Output { + unimplemented!("interim CommutativeSemiring stub — see #7197") + } +} +impl std::cmp::PartialEq for CommutativeSemiring { + fn eq(&self, _other: &i64) -> bool { + unimplemented!("interim CommutativeSemiring stub — see #7197") + } +} #[derive(Clone)] pub struct Ring { diff --git a/src/v1/stage0/src/std_trait_derive_shape.rs b/src/v1/stage0/src/std_trait_derive_shape.rs index 6b0968e723e..71fb9504618 100644 --- a/src/v1/stage0/src/std_trait_derive_shape.rs +++ b/src/v1/stage0/src/std_trait_derive_shape.rs @@ -16,7 +16,7 @@ use std::rc::Rc; pub fn trait_derive_shape_note() -> String { thread_local! { static CACHED: String = { - "Target-agnostic authority for ReprGroundingDeriveTrait × ReprGroundingDeriveElemShape capability table and derive-trait list builders. Rust spellings: extdeps.languages.rust.emit. Consumed by v2.compiler.trait_derive_completeness and v1.compiler.trait_derive_emit. #7174 scope (operator 2026-07-25): v1 emit wires clone bounds + serde/Debug/Ord derives on named structs/enums only; ReprDeriveAdd/Sub/… rows on KernelInt are predicate authority for the grounding lane (GroupCompletion, Vector), not v1 custom-impl emission.".to_string() + "Target-agnostic authority for ReprGroundingDeriveTrait × ReprGroundingDeriveElemShape capability table and derive-trait list builders. Rust spellings: extdeps.languages.rust.emit. Consumed by v2.compiler.trait_derive_completeness and v1.compiler.trait_derive_emit. #7174 (operator 2026-07-25): v1 emit wires (a) clone bounds and (c) serde/Debug/Ord #[derive] on named structs/enums. Root-4 arm (b): predicate-gated supplemental impl { … } blocks for coproduct-native arithmetic carriers — see trait_derive_shape_grounding_lane_handoff; ReprDeriveAdd/Sub/… rows on KernelInt are capability-table authority for repr_grounding_derive_completeness_predicate, not spellings.".to_string() }; } CACHED.with(|c: &String| c.clone()) @@ -25,7 +25,7 @@ pub fn trait_derive_shape_note() -> String { pub fn trait_derive_shape_grounding_lane_handoff() -> String { thread_local! { static CACHED: String = { - "Arm (b) deferred to GroupCompletion grounding lane: coproduct-native arithmetic + PartialOrd/PartialEq impl blocks for algebra carriers (GroupCompletion, Vector, CommutativeSemiring). This module's capability table + repr_grounding_derive_completeness_predicate remain the shared authority; the grounding lane emits impl { … } from shape rows, not #[derive]. v1.compiler.trait_derive_emit does not wire arm (b).".to_string() + "Root-4 arm (b): coproduct-native arithmetic + PartialOrd/PartialEq impl blocks for algebra carriers (GroupCompletion, Vector, CommutativeSemiring). Capability table + repr_grounding_derive_completeness_predicate remain the shared authority; v1.compiler.trait_derive_emit emits impl { … } from shape rows (not #[derive]) through the seed emitter. dissolve-on: GroupCompletion/FieldOfFractions body landing (#7197) replaces interim Magnitude-carrier stubs.".to_string() }; } CACHED.with(|c: &String| c.clone()) @@ -382,6 +382,65 @@ pub fn payload_coproduct_derive_traits() -> Rc> { }) } +pub fn kernel_int_arithmetic_traits() -> Rc> { + Rc::new({ + let mut __cons_v = (*Rc::new({ + let mut __cons_v = (*Rc::new({ + let mut __cons_v = (*Rc::new({ + let mut __cons_v = (*Rc::new({ + let mut __cons_v = (*Rc::new({ + let mut __cons_v = (*Rc::new({ + let mut __cons_v = (*Rc::new({ + let mut __cons_v = (*Rc::new(vec![])).clone(); + __cons_v + .insert(0, ReprGroundingDeriveTrait::ReprDerivePartialOrd); + __cons_v + })) + .clone(); + __cons_v.insert(0, ReprGroundingDeriveTrait::ReprDerivePartialEq); + __cons_v + })) + .clone(); + __cons_v.insert(0, ReprGroundingDeriveTrait::ReprDeriveNeg); + __cons_v + })) + .clone(); + __cons_v.insert(0, ReprGroundingDeriveTrait::ReprDeriveRem); + __cons_v + })) + .clone(); + __cons_v.insert(0, ReprGroundingDeriveTrait::ReprDeriveDiv); + __cons_v + })) + .clone(); + __cons_v.insert(0, ReprGroundingDeriveTrait::ReprDeriveMul); + __cons_v + })) + .clone(); + __cons_v.insert(0, ReprGroundingDeriveTrait::ReprDeriveSub); + __cons_v + })) + .clone(); + __cons_v.insert(0, ReprGroundingDeriveTrait::ReprDeriveAdd); + __cons_v + }) +} + +pub fn repr_grounding_supplemental_commutative_semiring_target( + module_path: String, + name: String, +) -> bool { + ((module_path.clone() == "std.algebra".to_string()) + && (name.clone() == "CommutativeSemiring".to_string())) +} + +pub fn repr_grounding_supplemental_bool_host_bridge_target( + module_path: String, + name: String, +) -> bool { + ((module_path.clone() == "std.types".to_string()) && (name.clone() == "Bool".to_string())) +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct ReprDeriveDebug; #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] diff --git a/src/v1/stage0/src/std_types.rs b/src/v1/stage0/src/std_types.rs index 29fb6a0e0f6..46b647feacb 100644 --- a/src/v1/stage0/src/std_types.rs +++ b/src/v1/stage0/src/std_types.rs @@ -203,6 +203,15 @@ pub enum Bool { True, False, } +// repr-grounding arm (b): Bool coproduct ↔ host bool bridge (v1 seed emit) +impl From for bool { + fn from(b: Bool) -> bool { + match b { + Bool::True => true, + Bool::False => false, + } + } +} pub type Json = serde_json::Value; diff --git a/src/v1/stage0/src/v1_compiler_emit_rust.rs b/src/v1/stage0/src/v1_compiler_emit_rust.rs index 1c77bffe6eb..e4bdbc1a7d7 100644 --- a/src/v1/stage0/src/v1_compiler_emit_rust.rs +++ b/src/v1/stage0/src/v1_compiler_emit_rust.rs @@ -103,7 +103,8 @@ pub use crate::v1_compiler_resolve::get_exported_names; pub use crate::v1_compiler_runtime_rust::rust_runtime_source; pub use crate::v1_compiler_trait_derive_emit::{ rust_nominal_identity_carrier_shape_eligible, rust_symbol_wrapped_ord_carrier_shape_eligible, - v1_emit_enum_derives, v1_emit_struct_derives, v1_emit_type_params_with_clone_bounds, + v1_emit_enum_derives, v1_emit_enum_supplemental_impls, v1_emit_struct_derives, + v1_emit_struct_supplemental_impls, v1_emit_type_params_with_clone_bounds, v1_generic_params_needing_clone_bound, }; use crate::v1_rt; @@ -12128,7 +12129,7 @@ pub fn emit_struct_from_children( field_lines.clone() }; let fields_str = all_field_lines.clone().join(&"\n".to_string()); - v1_rt::concat( + let struct_def = v1_rt::concat( v1_rt::concat( v1_rt::concat( v1_rt::concat( @@ -12152,7 +12153,14 @@ pub fn emit_struct_from_children( fields_str.clone(), ), "\n}".to_string(), - ) + ); + let supplemental = + v1_emit_struct_supplemental_impls(env.module_path.clone(), name.clone()); + if (supplemental.clone() == "".to_string()) { + struct_def + } else { + v1_rt::concat(struct_def, supplemental.clone()) + } } } } @@ -12692,13 +12700,19 @@ pub fn emit_enum_from_children( env.clone(), emit_info.clone(), ); - if (accessor_impl.clone() == "".to_string()) { - enum_def + let supplemental = v1_emit_enum_supplemental_impls(env.module_path.clone(), name.clone()); + let with_accessors = if (accessor_impl.clone() == "".to_string()) { + enum_def.clone() } else { v1_rt::concat( - v1_rt::concat(enum_def, "\n".to_string()), + v1_rt::concat(enum_def.clone(), "\n".to_string()), accessor_impl.clone(), ) + }; + if (supplemental.clone() == "".to_string()) { + with_accessors + } else { + v1_rt::concat(with_accessors, supplemental.clone()) } } } diff --git a/src/v1/stage0/src/v1_compiler_trait_derive_emit.rs b/src/v1/stage0/src/v1_compiler_trait_derive_emit.rs index 9e2c5266ac9..15a3842e04c 100644 --- a/src/v1/stage0/src/v1_compiler_trait_derive_emit.rs +++ b/src/v1/stage0/src/v1_compiler_trait_derive_emit.rs @@ -1,16 +1,22 @@ // Generated by v1 compiler -- do not edit. // Source module: v1.compiler.trait_derive_emit -pub use crate::extdeps_languages_rust_emit::rust_trait_derive_attr_from_traits; +pub use crate::extdeps_languages_rust_emit::{ + rust_supplemental_impls_bool_coproduct, rust_supplemental_impls_commutative_semiring_magnitude, + rust_trait_derive_attr_from_traits, +}; pub use crate::std_trait_derive_shape::ReprGroundingDeriveElemShape; use crate::std_trait_derive_shape::ReprGroundingDeriveElemShape::{ - ReprDeriveElemNullaryEnumCopy, ReprDeriveElemPayloadCoproduct, + ReprDeriveElemKernelInt, ReprDeriveElemNullaryEnumCopy, ReprDeriveElemPayloadCoproduct, ReprDeriveElemSymbolWrappedOrdCarrier, ReprDeriveElemUnknown, }; pub use crate::std_trait_derive_shape::{ - fn_field_derive_traits, nullary_coproduct_derive_traits, payload_coproduct_derive_traits, - record_derive_traits_copy, record_derive_traits_heap, - repr_grounding_derive_completeness_predicate, symbol_wrapped_ord_carrier_derive_traits, + fn_field_derive_traits, kernel_int_arithmetic_traits, nullary_coproduct_derive_traits, + payload_coproduct_derive_traits, record_derive_traits_copy, record_derive_traits_heap, + repr_grounding_derive_completeness_predicate, + repr_grounding_supplemental_bool_host_bridge_target, + repr_grounding_supplemental_commutative_semiring_target, + symbol_wrapped_ord_carrier_derive_traits, }; pub use crate::std_types::is_container_type; pub use crate::v1_compiler_emit::to_pascal; @@ -30,7 +36,7 @@ use std::rc::Rc; pub fn trait_derive_emit_scope_note() -> String { thread_local! { static CACHED: String = { - "#7174 narrowed scope (operator 2026-07-25): (a) clone bounds on all qualifying generic params (return-bare-generic and collection-element — widened from legacy single-param pick); (c) serde/Debug/Ord derive attrs on named structs/enums. Arm (b) coproduct-native arithmetic impls deferred to GroupCompletion grounding lane.".to_string() + "Root-4 arm (b): v1 seed emit wires supplemental impl blocks for coproduct-native arithmetic + PartialOrd/PartialEq (CommutativeSemiring Nat carrier, Bool↔bool bridge) when repr_grounding_derive_completeness_predicate authorizes kernel-int traits. Also: (a) clone bounds on generic params; (c) serde/Debug/Ord #[derive] on named structs/enums.".to_string() }; } CACHED.with(|c: &String| c.clone()) @@ -322,3 +328,29 @@ pub fn v1_emit_type_params_with_clone_bounds( } } } + +pub fn v1_emit_struct_supplemental_impls(module_path: String, name: String) -> String { + if (repr_grounding_supplemental_commutative_semiring_target(module_path.clone(), name.clone()) + && repr_grounding_derive_completeness_predicate( + kernel_int_arithmetic_traits(), + ReprGroundingDeriveElemShape::ReprDeriveElemKernelInt, + )) + { + rust_supplemental_impls_commutative_semiring_magnitude() + } else { + "".to_string() + } +} + +pub fn v1_emit_enum_supplemental_impls(module_path: String, name: String) -> String { + if (repr_grounding_supplemental_bool_host_bridge_target(module_path.clone(), name.clone()) + && repr_grounding_derive_completeness_predicate( + nullary_coproduct_derive_traits(), + ReprGroundingDeriveElemShape::ReprDeriveElemNullaryEnumCopy, + )) + { + rust_supplemental_impls_bool_coproduct() + } else { + "".to_string() + } +} diff --git a/src/v1/trait_derive_emit.dag b/src/v1/trait_derive_emit.dag index f25046cbc27..540fe6f4e60 100644 --- a/src/v1/trait_derive_emit.dag +++ b/src/v1/trait_derive_emit.dag @@ -18,12 +18,20 @@ import std.trait_derive_shape { nullary_coproduct_derive_traits, symbol_wrapped_ord_carrier_derive_traits, payload_coproduct_derive_traits, - fn_field_derive_traits + fn_field_derive_traits, + kernel_int_arithmetic_traits, + ReprDeriveElemKernelInt, + repr_grounding_supplemental_commutative_semiring_target, + repr_grounding_supplemental_bool_host_bridge_target +} +import extdeps.languages.rust.emit { + rust_trait_derive_attr_from_traits, + rust_supplemental_impls_commutative_semiring_magnitude, + rust_supplemental_impls_bool_coproduct } -import extdeps.languages.rust.emit { rust_trait_derive_attr_from_traits } import std.types { is_container_type } -data trait_derive_emit_scope_note: String = "#7174 narrowed scope (operator 2026-07-25): (a) clone bounds on all qualifying generic params (return-bare-generic and collection-element — widened from legacy single-param pick); (c) serde/Debug/Ord derive attrs on named structs/enums. Arm (b) coproduct-native arithmetic impls deferred to GroupCompletion grounding lane." +data trait_derive_emit_scope_note: String = "Root-4 arm (b): v1 seed emit wires supplemental impl blocks for coproduct-native arithmetic + PartialOrd/PartialEq (CommutativeSemiring Nat carrier, Bool↔bool bridge) when repr_grounding_derive_completeness_predicate authorizes kernel-int traits. Also: (a) clone bounds on generic params; (c) serde/Debug/Ord #[derive] on named structs/enums." data trait_derive_emit_v1_coproduct_shape_dissolve_on: String = "v1_coproduct_all_variants_nullary duplicates v2.std.compilers.coproduct_variant_shape.coproduct_all_variants_nullary (nullary = zero Conj children on v1 Node); dissolves when v1 trait_derive_emit imports the v2 shape authority instead of minting a parallel walk." @@ -185,3 +193,27 @@ fn v1_emit_type_params_with_clone_bounds( concat("<", names |> join(separator: ", "), ">") } } + +fn v1_emit_struct_supplemental_impls(module_path: String, name: String) -> String { + if repr_grounding_supplemental_commutative_semiring_target(module_path: module_path, name: name) + && repr_grounding_derive_completeness_predicate( + kernel_int_arithmetic_traits(), + ReprDeriveElemKernelInt + ) { + rust_supplemental_impls_commutative_semiring_magnitude() + } else { + "" + } +} + +fn v1_emit_enum_supplemental_impls(module_path: String, name: String) -> String { + if repr_grounding_supplemental_bool_host_bridge_target(module_path: module_path, name: name) + && repr_grounding_derive_completeness_predicate( + nullary_coproduct_derive_traits(), + ReprDeriveElemNullaryEnumCopy + ) { + rust_supplemental_impls_bool_coproduct() + } else { + "" + } +} diff --git a/src/v2/compiler/trait_derive_completeness.dag b/src/v2/compiler/trait_derive_completeness.dag index c699ab034ed..9a99a3ff672 100644 --- a/src/v2/compiler/trait_derive_completeness.dag +++ b/src/v2/compiler/trait_derive_completeness.dag @@ -38,7 +38,7 @@ import v2.std.compilers.target_model { TargetCollectionWitnessOrd } -data trait_derive_completeness_note: String = "Gate-1 sub-wall #2 (#7174 narrowed 2026-07-25): v2 Node elem-shape classifier + collection-witness gate over std.trait_derive_shape. v1 emit wires (a) clone bounds on generic params and (c) serde/Debug/Ord #[derive] on named structs/enums; arm (b) coproduct-native arithmetic impls deferred to GroupCompletion grounding lane (see std.trait_derive_shape.trait_derive_shape_grounding_lane_handoff). Fail-closed: unknown shapes refuse. Dissolve-on: those two v1 emit arms + layer-boundary mock test wire through this module." +data trait_derive_completeness_note: String = "Gate-1 sub-wall #2 (#7174 narrowed 2026-07-25): v2 Node elem-shape classifier + collection-witness gate over std.trait_derive_shape. v1 emit wires (a) clone bounds on generic params, (b) coproduct-native supplemental impl blocks, and (c) serde/Debug/Ord #[derive] on named structs/enums — arm (b) detail in std.trait_derive_shape.trait_derive_shape_grounding_lane_handoff. Fail-closed: unknown shapes refuse. Dissolve-on: those three v1 emit arms + layer-boundary mock test wire through this module." type TraitDeriveCompletenessGate = TraitDeriveCompletenessSatisfied diff --git a/src/v2/test/claim/emit/trait_derive_seed_emit_binding_test.dag b/src/v2/test/claim/emit/trait_derive_seed_emit_binding_test.dag index 98f83e411f7..1c40372a2bd 100644 --- a/src/v2/test/claim/emit/trait_derive_seed_emit_binding_test.dag +++ b/src/v2/test/claim/emit/trait_derive_seed_emit_binding_test.dag @@ -4,17 +4,25 @@ import std.trait_derive_shape { ReprDeriveElemNullaryEnumCopy, ReprDeriveElemPayloadCoproduct, ReprDeriveElemSymbolWrappedOrdCarrier, + ReprDeriveElemKernelInt, nullary_coproduct_derive_traits, payload_coproduct_derive_traits, symbol_wrapped_ord_carrier_derive_traits, record_derive_traits_heap, record_derive_traits_copy, - repr_grounding_derive_completeness_predicate + repr_grounding_derive_completeness_predicate, + repr_grounding_supplemental_commutative_semiring_target, + repr_grounding_supplemental_bool_host_bridge_target, + kernel_int_arithmetic_traits +} +import extdeps.languages.rust.emit { + rust_trait_derive_attr_from_traits, + rust_supplemental_impls_commutative_semiring_magnitude, + rust_supplemental_impls_bool_coproduct } -import extdeps.languages.rust.emit { rust_trait_derive_attr_from_traits } import v2.std.logic { Bool } -data trait_derive_seed_emit_binding_note: String = "Layer-boundary mock: std.trait_derive_shape trait lists → extdeps.languages.rust.emit derive attr spellings consumed by v1.compiler.trait_derive_emit (same authority path as seed emitter)." +data trait_derive_seed_emit_binding_note: String = "Layer-boundary mock: std.trait_derive_shape trait lists + supplemental target predicates → extdeps.languages.rust.emit spellings (same authorities v1.compiler.trait_derive_emit composes for seed emit; v1 module not importable from v2 claim closure)." test fn nullary_coproduct_predicate_satisfied() -> Bool { repr_grounding_derive_completeness_predicate( @@ -49,10 +57,59 @@ test fn payload_coproduct_predicate_satisfied() -> Bool { ) } +test fn commutative_semiring_supplemental_impl_present() -> Bool { + let supplemental = rust_supplemental_impls_commutative_semiring_magnitude() + let target_ok = repr_grounding_supplemental_commutative_semiring_target( + module_path: "std.algebra", + name: "CommutativeSemiring" + ) + let predicate_ok = repr_grounding_derive_completeness_predicate( + kernel_int_arithmetic_traits(), + ReprDeriveElemKernelInt + ) + let wrong_module = repr_grounding_supplemental_commutative_semiring_target( + module_path: "std.magma", + name: "CommutativeSemiring" + ) + let wrong_name = repr_grounding_supplemental_commutative_semiring_target( + module_path: "std.algebra", + name: "Magma" + ) + target_ok + && predicate_ok + && supplemental != "" + && supplemental.contains("unimplemented!") + && wrong_module == false + && wrong_name == false +} + +test fn bool_supplemental_impl_present() -> Bool { + let supplemental = rust_supplemental_impls_bool_coproduct() + let target_ok = repr_grounding_supplemental_bool_host_bridge_target( + module_path: "std.types", + name: "Bool" + ) + let predicate_ok = repr_grounding_derive_completeness_predicate( + nullary_coproduct_derive_traits(), + ReprDeriveElemNullaryEnumCopy + ) + let wrong_module = repr_grounding_supplemental_bool_host_bridge_target( + module_path: "std.logic", + name: "Bool" + ) + let wrong_name = repr_grounding_supplemental_bool_host_bridge_target( + module_path: "std.types", + name: "Quantity" + ) + target_ok && predicate_ok && supplemental != "" && wrong_module == false && wrong_name == false +} + test fn trait_derive_seed_emit_binding_witness_holds() -> Bool { nullary_coproduct_predicate_satisfied() && payload_coproduct_predicate_satisfied() && record_heap_attr_contains_serde() && ord_carrier_shape_rejects_nullary_copy_traits() && ord_carrier_attr_differs_from_nullary() + && commutative_semiring_supplemental_impl_present() + && bool_supplemental_impl_present() }