diff --git a/dsl/extdeps/rust/cargo.dag b/dsl/extdeps/rust/cargo.dag index d8f6c82fba4..b19a82ebf9d 100644 --- a/dsl/extdeps/rust/cargo.dag +++ b/dsl/extdeps/rust/cargo.dag @@ -11,6 +11,7 @@ module extdeps.cargo import extdeps.cargo_version { CargoPackageVersion, CargoVersionRequirement, CargoToolVersionFloor } +import extdeps.version.semver { SemVerConstraint } import std.types { FilePathParts } // -- Edition ------------------------------------------------------- diff --git a/dsl/product/compute_fabric.dag b/dsl/product/compute_fabric.dag index a3ef95c61c6..160793d80ad 100644 --- a/dsl/product/compute_fabric.dag +++ b/dsl/product/compute_fabric.dag @@ -42,6 +42,7 @@ import std.measure { HardwareThreadCount, byte_size, byte_size_count, + measure_count, hardware_thread_count, hardware_thread_count_value, hertz, @@ -151,7 +152,10 @@ fn money_micros(count: Nat) -> MoneyMicros { } fn money_micros_count(m: MoneyMicros) -> Nat { - m.count + // Cross-module Measure alias (MoneyAmount): `.count` only peels where + // Measure is local, so route through the generic std.measure.measure_count + // accessor (same pattern as bandwidth_count in hardware_selection). + measure_count(m: m) } type ProviderIdentity = NonEmptyStr where brand("ProviderIdentity") diff --git a/dsl/product/hardware_selection.dag b/dsl/product/hardware_selection.dag index 08d31925673..5be7de40518 100644 --- a/dsl/product/hardware_selection.dag +++ b/dsl/product/hardware_selection.dag @@ -76,7 +76,10 @@ fn milliwatt(count: Nat) -> Milliwatt { } fn milliwatt_count(w: Milliwatt) -> Nat { - w.count + // Cross-module Measure alias (Measure): `.count` only peels + // where Measure is local, so route through the generic std.measure.measure_count + // accessor (same pattern as bandwidth_count below). + measure_count(m: w) } // === The decision point: five grounded axes ============================== diff --git a/dsl/std/measure.dag b/dsl/std/measure.dag index 851f2563e25..54247aea4dd 100644 --- a/dsl/std/measure.dag +++ b/dsl/std/measure.dag @@ -392,7 +392,7 @@ fn gibibyte(count: Nat) -> Gibibyte { } fn gibibyte_count(g: Gibibyte) -> Nat { - g.count + measure_count(g) } fn gibibyte_to_byte_size(g: Gibibyte) -> ByteSize { @@ -444,7 +444,7 @@ fn watt(count: Nat) -> Watt { } fn watt_count(w: Watt) -> Nat { - w.count + measure_count(w) } fn celsius(count: Int) -> Celsius { @@ -452,7 +452,7 @@ fn celsius(count: Int) -> Celsius { } fn celsius_count(c: Celsius) -> Int { - c.count + measure_count(c) } fn rpm(count: Nat) -> RevolutionsPerMinute { @@ -460,7 +460,7 @@ fn rpm(count: Nat) -> RevolutionsPerMinute { } fn rpm_count(r: RevolutionsPerMinute) -> Nat { - r.count + measure_count(r) } // --- MoneyAmount: price magnitude carrier ------------------------------ @@ -509,7 +509,7 @@ fn money_amount_micro(count: Nat) -> MoneyAmountMicro { } fn money_amount_micro_count(m: MoneyAmountMicro) -> Nat { - m.count + measure_count(m) } fn byte_size(count: Nat) -> ByteSize { @@ -517,7 +517,7 @@ fn byte_size(count: Nat) -> ByteSize { } fn byte_size_count(b: ByteSize) -> Nat { - b.count + measure_count(b) } fn bit_width(count: Nat) -> BitWidth { @@ -525,7 +525,7 @@ fn bit_width(count: Nat) -> BitWidth { } fn bit_width_count(b: BitWidth) -> Nat { - b.count + measure_count(b) } fn hertz(count: Nat) -> Hertz { @@ -533,7 +533,7 @@ fn hertz(count: Nat) -> Hertz { } fn hertz_count(h: Hertz) -> Nat { - h.count + measure_count(h) } fn hardware_thread_count(count: Nat) -> HardwareThreadCount { @@ -541,5 +541,5 @@ fn hardware_thread_count(count: Nat) -> HardwareThreadCount { } fn hardware_thread_count_value(t: HardwareThreadCount) -> Nat { - t.count + measure_count(t) } diff --git a/src/v1/04_emit_info.dag b/src/v1/04_emit_info.dag index 36eb082824a..e9e385f05f1 100644 --- a/src/v1/04_emit_info.dag +++ b/src/v1/04_emit_info.dag @@ -41,6 +41,20 @@ type TypeSummary { has_fn_fields: Bool } +// RustCorpusRepr: which container/text REALIZATION HANDLER the Rust emitter +// selects for the WHOLE corpus. The spec is unchanged (List = FreeMonoid +// at std/types.dag; String) — this names WHICH of the §2 N handlers realizes it. +// It is a whole-CORPUS property, computed ONCE at the emit boundary +// (rust_corpus_repr in 05_emit_rust.dag) and threaded down as an individual +// emit-info field (like shared_types), never decided per-module: a corpus that +// bundles any v1 seed source (src/v1) emits the HOST representation end-to-end +// (§7 — the bootstrap seed is host: List→Vec, String, Nat/Int→i64); a pure v2 +// target keeps the faithful FreeMonoid carrier. Selecting once and threading the +// selection makes per-module divergence UNWRITABLE (§5 construction-not-check). +// §6-TRANSITIONAL: HostNative dissolves when src/v1 is deleted (seed→0 ⇒ no seed +// source ⇒ rust_corpus_repr is FaithfulFreeMonoid uniformly). +type RustCorpusRepr = HostNative | FaithfulFreeMonoid + // EmitGraphInfo: the reconcile→emit boundary contract. // // Invariant: emit never calls back into infer. All data the emitter needs @@ -78,6 +92,12 @@ type EmitGraphInfo { // (no Consumed) and fan-out > 1. These can be passed by borrow (&Rc). read_only_params_index: Map> read_only_params: Set + // Corpus-global Rust container/text realization handler (§2 one-spec-N-handlers). + // Computed ONCE at the emit boundary (rust_corpus_repr) and read by the + // type-renderers' leaf gates (rust_seed_host_container_base / _numeric_alias / + // rust_named_type_base) so every module emits the SAME representation — the + // single authority for the host-vs-faithful selection. §6-transitional. + corpus_repr: RustCorpusRepr } type EmitInfoBuildState { @@ -100,7 +120,10 @@ fn empty_emit_graph_info() -> EmitGraphInfo { variant_to_enum: empty_map(), owned_bindings: empty_set(), read_only_params_index: empty_map(), - read_only_params: empty_set() + read_only_params: empty_set(), + // Default to the faithful v2-target carrier; emit_rust overrides to HostNative + // for a corpus that bundles v1 seed source (rust_corpus_repr, computed once). + corpus_repr: FaithfulFreeMonoid } } diff --git a/src/v1/04_infer.dag b/src/v1/04_infer.dag index f57bef1be86..a65e63baae4 100644 --- a/src/v1/04_infer.dag +++ b/src/v1/04_infer.dag @@ -111,6 +111,7 @@ import v1.compiler.infer_sigs { import v1.compiler.infer_emit_info { TypeRepr, StructRepr, EnumRepr, TypeSummary, EmitGraphInfo, EmitInfoBuildState, + RustCorpusRepr, HostNative, FaithfulFreeMonoid, empty_emit_graph_info, lookup_emit_type_summary, build_struct_field_summaries, build_enum_field_summaries, add_emit_item_summary, derive_variant_to_enum @@ -6384,6 +6385,20 @@ fn build_positional_payload_variants(modules: List, type_summaries: ) } +// Corpus-global Rust representation selector (§2 handler selection). HostNative +// iff the corpus bundles any v1 seed source (src/v1) — then the whole crate emits +// the host representation (List→Vec, String, Nat/Int→i64) so the bootstrap seed +// compiles (§7); otherwise the faithful v2-target FreeMonoid carrier. Computed +// ONCE here (the single authority on EmitGraphInfo.corpus_repr); every emit site +// COPIES the field and the type-renderers READ it — never recomputed downstream, +// which is what makes per-module representation divergence unwritable (§5). +// §6-transitional: collapses to FaithfulFreeMonoid when src/v1 is deleted. +fn rust_corpus_repr(modules: List) -> RustCorpusRepr { + let has_seed = modules |> any(m => + map_keys(m.type_env.source_indices) |> any(k => contains(k, "/v1/") || contains(k, "src/v1"))) + if has_seed { HostNative } else { FaithfulFreeMonoid } +} + fn build_emit_graph_info(modules: List) -> EmitGraphInfo { let init = EmitInfoBuildState { type_summaries: empty_map() @@ -6412,7 +6427,8 @@ fn build_emit_graph_info(modules: List) -> EmitGraphInfo { variant_to_enum: vtoe, owned_bindings: empty_set(), read_only_params_index: empty_map(), - read_only_params: empty_set() + read_only_params: empty_set(), + corpus_repr: rust_corpus_repr(modules: modules) } } diff --git a/src/v1/05_emit_rust.dag b/src/v1/05_emit_rust.dag index 8328f8a32e2..6e5a9a4a711 100644 --- a/src/v1/05_emit_rust.dag +++ b/src/v1/05_emit_rust.dag @@ -61,7 +61,8 @@ import v1.std.core { make_span, with_required_cardinality, Connective, Conj, Disj, NoConnective, Cardinality, Required, CardOptional, - is_rest_transport, is_shell_transport, is_file_transport + is_rest_transport, is_shell_transport, is_file_transport, + empty_intern_table } import v1.compiler.artifact { RenderTarget, Rust } @@ -110,14 +111,14 @@ import v1.compiler.infer { expand_type_for_field_access } import v1.compiler.infer_emit_info { - EmitGraphInfo, TypeSummary, StructRepr, EnumRepr, + EmitGraphInfo, RustCorpusRepr, HostNative, FaithfulFreeMonoid, TypeSummary, StructRepr, EnumRepr, lookup_emit_type_summary, is_enum_in_summaries, find_variant_parent, is_known_variant, variant_belongs_to_enum, variant_summary_key } import v1.compiler.resolve { get_exported_names } import v1.compiler.infer_resolve { lookup_unit_variant_phantom_type, is_width_nat_type_literal } import v1.compiler.ownership { OwnershipProof, analyze_ownership, analyze_single_fold, build_movable_set, build_read_only_params, collect_callable_refs } -import std.induction { SubValueUnknown } +import std.induction { SubValueUnknown, InductiveField } import v1.compiler.emit { BlockEmitState, TcoFrame, TcoReassignInput, InterpPart, @@ -153,28 +154,29 @@ import v1.compiler.emit_core_support { is_type_alias_return_node, is_service_item, is_type_def_item, is_type_alias_item, is_type_decl_item, is_function_item, is_data_def_item, is_service_def_item, - is_resource_def_item, has_mock_prefix, extract_test_projections + is_resource_def_item, has_mock_prefix, extract_test_projections, + is_bare_leaf_item } -fn render_rust_type(n: Node, shared_types: Set, source_indices: Map) -> String { +fn render_rust_type(n: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { match n.inferred { Present { value: TypeVariable { id: tv } } => tv _ => match find_property(props: n.properties, prop_name: "__applied_type_args", source_indices: source_indices) { Present { value: applied } => if applied.children |> count > 0 { - render_rust_applied_type_shared(n: applied, generic_param_names: [], shared_types: shared_types, source_indices: source_indices, variant_to_enum: empty_map(), env: TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: source_indices, intern_table: empty_intern_table() }) + render_rust_applied_type_shared(n: applied, generic_param_names: [], shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: empty_map(), env: TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: source_indices, intern_table: empty_intern_table() }) } else { - render_rust_type_without_applied_binding(n: n, shared_types: shared_types, source_indices: source_indices) + render_rust_type_without_applied_binding(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } - Absent => render_rust_type_without_applied_binding(n: n, shared_types: shared_types, source_indices: source_indices) + Absent => render_rust_type_without_applied_binding(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } } -fn render_rust_type_without_applied_binding(n: Node, shared_types: Set, source_indices: Map) -> String { +fn render_rust_type_without_applied_binding(n: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { if n.connective == NoConnective && n.children |> count > 0 && !is_container_type(name: authored_name_at(source_indices: source_indices, node: n)) { - render_rust_applied_type_shared(n: n, generic_param_names: [], shared_types: shared_types, source_indices: source_indices, variant_to_enum: empty_map(), env: TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: source_indices, intern_table: empty_intern_table() }) + render_rust_applied_type_shared(n: n, generic_param_names: [], shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: empty_map(), env: TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: source_indices, intern_table: empty_intern_table() }) } else if node_is_set_collection(n: n, source_indices: source_indices) { match n.children |> first { Present { value: elem_child } => @@ -192,7 +194,7 @@ fn render_rust_type_without_applied_binding(n: Node, shared_types: Set, } } else { let tn = authored_name_at(source_indices: source_indices, node: n) - if tn == "String" && n.children |> count == 0 && rust_emit_faithful_text_carrier(source_indices: source_indices) { + if tn == "String" && n.children |> count == 0 && corpus_repr_is_faithful(corpus_repr: corpus_repr) { render_rust_text_carrier(shared_types: shared_types) } else { render_node_type(n: n, target: Rust, shared_types: shared_types, source_indices: source_indices) @@ -210,30 +212,38 @@ fn rust_type_is_rc_wrapped(type_name: String) -> Bool { // §3 faithful DAG String carrier for v2 Rust self-host (String = FreeMonoid, Char = Nat). // §7: carrier is v2-self-host target only — v1 seed/bootstrap keeps host String. -fn rust_corpus_includes_v1_compiler(source_indices: Map) -> Bool { - map_keys(source_indices) |> any(k => contains(k, "/v1/") || contains(k, "src/v1")) +// The corpus-representation choice is now a single corpus-global authority: +// `rust_corpus_repr` (04_infer.dag) computes RustCorpusRepr ONCE over all modules and +// threads it as `corpus_repr` to every renderer/emitter (EmitGraphInfo.corpus_repr). +// The old per-module gates (rust_corpus_includes_v1_compiler / rust_emit_faithful_text_carrier) +// were deleted: a per-module gate let a dsl module in a v1-bundled crate emit the faithful +// carrier while its siblings emit host — divergence was WRITABLE (a §5 dual-authority breach). +// §6-transitional: when src/v1 is deleted (seed→zero) no module has_seed, so corpus_repr +// resolves uniformly to FaithfulFreeMonoid — the pure-v2 faithful target; HostNative dissolves with the seed. +// Shape-reading predicates over the single corpus_repr authority (match, not `==`: +// a bare-variant `==` adjacent to a block `{` collides with record-literal syntax). +fn corpus_repr_is_faithful(corpus_repr: RustCorpusRepr) -> Bool { + match corpus_repr { FaithfulFreeMonoid => true HostNative => false } +} +fn corpus_repr_is_host(corpus_repr: RustCorpusRepr) -> Bool { + match corpus_repr { HostNative => true FaithfulFreeMonoid => false } } - -fn rust_emit_faithful_text_carrier(source_indices: Map) -> Bool { - !rust_corpus_includes_v1_compiler(source_indices: source_indices) -} - fn render_rust_text_carrier(shared_types: Set) -> String { render_rust_shared_type_if_needed(type_name: "FreeMonoid", rendered: "FreeMonoid", shared_types: shared_types) } // §2 — route ALL host→DAG String boundary bridges through HostStringText seam (one authority). // §7: seam wrappers are v2-self-host only; v1 seed keeps host String (no v2_std_text module). -fn emit_rust_host_to_dag_string_via_seam(host_expr: String, source_indices: Map) -> String { - if rust_emit_faithful_text_carrier(source_indices: source_indices) { +fn emit_rust_host_to_dag_string_via_seam(host_expr: String, corpus_repr: RustCorpusRepr) -> String { + if corpus_repr_is_faithful(corpus_repr: corpus_repr) { concat("crate::v2_std_text::host_string_text_from_rust_host(", host_expr, ")") } else { host_expr } } -fn emit_rust_dag_string_to_host_via_seam(dag_expr: String, source_indices: Map) -> String { - if rust_emit_faithful_text_carrier(source_indices: source_indices) { +fn emit_rust_dag_string_to_host_via_seam(dag_expr: String, corpus_repr: RustCorpusRepr) -> String { + if corpus_repr_is_faithful(corpus_repr: corpus_repr) { concat("crate::v2_std_text::host_string_text_to_rust_host(", dag_expr, ")") } else { dag_expr @@ -271,25 +281,40 @@ fn rust_opaque_kernel_alias_carrier(name: String) -> String? { // target), the algebraic numeric tower (Nat = CommutativeSemiring, // Int = AbelianGroup>) maps to the host primitive i64 -- the // numeric analogue of String -> host String in the seed branch. Gated by the SAME -// rust_corpus_includes_v1_compiler authority as the text carrier (single lever, no -// parallel mechanism). The v2-target faithful numeric representation is escalated to +// corpus-global `corpus_repr` (RustCorpusRepr) authority as the text carrier (single +// lever, no parallel mechanism). The v2-target faithful numeric representation is escalated to // operator + non-blocking, so the faithful branch leaves the algebraic alias intact. // The seed numeric ops (nat_compare/nat_max/nat_min) use /.clone(), all native to // i64, so the alias-RHS override alone clears them and the Nat-as-number consumers // (E0277/E0369). DISSOLUTION: remove when the numeric tower gains a faithful // host-realization seam mirroring the text carrier (emit_rust_host_to_dag_string_via_seam). -fn rust_seed_host_numeric_alias(name: String, source_indices: Map) -> String? { - if (name == "Nat" || name == "Int") && rust_corpus_includes_v1_compiler(source_indices: source_indices) { +fn rust_seed_host_numeric_alias(name: String, corpus_repr: RustCorpusRepr) -> String? { + if (name == "Nat" || name == "Int") && corpus_repr_is_host(corpus_repr: corpus_repr) { Present { value: "i64" } } else { none } } -fn rust_named_type_base(name: String, source_indices: Map) -> String { +// SEED carrier (container analogue of String->host / Nat->i64): in the v1-seed +// branch the List nominal renders as the HOST CONTAINER the v1_rt Vec ops already +// use, so the nominal resolves (E0425/E0432) in the type-rendering paths that +// preserve nominals (render_rust_applied_type fn-sigs, render_rust_alias_rhs_type). +// Carrier-specific (List only) and GUARDED — does NOT touch the general +// preserve-nominal alias-RHS policy for non-container nominals (FreeMonoid/Box) or +// the v2-TARGET faithful FreeMonoid representation. List ops stay Vec-based. +fn rust_seed_host_container_base(name: String, corpus_repr: RustCorpusRepr) -> String? { + if name == "List" && corpus_repr_is_host(corpus_repr: corpus_repr) { + Present { value: "Vec" } + } else { + none + } +} + +fn rust_named_type_base(name: String, corpus_repr: RustCorpusRepr) -> String { if name == "Witness" || name == "witness" { "Witness" - } else if name == "String" && rust_emit_faithful_text_carrier(source_indices: source_indices) { + } else if name == "String" && corpus_repr_is_faithful(corpus_repr: corpus_repr) { "FreeMonoid" } else { coerce_primitive_type(target: Rust, dag_name: name) @@ -325,41 +350,44 @@ fn is_parametric_opaque_type_base(type_name: String, def_mod_filename: String, t } } -fn render_rust_phantom_opaque_applied_type_arg(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, scope: InferScope, imports: List, registry: Map, module_name: String, export_sets: Map>, typed_modules: List, module_index: ModuleIndex, variant_to_enum: Map) -> String { +fn render_rust_phantom_opaque_applied_type_arg(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, scope: InferScope, imports: List, registry: Map, module_name: String, export_sets: Map>, typed_modules: List, module_index: ModuleIndex, variant_to_enum: Map) -> String { if is_width_nat_type_literal(n: n) { "()" } else { - render_rust_alias_rhs_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, scope: scope, imports: imports, registry: registry, module_name: module_name, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index, variant_to_enum: variant_to_enum) + render_rust_alias_rhs_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, scope: scope, imports: imports, registry: registry, module_name: module_name, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index, variant_to_enum: variant_to_enum) } } -fn render_rust_phantom_opaque_applied_decl_arg(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { +fn render_rust_phantom_opaque_applied_decl_arg(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { if is_width_nat_type_literal(n: n) { "()" } else { - render_rust_decl_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_decl_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } } -fn render_rust_applied_type_arg(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { +fn render_rust_applied_type_arg(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { match n.inferred { Present { value: TypeVariable { id: tv } } => tv - _ => render_rust_decl_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + _ => render_rust_decl_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } } -fn render_rust_applied_type(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { +fn render_rust_applied_type(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { let base_name = authored_name_at(source_indices: source_indices, node: n) - let base = rust_named_type_base(name: base_name, source_indices: source_indices) + let base = match rust_seed_host_container_base(name: base_name, corpus_repr: corpus_repr) { + Present { value: host } => host + Absent => rust_named_type_base(name: base_name, corpus_repr: corpus_repr) + } if n.children |> count == 0 { base } else { let peel = is_parametric_opaque_type_by_name(env: env, type_name: base_name) let args = n.children |> map(arg => if peel { - render_rust_phantom_opaque_applied_decl_arg(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_phantom_opaque_applied_decl_arg(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } else { - render_rust_applied_type_arg(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_applied_type_arg(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } ) |> join(separator: ", ") concat(base, "<", args, ">") @@ -373,15 +401,15 @@ fn render_rust_shared_type_if_needed(type_name: String, rendered: String, shared } // Single authority: shared_types decides Rc<> on rendered Rust type shells. -fn render_rust_applied_type_shared(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { - let rendered = render_rust_applied_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) +fn render_rust_applied_type_shared(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { + let rendered = render_rust_applied_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) let type_name = authored_name_at(source_indices: source_indices, node: n) render_rust_shared_type_if_needed(type_name: type_name, rendered: rendered, shared_types: shared_types) } // Generic type-param leaves compose with the canonical renderer (else arm); // direct self-recursion on type-arg children keeps regen_stage0 stacker guard. -fn render_rust_decl_type(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { +fn render_rust_decl_type(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { let applied_prop = find_property(props: n.properties, prop_name: "__applied_type_args", source_indices: source_indices) let applied_overlay = match applied_prop { Present { value: applied } => @@ -390,12 +418,12 @@ fn render_rust_decl_type(n: Node, generic_param_names: List, shared_type } match applied_overlay { Present { value: applied } => - render_rust_applied_type_shared(n: applied, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_applied_type_shared(n: applied, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) Absent => let name = authored_name_at(source_indices: source_indices, node: n) if n.connective == NoConnective && n.children |> count == 0 && (generic_param_names |> any(g => g == name)) { name - } else if n.connective == NoConnective && n.children |> count == 0 && applied_prop == none && name == "String" && rust_emit_faithful_text_carrier(source_indices: source_indices) { + } else if n.connective == NoConnective && n.children |> count == 0 && applied_prop == none && name == "String" && corpus_repr_is_faithful(corpus_repr: corpus_repr) { render_rust_text_carrier(shared_types: shared_types) } else if n.connective == NoConnective && n.children |> count == 0 && applied_prop == none && set_contains(shared_types, name) { let rendered = rust_render_type_leaf_name(name: name, variant_to_enum: variant_to_enum, env: env) @@ -404,20 +432,20 @@ fn render_rust_decl_type(n: Node, generic_param_names: List, shared_type if !is_container_type(name: name) && rust_fn_sig_peel_closed_alias(env: env, n: n) { render_rust_shared_type_if_needed(type_name: name, rendered: name, shared_types: shared_types) } else { - let base = rust_named_type_base(name: name, source_indices: source_indices) + let base = rust_named_type_base(name: name, corpus_repr: corpus_repr) let peel = is_parametric_opaque_type_by_name(env: env, type_name: name) let args = n.children |> map(arg => if peel { - render_rust_phantom_opaque_applied_decl_arg(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_phantom_opaque_applied_decl_arg(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } else { - render_rust_decl_type(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_decl_type(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } ) |> join(separator: ", ") let applied_ty = concat(base, "<", args, ">") render_rust_shared_type_if_needed(type_name: name, rendered: applied_ty, shared_types: shared_types) } } else { - render_rust_type_with_applied_binding(n: n, shared_types: shared_types, source_indices: source_indices) + render_rust_type_with_applied_binding(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } } @@ -445,20 +473,20 @@ fn rust_fn_sig_peel_closed_alias(env: TypeEnv, n: Node) -> Bool { (binding.params |> count) == 0 } -fn render_rust_fn_sig_type(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { +fn render_rust_fn_sig_type(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { let name = authored_name_at(source_indices: source_indices, node: n) - if n.connective == NoConnective && n.children |> count == 0 && name == "String" && rust_emit_faithful_text_carrier(source_indices: source_indices) { + if n.connective == NoConnective && n.children |> count == 0 && name == "String" && corpus_repr_is_faithful(corpus_repr: corpus_repr) { render_rust_text_carrier(shared_types: shared_types) } else if n.connective == NoConnective && n.children |> count > 0 && !is_container_type(name: name) && rust_fn_sig_peel_closed_alias(env: env, n: n) { render_rust_shared_type_if_needed(type_name: name, rendered: name, shared_types: shared_types) } else if generic_param_names |> count > 0 { - render_rust_decl_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_decl_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } else { - render_rust_fn_sig_type_applied_binding(n: n, shared_types: shared_types, source_indices: source_indices, env: env) + render_rust_fn_sig_type_applied_binding(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, env: env) } } -fn render_rust_fn_sig_type_applied_binding(n: Node, shared_types: Set, source_indices: Map, env: TypeEnv) -> String { +fn render_rust_fn_sig_type_applied_binding(n: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, env: TypeEnv) -> String { match find_property(props: n.properties, prop_name: "__applied_type_args", source_indices: source_indices) { Present { value: applied } => if applied.children |> count > 0 { @@ -466,23 +494,26 @@ fn render_rust_fn_sig_type_applied_binding(n: Node, shared_types: Set, s if outer_name != "" && n.connective == NoConnective && (n.children |> count) == 0 && rust_fn_sig_peel_closed_alias(env: env, n: n) { render_rust_shared_type_if_needed(type_name: outer_name, rendered: outer_name, shared_types: shared_types) } else { - render_rust_type_with_applied_binding(n: n, shared_types: shared_types, source_indices: source_indices) + render_rust_type_with_applied_binding(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } else { - render_rust_type_with_applied_binding(n: n, shared_types: shared_types, source_indices: source_indices) + render_rust_type_with_applied_binding(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } - Absent => render_rust_type_with_applied_binding(n: n, shared_types: shared_types, source_indices: source_indices) + Absent => render_rust_type_with_applied_binding(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } // Alias RHS: preserve nominal DAG type names (FreeMonoid, Box) — no container coercion. // Qualify bases from defining modules when RHS type lives outside the alias module. -fn render_rust_alias_rhs_type(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, scope: InferScope, imports: List, registry: Map, module_name: String, export_sets: Map>, typed_modules: List, module_index: ModuleIndex, variant_to_enum: Map) -> String { +fn render_rust_alias_rhs_type(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, scope: InferScope, imports: List, registry: Map, module_name: String, export_sets: Map>, typed_modules: List, module_index: ModuleIndex, variant_to_enum: Map) -> String { let name = authored_name_at(source_indices: source_indices, node: n) if n.connective == NoConnective && n.children |> count == 0 && (generic_param_names |> any(g => g == name)) { name } else if n.connective == NoConnective && n.children |> count == 0 { - if name == "String" && rust_emit_faithful_text_carrier(source_indices: source_indices) { + match rust_seed_host_numeric_alias(name: name, corpus_repr: corpus_repr) { + Present { value: host } => host + Absent => + if name == "String" && corpus_repr_is_faithful(corpus_repr: corpus_repr) { render_rust_text_carrier(shared_types: shared_types) } else { match rust_opaque_kernel_alias_carrier(name: name) { @@ -493,20 +524,24 @@ fn render_rust_alias_rhs_type(n: Node, generic_param_names: List, shared } } } + } } else if n.connective == NoConnective && n.children |> count > 0 { let local_mod = module_to_filename(name: module_name) let def_mod = alias_rhs_rust_qualify_module_filename(name: name, alias_module: module_name, imports: imports, scope: scope, registry: registry, export_sets: export_sets, typed_modules: typed_modules, source_indices: source_indices, module_index: module_index) - let base = if def_mod != local_mod { - concat("crate::", def_mod, "::", name) - } else { - name + let base = match rust_seed_host_container_base(name: name, corpus_repr: corpus_repr) { + Present { value: host } => host + Absent => if def_mod != local_mod { + concat("crate::", def_mod, "::", name) + } else { + name + } } let peel = is_parametric_opaque_type_base(type_name: name, def_mod_filename: def_mod, typed_modules: typed_modules, source_indices: source_indices, module_index: module_index) let args = n.children |> map(arg => if peel { - render_rust_phantom_opaque_applied_type_arg(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, scope: scope, imports: imports, registry: registry, module_name: module_name, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index, variant_to_enum: variant_to_enum) + render_rust_phantom_opaque_applied_type_arg(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, scope: scope, imports: imports, registry: registry, module_name: module_name, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index, variant_to_enum: variant_to_enum) } else { - render_rust_alias_rhs_type(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, scope: scope, imports: imports, registry: registry, module_name: module_name, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index, variant_to_enum: variant_to_enum) + render_rust_alias_rhs_type(n: arg, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, scope: scope, imports: imports, registry: registry, module_name: module_name, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index, variant_to_enum: variant_to_enum) } ) |> join(separator: ", ") let applied_ty = concat(base, "<", args, ">") @@ -516,7 +551,7 @@ fn render_rust_alias_rhs_type(n: Node, generic_param_names: List, shared applied_ty } } else { - render_rust_type(n: n, shared_types: shared_types, source_indices: source_indices) + render_rust_type(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } @@ -1469,7 +1504,8 @@ fn emit_rust(typed: ResolvedGraph) -> EmitResult { variant_to_enum: base_info.variant_to_enum, owned_bindings: empty_set(), read_only_params_index: ownership.read_only_params_index, - read_only_params: empty_set() + read_only_params: empty_set(), + corpus_repr: base_info.corpus_repr } let shared_types = emit_info.shared_types let registry = typed.item_registry @@ -1493,7 +1529,8 @@ fn emit_rust(typed: ResolvedGraph) -> EmitResult { let test_files = typed.modules |> map(tm => emit_test_file( module_name: authored_name_at(source_indices: tm.type_env.source_indices, node: tm.module), - projections: test_projections |> filter(p => p.module_name == authored_name_at(source_indices: tm.type_env.source_indices, node: tm.module)))) + projections: test_projections |> filter(p => p.module_name == authored_name_at(source_indices: tm.type_env.source_indices, node: tm.module)), + corpus_repr: emit_info.corpus_repr)) |> filter(f => f.path != "") let has_services = has_service_items(typed: typed) let has_pipeline = typed.modules |> any(m => authored_name_at(source_indices: m.type_env.source_indices, node: m.module) == "v1.compiler.compile") @@ -1553,7 +1590,11 @@ fn emit_lib_rs_from_files(all_module_files: List, has_compiler_tests: } let shared_types = emit_non_empty_wrappers() let content = concat("// Generated by v1 compiler -- do not edit.\n\n", - "#![allow(unused_imports, unused_variables, unused_mut, unused_parens, dead_code, unreachable_patterns, non_shorthand_field_patterns, suspicious_double_ref_op, clippy::all)]\n\n", + "#![allow(unused_imports, unused_variables, unused_mut, unused_parens, dead_code, unreachable_patterns, non_shorthand_field_patterns, suspicious_double_ref_op, clippy::all)]\n", + // serde_json::json! expands recursively (json_internal! TT-munching); larger emitted + // test literals exceed rustc's default macro recursion_limit of 128. Raise it crate-wide + // -- serde_json's own documented fix, a crate-config attribute, not a per-literal change. + "#![recursion_limit = \"256\"]\n\n", mod_decls |> join(separator: "\n"), hand_maintained_mods, "\n\n", shared_types, @@ -1581,7 +1622,8 @@ fn emit_module(typed_module: TypedModule, registry: Map) -> Te variant_to_enum: base_info.variant_to_enum, owned_bindings: empty_set(), read_only_params_index: base_info.read_only_params_index, - read_only_params: empty_set() + read_only_params: empty_set(), + corpus_repr: base_info.corpus_repr } let shared_types = emit_info.shared_types let export_sets = build_module_export_sets(modules: [typed_module]) @@ -2924,7 +2966,7 @@ fn emit_typed_item(item: Node, module_name: String, registry: Map concat(rust_visibility_prefix(), rust_items().type_alias_keyword, " ", item_text, " = ", host, ";") Absent => @@ -2932,6 +2974,7 @@ fn emit_typed_item(item: Node, module_name: String, registry: Map count) == 0 && rust_nominal_identity_carrier_type_eligible(type_name: item_text) { rust_nominal_identity_carrier_def(name: item_text) - } else if is_emittable_parametric_type_alias_item(item: item, item_text: item_text, source_indices: env.source_indices, module_name: module_name, imports: imports, scope: scope, registry: registry, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index) { - let type_params = emit_type_params(params: item.params, source_indices: env.source_indices) - let generic_names = item_generic_param_names(item: item, source_indices: env.source_indices) - concat( - rust_visibility_prefix(), - rust_items().type_alias_keyword, - " ", - item_text, - type_params, - " = ", - render_rust_alias_rhs_type( - n: resolved_type(n: item), - generic_param_names: generic_names, - shared_types: shared_types, - source_indices: env.source_indices, - scope: scope, - imports: imports, - registry: registry, - module_name: module_name, - export_sets: export_sets, - typed_modules: typed_modules, - module_index: module_index, - variant_to_enum: emit_info.variant_to_enum), - ";" - ) - } else if is_parametric_opaque_type_decl_item(item: item, source_indices: env.source_indices) { - emit_parametric_phantom_opaque_struct(item: item, source_indices: env.source_indices) } else { - "" + // Seed corpus: a canonical container decl (`type List = + // FreeMonoid`) is NOT emittable-parametric (its FreeMonoid RHS + // shell has no Rust nominal authority), so it would skip to `""` and leave + // `List` undefined while the seed still references it (`list_length`'s + // `Rc>` sig, consumers' `use crate::std_types::List`). Emit it as a + // host-container alias (`pub type List = Vec`) so every + // `List` reference + import resolves. Corpus-gated via + // `rust_seed_host_container_base` (List-only, v1-compiler seed only); the + // faithful v2-target emit keeps the FreeMonoid algebra (Absent → existing + // path). Dissolves with the seed. + match rust_seed_host_container_base(name: item_text, corpus_repr: emit_info.corpus_repr) { + Present { value: host } => + let type_params = emit_type_params(params: item.params, source_indices: env.source_indices) + let generic_names = item_generic_param_names(item: item, source_indices: env.source_indices) + concat( + rust_visibility_prefix(), + rust_items().type_alias_keyword, + " ", + item_text, + type_params, + " = ", + host, + "<", + generic_names |> join(separator: ", "), + ">;" + ) + Absent => + if is_emittable_parametric_type_alias_item(item: item, item_text: item_text, source_indices: env.source_indices, module_name: module_name, imports: imports, scope: scope, registry: registry, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index) { + let type_params = emit_type_params(params: item.params, source_indices: env.source_indices) + let generic_names = item_generic_param_names(item: item, source_indices: env.source_indices) + concat( + rust_visibility_prefix(), + rust_items().type_alias_keyword, + " ", + item_text, + type_params, + " = ", + render_rust_alias_rhs_type( + n: resolved_type(n: item), + generic_param_names: generic_names, + shared_types: shared_types, + corpus_repr: emit_info.corpus_repr, + source_indices: env.source_indices, + scope: scope, + imports: imports, + registry: registry, + module_name: module_name, + export_sets: export_sets, + typed_modules: typed_modules, + module_index: module_index, + variant_to_enum: emit_info.variant_to_enum), + ";" + ) + } else if is_parametric_opaque_type_decl_item(item: item, source_indices: env.source_indices) { + emit_parametric_phantom_opaque_struct(item: item, source_indices: env.source_indices) + } else { + "" + } + } } } else if is_function_item(item: item) { let fn_movable = match map_get(emit_info.ownership_index, qualified_name) { @@ -2999,7 +3073,8 @@ fn emit_typed_item(item: Node, module_name: String, registry: Map, source_indices: Map) -> String { +fn render_rust_type_with_applied_binding(n: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { match find_property(props: n.properties, prop_name: "__applied_type_args", source_indices: source_indices) { Present { value: applied } => if applied.children |> count > 0 { @@ -3260,28 +3335,28 @@ fn render_rust_type_with_applied_binding(n: Node, shared_types: Set, sou } else if set_contains(shared_types, outer_name) { render_rust_shared_type_if_needed(type_name: outer_name, rendered: outer_name, shared_types: shared_types) } else { - render_rust_applied_type_shared(n: applied, generic_param_names: [], shared_types: shared_types, source_indices: source_indices, variant_to_enum: empty_map(), env: TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: source_indices, intern_table: empty_intern_table() }) + render_rust_applied_type_shared(n: applied, generic_param_names: [], shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: empty_map(), env: TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: source_indices, intern_table: empty_intern_table() }) } } else { - render_rust_applied_type_shared(n: applied, generic_param_names: [], shared_types: shared_types, source_indices: source_indices, variant_to_enum: empty_map(), env: TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: source_indices, intern_table: empty_intern_table() }) + render_rust_applied_type_shared(n: applied, generic_param_names: [], shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: empty_map(), env: TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: source_indices, intern_table: empty_intern_table() }) } } else { - render_rust_type(n: n, shared_types: shared_types, source_indices: source_indices) + render_rust_type(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } - Absent => render_rust_type(n: n, shared_types: shared_types, source_indices: source_indices) + Absent => render_rust_type(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } -fn render_rust_field_type_with_applied_binding(field: Node, shared_types: Set, source_indices: Map) -> String { +fn render_rust_field_type_with_applied_binding(field: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { let authored_type = field_node_type_expr(n: field) if find_property(props: field.properties, prop_name: "__applied_type_args", source_indices: source_indices) != none { - render_rust_type_with_applied_binding(n: field, shared_types: shared_types, source_indices: source_indices) + render_rust_type_with_applied_binding(n: field, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } else if find_property(props: authored_type.properties, prop_name: "__applied_type_args", source_indices: source_indices) != none { - render_rust_type_with_applied_binding(n: authored_type, shared_types: shared_types, source_indices: source_indices) + render_rust_type_with_applied_binding(n: authored_type, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } else if authored_type.connective == NoConnective && authored_type.children |> count > 0 { - render_rust_type(n: authored_type, shared_types: shared_types, source_indices: source_indices) + render_rust_type(n: authored_type, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } else { - render_rust_type_with_applied_binding(n: resolved_type(n: field), shared_types: shared_types, source_indices: source_indices) + render_rust_type_with_applied_binding(n: resolved_type(n: field), shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } @@ -3291,11 +3366,11 @@ fn emit_struct_field_from_child(struct_name: String, child: Node, generic_param_ let ty = if generic_param_names |> count > 0 { render_node_type(n: rt_child, target: Rust, shared_types: shared_types, source_indices: env.source_indices) } else if find_property(props: child.properties, prop_name: "__applied_type_args", source_indices: env.source_indices) != none { - render_rust_type_with_applied_binding(n: child, shared_types: shared_types, source_indices: env.source_indices) + render_rust_type_with_applied_binding(n: child, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } else if find_property(props: authored_child_type.properties, prop_name: "__applied_type_args", source_indices: env.source_indices) != none { - render_rust_type_with_applied_binding(n: authored_child_type, shared_types: shared_types, source_indices: env.source_indices) + render_rust_type_with_applied_binding(n: authored_child_type, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } else if find_property(props: rt_child.properties, prop_name: "__applied_type_args", source_indices: env.source_indices) != none { - render_rust_type_with_applied_binding(n: rt_child, shared_types: shared_types, source_indices: env.source_indices) + render_rust_type_with_applied_binding(n: rt_child, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } else if is_product_type(n: rt_child) && rt_child.ident_span != none && rt_child.children |> count > 2 { let rt_child_name = authored_name_at(source_indices: env.source_indices, node: rt_child) match lookup_type_by_name(env: env, name: rt_child_name) { @@ -3306,12 +3381,12 @@ fn emit_struct_field_from_child(struct_name: String, child: Node, generic_param_ let with_params = concat(base, "<", param_names |> join(separator: ", "), ">") render_rust_shared_type_if_needed(type_name: rt_child_name, rendered: with_params, shared_types: shared_types) } else { - render_rust_type(n: rt_child, shared_types: shared_types, source_indices: env.source_indices) + render_rust_type(n: rt_child, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } - Absent => render_rust_type(n: rt_child, shared_types: shared_types, source_indices: env.source_indices) + Absent => render_rust_type(n: rt_child, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } } else { - render_rust_type(n: rt_child, shared_types: shared_types, source_indices: env.source_indices) + render_rust_type(n: rt_child, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } let generic_ty = if struct_name == "PartialFunction" { rust_normalize_partial_function_field_type_text(rendered: rust_normalize_witness_type_text(rendered: ty)) @@ -3393,7 +3468,7 @@ fn emit_enum_shared_accessors(name: String, type_params: String, children: List< let shared = all_shared |> filter(fname => let types = fielded |> map(variant => match variant.children |> filter(f => authored_name(env: env, node: f) == fname) |> first { - Present { value: f } => render_rust_field_type_with_applied_binding(field: f, shared_types: shared_types, source_indices: env.source_indices) + Present { value: f } => render_rust_field_type_with_applied_binding(field: f, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) Absent => "" } ) @@ -3406,7 +3481,7 @@ fn emit_enum_shared_accessors(name: String, type_params: String, children: List< if shared |> count == 0 { return "" } let accessor_fns = shared |> map(fname => let ty = match first_fielded.children |> filter(f => authored_name(env: env, node: f) == fname) |> first { - Present { value: f } => render_rust_field_type_with_applied_binding(field: f, shared_types: shared_types, source_indices: env.source_indices) + Present { value: f } => render_rust_field_type_with_applied_binding(field: f, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) Absent => "compile_error!(\"enum shared accessor missing field metadata\")" } let arms = children |> map(child => @@ -3587,14 +3662,14 @@ fn enum_variant_field_type_node(env: TypeEnv, enum_name: String, variant_name: S } } -fn render_variant_payload_type(n: Node, shared_types: Set, source_indices: Map) -> String { +fn render_variant_payload_type(n: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { if n.connective == NoConnective && n.children |> count > 0 { let tn = authored_name_at(source_indices: source_indices, node: n) - let args = n.children |> map(c => render_rust_type(n: child_type_node(ch: c), shared_types: shared_types, source_indices: source_indices)) + let args = n.children |> map(c => render_rust_type(n: child_type_node(ch: c), shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices)) let spec = language_spec(target: Rust) concat(coerce_primitive_type(target: Rust, dag_name: tn), spec.type_arg_open, args |> join(separator: ", "), spec.type_arg_close) } else { - render_rust_type(n: n, shared_types: shared_types, source_indices: source_indices) + render_rust_type(n: n, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } @@ -3625,11 +3700,11 @@ fn emit_variant_from_child(child: Node, enum_name: String, recursive_types: Set< enum_variant_field_type_node(env: env, enum_name: enum_name, variant_name: child_text, field_name: "0", fallback: fallback, source_indices: env.source_indices) } else { fallback } let raw_ty = if positional_payload { - render_variant_payload_type(n: type_node, shared_types: shared_types, source_indices: env.source_indices) + render_variant_payload_type(n: type_node, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } else { - render_rust_type(n: type_node, shared_types: shared_types, source_indices: env.source_indices) + render_rust_type(n: type_node, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } - let ty = if find_property(props: type_node.properties, prop_name: "__applied_type_args", source_indices: env.source_indices) != none { render_rust_type_with_applied_binding(n: type_node, shared_types: shared_types, source_indices: env.source_indices) } else { raw_ty } + let ty = if find_property(props: type_node.properties, prop_name: "__applied_type_args", source_indices: env.source_indices) != none { render_rust_type_with_applied_binding(n: type_node, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) } else { raw_ty } let final_ty = if needs_box_wrapping(n: type_node, recursive_types: recursive_types, shared_types: shared_types, source_indices: env.source_indices) { concat("Box<", ty, ">") } else { ty } @@ -3639,7 +3714,7 @@ fn emit_variant_from_child(child: Node, enum_name: String, recursive_types: Set< } else { let field_lines = child.children |> map(f => let rt_f = resolved_type(n: f) - let ty = render_rust_field_type_with_applied_binding(field: f, shared_types: shared_types, source_indices: env.source_indices) + let ty = render_rust_field_type_with_applied_binding(field: f, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) let final_ty = if needs_box_wrapping(n: rt_f, recursive_types: recursive_types, shared_types: shared_types, source_indices: env.source_indices) { concat("Box<", ty, ">") } else { ty } @@ -3651,7 +3726,7 @@ fn emit_variant_from_child(child: Node, enum_name: String, recursive_types: Set< } else { let field_lines = child.children |> map(f => let rt_f = resolved_type(n: f) - let ty = render_rust_field_type_with_applied_binding(field: f, shared_types: shared_types, source_indices: env.source_indices) + let ty = render_rust_field_type_with_applied_binding(field: f, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: env.source_indices) let final_ty = if needs_box_wrapping(n: rt_f, recursive_types: recursive_types, shared_types: shared_types, source_indices: env.source_indices) { concat("Box<", ty, ">") } else { ty } @@ -3675,7 +3750,7 @@ fn emit_fn_def(name: String, params: List, inferred: Node, body: Node, reg let si = scope.type_env.source_indices match rust_host_string_seam_fn_emit(name: name) { Present { value: seam_fn } => - if rust_emit_faithful_text_carrier(source_indices: si) { seam_fn } else { "" } + if corpus_repr_is_faithful(corpus_repr: emit_info.corpus_repr) { seam_fn } else { "" } Absent => { let type_params = function_type_params(params: params) let value_params = function_value_params(params: params) @@ -3688,14 +3763,14 @@ fn emit_fn_def(name: String, params: List, inferred: Node, body: Node, reg } let type_params_str = emit_type_params(params: type_params, source_indices: si) let generic_param_names = type_params |> map(p => generic_param_name_at(n: p, source_indices: si)) - let params_str = emit_params(params: value_params, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: si, read_only_params: emit_info.read_only_params, variant_to_enum: emit_info.variant_to_enum, env: scope.type_env) - let ret_str = emit_inferred(inferred: inferred, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: si, variant_to_enum: emit_info.variant_to_enum, env: scope.type_env) + let params_str = emit_params(params: value_params, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: si, read_only_params: emit_info.read_only_params, variant_to_enum: emit_info.variant_to_enum, env: scope.type_env) + let ret_str = emit_inferred(inferred: inferred, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: si, variant_to_enum: emit_info.variant_to_enum, env: scope.type_env) let body_scope = build_params_scope(scope: scope, params: value_params) let depth = 0 let use_tco = is_tco_eligible(name: name, body: body, registry: registry, source_indices: si) let needs_stacker = is_self_recursive(name: name, body: body, registry: registry, source_indices: si) && use_tco == false if use_tco { - let tco_params_str = emit_tco_params(params: value_params, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: si, variant_to_enum: emit_info.variant_to_enum, env: scope.type_env) + let tco_params_str = emit_tco_params(params: value_params, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: si, variant_to_enum: emit_info.variant_to_enum, env: scope.type_env) let body_str = emit_typed_tco_body(texpr: body, fn_name: name, params: value_params, registry: registry, scope: body_scope, depth: depth + 1, shared_types: shared_types, emit_info: emit_info) let kw = rust_items().func_keyword concat(rust_visibility_prefix(), kw, " ", emit_ident(name: name, target: Rust), type_params_str, "(", tco_params_str, ")", ret_str, " {\n", @@ -3753,8 +3828,8 @@ fn emit_func_def( Present { value: info } => info.service_names Absent => [] } - let params_str = emit_func_params(params: params, uses: uses, service_names: service_names, shared_types: shared_types, source_indices: scope.type_env.source_indices, read_only_params: emit_info.read_only_params, variant_to_enum: emit_info.variant_to_enum, env: scope.type_env) - let ret_str = emit_func_inferred(inferred: inferred, shared_types: shared_types, source_indices: scope.type_env.source_indices) + let params_str = emit_func_params(params: params, uses: uses, service_names: service_names, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices, read_only_params: emit_info.read_only_params, variant_to_enum: emit_info.variant_to_enum, env: scope.type_env) + let ret_str = emit_func_inferred(inferred: inferred, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) let body_scope = build_params_scope(scope: scope, params: params) let si = scope.type_env.source_indices let body_scope = fold(uses, init: body_scope, f: (s, u) => @@ -3811,25 +3886,25 @@ fn emit_func_body(body: Node, registry: Map, scope: InferScope // Tail-Call Optimization (TCO) -- Rust rendering // ========================================================================= -fn emit_tco_params(params: List, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { - let strs = params |> map(p => emit_tco_param(param: p, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env)) +fn emit_tco_params(params: List, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { + let strs = params |> map(p => emit_tco_param(param: p, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env)) strs |> join(separator: ", ") } -fn emit_tco_param(param: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { +fn emit_tco_param(param: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { let authored = param_node_type_expr(n: param) let ty = if authored.params |> count > 0 { - emit_rust_param_type(n: authored, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + emit_rust_param_type(n: authored, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } else { - render_rust_param_sig_type(param: param, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_param_sig_type(param: param, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } concat("mut ", emit_ident(name: param_node_name_at(n: param, source_indices: source_indices), target: Rust), rust_items().param_type_sep, ty) } -fn emit_func_params(params: List, uses: List, service_names: List, shared_types: Set, source_indices: Map, read_only_params: Set, variant_to_enum: Map, env: TypeEnv) -> String { - let param_strs = params |> map(p => emit_param(param: p, generic_param_names: [], shared_types: shared_types, source_indices: source_indices, read_only_params: read_only_params, variant_to_enum: variant_to_enum, env: env)) +fn emit_func_params(params: List, uses: List, service_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, read_only_params: Set, variant_to_enum: Map, env: TypeEnv) -> String { + let param_strs = params |> map(p => emit_param(param: p, generic_param_names: [], shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, read_only_params: read_only_params, variant_to_enum: variant_to_enum, env: env)) let resource_strs = uses |> map(u => - concat(emit_ident(name: resource_use_name_at(n: u, source_indices: source_indices), target: Rust), ": &", render_rust_type(n: resource_use_resource(n: u), shared_types: shared_types, source_indices: source_indices)) + concat(emit_ident(name: resource_use_name_at(n: u, source_indices: source_indices), target: Rust), ": &", render_rust_type(n: resource_use_resource(n: u), shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices)) ) let service_strs = service_names |> map(sn => concat(service_var_name(service_name: sn), ": &", sanitize_service_name(name: sn)) @@ -3838,16 +3913,16 @@ fn emit_func_params(params: List, uses: List, service_names: List join(separator: ", ") } -fn emit_func_inferred(inferred: Node, shared_types: Set, source_indices: Map) -> String { - concat(" -> Result<", render_rust_type(n: inferred, shared_types: shared_types, source_indices: source_indices), ", Box>") +fn emit_func_inferred(inferred: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { + concat(" -> Result<", render_rust_type(n: inferred, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices), ", Box>") } // ========================================================================= // Parameter emission // ========================================================================= -fn emit_params(params: List, generic_param_names: List, shared_types: Set, source_indices: Map, read_only_params: Set, variant_to_enum: Map, env: TypeEnv) -> String { - let strs = params |> map(p => emit_param(param: p, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, read_only_params: read_only_params, variant_to_enum: variant_to_enum, env: env)) +fn emit_params(params: List, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, read_only_params: Set, variant_to_enum: Map, env: TypeEnv) -> String { + let strs = params |> map(p => emit_param(param: p, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, read_only_params: read_only_params, variant_to_enum: variant_to_enum, env: env)) strs |> join(separator: ", ") } @@ -3864,38 +3939,38 @@ fn emit_params(params: List, generic_param_names: List, shared_typ // ordinary variable references (`emit_var_ref`). Do not remove `+ Clone` // here and "compensate" only in the emitter: that splits clone authority // between the type signature and ownership analysis and breaks fixed-point. -fn render_rust_param_sig_type(param: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { +fn render_rust_param_sig_type(param: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { let type_node = resolved_type(n: param) - render_rust_fn_sig_type(n: type_node, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_fn_sig_type(n: type_node, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } -fn emit_rust_param_type(n: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { +fn emit_rust_param_type(n: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { if n.params |> count > 0 { - let param_types = n.params |> map(p => render_rust_fn_sig_type(n: param_node_type_expr(n: p), generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env)) + let param_types = n.params |> map(p => render_rust_fn_sig_type(n: param_node_type_expr(n: p), generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env)) let param_str = param_types |> join(separator: ", ") let ret_str = match n.inferred { - Present { value: Resolved { node: rt } } => render_rust_fn_sig_type(n: rt, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + Present { value: Resolved { node: rt } } => render_rust_fn_sig_type(n: rt, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) _ => "()" } concat("impl Fn(", param_str, ") -> ", ret_str, " + Clone") } else { - render_rust_fn_sig_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_fn_sig_type(n: n, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } } -fn emit_param(param: Node, generic_param_names: List, shared_types: Set, source_indices: Map, read_only_params: Set, variant_to_enum: Map, env: TypeEnv) -> String { +fn emit_param(param: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, read_only_params: Set, variant_to_enum: Map, env: TypeEnv) -> String { let authored = param_node_type_expr(n: param) let ty = if authored.params |> count > 0 { - emit_rust_param_type(n: authored, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + emit_rust_param_type(n: authored, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } else { - render_rust_param_sig_type(param: param, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) + render_rust_param_sig_type(param: param, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env) } let pname = param_node_name_at(n: param, source_indices: source_indices) concat(emit_ident(name: pname, target: Rust), rust_items().param_type_sep, ty) } -fn emit_inferred(inferred: Node, generic_param_names: List, shared_types: Set, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { - concat(rust_items().return_arrow, render_rust_fn_sig_type(n: inferred, generic_param_names: generic_param_names, shared_types: shared_types, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env)) +fn emit_inferred(inferred: Node, generic_param_names: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map, variant_to_enum: Map, env: TypeEnv) -> String { + concat(rust_items().return_arrow, render_rust_fn_sig_type(n: inferred, generic_param_names: generic_param_names, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices, variant_to_enum: variant_to_enum, env: env)) } fn needs_reference_node(n: Node, source_indices: Map) -> Bool { @@ -4769,22 +4844,22 @@ fn rust_runtime_bridge_name(function_name: String) -> String { } } -fn rust_empty_map_value_type_str(map_type: Node, shared_types: Set, source_indices: Map) -> String { +fn rust_empty_map_value_type_str(map_type: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { match map_type.children |> skip(1) |> first { Present { value: value_child } => - let rendered = render_rust_type(n: child_type_node(ch: value_child), shared_types: shared_types, source_indices: source_indices) + let rendered = render_rust_type(n: child_type_node(ch: value_child), shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) if rendered == "" { "" } else { rendered } Absent => "" } } -fn rust_empty_map_kv_type_str(map_type: Node, shared_types: Set, source_indices: Map) -> String { +fn rust_empty_map_kv_type_str(map_type: Node, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { let key_str = match map_type.children |> first { Present { value: key_child } => - render_rust_type(n: child_type_node(ch: key_child), shared_types: shared_types, source_indices: source_indices) + render_rust_type(n: child_type_node(ch: key_child), shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) Absent => "" } - let val_str = rust_empty_map_value_type_str(map_type: map_type, shared_types: shared_types, source_indices: source_indices) + let val_str = rust_empty_map_value_type_str(map_type: map_type, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) if key_str != "" && val_str != "" { concat(key_str, ", ", val_str) } else { "" } @@ -5154,7 +5229,7 @@ fn emit_discriminant_call_lowering(value_arg: Node, registry: Map ", emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", child_text, "\""), source_indices: scope.type_env.source_indices), ",") + concat(" ", pat, " => ", emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", child_text, "\""), corpus_repr: emit_info.corpus_repr), ",") ) // Borrow the scrutinee so the arms (which never bind fields) don't move it. Shared types // are Rc-wrapped, so deref through the Rc with `&*` to reach `&T`; owned values use `&`. @@ -5166,9 +5241,9 @@ fn emit_discriminant_call_lowering(value_arg: Node, registry: Map join(separator: "\n"), "\n })") } else { // Product/record type: the discriminant is the type's own name (interpreter returns type_name). - emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", ty_name, "\""), source_indices: scope.type_env.source_indices) + emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", ty_name, "\""), corpus_repr: emit_info.corpus_repr) } - Absent => emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", ty_name, "\""), source_indices: scope.type_env.source_indices) + Absent => emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", ty_name, "\""), corpus_repr: emit_info.corpus_repr) } } @@ -5176,7 +5251,7 @@ fn emit_typed_call_expr(func: String, args: List, inferred: InferredNode?, let call_str = if func == "empty_map" { match inferred { Present { value: Resolved { node: ret_type } } => - let kv_type_str = rust_empty_map_kv_type_str(map_type: ret_type, shared_types: shared_types, source_indices: scope.type_env.source_indices) + let kv_type_str = rust_empty_map_kv_type_str(map_type: ret_type, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) if kv_type_str != "" { concat("v1_rt::rc_empty_map::<", kv_type_str, ">()") } else { @@ -5250,7 +5325,7 @@ fn emit_typed_call(func: String, args: List, registry: Map first { Present { value: value_arg } => - emit_rust_host_to_dag_string_via_seam(host_expr: concat("(", emit_typed_expr(texpr: arg_value(n: value_arg), registry: registry, scope: scope, depth: depth, shared_types: shared_types, emit_info: emit_info, fuel: 1024), ").to_string()"), source_indices: scope.type_env.source_indices) + emit_rust_host_to_dag_string_via_seam(host_expr: concat("(", emit_typed_expr(texpr: arg_value(n: value_arg), registry: registry, scope: scope, depth: depth, shared_types: shared_types, emit_info: emit_info, fuel: 1024), ").to_string()"), corpus_repr: emit_info.corpus_repr) Absent => "compile_error!(\"to_string call missing value argument\")" } return ts_result @@ -5448,7 +5523,7 @@ fn emit_typed_slice(base: Node, start: Node, end: Node, registry: Map, source_indices: Map) -> String { +fn collection_element_type(receiver_type: InferredNode?, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { match receiver_type { Present { value: Resolved { node: rt } } => let __rt_is_container = node_is_element_collection(n: rt, source_indices: source_indices) @@ -5458,7 +5533,7 @@ fn collection_element_type(receiver_type: InferredNode?, shared_types: Set "_" } } else { "_" } @@ -5482,7 +5557,7 @@ fn lambda_scope_from_children(scope: InferScope, params: List, param_nod ) } -fn lambda_param_type_strs(params: List, param_nodes: List, fallback_types: List, shared_types: Set, source_indices: Map) -> List { +fn lambda_param_type_strs(params: List, param_nodes: List, fallback_types: List, shared_types: Set, corpus_repr: RustCorpusRepr, source_indices: Map) -> List { params |> enumerate |> map(pair => let idx = pair.first let param_name = pair.second @@ -5495,7 +5570,7 @@ fn lambda_param_type_strs(params: List, param_nodes: List, fallbac if param_is_type_var || param_is_error { none } else { - Present { value: render_rust_type(n: param_type, shared_types: shared_types, source_indices: source_indices) } + Present { value: render_rust_type(n: param_type, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices) } } _ => none } @@ -5521,7 +5596,7 @@ fn emit_typed_collection_lambda(lambda_expr: Node, elem_type_str: String, regist let ps = lambda_param_names_at(texpr: lambda_expr, source_indices: scope.type_env.source_indices) let bd = lambda_body(texpr: lambda_expr) let pn = lambda_expr.children |> skip(1) - let param_strs = lambda_param_type_strs(params: ps, param_nodes: pn, fallback_types: [elem_type_str], shared_types: shared_types, source_indices: scope.type_env.source_indices) + let param_strs = lambda_param_type_strs(params: ps, param_nodes: pn, fallback_types: [elem_type_str], shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) let params_str = param_strs |> join(separator: ", ") let lambda_scope = lambda_scope_from_children(scope: scope, params: ps, param_nodes: pn) let body_str = emit_typed_expr(texpr: bd, registry: registry, scope: lambda_scope, depth: depth, shared_types: shared_types, emit_info: emit_info, fuel: 1024) @@ -5547,7 +5622,7 @@ fn emit_typed_fold_lambda(lambda_expr: Node, acc_type_str: String, elem_type_str let fallback_types = ps |> enumerate |> map(pair => if pair.first == 0 { safe_acc_type } else { elem_type_str } ) - let param_strs = lambda_param_type_strs(params: ps, param_nodes: [], fallback_types: fallback_types, shared_types: shared_types, source_indices: scope.type_env.source_indices) + let param_strs = lambda_param_type_strs(params: ps, param_nodes: [], fallback_types: fallback_types, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) let params_str = param_strs |> join(separator: ", ") let lambda_scope = lambda_scope_from_children(scope: scope, params: ps, param_nodes: pn) let body_str = emit_typed_expr(texpr: bd, registry: registry, scope: lambda_scope, depth: depth, shared_types: shared_types, emit_info: emit_info, fuel: 1024) @@ -5568,7 +5643,7 @@ fn emit_typed_fold_lambda(lambda_expr: Node, acc_type_str: String, elem_type_str fn emit_rust_fold_method_call(method_call_node: Node, fold_accumulator_type: Node?, result_type: InferredNode?, receiver: Node, args: List, registry: Map, scope: InferScope, depth: Int, shared_types: Set, emit_info: EmitGraphInfo) -> String { let recv_str = emit_typed_expr(texpr: receiver, registry: registry, scope: scope, depth: depth, shared_types: shared_types, emit_info: emit_info, fuel: 1024) - let elem_type_str = collection_element_type(receiver_type: receiver.inferred, shared_types: shared_types, source_indices: scope.type_env.source_indices) + let elem_type_str = collection_element_type(receiver_type: receiver.inferred, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) let contextual_acc_type = match result_type { Present { value: Resolved { node: method_result_type } } => Present { value: method_result_type } _ => none @@ -5632,7 +5707,8 @@ fn emit_rust_fold_method_call(method_call_node: Node, fold_accumulator_type: Nod variant_to_enum: emit_info.variant_to_enum, owned_bindings: set_insert(emit_info.owned_bindings, acc_name), read_only_params_index: emit_info.read_only_params_index, - read_only_params: emit_info.read_only_params + read_only_params: emit_info.read_only_params, + corpus_repr: emit_info.corpus_repr } Absent => emit_info } @@ -5655,14 +5731,15 @@ fn emit_rust_fold_method_call(method_call_node: Node, fold_accumulator_type: Nod variant_to_enum: emit_info.variant_to_enum, owned_bindings: emit_info.owned_bindings, read_only_params_index: emit_info.read_only_params_index, - read_only_params: emit_info.read_only_params + read_only_params: emit_info.read_only_params, + corpus_repr: emit_info.corpus_repr } Absent => emit_info } _ => emit_info } } else { emit_info } - let acc_type_str = render_rust_type(n: acc_type_node, shared_types: shared_types, source_indices: scope.type_env.source_indices) + let acc_type_str = render_rust_type(n: acc_type_node, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) let acc_type_is_type_var = if acc_type_node.inferred != none { is_type_variable(inferred: acc_type_node.inferred.value) } else { false } let acc_child_is_type_var = acc_type_node.children |> any(c => type_node_child_is_type_variable(c: c)) let is_bare_container = acc_type_node.children |> count == 0 && is_container_type(name: acc_type_name) @@ -5674,7 +5751,7 @@ fn emit_rust_fold_method_call(method_call_node: Node, fold_accumulator_type: Nod ExprCall { call_semantics: _, descent_evidence: _ } => let init_func = expr_call_func_at(texpr: arg_value(n: init_arg), source_indices: scope.type_env.source_indices) if init_func == "empty_map" && acc_type_str != "_" && acc_type_str != "" && !acc_has_unit_child { - let kv_type_str = rust_empty_map_kv_type_str(map_type: acc_type_node, shared_types: shared_types, source_indices: scope.type_env.source_indices) + let kv_type_str = rust_empty_map_kv_type_str(map_type: acc_type_node, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) if kv_type_str != "" { concat("v1_rt::rc_empty_map::<", kv_type_str, ">()") } else { @@ -5710,7 +5787,7 @@ fn emit_rust_sort_by_method_call(receiver: Node, args: List, registry: Map let elem = for_each_element_type_node(n: resolved, source_indices: scope.type_env.source_indices) let elem_is_type_var = if elem.inferred != none { is_type_variable(inferred: elem.inferred.value) } else { false } if elem.ident_span != none && !elem_is_type_var { - render_rust_type(n: elem, shared_types: shared_types, source_indices: scope.type_env.source_indices) + render_rust_type(n: elem, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) } else { "_" } _ => "_" } @@ -6448,7 +6525,7 @@ fn emit_typed_record_lit(type_name: String?, fields: List, parent_enum: St let missing = map_keys(fs) |> filter(k => !emit_map_has(m: provided_set, key: k)) let all_defaultable = missing |> all(fname => let has_zv = match map_get(ftm, fname) { - Present { value: ft } => match rust_zero_value(type_name: ft, source_indices: si) { Present { value: _ } => true, Absent => false } + Present { value: ft } => match rust_zero_value(type_name: ft, corpus_repr: emit_info.corpus_repr) { Present { value: _ } => true, Absent => false } Absent => false } has_zv || is_optional_struct_field(emit_info: emit_info, struct_name: variant_summary_name, field_name: fname) @@ -6460,7 +6537,7 @@ fn emit_typed_record_lit(type_name: String?, fields: List, parent_enum: St } else { match map_get(ftm, fname) { Present { value: ft } => - match rust_zero_value(type_name: ft, source_indices: si) { + match rust_zero_value(type_name: ft, corpus_repr: emit_info.corpus_repr) { Present { value: zv } => [concat(" ", emit_ident(name: fname, target: Rust), ": ", zv, ",")] Absent => [] } @@ -6498,11 +6575,11 @@ fn emit_typed_record_lit(type_name: String?, fields: List, parent_enum: St } } -fn rust_zero_value(type_name: String, source_indices: Map) -> String? { +fn rust_zero_value(type_name: String, corpus_repr: RustCorpusRepr) -> String? { if type_name == "Int" { Present { value: "0" } } else if type_name == "Bool" { Present { value: "false" } } else if type_name == "String" { - if rust_emit_faithful_text_carrier(source_indices: source_indices) { + if corpus_repr_is_faithful(corpus_repr: corpus_repr) { Present { value: "crate::v2_std_algebra::freemonoid_empty::()" } } else { Present { value: "\"\".to_string()" } @@ -6522,11 +6599,11 @@ fn emit_typed_bin_op(op: BinOp, algebra_field: AlgebraFieldKind?, left: Node, ri let l_optional = is_optional_typed_expr(e: left) let r_optional = is_optional_typed_expr(e: right) if l_optional || r_optional { - let l_cmp = if l_optional { concat(l_str, ".as_deref()") } else { concat("Some(", emit_rust_dag_string_to_host_via_seam(dag_expr: l_str, source_indices: scope.type_env.source_indices), ")") } - let r_cmp = if r_optional { concat(r_str, ".as_deref()") } else { concat("Some(", emit_rust_dag_string_to_host_via_seam(dag_expr: r_str, source_indices: scope.type_env.source_indices), ")") } + let l_cmp = if l_optional { concat(l_str, ".as_deref()") } else { concat("Some(", emit_rust_dag_string_to_host_via_seam(dag_expr: l_str, corpus_repr: emit_info.corpus_repr), ")") } + let r_cmp = if r_optional { concat(r_str, ".as_deref()") } else { concat("Some(", emit_rust_dag_string_to_host_via_seam(dag_expr: r_str, corpus_repr: emit_info.corpus_repr), ")") } concat("(", l_cmp, " ", op_str, " ", r_cmp, ")") } else { - concat("(", emit_rust_dag_string_to_host_via_seam(dag_expr: l_str, source_indices: scope.type_env.source_indices), " ", op_str, " ", emit_rust_dag_string_to_host_via_seam(dag_expr: r_str, source_indices: scope.type_env.source_indices), ")") + concat("(", emit_rust_dag_string_to_host_via_seam(dag_expr: l_str, corpus_repr: emit_info.corpus_repr), " ", op_str, " ", emit_rust_dag_string_to_host_via_seam(dag_expr: r_str, corpus_repr: emit_info.corpus_repr), ")") } } else { concat("(", l_str, " ", op_str, " ", r_str, ")") @@ -6568,10 +6645,10 @@ fn emit_typed_string_interp(parts: List, registry: Map map(p => p.arg_expr) |> filter(a => a != "") if args |> count == 0 { - emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", fmt_str, "\""), source_indices: scope.type_env.source_indices) + emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", fmt_str, "\""), corpus_repr: emit_info.corpus_repr) } else { let args_str = args |> join(separator: ", ") - emit_rust_host_to_dag_string_via_seam(host_expr: concat("format!(\"", fmt_str, "\", ", args_str, ")"), source_indices: scope.type_env.source_indices) + emit_rust_host_to_dag_string_via_seam(host_expr: concat("format!(\"", fmt_str, "\", ", args_str, ")"), corpus_repr: emit_info.corpus_repr) } } @@ -6833,13 +6910,14 @@ fn emit_service_def( item: Node, registry: Map, shared_types: Set, + corpus_repr: RustCorpusRepr, env: TypeEnv ) -> String { let safe_name = sanitize_service_name(name: authored_name(env: env, node: item)) let fallback_transport = service_fallback_transport(item: item) let op_children = item.children let struct_def = emit_service_struct(name: safe_name, fallback_transport: fallback_transport, op_children: op_children, service_item: item, source_indices: env.source_indices) - let impl_block = emit_service_impl(name: safe_name, transport: fallback_transport, op_children: op_children, registry: registry, shared_types: shared_types, env: env, service_item: item) + let impl_block = emit_service_impl(name: safe_name, transport: fallback_transport, op_children: op_children, registry: registry, shared_types: shared_types, corpus_repr: corpus_repr, env: env, service_item: item) concat(struct_def, "\n\n", impl_block) } @@ -6860,11 +6938,11 @@ fn emit_service_config_fields(fallback_transport: Node, op_children: List, else { decls |> join(separator: "") } } -fn emit_service_impl(name: String, transport: Node, op_children: List, registry: Map, shared_types: Set, env: TypeEnv, service_item: Node) -> String { +fn emit_service_impl(name: String, transport: Node, op_children: List, registry: Map, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv, service_item: Node) -> String { let depth = 0 let new_method = emit_service_new_method(name: name, fallback_transport: transport, op_children: op_children, service_item: service_item, source_indices: env.source_indices) let method_strs = op_children |> map(op_node => - emit_operation_method(service_name: name, transport: transport, op_node: op_node, registry: registry, depth: depth + 1, shared_types: shared_types, env: env, service_item: service_item) + emit_operation_method(service_name: name, transport: transport, op_node: op_node, registry: registry, depth: depth + 1, shared_types: shared_types, corpus_repr: corpus_repr, env: env, service_item: service_item) ) let all_methods = concat([new_method], method_strs) let methods_str = all_methods |> join(separator: "\n\n") @@ -6947,10 +7025,10 @@ fn emit_modifier_doc_from_props(properties: List, source_indices: Map, depth: Int, shared_types: Set, env: TypeEnv, service_item: Node) -> String { +fn emit_operation_method(service_name: String, transport: Node, op_node: Node, registry: Map, depth: Int, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv, service_item: Node) -> String { let op_text = authored_name(env: env, node: op_node) let input_params = op_node.params |> map(p => - concat(emit_ident(name: param_node_name_at(n: p, source_indices: env.source_indices), target: Rust), rust_items().param_type_sep, emit_rust_param_type(n: param_node_type_expr(n: p), generic_param_names: [], shared_types: shared_types, source_indices: env.source_indices, variant_to_enum: empty_map(), env: env.clone())) + concat(emit_ident(name: param_node_name_at(n: p, source_indices: env.source_indices), target: Rust), rust_items().param_type_sep, emit_rust_param_type(n: param_node_type_expr(n: p), generic_param_names: [], shared_types: shared_types, corpus_repr: corpus_repr, source_indices: env.source_indices, variant_to_enum: empty_map(), env: env.clone())) ) let params_str = input_params |> join(separator: ", ") let all_params = if params_str == "" { @@ -6958,12 +7036,12 @@ fn emit_operation_method(service_name: String, transport: Node, op_node: Node, r } else { concat("&self, ", params_str) } - let ret_type = render_rust_type(n: resolved_type(n: op_node), shared_types: shared_types, source_indices: env.source_indices) + let ret_type = render_rust_type(n: resolved_type(n: op_node), shared_types: shared_types, corpus_repr: corpus_repr, source_indices: env.source_indices) let eff_transport = effective_operation_transport(op_node: op_node, fallback: transport) let op_inferred = resolved_type(n: op_node) - let real_body = emit_transport_call(transport: eff_transport, op_name: op_text, registry: registry, depth: depth + 2, inferred: op_inferred, service_item: service_item, op_node: op_node, source_indices: env.source_indices, shared_types: shared_types, env: env) + let real_body = emit_transport_call(transport: eff_transport, op_name: op_text, registry: registry, depth: depth + 2, inferred: op_inferred, service_item: service_item, op_node: op_node, source_indices: env.source_indices, shared_types: shared_types, corpus_repr: corpus_repr, env: env) let mock_props = op_node.properties |> filter(p => has_mock_prefix(name: field_init_node_name_at(n: p, source_indices: env.source_indices))) - let dry_run_body = emit_dry_run_branch_from_props(op_name: op_text, inferred: resolved_type(n: op_node), mock_props: mock_props, registry: registry, source_indices: env.source_indices, op_node: op_node, env: env, shared_types: shared_types) + let dry_run_body = emit_dry_run_branch_from_props(op_name: op_text, inferred: resolved_type(n: op_node), mock_props: mock_props, registry: registry, source_indices: env.source_indices, op_node: op_node, env: env, shared_types: shared_types, corpus_repr: corpus_repr) let body = concat( "if self.dry_run.is_dry_run() {\n", make_indent(level: depth + 2),dry_run_body, "\n", @@ -6977,7 +7055,7 @@ fn emit_operation_method(service_name: String, transport: Node, op_node: Node, r make_indent(level: depth + 1),body, "\n}") } -fn emit_dry_run_branch_from_props(op_name: String, inferred: Node, mock_props: List, registry: Map, source_indices: Map, op_node: Node, env: TypeEnv, shared_types: Set) -> String { +fn emit_dry_run_branch_from_props(op_name: String, inferred: Node, mock_props: List, registry: Map, source_indices: Map, op_node: Node, env: TypeEnv, shared_types: Set, corpus_repr: RustCorpusRepr) -> String { let log_line = concat("eprintln!(\"[dry-run] ", op_name, "\");") if mock_props |> count > 0 { let first_mock = mock_props |> first @@ -7007,7 +7085,7 @@ fn emit_dry_run_branch_from_props(op_name: String, inferred: Node, mock_props: L Present { value: Resolved { node: rt } } => rt _ => tn } - concat("let __rest_wire: ", render_rust_type(n: wire_ty, shared_types: shared_types, source_indices: source_indices), " = serde_json::from_str(r#\"", mock_json, "\"#)?;\n") + concat("let __rest_wire: ", render_rust_type(n: wire_ty, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices), " = serde_json::from_str(r#\"", mock_json, "\"#)?;\n") } Absent => concat("let json_body: serde_json::Value = serde_json::from_str(r#\"", mock_json, "\"#)?;\n") } @@ -7026,7 +7104,7 @@ fn emit_dry_run_branch_from_props(op_name: String, inferred: Node, mock_props: L Absent => concat("let ", field_name, " = compile_error!(\"REST typed dry-run: response_200 wire type missing despite typed projection; illegal state\");\n") } } else { - emit_json_value_extract(var_name: field_name, from_path: from_path, dag_type_name: authored_name_at(source_indices: source_indices, node: tn), source_indices: source_indices) + emit_json_value_extract(var_name: field_name, from_path: from_path, dag_type_name: authored_name_at(source_indices: source_indices, node: tn), corpus_repr: corpus_repr, source_indices: source_indices) } _ => concat("let ", field_name, " = compile_error!(\"unresolved type for mock field: ", ch_name, "\");") @@ -7049,23 +7127,28 @@ fn emit_dry_run_branch_from_props(op_name: String, inferred: Node, mock_props: L Absent => concat(log_line, "\ncompile_error!(\"mock property list was non-empty but first() returned None\")") } } else { - concat(log_line, "\ncompile_error!(\"no mock data available for dry-run operation: ", op_name, "\")") + // Missing dry-run fixture is a RUNTIME condition (is_dry_run() && no mock + // data), not a compile-time one — emitting compile_error! here gated a + // runtime state at compile time (§5 category error), making the whole + // emitted crate fail to build whenever any service op lacks a fixture. + // Fail closed at runtime instead: a loud panic on the unprovisioned path. + concat(log_line, "\npanic!(\"no mock data available for dry-run operation: ", op_name, "\")") } } -fn emit_transport_call(transport: Node, op_name: String, registry: Map, depth: Int, inferred: Node, service_item: Node, op_node: Node, source_indices: Map, shared_types: Set, env: TypeEnv) -> String { - if is_rest_transport(t: transport, source_indices: source_indices) { emit_rest_call(op_name: op_name, transport: transport, registry: registry, depth: depth, service_item: service_item, op_node: op_node, source_indices: source_indices, shared_types: shared_types, env: env) } - else if is_shell_transport(t: transport) { emit_shell_call(op_name: op_name, transport: transport, registry: registry, depth: depth, inferred: inferred, op_node: op_node, source_indices: source_indices) } +fn emit_transport_call(transport: Node, op_name: String, registry: Map, depth: Int, inferred: Node, service_item: Node, op_node: Node, source_indices: Map, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv) -> String { + if is_rest_transport(t: transport, source_indices: source_indices) { emit_rest_call(op_name: op_name, transport: transport, registry: registry, depth: depth, service_item: service_item, op_node: op_node, source_indices: source_indices, shared_types: shared_types, corpus_repr: corpus_repr, env: env) } + else if is_shell_transport(t: transport) { emit_shell_call(op_name: op_name, transport: transport, registry: registry, depth: depth, inferred: inferred, op_node: op_node, corpus_repr: corpus_repr, source_indices: source_indices) } else if is_file_transport(t: transport, source_indices: source_indices) { emit_file_call(op_name: op_name, inferred: inferred) } else { emit_local_call(op_name: op_name) } } -fn emit_rest_call(op_name: String, transport: Node, registry: Map, depth: Int, service_item: Node, op_node: Node, source_indices: Map, shared_types: Set, env: TypeEnv) -> String { +fn emit_rest_call(op_name: String, transport: Node, registry: Map, depth: Int, service_item: Node, op_node: Node, source_indices: Map, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv) -> String { let client_init = "let client = reqwest::Client::builder().user_agent(\"gunbc/1.0\").build()?;" let url_line = emit_rest_url_line(transport: transport, op_name: op_name, source_indices: source_indices) let http_method = emit_rest_http_method(transport: transport, source_indices: source_indices) let auth_line = emit_rest_auth_line(transport: transport, service_item: service_item, http_method: http_method, source_indices: source_indices) - let query_line = emit_rest_query_line(transport: transport, source_indices: source_indices) + let query_line = emit_rest_query_line(transport: transport, corpus_repr: corpus_repr, source_indices: source_indices) let body_line = emit_rest_body_line(transport: transport, source_indices: source_indices) let headers = transport_headers(t: transport, source_indices: source_indices) let header_lines = headers |> map(h => @@ -7074,7 +7157,7 @@ fn emit_rest_call(op_name: String, transport: Node, registry: Map filter(l => l != "") @@ -7194,12 +7277,12 @@ fn emit_rest_auth_line(transport: Node, service_item: Node, http_method: String, } } -fn emit_rest_query_line(transport: Node, source_indices: Map) -> String { +fn emit_rest_query_line(transport: Node, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { match transport_query(t: transport, source_indices: source_indices) { Present { value: q } => { let pairs = q.children |> map(fi => concat("(\"", field_init_node_name_at(n: fi, source_indices: source_indices), "\", &", - emit_rust_dag_string_to_host_via_seam(dag_expr: emit_simple_expr(expr: field_init_node_value(n: fi), target: Rust, source_indices: source_indices), source_indices: source_indices), + emit_rust_dag_string_to_host_via_seam(dag_expr: emit_simple_expr(expr: field_init_node_value(n: fi), target: Rust, source_indices: source_indices), corpus_repr: corpus_repr), ")") ) if pairs |> count > 0 { @@ -7378,12 +7461,12 @@ fn escape_json_pointer_segment(seg: String) -> String { seg |> replace("~", "~0") |> replace("/", "~1") } -fn emit_json_value_extract(var_name: String, from_path: String, dag_type_name: String, source_indices: Map) -> String { +fn emit_json_value_extract(var_name: String, from_path: String, dag_type_name: String, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { let escaped_path = from_path |> split("/") |> map(seg => escape_json_pointer_segment(seg: seg)) |> join(separator: "/") let pointer = concat("/", escaped_path) let rust_type = coerce_primitive_type(target: Rust, dag_name: dag_type_name) let accessor = if dag_type_name == "String" { - concat(".and_then(|v| v.as_str()).map(|s| ", emit_rust_host_to_dag_string_via_seam(host_expr: "s.to_string()", source_indices: source_indices), ").ok_or(\"missing field: ", from_path, "\")?") + concat(".and_then(|v| v.as_str()).map(|s| ", emit_rust_host_to_dag_string_via_seam(host_expr: "s.to_string()", corpus_repr: corpus_repr), ").ok_or(\"missing field: ", from_path, "\")?") } else if rust_type == "i64" { concat(".and_then(|v| v.as_i64()).ok_or(\"missing field: ", from_path, "\")?") } else if rust_type == "f64" { @@ -7396,7 +7479,7 @@ fn emit_json_value_extract(var_name: String, from_path: String, dag_type_name: S concat("let ", var_name, " = json_body.pointer(\"", pointer, "\")", accessor, ";") } -fn emit_from_key_extraction(op_node: Node, source_indices: Map, shared_types: Set, env: TypeEnv) -> String { +fn emit_from_key_extraction(op_node: Node, source_indices: Map, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv) -> String { let rt = resolved_type(n: op_node) let children = rt.children let wire_opt = operation_response_200_resolved_type(op_node: op_node, source_indices: source_indices, env: env) @@ -7419,7 +7502,7 @@ fn emit_from_key_extraction(op_node: Node, source_indices: Map rt _ => tn } - concat("let __rest_wire: ", render_rust_type(n: wire_ty, shared_types: shared_types, source_indices: source_indices), " = response.json().await?;\n") + concat("let __rest_wire: ", render_rust_type(n: wire_ty, shared_types: shared_types, corpus_repr: corpus_repr, source_indices: source_indices), " = response.json().await?;\n") } Absent => "let json_body: serde_json::Value = response.json().await?;\n" } @@ -7438,7 +7521,7 @@ fn emit_from_key_extraction(op_node: Node, source_indices: Map concat("let ", field_name, " = compile_error!(\"REST typed response: response_200 wire type missing despite typed projection; illegal state\");\n") } } else { - emit_json_value_extract(var_name: field_name, from_path: from_path, dag_type_name: authored_name_at(source_indices: source_indices, node: tn), source_indices: source_indices) + emit_json_value_extract(var_name: field_name, from_path: from_path, dag_type_name: authored_name_at(source_indices: source_indices, node: tn), corpus_repr: corpus_repr, source_indices: source_indices) } _ => concat("let ", field_name, " = compile_error!(\"unresolved type for output field: ", ch_name, "\");") @@ -7466,17 +7549,17 @@ fn emit_plain_response_body(op_node: Node, transport: Node, source_indices: Map< } } -fn emit_response_code_handling(op_node: Node, transport: Node, source_indices: Map, shared_types: Set, env: TypeEnv) -> String { +fn emit_response_code_handling(op_node: Node, transport: Node, source_indices: Map, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv) -> String { let use_from_key = has_from_key_fields(op_node: op_node, source_indices: source_indices) let response_props = op_node.properties |> filter(p => has_response_prefix(name: field_init_node_name_at(n: p, source_indices: source_indices))) if response_props |> count == 0 { if use_from_key { - emit_from_key_extraction(op_node: op_node, source_indices: source_indices, shared_types: shared_types, env: env) + emit_from_key_extraction(op_node: op_node, source_indices: source_indices, shared_types: shared_types, corpus_repr: corpus_repr, env: env) } else { emit_plain_response_body(op_node: op_node, transport: transport, source_indices: source_indices) } } else { - let arms = response_props |> map(p => emit_response_arm(prop: p, op_node: op_node, use_from_key: use_from_key, transport: transport, source_indices: source_indices, shared_types: shared_types, env: env)) + let arms = response_props |> map(p => emit_response_arm(prop: p, op_node: op_node, use_from_key: use_from_key, transport: transport, source_indices: source_indices, shared_types: shared_types, corpus_repr: corpus_repr, env: env)) concat( "let status = response.status().as_u16();\n", "match status {\n", @@ -7486,7 +7569,7 @@ fn emit_response_code_handling(op_node: Node, transport: Node, source_indices: M } } -fn emit_response_arm(prop: Node, op_node: Node, use_from_key: Bool, transport: Node, source_indices: Map, shared_types: Set, env: TypeEnv) -> String { +fn emit_response_arm(prop: Node, op_node: Node, use_from_key: Bool, transport: Node, source_indices: Map, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv) -> String { let name = field_init_node_name_at(n: prop, source_indices: source_indices) let code_str = substring(s: name, start: 9, end: string_length(s: name)) let is_success = if string_length(s: code_str) >= 1 { @@ -7500,7 +7583,7 @@ fn emit_response_arm(prop: Node, op_node: Node, use_from_key: Bool, transport: N else { code_str } if is_success { if use_from_key { - concat(" ", pattern, " => { ", emit_from_key_extraction(op_node: op_node, source_indices: source_indices, shared_types: shared_types, env: env), " },") + concat(" ", pattern, " => { ", emit_from_key_extraction(op_node: op_node, source_indices: source_indices, shared_types: shared_types, corpus_repr: corpus_repr, env: env), " },") } else { concat(" ", pattern, " => { ", emit_plain_response_body(op_node: op_node, transport: transport, source_indices: source_indices), " },") } @@ -7514,15 +7597,15 @@ fn has_exit_prefix(name: String) -> Bool { else { substring(s: name, start: 0, end: 5) == "exit_" } } -fn emit_exit_code_handling(op_node: Node, inferred: Node, source_indices: Map) -> String { +fn emit_exit_code_handling(op_node: Node, inferred: Node, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { let exit_props = op_node.properties |> filter(p => has_exit_prefix(name: field_init_node_name_at(n: p, source_indices: source_indices))) if exit_props |> count == 0 { emit_shell_return(inferred: inferred, source_indices: source_indices) } else { let has_nonzero = exit_props |> any(p => field_init_node_name_at(n: p, source_indices: source_indices) == "exit_nonzero") - let exit_arms = exit_props |> map(p => emit_exit_arm(prop: p, inferred: inferred, source_indices: source_indices)) + let exit_arms = exit_props |> map(p => emit_exit_arm(prop: p, inferred: inferred, corpus_repr: corpus_repr, source_indices: source_indices)) let default_arm = if has_nonzero { "" } - else { concat("\n _ => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(", emit_rust_host_to_dag_string_via_seam(host_expr: "stderr", source_indices: source_indices), ") },") } + else { concat("\n _ => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(", emit_rust_host_to_dag_string_via_seam(host_expr: "stderr", corpus_repr: corpus_repr), ") },") } concat( "let exit_code = output.status.code().unwrap_or(-1);\n", "match exit_code {\n", @@ -7532,7 +7615,7 @@ fn emit_exit_code_handling(op_node: Node, inferred: Node, source_indices: Map) -> String { +fn emit_exit_arm(prop: Node, inferred: Node, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { let name = field_init_node_name_at(n: prop, source_indices: source_indices) let code_str = substring(s: name, start: 5, end: string_length(s: name)) let pattern = if code_str == "nonzero" { "_" } @@ -7541,11 +7624,11 @@ fn emit_exit_arm(prop: Node, inferred: Node, source_indices: Map { ", emit_shell_return(inferred: inferred, source_indices: source_indices), " },") } else { - concat(" ", pattern, " => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(", emit_rust_host_to_dag_string_via_seam(host_expr: "stderr", source_indices: source_indices), ") },") + concat(" ", pattern, " => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(", emit_rust_host_to_dag_string_via_seam(host_expr: "stderr", corpus_repr: corpus_repr), ") },") } } -fn emit_shell_call(op_name: String, transport: Node, registry: Map, depth: Int, inferred: Node, op_node: Node, source_indices: Map) -> String { +fn emit_shell_call(op_name: String, transport: Node, registry: Map, depth: Int, inferred: Node, op_node: Node, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { let argv = transport.children let optional_params = op_node.params |> filter(p => param_node_type_expr(n: p).return_cardinality == CardOptional) @@ -7558,7 +7641,7 @@ fn emit_shell_call(op_name: String, transport: Node, registry: Map count > 0 { match argv |> first { Present { value: first_arg } => concat(let_kw, " = std::process::Command::new(", - emit_shell_argv_element(arg: first_arg, optional_params: optional_params, source_indices: source_indices), ")") + emit_shell_argv_element(arg: first_arg, optional_params: optional_params, corpus_repr: corpus_repr, source_indices: source_indices), ")") Absent => concat(let_kw, " = std::process::Command::new(\"", emit_ident(name: op_name, target: Rust), "\")") } @@ -7568,7 +7651,7 @@ fn emit_shell_call(op_name: String, transport: Node, registry: Map count > 1 { argv |> skip(1) |> map(arg => - concat(" .arg(", emit_shell_argv_element(arg: arg, optional_params: optional_params, source_indices: source_indices), ")") + concat(" .arg(", emit_shell_argv_element(arg: arg, optional_params: optional_params, corpus_repr: corpus_repr, source_indices: source_indices), ")") ) } else { [] } let env_entries = transport_env(t: transport, source_indices: source_indices) @@ -7587,19 +7670,19 @@ fn emit_shell_call(op_name: String, transport: Node, registry: Map join(separator: "\n") } else { let output_line = " .output()?;" let check_line = "let stdout = String::from_utf8_lossy(&output.stdout).to_string();" - let return_line = emit_exit_code_handling(op_node: op_node, inferred: inferred, source_indices: source_indices) + let return_line = emit_exit_code_handling(op_node: op_node, inferred: inferred, corpus_repr: corpus_repr, source_indices: source_indices) let all_lines = concat([cmd_line], arg_lines, env_lines, [wd_line, output_line, check_line, return_line]) all_lines |> join(separator: "\n") } } -fn emit_shell_argv_element(arg: Node, optional_params: Map, source_indices: Map) -> String { +fn emit_shell_argv_element(arg: Node, optional_params: Map, corpus_repr: RustCorpusRepr, source_indices: Map) -> String { match arg.expr_data { ExprLiteral { value: LitStr { value: s } } => concat("\"", escape_string_literal_body(s: s), "\"") @@ -7640,9 +7723,9 @@ fn emit_shell_argv_element(arg: Node, optional_params: Map, source Absent => false } if is_opt { - emit_rust_dag_string_to_host_via_seam(dag_expr: concat(var_name, ".as_deref().unwrap_or(\"\")"), source_indices: source_indices) + emit_rust_dag_string_to_host_via_seam(dag_expr: concat(var_name, ".as_deref().unwrap_or(\"\")"), corpus_repr: corpus_repr) } else { - emit_rust_dag_string_to_host_via_seam(dag_expr: var_name, source_indices: source_indices) + emit_rust_dag_string_to_host_via_seam(dag_expr: var_name, corpus_repr: corpus_repr) } } _ => emit_simple_expr(expr: arg, target: Rust, source_indices: source_indices) @@ -7732,23 +7815,23 @@ fn emit_local_call(op_name: String) -> String { // Resource definition emission // ========================================================================= -fn emit_resource_def(item: Node, shared_types: Set, env: TypeEnv) -> String { +fn emit_resource_def(item: Node, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv) -> String { let item_text = authored_name(env: env, node: item) let cap_children = item.children if cap_children |> count == 0 { concat("#[derive(Debug, Clone)]\npub struct ", item_text, ";") } else { let depth = 0 - let cap_methods = cap_children |> map(c => emit_capability_method(cap_node: c, shared_types: shared_types, env: env)) + let cap_methods = cap_children |> map(c => emit_capability_method(cap_node: c, shared_types: shared_types, corpus_repr: corpus_repr, env: env)) let methods_str = cap_methods |> join(separator: "\n\n") concat("#[async_trait::async_trait]\npub trait ", item_text, " {\n", make_indent(level: depth + 1),methods_str, "\n}") } } -fn emit_capability_method(cap_node: Node, shared_types: Set, env: TypeEnv) -> String { +fn emit_capability_method(cap_node: Node, shared_types: Set, corpus_repr: RustCorpusRepr, env: TypeEnv) -> String { let input_params = cap_node.params |> map(p => - concat(emit_ident(name: param_node_name_at(n: p, source_indices: env.source_indices), target: Rust), rust_items().param_type_sep, emit_rust_param_type(n: param_node_type_expr(n: p), generic_param_names: [], shared_types: shared_types, source_indices: env.source_indices, variant_to_enum: empty_map(), env: env.clone())) + concat(emit_ident(name: param_node_name_at(n: p, source_indices: env.source_indices), target: Rust), rust_items().param_type_sep, emit_rust_param_type(n: param_node_type_expr(n: p), generic_param_names: [], shared_types: shared_types, corpus_repr: corpus_repr, source_indices: env.source_indices, variant_to_enum: empty_map(), env: env.clone())) ) let params_str = input_params |> join(separator: ", ") let all_params = if params_str == "" { @@ -7756,7 +7839,7 @@ fn emit_capability_method(cap_node: Node, shared_types: Set, env: TypeEn } else { concat("&self, ", params_str) } - let ret = render_rust_type(n: resolved_type(n: cap_node), shared_types: shared_types, source_indices: env.source_indices) + let ret = render_rust_type(n: resolved_type(n: cap_node), shared_types: shared_types, corpus_repr: corpus_repr, source_indices: env.source_indices) let items = rust_items() concat(items.async_prefix, items.func_keyword, " ", emit_ident(name: authored_name(env: env, node: cap_node), target: Rust), "(", all_params, ") -> Result<", ret, ", Box>;") } @@ -7785,7 +7868,7 @@ fn emit_data_def(name: String, type_node: Node, value: Node, registry: Map annotation_type_node } } - let raw_ty_str = render_rust_type_with_applied_binding(n: render_type_node, shared_types: shared_types, source_indices: scope.type_env.source_indices) + let raw_ty_str = render_rust_type_with_applied_binding(n: render_type_node, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) let ty_str = if raw_ty_str == "BoundedLattice" || raw_ty_str == "Rc" { match field_value_by_name(record: value, field_name: "top", source_indices: scope.type_env.source_indices) { Present { value: top_value } => @@ -7841,7 +7924,7 @@ fn rust_nominal_identity_data_expr(type_node: Node, value: Node, source_indices: } fn emit_data_def_body(type_node: Node, value: Node, registry: Map, scope: InferScope, depth: Int, shared_types: Set, emit_info: EmitGraphInfo, needs_rc: Bool) -> String { - let raw_ty_str = render_rust_type(n: type_node, shared_types: shared_types, source_indices: scope.type_env.source_indices) + let raw_ty_str = render_rust_type(n: type_node, shared_types: shared_types, corpus_repr: emit_info.corpus_repr, source_indices: scope.type_env.source_indices) let type_name = authored_name_at(source_indices: scope.type_env.source_indices, node: type_node) if type_name == "BoundedLattice" { match value.expr_data { @@ -7896,7 +7979,7 @@ fn emit_data_def_body(type_node: Node, value: Node, registry: Map let inserts = value.children |> map(f => let val_str = emit_typed_expr(texpr: field_init_node_value(n: f), registry: registry, scope: scope, depth: depth, shared_types: shared_types, emit_info: emit_info, fuel: 1024) - concat(" __m.insert(", emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", field_init_node_name_at(n: f, source_indices: scope.type_env.source_indices), "\""), source_indices: scope.type_env.source_indices), ", ", val_str, ");") + concat(" __m.insert(", emit_rust_host_to_dag_string_via_seam(host_expr: concat("\"", field_init_node_name_at(n: f, source_indices: scope.type_env.source_indices), "\""), corpus_repr: emit_info.corpus_repr), ", ", val_str, ");") ) let inserts_str = inserts |> join(separator: "\n") concat(" let mut __m = HashMap::new();\n", @@ -7920,10 +8003,10 @@ fn emit_data_def_body(type_node: Node, value: Node, registry: Map) -> TextFile { +fn emit_test_file(module_name: String, projections: List, corpus_repr: RustCorpusRepr) -> TextFile { let depth = 0 let test_fns = projections - |> map(p => emit_operation_test(projection: p, depth: depth + 1)) + |> map(p => emit_operation_test(projection: p, depth: depth + 1, corpus_repr: corpus_repr)) if test_fns |> count == 0 { TextFile { path: "", content: "" } } else { @@ -7939,9 +8022,10 @@ fn emit_test_file(module_name: String, projections: List) -> Tex } } -fn rust_test_signature_comment(projection: TestProjection) -> String { +fn rust_test_signature_comment(projection: TestProjection, corpus_repr: RustCorpusRepr) -> String { + let stub_env = TypeEnv { bindings: empty_map(), recursive_types: [], recursive_type_set: empty_map(), inductive_fields: empty_map(), source_indices: projection.source_indices, intern_table: empty_intern_table() } let params_str = projection.params - |> map(p => concat(param_node_name_at(n: p, source_indices: projection.source_indices), ": ", emit_rust_param_type(n: param_node_type_expr(n: p), generic_param_names: [], shared_types: empty_set(), source_indices: projection.source_indices, variant_to_enum: empty_map()))) + |> map(p => concat(param_node_name_at(n: p, source_indices: projection.source_indices), ": ", emit_rust_param_type(n: param_node_type_expr(n: p), generic_param_names: [], shared_types: empty_set(), corpus_repr: corpus_repr, source_indices: projection.source_indices, variant_to_enum: empty_map(), env: stub_env))) |> join(separator: ", ") concat( "// Signature: ", @@ -7953,7 +8037,7 @@ fn rust_test_signature_comment(projection: TestProjection) -> String { emit_node_type(n: projection.inferred, target: Rust, source_indices: projection.source_indices)) } -fn emit_operation_test(projection: TestProjection, depth: Int) -> String { +fn emit_operation_test(projection: TestProjection, depth: Int, corpus_repr: RustCorpusRepr) -> String { let test_name = rust_test_name(projection: projection) let struct_name = sanitize_service_name(name: projection.service_name) let op_method = to_snake(name: projection.operation_name) @@ -7964,7 +8048,7 @@ fn emit_operation_test(projection: TestProjection, depth: Int) -> String { let args_str = param_args |> join(separator: ", ") let call_args = if args_str == "" { "" } else { args_str } concat(rust_async_test_decorator(), "\nasync fn ", test_name, "() {\n", - indent, rust_test_signature_comment(projection: projection), "\n", + indent, rust_test_signature_comment(projection: projection, corpus_repr: corpus_repr), "\n", indent, "let service = ", struct_name, "::new(crate::dry_run::DryRunMode(true));\n", indent, "let result = service.", emit_ident(name: op_method, target: Rust), "(", call_args, ").await;\n", indent, "assert!(result.is_ok(), \"", struct_name, ".", projection.operation_name, " should succeed in dry-run mode: {:?}\", result.err());\n", diff --git a/src/v1/stage0/src/bin/regen_stage0.rs b/src/v1/stage0/src/bin/regen_stage0.rs index 3d3d9056484..05ce0786d80 100644 --- a/src/v1/stage0/src/bin/regen_stage0.rs +++ b/src/v1/stage0/src/bin/regen_stage0.rs @@ -109,6 +109,41 @@ const GENERATED_STAGE0_FILES: &[&str] = &[ "v1_std_core.rs", ]; +// ========================================================================= +// CARRIER MARK -- HAND-SYNCED MIRROR, NOT a regen fixpoint (class-3 splice). +// +// The committed stage0 seed is a HAND-SYNCED MIRROR of the .dag authority, NOT a +// clean-regen fixpoint. `regen_stage0 --verify` is therefore EXPECTED to differ +// from the committed seed today: a faithful full regen wires every emitted module, +// including the std-tower modules that are DELIBERATELY UNWIRED in lib.rs here +// (std_measure / std_algebra / std_realization_schedule / std_machine_constraints +// / std_integer / extdeps_version_semver / extdeps_cargo_version), and that wiring +// surfaces ~150 latent emitter-completeness gaps (std numeric/measure-tower generic +// emission). Those modules stay UNWIRED here exactly as on main. +// +// The class-3 emitter mirror (v1_compiler_emit_rust.rs / v1_compiler_infer.rs / +// v1_compiler_infer_emit_info.rs) was landed by overlay-3-committed: faithful regen +// of the class-3 .dag for those three modules, spliced onto the committed seed, +// with two local drifts hand-resolved (cargo header inlined to avoid importing the +// unwired extdeps_cargo_version orphan; wire policy passed by value, Rc clone, at +// wire_value_serialize.rs). Every other module is byte-identical to committed. +// +// LANE (deferred): regen-fixpoint emitter-self-host (~150-gap) -- wire-all-emitted- +// modules so a clean regen reproduces the committed seed bit-identically (the §7 +// reproduce-fixpoint that licenses deleting src/v1). +// PROVENANCE (#5514 verbatim deferral): "regen-write still emits a non-building seed +// from ~150 emitter-completeness gaps, the clean green regen fixpoint is deferred, +// converges with the Route-A emitter self-host". +// DISSOLUTION TRIGGER: §7 fixpoint convergence with the Route-A emitter self-host -- +// when wire-all-emitted-modules -> regen-equals-committed is in reach; a fresh +// work-item gets dispatched THEN. (breadcrumb: node://adhoc-80af9ff8-40f) +// +// INVARIANCE CAVEAT (quick-seal, verbatim): class-3 host-vs-faithful SELECTION is +// representation-invariant on the v1-bundled HOST seed at this tip -- CONTROL B +// (gate-isolated revert) builds green, CONTROL A errors are the wire policy confound +// not representation; the selection's behavioral discriminating-proof is OWED by the +// deferred faithful target, where the selection actually fires. +// ========================================================================= const HAND_MAINTAINED_STAGE0_FILES: &[&str] = &[ "cache_purity_oracle.rs", "cli_run.rs", @@ -219,6 +254,9 @@ fn run() -> Result<(), String> { time_phase(&mut phases, "patch_bootstrap_dag_collect", || { patch_bootstrap_dag_collect(&fresh_dir.join("src")) })?; + time_phase(&mut phases, "patch_languages_consumer_census_mod", || { + patch_languages_consumer_census_mod(&fresh_dir.join("src")) + })?; time_phase(&mut phases, "assert_bootstrap_emit_core_support", || { assert_bootstrap_emit_core_support(&fresh_dir.join("src")) })?; @@ -745,6 +783,39 @@ fn patch_bootstrap_dag_collect(src_dir: &Path) -> Result<(), String> { Ok(()) } +/// Declare the hand-maintained `languages_consumer_census` module in the +/// generated `lib.rs`. +/// +/// `languages_consumer_census.rs` is a hand-maintained v1 seed module (the v2 +/// authority is the lens `src/v2/lens/languages_consumer_census.dag`); it is +/// copied into the fresh crate by `copy_hand_maintained_support` and consumed by +/// `v1_interpreter.rs`. Unlike its sibling lens/projection modules, it is +/// uniquely absent from the emitter's `all_module_files`, so +/// `emit_lib_rs_from_files` (src/v1/05_emit_rust.dag) does not write a +/// `pub mod languages_consumer_census;` for it and the fresh crate fails to +/// resolve `crate::languages_consumer_census::*`. Inject the declaration here, +/// mirroring `patch_bootstrap_dag_collect`. +/// +/// DISSOLUTION: remove this patch once 05_emit_rust.dag's `all_module_files` +/// (or its `hand_maintained_mods` emission path) includes +/// `languages_consumer_census`, so the emitter declares it directly (single +/// authority — the §3 parallel-ledger note on `HAND_MAINTAINED_STAGE0_FILES`). +fn patch_languages_consumer_census_mod(src_dir: &Path) -> Result<(), String> { + let lib_path = src_dir.join("lib.rs"); + let mut lib_text = + fs::read_to_string(&lib_path).map_err(|e| format!("read {}: {e}", lib_path.display()))?; + if !lib_text.contains("pub mod languages_consumer_census;") { + // Insert after import_resolution_project so `cargo fmt` module order + // matches the committed lib.rs (emitter emits mods in sorted order). + lib_text = lib_text.replace( + "pub mod import_resolution_project;\n", + "pub mod import_resolution_project;\npub mod languages_consumer_census;\n", + ); + } + fs::write(&lib_path, lib_text).map_err(|e| format!("write {}: {e}", lib_path.display()))?; + Ok(()) +} + fn assert_no_local_delegated_fns(text: &str) -> Result<(), String> { let mut duplicates = Vec::new(); for symbol in DELEGATED_DAG_COLLECT_SYMBOLS { diff --git a/src/v1/stage0/src/v1_compiler_emit_rust.rs b/src/v1/stage0/src/v1_compiler_emit_rust.rs index c1e85f6f669..0ce63b591f2 100644 --- a/src/v1/stage0/src/v1_compiler_emit_rust.rs +++ b/src/v1/stage0/src/v1_compiler_emit_rust.rs @@ -1,5 +1,33 @@ // Generated by v1 compiler -- do not edit. // Source module: v1.compiler.emit_rust +// +// HAND-SYNCED MIRROR (class-3 splice) -- this committed seed is a HAND-SYNCED +// MIRROR of the .dag authority, NOT a regen fixpoint. This file is one of three +// (with v1_compiler_infer.rs, v1_compiler_infer_emit_info.rs) spliced from a +// faithful regen of the class-3 .dag onto the committed seed, with two local +// drifts hand-resolved (cargo header inlined below so it does not import the +// deliberately-unwired extdeps_cargo_version orphan; policy ref/value alignment +// at wire_value_serialize.rs). The other modules stay byte-identical to committed. +// +// LANE (deferred): regen-fixpoint emitter-self-host (~150-gap) -- wire-all-emitted- +// modules so a clean regen reproduces this committed seed bit-identically (the +// §7 reproduce-fixpoint that licenses deleting src/v1). +// SCOPE: a faithful full regen wires the deliberately-unwired orphan std modules +// (std_measure / std_algebra / std_realization_schedule / std_machine_constraints +// / std_integer / extdeps_version_semver / extdeps_cargo_version) and surfaces +// ~150 latent emitter-completeness gaps (std numeric/measure-tower generic +// emission). They stay UNWIRED here exactly as on main. +// PROVENANCE (#5514 verbatim deferral): "regen-write still emits a non-building +// seed from ~150 emitter-completeness gaps, the clean green regen fixpoint is +// deferred, converges with the Route-A emitter self-host". +// DISSOLUTION TRIGGER: §7 fixpoint convergence with the Route-A emitter self-host +// -- when wire-all-emitted-modules -> regen-equals-committed is in reach; a fresh +// work-item gets dispatched THEN. (breadcrumb: node://adhoc-80af9ff8-40f) +// INVARIANCE CAVEAT (quick-seal, verbatim): class-3 host-vs-faithful SELECTION is +// representation-invariant on the v1-bundled HOST seed at this tip -- CONTROL B +// (gate-isolated revert) builds green, CONTROL A errors are the wire policy +// confound not representation; the selection's behavioral discriminating-proof is +// OWED by the deferred faithful target, where the selection actually fires. pub use crate::extdeps_languages_rust_emit::HigherOrderMethodSpec; pub use crate::extdeps_languages_rust_emit::{ @@ -8,8 +36,8 @@ pub use crate::extdeps_languages_rust_emit::{ rust_method_templates, rust_method_wraps_result, rust_serde_rename_all_screaming_snake_case, rust_serde_rename_all_snake_case, rust_struct_derives, rust_struct_derives_copy, }; -pub use crate::std_induction::SubValueRelation; use crate::std_induction::SubValueRelation::SubValueUnknown; +pub use crate::std_induction::{InductiveField, SubValueRelation}; pub use crate::std_syntax::{AlgebraFieldKind, BinOp, LiteralValue}; pub use crate::std_types::SourceSpan; pub use crate::std_types::{is_container_type, is_kernel_type}; @@ -45,19 +73,25 @@ pub use crate::v1_compiler_emit_core_support::{ pub use crate::v1_compiler_emit_core_support::{EmitResult, TestProjection}; pub use crate::v1_compiler_infer::InferScope; pub use crate::v1_compiler_infer::{ - build_emit_graph_info, build_params_scope, expr_span, extend_scope, resolved_type_name, + build_emit_graph_info, build_params_scope, expand_type_for_field_access, expr_span, + extend_scope, resolved_type_name, }; +use crate::v1_compiler_infer_emit_info::RustCorpusRepr::{FaithfulFreeMonoid, HostNative}; use crate::v1_compiler_infer_emit_info::TypeRepr::{EnumRepr, StructRepr}; pub use crate::v1_compiler_infer_emit_info::{ find_variant_parent, is_enum_in_summaries, is_known_variant, lookup_emit_type_summary, variant_belongs_to_enum, variant_summary_key, }; -pub use crate::v1_compiler_infer_emit_info::{EmitGraphInfo, TypeRepr, TypeSummary}; +pub use crate::v1_compiler_infer_emit_info::{ + EmitGraphInfo, RustCorpusRepr, TypeRepr, TypeSummary, +}; pub use crate::v1_compiler_infer_env::{authored_name, lookup_type_by_name, lookup_type_for}; pub use crate::v1_compiler_infer_env::{TypeBinding, TypeEnv}; use crate::v1_compiler_infer_items::ItemKind::{DataItem, OtherItem, TypeItem}; pub use crate::v1_compiler_infer_items::{ItemInfo, ItemKind, ResolvedGraph, TypedModule}; -pub use crate::v1_compiler_infer_resolve::lookup_unit_variant_phantom_type; +pub use crate::v1_compiler_infer_resolve::{ + is_width_nat_type_literal, lookup_unit_variant_phantom_type, +}; pub use crate::v1_compiler_infer_service::{ extract_typed_service_name, is_typed_service_call_receiver, }; @@ -83,7 +117,6 @@ pub use crate::v1_compiler_runtime_rust::rust_runtime_source; use crate::v1_rt; use crate::v1_rt::Witness; use crate::v1_rt::Witness::{Holds, Violates}; -use crate::v1_std_core::empty_intern_table; use crate::v1_std_core::AlgebraFieldKind::*; use crate::v1_std_core::BinOp::*; use crate::v1_std_core::CallSemantics::{LookupCallSemantics, PlainCallSemantics}; @@ -112,16 +145,16 @@ use crate::v1_std_core::VarBindingKind::{ }; pub use crate::v1_std_core::{ arg_name_at, arg_value, arm_body, arm_guard, arm_pattern, authored_name_at, binop_left, - binop_right, cast_expr, cast_target, expr_call_func_at, expr_has_non_tail_self_call, - expr_has_self_call, expr_method_name_at, expr_var_name_at, field_access_base, - field_access_field_at, field_binding_name_at, field_binding_pattern, field_init_node_name_at, - field_init_node_value, field_node_name_at, field_node_type_expr, find_child_named, - find_property, foreach_body, foreach_collection, foreach_variable_at, generic_param_name_at, - if_condition, if_else_branch, if_then_branch, import_is_all, import_specific_names_at, - index_base, index_expr, is_compiler_error, is_file_transport, is_rest_transport, - is_shell_transport, lambda_body, lambda_param_names_at, let_binding_name_at, let_body, - let_value, make_arg_node, make_error_node, make_expr_node, make_named_expr_node, make_span, - match_arm_nodes, match_scrutinee, method_arg_nodes, method_receiver, module_imports, + binop_right, cast_expr, cast_target, empty_intern_table, expr_call_func_at, + expr_has_non_tail_self_call, expr_has_self_call, expr_method_name_at, expr_var_name_at, + field_access_base, field_access_field_at, field_binding_name_at, field_binding_pattern, + field_init_node_name_at, field_init_node_value, field_node_name_at, field_node_type_expr, + find_child_named, find_property, foreach_body, foreach_collection, foreach_variable_at, + generic_param_name_at, if_condition, if_else_branch, if_then_branch, import_is_all, + import_specific_names_at, index_base, index_expr, is_compiler_error, is_file_transport, + is_rest_transport, is_shell_transport, lambda_body, lambda_param_names_at, let_binding_name_at, + let_body, let_value, make_arg_node, make_error_node, make_expr_node, make_named_expr_node, + make_span, match_arm_nodes, match_scrutinee, method_arg_nodes, method_receiver, module_imports, module_items, param_node_default_value, param_node_name_at, param_node_type_expr, record_lit_type_name_at, resource_use_name_at, resource_use_resource, return_value, service_config_auth, service_config_auth_input, service_config_auth_source, @@ -144,6 +177,7 @@ use std::rc::Rc; pub fn render_rust_type( n: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { match n.inferred.clone().as_deref().cloned() { @@ -159,12 +193,26 @@ pub fn render_rust_type( applied.clone(), Rc::new(vec![]), shared_types, + corpus_repr, source_indices.clone(), + v1_rt::rc_empty_map::(), + Rc::new(TypeEnv { + bindings: v1_rt::rc_empty_map::>(), + recursive_types: Rc::new(vec![]), + recursive_type_set: v1_rt::rc_empty_map::(), + inductive_fields: v1_rt::rc_empty_map::< + String, + Rc>>, + >(), + source_indices: source_indices.clone(), + intern_table: empty_intern_table(), + }), ) } else { render_rust_type_without_applied_binding( n.clone(), shared_types, + corpus_repr, source_indices.clone(), ) } @@ -172,6 +220,7 @@ pub fn render_rust_type( None => render_rust_type_without_applied_binding( n.clone(), shared_types, + corpus_repr, source_indices.clone(), ), }, @@ -181,6 +230,7 @@ pub fn render_rust_type( pub fn render_rust_type_without_applied_binding( n: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { if (((n.connective.clone() == Connective::NoConnective) @@ -191,7 +241,17 @@ pub fn render_rust_type_without_applied_binding( n.clone(), Rc::new(vec![]), shared_types, + corpus_repr, source_indices.clone(), + v1_rt::rc_empty_map::(), + Rc::new(TypeEnv { + bindings: v1_rt::rc_empty_map::>(), + recursive_types: Rc::new(vec![]), + recursive_type_set: v1_rt::rc_empty_map::(), + inductive_fields: v1_rt::rc_empty_map::>>>(), + source_indices: source_indices.clone(), + intern_table: empty_intern_table(), + }), ) } else { if node_is_set_collection(n.clone(), source_indices.clone()) { @@ -231,19 +291,20 @@ pub fn render_rust_type_without_applied_binding( None => emit_rust_compile_error_expr("Set missing element type".to_string()), } } else { - let tn = authored_name_at(source_indices.clone(), n.clone()); - if (tn.clone().as_str() == "String".to_string().as_str() - && ((n.children.clone().len() as i64) == 0) - && rust_emit_faithful_text_carrier(source_indices.clone())) { - render_rust_text_carrier(shared_types.clone()) - } else { - render_node_type( - n.clone(), - RenderTarget::Rust, - shared_types, - source_indices.clone(), - ) + let tn = authored_name_at(source_indices.clone(), n.clone()); + if (((tn == "String".to_string()) && ((n.children.clone().len() as i64) == 0)) + && corpus_repr_is_faithful(corpus_repr)) + { + render_rust_text_carrier(shared_types) + } else { + render_node_type( + n.clone(), + RenderTarget::Rust, + shared_types, + source_indices.clone(), + ) + } } } } @@ -255,22 +316,21 @@ pub fn empty_string_bool_map() -> Rc> { pub fn rust_type_is_rc_wrapped(type_name: String) -> bool { ((v1_rt::string_length(&type_name) >= 3) - && (v1_rt::substring(&type_name, 0, 3).as_str() == "Rc<".to_string().as_str())) + && (v1_rt::substring(&type_name, 0, 3) == "Rc<".to_string())) } -pub fn rust_corpus_includes_v1_compiler( - source_indices: Rc>>, -) -> bool { - v1_rt::map_keys(&source_indices) - .iter() - .cloned() - .any(|k| k.contains("/v1/") || k.contains("src/v1")) +pub fn corpus_repr_is_faithful(corpus_repr: RustCorpusRepr) -> bool { + match corpus_repr { + RustCorpusRepr::FaithfulFreeMonoid => true, + RustCorpusRepr::HostNative => false, + } } -pub fn rust_emit_faithful_text_carrier( - source_indices: Rc>>, -) -> bool { - !rust_corpus_includes_v1_compiler(source_indices) +pub fn corpus_repr_is_host(corpus_repr: RustCorpusRepr) -> bool { + match corpus_repr { + RustCorpusRepr::HostNative => true, + RustCorpusRepr::FaithfulFreeMonoid => false, + } } pub fn render_rust_text_carrier(shared_types: Rc>) -> String { @@ -283,9 +343,9 @@ pub fn render_rust_text_carrier(shared_types: Rc>>, + corpus_repr: RustCorpusRepr, ) -> String { - if rust_emit_faithful_text_carrier(source_indices) { + if corpus_repr_is_faithful(corpus_repr) { v1_rt::concat( v1_rt::concat( "crate::v2_std_text::host_string_text_from_rust_host(".to_string(), @@ -300,9 +360,9 @@ pub fn emit_rust_host_to_dag_string_via_seam( pub fn emit_rust_dag_string_to_host_via_seam( dag_expr: String, - source_indices: Rc>>, + corpus_repr: RustCorpusRepr, ) -> String { - if rust_emit_faithful_text_carrier(source_indices) { + if corpus_repr_is_faithful(corpus_repr) { v1_rt::concat( v1_rt::concat( "crate::v2_std_text::host_string_text_to_rust_host(".to_string(), @@ -316,57 +376,52 @@ pub fn emit_rust_dag_string_to_host_via_seam( } pub fn rust_host_string_seam_fn_emit(name: String) -> Option { - if name.as_str() == "host_string_text_from_rust_host" { - Some(v1_rt::concat( - v1_rt::concat( - v1_rt::concat( - "pub fn host_string_text_from_rust_host(host: String) -> String {\n".to_string(), - " host.chars().fold(crate::v2_std_algebra::freemonoid_empty::(), ".to_string(), - ), - "|acc, ch| crate::v2_std_algebra::list_snoc_item(acc, v1_rt::code_point(ch.to_string())))\n".to_string(), - ), - "}\n".to_string(), - )) - } else if name.as_str() == "host_string_text_to_rust_host" { - Some(v1_rt::concat( - v1_rt::concat( - v1_rt::concat( - "pub fn host_string_text_to_rust_host(text: String) -> String {\n".to_string(), - " crate::v2_std_algebra::fold_list(text, String::new(), |acc, cp| v1_rt::concat(acc, v1_rt::from_code_point(cp)))\n".to_string(), - ), - "}\n".to_string(), - ), - "".to_string(), - )) + if (name.clone() == "host_string_text_from_rust_host".to_string()) { + Some(v1_rt::concat(v1_rt::concat(v1_rt::concat("pub fn host_string_text_from_rust_host(host: String) -> String {\n".to_string(), " host.chars().fold(crate::v2_std_algebra::freemonoid_empty::(), ".to_string()), "|acc, ch| crate::v2_std_algebra::list_snoc_item(acc, v1_rt::code_point(ch.to_string())))\n".to_string()), "}\n".to_string())) } else { - None + if (name.clone() == "host_string_text_to_rust_host".to_string()) { + Some(v1_rt::concat(v1_rt::concat("pub fn host_string_text_to_rust_host(text: String) -> String {\n".to_string(), " crate::v2_std_algebra::fold_list(text, String::new(), |acc, cp| v1_rt::concat(acc, v1_rt::from_code_point(cp)))\n".to_string()), "}\n".to_string())) + } else { + None + } } } pub fn rust_opaque_kernel_alias_carrier(name: String) -> Option { - if (name.clone().as_str() == "Json".to_string().as_str()) - || (name.clone().as_str() == "Bytes".to_string().as_str()) - { + if ((name.clone() == "Json".to_string()) || (name.clone() == "Bytes".to_string())) { Some(coerce_primitive_type(RenderTarget::Rust, name.clone())) } else { None } } -pub fn rust_named_type_base( - name: String, - source_indices: Rc>>, -) -> String { - if ((name.clone().as_str() == "Witness".to_string().as_str()) - || (name.clone().as_str() == "witness".to_string().as_str())) +pub fn rust_seed_host_numeric_alias(name: String, corpus_repr: RustCorpusRepr) -> Option { + if (((name.clone() == "Nat".to_string()) || (name.clone() == "Int".to_string())) + && corpus_repr_is_host(corpus_repr)) { + Some("i64".to_string()) + } else { + None + } +} + +pub fn rust_seed_host_container_base(name: String, corpus_repr: RustCorpusRepr) -> Option { + if ((name == "List".to_string()) && corpus_repr_is_host(corpus_repr)) { + Some("Vec".to_string()) + } else { + None + } +} + +pub fn rust_named_type_base(name: String, corpus_repr: RustCorpusRepr) -> String { + if ((name.clone() == "Witness".to_string()) || (name.clone() == "witness".to_string())) { "Witness".to_string() - } else if name.clone().as_str() == "String".to_string().as_str() - && rust_emit_faithful_text_carrier(source_indices) - { - "FreeMonoid".to_string() } else { - coerce_primitive_type(RenderTarget::Rust, name.clone()) + if ((name.clone() == "String".to_string()) && corpus_repr_is_faithful(corpus_repr)) { + "FreeMonoid".to_string() + } else { + coerce_primitive_type(RenderTarget::Rust, name.clone()) + } } } @@ -394,15 +449,112 @@ pub fn rust_normalize_partial_function_field_type_text(rendered: String) -> Stri ) } +pub fn is_parametric_opaque_type_by_name(env: Rc, type_name: String) -> bool { + match lookup_type_by_name(env.clone(), type_name) { + Some(item) => is_parametric_opaque_type_decl_item(item.clone(), env.source_indices.clone()), + None => false, + } +} + +pub fn is_parametric_opaque_type_base( + type_name: String, + def_mod_filename: String, + typed_modules: Rc>>, + source_indices: Rc>>, + module_index: Rc, +) -> bool { + match type_item_by_name_in_module_filename( + type_name, + def_mod_filename, + typed_modules, + source_indices.clone(), + module_index, + ) { + Some(item) => is_parametric_opaque_type_decl_item(item.clone(), source_indices.clone()), + None => false, + } +} + +pub fn render_rust_phantom_opaque_applied_type_arg( + n: Rc, + generic_param_names: Rc>, + shared_types: Rc>, + corpus_repr: RustCorpusRepr, + source_indices: Rc>>, + scope: Rc, + imports: Rc>>, + registry: Rc>>, + module_name: String, + export_sets: Rc>>>, + typed_modules: Rc>>, + module_index: Rc, + variant_to_enum: Rc>, +) -> String { + if is_width_nat_type_literal(n.clone()) { + "()".to_string() + } else { + render_rust_alias_rhs_type( + n.clone(), + generic_param_names, + shared_types, + corpus_repr, + source_indices, + scope, + imports, + registry, + module_name, + export_sets, + typed_modules, + module_index, + variant_to_enum, + ) + } +} + +pub fn render_rust_phantom_opaque_applied_decl_arg( + n: Rc, + generic_param_names: Rc>, + shared_types: Rc>, + corpus_repr: RustCorpusRepr, + source_indices: Rc>>, + variant_to_enum: Rc>, + env: Rc, +) -> String { + if is_width_nat_type_literal(n.clone()) { + "()".to_string() + } else { + render_rust_decl_type( + n.clone(), + generic_param_names, + shared_types, + corpus_repr, + source_indices, + variant_to_enum, + env, + ) + } +} + pub fn render_rust_applied_type_arg( n: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, + env: Rc, ) -> String { match n.inferred.clone().as_deref().cloned() { Some(InferredNode::TypeVariable { id: tv, .. }) => tv.clone(), - _ => render_rust_decl_type(n.clone(), generic_param_names, shared_types, source_indices), + _ => render_rust_decl_type( + n.clone(), + generic_param_names, + shared_types, + corpus_repr, + source_indices, + variant_to_enum, + env, + ), } } @@ -410,26 +562,46 @@ pub fn render_rust_applied_type( n: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, + env: Rc, ) -> String { { - let base = rust_named_type_base( - authored_name_at(source_indices.clone(), n.clone()), - source_indices.clone(), - ); + let base_name = authored_name_at(source_indices.clone(), n.clone()); + let base = match rust_seed_host_container_base(base_name.clone(), corpus_repr.clone()) { + Some(host) => host.clone(), + None => rust_named_type_base(base_name.clone(), corpus_repr.clone()), + }; if ((n.children.clone().len() as i64) == 0) { base } else { { + let peel = is_parametric_opaque_type_by_name(env.clone(), base_name.clone()); let args = Rc::new({ let mut __result = Vec::new(); for arg in n.children.clone().iter().cloned() { - __result.push(render_rust_applied_type_arg( - arg.clone(), - generic_param_names.clone(), - shared_types.clone(), - source_indices.clone(), - )); + __result.push(if peel.clone() { + render_rust_phantom_opaque_applied_decl_arg( + arg.clone(), + generic_param_names.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + variant_to_enum.clone(), + env.clone(), + ) + } else { + render_rust_applied_type_arg( + arg.clone(), + generic_param_names.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + variant_to_enum.clone(), + env.clone(), + ) + }); } __result }) @@ -460,14 +632,20 @@ pub fn render_rust_applied_type_shared( n: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, + env: Rc, ) -> String { { let rendered = render_rust_applied_type( n.clone(), generic_param_names, shared_types.clone(), + corpus_repr, source_indices.clone(), + variant_to_enum, + env, ); let type_name = authored_name_at(source_indices.clone(), n.clone()); render_rust_shared_type_if_needed(type_name, rendered, shared_types.clone()) @@ -478,7 +656,10 @@ pub fn render_rust_decl_type( n: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, + env: Rc, ) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { let applied_prop = find_property( @@ -486,8 +667,7 @@ pub fn render_rust_decl_type( "__applied_type_args".to_string(), source_indices.clone(), ); - let has_applied_prop = applied_prop.is_some(); - let applied_overlay = match applied_prop { + let applied_overlay = match applied_prop.clone() { Some(applied) => { if ((applied.children.clone().len() as i64) > 0) { Some(applied.clone()) @@ -502,7 +682,10 @@ pub fn render_rust_decl_type( applied.clone(), generic_param_names.clone(), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), + variant_to_enum.clone(), + env.clone(), ), None => { let name = authored_name_at(source_indices.clone(), n.clone()); @@ -511,7 +694,7 @@ pub fn render_rust_decl_type( && { let mut __found = false; for g in generic_param_names.clone().iter().cloned() { - if (g.clone().as_str() == name.clone().as_str()) { + if (g.clone() == name.clone()) { __found = true; break; } @@ -520,67 +703,103 @@ pub fn render_rust_decl_type( }) { name.clone() - } else if ((n.connective.clone() == Connective::NoConnective) - && ((n.children.clone().len() as i64) == 0) - && !has_applied_prop - && name.clone().as_str() == "String".to_string().as_str() - && rust_emit_faithful_text_carrier(source_indices.clone())) - { - render_rust_text_carrier(shared_types.clone()) - } else if ((n.connective.clone() == Connective::NoConnective) - && ((n.children.clone().len() as i64) == 0) - && !has_applied_prop - && v1_rt::set_contains(&shared_types, name.clone())) - { - let stub_env = Rc::new(TypeEnv { - bindings: Rc::new(HashMap::new()), - recursive_types: Rc::new(vec![]), - recursive_type_set: Rc::new(HashMap::new()), - inductive_fields: Rc::new(HashMap::new()), - source_indices: source_indices.clone(), - intern_table: empty_intern_table(), - }); - let rendered = rust_render_type_leaf_name( - name.clone(), - v1_rt::rc_empty_map::(), - stub_env, - ); - render_rust_shared_type_if_needed(name.clone(), rendered, shared_types.clone()) } else { - if ((n.connective.clone() == Connective::NoConnective) - && ((n.children.clone().len() as i64) > 0)) + if (((((n.connective.clone() == Connective::NoConnective) + && ((n.children.clone().len() as i64) == 0)) + && (applied_prop.clone() == None)) + && (name.clone() == "String".to_string())) + && corpus_repr_is_faithful(corpus_repr.clone())) { + render_rust_text_carrier(shared_types.clone()) + } else { + if ((((n.connective.clone() == Connective::NoConnective) + && ((n.children.clone().len() as i64) == 0)) + && (applied_prop.clone() == None)) + && v1_rt::set_contains(&shared_types, name.clone())) { - let base = rust_named_type_base(name.clone(), source_indices.clone()); - let args = Rc::new({ - let mut __result = Vec::new(); - for arg in n.children.clone().iter().cloned() { - __result.push(render_rust_decl_type( - arg.clone(), - generic_param_names.clone(), + { + let rendered = rust_render_type_leaf_name( + name.clone(), + variant_to_enum.clone(), + env.clone(), + ); + render_rust_shared_type_if_needed( + name.clone(), + rendered, + shared_types.clone(), + ) + } + } else { + if ((n.connective.clone() == Connective::NoConnective) + && ((n.children.clone().len() as i64) > 0)) + { + if (!is_container_type(name.clone()) + && rust_fn_sig_peel_closed_alias(env.clone(), n.clone())) + { + render_rust_shared_type_if_needed( + name.clone(), + name.clone(), shared_types.clone(), - source_indices.clone(), - )); + ) + } else { + { + let base = + rust_named_type_base(name.clone(), corpus_repr.clone()); + let peel = is_parametric_opaque_type_by_name( + env.clone(), + name.clone(), + ); + let args = Rc::new({ + let mut __result = Vec::new(); + for arg in n.children.clone().iter().cloned() { + __result.push(if peel.clone() { + render_rust_phantom_opaque_applied_decl_arg( + arg.clone(), + generic_param_names.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + variant_to_enum.clone(), + env.clone(), + ) + } else { + render_rust_decl_type( + arg.clone(), + generic_param_names.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + variant_to_enum.clone(), + env.clone(), + ) + }); + } + __result + }) + .join(&", ".to_string()); + let applied_ty = v1_rt::concat( + v1_rt::concat( + v1_rt::concat(base, "<".to_string()), + args, + ), + ">".to_string(), + ); + render_rust_shared_type_if_needed( + name.clone(), + applied_ty, + shared_types.clone(), + ) + } } - __result - }) - .join(&", ".to_string()); - let applied_ty = v1_rt::concat( - v1_rt::concat(v1_rt::concat(base, "<".to_string()), args), - ">".to_string(), - ); - render_rust_shared_type_if_needed( - name.clone(), - applied_ty, - shared_types.clone(), - ) + } else { + render_rust_type_with_applied_binding( + n.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + ) + } } - } else { - render_rust_type_with_applied_binding( - n.clone(), - shared_types.clone(), - source_indices.clone(), - ) } } } @@ -589,53 +808,78 @@ pub fn render_rust_decl_type( } pub fn rust_fn_sig_peel_closed_alias(env: Rc, n: Rc) -> bool { - let name = authored_name_at(env.source_indices.clone(), n.clone()); - if name.clone().as_str() == "String".to_string().as_str() { - return false; - } - let binding = match lookup_type_for(env.clone(), n.clone()) { - Some(b) => b, - None => { - let name = authored_name_at(env.source_indices.clone(), n.clone()); - match lookup_type_by_name(env.clone(), name) { - Some(b) => b, - None => return false, - } + { + let name = authored_name_at(env.source_indices.clone(), n.clone()); + if (name.clone() == "String".to_string()) { + return false; } - }; - (binding.params.clone().len() as i64) == 0 + let binding = match lookup_type_for(env.clone(), n.clone()) { + Some(b) => b.clone(), + None => { + let name = authored_name_at(env.source_indices.clone(), n.clone()); + match lookup_type_by_name(env.clone(), name.clone()) { + Some(b) => b.clone(), + None => return false, + } + } + }; + ((binding.params.clone().len() as i64) == 0) + } } pub fn render_rust_fn_sig_type( n: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, env: Rc, ) -> String { - let name = authored_name_at(source_indices.clone(), n.clone()); - if ((n.connective.clone() == Connective::NoConnective) - && ((n.children.clone().len() as i64) == 0) - && name.clone().as_str() == "String".to_string().as_str() - && rust_emit_faithful_text_carrier(source_indices.clone())) - { - render_rust_text_carrier(shared_types.clone()) - } else if ((n.connective.clone() == Connective::NoConnective) - && ((n.children.clone().len() as i64) > 0) - && !is_container_type(name.clone()) - && rust_fn_sig_peel_closed_alias(env.clone(), n.clone())) { - render_rust_shared_type_if_needed(name.clone(), name.clone(), shared_types.clone()) - } else if ((generic_param_names.clone().len() as i64) > 0) { - render_rust_decl_type(n, generic_param_names.clone(), shared_types, source_indices) - } else { - render_rust_fn_sig_type_applied_binding(n, shared_types, source_indices, env) + let name = authored_name_at(source_indices.clone(), n.clone()); + if ((((n.connective.clone() == Connective::NoConnective) + && ((n.children.clone().len() as i64) == 0)) + && (name.clone() == "String".to_string())) + && corpus_repr_is_faithful(corpus_repr.clone())) + { + render_rust_text_carrier(shared_types) + } else { + if ((((n.connective.clone() == Connective::NoConnective) + && ((n.children.clone().len() as i64) > 0)) + && !is_container_type(name.clone())) + && rust_fn_sig_peel_closed_alias(env.clone(), n.clone())) + { + render_rust_shared_type_if_needed(name.clone(), name.clone(), shared_types) + } else { + if ((generic_param_names.clone().len() as i64) > 0) { + render_rust_decl_type( + n.clone(), + generic_param_names.clone(), + shared_types, + corpus_repr.clone(), + source_indices.clone(), + variant_to_enum, + env.clone(), + ) + } else { + render_rust_fn_sig_type_applied_binding( + n.clone(), + shared_types, + corpus_repr.clone(), + source_indices.clone(), + env.clone(), + ) + } + } + } } } pub fn render_rust_fn_sig_type_applied_binding( n: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, env: Rc, ) -> String { @@ -646,25 +890,42 @@ pub fn render_rust_fn_sig_type_applied_binding( ) { Some(applied) => { if ((applied.children.clone().len() as i64) > 0) { - let outer_name = authored_name_at(source_indices.clone(), n.clone()); - if outer_name.as_str() != "" - && n.connective.clone() == Connective::NoConnective - && (n.children.clone().len() as i64) == 0 - && rust_fn_sig_peel_closed_alias(env.clone(), n.clone()) { - render_rust_shared_type_if_needed( - outer_name.clone(), - outer_name, - shared_types.clone(), - ) - } else { - render_rust_type_with_applied_binding(n, shared_types, source_indices) + let outer_name = authored_name_at(source_indices.clone(), n.clone()); + if ((((outer_name.clone() != "".to_string()) + && (n.connective.clone() == Connective::NoConnective)) + && ((n.children.clone().len() as i64) == 0)) + && rust_fn_sig_peel_closed_alias(env, n.clone())) + { + render_rust_shared_type_if_needed( + outer_name.clone(), + outer_name.clone(), + shared_types, + ) + } else { + render_rust_type_with_applied_binding( + n.clone(), + shared_types, + corpus_repr, + source_indices.clone(), + ) + } } } else { - render_rust_type_with_applied_binding(n, shared_types, source_indices) + render_rust_type_with_applied_binding( + n.clone(), + shared_types, + corpus_repr, + source_indices.clone(), + ) } } - None => render_rust_type_with_applied_binding(n, shared_types, source_indices), + None => render_rust_type_with_applied_binding( + n.clone(), + shared_types, + corpus_repr, + source_indices.clone(), + ), } } @@ -672,6 +933,7 @@ pub fn render_rust_alias_rhs_type( n: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, scope: Rc, imports: Rc>>, @@ -689,7 +951,7 @@ pub fn render_rust_alias_rhs_type( && { let mut __found = false; for g in generic_param_names.clone().iter().cloned() { - if (g.clone().as_str() == name.clone().as_str()) { + if (g.clone() == name.clone()) { __found = true; break; } @@ -698,85 +960,140 @@ pub fn render_rust_alias_rhs_type( }) { name.clone() - } else if ((n.connective.clone() == Connective::NoConnective) - && ((n.children.clone().len() as i64) == 0)) - { - if name.clone().as_str() == "String".to_string().as_str() - && rust_emit_faithful_text_carrier(source_indices.clone()) + } else { + if ((n.connective.clone() == Connective::NoConnective) + && ((n.children.clone().len() as i64) == 0)) { - render_rust_text_carrier(shared_types.clone()) - } else if let Some(carrier) = rust_opaque_kernel_alias_carrier(name.clone()) { - carrier + match rust_seed_host_numeric_alias(name.clone(), corpus_repr.clone()) { + Some(host) => host.clone(), + None => { + if ((name.clone() == "String".to_string()) + && corpus_repr_is_faithful(corpus_repr.clone())) + { + render_rust_text_carrier(shared_types.clone()) + } else { + match rust_opaque_kernel_alias_carrier(name.clone()) { + Some(carrier) => carrier.clone(), + None => { + let rendered = rust_render_type_leaf_name( + name.clone(), + variant_to_enum.clone(), + scope.type_env.clone(), + ); + render_rust_shared_type_if_needed( + name.clone(), + rendered, + shared_types.clone(), + ) + } + } + } + } + } } else { - let rendered = rust_render_type_leaf_name( - name.clone(), - variant_to_enum.clone(), - scope.type_env.clone(), - ); - render_rust_shared_type_if_needed(name.clone(), rendered, shared_types.clone()) - } - } else if ((n.connective.clone() == Connective::NoConnective) - && ((n.children.clone().len() as i64) > 0)) - { - { - let local_mod = module_to_filename(module_name.clone()); - let def_mod = alias_rhs_rust_qualify_module_filename( - name.clone(), - module_name.clone(), - imports.clone(), - scope.clone(), - registry.clone(), - export_sets.clone(), - typed_modules.clone(), - source_indices.clone(), - module_index.clone(), - ); - let base = if (def_mod.clone().as_str() != local_mod.as_str()) { - v1_rt::concat( - v1_rt::concat( - v1_rt::concat("crate::".to_string(), def_mod.clone()), - "::".to_string(), - ), - name.clone(), - ) - } else { - name.clone() - }; - let args = Rc::new({ - let mut __result = Vec::new(); - for arg in n.children.clone().iter().cloned() { - __result.push(render_rust_alias_rhs_type( - arg.clone(), - generic_param_names.clone(), - shared_types.clone(), - source_indices.clone(), - scope.clone(), + if ((n.connective.clone() == Connective::NoConnective) + && ((n.children.clone().len() as i64) > 0)) + { + { + let local_mod = module_to_filename(module_name.clone()); + let def_mod = alias_rhs_rust_qualify_module_filename( + name.clone(), + module_name.clone(), imports.clone(), + scope.clone(), registry.clone(), - module_name.clone(), export_sets.clone(), typed_modules.clone(), + source_indices.clone(), module_index.clone(), - variant_to_enum.clone(), - )); + ); + let base = match rust_seed_host_container_base( + name.clone(), + corpus_repr.clone(), + ) { + Some(host) => host.clone(), + None => { + if (def_mod.clone() != local_mod) { + v1_rt::concat( + v1_rt::concat( + v1_rt::concat("crate::".to_string(), def_mod.clone()), + "::".to_string(), + ), + name.clone(), + ) + } else { + name.clone() + } + } + }; + let peel = is_parametric_opaque_type_base( + name.clone(), + def_mod.clone(), + typed_modules.clone(), + source_indices.clone(), + module_index.clone(), + ); + let args = Rc::new({ + let mut __result = Vec::new(); + for arg in n.children.clone().iter().cloned() { + __result.push(if peel.clone() { + render_rust_phantom_opaque_applied_type_arg( + arg.clone(), + generic_param_names.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + scope.clone(), + imports.clone(), + registry.clone(), + module_name.clone(), + export_sets.clone(), + typed_modules.clone(), + module_index.clone(), + variant_to_enum.clone(), + ) + } else { + render_rust_alias_rhs_type( + arg.clone(), + generic_param_names.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + scope.clone(), + imports.clone(), + registry.clone(), + module_name.clone(), + export_sets.clone(), + typed_modules.clone(), + module_index.clone(), + variant_to_enum.clone(), + ) + }); + } + __result + }) + .join(&", ".to_string()); + let applied_ty = v1_rt::concat( + v1_rt::concat(v1_rt::concat(base, "<".to_string()), args), + ">".to_string(), + ); + if (v1_rt::set_contains(&shared_types, name.clone()) + && !rust_type_is_rc_wrapped(applied_ty.clone())) + { + wrap_shared_type(RenderTarget::Rust, applied_ty.clone()) + } else { + applied_ty.clone() + } } - __result - }) - .join(&", ".to_string()); - let applied_ty = v1_rt::concat( - v1_rt::concat(v1_rt::concat(base, "<".to_string()), args), - ">".to_string(), - ); - if (v1_rt::set_contains(&shared_types, name.clone()) - && !rust_type_is_rc_wrapped(applied_ty.clone())) - { - wrap_shared_type(RenderTarget::Rust, applied_ty.clone()) } else { - applied_ty.clone() + render_rust_type( + n.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + ) } } - } else { - render_rust_type(n.clone(), shared_types.clone(), source_indices.clone()) } }) } @@ -903,14 +1220,14 @@ pub fn rust_nominal_identity_carrier_def(name: String) -> String { } pub fn rust_nominal_identity_carrier_type_eligible(type_name: String) -> bool { - (type_name.as_str() == "Symbol".to_string().as_str()) + (type_name == "Symbol".to_string()) } pub fn rust_nominal_identity_carrier_shape_eligible( n: Rc, source_indices: Rc>>, ) -> bool { - ((((authored_name_at(source_indices, n.clone()).as_str() == "Symbol".to_string().as_str()) + ((((authored_name_at(source_indices, n.clone()) == "Symbol".to_string()) && ((n.children.clone().len() as i64) == 0)) && ((n.params.clone().len() as i64) == 0)) && (n.connective.clone() == Connective::NoConnective)) @@ -921,8 +1238,7 @@ pub fn rust_diff_id_ord_carrier_shape_eligible( children: Rc>>, source_indices: Rc>>, ) -> bool { - if ((name.as_str() != "DiffId".to_string().as_str()) || ((children.clone().len() as i64) != 1)) - { + if ((name != "DiffId".to_string()) || ((children.clone().len() as i64) != 1)) { false } else { match children.clone().first().cloned() { @@ -956,8 +1272,8 @@ pub fn rust_nominal_ord_type_ref_eligible( (((((elem_node.children.clone().len() as i64) == 0) && ((elem_node.params.clone().len() as i64) == 0)) && (elem_node.connective.clone() == Connective::NoConnective)) - && ((type_name.clone().as_str() == "Symbol".to_string().as_str()) - || (type_name.clone().as_str() == "DiffId".to_string().as_str()))) + && ((type_name.clone() == "Symbol".to_string()) + || (type_name.clone() == "DiffId".to_string()))) } } @@ -1058,9 +1374,7 @@ pub fn field_value_by_name( match Rc::new({ let mut __result = Vec::new(); for fi in record.children.clone().iter().cloned() { - if (field_init_node_name_at(fi.clone(), source_indices.clone()).as_str() - == field_name.clone().as_str()) - { + if (field_init_node_name_at(fi.clone(), source_indices.clone()) == field_name.clone()) { __result.push(fi); } } @@ -1130,18 +1444,16 @@ pub fn rust_string_policy_for_naming( ) -> Rc { { let naming_name = authored_name_at(source_indices.clone(), naming.clone()); - if (naming_name.clone().as_str() == "AsAuthored".to_string().as_str()) { + if (naming_name.clone() == "AsAuthored".to_string()) { rust_string_as_authored_policy() } else { - if (naming_name.clone().as_str() == "SnakeCase".to_string().as_str()) { + if (naming_name.clone() == "SnakeCase".to_string()) { rust_snake_string_policy() } else { - if (naming_name.clone().as_str() == "ScreamingSnakeCase".to_string().as_str()) { + if (naming_name.clone() == "ScreamingSnakeCase".to_string()) { rust_screaming_snake_string_policy() } else { - if (naming_name.clone().as_str() - == "StripPrefixAndSnakeCase".to_string().as_str()) - { + if (naming_name.clone() == "StripPrefixAndSnakeCase".to_string()) { match required_literal_string_policy_field( naming.clone(), "prefix".to_string(), @@ -1158,9 +1470,7 @@ pub fn rust_string_policy_for_naming( ), } } else { - if (naming_name.clone().as_str() - == "StripSuffixAndSnakeCase".to_string().as_str()) - { + if (naming_name.clone() == "StripSuffixAndSnakeCase".to_string()) { match required_literal_string_policy_field( naming.clone(), "suffix".to_string(), @@ -1177,35 +1487,15 @@ pub fn rust_string_policy_for_naming( ), } } else { - if (naming_name.clone().as_str() - == "StripPrefixSuffixAndSnakeCase".to_string().as_str()) + if (naming_name.clone() == "StripPrefixSuffixAndSnakeCase".to_string()) { - match required_literal_string_policy_field( - naming.clone(), - "prefix".to_string(), - source_indices.clone(), - ) { - Some(prefix) => match required_literal_string_policy_field( - naming.clone(), - "suffix".to_string(), - source_indices.clone(), - ) { - Some(suffix) => rust_serde_policy( - "".to_string(), - Some(prefix.clone()), - Some(suffix.clone()), - Some("StripAffixAndSnakeCase".to_string()), - ), - None => rust_serde_error_policy( - "StripPrefixSuffixAndSnakeCase requires a literal suffix" - .to_string(), - ), - }, - None => rust_serde_error_policy( - "StripPrefixSuffixAndSnakeCase requires a literal prefix" - .to_string(), - ), - } + match required_literal_string_policy_field(naming.clone(), "prefix".to_string(), source_indices.clone()) { + Some(prefix) => match required_literal_string_policy_field(naming.clone(), "suffix".to_string(), source_indices.clone()) { + Some(suffix) => rust_serde_policy("".to_string(), Some(prefix.clone()), Some(suffix.clone()), Some("StripAffixAndSnakeCase".to_string())), + None => rust_serde_error_policy("StripPrefixSuffixAndSnakeCase requires a literal suffix".to_string()), +}, + None => rust_serde_error_policy("StripPrefixSuffixAndSnakeCase requires a literal prefix".to_string()), +} } else { rust_serde_error_policy(v1_rt::concat( "unsupported VariantNaming: ".to_string(), @@ -1227,7 +1517,7 @@ pub fn rust_internal_policy_for_naming( ) -> Rc { { let naming_name = authored_name_at(source_indices.clone(), naming.clone()); - if (naming_name.clone().as_str() == "AsAuthored".to_string().as_str()) { + if (naming_name.clone() == "AsAuthored".to_string()) { rust_serde_policy( v1_rt::concat( v1_rt::concat("#[serde(tag = \"".to_string(), tag_field), @@ -1238,7 +1528,7 @@ pub fn rust_internal_policy_for_naming( None, ) } else { - if (naming_name.clone().as_str() == "SnakeCase".to_string().as_str()) { + if (naming_name.clone() == "SnakeCase".to_string()) { rust_serde_policy( v1_rt::concat( v1_rt::concat("#[serde(tag = \"".to_string(), tag_field), @@ -1249,7 +1539,7 @@ pub fn rust_internal_policy_for_naming( None, ) } else { - if (naming_name.clone().as_str() == "ScreamingSnakeCase".to_string().as_str()) { + if (naming_name.clone() == "ScreamingSnakeCase".to_string()) { rust_serde_policy( v1_rt::concat( v1_rt::concat("#[serde(tag = \"".to_string(), tag_field), @@ -1260,9 +1550,7 @@ pub fn rust_internal_policy_for_naming( None, ) } else { - if (naming_name.clone().as_str() - == "StripPrefixAndSnakeCase".to_string().as_str()) - { + if (naming_name.clone() == "StripPrefixAndSnakeCase".to_string()) { match required_literal_string_policy_field( naming.clone(), "prefix".to_string(), @@ -1282,9 +1570,7 @@ pub fn rust_internal_policy_for_naming( ), } } else { - if (naming_name.clone().as_str() - == "StripSuffixAndSnakeCase".to_string().as_str()) - { + if (naming_name.clone() == "StripSuffixAndSnakeCase".to_string()) { match required_literal_string_policy_field( naming.clone(), "suffix".to_string(), @@ -1304,41 +1590,15 @@ pub fn rust_internal_policy_for_naming( ), } } else { - if (naming_name.clone().as_str() - == "StripPrefixSuffixAndSnakeCase".to_string().as_str()) + if (naming_name.clone() == "StripPrefixSuffixAndSnakeCase".to_string()) { - match required_literal_string_policy_field( - naming.clone(), - "prefix".to_string(), - source_indices.clone(), - ) { - Some(prefix) => match required_literal_string_policy_field( - naming.clone(), - "suffix".to_string(), - source_indices.clone(), - ) { - Some(suffix) => rust_serde_policy( - v1_rt::concat( - v1_rt::concat( - "#[serde(tag = \"".to_string(), - tag_field, - ), - "\")]".to_string(), - ), - Some(prefix.clone()), - Some(suffix.clone()), - Some("StripAffixAndSnakeCase".to_string()), - ), - None => rust_serde_error_policy( - "StripPrefixSuffixAndSnakeCase requires a literal suffix" - .to_string(), - ), - }, - None => rust_serde_error_policy( - "StripPrefixSuffixAndSnakeCase requires a literal prefix" - .to_string(), - ), - } + match required_literal_string_policy_field(naming.clone(), "prefix".to_string(), source_indices.clone()) { + Some(prefix) => match required_literal_string_policy_field(naming.clone(), "suffix".to_string(), source_indices.clone()) { + Some(suffix) => rust_serde_policy(v1_rt::concat(v1_rt::concat("#[serde(tag = \"".to_string(), tag_field), "\")]".to_string()), Some(prefix.clone()), Some(suffix.clone()), Some("StripAffixAndSnakeCase".to_string())), + None => rust_serde_error_policy("StripPrefixSuffixAndSnakeCase requires a literal suffix".to_string()), +}, + None => rust_serde_error_policy("StripPrefixSuffixAndSnakeCase requires a literal prefix".to_string()), +} } else { rust_serde_error_policy(v1_rt::concat( "unsupported VariantNaming: ".to_string(), @@ -1384,10 +1644,10 @@ pub fn resolve_wire_serde_policy_from_encoding_node( ) -> Rc { { let encoding_name = authored_name_at(source_indices.clone(), ve.clone()); - if (encoding_name.clone().as_str() == "InternallyTaggedObject".to_string().as_str()) { + if (encoding_name.clone() == "InternallyTaggedObject".to_string()) { rust_internal_policy_for_encoding(ve.clone(), source_indices.clone()) } else { - if (encoding_name.clone().as_str() == "StringVariant".to_string().as_str()) { + if (encoding_name.clone() == "StringVariant".to_string()) { match naming_policy_node(ve.clone(), source_indices.clone()) { Some(nv) => rust_string_policy_for_naming(nv.clone(), source_indices.clone()), None => rust_serde_error_policy( @@ -1395,10 +1655,10 @@ pub fn resolve_wire_serde_policy_from_encoding_node( ), } } else { - if (encoding_name.clone().as_str() == "UntaggedVariant".to_string().as_str()) { + if (encoding_name.clone() == "UntaggedVariant".to_string()) { rust_untagged_policy() } else { - if (encoding_name.clone().as_str() == "TaggedVariant".to_string().as_str()) { + if (encoding_name.clone() == "TaggedVariant".to_string()) { rust_tagged_object_policy() } else { rust_serde_error_policy(v1_rt::concat( @@ -1428,8 +1688,7 @@ pub fn resolve_wire_serde_policy( } pub fn item_binding_is_named(env: Rc, node: Rc, name: String) -> bool { - ((authored_name(env, node.clone()).as_str() == name.clone().as_str()) - || (node.name.clone().as_str() == name.clone().as_str())) + ((authored_name(env, node.clone()) == name.clone()) || (node.name.clone() == name.clone())) } pub fn resolve_wire_serde_policy_for_coproduct( @@ -1622,7 +1881,7 @@ pub fn variant_encoding_is_string_variant( encoding: Rc, source_indices: Rc>>, ) -> bool { - (authored_name_at(source_indices, encoding).as_str() == "StringVariant".to_string().as_str()) + (authored_name_at(source_indices, encoding) == "StringVariant".to_string()) } pub fn coproduct_wire_contract_targets( @@ -1633,7 +1892,7 @@ pub fn coproduct_wire_contract_targets( match contract_item.body.clone() { Some(body) => { match record_string_field(body.clone(), "coproduct".to_string(), source_indices) { - Some(target_name) => (target_name.clone().as_str() == coproduct_name.as_str()), + Some(target_name) => (target_name.clone() == coproduct_name), None => false, } } @@ -1662,15 +1921,15 @@ pub fn module_imports_std_serialization_coproduct_wire_contract( { let mut __found = false; for imp in imports.iter().cloned() { - if ((authored_name_at(source_indices.clone(), imp.clone()).as_str() - == "std.serialization".to_string().as_str()) + if ((authored_name_at(source_indices.clone(), imp.clone()) + == "std.serialization".to_string()) && (import_is_all(imp.clone()) || { let mut __found = false; for name in import_specific_names_at(imp.clone(), source_indices.clone()) .iter() .cloned() { - if (name.clone().as_str() == "CoproductWireContract".to_string().as_str()) { + if (name.clone() == "CoproductWireContract".to_string()) { __found = true; break; } @@ -1693,8 +1952,8 @@ pub fn data_item_type_is_coproduct_wire_contract( ) -> bool { match item.type_annotation.clone() { Some(type_node) => { - ((authored_name_at(source_indices.clone(), type_node.clone()).as_str() - == "CoproductWireContract".to_string().as_str()) + ((authored_name_at(source_indices.clone(), type_node.clone()) + == "CoproductWireContract".to_string()) && module_imports_std_serialization_coproduct_wire_contract( imports, source_indices.clone(), @@ -1714,8 +1973,8 @@ pub fn module_defines_local_coproduct_wire_contract_type( if (((is_type_def_item(item.clone()) || is_type_alias_item(item.clone(), source_indices.clone())) || is_type_decl_item(item.clone(), source_indices.clone())) - && (authored_name_at(source_indices.clone(), item.clone()).as_str() - == "CoproductWireContract".to_string().as_str())) + && (authored_name_at(source_indices.clone(), item.clone()) + == "CoproductWireContract".to_string())) { __found = true; break; @@ -1776,7 +2035,7 @@ pub fn emit_coproduct_wire_contract_target_validation( if { let mut __found = false; for name in local_coproduct_names.iter().cloned() { - if (name.clone().as_str() == target_name.clone().as_str()) { + if (name.clone() == target_name.clone()) { __found = true; break; } @@ -1841,7 +2100,7 @@ pub fn emit_coproduct_wire_contract_validations( .iter() .cloned() { - if (text.clone().as_str() != "".to_string().as_str()) { + if (text.clone() != "".to_string()) { __result.push(text); } } @@ -2198,19 +2457,166 @@ pub fn emit_rust_init_block_stmts( }; let next_scope = scope_after_expr(stmt.clone(), scope.clone()); { - let __tco_0 = rest.clone(); - let __tco_1 = v1_rt::rc_list_push(text, line); - let __tco_2 = next_scope; - remaining = __tco_0; - text = __tco_1; - scope = __tco_2; - continue; + let __tco_0 = rest.clone(); + let __tco_1 = v1_rt::rc_list_push(text, line); + let __tco_2 = next_scope; + remaining = __tco_0; + text = __tco_1; + scope = __tco_2; + continue; + } + } + } + } + } + } +} + +pub fn rust_qualify_type_leaf_name( + name: String, + variant_to_enum: Rc>, +) -> String { + match v1_rt::map_get(&variant_to_enum, name.clone()) { + Some(parent) => { + if (parent.clone() != "".to_string()) { + v1_rt::concat( + v1_rt::concat(parent.clone(), "::".to_string()), + name.clone(), + ) + } else { + name.clone() + } + } + None => name.clone(), + } +} + +pub fn rust_render_type_leaf_name( + name: String, + variant_to_enum: Rc>, + env: Rc, +) -> String { + if is_phantom_unit_variant_type_arg(env, name.clone()) { + name.clone() + } else { + match rust_opaque_kernel_alias_carrier(name.clone()) { + Some(carrier) => carrier.clone(), + None => rust_qualify_type_leaf_name(name.clone(), variant_to_enum), + } + } +} + +pub fn rust_phantom_zst_marker_def(vname: String) -> String { + v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]\n".to_string(), rust_visibility_prefix()), rust_items().struct_keyword.clone()), " ".to_string()), vname), ";".to_string()) +} + +pub fn emit_phantom_zst_markers_for_enum(children: Rc>>, env: Rc) -> String { + { + let markers = Rc::new({ + let mut __result = Vec::new(); + for child in Rc::new({ + let mut __result = Vec::new(); + for child in Rc::new({ + let mut __result = Vec::new(); + for child in children.iter().cloned() { + if ((child.children.clone().len() as i64) == 0) { + __result.push(child); + } + } + __result + }) + .iter() + .cloned() + { + if is_phantom_unit_variant_type_arg( + env.clone(), + authored_name(env.clone(), child.clone()), + ) { + __result.push(child); + } + } + __result + }) + .iter() + .cloned() + { + __result.push({ + let vname = authored_name(env.clone(), child.clone()); + rust_phantom_zst_marker_def(vname.clone()) + }); + } + __result + }) + .join(&"\n".to_string()); + markers + } +} + +pub fn collect_phantom_zst_marker_names( + items: Rc>>, + env: Rc, +) -> Rc> { + Rc::new({ + let mut __result = Vec::new(); + for item in items.iter().cloned() { + if (is_type_def_item(item.clone()) && { + let mut __all = true; + for c in item.children.clone().iter().cloned() { + if !((c.children.clone().len() as i64) == 0) { + __all = false; + break; + } + } + __all + }) { + __result.push(item); + } + } + __result + }) + .iter() + .cloned() + .fold(Rc::new(vec![]), |acc: Rc>, item: Rc| { + item.children.clone().iter().cloned().fold( + acc, + |inner: Rc>, child: Rc| { + if ((child.children.clone().len() as i64) == 0) { + { + let vname = authored_name(env.clone(), child.clone()); + if (is_phantom_unit_variant_type_arg(env.clone(), vname.clone()) + && !{ + let mut __found = false; + for n in inner.clone().iter().cloned() { + if (n.clone() == vname.clone()) { + __found = true; + break; + } + } + __found + }) + { + v1_rt::concat(inner.clone(), Rc::new(vec![vname.clone()])) + } else { + inner.clone() } } + } else { + inner.clone() } - } + }, + ) + }) +} + +pub fn emit_module_phantom_zst_markers(items: Rc>>, env: Rc) -> String { + Rc::new({ + let mut __result = Vec::new(); + for vname in collect_phantom_zst_marker_names(items, env).iter().cloned() { + __result.push(rust_phantom_zst_marker_def(vname.clone())); } - } + __result + }) + .join(&"\n".to_string()) } pub fn has_complex_variants(item: Rc) -> bool { @@ -2352,9 +2758,8 @@ pub fn build_shared_types( .iter() .cloned() { - if ((sharing.needs_sharing.clone() - && (k.clone().as_str() != "optional".to_string().as_str())) - && (k.clone().as_str() != "boolean_algebra".to_string().as_str())) + if ((sharing.needs_sharing.clone() && (k.clone() != "optional".to_string())) + && (k.clone() != "boolean_algebra".to_string())) { __result.push(k); } @@ -2532,6 +2937,7 @@ pub fn emit_rust(typed: Rc) -> Rc { owned_bindings: v1_rt::rc_empty_set::(), read_only_params_index: ownership.read_only_params_index.clone(), read_only_params: v1_rt::rc_empty_set::(), + corpus_repr: base_info.corpus_repr.clone(), }); let shared_types = emit_info.shared_types.clone(); let registry = typed.item_registry.clone(); @@ -2612,18 +3018,18 @@ pub fn emit_rust(typed: Rc) -> Rc { Rc::new({ let mut __result = Vec::new(); for p in test_projections.clone().iter().cloned() { - if (p.module_name.clone().as_str() + if (p.module_name.clone() == authored_name_at( tm.type_env.clone().source_indices.clone(), tm.module.clone(), - ) - .as_str()) + )) { __result.push(p); } } __result }), + emit_info.corpus_repr.clone(), )); } __result @@ -2631,7 +3037,7 @@ pub fn emit_rust(typed: Rc) -> Rc { .iter() .cloned() { - if (f.path.clone().as_str() != "".to_string().as_str()) { + if (f.path.clone() != "".to_string()) { __result.push(f); } } @@ -2642,8 +3048,7 @@ pub fn emit_rust(typed: Rc) -> Rc { let mut __found = false; for m in typed.modules.clone().iter().cloned() { if (authored_name_at(m.type_env.clone().source_indices.clone(), m.module.clone()) - .as_str() - == "v1.compiler.compile".to_string().as_str()) + == "v1.compiler.compile".to_string()) { __found = true; break; @@ -2762,7 +3167,7 @@ pub fn emit_lib_rs_from_files( "".to_string() }; let shared_types = emit_non_empty_wrappers(); - let content = v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("// Generated by v1 compiler -- do not edit.\n\n".to_string(), "#![allow(unused_imports, unused_variables, unused_mut, unused_parens, dead_code, unreachable_patterns, non_shorthand_field_patterns, suspicious_double_ref_op, clippy::all)]\n\n".to_string()), mod_decls.join(&"\n".to_string())), hand_maintained_mods), "\n\n".to_string()), shared_types), test_mod); + let content = v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("// Generated by v1 compiler -- do not edit.\n\n".to_string(), "#![allow(unused_imports, unused_variables, unused_mut, unused_parens, dead_code, unreachable_patterns, non_shorthand_field_patterns, suspicious_double_ref_op, clippy::all)]\n".to_string()), "#![recursion_limit = \"256\"]\n\n".to_string()), mod_decls.join(&"\n".to_string())), hand_maintained_mods), "\n\n".to_string()), shared_types), test_mod); Rc::new(TextFile { path: v1_rt::concat( v1_rt::concat(rust_source_root(), "lib".to_string()), @@ -2796,6 +3201,7 @@ pub fn emit_module( owned_bindings: v1_rt::rc_empty_set::(), read_only_params_index: base_info.read_only_params_index.clone(), read_only_params: v1_rt::rc_empty_set::(), + corpus_repr: base_info.corpus_repr.clone(), }); let shared_types = emit_info.shared_types.clone(); let export_sets = build_module_export_sets(Rc::new(vec![typed_module.clone()])); @@ -2892,7 +3298,7 @@ pub fn emit_module_full( scope.type_env.clone().source_indices.clone(), module_index.clone(), ); - let imports_section = if (imports_str.clone().as_str() == "".to_string().as_str()) { + let imports_section = if (imports_str.clone() == "".to_string()) { "".to_string() } else { v1_rt::concat("\n".to_string(), imports_str.clone()) @@ -2922,7 +3328,7 @@ pub fn emit_module_full( __result.extend( (*match v1_rt::map_get(&svc_module_map, sn.clone()) { Some(mod_file) => { - if (mod_file.clone().as_str() == this_mod_filename.clone().as_str()) { + if (mod_file.clone() == this_mod_filename.clone()) { Rc::new(vec![]) } else { Rc::new(vec![v1_rt::concat( @@ -3009,7 +3415,7 @@ pub fn emit_module_full( scope.type_env.clone().source_indices.clone(), ); let coproduct_wire_contract_validation_section = - if (coproduct_wire_contract_validations.clone().as_str() == "".to_string().as_str()) { + if (coproduct_wire_contract_validations.clone() == "".to_string()) { "".to_string() } else { v1_rt::concat( @@ -3070,19 +3476,19 @@ pub fn emit_module_full( .join(&"\n\n".to_string()); let phantom_zst_markers = emit_module_phantom_zst_markers(typed_module.items.clone(), scope.type_env.clone()); - let phantom_section = if phantom_zst_markers.as_str() == "" { + let phantom_section = if (phantom_zst_markers.clone() == "".to_string()) { "".to_string() } else { - v1_rt::concat("\n\n".to_string(), phantom_zst_markers) + v1_rt::concat("\n\n".to_string(), phantom_zst_markers.clone()) }; let raw_filename = module_to_filename(authored_name(scope.type_env.clone(), m.clone())); - let filename = if (raw_filename.clone().as_str() == "main".to_string().as_str()) { + let filename = if (raw_filename.clone() == "main".to_string()) { "main_mod".to_string() } else { raw_filename.clone() }; - let module_attrs = if (authored_name(scope.type_env.clone(), m.clone()).as_str() - == "std.error_primitives".to_string().as_str()) + let module_attrs = if (authored_name(scope.type_env.clone(), m.clone()) + == "std.error_primitives".to_string()) { "#![allow(non_camel_case_types)]\n\n".to_string() } else { @@ -3284,10 +3690,10 @@ pub fn has_physical_type_def_in_module_filename( if { let mut __found = false; for item in tm.items.clone().iter().cloned() { - if ((authored_name_at(source_indices.clone(), item.clone()).as_str() - == rhs_name.clone().as_str()) - && (is_type_def_item(item.clone()) - || is_type_alias_item(item.clone(), source_indices.clone()) + if ((authored_name_at(source_indices.clone(), item.clone()) + == rhs_name.clone()) + && ((is_type_def_item(item.clone()) + || is_type_alias_item(item.clone(), source_indices.clone())) || is_type_decl_item(item.clone(), source_indices.clone()))) { __found = true; @@ -3339,8 +3745,8 @@ pub fn find_variant_parent_in_module( if { let mut __found = false; for child in item.children.clone().iter().cloned() { - if (authored_name_at(source_indices.clone(), child.clone()).as_str() - == variant_name.clone().as_str()) + if (authored_name_at(source_indices.clone(), child.clone()) + == variant_name.clone()) { __found = true; break; @@ -3382,8 +3788,7 @@ pub fn type_name_is_export_source_in_module( Some(tm) => { let mut __found = false; for item in tm.items.clone().iter().cloned() { - if ((authored_name_at(source_indices.clone(), item.clone()).as_str() - == name.clone().as_str()) + if ((authored_name_at(source_indices.clone(), item.clone()) == name.clone()) && ((is_type_def_item(item.clone()) || is_type_alias_item(item.clone(), source_indices.clone())) || is_type_decl_item(item.clone(), source_indices.clone()))) @@ -3416,8 +3821,7 @@ pub fn type_name_is_rust_importable_in_module( Some(tm) => match Rc::new({ let mut __result = Vec::new(); for item in tm.items.clone().iter().cloned() { - if ((authored_name_at(source_indices.clone(), item.clone()).as_str() - == name.clone().as_str()) + if ((authored_name_at(source_indices.clone(), item.clone()) == name.clone()) && ((is_type_def_item(item.clone()) || is_type_alias_item(item.clone(), source_indices.clone())) || is_type_decl_item(item.clone(), source_indices.clone()))) @@ -3499,7 +3903,7 @@ pub fn name_in_transitive_export_surface( if { let mut __found = false; for v in visited.clone().iter().cloned() { - if (v.clone().as_str() == module_name.clone().as_str()) { + if (v.clone() == module_name.clone()) { __found = true; break; } @@ -3594,7 +3998,7 @@ pub fn reexport_source_module_name_with_visited( if { let mut __found = false; for v in visited.clone().iter().cloned() { - if (v.clone().as_str() == import_module.clone().as_str()) { + if (v.clone() == import_module.clone()) { __found = true; break; } @@ -3648,8 +4052,7 @@ pub fn reexport_source_module_name_with_visited( .iter() .cloned() { - if (n.clone().as_str() == name.clone().as_str()) - { + if (n.clone() == name.clone()) { __found = true; break; } @@ -3823,7 +4226,7 @@ pub fn import_module_enum_scope( .iter() .cloned() { - if (p.clone().as_str() != "".to_string().as_str()) { + if (p.clone() != "".to_string()) { __result.push(p); } } @@ -3898,8 +4301,7 @@ pub fn enum_physically_defined_in_module( Some(tm) => { let mut __found = false; for item in tm.items.clone().iter().cloned() { - if (((authored_name_at(source_indices.clone(), item.clone()).as_str() - == enum_name.clone().as_str()) + if (((authored_name_at(source_indices.clone(), item.clone()) == enum_name.clone()) && is_type_def_item(item.clone())) && is_coproduct_type(item.clone())) { @@ -3924,7 +4326,7 @@ pub fn wildcard_import_pool_surface_names( if { let mut __found = false; for v in visited.clone().iter().cloned() { - if (v.clone().as_str() == module_name.clone().as_str()) { + if (v.clone() == module_name.clone()) { __found = true; break; } @@ -4021,7 +4423,7 @@ pub fn wildcard_reexport_surface_names( source_indices.clone(), module_index.clone(), ) { - Some(src) => (src.clone().as_str() != import_module.clone().as_str()), + Some(src) => (src.clone() != import_module.clone()), None => false, } { __result.push(n); @@ -4094,7 +4496,7 @@ pub fn variant_defining_module_filename_for_import( module_index.clone(), ) { Some(hop) => { - if (hop.clone().as_str() != import_module.clone().as_str()) { + if (hop.clone() != import_module.clone()) { { let __tco_0 = hop.clone(); import_module = __tco_0; @@ -4132,7 +4534,7 @@ pub fn variant_parent_defining_module_filename( module_index.clone(), ) { Some(local_parent) => { - if (local_parent.clone().as_str() == parent_enum.clone().as_str()) { + if (local_parent.clone() == parent_enum.clone()) { module_to_filename(import_module.clone()) } else { variant_defining_module_filename_for_import( @@ -4184,7 +4586,7 @@ pub fn explicit_import_source_module_for_name( .iter() .cloned() { - if (n.clone().as_str() == name.clone().as_str()) { + if (n.clone() == name.clone()) { __found = true; break; } @@ -4297,7 +4699,7 @@ pub fn reexport_variant_parent_in_import_module( module_index.clone(), ) { Some(hop) => { - if (hop.clone().as_str() != src_mod.clone().as_str()) { + if (hop.clone() != src_mod.clone()) { { let __tco_0 = hop.clone(); import_module = __tco_0; @@ -4388,7 +4790,7 @@ pub fn alias_rhs_base_module_filename( let local_mod = module_to_filename(alias_module.clone()); match lookup_item(scope.item_registry.clone(), name.clone()) { Some(info) => { - if ((info.module_name.clone().as_str() == alias_module.clone().as_str()) + if ((info.module_name.clone() == alias_module.clone()) && ((info.kind.clone() == ItemKind::TypeItem) || (info.kind.clone() == ItemKind::OtherItem))) { @@ -4441,7 +4843,7 @@ pub fn alias_rhs_base_module_from_import_or_registry( .iter() .cloned() { - if (n.clone().as_str() == name.clone().as_str()) { + if (n.clone() == name.clone()) { __found = true; break; } @@ -4548,8 +4950,8 @@ pub fn type_item_by_name_in_module_filename( Some(tm) => Rc::new({ let mut __result = Vec::new(); for item in tm.items.clone().iter().cloned() { - if ((authored_name_at(source_indices.clone(), item.clone()).as_str() - == rhs_name.clone().as_str()) + if ((authored_name_at(source_indices.clone(), item.clone()) + == rhs_name.clone()) && ((is_type_def_item(item.clone()) || is_type_alias_item(item.clone(), source_indices.clone())) || is_type_decl_item(item.clone(), source_indices.clone()))) @@ -4596,28 +4998,12 @@ pub fn type_item_has_rust_nominal_shell_authority( { true } else { - let rhs = resolved_type(item.clone()); - if is_type_alias_return_node(rhs.clone(), source_indices.clone()) - && ((rhs.children.clone().len() as i64) > 0) - { - alias_rhs_nominal_shell_has_rust_authority( - rhs.clone(), - module_name, - imports, - scope, - registry, - export_sets, - typed_modules, - source_indices.clone(), - module_index, - ) - } else if is_type_alias_return_node(rhs.clone(), source_indices.clone()) { - let rhs_name = - authored_name_at(source_indices.clone(), rhs.clone()); - (rhs_name.as_str() != item_text.as_str()) - && rhs_name.as_str() != "" - && alias_rhs_nominal_shell_has_rust_authority( + let rhs = resolved_type(item.clone()); + if (is_type_alias_return_node(rhs.clone(), source_indices.clone()) + && ((rhs.children.clone().len() as i64) > 0)) + { + alias_rhs_nominal_shell_has_rust_authority( rhs.clone(), module_name, imports, @@ -4628,8 +5014,34 @@ pub fn type_item_has_rust_nominal_shell_authority( source_indices.clone(), module_index, ) - } else { - false + } else { + if is_type_alias_return_node( + rhs.clone(), + source_indices.clone(), + ) { + { + let rhs_name = authored_name_at( + source_indices.clone(), + rhs.clone(), + ); + (((rhs_name.clone() != item_text.clone()) + && (rhs_name.clone() != "".to_string())) + && alias_rhs_nominal_shell_has_rust_authority( + rhs.clone(), + module_name, + imports, + scope, + registry, + export_sets, + typed_modules, + source_indices.clone(), + module_index, + )) + } + } else { + false + } + } } } } else { @@ -4827,9 +5239,7 @@ pub fn alias_rhs_nominal_shell_has_rust_authority( } else { { let name = authored_name_at(source_indices.clone(), n.clone()); - if ((name.clone().as_str() == "".to_string().as_str()) - || is_kernel_type(name.clone())) - { + if ((name.clone() == "".to_string()) || is_kernel_type(name.clone())) { true } else { if is_phantom_unit_variant_type_arg( @@ -4878,91 +5288,100 @@ pub fn is_self_referential_opaque_type_resolved( item: Rc, source_indices: Rc>>, ) -> bool { - let item_text = authored_name_at(source_indices.clone(), item.clone()); - let rhs = resolved_type(item.clone()); - is_type_alias_return_node(rhs.clone(), source_indices.clone()) - && authored_name_at(source_indices.clone(), rhs) == item_text + { + let item_text = authored_name_at(source_indices.clone(), item.clone()); + let rhs = resolved_type(item.clone()); + (is_type_alias_return_node(rhs.clone(), source_indices.clone()) + && (authored_name_at(source_indices.clone(), rhs.clone()) == item_text)) + } } pub fn is_zero_param_self_referential_opaque_decl( item: Rc, source_indices: Rc>>, ) -> bool { - is_bare_leaf_item(item.clone()) - && is_self_referential_opaque_type_resolved(item.clone(), source_indices) + (is_bare_leaf_item(item.clone()) + && is_self_referential_opaque_type_resolved(item.clone(), source_indices)) } pub fn is_parametric_opaque_type_decl_item( item: Rc, source_indices: Rc>>, ) -> bool { - ((item.params.clone().len() as i64) > 0) - && item.body.is_none() - && item.transport.is_none() - && (item.children.clone().len() as i64) == 0 + ((((((item.params.clone().len() as i64) > 0) && (item.body.clone() == None)) + && (item.transport.clone() == None)) + && ((item.children.clone().len() as i64) == 0)) && (!is_type_alias_return_node(resolved_type(item.clone()), source_indices.clone()) - || is_self_referential_opaque_type_resolved(item.clone(), source_indices)) + || is_self_referential_opaque_type_resolved(item.clone(), source_indices.clone()))) } pub fn emit_zero_param_phantom_opaque_struct( item: Rc, source_indices: Rc>>, ) -> String { - let item_text = authored_name_at(source_indices.clone(), item.clone()); - v1_rt::concat( + { + let item_text = authored_name_at(source_indices, item); v1_rt::concat( v1_rt::concat( v1_rt::concat( v1_rt::concat( - "#[derive(Debug, Clone, Copy, PartialEq, Eq)]\n".to_string(), - rust_visibility_prefix(), + v1_rt::concat( + "#[derive(Debug, Clone, Copy, PartialEq, Eq)]\n".to_string(), + rust_visibility_prefix(), + ), + rust_items().struct_keyword.clone(), ), - rust_items().struct_keyword.clone(), - ), - v1_rt::concat( - v1_rt::concat(" ".to_string(), item_text), - "(pub std::marker::PhantomData<()>);".to_string(), + " ".to_string(), ), + item_text, ), - "".to_string(), - ), - "".to_string(), - ) + "(pub std::marker::PhantomData<()>);".to_string(), + ) + } } pub fn emit_parametric_phantom_opaque_struct( item: Rc, source_indices: Rc>>, ) -> String { - let item_text = authored_name_at(source_indices.clone(), item.clone()); - let type_params = emit_type_params(item.params.clone(), source_indices.clone()); - let generic_names = item_generic_param_names(item.clone(), source_indices.clone()); - let marker_ty = match generic_names.first().cloned() { - Some(g) => v1_rt::concat( - v1_rt::concat("std::marker::PhantomData<".to_string(), g), - ">".to_string(), - ), - None => "std::marker::PhantomData<()>".to_string(), - }; - v1_rt::concat( + { + let item_text = authored_name_at(source_indices.clone(), item.clone()); + let type_params = emit_type_params(item.params.clone(), source_indices.clone()); + let generic_names = item_generic_param_names(item.clone(), source_indices.clone()); + let marker_ty = match generic_names.first().cloned() { + Some(g) => v1_rt::concat( + v1_rt::concat("std::marker::PhantomData<".to_string(), g.clone()), + ">".to_string(), + ), + None => "std::marker::PhantomData<()>".to_string(), + }; v1_rt::concat( v1_rt::concat( v1_rt::concat( v1_rt::concat( - "#[derive(Debug, Clone, Copy, PartialEq, Eq)]\n".to_string(), - rust_visibility_prefix(), + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + "#[derive(Debug, Clone, Copy, PartialEq, Eq)]\n" + .to_string(), + rust_visibility_prefix(), + ), + rust_items().struct_keyword.clone(), + ), + " ".to_string(), + ), + item_text, + ), + type_params, ), - rust_items().struct_keyword.clone(), + "(pub ".to_string(), ), - v1_rt::concat(v1_rt::concat(" ".to_string(), item_text), type_params), - ), - v1_rt::concat( - v1_rt::concat("(pub ".to_string(), marker_ty), - ");".to_string(), + marker_ty, ), - ), - "".to_string(), - ) + ");".to_string(), + ) + } } pub fn is_emittable_parametric_type_alias_item( @@ -4992,37 +5411,21 @@ pub fn is_emittable_parametric_type_alias_item( } else { { let rhs_name = authored_name_at(source_indices.clone(), rhs.clone()); - if rhs_name.as_str() != item_text.as_str() { - if (rhs.children.clone().len() as i64) > 0 { - alias_rhs_nominal_shell_has_rust_authority( - rhs.clone(), - module_name, - imports, - scope, - registry, - export_sets, - typed_modules, - source_indices.clone(), - module_index, - ) - } else if rhs_name.as_str() != "" { - alias_rhs_nominal_shell_has_rust_authority( - rhs.clone(), - module_name, - imports, - scope, - registry, - export_sets, - typed_modules, - source_indices.clone(), - module_index, - ) - } else { - false - } - } else { - false - } + ((rhs_name.clone() != item_text) + && (((rhs.children.clone().len() as i64) > 0) + || ((((rhs.children.clone().len() as i64) == 0) + && (rhs_name.clone() != "".to_string())) + && alias_rhs_nominal_shell_has_rust_authority( + rhs.clone(), + module_name, + imports, + scope, + registry, + export_sets, + typed_modules, + source_indices.clone(), + module_index, + )))) } } } @@ -5050,7 +5453,7 @@ pub fn emit_specific_import_block( if { let mut __all = true; for ln in local_names.clone().iter().cloned() { - if !(ln.clone().as_str() != n.clone().as_str()) { + if !(ln.clone() != n.clone()) { __all = false; break; } @@ -5192,7 +5595,7 @@ pub fn emit_specific_import_block( .iter() .cloned() { - if (p.clone().as_str() != "".to_string().as_str()) { + if (p.clone() != "".to_string()) { __result.push(p); } } @@ -5226,7 +5629,7 @@ pub fn emit_specific_import_block( source_indices.clone(), module_index.clone(), ) { - Some(found) => (found.clone().as_str() == p.clone().as_str()), + Some(found) => (found.clone() == p.clone()), None => false, } { __found = true; @@ -5248,7 +5651,7 @@ pub fn emit_specific_import_block( if { let mut __all = true; for n in direct_names.clone().iter().cloned() { - if !(n.clone().as_str() != p.clone().as_str()) { + if !(n.clone() != p.clone()) { __all = false; break; } @@ -5273,7 +5676,7 @@ pub fn emit_specific_import_block( source_indices.clone(), module_index.clone(), ) { - Some(found) => (found.clone().as_str() == p.clone().as_str()), + Some(found) => (found.clone() == p.clone()), None => false, } { __found = true; @@ -5357,9 +5760,7 @@ pub fn emit_specific_import_block( export_sets.clone(), source_indices.clone(), module_index.clone(), - ) - .as_str() - == def_mod.clone().as_str()) + ) == def_mod.clone()) { __result.push(n); } @@ -5437,13 +5838,13 @@ pub fn emit_specific_import_block( Rc::new({ let mut __result = Vec::new(); for l in type_direct_lines.iter().cloned() { - if (l.clone().as_str() != "".to_string().as_str()) { + if (l.clone() != "".to_string()) { __result.push(l); } } __result }), - if (other_direct_line.clone().as_str() != "".to_string().as_str()) { + if (other_direct_line.clone() != "".to_string()) { Rc::new(vec![other_direct_line.clone()]) } else { Rc::new(vec![]) @@ -5463,9 +5864,7 @@ pub fn emit_specific_import_block( source_indices.clone(), module_index.clone(), ) { - Some(found) => { - (found.clone().as_str() == p.clone().as_str()) - } + Some(found) => (found.clone() == p.clone()), None => match reexport_variant_parent_in_import_module( n.clone(), import_module.clone(), @@ -5476,9 +5875,7 @@ pub fn emit_specific_import_block( source_indices.clone(), module_index.clone(), ) { - Some(found) => { - (found.clone().as_str() == p.clone().as_str()) - } + Some(found) => (found.clone() == p.clone()), None => false, }, } { @@ -5517,15 +5914,15 @@ pub fn emit_specific_import_block( __result.push({ let group = Rc::new({ let mut __result = Vec::new(); for p in remote_parent_list.clone().iter().cloned() { if { let rep_variant = Rc::new({ let mut __result = Vec::new(); for n in deduped_names.clone().iter().cloned() { if match find_variant_parent_in_module(n.clone(), import_module.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone()) { - Some(found) => (found.clone().as_str() == p.clone().as_str()), + Some(found) => (found.clone() == p.clone()), None => match reexport_variant_parent_in_import_module(n.clone(), import_module.clone(), registry.clone(), type_summaries.clone(), typed_modules.clone(), export_sets.clone(), source_indices.clone(), module_index.clone()) { - Some(found) => (found.clone().as_str() == p.clone().as_str()), + Some(found) => (found.clone() == p.clone()), None => false, }, } { __result.push(n); } } __result }).first().cloned(); match rep_variant.clone() { - Some(v) => (variant_parent_defining_module_filename(p.clone(), v.clone(), import_module.clone(), typed_modules.clone(), export_sets.clone(), source_indices.clone(), registry.clone(), mod_name.clone(), module_index.clone()).as_str() == def_mod.clone().as_str()), - None => (item_defining_module_filename(p.clone(), registry.clone(), mod_name.clone()).as_str() == def_mod.clone().as_str()), + Some(v) => (variant_parent_defining_module_filename(p.clone(), v.clone(), import_module.clone(), typed_modules.clone(), export_sets.clone(), source_indices.clone(), registry.clone(), mod_name.clone(), module_index.clone()) == def_mod.clone()), + None => (item_defining_module_filename(p.clone(), registry.clone(), mod_name.clone()) == def_mod.clone()), } } { __result.push(p); } } __result }); if ((group.clone().len() as i64) > 0) { @@ -5546,7 +5943,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_visib Rc::new({ let mut __result = Vec::new(); for l in parent_main_lines.iter().cloned() { - if (l.clone().as_str() != "".to_string().as_str()) { + if (l.clone() != "".to_string()) { __result.push(l); } } @@ -5557,7 +5954,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_visib Rc::new({ let mut __result = Vec::new(); for l in parent_main_lines.iter().cloned() { - if (l.clone().as_str() != "".to_string().as_str()) { + if (l.clone() != "".to_string()) { __result.push(l); } } @@ -5593,10 +5990,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_visib source_indices.clone(), module_index.clone(), ) { - Some(found) => { - (found.clone().as_str() - == parent.clone().as_str()) - } + Some(found) => (found.clone() == parent.clone()), None => { match reexport_variant_parent_in_import_module( n.clone(), @@ -5609,8 +6003,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_visib module_index.clone(), ) { Some(found) => { - (found.clone().as_str() - == parent.clone().as_str()) + (found.clone() == parent.clone()) } None => match find_variant_parent( type_summaries.clone(), @@ -5689,7 +6082,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_visib if ({ let mut __found = false; for p in parent_list.clone().iter().cloned() { - if (p.clone().as_str() == en.clone().as_str()) { + if (p.clone() == en.clone()) { __found = true; break; } @@ -5723,7 +6116,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_visib Rc::new({ let mut __result = Vec::new(); for l in main_lines.iter().cloned() { - if (l.clone().as_str() != "".to_string().as_str()) { + if (l.clone() != "".to_string()) { __result.push(l); } } @@ -5732,7 +6125,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_visib Rc::new({ let mut __result = Vec::new(); for l in variant_lines.iter().cloned() { - if (l.clone().as_str() != "".to_string().as_str()) { + if (l.clone() != "".to_string()) { __result.push(l); } } @@ -5856,7 +6249,7 @@ pub fn rust_pub_use_braced_names(line: String) -> Rc> { } pub fn rust_pub_use_braced_line_has_name(line: String, mod_name: String, name: String) -> bool { - (((rust_pub_use_module_name(line.clone()).as_str() == mod_name.as_str()) + (((rust_pub_use_module_name(line.clone()) == mod_name) && v1_rt::contains(line.clone(), "::{".to_string())) && (((v1_rt::contains( line.clone(), @@ -5889,9 +6282,7 @@ pub fn rust_pub_use_singleton_covered(line: String, lines: Rc>) -> b { let mod_name = rust_pub_use_module_name(line.clone()); let name = rust_pub_use_singleton_name(line.clone()); - if ((mod_name.clone().as_str() == "".to_string().as_str()) - || (name.clone().as_str() == "".to_string().as_str())) - { + if ((mod_name.clone() == "".to_string()) || (name.clone() == "".to_string())) { false } else { { @@ -5916,17 +6307,14 @@ pub fn rust_pub_use_braced_subset_covered(line: String, lines: Rc>) { let mod_name = rust_pub_use_module_name(line.clone()); let names = rust_pub_use_braced_names(line.clone()); - if ((mod_name.clone().as_str() == "".to_string().as_str()) - || ((names.clone().len() as i64) == 0)) - { + if ((mod_name.clone() == "".to_string()) || ((names.clone().len() as i64) == 0)) { false } else { { let mut __found = false; for other in lines.iter().cloned() { - if (((((other.clone().as_str() != line.clone().as_str()) - && (rust_pub_use_module_name(other.clone()).as_str() - == mod_name.clone().as_str())) + if (((((other.clone() != line.clone()) + && (rust_pub_use_module_name(other.clone()) == mod_name.clone())) && v1_rt::contains(other.clone(), "::{".to_string())) && ((rust_pub_use_braced_names(other.clone()).len() as i64) > (names.clone().len() as i64))) @@ -5965,9 +6353,7 @@ pub fn rust_pub_use_braced_equal_prior_covered(line: String, lines: Rc>) -> Rc> { let exact = unique_strings(Rc::new({ let mut __result = Vec::new(); for line in lines.iter().cloned() { - if (line.clone().as_str() != "".to_string().as_str()) { + if (line.clone() != "".to_string()) { __result.push(line); } } @@ -6080,8 +6466,7 @@ pub fn emit_imports( let mut __result = Vec::new(); for imp in imports.clone().iter().cloned() { if (authored_name_at(source_indices.clone(), imp.clone()) - .as_str() - == import_module.clone().as_str()) + == import_module.clone()) { __result.push(imp); } @@ -6151,8 +6536,7 @@ pub fn emit_imports( source_indices.clone(), module_index.clone(), ); - if (specific_block.clone().as_str() != "".to_string().as_str()) - { + if (specific_block.clone() != "".to_string()) { v1_rt::concat( v1_rt::concat(wildcard_line.clone(), "\n".to_string()), specific_block.clone(), @@ -6282,44 +6666,74 @@ pub fn emit_typed_item( && rust_nominal_identity_carrier_type_eligible(item_text.clone())) { rust_nominal_identity_carrier_def(item_text.clone()) - } else if is_zero_param_self_referential_opaque_decl( - item.clone(), - env.source_indices.clone(), - ) { - emit_zero_param_phantom_opaque_struct(item.clone(), env.source_indices.clone()) } else { - v1_rt::concat( - v1_rt::concat( - v1_rt::concat( + if is_zero_param_self_referential_opaque_decl( + item.clone(), + env.source_indices.clone(), + ) { + emit_zero_param_phantom_opaque_struct( + item.clone(), + env.source_indices.clone(), + ) + } else { + match rust_seed_host_numeric_alias( + item_text.clone(), + emit_info.corpus_repr.clone(), + ) { + Some(host) => v1_rt::concat( v1_rt::concat( v1_rt::concat( v1_rt::concat( - rust_visibility_prefix(), - rust_items().type_alias_keyword.clone(), + v1_rt::concat( + v1_rt::concat( + rust_visibility_prefix(), + rust_items().type_alias_keyword.clone(), + ), + " ".to_string(), + ), + item_text.clone(), ), - " ".to_string(), + " = ".to_string(), ), - item_text.clone(), + host.clone(), ), - " = ".to_string(), + ";".to_string(), ), - render_rust_alias_rhs_type( - resolved_type(item.clone()), - Rc::new(vec![]), - shared_types, - env.source_indices.clone(), - scope.clone(), - imports.clone(), - registry.clone(), - module_name.clone(), - export_sets.clone(), - typed_modules.clone(), - module_index.clone(), - emit_info.variant_to_enum.clone(), + None => v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + rust_visibility_prefix(), + rust_items().type_alias_keyword.clone(), + ), + " ".to_string(), + ), + item_text.clone(), + ), + " = ".to_string(), + ), + render_rust_alias_rhs_type( + resolved_type(item.clone()), + Rc::new(vec![]), + shared_types, + emit_info.corpus_repr.clone(), + env.source_indices.clone(), + scope.clone(), + imports.clone(), + registry.clone(), + module_name.clone(), + export_sets.clone(), + typed_modules.clone(), + module_index.clone(), + emit_info.variant_to_enum.clone(), + ), + ), + ";".to_string(), ), - ), - ";".to_string(), - ) + } + } } } else { if is_type_decl_item(item.clone(), env.source_indices.clone()) { @@ -6328,19 +6742,11 @@ pub fn emit_typed_item( { rust_nominal_identity_carrier_def(item_text.clone()) } else { - if is_emittable_parametric_type_alias_item( - item.clone(), + match rust_seed_host_container_base( item_text.clone(), - env.source_indices.clone(), - module_name.clone(), - imports.clone(), - scope.clone(), - registry.clone(), - export_sets.clone(), - typed_modules.clone(), - module_index.clone(), + emit_info.corpus_repr.clone(), ) { - { + Some(host) => { let type_params = emit_type_params( item.params.clone(), env.source_indices.clone(), @@ -6356,45 +6762,105 @@ pub fn emit_typed_item( v1_rt::concat( v1_rt::concat( v1_rt::concat( - rust_visibility_prefix(), - rust_items().type_alias_keyword.clone(), + v1_rt::concat( + v1_rt::concat( + rust_visibility_prefix(), + rust_items() + .type_alias_keyword + .clone(), + ), + " ".to_string(), + ), + item_text.clone(), ), - " ".to_string(), + type_params, ), - item_text.clone(), + " = ".to_string(), ), - type_params, + host.clone(), ), - " = ".to_string(), - ), - render_rust_alias_rhs_type( - resolved_type(item.clone()), - generic_names, - shared_types, - env.source_indices.clone(), - scope.clone(), - imports.clone(), - registry.clone(), - module_name.clone(), - export_sets.clone(), - typed_modules.clone(), - module_index.clone(), - emit_info.variant_to_enum.clone(), + "<".to_string(), ), + generic_names.join(&", ".to_string()), ), - ";".to_string(), + ">;".to_string(), ) } - } else if is_parametric_opaque_type_decl_item( - item.clone(), - env.source_indices.clone(), - ) { - emit_parametric_phantom_opaque_struct( - item.clone(), - env.source_indices.clone(), - ) - } else { - "".to_string() + None => { + if is_emittable_parametric_type_alias_item( + item.clone(), + item_text.clone(), + env.source_indices.clone(), + module_name.clone(), + imports.clone(), + scope.clone(), + registry.clone(), + export_sets.clone(), + typed_modules.clone(), + module_index.clone(), + ) { + { + let type_params = emit_type_params( + item.params.clone(), + env.source_indices.clone(), + ); + let generic_names = item_generic_param_names( + item.clone(), + env.source_indices.clone(), + ); + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + rust_visibility_prefix(), + rust_items() + .type_alias_keyword + .clone(), + ), + " ".to_string(), + ), + item_text.clone(), + ), + type_params, + ), + " = ".to_string(), + ), + render_rust_alias_rhs_type( + resolved_type(item.clone()), + generic_names, + shared_types, + emit_info.corpus_repr.clone(), + env.source_indices.clone(), + scope.clone(), + imports.clone(), + registry.clone(), + module_name.clone(), + export_sets.clone(), + typed_modules.clone(), + module_index.clone(), + emit_info.variant_to_enum.clone(), + ), + ), + ";".to_string(), + ) + } + } else { + if is_parametric_opaque_type_decl_item( + item.clone(), + env.source_indices.clone(), + ) { + emit_parametric_phantom_opaque_struct( + item.clone(), + env.source_indices.clone(), + ) + } else { + "".to_string() + } + } + } } } } else { @@ -6438,6 +6904,7 @@ pub fn emit_typed_item( owned_bindings: v1_rt::rc_empty_set::(), read_only_params_index: emit_info.read_only_params_index.clone(), read_only_params: fn_read_only, + corpus_repr: emit_info.corpus_repr.clone(), }); let is_effectful = match lookup_item( registry.clone(), @@ -6492,11 +6959,17 @@ pub fn emit_typed_item( item.clone(), registry.clone(), shared_types, + emit_info.corpus_repr.clone(), env.clone(), ) } else { if is_resource_def_item(item.clone()) { - emit_resource_def(item.clone(), shared_types, env.clone()) + emit_resource_def( + item.clone(), + shared_types, + emit_info.corpus_repr.clone(), + env.clone(), + ) } else { v1_rt::concat( v1_rt::concat( @@ -6527,9 +7000,7 @@ pub fn needs_box_wrapping( if v1_rt::set_contains(&shared_types, name.clone()) { break false; } else { - if (coerce_primitive_type(RenderTarget::Rust, name.clone()).as_str() - != name.clone().as_str()) - { + if (coerce_primitive_type(RenderTarget::Rust, name.clone()) != name.clone()) { break false; } else { break v1_rt::set_contains(&recursive_types, name.clone()); @@ -6580,12 +7051,11 @@ pub fn is_function_type_param(param: Rc) -> bool { Some(inf) => is_type_variable(inf.clone()), None => false, }; - let same_source_span = (((param.span.clone().file.clone().as_str() - == type_expr.span.clone().file.clone().as_str()) + let same_source_span = (((param.span.clone().file.clone() + == type_expr.span.clone().file.clone()) && (param.span.clone().start.clone() == type_expr.span.clone().start.clone())) && (param.span.clone().end.clone() == type_expr.span.clone().end.clone())); - (((param.name.clone().as_str() != "".to_string().as_str()) - && (param.name.clone().as_str() == type_expr.name.clone().as_str())) + (((param.name.clone() != "".to_string()) && (param.name.clone() == type_expr.name.clone())) && (type_expr_is_var || same_source_span)) } } @@ -6706,11 +7176,10 @@ pub fn emit_type_def_from_connective( Some(message) => emit_rust_compile_error_item(message.clone()), None => "".to_string(), }; - let validations = if (policy_validation.clone().as_str() == "".to_string().as_str()) - { + let validations = if (policy_validation.clone() == "".to_string()) { rename_validations.clone() } else { - if (rename_validations.clone().as_str() == "".to_string().as_str()) { + if (rename_validations.clone() == "".to_string()) { policy_validation.clone() } else { v1_rt::concat( @@ -6737,7 +7206,7 @@ pub fn emit_type_def_from_connective( serde_policy.clone(), emit_info, ); - if (validations.clone().as_str() == "".to_string().as_str()) { + if (validations.clone() == "".to_string()) { enum_text } else { v1_rt::concat( @@ -6750,6 +7219,73 @@ pub fn emit_type_def_from_connective( } } +pub fn type_node_mentions_name( + n: Rc, + target: String, + source_indices: Rc>>, +) -> bool { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + if (authored_name_at(source_indices.clone(), n.clone()) == target.clone()) { + true + } else { + { + let mut __found = false; + for c in n.children.clone().iter().cloned() { + if type_node_mentions_name(c.clone(), target.clone(), source_indices.clone()) { + __found = true; + break; + } + } + __found + } + } + }) +} + +pub fn struct_unused_param_names( + generic_param_names: Rc>, + children: Rc>>, + source_indices: Rc>>, +) -> Rc> { + Rc::new({ + let mut __result = Vec::new(); + for p in generic_param_names.iter().cloned() { + if !{ + let mut __found = false; + for child in children.clone().iter().cloned() { + if type_node_mentions_name( + field_node_type_expr(child.clone()), + p.clone(), + source_indices.clone(), + ) { + __found = true; + break; + } + } + __found + } { + __result.push(p); + } + } + __result + }) +} + +pub fn rust_phantom_marker_inner(unused: Rc>) -> String { + if ((unused.clone().len() as i64) == 1) { + unused.clone().join(&", ".to_string()) + } else { + v1_rt::concat( + v1_rt::concat("(".to_string(), unused.clone().join(&", ".to_string())), + ")".to_string(), + ) + } +} + +pub fn rust_phantom_field_name() -> String { + "_phantom".to_string() +} + pub fn emit_struct_from_children( name: String, type_params: String, @@ -6772,9 +7308,7 @@ pub fn emit_struct_from_children( name.clone(), children.clone(), env.source_indices.clone(), - ) - .as_str() - != "".to_string().as_str()) + ) != "".to_string()) { rust_nominal_ord_derives_for_shape( name.clone(), @@ -6826,7 +7360,32 @@ pub fn emit_struct_from_children( } __result }); - let fields_str = field_lines.join(&"\n".to_string()); + let unused_params = struct_unused_param_names( + generic_param_names.clone(), + children.clone(), + env.source_indices.clone(), + ); + let all_field_lines = if ((unused_params.clone().len() as i64) > 0) { + v1_rt::concat( + field_lines, + Rc::new(vec![v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat( + v1_rt::concat(" ".to_string(), rust_visibility_prefix()), + rust_phantom_field_name(), + ), + ": std::marker::PhantomData<".to_string(), + ), + rust_phantom_marker_inner(unused_params.clone()), + ), + ">,".to_string(), + )]), + ) + } else { + field_lines + }; + let fields_str = all_field_lines.join(&"\n".to_string()); v1_rt::concat( v1_rt::concat( v1_rt::concat( @@ -6860,6 +7419,7 @@ pub fn emit_struct_from_children( pub fn render_rust_type_with_applied_binding( n: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { match find_property( @@ -6869,51 +7429,93 @@ pub fn render_rust_type_with_applied_binding( ) { Some(applied) => { if ((applied.children.clone().len() as i64) > 0) { - let outer_name = authored_name_at(source_indices.clone(), n.clone()); - let applied_name = authored_name_at(source_indices.clone(), applied.clone()); - if outer_name.as_str() != "" - && n.connective.clone() == Connective::NoConnective - && (n.children.clone().len() as i64) == 0 { - if outer_name != applied_name { - render_rust_shared_type_if_needed( - outer_name.clone(), - outer_name, - shared_types.clone(), - ) - } else if v1_rt::set_contains(&shared_types, outer_name.clone()) { - render_rust_shared_type_if_needed( - outer_name.clone(), - outer_name, - shared_types.clone(), - ) + let outer_name = authored_name_at(source_indices.clone(), n.clone()); + let applied_name = authored_name_at(source_indices.clone(), applied.clone()); + if (((outer_name.clone() != "".to_string()) + && (n.connective.clone() == Connective::NoConnective)) + && ((n.children.clone().len() as i64) == 0)) + { + if (outer_name.clone() != applied_name) { + render_rust_shared_type_if_needed( + outer_name.clone(), + outer_name.clone(), + shared_types.clone(), + ) + } else { + if v1_rt::set_contains(&shared_types, outer_name.clone()) { + render_rust_shared_type_if_needed( + outer_name.clone(), + outer_name.clone(), + shared_types.clone(), + ) + } else { + render_rust_applied_type_shared( + applied.clone(), + Rc::new(vec![]), + shared_types.clone(), + corpus_repr, + source_indices.clone(), + v1_rt::rc_empty_map::(), + Rc::new(TypeEnv { + bindings: v1_rt::rc_empty_map::>(), + recursive_types: Rc::new(vec![]), + recursive_type_set: v1_rt::rc_empty_map::(), + inductive_fields: v1_rt::rc_empty_map::< + String, + Rc>>, + >( + ), + source_indices: source_indices.clone(), + intern_table: empty_intern_table(), + }), + ) + } + } } else { render_rust_applied_type_shared( applied.clone(), Rc::new(vec![]), - shared_types, + shared_types.clone(), + corpus_repr, source_indices.clone(), + v1_rt::rc_empty_map::(), + Rc::new(TypeEnv { + bindings: v1_rt::rc_empty_map::>(), + recursive_types: Rc::new(vec![]), + recursive_type_set: v1_rt::rc_empty_map::(), + inductive_fields: v1_rt::rc_empty_map::< + String, + Rc>>, + >(), + source_indices: source_indices.clone(), + intern_table: empty_intern_table(), + }), ) } - } else { - render_rust_applied_type_shared( - applied.clone(), - Rc::new(vec![]), - shared_types, - source_indices.clone(), - ) } } else { - render_rust_type(n.clone(), shared_types, source_indices.clone()) + render_rust_type( + n.clone(), + shared_types.clone(), + corpus_repr, + source_indices.clone(), + ) } } - None => render_rust_type(n.clone(), shared_types, source_indices.clone()), + None => render_rust_type( + n.clone(), + shared_types.clone(), + corpus_repr, + source_indices.clone(), + ), } } pub fn render_rust_field_type_with_applied_binding( field: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { { @@ -6927,6 +7529,7 @@ pub fn render_rust_field_type_with_applied_binding( render_rust_type_with_applied_binding( field.clone(), shared_types, + corpus_repr, source_indices.clone(), ) } else { @@ -6939,17 +7542,24 @@ pub fn render_rust_field_type_with_applied_binding( render_rust_type_with_applied_binding( authored_type.clone(), shared_types, + corpus_repr, source_indices.clone(), ) } else { if ((authored_type.connective.clone() == Connective::NoConnective) && ((authored_type.children.clone().len() as i64) > 0)) { - render_rust_type(authored_type.clone(), shared_types, source_indices.clone()) + render_rust_type( + authored_type.clone(), + shared_types, + corpus_repr, + source_indices.clone(), + ) } else { render_rust_type_with_applied_binding( resolved_type(field.clone()), shared_types, + corpus_repr, source_indices.clone(), ) } @@ -6987,6 +7597,7 @@ pub fn emit_struct_field_from_child( render_rust_type_with_applied_binding( child.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ) } else { @@ -6999,6 +7610,7 @@ pub fn emit_struct_field_from_child( render_rust_type_with_applied_binding( authored_child_type.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ) } else { @@ -7011,6 +7623,7 @@ pub fn emit_struct_field_from_child( render_rust_type_with_applied_binding( rt_child.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ) } else { @@ -7057,6 +7670,7 @@ pub fn emit_struct_field_from_child( render_rust_type( rt_child.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ) } @@ -7064,6 +7678,7 @@ pub fn emit_struct_field_from_child( None => render_rust_type( rt_child.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ), } @@ -7072,6 +7687,7 @@ pub fn emit_struct_field_from_child( render_rust_type( rt_child.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ) } @@ -7079,7 +7695,7 @@ pub fn emit_struct_field_from_child( } } }; - let generic_ty = if (struct_name.as_str() == "PartialFunction".to_string().as_str()) { + let generic_ty = if (struct_name == "PartialFunction".to_string()) { rust_normalize_partial_function_field_type_text(rust_normalize_witness_type_text(ty)) } else { ty @@ -7110,8 +7726,8 @@ pub fn emit_struct_field_from_child( let rename_attr = match Rc::new({ let mut __result = Vec::new(); for p in child.properties.clone().iter().cloned() { - if (field_init_node_name_at(p.clone(), env.source_indices.clone()).as_str() - == "from_key".to_string().as_str()) + if (field_init_node_name_at(p.clone(), env.source_indices.clone()) + == "from_key".to_string()) { __result.push(p); } @@ -7156,19 +7772,18 @@ pub fn emit_rust_field_definition( { let snake = to_snake(authored.clone()); let emitted = emit_ident(authored.clone(), RenderTarget::Rust); - let keyword_rename = if ((emitted.clone().as_str() != snake.clone().as_str()) - && (rename_attr.clone().as_str() == "".to_string().as_str())) - { - v1_rt::concat( + let keyword_rename = + if ((emitted.clone() != snake.clone()) && (rename_attr.clone() == "".to_string())) { v1_rt::concat( - v1_rt::concat(indent.clone(), "#[serde(rename = \"".to_string()), - snake.clone(), - ), - "\")]\n".to_string(), - ) - } else { - "".to_string() - }; + v1_rt::concat( + v1_rt::concat(indent.clone(), "#[serde(rename = \"".to_string()), + snake.clone(), + ), + "\")]\n".to_string(), + ) + } else { + "".to_string() + }; v1_rt::concat( v1_rt::concat( v1_rt::concat( @@ -7238,7 +7853,7 @@ pub fn emit_enum_from_children( __result }); let variants_str = variant_lines.join(&"\n".to_string()); - let tag_line = if (serde_policy.enum_attr.clone().as_str() == "".to_string().as_str()) { + let tag_line = if (serde_policy.enum_attr.clone() == "".to_string()) { "".to_string() } else { v1_rt::concat(serde_policy.enum_attr.clone(), "\n".to_string()) @@ -7280,7 +7895,7 @@ pub fn emit_enum_from_children( env.clone(), emit_info.clone(), ); - if (accessor_impl.clone().as_str() == "".to_string().as_str()) { + if (accessor_impl.clone() == "".to_string()) { enum_def } else { v1_rt::concat( @@ -7329,9 +7944,7 @@ pub fn find_shared_enum_fields(children: Rc>>, env: Rc) -> if !({ let mut __found = false; for f in variant.children.clone().iter().cloned() { - if (authored_name(env.clone(), f.clone()).as_str() - == fname.clone().as_str()) - { + if (authored_name(env.clone(), f.clone()) == fname.clone()) { __found = true; break; } @@ -7395,8 +8008,7 @@ pub fn emit_enum_shared_accessors( match Rc::new({ let mut __result = Vec::new(); for f in variant.children.clone().iter().cloned() { - if (authored_name(env.clone(), f.clone()).as_str() - == fname.clone().as_str()) + if (authored_name(env.clone(), f.clone()) == fname.clone()) { __result.push(f); } @@ -7409,6 +8021,7 @@ pub fn emit_enum_shared_accessors( Some(f) => render_rust_field_type_with_applied_binding( f.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ), None => "".to_string(), @@ -7424,7 +8037,7 @@ pub fn emit_enum_shared_accessors( { let mut __all = true; for t in types.clone().iter().cloned() { - if !(t.clone().as_str() == first_type.clone().as_str()) { + if !(t.clone() == first_type.clone()) { __all = false; break; } @@ -7447,9 +8060,7 @@ pub fn emit_enum_shared_accessors( let ty = match Rc::new({ let mut __result = Vec::new(); for f in first_fielded.children.clone().iter().cloned() { - if (authored_name(env.clone(), f.clone()).as_str() - == fname.clone().as_str()) - { + if (authored_name(env.clone(), f.clone()) == fname.clone()) { __result.push(f); } } @@ -7461,6 +8072,7 @@ pub fn emit_enum_shared_accessors( Some(f) => render_rust_field_type_with_applied_binding( f.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ), None => "compile_error!(\"enum shared accessor missing field metadata\")" @@ -7606,8 +8218,7 @@ pub fn string_without_prefix(value: String, prefix: String) -> Option { None } else { if ((v1_rt::string_length(&value) >= v1_rt::string_length(&prefix)) - && (v1_rt::substring(&value, 0, v1_rt::string_length(&prefix)).as_str() - == prefix.clone().as_str())) + && (v1_rt::substring(&value, 0, v1_rt::string_length(&prefix)) == prefix.clone())) { Some(v1_rt::substring( &value, @@ -7629,9 +8240,7 @@ pub fn string_without_suffix(value: String, suffix: String) -> Option { &value, (v1_rt::string_length(&value) - v1_rt::string_length(&suffix)), v1_rt::string_length(&value), - ) - .as_str() - == suffix.clone().as_str())) + ) == suffix.clone())) { Some(v1_rt::substring( &value, @@ -7644,67 +8253,120 @@ pub fn string_without_suffix(value: String, suffix: String) -> Option { } } +pub fn string_index_of_from(mut haystack: String, mut needle: String, mut pos: i64) -> Option { + loop { + if ((pos.clone() + v1_rt::string_length(&needle)) > v1_rt::string_length(&haystack)) { + break None; + } else { + if (v1_rt::substring( + &haystack, + pos.clone(), + (pos.clone() + v1_rt::string_length(&needle)), + ) == needle.clone()) + { + break Some(pos.clone()); + } else { + { + let __tco_0 = (pos + 1); + pos = __tco_0; + continue; + } + } + } + } +} + +pub fn string_index_of(haystack: String, needle: String) -> Option { + string_index_of_from(haystack, needle, 0) +} + pub fn wire_variant_tag_for_policy( authored: String, policy: Rc, ) -> Option { - if policy.error_message.is_some() { - return None; - } - match policy.rename_style.clone() { - Some(style) => { - if style.as_str() == "StripAffixAndSnakeCase" { - let without_prefix = match policy.rename_prefix.clone() { - Some(prefix) => match string_without_prefix(authored, prefix) { - Some(stripped) => stripped, - None => return None, - }, - None => authored, - }; - let without_suffix = match policy.rename_suffix.clone() { - Some(suffix) => match string_without_suffix(without_prefix, suffix) { - Some(stripped) => stripped, - None => return None, - }, - None => without_prefix, - }; - Some(to_snake(without_suffix)) - } else { - None + if (policy.error_message.clone() != None) { + None + } else { + match policy.rename_style.clone() { + Some(style) => { + if (style.clone() == "StripAffixAndSnakeCase".to_string()) { + { + let without_prefix = match policy.rename_prefix.clone() { + Some(prefix) => match string_without_prefix(authored, prefix.clone()) { + Some(stripped) => stripped.clone(), + None => return None, + }, + None => authored, + }; + let without_suffix = match policy.rename_suffix.clone() { + Some(suffix) => { + match string_without_suffix(without_prefix, suffix.clone()) { + Some(stripped) => stripped.clone(), + None => return None, + } + } + None => without_prefix, + }; + Some(to_snake(without_suffix)) + } + } else { + None + } } - } - None => { - if policy.enum_attr.contains("rename_all = \"snake_case\"") { - Some(to_snake(authored)) - } else if policy.enum_attr.is_empty() - && policy.rename_prefix.is_none() - && policy.rename_suffix.is_none() - { - Some(authored) - } else { - None + None => { + if v1_rt::contains( + policy.enum_attr.clone(), + "rename_all = \"snake_case\"".to_string(), + ) { + Some(to_snake(authored)) + } else { + if (((policy.enum_attr.clone() == "".to_string()) + && (policy.rename_prefix.clone() == None)) + && (policy.rename_suffix.clone() == None)) + { + Some(authored) + } else { + None + } + } } } } } -pub fn policy_serde_tag_field(policy: &RustEnumWireSerde) -> Option { - let needle = "tag = \""; - let start = policy.enum_attr.find(needle)? + needle.len(); - let rest = &policy.enum_attr[start..]; - let end = rest.find('"')?; - Some(rest[..end].to_string()) +pub fn policy_serde_tag_field(policy: Rc) -> Option { + { + let needle = "tag = \"".to_string(); + match string_index_of(policy.enum_attr.clone(), needle.clone()) { + Some(start) => { + let after = (start.clone() + v1_rt::string_length(&needle)); + match string_index_of_from( + policy.enum_attr.clone(), + "\"".to_string(), + after.clone(), + ) { + Some(end) => Some(v1_rt::substring( + &policy.enum_attr.clone(), + after.clone(), + end.clone(), + )), + None => None, + } + } + None => None, + } + } } -pub fn policy_is_untagged(policy: &RustEnumWireSerde) -> bool { - policy.enum_attr.contains("untagged") +pub fn policy_is_untagged(policy: Rc) -> bool { + v1_rt::contains(policy.enum_attr.clone(), "untagged".to_string()) } -pub fn policy_is_string_variant(policy: &RustEnumWireSerde) -> bool { - !policy.enum_attr.contains("tag =") - && policy.rename_prefix.is_none() - && policy.rename_suffix.is_none() - && policy.rename_style.is_none() +pub fn policy_is_string_variant(policy: Rc) -> bool { + (((!v1_rt::contains(policy.enum_attr.clone(), "tag =".to_string()) + && (policy.rename_prefix.clone() == None)) + && (policy.rename_suffix.clone() == None)) + && (policy.rename_style.clone() == None)) } pub fn wire_variant_rename_attr_for_policy( @@ -7714,9 +8376,9 @@ pub fn wire_variant_rename_attr_for_policy( match wire_variant_tag_for_policy(authored, policy.clone()) { Some(tag) => match policy.rename_style.clone() { Some(style) => { - if style.as_str() == "StripAffixAndSnakeCase" { + if (style.clone() == "StripAffixAndSnakeCase".to_string()) { v1_rt::concat( - v1_rt::concat(" #[serde(rename = \"".to_string(), tag), + v1_rt::concat(" #[serde(rename = \"".to_string(), tag.clone()), "\")]\n".to_string(), ) } else { @@ -7735,7 +8397,7 @@ pub fn variant_rename_validation_for_policy( ) -> String { match policy.rename_style.clone() { Some(style) => { - if (style.clone().as_str() == "StripAffixAndSnakeCase".to_string().as_str()) { + if (style.clone() == "StripAffixAndSnakeCase".to_string()) { { let without_prefix = match policy.rename_prefix.clone() { Some(prefix) => { @@ -7798,7 +8460,7 @@ pub fn variant_rename_validations_for_policy( .iter() .cloned() { - if (text.clone().as_str() != "".to_string().as_str()) { + if (text.clone() != "".to_string()) { __result.push(text); } } @@ -7840,6 +8502,7 @@ pub fn enum_variant_field_type_node( pub fn render_variant_payload_type( n: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { if ((n.connective.clone() == Connective::NoConnective) @@ -7853,6 +8516,7 @@ pub fn render_variant_payload_type( __result.push(render_rust_type( child_type_node(c.clone()), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), )); } @@ -7871,7 +8535,12 @@ pub fn render_variant_payload_type( ) } } else { - render_rust_type(n.clone(), shared_types.clone(), source_indices.clone()) + render_rust_type( + n.clone(), + shared_types.clone(), + corpus_repr.clone(), + source_indices.clone(), + ) } } @@ -7883,9 +8552,7 @@ pub fn variant_is_synthetic_positional_payload( false } else { match fields.clone().first().cloned() { - Some(f) => { - (field_node_name_at(f.clone(), source_indices).as_str() == "0".to_string().as_str()) - } + Some(f) => (field_node_name_at(f.clone(), source_indices) == "0".to_string()), None => false, } } @@ -7920,8 +8587,7 @@ pub fn emit_variant_from_child( env.source_indices.clone(), ); let tuple_style = (positional_payload.clone() - || (serde_policy.enum_attr.clone().as_str() - == "#[serde(untagged)]".to_string().as_str())); + || (serde_policy.enum_attr.clone() == "#[serde(untagged)]".to_string())); if tuple_style { match child.children.clone().first().cloned() { Some(f) => { @@ -7942,12 +8608,14 @@ pub fn emit_variant_from_child( render_variant_payload_type( type_node.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ) } else { render_rust_type( type_node.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ) }; @@ -7960,6 +8628,7 @@ pub fn emit_variant_from_child( render_rust_type_with_applied_binding( type_node.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ) } else { @@ -8010,6 +8679,7 @@ pub fn emit_variant_from_child( let ty = render_rust_field_type_with_applied_binding( f.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ); let final_ty = if needs_box_wrapping( @@ -8063,6 +8733,7 @@ pub fn emit_variant_from_child( let ty = render_rust_field_type_with_applied_binding( f.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), env.source_indices.clone(), ); let final_ty = if needs_box_wrapping( @@ -8119,71 +8790,78 @@ pub fn emit_fn_def( shared_types: Rc>, emit_info: Rc, ) -> String { - if let Some(seam_fn) = rust_host_string_seam_fn_emit(name.clone()) { - if rust_emit_faithful_text_carrier(scope.type_env.source_indices.clone()) { - return seam_fn; - } else { - return "".to_string(); - } - } { let si = scope.type_env.clone().source_indices.clone(); - let type_params = function_type_params(params.clone()); - let value_params = function_value_params(params.clone()); - if function_type_params_have_collision(type_params.clone()) { - return v1_rt::concat(v1_rt::concat("compile_error!(\"type param name collides with a value param in fn '".to_string(), name.clone()), "' — a value param shares its name with a declared type param; rename the value param or dissolve via ParamKind/params-slot partition\");\n".to_string()); - } - let type_params_str = emit_type_params(type_params.clone(), si.clone()); - let generic_param_names = Rc::new({ - let mut __result = Vec::new(); - for p in type_params.clone().iter().cloned() { - __result.push(generic_param_name_at(p.clone(), si.clone())); + match rust_host_string_seam_fn_emit(name.clone()) { + Some(seam_fn) => { + if corpus_repr_is_faithful(emit_info.corpus_repr.clone()) { + seam_fn.clone() + } else { + "".to_string() + } } - __result - }); - let params_str = emit_params( - value_params.clone(), - generic_param_names.clone(), - shared_types.clone(), - si.clone(), - emit_info.read_only_params.clone(), - scope.type_env.clone(), - ); - let ret_str = emit_inferred( - inferred, - generic_param_names.clone(), - shared_types.clone(), - si.clone(), - scope.type_env.clone(), - ); - let body_scope = build_params_scope(scope.clone(), value_params.clone()); - let depth = 0; - let use_tco = is_tco_eligible(name.clone(), body.clone(), registry.clone(), si.clone()); - let needs_stacker = - (is_self_recursive(name.clone(), body.clone(), registry.clone(), si.clone()) - && (use_tco.clone() == false)); - if use_tco.clone() { - { - let tco_params_str = emit_tco_params( + None => { + let type_params = function_type_params(params.clone()); + let value_params = function_value_params(params.clone()); + if function_type_params_have_collision(type_params.clone()) { + return v1_rt::concat(v1_rt::concat("compile_error!(\"type param name collides with a value param in fn '".to_string(), name.clone()), "' — a value param shares its name with a declared type param; rename the value param or dissolve via ParamKind/params-slot partition\");\n".to_string()); + } + let type_params_str = emit_type_params(type_params.clone(), si.clone()); + let generic_param_names = Rc::new({ + let mut __result = Vec::new(); + for p in type_params.clone().iter().cloned() { + __result.push(generic_param_name_at(p.clone(), si.clone())); + } + __result + }); + let params_str = emit_params( value_params.clone(), generic_param_names.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), si.clone(), + emit_info.read_only_params.clone(), + emit_info.variant_to_enum.clone(), scope.type_env.clone(), ); - let body_str = emit_typed_tco_body( - body.clone(), - name.clone(), - value_params.clone(), - registry.clone(), - body_scope, - (depth.clone() + 1), + let ret_str = emit_inferred( + inferred, + generic_param_names.clone(), shared_types.clone(), - emit_info.clone(), + emit_info.corpus_repr.clone(), + si.clone(), + emit_info.variant_to_enum.clone(), + scope.type_env.clone(), ); - let kw = rust_items().func_keyword.clone(); - v1_rt::concat( - v1_rt::concat( + let body_scope = build_params_scope(scope.clone(), value_params.clone()); + let depth = 0; + let use_tco = + is_tco_eligible(name.clone(), body.clone(), registry.clone(), si.clone()); + let needs_stacker = + (is_self_recursive(name.clone(), body.clone(), registry.clone(), si.clone()) + && (use_tco.clone() == false)); + if use_tco.clone() { + { + let tco_params_str = emit_tco_params( + value_params.clone(), + generic_param_names.clone(), + shared_types.clone(), + emit_info.corpus_repr.clone(), + si.clone(), + emit_info.variant_to_enum.clone(), + scope.type_env.clone(), + ); + let body_str = emit_typed_tco_body( + body.clone(), + name.clone(), + value_params.clone(), + registry.clone(), + body_scope, + (depth.clone() + 1), + shared_types.clone(), + emit_info.clone(), + ); + let kw = rust_items().func_keyword.clone(); v1_rt::concat( v1_rt::concat( v1_rt::concat( @@ -8194,49 +8872,53 @@ pub fn emit_fn_def( v1_rt::concat( v1_rt::concat( v1_rt::concat( - rust_visibility_prefix(), - kw, + v1_rt::concat( + v1_rt::concat( + rust_visibility_prefix(), + kw, + ), + " ".to_string(), + ), + emit_ident( + name.clone(), + RenderTarget::Rust, + ), ), - " ".to_string(), - ), - emit_ident( - name.clone(), - RenderTarget::Rust, + type_params_str, ), + "(".to_string(), ), - type_params_str, + tco_params_str, ), - "(".to_string(), + ")".to_string(), ), - tco_params_str, + ret_str, ), - ")".to_string(), + " {\n".to_string(), ), - ret_str, + make_indent((depth.clone() + 1)), ), - " {\n".to_string(), + body_str, ), - make_indent((depth.clone() + 1)), - ), - body_str, - ), - "\n}".to_string(), - ) + "\n}".to_string(), + ) + } + } else { + emit_fn_def_non_tco( + name.clone(), + type_params_str, + params_str, + ret_str, + body.clone(), + registry.clone(), + body_scope, + depth.clone(), + shared_types.clone(), + emit_info.clone(), + needs_stacker, + ) + } } - } else { - emit_fn_def_non_tco( - name.clone(), - type_params_str, - params_str, - ret_str, - body.clone(), - registry.clone(), - body_scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - needs_stacker, - ) } } } @@ -8396,13 +9078,16 @@ pub fn emit_func_def( uses.clone(), service_names, shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), emit_info.read_only_params.clone(), + emit_info.variant_to_enum.clone(), scope.type_env.clone(), ); let ret_str = emit_func_inferred( inferred, shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ); let body_scope = build_params_scope(scope.clone(), params.clone()); @@ -8616,7 +9301,9 @@ pub fn emit_tco_params( params: Rc>>, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, env: Rc, ) -> String { { @@ -8627,7 +9314,9 @@ pub fn emit_tco_params( p.clone(), generic_param_names.clone(), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), + variant_to_enum.clone(), env.clone(), )); } @@ -8641,7 +9330,9 @@ pub fn emit_tco_param( param: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, env: Rc, ) -> String { { @@ -8651,15 +9342,19 @@ pub fn emit_tco_param( authored.clone(), generic_param_names, shared_types, + corpus_repr, source_indices.clone(), - env.clone(), + variant_to_enum, + env, ) } else { render_rust_param_sig_type( param.clone(), generic_param_names, shared_types, + corpus_repr, source_indices.clone(), + variant_to_enum, env, ) }; @@ -8684,8 +9379,10 @@ pub fn emit_func_params( uses: Rc>>, service_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, read_only_params: Rc>, + variant_to_enum: Rc>, env: Rc, ) -> String { { @@ -8696,8 +9393,10 @@ pub fn emit_func_params( p.clone(), Rc::new(vec![]), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), read_only_params.clone(), + variant_to_enum.clone(), env.clone(), )); } @@ -8717,6 +9416,7 @@ pub fn emit_func_params( render_rust_type( resource_use_resource(u.clone()), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), ), )); @@ -8741,12 +9441,13 @@ pub fn emit_func_params( pub fn emit_func_inferred( inferred: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { v1_rt::concat( v1_rt::concat( " -> Result<".to_string(), - render_rust_type(inferred, shared_types, source_indices), + render_rust_type(inferred, shared_types, corpus_repr, source_indices), ), ", Box>".to_string(), ) @@ -8756,8 +9457,10 @@ pub fn emit_params( params: Rc>>, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, read_only_params: Rc>, + variant_to_enum: Rc>, env: Rc, ) -> String { { @@ -8768,8 +9471,10 @@ pub fn emit_params( p.clone(), generic_param_names.clone(), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), read_only_params.clone(), + variant_to_enum.clone(), env.clone(), )); } @@ -8783,16 +9488,20 @@ pub fn render_rust_param_sig_type( param: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, env: Rc, ) -> String { { - let type_node = resolved_type(param.clone()); + let type_node = resolved_type(param); render_rust_fn_sig_type( type_node, generic_param_names, shared_types, + corpus_repr, source_indices, + variant_to_enum, env, ) } @@ -8802,7 +9511,9 @@ pub fn emit_rust_param_type( n: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, env: Rc, ) -> String { if ((n.params.clone().len() as i64) > 0) { @@ -8814,7 +9525,9 @@ pub fn emit_rust_param_type( param_node_type_expr(p.clone()), generic_param_names.clone(), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), + variant_to_enum.clone(), env.clone(), )); } @@ -8826,7 +9539,9 @@ pub fn emit_rust_param_type( rt.clone(), generic_param_names.clone(), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), + variant_to_enum.clone(), env.clone(), ), _ => "()".to_string(), @@ -8847,8 +9562,10 @@ pub fn emit_rust_param_type( n.clone(), generic_param_names.clone(), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), - env, + variant_to_enum.clone(), + env.clone(), ) } } @@ -8857,8 +9574,10 @@ pub fn emit_param( param: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, read_only_params: Rc>, + variant_to_enum: Rc>, env: Rc, ) -> String { { @@ -8868,15 +9587,19 @@ pub fn emit_param( authored.clone(), generic_param_names, shared_types, + corpus_repr, source_indices.clone(), - env.clone(), + variant_to_enum, + env, ) } else { render_rust_param_sig_type( param.clone(), generic_param_names, shared_types, + corpus_repr, source_indices.clone(), + variant_to_enum, env, ) }; @@ -8895,7 +9618,9 @@ pub fn emit_inferred( inferred: Rc, generic_param_names: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, + variant_to_enum: Rc>, env: Rc, ) -> String { v1_rt::concat( @@ -8904,7 +9629,9 @@ pub fn emit_inferred( inferred, generic_param_names, shared_types, + corpus_repr, source_indices, + variant_to_enum, env, ), ) @@ -8987,12 +9714,11 @@ pub fn collect_field_binding_string_guards( let fb_pat = field_binding_pattern(fb.clone()); if is_string_lit_pattern(fb_pat.clone()) { { - let field_path = - if (fb_name.clone().as_str() == "0".to_string().as_str()) { - v1_rt::rc_list_push(path_prefix.clone(), "0".to_string()) - } else { - v1_rt::rc_list_push(path_prefix.clone(), fb_name.clone()) - }; + let field_path = if (fb_name.clone() == "0".to_string()) { + v1_rt::rc_list_push(path_prefix.clone(), "0".to_string()) + } else { + v1_rt::rc_list_push(path_prefix.clone(), fb_name.clone()) + }; let bind_name = pattern_string_binding_name(field_path.clone()); match positional_payload_string_guard( fb_pat.clone(), @@ -9011,7 +9737,7 @@ pub fn collect_field_binding_string_guards( nested_path.clone(), source_indices.clone(), ); - if (nested.clone().as_str() == "".to_string().as_str()) { + if (nested.clone() == "".to_string()) { Rc::new(vec![]) } else { Rc::new(vec![nested.clone()]) @@ -9042,7 +9768,7 @@ pub fn collect_pattern_string_guards( field_bindings: fbs, .. } => { - if (((n.clone().as_str() == "Present".to_string().as_str()) + if (((n.clone() == "Present".to_string()) && (parent.clone().as_deref() == Some("Optional".to_string()).as_deref())) && ((fbs.clone().len() as i64) == 1)) { @@ -9085,8 +9811,7 @@ pub fn collect_pattern_string_guards( match fbs.clone().first().cloned() { Some(fb) => { if (field_binding_name_at(fb.clone(), source_indices.clone()) - .as_str() - == "0".to_string().as_str()) + == "0".to_string()) { let fb_pat = field_binding_pattern(fb.clone()); let pos_path = v1_rt::rc_list_push( @@ -9227,7 +9952,7 @@ pub fn pattern_parent_enum( type_summaries: Rc>>, ) -> Option { { - let scrut_is_known_enum = ((scrut_type.clone().as_str() != "".to_string().as_str()) + let scrut_is_known_enum = ((scrut_type.clone() != "".to_string()) && is_enum_type_name(scrut_type.clone(), type_summaries.clone())); if (parent_enum.clone() != None) { parent_enum.clone() @@ -9270,13 +9995,12 @@ pub fn unique_variant_parent( } pub fn is_optional_variant_name(name: String) -> bool { - ((name.clone().as_str() == "Present".to_string().as_str()) - || (name.clone().as_str() == "Absent".to_string().as_str())) + ((name.clone() == "Present".to_string()) || (name.clone() == "Absent".to_string())) } pub fn is_optional_parent(parent_enum: Option) -> bool { match parent_enum { - Some(parent) => (parent.clone().as_str() == "Optional".to_string().as_str()), + Some(parent) => (parent.clone() == "Optional".to_string()), None => false, } } @@ -9334,7 +10058,7 @@ pub fn emit_variant_pattern( let optional_variant = (is_optional_variant_name(name.clone()) && is_optional_parent(resolved_parent.clone())); let rust_name = if optional_variant.clone() { - if (name.clone().as_str() == "Present".to_string().as_str()) { + if (name.clone() == "Present".to_string()) { "Some".to_string() } else { "None".to_string() @@ -9347,7 +10071,7 @@ pub fn emit_variant_pattern( } else { match resolved_parent.clone() { Some(parent) => { - if (parent.clone().as_str() == "Witness".to_string().as_str()) { + if (parent.clone() == "Witness".to_string()) { v1_rt::concat("v1_rt::Witness::".to_string(), rust_name.clone()) } else { v1_rt::concat( @@ -9359,7 +10083,7 @@ pub fn emit_variant_pattern( None => rust_name.clone(), } }; - if ((optional_variant.clone() && (name.clone().as_str() == "Present".to_string().as_str())) + if ((optional_variant.clone() && (name.clone() == "Present".to_string())) && ((field_bindings.clone().len() as i64) == 1)) { match field_bindings.clone().first().cloned() { @@ -9390,8 +10114,8 @@ pub fn emit_variant_pattern( if ((field_bindings.clone().len() as i64) == 1) { match field_bindings.clone().first().cloned() { Some(fb) => { - if (field_binding_name_at(fb.clone(), source_indices.clone()).as_str() - == "0".to_string().as_str()) + if (field_binding_name_at(fb.clone(), source_indices.clone()) + == "0".to_string()) { { let fb_pat = field_binding_pattern(fb.clone()); @@ -9594,25 +10318,24 @@ pub fn emit_variant_pattern( let fb_pat = field_binding_pattern(fb.clone()); if is_string_lit_pattern(fb_pat.clone()) { { - let field_path = if (fb_name.clone().as_str() - == "0".to_string().as_str()) - { - v1_rt::rc_list_push( + let field_path = + if (fb_name.clone() == "0".to_string()) { v1_rt::rc_list_push( - path_prefix.clone(), - name.clone(), - ), - "0".to_string(), - ) - } else { - v1_rt::rc_list_push( + v1_rt::rc_list_push( + path_prefix.clone(), + name.clone(), + ), + "0".to_string(), + ) + } else { v1_rt::rc_list_push( - path_prefix.clone(), - name.clone(), - ), - fb_name.clone(), - ) - }; + v1_rt::rc_list_push( + path_prefix.clone(), + name.clone(), + ), + fb_name.clone(), + ) + }; let bind_name = pattern_string_binding_name( field_path.clone(), ); @@ -9623,15 +10346,13 @@ pub fn emit_variant_pattern( } } else { { - let is_shorthand = match (*fb_pat.clone()) - .clone() - { - MatchPattern::Bind { name: n, .. } => { - (n.clone().as_str() - == fb_name.clone().as_str()) - } - _ => false, - }; + let is_shorthand = + match (*fb_pat.clone()).clone() { + MatchPattern::Bind { + name: n, .. + } => (n.clone() == fb_name.clone()), + _ => false, + }; if is_shorthand.clone() { emit_ident( fb_name.clone(), @@ -9639,26 +10360,25 @@ pub fn emit_variant_pattern( ) } else { { - let field_path = - if (fb_name.clone().as_str() - == "0".to_string().as_str()) - { + let field_path = if (fb_name.clone() + == "0".to_string()) + { + v1_rt::rc_list_push( v1_rt::rc_list_push( - v1_rt::rc_list_push( - path_prefix.clone(), - name.clone(), - ), - "0".to_string(), - ) - } else { + path_prefix.clone(), + name.clone(), + ), + "0".to_string(), + ) + } else { + v1_rt::rc_list_push( v1_rt::rc_list_push( - v1_rt::rc_list_push( - path_prefix.clone(), - name.clone(), - ), - fb_name.clone(), - ) - }; + path_prefix.clone(), + name.clone(), + ), + fb_name.clone(), + ) + }; let pat_str = emit_pattern( fb_pat.clone(), field_path.clone(), @@ -9729,7 +10449,7 @@ pub fn field_needs_rc_ref(field_name: String, rc_analysis: Rc { let mut __found = false; for name in rc_analysis.ref_bound_fields.clone().iter().cloned() { - if (name.clone().as_str() == field_name.clone().as_str()) { + if (name.clone() == field_name.clone()) { __found = true; break; } @@ -9765,8 +10485,7 @@ pub fn analyze_rc_pattern( ); Rc::new(RcPatternAnalysis { matches_rc_variant: false, - matches_option_rc_variant: ((n.clone().as_str() - == "Present".to_string().as_str()) + matches_option_rc_variant: ((n.clone() == "Present".to_string()) && inner.matches_rc_variant.clone()), needs_rc_pattern: inner.needs_rc_pattern.clone(), ref_bound_fields: Rc::new(vec![]), @@ -9796,18 +10515,17 @@ pub fn analyze_rc_pattern( (*{ let fb_name = field_binding_name_at(fb.clone(), source_indices.clone()); - let inner_scrut = - if (fb_name.clone().as_str() == "0".to_string().as_str()) { - positional_payload_scrut_type( - resolved_parent.clone(), - n.clone(), - fb.clone(), - emit_info.clone(), - source_indices.clone(), - ) - } else { - "".to_string() - }; + let inner_scrut = if (fb_name.clone() == "0".to_string()) { + positional_payload_scrut_type( + resolved_parent.clone(), + n.clone(), + fb.clone(), + emit_info.clone(), + source_indices.clone(), + ) + } else { + "".to_string() + }; if analyze_rc_pattern( field_binding_pattern(fb.clone()), inner_scrut.clone(), @@ -9967,7 +10685,7 @@ pub fn emit_variant_pattern_rc_aware( let optional_variant = (is_optional_variant_name(name.clone()) && is_optional_parent(resolved_parent.clone())); let rust_name = if optional_variant.clone() { - if (name.clone().as_str() == "Present".to_string().as_str()) { + if (name.clone() == "Present".to_string()) { "Some".to_string() } else { "None".to_string() @@ -9980,7 +10698,7 @@ pub fn emit_variant_pattern_rc_aware( } else { match resolved_parent.clone() { Some(parent) => { - if (parent.clone().as_str() == "Witness".to_string().as_str()) { + if (parent.clone() == "Witness".to_string()) { v1_rt::concat("v1_rt::Witness::".to_string(), rust_name.clone()) } else { v1_rt::concat( @@ -9992,7 +10710,7 @@ pub fn emit_variant_pattern_rc_aware( None => rust_name.clone(), } }; - if ((optional_variant.clone() && (name.clone().as_str() == "Present".to_string().as_str())) + if ((optional_variant.clone() && (name.clone() == "Present".to_string())) && ((field_bindings.clone().len() as i64) == 1)) { match field_bindings.clone().first().cloned() { @@ -10031,8 +10749,8 @@ pub fn emit_variant_pattern_rc_aware( if ((field_bindings.clone().len() as i64) == 1) { match field_bindings.clone().first().cloned() { Some(fb) => { - if (field_binding_name_at(fb.clone(), source_indices.clone()).as_str() - == "0".to_string().as_str()) + if (field_binding_name_at(fb.clone(), source_indices.clone()) + == "0".to_string()) { { let fb_pat = field_binding_pattern(fb.clone()); @@ -10267,25 +10985,24 @@ pub fn emit_variant_pattern_rc_aware( let fb_pat = field_binding_pattern(fb.clone()); if is_string_lit_pattern(fb_pat.clone()) { { - let field_path = if (fb_name.clone().as_str() - == "0".to_string().as_str()) - { - v1_rt::rc_list_push( + let field_path = + if (fb_name.clone() == "0".to_string()) { v1_rt::rc_list_push( - path_prefix.clone(), - name.clone(), - ), - "0".to_string(), - ) - } else { - v1_rt::rc_list_push( + v1_rt::rc_list_push( + path_prefix.clone(), + name.clone(), + ), + "0".to_string(), + ) + } else { v1_rt::rc_list_push( - path_prefix.clone(), - name.clone(), - ), - fb_name.clone(), - ) - }; + v1_rt::rc_list_push( + path_prefix.clone(), + name.clone(), + ), + fb_name.clone(), + ) + }; let bind_name = pattern_string_binding_name( field_path.clone(), ); @@ -10313,10 +11030,7 @@ pub fn emit_variant_pattern_rc_aware( { MatchPattern::Bind { name: n, .. - } => { - (n.clone().as_str() - == fb_name.clone().as_str()) - } + } => (n.clone() == fb_name.clone()), _ => false, }; if is_shorthand.clone() { @@ -10326,26 +11040,26 @@ pub fn emit_variant_pattern_rc_aware( ) } else { { - let field_path = - if (fb_name.clone().as_str() - == "0".to_string().as_str()) - { + let field_path = if (fb_name + .clone() + == "0".to_string()) + { + v1_rt::rc_list_push( v1_rt::rc_list_push( - v1_rt::rc_list_push( - path_prefix.clone(), - name.clone(), - ), - "0".to_string(), - ) - } else { + path_prefix.clone(), + name.clone(), + ), + "0".to_string(), + ) + } else { + v1_rt::rc_list_push( v1_rt::rc_list_push( - v1_rt::rc_list_push( - path_prefix.clone(), - name.clone(), - ), - fb_name.clone(), - ) - }; + path_prefix.clone(), + name.clone(), + ), + fb_name.clone(), + ) + }; let inner_analysis = analyze_rc_pattern( fb_pat.clone(), @@ -10453,7 +11167,7 @@ pub fn rc_pattern_preludes( (*{ let fb_name = field_binding_name_at(fb.clone(), source_indices.clone()); - if (fb_name.clone().as_str() == "0".to_string().as_str()) { + if (fb_name.clone() == "0".to_string()) { { let payload_scrut = positional_payload_scrut_type( resolved_parent.clone(), @@ -10476,9 +11190,7 @@ pub fn rc_pattern_preludes( source_indices.clone(), emit_info.clone(), ); - if (inner_preludes.clone().as_str() - == "".to_string().as_str()) - { + if (inner_preludes.clone() == "".to_string()) { Rc::new(vec![]) } else { Rc::new(vec![inner_preludes.clone()]) @@ -10563,7 +11275,7 @@ pub fn explicit_record_struct_name( false }; let nname = authored_name_at(source_indices, n.clone()); - if (nname.clone().as_str() == "__EmitTypeCacheMiss".to_string().as_str()) { + if (nname.clone() == "__EmitTypeCacheMiss".to_string()) { type_name.clone() } else { if n_is_error { @@ -10611,142 +11323,31 @@ pub fn variant_parent_from_binding_kind( _ => None, } } - -pub fn apply_clone(expr: String) -> String { - apply_type_template1( - sharing_for_target(RenderTarget::Rust).clone_value.clone(), - expr, - ) -} - -pub fn apply_deref_clone(expr: String) -> String { - apply_type_template1( - sharing_for_target(RenderTarget::Rust).deref_clone.clone(), - expr, - ) -} - -pub fn apply_field_clone(expr: String, field: String) -> String { - apply_type_template2( - sharing_for_target(RenderTarget::Rust).field_clone.clone(), - expr, - field, - ) -} - -pub fn clone_iterator_suffix() -> String { - sharing_for_target(RenderTarget::Rust).clone_suffix.clone() -} - -pub fn rust_qualify_type_leaf_name( - name: String, - variant_to_enum: Rc>, -) -> String { - match v1_rt::map_get(&variant_to_enum, name.clone()) { - Some(parent) => { - if parent.as_str() != "" { - v1_rt::concat( - v1_rt::concat(parent.clone(), "::".to_string()), - name.clone(), - ) - } else { - name.clone() - } - } - None => name.clone(), - } -} - -pub fn rust_render_type_leaf_name( - name: String, - variant_to_enum: Rc>, - env: Rc, -) -> String { - if is_phantom_unit_variant_type_arg(env, name.clone()) { - name - } else if let Some(carrier) = rust_opaque_kernel_alias_carrier(name.clone()) { - carrier - } else { - rust_qualify_type_leaf_name(name, variant_to_enum) - } -} - -pub fn emit_phantom_zst_markers_for_enum(children: Rc>>, env: Rc) -> String { - Rc::new({ - let mut __result = Vec::new(); - for child in children.iter().cloned() { - if (child.children.clone().len() as i64) == 0 { - let vname = authored_name(env.clone(), child.clone()); - if is_phantom_unit_variant_type_arg(env.clone(), vname.clone()) { - __result.push(v1_rt::concat( - v1_rt::concat( - v1_rt::concat( - rust_visibility_prefix(), - rust_items().struct_keyword.clone(), - ), - " ".to_string(), - ), - v1_rt::concat(vname, ";".to_string()), - )); - } - } - } - __result - }) - .join("\n") -} - -pub fn collect_phantom_zst_marker_names( - items: Rc>>, - env: Rc, -) -> Rc> { - Rc::new({ - let mut names: Vec = Vec::new(); - for item in items.iter().cloned() { - if is_type_def_item(item.clone()) - && item - .children - .clone() - .iter() - .all(|c| c.children.clone().len() as i64 == 0) - { - for child in item.children.clone().iter().cloned() { - if (child.children.clone().len() as i64) == 0 { - let vname = authored_name(env.clone(), child.clone()); - if is_phantom_unit_variant_type_arg(env.clone(), vname.clone()) - && !names.iter().any(|n| n == &vname) - { - names.push(vname); - } - } - } - } - } - names - }) + +pub fn apply_clone(expr: String) -> String { + apply_type_template1( + sharing_for_target(RenderTarget::Rust).clone_value.clone(), + expr, + ) } -pub fn emit_module_phantom_zst_markers(items: Rc>>, env: Rc) -> String { - Rc::new({ - let mut __result = Vec::new(); - for vname in collect_phantom_zst_marker_names(items, env.clone()) - .iter() - .cloned() - { - __result.push(v1_rt::concat( - v1_rt::concat( - v1_rt::concat( - rust_visibility_prefix(), - rust_items().struct_keyword.clone(), - ), - " ".to_string(), - ), - v1_rt::concat(vname, ";".to_string()), - )); - } - __result - }) - .join("\n") +pub fn apply_deref_clone(expr: String) -> String { + apply_type_template1( + sharing_for_target(RenderTarget::Rust).deref_clone.clone(), + expr, + ) +} + +pub fn apply_field_clone(expr: String, field: String) -> String { + apply_type_template2( + sharing_for_target(RenderTarget::Rust).field_clone.clone(), + expr, + field, + ) +} + +pub fn clone_iterator_suffix() -> String { + sharing_for_target(RenderTarget::Rust).clone_suffix.clone() } pub fn effective_variant_parent( @@ -10759,7 +11360,7 @@ pub fn effective_variant_parent( { let cached = match v1_rt::map_get(&emit_info.variant_to_enum.clone(), name.clone()) { Some(p) => { - if (p.clone().as_str() != "".to_string().as_str()) { + if (p.clone() != "".to_string()) { Some(p.clone()) } else { None @@ -10772,8 +11373,7 @@ pub fn effective_variant_parent( None => match resolved_type.as_deref().cloned() { Some(InferredNode::Resolved { node: rt, .. }) => { let rt_name = authored_name_at(source_indices, rt.clone()); - if (((rt.ident_span.clone() != None) - && (rt_name.clone().as_str() != name.clone().as_str())) + if (((rt.ident_span.clone() != None) && (rt_name.clone() != name.clone())) && variant_belongs_to_enum( emit_info.type_summaries.clone(), name.clone(), @@ -10800,14 +11400,10 @@ pub fn emit_var_ref( emit_info: Rc, source_indices: Rc>>, ) -> String { - if ((name.clone().as_str() == "none".to_string().as_str()) - || (name.clone().as_str() == "None".to_string().as_str())) - { + if ((name.clone() == "none".to_string()) || (name.clone() == "None".to_string())) { emit_keyword("null".to_string(), RenderTarget::Rust) } else { - if ((name.clone().as_str() == "true".to_string().as_str()) - || (name.clone().as_str() == "false".to_string().as_str())) - { + if ((name.clone() == "true".to_string()) || (name.clone() == "false".to_string())) { emit_keyword(name.clone(), RenderTarget::Rust) } else { { @@ -10823,9 +11419,9 @@ pub fn emit_var_ref( let ref_str = match variant_parent { Some(enum_name) => { let qualified = if (is_optional_variant_name(name.clone()) - && (enum_name.clone().as_str() == "Optional".to_string().as_str())) + && (enum_name.clone() == "Optional".to_string())) { - if (name.clone().as_str() == "Present".to_string().as_str()) { + if (name.clone() == "Present".to_string()) { "Some".to_string() } else { "None".to_string() @@ -10915,14 +11511,10 @@ pub fn emit_typed_expr_base( .. } => { let n = expr_var_name_at(texpr.clone(), si.clone()); - if ((n.clone().as_str() == "none".to_string().as_str()) - || (n.clone().as_str() == "None".to_string().as_str())) - { + if ((n.clone() == "none".to_string()) || (n.clone() == "None".to_string())) { emit_keyword("null".to_string(), RenderTarget::Rust) } else { - if ((n.clone().as_str() == "true".to_string().as_str()) - || (n.clone().as_str() == "false".to_string().as_str())) - { + if ((n.clone() == "true".to_string()) || (n.clone() == "false".to_string())) { emit_keyword(n.clone(), RenderTarget::Rust) } else { { @@ -10936,10 +11528,9 @@ pub fn emit_typed_expr_base( match variant_parent { Some(enum_name) => { let qualified = if (is_optional_variant_name(n.clone()) - && (enum_name.clone().as_str() - == "Optional".to_string().as_str())) + && (enum_name.clone() == "Optional".to_string())) { - if (n.clone().as_str() == "Present".to_string().as_str()) { + if (n.clone() == "Present".to_string()) { "Some".to_string() } else { "None".to_string() @@ -10988,6 +11579,35 @@ pub fn emit_typed_expr_base( } } +pub fn field_access_field_is_boxed( + base: Rc, + field: String, + scope: Rc, + shared_types: Rc>, + emit_info: Rc, +) -> bool { + { + let base_struct = expand_type_for_field_access( + resolved_type(base), + scope.type_env.clone(), + scope.module_name.clone(), + ); + match find_child_named( + base_struct, + field, + scope.type_env.clone().source_indices.clone(), + ) { + Some(field_child) => needs_box_wrapping( + resolved_type(field_child.clone()), + emit_info.recursive_type_set.clone(), + shared_types, + scope.type_env.clone().source_indices.clone(), + ), + None => false, + } + } +} + pub fn emit_typed_field_access( base: Rc, field: String, @@ -11050,9 +11670,7 @@ pub fn emit_typed_field_access( if (authored_name_at( scope.type_env.clone().source_indices.clone(), pair.1.clone(), - ) - .as_str() - == field.clone().as_str()) + ) == field.clone()) { __result.push(pair); } @@ -11122,19 +11740,39 @@ pub fn emit_typed_field_access( } _ => false, }; - if base_is_owned { + let field_is_boxed = field_access_field_is_boxed( + base.clone(), + field.clone(), + scope.clone(), + shared_types.clone(), + emit_info.clone(), + ); + if field_is_boxed { v1_rt::concat( - v1_rt::concat(base_str, ".".to_string()), - emit_ident(field.clone(), RenderTarget::Rust), + v1_rt::concat( + v1_rt::concat( + v1_rt::concat("(*".to_string(), base_str), + ".".to_string(), + ), + emit_ident(field.clone(), RenderTarget::Rust), + ), + ").clone()".to_string(), ) } else { - apply_type_template1( - sharing.clone_value.clone(), + if base_is_owned { v1_rt::concat( v1_rt::concat(base_str, ".".to_string()), emit_ident(field.clone(), RenderTarget::Rust), - ), - ) + ) + } else { + apply_type_template1( + sharing.clone_value.clone(), + v1_rt::concat( + v1_rt::concat(base_str, ".".to_string()), + emit_ident(field.clone(), RenderTarget::Rust), + ), + ) + } } } }, @@ -11189,7 +11827,7 @@ pub fn type_needs_rc_seen( } else { let canonical = authored_name_at(source_indices.clone(), normed.clone()); if (normed.inferred.clone() != None) { - let next_seen = if (canonical.clone().as_str() == "".to_string().as_str()) { + let next_seen = if (canonical.clone() == "".to_string()) { seen.clone() } else { v1_rt::rc_map_insert(seen.clone(), canonical.clone(), true) @@ -11202,12 +11840,12 @@ pub fn type_needs_rc_seen( continue; } } else { - if ((canonical.clone().as_str() != "".to_string().as_str()) + if ((canonical.clone() != "".to_string()) && emit_map_has(seen.clone(), canonical.clone())) { break false; } else { - let next_seen = if (canonical.clone().as_str() == "".to_string().as_str()) { + let next_seen = if (canonical.clone() == "".to_string()) { seen.clone() } else { v1_rt::rc_map_insert(seen.clone(), canonical.clone(), true) @@ -11245,6 +11883,7 @@ pub fn rust_runtime_bridge_name(function_name: String) -> String { pub fn rust_empty_map_value_type_str( map_type: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { match map_type.children.clone().get(1 as usize).cloned() { @@ -11252,9 +11891,10 @@ pub fn rust_empty_map_value_type_str( let rendered = render_rust_type( child_type_node(value_child.clone()), shared_types, + corpus_repr, source_indices, ); - if (rendered.clone().as_str() == "".to_string().as_str()) { + if (rendered.clone() == "".to_string()) { "".to_string() } else { rendered.clone() @@ -11267,6 +11907,7 @@ pub fn rust_empty_map_value_type_str( pub fn rust_empty_map_kv_type_str( map_type: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { { @@ -11274,6 +11915,7 @@ pub fn rust_empty_map_kv_type_str( Some(key_child) => render_rust_type( child_type_node(key_child.clone()), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), ), None => "".to_string(), @@ -11281,11 +11923,10 @@ pub fn rust_empty_map_kv_type_str( let val_str = rust_empty_map_value_type_str( map_type.clone(), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), ); - if ((key_str.clone().as_str() != "".to_string().as_str()) - && (val_str.clone().as_str() != "".to_string().as_str())) - { + if ((key_str.clone() != "".to_string()) && (val_str.clone() != "".to_string())) { v1_rt::concat( v1_rt::concat(key_str.clone(), ", ".to_string()), val_str.clone(), @@ -11313,12 +11954,12 @@ pub fn rust_btree_set_element_ord_eligible( ) -> bool { { let elem_name = authored_name_at(source_indices.clone(), elem_node.clone()); - (((((((elem_name.clone().as_str() == "String".to_string().as_str()) - || (elem_name.clone().as_str() == "Int".to_string().as_str())) - || (elem_name.clone().as_str() == "Bool".to_string().as_str())) - || (elem_name.clone().as_str() == "Unit".to_string().as_str())) - || (elem_name.clone().as_str() == "Secret".to_string().as_str())) - || (elem_name.clone().as_str() == "Bytes".to_string().as_str())) + (((((((elem_name.clone() == "String".to_string()) + || (elem_name.clone() == "Int".to_string())) + || (elem_name.clone() == "Bool".to_string())) + || (elem_name.clone() == "Unit".to_string())) + || (elem_name.clone() == "Secret".to_string())) + || (elem_name.clone() == "Bytes".to_string())) || rust_nominal_ord_type_eligible(elem_node.clone(), source_indices.clone())) } } @@ -11391,7 +12032,7 @@ pub fn emit_rust_empty_set_expr( shared_types, source_indices.clone(), ); - if (elem_str.clone().as_str() != "".to_string().as_str()) { + if (elem_str.clone() != "".to_string()) { v1_rt::concat( v1_rt::concat( "v1_rt::rc_empty_set::<".to_string(), @@ -11694,36 +12335,70 @@ pub fn emit_rust_expr_record_lit( scope.type_env.clone().source_indices.clone(), ); let fs = expr.children.clone(); + let si = scope.type_env.clone().source_indices.clone(); + let resolved_rt = resolved_type(expr.clone()); + let expanded_rt = expand_type_for_field_access( + resolved_rt, + scope.type_env.clone(), + scope.module_name.clone(), + ); + let variant_name = match tn.clone() { + Some(n) => n.clone(), + None => "".to_string(), + }; + let peeled_type_name = if (((parent_enum.clone() == None) + && (expanded_rt.connective.clone() == Connective::Conj)) + && (expanded_rt.ident_span.clone() != None)) + { + { + let concrete = authored_name_at(si.clone(), expanded_rt.clone()); + if ((concrete.clone() != "".to_string()) + && (concrete.clone() != variant_name.clone())) + { + Some(concrete.clone()) + } else { + tn.clone() + } + } + } else { + tn.clone() + }; let raw = emit_typed_record_lit( - tn.clone(), + peeled_type_name, fs, parent_enum.clone(), - resolved_type(expr.clone()), + expanded_rt.clone(), registry, scope.clone(), depth, shared_types.clone(), emit_info.clone(), ); - let si = scope.type_env.clone().source_indices.clone(); - let variant_name = match tn.clone() { - Some(n) => n.clone(), - None => "".to_string(), - }; let rc_name = match parent_enum.clone() { Some(en) => en.clone(), None => match contextual_variant_parent( variant_name.clone(), parent_enum.clone(), - resolved_type(expr.clone()), + expanded_rt.clone(), emit_info.clone(), si.clone(), ) { - Some(p) => p, - None => variant_name.clone(), + Some(p) => p.clone(), + None => { + let expanded_name = authored_name_at(si.clone(), expanded_rt.clone()); + if ((((expanded_rt.ident_span.clone() != None) + && (expanded_name.clone() != "".to_string())) + && (expanded_name.clone() != variant_name.clone())) + && v1_rt::set_contains(&shared_types, expanded_name.clone())) + { + expanded_name.clone() + } else { + variant_name.clone() + } + } }, }; - if ((rc_name.clone().as_str() != "".to_string().as_str()) + if ((rc_name.clone() != "".to_string()) && v1_rt::set_contains(&shared_types, rc_name.clone())) { v1_rt::concat(v1_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) @@ -12158,7 +12833,7 @@ pub fn contextual_variant_parent( None => { let rt_name = authored_name_at(source_indices, resolved_type.clone()); if (((resolved_type.ident_span.clone() != None) - && (rt_name.clone().as_str() != variant_name.clone().as_str())) + && (rt_name.clone() != variant_name.clone())) && variant_belongs_to_enum( emit_info.type_summaries.clone(), variant_name.clone(), @@ -12201,7 +12876,7 @@ pub fn emit_discriminant_call_lowering( scope.clone(), depth, shared_types.clone(), - emit_info, + emit_info.clone(), 1024, ); let ty_name = @@ -12263,7 +12938,7 @@ pub fn emit_discriminant_call_lowering( ), "\"".to_string(), ), - scope.type_env.clone().source_indices.clone(), + emit_info.corpus_repr.clone(), ), ), ",".to_string(), @@ -12300,7 +12975,7 @@ pub fn emit_discriminant_call_lowering( v1_rt::concat("\"".to_string(), ty_name.clone()), "\"".to_string(), ), - scope.type_env.clone().source_indices.clone(), + emit_info.corpus_repr.clone(), ) } } @@ -12309,7 +12984,7 @@ pub fn emit_discriminant_call_lowering( v1_rt::concat("\"".to_string(), ty_name.clone()), "\"".to_string(), ), - scope.type_env.clone().source_indices.clone(), + emit_info.corpus_repr.clone(), ), } } @@ -12326,15 +13001,16 @@ pub fn emit_typed_call_expr( emit_info: Rc, ) -> String { { - let call_str = if (func.clone().as_str() == "empty_map".to_string().as_str()) { + let call_str = if (func.clone() == "empty_map".to_string()) { match inferred.as_deref().cloned() { Some(InferredNode::Resolved { node: ret_type, .. }) => { let kv_type_str = rust_empty_map_kv_type_str( ret_type.clone(), shared_types, + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ); - if (kv_type_str.clone().as_str() != "".to_string().as_str()) { + if (kv_type_str.clone() != "".to_string()) { v1_rt::concat( v1_rt::concat( "v1_rt::rc_empty_map::<".to_string(), @@ -12351,7 +13027,7 @@ pub fn emit_typed_call_expr( .to_string(), } } else { - if (func.clone().as_str() == "empty_set".to_string().as_str()) { + if (func.clone() == "empty_set".to_string()) { match inferred.as_deref().cloned() { Some(InferredNode::Resolved { node: ret_type, .. }) => { emit_rust_empty_set_expr( @@ -12395,7 +13071,7 @@ pub fn emit_typed_call( emit_info: Rc, ) -> String { { - if (func.clone().as_str() == "get".to_string().as_str()) { + if (func.clone() == "get".to_string()) { { let get_args = order_typed_call_args(args.clone(), func.clone(), scope.clone()); let get_list = get_args.clone().first().cloned(); @@ -12439,7 +13115,7 @@ pub fn emit_typed_call( return get_result; } } - if (func.clone().as_str() == "with".to_string().as_str()) { + if (func.clone() == "with".to_string()) { { let with_args = order_typed_call_args(args.clone(), func.clone(), scope.clone()); if ((with_args.clone().len() as i64) == 0) { @@ -12537,7 +13213,7 @@ pub fn emit_typed_call( } } } - if (func.clone().as_str() == "to_string".to_string().as_str()) { + if (func.clone() == "to_string".to_string()) { { let to_string_args = order_typed_call_args(args.clone(), func.clone(), scope.clone()); @@ -12558,45 +13234,24 @@ pub fn emit_typed_call( ), ").to_string()".to_string(), ), - scope.type_env.clone().source_indices.clone(), + emit_info.corpus_repr.clone(), ), None => "compile_error!(\"to_string call missing value argument\")".to_string(), }; return ts_result; } } - if (func.clone().as_str() == "utf8_decode_bytes".to_string().as_str()) { + if (func.clone() == "utf8_decode_bytes".to_string()) { { let decode_args = order_typed_call_args(args.clone(), func.clone(), scope.clone()); let decode_result = match decode_args.first().cloned() { - Some(value_arg) => v1_rt::concat( - v1_rt::concat( - v1_rt::concat( - "String::from_utf8(".to_string(), - emit_typed_expr( - arg_value(value_arg.clone()), - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - ), - ".clone()).map_err(|e| format!(\"invalid UTF-8 in access payload: {e}\"))?" - .to_string(), - ), - "".to_string(), - ), - None => { - "compile_error!(\"utf8_decode_bytes call missing value argument\")" - .to_string() - } - }; + Some(value_arg) => v1_rt::concat(v1_rt::concat("String::from_utf8(".to_string(), emit_typed_expr(arg_value(value_arg.clone()), registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone(), 1024)), ".clone()).map_err(|e| format!(\"invalid UTF-8 in access payload: {}\", e))?".to_string()), + None => "compile_error!(\"utf8_decode_bytes call missing value argument\")".to_string(), +}; return decode_result; } } - if (func.clone().as_str() == "discriminant".to_string().as_str()) { + if (func.clone() == "discriminant".to_string()) { { let disc_args = order_typed_call_args(args.clone(), func.clone(), scope.clone()); let disc_result = match disc_args.first().cloned() { @@ -12615,10 +13270,10 @@ pub fn emit_typed_call( return disc_result; } } - let collection_scope = if ((((func.clone().as_str() == "map".to_string().as_str()) - || (func.clone().as_str() == "filter".to_string().as_str())) - || (func.clone().as_str() == "flat_map".to_string().as_str())) - || (func.clone().as_str() == "fold".to_string().as_str())) + let collection_scope = if ((((func.clone() == "map".to_string()) + || (func.clone() == "filter".to_string())) + || (func.clone() == "flat_map".to_string())) + || (func.clone() == "fold".to_string())) { { let call_args = order_typed_call_args(args.clone(), func.clone(), scope.clone()); @@ -12793,8 +13448,7 @@ pub fn emit_typed_call( } else { func_ident }; - let call_str = if ((is_rt.clone() - && (func.clone().as_str() == "concat".to_string().as_str())) + let call_str = if ((is_rt.clone() && (func.clone() == "concat".to_string())) && ((all_args.clone().len() as i64) > 2)) { emit_nested_rt_concat(all_args.clone(), "".to_string(), shared_types.clone()) @@ -12850,12 +13504,11 @@ pub fn fill_default_args( let is_provided = { let mut __found = false; for n in provided_names.clone().iter().cloned() { - if (n.clone().as_str() + if (n.clone() == param_node_name_at( p.clone(), scope.type_env.clone().source_indices.clone(), - ) - .as_str()) + )) { __found = true; break; @@ -12968,7 +13621,7 @@ pub fn emit_nested_rt_concat( break acc.clone(); } Some(arg) => { - let next_acc = if (acc.clone().as_str() == "".to_string().as_str()) { + let next_acc = if (acc.clone() == "".to_string()) { arg.clone() } else { v1_rt::concat( @@ -13168,6 +13821,7 @@ pub fn emit_typed_slice( pub fn collection_element_type( receiver_type: Option>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { match receiver_type.as_deref().cloned() { @@ -13193,6 +13847,7 @@ pub fn collection_element_type( render_rust_type( elem_node.clone(), shared_types, + corpus_repr, source_indices.clone(), ) } @@ -13249,6 +13904,7 @@ pub fn lambda_param_type_strs( param_nodes: Rc>>, fallback_types: Rc>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> Rc> { Rc::new({ @@ -13288,6 +13944,7 @@ pub fn lambda_param_type_strs( Some(render_rust_type( param_type.clone(), shared_types.clone(), + corpus_repr.clone(), source_indices.clone(), )) } @@ -13351,6 +14008,7 @@ pub fn emit_typed_collection_lambda( pn.clone(), Rc::new(vec![elem_type_str]), shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ); let params_str = param_strs.join(&", ".to_string()); @@ -13361,7 +14019,7 @@ pub fn emit_typed_collection_lambda( lambda_scope, depth, shared_types.clone(), - emit_info, + emit_info.clone(), 1024, ); v1_rt::concat( @@ -13375,7 +14033,7 @@ pub fn emit_typed_collection_lambda( scope.clone(), depth, shared_types.clone(), - emit_info, + emit_info.clone(), 1024, ), } @@ -13407,10 +14065,9 @@ pub fn emit_typed_fold_lambda( .skip(1 as usize) .collect::>(), ); - let safe_acc_type = if (((acc_type_str.clone().as_str() - == "Rc>".to_string().as_str()) - || (acc_type_str.clone().as_str() == "Vec<()>".to_string().as_str())) - || (acc_type_str.clone().as_str() == "Option<()>".to_string().as_str())) + let safe_acc_type = if (((acc_type_str.clone() == "Rc>".to_string()) + || (acc_type_str.clone() == "Vec<()>".to_string())) + || (acc_type_str.clone() == "Option<()>".to_string())) { "_".to_string() } else { @@ -13442,6 +14099,7 @@ pub fn emit_typed_fold_lambda( Rc::new(vec![]), fallback_types, shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ); let params_str = param_strs.join(&", ".to_string()); @@ -13459,7 +14117,7 @@ pub fn emit_typed_fold_lambda( Some(n) => n.clone(), None => "".to_string(), }; - let needs_unwrap = ((acc_name.clone().as_str() != "".to_string().as_str()) + let needs_unwrap = ((acc_name.clone() != "".to_string()) && v1_rt::set_contains(&emit_info.owned_bindings.clone(), acc_name.clone())); if needs_unwrap { { @@ -13531,6 +14189,7 @@ pub fn emit_rust_fold_method_call( let elem_type_str = collection_element_type( receiver.inferred.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ); let contextual_acc_type = match result_type.as_deref().cloned() { @@ -13682,6 +14341,7 @@ pub fn emit_rust_fold_method_call( ), read_only_params_index: emit_info.read_only_params_index.clone(), read_only_params: emit_info.read_only_params.clone(), + corpus_repr: emit_info.corpus_repr.clone(), }), None => emit_info.clone(), } @@ -13714,6 +14374,7 @@ pub fn emit_rust_fold_method_call( owned_bindings: emit_info.owned_bindings.clone(), read_only_params_index: emit_info.read_only_params_index.clone(), read_only_params: emit_info.read_only_params.clone(), + corpus_repr: emit_info.corpus_repr.clone(), }), None => emit_info.clone(), } @@ -13727,6 +14388,7 @@ pub fn emit_rust_fold_method_call( let acc_type_str = render_rust_type( acc_type_node.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ); let acc_type_is_type_var = if (acc_type_node.inferred.clone() != None) { @@ -13787,18 +14449,19 @@ pub fn emit_rust_fold_method_call( arg_value(init_arg.clone()), scope.type_env.clone().source_indices.clone(), ); - if ((((init_func.clone().as_str() == "empty_map".to_string().as_str()) - && (acc_type_str.clone().as_str() != "_".to_string().as_str())) - && (acc_type_str.clone().as_str() != "".to_string().as_str())) + if ((((init_func.clone() == "empty_map".to_string()) + && (acc_type_str.clone() != "_".to_string())) + && (acc_type_str.clone() != "".to_string())) && !acc_has_unit_child.clone()) { { let kv_type_str = rust_empty_map_kv_type_str( acc_type_node.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ); - if (kv_type_str.clone().as_str() != "".to_string().as_str()) { + if (kv_type_str.clone() != "".to_string()) { v1_rt::concat( v1_rt::concat( "v1_rt::rc_empty_map::<".to_string(), @@ -13811,13 +14474,12 @@ pub fn emit_rust_fold_method_call( } } } else { - if (init_func.clone().as_str() == "empty_map".to_string().as_str()) { + if (init_func.clone() == "empty_map".to_string()) { "Rc::new(HashMap::new()) /* BRIDGE: fold empty_map accumulator type unresolved */".to_string() } else { - if ((((init_func.clone().as_str() - == "empty_set".to_string().as_str()) - && (acc_type_str.clone().as_str() != "_".to_string().as_str())) - && (acc_type_str.clone().as_str() != "".to_string().as_str())) + if ((((init_func.clone() == "empty_set".to_string()) + && (acc_type_str.clone() != "_".to_string())) + && (acc_type_str.clone() != "".to_string())) && !acc_has_unit_child.clone()) { emit_rust_empty_set_expr( @@ -13826,8 +14488,7 @@ pub fn emit_rust_fold_method_call( scope.type_env.clone().source_indices.clone(), ) } else { - if (init_func.clone().as_str() == "empty_set".to_string().as_str()) - { + if (init_func.clone() == "empty_set".to_string()) { "v1_rt::rc_empty_set::<_>()".to_string() } else { emit_typed_expr( @@ -13924,6 +14585,7 @@ pub fn emit_rust_sort_by_method_call( render_rust_type( elem.clone(), shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ) } else { @@ -13948,7 +14610,7 @@ pub fn emit_rust_sort_by_method_call( let iter_str = apply_type_template1(sharing.iter_owned.clone(), recv_str); let a_clone = apply_type_template1(sharing.clone_value.clone(), "a".to_string()); let b_clone = apply_type_template1(sharing.clone_value.clone(), "b".to_string()); - if (elem_type_str.clone().as_str() == "_".to_string().as_str()) { + if (elem_type_str.clone() == "_".to_string()) { v1_rt::concat(v1_rt::concat("Rc::new({ let mut __sorted: Vec<_> = ".to_string(), iter_str), ".collect(); __sorted.sort_by(|a, b| { a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal) }); __sorted })".to_string()) } else { 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("Rc::new({ let mut __sorted: Vec<_> = ".to_string(), iter_str), ".collect(); __sorted.sort_by(|a: &".to_string()), elem_type_str.clone()), ", b: &".to_string()), elem_type_str.clone()), "| { let __ka = (".to_string()), sort_key_fn.clone()), ")(".to_string()), a_clone), "); let __kb = (".to_string()), sort_key_fn.clone()), ")(".to_string()), b_clone), "); __ka.partial_cmp(&__kb).unwrap_or(std::cmp::Ordering::Equal) }); __sorted })".to_string()) @@ -14435,9 +15097,7 @@ pub fn emit_rust_first_method_call( if (expr_method_name_at( receiver.clone(), scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == "skip".to_string().as_str()) + ) == "skip".to_string()) { { let skip_recv = method_receiver(receiver.clone()); @@ -14675,9 +15335,7 @@ pub fn emit_typed_method_call( if (coerce_primitive_type( RenderTarget::Rust, authored_name_at(si.clone(), param_node_type_expr(p.clone())), - ) - .as_str() - == "serde_json::Value".to_string().as_str()) + ) == "serde_json::Value".to_string()) { __result.push(p); } @@ -14774,7 +15432,7 @@ pub fn emit_typed_method_call( scope.type_env.clone().source_indices.clone(), method_def.clone(), ); - if (method_name.clone().as_str() == "fold".to_string().as_str()) { + if (method_name.clone() == "fold".to_string()) { emit_rust_fold_method_call( method_call_node, fold_accumulator_type.clone(), @@ -14788,7 +15446,7 @@ pub fn emit_typed_method_call( emit_info.clone(), ) } else { - if (method_name.clone().as_str() == "sort_by".to_string().as_str()) { + if (method_name.clone() == "sort_by".to_string()) { emit_rust_sort_by_method_call( receiver.clone(), args.clone(), @@ -14799,7 +15457,7 @@ pub fn emit_typed_method_call( emit_info.clone(), ) } else { - if (method_name.clone().as_str() == "map".to_string().as_str()) { + if (method_name.clone() == "map".to_string()) { emit_rust_map_method_call( receiver.clone(), args.clone(), @@ -14813,9 +15471,7 @@ pub fn emit_typed_method_call( match Rc::new({ let mut __result = Vec::new(); for s in rust_higher_order_methods().iter().cloned() { - if (s.method_name.clone().as_str() - == method_name.clone().as_str()) - { + if (s.method_name.clone() == method_name.clone()) { __result.push(s); } } @@ -14835,8 +15491,7 @@ pub fn emit_typed_method_call( emit_info.clone(), ), None => { - if (method_name.clone().as_str() == "get".to_string().as_str()) - { + if (method_name.clone() == "get".to_string()) { emit_rust_get_method_call( receiver.clone(), args.clone(), @@ -14847,9 +15502,7 @@ pub fn emit_typed_method_call( emit_info.clone(), ) } else { - if (method_name.clone().as_str() - == "with".to_string().as_str()) - { + if (method_name.clone() == "with".to_string()) { emit_rust_with_method_call( receiver.clone(), args.clone(), @@ -14860,8 +15513,8 @@ pub fn emit_typed_method_call( emit_info.clone(), ) } else { - if (method_name.clone().as_str() - == "string_contains".to_string().as_str()) + if (method_name.clone() + == "string_contains".to_string()) { emit_rust_generic_method_call( "string_contains".to_string(), @@ -14875,9 +15528,7 @@ pub fn emit_typed_method_call( emit_info.clone(), ) } else { - if (method_name.clone().as_str() - == "concat".to_string().as_str()) - { + if (method_name.clone() == "concat".to_string()) { { let recv_str = emit_typed_expr( receiver.clone(), @@ -14914,8 +15565,7 @@ pub fn emit_typed_method_call( ) } } else { - if (method_name.clone().as_str() - == "first".to_string().as_str()) + if (method_name.clone() == "first".to_string()) { emit_rust_first_method_call( receiver.clone(), @@ -15306,8 +15956,8 @@ pub fn emit_typed_match_arm( ), None => "".to_string(), }; - let guard_str = if ((field_guards.clone().as_str() != "".to_string().as_str()) - && (arm_guard_str.clone().as_str() != "".to_string().as_str())) + let guard_str = if ((field_guards.clone() != "".to_string()) + && (arm_guard_str.clone() != "".to_string())) { v1_rt::concat( v1_rt::concat( @@ -15317,10 +15967,10 @@ pub fn emit_typed_match_arm( arm_guard_str.clone(), ) } else { - if (field_guards.clone().as_str() != "".to_string().as_str()) { + if (field_guards.clone() != "".to_string()) { v1_rt::concat(" if ".to_string(), field_guards.clone()) } else { - if (arm_guard_str.clone().as_str() != "".to_string().as_str()) { + if (arm_guard_str.clone() != "".to_string()) { v1_rt::concat(" if ".to_string(), arm_guard_str.clone()) } else { "".to_string() @@ -15582,14 +16232,13 @@ pub fn wrap_rust_record_field_value( field_name: String, ) -> String { { - let is_bounded_lattice_field = - (struct_name.clone().as_str() == "BoundedLattice".to_string().as_str()); + let is_bounded_lattice_field = (struct_name.clone() == "BoundedLattice".to_string()); if rust_record_field_needs_fn_rc(scope.clone(), struct_name.clone(), field_name.clone()) { v1_rt::concat(v1_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) } else { if (is_bounded_lattice_field.clone() - && ((field_name.clone().as_str() == "meet".to_string().as_str()) - || (field_name.clone().as_str() == "join".to_string().as_str()))) + && ((field_name.clone() == "meet".to_string()) + || (field_name.clone() == "join".to_string()))) { v1_rt::concat(v1_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) } else { @@ -15603,8 +16252,8 @@ pub fn wrap_rust_record_field_value( v1_rt::concat(v1_rt::concat("Box::new(".to_string(), raw), ")".to_string()) } else { if (is_bounded_lattice_field.clone() - && ((field_name.clone().as_str() == "top".to_string().as_str()) - || (field_name.clone().as_str() == "bottom".to_string().as_str()))) + && ((field_name.clone() == "top".to_string()) + || (field_name.clone() == "bottom".to_string()))) { v1_rt::concat(v1_rt::concat("Box::new(".to_string(), raw), ")".to_string()) } else { @@ -15635,16 +16284,13 @@ pub fn is_already_optional( binding_kind: binding_kind, .. } => { - if (((n.clone().as_str() == "Present".to_string().as_str()) - || (n.clone().as_str() == "Absent".to_string().as_str())) + if (((n.clone() == "Present".to_string()) || (n.clone() == "Absent".to_string())) && (variant_parent_from_binding_kind(binding_kind.clone()).as_deref() == Some("Optional".to_string()).as_deref())) { true } else { - if ((n.clone().as_str() == "none".to_string().as_str()) - || (n.clone().as_str() == "None".to_string().as_str())) - { + if ((n.clone() == "none".to_string()) || (n.clone() == "None".to_string())) { true } else { match texpr.inferred.clone().as_deref().cloned() { @@ -15668,8 +16314,8 @@ pub fn is_already_optional( } => match tn { Some(name) => { ((parent.clone().as_deref() == Some("Optional".to_string()).as_deref()) - && ((name.clone().as_str() == "Present".to_string().as_str()) - || (name.clone().as_str() == "Absent".to_string().as_str()))) + && ((name.clone() == "Present".to_string()) + || (name.clone() == "Absent".to_string()))) } None => false, }, @@ -15891,7 +16537,7 @@ pub fn emit_field_value_with_context( Some(en) => en.clone(), None => variant_name.clone(), }; - if ((rc_name.clone().as_str() != "".to_string().as_str()) + if ((rc_name.clone() != "".to_string()) && v1_rt::set_contains(&shared_types, rc_name.clone())) { v1_rt::concat(v1_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) @@ -16143,10 +16789,15 @@ pub fn emit_typed_record_lit( false }; let rt_name = authored_name_at(si.clone(), resolved_type.clone()); - if ((((resolved_type.ident_span.clone() != None) - && (rt_name.clone().as_str() != tn.clone().as_str())) + if (((((resolved_type.ident_span.clone() != None) + && (rt_name.clone() != tn.clone())) && !rt_is_type_var) - && (rt_name.clone().as_str() != "Error".to_string().as_str())) + && (rt_name.clone() != "Error".to_string())) + && variant_belongs_to_enum( + emit_info.type_summaries.clone(), + tn.clone(), + rt_name.clone(), + )) { Some(rt_name.clone()) } else { @@ -16158,7 +16809,7 @@ pub fn emit_typed_record_lit( && (is_optional_parent(parent_enum.clone()) || is_optional_parent(effective_parent.clone()))); let rust_tn = if optional_variant.clone() { - if (tn.clone().as_str() == "Present".to_string().as_str()) { + if (tn.clone() == "Present".to_string()) { "Some".to_string() } else { "None".to_string() @@ -16177,8 +16828,7 @@ pub fn emit_typed_record_lit( None => rust_tn, } }; - if ((optional_variant.clone() - && (tn.clone().as_str() == "Present".to_string().as_str())) + if ((optional_variant.clone() && (tn.clone() == "Present".to_string())) && ((fields.clone().len() as i64) == 1)) { match fields.clone().first().cloned() { @@ -16218,8 +16868,8 @@ pub fn emit_typed_record_lit( let is_positional_ctor = (((fields.clone().len() as i64) == 1) && match fields.clone().first().cloned() { Some(f) => { - (field_init_node_name_at(f.clone(), si.clone()).as_str() - == "0".to_string().as_str()) + (field_init_node_name_at(f.clone(), si.clone()) + == "0".to_string()) } None => false, }); @@ -16381,18 +17031,13 @@ pub fn emit_typed_record_lit( &ftm, fname.clone(), ) { - Some(ft) => { - match rust_zero_value( - ft.clone(), - scope - .type_env - .source_indices - .clone(), - ) { - Some(_) => true, - None => false, - } - } + Some(ft) => match rust_zero_value( + ft.clone(), + emit_info.corpus_repr.clone(), + ) { + Some(_) => true, + None => false, + }, None => false, }; (has_zv.clone() @@ -16416,10 +17061,7 @@ pub fn emit_typed_record_lit( Rc::new(vec![v1_rt::concat(v1_rt::concat(" ".to_string(), emit_ident(fname.clone(), RenderTarget::Rust)), ": None,".to_string())]) } else { match v1_rt::map_get(&ftm, fname.clone()) { - Some(ft) => match rust_zero_value( - ft.clone(), - scope.type_env.source_indices.clone(), - ) { + Some(ft) => match rust_zero_value(ft.clone(), emit_info.corpus_repr.clone()) { Some(zv) => Rc::new(vec![v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(" ".to_string(), emit_ident(fname.clone(), RenderTarget::Rust)), ": ".to_string()), zv.clone()), ",".to_string())]), None => Rc::new(vec![]), }, @@ -16435,7 +17077,48 @@ pub fn emit_typed_record_lit( } None => Rc::new(vec![]), }; - let all_field_strs = v1_rt::concat(field_strs, default_strs); + let phantom_strs = match lookup_type_by_name( + scope.type_env.clone(), + tn.clone(), + ) { + Some(struct_decl) => { + let is_struct = (struct_decl.connective.clone() + == Connective::Conj); + let pnames = Rc::new({ + let mut __result = Vec::new(); + for p in struct_decl.params.clone().iter().cloned() + { + __result.push(generic_param_name_at( + p.clone(), + si.clone(), + )); + } + __result + }); + let unused = struct_unused_param_names( + pnames, + struct_decl.children.clone(), + si.clone(), + ); + let has_unused = ((unused.len() as i64) > 0); + if (is_struct && has_unused) { + Rc::new(vec![v1_rt::concat( + v1_rt::concat( + " ".to_string(), + rust_phantom_field_name(), + ), + ": std::marker::PhantomData,".to_string(), + )]) + } else { + Rc::new(vec![]) + } + } + None => Rc::new(vec![]), + }; + let all_field_strs = v1_rt::concat( + v1_rt::concat(field_strs, default_strs), + phantom_strs, + ); let fields_str = all_field_strs.join(&"\n".to_string()); let raw = v1_rt::concat( v1_rt::concat( @@ -16455,18 +17138,15 @@ pub fn emit_typed_record_lit( } } -pub fn rust_zero_value( - type_name: String, - source_indices: Rc>>, -) -> Option { - if (type_name.clone().as_str() == "Int".to_string().as_str()) { +pub fn rust_zero_value(type_name: String, corpus_repr: RustCorpusRepr) -> Option { + if (type_name.clone() == "Int".to_string()) { Some("0".to_string()) } else { - if (type_name.clone().as_str() == "Bool".to_string().as_str()) { + if (type_name.clone() == "Bool".to_string()) { Some("false".to_string()) } else { - if (type_name.clone().as_str() == "String".to_string().as_str()) { - if rust_emit_faithful_text_carrier(source_indices) { + if (type_name.clone() == "String".to_string()) { + if corpus_repr_is_faithful(corpus_repr) { Some( "crate::v2_std_algebra::freemonoid_empty::()" .to_string(), @@ -16534,8 +17214,8 @@ pub fn emit_typed_bin_op( v1_rt::concat( "Some(".to_string(), emit_rust_dag_string_to_host_via_seam( - l_str.clone(), - scope.type_env.clone().source_indices.clone(), + l_str, + emit_info.corpus_repr.clone(), ), ), ")".to_string(), @@ -16548,8 +17228,8 @@ pub fn emit_typed_bin_op( v1_rt::concat( "Some(".to_string(), emit_rust_dag_string_to_host_via_seam( - r_str.clone(), - scope.type_env.clone().source_indices.clone(), + r_str, + emit_info.corpus_repr.clone(), ), ), ")".to_string(), @@ -16581,12 +17261,8 @@ pub fn emit_typed_bin_op( v1_rt::concat( "(".to_string(), emit_rust_dag_string_to_host_via_seam( - l_str.clone(), - scope - .type_env - .clone() - .source_indices - .clone(), + l_str, + emit_info.corpus_repr.clone(), ), ), " ".to_string(), @@ -16596,8 +17272,8 @@ pub fn emit_typed_bin_op( " ".to_string(), ), emit_rust_dag_string_to_host_via_seam( - r_str.clone(), - scope.type_env.clone().source_indices.clone(), + r_str, + emit_info.corpus_repr.clone(), ), ), ")".to_string(), @@ -16730,7 +17406,7 @@ pub fn emit_typed_string_interp( .iter() .cloned() { - if (a.clone().as_str() != "".to_string().as_str()) { + if (a.clone() != "".to_string()) { __result.push(a); } } @@ -16739,7 +17415,7 @@ pub fn emit_typed_string_interp( if ((args.clone().len() as i64) == 0) { emit_rust_host_to_dag_string_via_seam( v1_rt::concat(v1_rt::concat("\"".to_string(), fmt_str), "\"".to_string()), - scope.type_env.clone().source_indices.clone(), + emit_info.corpus_repr.clone(), ) } else { { @@ -16755,7 +17431,7 @@ pub fn emit_typed_string_interp( ), ")".to_string(), ), - scope.type_env.clone().source_indices.clone(), + emit_info.corpus_repr.clone(), ) } } @@ -16916,9 +17592,7 @@ pub fn emit_tco_init_stmt( if (param_node_name_at( p.clone(), scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == n.clone().as_str()) + ) == n.clone()) { __found = true; break; @@ -17272,9 +17946,7 @@ pub fn emit_rust_tco_let( if (param_node_name_at( p.clone(), frame.scope.clone().type_env.clone().source_indices.clone(), - ) - .as_str() - == n.clone().as_str()) + ) == n.clone()) { __found = true; break; @@ -17561,8 +18233,8 @@ pub fn emit_typed_tco_match_arm( ), None => "".to_string(), }; - let guard_str = if ((field_guards.clone().as_str() != "".to_string().as_str()) - && (arm_guard_str.clone().as_str() != "".to_string().as_str())) + let guard_str = if ((field_guards.clone() != "".to_string()) + && (arm_guard_str.clone() != "".to_string())) { v1_rt::concat( v1_rt::concat( @@ -17572,10 +18244,10 @@ pub fn emit_typed_tco_match_arm( arm_guard_str.clone(), ) } else { - if (field_guards.clone().as_str() != "".to_string().as_str()) { + if (field_guards.clone() != "".to_string()) { v1_rt::concat(" if ".to_string(), field_guards.clone()) } else { - if (arm_guard_str.clone().as_str() != "".to_string().as_str()) { + if (arm_guard_str.clone() != "".to_string()) { v1_rt::concat(" if ".to_string(), arm_guard_str.clone()) } else { "".to_string() @@ -17645,10 +18317,7 @@ pub fn expr_references_var( match (*node.expr_data.clone()).clone() { ExprData::ExprVar { binding_kind: _, .. - } => { - (expr_var_name_at(node.clone(), source_indices.clone()).as_str() - == var_name.clone().as_str()) - } + } => (expr_var_name_at(node.clone(), source_indices.clone()) == var_name.clone()), _ => { let mut __found = false; for c in node.children.clone().iter().cloned() { @@ -17835,6 +18504,7 @@ pub fn emit_service_def( item: Rc, registry: Rc>>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, ) -> String { { @@ -17854,6 +18524,7 @@ pub fn emit_service_def( op_children.clone(), registry, shared_types, + corpus_repr, env.clone(), item.clone(), ); @@ -17933,6 +18604,7 @@ pub fn emit_service_impl( op_children: Rc>>, registry: Rc>>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, service_item: Rc, ) -> String { @@ -17955,6 +18627,7 @@ pub fn emit_service_impl( registry.clone(), (depth.clone() + 1), shared_types.clone(), + corpus_repr.clone(), env.clone(), service_item.clone(), )); @@ -18020,7 +18693,7 @@ pub fn emit_service_new_method( }, None => "".to_string(), }; - let base_url_default = if (from_config.clone().as_str() != "".to_string().as_str()) { + let base_url_default = if (from_config.clone() != "".to_string()) { from_config.clone() } else { if fs.has_rest.clone() { @@ -18045,7 +18718,7 @@ pub fn emit_service_new_method( } else { "".to_string() }; - if (from_fallback.clone().as_str() != "".to_string().as_str()) { + if (from_fallback.clone() != "".to_string()) { from_fallback.clone() } else { "http://localhost".to_string() @@ -18113,7 +18786,7 @@ pub fn emit_auth_source_ctor( ) -> String { match (*source_expr.expr_data.clone()).clone() { ExprData::ExprRecordLit { .. } => match record_lit_type_name_at(source_expr.clone(), source_indices) { - Some(variant) => if (variant.clone().as_str() == "EnvVar".to_string().as_str()) { + Some(variant) => if (variant.clone() == "EnvVar".to_string()) { match source_expr.children.clone().first().cloned() { Some(fi) => match (*field_init_node_value(fi.clone()).expr_data.clone()).clone() { ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: env_name, .. } = value.as_ref() else { unreachable!() }; v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(" auth_token: std::env::var(\"".to_string(), env_name.clone()), "\").expect(\"missing credential: ".to_string()), env_name.clone()), "\"),\n".to_string()) }, @@ -18157,6 +18830,7 @@ pub fn emit_operation_method( registry: Rc>>, depth: i64, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, service_item: Rc, ) -> String { @@ -18177,15 +18851,17 @@ pub fn emit_operation_method( param_node_type_expr(p.clone()), Rc::new(vec![]), shared_types.clone(), + corpus_repr.clone(), env.source_indices.clone(), - env.clone(), + v1_rt::rc_empty_map::(), + env.clone().clone(), ), )); } __result }); let params_str = input_params.join(&", ".to_string()); - let all_params = if (params_str.clone().as_str() == "".to_string().as_str()) { + let all_params = if (params_str.clone() == "".to_string()) { "&self".to_string() } else { v1_rt::concat("&self, ".to_string(), params_str.clone()) @@ -18193,6 +18869,7 @@ pub fn emit_operation_method( let ret_type = render_rust_type( resolved_type(op_node.clone()), shared_types.clone(), + corpus_repr.clone(), env.source_indices.clone(), ); let eff_transport = effective_operation_transport(op_node.clone(), transport); @@ -18207,6 +18884,7 @@ pub fn emit_operation_method( op_node.clone(), env.source_indices.clone(), shared_types.clone(), + corpus_repr.clone(), env.clone(), ); let mock_props = Rc::new({ @@ -18230,6 +18908,7 @@ pub fn emit_operation_method( op_node.clone(), env.clone(), shared_types.clone(), + corpus_repr.clone(), ); let body = v1_rt::concat( v1_rt::concat( @@ -18311,6 +18990,7 @@ pub fn emit_dry_run_branch_from_props( op_node: Rc, env: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, ) -> String { { let log_line = v1_rt::concat( @@ -18348,7 +19028,7 @@ let prelude = match wire_opt.clone() { Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), _ => tn.clone(), }; -v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("let __rest_wire: ".to_string(), render_rust_type(wire_ty, shared_types, source_indices.clone())), " = serde_json::from_str(r#\"".to_string()), mock_json), "\"#)?;\n".to_string()) +v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("let __rest_wire: ".to_string(), render_rust_type(wire_ty, shared_types, corpus_repr.clone(), source_indices.clone())), " = serde_json::from_str(r#\"".to_string()), mock_json), "\"#)?;\n".to_string()) } }, None => v1_rt::concat(v1_rt::concat("let json_body: serde_json::Value = serde_json::from_str(r#\"".to_string(), mock_json), "\"#)?;\n".to_string()), @@ -18367,7 +19047,7 @@ let raw = match ch.inferred.clone().as_deref().cloned() { None => v1_rt::concat(v1_rt::concat("let ".to_string(), field_name.clone()), " = compile_error!(\"REST typed dry-run: response_200 wire type missing despite typed projection; illegal state\");\n".to_string()), } } else { - emit_json_value_extract(field_name.clone(), from_path.clone(), authored_name_at(source_indices.clone(), tn.clone()), source_indices.clone()) + emit_json_value_extract(field_name.clone(), from_path.clone(), authored_name_at(source_indices.clone(), tn.clone()), corpus_repr.clone(), source_indices.clone()) }, _ => v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("let ".to_string(), field_name.clone()), " = compile_error!(\"unresolved type for mock field: ".to_string()), ch_name.clone()), "\");".to_string()), }; @@ -18394,8 +19074,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::con v1_rt::concat( v1_rt::concat( log_line, - "\ncompile_error!(\"no mock data available for dry-run operation: " - .to_string(), + "\npanic!(\"no mock data available for dry-run operation: ".to_string(), ), op_name.clone(), ), @@ -18415,6 +19094,7 @@ pub fn emit_transport_call( op_node: Rc, source_indices: Rc>>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, ) -> String { if is_rest_transport(transport.clone(), source_indices.clone()) { @@ -18427,6 +19107,7 @@ pub fn emit_transport_call( op_node, source_indices.clone(), shared_types, + corpus_repr, env, ) } else { @@ -18438,6 +19119,7 @@ pub fn emit_transport_call( depth, inferred, op_node, + corpus_repr, source_indices.clone(), ) } else { @@ -18459,6 +19141,7 @@ pub fn emit_rest_call( op_node: Rc, source_indices: Rc>>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, ) -> String { { @@ -18473,7 +19156,11 @@ pub fn emit_rest_call( http_method, source_indices.clone(), ); - let query_line = emit_rest_query_line(transport.clone(), source_indices.clone()); + let query_line = emit_rest_query_line( + transport.clone(), + corpus_repr.clone(), + source_indices.clone(), + ); let body_line = emit_rest_body_line(transport.clone(), source_indices.clone()); let headers = transport_headers(transport.clone(), source_indices.clone()); let header_lines = Rc::new({ @@ -18506,6 +19193,7 @@ pub fn emit_rest_call( transport.clone(), source_indices.clone(), shared_types, + corpus_repr.clone(), env, ); let all_lines = Rc::new({ @@ -18520,7 +19208,7 @@ pub fn emit_rest_call( .iter() .cloned() { - if (l.clone().as_str() != "".to_string().as_str()) { + if (l.clone() != "".to_string()) { __result.push(l); } } @@ -18765,6 +19453,7 @@ v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::con pub fn emit_rest_query_line( transport: Rc, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { match transport_query(transport, source_indices.clone()) { @@ -18787,7 +19476,7 @@ pub fn emit_rest_query_line( RenderTarget::Rust, source_indices.clone(), ), - source_indices.clone(), + corpus_repr.clone(), ), ), ")".to_string(), @@ -18850,7 +19539,7 @@ pub fn has_response_prefix(name: String) -> bool { if (v1_rt::string_length(&name) < 9) { false } else { - (v1_rt::substring(&name, 0, 9).as_str() == "response_".to_string().as_str()) + (v1_rt::substring(&name, 0, 9) == "response_".to_string()) } } @@ -18861,8 +19550,8 @@ pub fn child_from_key( match Rc::new({ let mut __result = Vec::new(); for p in ch.properties.clone().iter().cloned() { - if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() - == "from_key".to_string().as_str()) + if (field_init_node_name_at(p.clone(), source_indices.clone()) + == "from_key".to_string()) { __result.push(p); } @@ -18916,8 +19605,8 @@ pub fn has_response_200_property( { let mut __found = false; for p in op_node.properties.clone().iter().cloned() { - if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() - == "response_200".to_string().as_str()) + if (field_init_node_name_at(p.clone(), source_indices.clone()) + == "response_200".to_string()) { __found = true; break; @@ -18935,8 +19624,8 @@ pub fn operation_response_200_resolved_type( match Rc::new({ let mut __result = Vec::new(); for p in op_node.properties.clone().iter().cloned() { - if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() - == "response_200".to_string().as_str()) + if (field_init_node_name_at(p.clone(), source_indices.clone()) + == "response_200".to_string()) { __result.push(p); } @@ -18955,7 +19644,7 @@ pub fn operation_response_200_resolved_type( source_indices.clone(), normalize_access_type_node(v.clone()), ); - if (type_name.clone().as_str() == "".to_string().as_str()) { + if (type_name.clone() == "".to_string()) { None } else { lookup_type_by_name(env, type_name.clone()) @@ -18973,7 +19662,7 @@ pub fn is_json_wire_declaration_type( ) -> bool { { let n = authored_name_at(source_indices, normalize_access_type_node(t)); - if (n.clone().as_str() == "Json".to_string().as_str()) { + if (n.clone() == "Json".to_string()) { true } else { { @@ -18984,7 +19673,7 @@ pub fn is_json_wire_declaration_type( .collect::>(), ); match parts.last().cloned() { - Some(last) => (last.clone().as_str() == "Json".to_string().as_str()), + Some(last) => (last.clone() == "Json".to_string()), None => false, } } @@ -19035,7 +19724,7 @@ pub fn wire_child_for_segment( Some(k) => k.clone(), None => authored.clone(), }; - (wire_key.clone().as_str() == seg.clone().as_str()) + (wire_key.clone() == seg.clone()) } { __result.push(ch); } @@ -19151,7 +19840,7 @@ pub fn emit_wire_struct_path_chain( .iter() .cloned() { - if (s.clone().as_str() != "".to_string().as_str()) { + if (s.clone() != "".to_string()) { __result.push(s); } } @@ -19217,6 +19906,7 @@ pub fn emit_json_value_extract( var_name: String, from_path: String, dag_type_name: String, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { { @@ -19238,9 +19928,8 @@ pub fn emit_json_value_extract( }) .join(&"/".to_string()); let pointer = v1_rt::concat("/".to_string(), escaped_path); - let is_dag_string = dag_type_name.as_str() == "String"; - let rust_type = coerce_primitive_type(RenderTarget::Rust, dag_type_name); - let accessor = if is_dag_string { + let rust_type = coerce_primitive_type(RenderTarget::Rust, dag_type_name.clone()); + let accessor = if (dag_type_name.clone() == "String".to_string()) { v1_rt::concat( v1_rt::concat( v1_rt::concat( @@ -19248,7 +19937,7 @@ pub fn emit_json_value_extract( ".and_then(|v| v.as_str()).map(|s| ".to_string(), emit_rust_host_to_dag_string_via_seam( "s.to_string()".to_string(), - source_indices.clone(), + corpus_repr, ), ), ").ok_or(\"missing field: ".to_string(), @@ -19258,7 +19947,7 @@ pub fn emit_json_value_extract( "\")?".to_string(), ) } else { - if (rust_type.clone().as_str() == "i64".to_string().as_str()) { + if (rust_type.clone() == "i64".to_string()) { v1_rt::concat( v1_rt::concat( ".and_then(|v| v.as_i64()).ok_or(\"missing field: ".to_string(), @@ -19267,7 +19956,7 @@ pub fn emit_json_value_extract( "\")?".to_string(), ) } else { - if (rust_type.clone().as_str() == "f64".to_string().as_str()) { + if (rust_type.clone() == "f64".to_string()) { v1_rt::concat( v1_rt::concat( ".and_then(|v| v.as_f64()).ok_or(\"missing field: ".to_string(), @@ -19276,7 +19965,7 @@ pub fn emit_json_value_extract( "\")?".to_string(), ) } else { - if (rust_type.clone().as_str() == "bool".to_string().as_str()) { + if (rust_type.clone() == "bool".to_string()) { v1_rt::concat( v1_rt::concat( ".and_then(|v| v.as_bool()).ok_or(\"missing field: ".to_string(), @@ -19313,6 +20002,7 @@ pub fn emit_from_key_extraction( op_node: Rc, source_indices: Rc>>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, ) -> String { { @@ -19350,6 +20040,7 @@ pub fn emit_from_key_extraction( render_rust_type( wire_ty, shared_types, + corpus_repr.clone(), source_indices.clone(), ), ), @@ -19379,7 +20070,7 @@ match ch.inferred.clone().as_deref().cloned() { None => v1_rt::concat(v1_rt::concat("let ".to_string(), field_name.clone()), " = compile_error!(\"REST typed response: response_200 wire type missing despite typed projection; illegal state\");\n".to_string()), } } else { - emit_json_value_extract(field_name.clone(), from_path.clone(), authored_name_at(source_indices.clone(), tn.clone()), source_indices.clone()) + emit_json_value_extract(field_name.clone(), from_path.clone(), authored_name_at(source_indices.clone(), tn.clone()), corpus_repr.clone(), source_indices.clone()) }, _ => v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("let ".to_string(), field_name.clone()), " = compile_error!(\"unresolved type for output field: ".to_string()), ch_name.clone()), "\");".to_string()), } @@ -19434,8 +20125,7 @@ pub fn emit_plain_response_body( { let is_text = match transport_response_format(transport, source_indices.clone()) { Some(fmt) => { - (authored_name_at(source_indices.clone(), fmt.clone()).as_str() - == "Text".to_string().as_str()) + (authored_name_at(source_indices.clone(), fmt.clone()) == "Text".to_string()) } None => false, }; @@ -19452,6 +20142,7 @@ pub fn emit_response_code_handling( transport: Rc, source_indices: Rc>>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, ) -> String { { @@ -19471,6 +20162,7 @@ pub fn emit_response_code_handling( op_node.clone(), source_indices.clone(), shared_types.clone(), + corpus_repr.clone(), env.clone(), ) } else { @@ -19488,6 +20180,7 @@ pub fn emit_response_code_handling( transport.clone(), source_indices.clone(), shared_types.clone(), + corpus_repr.clone(), env.clone(), )); } @@ -19519,21 +20212,22 @@ pub fn emit_response_arm( transport: Rc, source_indices: Rc>>, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, ) -> String { { let name = field_init_node_name_at(prop, source_indices.clone()); let code_str = v1_rt::substring(&name, 9, v1_rt::string_length(&name)); let is_success = if (v1_rt::string_length(&code_str) >= 1) { - (v1_rt::substring(&code_str, 0, 1).as_str() == "2".to_string().as_str()) + (v1_rt::substring(&code_str, 0, 1) == "2".to_string()) } else { false }; - let pattern = if (code_str.clone().as_str() == "nonzero".to_string().as_str()) { + let pattern = if (code_str.clone() == "nonzero".to_string()) { "_".to_string() } else { if ((v1_rt::string_length(&code_str) == 3) - && (v1_rt::substring(&code_str, 1, 3).as_str() == "xx".to_string().as_str())) + && (v1_rt::substring(&code_str, 1, 3) == "xx".to_string())) { { let prefix = v1_rt::substring(&code_str, 0, 1); @@ -19561,6 +20255,7 @@ pub fn emit_response_arm( op_node, source_indices.clone(), shared_types, + corpus_repr, env, ), ), @@ -19588,13 +20283,14 @@ pub fn has_exit_prefix(name: String) -> bool { if (v1_rt::string_length(&name) < 5) { false } else { - (v1_rt::substring(&name, 0, 5).as_str() == "exit_".to_string().as_str()) + (v1_rt::substring(&name, 0, 5) == "exit_".to_string()) } } pub fn emit_exit_code_handling( op_node: Rc, inferred: Rc, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { { @@ -19614,8 +20310,8 @@ pub fn emit_exit_code_handling( let has_nonzero = { let mut __found = false; for p in exit_props.clone().iter().cloned() { - if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() - == "exit_nonzero".to_string().as_str()) + if (field_init_node_name_at(p.clone(), source_indices.clone()) + == "exit_nonzero".to_string()) { __found = true; break; @@ -19629,6 +20325,7 @@ pub fn emit_exit_code_handling( __result.push(emit_exit_arm( p.clone(), inferred.clone(), + corpus_repr.clone(), source_indices.clone(), )); } @@ -19637,16 +20334,7 @@ pub fn emit_exit_code_handling( let default_arm = if has_nonzero { "".to_string() } else { - v1_rt::concat( - v1_rt::concat( - "\n _ => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(".to_string(), - emit_rust_host_to_dag_string_via_seam( - "stderr".to_string(), - source_indices.clone(), - ), - ), - ") },".to_string(), - ) + v1_rt::concat(v1_rt::concat("\n _ => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(".to_string(), emit_rust_host_to_dag_string_via_seam("stderr".to_string(), corpus_repr.clone())), ") },".to_string()) }; v1_rt::concat( v1_rt::concat( @@ -19669,17 +20357,18 @@ pub fn emit_exit_code_handling( pub fn emit_exit_arm( prop: Rc, inferred: Rc, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { { let name = field_init_node_name_at(prop, source_indices.clone()); let code_str = v1_rt::substring(&name, 5, v1_rt::string_length(&name)); - let pattern = if (code_str.clone().as_str() == "nonzero".to_string().as_str()) { + let pattern = if (code_str.clone() == "nonzero".to_string()) { "_".to_string() } else { code_str.clone() }; - let is_success = (code_str.clone().as_str() == "0".to_string().as_str()); + let is_success = (code_str.clone() == "0".to_string()); if is_success { v1_rt::concat( v1_rt::concat( @@ -19692,22 +20381,7 @@ pub fn emit_exit_arm( " },".to_string(), ) } else { - v1_rt::concat( - v1_rt::concat( - v1_rt::concat( - v1_rt::concat( - v1_rt::concat(" ".to_string(), pattern), - " => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(".to_string(), - ), - emit_rust_host_to_dag_string_via_seam( - "stderr".to_string(), - source_indices.clone(), - ), - ), - ") },".to_string(), - ), - "".to_string(), - ) + v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(" ".to_string(), pattern), " => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(".to_string()), emit_rust_host_to_dag_string_via_seam("stderr".to_string(), corpus_repr)), ") },".to_string()) } } } @@ -19719,6 +20393,7 @@ pub fn emit_shell_call( depth: i64, inferred: Rc, op_node: Rc, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { { @@ -19763,6 +20438,7 @@ pub fn emit_shell_call( emit_shell_argv_element( first_arg.clone(), optional_params.clone(), + corpus_repr.clone(), source_indices.clone(), ), ), @@ -19804,6 +20480,7 @@ pub fn emit_shell_call( emit_shell_argv_element( arg.clone(), optional_params.clone(), + corpus_repr.clone(), source_indices.clone(), ), ), @@ -19864,8 +20541,12 @@ pub fn emit_shell_call( let wait_line = "let output = output.wait_with_output()?;".to_string(); let check_line = "let stdout = String::from_utf8_lossy(&output.stdout).to_string();".to_string(); - let return_line = - emit_exit_code_handling(op_node.clone(), inferred, source_indices.clone()); + let return_line = emit_exit_code_handling( + op_node.clone(), + inferred, + corpus_repr.clone(), + source_indices.clone(), + ); let all_lines = v1_rt::concat( v1_rt::concat(v1_rt::concat(Rc::new(vec![cmd_line]), arg_lines), env_lines), Rc::new(vec![ @@ -19885,8 +20566,12 @@ pub fn emit_shell_call( let output_line = " .output()?;".to_string(); let check_line = "let stdout = String::from_utf8_lossy(&output.stdout).to_string();".to_string(); - let return_line = - emit_exit_code_handling(op_node.clone(), inferred, source_indices.clone()); + let return_line = emit_exit_code_handling( + op_node.clone(), + inferred, + corpus_repr.clone(), + source_indices.clone(), + ); let all_lines = v1_rt::concat( v1_rt::concat(v1_rt::concat(Rc::new(vec![cmd_line]), arg_lines), env_lines), Rc::new(vec![wd_line, output_line, check_line, return_line]), @@ -19900,6 +20585,7 @@ pub fn emit_shell_call( pub fn emit_shell_argv_element( arg: Rc, optional_params: Rc>, + corpus_repr: RustCorpusRepr, source_indices: Rc>>, ) -> String { match (*arg.expr_data.clone()).clone() { @@ -19998,10 +20684,10 @@ pub fn emit_shell_argv_element( if is_opt.clone() { emit_rust_dag_string_to_host_via_seam( v1_rt::concat(var_name.clone(), ".as_deref().unwrap_or(\"\")".to_string()), - source_indices.clone(), + corpus_repr, ) } else { - emit_rust_dag_string_to_host_via_seam(var_name.clone(), source_indices.clone()) + emit_rust_dag_string_to_host_via_seam(var_name.clone(), corpus_repr) } } _ => emit_simple_expr(arg.clone(), RenderTarget::Rust, source_indices.clone()), @@ -20068,7 +20754,7 @@ pub fn emit_shell_return( } __result }); - let lines = if (stderr_line.clone().as_str() != "".to_string().as_str()) { + let lines = if (stderr_line.clone() != "".to_string()) { v1_rt::concat(stderr_line.clone(), "\n".to_string()) } else { "".to_string() @@ -20095,13 +20781,13 @@ pub fn emit_shell_return( pub fn emit_shell_channel_expr(channel: String, is_optional: bool) -> String { { - let base = if (channel.clone().as_str() == "exit_success".to_string().as_str()) { + let base = if (channel.clone() == "exit_success".to_string()) { "output.status.success()".to_string() } else { - if (channel.clone().as_str() == "stderr".to_string().as_str()) { + if (channel.clone() == "stderr".to_string()) { "stderr.clone()".to_string() } else { - if (channel.clone().as_str() == "stdout_lines".to_string().as_str()) { + if (channel.clone() == "stdout_lines".to_string()) { "Rc::new(stdout.lines().filter(|l| !l.is_empty()).map(|l| l.trim().to_string()).collect())".to_string() } else { "stdout.clone()".to_string() @@ -20173,6 +20859,7 @@ pub fn emit_local_call(op_name: String) -> String { pub fn emit_resource_def( item: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, ) -> String { { @@ -20195,6 +20882,7 @@ pub fn emit_resource_def( __result.push(emit_capability_method( c.clone(), shared_types.clone(), + corpus_repr.clone(), env.clone(), )); } @@ -20225,6 +20913,7 @@ pub fn emit_resource_def( pub fn emit_capability_method( cap_node: Rc, shared_types: Rc>, + corpus_repr: RustCorpusRepr, env: Rc, ) -> String { { @@ -20243,15 +20932,17 @@ pub fn emit_capability_method( param_node_type_expr(p.clone()), Rc::new(vec![]), shared_types.clone(), + corpus_repr.clone(), env.source_indices.clone(), - env.clone(), + v1_rt::rc_empty_map::(), + env.clone().clone(), ), )); } __result }); let params_str = input_params.join(&", ".to_string()); - let all_params = if (params_str.clone().as_str() == "".to_string().as_str()) { + let all_params = if (params_str.clone() == "".to_string()) { "&self".to_string() } else { v1_rt::concat("&self, ".to_string(), params_str.clone()) @@ -20259,6 +20950,7 @@ pub fn emit_capability_method( let ret = render_rust_type( resolved_type(cap_node.clone()), shared_types.clone(), + corpus_repr.clone(), env.source_indices.clone(), ); let items = rust_items(); @@ -20347,10 +21039,11 @@ pub fn emit_data_def( let raw_ty_str = render_rust_type_with_applied_binding( render_type_node, shared_types.clone(), + emit_info.corpus_repr.clone(), scope.type_env.clone().source_indices.clone(), ); - let ty_str = if ((raw_ty_str.clone().as_str() == "BoundedLattice".to_string().as_str()) - || (raw_ty_str.clone().as_str() == "Rc".to_string().as_str())) + let ty_str = if ((raw_ty_str.clone() == "BoundedLattice".to_string()) + || (raw_ty_str.clone() == "Rc".to_string())) { match field_value_by_name( value.clone(), @@ -20362,12 +21055,10 @@ pub fn emit_data_def( scope.type_env.clone().source_indices.clone(), resolved_type(top_value.clone()), ); - if (top_type_name.clone().as_str() == "".to_string().as_str()) { + if (top_type_name.clone() == "".to_string()) { raw_ty_str.clone() } else { - if (raw_ty_str.clone().as_str() - == "Rc".to_string().as_str()) - { + if (raw_ty_str.clone() == "Rc".to_string()) { v1_rt::concat( v1_rt::concat( "Rc { let lattice_value = field_value_by_name( @@ -20669,38 +21361,31 @@ pub fn emit_data_def_body( v1_rt::concat( v1_rt::concat( v1_rt::concat( - " __m.insert(".to_string(), - emit_rust_host_to_dag_string_via_seam( - v1_rt::concat( + v1_rt::concat( + " __m.insert(".to_string(), + emit_rust_host_to_dag_string_via_seam( v1_rt::concat( - "\"".to_string(), - field_init_node_name_at( - f.clone(), - scope - .type_env - .clone() - .source_indices - .clone(), + v1_rt::concat( + "\"".to_string(), + field_init_node_name_at( + f.clone(), + scope + .type_env + .clone() + .source_indices + .clone(), + ), ), + "\"".to_string(), ), - "\"".to_string(), + emit_info.corpus_repr.clone(), ), - scope - .type_env - .clone() - .source_indices - .clone(), - ), - ), - v1_rt::concat( - v1_rt::concat( - ", ".to_string(), - val_str.clone(), ), - ");".to_string(), + ", ".to_string(), ), + val_str.clone(), ), - "".to_string(), + ");".to_string(), ) }); } @@ -20776,13 +21461,18 @@ pub fn emit_data_def_body( pub fn emit_test_file( module_name: String, projections: Rc>>, + corpus_repr: RustCorpusRepr, ) -> Rc { { let depth = 0; let test_fns = Rc::new({ let mut __result = Vec::new(); for p in projections.iter().cloned() { - __result.push(emit_operation_test(p.clone(), (depth.clone() + 1))); + __result.push(emit_operation_test( + p.clone(), + (depth.clone() + 1), + corpus_repr.clone(), + )); } __result }); @@ -20833,13 +21523,16 @@ pub fn emit_test_file( } } -pub fn rust_test_signature_comment(projection: Rc) -> String { +pub fn rust_test_signature_comment( + projection: Rc, + corpus_repr: RustCorpusRepr, +) -> String { { let stub_env = Rc::new(TypeEnv { - bindings: Rc::new(HashMap::new()), + bindings: v1_rt::rc_empty_map::>(), recursive_types: Rc::new(vec![]), - recursive_type_set: Rc::new(HashMap::new()), - inductive_fields: Rc::new(HashMap::new()), + recursive_type_set: v1_rt::rc_empty_map::(), + inductive_fields: v1_rt::rc_empty_map::>>>(), source_indices: projection.source_indices.clone(), intern_table: empty_intern_table(), }); @@ -20855,7 +21548,9 @@ pub fn rust_test_signature_comment(projection: Rc) -> String { param_node_type_expr(p.clone()), Rc::new(vec![]), v1_rt::rc_empty_set::(), + corpus_repr.clone(), projection.source_indices.clone(), + v1_rt::rc_empty_map::(), stub_env.clone(), ), )); @@ -20892,7 +21587,11 @@ pub fn rust_test_signature_comment(projection: Rc) -> String { } } -pub fn emit_operation_test(projection: Rc, depth: i64) -> String { +pub fn emit_operation_test( + projection: Rc, + depth: i64, + corpus_repr: RustCorpusRepr, +) -> String { { let test_name = rust_test_name(projection.clone()); let struct_name = sanitize_service_name(projection.service_name.clone()); @@ -20909,12 +21608,12 @@ pub fn emit_operation_test(projection: Rc, depth: i64) -> String __result }); let args_str = param_args.join(&", ".to_string()); - let call_args = if (args_str.clone().as_str() == "".to_string().as_str()) { + let call_args = if (args_str.clone() == "".to_string()) { "".to_string() } else { args_str.clone() }; - 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(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_async_test_decorator(), "\nasync fn ".to_string()), test_name), "() {\n".to_string()), indent.clone()), rust_test_signature_comment(projection.clone())), "\n".to_string()), indent.clone()), "let service = ".to_string()), struct_name.clone()), "::new(crate::dry_run::DryRunMode(true));\n".to_string()), indent.clone()), "let result = service.".to_string()), emit_ident(op_method, RenderTarget::Rust)), "(".to_string()), call_args), ").await;\n".to_string()), indent.clone()), "assert!(result.is_ok(), \"".to_string()), struct_name.clone()), ".".to_string()), projection.operation_name.clone()), " should succeed in dry-run mode: {:?}\", result.err());\n".to_string()), "}".to_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(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(rust_async_test_decorator(), "\nasync fn ".to_string()), test_name), "() {\n".to_string()), indent.clone()), rust_test_signature_comment(projection.clone(), corpus_repr)), "\n".to_string()), indent.clone()), "let service = ".to_string()), struct_name.clone()), "::new(crate::dry_run::DryRunMode(true));\n".to_string()), indent.clone()), "let result = service.".to_string()), emit_ident(op_method, RenderTarget::Rust)), "(".to_string()), call_args), ").await;\n".to_string()), indent.clone()), "assert!(result.is_ok(), \"".to_string()), struct_name.clone()), ".".to_string()), projection.operation_name.clone()), " should succeed in dry-run mode: {:?}\", result.err());\n".to_string()), "}".to_string()) } } @@ -21010,6 +21709,9 @@ pub fn emit_cargo_dep(name: String, version: String, features: Rc>) pub fn emit_cargo_toml(crate_name: String, has_services: bool) -> Rc { { + // HAND-SYNCED MIRROR drift fix: inline the [package] header instead of + // importing render_cargo_package_header_prefix from the deliberately- + // unwired extdeps_cargo_version orphan (byte-identical to committed emit). let header = v1_rt::concat( v1_rt::concat("[package]\nname = \"".to_string(), crate_name), "\"\nversion = \"0.1.0\"\nedition = \"2021\"\n".to_string(), @@ -21112,8 +21814,8 @@ pub fn resolve_param_default( ItemKind::DataItem => match Rc::new({ let mut __result = Vec::new(); for i in module_items.iter().cloned() { - if (authored_name_at(source_indices.clone(), i.clone()).as_str() - == authored_name_at(source_indices.clone(), dv.clone()).as_str()) + if (authored_name_at(source_indices.clone(), i.clone()) + == authored_name_at(source_indices.clone(), dv.clone())) { __result.push(i); } @@ -21323,9 +22025,7 @@ pub fn find_resource_module(resource_name: String, modules: Rc String { { - let about_attr = if (about.clone().as_str() != "".to_string().as_str()) { + let about_attr = if (about.clone() != "".to_string()) { v1_rt::concat( v1_rt::concat(", about = \"".to_string(), about.clone()), "\"".to_string(), @@ -21898,11 +22597,18 @@ pub fn emit_cli_param_type_node( if ((n.children.clone().len() as i64) == 0) { { let nname = authored_name_at(source_indices, n.clone()); - let mapped = coerce_primitive_type(RenderTarget::Rust, nname.clone()); - if (mapped.clone().as_str() != nname.clone().as_str()) { - mapped.clone() - } else { + if (nname.clone() == "String".to_string()) { "String".to_string() + } else { + { + let mapped = + coerce_primitive_type(RenderTarget::Rust, nname.clone()); + if (mapped.clone() != nname.clone()) { + mapped.clone() + } else { + "String".to_string() + } + } } } } else { @@ -21973,7 +22679,7 @@ pub fn emit_main_fn( ";".to_string(), ) }; - let body_lines = if (dry_run_line.clone().as_str() == "".to_string().as_str()) { + let body_lines = if (dry_run_line.clone() == "".to_string()) { v1_rt::concat(v1_rt::concat(parse_line, "\n".to_string()), result_handling) } else { v1_rt::concat( @@ -22008,15 +22714,7 @@ pub fn emit_compile_match_arm(crate_name: String) -> String { } pub fn emit_run_match_arm(crate_name: String) -> String { - v1_rt::concat( - v1_rt::concat( - "\n Commands::Run { source_roots, function, entry, claim_run } => {\n" - .to_string(), - " cli_run::handle_run_with_options(source_roots, function, entry, cli.dry_run, claim_run);\n" - .to_string(), - ), - " },".to_string(), - ) + v1_rt::concat(v1_rt::concat("\n Commands::Run { source_roots, function, entry, claim_run } => {\n".to_string(), " cli_run::handle_run_with_options(source_roots, function, entry, cli.dry_run, claim_run);\n".to_string()), " },".to_string()) } pub fn emit_main_pipeline_fns(crate_name: String) -> String { diff --git a/src/v1/stage0/src/v1_compiler_infer.rs b/src/v1/stage0/src/v1_compiler_infer.rs index a0c3dd4540f..c93bcd5e7a8 100644 --- a/src/v1/stage0/src/v1_compiler_infer.rs +++ b/src/v1/stage0/src/v1_compiler_infer.rs @@ -1,5 +1,30 @@ // Generated by v1 compiler -- do not edit. // Source module: v1.compiler.infer +// +// HAND-SYNCED MIRROR (class-3 splice) -- this committed seed is a HAND-SYNCED +// MIRROR of the .dag authority, NOT a regen fixpoint. One of three class-3 +// files (with v1_compiler_emit_rust.rs, v1_compiler_infer_emit_info.rs) spliced +// from a faithful regen of the class-3 .dag onto the committed seed. +// LANE (deferred): regen-fixpoint emitter-self-host (~150-gap) -- wire-all-emitted- +// modules so a clean regen reproduces this committed seed bit-identically (the +// §7 reproduce-fixpoint that licenses deleting src/v1). +// SCOPE: a faithful full regen wires the deliberately-unwired orphan std modules +// (std_measure / std_algebra / std_realization_schedule / std_machine_constraints +// / std_integer / extdeps_version_semver / extdeps_cargo_version) and surfaces +// ~150 latent emitter-completeness gaps (std numeric/measure-tower generic +// emission). They stay UNWIRED here exactly as on main. +// PROVENANCE (#5514 verbatim deferral): "regen-write still emits a non-building +// seed from ~150 emitter-completeness gaps, the clean green regen fixpoint is +// deferred, converges with the Route-A emitter self-host". +// DISSOLUTION TRIGGER: §7 fixpoint convergence with the Route-A emitter self-host +// -- when wire-all-emitted-modules -> regen-equals-committed is in reach; a fresh +// work-item gets dispatched THEN. (breadcrumb: node://adhoc-80af9ff8-40f) +// INVARIANCE CAVEAT (quick-seal, verbatim): class-3 host-vs-faithful SELECTION is +// representation-invariant on the v1-bundled HOST seed at this tip -- CONTROL B +// (gate-isolated revert) builds green, CONTROL A errors are the wire policy +// confound not representation; the selection's behavioral discriminating-proof is +// OWED by the deferred faithful target, where the selection actually fires. +// Full detail: carrier mark in v1_compiler_emit_rust.rs. use self::SizeExpr::*; pub use crate::std_algebra::CollectionSizeEffect; @@ -35,13 +60,14 @@ pub use crate::std_types::SourceSpan; pub use crate::v1_compiler_infer_access::AccessCheckResultNode; pub use crate::v1_compiler_infer_access::{check_index_access_node, check_slice_access_node}; pub use crate::v1_compiler_infer_cycle::detect_type_cycles_kahn; +use crate::v1_compiler_infer_emit_info::RustCorpusRepr::{FaithfulFreeMonoid, HostNative}; use crate::v1_compiler_infer_emit_info::TypeRepr::{EnumRepr, StructRepr}; pub use crate::v1_compiler_infer_emit_info::{ add_emit_item_summary, build_enum_field_summaries, build_struct_field_summaries, derive_variant_to_enum, empty_emit_graph_info, lookup_emit_type_summary, }; pub use crate::v1_compiler_infer_emit_info::{ - EmitGraphInfo, EmitInfoBuildState, TypeRepr, TypeSummary, + EmitGraphInfo, EmitInfoBuildState, RustCorpusRepr, TypeRepr, TypeSummary, }; pub use crate::v1_compiler_infer_env::{ inductive_fields_for, inductive_fields_list_to_map, is_recursive_type, @@ -163,8 +189,7 @@ use std::collections::HashMap; use std::rc::Rc; pub fn is_witness_type_name(name: String) -> bool { - ((name.clone().as_str() == "Witness".to_string().as_str()) - || (name.clone().as_str() == "witness".to_string().as_str())) + ((name.clone() == "Witness".to_string()) || (name.clone() == "witness".to_string())) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -547,7 +572,7 @@ pub fn classify_field_recursion( _ => field_node_type_expr(field_node.clone()), }; let field_type_name = authored_name_at(source_indices.clone(), type_expr.clone()); - if (field_type_name.clone().as_str() == parent_name.clone().as_str()) { + if (field_type_name.clone() == parent_name.clone()) { match field_node.return_cardinality.clone() { Cardinality::CardOptional => Some(Rc::new(FieldRecursionResult { shape: RecursionShape::OptionalRecursion, @@ -575,17 +600,15 @@ pub fn classify_field_recursion( Some(t) => authored_name_at(source_indices.clone(), t.clone()), None => "".to_string(), }; - let is_recursive_element = ((value_type.clone().as_str() - == parent_name.clone().as_str()) + let is_recursive_element = ((value_type.clone() == parent_name.clone()) || v1_rt::set_contains(&recursive_type_set, value_type.clone())); if is_recursive_element { { - let elem = - if (value_type.clone().as_str() == parent_name.clone().as_str()) { - parent_name.clone() - } else { - value_type.clone() - }; + let elem = if (value_type.clone() == parent_name.clone()) { + parent_name.clone() + } else { + value_type.clone() + }; match field_type_name.clone().as_str() { "List" => Some(Rc::new(FieldRecursionResult { shape: RecursionShape::ListRecursion, @@ -753,8 +776,8 @@ pub fn namespace_root_from_properties( match Rc::new({ let mut __result = Vec::new(); for p in properties.iter().cloned() { - if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() - == "namespace_root".to_string().as_str()) + if (field_init_node_name_at(p.clone(), source_indices.clone()) + == "namespace_root".to_string()) { __result.push(p); } @@ -884,8 +907,7 @@ pub fn rejects_string_for_optional_coproduct_field( let expected_is_optional_coproduct = ((expected.return_cardinality.clone() == Cardinality::CardOptional) && (expected_inner.connective.clone() == Connective::Disj)); - let got_is_string = - (authored_name_at(source_indices, got).as_str() == "String".to_string().as_str()); + let got_is_string = (authored_name_at(source_indices, got) == "String".to_string()); (expected_is_optional_coproduct && got_is_string) } } @@ -906,9 +928,7 @@ pub fn record_lit_expected_fields( if (authored_name_at( scope.type_env.clone().source_indices.clone(), v.clone(), - ) - .as_str() - == tn.clone().as_str()) + ) == tn.clone()) { __result.push(v); } @@ -942,9 +962,7 @@ pub fn record_lit_expanded_from_expected( if (((authored_name_at( scope.type_env.clone().source_indices.clone(), exp.clone(), - ) - .as_str() - == tn.clone().as_str()) + ) == tn.clone()) && (exp.connective.clone() == Connective::Conj)) && ((exp.children.clone().len() as i64) > 0)) { @@ -955,9 +973,7 @@ pub fn record_lit_expanded_from_expected( if (authored_name_at( scope.type_env.clone().source_indices.clone(), expanded.clone(), - ) - .as_str() - == tn.clone().as_str()) + ) == tn.clone()) { Some(expanded.clone()) } else { @@ -969,9 +985,7 @@ pub fn record_lit_expanded_from_expected( if (authored_name_at( scope.type_env.clone().source_indices.clone(), rt.clone(), - ) - .as_str() - == tn.clone().as_str()) + ) == tn.clone()) { Some(rt.clone()) } else { @@ -1015,8 +1029,7 @@ pub fn record_lit_instantiated_fields( Some(tn) => match expected { Some(exp) => { if (authored_name_at(scope.type_env.clone().source_indices.clone(), exp.clone()) - .as_str() - != tn.clone().as_str()) + != tn.clone()) { None } else { @@ -1186,10 +1199,9 @@ pub fn type_node_is_callable(n: Rc) -> bool { pub fn module_skips_direct_call_arg_check(module_name: String) -> bool { { let is_v4 = ((v1_rt::string_length(&module_name) >= 3) - && (v1_rt::substring(&module_name, 0, 3).as_str() == "v2.".to_string().as_str())); + && (v1_rt::substring(&module_name, 0, 3) == "v2.".to_string())); let is_compiler_substrate = ((v1_rt::string_length(&module_name) >= 13) - && (v1_rt::substring(&module_name, 0, 13).as_str() - == "v1.compiler.".to_string().as_str())); + && (v1_rt::substring(&module_name, 0, 13) == "v1.compiler.".to_string())); (is_v4 || is_compiler_substrate) } } @@ -1204,13 +1216,11 @@ pub fn nominal_call_arg_brand_mismatch( let actual_name = authored_name_at(source_indices.clone(), actual.clone()); ((((((((formal.connective.clone() != Connective::Arrow) && (actual.connective.clone() != Connective::Arrow)) - && (formal_name.clone().as_str() != "".to_string().as_str())) - && (actual_name.clone().as_str() != "".to_string().as_str())) - && (formal_name.clone().as_str() != actual_name.clone().as_str())) + && (formal_name.clone() != "".to_string())) + && (actual_name.clone() != "".to_string())) + && (formal_name.clone() != actual_name.clone())) && (structural_carrier_template_name(formal.clone(), source_indices.clone()) - .as_str() - == structural_carrier_template_name(actual.clone(), source_indices.clone()) - .as_str())) + == structural_carrier_template_name(actual.clone(), source_indices.clone()))) && !is_declared_container_alias_spelling(formal_name.clone())) && !is_declared_container_alias_spelling(actual_name.clone())) } @@ -1225,8 +1235,8 @@ pub fn container_element_nominal_brand_mismatch( ) -> bool { if ((node_is_element_collection(formal.clone(), source_indices.clone()) && node_is_element_collection(actual.clone(), source_indices.clone())) - && (authored_name_at(source_indices.clone(), formal.clone()).as_str() - == authored_name_at(source_indices.clone(), actual.clone()).as_str())) + && (authored_name_at(source_indices.clone(), formal.clone()) + == authored_name_at(source_indices.clone(), actual.clone()))) { match formal.children.clone().first().cloned() { Some(formal_ch) => match actual.children.clone().first().cloned() { @@ -1357,8 +1367,7 @@ pub fn infer_tier2b_builtin_with_kernel_diags( scope: Rc, span: Rc, ) -> Rc { - if ((func_name.clone().as_str() == "lookup".to_string().as_str()) - || (func_name.clone().as_str() == "map_get".to_string().as_str())) + if ((func_name.clone() == "lookup".to_string()) || (func_name.clone() == "map_get".to_string())) { Rc::new(Tier2bBt { bt: match typed_args.clone().first().cloned() { @@ -1374,7 +1383,7 @@ pub fn infer_tier2b_builtin_with_kernel_diags( }) => { match map_value_type_in_env(receiver_type.clone(), scope.type_env.clone()) { Some(value_type) => { - if (func_name.clone().as_str() == "lookup".to_string().as_str()) { + if (func_name.clone() == "lookup".to_string()) { witness_of_element(value_type.clone()) } else { with_optional_cardinality(value_type.clone()) @@ -1390,7 +1399,7 @@ pub fn infer_tier2b_builtin_with_kernel_diags( kernel_diags: Rc::new(vec![]), }) } else { - if (func_name.clone().as_str() == "map_keys".to_string().as_str()) { + if (func_name.clone() == "map_keys".to_string()) { match typed_args.clone().first().cloned() { Some(receiver_arg) => match arg_value(receiver_arg.clone()) .inferred @@ -1427,7 +1436,7 @@ pub fn infer_tier2b_builtin_with_kernel_diags( }), } } else { - if (func_name.clone().as_str() == "map_values".to_string().as_str()) { + if (func_name.clone() == "map_values".to_string()) { match typed_args.clone().first().cloned() { Some(receiver_arg) => match arg_value(receiver_arg.clone()) .inferred @@ -1465,14 +1474,13 @@ pub fn infer_tier2b_builtin_with_kernel_diags( }), } } else { - if (((func_name.clone().as_str() == "set_insert".to_string().as_str()) - || (func_name.clone().as_str() == "set_union".to_string().as_str())) - || (func_name.clone().as_str() == "set_contains".to_string().as_str())) + if (((func_name.clone() == "set_insert".to_string()) + || (func_name.clone() == "set_union".to_string())) + || (func_name.clone() == "set_contains".to_string())) { { - let operand_elem = if ((func_name.clone().as_str() - == "set_insert".to_string().as_str()) - || (func_name.clone().as_str() == "set_contains".to_string().as_str())) + let operand_elem = if ((func_name.clone() == "set_insert".to_string()) + || (func_name.clone() == "set_contains".to_string())) { match typed_args.clone().get(1 as usize).cloned() { Some(insert_arg) => match arg_value(insert_arg.clone()) @@ -1516,18 +1524,17 @@ pub fn infer_tier2b_builtin_with_kernel_diags( } None => false, }; - let union_other_bad = - if (func_name.clone().as_str() == "set_union".to_string().as_str()) { - match typed_args.clone().get(1 as usize).cloned() { - Some(other_arg) => set_union_other_operand_is_resolved_non_set( - other_arg.clone(), - scope.clone(), - ), - None => false, - } - } else { - false - }; + let union_other_bad = if (func_name.clone() == "set_union".to_string()) { + match typed_args.clone().get(1 as usize).cloned() { + Some(other_arg) => set_union_other_operand_is_resolved_non_set( + other_arg.clone(), + scope.clone(), + ), + None => false, + } + } else { + false + }; let recv_elem = match typed_args.clone().first().cloned() { Some(receiver_arg) => match arg_value(receiver_arg.clone()) .inferred @@ -1590,9 +1597,7 @@ pub fn infer_tier2b_builtin_with_kernel_diags( } else { Rc::new(vec![]) }; - let result_bt = if (func_name.clone().as_str() - == "set_contains".to_string().as_str()) - { + let result_bt = if (func_name.clone() == "set_contains".to_string()) { if (recv_is_set.clone() && !elem_mismatch.clone()) { bool_type() } else { @@ -1635,9 +1640,7 @@ pub fn infer_tier2b_builtin_with_kernel_diags( None => resolve_builtin_call_type(func_name.clone()), } }; - let build_diags = if (func_name.clone().as_str() - == "set_contains".to_string().as_str()) - { + let build_diags = if (func_name.clone() == "set_contains".to_string()) { Rc::new(vec![]) } else { match operand_elem.clone() { @@ -1689,7 +1692,7 @@ pub fn method_pipe_map_keys_values_fallback( scope: Rc, span: Rc, ) -> Rc { - if (method_name.clone().as_str() == "map_keys".to_string().as_str()) { + if (method_name.clone() == "map_keys".to_string()) { match map_key_type_in_env(recv_rt.clone(), scope.type_env.clone()) { Some(key_type) => { let lk = list_kernel_ty_from_element(key_type.clone()); @@ -1704,7 +1707,7 @@ pub fn method_pipe_map_keys_values_fallback( }), } } else { - if (method_name.clone().as_str() == "map_values".to_string().as_str()) { + if (method_name.clone() == "map_values".to_string()) { match map_value_type_in_env(recv_rt.clone(), scope.type_env.clone()) { Some(value_type) => { let lv = list_kernel_ty_from_element(value_type.clone()); @@ -1752,7 +1755,7 @@ pub fn validate_cast( match source_inferred.as_deref().cloned() { Some(InferredNode::Resolved { node: src_node, .. }) => { let source_name = authored_name_at(source_indices, src_node.clone()); - if (source_name.clone().as_str() == target_name.clone().as_str()) { + if (source_name.clone() == target_name.clone()) { None } else { if !is_dag_cast_domain_type(source_name.clone()) { @@ -1880,23 +1883,18 @@ pub fn annotate_pattern_parent_enums( let optional_cardinality_subject = ((resolved_scrut_node.return_cardinality.clone() == Cardinality::CardOptional) - && (scrutinee_name.clone().as_str() - != "Optional".to_string().as_str())); - let optional_coproduct_subject = ((scrutinee_name.clone().as_str() - == "Optional".to_string().as_str()) - && ((variant_name.clone().as_str() == "Present".to_string().as_str()) - || (variant_name.clone().as_str() - == "Absent".to_string().as_str()))); + && (scrutinee_name.clone() != "Optional".to_string())); + let optional_coproduct_subject = ((scrutinee_name.clone() + == "Optional".to_string()) + && ((variant_name.clone() == "Present".to_string()) + || (variant_name.clone() == "Absent".to_string()))); let witness_container_subject = (is_witness_type_name(scrutinee_name.clone()) - && ((variant_name.clone().as_str() - == "Holds".to_string().as_str()) - || (variant_name.clone().as_str() - == "Violates".to_string().as_str()))); + && ((variant_name.clone() == "Holds".to_string()) + || (variant_name.clone() == "Violates".to_string()))); if ((optional_cardinality_subject || optional_coproduct_subject) - && ((variant_name.clone().as_str() == "Present".to_string().as_str()) - || (variant_name.clone().as_str() - == "Absent".to_string().as_str()))) + && ((variant_name.clone() == "Present".to_string()) + || (variant_name.clone() == "Absent".to_string()))) { Some("Optional".to_string()) } else { @@ -2141,7 +2139,7 @@ pub fn derive_field_provenance( ), _ => "".to_string(), }; - if (scrut_type_name.clone().as_str() == "".to_string().as_str()) { + if (scrut_type_name.clone() == "".to_string()) { Rc::new(SubValueRelation::SubValueUnknown) } else { { @@ -2150,8 +2148,8 @@ pub fn derive_field_provenance( let matching = Rc::new({ let mut __result = Vec::new(); for f in ind_fields.iter().cloned() { - if ((f.variant_name.clone().as_str() == variant_name.clone().as_str()) - && (f.field_name.clone().as_str() == field_name.clone().as_str())) + if ((f.variant_name.clone() == variant_name.clone()) + && (f.field_name.clone() == field_name.clone())) { __result.push(f); } @@ -2279,7 +2277,7 @@ pub fn method_name_is(opt: Option, expected: String) -> bool { if (opt.clone() == None) { false } else { - (opt.clone().unwrap().as_str() == expected.as_str()) + (opt.clone().unwrap() == expected) } } @@ -2293,7 +2291,7 @@ pub fn arg_has_name( if (n.clone() == None) { false } else { - (n.clone().unwrap().as_str() == name.as_str()) + (n.clone().unwrap() == name) } } } @@ -2367,9 +2365,7 @@ pub fn derive_element_provenance( if (authored_name_at( scope.type_env.clone().source_indices.clone(), elem_type.clone(), - ) - .as_str() - == "".to_string().as_str()) + ) == "".to_string()) { Rc::new(SubValueRelation::SubValueUnknown) } else { @@ -2777,11 +2773,18 @@ pub fn infer_expr( ); match field_type_lookup { Some(field_type) => { - let field_summary = field_summary_for_type( + let field_summary = match field_summary_for_type( base_rt.clone(), scope.type_env.clone(), field_name.clone(), - ); + ) { + Some(s) => Some(s.clone()), + None => field_summary_for_type( + resolved_base.clone(), + scope.type_env.clone(), + field_name.clone(), + ), + }; let fa_texpr = make_named_expr_node( field_name.clone(), Rc::new(ExprData::ExprFieldAccess { @@ -3425,7 +3428,7 @@ pub fn infer_expr( }) } } else { - if (func_name.clone().as_str() == "empty_map".to_string().as_str()) { + if (func_name.clone() == "empty_map".to_string()) { { let bare_m = bare_map_node(); match expected.clone() { @@ -3489,8 +3492,7 @@ match bare_m { } } } else { - if (func_name.clone().as_str() == "empty_set".to_string().as_str()) - { + if (func_name.clone() == "empty_set".to_string()) { { let bare_s = bare_set_node(); match expected.clone() { @@ -3563,13 +3565,12 @@ match bare_s { span.clone(), ); let bt = tier2b.bt.clone(); - let call_semantics = if (func_name.clone().as_str() - == "lookup".to_string().as_str()) - { - Some(CallSemantics::LookupCallSemantics) - } else { - Some(CallSemantics::PlainCallSemantics) - }; + let call_semantics = + if (func_name.clone() == "lookup".to_string()) { + Some(CallSemantics::LookupCallSemantics) + } else { + Some(CallSemantics::PlainCallSemantics) + }; Rc::new(InferResult { typed: make_named_expr_node( func_name.clone(), @@ -4300,9 +4301,7 @@ match bare_s { (authored_name_at( scope.type_env.clone().source_indices.clone(), bd.clone(), - ) - .as_str() - == let_name.clone().as_str()) + ) == let_name.clone()) } _ => false, }, @@ -5306,7 +5305,7 @@ pub fn record_field_type_is_unresolved_param( let in_params = { let mut __found = false; for pn in param_names.iter().cloned() { - if (pn.clone().as_str() == fname.clone().as_str()) { + if (pn.clone() == fname.clone()) { __found = true; break; } @@ -5380,7 +5379,7 @@ pub fn expand_alias_chain_for_field_access( } else { let next_name = structural.name.clone(); let is_optional = (structural.return_cardinality.clone() == Cardinality::CardOptional); - let stop = ((is_optional || (next_name.clone().as_str() == "".to_string().as_str())) + let stop = ((is_optional || (next_name.clone() == "".to_string())) || emit_map_has(seen.clone(), next_name.clone())); if stop { break structural.clone(); @@ -5508,8 +5507,8 @@ pub fn field_in_any_variant_named(type_name: String, field: String, scope: Rc error_type(), }; let expected_optional_parent = Some("Optional".to_string()); - let is_present_ctor = ((type_name.clone().unwrap().as_str() - == "Present".to_string().as_str()) + let is_present_ctor = ((type_name.clone().unwrap() == "Present".to_string()) && (local_variant_parent.clone().as_deref() == expected_optional_parent.as_deref())); let resolved_node = if is_present_ctor { @@ -5848,9 +5843,7 @@ pub fn infer_record_lit( if (field_init_node_name_at( fir.typed_field.clone(), scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == "value".to_string().as_str()) + ) == "value".to_string()) { __result.push(fir); } @@ -5942,7 +5935,7 @@ pub fn classify_size_expr(val: Rc, ctx: Rc) -> Option { let mname = expr_method_name_at(val.clone(), ctx.type_env.clone().source_indices.clone()); - if (mname.as_str() == "count".to_string().as_str()) { + if (mname == "count".to_string()) { { let receiver = method_receiver(val.clone()); match (*receiver.expr_data.clone()).clone() { @@ -6039,7 +6032,7 @@ pub fn proportional_skip_alias_plus_literal( divisor: d, .. }) => { - if (p.clone().as_str() == param_name.clone().as_str()) { + if (p.clone() == param_name.clone()) { match (*lit_expr.expr_data.clone()).clone() { ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { @@ -6095,9 +6088,7 @@ pub fn classify_collection_shrink( arg_expr.clone(), ctx.type_env.clone().source_indices.clone(), ); - if ((mname.clone().as_str() == "take".to_string().as_str()) - || (mname.clone().as_str() == "skip".to_string().as_str())) - { + if ((mname.clone() == "take".to_string()) || (mname.clone() == "skip".to_string())) { { let receiver = method_receiver(arg_expr.clone()); match (*receiver.expr_data.clone()).clone() { @@ -6108,7 +6099,7 @@ pub fn classify_collection_shrink( receiver.clone(), ctx.type_env.clone().source_indices.clone(), ); - if (rname.as_str() == param_name.clone().as_str()) { + if (rname == param_name.clone()) { { let args = method_arg_nodes(arg_expr.clone()); match args.first().cloned() { @@ -6122,8 +6113,7 @@ pub fn classify_collection_shrink( unreachable!() }; if ((k.clone() > 0) - && (mname.clone().as_str() - == "skip".to_string().as_str())) + && (mname.clone() == "skip".to_string())) { match positive_descent_amount_from_positive_int(k.clone()) { Some(steps) => { @@ -6166,9 +6156,7 @@ Rc::new(SubValueRelation::StrictSubValue { divisor: d, .. }) => { - if (p.clone().as_str() - == param_name.clone().as_str()) - { + if (p.clone() == param_name.clone()) { match proportional_divisor_from_int_at_least_two(d.clone()) { Some(div_w) => { let synth_field = Rc::new(InductiveField { @@ -6199,8 +6187,7 @@ Rc::new(SubValueRelation::StrictSubValue { ExprData::ExprBinOp { op, .. } => { match op.clone() { BinOp::Add => { - if (mname.clone().as_str() - == "skip".to_string().as_str()) + if (mname.clone() == "skip".to_string()) { { let left = @@ -6321,16 +6308,15 @@ pub fn maybe_insert_match_field_relation( SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), _ => "".to_string(), }; - if (lookup_type.clone().as_str() != "".to_string().as_str()) { + if (lookup_type.clone() != "".to_string()) { { let ind_fields = inductive_fields_for(type_env, lookup_type.clone()); let matching = Rc::new({ let mut __result = Vec::new(); for f in ind_fields.iter().cloned() { - if ((f.field_name.clone().as_str() == field_label.clone().as_str()) - && ((f.variant_name.clone().as_str() == vname.clone().as_str()) - || (f.variant_name.clone().as_str() - == "".to_string().as_str()))) + if ((f.field_name.clone() == field_label.clone()) + && ((f.variant_name.clone() == vname.clone()) + || (f.variant_name.clone() == "".to_string()))) { __result.push(f); } @@ -6522,7 +6508,7 @@ pub fn resolve_collection_field( } } }; - if (base_type.clone().as_str() != "".to_string().as_str()) { + if (base_type.clone() != "".to_string()) { break Rc::new({ let mut __result = Vec::new(); for f in Rc::new({ @@ -6534,8 +6520,7 @@ pub fn resolve_collection_field( .iter() .cloned() { - if (f.field_name.clone().as_str() == fname.clone().as_str()) - { + if (f.field_name.clone() == fname.clone()) { __result.push(f); } } @@ -6606,12 +6591,12 @@ pub fn resolve_collection_field( } => { let inner_mname = expr_method_name_at(expr.clone(), ctx.type_env.clone().source_indices.clone()); - let is_collection_preserving = (((((inner_mname.clone().as_str() - == "enumerate".to_string().as_str()) - || (inner_mname.clone().as_str() == "skip".to_string().as_str())) - || (inner_mname.clone().as_str() == "take".to_string().as_str())) - || (inner_mname.clone().as_str() == "filter".to_string().as_str())) - || (inner_mname.clone().as_str() == "reverse".to_string().as_str())); + let is_collection_preserving = (((((inner_mname.clone() + == "enumerate".to_string()) + || (inner_mname.clone() == "skip".to_string())) + || (inner_mname.clone() == "take".to_string())) + || (inner_mname.clone() == "filter".to_string())) + || (inner_mname.clone() == "reverse".to_string())); if is_collection_preserving { { let __tco_0 = method_receiver(expr); @@ -6665,7 +6650,7 @@ pub fn classify_binding_provenance(val: Rc, scope: Rc) -> Rc, ctx: Rc) -> Option "".to_string(), }, }; - if (type_name.clone().as_str() != "".to_string().as_str()) { + if (type_name.clone() != "".to_string()) { { let fields = inductive_fields_for( ctx.type_env.clone(), @@ -6745,9 +6730,7 @@ pub fn classify_let_value(val: Rc, ctx: Rc) -> Option, ctx: Rc) -> Option "".to_string(), }, }; - if (inner_type.clone().as_str() - != "".to_string().as_str()) - { + if (inner_type.clone() != "".to_string()) { { let fields = inductive_fields_for( ctx.type_env.clone(), @@ -6892,7 +6873,7 @@ pub fn classify_let_value(val: Rc, ctx: Rc) -> Option "".to_string(), }; - if ((elem.clone().as_str() != "".to_string().as_str()) + if ((elem.clone() != "".to_string()) && is_recursive_type_by_name(ctx.type_env.clone(), elem.clone())) { { @@ -7037,7 +7018,7 @@ pub fn classify_let_value(val: Rc, ctx: Rc) -> Option "".to_string(), }; - if (left_name.clone().as_str() != "".to_string().as_str()) { + if (left_name.clone() != "".to_string()) { match (*right.expr_data.clone()).clone() { ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = @@ -7079,12 +7060,12 @@ pub fn classify_let_value(val: Rc, ctx: Rc) -> Option, ctx: Rc) -> Option { - if (mname.clone().as_str() == "skip".to_string().as_str()) { + if (mname.clone() == "skip".to_string()) { { let skip_args = method_arg_nodes(val.clone()); let skip_amount = match skip_args.first().cloned() { @@ -7297,7 +7278,7 @@ pub fn classify_argument( arg_expr.clone(), ctx.type_env.clone().source_indices.clone(), ); - if (vname.clone().as_str() == param_name.clone().as_str()) { + if (vname.clone() == param_name.clone()) { Rc::new(SubValueRelation::PreservedValue) } else { match v1_rt::map_get(&ctx.sub_value_vars.clone(), vname.clone()) { @@ -7343,7 +7324,7 @@ pub fn classify_argument( let matching = Rc::new({ let mut __result = Vec::new(); for f in fields.iter().cloned() { - if (f.field_name.clone().as_str() == field.clone().as_str()) { + if (f.field_name.clone() == field.clone()) { __result.push(f); } } @@ -7487,9 +7468,7 @@ pub fn classify_argument( ((expr_var_name_at( left.clone(), ctx.type_env.clone().source_indices.clone(), - ) - .as_str() - == param_name.clone().as_str()) + ) == param_name.clone()) || (v1_rt::map_get( &ctx.sub_value_vars.clone(), expr_var_name_at( @@ -7533,9 +7512,7 @@ pub fn classify_argument( ((expr_var_name_at( left.clone(), ctx.type_env.clone().source_indices.clone(), - ) - .as_str() - == param_name.clone().as_str()) + ) == param_name.clone()) || (v1_rt::map_get( &ctx.sub_value_vars.clone(), expr_var_name_at( @@ -7553,9 +7530,7 @@ pub fn classify_argument( ((expr_var_name_at( inner_left.clone(), ctx.type_env.clone().source_indices.clone(), - ) - .as_str() - == param_name.clone().as_str()) + ) == param_name.clone()) || (v1_rt::map_get( &ctx.sub_value_vars.clone(), expr_var_name_at( @@ -7697,8 +7672,7 @@ pub fn read_arg_provenance( let matching = Rc::new({ let mut __result = Vec::new(); for f in fields.iter().cloned() { - if (f.field_name.clone().as_str() == field.clone().as_str()) - { + if (f.field_name.clone() == field.clone()) { __result.push(f); } } @@ -7838,7 +7812,7 @@ pub fn build_call_evidence( } pub fn descent_source_type(found: String, arg_node: Rc, ctx: Rc) -> String { - if (found.clone().as_str() != "".to_string().as_str()) { + if (found.clone() != "".to_string()) { found.clone() } else { match (*arg_value(arg_node.clone()).expr_data.clone()).clone() { @@ -7885,7 +7859,7 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { let arg_val = arg_value(child.clone()); match (*arg_val.expr_data.clone()).clone() { ExprData::ExprLambda => { - if (source_type.clone().as_str() != "".to_string().as_str()) { + if (source_type.clone() != "".to_string()) { { let lparams = lambda_param_names_at( arg_val.clone(), @@ -7902,9 +7876,7 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { }; let lambda_ctx = Rc::new(DescentContext { fn_name: ctx.fn_name.clone(), - param_names: if (p2.clone().as_str() - != "".to_string().as_str()) - { + param_names: if (p2.clone() != "".to_string()) { v1_rt::rc_map_insert( v1_rt::rc_map_insert( ctx.param_names.clone(), @@ -7915,9 +7887,7 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { source_type.clone(), ) } else { - if (p1.clone().as_str() - != "".to_string().as_str()) - { + if (p1.clone() != "".to_string()) { v1_rt::rc_map_insert( ctx.param_names.clone(), p1.clone(), @@ -7929,9 +7899,7 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { }, param_order: ctx.param_order.clone(), type_env: ctx.type_env.clone(), - sub_value_vars: if (p1.clone().as_str() - != "".to_string().as_str()) - { + sub_value_vars: if (p1.clone() != "".to_string()) { { let source_fields = inductive_fields_for( ctx.type_env.clone(), @@ -7959,9 +7927,7 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { }), None => Rc::new(SubValueRelation::PreservedValue), }; - if (p2.clone().as_str() - != "".to_string().as_str()) - { + if (p2.clone() != "".to_string()) { v1_rt::rc_map_insert( v1_rt::rc_map_insert( ctx.sub_value_vars.clone(), @@ -8100,7 +8066,7 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { Some(t) => t.clone(), None => "".to_string(), }; - if (base_type.clone().as_str() != "".to_string().as_str()) { + if (base_type.clone() != "".to_string()) { { let ind_fields = inductive_fields_for( ctx.type_env.clone(), @@ -8109,9 +8075,7 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { Rc::new({ let mut __result = Vec::new(); for f in ind_fields.clone().iter().cloned() { - if (f.field_name.clone().as_str() - == fname.clone().as_str()) - { + if (f.field_name.clone() == fname.clone()) { __result.push(f); } } @@ -8135,8 +8099,8 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { scrut.clone(), ctx.type_env.clone().source_indices.clone(), ); - if ((mname.clone().as_str() == "first".to_string().as_str()) - || (mname.clone().as_str() == "last".to_string().as_str())) + if ((mname.clone() == "first".to_string()) + || (mname.clone() == "last".to_string())) { { let receiver = method_receiver(scrut.clone()); @@ -8148,8 +8112,7 @@ pub fn annotate_descent(body: Rc, ctx: Rc) -> Rc { } _ => None, }; - let scrut_has_inductive = (((scrut_type.clone().as_str() - != "".to_string().as_str()) + let scrut_has_inductive = (((scrut_type.clone() != "".to_string()) && ((inductive_fields_for(ctx.type_env.clone(), scrut_type.clone()).len() as i64) > 0)) @@ -8190,7 +8153,7 @@ let arm_ctx = match variant_arm_ctx.clone() { None => if scrut_has_inductive.clone() { match (*arm_pattern(arm_node.clone())).clone() { MatchPattern::VariantPattern { name: vname, field_bindings: bindings, .. } => match scrut_inducing_field.clone() { - Some(ind_field) => if (vname.clone().as_str() == "Present".to_string().as_str()) { + Some(ind_field) => if (vname.clone() == "Present".to_string()) { bindings.clone().iter().cloned().fold(ctx.clone(), |c: Rc, fb: Rc| match (*field_binding_pattern(fb.clone())).clone() { MatchPattern::Bind { name: bname, .. } => Rc::new(DescentContext { fn_name: c.fn_name.clone(), @@ -8214,9 +8177,9 @@ let inner_bind_name = match (*field_binding_pattern(inner_fb.clone())).clone() { MatchPattern::Bind { name: ibname, .. } => ibname.clone(), _ => "".to_string(), }; -let inner_matching = Rc::new({ let mut __result = Vec::new(); for f in inner_ind_fields.clone().iter().cloned() { if ((f.variant_name.clone().as_str() == inner_vname.clone().as_str()) && (f.field_name.clone().as_str() == inner_field_name.clone().as_str())) { __result.push(f); } } __result }).first().cloned(); +let inner_matching = Rc::new({ let mut __result = Vec::new(); for f in inner_ind_fields.clone().iter().cloned() { if ((f.variant_name.clone() == inner_vname.clone()) && (f.field_name.clone() == inner_field_name.clone())) { __result.push(f); } } __result }).first().cloned(); match inner_matching.clone() { - Some(inner_ind_field) => if (inner_bind_name.clone().as_str() != "".to_string().as_str()) { + Some(inner_ind_field) => if (inner_bind_name.clone() != "".to_string()) { Rc::new(DescentContext { fn_name: ic.fn_name.clone(), param_names: v1_rt::rc_map_insert(ic.param_names.clone(), inner_bind_name.clone(), inner_ind_field.element_type.clone()), @@ -8251,9 +8214,9 @@ let bind_name = match (*field_binding_pattern(fb.clone())).clone() { MatchPattern::Bind { name: bname, .. } => bname.clone(), _ => "".to_string(), }; -let matching = Rc::new({ let mut __result = Vec::new(); for f in ind_fields.clone().iter().cloned() { if ((f.variant_name.clone().as_str() == vname.clone().as_str()) && (f.field_name.clone().as_str() == field_name.clone().as_str())) { __result.push(f); } } __result }).first().cloned(); +let matching = Rc::new({ let mut __result = Vec::new(); for f in ind_fields.clone().iter().cloned() { if ((f.variant_name.clone() == vname.clone()) && (f.field_name.clone() == field_name.clone())) { __result.push(f); } } __result }).first().cloned(); match matching.clone() { - Some(ind_field) => if (bind_name.clone().as_str() != "".to_string().as_str()) { + Some(ind_field) => if (bind_name.clone() != "".to_string()) { Rc::new(DescentContext { fn_name: c.fn_name.clone(), param_names: c.param_names.clone(), @@ -8276,7 +8239,7 @@ match matching.clone() { }) }, }, - MatchPattern::Bind { name: bname, .. } => if (scrut_type.clone().as_str() != "".to_string().as_str()) { + MatchPattern::Bind { name: bname, .. } => if (scrut_type.clone() != "".to_string()) { Rc::new(DescentContext { fn_name: ctx.fn_name.clone(), param_names: v1_rt::rc_map_insert(ctx.param_names.clone(), bname.clone(), scrut_type.clone()), @@ -8369,7 +8332,7 @@ make_arm_node(arm_pattern(arm_node.clone()), arm_guard(arm_node.clone()), annota }; Rc::new(DescentContext { fn_name: ctx.fn_name.clone(), - param_names: if (sub_type.clone().as_str() != "".to_string().as_str()) { + param_names: if (sub_type.clone() != "".to_string()) { v1_rt::rc_map_insert( ctx.param_names.clone(), binding_name.clone(), @@ -8486,9 +8449,7 @@ make_arm_node(arm_pattern(arm_node.clone()), arm_guard(arm_node.clone()), annota }; Rc::new(DescentContext { fn_name: acc.ctx.clone().fn_name.clone(), - param_names: if (sub_type.clone().as_str() - != "".to_string().as_str()) - { + param_names: if (sub_type.clone() != "".to_string()) { v1_rt::rc_map_insert( acc.ctx.clone().param_names.clone(), bname.clone(), @@ -8592,7 +8553,7 @@ make_arm_node(arm_pattern(arm_node.clone()), arm_guard(arm_node.clone()), annota raw_receiver.clone(), ctx.type_env.clone().source_indices.clone(), ); - if (inner_mname.as_str() == "enumerate".to_string().as_str()) { + if (inner_mname == "enumerate".to_string()) { method_receiver(raw_receiver.clone()) } else { raw_receiver.clone() @@ -8638,7 +8599,7 @@ make_arm_node(arm_pattern(arm_node.clone()), arm_guard(arm_node.clone()), annota None => "".to_string(), }, }; - if (base_type.clone().as_str() != "".to_string().as_str()) { + if (base_type.clone() != "".to_string()) { Rc::new({ let mut __result = Vec::new(); for f in inductive_fields_for( @@ -8648,9 +8609,7 @@ make_arm_node(arm_pattern(arm_node.clone()), arm_guard(arm_node.clone()), annota .iter() .cloned() { - if (f.field_name.clone().as_str() - == fname.clone().as_str()) - { + if (f.field_name.clone() == fname.clone()) { __result.push(f); } } @@ -8954,9 +8913,7 @@ pub fn infer_output_provenance( |acc: Rc>, p: Rc| { let pname = param_node_name_at(p.clone(), type_env.source_indices.clone()); let ptype = resolved_type_name(p.clone(), type_env.source_indices.clone()); - if ((pname.clone().as_str() != "".to_string().as_str()) - && (ptype.clone().as_str() != "".to_string().as_str())) - { + if ((pname.clone() != "".to_string()) && (ptype.clone() != "".to_string())) { v1_rt::rc_map_insert(acc.clone(), pname.clone(), ptype.clone()) } else { acc.clone() @@ -9022,7 +8979,7 @@ pub fn classify_body_provenance( if { let mut __found = false; for pn in param_names.clone().iter().cloned() { - if (pn.clone().as_str() == vname.clone().as_str()) { + if (pn.clone() == vname.clone()) { __found = true; break; } @@ -9071,7 +9028,7 @@ pub fn classify_body_provenance( } _ => "".to_string(), }; - if (type_for_lookup.clone().as_str() != "".to_string().as_str()) { + if (type_for_lookup.clone() != "".to_string()) { { let fields = inductive_fields_for( type_env.clone(), @@ -9080,9 +9037,7 @@ pub fn classify_body_provenance( let matching = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { - if (f.field_name.clone().as_str() - == field.clone().as_str()) - { + if (f.field_name.clone() == field.clone()) { __result.push(f); } } @@ -9238,7 +9193,7 @@ let bind_name = match (*field_binding_pattern(binding.clone())).clone() { MatchPattern::Bind { name: bn, .. } => bn.clone(), _ => "".to_string(), }; -if ((bind_name.clone().as_str() != "".to_string().as_str()) && (field_label.clone().as_str() != "".to_string().as_str())) { +if ((bind_name.clone() != "".to_string()) && (field_label.clone() != "".to_string())) { { let field_prov = Rc::new(v1_rt::map_keys(&scrut_prov)).iter().cloned().fold(empty_prov_map(), |fp_acc: Rc>>, pname: String| maybe_insert_match_field_relation(fp_acc, pname.clone(), field_label.clone(), vname.clone(), v1_rt::map_get(&scrut_prov, pname.clone()), param_types.clone(), type_env.clone())); v1_rt::rc_map_insert(acc.clone(), bind_name.clone(), field_prov.clone()) @@ -9426,7 +9381,7 @@ pub fn method_call_args_by_name( Some(sig) => match sig.params.clone().first().cloned() { Some(first_p) => { let first_pname = param_node_name_at(first_p.clone(), source_indices.clone()); - if (first_pname.clone().as_str() != "".to_string().as_str()) { + if (first_pname.clone() != "".to_string()) { v1_rt::rc_map_insert( v1_rt::rc_empty_map::>(), first_pname.clone(), @@ -9838,8 +9793,8 @@ pub fn arm_ctx_from_variant_provenance( MatchPattern::Bind { name: bn, .. } => bn.clone(), _ => "".to_string(), }; - if ((bind_name.clone().as_str() == "".to_string().as_str()) - || (field_label.clone().as_str() == "".to_string().as_str())) + if ((bind_name.clone() == "".to_string()) + || (field_label.clone() == "".to_string())) { c.clone() } else { @@ -9997,8 +9952,8 @@ pub fn compute_variant_provenance( param_node_name_at(p.clone(), type_env.source_indices.clone()); let ptype = resolved_type_name(p.clone(), type_env.source_indices.clone()); - if ((pname.clone().as_str() != "".to_string().as_str()) - && (ptype.clone().as_str() != "".to_string().as_str())) + if ((pname.clone() != "".to_string()) + && (ptype.clone() != "".to_string())) { v1_rt::rc_map_insert(acc.clone(), pname.clone(), ptype.clone()) } else { @@ -10049,7 +10004,7 @@ pub fn collect_variant_constructors( parent_enum: pe, .. } => match pe.clone() { Some(enum_name) => { - if (enum_name.clone().as_str() == parent_enum.clone().as_str()) { + if (enum_name.clone() == parent_enum.clone()) { { let variant_name = body.name.clone(); let field_prov_map = body.children.clone().iter().cloned().fold( @@ -10073,7 +10028,7 @@ pub fn collect_variant_constructors( func_sigs.clone(), let_prov.clone(), ); - if (fname.clone().as_str() != "".to_string().as_str()) { + if (fname.clone() != "".to_string()) { v1_rt::rc_map_insert( m.clone(), fname.clone(), @@ -10110,9 +10065,7 @@ pub fn collect_variant_constructors( if ((authored_name_at( type_env.source_indices.clone(), sig.inferred.clone(), - ) - .as_str() - == parent_enum.clone().as_str()) + ) == parent_enum.clone()) && ((Rc::new(v1_rt::map_keys(&sig.variant_provenance.clone())).len() as i64) > 0)) @@ -10396,8 +10349,8 @@ pub fn populate_output_provenance( first_param.clone(), type_env.source_indices.clone(), ); - if ((ptype.clone().as_str() != "".to_string().as_str()) - && (pname.clone().as_str() != "".to_string().as_str())) + if ((ptype.clone() != "".to_string()) + && (pname.clone() != "".to_string())) { { let fields = inductive_fields_for( @@ -10689,9 +10642,7 @@ pub fn infer_auth_source_properties( if (field_init_node_name_at( p.clone(), scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == "svc_auth_source".to_string().as_str()) + ) == "svc_auth_source".to_string()) { { let val = field_init_node_value(p.clone()); @@ -11115,11 +11066,10 @@ pub fn infer_items( } pub fn is_type_variable_name(name: String) -> bool { - (((((name.clone().as_str() == "T".to_string().as_str()) - || (name.clone().as_str() == "K".to_string().as_str())) - || (name.clone().as_str() == "V".to_string().as_str())) - || (name.clone().as_str() == "MappedElement".to_string().as_str())) - || (name.clone().as_str() == "FoldAccumulator".to_string().as_str())) + (((((name.clone() == "T".to_string()) || (name.clone() == "K".to_string())) + || (name.clone() == "V".to_string())) + || (name.clone() == "MappedElement".to_string())) + || (name.clone() == "FoldAccumulator".to_string())) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -11134,7 +11084,7 @@ pub fn type_node_label( ) -> String { { let authored = authored_name_at(source_indices, n.clone()); - if (authored.clone().as_str() != "".to_string().as_str()) { + if (authored.clone() != "".to_string()) { authored.clone() } else { match n.inferred.clone().as_deref().cloned() { @@ -11159,9 +11109,9 @@ pub fn param_is_generic_decl( }; (((((pt.children.clone().len() as i64) == 0) && (pt.connective.clone() == Connective::NoConnective)) - && (pname.clone().as_str() != "".to_string().as_str())) - && ((pname.clone().as_str() == tname.as_str()) - || (type_expr_is_var && (pname.clone().as_str() == pt.name.clone().as_str())))) + && (pname.clone() != "".to_string())) + && ((pname.clone() == tname) + || (type_expr_is_var && (pname.clone() == pt.name.clone())))) } } @@ -11184,7 +11134,7 @@ pub fn unify_generics( && { let mut __found = false; for g in generic_names.clone().iter().cloned() { - if (g.clone().as_str() == bind_name.clone().as_str()) { + if (g.clone() == bind_name.clone()) { __found = true; break; } @@ -11243,9 +11193,9 @@ pub fn should_unify_record_lit_generics( { let formal_name = type_node_label(formal.clone(), source_indices.clone()); let record_name = type_node_label(arg_expr.clone(), source_indices.clone()); - (((formal_name.clone().as_str() != "".to_string().as_str()) - && (record_name.clone().as_str() != "".to_string().as_str())) - && (formal_name.clone().as_str() == record_name.clone().as_str())) + (((formal_name.clone() != "".to_string()) + && (record_name.clone() != "".to_string())) + && (formal_name.clone() == record_name.clone())) } } } @@ -11270,9 +11220,7 @@ pub fn unify_record_lit_field_walk( if (field_init_node_name_at( fi.clone(), scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == field_name.clone().as_str()) + ) == field_name.clone()) { __result.push(fi); } @@ -11327,7 +11275,7 @@ pub fn unify_record_lit_generics( let is_generic_slot = { let mut __found = false; for g in generic_names.clone().iter().cloned() { - if (g.clone().as_str() == formal_name.clone().as_str()) { + if (g.clone() == formal_name.clone()) { __found = true; break; } @@ -11349,8 +11297,8 @@ pub fn unify_record_lit_generics( record.clone(), scope.type_env.clone().source_indices.clone(), ); - if ((record_type_name.clone().as_str() != "".to_string().as_str()) - && (formal_name.clone().as_str() == record_type_name.clone().as_str())) + if ((record_type_name.clone() != "".to_string()) + && (formal_name.clone() == record_type_name.clone())) { unify_record_lit_field_walk( record_lit_expected_fields( @@ -11823,9 +11771,6 @@ pub fn build_type_env( source_indices: source_indices.clone(), intern_table: intern_table.clone(), }); - // §3 single-authority: no implicit std.types base-injection. Resolution - // flows through each module's explicit import graph only (mirrors - // v1.compiler.infer build_type_env in src/v1/04_infer.dag). let module_name_str = authored_name_at(source_indices.clone(), module.module.clone()); let parent_envs = Rc::new({ let mut __result = Vec::new(); @@ -11848,7 +11793,7 @@ pub fn build_type_env( imp.module_path.clone(), ) { Some(typed_parent) => { - if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { + if (imp.module_path.clone() == "std.types".to_string()) { Rc::new(v1_rt::map_keys( &typed_parent.type_env.clone().bindings.clone(), )) @@ -12420,8 +12365,7 @@ pub fn build_type_env_unresolved( source_indices: source_indices.clone(), intern_table: intern_table.clone(), }); - // §3 single-authority: no implicit std.types base-injection (mirrors - // build_type_env_unresolved in src/v1/04_infer.dag). + let module_name_str = authored_name_at(source_indices.clone(), module.module.clone()); let parent_envs = Rc::new({ let mut __result = Vec::new(); for imp in module.resolved_imports.clone().iter().cloned() { @@ -12443,7 +12387,7 @@ pub fn build_type_env_unresolved( imp.module_path.clone(), ) { Some(typed_parent) => { - if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { + if (imp.module_path.clone() == "std.types".to_string()) { Rc::new(v1_rt::map_keys( &typed_parent.type_env.clone().bindings.clone(), )) @@ -13357,8 +13301,8 @@ pub fn topo_resolve_types( let mut __all = true; for dep in deps.clone().iter().cloned() { if !((((is_kernel_type(dep.clone()) - || (dep.clone().as_str() == "None".to_string().as_str())) - || (dep.clone().as_str() == "".to_string().as_str())) + || (dep.clone() == "None".to_string())) + || (dep.clone() == "".to_string())) || is_recursive_type_by_name(env.clone(), dep.clone())) || (v1_rt::set_contains(&remaining_set, dep.clone()) == false)) { @@ -13571,9 +13515,7 @@ pub fn variant_has_positional_payload_shape( ) -> bool { (((variant.children.clone().len() as i64) == 1) && match variant.children.clone().first().cloned() { - Some(f) => { - (field_node_name_at(f.clone(), source_indices).as_str() == "0".to_string().as_str()) - } + Some(f) => (field_node_name_at(f.clone(), source_indices) == "0".to_string()), None => false, }) } @@ -13700,6 +13642,40 @@ pub fn build_positional_payload_variants( ) } +pub fn rust_corpus_repr(modules: Rc>>) -> RustCorpusRepr { + { + let has_seed = { + let mut __found = false; + for m in modules.iter().cloned() { + if { + let mut __found = false; + for k in Rc::new(v1_rt::map_keys(&m.type_env.clone().source_indices.clone())) + .iter() + .cloned() + { + if (v1_rt::contains(k.clone(), "/v1/".to_string()) + || v1_rt::contains(k.clone(), "src/v1".to_string())) + { + __found = true; + break; + } + } + __found + } { + __found = true; + break; + } + } + __found + }; + if has_seed { + RustCorpusRepr::HostNative + } else { + RustCorpusRepr::FaithfulFreeMonoid + } + } +} + pub fn build_emit_graph_info(modules: Rc>>) -> Rc { { let init = Rc::new(EmitInfoBuildState { @@ -13756,6 +13732,7 @@ pub fn build_emit_graph_info(modules: Rc>>) -> Rc>, >(), read_only_params: v1_rt::rc_empty_set::(), + corpus_repr: rust_corpus_repr(modules.clone()), }) } } diff --git a/src/v1/stage0/src/v1_compiler_infer_emit_info.rs b/src/v1/stage0/src/v1_compiler_infer_emit_info.rs index 98745ada53b..315a71c5dae 100644 --- a/src/v1/stage0/src/v1_compiler_infer_emit_info.rs +++ b/src/v1/stage0/src/v1_compiler_infer_emit_info.rs @@ -1,6 +1,32 @@ // Generated by v1 compiler -- do not edit. // Source module: v1.compiler.infer_emit_info +// +// HAND-SYNCED MIRROR (class-3 splice) -- this committed seed is a HAND-SYNCED +// MIRROR of the .dag authority, NOT a regen fixpoint. One of three class-3 +// files (with v1_compiler_emit_rust.rs, v1_compiler_infer.rs) spliced from a +// faithful regen of the class-3 .dag onto the committed seed. +// LANE (deferred): regen-fixpoint emitter-self-host (~150-gap) -- wire-all-emitted- +// modules so a clean regen reproduces this committed seed bit-identically (the +// §7 reproduce-fixpoint that licenses deleting src/v1). +// SCOPE: a faithful full regen wires the deliberately-unwired orphan std modules +// (std_measure / std_algebra / std_realization_schedule / std_machine_constraints +// / std_integer / extdeps_version_semver / extdeps_cargo_version) and surfaces +// ~150 latent emitter-completeness gaps (std numeric/measure-tower generic +// emission). They stay UNWIRED here exactly as on main. +// PROVENANCE (#5514 verbatim deferral): "regen-write still emits a non-building +// seed from ~150 emitter-completeness gaps, the clean green regen fixpoint is +// deferred, converges with the Route-A emitter self-host". +// DISSOLUTION TRIGGER: §7 fixpoint convergence with the Route-A emitter self-host +// -- when wire-all-emitted-modules -> regen-equals-committed is in reach; a fresh +// work-item gets dispatched THEN. (breadcrumb: node://adhoc-80af9ff8-40f) +// INVARIANCE CAVEAT (quick-seal, verbatim): class-3 host-vs-faithful SELECTION is +// representation-invariant on the v1-bundled HOST seed at this tip -- CONTROL B +// (gate-isolated revert) builds green, CONTROL A errors are the wire policy +// confound not representation; the selection's behavioral discriminating-proof is +// OWED by the deferred faithful target, where the selection actually fires. +// Full detail: carrier mark in v1_compiler_emit_rust.rs. +use self::RustCorpusRepr::*; use self::TypeRepr::*; pub use crate::v1_compiler_infer_types::{ child_type_node, emit_map_has, node_type_equals, normalize_access_type_node, @@ -62,6 +88,15 @@ pub struct TypeSummary { pub has_fn_fields: bool, } +#[derive( + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize, +)] +#[serde(tag = "_variant")] +pub enum RustCorpusRepr { + HostNative, + FaithfulFreeMonoid, +} + #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct EmitGraphInfo { pub type_summaries: Rc>>, @@ -75,6 +110,7 @@ pub struct EmitGraphInfo { pub owned_bindings: Rc>, pub read_only_params_index: Rc>>>, pub read_only_params: Rc>, + pub corpus_repr: RustCorpusRepr, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -96,6 +132,7 @@ pub fn empty_emit_graph_info() -> Rc { read_only_params_index: v1_rt::rc_empty_map::>>( ), read_only_params: v1_rt::rc_empty_set::(), + corpus_repr: RustCorpusRepr::FaithfulFreeMonoid, }) } @@ -453,9 +490,8 @@ pub fn build_field_type_map( false }; let key = authored_name_at(source_indices.clone(), child.clone()); - if (((resolved_name.clone().as_str() != "".to_string().as_str()) - && !ft_is_type_var.clone()) - && (resolved_name.clone().as_str() != "Dynamic".to_string().as_str())) + if (((resolved_name.clone() != "".to_string()) && !ft_is_type_var.clone()) + && (resolved_name.clone() != "Dynamic".to_string())) { v1_rt::rc_map_insert(acc.clone(), key.clone(), resolved_name.clone()) } else { @@ -621,3 +657,6 @@ pub fn add_emit_item_summary( None => state, } } + +pub struct HostNative; +pub struct FaithfulFreeMonoid; diff --git a/src/v1/stage0/src/v1_interpreter.rs b/src/v1/stage0/src/v1_interpreter.rs index d8da3a55aaa..13cd16d8c86 100644 --- a/src/v1/stage0/src/v1_interpreter.rs +++ b/src/v1/stage0/src/v1_interpreter.rs @@ -3524,6 +3524,33 @@ fn eval_algebra_method( }) } + // list_push(list, item): append the argument as a SINGLE element, even + // when it is itself a list (unlike concat/append/push below, which merge + // a list-valued arg). Mirrors the free-function list_push so the same op + // resolves through method dispatch too; the lexer drives it. Additive. + "list_push" => { + if matches!(&receiver, Value::Str(_)) { + return Err(InterpError::TypeError { + msg: "list_push not supported on String".to_string(), + }); + } + let item = args.first().cloned().unwrap_or(Value::Null); + match value_to_list_carrier(&receiver) { + Some((items, copied)) => { + let mut counters = ctx.mutation_counters.borrow_mut(); + counters.list_push_calls += 1; + counters.list_push_items_copied += copied; + drop(counters); + let mut result = (*items).clone(); + result.push_back(item); + Ok(list_value(result)) + } + None => Err(InterpError::TypeError { + msg: format!("list_push on non-list: {}", receiver.type_label()), + }), + } + } + "concat" | "append" | "push" => { // String concat preserves the String representation: a String IS a // FreeMonoid, but its canonical value form is Value::Str — concat must @@ -3677,6 +3704,18 @@ fn eval_algebra_method( Ok(Value::Str(strs.join(&sep))) } + // chars(s) -> List: decompose a String into its Unicode code + // points (Ints), matching the emitted Rust template in + // languages.dag (`{recv}.chars().map(|c| c as i64).collect()`) and the + // lexer's `source_chars: List` consumer (01_tokenize). Free-call + // `chars(source)` desugars to receiver-style method dispatch here; the + // interpreter must implement it to run the full compile/emit fold. + "chars" => { + let s = expect_str(Some(&receiver), "chars")?; + let items: Vec = s.chars().map(|c| Value::Int(c as i64)).collect(); + Ok(list_value(items)) + } + // Map key lookup is checked BEFORE the FreeMonoid list path: a String IS a // FreeMonoid, but `.get` on a String is not char-list indexing (ctrl#1476 B1; // same Str-representation rule as `index` / `slice` / `contains`). @@ -5311,6 +5350,39 @@ fn eval_builtin( _ => Ok(None), }, + // chars_to_string(chars: List, start, end) -> String: slice a + // code-point list [start, end) into a String (v1_rt::chars_to_string / + // languages.dag). The lexer builds token text this way, so the + // interpreter needs it to run the full compile/emit fold. + "chars_to_string" => { + let cps = match positional.first().copied() { + Some(v) => free_monoid_to_vec(v).ok_or_else(|| InterpError::TypeError { + msg: "chars_to_string expects a list of code points".to_string(), + })?, + None => { + return Err(InterpError::TypeError { + msg: "chars_to_string requires a code-point list".to_string(), + }) + } + }; + let len = cps.len() as i64; + let start = expect_int(positional.get(1).copied(), "chars_to_string start")? + .max(0) + .min(len); + let end = expect_int(positional.get(2).copied(), "chars_to_string end")? + .max(0) + .min(len) + .max(start); + let s: String = cps[start as usize..end as usize] + .iter() + .filter_map(|v| match v { + Value::Int(cp) => char::from_u32(*cp as u32), + _ => None, + }) + .collect(); + Ok(Some(Value::Str(s))) + } + "parse_int" => { let s = expect_str(positional.first().copied(), "parse_int")?; match s.parse::() { @@ -5319,6 +5391,13 @@ fn eval_builtin( } } + // Source-char cost metering primitive (runtime_rust.dag): a zero-arg + // side-effecting host fn the lexer (01_tokenize) calls directly. The + // compiled seed records a counter; the interpreter has no such counter, + // so it is a no-op returning unit. Needed for the interpreter to run + // the full compile/emit fold. + "record_source_chars_index_lookup" => Ok(Some(Value::Unit)), + "concat" => { // Variadic string concat (common in .dag code) if positional.len() >= 2 && positional.iter().all(|v| matches!(v, Value::Str(_))) { @@ -6527,20 +6606,31 @@ fn raw_map_lookup( }, Value::Record { fields, .. } | Value::Variant { fields, .. } => { let lookup_sym = ctx.sym("lookup"); - let lookup = fields - .get(&lookup_sym) - .ok_or_else(|| InterpError::TypeError { - msg: format!("raw_map_lookup expects Map, got {}", map.type_label()), - })?; - match lookup { - Value::Closure { .. } => apply_closure(lookup, &[key.clone()], env, ctx), - Value::Fn { node } => { + match fields.get(&lookup_sym) { + // A lookup-table abstraction carries a callable `lookup` field. + Some(lookup @ Value::Closure { .. }) => { + apply_closure(lookup, &[key.clone()], env, ctx) + } + Some(Value::Fn { node }) => { let named = vec![(None, key.clone())]; call_function(ctx, node, &named, env) } - _ => Err(InterpError::TypeError { + Some(_) => Err(InterpError::TypeError { msg: "Map.lookup field is not callable".to_string(), }), + // Record-form map (a `data x: Map = { ... }` literal, which + // the interpreter builds as a Record): look the key up as a + // field name. A miss yields Null, which the Witness/Optional + // bridge projects to Violates/Absent (see eval_match_pattern's + // record-form empty_map handling). Additive: this case + // previously errored. + None => match key { + Value::Str(s) => { + let k = ctx.sym(s); + Ok(fields.get(&k).cloned().unwrap_or(Value::Null)) + } + _ => Ok(Value::Null), + }, } } _ => Err(InterpError::TypeError { diff --git a/src/v1/stage0/src/wire_value_serialize.rs b/src/v1/stage0/src/wire_value_serialize.rs index e5e228ad024..24c49a1de93 100644 --- a/src/v1/stage0/src/wire_value_serialize.rs +++ b/src/v1/stage0/src/wire_value_serialize.rs @@ -149,17 +149,20 @@ fn serialize_variant_to_wire_json( .unwrap_or_else(|| format!("wire policy error for coproduct {type_name}"))); } - if policy_is_untagged(&policy) { + // HAND-SYNCED MIRROR drift fix: the class-3 emit_rust splice takes the wire + // policy by value (Rc), so pass policy.clone() (cheap Rc + // clone) instead of &policy. See the carrier mark in v1_compiler_emit_rust.rs. + if policy_is_untagged(policy.clone()) { return serialize_untagged_variant(fields, ctx); } - if policy_is_string_variant(&policy) { + if policy_is_string_variant(policy.clone()) { let tag = wire_variant_tag_for_policy(variant_name.to_string(), policy.clone()) .ok_or_else(|| format!("no wire tag for string variant {type_name}::{variant_name}"))?; return Ok(serde_json::Value::String(tag)); } - if let Some(tag_field) = policy_serde_tag_field(&policy) { + if let Some(tag_field) = policy_serde_tag_field(policy.clone()) { let wire_tag = wire_variant_tag_for_policy(variant_name.to_string(), policy.clone()) .ok_or_else(|| { format!("no wire tag for internally-tagged variant {type_name}::{variant_name}") @@ -176,7 +179,7 @@ fn serialize_variant_to_wire_json( } // TaggedVariant default: {"_variant": "Name", ...fields} - let tag_key = policy_serde_tag_field(&policy).unwrap_or_else(|| "_variant".to_string()); + let tag_key = policy_serde_tag_field(policy.clone()).unwrap_or_else(|| "_variant".to_string()); let default_tag = if policy.enum_attr == rust_serde_tag_attr() { variant_name.to_string() } else { diff --git a/src/v1/tests/src/width_nat_type_arg_test.rs b/src/v1/tests/src/width_nat_type_arg_test.rs index dbac53c96a7..e71e7867c1d 100644 --- a/src/v1/tests/src/width_nat_type_arg_test.rs +++ b/src/v1/tests/src/width_nat_type_arg_test.rs @@ -79,7 +79,7 @@ fn v1_std_float_dag_resolves_with_literal_machine_width() { } #[test] -#[ignore = "emitter seed on main lacks dag fix until #5325 co-land; E0107 10→0 verified via 2-stage bootstrap"] +#[ignore = "fix is in the .dag emitter (05_emit_rust) on this branch, but the in-process lib (committed stage0 seed) is not yet regenerated, so compile_sources here still uses the un-peeled emitter; un-ignore after the seed regen lands (2-stage bootstrap), per Track A step 3"] fn machine_width_phantom_arg_rust_emit_peels_literal_width_to_unit() { use v1_compiler::cli_run; use v1_compiler::v1_compiler_artifact::RenderTarget;