diff --git a/src/v3/compiler/tests/integration/v4_compiler_emit_translate_smoke_test.rs b/src/v3/compiler/tests/integration/v4_compiler_emit_translate_smoke_test.rs index c50918d8c92..6c30bb70c79 100644 --- a/src/v3/compiler/tests/integration/v4_compiler_emit_translate_smoke_test.rs +++ b/src/v3/compiler/tests/integration/v4_compiler_emit_translate_smoke_test.rs @@ -35,6 +35,8 @@ const RUST_LANGUAGE_DAG: &str = include_str!("../../../../v4/extdeps/languages/r const RUST_LANGUAGE_PATH: &str = "src/v4/extdeps/languages/rust.dag"; const JAVA_LANGUAGE_DAG: &str = include_str!("../../../../v4/extdeps/languages/java.dag"); const JAVA_LANGUAGE_PATH: &str = "src/v4/extdeps/languages/java.dag"; +const GO_LANGUAGE_DAG: &str = include_str!("../../../../v4/extdeps/languages/go.dag"); +const GO_LANGUAGE_PATH: &str = "src/v4/extdeps/languages/go.dag"; const MVP1_CLAIM_DAG: &str = include_str!("../../../../v4/test/claim/manual/mvp1_rust_add_translate.dag"); const MVP1_CLAIM_PATH: &str = "src/v4/test/claim/manual/mvp1_rust_add_translate.dag"; @@ -213,6 +215,28 @@ fn v4_java_language_model_declares_t11_translation_rules() { ); } +#[test] +fn v4_go_language_model_tokenizes_and_parses() { + let _module = parse_module(GO_LANGUAGE_DAG, GO_LANGUAGE_PATH); +} + +#[test] +fn v4_go_language_model_declares_wave1_carriers() { + let module = parse_module(GO_LANGUAGE_DAG, GO_LANGUAGE_PATH); + assert!( + surface_declares_fn(&module, "go_wave1_primitive_fact_bundles"), + "{GO_LANGUAGE_PATH}: must declare go_wave1_primitive_fact_bundles" + ); + assert!( + surface_declares_fn(&module, "go_model_core_wave1"), + "{GO_LANGUAGE_PATH}: must declare go_model_core_wave1" + ); + assert!( + import_includes_name(&module, &["v4", "std", "model_core"], "ModelCore"), + "{GO_LANGUAGE_PATH}: must import ModelCore from v4.std.model_core" + ); +} + #[test] fn v4_mvp1_rust_add_claim_tokenizes_and_parses() { let _module = parse_module(MVP1_CLAIM_DAG, MVP1_CLAIM_PATH); diff --git a/src/v4/extdeps/languages/go.dag b/src/v4/extdeps/languages/go.dag index 15d9a7503e9..9a403a89d9e 100644 --- a/src/v4/extdeps/languages/go.dag +++ b/src/v4/extdeps/languages/go.dag @@ -1,15 +1,27 @@ // src/v4/extdeps/languages/go.dag -// Scope: Go language spec surface (scalar width/kind sums, channel direction, export, cost shape, partial D2 resolver); L-2 pin go1.26 via Anchor. -// Owns: SignedIntWidth, UnsignedIntWidth, GoFloatWidth, GoComplexWidth, GoScalarKind, GoScalar, GoChannelDirection, GoExportLocus, GoExportStatus, GoChannel, GoCost, GoBuiltinIntegerArithmeticOverflow, GoIntegerOverflowDisposition, go_bool_grounding. -// Consumes: v4.std.node.Symbol; v4.std.logic.Bool, bool_boolean_algebra; v4.std.algebra.BooleanAlgebra; kernel-ambient Int (STRUCTURE.md traceability). -// Status: extdeps go slice; bool canonical-B decl-ref grounding β€” 🟑 E-6(b) staging; classifier = GoScalar.BoolScalar; numeric D2a rows deferred per D2-REV and resolver.dag; no D1 ops in-file. +// Scope: Go language spec surface β€” scalar fact-bundles, ModelCore wave-1, channel/export vocabulary. +// Owns: SignedIntWidth, UnsignedIntWidth, GoFloatWidth, GoComplexWidth, GoScalarKind, GoScalar, GoChannelDirection, GoExportLocus, GoExportStatus, GoChannel, GoCost, GoBuiltinIntegerArithmeticOverflow, GoIntegerOverflowDisposition, GoIntegerPrimitiveFacts, GoFloatPrimitiveFacts, GoComplexPrimitiveFacts, GoBoolPrimitiveFacts, GoStringPrimitiveFacts, go_*_facts_catalog, go_*_primitive_bundle, go_model_core_wave1, go_bool_grounding. +// Consumes: v4.std.collection, v4.std.model_core, v4.std.node, v4.std.logic, v4.std.algebra. +// Status: T-4 go slice β€” Go spec Β§Types (https://go.dev/ref/spec#Types) predeclared numeric/bool/string primitives as fact-bundles; ModelCore.primitives via fold; inhabitance/laws/effects/partiality empty (wave-2+); `go_model_core_wave1` is 🟑 E-6(b) consumer-less until GoLanguageModel lands (T-11); bool canonical-B decl-ref β€” 🟑 E-6(b) staging. // Anchor: https://go.dev/ref/spec module v4.extdeps.languages.go -import v4.std.node { Symbol } +import v4.std.collection { List, Map, list_append, list_snoc_item } +import v4.std.model_core { + EffectSemanticsDecl, + ModelCore, + PartialitySemanticsDecl, + PrimitiveFactBundle, + primitive_fact_axis_encoding, + primitive_fact_axis_overflow_disposition, + primitive_fact_axis_signedness, + primitive_fact_axis_surface_spelling, + primitive_fact_axis_width +} +import v4.std.node { Atom, Conj, Edge, Named, Node, Symbol, TypeNode } import v4.std.logic { Bool, bool_boolean_algebra } -import v4.std.algebra { BooleanAlgebra } +import v4.std.algebra { BooleanAlgebra, Empty, fold_list } // 🟒 coproduct dissolution β€” CP-3229-GREEN-TERMINAL. type SignedIntWidth @@ -82,6 +94,7 @@ type GoCost { allocation_cost: Int } +// Go spec: typed integer arithmetic truncates silently on overflow (not panic). // 🟒 coproduct dissolution β€” CP-3229-GREEN-TERMINAL. type GoBuiltinIntegerArithmeticOverflow = SignedTypedIntegerTruncatesSilentlyOnOverflow @@ -92,5 +105,763 @@ type GoIntegerOverflowDisposition { release_default: GoBuiltinIntegerArithmeticOverflow } +// Signedness axis for ModelCore primitive bundles (mirrors java/rust carrier shape). +// 🟒 coproduct dissolution β€” CP-3229-GREEN-TERMINAL. +type GoIntKind + = Signed + | Unsigned + +// Integer fact rows β€” signedness, width, and overflow disposition are one coproduct arm +// (illegal states like Signed + GoUnsignedWidth are unrepresentable). +// 🟒 coproduct dissolution β€” CP-3229-GREEN-TERMINAL. +type GoIntegerPrimitiveFacts + = GoSignedIntegerPrimitiveFacts { + surface_spelling: Symbol + width: SignedIntWidth + encoding: Symbol + std_projection: Symbol + } + | GoUnsignedIntegerPrimitiveFacts { + surface_spelling: Symbol + width: UnsignedIntWidth + encoding: Symbol + std_projection: Symbol + } + +type GoFloatPrimitiveFacts { + surface_spelling: Symbol + width: GoFloatWidth + ieee754_binary: Symbol + std_projection: Symbol +} + +// Go spec: complex is a pair of floating-point values (complex64 = two float32, etc.). +type GoComplexPrimitiveFacts { + surface_spelling: Symbol + width: GoComplexWidth + component_ieee754_binary: Symbol + std_projection: Symbol +} + +type GoBoolPrimitiveFacts { + surface_spelling: Symbol + encoding: Symbol + std_projection: Symbol +} + +type GoStringPrimitiveFacts { + surface_spelling: Symbol + encoding: Symbol + std_projection: Symbol +} + +data go_surface_spelling_int8: Symbol = go_surface_spelling_int8 +data go_surface_spelling_int16: Symbol = go_surface_spelling_int16 +data go_surface_spelling_int32: Symbol = go_surface_spelling_int32 +data go_surface_spelling_int64: Symbol = go_surface_spelling_int64 +data go_surface_spelling_int: Symbol = go_surface_spelling_int +data go_surface_spelling_uint8: Symbol = go_surface_spelling_uint8 +data go_surface_spelling_uint16: Symbol = go_surface_spelling_uint16 +data go_surface_spelling_uint32: Symbol = go_surface_spelling_uint32 +data go_surface_spelling_uint64: Symbol = go_surface_spelling_uint64 +data go_surface_spelling_uint: Symbol = go_surface_spelling_uint +data go_surface_spelling_uintptr: Symbol = go_surface_spelling_uintptr +data go_surface_spelling_float32: Symbol = go_surface_spelling_float32 +data go_surface_spelling_float64: Symbol = go_surface_spelling_float64 +data go_surface_spelling_complex64: Symbol = go_surface_spelling_complex64 +data go_surface_spelling_complex128: Symbol = go_surface_spelling_complex128 +data go_surface_spelling_bool: Symbol = go_surface_spelling_bool +data go_surface_spelling_string: Symbol = go_surface_spelling_string + +data go_std_projection_int8: Symbol = go_std_projection_int8 +data go_std_projection_int16: Symbol = go_std_projection_int16 +data go_std_projection_int32: Symbol = go_std_projection_int32 +data go_std_projection_int64: Symbol = go_std_projection_int64 +data go_std_projection_int: Symbol = go_std_projection_int +data go_std_projection_uint8: Symbol = go_std_projection_uint8 +data go_std_projection_uint16: Symbol = go_std_projection_uint16 +data go_std_projection_uint32: Symbol = go_std_projection_uint32 +data go_std_projection_uint64: Symbol = go_std_projection_uint64 +data go_std_projection_uint: Symbol = go_std_projection_uint +data go_std_projection_uintptr: Symbol = go_std_projection_uintptr +data go_std_projection_float32: Symbol = go_std_projection_float32 +data go_std_projection_float64: Symbol = go_std_projection_float64 +data go_std_projection_complex64: Symbol = go_std_projection_complex64 +data go_std_projection_complex128: Symbol = go_std_projection_complex128 +data go_std_projection_bool: Symbol = go_std_projection_bool +data go_std_projection_string: Symbol = go_std_projection_string + +data go_ieee754_binary32: Symbol = go_ieee754_binary32 +data go_ieee754_binary64: Symbol = go_ieee754_binary64 +data go_repr_twos_complement_integer: Symbol = go_repr_twos_complement_integer +data go_repr_boolean: Symbol = go_repr_boolean +data go_repr_string_immutable_byte_sequence: Symbol = go_repr_string_immutable_byte_sequence +data go_repr_complex_pair_binary32: Symbol = go_repr_complex_pair_binary32 +data go_repr_complex_pair_binary64: Symbol = go_repr_complex_pair_binary64 + +data go_facts_field_surface_spelling: Symbol = go_facts_field_surface_spelling +data go_facts_field_width: Symbol = go_facts_field_width +data go_facts_field_signedness: Symbol = go_facts_field_signedness +data go_facts_field_overflow: Symbol = go_facts_field_overflow +data go_facts_field_encoding: Symbol = go_facts_field_encoding +data go_facts_field_std_projection: Symbol = go_facts_field_std_projection +data go_facts_field_ieee754_binary: Symbol = go_facts_field_ieee754_binary +data go_facts_field_component_ieee754_binary: Symbol = go_facts_field_component_ieee754_binary + +data go_tag_signed: Symbol = go_tag_signed +data go_tag_unsigned: Symbol = go_tag_unsigned +data go_tag_signed_bits8: Symbol = go_tag_signed_bits8 +data go_tag_signed_bits16: Symbol = go_tag_signed_bits16 +data go_tag_signed_bits32: Symbol = go_tag_signed_bits32 +data go_tag_signed_bits64: Symbol = go_tag_signed_bits64 +data go_tag_signed_platform_int: Symbol = go_tag_signed_platform_int +data go_tag_unsigned_bits8: Symbol = go_tag_unsigned_bits8 +data go_tag_unsigned_bits16: Symbol = go_tag_unsigned_bits16 +data go_tag_unsigned_bits32: Symbol = go_tag_unsigned_bits32 +data go_tag_unsigned_bits64: Symbol = go_tag_unsigned_bits64 +data go_tag_unsigned_platform_int: Symbol = go_tag_unsigned_platform_int +data go_tag_unsigned_pointer_sized: Symbol = go_tag_unsigned_pointer_sized +data go_tag_float_bits32: Symbol = go_tag_float_bits32 +data go_tag_float_bits64: Symbol = go_tag_float_bits64 +data go_tag_complex_bits64: Symbol = go_tag_complex_bits64 +data go_tag_complex_bits128: Symbol = go_tag_complex_bits128 +data go_tag_overflow_signed_truncates: Symbol = go_tag_overflow_signed_truncates +data go_tag_overflow_unsigned_truncates: Symbol = go_tag_overflow_unsigned_truncates + +data go_facts_int8: GoIntegerPrimitiveFacts = GoSignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_int8, + width: SignedBits8, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_int8, +} + +data go_facts_int16: GoIntegerPrimitiveFacts = GoSignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_int16, + width: SignedBits16, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_int16, +} + +data go_facts_int32: GoIntegerPrimitiveFacts = GoSignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_int32, + width: SignedBits32, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_int32, +} + +data go_facts_int64: GoIntegerPrimitiveFacts = GoSignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_int64, + width: SignedBits64, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_int64, +} + +data go_facts_int: GoIntegerPrimitiveFacts = GoSignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_int, + width: SignedPlatformInt, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_int, +} + +data go_facts_uint8: GoIntegerPrimitiveFacts = GoUnsignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_uint8, + width: UnsignedBits8, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_uint8, +} + +data go_facts_uint16: GoIntegerPrimitiveFacts = GoUnsignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_uint16, + width: UnsignedBits16, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_uint16, +} + +data go_facts_uint32: GoIntegerPrimitiveFacts = GoUnsignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_uint32, + width: UnsignedBits32, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_uint32, +} + +data go_facts_uint64: GoIntegerPrimitiveFacts = GoUnsignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_uint64, + width: UnsignedBits64, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_uint64, +} + +data go_facts_uint: GoIntegerPrimitiveFacts = GoUnsignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_uint, + width: UnsignedPlatformInt, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_uint, +} + +data go_facts_uintptr: GoIntegerPrimitiveFacts = GoUnsignedIntegerPrimitiveFacts { + surface_spelling: go_surface_spelling_uintptr, + width: UnsignedPointerSized, + encoding: go_repr_twos_complement_integer, + std_projection: go_std_projection_uintptr, +} + +data go_facts_float32: GoFloatPrimitiveFacts = GoFloatPrimitiveFacts { + surface_spelling: go_surface_spelling_float32, + width: Bits32, + ieee754_binary: go_ieee754_binary32, + std_projection: go_std_projection_float32, +} + +data go_facts_float64: GoFloatPrimitiveFacts = GoFloatPrimitiveFacts { + surface_spelling: go_surface_spelling_float64, + width: Bits64, + ieee754_binary: go_ieee754_binary64, + std_projection: go_std_projection_float64, +} + +data go_facts_complex64: GoComplexPrimitiveFacts = GoComplexPrimitiveFacts { + surface_spelling: go_surface_spelling_complex64, + width: Bits64, + component_ieee754_binary: go_repr_complex_pair_binary32, + std_projection: go_std_projection_complex64, +} + +data go_facts_complex128: GoComplexPrimitiveFacts = GoComplexPrimitiveFacts { + surface_spelling: go_surface_spelling_complex128, + width: Bits128, + component_ieee754_binary: go_repr_complex_pair_binary64, + std_projection: go_std_projection_complex128, +} + +data go_facts_bool: GoBoolPrimitiveFacts = GoBoolPrimitiveFacts { + surface_spelling: go_surface_spelling_bool, + encoding: go_repr_boolean, + std_projection: go_std_projection_bool, +} + +data go_facts_string: GoStringPrimitiveFacts = GoStringPrimitiveFacts { + surface_spelling: go_surface_spelling_string, + encoding: go_repr_string_immutable_byte_sequence, + std_projection: go_std_projection_string, +} + +data go_integer_facts_catalog: List = [ + go_facts_int8, + go_facts_int16, + go_facts_int32, + go_facts_int64, + go_facts_int, + go_facts_uint8, + go_facts_uint16, + go_facts_uint32, + go_facts_uint64, + go_facts_uint, + go_facts_uintptr, +] + +data go_float_facts_catalog: List = [ + go_facts_float32, + go_facts_float64, +] + +data go_complex_facts_catalog: List = [ + go_facts_complex64, + go_facts_complex128, +] + +data go_bool_facts_catalog: List = [ + go_facts_bool, +] + +data go_string_facts_catalog: List = [ + go_facts_string, +] + // 🟑 canonical-B decl-ref Β· E-6(b) bounded-exception Β· scaffold feature:canonical-b-grounding-consumer Β· dissolve-on: B1-CANON+zip-fold consume (ledger: B1Β·T-9/C1 Β· grounding-worked-examples.md Β§0) data go_bool_grounding: BooleanAlgebra = bool_boolean_algebra + +fn go_inhabitant_atom(id: Symbol) -> Node { + Node { + kind: TypeNode { connective: Atom { identity: id } }, + children: [] + } +} + +fn go_named_edge(name: Symbol, target: Node) -> Edge { + Edge { label: Named { name: name }, target: target } +} + +fn go_int_kind_node(kind: GoIntKind) -> Node { + match kind { + Signed => go_inhabitant_atom(id: go_tag_signed) + Unsigned => go_inhabitant_atom(id: go_tag_unsigned) + } +} + +fn go_signed_int_width_node(width: SignedIntWidth) -> Node { + match width { + SignedBits8 => go_inhabitant_atom(id: go_tag_signed_bits8) + SignedBits16 => go_inhabitant_atom(id: go_tag_signed_bits16) + SignedBits32 => go_inhabitant_atom(id: go_tag_signed_bits32) + SignedBits64 => go_inhabitant_atom(id: go_tag_signed_bits64) + SignedPlatformInt => go_inhabitant_atom(id: go_tag_signed_platform_int) + } +} + +fn go_unsigned_int_width_node(width: UnsignedIntWidth) -> Node { + match width { + UnsignedBits8 => go_inhabitant_atom(id: go_tag_unsigned_bits8) + UnsignedBits16 => go_inhabitant_atom(id: go_tag_unsigned_bits16) + UnsignedBits32 => go_inhabitant_atom(id: go_tag_unsigned_bits32) + UnsignedBits64 => go_inhabitant_atom(id: go_tag_unsigned_bits64) + UnsignedPlatformInt => go_inhabitant_atom(id: go_tag_unsigned_platform_int) + UnsignedPointerSized => go_inhabitant_atom(id: go_tag_unsigned_pointer_sized) + } +} + +fn go_float_width_node(width: GoFloatWidth) -> Node { + match width { + Bits32 => go_inhabitant_atom(id: go_tag_float_bits32) + Bits64 => go_inhabitant_atom(id: go_tag_float_bits64) + } +} + +fn go_complex_width_node(width: GoComplexWidth) -> Node { + match width { + Bits64 => go_inhabitant_atom(id: go_tag_complex_bits64) + Bits128 => go_inhabitant_atom(id: go_tag_complex_bits128) + } +} + +fn go_overflow_node(overflow: GoBuiltinIntegerArithmeticOverflow) -> Node { + match overflow { + SignedTypedIntegerTruncatesSilentlyOnOverflow => + go_inhabitant_atom(id: go_tag_overflow_signed_truncates) + UnsignedTypedIntegerTruncatesSilentlyOnOverflow => + go_inhabitant_atom(id: go_tag_overflow_unsigned_truncates) + } +} + +fn go_integer_facts_node(facts: GoIntegerPrimitiveFacts) -> Node { + match facts { + GoSignedIntegerPrimitiveFacts { + surface_spelling, + width, + encoding, + std_projection + } => Node { + kind: TypeNode { connective: Conj }, + children: [ + go_named_edge( + name: go_facts_field_surface_spelling, + target: go_inhabitant_atom(id: surface_spelling) + ), + go_named_edge( + name: go_facts_field_width, + target: go_signed_int_width_node(width: width) + ), + go_named_edge( + name: go_facts_field_signedness, + target: go_int_kind_node(kind: Signed) + ), + go_named_edge( + name: go_facts_field_overflow, + target: go_overflow_node( + overflow: SignedTypedIntegerTruncatesSilentlyOnOverflow + ) + ), + go_named_edge( + name: go_facts_field_encoding, + target: go_inhabitant_atom(id: encoding) + ), + go_named_edge( + name: go_facts_field_std_projection, + target: go_inhabitant_atom(id: std_projection) + ) + ] + } + GoUnsignedIntegerPrimitiveFacts { + surface_spelling, + width, + encoding, + std_projection + } => Node { + kind: TypeNode { connective: Conj }, + children: [ + go_named_edge( + name: go_facts_field_surface_spelling, + target: go_inhabitant_atom(id: surface_spelling) + ), + go_named_edge( + name: go_facts_field_width, + target: go_unsigned_int_width_node(width: width) + ), + go_named_edge( + name: go_facts_field_signedness, + target: go_int_kind_node(kind: Unsigned) + ), + go_named_edge( + name: go_facts_field_overflow, + target: go_overflow_node( + overflow: UnsignedTypedIntegerTruncatesSilentlyOnOverflow + ) + ), + go_named_edge( + name: go_facts_field_encoding, + target: go_inhabitant_atom(id: encoding) + ), + go_named_edge( + name: go_facts_field_std_projection, + target: go_inhabitant_atom(id: std_projection) + ) + ] + } + } +} + +fn go_float_facts_node(facts: GoFloatPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + go_named_edge( + name: go_facts_field_surface_spelling, + target: go_inhabitant_atom(id: facts.surface_spelling) + ), + go_named_edge( + name: go_facts_field_width, + target: go_float_width_node(width: facts.width) + ), + go_named_edge( + name: go_facts_field_ieee754_binary, + target: go_inhabitant_atom(id: facts.ieee754_binary) + ), + go_named_edge( + name: go_facts_field_std_projection, + target: go_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn go_complex_facts_node(facts: GoComplexPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + go_named_edge( + name: go_facts_field_surface_spelling, + target: go_inhabitant_atom(id: facts.surface_spelling) + ), + go_named_edge( + name: go_facts_field_width, + target: go_complex_width_node(width: facts.width) + ), + go_named_edge( + name: go_facts_field_component_ieee754_binary, + target: go_inhabitant_atom(id: facts.component_ieee754_binary) + ), + go_named_edge( + name: go_facts_field_std_projection, + target: go_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn go_bool_facts_node(facts: GoBoolPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + go_named_edge( + name: go_facts_field_surface_spelling, + target: go_inhabitant_atom(id: facts.surface_spelling) + ), + go_named_edge( + name: go_facts_field_encoding, + target: go_inhabitant_atom(id: facts.encoding) + ), + go_named_edge( + name: go_facts_field_std_projection, + target: go_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn go_string_facts_node(facts: GoStringPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + go_named_edge( + name: go_facts_field_surface_spelling, + target: go_inhabitant_atom(id: facts.surface_spelling) + ), + go_named_edge( + name: go_facts_field_encoding, + target: go_inhabitant_atom(id: facts.encoding) + ), + go_named_edge( + name: go_facts_field_std_projection, + target: go_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn go_primitive_fact_map_2( + axis0: Symbol, + fact0: Node, + axis1: Symbol, + fact1: Node +) -> Map { + map_insert( + map_insert(empty_map(), axis0, fact0), + axis1, + fact1 + ) +} + +fn go_primitive_fact_map_3( + axis0: Symbol, + fact0: Node, + axis1: Symbol, + fact1: Node, + axis2: Symbol, + fact2: Node +) -> Map { + map_insert( + map_insert( + map_insert(empty_map(), axis0, fact0), + axis1, + fact1 + ), + axis2, + fact2 + ) +} + +fn go_primitive_fact_map_5( + axis0: Symbol, + fact0: Node, + axis1: Symbol, + fact1: Node, + axis2: Symbol, + fact2: Node, + axis3: Symbol, + fact3: Node, + axis4: Symbol, + fact4: Node +) -> Map { + map_insert( + map_insert( + map_insert( + map_insert( + map_insert(empty_map(), axis0, fact0), + axis1, + fact1 + ), + axis2, + fact2 + ), + axis3, + fact3 + ), + axis4, + fact4 + ) +} + +fn go_primitive_bundle_from_integer_facts(facts: GoIntegerPrimitiveFacts) -> PrimitiveFactBundle { + match facts { + GoSignedIntegerPrimitiveFacts { + surface_spelling, + width, + encoding, + std_projection: _ + } => PrimitiveFactBundle { + substrate_carrier: go_integer_facts_node(facts: facts), + spec_facts: go_primitive_fact_map_5( + axis0: primitive_fact_axis_surface_spelling, + fact0: go_inhabitant_atom(id: surface_spelling), + axis1: primitive_fact_axis_width, + fact1: go_signed_int_width_node(width: width), + axis2: primitive_fact_axis_signedness, + fact2: go_int_kind_node(kind: Signed), + axis3: primitive_fact_axis_overflow_disposition, + fact3: go_overflow_node( + overflow: SignedTypedIntegerTruncatesSilentlyOnOverflow + ), + axis4: primitive_fact_axis_encoding, + fact4: go_inhabitant_atom(id: encoding) + ) + } + GoUnsignedIntegerPrimitiveFacts { + surface_spelling, + width, + encoding, + std_projection: _ + } => PrimitiveFactBundle { + substrate_carrier: go_integer_facts_node(facts: facts), + spec_facts: go_primitive_fact_map_5( + axis0: primitive_fact_axis_surface_spelling, + fact0: go_inhabitant_atom(id: surface_spelling), + axis1: primitive_fact_axis_width, + fact1: go_unsigned_int_width_node(width: width), + axis2: primitive_fact_axis_signedness, + fact2: go_int_kind_node(kind: Unsigned), + axis3: primitive_fact_axis_overflow_disposition, + fact3: go_overflow_node( + overflow: UnsignedTypedIntegerTruncatesSilentlyOnOverflow + ), + axis4: primitive_fact_axis_encoding, + fact4: go_inhabitant_atom(id: encoding) + ) + } + } +} + +fn go_primitive_bundle_from_float_facts(facts: GoFloatPrimitiveFacts) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: go_float_facts_node(facts: facts), + spec_facts: go_primitive_fact_map_3( + axis0: primitive_fact_axis_surface_spelling, + fact0: go_inhabitant_atom(id: facts.surface_spelling), + axis1: primitive_fact_axis_width, + fact1: go_float_width_node(width: facts.width), + axis2: primitive_fact_axis_encoding, + fact2: go_inhabitant_atom(id: facts.ieee754_binary) + ) + } +} + +fn go_primitive_bundle_from_complex_facts(facts: GoComplexPrimitiveFacts) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: go_complex_facts_node(facts: facts), + spec_facts: go_primitive_fact_map_3( + axis0: primitive_fact_axis_surface_spelling, + fact0: go_inhabitant_atom(id: facts.surface_spelling), + axis1: primitive_fact_axis_width, + fact1: go_complex_width_node(width: facts.width), + axis2: primitive_fact_axis_encoding, + fact2: go_inhabitant_atom(id: facts.component_ieee754_binary) + ) + } +} + +fn go_primitive_bundle_from_bool_facts(facts: GoBoolPrimitiveFacts) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: go_bool_facts_node(facts: facts), + spec_facts: go_primitive_fact_map_2( + axis0: primitive_fact_axis_surface_spelling, + fact0: go_inhabitant_atom(id: facts.surface_spelling), + axis1: primitive_fact_axis_encoding, + fact1: go_inhabitant_atom(id: facts.encoding) + ) + } +} + +fn go_primitive_bundle_from_string_facts(facts: GoStringPrimitiveFacts) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: go_string_facts_node(facts: facts), + spec_facts: go_primitive_fact_map_2( + axis0: primitive_fact_axis_surface_spelling, + fact0: go_inhabitant_atom(id: facts.surface_spelling), + axis1: primitive_fact_axis_encoding, + fact1: go_inhabitant_atom(id: facts.encoding) + ) + } +} + +fn go_primitive_bundles_from_integer_catalog() -> List { + fold_list( + xs: go_integer_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: go_primitive_bundle_from_integer_facts(facts: facts) + ) + } + ) +} + +fn go_primitive_bundles_from_float_catalog() -> List { + fold_list( + xs: go_float_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: go_primitive_bundle_from_float_facts(facts: facts) + ) + } + ) +} + +fn go_primitive_bundles_from_complex_catalog() -> List { + fold_list( + xs: go_complex_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: go_primitive_bundle_from_complex_facts(facts: facts) + ) + } + ) +} + +fn go_primitive_bundles_from_bool_catalog() -> List { + fold_list( + xs: go_bool_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: go_primitive_bundle_from_bool_facts(facts: facts) + ) + } + ) +} + +fn go_primitive_bundles_from_string_catalog() -> List { + fold_list( + xs: go_string_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: go_primitive_bundle_from_string_facts(facts: facts) + ) + } + ) +} + +fn go_wave1_primitive_fact_bundles() -> List { + list_append( + left: list_append( + left: list_append( + left: list_append( + left: go_primitive_bundles_from_integer_catalog(), + right: go_primitive_bundles_from_float_catalog() + ), + right: go_primitive_bundles_from_complex_catalog() + ), + right: go_primitive_bundles_from_bool_catalog() + ), + right: go_primitive_bundles_from_string_catalog() + ) +} + +// 🟑 needs-more-work β€” feature:go-language-model-wave1-consumer β€” E-6(b) bounded +// exception β€” scaffold: T-4 go slice has no GoLanguageModel carrier yet (lex / grammar / +// MVP are T-11 rust-first specialization follow-on). Dissolve-on: GoLanguageModel lands and +// binds `core: go_model_core_wave1()`. +fn go_model_core_wave1() -> ModelCore { + ModelCore { + primitives: go_wave1_primitive_fact_bundles(), + inhabitance: [], + laws: [], + effects: EffectSemanticsDecl { operations: [] }, + partiality: PartialitySemanticsDecl { operations: [] } + } +} diff --git a/src/v4/extdeps/languages/swift.dag b/src/v4/extdeps/languages/swift.dag new file mode 100644 index 00000000000..cafdb206c2c --- /dev/null +++ b/src/v4/extdeps/languages/swift.dag @@ -0,0 +1,668 @@ +// src/v4/extdeps/languages/swift.dag +// Scope: Swift language/standard-library scalar fact-bundles and ModelCore wave-1. +// Owns: SwiftIntWidth, SwiftScalar, SwiftIntegerPrimitiveFacts, SwiftFloatPrimitiveFacts, SwiftNonNumericPrimitiveFacts, SwiftLanguageModel, swift_*_facts, swift_model_core_wave1, swift_language_model_wave1. +// Consumes: v4.std.collection, v4.std.model_core, v4.std.node, v4.std.logic, v4.std.algebra. +// Status: T-4 Swift wave-1; fixed-width integer spellings are explicit, Int/UInt stay platform-word-width facts, Float/Double carry IEEE-754 precision, bool canonical-B decl-ref is E-6(b) staging. +// Anchor: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/ + +module v4.extdeps.languages.swift + +import v4.std.collection { List, Map, Set, list_append, list_snoc_item } +import v4.std.model_core { + EffectSemanticsDecl, + ModelCore, + PartialitySemanticsDecl, + PrimitiveFactBundle, + primitive_fact_axis_encoding, + primitive_fact_axis_overflow_disposition, + primitive_fact_axis_signedness, + primitive_fact_axis_surface_spelling, + primitive_fact_axis_width +} +import v4.std.node { Atom, Conj, Edge, Named, Node, Symbol, TypeNode } +import v4.std.logic { Bool, bool_boolean_algebra } +import v4.std.algebra { BooleanAlgebra, fold_list } + +// 🟒 coproduct dissolution β€” alternatives are one-at-a-time scalar widths. +type SwiftIntWidth + = Bits8 + | Bits16 + | Bits32 + | Bits64 + | PointerWord + +// 🟒 coproduct dissolution β€” alternatives are signedness facts. +type SwiftIntSignedness + = Signed + | Unsigned + +// 🟒 coproduct dissolution β€” alternatives are one-at-a-time floating widths. +type SwiftFloatWidth + = Bits32 + | Bits64 + +type SwiftStringRepresentation {} + +type SwiftCharacterRepresentation {} + +type SwiftUnitRepresentation {} + +type SwiftBoolRepresentation {} + +type SwiftIntegerOverflowSemantics {} + +// 🟒 coproduct dissolution β€” one scalar classifier at a time. +type SwiftScalar + = IntScalar { signedness: SwiftIntSignedness, width: SwiftIntWidth } + | FloatScalar { width: SwiftFloatWidth } + | BoolScalar + | CharacterScalar + | StringScalar + | VoidScalar + +type SwiftIntegerPrimitiveFacts { + surface_spelling: Symbol + signedness: SwiftIntSignedness + width: SwiftIntWidth + overflow: SwiftIntegerOverflowSemantics +} + +type SwiftFloatPrimitiveFacts { + surface_spelling: Symbol + width: SwiftFloatWidth + ieee754_binary: Symbol +} + +// Nonnumeric primitive rows β€” each arm carries its matching representation (P2). +// 🟒 coproduct dissolution β€” CP-3229-GREEN-TERMINAL. +type SwiftNonNumericPrimitiveFacts + = SwiftBoolPrimitiveFacts { + surface_spelling: Symbol + representation: SwiftBoolRepresentation + } + | SwiftCharacterPrimitiveFacts { + surface_spelling: Symbol + representation: SwiftCharacterRepresentation + } + | SwiftStringPrimitiveFacts { + surface_spelling: Symbol + representation: SwiftStringRepresentation + } + | SwiftVoidPrimitiveFacts { + surface_spelling: Symbol + representation: SwiftUnitRepresentation + } + +type SwiftLanguageModel { + language_identity: Symbol + canonical_symbols: Set + core: ModelCore +} + +data swift_language_model_surface_id: Symbol = swift_language_model_surface_id + +data swift_surface_spelling_int: Symbol = swift_surface_spelling_int +data swift_surface_spelling_int8: Symbol = swift_surface_spelling_int8 +data swift_surface_spelling_int16: Symbol = swift_surface_spelling_int16 +data swift_surface_spelling_int32: Symbol = swift_surface_spelling_int32 +data swift_surface_spelling_int64: Symbol = swift_surface_spelling_int64 +data swift_surface_spelling_uint: Symbol = swift_surface_spelling_uint +data swift_surface_spelling_uint8: Symbol = swift_surface_spelling_uint8 +data swift_surface_spelling_uint16: Symbol = swift_surface_spelling_uint16 +data swift_surface_spelling_uint32: Symbol = swift_surface_spelling_uint32 +data swift_surface_spelling_uint64: Symbol = swift_surface_spelling_uint64 +data swift_surface_spelling_float: Symbol = swift_surface_spelling_float +data swift_surface_spelling_double: Symbol = swift_surface_spelling_double +data swift_surface_spelling_bool: Symbol = swift_surface_spelling_bool +data swift_surface_spelling_character: Symbol = swift_surface_spelling_character +data swift_surface_spelling_string: Symbol = swift_surface_spelling_string +data swift_surface_spelling_void: Symbol = swift_surface_spelling_void + +data swift_facts_field_surface_spelling: Symbol = swift_facts_field_surface_spelling +data swift_facts_field_signedness: Symbol = swift_facts_field_signedness +data swift_facts_field_width: Symbol = swift_facts_field_width +data swift_facts_field_overflow: Symbol = swift_facts_field_overflow +data swift_facts_field_ieee754_binary: Symbol = swift_facts_field_ieee754_binary +data swift_facts_field_scalar: Symbol = swift_facts_field_scalar +data swift_facts_field_value_fact: Symbol = swift_facts_field_value_fact + +data swift_primitive_fact_axis_scalar_classifier: Symbol = swift_primitive_fact_axis_scalar_classifier + +data swift_tag_signed: Symbol = swift_tag_signed +data swift_tag_unsigned: Symbol = swift_tag_unsigned +data swift_tag_bits8: Symbol = swift_tag_bits8 +data swift_tag_bits16: Symbol = swift_tag_bits16 +data swift_tag_bits32: Symbol = swift_tag_bits32 +data swift_tag_bits64: Symbol = swift_tag_bits64 +data swift_tag_pointer_word: Symbol = swift_tag_pointer_word +data swift_tag_trap_on_overflow: Symbol = swift_tag_trap_on_overflow +data swift_tag_ieee754_binary32: Symbol = swift_tag_ieee754_binary32 +data swift_tag_ieee754_binary64: Symbol = swift_tag_ieee754_binary64 +data swift_tag_bool_representation: Symbol = swift_tag_bool_representation +data swift_tag_character_extended_grapheme_cluster: Symbol = swift_tag_character_extended_grapheme_cluster +data swift_tag_string_unicode_text: Symbol = swift_tag_string_unicode_text +data swift_tag_void_empty_tuple: Symbol = swift_tag_void_empty_tuple +data swift_tag_scalar_int: Symbol = swift_tag_scalar_int +data swift_tag_scalar_float: Symbol = swift_tag_scalar_float +data swift_tag_scalar_bool: Symbol = swift_tag_scalar_bool +data swift_tag_scalar_character: Symbol = swift_tag_scalar_character +data swift_tag_scalar_string: Symbol = swift_tag_scalar_string +data swift_tag_scalar_void: Symbol = swift_tag_scalar_void + +data swift_integer_overflow_trap: SwiftIntegerOverflowSemantics = SwiftIntegerOverflowSemantics {} +data swift_bool_representation: SwiftBoolRepresentation = SwiftBoolRepresentation {} +data swift_character_representation: SwiftCharacterRepresentation = SwiftCharacterRepresentation {} +data swift_string_representation: SwiftStringRepresentation = SwiftStringRepresentation {} +data swift_unit_representation: SwiftUnitRepresentation = SwiftUnitRepresentation {} + +data swift_facts_int: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_int, + signedness: Signed, + width: PointerWord, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_int8: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_int8, + signedness: Signed, + width: Bits8, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_int16: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_int16, + signedness: Signed, + width: Bits16, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_int32: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_int32, + signedness: Signed, + width: Bits32, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_int64: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_int64, + signedness: Signed, + width: Bits64, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_uint: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_uint, + signedness: Unsigned, + width: PointerWord, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_uint8: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_uint8, + signedness: Unsigned, + width: Bits8, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_uint16: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_uint16, + signedness: Unsigned, + width: Bits16, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_uint32: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_uint32, + signedness: Unsigned, + width: Bits32, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_uint64: SwiftIntegerPrimitiveFacts = SwiftIntegerPrimitiveFacts { + surface_spelling: swift_surface_spelling_uint64, + signedness: Unsigned, + width: Bits64, + overflow: swift_integer_overflow_trap, +} + +data swift_facts_float: SwiftFloatPrimitiveFacts = SwiftFloatPrimitiveFacts { + surface_spelling: swift_surface_spelling_float, + width: Bits32, + ieee754_binary: swift_tag_ieee754_binary32, +} + +data swift_facts_double: SwiftFloatPrimitiveFacts = SwiftFloatPrimitiveFacts { + surface_spelling: swift_surface_spelling_double, + width: Bits64, + ieee754_binary: swift_tag_ieee754_binary64, +} + +data swift_facts_bool: SwiftNonNumericPrimitiveFacts = SwiftBoolPrimitiveFacts { + surface_spelling: swift_surface_spelling_bool, + representation: swift_bool_representation, +} + +data swift_facts_character: SwiftNonNumericPrimitiveFacts = SwiftCharacterPrimitiveFacts { + surface_spelling: swift_surface_spelling_character, + representation: swift_character_representation, +} + +data swift_facts_string: SwiftNonNumericPrimitiveFacts = SwiftStringPrimitiveFacts { + surface_spelling: swift_surface_spelling_string, + representation: swift_string_representation, +} + +data swift_facts_void: SwiftNonNumericPrimitiveFacts = SwiftVoidPrimitiveFacts { + surface_spelling: swift_surface_spelling_void, + representation: swift_unit_representation, +} + +data swift_integer_facts_catalog: List = [ + swift_facts_int, + swift_facts_int8, + swift_facts_int16, + swift_facts_int32, + swift_facts_int64, + swift_facts_uint, + swift_facts_uint8, + swift_facts_uint16, + swift_facts_uint32, + swift_facts_uint64 +] + +data swift_float_facts_catalog: List = [ + swift_facts_float, + swift_facts_double +] + +data swift_nonnumeric_facts_catalog: List = [ + swift_facts_bool, + swift_facts_character, + swift_facts_string, + swift_facts_void +] + +// 🟑 canonical-B decl-ref Β· E-6(b) bounded-exception Β· scaffold feature:canonical-b-grounding-consumer Β· dissolve-on: B1-CANON+zip-fold consume the Swift bool row for coincidence-checking. +data swift_bool_grounding: BooleanAlgebra = bool_boolean_algebra + +fn swift_atom(id: Symbol) -> Node { + Node { + kind: TypeNode { connective: Atom { identity: id } }, + children: [] + } +} + +fn swift_named_edge(name: Symbol, target: Node) -> Edge { + Edge { label: Named { name: name }, target: target } +} + +fn swift_signedness_node(signedness: SwiftIntSignedness) -> Node { + match signedness { + Signed => swift_atom(id: swift_tag_signed) + Unsigned => swift_atom(id: swift_tag_unsigned) + } +} + +fn swift_width_node(width: SwiftIntWidth) -> Node { + match width { + Bits8 => swift_atom(id: swift_tag_bits8) + Bits16 => swift_atom(id: swift_tag_bits16) + Bits32 => swift_atom(id: swift_tag_bits32) + Bits64 => swift_atom(id: swift_tag_bits64) + PointerWord => swift_atom(id: swift_tag_pointer_word) + } +} + +fn swift_float_width_node(width: SwiftFloatWidth) -> Node { + match width { + Bits32 => swift_atom(id: swift_tag_bits32) + Bits64 => swift_atom(id: swift_tag_bits64) + } +} + +fn swift_overflow_node(overflow: SwiftIntegerOverflowSemantics) -> Node { + let _witness = overflow + swift_atom(id: swift_tag_trap_on_overflow) +} + +fn swift_scalar_node(scalar: SwiftScalar) -> Node { + match scalar { + IntScalar { signedness: _, width: _ } => swift_atom(id: swift_tag_scalar_int) + FloatScalar { width: _ } => swift_atom(id: swift_tag_scalar_float) + BoolScalar => swift_atom(id: swift_tag_scalar_bool) + CharacterScalar => swift_atom(id: swift_tag_scalar_character) + StringScalar => swift_atom(id: swift_tag_scalar_string) + VoidScalar => swift_atom(id: swift_tag_scalar_void) + } +} + +fn swift_nonnumeric_representation_node(facts: SwiftNonNumericPrimitiveFacts) -> Node { + match facts { + SwiftBoolPrimitiveFacts { representation: _ } => + swift_atom(id: swift_tag_bool_representation) + SwiftCharacterPrimitiveFacts { representation: _ } => + swift_atom(id: swift_tag_character_extended_grapheme_cluster) + SwiftStringPrimitiveFacts { representation: _ } => + swift_atom(id: swift_tag_string_unicode_text) + SwiftVoidPrimitiveFacts { representation: _ } => + swift_atom(id: swift_tag_void_empty_tuple) + } +} + +fn swift_nonnumeric_scalar_classifier_node(facts: SwiftNonNumericPrimitiveFacts) -> Node { + match facts { + SwiftBoolPrimitiveFacts { .. } => swift_atom(id: swift_tag_scalar_bool) + SwiftCharacterPrimitiveFacts { .. } => swift_atom(id: swift_tag_scalar_character) + SwiftStringPrimitiveFacts { .. } => swift_atom(id: swift_tag_scalar_string) + SwiftVoidPrimitiveFacts { .. } => swift_atom(id: swift_tag_scalar_void) + } +} + +fn swift_integer_facts_node(facts: SwiftIntegerPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + swift_named_edge( + name: swift_facts_field_surface_spelling, + target: swift_atom(id: facts.surface_spelling) + ), + swift_named_edge( + name: swift_facts_field_signedness, + target: swift_signedness_node(signedness: facts.signedness) + ), + swift_named_edge( + name: swift_facts_field_width, + target: swift_width_node(width: facts.width) + ), + swift_named_edge( + name: swift_facts_field_overflow, + target: swift_overflow_node(overflow: facts.overflow) + ) + ] + } +} + +fn swift_float_facts_node(facts: SwiftFloatPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + swift_named_edge( + name: swift_facts_field_surface_spelling, + target: swift_atom(id: facts.surface_spelling) + ), + swift_named_edge( + name: swift_facts_field_width, + target: swift_float_width_node(width: facts.width) + ), + swift_named_edge( + name: swift_facts_field_ieee754_binary, + target: swift_atom(id: facts.ieee754_binary) + ) + ] + } +} + +fn swift_nonnumeric_surface_spelling(facts: SwiftNonNumericPrimitiveFacts) -> Symbol { + match facts { + SwiftBoolPrimitiveFacts { surface_spelling, .. } => surface_spelling + SwiftCharacterPrimitiveFacts { surface_spelling, .. } => surface_spelling + SwiftStringPrimitiveFacts { surface_spelling, .. } => surface_spelling + SwiftVoidPrimitiveFacts { surface_spelling, .. } => surface_spelling + } +} + +fn swift_nonnumeric_facts_node(facts: SwiftNonNumericPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + swift_named_edge( + name: swift_facts_field_surface_spelling, + target: swift_atom(id: swift_nonnumeric_surface_spelling(facts: facts)) + ), + swift_named_edge( + name: swift_facts_field_scalar, + target: swift_nonnumeric_scalar_classifier_node(facts: facts) + ), + swift_named_edge( + name: swift_facts_field_value_fact, + target: swift_nonnumeric_representation_node(facts: facts) + ) + ] + } +} + +fn swift_primitive_fact_map_4( + axis0: Symbol, + fact0: Node, + axis1: Symbol, + fact1: Node, + axis2: Symbol, + fact2: Node, + axis3: Symbol, + fact3: Node +) -> Map { + map_insert( + map_insert( + map_insert( + map_insert(empty_map(), axis0, fact0), + axis1, + fact1 + ), + axis2, + fact2 + ), + axis3, + fact3 + ) +} + +fn swift_primitive_fact_map_3( + axis0: Symbol, + fact0: Node, + axis1: Symbol, + fact1: Node, + axis2: Symbol, + fact2: Node +) -> Map { + map_insert( + map_insert( + map_insert(empty_map(), axis0, fact0), + axis1, + fact1 + ), + axis2, + fact2 + ) +} + +fn swift_primitive_fact_map_2( + axis0: Symbol, + fact0: Node, + axis1: Symbol, + fact1: Node +) -> Map { + map_insert( + map_insert(empty_map(), axis0, fact0), + axis1, + fact1 + ) +} + +fn swift_primitive_bundle_from_integer_facts(facts: SwiftIntegerPrimitiveFacts) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: swift_integer_facts_node(facts: facts), + spec_facts: swift_primitive_fact_map_4( + axis0: primitive_fact_axis_surface_spelling, + fact0: swift_atom(id: facts.surface_spelling), + axis1: primitive_fact_axis_signedness, + fact1: swift_signedness_node(signedness: facts.signedness), + axis2: primitive_fact_axis_width, + fact2: swift_width_node(width: facts.width), + axis3: primitive_fact_axis_overflow_disposition, + fact3: swift_overflow_node(overflow: facts.overflow) + ) + } +} + +fn swift_primitive_bundle_from_float_facts(facts: SwiftFloatPrimitiveFacts) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: swift_float_facts_node(facts: facts), + spec_facts: swift_primitive_fact_map_3( + axis0: primitive_fact_axis_surface_spelling, + fact0: swift_atom(id: facts.surface_spelling), + axis1: primitive_fact_axis_width, + fact1: swift_float_width_node(width: facts.width), + axis2: primitive_fact_axis_encoding, + fact2: swift_atom(id: facts.ieee754_binary) + ) + } +} + +fn swift_primitive_bundle_from_nonnumeric_facts( + facts: SwiftNonNumericPrimitiveFacts +) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: swift_nonnumeric_facts_node(facts: facts), + spec_facts: swift_primitive_fact_map_2( + axis0: primitive_fact_axis_surface_spelling, + fact0: swift_atom(id: swift_nonnumeric_surface_spelling(facts: facts)), + axis1: swift_primitive_fact_axis_scalar_classifier, + fact1: swift_nonnumeric_scalar_classifier_node(facts: facts) + ) + } +} + +fn swift_primitive_bundles_from_integer_catalog() -> List { + fold_list( + xs: swift_integer_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: swift_primitive_bundle_from_integer_facts(facts: facts) + ) + } + ) +} + +fn swift_primitive_bundles_from_float_catalog() -> List { + fold_list( + xs: swift_float_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: swift_primitive_bundle_from_float_facts(facts: facts) + ) + } + ) +} + +fn swift_primitive_bundles_from_nonnumeric_catalog() -> List { + fold_list( + xs: swift_nonnumeric_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: swift_primitive_bundle_from_nonnumeric_facts(facts: facts) + ) + } + ) +} + +fn swift_wave1_primitive_fact_bundles() -> List { + list_append( + left: list_append( + left: swift_primitive_bundles_from_integer_catalog(), + right: swift_primitive_bundles_from_float_catalog() + ), + right: swift_primitive_bundles_from_nonnumeric_catalog() + ) +} + +fn swift_integer_catalog_surface_symbol_step( + sym: Symbol, + acc: Bool, + facts: SwiftIntegerPrimitiveFacts +) -> Bool { + acc || sym == facts.surface_spelling +} + +fn swift_float_catalog_surface_symbol_step( + sym: Symbol, + acc: Bool, + facts: SwiftFloatPrimitiveFacts +) -> Bool { + acc || sym == facts.surface_spelling +} + +fn swift_nonnumeric_catalog_surface_symbol_step( + sym: Symbol, + acc: Bool, + facts: SwiftNonNumericPrimitiveFacts +) -> Bool { + acc || sym == swift_nonnumeric_surface_spelling(facts: facts) +} + +fn swift_integer_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: swift_integer_facts_catalog, + empty: false, + cons: fn(acc, facts) { + swift_integer_catalog_surface_symbol_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn swift_float_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: swift_float_facts_catalog, + empty: false, + cons: fn(acc, facts) { + swift_float_catalog_surface_symbol_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn swift_nonnumeric_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: swift_nonnumeric_facts_catalog, + empty: false, + cons: fn(acc, facts) { + swift_nonnumeric_catalog_surface_symbol_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn swift_catalog_surface_symbol(sym: Symbol) -> Bool { + swift_integer_catalog_surface_symbol(sym: sym) || + swift_float_catalog_surface_symbol(sym: sym) || + swift_nonnumeric_catalog_surface_symbol(sym: sym) +} + +fn swift_language_model_canonical_symbols() -> Set { + Set { + member: fn(sym) { + swift_catalog_surface_symbol(sym: sym) + } + } +} + +fn swift_model_core_wave1() -> ModelCore { + ModelCore { + primitives: swift_wave1_primitive_fact_bundles(), + inhabitance: [], + laws: [], + effects: EffectSemanticsDecl { operations: [] }, + partiality: PartialitySemanticsDecl { operations: [] } + } +} + +fn swift_language_model_wave1() -> SwiftLanguageModel { + SwiftLanguageModel { + language_identity: swift_language_model_surface_id, + canonical_symbols: swift_language_model_canonical_symbols(), + core: swift_model_core_wave1() + } +} diff --git a/src/v4/extdeps/languages/typescript.dag b/src/v4/extdeps/languages/typescript.dag index aaf5ca18208..1434c597705 100644 --- a/src/v4/extdeps/languages/typescript.dag +++ b/src/v4/extdeps/languages/typescript.dag @@ -29,7 +29,7 @@ import v4.std.node { TypeNode } import v4.std.logic { Bool, bool_boolean_algebra } -import v4.std.algebra { BooleanAlgebra, fold_list } +import v4.std.algebra { BooleanAlgebra, Empty, fold_list } import v4.std.target_model { target_model_edge_declared_inhabitants } // 🟒 grounded. diff --git a/src/v4/test/claim/manual/swift_language_model_anchor.dag b/src/v4/test/claim/manual/swift_language_model_anchor.dag new file mode 100644 index 00000000000..cbe7b87d583 --- /dev/null +++ b/src/v4/test/claim/manual/swift_language_model_anchor.dag @@ -0,0 +1,19 @@ +// src/v4/test/claim/manual/swift_language_model_anchor.dag +// Scope: T-4 compile anchor β€” swift.dag LanguageModel and ModelCore wave-1. +// Owns: swift_anchor_language_model, swift_anchor_core. +// Consumes: extdeps/languages/swift.dag. +// Status: compile-only anchor. + +module v4.test.claim.manual.swift_language_model_anchor + +import v4.extdeps.languages.swift { + SwiftLanguageModel, + swift_language_model_wave1, + swift_model_core_wave1 +} +import v4.std.model_core { ModelCore } + +type swift_anchor_language_model = SwiftLanguageModel + +data swift_anchor_wave1: swift_anchor_language_model = swift_language_model_wave1() +data swift_anchor_core: ModelCore = swift_model_core_wave1()