Skip to content
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f89a605
WIP: quiet-otter-242
briansrls May 3, 2026
b391299
chore(v3): regenerate bootstrap after CollectionOps fold_contract mig…
briansrls May 3, 2026
e45366e
docs(r3): document %Q decode in contract path for CollectionOps refra…
briansrls May 3, 2026
6e657a4
WIP: quiet-otter-242
briansrls May 3, 2026
384efe4
WIP: quiet-otter-242
briansrls May 3, 2026
c055c65
WIP: quiet-otter-242
briansrls May 3, 2026
84216ad
chore: apply cargo fmt
briansrls May 3, 2026
d8ed386
WIP: quiet-otter-242
briansrls May 3, 2026
776b080
WIP: quiet-otter-242
briansrls May 3, 2026
1bfe466
chore(v3): regen bootstrap snapshots for method-template .dag span drift
briansrls May 3, 2026
d1f8681
WIP: quiet-otter-242
briansrls May 3, 2026
ceeabab
WIP: quiet-otter-242
briansrls May 3, 2026
245a39a
WIP: quiet-otter-242
briansrls May 3, 2026
111986b
Merge remote-tracking branch 'origin/main' into feat/collectionops-al…
briansrls May 4, 2026
ae38c12
WIP: quiet-otter-242
briansrls May 4, 2026
5a1649e
WIP: quiet-otter-242
briansrls May 4, 2026
1a2583e
WIP: quiet-otter-242
briansrls May 4, 2026
5f016d9
chore: apply cargo fmt
briansrls May 4, 2026
7e6fee4
WIP: quiet-otter-242
briansrls May 4, 2026
d57ff54
chore: apply cargo fmt
briansrls May 4, 2026
0bf9251
WIP: quiet-otter-242
briansrls May 4, 2026
dc55118
WIP: quiet-otter-242
briansrls May 4, 2026
0424f11
WIP: quiet-otter-242
briansrls May 4, 2026
cf93965
WIP: quiet-otter-242
briansrls May 4, 2026
2ba7444
WIP: quiet-otter-242
briansrls May 4, 2026
f3d1191
WIP: quiet-otter-242
briansrls May 4, 2026
5376d6a
WIP: quiet-otter-242
briansrls May 4, 2026
775e2f3
WIP: quiet-otter-242
briansrls May 4, 2026
080a079
WIP: quiet-otter-242
briansrls May 4, 2026
c1a9488
chore(v3): refresh handwritten parse corpus manifest
briansrls May 4, 2026
c1ea7b5
Merge remote-tracking branch 'origin/main' into feat/collectionops-al…
briansrls May 4, 2026
384a1fa
WIP: quiet-otter-242
briansrls May 4, 2026
ddf4ae1
chore: apply cargo fmt
briansrls May 4, 2026
99722f5
WIP: quiet-otter-242
briansrls May 4, 2026
502ea13
WIP: quiet-otter-242
briansrls May 4, 2026
fb0e0a6
WIP: quiet-otter-242
briansrls May 4, 2026
108fb23
Merge remote-tracking branch 'origin/main' into HEAD
briansrls May 4, 2026
8c8adc4
Merge remote-tracking branch 'origin/main' into HEAD
briansrls May 4, 2026
152de34
Merge remote-tracking branch 'origin/main' into HEAD
briansrls May 4, 2026
7b3fe82
WIP: quiet-otter-242
briansrls May 4, 2026
008f527
Merge remote-tracking branch 'origin/main' into feat/collectionops-al…
briansrls May 4, 2026
9b1d7e7
Merge remote-tracking branch 'origin/main' into feat/collectionops-al…
briansrls May 4, 2026
b9c561d
Merge remote-tracking branch 'origin/main' into feat/collectionops-al…
briansrls May 4, 2026
b7d7989
Merge remote-tracking branch 'origin/main' into feat/collectionops-al…
briansrls May 4, 2026
371c8da
Merge remote-tracking branch 'origin/main' into feat/collectionops-al…
briansrls May 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/audit/grounding-tests-stratum-b-scaffold-readiness.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Current facts asserted:

