Skip to content

Disposition carrier slice-3 (core): ground std DeclarationRef String→record + mint std.decl_ref + emit-core rewrite - #5632

Merged
briansrls merged 22 commits into
mainfrom
session/cool-carp-699
Jun 24, 2026
Merged

briansrls merged 22 commits into
mainfrom
session/cool-carp-699

Conversation

@gunbai-bot

@gunbai-bot gunbai-bot Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Disposition carrier slice-3 (carrier-evolution): ground DeclarationRef String → record

Upgrades std.serialization.DeclarationRef from an anemic String to a grounded record, dissolves the temp DeclLocator scaffold from #5610 into it, and rewrites the DESIGN-named load-bearing src/v1/05_emit_rust.dag consumer that reads it. Atomic core per bright-stag's SCOPE=SPLIT ruling (FU1 wire-lens-live + FU2 restore-citations are separate follow-ups).

Single authority (§3, bright-stag HOME=B ruling)

  • Mint dsl/std/decl_ref.dag — a neutral 3rd home owning the locator:
    • type DeclField = WholeDeclaration | NamedField { field_name: NonEmptyStr }
    • type DeclarationRef { module_path: NonEmptyStr, decl_name: NonEmptyStr, field: DeclField }
  • std.serialization and std.disposition both import it downward (neither imports the other — no cycle).
  • Relocate-and-delete in one atomic core (§3 / §2 "net concepts must not grow"): DeclField lives ONLY in std.decl_ref; disposition's ScaffoldTarget is deleted and DeclLocator is deleted — Scaffold.bind now targets the unified DeclarationRef. Tree-wide grep confirms zero ScaffoldTarget / zero DeclLocator remaining.
  • The decl_locator_dissolves_into_declaration_ref Scaffold row is dropped (its successor now exists; the redundancy lens stays lens_unit per the FU1 split).