| Surface | Current assertion |
|---|---|
| `rust_method_template_contracts`, `python_method_template_contracts`, `go_method_template_contracts` | Row lists exist in `generated_full_bootstrap_dag()` and have Director-locked Phase 1 counts: Rust 13, Python 18, Go 14. |
| `rust_method_template_contracts`, `python_method_template_contracts`, `go_method_template_contracts` | Row lists exist in `generated_full_bootstrap_dag()` and have Director-locked Phase 1 counts: Rust 13, Python 17, Go 13. |
| `MethodTemplateContract` rows | Each row is a closed record with exactly `dag_method`, `emit_template`, `placeholder_convention`, `runtime_template`, and `wraps_result`. Duplicate, missing, and extra fields fail closed. |
| `MethodRef` | `dag_method` must be a `MethodRef { decl }` record, and `decl` must reference a declaration that instantiates `MethodDeclaration`. |
| Templates | `runtime_template` must be a string, `emit_template` must be a known `MethodEmitTemplate` variant, `PlaceholderConvention` must be a known nullary variant, and `wraps_result` must be bool. |
Expand Down
8 changes: 5 additions & 3 deletions docs/briefs/collectionops-algebra-reframe.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Use existing **`MethodTemplateContract`** (`src/v3/std/emit_model.dag`):
High confidence first (direct **FreeMonoid** hits, arity/shape already aligned with emitters):

1. **`fold`** — monoid-shaped reducer; **done in Phase 1 proof** (`emit_model.CollectionOps.fold_contract` + per-target `MethodTemplateContract`): **Rust** named `rust_language_spec_free_monoid_fold_contract` in `src/v3/spec/rust.dag`; **Python** + **Go** named `python_language_spec_free_monoid_fold_contract` / `go_language_spec_free_monoid_fold_contract` in `src/v3/std/{python,go}_method_template_contracts.dag` (single authority — **not** duplicated in the per-target `List<MethodTemplateContract>` rows; those lists previously carried a conflicting `fold_method` row).
2. **`concat`**, **`length`** (and **`is_empty`** where it mirrors `length` / monoid emptiness) — align to `concat` / `length` / derived emptiness on `FreeMonoid<T>`.
2. **`concat`**, **`length`**, **`is_empty`** — align to `FreeMonoid<T>` (`is_empty: fn() -> Bool` is a first-class algebra field; `MethodTemplateContract.dag_method` uses `is_empty_method` so registry identity matches the Bool emptiness realization; templates remain target sugar).
3. **`map`**, **`filter`**, **`flat_map`**, **`any`**, **`all`** — already have rich `MethodTemplateContract` rows on Rust; migrate `CollectionOps` fields to refs that **either** point at those list-backed rows (if made addressable) **or** named contracts that **share** the same templates (dedupe in a later “delete duplicate literal” pass).
4. **List literal / cons / empty_list** — still monoid-shaped surface; likely `empty` / `append` realizations plus list-syntax scaffold.
5. **`StringOps`** — align `concat` to `FreeMonoid<Char>` scalar profile; other fields to monoid / character methods as declared in algebra + `std.methods`.
Expand All @@ -50,16 +50,18 @@ High confidence first (direct **FreeMonoid** hits, arity/shape already aligned w

## Emitter contract

At index-build time the emitter **resolves** `fold_contract: DeclarationRef` → `MethodTemplateContract` value body → **extracts** the `emit_template` `SingleTemplate` string for the fold site (fail-closed if higher-order shape appears where a single template is required today).
At index-build time the emitter **resolves** each `CollectionOps.*_contract: DeclarationRef` → `MethodTemplateContract` value body → **extracts** the `emit_template` `SingleTemplate` string for that site (fail-closed if a higher-order shape appears where a single template is required today).

Runtime render sites (`ListFold`, Python callable fold) use that resolved template; the old **`fold: String` field on `emit_model.CollectionOps` is deleted**.
Runtime render sites use those resolved templates; the old **opaque `String` fields** on `emit_model.CollectionOps` for migrated operations are deleted in favor of contract refs.

### `%Q` vs `placeholder_convention` (Rust today)

The **Rust** emitter applies **`template.replace("%Q", "\"")`** when loading **any** syntax or contract template string that came through the substrate (same path as legacy `CollectionOps` string fields). **`%Q`** is the v3 tokenizer’s stand-in for a literal double-quote inside a `.dag` string literal (see `src/v3/spec/rust.dag` header comment on `{quote}` / `%Q`). It is **not** declared on `MethodTemplateContract` rows today — it is an **emitter-side decoding** step for Rust-shaped carriers, not a second semantic axis.

**Next slices:** either keep documenting `%Q` here (and in any new contract rows that use it) as long as the convention stays Rust-local, or **lift** quote-escaping into a first-class substrate fact (e.g. extend `placeholder_convention` or template-segment substrate) if Python/Go need the same escape channel from shared contract literals. Until then, any new `MethodTemplateContract` text consumed by `rust_target` should treat `%Q` like existing `LanguageSpec` templates.

**Phase-2 receipt (concat / length / is_empty contracts, PR #1602):** lifting `%Q` into `placeholder_convention` (or another substrate fact) stays **deferred** — Python/Go `MethodTemplateContract` literals added for those fields do not use `%Q`; only `rust_target`'s `method_contract_single_emit_template_string` applies the Rust-local decode. Revisit when a **shared** cross-target contract literal needs escaped quotes.

## References

- ROADMAP.md §542 (row text + dissolution).
Expand Down
10 changes: 7 additions & 3 deletions dsl/std/algebra.dag
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ type BooleanAlgebra<T> {
//
// Declared surface (receiver-shaped fields — matches the record below):
// Monoid: concat(self, other), empty, append(element)
// Indexed carrier: length(), count(), slice(i, j), first() -> T?,
// Indexed carrier: length(), count(), is_empty() -> Bool, slice(i, j), first() -> T?,
// last() -> T?; element lookup is total-only via `get(collection, index) -> T?`
// in std/primitives.dag, not a partial algebra field.
// map: endomorphic fn(T) -> T -> FreeMonoid<T> (not fn(T)->U with U free)
Expand All @@ -395,6 +395,7 @@ type FreeMonoid<T> {
// Positional access — partial direct indexing is intentionally absent.
slice: fn(Int, Int) -> FreeMonoid<T>
length: fn() -> Int
is_empty: fn() -> Bool
count: fn() -> Int
first: fn() -> T?
last: fn() -> T?
Expand Down Expand Up @@ -475,7 +476,8 @@ type Ordering = Less | Equal | Greater
// xor(a, b) = meet(join(a, b), complement(meet(a, b)))
//
// From FreeMonoid:
// length and count are declared methods (Int). contains is a declared predicate.
// length and count are declared methods (Int); is_empty() -> Bool;
// contains is a declared predicate.
// The record's fold is monoid-shaped on T, not a generic catamorphism init: U.

// =========================================================================
Expand Down Expand Up @@ -617,6 +619,7 @@ fn free_monoid_scalar_templates() -> List<AlgebraFieldTemplate> {
{ name: "concat", param_types: [ReceiverSelf, ReceiverSelf], return_type: ReceiverSelf, size_effect: none, cost_shape: none, callback_element_position: none },
{ name: "empty", param_types: [], return_type: ReceiverSelf, size_effect: none, cost_shape: none, callback_element_position: none },
{ name: "length", param_types: [ReceiverSelf], return_type: NamedTemplate { name: "Int" }, size_effect: none, cost_shape: none, callback_element_position: none },
{ name: "is_empty", param_types: [ReceiverSelf], return_type: NamedTemplate { name: "Bool" }, size_effect: none, cost_shape: none, callback_element_position: none },
{ name: "chars", param_types: [ReceiverSelf], return_type: ContainerOf { source: Named { name: "List" }, element: NamedTemplate { name: "Int" } }, size_effect: none, cost_shape: Some { value: ShapeLinearScan }, callback_element_position: none },
{ name: "split", param_types: [ReceiverSelf, ReceiverSelf], return_type: ContainerOf { source: Named { name: "List" }, element: ReceiverSelf }, size_effect: none, cost_shape: Some { value: ShapeLinearScan }, callback_element_position: none },
{ name: "join", param_types: [ContainerOf { source: Named { name: "List" }, element: ReceiverSelf }, ReceiverSelf], return_type: ReceiverSelf, size_effect: none, cost_shape: none, callback_element_position: none },
Expand Down Expand Up @@ -655,7 +658,8 @@ fn free_monoid_collection_templates() -> List<AlgebraFieldTemplate> {
{ name: "join", param_types: [ReceiverSelf, NamedTemplate { name: "String" }], return_type: NamedTemplate { name: "String" }, size_effect: none, cost_shape: Some { value: ShapeLinearScan }, callback_element_position: none },
{ name: "concat", param_types: [ReceiverSelf, ReceiverSelf], return_type: ReceiverSelf, size_effect: none, cost_shape: Some { value: ShapeLinearScan }, callback_element_position: none },
{ name: "list_push", param_types: [ReceiverSelf, ReceiverElement], return_type: ReceiverSelf, size_effect: none, cost_shape: none, callback_element_position: none },
{ name: "length", param_types: [ReceiverSelf], return_type: NamedTemplate { name: "Int" }, size_effect: none, cost_shape: Some { value: ShapeLinearScan }, callback_element_position: none }
{ name: "length", param_types: [ReceiverSelf], return_type: NamedTemplate { name: "Int" }, size_effect: none, cost_shape: Some { value: ShapeLinearScan }, callback_element_position: none },
{ name: "is_empty", param_types: [ReceiverSelf], return_type: NamedTemplate { name: "Bool" }, size_effect: none, cost_shape: Some { value: ShapeLinearScan }, callback_element_position: none }
]
}

Expand Down
3 changes: 2 additions & 1 deletion dsl/std/methods.dag
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// (`ordered_ring_templates`, `approximate_field_templates`,
// `boolean_algebra_templates`, `boolean_algebra_collection_templates`,
// `free_monoid_scalar_templates`, `free_monoid_collection_templates`,
// `partial_function_templates`). 63 names from algebra. The registry
// `partial_function_templates`). 64 names from algebra. The registry
// IS the closed-system namespace authority for every
// algebra-template method name; not a demand-shaped subset for the
// first Grounding consumer.
Expand Down Expand Up @@ -113,6 +113,7 @@ data fold_method: MethodDeclaration = { name: "fold" }
data get_method: MethodDeclaration = { name: "get" }
data has_method: MethodDeclaration = { name: "has" }
data intersect_method: MethodDeclaration = { name: "intersect" }
data is_empty_method: MethodDeclaration = { name: "is_empty" }
data join_method: MethodDeclaration = { name: "join" }
data keys_method: MethodDeclaration = { name: "keys" }
data last_method: MethodDeclaration = { name: "last" }
Expand Down
2 changes: 0 additions & 2 deletions src/v2/stage0/src/generated_method_template_projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub fn python_method_template_emit() -> Rc<HashMap<String, String>> {
__m.insert("any".to_string(), "any({arg}(x) for x in {recv})".to_string());
__m.insert("append".to_string(), "{recv} + [{arg}]".to_string());
__m.insert("chars".to_string(), "[ord(c) for c in {recv}]".to_string());
__m.insert("concat".to_string(), "{recv} + {arg}".to_string());
__m.insert("count".to_string(), "len({recv})".to_string());
__m.insert("enumerate".to_string(), "list(enumerate({recv}))".to_string());
__m.insert("filter".to_string(), "[x for x in {recv} if {arg}(x)]".to_string());
Expand All @@ -61,7 +60,6 @@ pub fn go_method_template_emit() -> Rc<HashMap<String, String>> {
__m.insert("all".to_string(), "v2rt.All({recv}, {arg})".to_string());
__m.insert("any".to_string(), "v2rt.Any({recv}, {arg})".to_string());
__m.insert("append".to_string(), "append({recv}, {arg})".to_string());
__m.insert("concat".to_string(), "append({recv}, {arg}...)".to_string());
__m.insert("count".to_string(), "len({recv})".to_string());
__m.insert("filter".to_string(), "v2rt.Filter({recv}, {arg})".to_string());
__m.insert("flat_map".to_string(), "v2rt.FlatMap({recv}, {arg})".to_string());
Expand Down
21 changes: 21 additions & 0 deletions src/v2/stage0/src/std_algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub struct FreeMonoid<T> {
pub append: Rc<dyn Fn(T) -> Rc<FreeMonoid<T>>>,
pub slice: Rc<dyn Fn(i64, i64) -> Rc<FreeMonoid<T>>>,
pub length: Rc<dyn Fn() -> i64>,
pub is_empty: Rc<dyn Fn() -> bool>,
pub count: Rc<dyn Fn() -> i64>,
pub first: Rc<dyn Fn() -> Option<T>>,
pub last: Rc<dyn Fn() -> Option<T>>,
Expand Down Expand Up @@ -712,6 +713,16 @@ pub fn free_monoid_scalar_templates() -> Rc<Vec<Rc<AlgebraFieldTemplate>>> {
cost_shape: None,
callback_element_position: None,
}),
Rc::new(AlgebraFieldTemplate {
name: "is_empty".to_string(),
param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]),
return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate {
name: "Bool".to_string(),
}),
size_effect: None,
cost_shape: None,
callback_element_position: None,
}),
Rc::new(AlgebraFieldTemplate {
name: "chars".to_string(),
param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]),
Expand Down Expand Up @@ -1162,6 +1173,16 @@ pub fn free_monoid_collection_templates() -> Rc<Vec<Rc<AlgebraFieldTemplate>>> {
cost_shape: Some(CostShape::ShapeLinearScan),
callback_element_position: None,
}),
Rc::new(AlgebraFieldTemplate {
name: "is_empty".to_string(),
param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]),
return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate {
name: "Bool".to_string(),
}),
size_effect: None,
cost_shape: Some(CostShape::ShapeLinearScan),
callback_element_position: None,
}),
])
}

Expand Down
Loading
Loading