Author-sites grounded (12 coproduct + 6 disposition bind)

  • 12 coproduct: "Name" literals across extdeps/{github/pulls, llm/openai, llm/anthropic} → coproduct: DeclarationRef { module_path, decl_name, field: WholeDeclaration }.
  • 6 anthropic structural_coverage_gap Scaffold bind: DeclLocator {...} → bind: DeclarationRef {...} (decl-shaped today; fierce-seal's Phase-2 wraps them into DeclBound under the ScaffoldAuthority widen).
  • v2 disposition_redundancy.dag lens + its test swept (DeclLocator→DeclarationRef, ScaffoldTarget→DeclField); lens stays lens_unit.

Load-bearing emit-core (src/v1/05_emit_rust.dag)

  • New helper coproduct_decl_ref_decl_name descends the coproduct record-init node to read its decl_name sub-field (same typed-record-init descent naming_policy_node already performs on an encoding value).
  • Both consumers (coproduct_wire_contract_targets, emit_coproduct_wire_contract_target_validation) rewired to it.

§7 seed receipt — narrow byte-splice (fixpoint DEFERRED, per bright-stag's re-scoped signed bar)

This is NOT a regen fixpoint. The v1 self-emit fixpoint is systemically broken on main (a full regen write produces a non-building seed — 764 errors / 84-file drift; documented in #5639's docs/plans/v1-seed-self-host-drift-findings.md). Per bright-stag's signed re-scope, the receipt here is the established hand-maintained-seed practice: a minimal byte-splice of ONLY the seed files this .dag change touches, verified by execution.

  • New src/v1/stage0/src/std_decl_ref.rs (emitted form of the mint) + registered in GENERATED_STAGE0_FILES + lib.rs pub mod.
  • std_serialization.rs / std_emit_model.rs deforked from their two divergent local DeclarationRef aliases (Rc<FreeMonoid<Nat>> and String) to pub use crate::std_decl_ref::DeclarationRef.
  • v1_compiler_emit_rust.rs emit-core mirrors the .dag (helper + 2 consumers).

The .dag is the authority; the seed splice is hand-maintained realization catching up. Full regen-verify / ci_fixed_point re-enter at the #5514 cutover (bright-stag plate), NOT here.

Verification (by execution)

  • Committed seed WITH the splice builds (cargo build -p v1-compiler, clean) and is fmt-clean.
  • cargo test -p v1-compiler-tests green — 770 passed, 0 failed, 92 ignored (the 92 are the deferred bootstrap/fixpoint tests), including pipeline::anthropic_request_coproduct_wire_contracts_emit_targeted_serde and the 6 CoproductWireContract emit witnesses migrated to the record form.
  • Discriminating check: reverting only the emit-core consumer splice (back to reading coproduct as a bare string) turns those 6 record-form witnesses RED while the 4 orthogonal local-shadow lookalike tests stay green — the new emit-core is load-bearing, not inert.

🤖 Generated with Claude Code

@briansrls
briansrls force-pushed the session/cool-carp-699 branch from 0d531b2 to 19ad64b Compare June 23, 2026 17:41
@gunbai-bot gunbai-bot Bot changed the title Disposition carrier slice-3 (carrier-evolution): upgrade std.serialization.DeclarationRef from anemic String to a grounded record (decl_name + module_path + field), rewrite the DESIGN-named load-bearing 05_emit_rust.dag stage that consumes it + the 3-rep seed mirror + self-emit §7 fixpoint, then dis Disposition carrier slice-3 (core): ground std DeclarationRef String→record + mint std.decl_ref + emit-core rewrite Jun 23, 2026
@gunbai-bot

gunbai-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Merge-order note (for the sequencing owner): this core DELETES DeclLocator. calm-otter's slice-2 #5631 ADDS DeclLocator rows and has not merged. To avoid breaking #5631 on merge, either #5631 lands FIRST (then I rebase+sweep its added rows into DeclarationRef), or this core lands first and #5631 rebases onto the deleted-DeclLocator tree. Parent neat-dove-397 makes the call. — sent from cool-carp-699

@gunbai-bot
gunbai-bot Bot marked this pull request as ready for review June 23, 2026 17:45
briansrls and others added 5 commits June 23, 2026 20:13
…ope)

The generated_artifact_drift_gate flags docs/plans/dsl-v2-defork-audit.md:
its .dag authority lacks the hand-added §2A block that main's committed .md
carries (grep: .dag=0, .md=1 on origin/main) — a pre-existing main-side
hand-edit-of-generated-artifact drift, red on main, unrelated to decl_ref.
A harness auto-commit ran main_wet which would destructively drop that §2A
content in this PR. Restore the file to main exactly so slice-3 stays scoped
to decl_ref; the drift is the plan-owner's to fix (add §2A to the .dag).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gunbai-bot
gunbai-bot Bot marked this pull request as draft June 24, 2026 01:50
briansrls and others added 5 commits June 24, 2026 02:35
…ef record upgrade

#5654 relocated CoproductWireContract rows from inline extdeps files into
*_contracts.dag sidecars (kept in old String form). Re-home the slice-3
DeclarationRef String->record upgrade + decl_ref import into all 5 sidecars
(anthropic/openai/pulls/docker/systemd) so the authority type change
(serialization.CoproductWireContract.coproduct: String->DeclarationRef)
typechecks corpus-wide. anthropic.dag keeps the bind: DeclarationRef
Disposition rows + import (those did not relocate).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts:
#	src/v2/lens/disposition_redundancy_test.dag
@gunbai-bot

gunbai-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Load-bearing 05_emit_rust composition re-confirm evidence (for @bright-stag)

DESIGN sign-off was granted on the standalone emit-core at fcff6e4950. Since then, #5654 (_contracts.dag sidecar convention) composed that core with new contracts_items/wire_context sidecar-merge helpers. Below is the literal delta between the signed head and the current synced head 57cfed8366, so the composition can be judged (not waived by byte-unchanged on the emit-core).

src/v1/05_emit_rust.dag (DESIGN-named stage) — git diff fcff6e4..57cfed8

diff --git a/src/v1/05_emit_rust.dag b/src/v1/05_emit_rust.dag
index 07b46efeac..a05249e2ce 100644
--- a/src/v1/05_emit_rust.dag
+++ b/src/v1/05_emit_rust.dag
@@ -1168,11 +1168,15 @@ fn emit_coproduct_wire_contract_target_validation(contract_item: Node, local_cop
 }
 
 fn emit_coproduct_wire_contract_validations(module_items: List<Node>, imports: List<Node>, local_coproduct_names: List<String>, source_indices: Map<String, NewlineIndex>) -> String {
-  module_items
-    |> filter(item => is_coproduct_wire_contract_row(item: item, module_items: module_items, imports: imports, source_indices: source_indices))
-    |> map(item => emit_coproduct_wire_contract_target_validation(contract_item: item, local_coproduct_names: local_coproduct_names, source_indices: source_indices))
-    |> filter(text => text != "")
-    |> join(separator: "\n")
+  if local_coproduct_names |> count == 0 {
+    ""
+  } else {
+    module_items
+      |> filter(item => is_coproduct_wire_contract_row(item: item, module_items: module_items, imports: imports, source_indices: source_indices))
+      |> map(item => emit_coproduct_wire_contract_target_validation(contract_item: item, local_coproduct_names: local_coproduct_names, source_indices: source_indices))
+      |> filter(text => text != "")
+      |> join(separator: "\n")
+  }
 }
 
 fn resolve_local_coproduct_wire_policy(coproduct_name: String, all_unit_variants: Bool, module_items: List<Node>, imports: List<Node>, source_indices: Map<String, NewlineIndex>) -> RustEnumWireSerde? {
@@ -1651,20 +1655,20 @@ fn emit_module_full(typed_module: TypedModule, registry: Map<String, ItemInfo>,
     |> filter(item => is_type_def_item(item: item) && is_coproduct_type(n: item))
     |> map(item => authored_name(env: scope.type_env, node: item))
   let module_import_items = module_imports(n: m)
-  let coproduct_wire_contract_validations = emit_coproduct_wire_contract_validations(module_items: typed_module.items, imports: module_import_items, local_coproduct_names: local_coproduct_names, source_indices: scope.type_env.source_indices)
+  let this_module_name = authored_name(env: scope.type_env, node: m)
+  let wire_context_items = concat(typed_module.items, contracts_items_for_module(module_name: this_module_name, typed_modules: typed_modules, source_indices: scope.type_env.source_indices, module_index: module_index))
+  let wire_context_imports = concat(module_import_items, contracts_imports_for_module(module_name: this_module_name, typed_modules: typed_modules, source_indices: scope.type_env.source_indices, module_index: module_index))
+  let coproduct_wire_contract_validations = emit_coproduct_wire_contract_validations(module_items: wire_context_items, imports: wire_context_imports, local_coproduct_names: local_coproduct_names, source_indices: scope.type_env.source_indices)
   let coproduct_wire_contract_validation_section = if coproduct_wire_contract_validations == "" { "" } else { concat(coproduct_wire_contract_validations, "\n\n") }
   let local_uses_str = if local_enum_uses |> count == 0 { "" }
     else { concat("\n", local_enum_uses |> join(separator: "\n")) }
-  let wire_contract_item = typed_module.items
+  let wire_contract_item = wire_context_items
     |> filter(i =>
-      item_binding_is_named(env: scope.type_env, node: i, name: "wire_contract")
-      && match map_get(scope.item_registry, "wire_contract") {
-        Present { value: info } => info.kind == DataItem
-        Absent => false
-      })
+      is_data_def_item(item: i)
+      && authored_name_at(source_indices: scope.type_env.source_indices, node: i) == "wire_contract")
     |> first
   let items_str = typed_module.items
-    |> map(item => emit_typed_item(item: item, module_name: authored_name(env: scope.type_env, node: m), registry: registry, scope: scope, shared_types: shared_types, emit_info: emit_info, wire_contract_item: wire_contract_item, data_items: scoped_data_items, module_items: typed_module.items, imports: module_import_items, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index))
+    |> map(item => emit_typed_item(item: item, module_name: authored_name(env: scope.type_env, node: m), registry: registry, scope: scope, shared_types: shared_types, emit_info: emit_info, wire_contract_item: wire_contract_item, data_items: scoped_data_items, module_items: wire_context_items, imports: wire_context_imports, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index))
     |> join(separator: "\n\n")
   let phantom_zst_markers = emit_module_phantom_zst_markers(items: typed_module.items, env: scope.type_env)
   let phantom_section = if phantom_zst_markers == "" { "" } else { concat("\n\n", phantom_zst_markers) }
@@ -1745,6 +1749,20 @@ fn typed_module_by_name(module_name: String, typed_modules: List<TypedModule>, s
   map_get(module_index.by_name, module_name)
 }
 
+fn contracts_items_for_module(module_name: String, typed_modules: List<TypedModule>, source_indices: Map<String, NewlineIndex>, module_index: ModuleIndex) -> List<Node> {
+  match typed_module_by_name(module_name: concat(module_name, "_contracts"), typed_modules: typed_modules, source_indices: source_indices, module_index: module_index) {
+    Present { value: tm } => tm.items
+    Absent => []
+  }
+}
+
+fn contracts_imports_for_module(module_name: String, typed_modules: List<TypedModule>, source_indices: Map<String, NewlineIndex>, module_index: ModuleIndex) -> List<Node> {
+  match typed_module_by_name(module_name: concat(module_name, "_contracts"), typed_modules: typed_modules, source_indices: source_indices, module_index: module_index) {
+    Present { value: tm } => module_imports(n: tm.module)
+    Absent => []
+  }
+}
+
 fn module_name_from_filename(mod_filename: String, typed_modules: List<TypedModule>, source_indices: Map<String, NewlineIndex>, module_index: ModuleIndex) -> String? {
   match map_get(module_index.by_filename, mod_filename) {
     Present { value: mods } => mods |> map(tm => authored_name_at(source_indices: source_indices, node: tm.module)) |> first

src/v1/stage0/src/v1_compiler_emit_rust.rs (.rs seed mirror) — git diff fcff6e4..57cfed8

diff --git a/src/v1/stage0/src/v1_compiler_emit_rust.rs b/src/v1/stage0/src/v1_compiler_emit_rust.rs
index 1cd8b8a57c..51ec1ea91a 100644
--- a/src/v1/stage0/src/v1_compiler_emit_rust.rs
+++ b/src/v1/stage0/src/v1_compiler_emit_rust.rs
@@ -3384,6 +3384,60 @@ pub fn build_module_export_sets(
     )
 }
 
+pub fn extend_scoped_data_items_with_sidecar(
+    base: Rc<HashMap<String, Rc<Vec<Rc<Node>>>>>,
+    module_name: String,
+    module_index: &Rc<ModuleIndex>,
+    data_items: Rc<HashMap<String, Rc<Node>>>,
+    source_indices: Rc<HashMap<String, Rc<NewlineIndex>>>,
+) -> Rc<HashMap<String, Rc<Vec<Rc<Node>>>>> {
+    match v1_rt::map_get(
+        &module_index.by_name.clone(),
+        v1_rt::concat(module_name, "_contracts".to_string()),
+    ) {
+        None => base,
+        Some(sidecar_tm) => module_imports(sidecar_tm.module.clone())
+            .iter()
+            .cloned()
+            .fold(
+                base,
+                |acc: Rc<HashMap<String, Rc<Vec<Rc<Node>>>>>, imp: Rc<Node>| {
+                    if import_is_all(imp.clone()) {
+                        acc.clone()
+                    } else {
+                        let import_path = authored_name_at(source_indices.clone(), imp.clone());
+                        import_specific_names_at(imp.clone(), source_indices.clone())
+                            .iter()
+                            .cloned()
+                            .fold(
+                                acc.clone(),
+                                |inner: Rc<HashMap<String, Rc<Vec<Rc<Node>>>>>,
+                                 imported_name: String| {
+                                    match v1_rt::map_get(&inner, imported_name.clone()) {
+                                        Some(_) => inner.clone(),
+                                        None => {
+                                            let qualified = v1_rt::concat(
+                                                v1_rt::concat(import_path.clone(), ".".to_string()),
+                                                imported_name.clone(),
+                                            );
+                                            match v1_rt::map_get(&data_items, qualified.clone()) {
+                                                Some(item) => insert_scoped_data_item(
+                                                    inner.clone(),
+                                                    imported_name.clone(),
+                                                    item.clone(),
+                                                ),
+                                                None => inner.clone(),
+                                            }
+                                        }
+                                    }
+                                },
+                            )
+                    }
+                },
+            ),
+    }
+}
+
 pub fn emit_module_full(
     typed_module: Rc<TypedModule>,
     registry: Rc<HashMap<String, Rc<ItemInfo>>>,
@@ -3398,7 +3452,16 @@ pub fn emit_module_full(
     {
         let m = typed_module.module.clone();
         let scope = module_emit_scope(typed_module.clone());
-        let scoped_data_items = build_scoped_data_item_index(typed_module.clone(), data_items);
+        let scoped_data_items = extend_scoped_data_items_with_sidecar(
+            build_scoped_data_item_index(typed_module.clone(), data_items.clone()),
+            authored_name_at(
+                typed_module.type_env.clone().source_indices.clone(),
+                typed_module.module.clone(),
+            ),
+            &module_index,
+            data_items,
+            typed_module.type_env.clone().source_indices.clone(),
+        );
         let prelude_imported_names = Rc::new({
             let mut __result = Vec::new();
             for imp in module_imports(m.clone()).iter().cloned() {
@@ -3568,9 +3631,17 @@ pub fn emit_module_full(
             __result
         });
         let module_import_items = module_imports(m.clone());
-        let coproduct_wire_contract_validations = emit_coproduct_wire_contract_validations(
-            typed_module.items.clone(),
+        let this_module_name = authored_name(scope.type_env.clone(), m.clone());
+        let sidecar_items =
+            contracts_items_for_module(this_module_name.clone(), module_index.clone());
+        let wire_context_items = v1_rt::concat(typed_module.items.clone(), sidecar_items.clone());
+        let wire_context_imports = v1_rt::concat(
             module_import_items.clone(),
+            contracts_imports_for_module(this_module_name.clone(), module_index.clone()),
+        );
+        let coproduct_wire_contract_validations = emit_coproduct_wire_contract_validations(
+            wire_context_items.clone(),
+            wire_context_imports.clone(),
             local_coproduct_names,
             scope.type_env.clone().source_indices.clone(),
         );
@@ -3591,27 +3662,38 @@ pub fn emit_module_full(
                 local_enum_uses.clone().join(&"\n".to_string()),
             )
         };
-        let wire_contract_item = Rc::new({
-            let mut __result = Vec::new();
-            for i in typed_module.items.clone().iter().cloned() {
-                if (item_binding_is_named(
-                    scope.type_env.clone(),
-                    i.clone(),
-                    "wire_contract".to_string(),
-                ) && match v1_rt::map_get(
-                    &scope.item_registry.clone(),
-                    "wire_contract".to_string(),
-                ) {
-                    Some(info) => (info.kind.clone() == ItemKind::DataItem),
-                    None => false,
-                }) {
-                    __result.push(i);
+        let wire_contract_item = {
+            let from_primary = Rc::new({
+                let mut __result = Vec::new();
+                for i in typed_module.items.clone().iter().cloned() {
+                    if (item_binding_is_named(
+                        scope.type_env.clone(),
+                        i.clone(),
+                        "wire_contract".to_string(),
+                    ) && match v1_rt::map_get(
+                        &scope.item_registry.clone(),
+                        "wire_contract".to_string(),
+                    ) {
+                        Some(info) => (info.kind.clone() == ItemKind::DataItem),
+                        None => false,
+                    }) {
+                        __result.push(i);
+                    }
                 }
-            }
-            __result
-        })
-        .first()
-        .cloned();
+                __result
+            })
+            .first()
+            .cloned();
+            from_primary.or_else(|| {
+                sidecar_items.clone().iter().cloned().find(|i| {
+                    item_binding_is_named(
+                        scope.type_env.clone(),
+                        i.clone(),
+                        "wire_contract".to_string(),
+                    )
+                })
+            })
+        };
         let items_str = Rc::new({
             let mut __result = Vec::new();
             for item in typed_module.items.clone().iter().cloned() {
@@ -3624,8 +3706,8 @@ pub fn emit_module_full(
                     emit_info.clone(),
                     wire_contract_item.clone(),
                     scoped_data_items.clone(),
-                    typed_module.items.clone(),
-                    module_import_items.clone(),
+                    wire_context_items.clone(),
+                    wire_context_imports.clone(),
                     export_sets.clone(),
                     typed_modules.clone(),
                     module_index.clone(),
@@ -3816,6 +3898,32 @@ pub fn typed_module_by_name(
     v1_rt::map_get(&module_index.by_name.clone(), module_name)
 }
 
+pub fn contracts_items_for_module(
+    module_name: String,
+    module_index: Rc<ModuleIndex>,
+) -> Rc<Vec<Rc<Node>>> {
+    match v1_rt::map_get(
+        &module_index.by_name.clone(),
+        v1_rt::concat(module_name, "_contracts".to_string()),
+    ) {
+        Some(tm) => tm.items.clone(),
+        None => Rc::new(vec![]),
+    }
+}
+
+pub fn contracts_imports_for_module(
+    module_name: String,
+    module_index: Rc<ModuleIndex>,
+) -> Rc<Vec<Rc<Node>>> {
+    match v1_rt::map_get(
+        &module_index.by_name.clone(),
+        v1_rt::concat(module_name, "_contracts".to_string()),
+    ) {
+        Some(tm) => module_imports(tm.module.clone()),
+        None => Rc::new(vec![]),
+    }
+}
+
 pub fn module_name_from_filename(
     mod_filename: String,
     typed_modules: Rc<Vec<Rc<TypedModule>>>,

@gunbai-bot
gunbai-bot Bot marked this pull request as ready for review June 24, 2026 04:28
@briansrls
briansrls merged commit b08a13d into main Jun 24, 2026
2 checks passed
@briansrls
briansrls deleted the session/cool-carp-699 branch June 24, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant