From 15292d69454fc53856d2a6448f544395a2c353d1 Mon Sep 17 00:00:00 2001 From: Brian Searls Date: Sun, 10 May 2026 00:10:06 +0000 Subject: [PATCH 1/8] retire exact string bridge residual --- docs/r3-program-plan.md | 2 +- docs/r3-structure.md | 2 +- dsl/std/types.dag | 10 +- src/v3/compiler/src/bootstrap.rs | 216 +-- src/v3/compiler/src/bootstrap_generated.rs | 1158 ++++++++--------- ...otstrap_generated_without_parse_surface.rs | 1158 ++++++++--------- src/v3/compiler/src/bootstrap_regen_fresh.rs | 1 - .../compiler/src/bootstrap_std_generated.rs | 1144 ++++++++-------- src/v3/compiler/src/diagnostics.rs | 18 +- src/v3/compiler/src/infer.rs | 8 +- .../integration/m1_5_verification_test.rs | 2 +- src/v3/std/bridge_ledger.dag | 27 +- 12 files changed, 1755 insertions(+), 1991 deletions(-) diff --git a/docs/r3-program-plan.md b/docs/r3-program-plan.md index e7f828d6165..b9cd13afc4f 100644 --- a/docs/r3-program-plan.md +++ b/docs/r3-program-plan.md @@ -258,7 +258,7 @@ This principle is NOT a separate lane; it's a per-lane gate-shape requirement ap | 32 | `bridge_mark_bootstrap_secret_nominal_opacity_retired` | state-check | T-Bridge-Retirement | **PASSING** | `dsl/std/types.dag` `type Secret nominal_opaque = String` + `src/v3/std/bridge_ledger.dag` row `Retired` + unit ratchet `dag.rs::bridge_mark_bootstrap_secret_nominal_opacity_retired` (bootstrap snapshots carry `Declaration.nominal_opacity` on `Secret`); historical name-keyed bootstrap bridge removed (#1272 / #937 lineage) | | 33 | `bridge_canonical_lens_name_dispatch_retired` | state-check | T-Bridge-Retirement | DECLARED | DeclarationRef/typed identity | | 34 | `bridge_include_str_side_channels_retired` | state-check | T-Bridge-Retirement | DECLARED | substrate query surface | -| 35 | `bridge_exact_string_patching_residual_retired` | state-check | T-Bridge-Retirement | DECLARED | umbrella for exact-string scaffolds | +| 35 | `bridge_exact_string_patching_residual_retired` | state-check | T-Bridge-Retirement | RETIRED | exact-string scaffolds retired; Bool-inhabits is source-authored and lower-helper patch remains zero-ratcheted | | 36 | `bridge_retirement_ledger_zero` | ledger-count | T-Bridge-Retirement | DECLARED | unified ledger reports 0 | | 37 | `cost_lens_reads_target_realization` | structural-fold | T-CostLens-Composition | **INTEGRATION_RECEIPT (partial — ε-slice)** — PR #2181 ε path: `lens_cost_target_realization_test.rs` proves (i) **TypeRealization** slice: Rust-side `symbolic_cost_of` on a tiny program × `rust_int` row `cost` composed via `Semiring` `sequential`; (ii) **CallableRealization** slice: bootstrap `rust_is_empty_callable` row `cost` readable as a lowered structural field (same row-shape discipline as (i), **without** a second `sequential` composition pin in that subtest). **Not** full emit-time / `LanguageSpec`-indexed cost-lens consumer (that closure remains with gates **#40** / **#70** / follow-on slices per program plan). Historical gate id; lens output stays abstract `SymbolicCost`. | ε-slice receipt; emit-time fold follow-on | | 38 | `coercion_cost_equals_complexity_by_construction` | structural-fold | T-CostLens-Composition | **SATISFIED-BY-CONSTRUCTION** (α-narrow PR #2171; `Semiring` `sequential`/`iterate` at `src/v3/std/algebra.dag:181-188` is sole composition authority — no parallel "complexity-vs-cost" reconciliation surface exists) | thesis unification holds structurally | diff --git a/docs/r3-structure.md b/docs/r3-structure.md index a4de53f8f5a..6d077eccd21 100644 --- a/docs/r3-structure.md +++ b/docs/r3-structure.md @@ -117,7 +117,7 @@ L6 (`l6_structural_form_coverage`) was moved out of this lane during the engine- - `bridge_mark_bootstrap_secret_nominal_opacity_retired` — name-keyed bootstrap bridge from #937 deleted; nominal-opacity authority lives in source-level declaration (PR A landed in R2) - `bridge_canonical_lens_name_dispatch_retired` — lens dispatch routes via `DeclarationRef`/typed identity, not canonical name strings - `bridge_include_str_side_channels_retired` — no `include_str!` macro reads source-substrate identity; substrate query surface used instead. **Open disposition (`pipeline_authority`, PR #1171, 2026-04-29):** `compile` remains `ArrowBody::Unparsed`, so compile-body stage order is not yet a structural Dag fact; runtime ordering reads `PipelineStageBinding` only — full gate for this site awaits derivation / lowered compile witness, not file IO. - - `bridge_exact_string_patching_residual_retired` — umbrella row for exact-string patching scaffolds. **PB lower-helper slice (Tier-2 / #1014 lineage) is pinned at zero** in v3-compiler Rust: no `patch_lower_helpers*` code paths remain, and `bridge_lower_helpers_patch_zero_residual_test` ratchets reintroduction. **Other** exact-string patching classes (outside this retired lower-helper post-process bridge) remain **out of scope for this receipt** and keep their own dissolution triggers. + - `bridge_exact_string_patching_residual_retired` — exact-string patching scaffolds retired. **PB lower-helper slice (Tier-2 / #1014 lineage) is pinned at zero** in v3-compiler Rust: no `patch_lower_helpers*` code paths remain, and `bridge_lower_helpers_patch_zero_residual_test` ratchets reintroduction. The BR-19 Bool-inhabits post-parse patch is retired by authoring `Bool inhabits BooleanAlgebra` directly in `dsl/std/types.dag`; bootstrap no longer mutates `Declaration.inhabits` for kernel `Bool`. - `bridge_retirement_ledger_zero` — unified ledger reports 0 named identity bridges remaining - **T-V2-Retirement** (NEW 2026-04-30; pulled into R3 per user directive *"nothing can be deferred past R3"*). - `v2_oracle_no_remaining_test_consumers` — no `.rs` test file under the workspace consumes anything from `src/v2/`; v2-oracle and v2-using test scaffolds retired diff --git a/dsl/std/types.dag b/dsl/std/types.dag index 75cbef5d4b7..9e5e2a928e9 100644 --- a/dsl/std/types.dag +++ b/dsl/std/types.dag @@ -164,13 +164,9 @@ fn canonical_container_names() -> List { // require v3 to resolve aliases in Branch input type-checking // (currently pins Bool as a direct Disj for if/else). Deferred until // that compiler work lands; keeps intent-signaling via distinct names. -// v3 Path A (Lane 1e-2b): `Bool` still parses here for v2 (`dsl/` is v2-scanned); -// `Declaration.inhabits` → `BooleanAlgebra` is applied in v3 bootstrap -// (`bootstrap::patch_kernel_bool_boolean_algebra_inhabits`). Surface -// `type … inhabits … =` is v3-only under `src/v3/compiler/` (generated parser). -// Dissolution: when v2 accepts `inhabits` on types, move the clause here and -// delete `patch_kernel_bool_boolean_algebra_inhabits` (see that function's doc). -type Bool = True | False +// v3 Path A (Lane 1e-2b): the `Bool` -> `BooleanAlgebra` relation is +// authored here, not patched after parse. +type Bool inhabits BooleanAlgebra = True | False // Unit: terminal object (zero-field product, single inhabitant). type Unit diff --git a/src/v3/compiler/src/bootstrap.rs b/src/v3/compiler/src/bootstrap.rs index d1f6d6f845d..7808769b179 100644 --- a/src/v3/compiler/src/bootstrap.rs +++ b/src/v3/compiler/src/bootstrap.rs @@ -67,14 +67,14 @@ // go through. A failed bootstrap is visible to callers without a // side channel. // -// **PB-1-e split — what stays here:** `patch_kernel_bool_boolean_algebra_inhabits`, -// `materialize_pipeline_realizations`, and `report_pipeline_authority_error` remain -// in this file because the `#[cfg(test)]` module below exercises them on -// `Dag::new()` snapshots. The regen-only fresh tokenize/parse/lower loop lives in +// **PB-1-e split — what stays here:** `materialize_pipeline_realizations` and +// `report_pipeline_authority_error` remain in this file because the +// `#[cfg(test)]` module below exercises them on `Dag::new()` snapshots. +// The regen-only fresh tokenize/parse/lower loop lives in // `bootstrap_regen_fresh.rs` (feature `bootstrap-regen-fresh`); do not duplicate // pipeline materialization there without relocating or rewriting these unit tests. -use crate::dag::{ArrowBody, Dag, Declaration, TemplateArgument, TypeConnective}; +use crate::dag::{ArrowBody, Dag, TypeConnective}; use crate::diagnostics::{Diagnostic, SourceSpan}; use crate::pipeline_authority::ordered_pipeline_stages; @@ -103,113 +103,6 @@ pub const BOOTSTRAP_FIXTURE_PATH_KEYS: &[&str] = &[ "src/v3/std/cross_target_coverage.dag", ]; -/// v3-only inhabitance for kernel `Bool` (Class 5 / Lane 1e-2b Path A). -/// -/// `dsl/std/types.dag` must stay free of `inhabits` so v2 can parse every -/// `dsl/` file. After the std fixtures lower, wire `Bool` to -/// `BooleanAlgebra` the same way surface `inhabits` lowering would, -/// without shadowing `Bool` (which would reallocate sum variants and break -/// `src/v3/std/algebra.dag` pattern wiring). -/// -/// Preconditions are checked: any failure attaches a bootstrap -/// `Diagnostic::ResolveError` via `Dag::attach_diagnostic` so compilation -/// fails closed instead of silently omitting `inhabits`. -/// -/// **Dissolution:** remove this patch once the v2 compiler surface accepts -/// `type … inhabits … =` in `dsl/` (then express -/// `type Bool inhabits BooleanAlgebra = True | False` in -/// `dsl/std/types.dag` and delete `patch_kernel_bool_boolean_algebra_inhabits`). -#[cfg_attr(not(feature = "bootstrap-regen-fresh"), allow(dead_code))] -pub(crate) fn patch_kernel_bool_boolean_algebra_inhabits(dag: &mut Dag) { - // Audit row #2 retirement (bootstrap.rs slice 1 of 2): - // The path-string `dsl/std/types.dag` is encapsulated behind - // `BootstrapAuthorityKey::for_kernel_bool()` and is no longer named - // in this file outside doc-comments. The participation gate is - // retained — `declaration_by_name` still rank-biases on `span.file` - // (audit row #14, separate owner) so a bare lookup could surface a - // non-kernel duplicate; we walk the declarations directly and gate - // by the authority's `path()` egress so the witness, not a free - // constant, is the structural source. Full dissolution (delete the - // gate; rely on a structural kernel-`Bool` `DeclarationId` accessor) - // lands when row #14 retires. - let bool_authority = crate::diagnostics::BootstrapAuthorityKey::for_kernel_bool(); - let Some(bool_decl) = dag - .declarations() - .iter() - .find(|d| d.name.as_deref() == Some("Bool") && d.span.file == bool_authority.path()) - else { - let authority_span = SourceSpan::new(bool_authority.path(), 0, 0); - dag.attach_bootstrap_diagnostic( - bool_authority, - Diagnostic::ResolveError { - name: "bootstrap: Lane 1e-2b Path A — kernel `Bool` not found in bootstrap Dag; \ - cannot set `Declaration.inhabits` for `BooleanAlgebra`" - .to_string(), - span: authority_span, - fixes: Vec::new(), - }, - ); - return; - }; - let bool_id = bool_decl.id; - let span_for_inst = bool_decl.span.clone(); - if dag.declaration(bool_id).inhabits.is_some() { - return; - } - let (ba_template, param_id) = { - let Some(ba) = dag.declaration_by_name("BooleanAlgebra") else { - dag.attach_bootstrap_diagnostic( - bool_authority, - Diagnostic::ResolveError { - name: "bootstrap: Lane 1e-2b Path A — `BooleanAlgebra` not present in the \ - bootstrap Dag; cannot wire kernel `Bool` `inhabits`" - .to_string(), - span: span_for_inst.clone(), - fixes: Vec::new(), - }, - ); - return; - }; - let Some(¶m_id) = ba.type_params.first() else { - dag.attach_bootstrap_diagnostic( - bool_authority, - Diagnostic::ResolveError { - name: - "bootstrap: Lane 1e-2b Path A — `BooleanAlgebra` has no type parameters; \ - cannot instantiate `BooleanAlgebra` for kernel `Bool` `inhabits`" - .to_string(), - span: span_for_inst.clone(), - fixes: Vec::new(), - }, - ); - return; - }; - (ba.id, param_id) - }; - let inst_id = dag.alloc_declaration_id(); - dag.push_declaration(Declaration { - id: inst_id, - name: None, - connective: TypeConnective::Instantiation { - template: ba_template, - arguments: vec![TemplateArgument { - parameter: param_id, - value: bool_id, - }], - }, - type_params: Vec::new(), - phantom_params: Vec::new(), - meta_tag: None, - specialization_parent: None, - inhabits: None, - value_body: None, - refinement: None, - nominal_opacity: None, - span: span_for_inst, - }); - dag.declaration_mut(bool_id).inhabits = Some(inst_id); -} - // DB-14 substrate accessors (`port` / `node` / `resolve_producer`) are // deliberately NOT materialized at bootstrap. Their Arrow bodies stay // `Unparsed` (the `{ host }` stub) because the accessor → realization @@ -523,103 +416,4 @@ mod tests { "expected exactly one bootstrap-attributed pipeline-stage diagnostic, got {matched}" ); } - - #[test] - fn kernel_bool_path_a_attaches_diagnostic_when_boolean_algebra_unresolvable() { - let mut dag = Dag::new(); - assert!( - dag.diagnostics().is_empty(), - "production bootstrap should satisfy Path A preconditions: {:?}", - dag.diagnostics().iter().collect::>() - ); - - let bool_id = dag - .declaration_by_name("Bool") - .expect("kernel Bool from std") - .id; - dag.declaration_mut(bool_id).inhabits = None; - - let ba_id = dag - .declaration_by_name("BooleanAlgebra") - .expect("BooleanAlgebra from std") - .id; - dag.declaration_mut(ba_id).name = Some("__test_hidden_BooleanAlgebra".to_string()); - - super::patch_kernel_bool_boolean_algebra_inhabits(&mut dag); - - assert!( - dag.declaration(bool_id).inhabits.is_none(), - "inhabits must stay unset when the patch cannot complete" - ); - assert!( - dag.diagnostics().iter().any(|(_, diag)| { - matches!( - diag, - Diagnostic::ResolveError { name, .. } - if name.contains("Lane 1e-2b Path A") && name.contains("BooleanAlgebra") - ) - }), - "expected bootstrap Path A diagnostic, got {:?}", - dag.diagnostics().iter().collect::>() - ); - } - - /// PB row 82 surface: detached phantom-port bootstrap diagnostics - /// must carry [`DiagnosticAttribution::BootstrapAuthority`] so - /// Verification can recover bootstrap origin without comparing - /// `SourceSpan.file` against a known authority path. Drives the - /// same Path A failure as the sibling test above and asserts the - /// attribution surface; consumer-side dispatch uses - /// `attribution.is_bootstrap()` and witness identity. - #[test] - fn kernel_bool_path_a_diagnostic_carries_bootstrap_authority_attribution() { - use crate::diagnostics::{BootstrapAuthorityKey, DiagnosticAttribution}; - - let mut dag = Dag::new(); - let bool_id = dag.declaration_by_name("Bool").expect("kernel Bool").id; - dag.declaration_mut(bool_id).inhabits = None; - let ba_id = dag - .declaration_by_name("BooleanAlgebra") - .expect("BooleanAlgebra") - .id; - dag.declaration_mut(ba_id).name = Some("__test_hidden_BooleanAlgebra".to_string()); - - super::patch_kernel_bool_boolean_algebra_inhabits(&mut dag); - - let expected_key = BootstrapAuthorityKey::for_kernel_bool(); - let mut bootstrap_attributed = 0usize; - for (port, diag, attribution) in dag.diagnostics().iter_attributed() { - // Sanity-check: the message we expect from this scenario. - let Diagnostic::ResolveError { name, .. } = diag else { - continue; - }; - if !(name.contains("Lane 1e-2b Path A") && name.contains("BooleanAlgebra")) { - continue; - } - // Consumer-side dispatch: no `span.file ==` compare here. - assert!( - attribution.is_bootstrap(), - "Path A diagnostic at port {port:?} must be DiagnosticAttribution::BootstrapAuthority(_), got {attribution:?}" - ); - assert_eq!( - attribution.as_bootstrap_authority(), - Some(&expected_key), - "attribution witness must match dsl/std/types.dag bootstrap-authority key" - ); - // Same answer through the per-port accessor. - assert_eq!( - dag.diagnostics().attribution(port), - Some(&DiagnosticAttribution::BootstrapAuthority( - expected_key.clone() - )) - ); - bootstrap_attributed += 1; - } - assert_eq!( - bootstrap_attributed, 1, - "expected exactly one bootstrap-attributed Path A diagnostic, got {bootstrap_attributed} \ - (table: {:?})", - dag.diagnostics().iter_attributed().collect::>() - ); - } } diff --git a/src/v3/compiler/src/bootstrap_generated.rs b/src/v3/compiler/src/bootstrap_generated.rs index 60ef6ab8b97..bcd4578cbfd 100644 --- a/src/v3/compiler/src/bootstrap_generated.rs +++ b/src/v3/compiler/src/bootstrap_generated.rs @@ -59,7 +59,7 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { id: NodeId(3), data: LiteralBits::Int("1".to_string()), output: PortId(4), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -67,13 +67,13 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(3), PortId(4)], output: PortId(5), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(5), data: LiteralBits::Int("5".to_string()), output: PortId(6), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -81,21 +81,21 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(3), PortId(6)], output: PortId(7), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(7), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(5), PortId(7)], output: PortId(8), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(8), name: "".to_string(), value: PortId(8), params: vec![PortId(3)], - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, emit_participation: None, })); @@ -103,7 +103,7 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { id: NodeId(9), data: LiteralBits::Int("100".to_string()), output: PortId(10), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -111,13 +111,13 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(9), PortId(10)], output: PortId(11), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(11), data: LiteralBits::Int("599".to_string()), output: PortId(12), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -125,21 +125,21 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(9), PortId(12)], output: PortId(13), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(13), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(11), PortId(13)], output: PortId(14), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(14), name: "".to_string(), value: PortId(14), params: vec![PortId(9)], - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, emit_participation: None, })); @@ -147,7 +147,7 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { id: NodeId(15), data: LiteralBits::Int("1".to_string()), output: PortId(16), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -155,13 +155,13 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(15), PortId(16)], output: PortId(17), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(17), data: LiteralBits::Int("65535".to_string()), output: PortId(18), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -169,21 +169,21 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(15), PortId(18)], output: PortId(19), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(19), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(17), PortId(19)], output: PortId(20), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(20), name: "".to_string(), value: PortId(20), params: vec![PortId(15)], - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, emit_participation: None, })); @@ -191,7 +191,7 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { id: NodeId(21), data: LiteralBits::Int("0".to_string()), output: PortId(22), - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -199,14 +199,14 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(21), PortId(22)], output: PortId(23), - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(23), name: "".to_string(), value: PortId(23), params: vec![PortId(21)], - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), lane2_workflow: None, emit_participation: None, })); @@ -214,7 +214,7 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { id: NodeId(24), data: LiteralBits::Int("0".to_string()), output: PortId(25), - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -222,14 +222,14 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(24), PortId(25)], output: PortId(26), - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(26), name: "".to_string(), value: PortId(26), params: vec![PortId(24)], - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), lane2_workflow: None, emit_participation: None, })); @@ -237,7 +237,7 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { id: NodeId(27), data: LiteralBits::Int("0".to_string()), output: PortId(28), - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -245,14 +245,14 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(27), PortId(28)], output: PortId(29), - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(29), name: "".to_string(), value: PortId(29), params: vec![PortId(27)], - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), lane2_workflow: None, emit_participation: None, })); @@ -260,7 +260,7 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { id: NodeId(30), data: LiteralBits::Int("0".to_string()), output: PortId(31), - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -268,14 +268,14 @@ fn bootstrapped_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(30), PortId(31)], output: PortId(32), - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(32), name: "".to_string(), value: PortId(32), params: vec![PortId(30)], - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), lane2_workflow: None, emit_participation: None, })); @@ -10299,7 +10299,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(618)), + meta_tag: Some(DeclarationId(619)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::Map( @@ -10379,7 +10379,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(619)), + meta_tag: Some(DeclarationId(620)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::Map( @@ -10493,7 +10493,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(620)), + meta_tag: Some(DeclarationId(621)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::Map( @@ -10543,7 +10543,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(621)), + meta_tag: Some(DeclarationId(622)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::Map( @@ -10658,11 +10658,11 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { phantom_params: Vec::new(), meta_tag: None, specialization_parent: None, - inhabits: Some(DeclarationId(664)), + inhabits: Some(DeclarationId(512)), value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7546, 7570), + span: SourceSpan::new("dsl/std/types.dag", 7187, 7241), }); declarations.push(Declaration { id: DeclarationId(127), @@ -10676,7 +10676,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7638, 7647), + span: SourceSpan::new("dsl/std/types.dag", 7309, 7318), }); declarations.push(Declaration { id: DeclarationId(128), @@ -10690,7 +10690,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7764, 7773), + span: SourceSpan::new("dsl/std/types.dag", 7435, 7444), }); declarations.push(Declaration { id: DeclarationId(129), @@ -10704,7 +10704,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7774, 7784), + span: SourceSpan::new("dsl/std/types.dag", 7445, 7455), }); declarations.push(Declaration { id: DeclarationId(130), @@ -10721,7 +10721,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 8475, 8490), + span: SourceSpan::new("dsl/std/types.dag", 8146, 8161), }); declarations.push(Declaration { id: DeclarationId(131), @@ -10741,7 +10741,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9254, 9294), + span: SourceSpan::new("dsl/std/types.dag", 8925, 8965), }); declarations.push(Declaration { id: DeclarationId(132), @@ -10755,7 +10755,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9254, 9294), + span: SourceSpan::new("dsl/std/types.dag", 8925, 8965), }); declarations.push(Declaration { id: DeclarationId(133), @@ -10775,7 +10775,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9295, 9338), + span: SourceSpan::new("dsl/std/types.dag", 8966, 9009), }); declarations.push(Declaration { id: DeclarationId(134), @@ -10789,7 +10789,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9295, 9338), + span: SourceSpan::new("dsl/std/types.dag", 8966, 9009), }); declarations.push(Declaration { id: DeclarationId(135), @@ -10815,7 +10815,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9339, 9389), + span: SourceSpan::new("dsl/std/types.dag", 9010, 9060), }); declarations.push(Declaration { id: DeclarationId(136), @@ -10829,7 +10829,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9339, 9389), + span: SourceSpan::new("dsl/std/types.dag", 9010, 9060), }); declarations.push(Declaration { id: DeclarationId(137), @@ -10843,7 +10843,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9339, 9389), + span: SourceSpan::new("dsl/std/types.dag", 9010, 9060), }); declarations.push(Declaration { id: DeclarationId(138), @@ -10860,7 +10860,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10735, 10761), + span: SourceSpan::new("dsl/std/types.dag", 10406, 10432), }); declarations.push(Declaration { id: DeclarationId(139), @@ -10877,7 +10877,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10829, 10855), + span: SourceSpan::new("dsl/std/types.dag", 10500, 10526), }); declarations.push(Declaration { id: DeclarationId(140), @@ -10889,9 +10889,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(622)), + refinement: Some(DeclarationId(623)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10856, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10527, 10578), }); declarations.push(Declaration { id: DeclarationId(141), @@ -10903,9 +10903,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(623)), + refinement: Some(DeclarationId(624)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10908, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10579, 10634), }); declarations.push(Declaration { id: DeclarationId(142), @@ -10922,7 +10922,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11037, 11063), + span: SourceSpan::new("dsl/std/types.dag", 10708, 10734), }); declarations.push(Declaration { id: DeclarationId(143), @@ -10934,9 +10934,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(624)), + refinement: Some(DeclarationId(625)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11064, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10735, 10790), }); declarations.push(Declaration { id: DeclarationId(144), @@ -10953,7 +10953,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11208, 11234), + span: SourceSpan::new("dsl/std/types.dag", 10879, 10905), }); declarations.push(Declaration { id: DeclarationId(145), @@ -10972,7 +10972,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { nominal_opacity: Some(NominalOpacity { permitted_accessors: vec![], }), - span: SourceSpan::new("dsl/std/types.dag", 11235, 11276), + span: SourceSpan::new("dsl/std/types.dag", 10906, 10947), }); declarations.push(Declaration { id: DeclarationId(146), @@ -10984,9 +10984,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(625)), + refinement: Some(DeclarationId(626)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11277, 11319), + span: SourceSpan::new("dsl/std/types.dag", 10948, 10990), }); declarations.push(Declaration { id: DeclarationId(147), @@ -11003,7 +11003,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11380, 11406), + span: SourceSpan::new("dsl/std/types.dag", 11051, 11077), }); declarations.push(Declaration { id: DeclarationId(148), @@ -11020,7 +11020,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11479, 11505), + span: SourceSpan::new("dsl/std/types.dag", 11150, 11176), }); declarations.push(Declaration { id: DeclarationId(149), @@ -11032,9 +11032,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(626)), + refinement: Some(DeclarationId(627)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11506, 11551), + span: SourceSpan::new("dsl/std/types.dag", 11177, 11222), }); declarations.push(Declaration { id: DeclarationId(150), @@ -11046,9 +11046,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(627)), + refinement: Some(DeclarationId(628)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11552, 11597), + span: SourceSpan::new("dsl/std/types.dag", 11223, 11268), }); declarations.push(Declaration { id: DeclarationId(151), @@ -11060,9 +11060,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(628)), + refinement: Some(DeclarationId(629)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11598, 11643), + span: SourceSpan::new("dsl/std/types.dag", 11269, 11314), }); declarations.push(Declaration { id: DeclarationId(152), @@ -11074,9 +11074,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(629)), + refinement: Some(DeclarationId(630)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12278, 12337), + span: SourceSpan::new("dsl/std/types.dag", 11949, 12008), }); declarations.push(Declaration { id: DeclarationId(153), @@ -11088,9 +11088,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(630)), + refinement: Some(DeclarationId(631)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12338, 12397), + span: SourceSpan::new("dsl/std/types.dag", 12009, 12068), }); declarations.push(Declaration { id: DeclarationId(154), @@ -11098,7 +11098,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { connective: TypeConnective::Conj { children: vec![Field { label: "segments".to_string(), - ty: DeclarationId(512), + ty: DeclarationId(513), }], }, type_params: vec![], @@ -11109,7 +11109,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12398, 12450), + span: SourceSpan::new("dsl/std/types.dag", 12069, 12121), }); declarations.push(Declaration { id: DeclarationId(155), @@ -11117,7 +11117,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { connective: TypeConnective::Conj { children: vec![Field { label: "segments".to_string(), - ty: DeclarationId(513), + ty: DeclarationId(514), }], }, type_params: vec![], @@ -11128,7 +11128,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12451, 12501), + span: SourceSpan::new("dsl/std/types.dag", 12122, 12172), }); declarations.push(Declaration { id: DeclarationId(156), @@ -11140,9 +11140,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(631)), + refinement: Some(DeclarationId(632)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12502, 12545), + span: SourceSpan::new("dsl/std/types.dag", 12173, 12216), }); declarations.push(Declaration { id: DeclarationId(157), @@ -11171,7 +11171,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13163, 13223), + span: SourceSpan::new("dsl/std/types.dag", 12834, 12894), }); declarations.push(Declaration { id: DeclarationId(158), @@ -11188,7 +11188,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13323, 13349), + span: SourceSpan::new("dsl/std/types.dag", 12994, 13020), }); declarations.push(Declaration { id: DeclarationId(159), @@ -11200,9 +11200,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(632)), + refinement: Some(DeclarationId(633)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13350, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13021, 13065), }); declarations.push(Declaration { id: DeclarationId(160), @@ -11214,9 +11214,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(633)), + refinement: Some(DeclarationId(634)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13395, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13066, 13110), }); declarations.push(Declaration { id: DeclarationId(161), @@ -11228,9 +11228,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(634)), + refinement: Some(DeclarationId(635)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13921, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13592, 13636), }); declarations.push(Declaration { id: DeclarationId(162), @@ -11242,9 +11242,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(635)), + refinement: Some(DeclarationId(636)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13966, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13637, 13681), }); declarations.push(Declaration { id: DeclarationId(163), @@ -11256,9 +11256,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(636)), + refinement: Some(DeclarationId(637)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14534, 14589), + span: SourceSpan::new("dsl/std/types.dag", 14205, 14260), }); declarations.push(Declaration { id: DeclarationId(164), @@ -11270,9 +11270,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(637)), + refinement: Some(DeclarationId(638)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14590, 14644), + span: SourceSpan::new("dsl/std/types.dag", 14261, 14315), }); declarations.push(Declaration { id: DeclarationId(165), @@ -11284,9 +11284,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(638)), + refinement: Some(DeclarationId(639)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14645, 14698), + span: SourceSpan::new("dsl/std/types.dag", 14316, 14369), }); declarations.push(Declaration { id: DeclarationId(166), @@ -11298,9 +11298,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(639)), + refinement: Some(DeclarationId(640)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14699, 14756), + span: SourceSpan::new("dsl/std/types.dag", 14370, 14427), }); declarations.push(Declaration { id: DeclarationId(167), @@ -11312,9 +11312,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(640)), + refinement: Some(DeclarationId(641)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14757, 14814), + span: SourceSpan::new("dsl/std/types.dag", 14428, 14485), }); declarations.push(Declaration { id: DeclarationId(168), @@ -11326,9 +11326,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(641)), + refinement: Some(DeclarationId(642)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14815, 14870), + span: SourceSpan::new("dsl/std/types.dag", 14486, 14541), }); declarations.push(Declaration { id: DeclarationId(169), @@ -11340,9 +11340,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(642)), + refinement: Some(DeclarationId(643)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14871, 14927), + span: SourceSpan::new("dsl/std/types.dag", 14542, 14598), }); declarations.push(Declaration { id: DeclarationId(170), @@ -11354,9 +11354,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(643)), + refinement: Some(DeclarationId(644)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14928, 14984), + span: SourceSpan::new("dsl/std/types.dag", 14599, 14655), }); declarations.push(Declaration { id: DeclarationId(171), @@ -11368,9 +11368,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(644)), + refinement: Some(DeclarationId(645)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14985, 15043), + span: SourceSpan::new("dsl/std/types.dag", 14656, 14714), }); declarations.push(Declaration { id: DeclarationId(172), @@ -11382,9 +11382,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(645)), + refinement: Some(DeclarationId(646)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15274, 15345), + span: SourceSpan::new("dsl/std/types.dag", 14945, 15016), }); declarations.push(Declaration { id: DeclarationId(173), @@ -11396,9 +11396,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(646)), + refinement: Some(DeclarationId(647)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15346, 15417), + span: SourceSpan::new("dsl/std/types.dag", 15017, 15088), }); declarations.push(Declaration { id: DeclarationId(174), @@ -11410,9 +11410,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(647)), + refinement: Some(DeclarationId(648)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15418, 15485), + span: SourceSpan::new("dsl/std/types.dag", 15089, 15156), }); declarations.push(Declaration { id: DeclarationId(175), @@ -11424,9 +11424,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(648)), + refinement: Some(DeclarationId(649)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15486, 15547), + span: SourceSpan::new("dsl/std/types.dag", 15157, 15218), }); declarations.push(Declaration { id: DeclarationId(176), @@ -11438,9 +11438,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(649)), + refinement: Some(DeclarationId(650)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15627, 15669), + span: SourceSpan::new("dsl/std/types.dag", 15298, 15340), }); declarations.push(Declaration { id: DeclarationId(177), @@ -11452,9 +11452,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(650)), + refinement: Some(DeclarationId(651)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16054, 16096), + span: SourceSpan::new("dsl/std/types.dag", 15725, 15767), }); declarations.push(Declaration { id: DeclarationId(178), @@ -11471,7 +11471,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16221, 16254), + span: SourceSpan::new("dsl/std/types.dag", 15892, 15925), }); declarations.push(Declaration { id: DeclarationId(179), @@ -11480,15 +11480,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Linux".to_string(), - ty: DeclarationId(514), + ty: DeclarationId(515), }, Field { label: "Macos".to_string(), - ty: DeclarationId(515), + ty: DeclarationId(516), }, Field { label: "Windows".to_string(), - ty: DeclarationId(516), + ty: DeclarationId(517), }, ], }, @@ -11500,7 +11500,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16640, 16683), + span: SourceSpan::new("dsl/std/types.dag", 16311, 16354), }); declarations.push(Declaration { id: DeclarationId(180), @@ -11509,19 +11509,19 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Pure".to_string(), - ty: DeclarationId(517), + ty: DeclarationId(518), }, Field { label: "Transport".to_string(), - ty: DeclarationId(518), + ty: DeclarationId(519), }, Field { label: "SubDag".to_string(), - ty: DeclarationId(519), + ty: DeclarationId(520), }, Field { label: "Env".to_string(), - ty: DeclarationId(520), + ty: DeclarationId(521), }, ], }, @@ -11533,7 +11533,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16811, 16866), + span: SourceSpan::new("dsl/std/types.dag", 16482, 16537), }); declarations.push(Declaration { id: DeclarationId(181), @@ -11542,15 +11542,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Template".to_string(), - ty: DeclarationId(521), + ty: DeclarationId(522), }, Field { label: "Generated".to_string(), - ty: DeclarationId(522), + ty: DeclarationId(523), }, Field { label: "Static".to_string(), - ty: DeclarationId(523), + ty: DeclarationId(524), }, ], }, @@ -11562,7 +11562,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16867, 16920), + span: SourceSpan::new("dsl/std/types.dag", 16538, 16591), }); declarations.push(Declaration { id: DeclarationId(182), @@ -11571,23 +11571,23 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Xs".to_string(), - ty: DeclarationId(524), + ty: DeclarationId(525), }, Field { label: "S".to_string(), - ty: DeclarationId(525), + ty: DeclarationId(526), }, Field { label: "M".to_string(), - ty: DeclarationId(526), + ty: DeclarationId(527), }, Field { label: "L".to_string(), - ty: DeclarationId(527), + ty: DeclarationId(528), }, Field { label: "Xl".to_string(), - ty: DeclarationId(528), + ty: DeclarationId(529), }, ], }, @@ -11599,7 +11599,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16922, 16959), + span: SourceSpan::new("dsl/std/types.dag", 16593, 16630), }); declarations.push(Declaration { id: DeclarationId(183), @@ -11608,23 +11608,23 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Stored".to_string(), - ty: DeclarationId(529), + ty: DeclarationId(530), }, Field { label: "PlatformInjected".to_string(), - ty: DeclarationId(530), + ty: DeclarationId(531), }, Field { label: "WorkloadIdentity".to_string(), - ty: DeclarationId(533), + ty: DeclarationId(534), }, Field { label: "InteractiveAuth".to_string(), - ty: DeclarationId(535), + ty: DeclarationId(536), }, Field { label: "Chained".to_string(), - ty: DeclarationId(537), + ty: DeclarationId(538), }, ], }, @@ -11636,7 +11636,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17207, 17529), + span: SourceSpan::new("dsl/std/types.dag", 16878, 17200), }); declarations.push(Declaration { id: DeclarationId(184), @@ -11645,47 +11645,47 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "X86_64".to_string(), - ty: DeclarationId(538), + ty: DeclarationId(539), }, Field { label: "X86".to_string(), - ty: DeclarationId(539), + ty: DeclarationId(540), }, Field { label: "Aarch64".to_string(), - ty: DeclarationId(540), + ty: DeclarationId(541), }, Field { label: "Arm".to_string(), - ty: DeclarationId(541), + ty: DeclarationId(542), }, Field { label: "Armv7".to_string(), - ty: DeclarationId(542), + ty: DeclarationId(543), }, Field { label: "Mips".to_string(), - ty: DeclarationId(543), + ty: DeclarationId(544), }, Field { label: "Mipsel".to_string(), - ty: DeclarationId(544), + ty: DeclarationId(545), }, Field { label: "Mips64".to_string(), - ty: DeclarationId(545), + ty: DeclarationId(546), }, Field { label: "Mips64el".to_string(), - ty: DeclarationId(546), + ty: DeclarationId(547), }, Field { label: "Riscv64".to_string(), - ty: DeclarationId(547), + ty: DeclarationId(548), }, Field { label: "Wasm32".to_string(), - ty: DeclarationId(548), + ty: DeclarationId(549), }, ], }, @@ -11697,7 +11697,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17604, 17707), + span: SourceSpan::new("dsl/std/types.dag", 17275, 17378), }); declarations.push(Declaration { id: DeclarationId(185), @@ -11706,19 +11706,19 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "UnknownVendor".to_string(), - ty: DeclarationId(549), + ty: DeclarationId(550), }, Field { label: "Pc".to_string(), - ty: DeclarationId(550), + ty: DeclarationId(551), }, Field { label: "Apple".to_string(), - ty: DeclarationId(551), + ty: DeclarationId(552), }, Field { label: "W64".to_string(), - ty: DeclarationId(552), + ty: DeclarationId(553), }, ], }, @@ -11730,7 +11730,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17708, 17754), + span: SourceSpan::new("dsl/std/types.dag", 17379, 17425), }); declarations.push(Declaration { id: DeclarationId(186), @@ -11739,31 +11739,31 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Linux".to_string(), - ty: DeclarationId(553), + ty: DeclarationId(554), }, Field { label: "Macos".to_string(), - ty: DeclarationId(554), + ty: DeclarationId(555), }, Field { label: "Windows".to_string(), - ty: DeclarationId(555), + ty: DeclarationId(556), }, Field { label: "Freebsd".to_string(), - ty: DeclarationId(556), + ty: DeclarationId(557), }, Field { label: "Android".to_string(), - ty: DeclarationId(557), + ty: DeclarationId(558), }, Field { label: "Ios".to_string(), - ty: DeclarationId(558), + ty: DeclarationId(559), }, Field { label: "Wasi".to_string(), - ty: DeclarationId(559), + ty: DeclarationId(560), }, ], }, @@ -11775,7 +11775,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17755, 17821), + span: SourceSpan::new("dsl/std/types.dag", 17426, 17492), }); declarations.push(Declaration { id: DeclarationId(187), @@ -11784,39 +11784,39 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "NoneAbi".to_string(), - ty: DeclarationId(560), + ty: DeclarationId(561), }, Field { label: "Gnu".to_string(), - ty: DeclarationId(561), + ty: DeclarationId(562), }, Field { label: "GnuEabi".to_string(), - ty: DeclarationId(562), + ty: DeclarationId(563), }, Field { label: "GnuEabihf".to_string(), - ty: DeclarationId(563), + ty: DeclarationId(564), }, Field { label: "Musl".to_string(), - ty: DeclarationId(564), + ty: DeclarationId(565), }, Field { label: "Msvc".to_string(), - ty: DeclarationId(565), + ty: DeclarationId(566), }, Field { label: "AndroidAbi".to_string(), - ty: DeclarationId(566), + ty: DeclarationId(567), }, Field { label: "Eabi".to_string(), - ty: DeclarationId(567), + ty: DeclarationId(568), }, Field { label: "Eabihf".to_string(), - ty: DeclarationId(568), + ty: DeclarationId(569), }, ], }, @@ -11828,7 +11828,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17822, 17914), + span: SourceSpan::new("dsl/std/types.dag", 17493, 17585), }); declarations.push(Declaration { id: DeclarationId(188), @@ -11837,23 +11837,23 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Native".to_string(), - ty: DeclarationId(569), + ty: DeclarationId(570), }, Field { label: "Wsl".to_string(), - ty: DeclarationId(570), + ty: DeclarationId(571), }, Field { label: "Container".to_string(), - ty: DeclarationId(571), + ty: DeclarationId(572), }, Field { label: "Ci".to_string(), - ty: DeclarationId(572), + ty: DeclarationId(573), }, Field { label: "Emulator".to_string(), - ty: DeclarationId(573), + ty: DeclarationId(574), }, ], }, @@ -11865,7 +11865,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17915, 17975), + span: SourceSpan::new("dsl/std/types.dag", 17586, 17646), }); declarations.push(Declaration { id: DeclarationId(189), @@ -11886,7 +11886,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "env".to_string(), - ty: DeclarationId(574), + ty: DeclarationId(575), }, ], }, @@ -11898,7 +11898,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17977, 18052), + span: SourceSpan::new("dsl/std/types.dag", 17648, 17723), }); declarations.push(Declaration { id: DeclarationId(190), @@ -11923,7 +11923,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18054, 18119), + span: SourceSpan::new("dsl/std/types.dag", 17725, 17790), }); declarations.push(Declaration { id: DeclarationId(191), @@ -11932,23 +11932,23 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "RegularFile".to_string(), - ty: DeclarationId(575), + ty: DeclarationId(576), }, Field { label: "Directory".to_string(), - ty: DeclarationId(576), + ty: DeclarationId(577), }, Field { label: "Symlink".to_string(), - ty: DeclarationId(577), + ty: DeclarationId(578), }, Field { label: "Missing".to_string(), - ty: DeclarationId(578), + ty: DeclarationId(579), }, Field { label: "Other".to_string(), - ty: DeclarationId(579), + ty: DeclarationId(580), }, ], }, @@ -11960,7 +11960,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18428, 18506), + span: SourceSpan::new("dsl/std/types.dag", 18099, 18177), }); declarations.push(Declaration { id: DeclarationId(192), @@ -11969,15 +11969,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "TargetFile".to_string(), - ty: DeclarationId(580), + ty: DeclarationId(581), }, Field { label: "TargetDir".to_string(), - ty: DeclarationId(581), + ty: DeclarationId(582), }, Field { label: "Broken".to_string(), - ty: DeclarationId(582), + ty: DeclarationId(583), }, ], }, @@ -11989,7 +11989,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18636, 18694), + span: SourceSpan::new("dsl/std/types.dag", 18307, 18365), }); declarations.push(Declaration { id: DeclarationId(193), @@ -12006,7 +12006,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 19855, 19885), + span: SourceSpan::new("dsl/std/types.dag", 19526, 19556), }); declarations.push(Declaration { id: DeclarationId(194), @@ -12023,7 +12023,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 19966, 19996), + span: SourceSpan::new("dsl/std/types.dag", 19637, 19667), }); declarations.push(Declaration { id: DeclarationId(195), @@ -12040,7 +12040,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 20213, 20235), + span: SourceSpan::new("dsl/std/types.dag", 19884, 19906), }); declarations.push(Declaration { id: DeclarationId(196), @@ -12049,31 +12049,31 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "GET".to_string(), - ty: DeclarationId(583), + ty: DeclarationId(584), }, Field { label: "POST".to_string(), - ty: DeclarationId(584), + ty: DeclarationId(585), }, Field { label: "PUT".to_string(), - ty: DeclarationId(585), + ty: DeclarationId(586), }, Field { label: "PATCH".to_string(), - ty: DeclarationId(586), + ty: DeclarationId(587), }, Field { label: "DELETE".to_string(), - ty: DeclarationId(587), + ty: DeclarationId(588), }, Field { label: "HEAD".to_string(), - ty: DeclarationId(588), + ty: DeclarationId(589), }, Field { label: "OPTIONS".to_string(), - ty: DeclarationId(589), + ty: DeclarationId(590), }, ], }, @@ -12085,7 +12085,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 20979, 21047), + span: SourceSpan::new("dsl/std/types.dag", 20650, 20718), }); declarations.push(Declaration { id: DeclarationId(197), @@ -12094,19 +12094,19 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Bearer".to_string(), - ty: DeclarationId(590), + ty: DeclarationId(591), }, Field { label: "Header".to_string(), - ty: DeclarationId(591), + ty: DeclarationId(592), }, Field { label: "Basic".to_string(), - ty: DeclarationId(592), + ty: DeclarationId(593), }, Field { label: "ApiKey".to_string(), - ty: DeclarationId(593), + ty: DeclarationId(594), }, ], }, @@ -12118,7 +12118,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21515, 21611), + span: SourceSpan::new("dsl/std/types.dag", 21186, 21282), }); declarations.push(Declaration { id: DeclarationId(198), @@ -12135,7 +12135,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "expires_at".to_string(), - ty: DeclarationId(594), + ty: DeclarationId(595), }, ], }, @@ -12147,7 +12147,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21733, 21866), + span: SourceSpan::new("dsl/std/types.dag", 21404, 21537), }); declarations.push(Declaration { id: DeclarationId(199), @@ -12164,7 +12164,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "header_name".to_string(), - ty: DeclarationId(595), + ty: DeclarationId(596), }, Field { label: "source_id".to_string(), @@ -12172,11 +12172,11 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "required_scopes".to_string(), - ty: DeclarationId(596), + ty: DeclarationId(597), }, Field { label: "expires_in".to_string(), - ty: DeclarationId(597), + ty: DeclarationId(598), }, ], }, @@ -12188,7 +12188,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21868, 22018), + span: SourceSpan::new("dsl/std/types.dag", 21539, 21689), }); declarations.push(Declaration { id: DeclarationId(200), @@ -12200,9 +12200,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(651)), + refinement: Some(DeclarationId(652)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22095, 22159), + span: SourceSpan::new("dsl/std/types.dag", 21766, 21830), }); declarations.push(Declaration { id: DeclarationId(201), @@ -12214,9 +12214,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(652)), + refinement: Some(DeclarationId(653)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22160, 22217), + span: SourceSpan::new("dsl/std/types.dag", 21831, 21888), }); declarations.push(Declaration { id: DeclarationId(202), @@ -12228,9 +12228,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(653)), + refinement: Some(DeclarationId(654)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22218, 22274), + span: SourceSpan::new("dsl/std/types.dag", 21889, 21945), }); declarations.push(Declaration { id: DeclarationId(203), @@ -12263,7 +12263,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22351, 22442), + span: SourceSpan::new("dsl/std/types.dag", 22022, 22113), }); declarations.push(Declaration { id: DeclarationId(204), @@ -12292,7 +12292,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22444, 22515), + span: SourceSpan::new("dsl/std/types.dag", 22115, 22186), }); declarations.push(Declaration { id: DeclarationId(205), @@ -12321,7 +12321,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22517, 22587), + span: SourceSpan::new("dsl/std/types.dag", 22188, 22258), }); declarations.push(Declaration { id: DeclarationId(206), @@ -12350,7 +12350,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22589, 22662), + span: SourceSpan::new("dsl/std/types.dag", 22260, 22333), }); declarations.push(Declaration { id: DeclarationId(207), @@ -12379,7 +12379,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22664, 22728), + span: SourceSpan::new("dsl/std/types.dag", 22335, 22399), }); declarations.push(Declaration { id: DeclarationId(208), @@ -12416,7 +12416,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22805, 22912), + span: SourceSpan::new("dsl/std/types.dag", 22476, 22583), }); declarations.push(Declaration { id: DeclarationId(209), @@ -12445,7 +12445,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22914, 22971), + span: SourceSpan::new("dsl/std/types.dag", 22585, 22642), }); declarations.push(Declaration { id: DeclarationId(210), @@ -12482,7 +12482,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22973, 23074), + span: SourceSpan::new("dsl/std/types.dag", 22644, 22745), }); declarations.push(Declaration { id: DeclarationId(211), @@ -12511,7 +12511,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23227, 23299), + span: SourceSpan::new("dsl/std/types.dag", 22898, 22970), }); declarations.push(Declaration { id: DeclarationId(212), @@ -12528,7 +12528,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "lines".to_string(), - ty: DeclarationId(598), + ty: DeclarationId(599), }, ], }, @@ -12540,7 +12540,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23301, 23387), + span: SourceSpan::new("dsl/std/types.dag", 22972, 23058), }); declarations.push(Declaration { id: DeclarationId(213), @@ -12561,7 +12561,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "sections".to_string(), - ty: DeclarationId(599), + ty: DeclarationId(600), }, Field { label: "trailing_newline".to_string(), @@ -12577,7 +12577,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23389, 23526), + span: SourceSpan::new("dsl/std/types.dag", 23060, 23197), }); declarations.push(Declaration { id: DeclarationId(214), @@ -12602,7 +12602,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23528, 23581), + span: SourceSpan::new("dsl/std/types.dag", 23199, 23252), }); declarations.push(Declaration { id: DeclarationId(215), @@ -12627,7 +12627,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23583, 23641), + span: SourceSpan::new("dsl/std/types.dag", 23254, 23312), }); declarations.push(Declaration { id: DeclarationId(216), @@ -12644,7 +12644,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "description".to_string(), - ty: DeclarationId(600), + ty: DeclarationId(601), }, ], }, @@ -12656,7 +12656,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23718, 23792), + span: SourceSpan::new("dsl/std/types.dag", 23389, 23463), }); declarations.push(Declaration { id: DeclarationId(217), @@ -12664,7 +12664,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { connective: TypeConnective::Conj { children: vec![Field { label: "tools".to_string(), - ty: DeclarationId(601), + ty: DeclarationId(602), }], }, type_params: vec![], @@ -12675,7 +12675,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23794, 23840), + span: SourceSpan::new("dsl/std/types.dag", 23465, 23511), }); declarations.push(Declaration { id: DeclarationId(218), @@ -12684,15 +12684,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { children: vec![ Field { label: "nodes".to_string(), - ty: DeclarationId(602), + ty: DeclarationId(603), }, Field { label: "edges".to_string(), - ty: DeclarationId(603), + ty: DeclarationId(604), }, Field { label: "subdag_boundaries".to_string(), - ty: DeclarationId(604), + ty: DeclarationId(605), }, ], }, @@ -12704,7 +12704,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24099, 24209), + span: SourceSpan::new("dsl/std/types.dag", 23770, 23880), }); declarations.push(Declaration { id: DeclarationId(219), @@ -12725,7 +12725,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "parent".to_string(), - ty: DeclarationId(605), + ty: DeclarationId(606), }, ], }, @@ -12737,7 +12737,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24211, 24331), + span: SourceSpan::new("dsl/std/types.dag", 23882, 24002), }); declarations.push(Declaration { id: DeclarationId(220), @@ -12754,7 +12754,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "port".to_string(), - ty: DeclarationId(606), + ty: DeclarationId(607), }, ], }, @@ -12766,7 +12766,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24333, 24398), + span: SourceSpan::new("dsl/std/types.dag", 24004, 24069), }); declarations.push(Declaration { id: DeclarationId(221), @@ -12775,15 +12775,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { children: vec![ Field { label: "added".to_string(), - ty: DeclarationId(607), + ty: DeclarationId(608), }, Field { label: "removed".to_string(), - ty: DeclarationId(608), + ty: DeclarationId(609), }, Field { label: "changed".to_string(), - ty: DeclarationId(609), + ty: DeclarationId(610), }, ], }, @@ -12795,7 +12795,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24400, 24486), + span: SourceSpan::new("dsl/std/types.dag", 24071, 24157), }); declarations.push(Declaration { id: DeclarationId(222), @@ -12812,15 +12812,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "backend".to_string(), - ty: DeclarationId(610), + ty: DeclarationId(611), }, Field { label: "target".to_string(), - ty: DeclarationId(611), + ty: DeclarationId(612), }, Field { label: "runtime_env".to_string(), - ty: DeclarationId(612), + ty: DeclarationId(613), }, ], }, @@ -12832,7 +12832,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24555, 24689), + span: SourceSpan::new("dsl/std/types.dag", 24226, 24360), }); declarations.push(Declaration { id: DeclarationId(223), @@ -12841,19 +12841,19 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Rust".to_string(), - ty: DeclarationId(613), + ty: DeclarationId(614), }, Field { label: "Go".to_string(), - ty: DeclarationId(614), + ty: DeclarationId(615), }, Field { label: "C".to_string(), - ty: DeclarationId(615), + ty: DeclarationId(616), }, Field { label: "Mips".to_string(), - ty: DeclarationId(616), + ty: DeclarationId(617), }, ], }, @@ -12865,7 +12865,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24691, 24733), + span: SourceSpan::new("dsl/std/types.dag", 24362, 24404), }); declarations.push(Declaration { id: DeclarationId(224), @@ -12882,7 +12882,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "scope".to_string(), - ty: DeclarationId(617), + ty: DeclarationId(618), }, ], }, @@ -12894,7 +12894,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24735, 24806), + span: SourceSpan::new("dsl/std/types.dag", 24406, 24477), }); declarations.push(Declaration { id: DeclarationId(225), @@ -12919,7 +12919,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24947, 25004), + span: SourceSpan::new("dsl/std/types.dag", 24618, 24675), }); declarations.push(Declaration { id: DeclarationId(226), @@ -12933,7 +12933,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 26938, 26957), + span: SourceSpan::new("dsl/std/types.dag", 26609, 26628), }); declarations.push(Declaration { id: DeclarationId(227), @@ -12947,7 +12947,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 26938, 26957), + span: SourceSpan::new("dsl/std/types.dag", 26609, 26628), }); declarations.push(Declaration { id: DeclarationId(228), @@ -12976,19 +12976,19 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Whitespace".to_string(), - ty: DeclarationId(654), + ty: DeclarationId(655), }, Field { label: "Digit".to_string(), - ty: DeclarationId(655), + ty: DeclarationId(656), }, Field { label: "IdentStart".to_string(), - ty: DeclarationId(656), + ty: DeclarationId(657), }, Field { label: "IdentContinue".to_string(), - ty: DeclarationId(657), + ty: DeclarationId(658), }, ], }, @@ -13027,15 +13027,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "ZeroWidth".to_string(), - ty: DeclarationId(658), + ty: DeclarationId(659), }, Field { label: "Narrow".to_string(), - ty: DeclarationId(659), + ty: DeclarationId(660), }, Field { label: "Wide".to_string(), - ty: DeclarationId(660), + ty: DeclarationId(661), }, ], }, @@ -13112,7 +13112,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(661)), + meta_tag: Some(DeclarationId(662)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![ @@ -13134,7 +13134,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -13157,7 +13157,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -13180,7 +13180,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -13203,7 +13203,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -13224,7 +13224,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -13247,7 +13247,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -13269,7 +13269,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(662)), + meta_tag: Some(DeclarationId(663)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![ @@ -13294,7 +13294,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(663)), + meta_tag: Some(DeclarationId(664)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![ @@ -13314,7 +13314,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13337,7 +13337,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13360,7 +13360,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13381,7 +13381,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13404,7 +13404,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13427,7 +13427,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13448,7 +13448,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13471,7 +13471,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13494,7 +13494,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13515,7 +13515,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13536,7 +13536,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13557,7 +13557,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13578,7 +13578,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13601,7 +13601,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13624,7 +13624,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -13645,7 +13645,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -18874,7 +18874,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7558, 7562), + span: SourceSpan::new("dsl/std/types.dag", 7229, 7233), }); declarations.push(Declaration { id: DeclarationId(511), @@ -18888,16 +18888,16 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7565, 7570), + span: SourceSpan::new("dsl/std/types.dag", 7236, 7241), }); declarations.push(Declaration { id: DeclarationId(512), name: None, connective: TypeConnective::Instantiation { - template: DeclarationId(131), + template: DeclarationId(45), arguments: vec![TemplateArgument { - parameter: DeclarationId(132), - value: DeclarationId(152), + parameter: DeclarationId(46), + value: DeclarationId(126), }], }, type_params: vec![], @@ -18908,7 +18908,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12431, 12448), + span: SourceSpan::new("dsl/std/types.dag", 7206, 7226), }); declarations.push(Declaration { id: DeclarationId(513), @@ -18917,7 +18917,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { template: DeclarationId(131), arguments: vec![TemplateArgument { parameter: DeclarationId(132), - value: DeclarationId(153), + value: DeclarationId(152), }], }, type_params: vec![], @@ -18928,12 +18928,18 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12482, 12499), + span: SourceSpan::new("dsl/std/types.dag", 12102, 12119), }); declarations.push(Declaration { id: DeclarationId(514), name: None, - connective: TypeConnective::Conj { children: vec![] }, + connective: TypeConnective::Instantiation { + template: DeclarationId(131), + arguments: vec![TemplateArgument { + parameter: DeclarationId(132), + value: DeclarationId(153), + }], + }, type_params: vec![], phantom_params: Vec::new(), meta_tag: None, @@ -18942,7 +18948,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16660, 16665), + span: SourceSpan::new("dsl/std/types.dag", 12153, 12170), }); declarations.push(Declaration { id: DeclarationId(515), @@ -18956,7 +18962,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16668, 16673), + span: SourceSpan::new("dsl/std/types.dag", 16331, 16336), }); declarations.push(Declaration { id: DeclarationId(516), @@ -18970,7 +18976,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16676, 16683), + span: SourceSpan::new("dsl/std/types.dag", 16339, 16344), }); declarations.push(Declaration { id: DeclarationId(517), @@ -18984,7 +18990,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16835, 16839), + span: SourceSpan::new("dsl/std/types.dag", 16347, 16354), }); declarations.push(Declaration { id: DeclarationId(518), @@ -18998,7 +19004,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16842, 16851), + span: SourceSpan::new("dsl/std/types.dag", 16506, 16510), }); declarations.push(Declaration { id: DeclarationId(519), @@ -19012,7 +19018,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16854, 16860), + span: SourceSpan::new("dsl/std/types.dag", 16513, 16522), }); declarations.push(Declaration { id: DeclarationId(520), @@ -19026,7 +19032,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16863, 16866), + span: SourceSpan::new("dsl/std/types.dag", 16525, 16531), }); declarations.push(Declaration { id: DeclarationId(521), @@ -19040,7 +19046,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16891, 16899), + span: SourceSpan::new("dsl/std/types.dag", 16534, 16537), }); declarations.push(Declaration { id: DeclarationId(522), @@ -19054,7 +19060,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16902, 16911), + span: SourceSpan::new("dsl/std/types.dag", 16562, 16570), }); declarations.push(Declaration { id: DeclarationId(523), @@ -19068,7 +19074,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16914, 16920), + span: SourceSpan::new("dsl/std/types.dag", 16573, 16582), }); declarations.push(Declaration { id: DeclarationId(524), @@ -19082,7 +19088,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16940, 16942), + span: SourceSpan::new("dsl/std/types.dag", 16585, 16591), }); declarations.push(Declaration { id: DeclarationId(525), @@ -19096,7 +19102,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16945, 16946), + span: SourceSpan::new("dsl/std/types.dag", 16611, 16613), }); declarations.push(Declaration { id: DeclarationId(526), @@ -19110,7 +19116,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16949, 16950), + span: SourceSpan::new("dsl/std/types.dag", 16616, 16617), }); declarations.push(Declaration { id: DeclarationId(527), @@ -19124,7 +19130,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16953, 16954), + span: SourceSpan::new("dsl/std/types.dag", 16620, 16621), }); declarations.push(Declaration { id: DeclarationId(528), @@ -19138,11 +19144,25 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16957, 16959), + span: SourceSpan::new("dsl/std/types.dag", 16624, 16625), }); declarations.push(Declaration { id: DeclarationId(529), name: None, + connective: TypeConnective::Conj { children: vec![] }, + type_params: vec![], + phantom_params: Vec::new(), + meta_tag: None, + specialization_parent: None, + inhabits: None, + value_body: None, + refinement: None, + nominal_opacity: None, + span: SourceSpan::new("dsl/std/types.dag", 16628, 16630), + }); + declarations.push(Declaration { + id: DeclarationId(530), + name: None, connective: TypeConnective::Conj { children: vec![Field { label: "secret_name".to_string(), @@ -19157,10 +19177,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17231, 17266), + span: SourceSpan::new("dsl/std/types.dag", 16902, 16937), }); declarations.push(Declaration { - id: DeclarationId(530), + id: DeclarationId(531), name: None, connective: TypeConnective::Conj { children: vec![Field { @@ -19176,10 +19196,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17271, 17312), + span: SourceSpan::new("dsl/std/types.dag", 16942, 16983), }); declarations.push(Declaration { - id: DeclarationId(531), + id: DeclarationId(532), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -19195,10 +19215,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17387, 17407), + span: SourceSpan::new("dsl/std/types.dag", 17058, 17078), }); declarations.push(Declaration { - id: DeclarationId(532), + id: DeclarationId(533), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -19215,10 +19235,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17422, 17434), + span: SourceSpan::new("dsl/std/types.dag", 17093, 17105), }); declarations.push(Declaration { - id: DeclarationId(533), + id: DeclarationId(534), name: None, connective: TypeConnective::Conj { children: vec![ @@ -19228,11 +19248,11 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { }, Field { label: "service_account".to_string(), - ty: DeclarationId(531), + ty: DeclarationId(532), }, Field { label: "scopes".to_string(), - ty: DeclarationId(532), + ty: DeclarationId(533), }, ], }, @@ -19244,10 +19264,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17317, 17440), + span: SourceSpan::new("dsl/std/types.dag", 16988, 17111), }); declarations.push(Declaration { - id: DeclarationId(534), + id: DeclarationId(535), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -19264,15 +19284,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17471, 17483), + span: SourceSpan::new("dsl/std/types.dag", 17142, 17154), }); declarations.push(Declaration { - id: DeclarationId(535), + id: DeclarationId(536), name: None, connective: TypeConnective::Conj { children: vec![Field { label: "scopes".to_string(), - ty: DeclarationId(534), + ty: DeclarationId(535), }], }, type_params: vec![], @@ -19283,10 +19303,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17445, 17485), + span: SourceSpan::new("dsl/std/types.dag", 17116, 17156), }); declarations.push(Declaration { - id: DeclarationId(536), + id: DeclarationId(537), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -19303,15 +19323,15 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17507, 17527), + span: SourceSpan::new("dsl/std/types.dag", 17178, 17198), }); declarations.push(Declaration { - id: DeclarationId(537), + id: DeclarationId(538), name: None, connective: TypeConnective::Conj { children: vec![Field { label: "steps".to_string(), - ty: DeclarationId(536), + ty: DeclarationId(537), }], }, type_params: vec![], @@ -19322,21 +19342,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17490, 17529), - }); - declarations.push(Declaration { - id: DeclarationId(538), - name: None, - connective: TypeConnective::Conj { children: vec![] }, - type_params: vec![], - phantom_params: Vec::new(), - meta_tag: None, - specialization_parent: None, - inhabits: None, - value_body: None, - refinement: None, - nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17616, 17622), + span: SourceSpan::new("dsl/std/types.dag", 17161, 17200), }); declarations.push(Declaration { id: DeclarationId(539), @@ -19350,7 +19356,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17625, 17628), + span: SourceSpan::new("dsl/std/types.dag", 17287, 17293), }); declarations.push(Declaration { id: DeclarationId(540), @@ -19364,7 +19370,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17631, 17638), + span: SourceSpan::new("dsl/std/types.dag", 17296, 17299), }); declarations.push(Declaration { id: DeclarationId(541), @@ -19378,7 +19384,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17641, 17644), + span: SourceSpan::new("dsl/std/types.dag", 17302, 17309), }); declarations.push(Declaration { id: DeclarationId(542), @@ -19392,7 +19398,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17647, 17652), + span: SourceSpan::new("dsl/std/types.dag", 17312, 17315), }); declarations.push(Declaration { id: DeclarationId(543), @@ -19406,7 +19412,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17655, 17659), + span: SourceSpan::new("dsl/std/types.dag", 17318, 17323), }); declarations.push(Declaration { id: DeclarationId(544), @@ -19420,7 +19426,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17662, 17668), + span: SourceSpan::new("dsl/std/types.dag", 17326, 17330), }); declarations.push(Declaration { id: DeclarationId(545), @@ -19434,7 +19440,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17671, 17677), + span: SourceSpan::new("dsl/std/types.dag", 17333, 17339), }); declarations.push(Declaration { id: DeclarationId(546), @@ -19448,7 +19454,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17680, 17688), + span: SourceSpan::new("dsl/std/types.dag", 17342, 17348), }); declarations.push(Declaration { id: DeclarationId(547), @@ -19462,7 +19468,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17691, 17698), + span: SourceSpan::new("dsl/std/types.dag", 17351, 17359), }); declarations.push(Declaration { id: DeclarationId(548), @@ -19476,7 +19482,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17701, 17707), + span: SourceSpan::new("dsl/std/types.dag", 17362, 17369), }); declarations.push(Declaration { id: DeclarationId(549), @@ -19490,7 +19496,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17722, 17735), + span: SourceSpan::new("dsl/std/types.dag", 17372, 17378), }); declarations.push(Declaration { id: DeclarationId(550), @@ -19504,7 +19510,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17738, 17740), + span: SourceSpan::new("dsl/std/types.dag", 17393, 17406), }); declarations.push(Declaration { id: DeclarationId(551), @@ -19518,7 +19524,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17743, 17748), + span: SourceSpan::new("dsl/std/types.dag", 17409, 17411), }); declarations.push(Declaration { id: DeclarationId(552), @@ -19532,7 +19538,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17751, 17754), + span: SourceSpan::new("dsl/std/types.dag", 17414, 17419), }); declarations.push(Declaration { id: DeclarationId(553), @@ -19546,7 +19552,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17765, 17770), + span: SourceSpan::new("dsl/std/types.dag", 17422, 17425), }); declarations.push(Declaration { id: DeclarationId(554), @@ -19560,7 +19566,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17773, 17778), + span: SourceSpan::new("dsl/std/types.dag", 17436, 17441), }); declarations.push(Declaration { id: DeclarationId(555), @@ -19574,7 +19580,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17781, 17788), + span: SourceSpan::new("dsl/std/types.dag", 17444, 17449), }); declarations.push(Declaration { id: DeclarationId(556), @@ -19588,7 +19594,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17791, 17798), + span: SourceSpan::new("dsl/std/types.dag", 17452, 17459), }); declarations.push(Declaration { id: DeclarationId(557), @@ -19602,7 +19608,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17801, 17808), + span: SourceSpan::new("dsl/std/types.dag", 17462, 17469), }); declarations.push(Declaration { id: DeclarationId(558), @@ -19616,7 +19622,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17811, 17814), + span: SourceSpan::new("dsl/std/types.dag", 17472, 17479), }); declarations.push(Declaration { id: DeclarationId(559), @@ -19630,7 +19636,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17817, 17821), + span: SourceSpan::new("dsl/std/types.dag", 17482, 17485), }); declarations.push(Declaration { id: DeclarationId(560), @@ -19644,7 +19650,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17836, 17843), + span: SourceSpan::new("dsl/std/types.dag", 17488, 17492), }); declarations.push(Declaration { id: DeclarationId(561), @@ -19658,7 +19664,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17846, 17849), + span: SourceSpan::new("dsl/std/types.dag", 17507, 17514), }); declarations.push(Declaration { id: DeclarationId(562), @@ -19672,7 +19678,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17852, 17859), + span: SourceSpan::new("dsl/std/types.dag", 17517, 17520), }); declarations.push(Declaration { id: DeclarationId(563), @@ -19686,7 +19692,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17862, 17871), + span: SourceSpan::new("dsl/std/types.dag", 17523, 17530), }); declarations.push(Declaration { id: DeclarationId(564), @@ -19700,7 +19706,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17874, 17878), + span: SourceSpan::new("dsl/std/types.dag", 17533, 17542), }); declarations.push(Declaration { id: DeclarationId(565), @@ -19714,7 +19720,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17881, 17885), + span: SourceSpan::new("dsl/std/types.dag", 17545, 17549), }); declarations.push(Declaration { id: DeclarationId(566), @@ -19728,7 +19734,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17888, 17898), + span: SourceSpan::new("dsl/std/types.dag", 17552, 17556), }); declarations.push(Declaration { id: DeclarationId(567), @@ -19742,7 +19748,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17901, 17905), + span: SourceSpan::new("dsl/std/types.dag", 17559, 17569), }); declarations.push(Declaration { id: DeclarationId(568), @@ -19756,7 +19762,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17908, 17914), + span: SourceSpan::new("dsl/std/types.dag", 17572, 17576), }); declarations.push(Declaration { id: DeclarationId(569), @@ -19770,7 +19776,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17935, 17941), + span: SourceSpan::new("dsl/std/types.dag", 17579, 17585), }); declarations.push(Declaration { id: DeclarationId(570), @@ -19784,7 +19790,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17944, 17947), + span: SourceSpan::new("dsl/std/types.dag", 17606, 17612), }); declarations.push(Declaration { id: DeclarationId(571), @@ -19798,7 +19804,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17950, 17959), + span: SourceSpan::new("dsl/std/types.dag", 17615, 17618), }); declarations.push(Declaration { id: DeclarationId(572), @@ -19812,7 +19818,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17962, 17964), + span: SourceSpan::new("dsl/std/types.dag", 17621, 17630), }); declarations.push(Declaration { id: DeclarationId(573), @@ -19826,17 +19832,12 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17967, 17975), + span: SourceSpan::new("dsl/std/types.dag", 17633, 17635), }); declarations.push(Declaration { id: DeclarationId(574), name: None, - connective: TypeConnective::Cardinality( - CardinalityPayload::new_unchecked_bypassing_idempotence( - DeclarationId(187), - CardinalityBound::AtMostOne, - ), - ), + connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], phantom_params: Vec::new(), meta_tag: None, @@ -19845,12 +19846,17 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18043, 18050), + span: SourceSpan::new("dsl/std/types.dag", 17638, 17646), }); declarations.push(Declaration { id: DeclarationId(575), name: None, - connective: TypeConnective::Conj { children: vec![] }, + connective: TypeConnective::Cardinality( + CardinalityPayload::new_unchecked_bypassing_idempotence( + DeclarationId(187), + CardinalityBound::AtMostOne, + ), + ), type_params: vec![], phantom_params: Vec::new(), meta_tag: None, @@ -19859,7 +19865,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18447, 18458), + span: SourceSpan::new("dsl/std/types.dag", 17714, 17721), }); declarations.push(Declaration { id: DeclarationId(576), @@ -19873,7 +19879,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18463, 18472), + span: SourceSpan::new("dsl/std/types.dag", 18118, 18129), }); declarations.push(Declaration { id: DeclarationId(577), @@ -19887,7 +19893,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18477, 18484), + span: SourceSpan::new("dsl/std/types.dag", 18134, 18143), }); declarations.push(Declaration { id: DeclarationId(578), @@ -19901,7 +19907,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18489, 18496), + span: SourceSpan::new("dsl/std/types.dag", 18148, 18155), }); declarations.push(Declaration { id: DeclarationId(579), @@ -19915,7 +19921,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18501, 18506), + span: SourceSpan::new("dsl/std/types.dag", 18160, 18167), }); declarations.push(Declaration { id: DeclarationId(580), @@ -19929,7 +19935,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18659, 18669), + span: SourceSpan::new("dsl/std/types.dag", 18172, 18177), }); declarations.push(Declaration { id: DeclarationId(581), @@ -19943,7 +19949,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18674, 18683), + span: SourceSpan::new("dsl/std/types.dag", 18330, 18340), }); declarations.push(Declaration { id: DeclarationId(582), @@ -19957,7 +19963,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18688, 18694), + span: SourceSpan::new("dsl/std/types.dag", 18345, 18354), }); declarations.push(Declaration { id: DeclarationId(583), @@ -19971,7 +19977,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 20997, 21000), + span: SourceSpan::new("dsl/std/types.dag", 18359, 18365), }); declarations.push(Declaration { id: DeclarationId(584), @@ -19985,7 +19991,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21003, 21007), + span: SourceSpan::new("dsl/std/types.dag", 20668, 20671), }); declarations.push(Declaration { id: DeclarationId(585), @@ -19999,7 +20005,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21010, 21013), + span: SourceSpan::new("dsl/std/types.dag", 20674, 20678), }); declarations.push(Declaration { id: DeclarationId(586), @@ -20013,7 +20019,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21016, 21021), + span: SourceSpan::new("dsl/std/types.dag", 20681, 20684), }); declarations.push(Declaration { id: DeclarationId(587), @@ -20027,7 +20033,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21024, 21030), + span: SourceSpan::new("dsl/std/types.dag", 20687, 20692), }); declarations.push(Declaration { id: DeclarationId(588), @@ -20041,7 +20047,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21033, 21037), + span: SourceSpan::new("dsl/std/types.dag", 20695, 20701), }); declarations.push(Declaration { id: DeclarationId(589), @@ -20055,7 +20061,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21040, 21047), + span: SourceSpan::new("dsl/std/types.dag", 20704, 20708), }); declarations.push(Declaration { id: DeclarationId(590), @@ -20069,11 +20075,25 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21535, 21541), + span: SourceSpan::new("dsl/std/types.dag", 20711, 20718), }); declarations.push(Declaration { id: DeclarationId(591), name: None, + connective: TypeConnective::Conj { children: vec![] }, + type_params: vec![], + phantom_params: Vec::new(), + meta_tag: None, + specialization_parent: None, + inhabits: None, + value_body: None, + refinement: None, + nominal_opacity: None, + span: SourceSpan::new("dsl/std/types.dag", 21206, 21212), + }); + declarations.push(Declaration { + id: DeclarationId(592), + name: None, connective: TypeConnective::Conj { children: vec![Field { label: "name".to_string(), @@ -20088,10 +20108,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21546, 21569), + span: SourceSpan::new("dsl/std/types.dag", 21217, 21240), }); declarations.push(Declaration { - id: DeclarationId(592), + id: DeclarationId(593), name: None, connective: TypeConnective::Conj { children: vec![Field { @@ -20107,10 +20127,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21574, 21600), + span: SourceSpan::new("dsl/std/types.dag", 21245, 21271), }); declarations.push(Declaration { - id: DeclarationId(593), + id: DeclarationId(594), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20121,10 +20141,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21605, 21611), + span: SourceSpan::new("dsl/std/types.dag", 21276, 21282), }); declarations.push(Declaration { - id: DeclarationId(594), + id: DeclarationId(595), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20140,10 +20160,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21803, 21813), + span: SourceSpan::new("dsl/std/types.dag", 21474, 21484), }); declarations.push(Declaration { - id: DeclarationId(595), + id: DeclarationId(596), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20159,10 +20179,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21938, 21945), + span: SourceSpan::new("dsl/std/types.dag", 21609, 21616), }); declarations.push(Declaration { - id: DeclarationId(596), + id: DeclarationId(597), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20179,10 +20199,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21985, 21997), + span: SourceSpan::new("dsl/std/types.dag", 21656, 21668), }); declarations.push(Declaration { - id: DeclarationId(597), + id: DeclarationId(598), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20198,10 +20218,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22012, 22016), + span: SourceSpan::new("dsl/std/types.dag", 21683, 21687), }); declarations.push(Declaration { - id: DeclarationId(598), + id: DeclarationId(599), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20218,10 +20238,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23367, 23385), + span: SourceSpan::new("dsl/std/types.dag", 23038, 23056), }); declarations.push(Declaration { - id: DeclarationId(599), + id: DeclarationId(600), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20238,10 +20258,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23478, 23499), + span: SourceSpan::new("dsl/std/types.dag", 23149, 23170), }); declarations.push(Declaration { - id: DeclarationId(600), + id: DeclarationId(601), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20257,10 +20277,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23783, 23790), + span: SourceSpan::new("dsl/std/types.dag", 23454, 23461), }); declarations.push(Declaration { - id: DeclarationId(601), + id: DeclarationId(602), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20277,10 +20297,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23823, 23838), + span: SourceSpan::new("dsl/std/types.dag", 23494, 23509), }); declarations.push(Declaration { - id: DeclarationId(602), + id: DeclarationId(603), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20297,10 +20317,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24127, 24145), + span: SourceSpan::new("dsl/std/types.dag", 23798, 23816), }); declarations.push(Declaration { - id: DeclarationId(603), + id: DeclarationId(604), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20317,10 +20337,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24155, 24173), + span: SourceSpan::new("dsl/std/types.dag", 23826, 23844), }); declarations.push(Declaration { - id: DeclarationId(604), + id: DeclarationId(605), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20337,10 +20357,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24195, 24207), + span: SourceSpan::new("dsl/std/types.dag", 23866, 23878), }); declarations.push(Declaration { - id: DeclarationId(605), + id: DeclarationId(606), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20356,10 +20376,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24295, 24302), + span: SourceSpan::new("dsl/std/types.dag", 23966, 23973), }); declarations.push(Declaration { - id: DeclarationId(606), + id: DeclarationId(607), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20375,10 +20395,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24389, 24396), + span: SourceSpan::new("dsl/std/types.dag", 24060, 24067), }); declarations.push(Declaration { - id: DeclarationId(607), + id: DeclarationId(608), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20395,10 +20415,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24424, 24436), + span: SourceSpan::new("dsl/std/types.dag", 24095, 24107), }); declarations.push(Declaration { - id: DeclarationId(608), + id: DeclarationId(609), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20415,10 +20435,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24448, 24460), + span: SourceSpan::new("dsl/std/types.dag", 24119, 24131), }); declarations.push(Declaration { - id: DeclarationId(609), + id: DeclarationId(610), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -20435,10 +20455,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24472, 24484), + span: SourceSpan::new("dsl/std/types.dag", 24143, 24155), }); declarations.push(Declaration { - id: DeclarationId(610), + id: DeclarationId(611), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20454,10 +20474,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24619, 24634), + span: SourceSpan::new("dsl/std/types.dag", 24290, 24305), }); declarations.push(Declaration { - id: DeclarationId(611), + id: DeclarationId(612), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20473,10 +20493,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24645, 24658), + span: SourceSpan::new("dsl/std/types.dag", 24316, 24329), }); declarations.push(Declaration { - id: DeclarationId(612), + id: DeclarationId(613), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20492,10 +20512,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24674, 24687), + span: SourceSpan::new("dsl/std/types.dag", 24345, 24358), }); declarations.push(Declaration { - id: DeclarationId(613), + id: DeclarationId(614), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20506,10 +20526,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24713, 24717), + span: SourceSpan::new("dsl/std/types.dag", 24384, 24388), }); declarations.push(Declaration { - id: DeclarationId(614), + id: DeclarationId(615), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20520,10 +20540,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24720, 24722), + span: SourceSpan::new("dsl/std/types.dag", 24391, 24393), }); declarations.push(Declaration { - id: DeclarationId(615), + id: DeclarationId(616), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20534,10 +20554,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24725, 24726), + span: SourceSpan::new("dsl/std/types.dag", 24396, 24397), }); declarations.push(Declaration { - id: DeclarationId(616), + id: DeclarationId(617), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20548,10 +20568,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24729, 24733), + span: SourceSpan::new("dsl/std/types.dag", 24400, 24404), }); declarations.push(Declaration { - id: DeclarationId(617), + id: DeclarationId(618), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -20567,10 +20587,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24797, 24804), + span: SourceSpan::new("dsl/std/types.dag", 24468, 24475), }); declarations.push(Declaration { - id: DeclarationId(618), + id: DeclarationId(619), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(135), @@ -20596,7 +20616,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/types.dag", 3063, 3080), }); declarations.push(Declaration { - id: DeclarationId(619), + id: DeclarationId(620), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(135), @@ -20622,7 +20642,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/types.dag", 3533, 3549), }); declarations.push(Declaration { - id: DeclarationId(620), + id: DeclarationId(621), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(135), @@ -20648,7 +20668,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/types.dag", 4740, 4757), }); declarations.push(Declaration { - id: DeclarationId(621), + id: DeclarationId(622), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(135), @@ -20674,7 +20694,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/types.dag", 5722, 5741), }); declarations.push(Declaration { - id: DeclarationId(622), + id: DeclarationId(623), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -20689,10 +20709,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), }); declarations.push(Declaration { - id: DeclarationId(623), + id: DeclarationId(624), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -20707,10 +20727,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), }); declarations.push(Declaration { - id: DeclarationId(624), + id: DeclarationId(625), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -20725,10 +20745,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), }); declarations.push(Declaration { - id: DeclarationId(625), + id: DeclarationId(626), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20739,10 +20759,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11277, 11319), + span: SourceSpan::new("dsl/std/types.dag", 10948, 10990), }); declarations.push(Declaration { - id: DeclarationId(626), + id: DeclarationId(627), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20753,10 +20773,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11506, 11551), + span: SourceSpan::new("dsl/std/types.dag", 11177, 11222), }); declarations.push(Declaration { - id: DeclarationId(627), + id: DeclarationId(628), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20767,10 +20787,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11552, 11597), + span: SourceSpan::new("dsl/std/types.dag", 11223, 11268), }); declarations.push(Declaration { - id: DeclarationId(628), + id: DeclarationId(629), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20781,10 +20801,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11598, 11643), + span: SourceSpan::new("dsl/std/types.dag", 11269, 11314), }); declarations.push(Declaration { - id: DeclarationId(629), + id: DeclarationId(630), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20795,10 +20815,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12278, 12337), + span: SourceSpan::new("dsl/std/types.dag", 11949, 12008), }); declarations.push(Declaration { - id: DeclarationId(630), + id: DeclarationId(631), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20809,10 +20829,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12338, 12397), + span: SourceSpan::new("dsl/std/types.dag", 12009, 12068), }); declarations.push(Declaration { - id: DeclarationId(631), + id: DeclarationId(632), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20823,10 +20843,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12502, 12545), + span: SourceSpan::new("dsl/std/types.dag", 12173, 12216), }); declarations.push(Declaration { - id: DeclarationId(632), + id: DeclarationId(633), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -20841,10 +20861,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), }); declarations.push(Declaration { - id: DeclarationId(633), + id: DeclarationId(634), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -20859,10 +20879,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), }); declarations.push(Declaration { - id: DeclarationId(634), + id: DeclarationId(635), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -20877,10 +20897,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), }); declarations.push(Declaration { - id: DeclarationId(635), + id: DeclarationId(636), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -20895,10 +20915,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), }); declarations.push(Declaration { - id: DeclarationId(636), + id: DeclarationId(637), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20909,10 +20929,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14534, 14589), + span: SourceSpan::new("dsl/std/types.dag", 14205, 14260), }); declarations.push(Declaration { - id: DeclarationId(637), + id: DeclarationId(638), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20923,10 +20943,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14590, 14644), + span: SourceSpan::new("dsl/std/types.dag", 14261, 14315), }); declarations.push(Declaration { - id: DeclarationId(638), + id: DeclarationId(639), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20937,10 +20957,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14645, 14698), + span: SourceSpan::new("dsl/std/types.dag", 14316, 14369), }); declarations.push(Declaration { - id: DeclarationId(639), + id: DeclarationId(640), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20951,10 +20971,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14699, 14756), + span: SourceSpan::new("dsl/std/types.dag", 14370, 14427), }); declarations.push(Declaration { - id: DeclarationId(640), + id: DeclarationId(641), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20965,10 +20985,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14757, 14814), + span: SourceSpan::new("dsl/std/types.dag", 14428, 14485), }); declarations.push(Declaration { - id: DeclarationId(641), + id: DeclarationId(642), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20979,10 +20999,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14815, 14870), + span: SourceSpan::new("dsl/std/types.dag", 14486, 14541), }); declarations.push(Declaration { - id: DeclarationId(642), + id: DeclarationId(643), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20993,10 +21013,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14871, 14927), + span: SourceSpan::new("dsl/std/types.dag", 14542, 14598), }); declarations.push(Declaration { - id: DeclarationId(643), + id: DeclarationId(644), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21007,10 +21027,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14928, 14984), + span: SourceSpan::new("dsl/std/types.dag", 14599, 14655), }); declarations.push(Declaration { - id: DeclarationId(644), + id: DeclarationId(645), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21021,10 +21041,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14985, 15043), + span: SourceSpan::new("dsl/std/types.dag", 14656, 14714), }); declarations.push(Declaration { - id: DeclarationId(645), + id: DeclarationId(646), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21035,10 +21055,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15274, 15345), + span: SourceSpan::new("dsl/std/types.dag", 14945, 15016), }); declarations.push(Declaration { - id: DeclarationId(646), + id: DeclarationId(647), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21049,10 +21069,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15346, 15417), + span: SourceSpan::new("dsl/std/types.dag", 15017, 15088), }); declarations.push(Declaration { - id: DeclarationId(647), + id: DeclarationId(648), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21063,10 +21083,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15418, 15485), + span: SourceSpan::new("dsl/std/types.dag", 15089, 15156), }); declarations.push(Declaration { - id: DeclarationId(648), + id: DeclarationId(649), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21077,10 +21097,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15486, 15547), + span: SourceSpan::new("dsl/std/types.dag", 15157, 15218), }); declarations.push(Declaration { - id: DeclarationId(649), + id: DeclarationId(650), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21091,10 +21111,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15627, 15669), + span: SourceSpan::new("dsl/std/types.dag", 15298, 15340), }); declarations.push(Declaration { - id: DeclarationId(650), + id: DeclarationId(651), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21105,10 +21125,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16054, 16096), + span: SourceSpan::new("dsl/std/types.dag", 15725, 15767), }); declarations.push(Declaration { - id: DeclarationId(651), + id: DeclarationId(652), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21119,10 +21139,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22095, 22159), + span: SourceSpan::new("dsl/std/types.dag", 21766, 21830), }); declarations.push(Declaration { - id: DeclarationId(652), + id: DeclarationId(653), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21133,10 +21153,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22160, 22217), + span: SourceSpan::new("dsl/std/types.dag", 21831, 21888), }); declarations.push(Declaration { - id: DeclarationId(653), + id: DeclarationId(654), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21147,10 +21167,10 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22218, 22274), + span: SourceSpan::new("dsl/std/types.dag", 21889, 21945), }); declarations.push(Declaration { - id: DeclarationId(654), + id: DeclarationId(655), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21164,7 +21184,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 3679, 3689), }); declarations.push(Declaration { - id: DeclarationId(655), + id: DeclarationId(656), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21178,7 +21198,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 3692, 3697), }); declarations.push(Declaration { - id: DeclarationId(656), + id: DeclarationId(657), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21192,7 +21212,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 3700, 3710), }); declarations.push(Declaration { - id: DeclarationId(657), + id: DeclarationId(658), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21206,7 +21226,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 3713, 3726), }); declarations.push(Declaration { - id: DeclarationId(658), + id: DeclarationId(659), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21220,7 +21240,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 4762, 4771), }); declarations.push(Declaration { - id: DeclarationId(659), + id: DeclarationId(660), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21234,7 +21254,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 4774, 4780), }); declarations.push(Declaration { - id: DeclarationId(660), + id: DeclarationId(661), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21248,7 +21268,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 4783, 4787), }); declarations.push(Declaration { - id: DeclarationId(661), + id: DeclarationId(662), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -21268,7 +21288,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 5335, 5353), }); declarations.push(Declaration { - id: DeclarationId(662), + id: DeclarationId(663), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -21288,7 +21308,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 6155, 6164), }); declarations.push(Declaration { - id: DeclarationId(663), + id: DeclarationId(664), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -21307,26 +21327,6 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { nominal_opacity: None, span: SourceSpan::new("dsl/std/unicode.dag", 6404, 6422), }); - declarations.push(Declaration { - id: DeclarationId(664), - name: None, - connective: TypeConnective::Instantiation { - template: DeclarationId(45), - arguments: vec![TemplateArgument { - parameter: DeclarationId(46), - value: DeclarationId(126), - }], - }, - type_params: vec![], - phantom_params: Vec::new(), - meta_tag: None, - specialization_parent: None, - inhabits: None, - value_body: None, - refinement: None, - nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7546, 7570), - }); declarations.push(Declaration { id: DeclarationId(665), name: Some("List".to_string()), @@ -26951,7 +26951,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4292, 4330), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4231, 4269), }); declarations.push(Declaration { id: DeclarationId(890), @@ -26970,7 +26970,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 5294, 5341), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 5233, 5280), }); declarations.push(Declaration { id: DeclarationId(891), @@ -27003,9 +27003,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 5984, 6094), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 5923, 6033), }); - declarations.push(Declaration { id: DeclarationId(892), name: Some("bridge_ledger".to_string()), connective: TypeConnective::Instantiation { template: DeclarationId(665), arguments: vec![TemplateArgument { parameter: DeclarationId(666), value: DeclarationId(891) }] }, type_params: vec![], phantom_params: Vec::new(), meta_tag: Some(DeclarationId(2032)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_source_span_file_participation_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R3".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("ROADMAP.md#lens-fold-file-path-semantics".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_mark_bootstrap_secret_nominal_opacity_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("PR #937".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_dispatch_pr1183_slice_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("src/v3/compiler/tests/integration/canonical_lens_bridge_ratchet_test.rs".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_patching_residual".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Runtime".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("docs/briefs/r2-pb-canonical-lens-bridge-disposition.md".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_include_str_side_channels_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("pipeline_authority".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("PR #1171".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_exact_string_patching_residual_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Tier-2".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("docs/r3-structure.md:83".to_string())))])])), refinement: None, nominal_opacity: None, span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6558, 8315) }); + declarations.push(Declaration { id: DeclarationId(892), name: Some("bridge_ledger".to_string()), connective: TypeConnective::Instantiation { template: DeclarationId(665), arguments: vec![TemplateArgument { parameter: DeclarationId(666), value: DeclarationId(891) }] }, type_params: vec![], phantom_params: Vec::new(), meta_tag: Some(DeclarationId(2032)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_source_span_file_participation_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R3".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("ROADMAP.md#lens-fold-file-path-semantics".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_mark_bootstrap_secret_nominal_opacity_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("PR #937".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_dispatch_pr1183_slice_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("src/v3/compiler/tests/integration/canonical_lens_bridge_ratchet_test.rs".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_patching_residual".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Runtime".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("docs/briefs/r2-pb-canonical-lens-bridge-disposition.md".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_include_str_side_channels_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("pipeline_authority".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("PR #1171".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_exact_string_patching_residual_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Tier-2".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("dsl/std/types.dag Bool inhabits BooleanAlgebra + src/v3/compiler/tests/integration/bridge_lower_helpers_patch_zero_residual_test.rs".to_string())))])])), refinement: None, nominal_opacity: None, span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6497, 7730) }); declarations.push(Declaration { id: DeclarationId(893), name: Some("CleanEmissionContract".to_string()), @@ -67676,7 +67676,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4314, 4321), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4253, 4260), }); declarations.push(Declaration { id: DeclarationId(2031), @@ -67690,7 +67690,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4326, 4330), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4265, 4269), }); declarations.push(Declaration { id: DeclarationId(2032), @@ -67710,7 +67710,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6578, 6599), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6517, 6538), }); declarations.push(Declaration { id: DeclarationId(2033), diff --git a/src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs b/src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs index e95034e9423..647e4b39f0f 100644 --- a/src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs +++ b/src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs @@ -59,7 +59,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { id: NodeId(3), data: LiteralBits::Int("1".to_string()), output: PortId(4), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -67,13 +67,13 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(3), PortId(4)], output: PortId(5), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(5), data: LiteralBits::Int("5".to_string()), output: PortId(6), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -81,21 +81,21 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(3), PortId(6)], output: PortId(7), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(7), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(5), PortId(7)], output: PortId(8), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(8), name: "".to_string(), value: PortId(8), params: vec![PortId(3)], - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, emit_participation: None, })); @@ -103,7 +103,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { id: NodeId(9), data: LiteralBits::Int("100".to_string()), output: PortId(10), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -111,13 +111,13 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(9), PortId(10)], output: PortId(11), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(11), data: LiteralBits::Int("599".to_string()), output: PortId(12), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -125,21 +125,21 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(9), PortId(12)], output: PortId(13), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(13), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(11), PortId(13)], output: PortId(14), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(14), name: "".to_string(), value: PortId(14), params: vec![PortId(9)], - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, emit_participation: None, })); @@ -147,7 +147,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { id: NodeId(15), data: LiteralBits::Int("1".to_string()), output: PortId(16), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -155,13 +155,13 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(15), PortId(16)], output: PortId(17), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(17), data: LiteralBits::Int("65535".to_string()), output: PortId(18), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -169,21 +169,21 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(15), PortId(18)], output: PortId(19), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(19), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(17), PortId(19)], output: PortId(20), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(20), name: "".to_string(), value: PortId(20), params: vec![PortId(15)], - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, emit_participation: None, })); @@ -191,7 +191,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { id: NodeId(21), data: LiteralBits::Int("0".to_string()), output: PortId(22), - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -199,14 +199,14 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(21), PortId(22)], output: PortId(23), - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(23), name: "".to_string(), value: PortId(23), params: vec![PortId(21)], - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), lane2_workflow: None, emit_participation: None, })); @@ -214,7 +214,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { id: NodeId(24), data: LiteralBits::Int("0".to_string()), output: PortId(25), - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -222,14 +222,14 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(24), PortId(25)], output: PortId(26), - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(26), name: "".to_string(), value: PortId(26), params: vec![PortId(24)], - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), lane2_workflow: None, emit_participation: None, })); @@ -237,7 +237,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { id: NodeId(27), data: LiteralBits::Int("0".to_string()), output: PortId(28), - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -245,14 +245,14 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(27), PortId(28)], output: PortId(29), - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(29), name: "".to_string(), value: PortId(29), params: vec![PortId(27)], - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), lane2_workflow: None, emit_participation: None, })); @@ -260,7 +260,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { id: NodeId(30), data: LiteralBits::Int("0".to_string()), output: PortId(31), - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -268,14 +268,14 @@ fn bootstrapped_fixture_without_parse_surface_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(30), PortId(31)], output: PortId(32), - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(32), name: "".to_string(), value: PortId(32), params: vec![PortId(30)], - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), lane2_workflow: None, emit_participation: None, })); @@ -10299,7 +10299,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20739,10 +20759,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20753,10 +20773,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20767,10 +20787,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20781,10 +20801,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20795,10 +20815,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20809,10 +20829,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20823,10 +20843,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec Vec Vec Vec Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20909,10 +20929,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20923,10 +20943,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20937,10 +20957,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20951,10 +20971,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20965,10 +20985,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20979,10 +20999,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -20993,10 +21013,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21007,10 +21027,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21021,10 +21041,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21035,10 +21055,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21049,10 +21069,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21063,10 +21083,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21077,10 +21097,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21091,10 +21111,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21105,10 +21125,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21119,10 +21139,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21133,10 +21153,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -21147,10 +21167,10 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec Vec + src/v3/compiler/tests/integration/bridge_lower_helpers_patch_zero_residual_test.rs".to_string())))])])), refinement: None, nominal_opacity: None, span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6497, 7730) }); declarations.push(Declaration { id: DeclarationId(893), name: Some("CleanEmissionContract".to_string()), @@ -64969,7 +64969,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec Vec Vec Option { diff --git a/src/v3/compiler/src/bootstrap_std_generated.rs b/src/v3/compiler/src/bootstrap_std_generated.rs index 36aba4a2856..3c3e310c2c1 100644 --- a/src/v3/compiler/src/bootstrap_std_generated.rs +++ b/src/v3/compiler/src/bootstrap_std_generated.rs @@ -59,7 +59,7 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { id: NodeId(3), data: LiteralBits::Int("1".to_string()), output: PortId(4), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -67,13 +67,13 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(3), PortId(4)], output: PortId(5), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(5), data: LiteralBits::Int("5".to_string()), output: PortId(6), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -81,21 +81,21 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(3), PortId(6)], output: PortId(7), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(7), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(5), PortId(7)], output: PortId(8), - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(8), name: "".to_string(), value: PortId(8), params: vec![PortId(3)], - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), lane2_workflow: None, emit_participation: None, })); @@ -103,7 +103,7 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { id: NodeId(9), data: LiteralBits::Int("100".to_string()), output: PortId(10), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -111,13 +111,13 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(9), PortId(10)], output: PortId(11), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(11), data: LiteralBits::Int("599".to_string()), output: PortId(12), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -125,21 +125,21 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(9), PortId(12)], output: PortId(13), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(13), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(11), PortId(13)], output: PortId(14), - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(14), name: "".to_string(), value: PortId(14), params: vec![PortId(9)], - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), lane2_workflow: None, emit_participation: None, })); @@ -147,7 +147,7 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { id: NodeId(15), data: LiteralBits::Int("1".to_string()), output: PortId(16), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -155,13 +155,13 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(15), PortId(16)], output: PortId(17), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Value(ValueNode { id: NodeId(17), data: LiteralBits::Int("65535".to_string()), output: PortId(18), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -169,21 +169,21 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Le)), inputs: vec![PortId(15), PortId(18)], output: PortId(19), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Transform(TransformNode { id: NodeId(19), target: TransformTarget::Operator(OperatorKind::Logical(LogicalOp::And)), inputs: vec![PortId(17), PortId(19)], output: PortId(20), - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(20), name: "".to_string(), value: PortId(20), params: vec![PortId(15)], - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), lane2_workflow: None, emit_participation: None, })); @@ -191,7 +191,7 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { id: NodeId(21), data: LiteralBits::Int("0".to_string()), output: PortId(22), - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -199,14 +199,14 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(21), PortId(22)], output: PortId(23), - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(23), name: "".to_string(), value: PortId(23), params: vec![PortId(21)], - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), lane2_workflow: None, emit_participation: None, })); @@ -214,7 +214,7 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { id: NodeId(24), data: LiteralBits::Int("0".to_string()), output: PortId(25), - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -222,14 +222,14 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(24), PortId(25)], output: PortId(26), - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(26), name: "".to_string(), value: PortId(26), params: vec![PortId(24)], - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), lane2_workflow: None, emit_participation: None, })); @@ -237,7 +237,7 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { id: NodeId(27), data: LiteralBits::Int("0".to_string()), output: PortId(28), - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -245,14 +245,14 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(27), PortId(28)], output: PortId(29), - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(29), name: "".to_string(), value: PortId(29), params: vec![PortId(27)], - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), lane2_workflow: None, emit_participation: None, })); @@ -260,7 +260,7 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { id: NodeId(30), data: LiteralBits::Int("0".to_string()), output: PortId(31), - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), lane2_workflow: None, })); nodes.push(Behavior::Transform(TransformNode { @@ -268,14 +268,14 @@ fn bootstrapped_std_fixture_dag_nodes() -> Vec { target: TransformTarget::Operator(OperatorKind::Comparison(ComparisonOp::Ge)), inputs: vec![PortId(30), PortId(31)], output: PortId(32), - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), })); nodes.push(Behavior::Bind(BindNode { id: NodeId(32), name: "".to_string(), value: PortId(32), params: vec![PortId(30)], - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), lane2_workflow: None, emit_participation: None, })); @@ -2991,7 +2991,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(618)), + meta_tag: Some(DeclarationId(619)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::Map( @@ -3071,7 +3071,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(619)), + meta_tag: Some(DeclarationId(620)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::Map( @@ -3185,7 +3185,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(620)), + meta_tag: Some(DeclarationId(621)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::Map( @@ -3235,7 +3235,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(621)), + meta_tag: Some(DeclarationId(622)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::Map( @@ -3350,11 +3350,11 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { phantom_params: Vec::new(), meta_tag: None, specialization_parent: None, - inhabits: Some(DeclarationId(664)), + inhabits: Some(DeclarationId(512)), value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7546, 7570), + span: SourceSpan::new("dsl/std/types.dag", 7187, 7241), }); declarations.push(Declaration { id: DeclarationId(127), @@ -3368,7 +3368,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7638, 7647), + span: SourceSpan::new("dsl/std/types.dag", 7309, 7318), }); declarations.push(Declaration { id: DeclarationId(128), @@ -3382,7 +3382,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7764, 7773), + span: SourceSpan::new("dsl/std/types.dag", 7435, 7444), }); declarations.push(Declaration { id: DeclarationId(129), @@ -3396,7 +3396,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7774, 7784), + span: SourceSpan::new("dsl/std/types.dag", 7445, 7455), }); declarations.push(Declaration { id: DeclarationId(130), @@ -3413,7 +3413,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 8475, 8490), + span: SourceSpan::new("dsl/std/types.dag", 8146, 8161), }); declarations.push(Declaration { id: DeclarationId(131), @@ -3433,7 +3433,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9254, 9294), + span: SourceSpan::new("dsl/std/types.dag", 8925, 8965), }); declarations.push(Declaration { id: DeclarationId(132), @@ -3447,7 +3447,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9254, 9294), + span: SourceSpan::new("dsl/std/types.dag", 8925, 8965), }); declarations.push(Declaration { id: DeclarationId(133), @@ -3467,7 +3467,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9295, 9338), + span: SourceSpan::new("dsl/std/types.dag", 8966, 9009), }); declarations.push(Declaration { id: DeclarationId(134), @@ -3481,7 +3481,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9295, 9338), + span: SourceSpan::new("dsl/std/types.dag", 8966, 9009), }); declarations.push(Declaration { id: DeclarationId(135), @@ -3507,7 +3507,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9339, 9389), + span: SourceSpan::new("dsl/std/types.dag", 9010, 9060), }); declarations.push(Declaration { id: DeclarationId(136), @@ -3521,7 +3521,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9339, 9389), + span: SourceSpan::new("dsl/std/types.dag", 9010, 9060), }); declarations.push(Declaration { id: DeclarationId(137), @@ -3535,7 +3535,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 9339, 9389), + span: SourceSpan::new("dsl/std/types.dag", 9010, 9060), }); declarations.push(Declaration { id: DeclarationId(138), @@ -3552,7 +3552,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10735, 10761), + span: SourceSpan::new("dsl/std/types.dag", 10406, 10432), }); declarations.push(Declaration { id: DeclarationId(139), @@ -3569,7 +3569,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10829, 10855), + span: SourceSpan::new("dsl/std/types.dag", 10500, 10526), }); declarations.push(Declaration { id: DeclarationId(140), @@ -3581,9 +3581,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(622)), + refinement: Some(DeclarationId(623)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10856, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10527, 10578), }); declarations.push(Declaration { id: DeclarationId(141), @@ -3595,9 +3595,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(623)), + refinement: Some(DeclarationId(624)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10908, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10579, 10634), }); declarations.push(Declaration { id: DeclarationId(142), @@ -3614,7 +3614,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11037, 11063), + span: SourceSpan::new("dsl/std/types.dag", 10708, 10734), }); declarations.push(Declaration { id: DeclarationId(143), @@ -3626,9 +3626,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(624)), + refinement: Some(DeclarationId(625)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11064, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10735, 10790), }); declarations.push(Declaration { id: DeclarationId(144), @@ -3645,7 +3645,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11208, 11234), + span: SourceSpan::new("dsl/std/types.dag", 10879, 10905), }); declarations.push(Declaration { id: DeclarationId(145), @@ -3664,7 +3664,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { nominal_opacity: Some(NominalOpacity { permitted_accessors: vec![], }), - span: SourceSpan::new("dsl/std/types.dag", 11235, 11276), + span: SourceSpan::new("dsl/std/types.dag", 10906, 10947), }); declarations.push(Declaration { id: DeclarationId(146), @@ -3676,9 +3676,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(625)), + refinement: Some(DeclarationId(626)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11277, 11319), + span: SourceSpan::new("dsl/std/types.dag", 10948, 10990), }); declarations.push(Declaration { id: DeclarationId(147), @@ -3695,7 +3695,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11380, 11406), + span: SourceSpan::new("dsl/std/types.dag", 11051, 11077), }); declarations.push(Declaration { id: DeclarationId(148), @@ -3712,7 +3712,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11479, 11505), + span: SourceSpan::new("dsl/std/types.dag", 11150, 11176), }); declarations.push(Declaration { id: DeclarationId(149), @@ -3724,9 +3724,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(626)), + refinement: Some(DeclarationId(627)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11506, 11551), + span: SourceSpan::new("dsl/std/types.dag", 11177, 11222), }); declarations.push(Declaration { id: DeclarationId(150), @@ -3738,9 +3738,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(627)), + refinement: Some(DeclarationId(628)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11552, 11597), + span: SourceSpan::new("dsl/std/types.dag", 11223, 11268), }); declarations.push(Declaration { id: DeclarationId(151), @@ -3752,9 +3752,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(628)), + refinement: Some(DeclarationId(629)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11598, 11643), + span: SourceSpan::new("dsl/std/types.dag", 11269, 11314), }); declarations.push(Declaration { id: DeclarationId(152), @@ -3766,9 +3766,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(629)), + refinement: Some(DeclarationId(630)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12278, 12337), + span: SourceSpan::new("dsl/std/types.dag", 11949, 12008), }); declarations.push(Declaration { id: DeclarationId(153), @@ -3780,9 +3780,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(630)), + refinement: Some(DeclarationId(631)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12338, 12397), + span: SourceSpan::new("dsl/std/types.dag", 12009, 12068), }); declarations.push(Declaration { id: DeclarationId(154), @@ -3790,7 +3790,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { connective: TypeConnective::Conj { children: vec![Field { label: "segments".to_string(), - ty: DeclarationId(512), + ty: DeclarationId(513), }], }, type_params: vec![], @@ -3801,7 +3801,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12398, 12450), + span: SourceSpan::new("dsl/std/types.dag", 12069, 12121), }); declarations.push(Declaration { id: DeclarationId(155), @@ -3809,7 +3809,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { connective: TypeConnective::Conj { children: vec![Field { label: "segments".to_string(), - ty: DeclarationId(513), + ty: DeclarationId(514), }], }, type_params: vec![], @@ -3820,7 +3820,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12451, 12501), + span: SourceSpan::new("dsl/std/types.dag", 12122, 12172), }); declarations.push(Declaration { id: DeclarationId(156), @@ -3832,9 +3832,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(631)), + refinement: Some(DeclarationId(632)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12502, 12545), + span: SourceSpan::new("dsl/std/types.dag", 12173, 12216), }); declarations.push(Declaration { id: DeclarationId(157), @@ -3863,7 +3863,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13163, 13223), + span: SourceSpan::new("dsl/std/types.dag", 12834, 12894), }); declarations.push(Declaration { id: DeclarationId(158), @@ -3880,7 +3880,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13323, 13349), + span: SourceSpan::new("dsl/std/types.dag", 12994, 13020), }); declarations.push(Declaration { id: DeclarationId(159), @@ -3892,9 +3892,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(632)), + refinement: Some(DeclarationId(633)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13350, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13021, 13065), }); declarations.push(Declaration { id: DeclarationId(160), @@ -3906,9 +3906,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(633)), + refinement: Some(DeclarationId(634)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13395, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13066, 13110), }); declarations.push(Declaration { id: DeclarationId(161), @@ -3920,9 +3920,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(634)), + refinement: Some(DeclarationId(635)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13921, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13592, 13636), }); declarations.push(Declaration { id: DeclarationId(162), @@ -3934,9 +3934,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(635)), + refinement: Some(DeclarationId(636)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13966, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13637, 13681), }); declarations.push(Declaration { id: DeclarationId(163), @@ -3948,9 +3948,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(636)), + refinement: Some(DeclarationId(637)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14534, 14589), + span: SourceSpan::new("dsl/std/types.dag", 14205, 14260), }); declarations.push(Declaration { id: DeclarationId(164), @@ -3962,9 +3962,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(637)), + refinement: Some(DeclarationId(638)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14590, 14644), + span: SourceSpan::new("dsl/std/types.dag", 14261, 14315), }); declarations.push(Declaration { id: DeclarationId(165), @@ -3976,9 +3976,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(638)), + refinement: Some(DeclarationId(639)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14645, 14698), + span: SourceSpan::new("dsl/std/types.dag", 14316, 14369), }); declarations.push(Declaration { id: DeclarationId(166), @@ -3990,9 +3990,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(639)), + refinement: Some(DeclarationId(640)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14699, 14756), + span: SourceSpan::new("dsl/std/types.dag", 14370, 14427), }); declarations.push(Declaration { id: DeclarationId(167), @@ -4004,9 +4004,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(640)), + refinement: Some(DeclarationId(641)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14757, 14814), + span: SourceSpan::new("dsl/std/types.dag", 14428, 14485), }); declarations.push(Declaration { id: DeclarationId(168), @@ -4018,9 +4018,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(641)), + refinement: Some(DeclarationId(642)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14815, 14870), + span: SourceSpan::new("dsl/std/types.dag", 14486, 14541), }); declarations.push(Declaration { id: DeclarationId(169), @@ -4032,9 +4032,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(642)), + refinement: Some(DeclarationId(643)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14871, 14927), + span: SourceSpan::new("dsl/std/types.dag", 14542, 14598), }); declarations.push(Declaration { id: DeclarationId(170), @@ -4046,9 +4046,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(643)), + refinement: Some(DeclarationId(644)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14928, 14984), + span: SourceSpan::new("dsl/std/types.dag", 14599, 14655), }); declarations.push(Declaration { id: DeclarationId(171), @@ -4060,9 +4060,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(644)), + refinement: Some(DeclarationId(645)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14985, 15043), + span: SourceSpan::new("dsl/std/types.dag", 14656, 14714), }); declarations.push(Declaration { id: DeclarationId(172), @@ -4074,9 +4074,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(645)), + refinement: Some(DeclarationId(646)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15274, 15345), + span: SourceSpan::new("dsl/std/types.dag", 14945, 15016), }); declarations.push(Declaration { id: DeclarationId(173), @@ -4088,9 +4088,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(646)), + refinement: Some(DeclarationId(647)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15346, 15417), + span: SourceSpan::new("dsl/std/types.dag", 15017, 15088), }); declarations.push(Declaration { id: DeclarationId(174), @@ -4102,9 +4102,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(647)), + refinement: Some(DeclarationId(648)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15418, 15485), + span: SourceSpan::new("dsl/std/types.dag", 15089, 15156), }); declarations.push(Declaration { id: DeclarationId(175), @@ -4116,9 +4116,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(648)), + refinement: Some(DeclarationId(649)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15486, 15547), + span: SourceSpan::new("dsl/std/types.dag", 15157, 15218), }); declarations.push(Declaration { id: DeclarationId(176), @@ -4130,9 +4130,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(649)), + refinement: Some(DeclarationId(650)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15627, 15669), + span: SourceSpan::new("dsl/std/types.dag", 15298, 15340), }); declarations.push(Declaration { id: DeclarationId(177), @@ -4144,9 +4144,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(650)), + refinement: Some(DeclarationId(651)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16054, 16096), + span: SourceSpan::new("dsl/std/types.dag", 15725, 15767), }); declarations.push(Declaration { id: DeclarationId(178), @@ -4163,7 +4163,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16221, 16254), + span: SourceSpan::new("dsl/std/types.dag", 15892, 15925), }); declarations.push(Declaration { id: DeclarationId(179), @@ -4172,15 +4172,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Linux".to_string(), - ty: DeclarationId(514), + ty: DeclarationId(515), }, Field { label: "Macos".to_string(), - ty: DeclarationId(515), + ty: DeclarationId(516), }, Field { label: "Windows".to_string(), - ty: DeclarationId(516), + ty: DeclarationId(517), }, ], }, @@ -4192,7 +4192,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16640, 16683), + span: SourceSpan::new("dsl/std/types.dag", 16311, 16354), }); declarations.push(Declaration { id: DeclarationId(180), @@ -4201,19 +4201,19 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Pure".to_string(), - ty: DeclarationId(517), + ty: DeclarationId(518), }, Field { label: "Transport".to_string(), - ty: DeclarationId(518), + ty: DeclarationId(519), }, Field { label: "SubDag".to_string(), - ty: DeclarationId(519), + ty: DeclarationId(520), }, Field { label: "Env".to_string(), - ty: DeclarationId(520), + ty: DeclarationId(521), }, ], }, @@ -4225,7 +4225,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16811, 16866), + span: SourceSpan::new("dsl/std/types.dag", 16482, 16537), }); declarations.push(Declaration { id: DeclarationId(181), @@ -4234,15 +4234,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Template".to_string(), - ty: DeclarationId(521), + ty: DeclarationId(522), }, Field { label: "Generated".to_string(), - ty: DeclarationId(522), + ty: DeclarationId(523), }, Field { label: "Static".to_string(), - ty: DeclarationId(523), + ty: DeclarationId(524), }, ], }, @@ -4254,7 +4254,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16867, 16920), + span: SourceSpan::new("dsl/std/types.dag", 16538, 16591), }); declarations.push(Declaration { id: DeclarationId(182), @@ -4263,23 +4263,23 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Xs".to_string(), - ty: DeclarationId(524), + ty: DeclarationId(525), }, Field { label: "S".to_string(), - ty: DeclarationId(525), + ty: DeclarationId(526), }, Field { label: "M".to_string(), - ty: DeclarationId(526), + ty: DeclarationId(527), }, Field { label: "L".to_string(), - ty: DeclarationId(527), + ty: DeclarationId(528), }, Field { label: "Xl".to_string(), - ty: DeclarationId(528), + ty: DeclarationId(529), }, ], }, @@ -4291,7 +4291,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16922, 16959), + span: SourceSpan::new("dsl/std/types.dag", 16593, 16630), }); declarations.push(Declaration { id: DeclarationId(183), @@ -4300,23 +4300,23 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Stored".to_string(), - ty: DeclarationId(529), + ty: DeclarationId(530), }, Field { label: "PlatformInjected".to_string(), - ty: DeclarationId(530), + ty: DeclarationId(531), }, Field { label: "WorkloadIdentity".to_string(), - ty: DeclarationId(533), + ty: DeclarationId(534), }, Field { label: "InteractiveAuth".to_string(), - ty: DeclarationId(535), + ty: DeclarationId(536), }, Field { label: "Chained".to_string(), - ty: DeclarationId(537), + ty: DeclarationId(538), }, ], }, @@ -4328,7 +4328,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17207, 17529), + span: SourceSpan::new("dsl/std/types.dag", 16878, 17200), }); declarations.push(Declaration { id: DeclarationId(184), @@ -4337,47 +4337,47 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "X86_64".to_string(), - ty: DeclarationId(538), + ty: DeclarationId(539), }, Field { label: "X86".to_string(), - ty: DeclarationId(539), + ty: DeclarationId(540), }, Field { label: "Aarch64".to_string(), - ty: DeclarationId(540), + ty: DeclarationId(541), }, Field { label: "Arm".to_string(), - ty: DeclarationId(541), + ty: DeclarationId(542), }, Field { label: "Armv7".to_string(), - ty: DeclarationId(542), + ty: DeclarationId(543), }, Field { label: "Mips".to_string(), - ty: DeclarationId(543), + ty: DeclarationId(544), }, Field { label: "Mipsel".to_string(), - ty: DeclarationId(544), + ty: DeclarationId(545), }, Field { label: "Mips64".to_string(), - ty: DeclarationId(545), + ty: DeclarationId(546), }, Field { label: "Mips64el".to_string(), - ty: DeclarationId(546), + ty: DeclarationId(547), }, Field { label: "Riscv64".to_string(), - ty: DeclarationId(547), + ty: DeclarationId(548), }, Field { label: "Wasm32".to_string(), - ty: DeclarationId(548), + ty: DeclarationId(549), }, ], }, @@ -4389,7 +4389,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17604, 17707), + span: SourceSpan::new("dsl/std/types.dag", 17275, 17378), }); declarations.push(Declaration { id: DeclarationId(185), @@ -4398,19 +4398,19 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "UnknownVendor".to_string(), - ty: DeclarationId(549), + ty: DeclarationId(550), }, Field { label: "Pc".to_string(), - ty: DeclarationId(550), + ty: DeclarationId(551), }, Field { label: "Apple".to_string(), - ty: DeclarationId(551), + ty: DeclarationId(552), }, Field { label: "W64".to_string(), - ty: DeclarationId(552), + ty: DeclarationId(553), }, ], }, @@ -4422,7 +4422,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17708, 17754), + span: SourceSpan::new("dsl/std/types.dag", 17379, 17425), }); declarations.push(Declaration { id: DeclarationId(186), @@ -4431,31 +4431,31 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Linux".to_string(), - ty: DeclarationId(553), + ty: DeclarationId(554), }, Field { label: "Macos".to_string(), - ty: DeclarationId(554), + ty: DeclarationId(555), }, Field { label: "Windows".to_string(), - ty: DeclarationId(555), + ty: DeclarationId(556), }, Field { label: "Freebsd".to_string(), - ty: DeclarationId(556), + ty: DeclarationId(557), }, Field { label: "Android".to_string(), - ty: DeclarationId(557), + ty: DeclarationId(558), }, Field { label: "Ios".to_string(), - ty: DeclarationId(558), + ty: DeclarationId(559), }, Field { label: "Wasi".to_string(), - ty: DeclarationId(559), + ty: DeclarationId(560), }, ], }, @@ -4467,7 +4467,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17755, 17821), + span: SourceSpan::new("dsl/std/types.dag", 17426, 17492), }); declarations.push(Declaration { id: DeclarationId(187), @@ -4476,39 +4476,39 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "NoneAbi".to_string(), - ty: DeclarationId(560), + ty: DeclarationId(561), }, Field { label: "Gnu".to_string(), - ty: DeclarationId(561), + ty: DeclarationId(562), }, Field { label: "GnuEabi".to_string(), - ty: DeclarationId(562), + ty: DeclarationId(563), }, Field { label: "GnuEabihf".to_string(), - ty: DeclarationId(563), + ty: DeclarationId(564), }, Field { label: "Musl".to_string(), - ty: DeclarationId(564), + ty: DeclarationId(565), }, Field { label: "Msvc".to_string(), - ty: DeclarationId(565), + ty: DeclarationId(566), }, Field { label: "AndroidAbi".to_string(), - ty: DeclarationId(566), + ty: DeclarationId(567), }, Field { label: "Eabi".to_string(), - ty: DeclarationId(567), + ty: DeclarationId(568), }, Field { label: "Eabihf".to_string(), - ty: DeclarationId(568), + ty: DeclarationId(569), }, ], }, @@ -4520,7 +4520,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17822, 17914), + span: SourceSpan::new("dsl/std/types.dag", 17493, 17585), }); declarations.push(Declaration { id: DeclarationId(188), @@ -4529,23 +4529,23 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Native".to_string(), - ty: DeclarationId(569), + ty: DeclarationId(570), }, Field { label: "Wsl".to_string(), - ty: DeclarationId(570), + ty: DeclarationId(571), }, Field { label: "Container".to_string(), - ty: DeclarationId(571), + ty: DeclarationId(572), }, Field { label: "Ci".to_string(), - ty: DeclarationId(572), + ty: DeclarationId(573), }, Field { label: "Emulator".to_string(), - ty: DeclarationId(573), + ty: DeclarationId(574), }, ], }, @@ -4557,7 +4557,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17915, 17975), + span: SourceSpan::new("dsl/std/types.dag", 17586, 17646), }); declarations.push(Declaration { id: DeclarationId(189), @@ -4578,7 +4578,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "env".to_string(), - ty: DeclarationId(574), + ty: DeclarationId(575), }, ], }, @@ -4590,7 +4590,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17977, 18052), + span: SourceSpan::new("dsl/std/types.dag", 17648, 17723), }); declarations.push(Declaration { id: DeclarationId(190), @@ -4615,7 +4615,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18054, 18119), + span: SourceSpan::new("dsl/std/types.dag", 17725, 17790), }); declarations.push(Declaration { id: DeclarationId(191), @@ -4624,23 +4624,23 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "RegularFile".to_string(), - ty: DeclarationId(575), + ty: DeclarationId(576), }, Field { label: "Directory".to_string(), - ty: DeclarationId(576), + ty: DeclarationId(577), }, Field { label: "Symlink".to_string(), - ty: DeclarationId(577), + ty: DeclarationId(578), }, Field { label: "Missing".to_string(), - ty: DeclarationId(578), + ty: DeclarationId(579), }, Field { label: "Other".to_string(), - ty: DeclarationId(579), + ty: DeclarationId(580), }, ], }, @@ -4652,7 +4652,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18428, 18506), + span: SourceSpan::new("dsl/std/types.dag", 18099, 18177), }); declarations.push(Declaration { id: DeclarationId(192), @@ -4661,15 +4661,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "TargetFile".to_string(), - ty: DeclarationId(580), + ty: DeclarationId(581), }, Field { label: "TargetDir".to_string(), - ty: DeclarationId(581), + ty: DeclarationId(582), }, Field { label: "Broken".to_string(), - ty: DeclarationId(582), + ty: DeclarationId(583), }, ], }, @@ -4681,7 +4681,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18636, 18694), + span: SourceSpan::new("dsl/std/types.dag", 18307, 18365), }); declarations.push(Declaration { id: DeclarationId(193), @@ -4698,7 +4698,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 19855, 19885), + span: SourceSpan::new("dsl/std/types.dag", 19526, 19556), }); declarations.push(Declaration { id: DeclarationId(194), @@ -4715,7 +4715,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 19966, 19996), + span: SourceSpan::new("dsl/std/types.dag", 19637, 19667), }); declarations.push(Declaration { id: DeclarationId(195), @@ -4732,7 +4732,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 20213, 20235), + span: SourceSpan::new("dsl/std/types.dag", 19884, 19906), }); declarations.push(Declaration { id: DeclarationId(196), @@ -4741,31 +4741,31 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "GET".to_string(), - ty: DeclarationId(583), + ty: DeclarationId(584), }, Field { label: "POST".to_string(), - ty: DeclarationId(584), + ty: DeclarationId(585), }, Field { label: "PUT".to_string(), - ty: DeclarationId(585), + ty: DeclarationId(586), }, Field { label: "PATCH".to_string(), - ty: DeclarationId(586), + ty: DeclarationId(587), }, Field { label: "DELETE".to_string(), - ty: DeclarationId(587), + ty: DeclarationId(588), }, Field { label: "HEAD".to_string(), - ty: DeclarationId(588), + ty: DeclarationId(589), }, Field { label: "OPTIONS".to_string(), - ty: DeclarationId(589), + ty: DeclarationId(590), }, ], }, @@ -4777,7 +4777,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 20979, 21047), + span: SourceSpan::new("dsl/std/types.dag", 20650, 20718), }); declarations.push(Declaration { id: DeclarationId(197), @@ -4786,19 +4786,19 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Bearer".to_string(), - ty: DeclarationId(590), + ty: DeclarationId(591), }, Field { label: "Header".to_string(), - ty: DeclarationId(591), + ty: DeclarationId(592), }, Field { label: "Basic".to_string(), - ty: DeclarationId(592), + ty: DeclarationId(593), }, Field { label: "ApiKey".to_string(), - ty: DeclarationId(593), + ty: DeclarationId(594), }, ], }, @@ -4810,7 +4810,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21515, 21611), + span: SourceSpan::new("dsl/std/types.dag", 21186, 21282), }); declarations.push(Declaration { id: DeclarationId(198), @@ -4827,7 +4827,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "expires_at".to_string(), - ty: DeclarationId(594), + ty: DeclarationId(595), }, ], }, @@ -4839,7 +4839,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21733, 21866), + span: SourceSpan::new("dsl/std/types.dag", 21404, 21537), }); declarations.push(Declaration { id: DeclarationId(199), @@ -4856,7 +4856,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "header_name".to_string(), - ty: DeclarationId(595), + ty: DeclarationId(596), }, Field { label: "source_id".to_string(), @@ -4864,11 +4864,11 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "required_scopes".to_string(), - ty: DeclarationId(596), + ty: DeclarationId(597), }, Field { label: "expires_in".to_string(), - ty: DeclarationId(597), + ty: DeclarationId(598), }, ], }, @@ -4880,7 +4880,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21868, 22018), + span: SourceSpan::new("dsl/std/types.dag", 21539, 21689), }); declarations.push(Declaration { id: DeclarationId(200), @@ -4892,9 +4892,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(651)), + refinement: Some(DeclarationId(652)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22095, 22159), + span: SourceSpan::new("dsl/std/types.dag", 21766, 21830), }); declarations.push(Declaration { id: DeclarationId(201), @@ -4906,9 +4906,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(652)), + refinement: Some(DeclarationId(653)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22160, 22217), + span: SourceSpan::new("dsl/std/types.dag", 21831, 21888), }); declarations.push(Declaration { id: DeclarationId(202), @@ -4920,9 +4920,9 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { specialization_parent: None, inhabits: None, value_body: None, - refinement: Some(DeclarationId(653)), + refinement: Some(DeclarationId(654)), nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22218, 22274), + span: SourceSpan::new("dsl/std/types.dag", 21889, 21945), }); declarations.push(Declaration { id: DeclarationId(203), @@ -4955,7 +4955,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22351, 22442), + span: SourceSpan::new("dsl/std/types.dag", 22022, 22113), }); declarations.push(Declaration { id: DeclarationId(204), @@ -4984,7 +4984,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22444, 22515), + span: SourceSpan::new("dsl/std/types.dag", 22115, 22186), }); declarations.push(Declaration { id: DeclarationId(205), @@ -5013,7 +5013,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22517, 22587), + span: SourceSpan::new("dsl/std/types.dag", 22188, 22258), }); declarations.push(Declaration { id: DeclarationId(206), @@ -5042,7 +5042,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22589, 22662), + span: SourceSpan::new("dsl/std/types.dag", 22260, 22333), }); declarations.push(Declaration { id: DeclarationId(207), @@ -5071,7 +5071,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22664, 22728), + span: SourceSpan::new("dsl/std/types.dag", 22335, 22399), }); declarations.push(Declaration { id: DeclarationId(208), @@ -5108,7 +5108,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22805, 22912), + span: SourceSpan::new("dsl/std/types.dag", 22476, 22583), }); declarations.push(Declaration { id: DeclarationId(209), @@ -5137,7 +5137,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22914, 22971), + span: SourceSpan::new("dsl/std/types.dag", 22585, 22642), }); declarations.push(Declaration { id: DeclarationId(210), @@ -5174,7 +5174,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22973, 23074), + span: SourceSpan::new("dsl/std/types.dag", 22644, 22745), }); declarations.push(Declaration { id: DeclarationId(211), @@ -5203,7 +5203,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23227, 23299), + span: SourceSpan::new("dsl/std/types.dag", 22898, 22970), }); declarations.push(Declaration { id: DeclarationId(212), @@ -5220,7 +5220,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "lines".to_string(), - ty: DeclarationId(598), + ty: DeclarationId(599), }, ], }, @@ -5232,7 +5232,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23301, 23387), + span: SourceSpan::new("dsl/std/types.dag", 22972, 23058), }); declarations.push(Declaration { id: DeclarationId(213), @@ -5253,7 +5253,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "sections".to_string(), - ty: DeclarationId(599), + ty: DeclarationId(600), }, Field { label: "trailing_newline".to_string(), @@ -5269,7 +5269,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23389, 23526), + span: SourceSpan::new("dsl/std/types.dag", 23060, 23197), }); declarations.push(Declaration { id: DeclarationId(214), @@ -5294,7 +5294,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23528, 23581), + span: SourceSpan::new("dsl/std/types.dag", 23199, 23252), }); declarations.push(Declaration { id: DeclarationId(215), @@ -5319,7 +5319,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23583, 23641), + span: SourceSpan::new("dsl/std/types.dag", 23254, 23312), }); declarations.push(Declaration { id: DeclarationId(216), @@ -5336,7 +5336,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "description".to_string(), - ty: DeclarationId(600), + ty: DeclarationId(601), }, ], }, @@ -5348,7 +5348,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23718, 23792), + span: SourceSpan::new("dsl/std/types.dag", 23389, 23463), }); declarations.push(Declaration { id: DeclarationId(217), @@ -5356,7 +5356,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { connective: TypeConnective::Conj { children: vec![Field { label: "tools".to_string(), - ty: DeclarationId(601), + ty: DeclarationId(602), }], }, type_params: vec![], @@ -5367,7 +5367,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23794, 23840), + span: SourceSpan::new("dsl/std/types.dag", 23465, 23511), }); declarations.push(Declaration { id: DeclarationId(218), @@ -5376,15 +5376,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { children: vec![ Field { label: "nodes".to_string(), - ty: DeclarationId(602), + ty: DeclarationId(603), }, Field { label: "edges".to_string(), - ty: DeclarationId(603), + ty: DeclarationId(604), }, Field { label: "subdag_boundaries".to_string(), - ty: DeclarationId(604), + ty: DeclarationId(605), }, ], }, @@ -5396,7 +5396,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24099, 24209), + span: SourceSpan::new("dsl/std/types.dag", 23770, 23880), }); declarations.push(Declaration { id: DeclarationId(219), @@ -5417,7 +5417,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "parent".to_string(), - ty: DeclarationId(605), + ty: DeclarationId(606), }, ], }, @@ -5429,7 +5429,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24211, 24331), + span: SourceSpan::new("dsl/std/types.dag", 23882, 24002), }); declarations.push(Declaration { id: DeclarationId(220), @@ -5446,7 +5446,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "port".to_string(), - ty: DeclarationId(606), + ty: DeclarationId(607), }, ], }, @@ -5458,7 +5458,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24333, 24398), + span: SourceSpan::new("dsl/std/types.dag", 24004, 24069), }); declarations.push(Declaration { id: DeclarationId(221), @@ -5467,15 +5467,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { children: vec![ Field { label: "added".to_string(), - ty: DeclarationId(607), + ty: DeclarationId(608), }, Field { label: "removed".to_string(), - ty: DeclarationId(608), + ty: DeclarationId(609), }, Field { label: "changed".to_string(), - ty: DeclarationId(609), + ty: DeclarationId(610), }, ], }, @@ -5487,7 +5487,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24400, 24486), + span: SourceSpan::new("dsl/std/types.dag", 24071, 24157), }); declarations.push(Declaration { id: DeclarationId(222), @@ -5504,15 +5504,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "backend".to_string(), - ty: DeclarationId(610), + ty: DeclarationId(611), }, Field { label: "target".to_string(), - ty: DeclarationId(611), + ty: DeclarationId(612), }, Field { label: "runtime_env".to_string(), - ty: DeclarationId(612), + ty: DeclarationId(613), }, ], }, @@ -5524,7 +5524,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24555, 24689), + span: SourceSpan::new("dsl/std/types.dag", 24226, 24360), }); declarations.push(Declaration { id: DeclarationId(223), @@ -5533,19 +5533,19 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Rust".to_string(), - ty: DeclarationId(613), + ty: DeclarationId(614), }, Field { label: "Go".to_string(), - ty: DeclarationId(614), + ty: DeclarationId(615), }, Field { label: "C".to_string(), - ty: DeclarationId(615), + ty: DeclarationId(616), }, Field { label: "Mips".to_string(), - ty: DeclarationId(616), + ty: DeclarationId(617), }, ], }, @@ -5557,7 +5557,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24691, 24733), + span: SourceSpan::new("dsl/std/types.dag", 24362, 24404), }); declarations.push(Declaration { id: DeclarationId(224), @@ -5574,7 +5574,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "scope".to_string(), - ty: DeclarationId(617), + ty: DeclarationId(618), }, ], }, @@ -5586,7 +5586,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24735, 24806), + span: SourceSpan::new("dsl/std/types.dag", 24406, 24477), }); declarations.push(Declaration { id: DeclarationId(225), @@ -5611,7 +5611,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24947, 25004), + span: SourceSpan::new("dsl/std/types.dag", 24618, 24675), }); declarations.push(Declaration { id: DeclarationId(226), @@ -5625,7 +5625,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 26938, 26957), + span: SourceSpan::new("dsl/std/types.dag", 26609, 26628), }); declarations.push(Declaration { id: DeclarationId(227), @@ -5639,7 +5639,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 26938, 26957), + span: SourceSpan::new("dsl/std/types.dag", 26609, 26628), }); declarations.push(Declaration { id: DeclarationId(228), @@ -5668,19 +5668,19 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "Whitespace".to_string(), - ty: DeclarationId(654), + ty: DeclarationId(655), }, Field { label: "Digit".to_string(), - ty: DeclarationId(655), + ty: DeclarationId(656), }, Field { label: "IdentStart".to_string(), - ty: DeclarationId(656), + ty: DeclarationId(657), }, Field { label: "IdentContinue".to_string(), - ty: DeclarationId(657), + ty: DeclarationId(658), }, ], }, @@ -5719,15 +5719,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { variants: vec![ Field { label: "ZeroWidth".to_string(), - ty: DeclarationId(658), + ty: DeclarationId(659), }, Field { label: "Narrow".to_string(), - ty: DeclarationId(659), + ty: DeclarationId(660), }, Field { label: "Wide".to_string(), - ty: DeclarationId(660), + ty: DeclarationId(661), }, ], }, @@ -5804,7 +5804,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(661)), + meta_tag: Some(DeclarationId(662)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![ @@ -5826,7 +5826,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -5849,7 +5849,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -5872,7 +5872,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -5895,7 +5895,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -5916,7 +5916,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -5939,7 +5939,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(658), + constructor: DeclarationId(659), payload: vec![], }, ), @@ -5961,7 +5961,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(662)), + meta_tag: Some(DeclarationId(663)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![ @@ -5986,7 +5986,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, type_params: vec![], phantom_params: Vec::new(), - meta_tag: Some(DeclarationId(663)), + meta_tag: Some(DeclarationId(664)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![ @@ -6006,7 +6006,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6029,7 +6029,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6052,7 +6052,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6073,7 +6073,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6096,7 +6096,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6119,7 +6119,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6140,7 +6140,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6163,7 +6163,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6186,7 +6186,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6207,7 +6207,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6228,7 +6228,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6249,7 +6249,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6270,7 +6270,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6293,7 +6293,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6316,7 +6316,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -6337,7 +6337,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { ( "default_width".to_string(), FieldValue::Variant { - constructor: DeclarationId(660), + constructor: DeclarationId(661), payload: vec![], }, ), @@ -11566,7 +11566,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7558, 7562), + span: SourceSpan::new("dsl/std/types.dag", 7229, 7233), }); declarations.push(Declaration { id: DeclarationId(511), @@ -11580,16 +11580,16 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7565, 7570), + span: SourceSpan::new("dsl/std/types.dag", 7236, 7241), }); declarations.push(Declaration { id: DeclarationId(512), name: None, connective: TypeConnective::Instantiation { - template: DeclarationId(131), + template: DeclarationId(45), arguments: vec![TemplateArgument { - parameter: DeclarationId(132), - value: DeclarationId(152), + parameter: DeclarationId(46), + value: DeclarationId(126), }], }, type_params: vec![], @@ -11600,7 +11600,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12431, 12448), + span: SourceSpan::new("dsl/std/types.dag", 7206, 7226), }); declarations.push(Declaration { id: DeclarationId(513), @@ -11609,7 +11609,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { template: DeclarationId(131), arguments: vec![TemplateArgument { parameter: DeclarationId(132), - value: DeclarationId(153), + value: DeclarationId(152), }], }, type_params: vec![], @@ -11620,12 +11620,18 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12482, 12499), + span: SourceSpan::new("dsl/std/types.dag", 12102, 12119), }); declarations.push(Declaration { id: DeclarationId(514), name: None, - connective: TypeConnective::Conj { children: vec![] }, + connective: TypeConnective::Instantiation { + template: DeclarationId(131), + arguments: vec![TemplateArgument { + parameter: DeclarationId(132), + value: DeclarationId(153), + }], + }, type_params: vec![], phantom_params: Vec::new(), meta_tag: None, @@ -11634,7 +11640,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16660, 16665), + span: SourceSpan::new("dsl/std/types.dag", 12153, 12170), }); declarations.push(Declaration { id: DeclarationId(515), @@ -11648,7 +11654,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16668, 16673), + span: SourceSpan::new("dsl/std/types.dag", 16331, 16336), }); declarations.push(Declaration { id: DeclarationId(516), @@ -11662,7 +11668,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16676, 16683), + span: SourceSpan::new("dsl/std/types.dag", 16339, 16344), }); declarations.push(Declaration { id: DeclarationId(517), @@ -11676,7 +11682,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16835, 16839), + span: SourceSpan::new("dsl/std/types.dag", 16347, 16354), }); declarations.push(Declaration { id: DeclarationId(518), @@ -11690,7 +11696,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16842, 16851), + span: SourceSpan::new("dsl/std/types.dag", 16506, 16510), }); declarations.push(Declaration { id: DeclarationId(519), @@ -11704,7 +11710,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16854, 16860), + span: SourceSpan::new("dsl/std/types.dag", 16513, 16522), }); declarations.push(Declaration { id: DeclarationId(520), @@ -11718,7 +11724,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16863, 16866), + span: SourceSpan::new("dsl/std/types.dag", 16525, 16531), }); declarations.push(Declaration { id: DeclarationId(521), @@ -11732,7 +11738,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16891, 16899), + span: SourceSpan::new("dsl/std/types.dag", 16534, 16537), }); declarations.push(Declaration { id: DeclarationId(522), @@ -11746,7 +11752,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16902, 16911), + span: SourceSpan::new("dsl/std/types.dag", 16562, 16570), }); declarations.push(Declaration { id: DeclarationId(523), @@ -11760,7 +11766,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16914, 16920), + span: SourceSpan::new("dsl/std/types.dag", 16573, 16582), }); declarations.push(Declaration { id: DeclarationId(524), @@ -11774,7 +11780,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16940, 16942), + span: SourceSpan::new("dsl/std/types.dag", 16585, 16591), }); declarations.push(Declaration { id: DeclarationId(525), @@ -11788,7 +11794,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16945, 16946), + span: SourceSpan::new("dsl/std/types.dag", 16611, 16613), }); declarations.push(Declaration { id: DeclarationId(526), @@ -11802,7 +11808,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16949, 16950), + span: SourceSpan::new("dsl/std/types.dag", 16616, 16617), }); declarations.push(Declaration { id: DeclarationId(527), @@ -11816,7 +11822,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16953, 16954), + span: SourceSpan::new("dsl/std/types.dag", 16620, 16621), }); declarations.push(Declaration { id: DeclarationId(528), @@ -11830,11 +11836,25 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16957, 16959), + span: SourceSpan::new("dsl/std/types.dag", 16624, 16625), }); declarations.push(Declaration { id: DeclarationId(529), name: None, + connective: TypeConnective::Conj { children: vec![] }, + type_params: vec![], + phantom_params: Vec::new(), + meta_tag: None, + specialization_parent: None, + inhabits: None, + value_body: None, + refinement: None, + nominal_opacity: None, + span: SourceSpan::new("dsl/std/types.dag", 16628, 16630), + }); + declarations.push(Declaration { + id: DeclarationId(530), + name: None, connective: TypeConnective::Conj { children: vec![Field { label: "secret_name".to_string(), @@ -11849,10 +11869,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17231, 17266), + span: SourceSpan::new("dsl/std/types.dag", 16902, 16937), }); declarations.push(Declaration { - id: DeclarationId(530), + id: DeclarationId(531), name: None, connective: TypeConnective::Conj { children: vec![Field { @@ -11868,10 +11888,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17271, 17312), + span: SourceSpan::new("dsl/std/types.dag", 16942, 16983), }); declarations.push(Declaration { - id: DeclarationId(531), + id: DeclarationId(532), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -11887,10 +11907,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17387, 17407), + span: SourceSpan::new("dsl/std/types.dag", 17058, 17078), }); declarations.push(Declaration { - id: DeclarationId(532), + id: DeclarationId(533), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -11907,10 +11927,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17422, 17434), + span: SourceSpan::new("dsl/std/types.dag", 17093, 17105), }); declarations.push(Declaration { - id: DeclarationId(533), + id: DeclarationId(534), name: None, connective: TypeConnective::Conj { children: vec![ @@ -11920,11 +11940,11 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { }, Field { label: "service_account".to_string(), - ty: DeclarationId(531), + ty: DeclarationId(532), }, Field { label: "scopes".to_string(), - ty: DeclarationId(532), + ty: DeclarationId(533), }, ], }, @@ -11936,10 +11956,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17317, 17440), + span: SourceSpan::new("dsl/std/types.dag", 16988, 17111), }); declarations.push(Declaration { - id: DeclarationId(534), + id: DeclarationId(535), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -11956,15 +11976,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17471, 17483), + span: SourceSpan::new("dsl/std/types.dag", 17142, 17154), }); declarations.push(Declaration { - id: DeclarationId(535), + id: DeclarationId(536), name: None, connective: TypeConnective::Conj { children: vec![Field { label: "scopes".to_string(), - ty: DeclarationId(534), + ty: DeclarationId(535), }], }, type_params: vec![], @@ -11975,10 +11995,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17445, 17485), + span: SourceSpan::new("dsl/std/types.dag", 17116, 17156), }); declarations.push(Declaration { - id: DeclarationId(536), + id: DeclarationId(537), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -11995,15 +12015,15 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17507, 17527), + span: SourceSpan::new("dsl/std/types.dag", 17178, 17198), }); declarations.push(Declaration { - id: DeclarationId(537), + id: DeclarationId(538), name: None, connective: TypeConnective::Conj { children: vec![Field { label: "steps".to_string(), - ty: DeclarationId(536), + ty: DeclarationId(537), }], }, type_params: vec![], @@ -12014,21 +12034,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17490, 17529), - }); - declarations.push(Declaration { - id: DeclarationId(538), - name: None, - connective: TypeConnective::Conj { children: vec![] }, - type_params: vec![], - phantom_params: Vec::new(), - meta_tag: None, - specialization_parent: None, - inhabits: None, - value_body: None, - refinement: None, - nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17616, 17622), + span: SourceSpan::new("dsl/std/types.dag", 17161, 17200), }); declarations.push(Declaration { id: DeclarationId(539), @@ -12042,7 +12048,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17625, 17628), + span: SourceSpan::new("dsl/std/types.dag", 17287, 17293), }); declarations.push(Declaration { id: DeclarationId(540), @@ -12056,7 +12062,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17631, 17638), + span: SourceSpan::new("dsl/std/types.dag", 17296, 17299), }); declarations.push(Declaration { id: DeclarationId(541), @@ -12070,7 +12076,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17641, 17644), + span: SourceSpan::new("dsl/std/types.dag", 17302, 17309), }); declarations.push(Declaration { id: DeclarationId(542), @@ -12084,7 +12090,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17647, 17652), + span: SourceSpan::new("dsl/std/types.dag", 17312, 17315), }); declarations.push(Declaration { id: DeclarationId(543), @@ -12098,7 +12104,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17655, 17659), + span: SourceSpan::new("dsl/std/types.dag", 17318, 17323), }); declarations.push(Declaration { id: DeclarationId(544), @@ -12112,7 +12118,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17662, 17668), + span: SourceSpan::new("dsl/std/types.dag", 17326, 17330), }); declarations.push(Declaration { id: DeclarationId(545), @@ -12126,7 +12132,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17671, 17677), + span: SourceSpan::new("dsl/std/types.dag", 17333, 17339), }); declarations.push(Declaration { id: DeclarationId(546), @@ -12140,7 +12146,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17680, 17688), + span: SourceSpan::new("dsl/std/types.dag", 17342, 17348), }); declarations.push(Declaration { id: DeclarationId(547), @@ -12154,7 +12160,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17691, 17698), + span: SourceSpan::new("dsl/std/types.dag", 17351, 17359), }); declarations.push(Declaration { id: DeclarationId(548), @@ -12168,7 +12174,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17701, 17707), + span: SourceSpan::new("dsl/std/types.dag", 17362, 17369), }); declarations.push(Declaration { id: DeclarationId(549), @@ -12182,7 +12188,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17722, 17735), + span: SourceSpan::new("dsl/std/types.dag", 17372, 17378), }); declarations.push(Declaration { id: DeclarationId(550), @@ -12196,7 +12202,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17738, 17740), + span: SourceSpan::new("dsl/std/types.dag", 17393, 17406), }); declarations.push(Declaration { id: DeclarationId(551), @@ -12210,7 +12216,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17743, 17748), + span: SourceSpan::new("dsl/std/types.dag", 17409, 17411), }); declarations.push(Declaration { id: DeclarationId(552), @@ -12224,7 +12230,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17751, 17754), + span: SourceSpan::new("dsl/std/types.dag", 17414, 17419), }); declarations.push(Declaration { id: DeclarationId(553), @@ -12238,7 +12244,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17765, 17770), + span: SourceSpan::new("dsl/std/types.dag", 17422, 17425), }); declarations.push(Declaration { id: DeclarationId(554), @@ -12252,7 +12258,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17773, 17778), + span: SourceSpan::new("dsl/std/types.dag", 17436, 17441), }); declarations.push(Declaration { id: DeclarationId(555), @@ -12266,7 +12272,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17781, 17788), + span: SourceSpan::new("dsl/std/types.dag", 17444, 17449), }); declarations.push(Declaration { id: DeclarationId(556), @@ -12280,7 +12286,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17791, 17798), + span: SourceSpan::new("dsl/std/types.dag", 17452, 17459), }); declarations.push(Declaration { id: DeclarationId(557), @@ -12294,7 +12300,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17801, 17808), + span: SourceSpan::new("dsl/std/types.dag", 17462, 17469), }); declarations.push(Declaration { id: DeclarationId(558), @@ -12308,7 +12314,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17811, 17814), + span: SourceSpan::new("dsl/std/types.dag", 17472, 17479), }); declarations.push(Declaration { id: DeclarationId(559), @@ -12322,7 +12328,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17817, 17821), + span: SourceSpan::new("dsl/std/types.dag", 17482, 17485), }); declarations.push(Declaration { id: DeclarationId(560), @@ -12336,7 +12342,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17836, 17843), + span: SourceSpan::new("dsl/std/types.dag", 17488, 17492), }); declarations.push(Declaration { id: DeclarationId(561), @@ -12350,7 +12356,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17846, 17849), + span: SourceSpan::new("dsl/std/types.dag", 17507, 17514), }); declarations.push(Declaration { id: DeclarationId(562), @@ -12364,7 +12370,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17852, 17859), + span: SourceSpan::new("dsl/std/types.dag", 17517, 17520), }); declarations.push(Declaration { id: DeclarationId(563), @@ -12378,7 +12384,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17862, 17871), + span: SourceSpan::new("dsl/std/types.dag", 17523, 17530), }); declarations.push(Declaration { id: DeclarationId(564), @@ -12392,7 +12398,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17874, 17878), + span: SourceSpan::new("dsl/std/types.dag", 17533, 17542), }); declarations.push(Declaration { id: DeclarationId(565), @@ -12406,7 +12412,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17881, 17885), + span: SourceSpan::new("dsl/std/types.dag", 17545, 17549), }); declarations.push(Declaration { id: DeclarationId(566), @@ -12420,7 +12426,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17888, 17898), + span: SourceSpan::new("dsl/std/types.dag", 17552, 17556), }); declarations.push(Declaration { id: DeclarationId(567), @@ -12434,7 +12440,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17901, 17905), + span: SourceSpan::new("dsl/std/types.dag", 17559, 17569), }); declarations.push(Declaration { id: DeclarationId(568), @@ -12448,7 +12454,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17908, 17914), + span: SourceSpan::new("dsl/std/types.dag", 17572, 17576), }); declarations.push(Declaration { id: DeclarationId(569), @@ -12462,7 +12468,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17935, 17941), + span: SourceSpan::new("dsl/std/types.dag", 17579, 17585), }); declarations.push(Declaration { id: DeclarationId(570), @@ -12476,7 +12482,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17944, 17947), + span: SourceSpan::new("dsl/std/types.dag", 17606, 17612), }); declarations.push(Declaration { id: DeclarationId(571), @@ -12490,7 +12496,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17950, 17959), + span: SourceSpan::new("dsl/std/types.dag", 17615, 17618), }); declarations.push(Declaration { id: DeclarationId(572), @@ -12504,7 +12510,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17962, 17964), + span: SourceSpan::new("dsl/std/types.dag", 17621, 17630), }); declarations.push(Declaration { id: DeclarationId(573), @@ -12518,17 +12524,12 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 17967, 17975), + span: SourceSpan::new("dsl/std/types.dag", 17633, 17635), }); declarations.push(Declaration { id: DeclarationId(574), name: None, - connective: TypeConnective::Cardinality( - CardinalityPayload::new_unchecked_bypassing_idempotence( - DeclarationId(187), - CardinalityBound::AtMostOne, - ), - ), + connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], phantom_params: Vec::new(), meta_tag: None, @@ -12537,12 +12538,17 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18043, 18050), + span: SourceSpan::new("dsl/std/types.dag", 17638, 17646), }); declarations.push(Declaration { id: DeclarationId(575), name: None, - connective: TypeConnective::Conj { children: vec![] }, + connective: TypeConnective::Cardinality( + CardinalityPayload::new_unchecked_bypassing_idempotence( + DeclarationId(187), + CardinalityBound::AtMostOne, + ), + ), type_params: vec![], phantom_params: Vec::new(), meta_tag: None, @@ -12551,7 +12557,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18447, 18458), + span: SourceSpan::new("dsl/std/types.dag", 17714, 17721), }); declarations.push(Declaration { id: DeclarationId(576), @@ -12565,7 +12571,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18463, 18472), + span: SourceSpan::new("dsl/std/types.dag", 18118, 18129), }); declarations.push(Declaration { id: DeclarationId(577), @@ -12579,7 +12585,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18477, 18484), + span: SourceSpan::new("dsl/std/types.dag", 18134, 18143), }); declarations.push(Declaration { id: DeclarationId(578), @@ -12593,7 +12599,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18489, 18496), + span: SourceSpan::new("dsl/std/types.dag", 18148, 18155), }); declarations.push(Declaration { id: DeclarationId(579), @@ -12607,7 +12613,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18501, 18506), + span: SourceSpan::new("dsl/std/types.dag", 18160, 18167), }); declarations.push(Declaration { id: DeclarationId(580), @@ -12621,7 +12627,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18659, 18669), + span: SourceSpan::new("dsl/std/types.dag", 18172, 18177), }); declarations.push(Declaration { id: DeclarationId(581), @@ -12635,7 +12641,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18674, 18683), + span: SourceSpan::new("dsl/std/types.dag", 18330, 18340), }); declarations.push(Declaration { id: DeclarationId(582), @@ -12649,7 +12655,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 18688, 18694), + span: SourceSpan::new("dsl/std/types.dag", 18345, 18354), }); declarations.push(Declaration { id: DeclarationId(583), @@ -12663,7 +12669,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 20997, 21000), + span: SourceSpan::new("dsl/std/types.dag", 18359, 18365), }); declarations.push(Declaration { id: DeclarationId(584), @@ -12677,7 +12683,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21003, 21007), + span: SourceSpan::new("dsl/std/types.dag", 20668, 20671), }); declarations.push(Declaration { id: DeclarationId(585), @@ -12691,7 +12697,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21010, 21013), + span: SourceSpan::new("dsl/std/types.dag", 20674, 20678), }); declarations.push(Declaration { id: DeclarationId(586), @@ -12705,7 +12711,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21016, 21021), + span: SourceSpan::new("dsl/std/types.dag", 20681, 20684), }); declarations.push(Declaration { id: DeclarationId(587), @@ -12719,7 +12725,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21024, 21030), + span: SourceSpan::new("dsl/std/types.dag", 20687, 20692), }); declarations.push(Declaration { id: DeclarationId(588), @@ -12733,7 +12739,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21033, 21037), + span: SourceSpan::new("dsl/std/types.dag", 20695, 20701), }); declarations.push(Declaration { id: DeclarationId(589), @@ -12747,7 +12753,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21040, 21047), + span: SourceSpan::new("dsl/std/types.dag", 20704, 20708), }); declarations.push(Declaration { id: DeclarationId(590), @@ -12761,11 +12767,25 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21535, 21541), + span: SourceSpan::new("dsl/std/types.dag", 20711, 20718), }); declarations.push(Declaration { id: DeclarationId(591), name: None, + connective: TypeConnective::Conj { children: vec![] }, + type_params: vec![], + phantom_params: Vec::new(), + meta_tag: None, + specialization_parent: None, + inhabits: None, + value_body: None, + refinement: None, + nominal_opacity: None, + span: SourceSpan::new("dsl/std/types.dag", 21206, 21212), + }); + declarations.push(Declaration { + id: DeclarationId(592), + name: None, connective: TypeConnective::Conj { children: vec![Field { label: "name".to_string(), @@ -12780,10 +12800,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21546, 21569), + span: SourceSpan::new("dsl/std/types.dag", 21217, 21240), }); declarations.push(Declaration { - id: DeclarationId(592), + id: DeclarationId(593), name: None, connective: TypeConnective::Conj { children: vec![Field { @@ -12799,10 +12819,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21574, 21600), + span: SourceSpan::new("dsl/std/types.dag", 21245, 21271), }); declarations.push(Declaration { - id: DeclarationId(593), + id: DeclarationId(594), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -12813,10 +12833,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21605, 21611), + span: SourceSpan::new("dsl/std/types.dag", 21276, 21282), }); declarations.push(Declaration { - id: DeclarationId(594), + id: DeclarationId(595), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -12832,10 +12852,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21803, 21813), + span: SourceSpan::new("dsl/std/types.dag", 21474, 21484), }); declarations.push(Declaration { - id: DeclarationId(595), + id: DeclarationId(596), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -12851,10 +12871,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21938, 21945), + span: SourceSpan::new("dsl/std/types.dag", 21609, 21616), }); declarations.push(Declaration { - id: DeclarationId(596), + id: DeclarationId(597), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -12871,10 +12891,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 21985, 21997), + span: SourceSpan::new("dsl/std/types.dag", 21656, 21668), }); declarations.push(Declaration { - id: DeclarationId(597), + id: DeclarationId(598), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -12890,10 +12910,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22012, 22016), + span: SourceSpan::new("dsl/std/types.dag", 21683, 21687), }); declarations.push(Declaration { - id: DeclarationId(598), + id: DeclarationId(599), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -12910,10 +12930,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23367, 23385), + span: SourceSpan::new("dsl/std/types.dag", 23038, 23056), }); declarations.push(Declaration { - id: DeclarationId(599), + id: DeclarationId(600), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -12930,10 +12950,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23478, 23499), + span: SourceSpan::new("dsl/std/types.dag", 23149, 23170), }); declarations.push(Declaration { - id: DeclarationId(600), + id: DeclarationId(601), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -12949,10 +12969,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23783, 23790), + span: SourceSpan::new("dsl/std/types.dag", 23454, 23461), }); declarations.push(Declaration { - id: DeclarationId(601), + id: DeclarationId(602), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -12969,10 +12989,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 23823, 23838), + span: SourceSpan::new("dsl/std/types.dag", 23494, 23509), }); declarations.push(Declaration { - id: DeclarationId(602), + id: DeclarationId(603), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -12989,10 +13009,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24127, 24145), + span: SourceSpan::new("dsl/std/types.dag", 23798, 23816), }); declarations.push(Declaration { - id: DeclarationId(603), + id: DeclarationId(604), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -13009,10 +13029,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24155, 24173), + span: SourceSpan::new("dsl/std/types.dag", 23826, 23844), }); declarations.push(Declaration { - id: DeclarationId(604), + id: DeclarationId(605), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -13029,10 +13049,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24195, 24207), + span: SourceSpan::new("dsl/std/types.dag", 23866, 23878), }); declarations.push(Declaration { - id: DeclarationId(605), + id: DeclarationId(606), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -13048,10 +13068,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24295, 24302), + span: SourceSpan::new("dsl/std/types.dag", 23966, 23973), }); declarations.push(Declaration { - id: DeclarationId(606), + id: DeclarationId(607), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -13067,10 +13087,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24389, 24396), + span: SourceSpan::new("dsl/std/types.dag", 24060, 24067), }); declarations.push(Declaration { - id: DeclarationId(607), + id: DeclarationId(608), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -13087,10 +13107,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24424, 24436), + span: SourceSpan::new("dsl/std/types.dag", 24095, 24107), }); declarations.push(Declaration { - id: DeclarationId(608), + id: DeclarationId(609), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -13107,10 +13127,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24448, 24460), + span: SourceSpan::new("dsl/std/types.dag", 24119, 24131), }); declarations.push(Declaration { - id: DeclarationId(609), + id: DeclarationId(610), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -13127,10 +13147,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24472, 24484), + span: SourceSpan::new("dsl/std/types.dag", 24143, 24155), }); declarations.push(Declaration { - id: DeclarationId(610), + id: DeclarationId(611), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -13146,10 +13166,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24619, 24634), + span: SourceSpan::new("dsl/std/types.dag", 24290, 24305), }); declarations.push(Declaration { - id: DeclarationId(611), + id: DeclarationId(612), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -13165,10 +13185,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24645, 24658), + span: SourceSpan::new("dsl/std/types.dag", 24316, 24329), }); declarations.push(Declaration { - id: DeclarationId(612), + id: DeclarationId(613), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -13184,10 +13204,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24674, 24687), + span: SourceSpan::new("dsl/std/types.dag", 24345, 24358), }); declarations.push(Declaration { - id: DeclarationId(613), + id: DeclarationId(614), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13198,10 +13218,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24713, 24717), + span: SourceSpan::new("dsl/std/types.dag", 24384, 24388), }); declarations.push(Declaration { - id: DeclarationId(614), + id: DeclarationId(615), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13212,10 +13232,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24720, 24722), + span: SourceSpan::new("dsl/std/types.dag", 24391, 24393), }); declarations.push(Declaration { - id: DeclarationId(615), + id: DeclarationId(616), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13226,10 +13246,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24725, 24726), + span: SourceSpan::new("dsl/std/types.dag", 24396, 24397), }); declarations.push(Declaration { - id: DeclarationId(616), + id: DeclarationId(617), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13240,10 +13260,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24729, 24733), + span: SourceSpan::new("dsl/std/types.dag", 24400, 24404), }); declarations.push(Declaration { - id: DeclarationId(617), + id: DeclarationId(618), name: None, connective: TypeConnective::Cardinality( CardinalityPayload::new_unchecked_bypassing_idempotence( @@ -13259,10 +13279,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 24797, 24804), + span: SourceSpan::new("dsl/std/types.dag", 24468, 24475), }); declarations.push(Declaration { - id: DeclarationId(618), + id: DeclarationId(619), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(135), @@ -13288,7 +13308,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/types.dag", 3063, 3080), }); declarations.push(Declaration { - id: DeclarationId(619), + id: DeclarationId(620), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(135), @@ -13314,7 +13334,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/types.dag", 3533, 3549), }); declarations.push(Declaration { - id: DeclarationId(620), + id: DeclarationId(621), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(135), @@ -13340,7 +13360,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/types.dag", 4740, 4757), }); declarations.push(Declaration { - id: DeclarationId(621), + id: DeclarationId(622), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(135), @@ -13366,7 +13386,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/types.dag", 5722, 5741), }); declarations.push(Declaration { - id: DeclarationId(622), + id: DeclarationId(623), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -13381,10 +13401,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10886, 10907), + span: SourceSpan::new("dsl/std/types.dag", 10557, 10578), }); declarations.push(Declaration { - id: DeclarationId(623), + id: DeclarationId(624), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -13399,10 +13419,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 10938, 10963), + span: SourceSpan::new("dsl/std/types.dag", 10609, 10634), }); declarations.push(Declaration { - id: DeclarationId(624), + id: DeclarationId(625), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -13417,10 +13437,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11094, 11119), + span: SourceSpan::new("dsl/std/types.dag", 10765, 10790), }); declarations.push(Declaration { - id: DeclarationId(625), + id: DeclarationId(626), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13431,10 +13451,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11277, 11319), + span: SourceSpan::new("dsl/std/types.dag", 10948, 10990), }); declarations.push(Declaration { - id: DeclarationId(626), + id: DeclarationId(627), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13445,10 +13465,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11506, 11551), + span: SourceSpan::new("dsl/std/types.dag", 11177, 11222), }); declarations.push(Declaration { - id: DeclarationId(627), + id: DeclarationId(628), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13459,10 +13479,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11552, 11597), + span: SourceSpan::new("dsl/std/types.dag", 11223, 11268), }); declarations.push(Declaration { - id: DeclarationId(628), + id: DeclarationId(629), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13473,10 +13493,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 11598, 11643), + span: SourceSpan::new("dsl/std/types.dag", 11269, 11314), }); declarations.push(Declaration { - id: DeclarationId(629), + id: DeclarationId(630), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13487,10 +13507,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12278, 12337), + span: SourceSpan::new("dsl/std/types.dag", 11949, 12008), }); declarations.push(Declaration { - id: DeclarationId(630), + id: DeclarationId(631), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13501,10 +13521,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12338, 12397), + span: SourceSpan::new("dsl/std/types.dag", 12009, 12068), }); declarations.push(Declaration { - id: DeclarationId(631), + id: DeclarationId(632), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13515,10 +13535,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 12502, 12545), + span: SourceSpan::new("dsl/std/types.dag", 12173, 12216), }); declarations.push(Declaration { - id: DeclarationId(632), + id: DeclarationId(633), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -13533,10 +13553,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13381, 13394), + span: SourceSpan::new("dsl/std/types.dag", 13052, 13065), }); declarations.push(Declaration { - id: DeclarationId(633), + id: DeclarationId(634), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -13551,10 +13571,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13426, 13439), + span: SourceSpan::new("dsl/std/types.dag", 13097, 13110), }); declarations.push(Declaration { - id: DeclarationId(634), + id: DeclarationId(635), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -13569,10 +13589,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13952, 13965), + span: SourceSpan::new("dsl/std/types.dag", 13623, 13636), }); declarations.push(Declaration { - id: DeclarationId(635), + id: DeclarationId(636), name: None, connective: TypeConnective::Arrow { inputs: vec![DeclarationId(93)], @@ -13587,10 +13607,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 13997, 14010), + span: SourceSpan::new("dsl/std/types.dag", 13668, 13681), }); declarations.push(Declaration { - id: DeclarationId(636), + id: DeclarationId(637), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13601,10 +13621,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14534, 14589), + span: SourceSpan::new("dsl/std/types.dag", 14205, 14260), }); declarations.push(Declaration { - id: DeclarationId(637), + id: DeclarationId(638), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13615,10 +13635,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14590, 14644), + span: SourceSpan::new("dsl/std/types.dag", 14261, 14315), }); declarations.push(Declaration { - id: DeclarationId(638), + id: DeclarationId(639), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13629,10 +13649,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14645, 14698), + span: SourceSpan::new("dsl/std/types.dag", 14316, 14369), }); declarations.push(Declaration { - id: DeclarationId(639), + id: DeclarationId(640), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13643,10 +13663,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14699, 14756), + span: SourceSpan::new("dsl/std/types.dag", 14370, 14427), }); declarations.push(Declaration { - id: DeclarationId(640), + id: DeclarationId(641), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13657,10 +13677,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14757, 14814), + span: SourceSpan::new("dsl/std/types.dag", 14428, 14485), }); declarations.push(Declaration { - id: DeclarationId(641), + id: DeclarationId(642), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13671,10 +13691,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14815, 14870), + span: SourceSpan::new("dsl/std/types.dag", 14486, 14541), }); declarations.push(Declaration { - id: DeclarationId(642), + id: DeclarationId(643), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13685,10 +13705,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14871, 14927), + span: SourceSpan::new("dsl/std/types.dag", 14542, 14598), }); declarations.push(Declaration { - id: DeclarationId(643), + id: DeclarationId(644), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13699,10 +13719,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14928, 14984), + span: SourceSpan::new("dsl/std/types.dag", 14599, 14655), }); declarations.push(Declaration { - id: DeclarationId(644), + id: DeclarationId(645), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13713,10 +13733,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 14985, 15043), + span: SourceSpan::new("dsl/std/types.dag", 14656, 14714), }); declarations.push(Declaration { - id: DeclarationId(645), + id: DeclarationId(646), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13727,10 +13747,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15274, 15345), + span: SourceSpan::new("dsl/std/types.dag", 14945, 15016), }); declarations.push(Declaration { - id: DeclarationId(646), + id: DeclarationId(647), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13741,10 +13761,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15346, 15417), + span: SourceSpan::new("dsl/std/types.dag", 15017, 15088), }); declarations.push(Declaration { - id: DeclarationId(647), + id: DeclarationId(648), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13755,10 +13775,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15418, 15485), + span: SourceSpan::new("dsl/std/types.dag", 15089, 15156), }); declarations.push(Declaration { - id: DeclarationId(648), + id: DeclarationId(649), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13769,10 +13789,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15486, 15547), + span: SourceSpan::new("dsl/std/types.dag", 15157, 15218), }); declarations.push(Declaration { - id: DeclarationId(649), + id: DeclarationId(650), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13783,10 +13803,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 15627, 15669), + span: SourceSpan::new("dsl/std/types.dag", 15298, 15340), }); declarations.push(Declaration { - id: DeclarationId(650), + id: DeclarationId(651), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13797,10 +13817,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 16054, 16096), + span: SourceSpan::new("dsl/std/types.dag", 15725, 15767), }); declarations.push(Declaration { - id: DeclarationId(651), + id: DeclarationId(652), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13811,10 +13831,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22095, 22159), + span: SourceSpan::new("dsl/std/types.dag", 21766, 21830), }); declarations.push(Declaration { - id: DeclarationId(652), + id: DeclarationId(653), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13825,10 +13845,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22160, 22217), + span: SourceSpan::new("dsl/std/types.dag", 21831, 21888), }); declarations.push(Declaration { - id: DeclarationId(653), + id: DeclarationId(654), name: Some("".to_string()), connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13839,10 +13859,10 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 22218, 22274), + span: SourceSpan::new("dsl/std/types.dag", 21889, 21945), }); declarations.push(Declaration { - id: DeclarationId(654), + id: DeclarationId(655), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13856,7 +13876,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 3679, 3689), }); declarations.push(Declaration { - id: DeclarationId(655), + id: DeclarationId(656), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13870,7 +13890,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 3692, 3697), }); declarations.push(Declaration { - id: DeclarationId(656), + id: DeclarationId(657), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13884,7 +13904,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 3700, 3710), }); declarations.push(Declaration { - id: DeclarationId(657), + id: DeclarationId(658), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13898,7 +13918,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 3713, 3726), }); declarations.push(Declaration { - id: DeclarationId(658), + id: DeclarationId(659), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13912,7 +13932,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 4762, 4771), }); declarations.push(Declaration { - id: DeclarationId(659), + id: DeclarationId(660), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13926,7 +13946,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 4774, 4780), }); declarations.push(Declaration { - id: DeclarationId(660), + id: DeclarationId(661), name: None, connective: TypeConnective::Conj { children: vec![] }, type_params: vec![], @@ -13940,7 +13960,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 4783, 4787), }); declarations.push(Declaration { - id: DeclarationId(661), + id: DeclarationId(662), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -13960,7 +13980,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 5335, 5353), }); declarations.push(Declaration { - id: DeclarationId(662), + id: DeclarationId(663), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -13980,7 +14000,7 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { span: SourceSpan::new("dsl/std/unicode.dag", 6155, 6164), }); declarations.push(Declaration { - id: DeclarationId(663), + id: DeclarationId(664), name: None, connective: TypeConnective::Instantiation { template: DeclarationId(131), @@ -13999,26 +14019,6 @@ fn bootstrapped_std_fixture_dag_declarations() -> Vec { nominal_opacity: None, span: SourceSpan::new("dsl/std/unicode.dag", 6404, 6422), }); - declarations.push(Declaration { - id: DeclarationId(664), - name: None, - connective: TypeConnective::Instantiation { - template: DeclarationId(45), - arguments: vec![TemplateArgument { - parameter: DeclarationId(46), - value: DeclarationId(126), - }], - }, - type_params: vec![], - phantom_params: Vec::new(), - meta_tag: None, - specialization_parent: None, - inhabits: None, - value_body: None, - refinement: None, - nominal_opacity: None, - span: SourceSpan::new("dsl/std/types.dag", 7546, 7570), - }); declarations } } diff --git a/src/v3/compiler/src/diagnostics.rs b/src/v3/compiler/src/diagnostics.rs index 7dac307d7e3..dfa64f75106 100644 --- a/src/v3/compiler/src/diagnostics.rs +++ b/src/v3/compiler/src/diagnostics.rs @@ -723,10 +723,9 @@ pub(crate) fn witness_correction_for_decl( /// Opaque, validated witness to a path in the substrate /// `bootstrap_authority` set declared by /// `src/v3/std/bootstrap_authority.dag`. Held internally as a -/// `&'static str` because the only minters are the bootstrap loader -/// (`bootstrap_regen_fresh::parse_fixture`) and bootstrap kernel-patch -/// helpers (`bootstrap::patch_kernel_bool_boolean_algebra_inhabits`), -/// both of which iterate the `&'static`-keyed authority arrays +/// `&'static str` because the only minters are bootstrap loading paths +/// such as `bootstrap_regen_fresh::parse_fixture`, which iterate +/// the `&'static`-keyed authority arrays /// produced by `build.rs` (`STAGED_FILES`/`V3_SPECS`/`COMPILER_FILES`/ /// `EXTDEPS_FILES`) — derivations of the same substrate /// `bootstrap_authority` set. @@ -748,17 +747,6 @@ impl BootstrapAuthorityKey { Self(path) } - /// Typed witness for the kernel-`Bool` `inhabits` patch authority - /// (`dsl/std/types.dag` row of the substrate `bootstrap_authority` - /// set, classified `StdAuthority`). Encapsulates the path-string so - /// `bootstrap.rs` consumers do not name `dsl/std/types.dag` directly - /// — audit-row #2 retirement (bootstrap.rs slice 1 of 2). Reviewers - /// must treat new `for_*` accessors as additions to the witness - /// surface; each one represents a hand-Rust authority site. - pub(crate) fn for_kernel_bool() -> Self { - Self::new("dsl/std/types.dag") - } - /// Typed witness for the pipeline-authority row /// (`src/v3/compiler/pipeline.dag` of the substrate /// `bootstrap_authority` set, classified `CompilerAuthority`). diff --git a/src/v3/compiler/src/infer.rs b/src/v3/compiler/src/infer.rs index c59759e8c50..c433be964cc 100644 --- a/src/v3/compiler/src/infer.rs +++ b/src/v3/compiler/src/infer.rs @@ -4357,11 +4357,9 @@ const WALK_DEPTH_LIMIT: usize = 32; /// **Not yet covered** (tracked in DOWNSTREAM_REQUIREMENTS.md as /// class-5 gaps): /// - `Bool`: ~~no structural link~~ now uses `Declaration.inhabits` on -/// the kernel `Bool` sum in `dsl/std/types.dag`, populated at bootstrap -/// (`bootstrap::patch_kernel_bool_boolean_algebra_inhabits`) so v2 -/// keeps a plain `type Bool = True | False` surface. The walk follows -/// `Declaration.inhabits` when the connective chain hits a `Disj` -/// without an inline algebra. +/// the kernel `Bool` sum authored directly in `dsl/std/types.dag`. +/// The walk follows `Declaration.inhabits` when the connective chain +/// hits a `Disj` without an inline algebra. /// - `String` / collection-level algebras whose receiver is /// `FreeMonoid` / `Set` / `Map` (the whole /// instantiation, not just `T`): needs a refinement to the diff --git a/src/v3/compiler/tests/integration/m1_5_verification_test.rs b/src/v3/compiler/tests/integration/m1_5_verification_test.rs index 5e91dda4dba..7c15d47886b 100644 --- a/src/v3/compiler/tests/integration/m1_5_verification_test.rs +++ b/src/v3/compiler/tests/integration/m1_5_verification_test.rs @@ -564,7 +564,7 @@ static BRIDGE_LEDGER_OPEN_ROW_NAMES: OnceLock> = OnceLock::new(); /// count retire bridges, and PRs that need to increase it must update /// `r3-v-bridge-ratchet-test-design.md` §Per-Bridge Gate Audit and obtain /// Verification-Mgr acknowledgment. -const EXPECTED_OPEN_BOUND: usize = 4; +const EXPECTED_OPEN_BOUND: usize = 3; fn bridge_ledger_open_row_names() -> &'static [String] { BRIDGE_LEDGER_OPEN_ROW_NAMES.get_or_init(|| { diff --git a/src/v3/std/bridge_ledger.dag b/src/v3/std/bridge_ledger.dag index a99d2b74805..53c21155a5d 100644 --- a/src/v3/std/bridge_ledger.dag +++ b/src/v3/std/bridge_ledger.dag @@ -55,13 +55,12 @@ import v3.spec.v3_l1 { DeclarationRef } // so compile-body stage order is not yet a structural Dag fact; // full gate for this site awaits derivation / lowered compile // witness." -// - `bridge_exact_string_patching_residual_retired` — Open. Per -// `r3-structure.md:83`: PB lower-helper slice (Tier-2 / #1014 -// lineage) is pinned at zero, BUT "Other exact-string patching -// classes (outside this retired lower-helper post-process bridge) -// remain out of scope for this receipt and keep their own -// dissolution triggers" — the umbrella row stays Open until those -// other classes land their own retirement receipts. +// - `bridge_exact_string_patching_residual_retired` — Retired. +// The lower-helper exact-string patch class remains pinned at zero +// by `bridge_lower_helpers_patch_zero_residual_test.rs`, and the +// live BR-19 Bool-inhabits class now authors +// `Bool inhabits BooleanAlgebra` directly in `dsl/std/types.dag` +// instead of mutating `Declaration.inhabits` from bootstrap Rust. // 🟢 TERMINAL. Closed retirement-state coproduct for ledger rows. Two // states are sufficient at this scope: a bridge has either landed its @@ -154,17 +153,7 @@ data bridge_ledger: List = [ { name: "bridge_exact_string_patching_residual_retired", owner: "PB-Tier-2", - status: Open, - // Umbrella row — `bridge_lower_helpers_patch_zero_residual_test.rs` - // ratchets only the retired sub-slice (PR #1014 lineage); the row - // stays Open because *other* exact-string patching classes remain - // outside that receipt's scope. Point `authority` at the prose - // row where the umbrella's open-scope framing is defined, - // not at the closed sub-slice's ratchet (the residual debt the - // open status tracks is exactly the "other classes" the prose - // row names — those classes' own dissolution triggers cover the - // remaining scope, and the umbrella retires when those triggers - // all fire). - authority: "docs/r3-structure.md:83" + status: Retired, + authority: "dsl/std/types.dag Bool inhabits BooleanAlgebra + src/v3/compiler/tests/integration/bridge_lower_helpers_patch_zero_residual_test.rs" } ] From c1dcd0adfbd07fc8aaafcd365db8d3b7169dc36e Mon Sep 17 00:00:00 2001 From: Brian Searls Date: Sat, 9 May 2026 20:34:03 -0400 Subject: [PATCH 2/8] WIP: R3 gate #35: bridge exact string patching residual retired --- src/v2/02_parse.dag | 16 ++++++++++ src/v2/stage0/src/v2_compiler_parse.rs | 44 ++++++++++++++++++++++++++ src/v2/tests/src/parse.rs | 12 +++++++ 3 files changed, 72 insertions(+) diff --git a/src/v2/02_parse.dag b/src/v2/02_parse.dag index da86248ea7f..3c0866912d3 100644 --- a/src/v2/02_parse.dag +++ b/src/v2/02_parse.dag @@ -399,6 +399,14 @@ fn drop_leading_type_modifier(tokens: List, modifier: String) -> List) -> List { drop_leading_type_modifier(tokens: tokens, modifier: "nominal_opaque") } +fn parse_optional_type_inhabits_clause(tokens: List, ctx: ParseContext) -> TypeResult { + if tok_is_ident_text(tok: tokens |> first, text: "inhabits") { + let r = parse_type_expr(tokens: tokens |> skip(1), ctx: ctx) + TypeResult { type_expr: r.type_expr, tokens: skip_newlines(tokens: r.tokens), ctx: r.ctx, err: r.err } + } else { + TypeResult { type_expr: leaf_type_node(name: "", span: no_span()), tokens: tokens, ctx: ctx, err: none } + } +} fn tok_is_newline(tok: Token?) -> Bool { match tok { Some { value: t } => is_newline_shape(shape: t.shape) None => false } } @@ -1279,6 +1287,10 @@ fn parse_type_after_kw(tokens: List, ctx: ParseContext, start_span: Sourc let tokens = skip_newlines(tokens: type_params_result.tokens) let ctx = type_params_result.ctx let tokens = type_body_tokens_after_modifiers(tokens: tokens) + let inhabits_result = parse_optional_type_inhabits_clause(tokens: tokens, ctx: ctx) + if has_err(err: inhabits_result.err) { return ItemResult { item: dummy, tokens: inhabits_result.tokens, ctx: inhabits_result.ctx, err: inhabits_result.err } } + let tokens = inhabits_result.tokens + let ctx = inhabits_result.ctx // Record type: type Name { fields } match eat(tokens: tokens, expected: ExpectLBrace) { @@ -1317,6 +1329,10 @@ fn parse_type_body_from_prefix(prefix: ItemPrefixResult, start_span: SourceSpan) let ctx = prefix.ctx let named_dummy = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, connective: NoConnective, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } let tokens = type_body_tokens_after_modifiers(tokens: skip_newlines(tokens: prefix.tokens)) + let inhabits_result = parse_optional_type_inhabits_clause(tokens: tokens, ctx: ctx) + if has_err(err: inhabits_result.err) { return ItemResult { item: named_dummy, tokens: inhabits_result.tokens, ctx: inhabits_result.ctx, err: inhabits_result.err } } + let tokens = inhabits_result.tokens + let ctx = inhabits_result.ctx // Record type: type Name { fields } match eat(tokens: tokens, expected: ExpectLBrace) { diff --git a/src/v2/stage0/src/v2_compiler_parse.rs b/src/v2/stage0/src/v2_compiler_parse.rs index f70bb1e0fd1..a0ed0cb9e39 100644 --- a/src/v2/stage0/src/v2_compiler_parse.rs +++ b/src/v2/stage0/src/v2_compiler_parse.rs @@ -1193,6 +1193,28 @@ pub fn type_body_tokens_after_modifiers(tokens: Rc>>) -> Rc>>, + ctx: &Rc, +) -> Rc { + if tok_is_ident_text(tokens.first().cloned(), "inhabits".to_string()) { + let r = parse_type_expr(&Rc::new(tokens.iter().skip(1).cloned().collect()), ctx); + Rc::new(TypeResult { + type_expr: r.type_expr.clone(), + tokens: skip_newlines(r.tokens.clone()), + ctx: r.ctx.clone(), + err: r.err.clone(), + }) + } else { + Rc::new(TypeResult { + type_expr: leaf_type_node(&"".to_string(), &no_span()), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, + }) + } +} + pub fn tok_is_newline(tok: Option>) -> bool { match tok { Some(t) => is_newline_shape(t.shape.clone()), @@ -2996,6 +3018,17 @@ pub fn parse_type_after_kw( let tokens = skip_newlines(type_params_result.tokens.clone()); let ctx = type_params_result.ctx.clone(); let tokens = type_body_tokens_after_modifiers(tokens.clone()); + let inhabits_result = parse_optional_type_inhabits_clause(&tokens, &ctx); + if has_err(inhabits_result.err.clone()) { + return Rc::new(ItemResult { + item: dummy, + tokens: inhabits_result.tokens.clone(), + ctx: inhabits_result.ctx.clone(), + err: inhabits_result.err.clone(), + }); + } + let tokens = inhabits_result.tokens.clone(); + let ctx = inhabits_result.ctx.clone(); match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { EatResult::EatConsumed { tokens: __ec, .. } => { let r = parse_field_list(skip_newlines(__ec.clone()), ctx.clone()); @@ -3151,6 +3184,17 @@ pub fn parse_type_body_from_prefix( ident: None, }); let tokens = type_body_tokens_after_modifiers(skip_newlines(prefix.tokens.clone())); + let inhabits_result = parse_optional_type_inhabits_clause(&tokens, &ctx); + if has_err(inhabits_result.err.clone()) { + return Rc::new(ItemResult { + item: named_dummy.clone(), + tokens: inhabits_result.tokens.clone(), + ctx: inhabits_result.ctx.clone(), + err: inhabits_result.err.clone(), + }); + } + let tokens = inhabits_result.tokens.clone(); + let ctx = inhabits_result.ctx.clone(); match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { EatResult::EatConsumed { tokens: __ec, .. } => { let r = parse_field_list(skip_newlines(__ec.clone()), ctx.clone()); diff --git a/src/v2/tests/src/parse.rs b/src/v2/tests/src/parse.rs index 3c75887550c..b823c14be61 100644 --- a/src/v2/tests/src/parse.rs +++ b/src/v2/tests/src/parse.rs @@ -699,6 +699,18 @@ fn gist_transitive_closure_parse() { } } +#[test] +fn shared_std_types_accepts_type_inhabits_clause() { + assert_parses_strict("dsl/std/types.dag"); + let source = "module test\ntype Bool inhabits BooleanAlgebra = True | False\n"; + let result = parse_source(source); + assert!( + result.error.is_none(), + "v2 parser should accept and ignore shared type inhabits clauses: {:?}", + result.error + ); +} + // ── keyword-as-name regression (dag_non_name_keywords authority) ─────── /// Keywords that ARE valid as field/type names should parse. From dae9d9f29fca0854f107956ad8a2108fc559fcff Mon Sep 17 00:00:00 2001 From: Brian Searls Date: Sat, 9 May 2026 20:54:23 -0400 Subject: [PATCH 3/8] WIP: R3 gate #35: bridge exact string patching residual retired --- src/v2/02_parse.dag | 39 +++++++++++------- src/v2/stage0/src/compiler_tests.rs | 2 - .../generated_method_template_projection.rs | 2 - src/v2/stage0/src/std_computation.rs | 12 +----- src/v2/stage0/src/std_induction.rs | 8 ++-- src/v2/stage0/src/std_termination.rs | 9 +++++ src/v2/stage0/src/std_types.rs | 12 ++++-- src/v2/stage0/src/v2_compiler_parse.rs | 40 ++++++++++++------- src/v2/tests/src/parse.rs | 14 ++++++- 9 files changed, 86 insertions(+), 52 deletions(-) diff --git a/src/v2/02_parse.dag b/src/v2/02_parse.dag index 3c0866912d3..62c2569f97c 100644 --- a/src/v2/02_parse.dag +++ b/src/v2/02_parse.dag @@ -204,6 +204,7 @@ fn parse_recovery_placeholder() -> Node { type OptRetResult { inferred: InferredNode?, tokens: List, ctx: ParseContext, err: ErrorNode? } type GuardResult { guard: Node?, tokens: List, ctx: ParseContext, err: ErrorNode? } type FromKeyResult { from_key: String?, tokens: List, ctx: ParseContext, err: ErrorNode? } +type TypeInhabitsResult { type_expr: Node?, tokens: List, ctx: ParseContext, err: ErrorNode? } // Multi-field results type PostfixResult { expr: Node, changed: Bool, tokens: List, ctx: ParseContext, err: ErrorNode? } @@ -399,12 +400,18 @@ fn drop_leading_type_modifier(tokens: List, modifier: String) -> List) -> List { drop_leading_type_modifier(tokens: tokens, modifier: "nominal_opaque") } -fn parse_optional_type_inhabits_clause(tokens: List, ctx: ParseContext) -> TypeResult { +fn parse_optional_type_inhabits_clause(tokens: List, ctx: ParseContext) -> TypeInhabitsResult { if tok_is_ident_text(tok: tokens |> first, text: "inhabits") { let r = parse_type_expr(tokens: tokens |> skip(1), ctx: ctx) - TypeResult { type_expr: r.type_expr, tokens: skip_newlines(tokens: r.tokens), ctx: r.ctx, err: r.err } + TypeInhabitsResult { type_expr: Some { value: r.type_expr }, tokens: skip_newlines(tokens: r.tokens), ctx: r.ctx, err: r.err } } else { - TypeResult { type_expr: leaf_type_node(name: "", span: no_span()), tokens: tokens, ctx: ctx, err: none } + TypeInhabitsResult { type_expr: none, tokens: tokens, ctx: ctx, err: none } + } +} +fn type_inhabits_properties(type_expr: Node?) -> List { + match type_expr { + Some { value: t } => [make_field_init_node(name: "inhabits", value: t, span: t.span, name_span: no_span())] + None => [] } } fn tok_is_newline(tok: Token?) -> Bool { @@ -1291,19 +1298,20 @@ fn parse_type_after_kw(tokens: List, ctx: ParseContext, start_span: Sourc if has_err(err: inhabits_result.err) { return ItemResult { item: dummy, tokens: inhabits_result.tokens, ctx: inhabits_result.ctx, err: inhabits_result.err } } let tokens = inhabits_result.tokens let ctx = inhabits_result.ctx + let type_properties = type_inhabits_properties(type_expr: inhabits_result.type_expr) // Record type: type Name { fields } match eat(tokens: tokens, expected: ExpectLBrace) { EatConsumed { token: _, tokens: __ec } => let r = parse_field_list(tokens: skip_newlines(tokens: __ec), ctx: ctx) - let named_dummy = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, connective: NoConnective, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } + let named_dummy = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, connective: NoConnective, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } if has_err(err: r.err) { return ItemResult { item: named_dummy, tokens: r.tokens, ctx: r.ctx, err: r.err } } let tokens = skip_newlines(tokens: r.tokens) let ctx = r.ctx let r2 = expect(tokens: tokens, expected: ExpectRBrace) if has_err(err: r2.err) { return ItemResult { item: named_dummy, tokens: r2.tokens, ctx: ctx, err: r2.err } } let type_children = r.fields |> map(f => field_to_child_node(field: f, source_indices: ctx.source_indices)) - let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: type_children, connective: Conj, params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } + let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: type_children, connective: Conj, params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } ItemResult { item: item, tokens: skip_newlines(tokens: r2.tokens), ctx: ctx, err: none } EatUnchanged { tokens: __eu } => // Sum type or alias: type Name = ... @@ -1311,10 +1319,10 @@ fn parse_type_after_kw(tokens: List, ctx: ParseContext, start_span: Sourc match eat(tokens: tokens, expected: ExpectEq) { EatConsumed { token: _, tokens: __ec } => let tokens = skip_newlines(tokens: __ec) - parse_type_body_after_eq(tokens: tokens, ctx: ctx, name: name, name_span: name_span, start_span: start_span, type_params: type_params) + parse_type_body_after_eq(tokens: tokens, ctx: ctx, name: name, name_span: name_span, start_span: start_span, type_params: type_params, type_properties: type_properties) EatUnchanged { tokens: __eu } => // Bare type declaration -- primitive type with no structural expansion - let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], connective: NoConnective, params: type_params, inferred: Some { value: Resolved { node: leaf_type_node(name: name, span: name_span) } }, return_cardinality: Required, uses: [], body: none, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } + let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], connective: NoConnective, params: type_params, inferred: Some { value: Resolved { node: leaf_type_node(name: name, span: name_span) } }, return_cardinality: Required, uses: [], body: none, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } ItemResult { item: item, tokens: __eu, ctx: ctx, err: none } } } @@ -1333,6 +1341,7 @@ fn parse_type_body_from_prefix(prefix: ItemPrefixResult, start_span: SourceSpan) if has_err(err: inhabits_result.err) { return ItemResult { item: named_dummy, tokens: inhabits_result.tokens, ctx: inhabits_result.ctx, err: inhabits_result.err } } let tokens = inhabits_result.tokens let ctx = inhabits_result.ctx + let type_properties = type_inhabits_properties(type_expr: inhabits_result.type_expr) // Record type: type Name { fields } match eat(tokens: tokens, expected: ExpectLBrace) { @@ -1344,7 +1353,7 @@ fn parse_type_body_from_prefix(prefix: ItemPrefixResult, start_span: SourceSpan) let r2 = expect(tokens: tokens, expected: ExpectRBrace) if has_err(err: r2.err) { return ItemResult { item: named_dummy, tokens: r2.tokens, ctx: ctx, err: r2.err } } let type_children = r.fields |> map(f => field_to_child_node(field: f, source_indices: ctx.source_indices)) - let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: type_children, connective: Conj, params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } + let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: type_children, connective: Conj, params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } ItemResult { item: item, tokens: skip_newlines(tokens: r2.tokens), ctx: ctx, err: none } EatUnchanged { tokens: __eu } => // Sum type or alias: type Name = ... @@ -1352,18 +1361,18 @@ fn parse_type_body_from_prefix(prefix: ItemPrefixResult, start_span: SourceSpan) match eat(tokens: tokens, expected: ExpectEq) { EatConsumed { token: _, tokens: __ec } => let tokens = skip_newlines(tokens: __ec) - parse_type_body_after_eq(tokens: tokens, ctx: ctx, name: name, name_span: name_span, start_span: start_span, type_params: type_params) + parse_type_body_after_eq(tokens: tokens, ctx: ctx, name: name, name_span: name_span, start_span: start_span, type_params: type_params, type_properties: type_properties) EatUnchanged { tokens: __eu } => // Bare type declaration -- primitive type with no structural expansion - let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], connective: NoConnective, params: type_params, inferred: Some { value: Resolved { node: leaf_type_node(name: name, span: name_span) } }, return_cardinality: Required, uses: [], body: none, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } + let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], connective: NoConnective, params: type_params, inferred: Some { value: Resolved { node: leaf_type_node(name: name, span: name_span) } }, return_cardinality: Required, uses: [], body: none, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } ItemResult { item: item, tokens: __eu, ctx: ctx, err: none } } } } // After `type Name =`, determine if this is a sum type or alias. -fn parse_type_body_after_eq(tokens: List, ctx: ParseContext, name: String, name_span: SourceSpan, start_span: SourceSpan, type_params: List) -> ItemResult { - let dummy = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, connective: NoConnective, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } +fn parse_type_body_after_eq(tokens: List, ctx: ParseContext, name: String, name_span: SourceSpan, start_span: SourceSpan, type_params: List, type_properties: List) -> ItemResult { + let dummy = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, connective: NoConnective, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } // Check if the first token is an identifier (potential variant name) // followed by LBrace or Pipe (sum type indicators). // If it's an identifier, try to parse as a sum type. @@ -1383,7 +1392,7 @@ fn parse_type_body_after_eq(tokens: List, ctx: ParseContext, name: String if has_err(err: rest.err) { return ItemResult { item: dummy, tokens: rest.tokens, ctx: rest.ctx, err: rest.err } } let variants = rest.variants let type_children = variants |> map(v => variant_to_child_node(variant: v, source_indices: ctx.source_indices)) - let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: type_children, connective: Disj, params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } + let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: type_children, connective: Disj, params: type_params, inferred: none, return_cardinality: Required, uses: [], body: none, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } ItemResult { item: item, tokens: skip_newlines(tokens: rest.tokens), ctx: rest.ctx, err: none } } else { // It's an alias: type Name = SomeType @@ -1392,7 +1401,7 @@ fn parse_type_body_after_eq(tokens: List, ctx: ParseContext, name: String // Check for where clause: type Name = BaseType where predicate(...) let wr = try_where_clause(tokens: r.tokens, ctx: r.ctx, base_te: r.type_expr, start_span: start_span) if has_err(err: wr.err) { return ItemResult { item: dummy, tokens: wr.tokens, ctx: wr.ctx, err: wr.err } } - let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], connective: NoConnective, params: type_params, inferred: Some { value: Resolved { node: wr.type_expr } }, return_cardinality: Required, uses: [], body: none, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } + let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], connective: NoConnective, params: type_params, inferred: Some { value: Resolved { node: wr.type_expr } }, return_cardinality: Required, uses: [], body: none, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } ItemResult { item: item, tokens: skip_newlines(tokens: wr.tokens), ctx: wr.ctx, err: none } } } else { @@ -1402,7 +1411,7 @@ fn parse_type_body_after_eq(tokens: List, ctx: ParseContext, name: String // Check for where clause let wr = try_where_clause(tokens: r.tokens, ctx: r.ctx, base_te: r.type_expr, start_span: start_span) if has_err(err: wr.err) { return ItemResult { item: dummy, tokens: wr.tokens, ctx: wr.ctx, err: wr.err } } - let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], connective: NoConnective, params: type_params, inferred: Some { value: Resolved { node: wr.type_expr } }, return_cardinality: Required, uses: [], body: none, transport: none, properties: [], type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } + let item = Node { name: name, span: start_span, ident_span: Some { value: name_span }, children: [], connective: NoConnective, params: type_params, inferred: Some { value: Resolved { node: wr.type_expr } }, return_cardinality: Required, uses: [], body: none, transport: none, properties: type_properties, type_annotation: none, is_self_recursive: false, has_non_tail_self_call: false, match_pattern: none, expr_data: NoExprData } ItemResult { item: item, tokens: skip_newlines(tokens: wr.tokens), ctx: wr.ctx, err: none } } } diff --git a/src/v2/stage0/src/compiler_tests.rs b/src/v2/stage0/src/compiler_tests.rs index daa95fa3e6f..090fdc8a468 100644 --- a/src/v2/stage0/src/compiler_tests.rs +++ b/src/v2/stage0/src/compiler_tests.rs @@ -186,12 +186,10 @@ mod compiler_tests { "dsl/extdeps/github/auth.dag", "dsl/extdeps/github/gists.dag", "dsl/extdeps/github/github.dag", - "dsl/extdeps/shell.dag", "dsl/gunbc/auth/credentials.dag", "dsl/gunbc/tools/gist.dag", "dsl/std/error_primitives.dag", "dsl/std/algebra.dag", - "dsl/std/credentials.dag", "dsl/std/encoding.dag", "dsl/std/errors.dag", "dsl/std/filesystem.dag", diff --git a/src/v2/stage0/src/generated_method_template_projection.rs b/src/v2/stage0/src/generated_method_template_projection.rs index 6d195ebd7c9..0ec3341ea20 100644 --- a/src/v2/stage0/src/generated_method_template_projection.rs +++ b/src/v2/stage0/src/generated_method_template_projection.rs @@ -41,7 +41,6 @@ pub fn python_method_template_emit() -> Rc> { __m.insert("flat_map".to_string(), "[y for x in {recv} for y in {arg}(x)]".to_string()); __m.insert("join".to_string(), "{arg}.join({recv})".to_string()); __m.insert("last".to_string(), "{recv}[-1] if {recv} else None".to_string()); - __m.insert("map".to_string(), "[{arg}(x) for x in {recv}]".to_string()); __m.insert("skip".to_string(), "{recv}[{arg}:]".to_string()); __m.insert("sort_by".to_string(), "sorted({recv}, key={arg})".to_string()); __m.insert("split".to_string(), "{recv}.split({arg})".to_string()); @@ -64,7 +63,6 @@ pub fn go_method_template_emit() -> Rc> { __m.insert("filter".to_string(), "v2rt.Filter({recv}, {arg})".to_string()); __m.insert("flat_map".to_string(), "v2rt.FlatMap({recv}, {arg})".to_string()); __m.insert("join".to_string(), "strings.Join({recv}, {arg})".to_string()); - __m.insert("map".to_string(), "v2rt.Map({recv}, {arg})".to_string()); __m.insert("skip".to_string(), "{recv}[{arg}:]".to_string()); __m.insert("sort_by".to_string(), "v2rt.SortBy({recv}, {arg})".to_string()); __m.insert("split".to_string(), "strings.Split({recv}, {arg})".to_string()); diff --git a/src/v2/stage0/src/std_computation.rs b/src/v2/stage0/src/std_computation.rs index 8d80b44bedd..73550cefcca 100644 --- a/src/v2/stage0/src/std_computation.rs +++ b/src/v2/stage0/src/std_computation.rs @@ -17,7 +17,8 @@ use crate::std_termination::PositiveDescentAmount::{AdditionalStep, OneStep}; use crate::std_termination::ProportionalDivisor::{DivideByTwo, StrictlyLarger}; use crate::std_termination::RankingDimension::*; pub use crate::std_termination::{ - DescentEvidence, PositiveDescentAmount, ProportionalDivisor, RankingDimension, + positive_descent_count, DescentEvidence, PositiveDescentAmount, ProportionalDivisor, + RankingDimension, }; use crate::v2_rt; use crate::NonEmptyBTreeSet; @@ -42,15 +43,6 @@ pub fn tree_size_bound(param: String) -> Rc { Rc::new(SizeBound::TreeSize { param: param }) } -pub fn positive_descent_count(steps: Rc) -> i64 { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*steps).clone() { - PositiveDescentAmount::OneStep => 1, - PositiveDescentAmount::AdditionalStep { previous: p, .. } => { - (1 + positive_descent_count(p.clone())) - } - }) -} - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum CallPattern { diff --git a/src/v2/stage0/src/std_induction.rs b/src/v2/stage0/src/std_induction.rs index b5fab6085e5..ab652cf1049 100644 --- a/src/v2/stage0/src/std_induction.rs +++ b/src/v2/stage0/src/std_induction.rs @@ -13,8 +13,7 @@ use crate::std_computation::IterationPrimitive::{Descend, Fold, Repeat}; use crate::std_computation::ShrinkFactor::{ConstantShrink, ProportionalShrink, UnitShrink}; use crate::std_computation::SizeBound::{ArithmeticParam, CollectionSize, Forever}; pub use crate::std_computation::{ - positive_descent_count, tree_size_bound, CallPattern, IterationPrimitive, LoweringTarget, - ShrinkFactor, SizeBound, + tree_size_bound, CallPattern, IterationPrimitive, LoweringTarget, ShrinkFactor, SizeBound, }; use crate::std_termination::DescentEvidence::{DescentUnknown, NonIncreasing, Strict}; use crate::std_termination::PositiveDescentAmount::{AdditionalStep, OneStep}; @@ -22,8 +21,9 @@ use crate::std_termination::ProportionalDivisor::{DivideByTwo, StrictlyLarger}; use crate::std_termination::RankingDimension::TreeSize; pub use crate::std_termination::{ peano_literal_materialization_cap, positive_descent_amount_from_positive_int, - proportional_divisor_from_int_at_least_two, proportional_divisor_to_int, DescentEvidence, - PositiveDescentAmount, ProportionalDivisor, RankingDimension, + positive_descent_count, proportional_divisor_from_int_at_least_two, + proportional_divisor_to_int, DescentEvidence, PositiveDescentAmount, ProportionalDivisor, + RankingDimension, }; use crate::v2_rt; use crate::NonEmptyBTreeSet; diff --git a/src/v2/stage0/src/std_termination.rs b/src/v2/stage0/src/std_termination.rs index 79bf0c81769..0e132b78d33 100644 --- a/src/v2/stage0/src/std_termination.rs +++ b/src/v2/stage0/src/std_termination.rs @@ -131,6 +131,15 @@ impl PositiveDescentAmount { } } +pub fn positive_descent_count(steps: Rc) -> i64 { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*steps).clone() { + PositiveDescentAmount::OneStep => 1, + PositiveDescentAmount::AdditionalStep { previous: p, .. } => { + (1 + positive_descent_count(p.clone())) + } + }) +} + #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum ProportionalDivisor { diff --git a/src/v2/stage0/src/std_types.rs b/src/v2/stage0/src/std_types.rs index 6a2e4dea177..f04b8a90acf 100644 --- a/src/v2/stage0/src/std_types.rs +++ b/src/v2/stage0/src/std_types.rs @@ -215,10 +215,6 @@ pub type LanguageId = String; pub type SecretName = String; -pub type PositiveInt = i64; - -pub type NonNegativeInt = i64; - pub type PathSegment = String; pub type GlobSegment = String; @@ -270,6 +266,14 @@ pub type SignalKey = String; pub type ContentHash = String; +pub type WorkflowProducerId = String; + +pub type WorkflowObserverId = String; + +pub type WorkflowProverId = String; + +pub type WorkflowRunId = String; + pub type GitRef = String; pub type GcpProjectId = String; diff --git a/src/v2/stage0/src/v2_compiler_parse.rs b/src/v2/stage0/src/v2_compiler_parse.rs index a0ed0cb9e39..5b181394296 100644 --- a/src/v2/stage0/src/v2_compiler_parse.rs +++ b/src/v2/stage0/src/v2_compiler_parse.rs @@ -1195,21 +1195,33 @@ pub fn type_body_tokens_after_modifiers(tokens: Rc>>) -> Rc>>, - ctx: &Rc, + ctx: Rc, ) -> Rc { - if tok_is_ident_text(tokens.first().cloned(), "inhabits".to_string()) { - let r = parse_type_expr(&Rc::new(tokens.iter().skip(1).cloned().collect()), ctx); - Rc::new(TypeResult { - type_expr: r.type_expr.clone(), - tokens: skip_newlines(r.tokens.clone()), - ctx: r.ctx.clone(), - err: r.err.clone(), - }) + if tok_is_ident_text(tokens.clone().first().cloned(), "inhabits".to_string()) { + { + let r = parse_type_expr( + &Rc::new( + tokens + .clone() + .iter() + .cloned() + .skip(1 as usize) + .collect::>(), + ), + &ctx, + ); + Rc::new(TypeResult { + type_expr: r.type_expr.clone(), + tokens: skip_newlines(r.tokens.clone()), + ctx: r.ctx.clone(), + err: r.err.clone(), + }) + } } else { Rc::new(TypeResult { type_expr: leaf_type_node(&"".to_string(), &no_span()), tokens: tokens.clone(), - ctx: ctx.clone(), + ctx: ctx, err: None, }) } @@ -3004,7 +3016,7 @@ pub fn parse_type_after_kw( let r = expect_ident(&tokens); if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, + item: dummy.clone(), tokens: r.tokens.clone(), ctx: ctx.clone(), err: r.err.clone(), @@ -3018,10 +3030,10 @@ pub fn parse_type_after_kw( let tokens = skip_newlines(type_params_result.tokens.clone()); let ctx = type_params_result.ctx.clone(); let tokens = type_body_tokens_after_modifiers(tokens.clone()); - let inhabits_result = parse_optional_type_inhabits_clause(&tokens, &ctx); + let inhabits_result = parse_optional_type_inhabits_clause(&tokens, ctx.clone()); if has_err(inhabits_result.err.clone()) { return Rc::new(ItemResult { - item: dummy, + item: dummy.clone(), tokens: inhabits_result.tokens.clone(), ctx: inhabits_result.ctx.clone(), err: inhabits_result.err.clone(), @@ -3184,7 +3196,7 @@ pub fn parse_type_body_from_prefix( ident: None, }); let tokens = type_body_tokens_after_modifiers(skip_newlines(prefix.tokens.clone())); - let inhabits_result = parse_optional_type_inhabits_clause(&tokens, &ctx); + let inhabits_result = parse_optional_type_inhabits_clause(&tokens, ctx.clone()); if has_err(inhabits_result.err.clone()) { return Rc::new(ItemResult { item: named_dummy.clone(), diff --git a/src/v2/tests/src/parse.rs b/src/v2/tests/src/parse.rs index b823c14be61..205bc5befd0 100644 --- a/src/v2/tests/src/parse.rs +++ b/src/v2/tests/src/parse.rs @@ -706,9 +706,21 @@ fn shared_std_types_accepts_type_inhabits_clause() { let result = parse_source(source); assert!( result.error.is_none(), - "v2 parser should accept and ignore shared type inhabits clauses: {:?}", + "v2 parser should accept shared type inhabits clauses: {:?}", result.error ); + let module = result.module.clone().expect("module"); + let type_item = module.children[0].clone(); + let inhabits = type_item + .properties + .iter() + .find(|property| property.name == "inhabits") + .expect("type inhabits clause should be carried as a structural property"); + let inhabits_expr = inhabits + .children + .first() + .expect("inhabits property should contain the parsed relation type"); + assert_eq!(inhabits_expr.name, "BooleanAlgebra"); } // ── keyword-as-name regression (dag_non_name_keywords authority) ─────── From abdd07fd974b38dbce1b4ff01f126d03c234bee9 Mon Sep 17 00:00:00 2001 From: Brian Searls Date: Sat, 9 May 2026 20:59:44 -0400 Subject: [PATCH 4/8] WIP: R3 gate #35: bridge exact string patching residual retired --- src/v2/stage0/src/compiler_tests.rs | 598 +- .../stage0/src/extdeps_languages_dag_emit.rs | 6 +- .../src/extdeps_languages_dag_syntax.rs | 420 +- .../stage0/src/extdeps_languages_dag_types.rs | 8 +- .../stage0/src/extdeps_languages_go_emit.rs | 6 +- .../stage0/src/extdeps_languages_go_syntax.rs | 280 +- .../stage0/src/extdeps_languages_go_types.rs | 12 +- .../src/extdeps_languages_python_emit.rs | 6 +- .../src/extdeps_languages_python_syntax.rs | 296 +- .../src/extdeps_languages_python_types.rs | 10 +- .../stage0/src/extdeps_languages_rust_emit.rs | 98 +- .../src/extdeps_languages_rust_syntax.rs | 406 +- .../src/extdeps_languages_rust_types.rs | 20 +- .../generated_method_template_projection.rs | 6 +- src/v2/stage0/src/lib.rs | 82 +- src/v2/stage0/src/main.rs | 86 +- src/v2/stage0/src/std_algebra.rs | 1965 +- src/v2/stage0/src/std_coercion.rs | 32 +- src/v2/stage0/src/std_computation.rs | 270 +- src/v2/stage0/src/std_effects.rs | 275 +- src/v2/stage0/src/std_error_primitives.rs | 18 +- src/v2/stage0/src/std_graph.rs | 293 +- src/v2/stage0/src/std_http_path.rs | 335 +- src/v2/stage0/src/std_induction.rs | 1127 +- src/v2/stage0/src/std_iteration.rs | 8 +- src/v2/stage0/src/std_node.rs | 182 +- src/v2/stage0/src/std_syntax.rs | 86 +- src/v2/stage0/src/std_termination.rs | 201 +- src/v2/stage0/src/std_types.rs | 121 +- src/v2/stage0/src/v2_compiler_artifact.rs | 55 +- src/v2/stage0/src/v2_compiler_coercion.rs | 440 +- src/v2/stage0/src/v2_compiler_compile.rs | 2537 +- .../src/v2_compiler_compiler_tests_rust.rs | 231 +- src/v2/stage0/src/v2_compiler_complexity.rs | 12325 +++------- .../src/v2_compiler_effect_derivation.rs | 55 +- src/v2/stage0/src/v2_compiler_emit.rs | 6870 ++---- src/v2/stage0/src/v2_compiler_emit_go.rs | 1829 +- src/v2/stage0/src/v2_compiler_emit_python.rs | 1581 +- src/v2/stage0/src/v2_compiler_emit_rust.rs | 18066 ++++---------- src/v2/stage0/src/v2_compiler_infer.rs | 16022 +++++------- src/v2/stage0/src/v2_compiler_infer_access.rs | 266 +- src/v2/stage0/src/v2_compiler_infer_cycle.rs | 368 +- .../stage0/src/v2_compiler_infer_emit_info.rs | 699 +- src/v2/stage0/src/v2_compiler_infer_env.rs | 279 +- src/v2/stage0/src/v2_compiler_infer_items.rs | 180 +- src/v2/stage0/src/v2_compiler_infer_lookup.rs | 735 +- src/v2/stage0/src/v2_compiler_infer_method.rs | 185 +- .../stage0/src/v2_compiler_infer_patterns.rs | 484 +- .../stage0/src/v2_compiler_infer_resolve.rs | 3834 ++- .../stage0/src/v2_compiler_infer_service.rs | 472 +- src/v2/stage0/src/v2_compiler_infer_sigs.rs | 572 +- src/v2/stage0/src/v2_compiler_infer_types.rs | 3175 +-- src/v2/stage0/src/v2_compiler_languages.rs | 1750 +- src/v2/stage0/src/v2_compiler_normalize.rs | 249 +- src/v2/stage0/src/v2_compiler_ownership.rs | 1490 +- src/v2/stage0/src/v2_compiler_parse.rs | 20169 +++++++--------- src/v2/stage0/src/v2_compiler_resolve.rs | 920 +- src/v2/stage0/src/v2_compiler_runtime_rust.rs | 86 +- src/v2/stage0/src/v2_compiler_tokenize.rs | 1000 +- src/v2/stage0/src/v2_compiler_trace.rs | 225 +- src/v2/stage0/src/v2_rt.rs | 187 +- src/v2/stage0/src/v2_std_core.rs | 3419 +-- 62 files changed, 35911 insertions(+), 72097 deletions(-) diff --git a/src/v2/stage0/src/compiler_tests.rs b/src/v2/stage0/src/compiler_tests.rs index 090fdc8a468..5b1482a6d38 100644 --- a/src/v2/stage0/src/compiler_tests.rs +++ b/src/v2/stage0/src/compiler_tests.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod compiler_tests { - use crate::v2_compiler_tokenize::tokenize; use std::collections::HashMap; + use crate::v2_compiler_tokenize::tokenize; /// Find workspace root by walking up from the current directory looking for Cargo.toml + dsl/ fn workspace_root() -> std::path::PathBuf { @@ -92,11 +92,9 @@ mod compiler_tests { crate::v2_std_core::diagnostic_to_message(err.diagnostic.clone()) ); } - parsed - .result - .module - .clone() - .unwrap_or_else(|| panic!("{} produced no module while building source closure", path)) + parsed.result.module.clone().unwrap_or_else(|| { + panic!("{} produced no module while building source closure", path) + }) } fn module_path_from_source(path: &str, content: &str) -> String { @@ -111,7 +109,9 @@ mod compiler_tests { .collect() } - fn build_source_index(roots: &[&str]) -> HashMap { + fn build_source_index( + roots: &[&str], + ) -> HashMap { let mut index = HashMap::new(); for root in roots { for (path, content) in discover_dag_files(root) { @@ -119,7 +119,9 @@ mod compiler_tests { if let Some((existing, _)) = index.get(&module_path) { panic!( "duplicate module path '{}': declared in both {} and {}", - module_path, existing, path + module_path, + existing, + path ); } index.insert(module_path, (path, content)); @@ -133,8 +135,7 @@ mod compiler_tests { roots: &[&str], ) -> Vec> { let index = build_source_index(roots); - let mut seen = - HashMap::>::new(); + let mut seen = HashMap::>::new(); let mut queue = Vec::new(); for (path, content) in entry_pairs { @@ -214,10 +215,7 @@ mod compiler_tests { #[test] fn tokenize_produces_tokens() { - let tokens = tokenize( - &"fn foo() -> Int { 42 }".to_string(), - "test.dag".to_string(), - ); + let tokens = tokenize(&"fn foo() -> Int { 42 }".to_string(), "test.dag".to_string()); assert!( !tokens.is_empty(), "tokenize should produce at least one token" @@ -269,10 +267,7 @@ mod compiler_tests { &"module test\ntype Foo { x: Int }\n".to_string(), "test.dag".to_string(), ); - let result = crate::v2_compiler_parse::parse( - tokens, - std::rc::Rc::new(std::collections::HashMap::new()), - ); + let result = crate::v2_compiler_parse::parse(tokens, std::rc::Rc::new(std::collections::HashMap::new())); assert!( result.module.is_some(), "valid module should parse successfully" @@ -299,10 +294,7 @@ mod compiler_tests { last.shape ); - let result = crate::v2_compiler_parse::parse( - tokens, - std::rc::Rc::new(std::collections::HashMap::new()), - ); + let result = crate::v2_compiler_parse::parse(tokens, std::rc::Rc::new(std::collections::HashMap::new())); assert!( result.module.is_some(), @@ -379,10 +371,7 @@ mod compiler_tests { "{} should end with Eof", file ); - let result = crate::v2_compiler_parse::parse( - tokens, - std::rc::Rc::new(std::collections::HashMap::new()), - ); + let result = crate::v2_compiler_parse::parse(tokens, std::rc::Rc::new(std::collections::HashMap::new())); assert!( result.module.is_some(), "{} should parse successfully, error: {:?}", @@ -653,201 +642,81 @@ mod compiler_tests { #[test] fn coercion_rust_checkpoint_resolves_primitives() { use crate::v2_compiler_coercion::*; - assert_eq!( - coerce_primitive_type(RenderTarget::Rust, "Int".into()), - "i64" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Rust, "Float".into()), - "f64" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Rust, "Bool".into()), - "bool" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Rust, "Unit".into()), - "()" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Rust, "String".into()), - "String" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Rust, "Bytes".into()), - "Vec" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Rust, "Secret".into()), - "String" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Rust, "Json".into()), - "serde_json::Value" - ); + assert_eq!(coerce_primitive_type(RenderTarget::Rust, "Int".into()), "i64"); + assert_eq!(coerce_primitive_type(RenderTarget::Rust, "Float".into()), "f64"); + assert_eq!(coerce_primitive_type(RenderTarget::Rust, "Bool".into()), "bool"); + assert_eq!(coerce_primitive_type(RenderTarget::Rust, "Unit".into()), "()"); + assert_eq!(coerce_primitive_type(RenderTarget::Rust, "String".into()), "String"); + assert_eq!(coerce_primitive_type(RenderTarget::Rust, "Bytes".into()), "Vec"); + assert_eq!(coerce_primitive_type(RenderTarget::Rust, "Secret".into()), "String"); + assert_eq!(coerce_primitive_type(RenderTarget::Rust, "Json".into()), "serde_json::Value"); } + #[test] fn coercion_python_checkpoint_resolves_primitives() { use crate::v2_compiler_coercion::*; - assert_eq!( - coerce_primitive_type(RenderTarget::Python, "Int".into()), - "int" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Python, "Float".into()), - "float" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Python, "Bool".into()), - "bool" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Python, "Unit".into()), - "None" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Python, "String".into()), - "str" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Python, "Bytes".into()), - "bytes" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Python, "Secret".into()), - "str" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Python, "Json".into()), - "dict" - ); + assert_eq!(coerce_primitive_type(RenderTarget::Python, "Int".into()), "int"); + assert_eq!(coerce_primitive_type(RenderTarget::Python, "Float".into()), "float"); + assert_eq!(coerce_primitive_type(RenderTarget::Python, "Bool".into()), "bool"); + assert_eq!(coerce_primitive_type(RenderTarget::Python, "Unit".into()), "None"); + assert_eq!(coerce_primitive_type(RenderTarget::Python, "String".into()), "str"); + assert_eq!(coerce_primitive_type(RenderTarget::Python, "Bytes".into()), "bytes"); + assert_eq!(coerce_primitive_type(RenderTarget::Python, "Secret".into()), "str"); + assert_eq!(coerce_primitive_type(RenderTarget::Python, "Json".into()), "dict"); } + #[test] fn coercion_go_checkpoint_resolves_primitives() { use crate::v2_compiler_coercion::*; - assert_eq!( - coerce_primitive_type(RenderTarget::Go, "Int".into()), - "int64" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Go, "Float".into()), - "float64" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Go, "Bool".into()), - "bool" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Go, "Unit".into()), - "struct{}" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Go, "String".into()), - "string" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Go, "Bytes".into()), - "[]byte" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Go, "Secret".into()), - "string" - ); - assert_eq!( - coerce_primitive_type(RenderTarget::Go, "Json".into()), - "interface{}" - ); + assert_eq!(coerce_primitive_type(RenderTarget::Go, "Int".into()), "int64"); + assert_eq!(coerce_primitive_type(RenderTarget::Go, "Float".into()), "float64"); + assert_eq!(coerce_primitive_type(RenderTarget::Go, "Bool".into()), "bool"); + assert_eq!(coerce_primitive_type(RenderTarget::Go, "Unit".into()), "struct{}"); + assert_eq!(coerce_primitive_type(RenderTarget::Go, "String".into()), "string"); + assert_eq!(coerce_primitive_type(RenderTarget::Go, "Bytes".into()), "[]byte"); + assert_eq!(coerce_primitive_type(RenderTarget::Go, "Secret".into()), "string"); + assert_eq!(coerce_primitive_type(RenderTarget::Go, "Json".into()), "interface{}"); } + #[test] fn coercion_rust_inhabitant_resolves_containers() { use crate::v2_compiler_coercion::*; - assert_eq!( - coerce_container_template(RenderTarget::Rust, "BooleanAlgebra".into()), - Some("std::collections::BTreeSet<{0}>".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Rust, "FreeMonoid".into()), - Some("Vec<{0}>".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Rust, "List".into()), - Some("Vec<{0}>".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Rust, "Map".into()), - Some("HashMap<{0}, {1}>".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Rust, "PartialFunction".into()), - Some("HashMap<{0}, {1}>".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Rust, "Set".into()), - Some("std::collections::BTreeSet<{0}>".to_string()) - ); + assert_eq!(coerce_container_template(RenderTarget::Rust, "BooleanAlgebra".into()), Some("std::collections::BTreeSet<{0}>".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Rust, "FreeMonoid".into()), Some("Vec<{0}>".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Rust, "List".into()), Some("Vec<{0}>".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Rust, "Map".into()), Some("HashMap<{0}, {1}>".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Rust, "PartialFunction".into()), Some("HashMap<{0}, {1}>".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Rust, "Set".into()), Some("std::collections::BTreeSet<{0}>".to_string())); } + #[test] fn coercion_python_inhabitant_resolves_containers() { use crate::v2_compiler_coercion::*; - assert_eq!( - coerce_container_template(RenderTarget::Python, "BooleanAlgebra".into()), - Some("set[{0}]".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Python, "FreeMonoid".into()), - Some("list[{0}]".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Python, "List".into()), - Some("list[{0}]".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Python, "Map".into()), - Some("dict[{0}, {1}]".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Python, "PartialFunction".into()), - Some("dict[{0}, {1}]".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Python, "Set".into()), - Some("set[{0}]".to_string()) - ); + assert_eq!(coerce_container_template(RenderTarget::Python, "BooleanAlgebra".into()), Some("set[{0}]".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Python, "FreeMonoid".into()), Some("list[{0}]".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Python, "List".into()), Some("list[{0}]".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Python, "Map".into()), Some("dict[{0}, {1}]".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Python, "PartialFunction".into()), Some("dict[{0}, {1}]".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Python, "Set".into()), Some("set[{0}]".to_string())); } + #[test] fn coercion_go_inhabitant_resolves_containers() { use crate::v2_compiler_coercion::*; - assert_eq!( - coerce_container_template(RenderTarget::Go, "BooleanAlgebra".into()), - Some("map[{0}]struct{}".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Go, "FreeMonoid".into()), - Some("[]{0}".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Go, "List".into()), - Some("[]{0}".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Go, "Map".into()), - Some("map[{0}]{1}".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Go, "PartialFunction".into()), - Some("map[{0}]{1}".to_string()) - ); - assert_eq!( - coerce_container_template(RenderTarget::Go, "Set".into()), - Some("map[{0}]struct{}".to_string()) - ); + assert_eq!(coerce_container_template(RenderTarget::Go, "BooleanAlgebra".into()), Some("map[{0}]struct{}".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Go, "FreeMonoid".into()), Some("[]{0}".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Go, "List".into()), Some("[]{0}".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Go, "Map".into()), Some("map[{0}]{1}".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Go, "PartialFunction".into()), Some("map[{0}]{1}".to_string())); + assert_eq!(coerce_container_template(RenderTarget::Go, "Set".into()), Some("map[{0}]struct{}".to_string())); } + #[test] fn coercion_is_copy_from_checkpoint() { use crate::v2_compiler_coercion::*; @@ -861,45 +730,19 @@ mod compiler_tests { assert_eq!(is_copy(RenderTarget::Rust, "Json".into()), Some(false)); } + #[test] fn coercion_template_application() { use crate::v2_compiler_coercion::*; - assert_eq!( - apply_inhabitant_template1("Vec<{0}>".into(), "i64".into()), - "Vec" - ); - assert_eq!( - apply_inhabitant_template1("std::collections::BTreeSet<{0}>".into(), "i64".into()), - "std::collections::BTreeSet" - ); - assert_eq!( - apply_inhabitant_template2("HashMap<{0}, {1}>".into(), "String".into(), "i64".into()), - "HashMap" - ); - assert_eq!( - apply_inhabitant_template1("list[{0}]".into(), "int".into()), - "list[int]" - ); - assert_eq!( - apply_inhabitant_template1("set[{0}]".into(), "int".into()), - "set[int]" - ); - assert_eq!( - apply_inhabitant_template2("dict[{0}, {1}]".into(), "str".into(), "int".into()), - "dict[str, int]" - ); - assert_eq!( - apply_inhabitant_template1("[]{0}".into(), "int64".into()), - "[]int64" - ); - assert_eq!( - apply_inhabitant_template1("map[{0}]struct{}".into(), "int64".into()), - "map[int64]struct{}" - ); - assert_eq!( - apply_inhabitant_template2("map[{0}]{1}".into(), "string".into(), "int64".into()), - "map[string]int64" - ); + assert_eq!(apply_inhabitant_template1("Vec<{0}>".into(), "i64".into()), "Vec"); + assert_eq!(apply_inhabitant_template1("std::collections::BTreeSet<{0}>".into(), "i64".into()), "std::collections::BTreeSet"); + assert_eq!(apply_inhabitant_template2("HashMap<{0}, {1}>".into(), "String".into(), "i64".into()), "HashMap"); + assert_eq!(apply_inhabitant_template1("list[{0}]".into(), "int".into()), "list[int]"); + assert_eq!(apply_inhabitant_template1("set[{0}]".into(), "int".into()), "set[int]"); + assert_eq!(apply_inhabitant_template2("dict[{0}, {1}]".into(), "str".into(), "int".into()), "dict[str, int]"); + assert_eq!(apply_inhabitant_template1("[]{0}".into(), "int64".into()), "[]int64"); + assert_eq!(apply_inhabitant_template1("map[{0}]struct{}".into(), "int64".into()), "map[int64]struct{}"); + assert_eq!(apply_inhabitant_template2("map[{0}]{1}".into(), "string".into(), "int64".into()), "map[string]int64"); } /// Return current process RSS in bytes (macOS via mach_task_basic_info). @@ -1012,10 +855,7 @@ mod compiler_tests { let parsed = crate::v2_compiler_parse::parse_with_table( tokens, crate::v2_rt::rc_map_insert( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), + crate::v2_rt::rc_empty_map::>(), si.file.clone(), si.clone(), ), @@ -1029,9 +869,7 @@ mod compiler_tests { " parse {:>40}: {:>8.2?} (ok={})", sources[i].path, elapsed, ok ); - let m = result - .module - .clone() + let m = result.module.clone() .unwrap_or_else(|| panic!("parse failed for source {}", sources[i].path)); modules.push(m); } @@ -1040,25 +878,10 @@ mod compiler_tests { let t_stage = Instant::now(); let resolve_si = sources.iter().fold( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), - |acc, s| { - crate::v2_rt::rc_map_insert( - acc, - s.path.clone(), - crate::v2_std_core::build_newline_index( - s.path.clone(), - &s.content.clone(), - ), - ) - }, - ); - let graph = crate::v2_compiler_resolve::resolve_modules( - &std::rc::Rc::new(modules), - &resolve_si, + crate::v2_rt::rc_empty_map::>(), + |acc, s| crate::v2_rt::rc_map_insert(acc, s.path.clone(), crate::v2_std_core::build_newline_index(s.path.clone(), &s.content.clone())), ); + let graph = crate::v2_compiler_resolve::resolve_modules(&std::rc::Rc::new(modules), &resolve_si); let resolve_total = t_stage.elapsed(); let errors: Vec<_> = graph .diagnostics @@ -1145,10 +968,7 @@ mod compiler_tests { let parsed = crate::v2_compiler_parse::parse_with_table( tokens, crate::v2_rt::rc_map_insert( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), + crate::v2_rt::rc_empty_map::>(), si.file.clone(), si.clone(), ), @@ -1165,9 +985,7 @@ mod compiler_tests { " parse {:>40}: {:>8.2?} (ok={})", sources[i].path, elapsed, ok ); - let m = result - .module - .clone() + let m = result.module.clone() .unwrap_or_else(|| panic!("parse failed for source {}", sources[i].path)); modules.push(m); } @@ -1182,25 +1000,10 @@ mod compiler_tests { let t_stage = Instant::now(); let resolve_si = sources.iter().fold( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), - |acc, s| { - crate::v2_rt::rc_map_insert( - acc, - s.path.clone(), - crate::v2_std_core::build_newline_index( - s.path.clone(), - &s.content.clone(), - ), - ) - }, - ); - let graph = crate::v2_compiler_resolve::resolve_modules( - &std::rc::Rc::new(modules), - &resolve_si, + crate::v2_rt::rc_empty_map::>(), + |acc, s| crate::v2_rt::rc_map_insert(acc, s.path.clone(), crate::v2_std_core::build_newline_index(s.path.clone(), &s.content.clone())), ); + let graph = crate::v2_compiler_resolve::resolve_modules(&std::rc::Rc::new(modules), &resolve_si); let resolve_total = t_stage.elapsed(); let phase3_diags: usize = graph .diagnostics @@ -1229,11 +1032,7 @@ mod compiler_tests { acc }, ); - let typed = crate::v2_compiler_infer::reconcile( - graph, - std::rc::Rc::new(source_indices), - intern_table_p.clone(), - ); + let typed = crate::v2_compiler_infer::reconcile(graph, std::rc::Rc::new(source_indices), intern_table_p.clone()); let reconcile_total = t_stage.elapsed(); let phase4_diags: usize = typed .diagnostics @@ -1309,18 +1108,14 @@ mod compiler_tests { let source_count = sources.len(); let total_chars: usize = sources.iter().map(|s| s.content.len()).sum(); - eprintln!( - "\n=== FULL PIPELINE PROFILE ({} sources, {} chars) ===\n", - source_count, total_chars - ); + eprintln!("\n=== FULL PIPELINE PROFILE ({} sources, {} chars) ===\n", source_count, total_chars); // 1a. Tokenize + parse let t = Instant::now(); let mut token_lists = Vec::new(); for source in &sources { let tokens = crate::v2_compiler_tokenize::tokenize( - &source.content.clone(), - source.path.clone(), + &source.content.clone(), source.path.clone(), ); token_lists.push(tokens); } @@ -1337,10 +1132,7 @@ mod compiler_tests { let parsed = crate::v2_compiler_parse::parse_with_table( tokens, crate::v2_rt::rc_map_insert( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), + crate::v2_rt::rc_empty_map::>(), si.file.clone(), si.clone(), ), @@ -1348,9 +1140,7 @@ mod compiler_tests { ); let result = parsed.result.clone(); intern_table_fp = parsed.intern_table.clone(); - let m = result - .module - .clone() + let m = result.module.clone() .unwrap_or_else(|| panic!("parse failed for source {}", sources[i].path)); modules.push(m); } @@ -1358,200 +1148,91 @@ mod compiler_tests { // 1b. Resolve let t = Instant::now(); let resolve_si = sources.iter().fold( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), - |acc, s| { - crate::v2_rt::rc_map_insert( - acc, - s.path.clone(), - crate::v2_std_core::build_newline_index( - s.path.clone(), - &s.content.clone(), - ), - ) - }, - ); - let graph = crate::v2_compiler_resolve::resolve_modules( - &std::rc::Rc::new(modules), - &resolve_si, + crate::v2_rt::rc_empty_map::>(), + |acc, s| crate::v2_rt::rc_map_insert(acc, s.path.clone(), crate::v2_std_core::build_newline_index(s.path.clone(), &s.content.clone())), ); + let graph = crate::v2_compiler_resolve::resolve_modules(&std::rc::Rc::new(modules), &resolve_si); let resolve_elapsed = t.elapsed(); - let resolve_errors: usize = graph - .diagnostics - .iter() + let resolve_errors: usize = graph.diagnostics.iter() .filter(|d| crate::v2_std_core::is_error_diagnostic(d.diagnostic.clone())) .count(); // 1c. Newline indices let t = Instant::now(); - let newline_indices: Vec<_> = sources - .iter() - .map(|s| { - crate::v2_std_core::build_newline_index(s.path.clone(), &s.content.clone()) - }) - .collect(); + let newline_indices: Vec<_> = sources.iter().map(|s| { + crate::v2_std_core::build_newline_index(s.path.clone(), &s.content.clone()) + }).collect(); let newline_elapsed = t.elapsed(); - let frontend_elapsed = - tokenize_elapsed + parse_elapsed + resolve_elapsed + newline_elapsed; + let frontend_elapsed = tokenize_elapsed + parse_elapsed + resolve_elapsed + newline_elapsed; eprintln!(" Tokenize: {:>8.2?}", tokenize_elapsed); eprintln!(" Parse: {:>8.2?}", parse_elapsed); - eprintln!( - " Resolve: {:>8.2?} ({} resolve errors)", - resolve_elapsed, resolve_errors - ); + eprintln!(" Resolve: {:>8.2?} ({} resolve errors)", resolve_elapsed, resolve_errors); eprintln!(" Newline indices: {:>8.2?}", newline_elapsed); eprintln!(" Frontend total: {:>8.2?}", frontend_elapsed); // 2. Normalize let t = Instant::now(); let source_indices = newline_indices.iter().cloned().fold( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), - |acc, index| { - crate::v2_rt::rc_map_insert(acc, index.file.clone(), index.clone()) - }, + crate::v2_rt::rc_empty_map::>(), + |acc, index| crate::v2_rt::rc_map_insert(acc, index.file.clone(), index.clone()), ); - let norm = - crate::v2_compiler_normalize::normalize_graph(&graph, source_indices.clone()); + let norm = crate::v2_compiler_normalize::normalize_graph(&graph, source_indices.clone()); let normalize_elapsed = t.elapsed(); - eprintln!( - " Normalize: {:>8.2?}", - normalize_elapsed - ); + eprintln!(" Normalize: {:>8.2?}", normalize_elapsed); // 3. Reconcile let t = Instant::now(); - let typed = crate::v2_compiler_infer::reconcile( - norm.graph.clone(), - source_indices.clone(), - intern_table_fp.clone(), - ); + let typed = crate::v2_compiler_infer::reconcile(norm.graph.clone(), source_indices.clone(), intern_table_fp.clone()); let reconcile_elapsed = t.elapsed(); - let type_errors: usize = typed - .diagnostics - .iter() + let type_errors: usize = typed.diagnostics.iter() .filter(|d| crate::v2_std_core::is_error_diagnostic(d.diagnostic.clone())) .count(); - eprintln!( - " Reconcile: {:>8.2?} ({} type errors)", - reconcile_elapsed, type_errors - ); + eprintln!(" Reconcile: {:>8.2?} ({} type errors)", reconcile_elapsed, type_errors); // 4. Complexity let t = Instant::now(); let func_entries = crate::v2_compiler_compile::extract_func_entries(typed.clone()); let func_count = func_entries.len(); - let recursion_ctx = - crate::v2_compiler_compile::build_recursion_context(typed.clone()); + let recursion_ctx = crate::v2_compiler_compile::build_recursion_context(typed.clone()); let complexity = crate::v2_compiler_complexity::build_complexity_report( - &func_entries, - recursion_ctx, - source_indices.clone(), + &func_entries, recursion_ctx, source_indices.clone(), ); let complexity_elapsed = t.elapsed(); - let cx_diags = - crate::v2_compiler_compile::complexity_diagnostics(complexity.clone()); - eprintln!( - " Complexity: {:>8.2?} ({} funcs, {} diagnostics)", - complexity_elapsed, - func_count, - cx_diags.len() - ); + let cx_diags = crate::v2_compiler_compile::complexity_diagnostics(complexity.clone()); + eprintln!(" Complexity: {:>8.2?} ({} funcs, {} diagnostics)", complexity_elapsed, func_count, cx_diags.len()); // 5. Ownership let t = Instant::now(); let ownership = crate::v2_compiler_compile::extract_ownership_proofs(typed.clone()); let ownership_elapsed = t.elapsed(); - let own_diags = - crate::v2_compiler_compile::ownership_diagnostics(ownership.clone()); - eprintln!( - " Ownership: {:>8.2?} ({} proofs, {} diagnostics)", - ownership_elapsed, - ownership.len(), - own_diags.len() - ); + let own_diags = crate::v2_compiler_compile::ownership_diagnostics(ownership.clone()); + eprintln!(" Ownership: {:>8.2?} ({} proofs, {} diagnostics)", ownership_elapsed, ownership.len(), own_diags.len()); // 6. Emit let artifact_plan = crate::v2_compiler_compile::default_artifact_plan( - std::rc::Rc::new( - typed - .modules - .iter() - .map(|m| m.module.clone().name.clone()) - .collect(), - ), + std::rc::Rc::new(typed.modules.iter().map(|m| m.module.clone().name.clone()).collect()), crate::v2_compiler_artifact::RenderTarget::Rust, ); let t = Instant::now(); - let emit_result = crate::v2_compiler_compile::emit_from_artifact_plan( - typed.clone(), - &artifact_plan, - ); + let emit_result = crate::v2_compiler_compile::emit_from_artifact_plan(typed.clone(), &artifact_plan); let emit_elapsed = t.elapsed(); let emitted_files = emit_result.files.len(); let emitted_bytes: usize = emit_result.files.iter().map(|f| f.content.len()).sum(); - eprintln!( - " Emit: {:>8.2?} ({} files, {} bytes)", - emit_elapsed, emitted_files, emitted_bytes - ); + eprintln!(" Emit: {:>8.2?} ({} files, {} bytes)", emit_elapsed, emitted_files, emitted_bytes); - let total = frontend_elapsed - + normalize_elapsed - + reconcile_elapsed - + complexity_elapsed - + ownership_elapsed - + emit_elapsed; + let total = frontend_elapsed + normalize_elapsed + reconcile_elapsed + + complexity_elapsed + ownership_elapsed + emit_elapsed; eprintln!("\n=== SUMMARY ==="); - eprintln!( - " Tokenize: {:>8.2?} ({:.0}%)", - tokenize_elapsed, - tokenize_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); - eprintln!( - " Parse: {:>8.2?} ({:.0}%)", - parse_elapsed, - parse_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); - eprintln!( - " Resolve: {:>8.2?} ({:.0}%)", - resolve_elapsed, - resolve_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); - eprintln!( - " Newline: {:>8.2?} ({:.0}%)", - newline_elapsed, - newline_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); - eprintln!( - " Normalize: {:>8.2?} ({:.0}%)", - normalize_elapsed, - normalize_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); - eprintln!( - " Reconcile: {:>8.2?} ({:.0}%)", - reconcile_elapsed, - reconcile_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); - eprintln!( - " Complexity: {:>8.2?} ({:.0}%)", - complexity_elapsed, - complexity_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); - eprintln!( - " Ownership: {:>8.2?} ({:.0}%)", - ownership_elapsed, - ownership_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); - eprintln!( - " Emit: {:>8.2?} ({:.0}%)", - emit_elapsed, - emit_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0 - ); + eprintln!(" Tokenize: {:>8.2?} ({:.0}%)", tokenize_elapsed, tokenize_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); + eprintln!(" Parse: {:>8.2?} ({:.0}%)", parse_elapsed, parse_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); + eprintln!(" Resolve: {:>8.2?} ({:.0}%)", resolve_elapsed, resolve_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); + eprintln!(" Newline: {:>8.2?} ({:.0}%)", newline_elapsed, newline_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); + eprintln!(" Normalize: {:>8.2?} ({:.0}%)", normalize_elapsed, normalize_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); + eprintln!(" Reconcile: {:>8.2?} ({:.0}%)", reconcile_elapsed, reconcile_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); + eprintln!(" Complexity: {:>8.2?} ({:.0}%)", complexity_elapsed, complexity_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); + eprintln!(" Ownership: {:>8.2?} ({:.0}%)", ownership_elapsed, ownership_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); + eprintln!(" Emit: {:>8.2?} ({:.0}%)", emit_elapsed, emit_elapsed.as_secs_f64() / total.as_secs_f64() * 100.0); eprintln!(" TOTAL: {:>8.2?}", total); }) .expect("failed to spawn thread") @@ -1590,10 +1271,7 @@ mod compiler_tests { let parsed = crate::v2_compiler_parse::parse_with_table( &tokens, crate::v2_rt::rc_map_insert( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), + crate::v2_rt::rc_empty_map::>(), si.file.clone(), si.clone(), ), @@ -1601,32 +1279,15 @@ mod compiler_tests { ); let result = parsed.result.clone(); intern_table = parsed.intern_table.clone(); - let m = result - .module - .clone() + let m = result.module.clone() .unwrap_or_else(|| panic!("parse failed for source {}", source.path)); modules.push(m); } let resolve_si = sources.iter().fold( - crate::v2_rt::rc_empty_map::< - String, - std::rc::Rc, - >(), - |acc, s| { - crate::v2_rt::rc_map_insert( - acc, - s.path.clone(), - crate::v2_std_core::build_newline_index( - s.path.clone(), - &s.content.clone(), - ), - ) - }, - ); - let graph = crate::v2_compiler_resolve::resolve_modules( - &std::rc::Rc::new(modules), - &resolve_si, + crate::v2_rt::rc_empty_map::>(), + |acc, s| crate::v2_rt::rc_map_insert(acc, s.path.clone(), crate::v2_std_core::build_newline_index(s.path.clone(), &s.content.clone())), ); + let graph = crate::v2_compiler_resolve::resolve_modules(&std::rc::Rc::new(modules), &resolve_si); let setup_time = t0.elapsed(); let rss_baseline = get_rss_bytes(); eprintln!( @@ -1777,4 +1438,5 @@ mod compiler_tests { .join(); result.expect("profile_reconcile_per_module panicked"); } + } diff --git a/src/v2/stage0/src/extdeps_languages_dag_emit.rs b/src/v2/stage0/src/extdeps_languages_dag_emit.rs index 557109d0c3b..1e1559de24c 100644 --- a/src/v2/stage0/src/extdeps_languages_dag_emit.rs +++ b/src/v2/stage0/src/extdeps_languages_dag_emit.rs @@ -1,11 +1,11 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.dag.emit -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; pub fn dag_keywords() -> Rc> { thread_local! { diff --git a/src/v2/stage0/src/extdeps_languages_dag_syntax.rs b/src/v2/stage0/src/extdeps_languages_dag_syntax.rs index e467f1c693d..75f3f1b3c54 100644 --- a/src/v2/stage0/src/extdeps_languages_dag_syntax.rs +++ b/src/v2/stage0/src/extdeps_languages_dag_syntax.rs @@ -1,121 +1,113 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.dag.syntax -use crate::std_syntax::BinOp::{ - Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, NullCoalesce, Or, Sub, -}; -use crate::std_syntax::BodyKind::{ - BlockBody, ExprBody, NoBody, ResourceBody, ServiceBody, TypeBody, ValueBody, -}; -use crate::std_syntax::ItemFormKind::{ - EnumForm, FuncForm, ModuleForm, OtherForm, StructForm, TypeAliasForm, -}; -use crate::std_syntax::LiteralValue::{LitBool, LitNull}; -pub use crate::std_syntax::{ - BinOp, BodyKind, ItemForm, ItemFormKind, LiteralValue, OperatorSpec, SyntaxSpec, -}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_syntax::{ItemForm, ItemFormKind, BodyKind, OperatorSpec, SyntaxSpec, BinOp, LiteralValue}; +use crate::std_syntax::ItemFormKind::{FuncForm, StructForm, EnumForm, TypeAliasForm, ModuleForm, OtherForm}; +use crate::std_syntax::BodyKind::{ExprBody, BlockBody, TypeBody, ValueBody, NoBody, ResourceBody, ServiceBody}; +use crate::std_syntax::BinOp::{Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Gt, Le, Ge, And, Or, NullCoalesce}; +use crate::std_syntax::LiteralValue::{LitBool, LitNull}; pub fn dag_item_forms() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(ItemForm { - kind: ItemFormKind::TypeAliasForm, - keyword: "type".to_string(), - has_type_params: true, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::TypeBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::FuncForm, - keyword: "fn".to_string(), - has_type_params: true, - has_params: true, - has_return_type: true, - return_required: true, - has_uses: false, - body_kind: BodyKind::ExprBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::FuncForm, - keyword: "func".to_string(), - has_type_params: false, - has_params: true, - has_return_type: true, - return_required: false, - has_uses: true, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "resource".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::ResourceBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "service".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::ServiceBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "data".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::ValueBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "pattern".to_string(), - has_type_params: false, - has_params: true, - has_return_type: true, - return_required: false, - has_uses: true, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "interface".to_string(), - has_type_params: false, - has_params: true, - has_return_type: true, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(ItemForm { + kind: ItemFormKind::TypeAliasForm, + keyword: "type".to_string(), + has_type_params: true, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::TypeBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::FuncForm, + keyword: "fn".to_string(), + has_type_params: true, + has_params: true, + has_return_type: true, + return_required: true, + has_uses: false, + body_kind: BodyKind::ExprBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::FuncForm, + keyword: "func".to_string(), + has_type_params: false, + has_params: true, + has_return_type: true, + return_required: false, + has_uses: true, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "resource".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::ResourceBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "service".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::ServiceBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "data".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::ValueBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "pattern".to_string(), + has_type_params: false, + has_params: true, + has_return_type: true, + return_required: false, + has_uses: true, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "interface".to_string(), + has_type_params: false, + has_params: true, + has_return_type: true, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +})]) + }; + } CACHED.with(|c| c.clone()) } pub fn dag_keyword_literals() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - let mut __m = HashMap::new(); - __m.insert("true".to_string(), Rc::new(LiteralValue::LitBool { - value: true, - })); - __m.insert("false".to_string(), Rc::new(LiteralValue::LitBool { - value: false, - })); - __m.insert("none".to_string(), Rc::new(LiteralValue::LitNull)); - __m.insert("null".to_string(), Rc::new(LiteralValue::LitNull)); - Rc::new(__m) - }; - } + static CACHED: Rc>> = { + let mut __m = HashMap::new(); + __m.insert("true".to_string(), Rc::new(LiteralValue::LitBool { + value: true, +})); + __m.insert("false".to_string(), Rc::new(LiteralValue::LitBool { + value: false, +})); + __m.insert("none".to_string(), Rc::new(LiteralValue::LitNull)); + __m.insert("null".to_string(), Rc::new(LiteralValue::LitNull)); + Rc::new(__m) + }; + } CACHED.with(|c| c.clone()) } @@ -182,106 +174,106 @@ pub fn dag_non_name_keywords() -> Rc> { pub fn dag_operators() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(OperatorSpec { - symbol: "||".to_string(), - left_bp: 5, - right_bp: 6, - binop: Some(BinOp::Or), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "&&".to_string(), - left_bp: 7, - right_bp: 8, - binop: Some(BinOp::And), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "??".to_string(), - left_bp: 8, - right_bp: 9, - binop: Some(BinOp::NullCoalesce), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "==".to_string(), - left_bp: 9, - right_bp: 10, - binop: Some(BinOp::Eq), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "!=".to_string(), - left_bp: 9, - right_bp: 10, - binop: Some(BinOp::Ne), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "<".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Lt), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ">".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Gt), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "<=".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Le), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ">=".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Ge), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "+".to_string(), - left_bp: 13, - right_bp: 14, - binop: Some(BinOp::Add), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "-".to_string(), - left_bp: 13, - right_bp: 14, - binop: Some(BinOp::Sub), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "*".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Mul), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "/".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Div), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "%".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Mod), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "|>".to_string(), - left_bp: 17, - right_bp: 18, - binop: None, - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ".".to_string(), - left_bp: 19, - right_bp: 20, - binop: None, - algebra_field: None, - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(OperatorSpec { + symbol: "||".to_string(), + left_bp: 5, + right_bp: 6, + binop: Some(BinOp::Or), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "&&".to_string(), + left_bp: 7, + right_bp: 8, + binop: Some(BinOp::And), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "??".to_string(), + left_bp: 8, + right_bp: 9, + binop: Some(BinOp::NullCoalesce), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "==".to_string(), + left_bp: 9, + right_bp: 10, + binop: Some(BinOp::Eq), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "!=".to_string(), + left_bp: 9, + right_bp: 10, + binop: Some(BinOp::Ne), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "<".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Lt), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ">".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Gt), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "<=".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Le), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ">=".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Ge), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "+".to_string(), + left_bp: 13, + right_bp: 14, + binop: Some(BinOp::Add), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "-".to_string(), + left_bp: 13, + right_bp: 14, + binop: Some(BinOp::Sub), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "*".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Mul), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "/".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Div), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "%".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Mod), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "|>".to_string(), + left_bp: 17, + right_bp: 18, + binop: None, + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ".".to_string(), + left_bp: 19, + right_bp: 20, + binop: None, + algebra_field: None, +})]) + }; + } CACHED.with(|c| c.clone()) } @@ -311,14 +303,14 @@ pub fn v3_supported_dag_operators() -> Rc> { pub fn dag_syntax_spec() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(SyntaxSpec { - item_forms: dag_item_forms(), - operators: dag_operators(), - keyword_literals: dag_keyword_literals(), - keyword_set: dag_keyword_set(), - }) - }; - } + static CACHED: Rc = { + Rc::new(SyntaxSpec { + item_forms: dag_item_forms(), + operators: dag_operators(), + keyword_literals: dag_keyword_literals(), + keyword_set: dag_keyword_set(), +}) + }; + } CACHED.with(|c| c.clone()) } diff --git a/src/v2/stage0/src/extdeps_languages_dag_types.rs b/src/v2/stage0/src/extdeps_languages_dag_types.rs index 747e7726ac8..c95c45171d0 100644 --- a/src/v2/stage0/src/extdeps_languages_dag_types.rs +++ b/src/v2/stage0/src/extdeps_languages_dag_types.rs @@ -1,12 +1,12 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.dag.types -pub use crate::std_coercion::TypeCheckpoint; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_coercion::{TypeCheckpoint}; pub fn dag_type_checkpoints() -> Rc>> { thread_local! { diff --git a/src/v2/stage0/src/extdeps_languages_go_emit.rs b/src/v2/stage0/src/extdeps_languages_go_emit.rs index c6ad3e3c756..a6ddd844b04 100644 --- a/src/v2/stage0/src/extdeps_languages_go_emit.rs +++ b/src/v2/stage0/src/extdeps_languages_go_emit.rs @@ -1,11 +1,11 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.go.emit -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; pub fn go_keywords() -> Rc> { thread_local! { diff --git a/src/v2/stage0/src/extdeps_languages_go_syntax.rs b/src/v2/stage0/src/extdeps_languages_go_syntax.rs index a488a4b3987..ea0c113871a 100644 --- a/src/v2/stage0/src/extdeps_languages_go_syntax.rs +++ b/src/v2/stage0/src/extdeps_languages_go_syntax.rs @@ -1,157 +1,153 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.go.syntax -use crate::std_syntax::BinOp::{ - Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, NullCoalesce, Or, Sub, -}; -use crate::std_syntax::BodyKind::{BlockBody, NoBody, TypeBody}; -use crate::std_syntax::ItemFormKind::{ - EnumForm, FuncForm, ModuleForm, OtherForm, StructForm, TypeAliasForm, -}; -pub use crate::std_syntax::{BinOp, BodyKind, ItemForm, ItemFormKind, OperatorSpec}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_syntax::{ItemForm, ItemFormKind, BodyKind, OperatorSpec, BinOp}; +use crate::std_syntax::ItemFormKind::{FuncForm, StructForm, EnumForm, TypeAliasForm, ModuleForm, OtherForm}; +use crate::std_syntax::BodyKind::{BlockBody, TypeBody, NoBody}; +use crate::std_syntax::BinOp::{Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Gt, Le, Ge, And, Or, NullCoalesce}; pub fn go_item_forms() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(ItemForm { - kind: ItemFormKind::FuncForm, - keyword: "func".to_string(), - has_type_params: false, - has_params: true, - has_return_type: true, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::StructForm, - keyword: "struct".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::TypeBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::EnumForm, - keyword: "type".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::NoBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::TypeAliasForm, - keyword: "type".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::NoBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::ModuleForm, - keyword: "package".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::NoBody, - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(ItemForm { + kind: ItemFormKind::FuncForm, + keyword: "func".to_string(), + has_type_params: false, + has_params: true, + has_return_type: true, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::StructForm, + keyword: "struct".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::TypeBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::EnumForm, + keyword: "type".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::NoBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::TypeAliasForm, + keyword: "type".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::NoBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::ModuleForm, + keyword: "package".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::NoBody, +})]) + }; + } CACHED.with(|c| c.clone()) } pub fn go_operators() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(OperatorSpec { - symbol: "||".to_string(), - left_bp: 5, - right_bp: 6, - binop: Some(BinOp::Or), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "&&".to_string(), - left_bp: 7, - right_bp: 8, - binop: Some(BinOp::And), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "==".to_string(), - left_bp: 9, - right_bp: 10, - binop: Some(BinOp::Eq), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "!=".to_string(), - left_bp: 9, - right_bp: 10, - binop: Some(BinOp::Ne), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "<".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Lt), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ">".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Gt), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "<=".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Le), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ">=".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Ge), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "+".to_string(), - left_bp: 13, - right_bp: 14, - binop: Some(BinOp::Add), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "-".to_string(), - left_bp: 13, - right_bp: 14, - binop: Some(BinOp::Sub), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "*".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Mul), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "/".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Div), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "%".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Mod), - algebra_field: None, - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(OperatorSpec { + symbol: "||".to_string(), + left_bp: 5, + right_bp: 6, + binop: Some(BinOp::Or), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "&&".to_string(), + left_bp: 7, + right_bp: 8, + binop: Some(BinOp::And), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "==".to_string(), + left_bp: 9, + right_bp: 10, + binop: Some(BinOp::Eq), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "!=".to_string(), + left_bp: 9, + right_bp: 10, + binop: Some(BinOp::Ne), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "<".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Lt), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ">".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Gt), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "<=".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Le), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ">=".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Ge), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "+".to_string(), + left_bp: 13, + right_bp: 14, + binop: Some(BinOp::Add), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "-".to_string(), + left_bp: 13, + right_bp: 14, + binop: Some(BinOp::Sub), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "*".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Mul), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "/".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Div), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "%".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Mod), + algebra_field: None, +})]) + }; + } CACHED.with(|c| c.clone()) } diff --git a/src/v2/stage0/src/extdeps_languages_go_types.rs b/src/v2/stage0/src/extdeps_languages_go_types.rs index f76a6e48558..71c584f3f82 100644 --- a/src/v2/stage0/src/extdeps_languages_go_types.rs +++ b/src/v2/stage0/src/extdeps_languages_go_types.rs @@ -1,12 +1,12 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.go.types -pub use crate::std_coercion::{CallableRepr, CastSyntax, InhabitantDecl, TypeCheckpoint}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_coercion::{TypeCheckpoint, InhabitantDecl, CallableRepr, CastSyntax}; pub fn go_type_checkpoints() -> Rc>> { thread_local! { @@ -74,9 +74,7 @@ pub fn nil_literal() -> String { CACHED.with(|c| c.clone()) } -pub fn visibility_by_case() -> bool { - true -} +pub fn visibility_by_case() -> bool { true } pub fn embedded_field_syntax() -> String { thread_local! { diff --git a/src/v2/stage0/src/extdeps_languages_python_emit.rs b/src/v2/stage0/src/extdeps_languages_python_emit.rs index 67bdcccec21..be02c40f3e0 100644 --- a/src/v2/stage0/src/extdeps_languages_python_emit.rs +++ b/src/v2/stage0/src/extdeps_languages_python_emit.rs @@ -1,11 +1,11 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.python.emit -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; pub fn python_keywords() -> Rc> { thread_local! { diff --git a/src/v2/stage0/src/extdeps_languages_python_syntax.rs b/src/v2/stage0/src/extdeps_languages_python_syntax.rs index 6fdeb0197c0..f70c8c577e9 100644 --- a/src/v2/stage0/src/extdeps_languages_python_syntax.rs +++ b/src/v2/stage0/src/extdeps_languages_python_syntax.rs @@ -1,166 +1,160 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.python.syntax -use crate::std_syntax::AlgebraFieldKind::{AlgQuotient, AlgReciprocal}; -use crate::std_syntax::BinOp::{ - Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, NullCoalesce, Or, Sub, -}; -use crate::std_syntax::BodyKind::{BlockBody, NoBody, TypeBody}; -use crate::std_syntax::ItemFormKind::{ - EnumForm, FuncForm, ModuleForm, OtherForm, StructForm, TypeAliasForm, -}; -pub use crate::std_syntax::{ - AlgebraFieldKind, BinOp, BodyKind, ItemForm, ItemFormKind, OperatorSpec, -}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_syntax::{ItemForm, ItemFormKind, BodyKind, OperatorSpec, BinOp, AlgebraFieldKind}; +use crate::std_syntax::ItemFormKind::{FuncForm, StructForm, EnumForm, TypeAliasForm, ModuleForm, OtherForm}; +use crate::std_syntax::BodyKind::{BlockBody, TypeBody, NoBody}; +use crate::std_syntax::BinOp::{Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Gt, Le, Ge, And, Or, NullCoalesce}; +use crate::std_syntax::AlgebraFieldKind::{AlgReciprocal, AlgQuotient}; pub fn python_item_forms() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(ItemForm { - kind: ItemFormKind::FuncForm, - keyword: "def".to_string(), - has_type_params: false, - has_params: true, - has_return_type: true, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::StructForm, - keyword: "class".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::EnumForm, - keyword: "class".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::TypeAliasForm, - keyword: "".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::NoBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::ModuleForm, - keyword: "".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::NoBody, - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(ItemForm { + kind: ItemFormKind::FuncForm, + keyword: "def".to_string(), + has_type_params: false, + has_params: true, + has_return_type: true, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::StructForm, + keyword: "class".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::EnumForm, + keyword: "class".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::TypeAliasForm, + keyword: "".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::NoBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::ModuleForm, + keyword: "".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::NoBody, +})]) + }; + } CACHED.with(|c| c.clone()) } pub fn python_operators() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(OperatorSpec { - symbol: "or".to_string(), - left_bp: 5, - right_bp: 6, - binop: Some(BinOp::Or), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "and".to_string(), - left_bp: 7, - right_bp: 8, - binop: Some(BinOp::And), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "==".to_string(), - left_bp: 9, - right_bp: 10, - binop: Some(BinOp::Eq), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "!=".to_string(), - left_bp: 9, - right_bp: 10, - binop: Some(BinOp::Ne), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "<".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Lt), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ">".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Gt), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "<=".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Le), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ">=".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Ge), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "+".to_string(), - left_bp: 13, - right_bp: 14, - binop: Some(BinOp::Add), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "-".to_string(), - left_bp: 13, - right_bp: 14, - binop: Some(BinOp::Sub), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "*".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Mul), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "/".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Div), - algebra_field: Some(AlgebraFieldKind::AlgReciprocal), - }), Rc::new(OperatorSpec { - symbol: "//".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Div), - algebra_field: Some(AlgebraFieldKind::AlgQuotient), - }), Rc::new(OperatorSpec { - symbol: "%".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Mod), - algebra_field: None, - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(OperatorSpec { + symbol: "or".to_string(), + left_bp: 5, + right_bp: 6, + binop: Some(BinOp::Or), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "and".to_string(), + left_bp: 7, + right_bp: 8, + binop: Some(BinOp::And), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "==".to_string(), + left_bp: 9, + right_bp: 10, + binop: Some(BinOp::Eq), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "!=".to_string(), + left_bp: 9, + right_bp: 10, + binop: Some(BinOp::Ne), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "<".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Lt), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ">".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Gt), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "<=".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Le), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ">=".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Ge), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "+".to_string(), + left_bp: 13, + right_bp: 14, + binop: Some(BinOp::Add), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "-".to_string(), + left_bp: 13, + right_bp: 14, + binop: Some(BinOp::Sub), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "*".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Mul), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "/".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Div), + algebra_field: Some(AlgebraFieldKind::AlgReciprocal), +}), Rc::new(OperatorSpec { + symbol: "//".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Div), + algebra_field: Some(AlgebraFieldKind::AlgQuotient), +}), Rc::new(OperatorSpec { + symbol: "%".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Mod), + algebra_field: None, +})]) + }; + } CACHED.with(|c| c.clone()) } diff --git a/src/v2/stage0/src/extdeps_languages_python_types.rs b/src/v2/stage0/src/extdeps_languages_python_types.rs index c770af67413..3d5b6ca151f 100644 --- a/src/v2/stage0/src/extdeps_languages_python_types.rs +++ b/src/v2/stage0/src/extdeps_languages_python_types.rs @@ -1,13 +1,13 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.python.types -use self::PythonTypeKind::*; -pub use crate::std_coercion::{CallableRepr, CastSyntax, InhabitantDecl, TypeCheckpoint}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_coercion::{TypeCheckpoint, InhabitantDecl, CallableRepr, CastSyntax}; +use self::PythonTypeKind::*; pub fn python_type_checkpoints() -> Rc>> { thread_local! { diff --git a/src/v2/stage0/src/extdeps_languages_rust_emit.rs b/src/v2/stage0/src/extdeps_languages_rust_emit.rs index 5e4c2f0bd8a..6e28fab40d4 100644 --- a/src/v2/stage0/src/extdeps_languages_rust_emit.rs +++ b/src/v2/stage0/src/extdeps_languages_rust_emit.rs @@ -1,11 +1,11 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.rust.emit -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; pub fn rust_keywords() -> Rc> { thread_local! { @@ -59,32 +59,11 @@ pub fn rust_simple_method_specs() -> Rc>> { } pub fn rust_method_templates() -> Rc> { - rust_simple_method_specs().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, spec: Rc| { - v2_rt::rc_map_insert(acc, spec.method_name.clone(), spec.template.clone()) - }, - ) + rust_simple_method_specs().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, spec: Rc| v2_rt::rc_map_insert(acc, spec.method_name.clone(), spec.template.clone())) } pub fn rust_method_wraps_result() -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for s in rust_simple_method_specs().iter().cloned() { - if s.wraps_result.clone() { - __result.push(s); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, spec: Rc| { - v2_rt::rc_map_insert(acc, spec.method_name.clone(), true) - }, - ) + Rc::new({ let mut __result = Vec::new(); for s in rust_simple_method_specs().iter().cloned() { if s.wraps_result.clone() { __result.push(s); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, spec: Rc| v2_rt::rc_map_insert(acc, spec.method_name.clone(), true)) } pub fn rust_reserved() -> Rc> { @@ -430,72 +409,19 @@ pub fn rt_function_registry() -> Rc>> { } pub fn rt_functions() -> Rc> { - rt_function_registry().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, entry: Rc| { - v2_rt::rc_map_insert(acc, entry.name.clone(), true) - }, - ) + rt_function_registry().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, entry: Rc| v2_rt::rc_map_insert(acc, entry.name.clone(), true)) } pub fn rt_ref_map_functions() -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for f in rt_function_registry().iter().cloned() { - if f.passes_by_ref.clone() { - __result.push(f); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, entry: Rc| { - v2_rt::rc_map_insert(acc, entry.name.clone(), true) - }, - ) + Rc::new({ let mut __result = Vec::new(); for f in rt_function_registry().iter().cloned() { if f.passes_by_ref.clone() { __result.push(f); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, entry: Rc| v2_rt::rc_map_insert(acc, entry.name.clone(), true)) } pub fn rt_wraps_result() -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for f in rt_function_registry().iter().cloned() { - if f.wraps_result.clone() { - __result.push(f); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, entry: Rc| { - v2_rt::rc_map_insert(acc, entry.name.clone(), true) - }, - ) + Rc::new({ let mut __result = Vec::new(); for f in rt_function_registry().iter().cloned() { if f.wraps_result.clone() { __result.push(f); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, entry: Rc| v2_rt::rc_map_insert(acc, entry.name.clone(), true)) } pub fn rt_bridge_function_names() -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for f in rt_function_registry().iter().cloned() { - if (f.name.clone().as_str() != f.bridge_name.clone().as_str()) { - __result.push(f); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, entry: Rc| { - v2_rt::rc_map_insert(acc, entry.name.clone(), entry.bridge_name.clone()) - }, - ) + Rc::new({ let mut __result = Vec::new(); for f in rt_function_registry().iter().cloned() { if (f.name.clone().as_str() != f.bridge_name.clone().as_str()) { __result.push(f); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, entry: Rc| v2_rt::rc_map_insert(acc, entry.name.clone(), entry.bridge_name.clone())) } pub fn is_rt_function(name: String) -> bool { @@ -504,9 +430,9 @@ pub fn is_rt_function(name: String) -> bool { pub fn rt_bridge_name(name: String) -> String { match v2_rt::map_get(&rt_bridge_function_names(), name.clone()) { - Some(bridge) => bridge.clone(), - None => name.clone(), - } + Some(bridge) => bridge.clone(), + None => name.clone(), +} } pub fn rt_passes_by_ref(name: String) -> bool { diff --git a/src/v2/stage0/src/extdeps_languages_rust_syntax.rs b/src/v2/stage0/src/extdeps_languages_rust_syntax.rs index 41e62fe19b4..7ee94af98c8 100644 --- a/src/v2/stage0/src/extdeps_languages_rust_syntax.rs +++ b/src/v2/stage0/src/extdeps_languages_rust_syntax.rs @@ -1,124 +1,120 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.rust.syntax -use crate::std_syntax::BinOp::{Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, Or, Sub}; -use crate::std_syntax::BodyKind::{BlockBody, ExprBody, NoBody, TypeBody}; -use crate::std_syntax::ItemFormKind::{ - EnumForm, FuncForm, ModuleForm, OtherForm, StructForm, TypeAliasForm, -}; -use crate::std_syntax::LiteralValue::LitBool; -pub use crate::std_syntax::{ - BinOp, BodyKind, ItemForm, ItemFormKind, LiteralValue, OperatorSpec, SyntaxSpec, -}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_syntax::{ItemForm, ItemFormKind, BodyKind, OperatorSpec, SyntaxSpec, BinOp, LiteralValue}; +use crate::std_syntax::ItemFormKind::{FuncForm, StructForm, EnumForm, TypeAliasForm, ModuleForm, OtherForm}; +use crate::std_syntax::BodyKind::{ExprBody, BlockBody, TypeBody, NoBody}; +use crate::std_syntax::BinOp::{Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Gt, Le, Ge, And, Or}; +use crate::std_syntax::LiteralValue::{LitBool}; pub fn rust_item_forms() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(ItemForm { - kind: ItemFormKind::FuncForm, - keyword: "fn".to_string(), - has_type_params: true, - has_params: true, - has_return_type: true, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::StructForm, - keyword: "struct".to_string(), - has_type_params: true, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::TypeBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::EnumForm, - keyword: "enum".to_string(), - has_type_params: true, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::TypeBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::TypeAliasForm, - keyword: "type".to_string(), - has_type_params: true, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::NoBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "trait".to_string(), - has_type_params: true, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "impl".to_string(), - has_type_params: true, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "const".to_string(), - has_type_params: false, - has_params: false, - has_return_type: true, - return_required: true, - has_uses: false, - body_kind: BodyKind::ExprBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: "static".to_string(), - has_type_params: false, - has_params: false, - has_return_type: true, - return_required: true, - has_uses: false, - body_kind: BodyKind::ExprBody, - }), Rc::new(ItemForm { - kind: ItemFormKind::ModuleForm, - keyword: "mod".to_string(), - has_type_params: false, - has_params: false, - has_return_type: false, - return_required: false, - has_uses: false, - body_kind: BodyKind::BlockBody, - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(ItemForm { + kind: ItemFormKind::FuncForm, + keyword: "fn".to_string(), + has_type_params: true, + has_params: true, + has_return_type: true, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::StructForm, + keyword: "struct".to_string(), + has_type_params: true, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::TypeBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::EnumForm, + keyword: "enum".to_string(), + has_type_params: true, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::TypeBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::TypeAliasForm, + keyword: "type".to_string(), + has_type_params: true, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::NoBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "trait".to_string(), + has_type_params: true, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "impl".to_string(), + has_type_params: true, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "const".to_string(), + has_type_params: false, + has_params: false, + has_return_type: true, + return_required: true, + has_uses: false, + body_kind: BodyKind::ExprBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: "static".to_string(), + has_type_params: false, + has_params: false, + has_return_type: true, + return_required: true, + has_uses: false, + body_kind: BodyKind::ExprBody, +}), Rc::new(ItemForm { + kind: ItemFormKind::ModuleForm, + keyword: "mod".to_string(), + has_type_params: false, + has_params: false, + has_return_type: false, + return_required: false, + has_uses: false, + body_kind: BodyKind::BlockBody, +})]) + }; + } CACHED.with(|c| c.clone()) } pub fn rust_keyword_literals() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - let mut __m = HashMap::new(); - __m.insert("true".to_string(), Rc::new(LiteralValue::LitBool { - value: true, - })); - __m.insert("false".to_string(), Rc::new(LiteralValue::LitBool { - value: false, - })); - Rc::new(__m) - }; - } + static CACHED: Rc>> = { + let mut __m = HashMap::new(); + __m.insert("true".to_string(), Rc::new(LiteralValue::LitBool { + value: true, +})); + __m.insert("false".to_string(), Rc::new(LiteralValue::LitBool { + value: false, +})); + Rc::new(__m) + }; + } CACHED.with(|c| c.clone()) } @@ -171,107 +167,107 @@ pub fn rust_keyword_set() -> Rc> { pub fn rust_operators() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(OperatorSpec { - symbol: "||".to_string(), - left_bp: 5, - right_bp: 6, - binop: Some(BinOp::Or), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "&&".to_string(), - left_bp: 7, - right_bp: 8, - binop: Some(BinOp::And), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "==".to_string(), - left_bp: 9, - right_bp: 10, - binop: Some(BinOp::Eq), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "!=".to_string(), - left_bp: 9, - right_bp: 10, - binop: Some(BinOp::Ne), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "<".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Lt), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ">".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Gt), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "<=".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Le), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ">=".to_string(), - left_bp: 11, - right_bp: 12, - binop: Some(BinOp::Ge), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "+".to_string(), - left_bp: 13, - right_bp: 14, - binop: Some(BinOp::Add), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "-".to_string(), - left_bp: 13, - right_bp: 14, - binop: Some(BinOp::Sub), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "*".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Mul), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "/".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Div), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: "%".to_string(), - left_bp: 15, - right_bp: 16, - binop: Some(BinOp::Mod), - algebra_field: None, - }), Rc::new(OperatorSpec { - symbol: ".".to_string(), - left_bp: 19, - right_bp: 20, - binop: None, - algebra_field: None, - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(OperatorSpec { + symbol: "||".to_string(), + left_bp: 5, + right_bp: 6, + binop: Some(BinOp::Or), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "&&".to_string(), + left_bp: 7, + right_bp: 8, + binop: Some(BinOp::And), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "==".to_string(), + left_bp: 9, + right_bp: 10, + binop: Some(BinOp::Eq), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "!=".to_string(), + left_bp: 9, + right_bp: 10, + binop: Some(BinOp::Ne), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "<".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Lt), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ">".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Gt), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "<=".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Le), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ">=".to_string(), + left_bp: 11, + right_bp: 12, + binop: Some(BinOp::Ge), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "+".to_string(), + left_bp: 13, + right_bp: 14, + binop: Some(BinOp::Add), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "-".to_string(), + left_bp: 13, + right_bp: 14, + binop: Some(BinOp::Sub), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "*".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Mul), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "/".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Div), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: "%".to_string(), + left_bp: 15, + right_bp: 16, + binop: Some(BinOp::Mod), + algebra_field: None, +}), Rc::new(OperatorSpec { + symbol: ".".to_string(), + left_bp: 19, + right_bp: 20, + binop: None, + algebra_field: None, +})]) + }; + } CACHED.with(|c| c.clone()) } pub fn rust_syntax_spec() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(SyntaxSpec { - item_forms: rust_item_forms(), - operators: rust_operators(), - keyword_literals: rust_keyword_literals(), - keyword_set: rust_keyword_set(), - }) - }; - } + static CACHED: Rc = { + Rc::new(SyntaxSpec { + item_forms: rust_item_forms(), + operators: rust_operators(), + keyword_literals: rust_keyword_literals(), + keyword_set: rust_keyword_set(), +}) + }; + } CACHED.with(|c| c.clone()) } diff --git a/src/v2/stage0/src/extdeps_languages_rust_types.rs b/src/v2/stage0/src/extdeps_languages_rust_types.rs index dfc86341d78..ff74f611836 100644 --- a/src/v2/stage0/src/extdeps_languages_rust_types.rs +++ b/src/v2/stage0/src/extdeps_languages_rust_types.rs @@ -1,14 +1,14 @@ // Generated by v2 compiler -- do not edit. // Source module: extdeps.languages.rust.types -use self::OwnershipKind::*; -use self::SmartPointerKind::*; -pub use crate::std_coercion::{CallableRepr, CastRule, CastSyntax, InhabitantDecl, TypeCheckpoint}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_coercion::{TypeCheckpoint, InhabitantDecl, CallableRepr, CastSyntax, CastRule}; +use self::OwnershipKind::*; +use self::SmartPointerKind::*; pub fn rust_type_checkpoints() -> Rc>> { thread_local! { @@ -76,13 +76,9 @@ pub enum OwnershipKind { RawPtr, } -pub fn pass_copy_by_value() -> bool { - true -} +pub fn pass_copy_by_value() -> bool { true } -pub fn pass_non_copy_by_ref() -> bool { - true -} +pub fn pass_non_copy_by_ref() -> bool { true } pub fn ref_prefix() -> String { thread_local! { diff --git a/src/v2/stage0/src/generated_method_template_projection.rs b/src/v2/stage0/src/generated_method_template_projection.rs index 0ec3341ea20..b6f8367137c 100644 --- a/src/v2/stage0/src/generated_method_template_projection.rs +++ b/src/v2/stage0/src/generated_method_template_projection.rs @@ -1,11 +1,11 @@ // Generated by v2 compiler -- do not edit. // Source module: generated.method_template_projection -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; pub fn rust_method_template_emit() -> Rc> { thread_local! { diff --git a/src/v2/stage0/src/lib.rs b/src/v2/stage0/src/lib.rs index 8ba13372286..8b07dea78cf 100644 --- a/src/v2/stage0/src/lib.rs +++ b/src/v2/stage0/src/lib.rs @@ -1,79 +1,69 @@ // Generated by v2 compiler -- do not edit. -#![allow( - unused_imports, - unused_variables, - unused_mut, - unused_parens, - dead_code, - unreachable_patterns, - non_shorthand_field_patterns, - suspicious_double_ref_op, - clippy::all -)] +#![allow(unused_imports, unused_variables, unused_mut, unused_parens, dead_code, unreachable_patterns, non_shorthand_field_patterns, suspicious_double_ref_op, clippy::all)] -pub mod cli_run; +pub mod std_error_primitives; +pub mod std_algebra; +pub mod std_types; pub mod extdeps_languages_dag_emit; +pub mod extdeps_languages_go_emit; +pub mod extdeps_languages_python_emit; +pub mod extdeps_languages_rust_emit; +pub mod generated_method_template_projection; +pub mod std_coercion; +pub mod std_http_path; +pub mod std_iteration; +pub mod std_syntax; +pub mod std_termination; +pub mod v2_compiler_runtime_rust; pub mod extdeps_languages_dag_syntax; pub mod extdeps_languages_dag_types; -pub mod extdeps_languages_go_emit; pub mod extdeps_languages_go_syntax; pub mod extdeps_languages_go_types; -pub mod extdeps_languages_python_emit; pub mod extdeps_languages_python_syntax; pub mod extdeps_languages_python_types; -pub mod extdeps_languages_rust_emit; pub mod extdeps_languages_rust_syntax; pub mod extdeps_languages_rust_types; -pub mod generated_method_template_projection; -pub mod rest_transport_facts; -pub mod std_algebra; -pub mod std_coercion; pub mod std_computation; pub mod std_effects; -pub mod std_error_primitives; pub mod std_graph; -pub mod std_http_path; pub mod std_induction; -pub mod std_iteration; +pub mod v2_compiler_effect_derivation; pub mod std_node; -pub mod std_syntax; -pub mod std_termination; -pub mod std_types; +pub mod v2_std_core; pub mod v2_compiler_artifact; +pub mod v2_compiler_infer_env; +pub mod v2_compiler_infer_types; +pub mod v2_compiler_resolve; +pub mod v2_compiler_tokenize; +pub mod v2_compiler_trace; pub mod v2_compiler_coercion; -pub mod v2_compiler_compile; -pub mod v2_compiler_compiler_tests_rust; -pub mod v2_compiler_complexity; -pub mod v2_compiler_effect_derivation; -pub mod v2_compiler_emit; -pub mod v2_compiler_emit_go; -pub mod v2_compiler_emit_python; -pub mod v2_compiler_emit_rust; -pub mod v2_compiler_infer; pub mod v2_compiler_infer_access; pub mod v2_compiler_infer_cycle; pub mod v2_compiler_infer_emit_info; -pub mod v2_compiler_infer_env; -pub mod v2_compiler_infer_items; -pub mod v2_compiler_infer_lookup; pub mod v2_compiler_infer_method; pub mod v2_compiler_infer_patterns; pub mod v2_compiler_infer_resolve; -pub mod v2_compiler_infer_service; pub mod v2_compiler_infer_sigs; -pub mod v2_compiler_infer_types; pub mod v2_compiler_languages; pub mod v2_compiler_normalize; -pub mod v2_compiler_ownership; +pub mod v2_compiler_compiler_tests_rust; +pub mod v2_compiler_infer_items; pub mod v2_compiler_parse; -pub mod v2_compiler_resolve; -pub mod v2_compiler_runtime_rust; -pub mod v2_compiler_tokenize; -pub mod v2_compiler_trace; -pub mod v2_interpreter; +pub mod v2_compiler_infer_service; +pub mod v2_compiler_infer_lookup; +pub mod v2_compiler_infer; +pub mod v2_compiler_emit; +pub mod v2_compiler_complexity; +pub mod v2_compiler_emit_go; +pub mod v2_compiler_emit_python; +pub mod v2_compiler_ownership; +pub mod v2_compiler_emit_rust; +pub mod v2_compiler_compile; pub mod v2_rt; -pub mod v2_std_core; +pub mod v2_interpreter; +pub mod cli_run; +pub mod rest_transport_facts; #[derive(Debug, Clone, PartialEq)] pub struct NonEmptyVec(Vec); diff --git a/src/v2/stage0/src/main.rs b/src/v2/stage0/src/main.rs index 229429e5f0d..ec899eedd43 100644 --- a/src/v2/stage0/src/main.rs +++ b/src/v2/stage0/src/main.rs @@ -6,14 +6,15 @@ use clap::{Parser, Subcommand}; use std::collections::HashMap; use std::rc::Rc; -use v2_compiler::cli_run; -use v2_compiler::v2_compiler_artifact; use v2_compiler::v2_compiler_compile; use v2_compiler::v2_compiler_compile::PipelineResult; +use v2_compiler::v2_compiler_artifact; use v2_compiler::v2_std_core::{ - byte_to_line_col, diagnostic_to_message, diagnostic_to_span, source_line_at, - CompilerDiagnostic, NewlineIndex, + diagnostic_to_message, diagnostic_to_span, + byte_to_line_col, source_line_at, NewlineIndex, + CompilerDiagnostic, }; +use v2_compiler::cli_run; #[derive(Parser)] #[command(name = "v2-compiled", about = "Generated CLI from DAG compiler")] @@ -42,7 +43,7 @@ enum Commands { #[arg(long, default_value = "rust")] target: String, }, - /// Execute a .dag program directly (interpreter) +/// Execute a .dag program directly (interpreter) Run { /// Source root directories (searched recursively for .dag files) #[arg(long = "source-root")] @@ -117,10 +118,8 @@ fn build_module_index(source_roots: &[String]) -> HashMap { +let _result = match cli.command { + Commands::Compile { source_roots, source_dir, output_dir, target } => { let render_target = match target.as_str() { "rust" => v2_compiler_artifact::RenderTarget::Rust, "python" => v2_compiler_artifact::RenderTarget::Python, "go" => v2_compiler_artifact::RenderTarget::Go, "dag" => v2_compiler_artifact::RenderTarget::Dag, other => { - eprintln!( - "unknown target: {}. supported: rust, python, go, dag", - other - ); + eprintln!("unknown target: {}. supported: rust, python, go, dag", other); std::process::exit(1); } }; @@ -195,11 +183,7 @@ fn main() { let sources = if !source_roots.is_empty() { // FF-9: Import-driven resolution from source roots let index = build_module_index(&source_roots); - eprintln!( - "indexed {} modules from {} source roots", - index.len(), - source_roots.len() - ); + eprintln!("indexed {} modules from {} source roots", index.len(), source_roots.len()); // Entry modules: all .dag files in the FIRST source root. // Additional roots are dependency pools resolved via imports. @@ -237,11 +221,9 @@ fn main() { resolved.push(Rc::new(v2_compiler_compile::SourceFile { path, content })); } } - eprintln!( - "resolved {} sources (transitive import closure)", - resolved.len() - ); + eprintln!("resolved {} sources (transitive import closure)", resolved.len()); resolved + } else if let Some(dir) = source_dir { // Legacy: flat directory scan (backward compatibility) let mut dag_paths = Vec::new(); @@ -256,13 +238,9 @@ fn main() { content, })); } - eprintln!( - "compiling {} .dag files from {} (target: {})", - sources.len(), - dir, - target - ); + eprintln!("compiling {} .dag files from {} (target: {})", sources.len(), dir, target); sources + } else { eprintln!("error: provide --source-root or --source-dir"); std::process::exit(1); @@ -280,18 +258,12 @@ fn main() { std::fs::write(&out_path, &*file.content) .unwrap_or_else(|e| panic!("failed to write {}: {}", file.path, e)); } - eprintln!( - "compiled: {} files emitted, {} diagnostics", - result.files.len(), - result.diagnostics.len() - ); + eprintln!("compiled: {} files emitted, {} diagnostics", + result.files.len(), result.diagnostics.len()); render_diagnostics(&result); // Complexity violations are non-blocking (analyzer limitations). let hard_errors = result.diagnostics.iter().any(|d| { - !matches!( - *d.diagnostic.clone(), - CompilerDiagnostic::ComplexityUnknown { .. } - ) + !matches!(*d.diagnostic.clone(), CompilerDiagnostic::ComplexityUnknown { .. }) }); if hard_errors { std::process::exit(1); @@ -300,14 +272,11 @@ fn main() { eprintln!("error: no files emitted"); std::process::exit(1); } - } + }, - Commands::Run { - source_roots, - function, - } => { + Commands::Run { source_roots, function } => { cli_run::handle_run(source_roots, function); - } + }, }; } @@ -373,10 +342,7 @@ fn render_one_diagnostic( indent, " ".repeat(gutter_width), " ".repeat(col_offset), - "^".repeat(std::cmp::min( - span_len, - line_text.len().saturating_sub(col_offset) - )) + "^".repeat(std::cmp::min(span_len, line_text.len().saturating_sub(col_offset))) ); } } diff --git a/src/v2/stage0/src/std_algebra.rs b/src/v2/stage0/src/std_algebra.rs index 81e3f747a1b..56137791ad0 100644 --- a/src/v2/stage0/src/std_algebra.rs +++ b/src/v2/stage0/src/std_algebra.rs @@ -1,20 +1,20 @@ // Generated by v2 compiler -- do not edit. // Source module: std.algebra +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_error_primitives::{DivError, Result}; +use crate::std_error_primitives::DivError::*; +use crate::std_error_primitives::Result::*; +use self::Ordering::*; use self::AlgebraProfile::*; +use self::ContainerSource::*; use self::AlgebraTypeTemplate::*; use self::CollectionSizeEffect::*; -use self::ContainerSource::*; use self::CostShape::*; -use self::Ordering::*; -use crate::std_error_primitives::DivError::*; -use crate::std_error_primitives::Result::*; -pub use crate::std_error_primitives::{DivError, Result}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; #[derive(Clone)] pub struct Magma { @@ -52,6 +52,10 @@ pub struct AbelianGroup { pub inverse: Rc T>, } + + + + #[derive(Clone)] pub struct Semiring { pub add: Rc T>, @@ -192,7 +196,9 @@ pub enum AlgebraProfile { #[serde(tag = "_variant")] pub enum ContainerSource { SameAsReceiver, - Named { name: String }, + Named { + name: String, + }, } impl ContainerSource { pub fn name(&self) -> String { @@ -278,1127 +284,870 @@ pub fn kernel_algebra_profile() -> Rc> { } pub fn ordered_ring_templates() -> Rc>> { - Rc::new(vec![ - Rc::new(AlgebraFieldTemplate { - name: "add".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "zero".to_string(), - param_types: Rc::new(vec![]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "negate".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "mul".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "one".to_string(), - param_types: Rc::new(vec![]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "compare".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Ordering".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "clamp".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: Some(CostShape::ShapeConstant), - callback_element_position: None, - }), - ]) + Rc::new(vec![Rc::new(AlgebraFieldTemplate { + name: "add".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "zero".to_string(), + param_types: Rc::new(vec![]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "negate".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "mul".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "one".to_string(), + param_types: Rc::new(vec![]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "compare".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Ordering".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "clamp".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: Some(CostShape::ShapeConstant), + callback_element_position: None, +})]) } pub fn approximate_field_templates() -> Rc>> { - Rc::new(vec![ - Rc::new(AlgebraFieldTemplate { - name: "add".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "zero".to_string(), - param_types: Rc::new(vec![]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "negate".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "mul".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "one".to_string(), - param_types: Rc::new(vec![]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "reciprocal".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "compare".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Ordering".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - ]) + Rc::new(vec![Rc::new(AlgebraFieldTemplate { + name: "add".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "zero".to_string(), + param_types: Rc::new(vec![]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "negate".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "mul".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "one".to_string(), + param_types: Rc::new(vec![]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "reciprocal".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "compare".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Ordering".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +})]) } pub fn boolean_algebra_templates() -> Rc>> { - Rc::new(vec![ - Rc::new(AlgebraFieldTemplate { - name: "meet".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "join".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "complement".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "top".to_string(), - param_types: Rc::new(vec![]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "bottom".to_string(), - param_types: Rc::new(vec![]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - ]) + Rc::new(vec![Rc::new(AlgebraFieldTemplate { + name: "meet".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "join".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "complement".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "top".to_string(), + param_types: Rc::new(vec![]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "bottom".to_string(), + param_types: Rc::new(vec![]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +})]) } pub fn boolean_algebra_collection_templates() -> Rc>> { - Rc::new(vec![ - Rc::new(AlgebraFieldTemplate { - name: "union".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "intersect".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "diff".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "member".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverElement), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "contains".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverElement), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "filter".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: Some(CollectionSizeEffect::IdentityEffect), - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "map".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "MappedElement".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::SameAsReceiver), - element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "MappedElement".to_string(), - }), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "flat_map".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::SameAsReceiver), - element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "MappedElement".to_string(), - }), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::SameAsReceiver), - element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "MappedElement".to_string(), - }), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "fold".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "FoldAccumulator".to_string(), - }), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "FoldAccumulator".to_string(), - }), - Rc::new(AlgebraTypeTemplate::ReceiverElement), - ]), - return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "FoldAccumulator".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "FoldAccumulator".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(1), - }), - Rc::new(AlgebraFieldTemplate { - name: "any".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "all".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "count".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "length".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - ]) + Rc::new(vec![Rc::new(AlgebraFieldTemplate { + name: "union".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "intersect".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "diff".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "member".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "contains".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "filter".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: Some(CollectionSizeEffect::IdentityEffect), + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "map".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "MappedElement".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::SameAsReceiver), + element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "MappedElement".to_string(), +}), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "flat_map".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::SameAsReceiver), + element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "MappedElement".to_string(), +}), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::SameAsReceiver), + element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "MappedElement".to_string(), +}), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "fold".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "FoldAccumulator".to_string(), +}), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "FoldAccumulator".to_string(), +}), Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "FoldAccumulator".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "FoldAccumulator".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(1), +}), Rc::new(AlgebraFieldTemplate { + name: "any".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "all".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "count".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "length".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +})]) } pub fn free_monoid_scalar_templates() -> Rc>> { - Rc::new(vec![ - Rc::new(AlgebraFieldTemplate { - name: "concat".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "empty".to_string(), - param_types: Rc::new(vec![]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "length".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "is_empty".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "chars".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::Named { - name: "List".to_string(), - }), - element: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "split".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::Named { - name: "List".to_string(), - }), - element: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "join".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::Named { - name: "List".to_string(), - }), - element: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - }), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "contains".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "starts_with".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "ends_with".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "trim".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "to_lower".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "to_upper".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "replace".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "substring".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "to_int".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "to_string".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "reverse".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - ]) + Rc::new(vec![Rc::new(AlgebraFieldTemplate { + name: "concat".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "empty".to_string(), + param_types: Rc::new(vec![]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "length".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "is_empty".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "chars".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::Named { + name: "List".to_string(), +}), + element: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "split".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::Named { + name: "List".to_string(), +}), + element: Rc::new(AlgebraTypeTemplate::ReceiverSelf), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "join".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::Named { + name: "List".to_string(), +}), + element: Rc::new(AlgebraTypeTemplate::ReceiverSelf), +}), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "contains".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "starts_with".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "ends_with".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "trim".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "to_lower".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "to_upper".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "replace".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "substring".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "to_int".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "to_string".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "reverse".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +})]) } pub fn free_monoid_collection_templates() -> Rc>> { - Rc::new(vec![ - Rc::new(AlgebraFieldTemplate { - name: "map".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "MappedElement".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::SameAsReceiver), - element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "MappedElement".to_string(), - }), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "filter".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: Some(CollectionSizeEffect::IdentityEffect), - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "flat_map".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::SameAsReceiver), - element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "MappedElement".to_string(), - }), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::SameAsReceiver), - element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "MappedElement".to_string(), - }), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "fold".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "FoldAccumulator".to_string(), - }), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "FoldAccumulator".to_string(), - }), - Rc::new(AlgebraTypeTemplate::ReceiverElement), - ]), - return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "FoldAccumulator".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { - id: "FoldAccumulator".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(1), - }), - Rc::new(AlgebraFieldTemplate { - name: "any".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "all".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::CallableOf { - params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: Some(0), - }), - Rc::new(AlgebraFieldTemplate { - name: "count".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "first".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { - inner: Rc::new(AlgebraTypeTemplate::ReceiverElement), - }), - size_effect: Some(CollectionSizeEffect::ProjectionEffect), - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "last".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { - inner: Rc::new(AlgebraTypeTemplate::ReceiverElement), - }), - size_effect: Some(CollectionSizeEffect::ProjectionEffect), - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "skip".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: Some(CollectionSizeEffect::ShrinkEffect), - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "take".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "sort_by".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: Some(CollectionSizeEffect::IdentityEffect), - cost_shape: Some(CostShape::ShapeSortBody), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "append".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverElement), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: Some(CostShape::ShapeConstant), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "contains".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverElement), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "enumerate".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::SameAsReceiver), - element: Rc::new(AlgebraTypeTemplate::TupleOf { - first: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - second: Rc::new(AlgebraTypeTemplate::ReceiverElement), - }), - }), - size_effect: Some(CollectionSizeEffect::IdentityEffect), - cost_shape: Some(CostShape::ShapeIterateBody), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "reverse".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: Some(CollectionSizeEffect::IdentityEffect), - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "join".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "String".to_string(), - }), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "String".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "concat".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "list_push".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverElement), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "length".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "is_empty".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: Some(CostShape::ShapeLinearScan), - callback_element_position: None, - }), - ]) + Rc::new(vec![Rc::new(AlgebraFieldTemplate { + name: "map".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "MappedElement".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::SameAsReceiver), + element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "MappedElement".to_string(), +}), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "filter".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: Some(CollectionSizeEffect::IdentityEffect), + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "flat_map".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::SameAsReceiver), + element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "MappedElement".to_string(), +}), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::SameAsReceiver), + element: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "MappedElement".to_string(), +}), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "fold".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "FoldAccumulator".to_string(), +}), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "FoldAccumulator".to_string(), +}), Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "FoldAccumulator".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::AlgebraTypeVariable { + id: "FoldAccumulator".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(1), +}), Rc::new(AlgebraFieldTemplate { + name: "any".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "all".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::CallableOf { + params: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), +})]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: Some(0), +}), Rc::new(AlgebraFieldTemplate { + name: "count".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "first".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { + inner: Rc::new(AlgebraTypeTemplate::ReceiverElement), +}), + size_effect: Some(CollectionSizeEffect::ProjectionEffect), + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "last".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { + inner: Rc::new(AlgebraTypeTemplate::ReceiverElement), +}), + size_effect: Some(CollectionSizeEffect::ProjectionEffect), + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "skip".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: Some(CollectionSizeEffect::ShrinkEffect), + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "take".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +})]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "sort_by".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: Some(CollectionSizeEffect::IdentityEffect), + cost_shape: Some(CostShape::ShapeSortBody), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "append".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: Some(CostShape::ShapeConstant), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "contains".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "enumerate".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::SameAsReceiver), + element: Rc::new(AlgebraTypeTemplate::TupleOf { + first: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), + second: Rc::new(AlgebraTypeTemplate::ReceiverElement), +}), +}), + size_effect: Some(CollectionSizeEffect::IdentityEffect), + cost_shape: Some(CostShape::ShapeIterateBody), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "reverse".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: Some(CollectionSizeEffect::IdentityEffect), + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "join".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "String".to_string(), +})]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "String".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "concat".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "list_push".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverElement)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "length".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "is_empty".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: Some(CostShape::ShapeLinearScan), + callback_element_position: None, +})]) } pub fn partial_function_templates() -> Rc>> { - Rc::new(vec![ - Rc::new(AlgebraFieldTemplate { - name: "get".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - ]), - return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { - inner: Rc::new(AlgebraTypeTemplate::ReceiverValue), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "map_get".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - ]), - return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { - inner: Rc::new(AlgebraTypeTemplate::ReceiverValue), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "lookup".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - ]), - return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { - inner: Rc::new(AlgebraTypeTemplate::ReceiverValue), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "map_insert".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - Rc::new(AlgebraTypeTemplate::ReceiverValue), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "map_merge".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "has".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "map_has".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "map_contains_key".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "keys".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::Named { - name: "List".to_string(), - }), - element: Rc::new(AlgebraTypeTemplate::ReceiverKey), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "map_keys".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::Named { - name: "List".to_string(), - }), - element: Rc::new(AlgebraTypeTemplate::ReceiverKey), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "values".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::Named { - name: "List".to_string(), - }), - element: Rc::new(AlgebraTypeTemplate::ReceiverValue), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "map_values".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { - source: Rc::new(ContainerSource::Named { - name: "List".to_string(), - }), - element: Rc::new(AlgebraTypeTemplate::ReceiverValue), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "with".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - Rc::new(AlgebraTypeTemplate::ReceiverValue), - ]), - return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "contains".to_string(), - param_types: Rc::new(vec![ - Rc::new(AlgebraTypeTemplate::ReceiverSelf), - Rc::new(AlgebraTypeTemplate::ReceiverKey), - ]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Bool".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - Rc::new(AlgebraFieldTemplate { - name: "length".to_string(), - param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), - return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { - name: "Int".to_string(), - }), - size_effect: None, - cost_shape: None, - callback_element_position: None, - }), - ]) + Rc::new(vec![Rc::new(AlgebraFieldTemplate { + name: "get".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey)]), + return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { + inner: Rc::new(AlgebraTypeTemplate::ReceiverValue), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "map_get".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey)]), + return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { + inner: Rc::new(AlgebraTypeTemplate::ReceiverValue), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "lookup".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey)]), + return_type: Rc::new(AlgebraTypeTemplate::OptionalOf { + inner: Rc::new(AlgebraTypeTemplate::ReceiverValue), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "map_insert".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey), Rc::new(AlgebraTypeTemplate::ReceiverValue)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "map_merge".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "has".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "map_has".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "map_contains_key".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "keys".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::Named { + name: "List".to_string(), +}), + element: Rc::new(AlgebraTypeTemplate::ReceiverKey), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "map_keys".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::Named { + name: "List".to_string(), +}), + element: Rc::new(AlgebraTypeTemplate::ReceiverKey), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "values".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::Named { + name: "List".to_string(), +}), + element: Rc::new(AlgebraTypeTemplate::ReceiverValue), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "map_values".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::ContainerOf { + source: Rc::new(ContainerSource::Named { + name: "List".to_string(), +}), + element: Rc::new(AlgebraTypeTemplate::ReceiverValue), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "with".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey), Rc::new(AlgebraTypeTemplate::ReceiverValue)]), + return_type: Rc::new(AlgebraTypeTemplate::ReceiverSelf), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "contains".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf), Rc::new(AlgebraTypeTemplate::ReceiverKey)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Bool".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +}), Rc::new(AlgebraFieldTemplate { + name: "length".to_string(), + param_types: Rc::new(vec![Rc::new(AlgebraTypeTemplate::ReceiverSelf)]), + return_type: Rc::new(AlgebraTypeTemplate::NamedTemplate { + name: "Int".to_string(), +}), + size_effect: None, + cost_shape: None, + callback_element_position: None, +})]) } pub fn algebra_templates_for_profile(profile: AlgebraProfile) -> Rc>> { match profile { - AlgebraProfile::OrderedRingProfile => ordered_ring_templates(), - AlgebraProfile::ApproximateFieldProfile => approximate_field_templates(), - AlgebraProfile::BooleanAlgebraProfile => boolean_algebra_templates(), - AlgebraProfile::BooleanAlgebraCollectionProfile => boolean_algebra_collection_templates(), - AlgebraProfile::FreeMonoidScalarProfile => free_monoid_scalar_templates(), - AlgebraProfile::FreeMonoidCollectionProfile => free_monoid_collection_templates(), - AlgebraProfile::PartialFunctionProfile => partial_function_templates(), - } + AlgebraProfile::OrderedRingProfile => ordered_ring_templates(), + AlgebraProfile::ApproximateFieldProfile => approximate_field_templates(), + AlgebraProfile::BooleanAlgebraProfile => boolean_algebra_templates(), + AlgebraProfile::BooleanAlgebraCollectionProfile => boolean_algebra_collection_templates(), + AlgebraProfile::FreeMonoidScalarProfile => free_monoid_scalar_templates(), + AlgebraProfile::FreeMonoidCollectionProfile => free_monoid_collection_templates(), + AlgebraProfile::PartialFunctionProfile => partial_function_templates(), +} } pub fn algebra_type_param_names(profile: AlgebraProfile) -> Rc> { match profile { - AlgebraProfile::OrderedRingProfile => Rc::new(vec![]), - AlgebraProfile::ApproximateFieldProfile => Rc::new(vec![]), - AlgebraProfile::BooleanAlgebraProfile => Rc::new(vec![]), - AlgebraProfile::BooleanAlgebraCollectionProfile => Rc::new(vec!["T".to_string()]), - AlgebraProfile::FreeMonoidScalarProfile => Rc::new(vec![]), - AlgebraProfile::FreeMonoidCollectionProfile => Rc::new(vec!["T".to_string()]), - AlgebraProfile::PartialFunctionProfile => Rc::new(vec!["K".to_string(), "V".to_string()]), - } + AlgebraProfile::OrderedRingProfile => Rc::new(vec![]), + AlgebraProfile::ApproximateFieldProfile => Rc::new(vec![]), + AlgebraProfile::BooleanAlgebraProfile => Rc::new(vec![]), + AlgebraProfile::BooleanAlgebraCollectionProfile => Rc::new(vec!["T".to_string()]), + AlgebraProfile::FreeMonoidScalarProfile => Rc::new(vec![]), + AlgebraProfile::FreeMonoidCollectionProfile => Rc::new(vec!["T".to_string()]), + AlgebraProfile::PartialFunctionProfile => Rc::new(vec!["K".to_string(), "V".to_string()]), +} } diff --git a/src/v2/stage0/src/std_coercion.rs b/src/v2/stage0/src/std_coercion.rs index 84ed2736a2a..37e8e60fe56 100644 --- a/src/v2/stage0/src/std_coercion.rs +++ b/src/v2/stage0/src/std_coercion.rs @@ -1,11 +1,11 @@ // Generated by v2 compiler -- do not edit. // Source module: std.coercion -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct TypeCheckpoint { @@ -57,31 +57,9 @@ pub fn dag_cast_rules() -> Rc>> { } pub fn dag_can_cast(source_type: String, target_type: String) -> bool { - { - let mut __found = false; - for r in dag_cast_rules().iter().cloned() { - if ((r.from_type.clone().as_str() == source_type.clone().as_str()) - && (r.to_type.clone().as_str() == target_type.clone().as_str())) - { - __found = true; - break; - } - } - __found - } + { let mut __found = false; for r in dag_cast_rules().iter().cloned() { if ((r.from_type.clone().as_str() == source_type.clone().as_str()) && (r.to_type.clone().as_str() == target_type.clone().as_str())) { __found = true; break; } } __found } } pub fn is_dag_cast_domain_type(name: String) -> bool { - { - let mut __found = false; - for r in dag_cast_rules().iter().cloned() { - if ((r.from_type.clone().as_str() == name.clone().as_str()) - || (r.to_type.clone().as_str() == name.clone().as_str())) - { - __found = true; - break; - } - } - __found - } + { let mut __found = false; for r in dag_cast_rules().iter().cloned() { if ((r.from_type.clone().as_str() == name.clone().as_str()) || (r.to_type.clone().as_str() == name.clone().as_str())) { __found = true; break; } } __found } } diff --git a/src/v2/stage0/src/std_computation.rs b/src/v2/stage0/src/std_computation.rs index 73550cefcca..bf35aa694af 100644 --- a/src/v2/stage0/src/std_computation.rs +++ b/src/v2/stage0/src/std_computation.rs @@ -1,46 +1,53 @@ // Generated by v2 compiler -- do not edit. // Source module: std.computation -use self::CallPattern::*; -use self::IterationDimension::*; -use self::IterationPrimitive::*; -use self::ShrinkFactor::*; -use self::SizeBound::*; -use crate::std_algebra::AlgebraProfile::{ - ApproximateFieldProfile, BooleanAlgebraCollectionProfile, BooleanAlgebraProfile, - FreeMonoidCollectionProfile, FreeMonoidScalarProfile, OrderedRingProfile, - PartialFunctionProfile, -}; -pub use crate::std_algebra::{kernel_algebra_profile, AlgebraProfile}; -use crate::std_termination::DescentEvidence::DescentUnknown; -use crate::std_termination::PositiveDescentAmount::{AdditionalStep, OneStep}; -use crate::std_termination::ProportionalDivisor::{DivideByTwo, StrictlyLarger}; -use crate::std_termination::RankingDimension::*; -pub use crate::std_termination::{ - positive_descent_count, DescentEvidence, PositiveDescentAmount, ProportionalDivisor, - RankingDimension, -}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_termination::{DescentEvidence, RankingDimension, PositiveDescentAmount, ProportionalDivisor, positive_descent_count}; +use crate::std_termination::DescentEvidence::{DescentUnknown}; +use crate::std_termination::PositiveDescentAmount::{OneStep, AdditionalStep}; +use crate::std_termination::ProportionalDivisor::{DivideByTwo, StrictlyLarger}; +use crate::std_termination::RankingDimension::*; +pub use crate::std_algebra::{AlgebraProfile, kernel_algebra_profile}; +use crate::std_algebra::AlgebraProfile::{OrderedRingProfile, ApproximateFieldProfile, BooleanAlgebraProfile, BooleanAlgebraCollectionProfile, FreeMonoidScalarProfile, FreeMonoidCollectionProfile, PartialFunctionProfile}; +use self::SizeBound::*; +use self::CallPattern::*; +use self::ShrinkFactor::*; +use self::IterationPrimitive::*; +use self::IterationDimension::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum SizeBound { - CollectionSize { param: String }, - ParserStreamSize { witness: String }, - WorklistDrainSize { element: String }, - TreeSize { param: String }, - ArithmeticParam { param: String }, + CollectionSize { + param: String, + }, + ParserStreamSize { + witness: String, + }, + WorklistDrainSize { + element: String, + }, + TreeSize { + param: String, + }, + ArithmeticParam { + param: String, + }, ExplicitCountZero, - ExplicitCountPositive { steps: Rc }, + ExplicitCountPositive { + steps: Rc, + }, Forever, } pub fn tree_size_bound(param: String) -> Rc { - Rc::new(SizeBound::TreeSize { param: param }) + Rc::new(SizeBound::TreeSize { + param: param, +}) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -77,8 +84,12 @@ pub enum CallPattern { #[serde(tag = "_variant")] pub enum ShrinkFactor { UnitShrink, - ConstantShrink { steps: Rc }, - ProportionalShrink { divisor: Rc }, + ConstantShrink { + steps: Rc, + }, + ProportionalShrink { + divisor: Rc, + }, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -99,94 +110,97 @@ pub enum IterationPrimitive { pub fn lower_call_pattern(pattern: Rc) -> Rc { match (*pattern).clone() { - CallPattern::ChildAccessorCall { accessor: a, .. } => Rc::new(LoweringTarget { - primitive: IterationPrimitive::Descend, - bound: Rc::new(SizeBound::TreeSize { param: a.clone() }), - evidence: DescentEvidence::Strict, - factor: None, - }), - CallPattern::CollectionShrinkCall { - amount: p, - collection: c, - .. - } => Rc::new(LoweringTarget { - primitive: IterationPrimitive::Fold, - bound: Rc::new(SizeBound::CollectionSize { param: c.clone() }), - evidence: DescentEvidence::Strict, - factor: Some(Rc::new(ShrinkFactor::ConstantShrink { steps: p.clone() })), - }), - CallPattern::ArithmeticSubtractCall { - steps: p, - ring_param: r, - .. - } => Rc::new(LoweringTarget { - primitive: IterationPrimitive::Repeat, - bound: Rc::new(SizeBound::ArithmeticParam { param: r.clone() }), - evidence: DescentEvidence::Strict, - factor: Some(Rc::new(ShrinkFactor::ConstantShrink { steps: p.clone() })), - }), - CallPattern::ArithmeticDivideCall { - divisor: d, - ring_param: r, - .. - } => Rc::new(LoweringTarget { - primitive: IterationPrimitive::Repeat, - bound: Rc::new(SizeBound::ArithmeticParam { param: r.clone() }), - evidence: DescentEvidence::Strict, - factor: Some(Rc::new(ShrinkFactor::ProportionalShrink { - divisor: d.clone(), - })), - }), - CallPattern::ParserAdvanceCall { witness: w, .. } => Rc::new(LoweringTarget { - primitive: IterationPrimitive::Fold, - bound: Rc::new(SizeBound::ParserStreamSize { witness: w.clone() }), - evidence: DescentEvidence::Strict, - factor: None, - }), - CallPattern::WorklistDrainCall { element: e, .. } => Rc::new(LoweringTarget { - primitive: IterationPrimitive::Fold, - bound: Rc::new(SizeBound::WorklistDrainSize { element: e.clone() }), - evidence: DescentEvidence::Strict, - factor: None, - }), - CallPattern::FoldBodyCall { - outer_collection: oc, - .. - } => Rc::new(LoweringTarget { - primitive: IterationPrimitive::Fold, - bound: Rc::new(SizeBound::CollectionSize { param: oc.clone() }), - evidence: DescentEvidence::NonIncreasing, - factor: None, - }), - CallPattern::SameArgumentCall => Rc::new(LoweringTarget { - primitive: IterationPrimitive::Repeat, - bound: Rc::new(SizeBound::Forever), - evidence: DescentEvidence::NonIncreasing, - factor: None, - }), - } + CallPattern::ChildAccessorCall { accessor: a, .. } => Rc::new(LoweringTarget { + primitive: IterationPrimitive::Descend, + bound: Rc::new(SizeBound::TreeSize { + param: a.clone(), +}), + evidence: DescentEvidence::Strict, + factor: None, +}), + CallPattern::CollectionShrinkCall { amount: p, collection: c, .. } => Rc::new(LoweringTarget { + primitive: IterationPrimitive::Fold, + bound: Rc::new(SizeBound::CollectionSize { + param: c.clone(), +}), + evidence: DescentEvidence::Strict, + factor: Some(Rc::new(ShrinkFactor::ConstantShrink { + steps: p.clone(), +})), +}), + CallPattern::ArithmeticSubtractCall { steps: p, ring_param: r, .. } => Rc::new(LoweringTarget { + primitive: IterationPrimitive::Repeat, + bound: Rc::new(SizeBound::ArithmeticParam { + param: r.clone(), +}), + evidence: DescentEvidence::Strict, + factor: Some(Rc::new(ShrinkFactor::ConstantShrink { + steps: p.clone(), +})), +}), + CallPattern::ArithmeticDivideCall { divisor: d, ring_param: r, .. } => Rc::new(LoweringTarget { + primitive: IterationPrimitive::Repeat, + bound: Rc::new(SizeBound::ArithmeticParam { + param: r.clone(), +}), + evidence: DescentEvidence::Strict, + factor: Some(Rc::new(ShrinkFactor::ProportionalShrink { + divisor: d.clone(), +})), +}), + CallPattern::ParserAdvanceCall { witness: w, .. } => Rc::new(LoweringTarget { + primitive: IterationPrimitive::Fold, + bound: Rc::new(SizeBound::ParserStreamSize { + witness: w.clone(), +}), + evidence: DescentEvidence::Strict, + factor: None, +}), + CallPattern::WorklistDrainCall { element: e, .. } => Rc::new(LoweringTarget { + primitive: IterationPrimitive::Fold, + bound: Rc::new(SizeBound::WorklistDrainSize { + element: e.clone(), +}), + evidence: DescentEvidence::Strict, + factor: None, +}), + CallPattern::FoldBodyCall { outer_collection: oc, .. } => Rc::new(LoweringTarget { + primitive: IterationPrimitive::Fold, + bound: Rc::new(SizeBound::CollectionSize { + param: oc.clone(), +}), + evidence: DescentEvidence::NonIncreasing, + factor: None, +}), + CallPattern::SameArgumentCall => Rc::new(LoweringTarget { + primitive: IterationPrimitive::Repeat, + bound: Rc::new(SizeBound::Forever), + evidence: DescentEvidence::NonIncreasing, + factor: None, +}), +} } pub fn size_bound_param(bound: Rc) -> Option { match (*bound).clone() { - SizeBound::TreeSize { param: p, .. } => Some(p.clone()), - SizeBound::CollectionSize { param: p, .. } => Some(p.clone()), - SizeBound::ParserStreamSize { witness: w, .. } => Some(w.clone()), - SizeBound::WorklistDrainSize { element: e, .. } => Some(e.clone()), - SizeBound::ArithmeticParam { param: p, .. } => Some(p.clone()), - SizeBound::ExplicitCountZero => None, - SizeBound::ExplicitCountPositive { .. } => None, - SizeBound::Forever => None, - } + SizeBound::TreeSize { param: p, .. } => Some(p.clone()), + SizeBound::CollectionSize { param: p, .. } => Some(p.clone()), + SizeBound::ParserStreamSize { witness: w, .. } => Some(w.clone()), + SizeBound::WorklistDrainSize { element: e, .. } => Some(e.clone()), + SizeBound::ArithmeticParam { param: p, .. } => Some(p.clone()), + SizeBound::ExplicitCountZero => None, + SizeBound::ExplicitCountPositive { .. } => None, + SizeBound::Forever => None, +} } pub fn is_constant_bound(bound: Rc) -> bool { match (*bound).clone() { - SizeBound::ExplicitCountZero => true, - SizeBound::ExplicitCountPositive { .. } => true, - SizeBound::Forever => true, - _ => false, - } + SizeBound::ExplicitCountZero => true, + SizeBound::ExplicitCountPositive { .. } => true, + SizeBound::Forever => true, + _ => false, +} } pub fn forever_iteration_bound() -> i64 { @@ -195,13 +209,11 @@ pub fn forever_iteration_bound() -> i64 { pub fn constant_bound_value(bound: Rc) -> Option { match (*bound).clone() { - SizeBound::ExplicitCountZero => Some(0), - SizeBound::ExplicitCountPositive { steps: s, .. } => { - Some(positive_descent_count(s.clone())) - } - SizeBound::Forever => Some(forever_iteration_bound()), - _ => None, - } + SizeBound::ExplicitCountZero => Some(0), + SizeBound::ExplicitCountPositive { steps: s, .. } => Some(positive_descent_count(s.clone())), + SizeBound::Forever => Some(forever_iteration_bound()), + _ => None, +} } #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] @@ -214,14 +226,14 @@ pub enum IterationDimension { pub fn algebra_profile_to_dimension(profile: AlgebraProfile) -> Option { match profile { - AlgebraProfile::FreeMonoidCollectionProfile => Some(IterationDimension::CollectionFold), - AlgebraProfile::FreeMonoidScalarProfile => Some(IterationDimension::CollectionFold), - AlgebraProfile::BooleanAlgebraCollectionProfile => Some(IterationDimension::CollectionFold), - AlgebraProfile::PartialFunctionProfile => Some(IterationDimension::CollectionFold), - AlgebraProfile::OrderedRingProfile => Some(IterationDimension::ArithmeticRepeat), - AlgebraProfile::ApproximateFieldProfile => Some(IterationDimension::ArithmeticRepeat), - AlgebraProfile::BooleanAlgebraProfile => None, - } + AlgebraProfile::FreeMonoidCollectionProfile => Some(IterationDimension::CollectionFold), + AlgebraProfile::FreeMonoidScalarProfile => Some(IterationDimension::CollectionFold), + AlgebraProfile::BooleanAlgebraCollectionProfile => Some(IterationDimension::CollectionFold), + AlgebraProfile::PartialFunctionProfile => Some(IterationDimension::CollectionFold), + AlgebraProfile::OrderedRingProfile => Some(IterationDimension::ArithmeticRepeat), + AlgebraProfile::ApproximateFieldProfile => Some(IterationDimension::ArithmeticRepeat), + AlgebraProfile::BooleanAlgebraProfile => None, +} } pub fn type_iteration_dimension(type_name: &String) -> Option { @@ -229,8 +241,8 @@ pub fn type_iteration_dimension(type_name: &String) -> Option algebra_profile_to_dimension(p.clone()), - None => None, - } + Some(p) => algebra_profile_to_dimension(p.clone()), + None => None, +} } } diff --git a/src/v2/stage0/src/std_effects.rs b/src/v2/stage0/src/std_effects.rs index 7f46ca05f6f..bac6fa5a39c 100644 --- a/src/v2/stage0/src/std_effects.rs +++ b/src/v2/stage0/src/std_effects.rs @@ -1,29 +1,31 @@ // Generated by v2 compiler -- do not edit. // Source module: std.effects -use self::DeriveOpEffectResult::*; +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{HttpMethod}; +use crate::std_types::HttpMethod::{GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS}; +pub use crate::std_http_path::{PathTemplate, PathTemplateParseResult, parse_path_template, has_path_params, last_path_param}; +use crate::std_http_path::PathTemplateParseResult::{ParsedPathTemplate, MalformedPathTemplate}; use self::EffectShape::*; -use self::IdempotencyEvidence::*; use self::KeySource::*; +use self::IdempotencyEvidence::*; +use self::DeriveOpEffectResult::*; use self::ModifierAgreement::*; -use crate::std_http_path::PathTemplateParseResult::{MalformedPathTemplate, ParsedPathTemplate}; -pub use crate::std_http_path::{ - has_path_params, last_path_param, parse_path_template, PathTemplate, PathTemplateParseResult, -}; -pub use crate::std_types::HttpMethod; -use crate::std_types::HttpMethod::{DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum EffectShape { ReadEffect, - UpsertEffect { key_source: Rc }, - DeleteEffect { key_source: Rc }, + UpsertEffect { + key_source: Rc, + }, + DeleteEffect { + key_source: Rc, + }, CreateEffect, AppendEffect, } @@ -31,12 +33,8 @@ impl EffectShape { pub fn key_source(&self) -> Rc { match self { EffectShape::ReadEffect => panic!("no key_source on unit variant"), - EffectShape::UpsertEffect { - key_source: __val, .. - } => __val.clone(), - EffectShape::DeleteEffect { - key_source: __val, .. - } => __val.clone(), + EffectShape::UpsertEffect { key_source: __val, .. } => __val.clone(), + EffectShape::DeleteEffect { key_source: __val, .. } => __val.clone(), EffectShape::CreateEffect => panic!("no key_source on unit variant"), EffectShape::AppendEffect => panic!("no key_source on unit variant"), } @@ -46,9 +44,15 @@ impl EffectShape { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum KeySource { - PathParam { param: String }, - InputField { field: String }, - CompositeKey { fields: Rc> }, + PathParam { + param: String, + }, + InputField { + field: String, + }, + CompositeKey { + fields: Rc>, + }, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -75,12 +79,12 @@ impl IdempotencyEvidence { pub fn is_idempotent_effect(shape: Rc) -> bool { match (*shape).clone() { - EffectShape::ReadEffect => true, - EffectShape::UpsertEffect { .. } => true, - EffectShape::DeleteEffect { .. } => true, - EffectShape::CreateEffect => false, - EffectShape::AppendEffect => false, - } + EffectShape::ReadEffect => true, + EffectShape::UpsertEffect { .. } => true, + EffectShape::DeleteEffect { .. } => true, + EffectShape::CreateEffect => false, + EffectShape::AppendEffect => false, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -99,29 +103,21 @@ pub struct OperationEffect { pub fn compose_effects(effects: &Rc>>) -> Rc { { - let non_idempotent = Rc::new({ - let mut __result = Vec::new(); - for e in effects.clone().iter().cloned() { - if match (*e.evidence.clone()).clone() { - IdempotencyEvidence::NonIdempotent { .. } => true, - _ => false, - } { - __result.push(e); - } - } - __result - }); - let breaker = non_idempotent.clone().first().cloned(); - let breaker_name = match breaker { - Some(op) => Some(op.operation_name.clone()), - None => None, - }; - Rc::new(ComposedEffect { - operations: effects.clone(), - idempotent: ((non_idempotent.clone().len() as i64) == 0), - breaking_operation: breaker_name, - }) - } + let non_idempotent = Rc::new({ let mut __result = Vec::new(); for e in effects.clone().iter().cloned() { if match (*e.evidence.clone()).clone() { + IdempotencyEvidence::NonIdempotent { .. } => true, + _ => false, +} { __result.push(e); } } __result }); +let breaker = non_idempotent.clone().first().cloned(); +let breaker_name = match breaker { + Some(op) => Some(op.operation_name.clone()), + None => None, +}; +Rc::new(ComposedEffect { + operations: effects.clone(), + idempotent: ((non_idempotent.clone().len() as i64) == 0), + breaking_operation: breaker_name, +}) +} } pub fn parse_http_method(raw: &String) -> Option { @@ -185,53 +181,76 @@ pub enum DeriveOpEffectResult { pub fn derive_effect_shape(method: HttpMethod, path: Rc) -> Rc { match method { - HttpMethod::GET => Rc::new(EffectShape::ReadEffect), - HttpMethod::HEAD => Rc::new(EffectShape::ReadEffect), - HttpMethod::OPTIONS => Rc::new(EffectShape::ReadEffect), - HttpMethod::POST => Rc::new(EffectShape::CreateEffect), - HttpMethod::DELETE => match last_path_param(path) { - Some(p) => Rc::new(EffectShape::DeleteEffect { - key_source: Rc::new(KeySource::PathParam { param: p.clone() }), - }), - None => Rc::new(EffectShape::CreateEffect), - }, - HttpMethod::PUT => match last_path_param(path) { - Some(p) => Rc::new(EffectShape::UpsertEffect { - key_source: Rc::new(KeySource::PathParam { param: p.clone() }), - }), - None => Rc::new(EffectShape::CreateEffect), - }, - HttpMethod::PATCH => match last_path_param(path) { - Some(p) => Rc::new(EffectShape::UpsertEffect { - key_source: Rc::new(KeySource::PathParam { param: p.clone() }), - }), - None => Rc::new(EffectShape::CreateEffect), - }, - } + HttpMethod::GET => Rc::new(EffectShape::ReadEffect), + HttpMethod::HEAD => Rc::new(EffectShape::ReadEffect), + HttpMethod::OPTIONS => Rc::new(EffectShape::ReadEffect), + HttpMethod::POST => Rc::new(EffectShape::CreateEffect), + HttpMethod::DELETE => match last_path_param(path) { + Some(p) => Rc::new(EffectShape::DeleteEffect { + key_source: Rc::new(KeySource::PathParam { + param: p.clone(), +}), +}), + None => Rc::new(EffectShape::CreateEffect), +}, + HttpMethod::PUT => match last_path_param(path) { + Some(p) => Rc::new(EffectShape::UpsertEffect { + key_source: Rc::new(KeySource::PathParam { + param: p.clone(), +}), +}), + None => Rc::new(EffectShape::CreateEffect), +}, + HttpMethod::PATCH => match last_path_param(path) { + Some(p) => Rc::new(EffectShape::UpsertEffect { + key_source: Rc::new(KeySource::PathParam { + param: p.clone(), +}), +}), + None => Rc::new(EffectShape::CreateEffect), +}, +} } -pub fn derive_op_effect( - operation_name: String, - method: HttpMethod, - path: Rc, -) -> Rc { - let shape = derive_effect_shape(method.clone(), path.clone()); - Rc::new(DeriveOpEffectResult::DerivedEffect { - effect: Rc::new(DerivedOpEffect { - operation_name: operation_name, - method: method.clone(), - path_template: path.clone(), - shape: shape, - }), - }) +pub fn derive_op_effect(operation_name: String, method_str: &String, path_str: String) -> Rc { + match parse_http_method(&method_str) { + None => Rc::new(DeriveOpEffectResult::UnknownHttpMethodInput { + operation_name: operation_name, + method_str: method_str.clone(), +}), + Some(method) => match (*parse_path_template(&path_str)).clone() { + PathTemplateParseResult::ParsedPathTemplate { template: path, .. } => { + let shape = derive_effect_shape(method.clone(), path.clone()); +Rc::new(DeriveOpEffectResult::DerivedEffect { + effect: Rc::new(DerivedOpEffect { + operation_name: operation_name, + method: method.clone(), + path_template: path.clone(), + shape: shape, +}), +}) +}, + PathTemplateParseResult::MalformedPathTemplate { raw: raw_path, segment, reason, .. } => Rc::new(DeriveOpEffectResult::MalformedPathInput { + operation_name: operation_name, + method: method.clone(), + raw_path: raw_path.clone(), + segment: segment.clone(), + reason: reason.clone(), +}), +}, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum ModifierAgreement { Agrees, - Disagrees { reason: String }, - DerivationUnknown { reason: String }, + Disagrees { + reason: String, + }, + DerivationUnknown { + reason: String, + }, } impl ModifierAgreement { pub fn reason(&self) -> String { @@ -252,14 +271,10 @@ pub struct ModifierCheck { pub agreement: Rc, } -pub fn check_modifier_vs_derivation( - op: &Rc, - declared_idempotent: &bool, - declared_readonly: &bool, -) -> Rc { +pub fn check_modifier_vs_derivation(op: &Rc, declared_idempotent: &bool, declared_readonly: &bool) -> Rc { { let derived_idempotent = is_idempotent_effect(op.shape.clone()); - let agreement = if (declared_idempotent.clone() && derived_idempotent.clone()) { +let agreement = if (declared_idempotent.clone() && derived_idempotent.clone()) { Rc::new(ModifierAgreement::Agrees) } else { if (declared_idempotent.clone() && !derived_idempotent.clone()) { @@ -274,27 +289,26 @@ pub fn check_modifier_vs_derivation( } else { if (!declared_idempotent.clone() && declared_readonly.clone()) { match op.method.clone() { - HttpMethod::GET => Rc::new(ModifierAgreement::Agrees), - HttpMethod::HEAD => Rc::new(ModifierAgreement::Agrees), - HttpMethod::OPTIONS => Rc::new(ModifierAgreement::Agrees), - _ => Rc::new(ModifierAgreement::Disagrees { - reason: "readonly declared but method is not GET/HEAD/OPTIONS" - .to_string(), - }), - } + HttpMethod::GET => Rc::new(ModifierAgreement::Agrees), + HttpMethod::HEAD => Rc::new(ModifierAgreement::Agrees), + HttpMethod::OPTIONS => Rc::new(ModifierAgreement::Agrees), + _ => Rc::new(ModifierAgreement::Disagrees { + reason: "readonly declared but method is not GET/HEAD/OPTIONS".to_string(), +}), +} } else { Rc::new(ModifierAgreement::Agrees) } } }; - Rc::new(ModifierCheck { - operation_name: op.operation_name.clone(), - declared_idempotent: declared_idempotent.clone(), - declared_readonly: declared_readonly.clone(), - derived_shape: op.shape.clone(), - agreement: agreement, - }) - } +Rc::new(ModifierCheck { + operation_name: op.operation_name.clone(), + declared_idempotent: declared_idempotent.clone(), + declared_readonly: declared_readonly.clone(), + derived_shape: op.shape.clone(), + agreement: agreement, +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -305,32 +319,13 @@ pub struct IdempotencyTestObligation { pub witness_required: bool, } -pub fn generate_idempotency_obligations( - ops: Rc>>, -) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for o in Rc::new({ - let mut __result = Vec::new(); - for o in ops.iter().cloned() { - if is_idempotent_effect(o.shape.clone()) { - __result.push(o); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(Rc::new(IdempotencyTestObligation { - operation_name: o.operation_name.clone(), - effect_shape: o.shape.clone(), - claim: "f(f(x)) == f(x)".to_string(), - witness_required: true, - })); - } - __result - }) +pub fn generate_idempotency_obligations(ops: Rc>>) -> Rc>> { + Rc::new({ let mut __result = Vec::new(); for o in Rc::new({ let mut __result = Vec::new(); for o in ops.iter().cloned() { if is_idempotent_effect(o.shape.clone()) { __result.push(o); } } __result }).iter().cloned() { __result.push(Rc::new(IdempotencyTestObligation { + operation_name: o.operation_name.clone(), + effect_shape: o.shape.clone(), + claim: "f(f(x)) == f(x)".to_string(), + witness_required: true, +})); } __result }) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] diff --git a/src/v2/stage0/src/std_error_primitives.rs b/src/v2/stage0/src/std_error_primitives.rs index a3fc3d2d54b..52d156a47f2 100644 --- a/src/v2/stage0/src/std_error_primitives.rs +++ b/src/v2/stage0/src/std_error_primitives.rs @@ -3,19 +3,23 @@ #![allow(non_camel_case_types)] -use self::DivError::*; -use self::Result::*; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +use self::Result::*; +use self::DivError::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum Result { - Ok { value: Box }, - Err { value: Box }, + Ok { + value: Box, + }, + Err { + value: Box, + }, } #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] diff --git a/src/v2/stage0/src/std_graph.rs b/src/v2/stage0/src/std_graph.rs index 44199c2545f..cfcaeb9aab9 100644 --- a/src/v2/stage0/src/std_graph.rs +++ b/src/v2/stage0/src/std_graph.rs @@ -1,13 +1,13 @@ // Generated by v2 compiler -- do not edit. // Source module: std.graph -use crate::std_termination::DescentEvidence::{DescentUnknown, NonIncreasing, Strict}; -pub use crate::std_termination::{DescentEvidence, ProofEdge, TerminationProof}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_termination::{ProofEdge, DescentEvidence, TerminationProof}; +use crate::std_termination::DescentEvidence::{Strict, NonIncreasing, DescentUnknown}; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct CallGraph { @@ -38,240 +38,135 @@ pub fn set_has(m: Rc>, key: String) -> bool { } pub fn seed_adjacency_map(names: Rc>) -> Rc>>> { - names.iter().cloned().fold( - v2_rt::rc_empty_map::>>(), - |acc: Rc>>>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), Rc::new(vec![])) - }, - ) + names.iter().cloned().fold(v2_rt::rc_empty_map::>>(), |acc: Rc>>>, name: String| v2_rt::rc_map_insert(acc, name.clone(), Rc::new(vec![]))) } -pub fn build_call_graph_from_proof_edges( - names: &Rc>, - edges: Rc>>, -) -> Rc { +pub fn build_call_graph_from_proof_edges(names: &Rc>, edges: Rc>>) -> Rc { { let initial_forward = seed_adjacency_map(names.clone()); - let initial_reverse = seed_adjacency_map(names.clone()); - Rc::new({ - let mut __result = Vec::new(); - for e in edges.iter().cloned() { - if (e.caller.clone().as_str() != e.callee.clone().as_str()) { - __result.push(e); - } - } - __result - }) - .iter() - .cloned() - .fold( - Rc::new(CallGraph { - forward: initial_forward, - reverse: initial_reverse, - }), - |acc: Rc, edge: Rc| { - let forward_neighbors = - match v2_rt::map_get(&acc.forward.clone(), edge.caller.clone()) { - Some(ns) => v2_rt::concat(ns.clone(), Rc::new(vec![edge.callee.clone()])), - None => Rc::new(vec![edge.callee.clone()]), - }; - let reverse_neighbors = - match v2_rt::map_get(&acc.reverse.clone(), edge.callee.clone()) { - Some(ns) => v2_rt::concat(ns.clone(), Rc::new(vec![edge.caller.clone()])), - None => Rc::new(vec![edge.caller.clone()]), - }; - Rc::new(CallGraph { - forward: v2_rt::rc_map_insert( - acc.forward.clone(), - edge.caller.clone(), - forward_neighbors.clone(), - ), - reverse: v2_rt::rc_map_insert( - acc.reverse.clone(), - edge.callee.clone(), - reverse_neighbors.clone(), - ), - }) - }, - ) - } +let initial_reverse = seed_adjacency_map(names.clone()); +Rc::new({ let mut __result = Vec::new(); for e in edges.iter().cloned() { if (e.caller.clone().as_str() != e.callee.clone().as_str()) { __result.push(e); } } __result }).iter().cloned().fold(Rc::new(CallGraph { + forward: initial_forward, + reverse: initial_reverse, +}), |acc: Rc, edge: Rc| { + let forward_neighbors = match v2_rt::map_get(&acc.forward.clone(), edge.caller.clone()) { + Some(ns) => v2_rt::concat(ns.clone(), Rc::new(vec![edge.callee.clone()])), + None => Rc::new(vec![edge.callee.clone()]), +}; +let reverse_neighbors = match v2_rt::map_get(&acc.reverse.clone(), edge.callee.clone()) { + Some(ns) => v2_rt::concat(ns.clone(), Rc::new(vec![edge.caller.clone()])), + None => Rc::new(vec![edge.caller.clone()]), +}; +Rc::new(CallGraph { + forward: v2_rt::rc_map_insert(acc.forward.clone(), edge.caller.clone(), forward_neighbors.clone()), + reverse: v2_rt::rc_map_insert(acc.reverse.clone(), edge.callee.clone(), reverse_neighbors.clone()), +}) +}) +} } -pub fn dfs_finish_order( - node: &String, - adjacency: &Rc>>>, - acc: &Rc, -) -> Rc { +pub fn dfs_finish_order(node: &String, adjacency: &Rc>>>, acc: &Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { if set_has(acc.visited.clone(), node.clone()) { acc.clone() } else { { let next_visited = v2_rt::rc_map_insert(acc.visited.clone(), node.clone(), true); - let neighbors = match v2_rt::map_get(&adjacency, node.clone()) { - Some(ns) => ns.clone(), - None => Rc::new(vec![]), - }; - let explored = neighbors.iter().cloned().fold( - Rc::new(DfsFinishAcc { - visited: next_visited, - order: acc.order.clone(), - }), - |inner: Rc, neighbor: String| { - dfs_finish_order(&neighbor, &adjacency, &inner) - }, - ); - Rc::new(DfsFinishAcc { - visited: explored.visited.clone(), - order: v2_rt::rc_list_push(explored.order.clone(), node.clone()), - }) - } +let neighbors = match v2_rt::map_get(&adjacency, node.clone()) { + Some(ns) => ns.clone(), + None => Rc::new(vec![]), +}; +let explored = neighbors.iter().cloned().fold(Rc::new(DfsFinishAcc { + visited: next_visited, + order: acc.order.clone(), +}), |inner: Rc, neighbor: String| dfs_finish_order(&neighbor, &adjacency, &inner)); +Rc::new(DfsFinishAcc { + visited: explored.visited.clone(), + order: v2_rt::rc_list_push(explored.order.clone(), node.clone()), +}) +} } }) } -pub fn dfs_collect_component( - node: &String, - adjacency: &Rc>>>, - acc: &Rc, -) -> Rc { +pub fn dfs_collect_component(node: &String, adjacency: &Rc>>>, acc: &Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { if set_has(acc.visited.clone(), node.clone()) { acc.clone() } else { { let next_visited = v2_rt::rc_map_insert(acc.visited.clone(), node.clone(), true); - let next_members = v2_rt::rc_list_push(acc.members.clone(), node.clone()); - let neighbors = match v2_rt::map_get(&adjacency, node.clone()) { - Some(ns) => ns.clone(), - None => Rc::new(vec![]), - }; - neighbors.iter().cloned().fold( - Rc::new(SccComponentAcc { - visited: next_visited, - members: next_members, - }), - |inner: Rc, neighbor: String| { - dfs_collect_component(&neighbor, &adjacency, &inner) - }, - ) - } +let next_members = v2_rt::rc_list_push(acc.members.clone(), node.clone()); +let neighbors = match v2_rt::map_get(&adjacency, node.clone()) { + Some(ns) => ns.clone(), + None => Rc::new(vec![]), +}; +neighbors.iter().cloned().fold(Rc::new(SccComponentAcc { + visited: next_visited, + members: next_members, +}), |inner: Rc, neighbor: String| dfs_collect_component(&neighbor, &adjacency, &inner)) +} } }) } pub fn graph_has_multi_node_scc(names: Rc>, graph: Rc) -> bool { { - let finish = names.iter().cloned().fold( - Rc::new(DfsFinishAcc { - visited: v2_rt::rc_empty_map::(), - order: Rc::new(vec![]), - }), - |acc: Rc, name: String| { - dfs_finish_order(&name, &graph.forward.clone(), &acc) - }, - ); - let result = v2_rt::reverse(finish.order.clone()).iter().cloned().fold( - Rc::new(SccCycleAcc { - visited: v2_rt::rc_empty_map::(), - has_cycle: false, - }), - |acc: Rc, name: String| { - if (acc.has_cycle.clone() || set_has(acc.visited.clone(), name.clone())) { - acc.clone() - } else { - { - let component = dfs_collect_component( - &name, - &graph.reverse.clone(), - &Rc::new(SccComponentAcc { - visited: acc.visited.clone(), - members: Rc::new(vec![]), - }), - ); - Rc::new(SccCycleAcc { - visited: component.visited.clone(), - has_cycle: ((component.members.clone().len() as i64) > 1), - }) - } - } - }, - ); - result.has_cycle.clone() - } + let finish = names.iter().cloned().fold(Rc::new(DfsFinishAcc { + visited: v2_rt::rc_empty_map::(), + order: Rc::new(vec![]), +}), |acc: Rc, name: String| dfs_finish_order(&name, &graph.forward.clone(), &acc)); +let result = v2_rt::reverse(finish.order.clone()).iter().cloned().fold(Rc::new(SccCycleAcc { + visited: v2_rt::rc_empty_map::(), + has_cycle: false, +}), |acc: Rc, name: String| if (acc.has_cycle.clone() || set_has(acc.visited.clone(), name.clone())) { + acc.clone() + } else { + { + let component = dfs_collect_component(&name, &graph.reverse.clone(), &Rc::new(SccComponentAcc { + visited: acc.visited.clone(), + members: Rc::new(vec![]), +})); +Rc::new(SccCycleAcc { + visited: component.visited.clone(), + has_cycle: ((component.members.clone().len() as i64) > 1), +}) +} + }); +result.has_cycle.clone() +} } pub fn is_lexicographic_descent(mut evidence: Rc>) -> bool { loop { match evidence.clone().first().cloned() { - None => { - break false; - } - Some(e) => match e.clone() { - DescentEvidence::Strict => { - break true; - } - DescentEvidence::NonIncreasing => { - let __tco_0 = Rc::new( - evidence - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - evidence = __tco_0; - continue; - } - DescentEvidence::DescentUnknown => { - break false; - } - }, - } - } + None => { break false; }, + Some(e) => { match e.clone() { + DescentEvidence::Strict => { break true; }, + DescentEvidence::NonIncreasing => { { + let __tco_0 = Rc::new(evidence.iter().cloned().skip(1 as usize).collect::>()); +evidence = __tco_0; +continue; +} }, + DescentEvidence::DescentUnknown => { break false; }, +} }, +} +} } pub fn is_valid_proof(proof: Rc, edges: &Rc>>) -> bool { { let expected_dims = (proof.dimensions.clone().len() as i64); - let non_descending = Rc::new({ - let mut __result = Vec::new(); - for e in edges.clone().iter().cloned() { - if (((e.evidence.clone().len() as i64) != expected_dims.clone()) - || (is_lexicographic_descent(e.evidence.clone()) == false)) - { - __result.push(e); - } - } - __result - }); - let has_self_cycle = { - let mut __found = false; - for e in non_descending.clone().iter().cloned() { - if (e.caller.clone().as_str() == e.callee.clone().as_str()) { - __found = true; - break; - } - } - __found - }; - if has_self_cycle { +let non_descending = Rc::new({ let mut __result = Vec::new(); for e in edges.clone().iter().cloned() { if (((e.evidence.clone().len() as i64) != expected_dims.clone()) || (is_lexicographic_descent(e.evidence.clone()) == false)) { __result.push(e); } } __result }); +let has_self_cycle = { let mut __found = false; for e in non_descending.clone().iter().cloned() { if (e.caller.clone().as_str() == e.callee.clone().as_str()) { __found = true; break; } } __found }; +if has_self_cycle { false } else { { - let members = Rc::new({ - let mut __result = Vec::new(); - for e in edges.clone().iter().cloned() { - __result.extend( - (*Rc::new(vec![e.caller.clone(), e.callee.clone()])) - .iter() - .cloned(), - ); - } - __result - }); - let nd_graph = build_call_graph_from_proof_edges(&members, non_descending.clone()); - (graph_has_multi_node_scc(members.clone(), nd_graph) == false) - } + let members = Rc::new({ let mut __result = Vec::new(); for e in edges.clone().iter().cloned() { __result.extend((*Rc::new(vec![e.caller.clone(), e.callee.clone()])).iter().cloned()); } __result }); +let nd_graph = build_call_graph_from_proof_edges(&members, non_descending.clone()); +(graph_has_multi_node_scc(members.clone(), nd_graph) == false) +} } - } +} } diff --git a/src/v2/stage0/src/std_http_path.rs b/src/v2/stage0/src/std_http_path.rs index c67a8d74b5f..273e30ca225 100644 --- a/src/v2/stage0/src/std_http_path.rs +++ b/src/v2/stage0/src/std_http_path.rs @@ -1,20 +1,24 @@ // Generated by v2 compiler -- do not edit. // Source module: std.http_path -use self::PathSegmentTokensResult::*; -use self::PathTemplateParseResult::*; -use self::UrlPathToken::*; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +use self::UrlPathToken::*; +use self::PathSegmentTokensResult::*; +use self::PathTemplateParseResult::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum UrlPathToken { - LiteralToken { text: String }, - ParamToken { name: String }, + LiteralToken { + text: String, + }, + ParamToken { + name: String, + }, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -25,8 +29,13 @@ pub struct PathTemplate { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum PathSegmentTokensResult { - ParsedSegmentTokens { tokens: Rc>> }, - MalformedPathSegment { segment: String, reason: String }, + ParsedSegmentTokens { + tokens: Rc>>, + }, + MalformedPathSegment { + segment: String, + reason: String, + }, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -44,242 +53,150 @@ pub enum PathTemplateParseResult { pub fn parse_path_template(raw: &String) -> Rc { { - let path_only = match Rc::new( - raw.clone() - .split(&"?".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .first() - .cloned() - { - Some(p) => p.clone(), - None => raw.clone(), - }; - let segments = Rc::new({ - let mut __result = Vec::new(); - for s in Rc::new( - path_only - .split(&"/".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .iter() - .cloned() - { - if (s.clone().as_str() != "".to_string().as_str()) { - __result.push(s); - } - } - __result - }); - match segments.clone().first().cloned() { - None => Rc::new(PathTemplateParseResult::ParsedPathTemplate { - template: Rc::new(PathTemplate { - tokens: Rc::new(vec![]), - }), - }), - Some(first_seg) => match (*parse_segment_tokens(&first_seg)).clone() { - PathSegmentTokensResult::MalformedPathSegment { - segment: s, - reason: r, - .. - } => Rc::new(PathTemplateParseResult::MalformedPathTemplate { - raw: raw.clone(), - segment: s.clone(), - reason: r.clone(), - }), - PathSegmentTokensResult::ParsedSegmentTokens { - tokens: first_tokens, - .. - } => { - let parsed = Rc::new( - segments - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) - .iter() - .cloned() - .fold( - Rc::new(PathTemplateParseResult::ParsedPathTemplate { - template: Rc::new(PathTemplate { - tokens: first_tokens.clone(), - }), - }), - |acc: Rc, seg: String| match (*acc.clone()).clone() - { - PathTemplateParseResult::MalformedPathTemplate { .. } => acc.clone(), - PathTemplateParseResult::ParsedPathTemplate { - template: path, .. - } => match (*parse_segment_tokens(&seg)).clone() { - PathSegmentTokensResult::MalformedPathSegment { - segment: s, - reason: r, - .. - } => Rc::new(PathTemplateParseResult::MalformedPathTemplate { - raw: raw.clone(), - segment: s.clone(), - reason: r.clone(), - }), - PathSegmentTokensResult::ParsedSegmentTokens { - tokens: seg_tokens, - .. - } => Rc::new(PathTemplateParseResult::ParsedPathTemplate { - template: Rc::new(PathTemplate { - tokens: v2_rt::concat( - path.tokens.clone(), - seg_tokens.clone(), - ), - }), - }), - }, - }, - ); - parsed - } - }, - } - } + let path_only = match Rc::new(raw.clone().split(&"?".to_string()).map(|s| s.to_string()).collect::>()).first().cloned() { + Some(p) => p.clone(), + None => raw.clone(), +}; +let segments = Rc::new({ let mut __result = Vec::new(); for s in Rc::new(path_only.split(&"/".to_string()).map(|s| s.to_string()).collect::>()).iter().cloned() { if (s.clone().as_str() != "".to_string().as_str()) { __result.push(s); } } __result }); +match segments.clone().first().cloned() { + None => Rc::new(PathTemplateParseResult::ParsedPathTemplate { + template: Rc::new(PathTemplate { + tokens: Rc::new(vec![]), +}), +}), + Some(first_seg) => match (*parse_segment_tokens(&first_seg)).clone() { + PathSegmentTokensResult::MalformedPathSegment { segment: s, reason: r, .. } => Rc::new(PathTemplateParseResult::MalformedPathTemplate { + raw: raw.clone(), + segment: s.clone(), + reason: r.clone(), +}), + PathSegmentTokensResult::ParsedSegmentTokens { tokens: first_tokens, .. } => { + let parsed = Rc::new(segments.clone().iter().cloned().skip(1 as usize).collect::>()).iter().cloned().fold(Rc::new(PathTemplateParseResult::ParsedPathTemplate { + template: Rc::new(PathTemplate { + tokens: first_tokens.clone(), +}), +}), |acc: Rc, seg: String| match (*acc.clone()).clone() { + PathTemplateParseResult::MalformedPathTemplate { .. } => acc.clone(), + PathTemplateParseResult::ParsedPathTemplate { template: path, .. } => match (*parse_segment_tokens(&seg)).clone() { + PathSegmentTokensResult::MalformedPathSegment { segment: s, reason: r, .. } => Rc::new(PathTemplateParseResult::MalformedPathTemplate { + raw: raw.clone(), + segment: s.clone(), + reason: r.clone(), +}), + PathSegmentTokensResult::ParsedSegmentTokens { tokens: seg_tokens, .. } => Rc::new(PathTemplateParseResult::ParsedPathTemplate { + template: Rc::new(PathTemplate { + tokens: v2_rt::concat(path.tokens.clone(), seg_tokens.clone()), +}), +}), +}, +}); +parsed +}, +}, +} +} } pub fn parse_segment_tokens(seg: &String) -> Rc { if !v2_rt::contains(seg.clone(), "{".to_string()) { if v2_rt::contains(seg.clone(), "}".to_string()) { Rc::new(PathSegmentTokensResult::MalformedPathSegment { - segment: seg.clone(), - reason: "stray closing brace".to_string(), - }) + segment: seg.clone(), + reason: "stray closing brace".to_string(), +}) } else { Rc::new(PathSegmentTokensResult::ParsedSegmentTokens { - tokens: Rc::new(vec![Rc::new(UrlPathToken::LiteralToken { - text: seg.clone(), - })]), - }) + tokens: Rc::new(vec![Rc::new(UrlPathToken::LiteralToken { + text: seg.clone(), +})]), +}) } } else { { - let before_and_rest = Rc::new( - seg.clone() - .split(&"{".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - if ((before_and_rest.clone().len() as i64) != 2) { + let before_and_rest = Rc::new(seg.clone().split(&"{".to_string()).map(|s| s.to_string()).collect::>()); +if ((before_and_rest.clone().len() as i64) != 2) { return Rc::new(PathSegmentTokensResult::MalformedPathSegment { - segment: seg.clone(), - reason: "multiple opening braces in one segment".to_string(), - }); + segment: seg.clone(), + reason: "multiple opening braces in one segment".to_string(), +}) } - let prefix = match before_and_rest.clone().first().cloned() { - Some(p) => p.clone(), - None => "".to_string(), - }; - let after_open = match before_and_rest.clone().get(1 as usize).cloned() { - Some(r) => r.clone(), - None => "".to_string(), - }; - let name_and_suffix = Rc::new( - after_open - .split(&"}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - if (v2_rt::contains(prefix.clone(), "}".to_string()) - || ((name_and_suffix.clone().len() as i64) != 2)) - { +let prefix = match before_and_rest.clone().first().cloned() { + Some(p) => p.clone(), + None => "".to_string(), +}; +let after_open = match before_and_rest.clone().get(1 as usize).cloned() { + Some(r) => r.clone(), + None => "".to_string(), +}; +let name_and_suffix = Rc::new(after_open.split(&"}".to_string()).map(|s| s.to_string()).collect::>()); +if (v2_rt::contains(prefix.clone(), "}".to_string()) || ((name_and_suffix.clone().len() as i64) != 2)) { return Rc::new(PathSegmentTokensResult::MalformedPathSegment { - segment: seg.clone(), - reason: "missing closing brace or extra closing brace".to_string(), - }); + segment: seg.clone(), + reason: "missing closing brace or extra closing brace".to_string(), +}) } - let param_name = match name_and_suffix.clone().first().cloned() { - Some(p) => p.clone(), - None => "".to_string(), - }; - let suffix = match name_and_suffix.clone().get(1 as usize).cloned() { - Some(s) => s.clone(), - None => "".to_string(), - }; - let prefix_tokens = if (prefix.clone().as_str() != "".to_string().as_str()) { +let param_name = match name_and_suffix.clone().first().cloned() { + Some(p) => p.clone(), + None => "".to_string(), +}; +let suffix = match name_and_suffix.clone().get(1 as usize).cloned() { + Some(s) => s.clone(), + None => "".to_string(), +}; +let prefix_tokens = if (prefix.clone().as_str() != "".to_string().as_str()) { Rc::new(vec![Rc::new(UrlPathToken::LiteralToken { - text: prefix.clone(), - })]) + text: prefix.clone(), +})]) } else { Rc::new(vec![]) }; - let param_tokens = if (param_name.clone().as_str() != "".to_string().as_str()) { +let param_tokens = if (param_name.clone().as_str() != "".to_string().as_str()) { Rc::new(vec![Rc::new(UrlPathToken::ParamToken { - name: param_name.clone(), - })]) + name: param_name.clone(), +})]) } else { Rc::new(vec![]) }; - let suffix_tokens = if (suffix.clone().as_str() != "".to_string().as_str()) { +let suffix_tokens = if (suffix.clone().as_str() != "".to_string().as_str()) { Rc::new(vec![Rc::new(UrlPathToken::LiteralToken { - text: suffix.clone(), - })]) + text: suffix.clone(), +})]) } else { Rc::new(vec![]) }; - if (((param_name.clone().as_str() == "".to_string().as_str()) - || v2_rt::contains(suffix.clone(), "{".to_string())) - || v2_rt::contains(suffix.clone(), "}".to_string())) - { +if (((param_name.clone().as_str() == "".to_string().as_str()) || v2_rt::contains(suffix.clone(), "{".to_string())) || v2_rt::contains(suffix.clone(), "}".to_string())) { Rc::new(PathSegmentTokensResult::MalformedPathSegment { - segment: seg.clone(), - reason: "invalid parameter segment structure".to_string(), - }) + segment: seg.clone(), + reason: "invalid parameter segment structure".to_string(), +}) } else { Rc::new(PathSegmentTokensResult::ParsedSegmentTokens { - tokens: v2_rt::concat( - v2_rt::concat(prefix_tokens, param_tokens), - suffix_tokens, - ), - }) + tokens: v2_rt::concat(v2_rt::concat(prefix_tokens, param_tokens), suffix_tokens), +}) } - } +} } } pub fn has_path_params(template: Rc) -> bool { - { - let mut __found = false; - for t in template.tokens.clone().iter().cloned() { - if match (*t.clone()).clone() { - UrlPathToken::ParamToken { .. } => true, - UrlPathToken::LiteralToken { .. } => false, - } { - __found = true; - break; - } - } - __found - } + { let mut __found = false; for t in template.tokens.clone().iter().cloned() { if match (*t.clone()).clone() { + UrlPathToken::ParamToken { .. } => true, + UrlPathToken::LiteralToken { .. } => false, +} { __found = true; break; } } __found } } pub fn last_path_param(template: Rc) -> Option { { - let params = Rc::new({ - let mut __result = Vec::new(); - for t in template.tokens.clone().iter().cloned() { - if match (*t.clone()).clone() { - UrlPathToken::ParamToken { .. } => true, - UrlPathToken::LiteralToken { .. } => false, - } { - __result.push(t); - } - } - __result - }); - match params.last().cloned() { - Some(tok) => match (*tok.clone()).clone() { - UrlPathToken::ParamToken { name: n, .. } => Some(n.clone()), - UrlPathToken::LiteralToken { .. } => None, - }, - None => None, - } - } + let params = Rc::new({ let mut __result = Vec::new(); for t in template.tokens.clone().iter().cloned() { if match (*t.clone()).clone() { + UrlPathToken::ParamToken { .. } => true, + UrlPathToken::LiteralToken { .. } => false, +} { __result.push(t); } } __result }); +match params.last().cloned() { + Some(tok) => match (*tok.clone()).clone() { + UrlPathToken::ParamToken { name: n, .. } => Some(n.clone()), + UrlPathToken::LiteralToken { .. } => None, +}, + None => None, +} +} } diff --git a/src/v2/stage0/src/std_induction.rs b/src/v2/stage0/src/std_induction.rs index ab652cf1049..9dccaee9577 100644 --- a/src/v2/stage0/src/std_induction.rs +++ b/src/v2/stage0/src/std_induction.rs @@ -1,35 +1,26 @@ // Generated by v2 compiler -- do not edit. // Source module: std.induction -use self::AtomicCost::*; -use self::CostBound::*; -use self::PolynomialExponent::*; -use self::RecursionShape::*; -use self::SubValueRelation::*; -use crate::std_computation::CallPattern::{ - ArithmeticDivideCall, ArithmeticSubtractCall, ChildAccessorCall, FoldBodyCall, SameArgumentCall, -}; -use crate::std_computation::IterationPrimitive::{Descend, Fold, Repeat}; -use crate::std_computation::ShrinkFactor::{ConstantShrink, ProportionalShrink, UnitShrink}; -use crate::std_computation::SizeBound::{ArithmeticParam, CollectionSize, Forever}; -pub use crate::std_computation::{ - tree_size_bound, CallPattern, IterationPrimitive, LoweringTarget, ShrinkFactor, SizeBound, -}; -use crate::std_termination::DescentEvidence::{DescentUnknown, NonIncreasing, Strict}; -use crate::std_termination::PositiveDescentAmount::{AdditionalStep, OneStep}; -use crate::std_termination::ProportionalDivisor::{DivideByTwo, StrictlyLarger}; -use crate::std_termination::RankingDimension::TreeSize; -pub use crate::std_termination::{ - peano_literal_materialization_cap, positive_descent_amount_from_positive_int, - positive_descent_count, proportional_divisor_from_int_at_least_two, - proportional_divisor_to_int, DescentEvidence, PositiveDescentAmount, ProportionalDivisor, - RankingDimension, -}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_termination::{DescentEvidence, RankingDimension, PositiveDescentAmount, ProportionalDivisor, proportional_divisor_to_int, positive_descent_amount_from_positive_int, proportional_divisor_from_int_at_least_two, peano_literal_materialization_cap, positive_descent_count}; +use crate::std_termination::DescentEvidence::{Strict, NonIncreasing, DescentUnknown}; +use crate::std_termination::RankingDimension::{TreeSize}; +use crate::std_termination::PositiveDescentAmount::{OneStep, AdditionalStep}; +use crate::std_termination::ProportionalDivisor::{DivideByTwo, StrictlyLarger}; +pub use crate::std_computation::{CallPattern, LoweringTarget, IterationPrimitive, ShrinkFactor, tree_size_bound, SizeBound}; +use crate::std_computation::CallPattern::{ChildAccessorCall, FoldBodyCall, SameArgumentCall, ArithmeticSubtractCall, ArithmeticDivideCall}; +use crate::std_computation::IterationPrimitive::{Descend, Fold, Repeat}; +use crate::std_computation::ShrinkFactor::{UnitShrink, ConstantShrink, ProportionalShrink}; +use crate::std_computation::SizeBound::{CollectionSize, ArithmeticParam, Forever}; +use self::RecursionShape::*; +use self::SubValueRelation::*; +use self::PolynomialExponent::*; +use self::AtomicCost::*; +use self::CostBound::*; #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] @@ -52,42 +43,37 @@ pub struct InductiveField { pub fn recursion_shape_eq(a: RecursionShape, b: RecursionShape) -> bool { match a { - RecursionShape::DirectRecursion => match b { - RecursionShape::DirectRecursion => true, - _ => false, - }, - RecursionShape::ListRecursion => match b { - RecursionShape::ListRecursion => true, - _ => false, - }, - RecursionShape::OptionalRecursion => match b { - RecursionShape::OptionalRecursion => true, - _ => false, - }, - RecursionShape::SetRecursion => match b { - RecursionShape::SetRecursion => true, - _ => false, - }, - RecursionShape::MapValueRecursion => match b { - RecursionShape::MapValueRecursion => true, - _ => false, - }, - } + RecursionShape::DirectRecursion => match b { + RecursionShape::DirectRecursion => true, + _ => false, +}, + RecursionShape::ListRecursion => match b { + RecursionShape::ListRecursion => true, + _ => false, +}, + RecursionShape::OptionalRecursion => match b { + RecursionShape::OptionalRecursion => true, + _ => false, +}, + RecursionShape::SetRecursion => match b { + RecursionShape::SetRecursion => true, + _ => false, +}, + RecursionShape::MapValueRecursion => match b { + RecursionShape::MapValueRecursion => true, + _ => false, +}, +} } pub fn inductive_field_eq(a: &Rc, b: &Rc) -> bool { - (((((a.type_name.clone().as_str() == b.type_name.clone().as_str()) - && (a.variant_name.clone().as_str() == b.variant_name.clone().as_str())) - && (a.field_name.clone().as_str() == b.field_name.clone().as_str())) - && recursion_shape_eq(a.shape.clone(), b.shape.clone())) - && (a.element_type.clone().as_str() == b.element_type.clone().as_str())) + (((((a.type_name.clone().as_str() == b.type_name.clone().as_str()) && (a.variant_name.clone().as_str() == b.variant_name.clone().as_str())) && (a.field_name.clone().as_str() == b.field_name.clone().as_str())) && recursion_shape_eq(a.shape.clone(), b.shape.clone())) && (a.element_type.clone().as_str() == b.element_type.clone().as_str())) } -pub fn inductive_field_to_dimension( - field: Rc, - param: String, -) -> Rc { - Rc::new(RankingDimension::TreeSize { param: param }) +pub fn inductive_field_to_dimension(field: Rc, param: String) -> Rc { + Rc::new(RankingDimension::TreeSize { + param: param, +}) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -110,344 +96,256 @@ pub enum SubValueRelation { pub fn sub_value_to_evidence(relation: Rc) -> DescentEvidence { match (*relation).clone() { - SubValueRelation::StrictSubValue { factor: f, .. } => match (*f.clone()).clone() { - ShrinkFactor::UnitShrink => DescentEvidence::Strict, - ShrinkFactor::ConstantShrink { .. } => DescentEvidence::Strict, - ShrinkFactor::ProportionalShrink { .. } => DescentEvidence::Strict, - }, - SubValueRelation::IteratedSubValue { .. } => DescentEvidence::Strict, - SubValueRelation::ArithmeticDescent { factor: f, .. } => match (*f.clone()).clone() { - ShrinkFactor::UnitShrink => DescentEvidence::Strict, - ShrinkFactor::ConstantShrink { .. } => DescentEvidence::Strict, - ShrinkFactor::ProportionalShrink { .. } => DescentEvidence::Strict, - }, - SubValueRelation::PreservedValue => DescentEvidence::NonIncreasing, - SubValueRelation::SubValueUnknown => DescentEvidence::DescentUnknown, - } + SubValueRelation::StrictSubValue { factor: f, .. } => match (*f.clone()).clone() { + ShrinkFactor::UnitShrink => DescentEvidence::Strict, + ShrinkFactor::ConstantShrink { .. } => DescentEvidence::Strict, + ShrinkFactor::ProportionalShrink { .. } => DescentEvidence::Strict, +}, + SubValueRelation::IteratedSubValue { .. } => DescentEvidence::Strict, + SubValueRelation::ArithmeticDescent { factor: f, .. } => match (*f.clone()).clone() { + ShrinkFactor::UnitShrink => DescentEvidence::Strict, + ShrinkFactor::ConstantShrink { .. } => DescentEvidence::Strict, + ShrinkFactor::ProportionalShrink { .. } => DescentEvidence::Strict, +}, + SubValueRelation::PreservedValue => DescentEvidence::NonIncreasing, + SubValueRelation::SubValueUnknown => DescentEvidence::DescentUnknown, +} } pub fn shrink_factor_eq(a: Rc, b: Rc) -> bool { match (*a).clone() { - ShrinkFactor::UnitShrink => match (*b).clone() { - ShrinkFactor::UnitShrink => true, - _ => false, - }, - ShrinkFactor::ConstantShrink { steps: sa, .. } => match (*b).clone() { - ShrinkFactor::ConstantShrink { steps: sb, .. } => { - (positive_descent_count(sa.clone()) == positive_descent_count(sb.clone())) - } - _ => false, - }, - ShrinkFactor::ProportionalShrink { divisor: da, .. } => match (*b).clone() { - ShrinkFactor::ProportionalShrink { divisor: db, .. } => { - (proportional_divisor_to_int(da.clone()) == proportional_divisor_to_int(db.clone())) - } - _ => false, - }, - } + ShrinkFactor::UnitShrink => match (*b).clone() { + ShrinkFactor::UnitShrink => true, + _ => false, +}, + ShrinkFactor::ConstantShrink { steps: sa, .. } => match (*b).clone() { + ShrinkFactor::ConstantShrink { steps: sb, .. } => (positive_descent_count(sa.clone()) == positive_descent_count(sb.clone())), + _ => false, +}, + ShrinkFactor::ProportionalShrink { divisor: da, .. } => match (*b).clone() { + ShrinkFactor::ProportionalShrink { divisor: db, .. } => (proportional_divisor_to_int(da.clone()) == proportional_divisor_to_int(db.clone())), + _ => false, +}, +} } pub fn meet_sub_value(a: Rc, b: Rc) -> Rc { match (*a.clone()).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - SubValueRelation::PreservedValue => match (*b).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - _ => Rc::new(SubValueRelation::PreservedValue), - }, - SubValueRelation::StrictSubValue { - field: fa, - factor: fac_a, - .. - } => match (*b).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - SubValueRelation::PreservedValue => Rc::new(SubValueRelation::PreservedValue), - SubValueRelation::StrictSubValue { - field: fb, - factor: fac_b, - .. - } => { - if inductive_field_eq(&fa, &fb) { - if shrink_factor_eq(fac_a.clone(), fac_b.clone()) { - Rc::new(SubValueRelation::StrictSubValue { - field: fa.clone(), - factor: fac_a.clone(), - }) - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - }, - SubValueRelation::IteratedSubValue { field: fa, .. } => match (*b).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - SubValueRelation::PreservedValue => Rc::new(SubValueRelation::PreservedValue), - SubValueRelation::IteratedSubValue { field: fb, .. } => { - if inductive_field_eq(&fa, &fb) { - a.clone() - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - }, - SubValueRelation::ArithmeticDescent { - param: pa, - factor: fac_a, - .. - } => match (*b).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - SubValueRelation::PreservedValue => Rc::new(SubValueRelation::PreservedValue), - SubValueRelation::ArithmeticDescent { - param: pb, - factor: fac_b, - .. - } => { - if (pa.clone().as_str() == pb.clone().as_str()) { - if shrink_factor_eq(fac_a.clone(), fac_b.clone()) { - Rc::new(SubValueRelation::ArithmeticDescent { - param: pa.clone(), - factor: fac_a.clone(), - }) - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - }, - } + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + SubValueRelation::PreservedValue => match (*b).clone() { + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + _ => Rc::new(SubValueRelation::PreservedValue), +}, + SubValueRelation::StrictSubValue { field: fa, factor: fac_a, .. } => match (*b).clone() { + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + SubValueRelation::PreservedValue => Rc::new(SubValueRelation::PreservedValue), + SubValueRelation::StrictSubValue { field: fb, factor: fac_b, .. } => if inductive_field_eq(&fa, &fb) { + if shrink_factor_eq(fac_a.clone(), fac_b.clone()) { + Rc::new(SubValueRelation::StrictSubValue { + field: fa.clone(), + factor: fac_a.clone(), +}) + } else { + Rc::new(SubValueRelation::SubValueUnknown) + } + } else { + Rc::new(SubValueRelation::SubValueUnknown) + }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +}, + SubValueRelation::IteratedSubValue { field: fa, .. } => match (*b).clone() { + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + SubValueRelation::PreservedValue => Rc::new(SubValueRelation::PreservedValue), + SubValueRelation::IteratedSubValue { field: fb, .. } => if inductive_field_eq(&fa, &fb) { + a.clone() + } else { + Rc::new(SubValueRelation::SubValueUnknown) + }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +}, + SubValueRelation::ArithmeticDescent { param: pa, factor: fac_a, .. } => match (*b).clone() { + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + SubValueRelation::PreservedValue => Rc::new(SubValueRelation::PreservedValue), + SubValueRelation::ArithmeticDescent { param: pb, factor: fac_b, .. } => if (pa.clone().as_str() == pb.clone().as_str()) { + if shrink_factor_eq(fac_a.clone(), fac_b.clone()) { + Rc::new(SubValueRelation::ArithmeticDescent { + param: pa.clone(), + factor: fac_a.clone(), +}) + } else { + Rc::new(SubValueRelation::SubValueUnknown) + } + } else { + Rc::new(SubValueRelation::SubValueUnknown) + }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +}, +} } pub fn join_sub_value(a: Rc, b: Rc) -> Rc { match (*a.clone()).clone() { - SubValueRelation::SubValueUnknown => b.clone(), - SubValueRelation::PreservedValue => match (*b.clone()).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::PreservedValue), - _ => b.clone(), - }, - SubValueRelation::StrictSubValue { - field: fa, - factor: fac_a, - .. - } => match (*b.clone()).clone() { - SubValueRelation::SubValueUnknown => a.clone(), - SubValueRelation::PreservedValue => a.clone(), - SubValueRelation::StrictSubValue { - field: fb, - factor: fac_b, - .. - } => { - if inductive_field_eq(&fa, &fb) { - if shrink_factor_eq(fac_a.clone(), fac_b.clone()) { - Rc::new(SubValueRelation::StrictSubValue { - field: fa.clone(), - factor: fac_a.clone(), - }) - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - }, - SubValueRelation::IteratedSubValue { field: fa, .. } => match (*b.clone()).clone() { - SubValueRelation::SubValueUnknown => a.clone(), - SubValueRelation::PreservedValue => a.clone(), - SubValueRelation::IteratedSubValue { field: fb, .. } => { - if inductive_field_eq(&fa, &fb) { - a.clone() - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - }, - SubValueRelation::ArithmeticDescent { - param: pa, - factor: fac_a, - .. - } => match (*b.clone()).clone() { - SubValueRelation::SubValueUnknown => a.clone(), - SubValueRelation::PreservedValue => a.clone(), - SubValueRelation::ArithmeticDescent { - param: pb, - factor: fac_b, - .. - } => { - if (pa.clone().as_str() == pb.clone().as_str()) { - if shrink_factor_eq(fac_a.clone(), fac_b.clone()) { - Rc::new(SubValueRelation::ArithmeticDescent { - param: pa.clone(), - factor: fac_a.clone(), - }) - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - }, - } + SubValueRelation::SubValueUnknown => b.clone(), + SubValueRelation::PreservedValue => match (*b.clone()).clone() { + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::PreservedValue), + _ => b.clone(), +}, + SubValueRelation::StrictSubValue { field: fa, factor: fac_a, .. } => match (*b.clone()).clone() { + SubValueRelation::SubValueUnknown => a.clone(), + SubValueRelation::PreservedValue => a.clone(), + SubValueRelation::StrictSubValue { field: fb, factor: fac_b, .. } => if inductive_field_eq(&fa, &fb) { + if shrink_factor_eq(fac_a.clone(), fac_b.clone()) { + Rc::new(SubValueRelation::StrictSubValue { + field: fa.clone(), + factor: fac_a.clone(), +}) + } else { + Rc::new(SubValueRelation::SubValueUnknown) + } + } else { + Rc::new(SubValueRelation::SubValueUnknown) + }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +}, + SubValueRelation::IteratedSubValue { field: fa, .. } => match (*b.clone()).clone() { + SubValueRelation::SubValueUnknown => a.clone(), + SubValueRelation::PreservedValue => a.clone(), + SubValueRelation::IteratedSubValue { field: fb, .. } => if inductive_field_eq(&fa, &fb) { + a.clone() + } else { + Rc::new(SubValueRelation::SubValueUnknown) + }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +}, + SubValueRelation::ArithmeticDescent { param: pa, factor: fac_a, .. } => match (*b.clone()).clone() { + SubValueRelation::SubValueUnknown => a.clone(), + SubValueRelation::PreservedValue => a.clone(), + SubValueRelation::ArithmeticDescent { param: pb, factor: fac_b, .. } => if (pa.clone().as_str() == pb.clone().as_str()) { + if shrink_factor_eq(fac_a.clone(), fac_b.clone()) { + Rc::new(SubValueRelation::ArithmeticDescent { + param: pa.clone(), + factor: fac_a.clone(), +}) + } else { + Rc::new(SubValueRelation::SubValueUnknown) + } + } else { + Rc::new(SubValueRelation::SubValueUnknown) + }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +}, +} } -pub fn compose_sub_value( - base: Rc, - field: Rc, -) -> Rc { +pub fn compose_sub_value(base: Rc, field: Rc) -> Rc { match (*base).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - _ => Rc::new(SubValueRelation::StrictSubValue { - field: field, - factor: Rc::new(ShrinkFactor::UnitShrink), - }), - } + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + _ => Rc::new(SubValueRelation::StrictSubValue { + field: field, + factor: Rc::new(ShrinkFactor::UnitShrink), +}), +} } -pub fn compose_sub_value_relations( - arg_rel: Rc, - callee_rel: Rc, -) -> Rc { +pub fn compose_sub_value_relations(arg_rel: Rc, callee_rel: Rc) -> Rc { match (*callee_rel.clone()).clone() { - SubValueRelation::PreservedValue => arg_rel, - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - SubValueRelation::StrictSubValue { .. } => match (*arg_rel).clone() { - SubValueRelation::PreservedValue => callee_rel.clone(), - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - SubValueRelation::StrictSubValue { field: f, .. } => { - Rc::new(SubValueRelation::StrictSubValue { - field: f.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), - }) - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - Rc::new(SubValueRelation::StrictSubValue { - field: f.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), - }) - } - SubValueRelation::ArithmeticDescent { .. } => { - Rc::new(SubValueRelation::SubValueUnknown) - } - }, - SubValueRelation::IteratedSubValue { .. } => match (*arg_rel).clone() { - SubValueRelation::PreservedValue => callee_rel.clone(), - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - SubValueRelation::StrictSubValue { field: f, .. } => { - Rc::new(SubValueRelation::StrictSubValue { - field: f.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), - }) - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - Rc::new(SubValueRelation::StrictSubValue { - field: f.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), - }) - } - SubValueRelation::ArithmeticDescent { .. } => { - Rc::new(SubValueRelation::SubValueUnknown) - } - }, - SubValueRelation::ArithmeticDescent { - param: p, - factor: f, - .. - } => match (*arg_rel).clone() { - SubValueRelation::PreservedValue => Rc::new(SubValueRelation::ArithmeticDescent { - param: p.clone(), - factor: f.clone(), - }), - _ => Rc::new(SubValueRelation::SubValueUnknown), - }, - } + SubValueRelation::PreservedValue => arg_rel, + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + SubValueRelation::StrictSubValue { .. } => match (*arg_rel).clone() { + SubValueRelation::PreservedValue => callee_rel.clone(), + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + SubValueRelation::StrictSubValue { field: f, .. } => Rc::new(SubValueRelation::StrictSubValue { + field: f.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +}), + SubValueRelation::IteratedSubValue { field: f, .. } => Rc::new(SubValueRelation::StrictSubValue { + field: f.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +}), + SubValueRelation::ArithmeticDescent { .. } => Rc::new(SubValueRelation::SubValueUnknown), +}, + SubValueRelation::IteratedSubValue { .. } => match (*arg_rel).clone() { + SubValueRelation::PreservedValue => callee_rel.clone(), + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + SubValueRelation::StrictSubValue { field: f, .. } => Rc::new(SubValueRelation::StrictSubValue { + field: f.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +}), + SubValueRelation::IteratedSubValue { field: f, .. } => Rc::new(SubValueRelation::StrictSubValue { + field: f.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +}), + SubValueRelation::ArithmeticDescent { .. } => Rc::new(SubValueRelation::SubValueUnknown), +}, + SubValueRelation::ArithmeticDescent { param: p, factor: f, .. } => match (*arg_rel).clone() { + SubValueRelation::PreservedValue => Rc::new(SubValueRelation::ArithmeticDescent { + param: p.clone(), + factor: f.clone(), +}), + _ => Rc::new(SubValueRelation::SubValueUnknown), +}, +} } pub fn sub_value_to_call_pattern(relation: Rc) -> Option> { match (*relation).clone() { - SubValueRelation::StrictSubValue { field: f, .. } => { - Some(Rc::new(CallPattern::ChildAccessorCall { - accessor: f.field_name.clone(), - })) - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - Some(Rc::new(CallPattern::ChildAccessorCall { - accessor: f.field_name.clone(), - })) - } - SubValueRelation::ArithmeticDescent { - param: p, - factor: f, - .. - } => match (*f.clone()).clone() { - ShrinkFactor::ConstantShrink { steps, .. } => { - Some(Rc::new(CallPattern::ArithmeticSubtractCall { - steps: steps.clone(), - ring_param: p.clone(), - })) - } - ShrinkFactor::ProportionalShrink { divisor: d, .. } => { - Some(Rc::new(CallPattern::ArithmeticDivideCall { - divisor: d.clone(), - ring_param: p.clone(), - })) - } - ShrinkFactor::UnitShrink => Some(Rc::new(CallPattern::ArithmeticSubtractCall { - steps: Rc::new(PositiveDescentAmount::OneStep), - ring_param: p.clone(), - })), - }, - SubValueRelation::PreservedValue => Some(Rc::new(CallPattern::SameArgumentCall)), - SubValueRelation::SubValueUnknown => None, - } + SubValueRelation::StrictSubValue { field: f, .. } => Some(Rc::new(CallPattern::ChildAccessorCall { + accessor: f.field_name.clone(), +})), + SubValueRelation::IteratedSubValue { field: f, .. } => Some(Rc::new(CallPattern::ChildAccessorCall { + accessor: f.field_name.clone(), +})), + SubValueRelation::ArithmeticDescent { param: p, factor: f, .. } => match (*f.clone()).clone() { + ShrinkFactor::ConstantShrink { steps, .. } => Some(Rc::new(CallPattern::ArithmeticSubtractCall { + steps: steps.clone(), + ring_param: p.clone(), +})), + ShrinkFactor::ProportionalShrink { divisor: d, .. } => Some(Rc::new(CallPattern::ArithmeticDivideCall { + divisor: d.clone(), + ring_param: p.clone(), +})), + ShrinkFactor::UnitShrink => Some(Rc::new(CallPattern::ArithmeticSubtractCall { + steps: Rc::new(PositiveDescentAmount::OneStep), + ring_param: p.clone(), +})), +}, + SubValueRelation::PreservedValue => Some(Rc::new(CallPattern::SameArgumentCall)), + SubValueRelation::SubValueUnknown => None, +} } pub fn sub_value_to_lowering_target(relation: Rc) -> Option> { match (*relation).clone() { - SubValueRelation::StrictSubValue { - field: f, - factor: fac, - .. - } => Some(Rc::new(LoweringTarget { - primitive: IterationPrimitive::Descend, - bound: tree_size_bound(f.field_name.clone()), - evidence: DescentEvidence::Strict, - factor: Some(fac.clone()), - })), - SubValueRelation::IteratedSubValue { field: f, .. } => Some(Rc::new(LoweringTarget { - primitive: IterationPrimitive::Fold, - bound: Rc::new(SizeBound::CollectionSize { - param: f.field_name.clone(), - }), - evidence: DescentEvidence::Strict, - factor: None, - })), - SubValueRelation::ArithmeticDescent { - param: p, - factor: fac, - .. - } => Some(Rc::new(LoweringTarget { - primitive: IterationPrimitive::Repeat, - bound: Rc::new(SizeBound::ArithmeticParam { param: p.clone() }), - evidence: DescentEvidence::Strict, - factor: Some(fac.clone()), - })), - SubValueRelation::PreservedValue => Some(Rc::new(LoweringTarget { - primitive: IterationPrimitive::Repeat, - bound: Rc::new(SizeBound::Forever), - evidence: DescentEvidence::NonIncreasing, - factor: None, - })), - SubValueRelation::SubValueUnknown => None, - } + SubValueRelation::StrictSubValue { field: f, factor: fac, .. } => Some(Rc::new(LoweringTarget { + primitive: IterationPrimitive::Descend, + bound: tree_size_bound(f.field_name.clone()), + evidence: DescentEvidence::Strict, + factor: Some(fac.clone()), +})), + SubValueRelation::IteratedSubValue { field: f, .. } => Some(Rc::new(LoweringTarget { + primitive: IterationPrimitive::Fold, + bound: Rc::new(SizeBound::CollectionSize { + param: f.field_name.clone(), +}), + evidence: DescentEvidence::Strict, + factor: None, +})), + SubValueRelation::ArithmeticDescent { param: p, factor: fac, .. } => Some(Rc::new(LoweringTarget { + primitive: IterationPrimitive::Repeat, + bound: Rc::new(SizeBound::ArithmeticParam { + param: p.clone(), +}), + evidence: DescentEvidence::Strict, + factor: Some(fac.clone()), +})), + SubValueRelation::PreservedValue => Some(Rc::new(LoweringTarget { + primitive: IterationPrimitive::Repeat, + bound: Rc::new(SizeBound::Forever), + evidence: DescentEvidence::NonIncreasing, + factor: None, +})), + SubValueRelation::SubValueUnknown => None, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -469,8 +367,8 @@ pub enum PolynomialExponent { pub fn poly_exp_degree_one() -> Rc { Rc::new(PolynomialExponent::IntegerExpPos { - degree: Rc::new(PositiveDescentAmount::OneStep), - }) + degree: Rc::new(PositiveDescentAmount::OneStep), +}) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -515,23 +413,23 @@ pub enum CostBound { pub fn sum_bound(terms: &Rc>>) -> Rc { match terms.clone().first().cloned() { - None => Rc::new(CostBound::ErrorBound), - Some(_) => Rc::new(CostBound::SumBound { - terms: terms.clone(), - }), - } + None => Rc::new(CostBound::ErrorBound), + Some(_) => Rc::new(CostBound::SumBound { + terms: terms.clone(), +}), +} } pub fn cost_bound_is_sum_bound(b: Rc) -> bool { match (*b).clone() { - CostBound::SumBound { .. } => true, - CostBound::ConstantBound => false, - CostBound::AtomicBound { .. } => false, - CostBound::ProductBound { .. } => false, - CostBound::SumOfProductsBound { .. } => false, - CostBound::ForeverBound => false, - CostBound::ErrorBound => false, - } + CostBound::SumBound { .. } => true, + CostBound::ConstantBound => false, + CostBound::AtomicBound { .. } => false, + CostBound::ProductBound { .. } => false, + CostBound::SumOfProductsBound { .. } => false, + CostBound::ForeverBound => false, + CostBound::ErrorBound => false, +} } pub fn cost_constant() -> Rc { @@ -540,11 +438,11 @@ pub fn cost_constant() -> Rc { pub fn cost_linear(param: String) -> Rc { Rc::new(CostBound::AtomicBound { - cost: Rc::new(AtomicCost::PolyCost { - param: param, - exponent: poly_exp_degree_one(), - }), - }) + cost: Rc::new(AtomicCost::PolyCost { + param: param, + exponent: poly_exp_degree_one(), +}), +}) } pub fn cost_poly(param: String, degree: i64) -> Rc { @@ -553,23 +451,23 @@ pub fn cost_poly(param: String, degree: i64) -> Rc { } else { if (degree.clone() == 0) { Rc::new(CostBound::AtomicBound { - cost: Rc::new(AtomicCost::PolyCost { - param: param, - exponent: Rc::new(PolynomialExponent::IntegerExpZero), - }), - }) + cost: Rc::new(AtomicCost::PolyCost { + param: param, + exponent: Rc::new(PolynomialExponent::IntegerExpZero), +}), +}) } else { match positive_descent_amount_from_positive_int(degree.clone()) { - Some(deg) => Rc::new(CostBound::AtomicBound { - cost: Rc::new(AtomicCost::PolyCost { - param: param, - exponent: Rc::new(PolynomialExponent::IntegerExpPos { - degree: deg.clone(), - }), - }), - }), - None => Rc::new(CostBound::ErrorBound), - } + Some(deg) => Rc::new(CostBound::AtomicBound { + cost: Rc::new(AtomicCost::PolyCost { + param: param, + exponent: Rc::new(PolynomialExponent::IntegerExpPos { + degree: deg.clone(), +}), +}), +}), + None => Rc::new(CostBound::ErrorBound), +} } } } @@ -579,17 +477,17 @@ pub fn cost_root(param: String, k: i64) -> Rc { Rc::new(CostBound::ErrorBound) } else { match positive_descent_amount_from_positive_int(k.clone()) { - Some(rw) => Rc::new(CostBound::AtomicBound { - cost: Rc::new(AtomicCost::PolyCost { - param: param, - exponent: Rc::new(PolynomialExponent::FractionExp { - numerator: Rc::new(PositiveDescentAmount::OneStep), - root: rw.clone(), - }), - }), - }), - None => Rc::new(CostBound::ErrorBound), - } + Some(rw) => Rc::new(CostBound::AtomicBound { + cost: Rc::new(AtomicCost::PolyCost { + param: param, + exponent: Rc::new(PolynomialExponent::FractionExp { + numerator: Rc::new(PositiveDescentAmount::OneStep), + root: rw.clone(), +}), +}), +}), + None => Rc::new(CostBound::ErrorBound), +} } } @@ -603,37 +501,33 @@ pub fn cost_cbrt(param: String) -> Rc { pub fn cost_log(param: String) -> Rc { Rc::new(CostBound::AtomicBound { - cost: Rc::new(AtomicCost::LogCost { param: param }), - }) + cost: Rc::new(AtomicCost::LogCost { + param: param, +}), +}) } pub fn cost_nlogn(param: &String) -> Rc { Rc::new(CostBound::ProductBound { - factors: Rc::new(vec![ - Rc::new(AtomicCost::PolyCost { - param: param.clone(), - exponent: poly_exp_degree_one(), - }), - Rc::new(AtomicCost::LogCost { - param: param.clone(), - }), - ]), - }) + factors: Rc::new(vec![Rc::new(AtomicCost::PolyCost { + param: param.clone(), + exponent: poly_exp_degree_one(), +}), Rc::new(AtomicCost::LogCost { + param: param.clone(), +})]), +}) } pub fn cost_graph_linear(v_param: String, e_param: String) -> Rc { Rc::new(CostBound::SumOfProductsBound { - terms: Rc::new(vec![ - Rc::new(vec![Rc::new(AtomicCost::PolyCost { - param: v_param, - exponent: poly_exp_degree_one(), - })]), - Rc::new(vec![Rc::new(AtomicCost::PolyCost { - param: e_param, - exponent: poly_exp_degree_one(), - })]), - ]), - }) + terms: Rc::new(vec![Rc::new(vec![Rc::new(AtomicCost::PolyCost { + param: v_param, + exponent: poly_exp_degree_one(), +})]), Rc::new(vec![Rc::new(AtomicCost::PolyCost { + param: e_param, + exponent: poly_exp_degree_one(), +})])]), +}) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -725,46 +619,41 @@ pub fn bounded_int_pow_exponent(k: i64) -> Option { } pub fn int_pow_bounded(base: i64, exp: i64) -> Option { - stacker::maybe_grow( - 512 * 1024, - 2 * 1024 * 1024, - || match bounded_int_pow_exponent(exp.clone()) { - None => None, - Some(e) => { - if (e.clone() == 0) { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match bounded_int_pow_exponent(exp.clone()) { + None => None, + Some(e) => if (e.clone() == 0) { + Some(1) + } else { + if (base.clone() == 0) { + Some(0) + } else { + if (base.clone() == 1) { Some(1) } else { - if (base.clone() == 0) { - Some(0) - } else { - if (base.clone() == 1) { - Some(1) - } else { - if (base.clone() == (0 - 1)) { - { - let half = (e.clone() / 2); - if ((half.clone() + half.clone()) == e.clone()) { - Some(1) - } else { - Some((0 - 1)) - } - } + if (base.clone() == (0 - 1)) { + { + let half = (e.clone() / 2); +if ((half.clone() + half.clone()) == e.clone()) { + Some(1) } else { - match int_pow_bounded(base.clone(), (exp.clone() - 1)) { - Some(prev) => match int_mul_checked(base.clone(), prev.clone()) - { - Some(prod) => Some(prod.clone()), - None => None, - }, - None => None, - } + Some((0 - 1)) } - } +} + } else { + match int_pow_bounded(base.clone(), (exp.clone() - 1)) { + Some(prev) => match int_mul_checked(base.clone(), prev.clone()) { + Some(prod) => Some(prod.clone()), + None => None, +}, + None => None, +} } } } }, - ) +} + }) } pub fn ceil_log(base: i64, argument: i64) -> Option { @@ -779,97 +668,82 @@ pub fn ceil_log_iter(mut base: i64, mut argument: i64, mut k: i64, mut power: i6 loop { if (power.clone() >= argument.clone()) { break Some(k); - } else { +} else { match int_mul_checked(power.clone(), base.clone()) { - None => { - break None; - } - Some(next_power) => match int_add_checked(k, 1) { - None => { - break None; - } - Some(k1) => { - let __tco_0 = k1.clone(); - let __tco_1 = next_power.clone(); - k = __tco_0; - power = __tco_1; - continue; - } - }, - } - } - } + None => { break None; }, + Some(next_power) => { match int_add_checked(k, 1) { + None => { break None; }, + Some(k1) => { { + let __tco_0 = k1.clone(); +let __tco_1 = next_power.clone(); +k = __tco_0; +power = __tco_1; +continue; +} }, +} }, +} +} +} } pub fn master_theorem(form: &Rc) -> Rc { { let a = form.branches.clone(); - let b = form.divisor.clone(); - let d = form.work_exponent.clone(); - let n = form.param.clone(); - if ((a.clone() < 1) || (b.clone() < 2)) { +let b = form.divisor.clone(); +let d = form.work_exponent.clone(); +let n = form.param.clone(); +if ((a.clone() < 1) || (b.clone() < 2)) { Rc::new(CostBound::ErrorBound) } else { match bounded_int_pow_exponent(d) { - None => Rc::new(CostBound::ErrorBound), - Some(d_ok) => match int_pow_bounded(b.clone(), d_ok.clone()) { - None => Rc::new(CostBound::ErrorBound), - Some(b_to_d) => { - if (a.clone() < b_to_d.clone()) { - match d_ok.clone() { - 0 => Rc::new(CostBound::ConstantBound), - _ => cost_poly(n.clone(), d_ok.clone()), - } - } else { - if (a.clone() == b_to_d.clone()) { - match d_ok.clone() { - 0 => cost_log(n.clone()), - _ => match positive_descent_amount_from_positive_int( - d_ok.clone(), - ) { - Some(deg) => Rc::new(CostBound::ProductBound { - factors: Rc::new(vec![ - Rc::new(AtomicCost::PolyCost { - param: n.clone(), - exponent: Rc::new( - PolynomialExponent::IntegerExpPos { - degree: deg.clone(), - }, - ), - }), - Rc::new(AtomicCost::LogCost { param: n.clone() }), - ]), - }), - None => Rc::new(CostBound::ErrorBound), - }, - } - } else { - match proportional_divisor_from_int_at_least_two(b.clone()) { - Some(base_w) => { - match positive_descent_amount_from_positive_int(a.clone()) { - Some(arg_w) => Rc::new(CostBound::AtomicBound { - cost: Rc::new(AtomicCost::PolyCost { - param: n.clone(), - exponent: Rc::new( - PolynomialExponent::LogBasedExp { - base: base_w.clone(), - argument: arg_w.clone(), - }, - ), - }), - }), - None => Rc::new(CostBound::ErrorBound), - } - } - None => Rc::new(CostBound::ErrorBound), - } - } - } - } - }, - } + None => Rc::new(CostBound::ErrorBound), + Some(d_ok) => match int_pow_bounded(b.clone(), d_ok.clone()) { + None => Rc::new(CostBound::ErrorBound), + Some(b_to_d) => if (a.clone() < b_to_d.clone()) { + match d_ok.clone() { + 0 => Rc::new(CostBound::ConstantBound), + _ => cost_poly(n.clone(), d_ok.clone()), +} + } else { + if (a.clone() == b_to_d.clone()) { + match d_ok.clone() { + 0 => cost_log(n.clone()), + _ => match positive_descent_amount_from_positive_int(d_ok.clone()) { + Some(deg) => Rc::new(CostBound::ProductBound { + factors: Rc::new(vec![Rc::new(AtomicCost::PolyCost { + param: n.clone(), + exponent: Rc::new(PolynomialExponent::IntegerExpPos { + degree: deg.clone(), +}), +}), Rc::new(AtomicCost::LogCost { + param: n.clone(), +})]), +}), + None => Rc::new(CostBound::ErrorBound), +}, +} + } else { + match proportional_divisor_from_int_at_least_two(b.clone()) { + Some(base_w) => match positive_descent_amount_from_positive_int(a.clone()) { + Some(arg_w) => Rc::new(CostBound::AtomicBound { + cost: Rc::new(AtomicCost::PolyCost { + param: n.clone(), + exponent: Rc::new(PolynomialExponent::LogBasedExp { + base: base_w.clone(), + argument: arg_w.clone(), +}), +}), +}), + None => Rc::new(CostBound::ErrorBound), +}, + None => Rc::new(CostBound::ErrorBound), +} + } + }, +}, +} } - } +} } pub fn catamorphism_bound(param: String, nesting_depth: i64) -> Rc { @@ -884,42 +758,31 @@ pub fn catamorphism_bound(param: String, nesting_depth: i64) -> Rc { } } -pub fn derive_bound( - param: String, - branches: i64, - factor: Rc, - work_exponent: i64, -) -> Rc { +pub fn derive_bound(param: String, branches: i64, factor: Rc, work_exponent: i64) -> Rc { if (branches.clone() < 1) { Rc::new(CostBound::ErrorBound) } else { match bounded_int_pow_exponent(work_exponent.clone()) { - None => Rc::new(CostBound::ErrorBound), - Some(_) => match (*factor).clone() { - ShrinkFactor::UnitShrink => { - if (branches.clone() <= 1) { - cost_linear(param) - } else { - Rc::new(CostBound::ForeverBound) - } - } - ShrinkFactor::ConstantShrink { .. } => { - if (branches.clone() <= 1) { - cost_linear(param) - } else { - Rc::new(CostBound::ForeverBound) - } - } - ShrinkFactor::ProportionalShrink { divisor: d, .. } => { - master_theorem(&Rc::new(RecurrenceForm { - param: param, - branches: branches.clone(), - divisor: proportional_divisor_to_int(d.clone()), - work_exponent: work_exponent.clone(), - })) - } - }, - } + None => Rc::new(CostBound::ErrorBound), + Some(_) => match (*factor).clone() { + ShrinkFactor::UnitShrink => if (branches.clone() <= 1) { + cost_linear(param) + } else { + Rc::new(CostBound::ForeverBound) + }, + ShrinkFactor::ConstantShrink { .. } => if (branches.clone() <= 1) { + cost_linear(param) + } else { + Rc::new(CostBound::ForeverBound) + }, + ShrinkFactor::ProportionalShrink { divisor: d, .. } => master_theorem(&Rc::new(RecurrenceForm { + param: param, + branches: branches.clone(), + divisor: proportional_divisor_to_int(d.clone()), + work_exponent: work_exponent.clone(), +})), +}, +} } } @@ -936,47 +799,27 @@ pub fn linear_scan_bound() -> Rc { } pub fn binary_search_bound() -> Rc { - derive_bound( - "xs".to_string(), - 1, - Rc::new(ShrinkFactor::ProportionalShrink { - divisor: Rc::new(ProportionalDivisor::DivideByTwo), - }), - 0, - ) + derive_bound("xs".to_string(), 1, Rc::new(ShrinkFactor::ProportionalShrink { + divisor: Rc::new(ProportionalDivisor::DivideByTwo), +}), 0) } pub fn mergesort_bound() -> Rc { - derive_bound( - "xs".to_string(), - 2, - Rc::new(ShrinkFactor::ProportionalShrink { - divisor: Rc::new(ProportionalDivisor::DivideByTwo), - }), - 1, - ) + derive_bound("xs".to_string(), 2, Rc::new(ShrinkFactor::ProportionalShrink { + divisor: Rc::new(ProportionalDivisor::DivideByTwo), +}), 1) } pub fn karatsuba_bound() -> Rc { - derive_bound( - "digits".to_string(), - 3, - Rc::new(ShrinkFactor::ProportionalShrink { - divisor: Rc::new(ProportionalDivisor::DivideByTwo), - }), - 1, - ) + derive_bound("digits".to_string(), 3, Rc::new(ShrinkFactor::ProportionalShrink { + divisor: Rc::new(ProportionalDivisor::DivideByTwo), +}), 1) } pub fn strassen_bound() -> Rc { - derive_bound( - "n".to_string(), - 7, - Rc::new(ShrinkFactor::ProportionalShrink { - divisor: Rc::new(ProportionalDivisor::DivideByTwo), - }), - 2, - ) + derive_bound("n".to_string(), 7, Rc::new(ShrinkFactor::ProportionalShrink { + divisor: Rc::new(ProportionalDivisor::DivideByTwo), +}), 2) } pub fn trial_division_bound() -> Rc { @@ -997,42 +840,30 @@ pub fn bfs_dfs_bound() -> Rc { pub fn dijkstra_bound() -> Rc { Rc::new(CostBound::SumOfProductsBound { - terms: Rc::new(vec![ - Rc::new(vec![ - Rc::new(AtomicCost::PolyCost { - param: "V".to_string(), - exponent: poly_exp_degree_one(), - }), - Rc::new(AtomicCost::LogCost { - param: "V".to_string(), - }), - ]), - Rc::new(vec![ - Rc::new(AtomicCost::PolyCost { - param: "E".to_string(), - exponent: poly_exp_degree_one(), - }), - Rc::new(AtomicCost::LogCost { - param: "V".to_string(), - }), - ]), - ]), - }) + terms: Rc::new(vec![Rc::new(vec![Rc::new(AtomicCost::PolyCost { + param: "V".to_string(), + exponent: poly_exp_degree_one(), +}), Rc::new(AtomicCost::LogCost { + param: "V".to_string(), +})]), Rc::new(vec![Rc::new(AtomicCost::PolyCost { + param: "E".to_string(), + exponent: poly_exp_degree_one(), +}), Rc::new(AtomicCost::LogCost { + param: "V".to_string(), +})])]), +}) } pub fn bellman_ford_bound() -> Rc { Rc::new(CostBound::ProductBound { - factors: Rc::new(vec![ - Rc::new(AtomicCost::PolyCost { - param: "V".to_string(), - exponent: poly_exp_degree_one(), - }), - Rc::new(AtomicCost::PolyCost { - param: "E".to_string(), - exponent: poly_exp_degree_one(), - }), - ]), - }) + factors: Rc::new(vec![Rc::new(AtomicCost::PolyCost { + param: "V".to_string(), + exponent: poly_exp_degree_one(), +}), Rc::new(AtomicCost::PolyCost { + param: "E".to_string(), + exponent: poly_exp_degree_one(), +})]), +}) } pub fn floyd_warshall_bound() -> Rc { diff --git a/src/v2/stage0/src/std_iteration.rs b/src/v2/stage0/src/std_iteration.rs index 306aae0c49b..044b21e8651 100644 --- a/src/v2/stage0/src/std_iteration.rs +++ b/src/v2/stage0/src/std_iteration.rs @@ -1,8 +1,10 @@ // Generated by v2 compiler -- do not edit. // Source module: std.iteration -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; + + diff --git a/src/v2/stage0/src/std_node.rs b/src/v2/stage0/src/std_node.rs index 7837270511c..b388294735d 100644 --- a/src/v2/stage0/src/std_node.rs +++ b/src/v2/stage0/src/std_node.rs @@ -1,100 +1,98 @@ // Generated by v2 compiler -- do not edit. // Source module: std.node -use crate::std_induction::RecursionShape::{ - DirectRecursion, ListRecursion, MapValueRecursion, OptionalRecursion, SetRecursion, -}; -pub use crate::std_induction::{InductiveField, RecursionShape}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_induction::{InductiveField, RecursionShape}; +use crate::std_induction::RecursionShape::{DirectRecursion, ListRecursion, OptionalRecursion, SetRecursion, MapValueRecursion}; pub fn compiler_inductive_fields() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(InductiveField { - type_name: "Node".to_string(), - variant_name: "".to_string(), - field_name: "children".to_string(), - shape: RecursionShape::ListRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "Node".to_string(), - variant_name: "".to_string(), - field_name: "params".to_string(), - shape: RecursionShape::ListRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "Node".to_string(), - variant_name: "".to_string(), - field_name: "uses".to_string(), - shape: RecursionShape::ListRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "Node".to_string(), - variant_name: "".to_string(), - field_name: "properties".to_string(), - shape: RecursionShape::ListRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "Node".to_string(), - variant_name: "".to_string(), - field_name: "body".to_string(), - shape: RecursionShape::OptionalRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "Node".to_string(), - variant_name: "".to_string(), - field_name: "transport".to_string(), - shape: RecursionShape::OptionalRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "Node".to_string(), - variant_name: "".to_string(), - field_name: "type_annotation".to_string(), - shape: RecursionShape::OptionalRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "Node".to_string(), - variant_name: "".to_string(), - field_name: "inferred".to_string(), - shape: RecursionShape::OptionalRecursion, - element_type: "InferredNode".to_string(), - }), Rc::new(InductiveField { - type_name: "InferredNode".to_string(), - variant_name: "Resolved".to_string(), - field_name: "node".to_string(), - shape: RecursionShape::DirectRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "MatchPattern".to_string(), - variant_name: "VariantPattern".to_string(), - field_name: "field_bindings".to_string(), - shape: RecursionShape::ListRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "MethodSemantics".to_string(), - variant_name: "AlgebraMethodSemantics".to_string(), - field_name: "method_def".to_string(), - shape: RecursionShape::DirectRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "MethodSemantics".to_string(), - variant_name: "AlgebraMethodSemantics".to_string(), - field_name: "fold_accumulator_type".to_string(), - shape: RecursionShape::OptionalRecursion, - element_type: "Node".to_string(), - }), Rc::new(InductiveField { - type_name: "MethodSemantics".to_string(), - variant_name: "ServiceMethodSemantics".to_string(), - field_name: "op_params".to_string(), - shape: RecursionShape::ListRecursion, - element_type: "Node".to_string(), - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(InductiveField { + type_name: "Node".to_string(), + variant_name: "".to_string(), + field_name: "children".to_string(), + shape: RecursionShape::ListRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "Node".to_string(), + variant_name: "".to_string(), + field_name: "params".to_string(), + shape: RecursionShape::ListRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "Node".to_string(), + variant_name: "".to_string(), + field_name: "uses".to_string(), + shape: RecursionShape::ListRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "Node".to_string(), + variant_name: "".to_string(), + field_name: "properties".to_string(), + shape: RecursionShape::ListRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "Node".to_string(), + variant_name: "".to_string(), + field_name: "body".to_string(), + shape: RecursionShape::OptionalRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "Node".to_string(), + variant_name: "".to_string(), + field_name: "transport".to_string(), + shape: RecursionShape::OptionalRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "Node".to_string(), + variant_name: "".to_string(), + field_name: "type_annotation".to_string(), + shape: RecursionShape::OptionalRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "Node".to_string(), + variant_name: "".to_string(), + field_name: "inferred".to_string(), + shape: RecursionShape::OptionalRecursion, + element_type: "InferredNode".to_string(), +}), Rc::new(InductiveField { + type_name: "InferredNode".to_string(), + variant_name: "Resolved".to_string(), + field_name: "node".to_string(), + shape: RecursionShape::DirectRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "MatchPattern".to_string(), + variant_name: "VariantPattern".to_string(), + field_name: "field_bindings".to_string(), + shape: RecursionShape::ListRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "MethodSemantics".to_string(), + variant_name: "AlgebraMethodSemantics".to_string(), + field_name: "method_def".to_string(), + shape: RecursionShape::DirectRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "MethodSemantics".to_string(), + variant_name: "AlgebraMethodSemantics".to_string(), + field_name: "fold_accumulator_type".to_string(), + shape: RecursionShape::OptionalRecursion, + element_type: "Node".to_string(), +}), Rc::new(InductiveField { + type_name: "MethodSemantics".to_string(), + variant_name: "ServiceMethodSemantics".to_string(), + field_name: "op_params".to_string(), + shape: RecursionShape::ListRecursion, + element_type: "Node".to_string(), +})]) + }; + } CACHED.with(|c| c.clone()) } @@ -114,7 +112,7 @@ pub fn compiler_recursive_types() -> Rc> { pub fn is_compiler_recursive_type(name: String) -> bool { match v2_rt::map_get(&compiler_recursive_types(), name) { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } diff --git a/src/v2/stage0/src/std_syntax.rs b/src/v2/stage0/src/std_syntax.rs index 3f1dc19b430..80c4dd8193d 100644 --- a/src/v2/stage0/src/std_syntax.rs +++ b/src/v2/stage0/src/std_syntax.rs @@ -1,16 +1,16 @@ // Generated by v2 compiler -- do not edit. // Source module: std.syntax -use self::AlgebraFieldKind::*; +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; use self::BinOp::*; +use self::LiteralValue::*; use self::BodyKind::*; use self::ItemFormKind::*; -use self::LiteralValue::*; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +use self::AlgebraFieldKind::*; #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] @@ -34,10 +34,18 @@ pub enum BinOp { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum LiteralValue { - LitStr { value: String }, - LitInt { value: i64 }, - LitFloat { value: String }, - LitBool { value: bool }, + LitStr { + value: String, + }, + LitInt { + value: i64, + }, + LitFloat { + value: String, + }, + LitBool { + value: bool, + }, LitNull, } @@ -97,34 +105,34 @@ pub struct AlgebraFieldEntry { pub fn algebra_field_entries() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - Rc::new(vec![Rc::new(AlgebraFieldEntry { - kind: AlgebraFieldKind::AlgAdd, - field_name: "add".to_string(), - }), Rc::new(AlgebraFieldEntry { - kind: AlgebraFieldKind::AlgMul, - field_name: "mul".to_string(), - }), Rc::new(AlgebraFieldEntry { - kind: AlgebraFieldKind::AlgReciprocal, - field_name: "reciprocal".to_string(), - }), Rc::new(AlgebraFieldEntry { - kind: AlgebraFieldKind::AlgQuotient, - field_name: "quotient".to_string(), - }), Rc::new(AlgebraFieldEntry { - kind: AlgebraFieldKind::AlgRemainder, - field_name: "remainder".to_string(), - }), Rc::new(AlgebraFieldEntry { - kind: AlgebraFieldKind::AlgCompare, - field_name: "compare".to_string(), - }), Rc::new(AlgebraFieldEntry { - kind: AlgebraFieldKind::AlgMeet, - field_name: "meet".to_string(), - }), Rc::new(AlgebraFieldEntry { - kind: AlgebraFieldKind::AlgJoin, - field_name: "join".to_string(), - })]) - }; - } + static CACHED: Rc>> = { + Rc::new(vec![Rc::new(AlgebraFieldEntry { + kind: AlgebraFieldKind::AlgAdd, + field_name: "add".to_string(), +}), Rc::new(AlgebraFieldEntry { + kind: AlgebraFieldKind::AlgMul, + field_name: "mul".to_string(), +}), Rc::new(AlgebraFieldEntry { + kind: AlgebraFieldKind::AlgReciprocal, + field_name: "reciprocal".to_string(), +}), Rc::new(AlgebraFieldEntry { + kind: AlgebraFieldKind::AlgQuotient, + field_name: "quotient".to_string(), +}), Rc::new(AlgebraFieldEntry { + kind: AlgebraFieldKind::AlgRemainder, + field_name: "remainder".to_string(), +}), Rc::new(AlgebraFieldEntry { + kind: AlgebraFieldKind::AlgCompare, + field_name: "compare".to_string(), +}), Rc::new(AlgebraFieldEntry { + kind: AlgebraFieldKind::AlgMeet, + field_name: "meet".to_string(), +}), Rc::new(AlgebraFieldEntry { + kind: AlgebraFieldKind::AlgJoin, + field_name: "join".to_string(), +})]) + }; + } CACHED.with(|c| c.clone()) } diff --git a/src/v2/stage0/src/std_termination.rs b/src/v2/stage0/src/std_termination.rs index 0e132b78d33..fa1aa3dd700 100644 --- a/src/v2/stage0/src/std_termination.rs +++ b/src/v2/stage0/src/std_termination.rs @@ -1,18 +1,18 @@ // Generated by v2 compiler -- do not edit. // Source module: std.termination +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_algebra::{Ordering}; +use crate::std_algebra::Ordering::*; use self::DescentEvidence::*; -use self::DescentSource::*; +use self::RankingDimension::*; use self::PositiveDescentAmount::*; use self::ProportionalDivisor::*; -use self::RankingDimension::*; -pub use crate::std_algebra::Ordering; -use crate::std_algebra::Ordering::*; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +use self::DescentSource::*; #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] @@ -24,83 +24,82 @@ pub enum DescentEvidence { pub fn evidence_rank(e: DescentEvidence) -> i64 { match e { - DescentEvidence::Strict => 2, - DescentEvidence::NonIncreasing => 1, - DescentEvidence::DescentUnknown => 0, - } + DescentEvidence::Strict => 2, + DescentEvidence::NonIncreasing => 1, + DescentEvidence::DescentUnknown => 0, +} } pub fn merge_evidence(a: DescentEvidence, b: DescentEvidence) -> DescentEvidence { match a { - DescentEvidence::Strict => match b { - DescentEvidence::Strict => DescentEvidence::Strict, - DescentEvidence::NonIncreasing => DescentEvidence::NonIncreasing, - _ => DescentEvidence::DescentUnknown, - }, - DescentEvidence::NonIncreasing => match b { - DescentEvidence::Strict => DescentEvidence::NonIncreasing, - DescentEvidence::NonIncreasing => DescentEvidence::NonIncreasing, - _ => DescentEvidence::DescentUnknown, - }, - _ => DescentEvidence::DescentUnknown, - } + DescentEvidence::Strict => match b { + DescentEvidence::Strict => DescentEvidence::Strict, + DescentEvidence::NonIncreasing => DescentEvidence::NonIncreasing, + _ => DescentEvidence::DescentUnknown, +}, + DescentEvidence::NonIncreasing => match b { + DescentEvidence::Strict => DescentEvidence::NonIncreasing, + DescentEvidence::NonIncreasing => DescentEvidence::NonIncreasing, + _ => DescentEvidence::DescentUnknown, +}, + _ => DescentEvidence::DescentUnknown, +} } pub fn join_evidence(a: DescentEvidence, b: DescentEvidence) -> DescentEvidence { match a { - DescentEvidence::DescentUnknown => b, - DescentEvidence::NonIncreasing => match b { - DescentEvidence::Strict => DescentEvidence::Strict, - _ => DescentEvidence::NonIncreasing, - }, - DescentEvidence::Strict => DescentEvidence::Strict, - } + DescentEvidence::DescentUnknown => b, + DescentEvidence::NonIncreasing => match b { + DescentEvidence::Strict => DescentEvidence::Strict, + _ => DescentEvidence::NonIncreasing, +}, + DescentEvidence::Strict => DescentEvidence::Strict, +} } pub fn promote_to_strict(evidence: DescentEvidence) -> DescentEvidence { match evidence { - DescentEvidence::NonIncreasing => DescentEvidence::NonIncreasing, - DescentEvidence::Strict => DescentEvidence::Strict, - _ => DescentEvidence::DescentUnknown, - } + DescentEvidence::NonIncreasing => DescentEvidence::NonIncreasing, + DescentEvidence::Strict => DescentEvidence::Strict, + _ => DescentEvidence::DescentUnknown, +} } -pub fn optional_evidence_meet( - a: Option, - b: Option, -) -> Option { +pub fn optional_evidence_meet(a: Option, b: Option) -> Option { match a.clone() { - None => b, - Some(va) => match b { - None => a.clone(), - Some(vb) => Some(merge_evidence(va.clone(), vb.clone())), - }, - } + None => b, + Some(va) => match b { + None => a.clone(), + Some(vb) => Some(merge_evidence(va.clone(), vb.clone())), +}, +} } -pub fn map_evidence_merge_at( - base: &Rc>, - key: &String, - new_val: DescentEvidence, -) -> Rc> { +pub fn map_evidence_merge_at(base: &Rc>, key: &String, new_val: DescentEvidence) -> Rc> { match v2_rt::map_get(&base, key.clone()) { - Some(existing) => v2_rt::rc_map_insert( - base.clone(), - key.clone(), - merge_evidence(existing.clone(), new_val), - ), - None => v2_rt::rc_map_insert(base.clone(), key.clone(), new_val), - } + Some(existing) => v2_rt::rc_map_insert(base.clone(), key.clone(), merge_evidence(existing.clone(), new_val)), + None => v2_rt::rc_map_insert(base.clone(), key.clone(), new_val), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum RankingDimension { - TreeSize { param: String }, - ListLength { param: String }, - ArithmeticValue { param: String }, - TokenPosition { param: String }, - SetCardinality { param: String }, + TreeSize { + param: String, + }, + ListLength { + param: String, + }, + ArithmeticValue { + param: String, + }, + TokenPosition { + param: String, + }, + SetCardinality { + param: String, + }, } impl RankingDimension { pub fn param(&self) -> String { @@ -118,25 +117,25 @@ impl RankingDimension { #[serde(tag = "_variant")] pub enum PositiveDescentAmount { OneStep, - AdditionalStep { previous: Rc }, + AdditionalStep { + previous: Rc, + }, } impl PositiveDescentAmount { pub fn previous(&self) -> Rc { match self { PositiveDescentAmount::OneStep => panic!("no previous on unit variant"), - PositiveDescentAmount::AdditionalStep { - previous: __val, .. - } => __val.clone(), + PositiveDescentAmount::AdditionalStep { previous: __val, .. } => __val.clone(), } } } pub fn positive_descent_count(steps: Rc) -> i64 { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*steps).clone() { - PositiveDescentAmount::OneStep => 1, - PositiveDescentAmount::AdditionalStep { previous: p, .. } => { - (1 + positive_descent_count(p.clone())) - } + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*steps).clone() { + PositiveDescentAmount::OneStep => 1, + PositiveDescentAmount::AdditionalStep { previous: p, .. } => (1 + positive_descent_count(p.clone())), +} }) } @@ -144,7 +143,9 @@ pub fn positive_descent_count(steps: Rc) -> i64 { #[serde(tag = "_variant")] pub enum ProportionalDivisor { DivideByTwo, - StrictlyLarger { inner: Rc }, + StrictlyLarger { + inner: Rc, + }, } impl ProportionalDivisor { pub fn inner(&self) -> Rc { @@ -156,11 +157,11 @@ impl ProportionalDivisor { } pub fn proportional_divisor_to_int(d: Rc) -> i64 { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*d).clone() { - ProportionalDivisor::DivideByTwo => 2, - ProportionalDivisor::StrictlyLarger { inner: p, .. } => { - (1 + proportional_divisor_to_int(p.clone())) - } + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*d).clone() { + ProportionalDivisor::DivideByTwo => 2, + ProportionalDivisor::StrictlyLarger { inner: p, .. } => (1 + proportional_divisor_to_int(p.clone())), +} }) } @@ -180,11 +181,11 @@ pub fn positive_descent_amount_from_positive_int(k: i64) -> Option Some(Rc::new(PositiveDescentAmount::AdditionalStep { - previous: prev.clone(), - })), - None => None, - } + Some(prev) => Some(Rc::new(PositiveDescentAmount::AdditionalStep { + previous: prev.clone(), +})), + None => None, +} } } } @@ -203,11 +204,11 @@ pub fn proportional_divisor_from_int_at_least_two(k: i64) -> Option Some(Rc::new(ProportionalDivisor::StrictlyLarger { - inner: prev.clone(), - })), - None => None, - } + Some(prev) => Some(Rc::new(ProportionalDivisor::StrictlyLarger { + inner: prev.clone(), +})), + None => None, +} } } } @@ -217,12 +218,24 @@ pub fn proportional_divisor_from_int_at_least_two(k: i64) -> Option }, - ArithmeticSubtractDescent { steps: Rc }, - ArithmeticDivideDescent { divisor: Rc }, - ParserAdvance { witness: String }, - SetRemoval { element: String }, + ChildAccessor { + accessor: String, + }, + ListShrink { + amount: Rc, + }, + ArithmeticSubtractDescent { + steps: Rc, + }, + ArithmeticDivideDescent { + divisor: Rc, + }, + ParserAdvance { + witness: String, + }, + SetRemoval { + element: String, + }, FoldIteration, } diff --git a/src/v2/stage0/src/std_types.rs b/src/v2/stage0/src/std_types.rs index f04b8a90acf..95c1c47bf53 100644 --- a/src/v2/stage0/src/std_types.rs +++ b/src/v2/stage0/src/std_types.rs @@ -1,30 +1,28 @@ // Generated by v2 compiler -- do not edit. // Source module: std.types -use self::AbiEnv::*; -use self::Arch::*; -use self::AuthScheme::*; +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_algebra::{BooleanAlgebra, FreeMonoid, PartialFunction, kernel_algebra_profile, algebra_type_param_names}; use self::Bool::*; -use self::CodegenBackend::*; -use self::CredentialFlow::*; +use self::Platform::*; +use self::TopologyNodeKind::*; use self::DocSourceKind::*; -use self::EntryKind::*; -use self::ExecutionEnv::*; use self::FermiDepth::*; -use self::HttpMethod::*; +use self::CredentialFlow::*; +use self::Arch::*; +use self::Vendor::*; use self::Os::*; -use self::Platform::*; +use self::AbiEnv::*; +use self::ExecutionEnv::*; +use self::EntryKind::*; use self::SymlinkTarget::*; -use self::TopologyNodeKind::*; -use self::Vendor::*; -pub use crate::std_algebra::{ - algebra_type_param_names, kernel_algebra_profile, BooleanAlgebra, FreeMonoid, PartialFunction, -}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +use self::HttpMethod::*; +use self::AuthScheme::*; +use self::CodegenBackend::*; pub fn kernel_type_set() -> Rc> { thread_local! { @@ -46,9 +44,9 @@ pub fn kernel_type_set() -> Rc> { pub fn is_kernel_type(name: String) -> bool { match v2_rt::map_get(&kernel_type_set(), name) { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } pub fn container_type_arity() -> Rc> { @@ -66,9 +64,9 @@ pub fn container_type_arity() -> Rc> { pub fn is_container_type(name: String) -> bool { match container_expected_arity(name) { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } pub fn container_expected_arity(name: String) -> Option { @@ -77,49 +75,19 @@ pub fn container_expected_arity(name: String) -> Option { pub fn container_param_names_for(kind_name: String) -> Rc> { match v2_rt::map_get(&kernel_algebra_profile(), kind_name) { - Some(p) => algebra_type_param_names(p.clone()), - None => Rc::new(vec![]), - } + Some(p) => algebra_type_param_names(p.clone()), + None => Rc::new(vec![]), +} } pub fn container_param_name(kind_name: String, index: i64) -> Option { { let names = container_param_names_for(kind_name); - match Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - names - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (pair.0.clone() == index.clone()) { - __result.push(pair); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(pair.1.clone()); - } - __result - }) - .first() - .cloned() - { - Some(name) => Some(name.clone()), - None => None, - } - } +match Rc::new({ let mut __result = Vec::new(); for pair in Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(names.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (pair.0.clone() == index.clone()) { __result.push(pair); } } __result }).iter().cloned() { __result.push(pair.1.clone()); } __result }).first().cloned() { + Some(name) => Some(name.clone()), + None => None, +} +} } pub fn ordered_element_collections() -> Rc> { @@ -164,14 +132,7 @@ pub fn container_template_algebra(name: String) -> Option { } pub fn canonical_container_names() -> Rc> { - Rc::new(vec![ - "BooleanAlgebra".to_string(), - "FreeMonoid".to_string(), - "List".to_string(), - "Map".to_string(), - "PartialFunction".to_string(), - "Set".to_string(), - ]) + Rc::new(vec!["BooleanAlgebra".to_string(), "FreeMonoid".to_string(), "List".to_string(), "Map".to_string(), "PartialFunction".to_string(), "Set".to_string()]) } #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] @@ -181,12 +142,20 @@ pub enum Bool { False, } + + pub type Json = serde_json::Value; pub type Bytes = Vec; pub type Char = i64; + + + + + + pub type CommitSha = String; pub type Sha256 = String; @@ -452,8 +421,12 @@ pub enum HttpMethod { #[serde(tag = "_variant")] pub enum AuthScheme { Bearer, - Header { name: String }, - Basic { username: String }, + Header { + name: String, + }, + Basic { + username: String, + }, ApiKey, } @@ -647,3 +620,5 @@ pub struct DocSource { pub path: String, pub kind: DocSourceKind, } + + diff --git a/src/v2/stage0/src/v2_compiler_artifact.rs b/src/v2/stage0/src/v2_compiler_artifact.rs index d2e80ac7366..75e6b639642 100644 --- a/src/v2/stage0/src/v2_compiler_artifact.rs +++ b/src/v2/stage0/src/v2_compiler_artifact.rs @@ -1,16 +1,16 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.artifact +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{TextFile}; +use self::RenderTarget::*; use self::ArtifactKind::*; use self::BoundaryKind::*; use self::PartitionRule::*; -use self::RenderTarget::*; -use crate::v2_rt; -pub use crate::v2_std_core::TextFile; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] @@ -66,27 +66,25 @@ pub struct ArtifactPlan { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum PartitionRule { - Explicit { artifacts: Rc>> }, + Explicit { + artifacts: Rc>>, + }, } impl PartitionRule { pub fn artifacts(&self) -> Rc>> { match self { - PartitionRule::Explicit { - artifacts: __val, .. - } => __val.clone(), + PartitionRule::Explicit { artifacts: __val, .. } => __val.clone(), } } } pub fn plan_artifacts(rule: Rc) -> Rc { match (*rule).clone() { - PartitionRule::Explicit { - artifacts: arts, .. - } => Rc::new(ArtifactPlan { - artifacts: arts.clone(), - boundaries: Rc::new(vec![]), - }), - } + PartitionRule::Explicit { artifacts: arts, .. } => Rc::new(ArtifactPlan { + artifacts: arts.clone(), + boundaries: Rc::new(vec![]), +}), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -95,17 +93,14 @@ pub struct ArtifactOutput { pub files: Rc>>, } -pub fn default_artifact_plan( - root_modules: Rc>, - target: RenderTarget, -) -> Rc { +pub fn default_artifact_plan(root_modules: Rc>, target: RenderTarget) -> Rc { plan_artifacts(Rc::new(PartitionRule::Explicit { - artifacts: Rc::new(vec![Rc::new(Artifact { - name: "default".to_string(), - kind: ArtifactKind::ServiceBinary, - target: target, - entry_modules: root_modules, - dependencies: Rc::new(vec![]), - })]), - })) + artifacts: Rc::new(vec![Rc::new(Artifact { + name: "default".to_string(), + kind: ArtifactKind::ServiceBinary, + target: target, + entry_modules: root_modules, + dependencies: Rc::new(vec![]), +})]), +})) } diff --git a/src/v2/stage0/src/v2_compiler_coercion.rs b/src/v2/stage0/src/v2_compiler_coercion.rs index c803d00b647..e145655eaf9 100644 --- a/src/v2/stage0/src/v2_compiler_coercion.rs +++ b/src/v2/stage0/src/v2_compiler_coercion.rs @@ -1,174 +1,131 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.coercion -use self::CoercionAssertion::*; -pub use crate::extdeps_languages_dag_types::dag_type_checkpoints; -pub use crate::extdeps_languages_go_types::{ - go_algebra_inhabitants, go_callable, go_cast_syntax, go_optional_template, go_type_checkpoints, -}; -pub use crate::extdeps_languages_python_types::{ - python_algebra_inhabitants, python_callable, python_cast_syntax, python_optional_template, - python_type_checkpoints, -}; -pub use crate::extdeps_languages_rust_types::{ - rust_algebra_inhabitants, rust_callable, rust_cast_syntax, rust_optional_template, - rust_type_checkpoints, -}; -pub use crate::std_coercion::{CallableRepr, CastSyntax, InhabitantDecl, TypeCheckpoint}; -pub use crate::std_types::{canonical_container_names, container_template_algebra}; -pub use crate::v2_compiler_artifact::RenderTarget; -use crate::v2_compiler_artifact::RenderTarget::{Dag, Go, Python, Rust}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_compiler_artifact::{RenderTarget}; +use crate::v2_compiler_artifact::RenderTarget::{Rust, Python, Go, Dag}; +pub use crate::std_coercion::{TypeCheckpoint, InhabitantDecl, CallableRepr, CastSyntax}; +pub use crate::std_types::{container_template_algebra, canonical_container_names}; +pub use crate::extdeps_languages_rust_types::{rust_type_checkpoints, rust_algebra_inhabitants, rust_callable, rust_optional_template, rust_cast_syntax}; +pub use crate::extdeps_languages_python_types::{python_type_checkpoints, python_algebra_inhabitants, python_callable, python_optional_template, python_cast_syntax}; +pub use crate::extdeps_languages_go_types::{go_type_checkpoints, go_algebra_inhabitants, go_callable, go_optional_template, go_cast_syntax}; +pub use crate::extdeps_languages_dag_types::{dag_type_checkpoints}; +use self::CoercionAssertion::*; pub fn target_checkpoints(target: RenderTarget) -> Rc>> { match target { - RenderTarget::Rust => rust_type_checkpoints(), - RenderTarget::Python => python_type_checkpoints(), - RenderTarget::Go => go_type_checkpoints(), - RenderTarget::Dag => dag_type_checkpoints(), - } + RenderTarget::Rust => rust_type_checkpoints(), + RenderTarget::Python => python_type_checkpoints(), + RenderTarget::Go => go_type_checkpoints(), + RenderTarget::Dag => dag_type_checkpoints(), +} } pub fn target_inhabitants(target: RenderTarget) -> Rc>> { match target { - RenderTarget::Rust => rust_algebra_inhabitants(), - RenderTarget::Python => python_algebra_inhabitants(), - RenderTarget::Go => go_algebra_inhabitants(), - RenderTarget::Dag => Rc::new(vec![]), - } + RenderTarget::Rust => rust_algebra_inhabitants(), + RenderTarget::Python => python_algebra_inhabitants(), + RenderTarget::Go => go_algebra_inhabitants(), + RenderTarget::Dag => Rc::new(vec![]), +} } pub fn target_callable(target: RenderTarget) -> Rc { match target { - RenderTarget::Rust => rust_callable(), - RenderTarget::Python => python_callable(), - RenderTarget::Go => go_callable(), - RenderTarget::Dag => Rc::new(CallableRepr { - template: "fn({params}) -> {return}".to_string(), - param_separator: ", ".to_string(), - return_separator: " -> ".to_string(), - import_path: None, - }), - } + RenderTarget::Rust => rust_callable(), + RenderTarget::Python => python_callable(), + RenderTarget::Go => go_callable(), + RenderTarget::Dag => Rc::new(CallableRepr { + template: "fn({params}) -> {return}".to_string(), + param_separator: ", ".to_string(), + return_separator: " -> ".to_string(), + import_path: None, +}), +} } pub fn target_optional_template(target: RenderTarget) -> String { match target { - RenderTarget::Rust => rust_optional_template(), - RenderTarget::Python => python_optional_template(), - RenderTarget::Go => go_optional_template(), - RenderTarget::Dag => "{0}?".to_string(), - } + RenderTarget::Rust => rust_optional_template(), + RenderTarget::Python => python_optional_template(), + RenderTarget::Go => go_optional_template(), + RenderTarget::Dag => "{0}?".to_string(), +} } pub fn target_cast_syntax(target: RenderTarget) -> Option> { match target { - RenderTarget::Rust => Some(rust_cast_syntax()), - RenderTarget::Python => Some(python_cast_syntax()), - RenderTarget::Go => Some(go_cast_syntax()), - RenderTarget::Dag => None, - } + RenderTarget::Rust => Some(rust_cast_syntax()), + RenderTarget::Python => Some(python_cast_syntax()), + RenderTarget::Go => Some(go_cast_syntax()), + RenderTarget::Dag => None, +} } pub fn can_cast(target: RenderTarget, source_type: String, target_type: String) -> bool { match target_cast_syntax(target) { - Some(syntax) => { - let mut __found = false; - for r in syntax.cast_rules.clone().iter().cloned() { - if ((r.from_type.clone().as_str() == source_type.clone().as_str()) - && (r.to_type.clone().as_str() == target_type.clone().as_str())) - { - __found = true; - break; - } - } - __found - } - None => false, - } + Some(syntax) => { let mut __found = false; for r in syntax.cast_rules.clone().iter().cloned() { if ((r.from_type.clone().as_str() == source_type.clone().as_str()) && (r.to_type.clone().as_str() == target_type.clone().as_str())) { __found = true; break; } } __found }, + None => false, +} } pub fn render_cast(expr_str: String, type_str: String, target: RenderTarget) -> String { { let syntax = match target_cast_syntax(target) { - Some(s) => s.clone(), - None => Rc::new(CastSyntax { - template: "{expr}".to_string(), - cast_rules: Rc::new(vec![]), - }), - }; - v2_rt::replace( - v2_rt::replace(syntax.template.clone(), "{expr}".to_string(), expr_str), - "{type}".to_string(), - type_str, - ) - } + Some(s) => s.clone(), + None => Rc::new(CastSyntax { + template: "{expr}".to_string(), + cast_rules: Rc::new(vec![]), +}), +}; +v2_rt::replace(v2_rt::replace(syntax.template.clone(), "{expr}".to_string(), expr_str), "{type}".to_string(), type_str) +} } pub fn lookup_checkpoint(target: RenderTarget, dag_name: String) -> Option> { - Rc::new({ - let mut __result = Vec::new(); - for cp in target_checkpoints(target).iter().cloned() { - if (cp.dag_name.clone().as_str() == dag_name.clone().as_str()) { - __result.push(cp); - } - } - __result - }) - .first() - .cloned() + Rc::new({ let mut __result = Vec::new(); for cp in target_checkpoints(target).iter().cloned() { if (cp.dag_name.clone().as_str() == dag_name.clone().as_str()) { __result.push(cp); } } __result }).first().cloned() } pub fn coerce_primitive_type(target: RenderTarget, dag_name: String) -> String { match lookup_checkpoint(target, dag_name.clone()) { - Some(cp) => cp.target_type.clone(), - None => dag_name.clone(), - } + Some(cp) => cp.target_type.clone(), + None => dag_name.clone(), +} } pub fn is_copy(target: RenderTarget, dag_name: String) -> Option { match lookup_checkpoint(target, dag_name) { - Some(cp) => cp.is_copy.clone(), - None => None, - } + Some(cp) => cp.is_copy.clone(), + None => None, +} } pub fn literal_suffix(target: RenderTarget, dag_name: String) -> Option { match lookup_checkpoint(target, dag_name) { - Some(cp) => match cp.literal_suffix.clone() { - Some(s) => Some(s.clone()), - None => Some("".to_string()), - }, - None => None, - } + Some(cp) => match cp.literal_suffix.clone() { + Some(s) => Some(s.clone()), + None => Some("".to_string()), +}, + None => None, +} } pub fn lookup_inhabitant(target: RenderTarget, algebra: String) -> Option> { - Rc::new({ - let mut __result = Vec::new(); - for inh in target_inhabitants(target).iter().cloned() { - if (inh.algebra.clone().as_str() == algebra.clone().as_str()) { - __result.push(inh); - } - } - __result - }) - .first() - .cloned() + Rc::new({ let mut __result = Vec::new(); for inh in target_inhabitants(target).iter().cloned() { if (inh.algebra.clone().as_str() == algebra.clone().as_str()) { __result.push(inh); } } __result }).first().cloned() } pub fn coerce_container_template(target: RenderTarget, container_name: String) -> Option { match container_template_algebra(container_name) { - Some(algebra) => match lookup_inhabitant(target, algebra.clone()) { - Some(inh) => Some(inh.template.clone()), - None => None, - }, - None => None, - } + Some(algebra) => match lookup_inhabitant(target, algebra.clone()) { + Some(inh) => Some(inh.template.clone()), + None => None, +}, + None => None, +} } pub fn apply_inhabitant_template1(template: String, inner: String) -> String { @@ -176,11 +133,7 @@ pub fn apply_inhabitant_template1(template: String, inner: String) -> String { } pub fn apply_inhabitant_template2(template: String, first: String, second: String) -> String { - v2_rt::replace( - v2_rt::replace(template, "{0}".to_string(), first), - "{1}".to_string(), - second, - ) + v2_rt::replace(v2_rt::replace(template, "{0}".to_string(), first), "{1}".to_string(), second) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -216,39 +169,30 @@ pub struct CoercionTestEntry { pub fn target_label(target: RenderTarget) -> String { match target { - RenderTarget::Rust => "rust".to_string(), - RenderTarget::Python => "python".to_string(), - RenderTarget::Go => "go".to_string(), - RenderTarget::Dag => "dag".to_string(), - } + RenderTarget::Rust => "rust".to_string(), + RenderTarget::Python => "python".to_string(), + RenderTarget::Go => "go".to_string(), + RenderTarget::Dag => "dag".to_string(), +} } pub fn checkpoint_tests(target: &RenderTarget) -> Rc>> { { let label = target_label(target.clone()); - let cps = target_checkpoints(target.clone()); - if ((cps.clone().len() as i64) == 0) { +let cps = target_checkpoints(target.clone()); +if ((cps.clone().len() as i64) == 0) { Rc::new(vec![]) } else { Rc::new(vec![Rc::new(CoercionTestEntry { - test_name: v2_rt::concat( - v2_rt::concat("coercion_".to_string(), label), - "_checkpoint_resolves_primitives".to_string(), - ), - assertions: Rc::new({ - let mut __result = Vec::new(); - for cp in cps.clone().iter().cloned() { - __result.push(Rc::new(CoercionAssertion::CheckpointAssertion { - target: target.clone(), - dag_name: cp.dag_name.clone(), - expected_type: cp.target_type.clone(), - })); - } - __result - }), - })]) + test_name: v2_rt::concat(v2_rt::concat("coercion_".to_string(), label), "_checkpoint_resolves_primitives".to_string()), + assertions: Rc::new({ let mut __result = Vec::new(); for cp in cps.clone().iter().cloned() { __result.push(Rc::new(CoercionAssertion::CheckpointAssertion { + target: target.clone(), + dag_name: cp.dag_name.clone(), + expected_type: cp.target_type.clone(), +})); } __result }), +})]) } - } +} } pub fn inhabitant_test_names() -> Rc> { @@ -258,173 +202,89 @@ pub fn inhabitant_test_names() -> Rc> { pub fn inhabitant_tests(target: &RenderTarget) -> Rc>> { { let label = target_label(target.clone()); - let assertions = Rc::new({ - let mut __result = Vec::new(); - for name in inhabitant_test_names().iter().cloned() { - __result.extend( - (*match coerce_container_template(target.clone(), name.clone()) { - Some(tmpl) => { - Rc::new(vec![Rc::new(CoercionAssertion::ContainerAssertion { - target: target.clone(), - container_name: name.clone(), - expected_template: tmpl.clone(), - })]) - } - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - if ((assertions.clone().len() as i64) == 0) { +let assertions = Rc::new({ let mut __result = Vec::new(); for name in inhabitant_test_names().iter().cloned() { __result.extend((*match coerce_container_template(target.clone(), name.clone()) { + Some(tmpl) => Rc::new(vec![Rc::new(CoercionAssertion::ContainerAssertion { + target: target.clone(), + container_name: name.clone(), + expected_template: tmpl.clone(), +})]), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +if ((assertions.clone().len() as i64) == 0) { Rc::new(vec![]) } else { Rc::new(vec![Rc::new(CoercionTestEntry { - test_name: v2_rt::concat( - v2_rt::concat("coercion_".to_string(), label), - "_inhabitant_resolves_containers".to_string(), - ), - assertions: assertions.clone(), - })]) + test_name: v2_rt::concat(v2_rt::concat("coercion_".to_string(), label), "_inhabitant_resolves_containers".to_string()), + assertions: assertions.clone(), +})]) } - } +} } pub fn copy_tests() -> Rc>> { { let cps = target_checkpoints(RenderTarget::Rust); - let copy_assertions = Rc::new({ - let mut __result = Vec::new(); - for cp in cps.iter().cloned() { - __result.extend( - (*match cp.is_copy.clone() { - Some(v) => Rc::new(vec![Rc::new(CoercionAssertion::CopyAssertion { - target: RenderTarget::Rust, - dag_name: cp.dag_name.clone(), - expected_copy: v.clone(), - })]), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - if ((copy_assertions.clone().len() as i64) == 0) { +let copy_assertions = Rc::new({ let mut __result = Vec::new(); for cp in cps.iter().cloned() { __result.extend((*match cp.is_copy.clone() { + Some(v) => Rc::new(vec![Rc::new(CoercionAssertion::CopyAssertion { + target: RenderTarget::Rust, + dag_name: cp.dag_name.clone(), + expected_copy: v.clone(), +})]), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +if ((copy_assertions.clone().len() as i64) == 0) { Rc::new(vec![]) } else { Rc::new(vec![Rc::new(CoercionTestEntry { - test_name: "coercion_is_copy_from_checkpoint".to_string(), - assertions: copy_assertions.clone(), - })]) + test_name: "coercion_is_copy_from_checkpoint".to_string(), + assertions: copy_assertions.clone(), +})]) } - } +} } pub fn template_application_tests() -> Rc>> { { - let targets = Rc::new(vec![ - RenderTarget::Rust, - RenderTarget::Python, - RenderTarget::Go, - ]); - let assertions = Rc::new({ - let mut __result = Vec::new(); - for t in targets.iter().cloned() { - __result.extend( - (*{ - let inhs = target_inhabitants(t.clone()); - let int_target = coerce_primitive_type(t.clone(), "Int".to_string()); - let str_target = coerce_primitive_type(t.clone(), "String".to_string()); - Rc::new({ - let mut __result = Vec::new(); - for inh in inhs.clone().iter().cloned() { - __result.extend( - (*if (inh.arity.clone() == 1) { - { - let expected = apply_inhabitant_template1( - inh.template.clone(), - int_target.clone(), - ); - Rc::new(vec![Rc::new( - CoercionAssertion::TemplateAssertion { - template: inh.template.clone(), - args: Rc::new(vec![int_target.clone()]), - expected: expected.clone(), - }, - )]) - } - } else { - if (inh.arity.clone() == 2) { - { - let expected = apply_inhabitant_template2( - inh.template.clone(), - str_target.clone(), - int_target.clone(), - ); - Rc::new(vec![Rc::new( - CoercionAssertion::TemplateAssertion { - template: inh.template.clone(), - args: Rc::new(vec![ - str_target.clone(), - int_target.clone(), - ]), - expected: expected.clone(), - }, - )]) - } - } else { - Rc::new(vec![]) - } - }) - .iter() - .cloned(), - ); - } - __result - }) - }) - .iter() - .cloned(), - ); - } - __result - }); - if ((assertions.clone().len() as i64) == 0) { + let targets = Rc::new(vec![RenderTarget::Rust, RenderTarget::Python, RenderTarget::Go]); +let assertions = Rc::new({ let mut __result = Vec::new(); for t in targets.iter().cloned() { __result.extend((*{ + let inhs = target_inhabitants(t.clone()); +let int_target = coerce_primitive_type(t.clone(), "Int".to_string()); +let str_target = coerce_primitive_type(t.clone(), "String".to_string()); +Rc::new({ let mut __result = Vec::new(); for inh in inhs.clone().iter().cloned() { __result.extend((*if (inh.arity.clone() == 1) { + { + let expected = apply_inhabitant_template1(inh.template.clone(), int_target.clone()); +Rc::new(vec![Rc::new(CoercionAssertion::TemplateAssertion { + template: inh.template.clone(), + args: Rc::new(vec![int_target.clone()]), + expected: expected.clone(), +})]) +} + } else { + if (inh.arity.clone() == 2) { + { + let expected = apply_inhabitant_template2(inh.template.clone(), str_target.clone(), int_target.clone()); +Rc::new(vec![Rc::new(CoercionAssertion::TemplateAssertion { + template: inh.template.clone(), + args: Rc::new(vec![str_target.clone(), int_target.clone()]), + expected: expected.clone(), +})]) +} + } else { + Rc::new(vec![]) + } + }).iter().cloned()); } __result }) +}).iter().cloned()); } __result }); +if ((assertions.clone().len() as i64) == 0) { Rc::new(vec![]) } else { Rc::new(vec![Rc::new(CoercionTestEntry { - test_name: "coercion_template_application".to_string(), - assertions: assertions.clone(), - })]) + test_name: "coercion_template_application".to_string(), + assertions: assertions.clone(), +})]) } - } +} } pub fn extract_coercion_tests() -> Rc>> { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - checkpoint_tests(&RenderTarget::Rust), - checkpoint_tests(&RenderTarget::Python), - ), - checkpoint_tests(&RenderTarget::Go), - ), - inhabitant_tests(&RenderTarget::Rust), - ), - inhabitant_tests(&RenderTarget::Python), - ), - inhabitant_tests(&RenderTarget::Go), - ), - copy_tests(), - ), - template_application_tests(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(checkpoint_tests(&RenderTarget::Rust), checkpoint_tests(&RenderTarget::Python)), checkpoint_tests(&RenderTarget::Go)), inhabitant_tests(&RenderTarget::Rust)), inhabitant_tests(&RenderTarget::Python)), inhabitant_tests(&RenderTarget::Go)), copy_tests()), template_application_tests()) } diff --git a/src/v2/stage0/src/v2_compiler_compile.rs b/src/v2/stage0/src/v2_compiler_compile.rs index 667fde627bc..d563415770e 100644 --- a/src/v2/stage0/src/v2_compiler_compile.rs +++ b/src/v2/stage0/src/v2_compiler_compile.rs @@ -1,76 +1,51 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.compile -use crate::std_induction::RecursionShape::{ - DirectRecursion, ListRecursion, MapValueRecursion, OptionalRecursion, SetRecursion, -}; -use crate::std_induction::ShrinkFactor::{ConstantShrink, ProportionalShrink, UnitShrink}; -use crate::std_induction::SubValueRelation::{ - IteratedSubValue, PreservedValue, StrictSubValue, SubValueUnknown, -}; -pub use crate::std_induction::{InductiveField, RecursionShape, ShrinkFactor, SubValueRelation}; -use crate::std_termination::PositiveDescentAmount::{AdditionalStep, OneStep}; -use crate::std_termination::ProportionalDivisor::{DivideByTwo, StrictlyLarger}; -pub use crate::std_termination::{PositiveDescentAmount, ProportionalDivisor}; -use crate::v2_compiler_artifact::RenderTarget::Dag; -pub use crate::v2_compiler_artifact::{ - default_artifact_plan, Artifact, ArtifactPlan, RenderTarget, -}; -pub use crate::v2_compiler_complexity::{ - build_complexity_report, empty_complexity_report, ComplexityReport, ComplexityViolation, - FuncEntry, RecursionContext, -}; -pub use crate::v2_compiler_emit::{escape_json_string, EmitResult}; -pub use crate::v2_compiler_emit_go::emit_go; -pub use crate::v2_compiler_emit_python::emit_python; -pub use crate::v2_compiler_emit_rust::emit_rust; -pub use crate::v2_compiler_infer::reconcile; -pub use crate::v2_compiler_infer_items::{ResolvedGraph, TypedModule}; -pub use crate::v2_compiler_infer_types::algebra_field_kind_name; -pub use crate::v2_compiler_normalize::{normalize_graph, NormalizeResult}; -use crate::v2_compiler_ownership::OwnershipDecision::SharedError; -pub use crate::v2_compiler_ownership::{analyze_ownership, OwnershipDecision, OwnershipProof}; -pub use crate::v2_compiler_parse::{parse_with_table, ParseResult}; -pub use crate::v2_compiler_resolve::{resolve_modules, ModuleGraph}; -pub use crate::v2_compiler_tokenize::tokenize; +use std::collections::HashMap; +use std::rc::Rc; use crate::v2_rt; -use crate::v2_std_core::BinOp::*; -use crate::v2_std_core::CallSemantics::*; -use crate::v2_std_core::Cardinality::*; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{CompileResult, TextFile, SourceSpan, authored_name_at, ErrorNode, CompilerDiagnostic, is_error_diagnostic, diagnostic_to_message, diagnostic_to_span, make_error_node, no_span, Connective, Cardinality, resource_use_name_at, resource_use_resource, param_node_name_at, param_node_type_expr, param_node_default_value, param_node_span, field_node_name_at, field_node_type_expr, field_node_cardinality, field_node_default_value, field_node_from_key, field_node_span, module_imports, module_items, import_is_all, import_specific_names_at, FieldAccessStyle, FieldValueShape, FieldSummary, InferredNode, VarBindingKind, CallSemantics, MethodSemantics, ExprErrorKind, ExprData, MatchPattern, field_binding_name_at, field_binding_pattern, arg_name_at, arg_value, arm_pattern, arm_guard, arm_body, field_init_node_name_at, field_init_node_value, LiteralValue, BinOp, UnaryOpKind, StringPart, Node, Token, NewlineIndex, build_newline_index, field_access_field_at, expr_call_func_at, lambda_param_names_at, record_lit_type_name_at, foreach_variable_at, expr_method_name_at, InternTable, InternResult, empty_intern_table, intern}; use crate::v2_std_core::CompilerDiagnostic::{InternalError, OwnershipViolation}; -use crate::v2_std_core::Connective::{Arrow, NoConnective}; -use crate::v2_std_core::ExprData::*; -use crate::v2_std_core::ExprErrorKind::*; +use crate::v2_std_core::Connective::{NoConnective, Arrow}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::MethodSemantics::{PlainMethodSemantics, AlgebraMethodSemantics, ServiceMethodSemantics}; +use crate::v2_std_core::Cardinality::*; use crate::v2_std_core::FieldAccessStyle::*; use crate::v2_std_core::FieldValueShape::*; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; -use crate::v2_std_core::LiteralValue::*; +use crate::v2_std_core::VarBindingKind::*; +use crate::v2_std_core::CallSemantics::*; +use crate::v2_std_core::ExprErrorKind::*; +use crate::v2_std_core::ExprData::*; use crate::v2_std_core::MatchPattern::*; -use crate::v2_std_core::MethodSemantics::{ - AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics, -}; -use crate::v2_std_core::StringPart::*; +use crate::v2_std_core::LiteralValue::*; +use crate::v2_std_core::BinOp::*; use crate::v2_std_core::UnaryOpKind::*; -use crate::v2_std_core::VarBindingKind::*; -pub use crate::v2_std_core::{ - arg_name_at, arg_value, arm_body, arm_guard, arm_pattern, authored_name_at, - build_newline_index, diagnostic_to_message, diagnostic_to_span, empty_intern_table, - expr_call_func_at, expr_method_name_at, field_access_field_at, field_binding_name_at, - field_binding_pattern, field_init_node_name_at, field_init_node_value, field_node_cardinality, - field_node_default_value, field_node_from_key, field_node_name_at, field_node_span, - field_node_type_expr, foreach_variable_at, import_is_all, import_specific_names_at, intern, - is_error_diagnostic, lambda_param_names_at, make_error_node, module_imports, module_items, - no_span, param_node_default_value, param_node_name_at, param_node_span, param_node_type_expr, - record_lit_type_name_at, resource_use_name_at, resource_use_resource, BinOp, CallSemantics, - Cardinality, CompileResult, CompilerDiagnostic, Connective, ErrorNode, ExprData, ExprErrorKind, - FieldAccessStyle, FieldSummary, FieldValueShape, InferredNode, InternResult, InternTable, - LiteralValue, MatchPattern, MethodSemantics, NewlineIndex, Node, SourceSpan, StringPart, - TextFile, Token, UnaryOpKind, VarBindingKind, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +use crate::v2_std_core::StringPart::*; +pub use crate::v2_compiler_tokenize::{tokenize}; +pub use crate::v2_compiler_parse::{parse_with_table, ParseResult}; +pub use crate::v2_compiler_resolve::{resolve_modules, ModuleGraph}; +pub use crate::v2_compiler_normalize::{normalize_graph, NormalizeResult}; +pub use crate::v2_compiler_infer_items::{ResolvedGraph, TypedModule}; +pub use crate::v2_compiler_infer::{reconcile}; +pub use crate::v2_compiler_infer_types::{algebra_field_kind_name}; +pub use crate::v2_compiler_emit::{EmitResult, escape_json_string}; +pub use crate::v2_compiler_emit_rust::{emit_rust}; +pub use crate::v2_compiler_emit_python::{emit_python}; +pub use crate::v2_compiler_emit_go::{emit_go}; +pub use crate::v2_compiler_complexity::{ComplexityReport, ComplexityViolation, FuncEntry, RecursionContext, build_complexity_report, empty_complexity_report}; +pub use crate::std_induction::{SubValueRelation, InductiveField, ShrinkFactor, RecursionShape}; +use crate::std_induction::SubValueRelation::{StrictSubValue, IteratedSubValue, PreservedValue, SubValueUnknown}; +use crate::std_induction::ShrinkFactor::{UnitShrink, ConstantShrink, ProportionalShrink}; +use crate::std_induction::RecursionShape::{DirectRecursion, ListRecursion, OptionalRecursion, SetRecursion, MapValueRecursion}; +pub use crate::std_termination::{PositiveDescentAmount, ProportionalDivisor}; +use crate::std_termination::PositiveDescentAmount::{OneStep, AdditionalStep}; +use crate::std_termination::ProportionalDivisor::{DivideByTwo, StrictlyLarger}; +pub use crate::v2_compiler_ownership::{OwnershipProof, OwnershipDecision, analyze_ownership}; +use crate::v2_compiler_ownership::OwnershipDecision::{SharedError}; +pub use crate::v2_compiler_artifact::{ArtifactPlan, Artifact, RenderTarget, default_artifact_plan}; +use crate::v2_compiler_artifact::RenderTarget::{Dag}; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct SourceFile { @@ -104,64 +79,13 @@ pub struct FrontendAccum { } pub fn extract_func_entries(typed: Rc) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for m in Rc::new({ - let mut __result = Vec::new(); - for m in typed.modules.clone().iter().cloned() { - if { - let mut __found = false; - for item in m.items.clone().iter().cloned() { - if (item.body.clone() != None) { - __found = true; - break; - } - } - __found - } { - __result.push(m); - } - } - __result - }) - .iter() - .cloned() - { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in m.items.clone().iter().cloned() { - if (item.body.clone() != None) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(Rc::new(FuncEntry { - name: authored_name_at( - m.type_env.clone().source_indices.clone(), - &item, - ), - body: item.body.clone().clone().unwrap(), - params: item.params.clone(), - span: item.span.clone(), - is_tail_recursive: (item.is_self_recursive.clone() - && (item.has_non_tail_self_call.clone() == false)), - })); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for m in Rc::new({ let mut __result = Vec::new(); for m in typed.modules.clone().iter().cloned() { if { let mut __found = false; for item in m.items.clone().iter().cloned() { if (item.body.clone() != None) { __found = true; break; } } __found } { __result.push(m); } } __result }).iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in m.items.clone().iter().cloned() { if (item.body.clone() != None) { __result.push(item); } } __result }).iter().cloned() { __result.push(Rc::new(FuncEntry { + name: authored_name_at(m.type_env.clone().source_indices.clone(), &item), + body: item.body.clone().clone().unwrap(), + params: item.params.clone(), + span: item.span.clone(), + is_tail_recursive: (item.is_self_recursive.clone() && (item.has_non_tail_self_call.clone() == false)), +})); } __result })).iter().cloned()); } __result }) } pub fn build_recursion_context(typed: Rc) -> RecursionContext { @@ -169,190 +93,86 @@ pub fn build_recursion_context(typed: Rc) -> RecursionContext { } pub fn extract_ownership_proofs(typed: Rc) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for m in Rc::new({ - let mut __result = Vec::new(); - for m in typed.modules.clone().iter().cloned() { - if { - let mut __found = false; - for item in m.items.clone().iter().cloned() { - if (item.body.clone() != None) { - __found = true; - break; - } - } - __found - } { - __result.push(m); - } - } - __result - }) - .iter() - .cloned() - { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in m.items.clone().iter().cloned() { - if (item.body.clone() != None) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(analyze_ownership( - authored_name_at(m.type_env.clone().source_indices.clone(), &item), - item.params.clone(), - item.body.clone().clone().unwrap(), - &m.type_env.clone().source_indices.clone(), - )); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for m in Rc::new({ let mut __result = Vec::new(); for m in typed.modules.clone().iter().cloned() { if { let mut __found = false; for item in m.items.clone().iter().cloned() { if (item.body.clone() != None) { __found = true; break; } } __found } { __result.push(m); } } __result }).iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in m.items.clone().iter().cloned() { if (item.body.clone() != None) { __result.push(item); } } __result }).iter().cloned() { __result.push(analyze_ownership(authored_name_at(m.type_env.clone().source_indices.clone(), &item), item.params.clone(), item.body.clone().clone().unwrap(), &m.type_env.clone().source_indices.clone())); } __result })).iter().cloned()); } __result }) } pub fn ownership_diagnostics(proofs: Rc>>) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for proof in proofs.iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for decision in proof.decisions.clone().iter().cloned() { - __result.extend( - (*match (*decision.clone()).clone() { - OwnershipDecision::SharedError { - binding, - consumer_count: count, - sites, - .. - } => Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::OwnershipViolation { - binding: binding.clone(), - fn_name: proof.func_name.clone(), - consumers: count.clone(), - span: no_span(), - }), - proof.func_name.clone(), - )]), - _ => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for proof in proofs.iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for decision in proof.decisions.clone().iter().cloned() { __result.extend((*match (*decision.clone()).clone() { + OwnershipDecision::SharedError { binding, consumer_count: count, sites, .. } => Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::OwnershipViolation { + binding: binding.clone(), + fn_name: proof.func_name.clone(), + consumers: count.clone(), + span: no_span(), +}), proof.func_name.clone())]), + _ => Rc::new(vec![]), +}).iter().cloned()); } __result })).iter().cloned()); } __result }) } pub fn complexity_diagnostics(complexity: Rc) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for v in complexity.violations.clone().iter().cloned() { - __result.push(make_error_node( - Rc::new(CompilerDiagnostic::ComplexityUnknown { - func_name: v.func_name.clone(), - reason: v.reason.clone(), - span: v.span.clone(), - }), - v.func_name.clone(), - )); - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for v in complexity.violations.clone().iter().cloned() { __result.push(make_error_node(Rc::new(CompilerDiagnostic::ComplexityUnknown { + func_name: v.func_name.clone(), + reason: v.reason.clone(), + span: v.span.clone(), +}), v.func_name.clone())); } __result }) } pub fn empty_artifact_plan() -> Rc { Rc::new(ArtifactPlan { - artifacts: Rc::new(vec![]), - boundaries: Rc::new(vec![]), - }) + artifacts: Rc::new(vec![]), + boundaries: Rc::new(vec![]), +}) } pub fn compile_bundle_error(message: String) -> Rc { - make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: message, - span: no_span(), - }), - "".to_string(), - ) + make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: message, + span: no_span(), +}), "".to_string()) } pub fn emit_artifact(typed: Rc, artifact: Rc) -> Rc { match artifact.target.clone() { - RenderTarget::Rust => emit_rust(&typed), - RenderTarget::Python => emit_python(&typed), - RenderTarget::Go => emit_go(&typed), - RenderTarget::Dag => emit_dag_artifact(&typed), - } + RenderTarget::Rust => emit_rust(&typed), + RenderTarget::Python => emit_python(&typed), + RenderTarget::Go => emit_go(&typed), + RenderTarget::Dag => emit_dag_artifact(&typed), +} } pub fn json_quote(s: String) -> String { - v2_rt::concat( - v2_rt::concat("\"".to_string(), escape_json_string(s)), - "\"".to_string(), - ) + v2_rt::concat(v2_rt::concat("\"".to_string(), escape_json_string(s)), "\"".to_string()) } pub fn json_list(items: Rc>) -> String { - v2_rt::concat( - v2_rt::concat("[".to_string(), items.join(&", ".to_string())), - "]".to_string(), - ) + v2_rt::concat(v2_rt::concat("[".to_string(), items.join(&", ".to_string())), "]".to_string()) } pub fn json_optional_string(value: Option) -> String { match value { - Some(inner) => json_quote(inner.clone()), - None => "null".to_string(), - } + Some(inner) => json_quote(inner.clone()), + None => "null".to_string(), +} } -pub fn json_optional_node( - value: Option>, - source_indices: Rc>>, -) -> String { +pub fn json_optional_node(value: Option>, source_indices: Rc>>) -> String { match value { - Some(inner) => serialize_node(&inner, &source_indices), - None => "null".to_string(), - } + Some(inner) => serialize_node(&inner, &source_indices), + None => "null".to_string(), +} } -pub fn json_optional_inferred_node( - value: Option>, - source_indices: Rc>>, -) -> String { +pub fn json_optional_inferred_node(value: Option>, source_indices: Rc>>) -> String { match value { - Some(inner) => serialize_inferred_node(inner.clone(), source_indices), - None => "null".to_string(), - } + Some(inner) => serialize_inferred_node(inner.clone(), source_indices), + None => "null".to_string(), +} } pub fn json_optional_span(value: Option>) -> String { match value { - Some(inner) => serialize_span(&inner), - None => "null".to_string(), - } + Some(inner) => serialize_span(&inner), + None => "null".to_string(), +} } pub fn json_bool(value: bool) -> String { @@ -365,1197 +185,306 @@ pub fn json_bool(value: bool) -> String { pub fn connective_name(value: Connective) -> String { match value { - Connective::Conj => "Conj".to_string(), - Connective::Disj => "Disj".to_string(), - Connective::NoConnective => "NoConnective".to_string(), - Connective::Arrow => "Arrow".to_string(), - } + Connective::Conj => "Conj".to_string(), + Connective::Disj => "Disj".to_string(), + Connective::NoConnective => "NoConnective".to_string(), + Connective::Arrow => "Arrow".to_string(), +} } pub fn cardinality_name(value: Cardinality) -> String { match value { - Cardinality::Required => "Required".to_string(), - Cardinality::CardOptional => "CardOptional".to_string(), - } + Cardinality::Required => "Required".to_string(), + Cardinality::CardOptional => "CardOptional".to_string(), +} } pub fn field_access_style_name(value: FieldAccessStyle) -> String { match value { - FieldAccessStyle::StoredField => "StoredField".to_string(), - FieldAccessStyle::EnumAccessor => "EnumAccessor".to_string(), - FieldAccessStyle::OptionalUnwrap => "OptionalUnwrap".to_string(), - FieldAccessStyle::TupleFirst => "TupleFirst".to_string(), - FieldAccessStyle::TupleSecond => "TupleSecond".to_string(), - } + FieldAccessStyle::StoredField => "StoredField".to_string(), + FieldAccessStyle::EnumAccessor => "EnumAccessor".to_string(), + FieldAccessStyle::OptionalUnwrap => "OptionalUnwrap".to_string(), + FieldAccessStyle::TupleFirst => "TupleFirst".to_string(), + FieldAccessStyle::TupleSecond => "TupleSecond".to_string(), +} } pub fn field_value_shape_name(value: FieldValueShape) -> String { match value { - FieldValueShape::PlainValue => "PlainValue".to_string(), - FieldValueShape::OptionalValue => "OptionalValue".to_string(), - } + FieldValueShape::PlainValue => "PlainValue".to_string(), + FieldValueShape::OptionalValue => "OptionalValue".to_string(), +} } pub fn var_binding_kind_name(value: Rc) -> String { match (*value).clone() { - VarBindingKind::LocalValueBinding => "LocalValueBinding".to_string(), - VarBindingKind::FunctionValueBinding => "FunctionValueBinding".to_string(), - VarBindingKind::VariantValueBinding { .. } => "VariantValueBinding".to_string(), - VarBindingKind::MatchBoundBinding => "MatchBoundBinding".to_string(), - } + VarBindingKind::LocalValueBinding => "LocalValueBinding".to_string(), + VarBindingKind::FunctionValueBinding => "FunctionValueBinding".to_string(), + VarBindingKind::VariantValueBinding { .. } => "VariantValueBinding".to_string(), + VarBindingKind::MatchBoundBinding => "MatchBoundBinding".to_string(), +} } pub fn call_semantics_name(value: CallSemantics) -> String { match value { - CallSemantics::PlainCallSemantics => "PlainCallSemantics".to_string(), - CallSemantics::LookupCallSemantics => "LookupCallSemantics".to_string(), - } + CallSemantics::PlainCallSemantics => "PlainCallSemantics".to_string(), + CallSemantics::LookupCallSemantics => "LookupCallSemantics".to_string(), +} } pub fn expr_error_kind_name(value: ExprErrorKind) -> String { match value { - ExprErrorKind::ParseRecoveryError => "ParseRecoveryError".to_string(), - ExprErrorKind::SemanticExprError => "SemanticExprError".to_string(), - ExprErrorKind::InternalExprError => "InternalExprError".to_string(), - } + ExprErrorKind::ParseRecoveryError => "ParseRecoveryError".to_string(), + ExprErrorKind::SemanticExprError => "SemanticExprError".to_string(), + ExprErrorKind::InternalExprError => "InternalExprError".to_string(), +} } pub fn bin_op_name(value: BinOp) -> String { match value { - BinOp::Add => "Add".to_string(), - BinOp::Sub => "Sub".to_string(), - BinOp::Mul => "Mul".to_string(), - BinOp::Div => "Div".to_string(), - BinOp::Mod => "Mod".to_string(), - BinOp::Eq => "Eq".to_string(), - BinOp::Ne => "Ne".to_string(), - BinOp::Lt => "Lt".to_string(), - BinOp::Gt => "Gt".to_string(), - BinOp::Le => "Le".to_string(), - BinOp::Ge => "Ge".to_string(), - BinOp::And => "And".to_string(), - BinOp::Or => "Or".to_string(), - BinOp::NullCoalesce => "NullCoalesce".to_string(), - } + BinOp::Add => "Add".to_string(), + BinOp::Sub => "Sub".to_string(), + BinOp::Mul => "Mul".to_string(), + BinOp::Div => "Div".to_string(), + BinOp::Mod => "Mod".to_string(), + BinOp::Eq => "Eq".to_string(), + BinOp::Ne => "Ne".to_string(), + BinOp::Lt => "Lt".to_string(), + BinOp::Gt => "Gt".to_string(), + BinOp::Le => "Le".to_string(), + BinOp::Ge => "Ge".to_string(), + BinOp::And => "And".to_string(), + BinOp::Or => "Or".to_string(), + BinOp::NullCoalesce => "NullCoalesce".to_string(), +} } pub fn unary_op_name(value: UnaryOpKind) -> String { match value { - UnaryOpKind::Not => "Not".to_string(), - UnaryOpKind::Neg => "Neg".to_string(), - } + UnaryOpKind::Not => "Not".to_string(), + UnaryOpKind::Neg => "Neg".to_string(), +} } pub fn serialize_span(span: &Rc) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("{\"start\": ".to_string(), (span.start.clone()).to_string()), - ", \"end\": ".to_string(), - ), - (span.end.clone()).to_string(), - ), - "}".to_string(), - ) -} - -pub fn serialize_import_node( - imp: &Rc, - source_indices: &Rc>>, -) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"start\": ".to_string(), (span.start.clone()).to_string()), ", \"end\": ".to_string()), (span.end.clone()).to_string()), "}".to_string()) +} + +pub fn serialize_import_node(imp: &Rc, source_indices: &Rc>>) -> String { { let names_json = if import_is_all(imp.clone()) { "{\"kind\": \"ImportAll\"}".to_string() } else { - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ImportSpecific\", \"names\": ".to_string(), - json_list(Rc::new({ - let mut __result = Vec::new(); - for v in import_specific_names_at(imp.clone(), source_indices.clone()) - .iter() - .cloned() - { - __result.push(json_quote(v.clone())); - } - __result - })), - ), - "}".to_string(), - ) + v2_rt::concat(v2_rt::concat("{\"kind\": \"ImportSpecific\", \"names\": ".to_string(), json_list(Rc::new({ let mut __result = Vec::new(); for v in import_specific_names_at(imp.clone(), source_indices.clone()).iter().cloned() { __result.push(json_quote(v.clone())); } __result }))), "}".to_string()) }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"module_path\": ".to_string(), - json_quote(authored_name_at(source_indices.clone(), &imp)), - ), - ", \"names\": ".to_string(), - ), - names_json, - ), - ", \"span\": ".to_string(), - ), - serialize_span(&imp.span.clone()), - ), - "}".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"module_path\": ".to_string(), json_quote(authored_name_at(source_indices.clone(), &imp))), ", \"names\": ".to_string()), names_json), ", \"span\": ".to_string()), serialize_span(&imp.span.clone())), "}".to_string()) +} } pub fn serialize_field_summary(summary: &Rc) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"access_style\": ".to_string(), - json_quote(field_access_style_name(summary.access_style.clone())), - ), - ", \"value_shape\": ".to_string(), - ), - json_quote(field_value_shape_name(summary.value_shape.clone())), - ), - "}".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"access_style\": ".to_string(), json_quote(field_access_style_name(summary.access_style.clone()))), ", \"value_shape\": ".to_string()), json_quote(field_value_shape_name(summary.value_shape.clone()))), "}".to_string()) } pub fn serialize_literal(value: Rc) -> String { match (*value).clone() { - LiteralValue::LitStr { value: inner, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"LitStr\", \"value\": ".to_string(), - json_quote(inner.clone()), - ), - "}".to_string(), - ), - LiteralValue::LitInt { value: inner, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"LitInt\", \"value\": ".to_string(), - (inner.clone()).to_string(), - ), - "}".to_string(), - ), - LiteralValue::LitFloat { value: inner, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"LitFloat\", \"value\": ".to_string(), - json_quote(inner.clone()), - ), - "}".to_string(), - ), - LiteralValue::LitBool { value: inner, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"LitBool\", \"value\": ".to_string(), - json_bool(inner.clone()), - ), - "}".to_string(), - ), - LiteralValue::LitNull => "{\"kind\": \"LitNull\"}".to_string(), - } + LiteralValue::LitStr { value: inner, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"LitStr\", \"value\": ".to_string(), json_quote(inner.clone())), "}".to_string()), + LiteralValue::LitInt { value: inner, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"LitInt\", \"value\": ".to_string(), (inner.clone()).to_string()), "}".to_string()), + LiteralValue::LitFloat { value: inner, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"LitFloat\", \"value\": ".to_string(), json_quote(inner.clone())), "}".to_string()), + LiteralValue::LitBool { value: inner, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"LitBool\", \"value\": ".to_string(), json_bool(inner.clone())), "}".to_string()), + LiteralValue::LitNull => "{\"kind\": \"LitNull\"}".to_string(), +} } -pub fn serialize_field_binding( - binding: &Rc, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"field_name\": ".to_string(), - json_quote(field_binding_name_at( - binding.clone(), - source_indices.clone(), - )), - ), - ", \"binding\": ".to_string(), - ), - serialize_match_pattern( - field_binding_pattern(binding.clone()), - source_indices.clone(), - ), - ), - "}".to_string(), - ) -} - -pub fn serialize_match_pattern( - pattern: Rc, - source_indices: Rc>>, -) -> String { +pub fn serialize_field_binding(binding: &Rc, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"field_name\": ".to_string(), json_quote(field_binding_name_at(binding.clone(), source_indices.clone()))), ", \"binding\": ".to_string()), serialize_match_pattern(field_binding_pattern(binding.clone()), source_indices.clone())), "}".to_string()) +} + +pub fn serialize_match_pattern(pattern: Rc, source_indices: Rc>>) -> String { match (*pattern).clone() { - MatchPattern::Bind { name: inner, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"Bind\", \"name\": ".to_string(), - json_quote(inner.clone()), - ), - "}".to_string(), - ), - MatchPattern::LitPattern { value: inner, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"LitPattern\", \"value\": ".to_string(), - serialize_literal(inner.clone()), - ), - "}".to_string(), - ), - MatchPattern::VariantPattern { - name: inner, - parent_enum, - field_bindings, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"VariantPattern\", \"name\": ".to_string(), - json_quote(inner.clone()), - ), - ", \"parent_enum\": ".to_string(), - ), - json_optional_string(parent_enum.clone()), - ), - ", \"field_bindings\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for fb in field_bindings.clone().iter().cloned() { - __result.push(serialize_field_binding(&fb, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - MatchPattern::Wildcard => "{\"kind\": \"Wildcard\"}".to_string(), - } + MatchPattern::Bind { name: inner, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"Bind\", \"name\": ".to_string(), json_quote(inner.clone())), "}".to_string()), + MatchPattern::LitPattern { value: inner, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"LitPattern\", \"value\": ".to_string(), serialize_literal(inner.clone())), "}".to_string()), + MatchPattern::VariantPattern { name: inner, parent_enum, field_bindings, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"VariantPattern\", \"name\": ".to_string(), json_quote(inner.clone())), ", \"parent_enum\": ".to_string()), json_optional_string(parent_enum.clone())), ", \"field_bindings\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for fb in field_bindings.clone().iter().cloned() { __result.push(serialize_field_binding(&fb, &source_indices)); } __result }))), "}".to_string()), + MatchPattern::Wildcard => "{\"kind\": \"Wildcard\"}".to_string(), +} } -pub fn serialize_named_arg( - arg: &Rc, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"name\": ".to_string(), - json_optional_string(arg_name_at(arg.clone(), source_indices.clone())), - ), - ", \"value\": ".to_string(), - ), - serialize_node(&arg_value(&arg), &source_indices), - ), - "}".to_string(), - ) -} - -pub fn serialize_match_arm( - arm: &Rc, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"pattern\": ".to_string(), - serialize_match_pattern( - arm_pattern(arm.clone()), - source_indices.clone(), - ), - ), - ", \"guard\": ".to_string(), - ), - json_optional_node(arm_guard(&arm), source_indices.clone()), - ), - ", \"body\": ".to_string(), - ), - serialize_node(&arm_body(&arm), &source_indices), - ), - "}".to_string(), - ) -} - -pub fn serialize_field_init( - field_init: &Rc, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"name\": ".to_string(), - json_quote(field_init_node_name_at( - field_init.clone(), - source_indices.clone(), - )), - ), - ", \"value\": ".to_string(), - ), - serialize_node(&field_init_node_value(&field_init), &source_indices), - ), - "}".to_string(), - ) -} - -pub fn serialize_string_part( - part: Rc, - source_indices: Rc>>, -) -> String { +pub fn serialize_named_arg(arg: &Rc, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"name\": ".to_string(), json_optional_string(arg_name_at(arg.clone(), source_indices.clone()))), ", \"value\": ".to_string()), serialize_node(&arg_value(&arg), &source_indices)), "}".to_string()) +} + +pub fn serialize_match_arm(arm: &Rc, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"pattern\": ".to_string(), serialize_match_pattern(arm_pattern(arm.clone()), source_indices.clone())), ", \"guard\": ".to_string()), json_optional_node(arm_guard(&arm), source_indices.clone())), ", \"body\": ".to_string()), serialize_node(&arm_body(&arm), &source_indices)), "}".to_string()) +} + +pub fn serialize_field_init(field_init: &Rc, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"name\": ".to_string(), json_quote(field_init_node_name_at(field_init.clone(), source_indices.clone()))), ", \"value\": ".to_string()), serialize_node(&field_init_node_value(&field_init), &source_indices)), "}".to_string()) +} + +pub fn serialize_string_part(part: Rc, source_indices: Rc>>) -> String { match (*part).clone() { - StringPart::Text { value: inner, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"Text\", \"value\": ".to_string(), - json_quote(inner.clone()), - ), - "}".to_string(), - ), - StringPart::Interpolation { expr: inner, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"Interpolation\", \"expr\": ".to_string(), - serialize_node(&inner, &source_indices), - ), - "}".to_string(), - ), - } + StringPart::Text { value: inner, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"Text\", \"value\": ".to_string(), json_quote(inner.clone())), "}".to_string()), + StringPart::Interpolation { expr: inner, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"Interpolation\", \"expr\": ".to_string(), serialize_node(&inner, &source_indices)), "}".to_string()), +} } pub fn serialize_call_semantics(value: Option) -> String { match value { - Some(inner) => v2_rt::concat( - v2_rt::concat( - "{\"kind\": ".to_string(), - json_quote(call_semantics_name(inner.clone())), - ), - "}".to_string(), - ), - None => "null".to_string(), - } + Some(inner) => v2_rt::concat(v2_rt::concat("{\"kind\": ".to_string(), json_quote(call_semantics_name(inner.clone()))), "}".to_string()), + None => "null".to_string(), +} } -pub fn serialize_method_semantics( - value: Option>, - source_indices: &Rc>>, -) -> String { +pub fn serialize_method_semantics(value: Option>, source_indices: &Rc>>) -> String { match value.as_deref().cloned() { - Some(MethodSemantics::PlainMethodSemantics) => { - "{\"kind\": \"PlainMethodSemantics\"}".to_string() - } - Some(MethodSemantics::AlgebraMethodSemantics { - method_def, - fold_accumulator_type, - .. - }) => { - let mn = authored_name_at(source_indices.clone(), &method_def); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"AlgebraMethodSemantics\", \"method_name\": ".to_string(), - json_quote(mn), - ), - ", \"fold_accumulator_type\": ".to_string(), - ), - json_optional_node(fold_accumulator_type.clone(), source_indices.clone()), - ), - "}".to_string(), - ) - } - Some(MethodSemantics::ServiceMethodSemantics { - service_name, - op_params, - .. - }) => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ServiceMethodSemantics\", \"service_name\": ".to_string(), - json_quote(service_name.clone()), - ), - ", \"op_params\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for p in op_params.clone().iter().cloned() { - __result.push(serialize_param(&p, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - None => "null".to_string(), - } + Some(MethodSemantics::PlainMethodSemantics) => "{\"kind\": \"PlainMethodSemantics\"}".to_string(), + Some(MethodSemantics::AlgebraMethodSemantics { method_def, fold_accumulator_type, .. }) => { + let mn = authored_name_at(source_indices.clone(), &method_def); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"AlgebraMethodSemantics\", \"method_name\": ".to_string(), json_quote(mn)), ", \"fold_accumulator_type\": ".to_string()), json_optional_node(fold_accumulator_type.clone(), source_indices.clone())), "}".to_string()) +}, + Some(MethodSemantics::ServiceMethodSemantics { service_name, op_params, .. }) => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ServiceMethodSemantics\", \"service_name\": ".to_string(), json_quote(service_name.clone())), ", \"op_params\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for p in op_params.clone().iter().cloned() { __result.push(serialize_param(&p, &source_indices)); } __result }))), "}".to_string()), + None => "null".to_string(), +} } pub fn serialize_recursion_shape(shape: RecursionShape) -> String { match shape { - RecursionShape::DirectRecursion => "{\"_variant\": \"DirectRecursion\"}".to_string(), - RecursionShape::ListRecursion => "{\"_variant\": \"ListRecursion\"}".to_string(), - RecursionShape::OptionalRecursion => "{\"_variant\": \"OptionalRecursion\"}".to_string(), - RecursionShape::SetRecursion => "{\"_variant\": \"SetRecursion\"}".to_string(), - RecursionShape::MapValueRecursion => "{\"_variant\": \"MapValueRecursion\"}".to_string(), - } + RecursionShape::DirectRecursion => "{\"_variant\": \"DirectRecursion\"}".to_string(), + RecursionShape::ListRecursion => "{\"_variant\": \"ListRecursion\"}".to_string(), + RecursionShape::OptionalRecursion => "{\"_variant\": \"OptionalRecursion\"}".to_string(), + RecursionShape::SetRecursion => "{\"_variant\": \"SetRecursion\"}".to_string(), + RecursionShape::MapValueRecursion => "{\"_variant\": \"MapValueRecursion\"}".to_string(), +} } pub fn serialize_inductive_field(field: &Rc) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"type_name\": ".to_string(), - json_quote(field.type_name.clone()), - ), - ", \"variant_name\": ".to_string(), - ), - json_quote(field.variant_name.clone()), - ), - ", \"field_name\": ".to_string(), - ), - json_quote(field.field_name.clone()), - ), - ", \"shape\": ".to_string(), - ), - serialize_recursion_shape(field.shape.clone()), - ), - "}".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"type_name\": ".to_string(), json_quote(field.type_name.clone())), ", \"variant_name\": ".to_string()), json_quote(field.variant_name.clone())), ", \"field_name\": ".to_string()), json_quote(field.field_name.clone())), ", \"shape\": ".to_string()), serialize_recursion_shape(field.shape.clone())), "}".to_string()) } pub fn serialize_positive_descent_amount(steps: Rc) -> String { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*steps).clone() { - PositiveDescentAmount::OneStep => "{\"_variant\": \"OneStep\"}".to_string(), - PositiveDescentAmount::AdditionalStep { previous: p, .. } => v2_rt::concat( - v2_rt::concat( - "{\"_variant\": \"AdditionalStep\", \"previous\": ".to_string(), - serialize_positive_descent_amount(p.clone()), - ), - "}".to_string(), - ), + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*steps).clone() { + PositiveDescentAmount::OneStep => "{\"_variant\": \"OneStep\"}".to_string(), + PositiveDescentAmount::AdditionalStep { previous: p, .. } => v2_rt::concat(v2_rt::concat("{\"_variant\": \"AdditionalStep\", \"previous\": ".to_string(), serialize_positive_descent_amount(p.clone())), "}".to_string()), +} }) } pub fn serialize_proportional_divisor(d: Rc) -> String { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*d).clone() { - ProportionalDivisor::DivideByTwo => "{\"_variant\": \"DivideByTwo\"}".to_string(), - ProportionalDivisor::StrictlyLarger { inner: i, .. } => v2_rt::concat( - v2_rt::concat( - "{\"_variant\": \"StrictlyLarger\", \"inner\": ".to_string(), - serialize_proportional_divisor(i.clone()), - ), - "}".to_string(), - ), + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*d).clone() { + ProportionalDivisor::DivideByTwo => "{\"_variant\": \"DivideByTwo\"}".to_string(), + ProportionalDivisor::StrictlyLarger { inner: i, .. } => v2_rt::concat(v2_rt::concat("{\"_variant\": \"StrictlyLarger\", \"inner\": ".to_string(), serialize_proportional_divisor(i.clone())), "}".to_string()), +} }) } pub fn serialize_shrink_factor(factor: Rc) -> String { match (*factor).clone() { - ShrinkFactor::UnitShrink => "{\"_variant\": \"UnitShrink\"}".to_string(), - ShrinkFactor::ConstantShrink { steps: s, .. } => v2_rt::concat( - v2_rt::concat( - "{\"_variant\": \"ConstantShrink\", \"steps\": ".to_string(), - serialize_positive_descent_amount(s.clone()), - ), - "}".to_string(), - ), - ShrinkFactor::ProportionalShrink { divisor: d, .. } => v2_rt::concat( - v2_rt::concat( - "{\"_variant\": \"ProportionalShrink\", \"divisor\": ".to_string(), - serialize_proportional_divisor(d.clone()), - ), - "}".to_string(), - ), - } + ShrinkFactor::UnitShrink => "{\"_variant\": \"UnitShrink\"}".to_string(), + ShrinkFactor::ConstantShrink { steps: s, .. } => v2_rt::concat(v2_rt::concat("{\"_variant\": \"ConstantShrink\", \"steps\": ".to_string(), serialize_positive_descent_amount(s.clone())), "}".to_string()), + ShrinkFactor::ProportionalShrink { divisor: d, .. } => v2_rt::concat(v2_rt::concat("{\"_variant\": \"ProportionalShrink\", \"divisor\": ".to_string(), serialize_proportional_divisor(d.clone())), "}".to_string()), +} } pub fn serialize_sub_value_relation(rel: Rc) -> String { match (*rel).clone() { - SubValueRelation::StrictSubValue { - field: f, - factor: fac, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"_variant\": \"StrictSubValue\", \"field\": ".to_string(), - serialize_inductive_field(&f), - ), - ", \"factor\": ".to_string(), - ), - serialize_shrink_factor(fac.clone()), - ), - "}".to_string(), - ), - SubValueRelation::IteratedSubValue { field: f, .. } => v2_rt::concat( - v2_rt::concat( - "{\"_variant\": \"IteratedSubValue\", \"field\": ".to_string(), - serialize_inductive_field(&f), - ), - "}".to_string(), - ), - SubValueRelation::ArithmeticDescent { - param: p, - factor: fac, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"_variant\": \"ArithmeticDescent\", \"param\": ".to_string(), - json_quote(p.clone()), - ), - ", \"factor\": ".to_string(), - ), - serialize_shrink_factor(fac.clone()), - ), - "}".to_string(), - ), - SubValueRelation::PreservedValue => "{\"_variant\": \"PreservedValue\"}".to_string(), - SubValueRelation::SubValueUnknown => "{\"_variant\": \"SubValueUnknown\"}".to_string(), - } + SubValueRelation::StrictSubValue { field: f, factor: fac, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"_variant\": \"StrictSubValue\", \"field\": ".to_string(), serialize_inductive_field(&f)), ", \"factor\": ".to_string()), serialize_shrink_factor(fac.clone())), "}".to_string()), + SubValueRelation::IteratedSubValue { field: f, .. } => v2_rt::concat(v2_rt::concat("{\"_variant\": \"IteratedSubValue\", \"field\": ".to_string(), serialize_inductive_field(&f)), "}".to_string()), + SubValueRelation::ArithmeticDescent { param: p, factor: fac, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"_variant\": \"ArithmeticDescent\", \"param\": ".to_string(), json_quote(p.clone())), ", \"factor\": ".to_string()), serialize_shrink_factor(fac.clone())), "}".to_string()), + SubValueRelation::PreservedValue => "{\"_variant\": \"PreservedValue\"}".to_string(), + SubValueRelation::SubValueUnknown => "{\"_variant\": \"SubValueUnknown\"}".to_string(), +} } pub fn serialize_descent_evidence(de: Option>>>) -> String { match de { - Some(evidence) => json_list(Rc::new({ - let mut __result = Vec::new(); - for rel in evidence.clone().iter().cloned() { - __result.push(serialize_sub_value_relation(rel.clone())); - } - __result - })), - None => "null".to_string(), - } + Some(evidence) => json_list(Rc::new({ let mut __result = Vec::new(); for rel in evidence.clone().iter().cloned() { __result.push(serialize_sub_value_relation(rel.clone())); } __result })), + None => "null".to_string(), +} } -pub fn serialize_expr_data( - expr_node: &Rc, - source_indices: &Rc>>, -) -> String { +pub fn serialize_expr_data(expr_node: &Rc, source_indices: &Rc>>) -> String { { let ch = expr_node.children.clone(); - let name = authored_name_at(source_indices.clone(), &expr_node); - match (*expr_node.expr_data.clone()).clone() { - ExprData::NoExprData => "{\"kind\": \"NoExprData\"}".to_string(), - ExprData::ExprLiteral { value, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprLiteral\", \"value\": ".to_string(), - serialize_literal(value.clone()), - ), - "}".to_string(), - ), - ExprData::ExprError { kind, message, .. } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprError\", \"error_kind\": ".to_string(), - json_quote(expr_error_kind_name(kind.clone())), - ), - ", \"message\": ".to_string(), - ), - json_quote(message.clone()), - ), - "}".to_string(), - ), - ExprData::ExprVar { binding_kind, .. } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprVar\", \"name\": ".to_string(), - json_quote(name), - ), - ", \"binding_kind\": ".to_string(), - ), - match binding_kind.clone() { - Some(inner) => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": ".to_string(), - json_quote(var_binding_kind_name(inner.clone())), - ), - match (*inner.clone()).clone() { - VarBindingKind::VariantValueBinding { parent_enum, .. } => { - v2_rt::concat( - ", \"parent_enum\": ".to_string(), - json_quote(parent_enum.clone()), - ) - } - _ => "".to_string(), - }, - ), - "}".to_string(), - ), - None => "null".to_string(), - }, - ), - "}".to_string(), - ), - ExprData::ExprFieldAccess { summary, .. } => { - let field = field_access_field_at(expr_node.clone(), source_indices.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprFieldAccess\", \"field\": ".to_string(), - json_quote(field), - ), - ", \"summary\": ".to_string(), - ), - match summary.clone() { - Some(inner) => serialize_field_summary(&inner), - None => "null".to_string(), - }, - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ) - } - ExprData::ExprCall { - call_semantics, - descent_evidence: de, - .. - } => { - let func = expr_call_func_at(expr_node.clone(), source_indices.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprCall\", \"func\": ".to_string(), - json_quote(func), - ), - ", \"call_semantics\": ".to_string(), - ), - serialize_call_semantics(call_semantics.clone()), - ), - ", \"descent_evidence\": ".to_string(), - ), - serialize_descent_evidence(de.clone()), - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ) - } - ExprData::ExprMethodCall { - method_semantics, .. - } => { - let method = expr_method_name_at(expr_node.clone(), source_indices.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprMethodCall\", \"method\": ".to_string(), - json_quote(method), - ), - ", \"method_semantics\": ".to_string(), - ), - serialize_method_semantics( - method_semantics.clone(), - &source_indices, - ), - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ) - } - ExprData::ExprBinOp { - op, - algebra_field: af, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprBinOp\", \"op\": ".to_string(), - json_quote(bin_op_name(op.clone())), - ), - ", \"algebra_field\": ".to_string(), - ), - match af.clone() { - Some(f) => json_quote(algebra_field_kind_name(f.clone())), - None => "null".to_string(), - }, - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprUnaryOp { op, .. } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprUnaryOp\", \"op\": ".to_string(), - json_quote(unary_op_name(op.clone())), - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprLambda => { - let params = lambda_param_names_at(expr_node.clone(), source_indices.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprLambda\", \"params\": ".to_string(), - json_list(Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - __result.push(json_quote(p.clone())); - } - __result - })), - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ) - } - ExprData::ExprLet => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprLet\", \"name\": ".to_string(), - json_quote(name), - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprRecordLit { parent_enum, .. } => { - let type_name = record_lit_type_name_at(expr_node.clone(), source_indices.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprRecordLit\", \"type_name\": ".to_string(), - json_optional_string(type_name), - ), - ", \"parent_enum\": ".to_string(), - ), - json_optional_string(parent_enum.clone()), - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ) - } - ExprData::ExprForEach => { - let variable = foreach_variable_at(expr_node.clone(), source_indices.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprForEach\", \"variable\": ".to_string(), - json_quote(variable), - ), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ) - } - ExprData::ExprMatch => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprMatch\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprIf => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprIf\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprListLit => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprListLit\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprStringInterp => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprStringInterp\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprBlock => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprBlock\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprCast => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprCast\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprIndex => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprIndex\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprSlice => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprSlice\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - ExprData::ExprReturn => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"ExprReturn\"".to_string(), - ", \"children\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for c in ch.iter().cloned() { - __result.push(serialize_node(&c, &source_indices)); - } - __result - })), - ), - "}".to_string(), - ), - } - } +let name = authored_name_at(source_indices.clone(), &expr_node); +match (*expr_node.expr_data.clone()).clone() { + ExprData::NoExprData => "{\"kind\": \"NoExprData\"}".to_string(), + ExprData::ExprLiteral { value, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprLiteral\", \"value\": ".to_string(), serialize_literal(value.clone())), "}".to_string()), + ExprData::ExprError { kind, message, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprError\", \"error_kind\": ".to_string(), json_quote(expr_error_kind_name(kind.clone()))), ", \"message\": ".to_string()), json_quote(message.clone())), "}".to_string()), + ExprData::ExprVar { binding_kind, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprVar\", \"name\": ".to_string(), json_quote(name)), ", \"binding_kind\": ".to_string()), match binding_kind.clone() { + Some(inner) => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": ".to_string(), json_quote(var_binding_kind_name(inner.clone()))), match (*inner.clone()).clone() { + VarBindingKind::VariantValueBinding { parent_enum, .. } => v2_rt::concat(", \"parent_enum\": ".to_string(), json_quote(parent_enum.clone())), + _ => "".to_string(), +}), "}".to_string()), + None => "null".to_string(), +}), "}".to_string()), + ExprData::ExprFieldAccess { summary, .. } => { + let field = field_access_field_at(expr_node.clone(), source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprFieldAccess\", \"field\": ".to_string(), json_quote(field)), ", \"summary\": ".to_string()), match summary.clone() { + Some(inner) => serialize_field_summary(&inner), + None => "null".to_string(), +}), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()) +}, + ExprData::ExprCall { call_semantics, descent_evidence: de, .. } => { + let func = expr_call_func_at(expr_node.clone(), source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprCall\", \"func\": ".to_string(), json_quote(func)), ", \"call_semantics\": ".to_string()), serialize_call_semantics(call_semantics.clone())), ", \"descent_evidence\": ".to_string()), serialize_descent_evidence(de.clone())), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()) +}, + ExprData::ExprMethodCall { method_semantics, .. } => { + let method = expr_method_name_at(expr_node.clone(), source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprMethodCall\", \"method\": ".to_string(), json_quote(method)), ", \"method_semantics\": ".to_string()), serialize_method_semantics(method_semantics.clone(), &source_indices)), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()) +}, + ExprData::ExprBinOp { op, algebra_field: af, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprBinOp\", \"op\": ".to_string(), json_quote(bin_op_name(op.clone()))), ", \"algebra_field\": ".to_string()), match af.clone() { + Some(f) => json_quote(algebra_field_kind_name(f.clone())), + None => "null".to_string(), +}), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprUnaryOp { op, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprUnaryOp\", \"op\": ".to_string(), json_quote(unary_op_name(op.clone()))), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprLambda => { + let params = lambda_param_names_at(expr_node.clone(), source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprLambda\", \"params\": ".to_string(), json_list(Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { __result.push(json_quote(p.clone())); } __result }))), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()) +}, + ExprData::ExprLet => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprLet\", \"name\": ".to_string(), json_quote(name)), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprRecordLit { parent_enum, .. } => { + let type_name = record_lit_type_name_at(expr_node.clone(), source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprRecordLit\", \"type_name\": ".to_string(), json_optional_string(type_name)), ", \"parent_enum\": ".to_string()), json_optional_string(parent_enum.clone())), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()) +}, + ExprData::ExprForEach => { + let variable = foreach_variable_at(expr_node.clone(), source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprForEach\", \"variable\": ".to_string(), json_quote(variable)), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()) +}, + ExprData::ExprMatch => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprMatch\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprIf => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprIf\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprListLit => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprListLit\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprStringInterp => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprStringInterp\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprBlock => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprBlock\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprCast => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprCast\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprIndex => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprIndex\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprSlice => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprSlice\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), + ExprData::ExprReturn => v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"ExprReturn\"".to_string(), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for c in ch.iter().cloned() { __result.push(serialize_node(&c, &source_indices)); } __result }))), "}".to_string()), +} +} +} + +pub fn serialize_inferred_node(inferred: Rc, source_indices: Rc>>) -> String { + match (*inferred).clone() { + InferredNode::Resolved { node, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"Resolved\", \"node\": ".to_string(), serialize_node(&node, &source_indices)), "}".to_string()), + InferredNode::CompilerError { message, span, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"kind\": \"CompilerError\", \"message\": ".to_string(), json_quote(message.clone())), ", \"span\": ".to_string()), serialize_span(&span)), "}".to_string()), + InferredNode::TypeVariable { id, .. } => v2_rt::concat(v2_rt::concat("{\"kind\": \"TypeVariable\", \"id\": ".to_string(), json_quote(id.clone())), "}".to_string()), +} } -pub fn serialize_inferred_node( - inferred: Rc, - source_indices: Rc>>, -) -> String { - match (*inferred).clone() { - InferredNode::Resolved { node, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"Resolved\", \"node\": ".to_string(), - serialize_node(&node, &source_indices), - ), - "}".to_string(), - ), - InferredNode::CompilerError { message, span, .. } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"CompilerError\", \"message\": ".to_string(), - json_quote(message.clone()), - ), - ", \"span\": ".to_string(), - ), - serialize_span(&span), - ), - "}".to_string(), - ), - InferredNode::TypeVariable { id, .. } => v2_rt::concat( - v2_rt::concat( - "{\"kind\": \"TypeVariable\", \"id\": ".to_string(), - json_quote(id.clone()), - ), - "}".to_string(), - ), - } +pub fn serialize_resource_use(resource_use: &Rc, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"name\": ".to_string(), json_quote(resource_use_name_at(resource_use.clone(), source_indices.clone()))), ", \"resource\": ".to_string()), serialize_node(&resource_use_resource(&resource_use), &source_indices)), ", \"span\": ".to_string()), serialize_span(&resource_use.span.clone())), "}".to_string()) } -pub fn serialize_resource_use( - resource_use: &Rc, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"name\": ".to_string(), - json_quote(resource_use_name_at( - resource_use.clone(), - source_indices.clone(), - )), - ), - ", \"resource\": ".to_string(), - ), - serialize_node(&resource_use_resource(&resource_use), &source_indices), - ), - ", \"span\": ".to_string(), - ), - serialize_span(&resource_use.span.clone()), - ), - "}".to_string(), - ) -} - -pub fn serialize_field( - field: &Rc, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"name\": ".to_string(), - json_quote(field_node_name_at( - field.clone(), - source_indices.clone(), - )), - ), - ", \"type_expr\": ".to_string(), - ), - serialize_node( - &field_node_type_expr(&field), - &source_indices, - ), - ), - ", \"cardinality\": ".to_string(), - ), - json_quote(cardinality_name(field_node_cardinality( - field.clone(), - ))), - ), - ", \"default_value\": ".to_string(), - ), - json_optional_node( - field_node_default_value(&field), - source_indices.clone(), - ), - ), - ", \"from_key\": ".to_string(), - ), - json_optional_string(field_node_from_key( - field.clone(), - source_indices.clone(), - )), - ), - ", \"span\": ".to_string(), - ), - serialize_span(&field_node_span(field.clone())), - ), - "}".to_string(), - ) -} - -pub fn serialize_param( - param: &Rc, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"name\": ".to_string(), - json_quote(param_node_name_at( - param.clone(), - source_indices.clone(), - )), - ), - ", \"type_expr\": ".to_string(), - ), - serialize_node(¶m_node_type_expr(¶m), &source_indices), - ), - ", \"default_value\": ".to_string(), - ), - json_optional_node(param_node_default_value(¶m), source_indices.clone()), - ), - ", \"span\": ".to_string(), - ), - serialize_span(¶m_node_span(param.clone())), - ), - "}".to_string(), - ) -} - -pub fn serialize_node( - node: &Rc, - source_indices: &Rc>>, -) -> String { +pub fn serialize_field(field: &Rc, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"name\": ".to_string(), json_quote(field_node_name_at(field.clone(), source_indices.clone()))), ", \"type_expr\": ".to_string()), serialize_node(&field_node_type_expr(&field), &source_indices)), ", \"cardinality\": ".to_string()), json_quote(cardinality_name(field_node_cardinality(field.clone())))), ", \"default_value\": ".to_string()), json_optional_node(field_node_default_value(&field), source_indices.clone())), ", \"from_key\": ".to_string()), json_optional_string(field_node_from_key(field.clone(), source_indices.clone()))), ", \"span\": ".to_string()), serialize_span(&field_node_span(field.clone()))), "}".to_string()) +} + +pub fn serialize_param(param: &Rc, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"name\": ".to_string(), json_quote(param_node_name_at(param.clone(), source_indices.clone()))), ", \"type_expr\": ".to_string()), serialize_node(¶m_node_type_expr(¶m), &source_indices)), ", \"default_value\": ".to_string()), json_optional_node(param_node_default_value(¶m), source_indices.clone())), ", \"span\": ".to_string()), serialize_span(¶m_node_span(param.clone()))), "}".to_string()) +} + +pub fn serialize_node(node: &Rc, source_indices: &Rc>>) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"name\": ".to_string(), json_quote(authored_name_at(source_indices.clone(), &node))), ", \"span\": ".to_string()), serialize_span(&node.span.clone())), ", \"ident_span\": ".to_string()), json_optional_span(node.ident_span.clone())), ", \"children\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for child in node.children.clone().iter().cloned() { __result.push(serialize_node(&child, &source_indices)); } __result }))), ", \"connective\": ".to_string()), match node.connective.clone() { Connective::Conj => json_quote(connective_name(Connective::Conj)), @@ -1566,546 +495,234 @@ pub fn serialize_node( }) } -pub fn serialize_module( - module: &Rc, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"name\": ".to_string(), - json_quote(authored_name_at(source_indices.clone(), &module)), - ), - ", \"imports\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for imp in module_imports(module.clone()).iter().cloned() { - __result.push(serialize_import_node(&imp, &source_indices)); - } - __result - })), - ), - ", \"span\": ".to_string(), - ), - serialize_span(&module.span.clone()), - ), - "}".to_string(), - ) +pub fn serialize_module(module: &Rc, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"name\": ".to_string(), json_quote(authored_name_at(source_indices.clone(), &module))), ", \"imports\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for imp in module_imports(module.clone()).iter().cloned() { __result.push(serialize_import_node(&imp, &source_indices)); } __result }))), ", \"span\": ".to_string()), serialize_span(&module.span.clone())), "}".to_string()) } pub fn serialize_typed_module(module: &Rc) -> String { { let si = module.type_env.clone().source_indices.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"module\": ".to_string(), - serialize_module(&module.module.clone(), &si), - ), - ", \"items\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for item in module.items.clone().iter().cloned() { - __result.push(serialize_node(&item, &si)); - } - __result - })), - ), - ", \"item_registry_keys\": ".to_string(), - ), - json_list(Rc::new({ - let mut __result = Vec::new(); - for k in Rc::new(v2_rt::map_keys(&module.item_registry.clone())) - .iter() - .cloned() - { - __result.push(json_quote(k.clone())); - } - __result - })), - ), - "}".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"module\": ".to_string(), serialize_module(&module.module.clone(), &si)), ", \"items\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for item in module.items.clone().iter().cloned() { __result.push(serialize_node(&item, &si)); } __result }))), ", \"item_registry_keys\": ".to_string()), json_list(Rc::new({ let mut __result = Vec::new(); for k in Rc::new(v2_rt::map_keys(&module.item_registry.clone())).iter().cloned() { __result.push(json_quote(k.clone())); } __result }))), "}".to_string()) +} } pub fn serialize_diagnostic(diagnostic: &Rc) -> String { { let severity = "error".to_string(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\"severity\": ".to_string(), - json_quote(severity), - ), - ", \"message\": ".to_string(), - ), - json_quote(diagnostic_to_message( - diagnostic.diagnostic.clone(), - )), - ), - ", \"span\": ".to_string(), - ), - serialize_span(&diagnostic_to_span(diagnostic.diagnostic.clone())), - ), - ", \"module_name\": ".to_string(), - ), - json_optional_string(Some(diagnostic.module_name.clone())), - ), - ", \"category\": ".to_string(), - ), - "null".to_string(), - ), - "}".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\"severity\": ".to_string(), json_quote(severity)), ", \"message\": ".to_string()), json_quote(diagnostic_to_message(diagnostic.diagnostic.clone()))), ", \"span\": ".to_string()), serialize_span(&diagnostic_to_span(diagnostic.diagnostic.clone()))), ", \"module_name\": ".to_string()), json_optional_string(Some(diagnostic.module_name.clone()))), ", \"category\": ".to_string()), "null".to_string()), "}".to_string()) +} } pub fn emit_dag_artifact(typed: &Rc) -> Rc { { - let modules_json = Rc::new({ - let mut __result = Vec::new(); - for m in typed.modules.clone().iter().cloned() { - __result.push(serialize_typed_module(&m)); - } - __result - }) - .join(&", ".to_string()); - let diagnostics_json = Rc::new({ - let mut __result = Vec::new(); - for d in typed.diagnostics.clone().iter().cloned() { - __result.push(serialize_diagnostic(&d)); - } - __result - }) - .join(&", ".to_string()); - let item_registry_json = Rc::new({ - let mut __result = Vec::new(); - for k in Rc::new(v2_rt::map_keys(&typed.item_registry.clone())) - .iter() - .cloned() - { - __result.push(json_quote(k.clone())); - } - __result - }) - .join(&", ".to_string()); - let json = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "{\n \"version\": \"0.1.0\",\n \"modules\": [".to_string(), - modules_json, - ), - "],\n \"item_registry_keys\": [".to_string(), - ), - item_registry_json, - ), - "],\n \"diagnostics\": [".to_string(), - ), - diagnostics_json, - ), - "],\n \"files\": []\n}".to_string(), - ); - Rc::new(EmitResult { - files: Rc::new(vec![Rc::new(TextFile { - path: "dag-artifact.json".to_string(), - content: json, - })]), - diagnostics: Rc::new(vec![]), - }) - } + let modules_json = Rc::new({ let mut __result = Vec::new(); for m in typed.modules.clone().iter().cloned() { __result.push(serialize_typed_module(&m)); } __result }).join(&", ".to_string()); +let diagnostics_json = Rc::new({ let mut __result = Vec::new(); for d in typed.diagnostics.clone().iter().cloned() { __result.push(serialize_diagnostic(&d)); } __result }).join(&", ".to_string()); +let item_registry_json = Rc::new({ let mut __result = Vec::new(); for k in Rc::new(v2_rt::map_keys(&typed.item_registry.clone())).iter().cloned() { __result.push(json_quote(k.clone())); } __result }).join(&", ".to_string()); +let json = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\n \"version\": \"0.1.0\",\n \"modules\": [".to_string(), modules_json), "],\n \"item_registry_keys\": [".to_string()), item_registry_json), "],\n \"diagnostics\": [".to_string()), diagnostics_json), "],\n \"files\": []\n}".to_string()); +Rc::new(EmitResult { + files: Rc::new(vec![Rc::new(TextFile { + path: "dag-artifact.json".to_string(), + content: json, +})]), + diagnostics: Rc::new(vec![]), +}) +} } pub fn boundary_ref_error(names: Rc>, ref_name: &String) -> Rc>> { - if { - let mut __found = false; - for n in names.iter().cloned() { - if (n.clone().as_str() == ref_name.clone().as_str()) { - __found = true; - break; - } - } - __found - } { + if { let mut __found = false; for n in names.iter().cloned() { if (n.clone().as_str() == ref_name.clone().as_str()) { __found = true; break; } } __found } { Rc::new(vec![]) } else { - Rc::new(vec![compile_bundle_error(v2_rt::concat( - v2_rt::concat( - "boundary references unknown artifact '".to_string(), - ref_name.clone(), - ), - "'".to_string(), - ))]) + Rc::new(vec![compile_bundle_error(v2_rt::concat(v2_rt::concat("boundary references unknown artifact '".to_string(), ref_name.clone()), "'".to_string()))]) } } pub fn validate_boundaries(plan: &Rc) -> Rc>> { { - let names = Rc::new({ - let mut __result = Vec::new(); - for a in plan.artifacts.clone().iter().cloned() { - __result.push(a.name.clone()); - } - __result - }); - Rc::new({ - let mut __result = Vec::new(); - for b in plan.boundaries.clone().iter().cloned() { - __result.extend( - (*v2_rt::concat( - boundary_ref_error(names.clone(), &b.from_artifact.clone()), - boundary_ref_error(names.clone(), &b.to_artifact.clone()), - )) - .iter() - .cloned(), - ); - } - __result - }) - } + let names = Rc::new({ let mut __result = Vec::new(); for a in plan.artifacts.clone().iter().cloned() { __result.push(a.name.clone()); } __result }); +Rc::new({ let mut __result = Vec::new(); for b in plan.boundaries.clone().iter().cloned() { __result.extend((*v2_rt::concat(boundary_ref_error(names.clone(), &b.from_artifact.clone()), boundary_ref_error(names.clone(), &b.to_artifact.clone()))).iter().cloned()); } __result }) +} } -pub fn emit_from_artifact_plan( - typed: Rc, - artifact_plan: &Rc, -) -> Rc { +pub fn emit_from_artifact_plan(typed: Rc, artifact_plan: &Rc) -> Rc { { if ((artifact_plan.artifacts.clone().len() as i64) == 0) { return Rc::new(EmitResult { - files: Rc::new(vec![]), - diagnostics: Rc::new(vec![compile_bundle_error( - "compile_sources planned no artifacts".to_string(), - )]), - }); + files: Rc::new(vec![]), + diagnostics: Rc::new(vec![compile_bundle_error("compile_sources planned no artifacts".to_string())]), +}) } - let boundary_diags = validate_boundaries(&artifact_plan); - if ((boundary_diags.clone().len() as i64) > 0) { +let boundary_diags = validate_boundaries(&artifact_plan); +if ((boundary_diags.clone().len() as i64) > 0) { return Rc::new(EmitResult { - files: Rc::new(vec![]), - diagnostics: boundary_diags.clone(), - }); + files: Rc::new(vec![]), + diagnostics: boundary_diags.clone(), +}) } - let results = Rc::new({ - let mut __result = Vec::new(); - for artifact in artifact_plan.artifacts.clone().iter().cloned() { - __result.push(emit_artifact(typed.clone(), artifact.clone())); - } - __result - }); - let all_files = Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - __result.extend((*r.files.clone()).iter().cloned()); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - __result.extend((*r.diagnostics.clone()).iter().cloned()); - } - __result - }); - Rc::new(EmitResult { - files: all_files, - diagnostics: all_diags, - }) - } +let results = Rc::new({ let mut __result = Vec::new(); for artifact in artifact_plan.artifacts.clone().iter().cloned() { __result.push(emit_artifact(typed.clone(), artifact.clone())); } __result }); +let all_files = Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { __result.extend((*r.files.clone()).iter().cloned()); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { __result.extend((*r.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(EmitResult { + files: all_files, + diagnostics: all_diags, +}) +} } pub fn collect_diagnostics(parse_results: Rc>>) -> Rc>> { - parse_results.iter().cloned().fold( - Rc::new(vec![]), - |acc: Rc>>, pr: Rc| match pr.error.clone() { - Some(diag) => v2_rt::rc_list_push(acc.clone(), diag.clone()), - None => acc.clone(), - }, - ) + parse_results.iter().cloned().fold(Rc::new(vec![]), |acc: Rc>>, pr: Rc| match pr.error.clone() { + Some(diag) => v2_rt::rc_list_push(acc.clone(), diag.clone()), + None => acc.clone(), +}) } pub fn front_end_sources(sources: Rc>>) -> Rc { { - let acc = sources.iter().cloned().fold( - Rc::new(FrontendAccum { - parse_results: Rc::new(vec![]), - newline_indices: Rc::new(vec![]), - intern_table: empty_intern_table(), - }), - |acc: Rc, s: Rc| { - let acc = Rc::try_unwrap(acc).unwrap_or_else(|rc| (*rc).clone()); - { - let tokens = tokenize(&s.content.clone(), s.path.clone()); - let si = build_newline_index(s.path.clone(), &s.content.clone()); - let parsed = parse_with_table( - &tokens, - v2_rt::rc_map_insert( - v2_rt::rc_empty_map::>(), - si.file.clone(), - si.clone(), - ), - acc.intern_table, - ); - let pr = parsed.result.clone(); - Rc::new(FrontendAccum { - parse_results: v2_rt::rc_list_push(acc.parse_results, pr.clone()), - newline_indices: v2_rt::rc_list_push(acc.newline_indices, si.clone()), - intern_table: parsed.intern_table.clone(), - }) - } - }, - ); - let parse_results = acc.parse_results.clone(); - let newline_indices = acc.newline_indices.clone(); - let intern_table = acc.intern_table.clone(); - let parse_diagnostics = collect_diagnostics(parse_results.clone()); - let has_parse_errors = { - let mut __found = false; - for p in parse_results.clone().iter().cloned() { - if (p.error.clone() != None) { - __found = true; - break; - } - } - __found - }; - if has_parse_errors { + let acc = sources.iter().cloned().fold(Rc::new(FrontendAccum { + parse_results: Rc::new(vec![]), + newline_indices: Rc::new(vec![]), + intern_table: empty_intern_table(), +}), |acc: Rc, s: Rc| { let acc = Rc::try_unwrap(acc).unwrap_or_else(|rc| (*rc).clone()); { + let tokens = tokenize(&s.content.clone(), s.path.clone()); +let si = build_newline_index(s.path.clone(), &s.content.clone()); +let parsed = parse_with_table(&tokens, v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), si.file.clone(), si.clone()), acc.intern_table); +let pr = parsed.result.clone(); +Rc::new(FrontendAccum { + parse_results: v2_rt::rc_list_push(acc.parse_results, pr.clone()), + newline_indices: v2_rt::rc_list_push(acc.newline_indices, si.clone()), + intern_table: parsed.intern_table.clone(), +}) +} }); +let parse_results = acc.parse_results.clone(); +let newline_indices = acc.newline_indices.clone(); +let intern_table = acc.intern_table.clone(); +let parse_diagnostics = collect_diagnostics(parse_results.clone()); +let has_parse_errors = { let mut __found = false; for p in parse_results.clone().iter().cloned() { if (p.error.clone() != None) { __found = true; break; } } __found }; +if has_parse_errors { Rc::new(FrontendResult { - graph: None, - diagnostics: parse_diagnostics, - newline_indices: newline_indices.clone(), - intern_table: intern_table, - }) + graph: None, + diagnostics: parse_diagnostics, + newline_indices: newline_indices.clone(), + intern_table: intern_table, +}) } else { { - let modules = Rc::new({ - let mut __result = Vec::new(); - for p in parse_results.clone().iter().cloned() { - __result.push(p.module.clone().clone().unwrap()); - } - __result - }); - let source_indices = newline_indices.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, si: Rc| { - v2_rt::rc_map_insert(acc, si.file.clone(), si.clone()) - }, - ); - let graph = resolve_modules(&modules, &source_indices); - Rc::new(FrontendResult { - graph: Some(graph.clone()), - diagnostics: v2_rt::concat(parse_diagnostics, graph.diagnostics.clone()), - newline_indices: newline_indices.clone(), - intern_table: intern_table, - }) - } + let modules = Rc::new({ let mut __result = Vec::new(); for p in parse_results.clone().iter().cloned() { __result.push(p.module.clone().clone().unwrap()); } __result }); +let source_indices = newline_indices.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, si: Rc| v2_rt::rc_map_insert(acc, si.file.clone(), si.clone())); +let graph = resolve_modules(&modules, &source_indices); +Rc::new(FrontendResult { + graph: Some(graph.clone()), + diagnostics: v2_rt::concat(parse_diagnostics, graph.diagnostics.clone()), + newline_indices: newline_indices.clone(), + intern_table: intern_table, +}) +} } - } +} } pub fn resolve_sources(sources: Rc>>) -> Rc { { let frontend = front_end_sources(sources); - Rc::new(CompileResult { - files: Rc::new(vec![]), - diagnostics: frontend.diagnostics.clone(), - }) - } +Rc::new(CompileResult { + files: Rc::new(vec![]), + diagnostics: frontend.diagnostics.clone(), +}) +} } -pub fn compile_sources( - sources: Rc>>, - target: RenderTarget, -) -> Rc { +pub fn compile_sources(sources: Rc>>, target: RenderTarget) -> Rc { { let frontend = front_end_sources(sources); - let newline_indices = frontend.newline_indices.clone(); - match frontend.graph.clone() { - None => Rc::new(PipelineResult { - files: Rc::new(vec![]), - diagnostics: frontend.diagnostics.clone(), - complexity: empty_complexity_report(), - ownership: Rc::new(vec![]), - artifact_plan: empty_artifact_plan(), - newline_indices: newline_indices.clone(), - }), - Some(graph) => { - let graph_diags = graph.diagnostics.clone(); - let resolve_errors = Rc::new({ - let mut __result = Vec::new(); - for d in graph_diags.iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - if ((resolve_errors.len() as i64) > 0) { - return Rc::new(PipelineResult { - files: Rc::new(vec![]), - diagnostics: frontend.diagnostics.clone(), - complexity: empty_complexity_report(), - ownership: Rc::new(vec![]), - artifact_plan: empty_artifact_plan(), - newline_indices: newline_indices.clone(), - }); - } - let source_indices = newline_indices.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, index: Rc| { - v2_rt::rc_map_insert(acc, index.file.clone(), index.clone()) - }, - ); - let norm = normalize_graph(&graph, source_indices.clone()); - let norm_diags = norm.diagnostics.clone(); - let norm_errors = Rc::new({ - let mut __result = Vec::new(); - for d in norm_diags.clone().iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - if ((norm_errors.len() as i64) > 0) { - return Rc::new(PipelineResult { - files: Rc::new(vec![]), - diagnostics: v2_rt::concat( - frontend.diagnostics.clone(), - norm_diags.clone(), - ), - complexity: empty_complexity_report(), - ownership: Rc::new(vec![]), - artifact_plan: empty_artifact_plan(), - newline_indices: newline_indices.clone(), - }); - } - let typed = reconcile( - norm.graph.clone(), - source_indices.clone(), - frontend.intern_table.clone(), - ); - let typed_diags = typed.diagnostics.clone(); - let func_entries = extract_func_entries(typed.clone()); - let recursion_ctx = build_recursion_context(typed.clone()); - let complexity = - build_complexity_report(&func_entries, recursion_ctx, source_indices.clone()); - let complexity_diags = complexity_diagnostics(complexity.clone()); - let all_diags = v2_rt::concat(typed_diags.clone(), complexity_diags); - let type_errors = Rc::new({ - let mut __result = Vec::new(); - for d in typed_diags.clone().iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - if ((type_errors.len() as i64) > 0) { - return Rc::new(PipelineResult { - files: Rc::new(vec![]), - diagnostics: v2_rt::concat( - v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), - all_diags.clone(), - ), - complexity: complexity.clone(), - ownership: Rc::new(vec![]), - artifact_plan: empty_artifact_plan(), - newline_indices: newline_indices.clone(), - }); - } - let ownership = extract_ownership_proofs(typed.clone()); - let ownership_diags = ownership_diagnostics(ownership.clone()); - let ownership_errors = Rc::new({ - let mut __result = Vec::new(); - for d in ownership_diags.clone().iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - if ((ownership_errors.len() as i64) > 0) { - return Rc::new(PipelineResult { - files: Rc::new(vec![]), - diagnostics: v2_rt::concat( - v2_rt::concat( - v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), - all_diags.clone(), - ), - ownership_diags.clone(), - ), - complexity: complexity.clone(), - ownership: ownership.clone(), - artifact_plan: empty_artifact_plan(), - newline_indices: newline_indices.clone(), - }); - } - let artifact_plan = default_artifact_plan( - Rc::new({ - let mut __result = Vec::new(); - for m in typed.modules.clone().iter().cloned() { - __result - .push(authored_name_at(source_indices.clone(), &m.module.clone())); - } - __result - }), - target, - ); - let emit_result = emit_from_artifact_plan(typed.clone(), &artifact_plan); - let emit_files = emit_result.files.clone(); - let emit_diags = emit_result.diagnostics.clone(); - let emit_errors = Rc::new({ - let mut __result = Vec::new(); - for d in emit_diags.clone().iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - let final_files = if ((emit_errors.len() as i64) > 0) { - Rc::new(vec![]) - } else { - emit_files - }; - Rc::new(PipelineResult { - files: final_files, - diagnostics: v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), - all_diags.clone(), - ), - ownership_diags.clone(), - ), - emit_diags.clone(), - ), - complexity: complexity.clone(), - ownership: ownership.clone(), - artifact_plan: artifact_plan.clone(), - newline_indices: newline_indices.clone(), - }) +let newline_indices = frontend.newline_indices.clone(); +match frontend.graph.clone() { + None => Rc::new(PipelineResult { + files: Rc::new(vec![]), + diagnostics: frontend.diagnostics.clone(), + complexity: empty_complexity_report(), + ownership: Rc::new(vec![]), + artifact_plan: empty_artifact_plan(), + newline_indices: newline_indices.clone(), +}), + Some(graph) => { + let graph_diags = graph.diagnostics.clone(); +let resolve_errors = Rc::new({ let mut __result = Vec::new(); for d in graph_diags.iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +if ((resolve_errors.len() as i64) > 0) { + return Rc::new(PipelineResult { + files: Rc::new(vec![]), + diagnostics: frontend.diagnostics.clone(), + complexity: empty_complexity_report(), + ownership: Rc::new(vec![]), + artifact_plan: empty_artifact_plan(), + newline_indices: newline_indices.clone(), +}) } - } - } +let source_indices = newline_indices.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, index: Rc| v2_rt::rc_map_insert(acc, index.file.clone(), index.clone())); +let norm = normalize_graph(&graph, source_indices.clone()); +let norm_diags = norm.diagnostics.clone(); +let norm_errors = Rc::new({ let mut __result = Vec::new(); for d in norm_diags.clone().iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +if ((norm_errors.len() as i64) > 0) { + return Rc::new(PipelineResult { + files: Rc::new(vec![]), + diagnostics: v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), + complexity: empty_complexity_report(), + ownership: Rc::new(vec![]), + artifact_plan: empty_artifact_plan(), + newline_indices: newline_indices.clone(), +}) + } +let typed = reconcile(norm.graph.clone(), source_indices.clone(), frontend.intern_table.clone()); +let typed_diags = typed.diagnostics.clone(); +let func_entries = extract_func_entries(typed.clone()); +let recursion_ctx = build_recursion_context(typed.clone()); +let complexity = build_complexity_report(&func_entries, recursion_ctx, source_indices.clone()); +let complexity_diags = complexity_diagnostics(complexity.clone()); +let all_diags = v2_rt::concat(typed_diags.clone(), complexity_diags); +let type_errors = Rc::new({ let mut __result = Vec::new(); for d in typed_diags.clone().iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +if ((type_errors.len() as i64) > 0) { + return Rc::new(PipelineResult { + files: Rc::new(vec![]), + diagnostics: v2_rt::concat(v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), all_diags.clone()), + complexity: complexity.clone(), + ownership: Rc::new(vec![]), + artifact_plan: empty_artifact_plan(), + newline_indices: newline_indices.clone(), +}) + } +let ownership = extract_ownership_proofs(typed.clone()); +let ownership_diags = ownership_diagnostics(ownership.clone()); +let ownership_errors = Rc::new({ let mut __result = Vec::new(); for d in ownership_diags.clone().iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +if ((ownership_errors.len() as i64) > 0) { + return Rc::new(PipelineResult { + files: Rc::new(vec![]), + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), all_diags.clone()), ownership_diags.clone()), + complexity: complexity.clone(), + ownership: ownership.clone(), + artifact_plan: empty_artifact_plan(), + newline_indices: newline_indices.clone(), +}) + } +let artifact_plan = default_artifact_plan(Rc::new({ let mut __result = Vec::new(); for m in typed.modules.clone().iter().cloned() { __result.push(authored_name_at(source_indices.clone(), &m.module.clone())); } __result }), target); +let emit_result = emit_from_artifact_plan(typed.clone(), &artifact_plan); +let emit_files = emit_result.files.clone(); +let emit_diags = emit_result.diagnostics.clone(); +let emit_errors = Rc::new({ let mut __result = Vec::new(); for d in emit_diags.clone().iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +let final_files = if ((emit_errors.len() as i64) > 0) { + Rc::new(vec![]) + } else { + emit_files + }; +Rc::new(PipelineResult { + files: final_files, + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), all_diags.clone()), ownership_diags.clone()), emit_diags.clone()), + complexity: complexity.clone(), + ownership: ownership.clone(), + artifact_plan: artifact_plan.clone(), + newline_indices: newline_indices.clone(), +}) +}, +} +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -2121,143 +738,83 @@ pub struct ResolvedPipelineResult { pub fn compile_to_resolved(sources: Rc>>) -> Rc { { let frontend = front_end_sources(sources); - let newline_indices = frontend.newline_indices.clone(); - match frontend.graph.clone() { - None => Rc::new(ResolvedPipelineResult { - graph: None, - diagnostics: frontend.diagnostics.clone(), - source_indices: v2_rt::rc_empty_map::>(), - complexity: empty_complexity_report(), - ownership: Rc::new(vec![]), - newline_indices: newline_indices.clone(), - }), - Some(graph) => { - let graph_diags = graph.diagnostics.clone(); - let resolve_errors = Rc::new({ - let mut __result = Vec::new(); - for d in graph_diags.iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - if ((resolve_errors.len() as i64) > 0) { - return Rc::new(ResolvedPipelineResult { - graph: None, - diagnostics: frontend.diagnostics.clone(), - source_indices: v2_rt::rc_empty_map::>(), - complexity: empty_complexity_report(), - ownership: Rc::new(vec![]), - newline_indices: newline_indices.clone(), - }); - } - let source_indices = newline_indices.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, index: Rc| { - v2_rt::rc_map_insert(acc, index.file.clone(), index.clone()) - }, - ); - let norm = normalize_graph(&graph, source_indices.clone()); - let norm_diags = norm.diagnostics.clone(); - let norm_errors = Rc::new({ - let mut __result = Vec::new(); - for d in norm_diags.clone().iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - if ((norm_errors.len() as i64) > 0) { - return Rc::new(ResolvedPipelineResult { - graph: None, - diagnostics: v2_rt::concat( - frontend.diagnostics.clone(), - norm_diags.clone(), - ), - source_indices: source_indices.clone(), - complexity: empty_complexity_report(), - ownership: Rc::new(vec![]), - newline_indices: newline_indices.clone(), - }); - } - let typed = reconcile( - norm.graph.clone(), - source_indices.clone(), - frontend.intern_table.clone(), - ); - let typed_diags = typed.diagnostics.clone(); - let func_entries = extract_func_entries(typed.clone()); - let recursion_ctx = build_recursion_context(typed.clone()); - let complexity = - build_complexity_report(&func_entries, recursion_ctx, source_indices.clone()); - let complexity_diags = complexity_diagnostics(complexity.clone()); - let all_diags = v2_rt::concat(typed_diags.clone(), complexity_diags); - let type_errors = Rc::new({ - let mut __result = Vec::new(); - for d in typed_diags.clone().iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - if ((type_errors.len() as i64) > 0) { - return Rc::new(ResolvedPipelineResult { - graph: None, - diagnostics: v2_rt::concat( - v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), - all_diags.clone(), - ), - source_indices: source_indices.clone(), - complexity: complexity.clone(), - ownership: Rc::new(vec![]), - newline_indices: newline_indices.clone(), - }); - } - let ownership = extract_ownership_proofs(typed.clone()); - let ownership_diags = ownership_diagnostics(ownership.clone()); - let ownership_errors = Rc::new({ - let mut __result = Vec::new(); - for d in ownership_diags.clone().iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - if ((ownership_errors.len() as i64) > 0) { - return Rc::new(ResolvedPipelineResult { - graph: None, - diagnostics: v2_rt::concat( - v2_rt::concat( - v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), - all_diags.clone(), - ), - ownership_diags.clone(), - ), - source_indices: source_indices.clone(), - complexity: complexity.clone(), - ownership: ownership.clone(), - newline_indices: newline_indices.clone(), - }); - } - Rc::new(ResolvedPipelineResult { - graph: Some(typed.clone()), - diagnostics: v2_rt::concat( - v2_rt::concat( - v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), - all_diags.clone(), - ), - ownership_diags.clone(), - ), - source_indices: source_indices.clone(), - complexity: complexity.clone(), - ownership: ownership.clone(), - newline_indices: newline_indices.clone(), - }) +let newline_indices = frontend.newline_indices.clone(); +match frontend.graph.clone() { + None => Rc::new(ResolvedPipelineResult { + graph: None, + diagnostics: frontend.diagnostics.clone(), + source_indices: v2_rt::rc_empty_map::>(), + complexity: empty_complexity_report(), + ownership: Rc::new(vec![]), + newline_indices: newline_indices.clone(), +}), + Some(graph) => { + let graph_diags = graph.diagnostics.clone(); +let resolve_errors = Rc::new({ let mut __result = Vec::new(); for d in graph_diags.iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +if ((resolve_errors.len() as i64) > 0) { + return Rc::new(ResolvedPipelineResult { + graph: None, + diagnostics: frontend.diagnostics.clone(), + source_indices: v2_rt::rc_empty_map::>(), + complexity: empty_complexity_report(), + ownership: Rc::new(vec![]), + newline_indices: newline_indices.clone(), +}) } - } - } +let source_indices = newline_indices.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, index: Rc| v2_rt::rc_map_insert(acc, index.file.clone(), index.clone())); +let norm = normalize_graph(&graph, source_indices.clone()); +let norm_diags = norm.diagnostics.clone(); +let norm_errors = Rc::new({ let mut __result = Vec::new(); for d in norm_diags.clone().iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +if ((norm_errors.len() as i64) > 0) { + return Rc::new(ResolvedPipelineResult { + graph: None, + diagnostics: v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), + source_indices: source_indices.clone(), + complexity: empty_complexity_report(), + ownership: Rc::new(vec![]), + newline_indices: newline_indices.clone(), +}) + } +let typed = reconcile(norm.graph.clone(), source_indices.clone(), frontend.intern_table.clone()); +let typed_diags = typed.diagnostics.clone(); +let func_entries = extract_func_entries(typed.clone()); +let recursion_ctx = build_recursion_context(typed.clone()); +let complexity = build_complexity_report(&func_entries, recursion_ctx, source_indices.clone()); +let complexity_diags = complexity_diagnostics(complexity.clone()); +let all_diags = v2_rt::concat(typed_diags.clone(), complexity_diags); +let type_errors = Rc::new({ let mut __result = Vec::new(); for d in typed_diags.clone().iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +if ((type_errors.len() as i64) > 0) { + return Rc::new(ResolvedPipelineResult { + graph: None, + diagnostics: v2_rt::concat(v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), all_diags.clone()), + source_indices: source_indices.clone(), + complexity: complexity.clone(), + ownership: Rc::new(vec![]), + newline_indices: newline_indices.clone(), +}) + } +let ownership = extract_ownership_proofs(typed.clone()); +let ownership_diags = ownership_diagnostics(ownership.clone()); +let ownership_errors = Rc::new({ let mut __result = Vec::new(); for d in ownership_diags.clone().iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +if ((ownership_errors.len() as i64) > 0) { + return Rc::new(ResolvedPipelineResult { + graph: None, + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), all_diags.clone()), ownership_diags.clone()), + source_indices: source_indices.clone(), + complexity: complexity.clone(), + ownership: ownership.clone(), + newline_indices: newline_indices.clone(), +}) + } +Rc::new(ResolvedPipelineResult { + graph: Some(typed.clone()), + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(frontend.diagnostics.clone(), norm_diags.clone()), all_diags.clone()), ownership_diags.clone()), + source_indices: source_indices.clone(), + complexity: complexity.clone(), + ownership: ownership.clone(), + newline_indices: newline_indices.clone(), +}) +}, +} +} } diff --git a/src/v2/stage0/src/v2_compiler_compiler_tests_rust.rs b/src/v2/stage0/src/v2_compiler_compiler_tests_rust.rs index 1f2d41a19e1..664d4b467fa 100644 --- a/src/v2/stage0/src/v2_compiler_compiler_tests_rust.rs +++ b/src/v2/stage0/src/v2_compiler_compiler_tests_rust.rs @@ -1,31 +1,18 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.compiler_tests_rust -pub use crate::v2_compiler_artifact::RenderTarget; -use crate::v2_compiler_artifact::RenderTarget::{Go, Python, Rust}; -use crate::v2_compiler_coercion::CoercionAssertion::{ - CheckpointAssertion, ContainerAssertion, CopyAssertion, TemplateAssertion, -}; -pub use crate::v2_compiler_coercion::{ - extract_coercion_tests, CoercionAssertion, CoercionTestEntry, -}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_compiler_artifact::{RenderTarget}; +use crate::v2_compiler_artifact::RenderTarget::{Rust, Python, Go}; +pub use crate::v2_compiler_coercion::{extract_coercion_tests, CoercionTestEntry, CoercionAssertion}; +use crate::v2_compiler_coercion::CoercionAssertion::{CheckpointAssertion, ContainerAssertion, CopyAssertion, TemplateAssertion}; pub fn ct_module_header() -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "#[cfg(test)]\n".to_string(), - "mod compiler_tests {\n".to_string(), - ), - " use std::collections::HashMap;\n".to_string(), - ), - " use crate::v2_compiler_tokenize::tokenize;\n\n".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat("#[cfg(test)]\n".to_string(), "mod compiler_tests {\n".to_string()), " use std::collections::HashMap;\n".to_string()), " use crate::v2_compiler_tokenize::tokenize;\n\n".to_string()) } pub fn ct_workspace_helpers() -> String { @@ -87,189 +74,67 @@ pub fn ct_type_size_test() -> String { pub fn ct_coercion_tests() -> String { { let entries = extract_coercion_tests(); - let test_fns = Rc::new({ - let mut __result = Vec::new(); - for e in entries.iter().cloned() { - __result.push(render_coercion_test_rust(&e)); - } - __result - }); - v2_rt::concat(v2_rt::concat(v2_rt::concat(" // =========================================================================\n".to_string(), " // Coercion registry tests (auto-generated from data declarations)\n".to_string()), " // =========================================================================\n\n".to_string()), test_fns.join(&"\n".to_string())) - } +let test_fns = Rc::new({ let mut __result = Vec::new(); for e in entries.iter().cloned() { __result.push(render_coercion_test_rust(&e)); } __result }); +v2_rt::concat(v2_rt::concat(v2_rt::concat(" // =========================================================================\n".to_string(), " // Coercion registry tests (auto-generated from data declarations)\n".to_string()), " // =========================================================================\n\n".to_string()), test_fns.join(&"\n".to_string())) +} } pub fn render_target_rust_enum(target: RenderTarget) -> String { match target { - RenderTarget::Rust => "RenderTarget::Rust".to_string(), - RenderTarget::Python => "RenderTarget::Python".to_string(), - RenderTarget::Go => "RenderTarget::Go".to_string(), - RenderTarget::Dag => "RenderTarget::Dag".to_string(), - } + RenderTarget::Rust => "RenderTarget::Rust".to_string(), + RenderTarget::Python => "RenderTarget::Python".to_string(), + RenderTarget::Go => "RenderTarget::Go".to_string(), + RenderTarget::Dag => "RenderTarget::Dag".to_string(), +} } pub fn render_coercion_test_rust(entry: &Rc) -> String { { - let assertions = Rc::new({ - let mut __result = Vec::new(); - for a in entry.assertions.clone().iter().cloned() { - __result.push(render_coercion_assertion_rust(a.clone())); - } - __result - }); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" #[test]\n".to_string(), " fn ".to_string()), - entry.test_name.clone(), - ), - "() {\n".to_string(), - ), - " use crate::v2_compiler_coercion::*;\n".to_string(), - ), - assertions.join(&"".to_string()), - ), - " }\n\n".to_string(), - ) - } + let assertions = Rc::new({ let mut __result = Vec::new(); for a in entry.assertions.clone().iter().cloned() { __result.push(render_coercion_assertion_rust(a.clone())); } __result }); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" #[test]\n".to_string(), " fn ".to_string()), entry.test_name.clone()), "() {\n".to_string()), " use crate::v2_compiler_coercion::*;\n".to_string()), assertions.join(&"".to_string())), " }\n\n".to_string()) +} } pub fn first_or_empty(items: Rc>) -> String { match items.first().cloned() { - Some(v) => v.clone(), - None => "".to_string(), - } + Some(v) => v.clone(), + None => "".to_string(), +} } pub fn second_or_empty(items: Rc>) -> String { match items.get(1 as usize).cloned() { - Some(v) => v.clone(), - None => "".to_string(), - } + Some(v) => v.clone(), + None => "".to_string(), +} } pub fn render_coercion_assertion_rust(a: Rc) -> String { match (*a).clone() { - CoercionAssertion::CheckpointAssertion { - target: t, - dag_name: name, - expected_type: expected, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " assert_eq!(coerce_primitive_type(".to_string(), - render_target_rust_enum(t.clone()), - ), - ", \"".to_string(), - ), - name.clone(), - ), - "\".into()), \"".to_string(), - ), - expected.clone(), - ), - "\");\n".to_string(), - ), - CoercionAssertion::ContainerAssertion { - target: t, - container_name: name, - expected_template: expected, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " assert_eq!(coerce_container_template(".to_string(), - render_target_rust_enum(t.clone()), - ), - ", \"".to_string(), - ), - name.clone(), - ), - "\".into()), Some(\"".to_string(), - ), - expected.clone(), - ), - "\".to_string()));\n".to_string(), - ), - CoercionAssertion::CopyAssertion { - target: t, - dag_name: name, - expected_copy: expected, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " assert_eq!(is_copy(".to_string(), - render_target_rust_enum(t.clone()), - ), - ", \"".to_string(), - ), - name.clone(), - ), - "\".into()), Some(".to_string(), - ), - if expected.clone() { - "true".to_string() - } else { - "false".to_string() - }, - ), - "));\n".to_string(), - ), - CoercionAssertion::TemplateAssertion { - template: tmpl, - args: arg_list, - expected, - .. - } => { - if ((arg_list.clone().len() as i64) == 1) { - { - let arg0 = first_or_empty(arg_list.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " assert_eq!(apply_inhabitant_template1(\"" - .to_string(), - tmpl.clone(), - ), - "\".into(), \"".to_string(), - ), - arg0, - ), - "\".into()), \"".to_string(), - ), - expected.clone(), - ), - "\");\n".to_string(), - ) - } - } else { - if ((arg_list.clone().len() as i64) == 2) { - { - let arg0 = first_or_empty(arg_list.clone()); - let arg1 = second_or_empty(arg_list.clone()); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" assert_eq!(apply_inhabitant_template2(\"".to_string(), tmpl.clone()), "\".into(), \"".to_string()), arg0), "\".into(), \"".to_string()), arg1), "\".into()), \"".to_string()), expected.clone()), "\");\n".to_string()) - } - } else { - "".to_string() - } - } + CoercionAssertion::CheckpointAssertion { target: t, dag_name: name, expected_type: expected, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" assert_eq!(coerce_primitive_type(".to_string(), render_target_rust_enum(t.clone())), ", \"".to_string()), name.clone()), "\".into()), \"".to_string()), expected.clone()), "\");\n".to_string()), + CoercionAssertion::ContainerAssertion { target: t, container_name: name, expected_template: expected, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" assert_eq!(coerce_container_template(".to_string(), render_target_rust_enum(t.clone())), ", \"".to_string()), name.clone()), "\".into()), Some(\"".to_string()), expected.clone()), "\".to_string()));\n".to_string()), + CoercionAssertion::CopyAssertion { target: t, dag_name: name, expected_copy: expected, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" assert_eq!(is_copy(".to_string(), render_target_rust_enum(t.clone())), ", \"".to_string()), name.clone()), "\".into()), Some(".to_string()), if expected.clone() { + "true".to_string() + } else { + "false".to_string() + }), "));\n".to_string()), + CoercionAssertion::TemplateAssertion { template: tmpl, args: arg_list, expected, .. } => if ((arg_list.clone().len() as i64) == 1) { + { + let arg0 = first_or_empty(arg_list.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" assert_eq!(apply_inhabitant_template1(\"".to_string(), tmpl.clone()), "\".into(), \"".to_string()), arg0), "\".into()), \"".to_string()), expected.clone()), "\");\n".to_string()) +} + } else { + if ((arg_list.clone().len() as i64) == 2) { + { + let arg0 = first_or_empty(arg_list.clone()); +let arg1 = second_or_empty(arg_list.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" assert_eq!(apply_inhabitant_template2(\"".to_string(), tmpl.clone()), "\".into(), \"".to_string()), arg0), "\".into(), \"".to_string()), arg1), "\".into()), \"".to_string()), expected.clone()), "\");\n".to_string()) +} + } else { + "".to_string() } - } + }, +} } pub fn ct_profile_helpers() -> String { diff --git a/src/v2/stage0/src/v2_compiler_complexity.rs b/src/v2/stage0/src/v2_compiler_complexity.rs index c1e41046c5d..725f0c52d46 100644 --- a/src/v2/stage0/src/v2_compiler_complexity.rs +++ b/src/v2/stage0/src/v2_compiler_complexity.rs @@ -1,93 +1,45 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.complexity -use self::Certainty::*; -use self::CostExpr::*; -use self::ParserResultSource::*; -use self::SizeExpr::*; -use crate::std_algebra::CollectionSizeEffect::{IdentityEffect, ProjectionEffect, ShrinkEffect}; -use crate::std_algebra::CostShape::{ - ShapeConstant, ShapeIterateBody, ShapeLinearScan, ShapeSortBody, -}; -pub use crate::std_algebra::{CollectionSizeEffect, CostShape}; -use crate::std_computation::CallPattern::{ - ArithmeticSubtractCall, ChildAccessorCall, CollectionShrinkCall, FoldBodyCall, - ParserAdvanceCall, SameArgumentCall, WorklistDrainCall, -}; -use crate::std_computation::IterationDimension::{ArithmeticRepeat, CollectionFold, TreeDescent}; -pub use crate::std_computation::{ - lower_call_pattern, size_bound_param, type_iteration_dimension, CallPattern, - IterationDimension, LoweringTarget, -}; -pub use crate::std_graph::{ - build_call_graph_from_proof_edges, dfs_collect_component, dfs_finish_order, - graph_has_multi_node_scc, is_lexicographic_descent, is_valid_proof, seed_adjacency_map, - CallGraph, DfsFinishAcc, SccComponentAcc, SccCycleAcc, -}; -use crate::std_induction::AtomicCost::PolyCost; -use crate::std_induction::CostBound::{AtomicBound, ConstantBound, ErrorBound, ForeverBound}; -use crate::std_induction::PolynomialExponent::*; -use crate::std_induction::ShrinkFactor::{ConstantShrink, ProportionalShrink, UnitShrink}; -use crate::std_induction::SubValueRelation::{ - ArithmeticDescent, IteratedSubValue, PreservedValue, StrictSubValue, SubValueUnknown, -}; -pub use crate::std_induction::{ - catamorphism_bound, derive_bound, sub_value_to_call_pattern, sub_value_to_evidence, - sub_value_to_lowering_target, AtomicCost, CostBound, PolynomialExponent, ShrinkFactor, - SubValueRelation, -}; -use crate::std_termination::DescentEvidence::{DescentUnknown, NonIncreasing, Strict}; -use crate::std_termination::DescentSource::{ - ArithmeticDivideDescent, ArithmeticSubtractDescent, ChildAccessor, FoldIteration, ListShrink, - ParserAdvance, SetRemoval, -}; -use crate::std_termination::PositiveDescentAmount::OneStep; -use crate::std_termination::RankingDimension::{ - ArithmeticValue, ListLength, SetCardinality, TokenPosition, TreeSize, -}; -pub use crate::std_termination::{ - evidence_rank, join_evidence, map_evidence_merge_at, merge_evidence, optional_evidence_meet, - DescentEvidence, DescentSource, PositiveDescentAmount, ProofEdge, RankingDimension, - TerminationProof, -}; -pub use crate::std_types::SourceSpan; -pub use crate::v2_compiler_emit::to_string; -pub use crate::v2_compiler_infer_types::{node_is_collection, resolved_type}; -use crate::v2_compiler_parse::ParserCallIdentity::{ParserCallFunction, ParserCallHelper}; -use crate::v2_compiler_parse::ParserResultWitness::{ - ParserWitnessAdvance, ParserWitnessCall, ParserWitnessEat, ParserWitnessExpect, - ParserWitnessOpaque, -}; -pub use crate::v2_compiler_parse::{ - parser_passthrough_state_expr, parser_progress_flag_var, parser_result_witness, - ParserCallIdentity, ParserResultWitness, -}; -use crate::v2_rt; -use crate::v2_std_core::BinOp::{Div, Sub}; -use crate::v2_std_core::ExprData::{ - ExprBinOp, ExprBlock, ExprCall, ExprError, ExprFieldAccess, ExprForEach, ExprIf, ExprLambda, - ExprLet, ExprLiteral, ExprMatch, ExprMethodCall, ExprRecordLit, ExprReturn, ExprUnaryOp, - ExprVar, -}; -use crate::v2_std_core::LiteralValue::{LitInt, LitNull}; -use crate::v2_std_core::MatchPattern::{Bind, VariantPattern}; -use crate::v2_std_core::MethodSemantics::{ - AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics, -}; -pub use crate::v2_std_core::{ - arg_name_at, arg_value, arm_body, arm_guard, arm_pattern, authored_name_at, binop_left, - binop_right, expr_call_func_at, expr_var_name_at, field_access_base, field_access_field_at, - field_binding_pattern, field_init_node_name_at, field_init_node_value, foreach_body, - foreach_collection, if_condition, if_else_branch, if_then_branch, is_child_accessor_in_model, - is_children_list_field, is_sub_value_field, is_tree_size_preserving, is_tree_size_reducing, - lambda_body, lambda_param_names_at, let_binding_name_at, let_body, let_value, match_arm_nodes, - match_scrutinee, method_arg_nodes, method_receiver, param_node_name_at, param_node_type_expr, - return_value, BinOp, ExprData, LiteralValue, MatchPattern, MethodSemantics, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan}; +pub use crate::v2_compiler_emit::{to_string}; +pub use crate::v2_compiler_parse::{ParserResultWitness, parser_progress_flag_var, parser_passthrough_state_expr, parser_result_witness, ParserCallIdentity}; +use crate::v2_compiler_parse::ParserResultWitness::{ParserWitnessAdvance, ParserWitnessExpect, ParserWitnessEat, ParserWitnessCall, ParserWitnessOpaque}; +use crate::v2_compiler_parse::ParserCallIdentity::{ParserCallHelper, ParserCallFunction}; +pub use crate::std_termination::{DescentEvidence, RankingDimension, DescentSource, TerminationProof, ProofEdge, merge_evidence, join_evidence, evidence_rank, optional_evidence_meet, map_evidence_merge_at, PositiveDescentAmount}; +use crate::std_termination::DescentEvidence::{Strict, NonIncreasing, DescentUnknown}; +use crate::std_termination::RankingDimension::{TreeSize, ListLength, ArithmeticValue, TokenPosition, SetCardinality}; +use crate::std_termination::DescentSource::{ChildAccessor, ListShrink, ArithmeticSubtractDescent, ArithmeticDivideDescent, ParserAdvance, SetRemoval, FoldIteration}; +use crate::std_termination::PositiveDescentAmount::{OneStep}; +pub use crate::std_computation::{CallPattern, LoweringTarget, lower_call_pattern, size_bound_param, IterationDimension, type_iteration_dimension}; +use crate::std_computation::CallPattern::{ChildAccessorCall, CollectionShrinkCall, ArithmeticSubtractCall, ParserAdvanceCall, WorklistDrainCall, FoldBodyCall, SameArgumentCall}; +use crate::std_computation::IterationDimension::{TreeDescent, CollectionFold, ArithmeticRepeat}; +pub use crate::std_induction::{SubValueRelation, ShrinkFactor, CostBound, AtomicCost, PolynomialExponent, sub_value_to_evidence, sub_value_to_call_pattern, sub_value_to_lowering_target, catamorphism_bound, derive_bound}; +use crate::std_induction::SubValueRelation::{StrictSubValue, IteratedSubValue, ArithmeticDescent, PreservedValue, SubValueUnknown}; +use crate::std_induction::ShrinkFactor::{UnitShrink, ConstantShrink, ProportionalShrink}; +use crate::std_induction::CostBound::{ConstantBound, AtomicBound, ForeverBound, ErrorBound}; +use crate::std_induction::AtomicCost::{PolyCost}; +use crate::std_induction::PolynomialExponent::*; +pub use crate::v2_std_core::{Node, NewlineIndex, ExprData, BinOp, MatchPattern, field_init_node_name_at, field_init_node_value, arg_name_at, arg_value, arm_body, arm_guard, arm_pattern, MethodSemantics, binop_left, binop_right, field_binding_pattern, foreach_collection, foreach_body, if_condition, if_then_branch, if_else_branch, let_value, let_body, let_binding_name_at, match_scrutinee, match_arm_nodes, method_receiver, method_arg_nodes, param_node_name_at, param_node_type_expr, return_value, expr_call_func_at, expr_var_name_at, field_access_base, field_access_field_at, LiteralValue, is_child_accessor_in_model, lambda_param_names_at, lambda_body, is_children_list_field, is_sub_value_field, is_tree_size_preserving, is_tree_size_reducing, authored_name_at}; +use crate::v2_std_core::ExprData::{ExprLiteral, ExprError, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprBinOp, ExprUnaryOp, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprBlock, ExprForEach, ExprReturn, ExprLambda}; +use crate::v2_std_core::BinOp::{Sub, Div}; +use crate::v2_std_core::MatchPattern::{Bind, VariantPattern}; +use crate::v2_std_core::MethodSemantics::{AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics}; +use crate::v2_std_core::LiteralValue::{LitNull, LitInt}; +pub use crate::v2_compiler_infer_types::{resolved_type, node_is_collection}; +pub use crate::std_algebra::{CollectionSizeEffect, CostShape}; +use crate::std_algebra::CollectionSizeEffect::{ShrinkEffect, ProjectionEffect, IdentityEffect}; +use crate::std_algebra::CostShape::{ShapeConstant, ShapeLinearScan, ShapeIterateBody, ShapeSortBody}; +pub use crate::std_graph::{CallGraph, DfsFinishAcc, SccComponentAcc, SccCycleAcc, seed_adjacency_map, build_call_graph_from_proof_edges, dfs_finish_order, dfs_collect_component, graph_has_multi_node_scc, is_lexicographic_descent, is_valid_proof}; +use self::SizeExpr::*; +use self::CostExpr::*; +use self::Certainty::*; +use self::ParserResultSource::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] @@ -168,38 +120,31 @@ pub struct CostInternTable { pub fn empty_intern_table() -> Rc { Rc::new(CostInternTable { - summaries: v2_rt::rc_empty_map::>(), - }) + summaries: v2_rt::rc_empty_map::>(), +}) } -pub fn cache_summary( - table: Rc, - func_name: String, - summary: Rc, -) -> Rc { +pub fn cache_summary(table: Rc, func_name: String, summary: Rc) -> Rc { Rc::new(CostInternTable { - summaries: v2_rt::rc_map_insert(table.summaries.clone(), func_name, summary), - }) + summaries: v2_rt::rc_map_insert(table.summaries.clone(), func_name, summary), +}) } -pub fn lookup_summary( - table: Rc, - func_name: String, -) -> Option> { +pub fn lookup_summary(table: Rc, func_name: String) -> Option> { v2_rt::map_get(&table.summaries.clone(), func_name) } pub fn evict_summary(table: Rc, func_name: String) -> Rc { - cache_summary( - table, - func_name, - Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - ) + cache_summary(table, func_name, Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +})) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -308,56 +253,39 @@ pub struct SccEdgeBlockAcc { pub fn is_algebra_iteration_method(method_semantics: Option>) -> bool { match method_semantics.as_deref().cloned() { - Some(MethodSemantics::AlgebraMethodSemantics { .. }) => true, - _ => false, - } + Some(MethodSemantics::AlgebraMethodSemantics { .. }) => true, + _ => false, +} } -pub fn method_size_effect( - method_semantics: Option>, -) -> Option { +pub fn method_size_effect(method_semantics: Option>) -> Option { match method_semantics.as_deref().cloned() { - Some(MethodSemantics::AlgebraMethodSemantics { - size_effect: se, .. - }) => se.clone(), - _ => None, - } + Some(MethodSemantics::AlgebraMethodSemantics { size_effect: se, .. }) => se.clone(), + _ => None, +} } -pub fn method_callback_element_position( - method_semantics: Option>, -) -> Option { +pub fn method_callback_element_position(method_semantics: Option>) -> Option { match method_semantics.as_deref().cloned() { - Some(MethodSemantics::AlgebraMethodSemantics { - algebra_template: at, - .. - }) => match at.clone() { - Some(template) => template.callback_element_position.clone(), - None => None, - }, - _ => None, - } + Some(MethodSemantics::AlgebraMethodSemantics { algebra_template: at, .. }) => match at.clone() { + Some(template) => template.callback_element_position.clone(), + None => None, +}, + _ => None, +} } -pub fn iteration_element_name( - method_semantics: Option>, - lambda: Rc, - si: Rc>>, -) -> Option { +pub fn iteration_element_name(method_semantics: Option>, lambda: Rc, si: Rc>>) -> Option { { let params = lambda_param_names_at(lambda, si); - match method_callback_element_position(method_semantics) { - Some(pos) => params.get(pos.clone() as usize).cloned(), - None => None, - } - } +match method_callback_element_position(method_semantics) { + Some(pos) => params.get(pos.clone() as usize).cloned(), + None => None, +} +} } -pub fn proof_has_non_descending_cycle( - proof: Rc, - members: Rc>, - edges: Rc>>, -) -> bool { +pub fn proof_has_non_descending_cycle(proof: Rc, members: Rc>, edges: Rc>>) -> bool { (is_valid_proof(proof, &edges) == false) } @@ -367,1163 +295,482 @@ pub fn set_has(m: Rc>, key: String) -> bool { pub fn strict_after_parser_witness(input: DescentEvidence) -> DescentEvidence { match input { - DescentEvidence::DescentUnknown => DescentEvidence::DescentUnknown, - _ => DescentEvidence::Strict, - } + DescentEvidence::DescentUnknown => DescentEvidence::DescentUnknown, + _ => DescentEvidence::Strict, +} } pub fn empty_parser_progress_env() -> Rc { Rc::new(ParserProgressEnv { - state_aliases: v2_rt::rc_empty_map::(), - result_sources: v2_rt::rc_empty_map::>(), - }) + state_aliases: v2_rt::rc_empty_map::(), + result_sources: v2_rt::rc_empty_map::>(), +}) } -pub fn parser_state_param( - params: Rc>>, - si: Rc>>, -) -> Option> { - Rc::new( - params - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold(None, |acc: _, pair: (i64, Rc)| { - if (acc.clone() != None) { - acc.clone() - } else { - { - let idx = pair.0.clone(); - let param = pair.1.clone(); - if (authored_name_at(si.clone(), ¶m_node_type_expr(¶m)).as_str() - == "ParserState".to_string().as_str()) - { - Some(Rc::new(ParserStateParam { - name: param_node_name_at(param.clone(), si.clone()), - index: idx.clone(), - })) - } else { - None - } +pub fn parser_state_param(params: Rc>>, si: Rc>>) -> Option> { + Rc::new(params.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(None, |acc: _, pair: (i64, Rc)| if (acc.clone() != None) { + acc.clone() + } else { + { + let idx = pair.0.clone(); +let param = pair.1.clone(); +if (authored_name_at(si.clone(), ¶m_node_type_expr(¶m)).as_str() == "ParserState".to_string().as_str()) { + Some(Rc::new(ParserStateParam { + name: param_node_name_at(param.clone(), si.clone()), + index: idx.clone(), +})) + } else { + None } - } +} }) } -pub fn parser_state_base_var( - expr: &Rc, - si: Rc>>, -) -> Option { +pub fn parser_state_base_var(expr: &Rc, si: Rc>>) -> Option { match (*expr.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => match expr.children.clone().first().cloned() { - Some(base) => match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => Some(expr_var_name_at(base.clone(), si)), - _ => None, - }, - None => None, - }, - _ => None, - } + ExprData::ExprFieldAccess { .. } => match expr.children.clone().first().cloned() { + Some(base) => match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => Some(expr_var_name_at(base.clone(), si)), + _ => None, +}, + None => None, +}, + _ => None, +} } -pub fn parser_result_state_progress( - source: Rc, - parser_always_advancing: Rc>, - consumed_true_set: Rc>, - result_name: String, -) -> DescentEvidence { +pub fn parser_result_state_progress(source: Rc, parser_always_advancing: Rc>, consumed_true_set: Rc>, result_name: String) -> DescentEvidence { match (*source).clone() { - ParserResultSource::ParserResultAdvance { input, .. } => { - strict_after_parser_witness(input.clone()) - } - ParserResultSource::ParserResultExpect { input, .. } => { - strict_after_parser_witness(input.clone()) - } - ParserResultSource::ParserResultEat { input, .. } => { - if set_has(consumed_true_set, result_name) { - strict_after_parser_witness(input.clone()) + ParserResultSource::ParserResultAdvance { input, .. } => strict_after_parser_witness(input.clone()), + ParserResultSource::ParserResultExpect { input, .. } => strict_after_parser_witness(input.clone()), + ParserResultSource::ParserResultEat { input, .. } => if set_has(consumed_true_set, result_name) { + strict_after_parser_witness(input.clone()) + } else { + input.clone() + }, + ParserResultSource::ParserResultCall { input, callee, .. } => if (set_has(consumed_true_set, result_name) || set_has(parser_always_advancing, callee.clone())) { + strict_after_parser_witness(input.clone()) + } else { + input.clone() + }, + ParserResultSource::ParserResultDirectState { input: p, .. } => p.clone(), + ParserResultSource::ParserResultOpaque => DescentEvidence::DescentUnknown, +} +} + +pub fn parser_state_arg_expr(call_node: Rc, state_param: Rc, si: Rc>>) -> Option> { + Rc::new(call_node.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(None, |acc: _, pair: (i64, Rc)| if (acc.clone() != None) { + acc.clone() + } else { + { + let idx = pair.0.clone(); +let arg_node = pair.1.clone(); +let matches_state = if (arg_name_at(arg_node.clone(), si.clone()).as_deref() != Some("".to_string().as_str())) { + (arg_name_at(arg_node.clone(), si.clone()).as_deref() == Some(state_param.name.clone().as_str())) } else { - input.clone() - } - } - ParserResultSource::ParserResultCall { input, callee, .. } => { - if (set_has(consumed_true_set, result_name) - || set_has(parser_always_advancing, callee.clone())) - { - strict_after_parser_witness(input.clone()) + (idx.clone() == state_param.index.clone()) + }; +if matches_state.clone() { + Some(arg_value(&arg_node)) } else { - input.clone() + None } - } - ParserResultSource::ParserResultDirectState { input: p, .. } => p.clone(), - ParserResultSource::ParserResultOpaque => DescentEvidence::DescentUnknown, - } } - -pub fn parser_state_arg_expr( - call_node: Rc, - state_param: Rc, - si: Rc>>, -) -> Option> { - Rc::new( - call_node - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold(None, |acc: _, pair: (i64, Rc)| { - if (acc.clone() != None) { - acc.clone() - } else { - { - let idx = pair.0.clone(); - let arg_node = pair.1.clone(); - let matches_state = if (arg_name_at(arg_node.clone(), si.clone()).as_deref() - != Some("".to_string().as_str())) - { - (arg_name_at(arg_node.clone(), si.clone()).as_deref() - == Some(state_param.name.clone().as_str())) - } else { - (idx.clone() == state_param.index.clone()) - }; - if matches_state.clone() { - Some(arg_value(&arg_node)) - } else { - None - } - } - } }) } -pub fn parser_state_expr_progress( - expr: &Rc, - state_param: &Rc, - env: &Rc, - parser_always_advancing: &Rc>, - consumed_true_set: &Rc>, - si: &Rc>>, -) -> DescentEvidence { +pub fn parser_state_expr_progress(expr: &Rc, state_param: &Rc, env: &Rc, parser_always_advancing: &Rc>, consumed_true_set: &Rc>, si: &Rc>>) -> DescentEvidence { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let name = expr_var_name_at(expr.clone(), si.clone()); - if (name.clone().as_str() == state_param.name.clone().as_str()) { - DescentEvidence::NonIncreasing - } else { - match v2_rt::map_get(&env.state_aliases.clone(), name.clone()) { - Some(progress) => progress.clone(), - None => DescentEvidence::DescentUnknown, - } - } - } - ExprData::ExprFieldAccess { .. } => { - if (field_access_field_at(expr.clone(), si.clone()).as_str() - == "state".to_string().as_str()) - { - match parser_state_base_var(&expr, si.clone()) { - Some(result_name) => { - match v2_rt::map_get(&env.result_sources.clone(), result_name.clone()) { - Some(source) => parser_result_state_progress( - source.clone(), - parser_always_advancing.clone(), - consumed_true_set.clone(), - result_name.clone(), - ), - None => DescentEvidence::DescentUnknown, - } - } - None => DescentEvidence::DescentUnknown, - } - } else { - DescentEvidence::DescentUnknown - } - } - ExprData::ExprCall { .. } => match parser_passthrough_state_expr(&expr, &si) { - Some(state_expr) => parser_state_expr_progress( - &state_expr, - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => DescentEvidence::DescentUnknown, - }, - ExprData::ExprIf => { - let cond = if_condition(expr.clone()); - let then_consumed = match parser_progress_flag_var(&cond, &si) { - Some(name) => { - v2_rt::rc_map_insert(consumed_true_set.clone(), name.clone(), true) - } - None => consumed_true_set.clone(), - }; - let then_progress = parser_state_expr_progress( - &if_then_branch(expr.clone()), - &state_param, - &env, - &parser_always_advancing, - &then_consumed, - &si, - ); - let else_progress = match if_else_branch(expr.clone()) { - Some(eb) => parser_state_expr_progress( - &eb, - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => DescentEvidence::DescentUnknown, - }; - merge_evidence(then_progress, else_progress) - } - ExprData::ExprLet => { - let next_env = parser_env_with_binding( - &let_binding_name_at(expr.clone(), si.clone()), - &let_value(expr.clone()), - &env, - &state_param, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - match let_body(expr.clone()) { - Some(body) => parser_state_expr_progress( - &body, - &state_param, - &next_env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => DescentEvidence::DescentUnknown, - } - } - ExprData::ExprMatch => { - let arm_progresses = Rc::new({ - let mut __result = Vec::new(); - for arm_node in match_arm_nodes(expr.clone()).iter().cloned() { - __result.push(parser_state_expr_progress( - &arm_body(&arm_node), - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - )); - } - __result - }); - match arm_progresses.clone().first().cloned() { - Some(initial) => arm_progresses.clone().iter().cloned().fold( - initial.clone(), - |acc: DescentEvidence, p: DescentEvidence| merge_evidence(acc, p.clone()), - ), - None => DescentEvidence::DescentUnknown, - } + ExprData::ExprVar { .. } => { + let name = expr_var_name_at(expr.clone(), si.clone()); +if (name.clone().as_str() == state_param.name.clone().as_str()) { + DescentEvidence::NonIncreasing + } else { + match v2_rt::map_get(&env.state_aliases.clone(), name.clone()) { + Some(progress) => progress.clone(), + None => DescentEvidence::DescentUnknown, +} } - ExprData::ExprBlock => parser_block_state_progress( - &expr.children.clone(), - &state_param, - env.clone(), - &parser_always_advancing, - &consumed_true_set, - &si, - ), - _ => DescentEvidence::DescentUnknown, - } +}, + ExprData::ExprFieldAccess { .. } => if (field_access_field_at(expr.clone(), si.clone()).as_str() == "state".to_string().as_str()) { + match parser_state_base_var(&expr, si.clone()) { + Some(result_name) => match v2_rt::map_get(&env.result_sources.clone(), result_name.clone()) { + Some(source) => parser_result_state_progress(source.clone(), parser_always_advancing.clone(), consumed_true_set.clone(), result_name.clone()), + None => DescentEvidence::DescentUnknown, +}, + None => DescentEvidence::DescentUnknown, +} + } else { + DescentEvidence::DescentUnknown + }, + ExprData::ExprCall { .. } => match parser_passthrough_state_expr(&expr, &si) { + Some(state_expr) => parser_state_expr_progress(&state_expr, &state_param, &env, &parser_always_advancing, &consumed_true_set, &si), + None => DescentEvidence::DescentUnknown, +}, + ExprData::ExprIf => { + let cond = if_condition(expr.clone()); +let then_consumed = match parser_progress_flag_var(&cond, &si) { + Some(name) => v2_rt::rc_map_insert(consumed_true_set.clone(), name.clone(), true), + None => consumed_true_set.clone(), +}; +let then_progress = parser_state_expr_progress(&if_then_branch(expr.clone()), &state_param, &env, &parser_always_advancing, &then_consumed, &si); +let else_progress = match if_else_branch(expr.clone()) { + Some(eb) => parser_state_expr_progress(&eb, &state_param, &env, &parser_always_advancing, &consumed_true_set, &si), + None => DescentEvidence::DescentUnknown, +}; +merge_evidence(then_progress, else_progress) +}, + ExprData::ExprLet => { + let next_env = parser_env_with_binding(&let_binding_name_at(expr.clone(), si.clone()), &let_value(expr.clone()), &env, &state_param, &parser_always_advancing, &consumed_true_set, &si); +match let_body(expr.clone()) { + Some(body) => parser_state_expr_progress(&body, &state_param, &next_env, &parser_always_advancing, &consumed_true_set, &si), + None => DescentEvidence::DescentUnknown, +} +}, + ExprData::ExprMatch => { + let arm_progresses = Rc::new({ let mut __result = Vec::new(); for arm_node in match_arm_nodes(expr.clone()).iter().cloned() { __result.push(parser_state_expr_progress(&arm_body(&arm_node), &state_param, &env, &parser_always_advancing, &consumed_true_set, &si)); } __result }); +match arm_progresses.clone().first().cloned() { + Some(initial) => arm_progresses.clone().iter().cloned().fold(initial.clone(), |acc: DescentEvidence, p: DescentEvidence| merge_evidence(acc, p.clone())), + None => DescentEvidence::DescentUnknown, +} +}, + ExprData::ExprBlock => parser_block_state_progress(&expr.children.clone(), &state_param, env.clone(), &parser_always_advancing, &consumed_true_set, &si), + _ => DescentEvidence::DescentUnknown, +} }) } -pub fn parser_block_state_progress( - stmts: &Rc>>, - state_param: &Rc, - env: Rc, - parser_always_advancing: &Rc>, - consumed_true_set: &Rc>, - si: &Rc>>, -) -> DescentEvidence { +pub fn parser_block_state_progress(stmts: &Rc>>, state_param: &Rc, env: Rc, parser_always_advancing: &Rc>, consumed_true_set: &Rc>, si: &Rc>>) -> DescentEvidence { match stmts.clone().last().cloned() { - None => DescentEvidence::DescentUnknown, - Some(last_stmt) => { - let leading = Rc::new( - stmts - .clone() - .iter() - .cloned() - .take(((stmts.clone().len() as i64) - 1) as usize) - .collect::>(), - ); - let final_env = leading.iter().cloned().fold( - env.clone(), - |acc_env: Rc, stmt: Rc| match (*stmt.expr_data.clone()) - .clone() - { - ExprData::ExprLet => match let_body(stmt.clone()) { - None => parser_env_with_binding( - &let_binding_name_at(stmt.clone(), si.clone()), - &let_value(stmt.clone()), - &acc_env, - &state_param, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - Some(_) => acc_env.clone(), - }, - _ => acc_env.clone(), - }, - ); - parser_state_expr_progress( - &last_stmt, - &state_param, - &final_env, - &parser_always_advancing, - &consumed_true_set, - &si, - ) - } - } + None => DescentEvidence::DescentUnknown, + Some(last_stmt) => { + let leading = Rc::new(stmts.clone().iter().cloned().take(((stmts.clone().len() as i64) - 1) as usize).collect::>()); +let final_env = leading.iter().cloned().fold(env.clone(), |acc_env: Rc, stmt: Rc| match (*stmt.expr_data.clone()).clone() { + ExprData::ExprLet => match let_body(stmt.clone()) { + None => parser_env_with_binding(&let_binding_name_at(stmt.clone(), si.clone()), &let_value(stmt.clone()), &acc_env, &state_param, &parser_always_advancing, &consumed_true_set, &si), + Some(_) => acc_env.clone(), +}, + _ => acc_env.clone(), +}); +parser_state_expr_progress(&last_stmt, &state_param, &final_env, &parser_always_advancing, &consumed_true_set, &si) +}, +} } -pub fn parser_result_source_for_expr( - expr: &Rc, - state_param: &Rc, - env: Rc, - parser_always_advancing: Rc>, - consumed_true_set: Rc>, - si: &Rc>>, -) -> Rc { +pub fn parser_result_source_for_expr(expr: &Rc, state_param: &Rc, env: Rc, parser_always_advancing: Rc>, consumed_true_set: Rc>, si: &Rc>>) -> Rc { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let input_progress = - match parser_state_arg_expr(expr.clone(), state_param.clone(), si.clone()) { - Some(state_expr) => parser_state_expr_progress( - &state_expr, - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => DescentEvidence::DescentUnknown, - }; - match (*parser_result_witness(&expr, si.clone())).clone() { - ParserResultWitness::ParserWitnessAdvance => { - Rc::new(ParserResultSource::ParserResultAdvance { - input: input_progress.clone(), - }) - } - ParserResultWitness::ParserWitnessExpect => { - Rc::new(ParserResultSource::ParserResultExpect { - input: input_progress.clone(), - }) - } - ParserResultWitness::ParserWitnessEat => { - Rc::new(ParserResultSource::ParserResultEat { - input: input_progress.clone(), - }) - } - ParserResultWitness::ParserWitnessCall { callee, .. } => { - match (*callee.clone()).clone() { - ParserCallIdentity::ParserCallHelper { .. } => { - Rc::new(ParserResultSource::ParserResultOpaque) - } - ParserCallIdentity::ParserCallFunction { name, .. } => { - match input_progress.clone() { - DescentEvidence::DescentUnknown => { - Rc::new(ParserResultSource::ParserResultOpaque) - } - _ => Rc::new(ParserResultSource::ParserResultCall { - input: input_progress.clone(), - callee: name.clone(), - }), - } - } - } - } - ParserResultWitness::ParserWitnessOpaque => { - Rc::new(ParserResultSource::ParserResultOpaque) - } - } - } - _ => { - let progress = parser_success_progress( - &expr, - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - match progress.clone() { - DescentEvidence::DescentUnknown => Rc::new(ParserResultSource::ParserResultOpaque), - _ => Rc::new(ParserResultSource::ParserResultDirectState { - input: progress.clone(), - }), - } - } - } + ExprData::ExprCall { .. } => { + let input_progress = match parser_state_arg_expr(expr.clone(), state_param.clone(), si.clone()) { + Some(state_expr) => parser_state_expr_progress(&state_expr, &state_param, &env, &parser_always_advancing, &consumed_true_set, &si), + None => DescentEvidence::DescentUnknown, +}; +match (*parser_result_witness(&expr, si.clone())).clone() { + ParserResultWitness::ParserWitnessAdvance => Rc::new(ParserResultSource::ParserResultAdvance { + input: input_progress.clone(), +}), + ParserResultWitness::ParserWitnessExpect => Rc::new(ParserResultSource::ParserResultExpect { + input: input_progress.clone(), +}), + ParserResultWitness::ParserWitnessEat => Rc::new(ParserResultSource::ParserResultEat { + input: input_progress.clone(), +}), + ParserResultWitness::ParserWitnessCall { callee, .. } => match (*callee.clone()).clone() { + ParserCallIdentity::ParserCallHelper { .. } => Rc::new(ParserResultSource::ParserResultOpaque), + ParserCallIdentity::ParserCallFunction { name, .. } => match input_progress.clone() { + DescentEvidence::DescentUnknown => Rc::new(ParserResultSource::ParserResultOpaque), + _ => Rc::new(ParserResultSource::ParserResultCall { + input: input_progress.clone(), + callee: name.clone(), +}), +}, +}, + ParserResultWitness::ParserWitnessOpaque => Rc::new(ParserResultSource::ParserResultOpaque), +} +}, + _ => { + let progress = parser_success_progress(&expr, &state_param, &env, &parser_always_advancing, &consumed_true_set, &si); +match progress.clone() { + DescentEvidence::DescentUnknown => Rc::new(ParserResultSource::ParserResultOpaque), + _ => Rc::new(ParserResultSource::ParserResultDirectState { + input: progress.clone(), +}), +} +}, +} } -pub fn parser_env_with_binding( - name: &String, - value_expr: &Rc, - env: &Rc, - state_param: &Rc, - parser_always_advancing: &Rc>, - consumed_true_set: &Rc>, - si: &Rc>>, -) -> Rc { +pub fn parser_env_with_binding(name: &String, value_expr: &Rc, env: &Rc, state_param: &Rc, parser_always_advancing: &Rc>, consumed_true_set: &Rc>, si: &Rc>>) -> Rc { { - let state_progress = parser_state_expr_progress( - &value_expr, - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - let result_source = parser_result_source_for_expr( - &value_expr, - &state_param, - env.clone(), - parser_always_advancing.clone(), - consumed_true_set.clone(), - &si, - ); - Rc::new(ParserProgressEnv { - state_aliases: v2_rt::rc_map_insert( - env.state_aliases.clone(), - name.clone(), - state_progress, - ), - result_sources: v2_rt::rc_map_insert( - env.result_sources.clone(), - name.clone(), - result_source, - ), - }) - } + let state_progress = parser_state_expr_progress(&value_expr, &state_param, &env, &parser_always_advancing, &consumed_true_set, &si); +let result_source = parser_result_source_for_expr(&value_expr, &state_param, env.clone(), parser_always_advancing.clone(), consumed_true_set.clone(), &si); +Rc::new(ParserProgressEnv { + state_aliases: v2_rt::rc_map_insert(env.state_aliases.clone(), name.clone(), state_progress), + result_sources: v2_rt::rc_map_insert(env.result_sources.clone(), name.clone(), result_source), +}) +} } -pub fn parser_call_edge_progress( - call_node: &Rc, - state_param: &Rc, - env: Rc, - parser_always_advancing: &Rc>, - consumed_true_set: Rc>, - si: &Rc>>, -) -> DescentEvidence { +pub fn parser_call_edge_progress(call_node: &Rc, state_param: &Rc, env: Rc, parser_always_advancing: &Rc>, consumed_true_set: Rc>, si: &Rc>>) -> DescentEvidence { match parser_state_arg_expr(call_node.clone(), state_param.clone(), si.clone()) { - Some(state_expr) => { - let input_progress = parser_state_expr_progress( - &state_expr, - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - if set_has( - parser_always_advancing.clone(), - expr_call_func_at(call_node.clone(), si.clone()), - ) { - strict_after_parser_witness(input_progress) - } else { - input_progress - } + Some(state_expr) => { + let input_progress = parser_state_expr_progress(&state_expr, &state_param, &env, &parser_always_advancing, &consumed_true_set, &si); +if set_has(parser_always_advancing.clone(), expr_call_func_at(call_node.clone(), si.clone())) { + strict_after_parser_witness(input_progress) + } else { + input_progress } - None => DescentEvidence::DescentUnknown, - } +}, + None => DescentEvidence::DescentUnknown, +} } -pub fn collect_parser_progress_block_edges( - caller: String, - stmts: Rc>>, - state_param: Rc, - scc_name_set: Rc>, - env: Rc, - parser_always_advancing: Rc>, - consumed_true_set: Rc>, - si: Rc>>, -) -> Rc>> { +pub fn collect_parser_progress_block_edges(caller: String, stmts: Rc>>, state_param: Rc, scc_name_set: Rc>, env: Rc, parser_always_advancing: Rc>, consumed_true_set: Rc>, si: Rc>>) -> Rc>> { { - let acc = stmts.iter().cloned().fold( - Rc::new(ParserProgressAcc { - edges: Rc::new(vec![]), - env: env, - }), - |acc: Rc, stmt: Rc| match (*stmt.expr_data.clone()).clone() { - ExprData::ExprLet => match let_body(stmt.clone()) { - None => { - let value_expr = let_value(stmt.clone()); - let value_edges = collect_parser_progress_edges( - &caller, - &value_expr, - &state_param, - &scc_name_set, - &acc.env.clone(), - &parser_always_advancing, - &consumed_true_set, - &si, - ); - let next_env = parser_env_with_binding( - &let_binding_name_at(stmt.clone(), si.clone()), - &value_expr, - &acc.env.clone(), - &state_param, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - Rc::new(ParserProgressAcc { - edges: v2_rt::concat(acc.edges.clone(), value_edges.clone()), - env: next_env.clone(), - }) - } - Some(_) => { - let stmt_edges = collect_parser_progress_edges( - &caller, - &stmt, - &state_param, - &scc_name_set, - &acc.env.clone(), - &parser_always_advancing, - &consumed_true_set, - &si, - ); - Rc::new(ParserProgressAcc { - edges: v2_rt::concat(acc.edges.clone(), stmt_edges.clone()), - env: acc.env.clone(), - }) - } - }, - _ => { - let stmt_edges = collect_parser_progress_edges( - &caller, - &stmt, - &state_param, - &scc_name_set, - &acc.env.clone(), - &parser_always_advancing, - &consumed_true_set, - &si, - ); - Rc::new(ParserProgressAcc { - edges: v2_rt::concat(acc.edges.clone(), stmt_edges.clone()), - env: acc.env.clone(), - }) - } - }, - ); - acc.edges.clone() - } + let acc = stmts.iter().cloned().fold(Rc::new(ParserProgressAcc { + edges: Rc::new(vec![]), + env: env, +}), |acc: Rc, stmt: Rc| match (*stmt.expr_data.clone()).clone() { + ExprData::ExprLet => match let_body(stmt.clone()) { + None => { + let value_expr = let_value(stmt.clone()); +let value_edges = collect_parser_progress_edges(&caller, &value_expr, &state_param, &scc_name_set, &acc.env.clone(), &parser_always_advancing, &consumed_true_set, &si); +let next_env = parser_env_with_binding(&let_binding_name_at(stmt.clone(), si.clone()), &value_expr, &acc.env.clone(), &state_param, &parser_always_advancing, &consumed_true_set, &si); +Rc::new(ParserProgressAcc { + edges: v2_rt::concat(acc.edges.clone(), value_edges.clone()), + env: next_env.clone(), +}) +}, + Some(_) => { + let stmt_edges = collect_parser_progress_edges(&caller, &stmt, &state_param, &scc_name_set, &acc.env.clone(), &parser_always_advancing, &consumed_true_set, &si); +Rc::new(ParserProgressAcc { + edges: v2_rt::concat(acc.edges.clone(), stmt_edges.clone()), + env: acc.env.clone(), +}) +}, +}, + _ => { + let stmt_edges = collect_parser_progress_edges(&caller, &stmt, &state_param, &scc_name_set, &acc.env.clone(), &parser_always_advancing, &consumed_true_set, &si); +Rc::new(ParserProgressAcc { + edges: v2_rt::concat(acc.edges.clone(), stmt_edges.clone()), + env: acc.env.clone(), +}) +}, +}); +acc.edges.clone() +} } -pub fn collect_parser_progress_edges( - caller: &String, - body: &Rc, - state_param: &Rc, - scc_name_set: &Rc>, - env: &Rc, - parser_always_advancing: &Rc>, - consumed_true_set: &Rc>, - si: &Rc>>, -) -> Rc>> { +pub fn collect_parser_progress_edges(caller: &String, body: &Rc, state_param: &Rc, scc_name_set: &Rc>, env: &Rc, parser_always_advancing: &Rc>, consumed_true_set: &Rc>, si: &Rc>>) -> Rc>> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let own_edges = if set_has( - scc_name_set.clone(), - expr_call_func_at(body.clone(), si.clone()), - ) { - Rc::new(vec![Rc::new(ParserProgressEdge { - caller: caller.clone(), - callee: expr_call_func_at(body.clone(), si.clone()), - progress: parser_call_edge_progress( - &body, - &state_param, - env.clone(), - &parser_always_advancing, - consumed_true_set.clone(), - &si, - ), - })]) - } else { - Rc::new(vec![]) - }; - let child_edges = Rc::new({ - let mut __result = Vec::new(); - for child in body.children.clone().iter().cloned() { - __result.extend( - (*collect_parser_progress_edges( - &caller, - &child, - &state_param, - &scc_name_set, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - )) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat(own_edges, child_edges) - } - ExprData::ExprIf => { - let cond = if_condition(body.clone()); - let cond_edges = collect_parser_progress_edges( - &caller, - &cond, - &state_param, - &scc_name_set, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - let then_consumed = match parser_progress_flag_var(&cond, &si) { - Some(name) => { - v2_rt::rc_map_insert(consumed_true_set.clone(), name.clone(), true) - } - None => consumed_true_set.clone(), - }; - let then_edges = collect_parser_progress_edges( - &caller, - &if_then_branch(body.clone()), - &state_param, - &scc_name_set, - &env, - &parser_always_advancing, - &then_consumed, - &si, - ); - let else_edges = match if_else_branch(body.clone()) { - Some(eb) => collect_parser_progress_edges( - &caller, - &eb, - &state_param, - &scc_name_set, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => Rc::new(vec![]), - }; - v2_rt::concat(v2_rt::concat(cond_edges, then_edges), else_edges) - } - ExprData::ExprLet => { - let value_expr = let_value(body.clone()); - let value_edges = collect_parser_progress_edges( - &caller, - &value_expr, - &state_param, - &scc_name_set, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - let next_env = parser_env_with_binding( - &let_binding_name_at(body.clone(), si.clone()), - &value_expr, - &env, - &state_param, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - let body_edges = match let_body(body.clone()) { - Some(b) => collect_parser_progress_edges( - &caller, - &b, - &state_param, - &scc_name_set, - &next_env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => Rc::new(vec![]), - }; - v2_rt::concat(value_edges, body_edges) - } - ExprData::ExprBlock => collect_parser_progress_block_edges( - caller.clone(), - body.children.clone(), - state_param.clone(), - scc_name_set.clone(), - env.clone(), - parser_always_advancing.clone(), - consumed_true_set.clone(), - si.clone(), - ), - ExprData::ExprMatch => { - let scrut_edges = collect_parser_progress_edges( - &caller, - &match_scrutinee(body.clone()), - &state_param, - &scc_name_set, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - let arm_edges = Rc::new({ - let mut __result = Vec::new(); - for arm_node in match_arm_nodes(body.clone()).iter().cloned() { - __result.extend( - (*collect_parser_progress_edges( - &caller, - &arm_body(&arm_node), - &state_param, - &scc_name_set, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - )) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat(scrut_edges, arm_edges) - } - _ => Rc::new({ - let mut __result = Vec::new(); - for child in body.children.clone().iter().cloned() { - __result.extend( - (*collect_parser_progress_edges( - &caller, - &child, - &state_param, - &scc_name_set, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - )) - .iter() - .cloned(), - ); - } - __result - }), - } + ExprData::ExprCall { .. } => { + let own_edges = if set_has(scc_name_set.clone(), expr_call_func_at(body.clone(), si.clone())) { + Rc::new(vec![Rc::new(ParserProgressEdge { + caller: caller.clone(), + callee: expr_call_func_at(body.clone(), si.clone()), + progress: parser_call_edge_progress(&body, &state_param, env.clone(), &parser_always_advancing, consumed_true_set.clone(), &si), +})]) + } else { + Rc::new(vec![]) + }; +let child_edges = Rc::new({ let mut __result = Vec::new(); for child in body.children.clone().iter().cloned() { __result.extend((*collect_parser_progress_edges(&caller, &child, &state_param, &scc_name_set, &env, &parser_always_advancing, &consumed_true_set, &si)).iter().cloned()); } __result }); +v2_rt::concat(own_edges, child_edges) +}, + ExprData::ExprIf => { + let cond = if_condition(body.clone()); +let cond_edges = collect_parser_progress_edges(&caller, &cond, &state_param, &scc_name_set, &env, &parser_always_advancing, &consumed_true_set, &si); +let then_consumed = match parser_progress_flag_var(&cond, &si) { + Some(name) => v2_rt::rc_map_insert(consumed_true_set.clone(), name.clone(), true), + None => consumed_true_set.clone(), +}; +let then_edges = collect_parser_progress_edges(&caller, &if_then_branch(body.clone()), &state_param, &scc_name_set, &env, &parser_always_advancing, &then_consumed, &si); +let else_edges = match if_else_branch(body.clone()) { + Some(eb) => collect_parser_progress_edges(&caller, &eb, &state_param, &scc_name_set, &env, &parser_always_advancing, &consumed_true_set, &si), + None => Rc::new(vec![]), +}; +v2_rt::concat(v2_rt::concat(cond_edges, then_edges), else_edges) +}, + ExprData::ExprLet => { + let value_expr = let_value(body.clone()); +let value_edges = collect_parser_progress_edges(&caller, &value_expr, &state_param, &scc_name_set, &env, &parser_always_advancing, &consumed_true_set, &si); +let next_env = parser_env_with_binding(&let_binding_name_at(body.clone(), si.clone()), &value_expr, &env, &state_param, &parser_always_advancing, &consumed_true_set, &si); +let body_edges = match let_body(body.clone()) { + Some(b) => collect_parser_progress_edges(&caller, &b, &state_param, &scc_name_set, &next_env, &parser_always_advancing, &consumed_true_set, &si), + None => Rc::new(vec![]), +}; +v2_rt::concat(value_edges, body_edges) +}, + ExprData::ExprBlock => collect_parser_progress_block_edges(caller.clone(), body.children.clone(), state_param.clone(), scc_name_set.clone(), env.clone(), parser_always_advancing.clone(), consumed_true_set.clone(), si.clone()), + ExprData::ExprMatch => { + let scrut_edges = collect_parser_progress_edges(&caller, &match_scrutinee(body.clone()), &state_param, &scc_name_set, &env, &parser_always_advancing, &consumed_true_set, &si); +let arm_edges = Rc::new({ let mut __result = Vec::new(); for arm_node in match_arm_nodes(body.clone()).iter().cloned() { __result.extend((*collect_parser_progress_edges(&caller, &arm_body(&arm_node), &state_param, &scc_name_set, &env, &parser_always_advancing, &consumed_true_set, &si)).iter().cloned()); } __result }); +v2_rt::concat(scrut_edges, arm_edges) +}, + _ => Rc::new({ let mut __result = Vec::new(); for child in body.children.clone().iter().cloned() { __result.extend((*collect_parser_progress_edges(&caller, &child, &state_param, &scc_name_set, &env, &parser_always_advancing, &consumed_true_set, &si)).iter().cloned()); } __result }), +} }) } -pub fn parser_record_field_value( - expr: Rc, - field_name: String, - si: Rc>>, -) -> Option> { - Rc::new({ - let mut __result = Vec::new(); - for child in Rc::new({ - let mut __result = Vec::new(); - for child in expr.children.clone().iter().cloned() { - if (field_init_node_name_at(child.clone(), si.clone()).as_str() - == field_name.clone().as_str()) - { - __result.push(child); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(field_init_node_value(&child)); - } - __result - }) - .first() - .cloned() +pub fn parser_record_field_value(expr: Rc, field_name: String, si: Rc>>) -> Option> { + Rc::new({ let mut __result = Vec::new(); for child in Rc::new({ let mut __result = Vec::new(); for child in expr.children.clone().iter().cloned() { if (field_init_node_name_at(child.clone(), si.clone()).as_str() == field_name.clone().as_str()) { __result.push(child); } } __result }).iter().cloned() { __result.push(field_init_node_value(&child)); } __result }).first().cloned() } pub fn parser_expr_is_none(expr: Rc) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitNull => true, - _ => false, - }, - _ => false, - } + ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitNull => true, + _ => false, +}, + _ => false, +} } -pub fn parser_success_progress( - expr: &Rc, - state_param: &Rc, - env: &Rc, - parser_always_advancing: &Rc>, - consumed_true_set: &Rc>, - si: &Rc>>, -) -> DescentEvidence { +pub fn parser_success_progress(expr: &Rc, state_param: &Rc, env: &Rc, parser_always_advancing: &Rc>, consumed_true_set: &Rc>, si: &Rc>>) -> DescentEvidence { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*expr.expr_data.clone()).clone() { - ExprData::ExprReturn => parser_success_progress( - &return_value(expr.clone()), - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - ExprData::ExprVar { .. } => match v2_rt::map_get( - &env.result_sources.clone(), - expr_var_name_at(expr.clone(), si.clone()), - ) { - Some(source) => parser_result_state_progress( - source.clone(), - parser_always_advancing.clone(), - consumed_true_set.clone(), - expr_var_name_at(expr.clone(), si.clone()), - ), - None => DescentEvidence::DescentUnknown, - }, - ExprData::ExprCall { .. } => parser_result_state_progress( - parser_result_source_for_expr( - &expr, - &state_param, - env.clone(), - parser_always_advancing.clone(), - consumed_true_set.clone(), - &si, - ), - parser_always_advancing.clone(), - consumed_true_set.clone(), - "".to_string(), - ), - ExprData::ExprRecordLit { .. } => { - match parser_record_field_value(expr.clone(), "err".to_string(), si.clone()) { - Some(err_expr) => { - if parser_expr_is_none(err_expr.clone()) { - match parser_record_field_value( - expr.clone(), - "state".to_string(), - si.clone(), - ) { - Some(state_expr) => parser_state_expr_progress( - &state_expr, - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => DescentEvidence::DescentUnknown, - } - } else { - DescentEvidence::DescentUnknown - } - } - None => DescentEvidence::DescentUnknown, - } - } - ExprData::ExprIf => { - let cond = if_condition(expr.clone()); - let then_consumed = match parser_progress_flag_var(&cond, &si) { - Some(name) => { - v2_rt::rc_map_insert(consumed_true_set.clone(), name.clone(), true) - } - None => consumed_true_set.clone(), - }; - let then_progress = parser_success_progress( - &if_then_branch(expr.clone()), - &state_param, - &env, - &parser_always_advancing, - &then_consumed, - &si, - ); - let else_progress = match if_else_branch(expr.clone()) { - Some(eb) => parser_success_progress( - &eb, - &state_param, - &env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => DescentEvidence::DescentUnknown, - }; - merge_evidence(then_progress, else_progress) - } - ExprData::ExprLet => { - let next_env = parser_env_with_binding( - &let_binding_name_at(expr.clone(), si.clone()), - &let_value(expr.clone()), - &env, - &state_param, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - match let_body(expr.clone()) { - Some(body) => parser_success_progress( - &body, - &state_param, - &next_env, - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => DescentEvidence::DescentUnknown, - } - } - ExprData::ExprBlock => { - let prefix = v2_rt::reverse(Rc::new( - v2_rt::reverse(expr.children.clone()) - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - )); - let acc = prefix.iter().cloned().fold( - Rc::new(ParserProgressAcc { - edges: Rc::new(vec![]), - env: env.clone(), - }), - |acc: Rc, stmt: Rc| match (*stmt.expr_data.clone()) - .clone() - { - ExprData::ExprLet => match let_body(stmt.clone()) { - None => { - let next_env = parser_env_with_binding( - &let_binding_name_at(stmt.clone(), si.clone()), - &let_value(stmt.clone()), - &acc.env.clone(), - &state_param, - &parser_always_advancing, - &consumed_true_set, - &si, - ); - Rc::new(ParserProgressAcc { - edges: acc.edges.clone(), - env: next_env.clone(), - }) - } - Some(_) => acc.clone(), - }, - _ => acc.clone(), - }, - ); - match expr.children.clone().last().cloned() { - Some(last_stmt) => parser_success_progress( - &last_stmt, - &state_param, - &acc.env.clone(), - &parser_always_advancing, - &consumed_true_set, - &si, - ), - None => DescentEvidence::DescentUnknown, - } - } - _ => DescentEvidence::DescentUnknown, - } + ExprData::ExprReturn => parser_success_progress(&return_value(expr.clone()), &state_param, &env, &parser_always_advancing, &consumed_true_set, &si), + ExprData::ExprVar { .. } => match v2_rt::map_get(&env.result_sources.clone(), expr_var_name_at(expr.clone(), si.clone())) { + Some(source) => parser_result_state_progress(source.clone(), parser_always_advancing.clone(), consumed_true_set.clone(), expr_var_name_at(expr.clone(), si.clone())), + None => DescentEvidence::DescentUnknown, +}, + ExprData::ExprCall { .. } => parser_result_state_progress(parser_result_source_for_expr(&expr, &state_param, env.clone(), parser_always_advancing.clone(), consumed_true_set.clone(), &si), parser_always_advancing.clone(), consumed_true_set.clone(), "".to_string()), + ExprData::ExprRecordLit { .. } => match parser_record_field_value(expr.clone(), "err".to_string(), si.clone()) { + Some(err_expr) => if parser_expr_is_none(err_expr.clone()) { + match parser_record_field_value(expr.clone(), "state".to_string(), si.clone()) { + Some(state_expr) => parser_state_expr_progress(&state_expr, &state_param, &env, &parser_always_advancing, &consumed_true_set, &si), + None => DescentEvidence::DescentUnknown, +} + } else { + DescentEvidence::DescentUnknown + }, + None => DescentEvidence::DescentUnknown, +}, + ExprData::ExprIf => { + let cond = if_condition(expr.clone()); +let then_consumed = match parser_progress_flag_var(&cond, &si) { + Some(name) => v2_rt::rc_map_insert(consumed_true_set.clone(), name.clone(), true), + None => consumed_true_set.clone(), +}; +let then_progress = parser_success_progress(&if_then_branch(expr.clone()), &state_param, &env, &parser_always_advancing, &then_consumed, &si); +let else_progress = match if_else_branch(expr.clone()) { + Some(eb) => parser_success_progress(&eb, &state_param, &env, &parser_always_advancing, &consumed_true_set, &si), + None => DescentEvidence::DescentUnknown, +}; +merge_evidence(then_progress, else_progress) +}, + ExprData::ExprLet => { + let next_env = parser_env_with_binding(&let_binding_name_at(expr.clone(), si.clone()), &let_value(expr.clone()), &env, &state_param, &parser_always_advancing, &consumed_true_set, &si); +match let_body(expr.clone()) { + Some(body) => parser_success_progress(&body, &state_param, &next_env, &parser_always_advancing, &consumed_true_set, &si), + None => DescentEvidence::DescentUnknown, +} +}, + ExprData::ExprBlock => { + let prefix = v2_rt::reverse(Rc::new(v2_rt::reverse(expr.children.clone()).iter().cloned().skip(1 as usize).collect::>())); +let acc = prefix.iter().cloned().fold(Rc::new(ParserProgressAcc { + edges: Rc::new(vec![]), + env: env.clone(), +}), |acc: Rc, stmt: Rc| match (*stmt.expr_data.clone()).clone() { + ExprData::ExprLet => match let_body(stmt.clone()) { + None => { + let next_env = parser_env_with_binding(&let_binding_name_at(stmt.clone(), si.clone()), &let_value(stmt.clone()), &acc.env.clone(), &state_param, &parser_always_advancing, &consumed_true_set, &si); +Rc::new(ParserProgressAcc { + edges: acc.edges.clone(), + env: next_env.clone(), +}) +}, + Some(_) => acc.clone(), +}, + _ => acc.clone(), +}); +match expr.children.clone().last().cloned() { + Some(last_stmt) => parser_success_progress(&last_stmt, &state_param, &acc.env.clone(), &parser_always_advancing, &consumed_true_set, &si), + None => DescentEvidence::DescentUnknown, +} +}, + _ => DescentEvidence::DescentUnknown, +} }) } -pub fn parser_member_is_always_advancing( - entry: &Rc, - parser_name_set: Rc>, - proven: &Rc>, - si: &Rc>>, -) -> bool { +pub fn parser_member_is_always_advancing(entry: &Rc, parser_name_set: Rc>, proven: &Rc>, si: &Rc>>) -> bool { match parser_state_param(entry.params.clone(), si.clone()) { - Some(state_param) => { - let edges = collect_parser_progress_edges( - &entry.name.clone(), - &entry.body.clone(), - &state_param, - &parser_name_set, - &empty_parser_progress_env(), - &proven, - &v2_rt::rc_empty_map::(), - &si, - ); - ({ - let mut __all = true; - for edge in edges.iter().cloned() { - if !((edge.progress.clone() == DescentEvidence::Strict) - || ((edge.progress.clone() == DescentEvidence::NonIncreasing) - && set_has(proven.clone(), edge.callee.clone()))) - { - __all = false; - break; - } - } - __all - } && (parser_success_progress( - &entry.body.clone(), - &state_param, - &empty_parser_progress_env(), - &proven, - &v2_rt::rc_empty_map::(), - &si, - ) == DescentEvidence::Strict)) - } - None => false, - } + Some(state_param) => { + let edges = collect_parser_progress_edges(&entry.name.clone(), &entry.body.clone(), &state_param, &parser_name_set, &empty_parser_progress_env(), &proven, &v2_rt::rc_empty_map::(), &si); +({ let mut __all = true; for edge in edges.iter().cloned() { if !(((edge.progress.clone() == DescentEvidence::Strict) || ((edge.progress.clone() == DescentEvidence::NonIncreasing) && set_has(proven.clone(), edge.callee.clone())))) { __all = false; break; } } __all } && (parser_success_progress(&entry.body.clone(), &state_param, &empty_parser_progress_env(), &proven, &v2_rt::rc_empty_map::(), &si) == DescentEvidence::Strict)) +}, + None => false, +} } -pub fn infer_parser_always_advancing_members_worklist( - mut queue: Rc>, - mut func_index: Rc>>, - mut parser_name_set: Rc>, - mut reverse_graph: Rc>>>, - mut proven: Rc>, - mut si: Rc>>, -) -> Rc> { +pub fn infer_parser_always_advancing_members_worklist(mut queue: Rc>, mut func_index: Rc>>, mut parser_name_set: Rc>, mut reverse_graph: Rc>>>, mut proven: Rc>, mut si: Rc>>) -> Rc> { loop { match queue.clone().first().cloned() { - Some(name) => { - let rest = Rc::new( - queue - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - if set_has(proven.clone(), name.clone()) { - { - let __tco_0 = rest; - queue = __tco_0; - continue; - } - } else { - match v2_rt::map_get(&func_index, name.clone()) { - Some(entry) => { - if parser_member_is_always_advancing( - &entry, - parser_name_set.clone(), - &proven, - &si, - ) { - let callers = match v2_rt::map_get(&reverse_graph, name.clone()) { - Some(members) => members.clone(), - None => Rc::new(vec![]), - }; - { - let __tco_0 = deduplicate(v2_rt::concat(rest, callers)); - let __tco_1 = v2_rt::rc_map_insert(proven, name.clone(), true); - queue = __tco_0; - proven = __tco_1; - continue; - } - } else { - { - let __tco_0 = rest; - queue = __tco_0; - continue; - } - } - } - None => { - let __tco_0 = rest; - queue = __tco_0; - continue; - } - } - } - } - None => { - break proven.clone(); - } - } - } + Some(name) => { let rest = Rc::new(queue.clone().iter().cloned().skip(1 as usize).collect::>()); +if set_has(proven.clone(), name.clone()) { + { + let __tco_0 = rest; +queue = __tco_0; +continue; +} +} else { + match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => { if parser_member_is_always_advancing(&entry, parser_name_set.clone(), &proven, &si) { + let callers = match v2_rt::map_get(&reverse_graph, name.clone()) { + Some(members) => members.clone(), + None => Rc::new(vec![]), +}; +{ + let __tco_0 = deduplicate(v2_rt::concat(rest, callers)); +let __tco_1 = v2_rt::rc_map_insert(proven, name.clone(), true); +queue = __tco_0; +proven = __tco_1; +continue; +} +} else { + { + let __tco_0 = rest; +queue = __tco_0; +continue; +} +} }, + None => { { + let __tco_0 = rest; +queue = __tco_0; +continue; +} }, +} +} }, + None => { break proven.clone(); }, +} +} } -pub fn infer_parser_always_advancing_members( - members: &Rc>, - func_index: &Rc>>, - si: &Rc>>, -) -> Rc> { +pub fn infer_parser_always_advancing_members(members: &Rc>, func_index: &Rc>>, si: &Rc>>) -> Rc> { { - let parser_name_set = members.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let parser_entries = Rc::new({ - let mut __result = Vec::new(); - for name in members.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&func_index, name.clone()) { - Some(entry) => Rc::new(vec![entry.clone()]), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let reverse_graph = build_call_graph(&parser_entries, si.clone()) - .reverse - .clone(); - infer_parser_always_advancing_members_worklist( - members.clone(), - func_index.clone(), - parser_name_set, - reverse_graph, - v2_rt::rc_empty_map::(), - si.clone(), - ) - } + let parser_name_set = members.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let parser_entries = Rc::new({ let mut __result = Vec::new(); for name in members.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => Rc::new(vec![entry.clone()]), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let reverse_graph = build_call_graph(&parser_entries, si.clone()).reverse.clone(); +infer_parser_always_advancing_members_worklist(members.clone(), func_index.clone(), parser_name_set, reverse_graph, v2_rt::rc_empty_map::(), si.clone()) +} } -pub fn parser_function_names( - func_index: &Rc>>, - si: Rc>>, -) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for name in Rc::new(v2_rt::map_keys(&func_index)).iter().cloned() { - if match v2_rt::map_get(&func_index, name.clone()) { - Some(entry) => (parser_state_param(entry.params.clone(), si.clone()) != None), - None => false, - } { - __result.push(name); - } - } - __result - }) +pub fn parser_function_names(func_index: &Rc>>, si: Rc>>) -> Rc> { + Rc::new({ let mut __result = Vec::new(); for name in Rc::new(v2_rt::map_keys(&func_index)).iter().cloned() { if match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => (parser_state_param(entry.params.clone(), si.clone()) != None), + None => false, +} { __result.push(name); } } __result }) } -pub fn infer_all_parser_always_advancing( - func_index: &Rc>>, - si: &Rc>>, -) -> Rc> { +pub fn infer_all_parser_always_advancing(func_index: &Rc>>, si: &Rc>>) -> Rc> { { let members = parser_function_names(&func_index, si.clone()); - infer_parser_always_advancing_members(&members, &func_index, &si) - } +infer_parser_always_advancing_members(&members, &func_index, &si) +} } pub fn seed_string_map(key: String, value: String) -> Rc> { @@ -1538,1256 +785,598 @@ pub fn seed_cost_map(key: String, value: Rc) -> Rc>(), key, value) } -pub fn seed_func_entry_map( - key: String, - value: Rc, -) -> Rc>> { +pub fn seed_func_entry_map(key: String, value: Rc) -> Rc>> { v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), key, value) } -pub fn build_call_graph_from_parser_edges( - names: &Rc>, - edges: Rc>>, -) -> Rc { +pub fn build_call_graph_from_parser_edges(names: &Rc>, edges: Rc>>) -> Rc { { let initial_forward = seed_adjacency_map(names.clone()); - let initial_reverse = seed_adjacency_map(names.clone()); - edges.iter().cloned().fold( - Rc::new(CallGraph { - forward: initial_forward, - reverse: initial_reverse, - }), - |acc: Rc, edge: Rc| { - let forward_neighbors = - match v2_rt::map_get(&acc.forward.clone(), edge.caller.clone()) { - Some(ns) => ns.clone(), - None => Rc::new(vec![]), - }; - let reverse_neighbors = - match v2_rt::map_get(&acc.reverse.clone(), edge.callee.clone()) { - Some(ns) => ns.clone(), - None => Rc::new(vec![]), - }; - Rc::new(CallGraph { - forward: v2_rt::rc_map_insert( - acc.forward.clone(), - edge.caller.clone(), - v2_rt::rc_list_push(forward_neighbors.clone(), edge.callee.clone()), - ), - reverse: v2_rt::rc_map_insert( - acc.reverse.clone(), - edge.callee.clone(), - v2_rt::rc_list_push(reverse_neighbors.clone(), edge.caller.clone()), - ), - }) - }, - ) - } +let initial_reverse = seed_adjacency_map(names.clone()); +edges.iter().cloned().fold(Rc::new(CallGraph { + forward: initial_forward, + reverse: initial_reverse, +}), |acc: Rc, edge: Rc| { + let forward_neighbors = match v2_rt::map_get(&acc.forward.clone(), edge.caller.clone()) { + Some(ns) => ns.clone(), + None => Rc::new(vec![]), +}; +let reverse_neighbors = match v2_rt::map_get(&acc.reverse.clone(), edge.callee.clone()) { + Some(ns) => ns.clone(), + None => Rc::new(vec![]), +}; +Rc::new(CallGraph { + forward: v2_rt::rc_map_insert(acc.forward.clone(), edge.caller.clone(), v2_rt::rc_list_push(forward_neighbors.clone(), edge.callee.clone())), + reverse: v2_rt::rc_map_insert(acc.reverse.clone(), edge.callee.clone(), v2_rt::rc_list_push(reverse_neighbors.clone(), edge.caller.clone())), +}) +}) +} } -pub fn same_progress_subgraph_has_cycle( - members: &Rc>, - edges: Rc>>, -) -> bool { +pub fn same_progress_subgraph_has_cycle(members: &Rc>, edges: Rc>>) -> bool { { - let same_edges = Rc::new({ - let mut __result = Vec::new(); - for edge in edges.iter().cloned() { - if (edge.progress.clone() == DescentEvidence::NonIncreasing) { - __result.push(edge); - } - } - __result - }); - let has_self_cycle = { - let mut __found = false; - for edge in same_edges.clone().iter().cloned() { - if (edge.caller.clone().as_str() == edge.callee.clone().as_str()) { - __found = true; - break; - } - } - __found - }; - if has_self_cycle { + let same_edges = Rc::new({ let mut __result = Vec::new(); for edge in edges.iter().cloned() { if (edge.progress.clone() == DescentEvidence::NonIncreasing) { __result.push(edge); } } __result }); +let has_self_cycle = { let mut __found = false; for edge in same_edges.clone().iter().cloned() { if (edge.caller.clone().as_str() == edge.callee.clone().as_str()) { __found = true; break; } } __found }; +if has_self_cycle { true } else { { - let same_cross_edges = Rc::new({ - let mut __result = Vec::new(); - for edge in same_edges.clone().iter().cloned() { - if (edge.caller.clone().as_str() != edge.callee.clone().as_str()) { - __result.push(edge); - } - } - __result - }); - let graph = build_call_graph_from_parser_edges(&members, same_cross_edges); - graph_has_multi_node_scc(members.clone(), graph) - } + let same_cross_edges = Rc::new({ let mut __result = Vec::new(); for edge in same_edges.clone().iter().cloned() { if (edge.caller.clone().as_str() != edge.callee.clone().as_str()) { __result.push(edge); } } __result }); +let graph = build_call_graph_from_parser_edges(&members, same_cross_edges); +graph_has_multi_node_scc(members.clone(), graph) +} } - } +} } -pub fn collect_parser_edges_for_scc( - members: &Rc>, - func_index: &Rc>>, - scc_name_set: Rc>, - si: &Rc>>, -) -> Rc>> { +pub fn collect_parser_edges_for_scc(members: &Rc>, func_index: &Rc>>, scc_name_set: Rc>, si: &Rc>>) -> Rc>> { { - let all_have_state = { - let mut __all = true; - for name in members.clone().iter().cloned() { - if !(match v2_rt::map_get(&func_index, name.clone()) { - Some(entry) => (parser_state_param(entry.params.clone(), si.clone()) != None), - None => false, - }) { - __all = false; - break; - } - } - __all - }; - if (all_have_state == false) { + let all_have_state = { let mut __all = true; for name in members.clone().iter().cloned() { if !(match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => (parser_state_param(entry.params.clone(), si.clone()) != None), + None => false, +}) { __all = false; break; } } __all }; +if (all_have_state == false) { Rc::new(vec![]) } else { { - let proven = infer_parser_always_advancing_members( - &parser_function_names(&func_index, si.clone()), - &func_index, - &si, - ); - let parser_always_advancing = proven; - Rc::new({ - let mut __result = Vec::new(); - for name in members.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&func_index, name.clone()) { - Some(entry) => { - match parser_state_param(entry.params.clone(), si.clone()) { - Some(state_param) => collect_parser_progress_edges( - &name, - &entry.body.clone(), - &state_param, - &scc_name_set, - &empty_parser_progress_env(), - &parser_always_advancing, - &v2_rt::rc_empty_map::(), - &si, - ), - None => Rc::new(vec![]), - } - } - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }) - } + let proven = infer_parser_always_advancing_members(&parser_function_names(&func_index, si.clone()), &func_index, &si); +let parser_always_advancing = proven; +Rc::new({ let mut __result = Vec::new(); for name in members.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => match parser_state_param(entry.params.clone(), si.clone()) { + Some(state_param) => collect_parser_progress_edges(&name, &entry.body.clone(), &state_param, &scc_name_set, &empty_parser_progress_env(), &parser_always_advancing, &v2_rt::rc_empty_map::(), &si), + None => Rc::new(vec![]), +}, + None => Rc::new(vec![]), +}).iter().cloned()); } __result }) +} } - } +} } -pub fn classify_parser_scc_recursion_pattern( - members: &Rc>, - func_index: Rc>>, - si: Rc>>, -) -> Option> { +pub fn classify_parser_scc_recursion_pattern(members: &Rc>, func_index: Rc>>, si: Rc>>) -> Option> { { - let scc_name_set = members.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let edges = collect_parser_edges_for_scc(&members, &func_index, scc_name_set, &si); - if ((edges.clone().len() as i64) == 0) { + let scc_name_set = members.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let edges = collect_parser_edges_for_scc(&members, &func_index, scc_name_set, &si); +if ((edges.clone().len() as i64) == 0) { None } else { { - let all_known = { - let mut __all = true; - for edge in edges.clone().iter().cloned() { - if !(edge.progress.clone() != DescentEvidence::DescentUnknown) { - __all = false; - break; - } - } - __all - }; - if (all_known - && (same_progress_subgraph_has_cycle(&members, edges.clone()) == false)) - { - Some(lower_call_pattern(Rc::new( - CallPattern::ParserAdvanceCall { - witness: "parser_state".to_string(), - }, - ))) + let all_known = { let mut __all = true; for edge in edges.clone().iter().cloned() { if !((edge.progress.clone() != DescentEvidence::DescentUnknown)) { __all = false; break; } } __all }; +if (all_known && (same_progress_subgraph_has_cycle(&members, edges.clone()) == false)) { + Some(lower_call_pattern(Rc::new(CallPattern::ParserAdvanceCall { + witness: "parser_state".to_string(), +}))) } else { None } - } +} } - } +} } -pub fn count_self_calls( - body: &Rc, - func_name: &String, - si: &Rc>>, -) -> i64 { +pub fn count_self_calls(body: &Rc, func_name: &String, si: &Rc>>) -> i64 { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let own = match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { + { + let own = match (*body.expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { let f = expr_call_func_at(body.clone(), si.clone()); - if (f.as_str() == func_name.clone().as_str()) { +if (f.as_str() == func_name.clone().as_str()) { 1 } else { 0 } - } - _ => 0, - }; - let from_children = body - .children - .clone() - .iter() - .cloned() - .fold(0, |acc: i64, child: Rc| { - (acc + count_self_calls(&child, &func_name, &si)) - }); - (own + from_children) +}, + _ => 0, +}; +let from_children = body.children.clone().iter().cloned().fold(0, |acc: i64, child: Rc| (acc + count_self_calls(&child, &func_name, &si))); +(own + from_children) +} }) } -pub fn max_path_self_calls( - body: Rc, - func_name: String, - si: Rc>>, -) -> i64 { +pub fn max_path_self_calls(body: Rc, func_name: String, si: Rc>>) -> i64 { max_path_self_calls_with_cont(&body, &func_name, 0, &si) } -pub fn max_path_self_calls_with_cont( - body: &Rc, - func_name: &String, - continue_calls: i64, - si: &Rc>>, -) -> i64 { +pub fn max_path_self_calls_with_cont(body: &Rc, func_name: &String, continue_calls: i64, si: &Rc>>) -> i64 { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let f = expr_call_func_at(body.clone(), si.clone()); - let own = if (f.as_str() == func_name.clone().as_str()) { - 1 - } else { - 0 - }; - let arg_calls = - body.children - .clone() - .iter() - .cloned() - .fold(0, |acc: i64, child: Rc| { - let val = arg_value(&child); - match (*val.expr_data.clone()).clone() { - ExprData::ExprLambda => { - (acc.clone() - + max_path_self_calls_with_cont( - &lambda_body(val.clone()), - &func_name, - 0, - &si, - )) - } - _ => { - (acc.clone() - + max_path_self_calls_with_cont(&val, &func_name, 0, &si)) - } - } - }); - ((own + arg_calls) + continue_calls.clone()) - } - ExprData::ExprMatch => { - let scrut_calls = max_path_self_calls_with_cont( - &match_scrutinee(body.clone()), - &func_name, - 0, - &si, - ); - let max_arm = match_arm_nodes(body.clone()).iter().cloned().fold( - continue_calls.clone(), - |acc: i64, arm_node: Rc| { - let arm_calls = max_path_self_calls_with_cont( - &arm_body(&arm_node), - &func_name, - continue_calls.clone(), - &si, - ); - if (arm_calls.clone() > acc.clone()) { - arm_calls.clone() - } else { - acc.clone() - } - }, - ); - (scrut_calls + max_arm) - } - ExprData::ExprIf => { - let cond_calls = - max_path_self_calls_with_cont(&if_condition(body.clone()), &func_name, 0, &si); - let then_calls = max_path_self_calls_with_cont( - &if_then_branch(body.clone()), - &func_name, - continue_calls.clone(), - &si, - ); - let else_calls = match if_else_branch(body.clone()) { - Some(eb) => { - max_path_self_calls_with_cont(&eb, &func_name, continue_calls.clone(), &si) - } - None => continue_calls.clone(), - }; - let branch_max = if (then_calls.clone() > else_calls.clone()) { - then_calls.clone() + ExprData::ExprCall { .. } => { + let f = expr_call_func_at(body.clone(), si.clone()); +let own = if (f.as_str() == func_name.clone().as_str()) { + 1 + } else { + 0 + }; +let arg_calls = body.children.clone().iter().cloned().fold(0, |acc: i64, child: Rc| { + let val = arg_value(&child); +match (*val.expr_data.clone()).clone() { + ExprData::ExprLambda => (acc.clone() + max_path_self_calls_with_cont(&lambda_body(val.clone()), &func_name, 0, &si)), + _ => (acc.clone() + max_path_self_calls_with_cont(&val, &func_name, 0, &si)), +} +}); +((own + arg_calls) + continue_calls.clone()) +}, + ExprData::ExprMatch => { + let scrut_calls = max_path_self_calls_with_cont(&match_scrutinee(body.clone()), &func_name, 0, &si); +let max_arm = match_arm_nodes(body.clone()).iter().cloned().fold(continue_calls.clone(), |acc: i64, arm_node: Rc| { + let arm_calls = max_path_self_calls_with_cont(&arm_body(&arm_node), &func_name, continue_calls.clone(), &si); +if (arm_calls.clone() > acc.clone()) { + arm_calls.clone() } else { - else_calls.clone() - }; - (cond_calls + branch_max) - } - ExprData::ExprForEach => { - (max_path_self_calls_with_cont( - &foreach_collection(body.clone()), - &func_name, - 0, - &si, - ) + continue_calls.clone()) - } - ExprData::ExprLet => { - let val_calls = - max_path_self_calls_with_cont(&let_value(body.clone()), &func_name, 0, &si); - let body_calls = match let_body(body.clone()) { - Some(b) => { - max_path_self_calls_with_cont(&b, &func_name, continue_calls.clone(), &si) - } - None => continue_calls.clone(), - }; - (val_calls + body_calls) - } - ExprData::ExprBlock => v2_rt::reverse(body.children.clone()).iter().cloned().fold( - continue_calls.clone(), - |acc: i64, stmt: Rc| { - max_path_self_calls_with_cont(&stmt, &func_name, acc, &si) - }, - ), - ExprData::ExprMethodCall { .. } => { - let recv_calls = max_path_self_calls_with_cont( - &method_receiver(body.clone()), - &func_name, - 0, - &si, - ); - let arg_calls = method_arg_nodes(body.clone()).iter().cloned().fold( - 0, - |acc: i64, arg_node: Rc| { - let val = arg_value(&arg_node); - match (*val.expr_data.clone()).clone() { - ExprData::ExprLambda => { - (acc.clone() - + max_path_self_calls_with_cont( - &lambda_body(val.clone()), - &func_name, - 0, - &si, - )) - } - _ => { - (acc.clone() - + max_path_self_calls_with_cont(&val, &func_name, 0, &si)) - } - } - }, - ); - ((recv_calls + arg_calls) + continue_calls.clone()) - } - ExprData::ExprReturn => { - max_path_self_calls_with_cont(&return_value(body.clone()), &func_name, 0, &si) - } - _ => { - (body - .children - .clone() - .iter() - .cloned() - .fold(0, |acc: i64, child: Rc| { - (acc + max_path_self_calls_with_cont(&child, &func_name, 0, &si)) - }) - + continue_calls.clone()) - } - } + acc.clone() + } +}); +(scrut_calls + max_arm) +}, + ExprData::ExprIf => { + let cond_calls = max_path_self_calls_with_cont(&if_condition(body.clone()), &func_name, 0, &si); +let then_calls = max_path_self_calls_with_cont(&if_then_branch(body.clone()), &func_name, continue_calls.clone(), &si); +let else_calls = match if_else_branch(body.clone()) { + Some(eb) => max_path_self_calls_with_cont(&eb, &func_name, continue_calls.clone(), &si), + None => continue_calls.clone(), +}; +let branch_max = if (then_calls.clone() > else_calls.clone()) { + then_calls.clone() + } else { + else_calls.clone() + }; +(cond_calls + branch_max) +}, + ExprData::ExprForEach => (max_path_self_calls_with_cont(&foreach_collection(body.clone()), &func_name, 0, &si) + continue_calls.clone()), + ExprData::ExprLet => { + let val_calls = max_path_self_calls_with_cont(&let_value(body.clone()), &func_name, 0, &si); +let body_calls = match let_body(body.clone()) { + Some(b) => max_path_self_calls_with_cont(&b, &func_name, continue_calls.clone(), &si), + None => continue_calls.clone(), +}; +(val_calls + body_calls) +}, + ExprData::ExprBlock => v2_rt::reverse(body.children.clone()).iter().cloned().fold(continue_calls.clone(), |acc: i64, stmt: Rc| max_path_self_calls_with_cont(&stmt, &func_name, acc, &si)), + ExprData::ExprMethodCall { .. } => { + let recv_calls = max_path_self_calls_with_cont(&method_receiver(body.clone()), &func_name, 0, &si); +let arg_calls = method_arg_nodes(body.clone()).iter().cloned().fold(0, |acc: i64, arg_node: Rc| { + let val = arg_value(&arg_node); +match (*val.expr_data.clone()).clone() { + ExprData::ExprLambda => (acc.clone() + max_path_self_calls_with_cont(&lambda_body(val.clone()), &func_name, 0, &si)), + _ => (acc.clone() + max_path_self_calls_with_cont(&val, &func_name, 0, &si)), +} +}); +((recv_calls + arg_calls) + continue_calls.clone()) +}, + ExprData::ExprReturn => max_path_self_calls_with_cont(&return_value(body.clone()), &func_name, 0, &si), + _ => (body.children.clone().iter().cloned().fold(0, |acc: i64, child: Rc| (acc + max_path_self_calls_with_cont(&child, &func_name, 0, &si))) + continue_calls.clone()), +} }) } -pub fn max_path_self_calls_block( - stmts: Rc>>, - func_name: String, - continue_calls: i64, - si: Rc>>, -) -> i64 { - v2_rt::reverse(stmts) - .iter() - .cloned() - .fold(continue_calls.clone(), |acc: i64, stmt: Rc| { - max_path_self_calls_with_cont(&stmt, &func_name, acc, &si) - }) -} - -pub fn count_target_calls( - body: &Rc, - target_set: &Rc>, - si: &Rc>>, -) -> i64 { +pub fn max_path_self_calls_block(stmts: Rc>>, func_name: String, continue_calls: i64, si: Rc>>) -> i64 { + v2_rt::reverse(stmts).iter().cloned().fold(continue_calls.clone(), |acc: i64, stmt: Rc| max_path_self_calls_with_cont(&stmt, &func_name, acc, &si)) +} + +pub fn count_target_calls(body: &Rc, target_set: &Rc>, si: &Rc>>) -> i64 { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let own = match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { + { + let own = match (*body.expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { let f = expr_call_func_at(body.clone(), si.clone()); - if set_has(target_set.clone(), f) { +if set_has(target_set.clone(), f) { 1 } else { 0 } - } - _ => 0, - }; - let from_children = body - .children - .clone() - .iter() - .cloned() - .fold(0, |acc: i64, child: Rc| { - (acc + count_target_calls(&child, &target_set, &si)) - }); - (own + from_children) +}, + _ => 0, +}; +let from_children = body.children.clone().iter().cloned().fold(0, |acc: i64, child: Rc| (acc + count_target_calls(&child, &target_set, &si))); +(own + from_children) +} }) } -pub fn max_path_target_calls( - body: Rc, - target_set: Rc>, - si: Rc>>, -) -> i64 { +pub fn max_path_target_calls(body: Rc, target_set: Rc>, si: Rc>>) -> i64 { max_path_target_calls_with_cont(&body, &target_set, 0, &si) } -pub fn max_path_target_calls_with_cont( - body: &Rc, - target_set: &Rc>, - continue_calls: i64, - si: &Rc>>, -) -> i64 { +pub fn max_path_target_calls_with_cont(body: &Rc, target_set: &Rc>, continue_calls: i64, si: &Rc>>) -> i64 { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let f = expr_call_func_at(body.clone(), si.clone()); - let own = if set_has(target_set.clone(), f) { 1 } else { 0 }; - let arg_calls = - body.children - .clone() - .iter() - .cloned() - .fold(0, |acc: i64, child: Rc| { - (acc + max_path_target_calls_with_cont( - &arg_value(&child), - &target_set, - 0, - &si, - )) - }); - ((own + arg_calls) + continue_calls.clone()) - } - ExprData::ExprMatch => { - let scrut_calls = max_path_target_calls_with_cont( - &match_scrutinee(body.clone()), - &target_set, - 0, - &si, - ); - let max_arm = match_arm_nodes(body.clone()).iter().cloned().fold( - continue_calls.clone(), - |acc: i64, arm_node: Rc| { - let arm_calls = max_path_target_calls_with_cont( - &arm_body(&arm_node), - &target_set, - continue_calls.clone(), - &si, - ); - if (arm_calls.clone() > acc.clone()) { - arm_calls.clone() - } else { - acc.clone() - } - }, - ); - (scrut_calls + max_arm) - } - ExprData::ExprIf => { - let cond_calls = max_path_target_calls_with_cont( - &if_condition(body.clone()), - &target_set, - 0, - &si, - ); - let then_calls = max_path_target_calls_with_cont( - &if_then_branch(body.clone()), - &target_set, - continue_calls.clone(), - &si, - ); - let else_calls = match if_else_branch(body.clone()) { - Some(eb) => max_path_target_calls_with_cont( - &eb, - &target_set, - continue_calls.clone(), - &si, - ), - None => continue_calls.clone(), - }; - let branch_max = if (then_calls.clone() > else_calls.clone()) { - then_calls.clone() + ExprData::ExprCall { .. } => { + let f = expr_call_func_at(body.clone(), si.clone()); +let own = if set_has(target_set.clone(), f) { + 1 + } else { + 0 + }; +let arg_calls = body.children.clone().iter().cloned().fold(0, |acc: i64, child: Rc| (acc + max_path_target_calls_with_cont(&arg_value(&child), &target_set, 0, &si))); +((own + arg_calls) + continue_calls.clone()) +}, + ExprData::ExprMatch => { + let scrut_calls = max_path_target_calls_with_cont(&match_scrutinee(body.clone()), &target_set, 0, &si); +let max_arm = match_arm_nodes(body.clone()).iter().cloned().fold(continue_calls.clone(), |acc: i64, arm_node: Rc| { + let arm_calls = max_path_target_calls_with_cont(&arm_body(&arm_node), &target_set, continue_calls.clone(), &si); +if (arm_calls.clone() > acc.clone()) { + arm_calls.clone() } else { - else_calls.clone() - }; - (cond_calls + branch_max) - } - ExprData::ExprForEach => { - (max_path_target_calls_with_cont( - &foreach_collection(body.clone()), - &target_set, - 0, - &si, - ) + continue_calls.clone()) - } - ExprData::ExprLet => { - let val_calls = - max_path_target_calls_with_cont(&let_value(body.clone()), &target_set, 0, &si); - let body_calls = match let_body(body.clone()) { - Some(b) => max_path_target_calls_with_cont( - &b, - &target_set, - continue_calls.clone(), - &si, - ), - None => continue_calls.clone(), - }; - (val_calls + body_calls) - } - ExprData::ExprBlock => v2_rt::reverse(body.children.clone()).iter().cloned().fold( - continue_calls.clone(), - |acc: i64, stmt: Rc| { - max_path_target_calls_with_cont(&stmt, &target_set, acc, &si) - }, - ), - ExprData::ExprMethodCall { .. } => { - let recv_calls = max_path_target_calls_with_cont( - &method_receiver(body.clone()), - &target_set, - 0, - &si, - ); - let arg_calls = method_arg_nodes(body.clone()).iter().cloned().fold( - 0, - |acc: i64, arg_node: Rc| { - let val = arg_value(&arg_node); - match (*val.expr_data.clone()).clone() { - ExprData::ExprLambda => { - (acc.clone() - + max_path_target_calls_with_cont( - &lambda_body(val.clone()), - &target_set, - 0, - &si, - )) - } - _ => { - (acc.clone() - + max_path_target_calls_with_cont(&val, &target_set, 0, &si)) - } - } - }, - ); - ((recv_calls + arg_calls) + continue_calls.clone()) - } - ExprData::ExprReturn => { - max_path_target_calls_with_cont(&return_value(body.clone()), &target_set, 0, &si) - } - _ => body.children.clone().iter().cloned().fold( - continue_calls.clone(), - |acc: i64, child: Rc| { - (acc + max_path_target_calls_with_cont(&child, &target_set, 0, &si)) - }, - ), - } + acc.clone() + } +}); +(scrut_calls + max_arm) +}, + ExprData::ExprIf => { + let cond_calls = max_path_target_calls_with_cont(&if_condition(body.clone()), &target_set, 0, &si); +let then_calls = max_path_target_calls_with_cont(&if_then_branch(body.clone()), &target_set, continue_calls.clone(), &si); +let else_calls = match if_else_branch(body.clone()) { + Some(eb) => max_path_target_calls_with_cont(&eb, &target_set, continue_calls.clone(), &si), + None => continue_calls.clone(), +}; +let branch_max = if (then_calls.clone() > else_calls.clone()) { + then_calls.clone() + } else { + else_calls.clone() + }; +(cond_calls + branch_max) +}, + ExprData::ExprForEach => (max_path_target_calls_with_cont(&foreach_collection(body.clone()), &target_set, 0, &si) + continue_calls.clone()), + ExprData::ExprLet => { + let val_calls = max_path_target_calls_with_cont(&let_value(body.clone()), &target_set, 0, &si); +let body_calls = match let_body(body.clone()) { + Some(b) => max_path_target_calls_with_cont(&b, &target_set, continue_calls.clone(), &si), + None => continue_calls.clone(), +}; +(val_calls + body_calls) +}, + ExprData::ExprBlock => v2_rt::reverse(body.children.clone()).iter().cloned().fold(continue_calls.clone(), |acc: i64, stmt: Rc| max_path_target_calls_with_cont(&stmt, &target_set, acc, &si)), + ExprData::ExprMethodCall { .. } => { + let recv_calls = max_path_target_calls_with_cont(&method_receiver(body.clone()), &target_set, 0, &si); +let arg_calls = method_arg_nodes(body.clone()).iter().cloned().fold(0, |acc: i64, arg_node: Rc| { + let val = arg_value(&arg_node); +match (*val.expr_data.clone()).clone() { + ExprData::ExprLambda => (acc.clone() + max_path_target_calls_with_cont(&lambda_body(val.clone()), &target_set, 0, &si)), + _ => (acc.clone() + max_path_target_calls_with_cont(&val, &target_set, 0, &si)), +} +}); +((recv_calls + arg_calls) + continue_calls.clone()) +}, + ExprData::ExprReturn => max_path_target_calls_with_cont(&return_value(body.clone()), &target_set, 0, &si), + _ => body.children.clone().iter().cloned().fold(continue_calls.clone(), |acc: i64, child: Rc| (acc + max_path_target_calls_with_cont(&child, &target_set, 0, &si))), +} }) } -pub fn build_scc_measure_params( - members: Rc>, - func_index: Rc>>, - si: Rc>>, -) -> Rc>>> { - members.iter().cloned().fold( - v2_rt::rc_empty_map::>>(), - |acc: Rc>>>, name: String| match v2_rt::map_get( - &func_index, - name.clone(), - ) { - Some(entry) => v2_rt::rc_map_insert( - acc.clone(), - name.clone(), - recursive_measure_param_names(&entry.body.clone(), &entry.params.clone(), &si), - ), - None => acc.clone(), - }, - ) +pub fn build_scc_measure_params(members: Rc>, func_index: Rc>>, si: Rc>>) -> Rc>>> { + members.iter().cloned().fold(v2_rt::rc_empty_map::>>(), |acc: Rc>>>, name: String| match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => v2_rt::rc_map_insert(acc.clone(), name.clone(), recursive_measure_param_names(&entry.body.clone(), &entry.params.clone(), &si)), + None => acc.clone(), +}) } -pub fn target_call_has_arithmetic_descent( - call_node: &Rc, - target_set: &Rc>, - func_index: Rc>>, - scc_measure_params: Rc>>>, - si: &Rc>>, -) -> bool { +pub fn target_call_has_arithmetic_descent(call_node: &Rc, target_set: &Rc>, func_index: Rc>>, scc_measure_params: Rc>>>, si: &Rc>>) -> bool { { let callee = expr_call_func_at(call_node.clone(), si.clone()); - if (set_has(target_set.clone(), callee.clone()) == false) { +if (set_has(target_set.clone(), callee.clone()) == false) { true } else { match v2_rt::map_get(&func_index, callee.clone()) { - Some(callee_entry) => { - let callee_measure_params = - match v2_rt::map_get(&scc_measure_params, callee.clone()) { - Some(params) => params.clone(), - None => v2_rt::rc_empty_map::(), - }; - { - let mut __found = false; - for pair in Rc::new( - call_node - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if { - let arg_expr = arg_value(&pair.1.clone()); - (((max_path_target_calls( - arg_expr.clone(), - target_set.clone(), - si.clone(), - ) == 0) - && is_descending_expr(&arg_expr)) - && match recursive_param_name_for_arg( - pair.0.clone(), - pair.1.clone(), - callee_entry.params.clone(), - &si, - ) { - Some(param_name) => { - (v2_rt::map_get( - &callee_measure_params, - param_name.clone(), - ) != None) - } - None => false, - }) - } { - __found = true; - break; - } - } - __found - } - } - None => false, - } + Some(callee_entry) => { + let callee_measure_params = match v2_rt::map_get(&scc_measure_params, callee.clone()) { + Some(params) => params.clone(), + None => v2_rt::rc_empty_map::(), +}; +{ let mut __found = false; for pair in Rc::new(call_node.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if { + let arg_expr = arg_value(&pair.1.clone()); +(((max_path_target_calls(arg_expr.clone(), target_set.clone(), si.clone()) == 0) && is_descending_expr(&arg_expr)) && match recursive_param_name_for_arg(pair.0.clone(), pair.1.clone(), callee_entry.params.clone(), &si) { + Some(param_name) => (v2_rt::map_get(&callee_measure_params, param_name.clone()) != None), + None => false, +}) +} { __found = true; break; } } __found } +}, + None => false, +} } - } +} } -pub fn scc_calls_have_arithmetic_descent( - body: &Rc, - target_set: &Rc>, - func_index: &Rc>>, - scc_measure_params: &Rc>>>, - si: &Rc>>, -) -> bool { +pub fn scc_calls_have_arithmetic_descent(body: &Rc, target_set: &Rc>, func_index: &Rc>>, scc_measure_params: &Rc>>>, si: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - (target_call_has_arithmetic_descent( - &body, - &target_set, - func_index.clone(), - scc_measure_params.clone(), - &si, - ) && { - let mut __all = true; - for child in body.children.clone().iter().cloned() { - if !(scc_calls_have_arithmetic_descent( - &child, - &target_set, - &func_index, - &scc_measure_params, - &si, - )) { - __all = false; - break; - } - } - __all - }) - } - _ => { - let mut __all = true; - for child in body.children.clone().iter().cloned() { - if !(scc_calls_have_arithmetic_descent( - &child, - &target_set, - &func_index, - &scc_measure_params, - &si, - )) { - __all = false; - break; - } - } - __all - } - } + ExprData::ExprCall { .. } => (target_call_has_arithmetic_descent(&body, &target_set, func_index.clone(), scc_measure_params.clone(), &si) && { let mut __all = true; for child in body.children.clone().iter().cloned() { if !(scc_calls_have_arithmetic_descent(&child, &target_set, &func_index, &scc_measure_params, &si)) { __all = false; break; } } __all }), + _ => { let mut __all = true; for child in body.children.clone().iter().cloned() { if !(scc_calls_have_arithmetic_descent(&child, &target_set, &func_index, &scc_measure_params, &si)) { __all = false; break; } } __all }, +} }) } -pub fn descending_name_set_without_key( - names: &Rc>, - key: String, -) -> Rc> { - Rc::new(v2_rt::map_keys(&names)).iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - if (name.clone().as_str() == key.clone().as_str()) { - acc.clone() - } else { - match v2_rt::map_get(&names, name.clone()) { - Some(source) => v2_rt::rc_map_insert(acc.clone(), name.clone(), source.clone()), - None => acc.clone(), - } - } - }, - ) +pub fn descending_name_set_without_key(names: &Rc>, key: String) -> Rc> { + Rc::new(v2_rt::map_keys(&names)).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| if (name.clone().as_str() == key.clone().as_str()) { + acc.clone() + } else { + match v2_rt::map_get(&names, name.clone()) { + Some(source) => v2_rt::rc_map_insert(acc.clone(), name.clone(), source.clone()), + None => acc.clone(), +} + }) } -pub fn expr_descending_witness_source( - mut expr: Rc, - mut descending_witness_names: Rc>, - mut si: Rc>>, -) -> Option { +pub fn expr_descending_witness_source(mut expr: Rc, mut descending_witness_names: Rc>, mut si: Rc>>) -> Option { loop { match (*expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - break v2_rt::map_get( - &descending_witness_names, - expr_var_name_at(expr.clone(), si), - ); - } - ExprData::ExprBinOp { op, .. } => match op.clone() { - BinOp::Sub => { - let __tco_0 = binop_left(expr); - expr = __tco_0; - continue; - } - BinOp::Div => { - let __tco_0 = binop_left(expr); - expr = __tco_0; - continue; - } - _ => { - break None; - } - }, - _ => { - break None; - } - } - } -} - -pub fn condition_param_names( - expr: &Rc, - param_set: Rc>, - si: Rc>>, -) -> Rc> { + ExprData::ExprVar { .. } => { break v2_rt::map_get(&descending_witness_names, expr_var_name_at(expr.clone(), si)); }, + ExprData::ExprBinOp { op, .. } => { match op.clone() { + BinOp::Sub => { { + let __tco_0 = binop_left(expr); +expr = __tco_0; +continue; +} }, + BinOp::Div => { { + let __tco_0 = binop_left(expr); +expr = __tco_0; +continue; +} }, + _ => { break None; }, +} }, + _ => { break None; }, +} +} +} + +pub fn condition_param_names(expr: &Rc, param_set: Rc>, si: Rc>>) -> Rc> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let name = expr_var_name_at(expr.clone(), si.clone()); - match v2_rt::map_get(¶m_set, name.clone()) { - Some(_) => seed_string_map(name.clone(), name.clone()), - None => v2_rt::rc_empty_map::(), - } - } - _ => expr.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, child: Rc| { - v2_rt::rc_map_merge( - acc, - condition_param_names(&child, param_set.clone(), si.clone()), - ) - }, - ), - } + ExprData::ExprVar { .. } => { + let name = expr_var_name_at(expr.clone(), si.clone()); +match v2_rt::map_get(¶m_set, name.clone()) { + Some(_) => seed_string_map(name.clone(), name.clone()), + None => v2_rt::rc_empty_map::(), +} +}, + _ => expr.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, child: Rc| v2_rt::rc_map_merge(acc, condition_param_names(&child, param_set.clone(), si.clone()))), +} }) } -pub fn recursive_measure_param_names( - body: &Rc, - params: &Rc>>, - si: &Rc>>, -) -> Rc> { +pub fn recursive_measure_param_names(body: &Rc, params: &Rc>>, si: &Rc>>) -> Rc> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let param_set = params.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, param: Rc| { - v2_rt::rc_map_insert( - acc, - param_node_name_at(param.clone(), si.clone()), - param_node_name_at(param.clone(), si.clone()), - ) - }, - ); - match (*body.expr_data.clone()).clone() { - ExprData::ExprIf => { - let then_names = - recursive_measure_param_names(&if_then_branch(body.clone()), ¶ms, &si); - let else_names = match if_else_branch(body.clone()) { - Some(eb) => recursive_measure_param_names(&eb, ¶ms, &si), - None => v2_rt::rc_empty_map::(), - }; - v2_rt::rc_map_merge( - v2_rt::rc_map_merge( - condition_param_names(&if_condition(body.clone()), param_set, si.clone()), - then_names, - ), - else_names, - ) - } - ExprData::ExprMatch => { - let scrut_names = - condition_param_names(&match_scrutinee(body.clone()), param_set, si.clone()); - let arm_names = match_arm_nodes(body.clone()).iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, arm_node: Rc| { - v2_rt::rc_map_merge( - acc, - recursive_measure_param_names(&arm_body(&arm_node), ¶ms, &si), - ) - }, - ); - v2_rt::rc_map_merge(scrut_names, arm_names) - } - ExprData::ExprLet => match let_body(body.clone()) { - Some(b) => recursive_measure_param_names(&b, ¶ms, &si), - None => v2_rt::rc_empty_map::(), - }, - ExprData::ExprBlock => body.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, stmt: Rc| { - v2_rt::rc_map_merge(acc, recursive_measure_param_names(&stmt, ¶ms, &si)) - }, - ), - _ => body.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, child: Rc| { - v2_rt::rc_map_merge(acc, recursive_measure_param_names(&child, ¶ms, &si)) - }, - ), - } + { + let param_set = params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, param: Rc| v2_rt::rc_map_insert(acc, param_node_name_at(param.clone(), si.clone()), param_node_name_at(param.clone(), si.clone()))); +match (*body.expr_data.clone()).clone() { + ExprData::ExprIf => { + let then_names = recursive_measure_param_names(&if_then_branch(body.clone()), ¶ms, &si); +let else_names = match if_else_branch(body.clone()) { + Some(eb) => recursive_measure_param_names(&eb, ¶ms, &si), + None => v2_rt::rc_empty_map::(), +}; +v2_rt::rc_map_merge(v2_rt::rc_map_merge(condition_param_names(&if_condition(body.clone()), param_set, si.clone()), then_names), else_names) +}, + ExprData::ExprMatch => { + let scrut_names = condition_param_names(&match_scrutinee(body.clone()), param_set, si.clone()); +let arm_names = match_arm_nodes(body.clone()).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, arm_node: Rc| v2_rt::rc_map_merge(acc, recursive_measure_param_names(&arm_body(&arm_node), ¶ms, &si))); +v2_rt::rc_map_merge(scrut_names, arm_names) +}, + ExprData::ExprLet => match let_body(body.clone()) { + Some(b) => recursive_measure_param_names(&b, ¶ms, &si), + None => v2_rt::rc_empty_map::(), +}, + ExprData::ExprBlock => body.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, stmt: Rc| v2_rt::rc_map_merge(acc, recursive_measure_param_names(&stmt, ¶ms, &si))), + _ => body.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, child: Rc| v2_rt::rc_map_merge(acc, recursive_measure_param_names(&child, ¶ms, &si))), +} +} }) } -pub fn recursive_param_name_for_arg( - idx: i64, - arg_node: Rc, - params: Rc>>, - si: &Rc>>, -) -> Option { +pub fn recursive_param_name_for_arg(idx: i64, arg_node: Rc, params: Rc>>, si: &Rc>>) -> Option { match arg_name_at(arg_node, si.clone()) { - Some(name) => Some(name.clone()), - None => Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - params - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (pair.0.clone() == idx.clone()) { - __result.push(pair); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(param_node_name_at(pair.1.clone(), si.clone())); - } - __result - }) - .first() - .cloned(), - } + Some(name) => Some(name.clone()), + None => Rc::new({ let mut __result = Vec::new(); for pair in Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(params.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (pair.0.clone() == idx.clone()) { __result.push(pair); } } __result }).iter().cloned() { __result.push(param_node_name_at(pair.1.clone(), si.clone())); } __result }).first().cloned(), +} } pub fn is_descending_expr(expr: &Rc) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprBinOp { op, .. } => match op.clone() { - BinOp::Sub => match (*binop_left(expr.clone()).expr_data.clone()).clone() { - ExprData::ExprVar { .. } => true, - _ => false, - }, - BinOp::Div => match (*binop_left(expr.clone()).expr_data.clone()).clone() { - ExprData::ExprVar { .. } => true, - _ => false, - }, - _ => false, - }, - _ => false, - } + ExprData::ExprBinOp { op, .. } => match op.clone() { + BinOp::Sub => match (*binop_left(expr.clone()).expr_data.clone()).clone() { + ExprData::ExprVar { .. } => true, + _ => false, +}, + BinOp::Div => match (*binop_left(expr.clone()).expr_data.clone()).clone() { + ExprData::ExprVar { .. } => true, + _ => false, +}, + _ => false, +}, + _ => false, +} } -pub fn has_arithmetic_descent( - body: &Rc, - func_name: &String, - si: &Rc>>, -) -> bool { +pub fn has_arithmetic_descent(body: &Rc, func_name: &String, si: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let own_ok = if (expr_call_func_at(body.clone(), si.clone()).as_str() - == func_name.clone().as_str()) - { - { - let mut __found = false; - for arg_node in body.children.clone().iter().cloned() { - if is_descending_expr(&arg_value(&arg_node)) { - __found = true; - break; - } - } - __found - } - } else { - false - }; - if own_ok { - true - } else { - { - let mut __found = false; - for c in body.children.clone().iter().cloned() { - if has_arithmetic_descent(&c, &func_name, &si) { - __found = true; - break; - } - } - __found - } - } - } - _ => { - let mut __found = false; - for c in body.children.clone().iter().cloned() { - if has_arithmetic_descent(&c, &func_name, &si) { - __found = true; - break; - } - } - __found + ExprData::ExprCall { .. } => { + let own_ok = if (expr_call_func_at(body.clone(), si.clone()).as_str() == func_name.clone().as_str()) { + { let mut __found = false; for arg_node in body.children.clone().iter().cloned() { if is_descending_expr(&arg_value(&arg_node)) { __found = true; break; } } __found } + } else { + false + }; +if own_ok { + true + } else { + { let mut __found = false; for c in body.children.clone().iter().cloned() { if has_arithmetic_descent(&c, &func_name, &si) { __found = true; break; } } __found } } - } +}, + _ => { let mut __found = false; for c in body.children.clone().iter().cloned() { if has_arithmetic_descent(&c, &func_name, &si) { __found = true; break; } } __found }, +} }) } -pub fn is_accessor_of_param( - expr: &Rc, - param_name: String, - vars: Rc>, - si: &Rc>>, -) -> bool { +pub fn is_accessor_of_param(expr: &Rc, param_name: String, vars: Rc>, si: &Rc>>) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let callee = expr_call_func_at(expr.clone(), si.clone()); - (is_child_accessor_in_model(callee) && { - let mut __found = false; - for arg_node in expr.children.clone().iter().cloned() { - if match (*arg_value(&arg_node).expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at(arg_value(&arg_node), si.clone()); - ((vname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars.clone(), vname.clone())) - } - _ => false, - } { - __found = true; - break; - } - } - __found - }) - } - _ => false, - } + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(expr.clone(), si.clone()); +(is_child_accessor_in_model(callee) && { let mut __found = false; for arg_node in expr.children.clone().iter().cloned() { if match (*arg_value(&arg_node).expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(arg_value(&arg_node), si.clone()); +((vname.clone().as_str() == param_name.clone().as_str()) || set_has(vars.clone(), vname.clone())) +}, + _ => false, +} { __found = true; break; } } __found }) +}, + _ => false, +} } -pub fn is_children_of_param( - mut expr: Rc, - mut param_name: String, - mut vars: Rc>, - mut si: Rc>>, -) -> bool { +pub fn is_children_of_param(mut expr: Rc, mut param_name: String, mut vars: Rc>, mut si: Rc>>) -> bool { loop { match (*expr.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(expr.clone()); - let field = field_access_field_at(expr.clone(), si.clone()); - break (is_children_list_field(field) - && match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(base.clone(), si.clone()).as_str() - == param_name.as_str()) - } - _ => false, - }); - } - ExprData::ExprVar { .. } => { - break set_has(vars, expr_var_name_at(expr.clone(), si.clone())); - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => match method_size_effect(ms.clone()) { - Some(CollectionSizeEffect::ShrinkEffect) => { - let __tco_0 = method_receiver(expr); - expr = __tco_0; - continue; - } - _ => { - break false; - } - }, - _ => { - break false; - } - } - } + ExprData::ExprFieldAccess { .. } => { let base = field_access_base(expr.clone()); +let field = field_access_field_at(expr.clone(), si.clone()); +break (is_children_list_field(field) && match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(base.clone(), si.clone()).as_str() == param_name.as_str()), + _ => false, +}); }, + ExprData::ExprVar { .. } => { break set_has(vars, expr_var_name_at(expr.clone(), si.clone())); }, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { match method_size_effect(ms.clone()) { + Some(CollectionSizeEffect::ShrinkEffect) => { { + let __tco_0 = method_receiver(expr); +expr = __tco_0; +continue; +} }, + _ => { break false; }, +} }, + _ => { break false; }, +} +} } -pub fn is_structural_children( - expr: &Rc, - param_name: &String, - vars: &Rc>, - si: &Rc>>, -) -> bool { +pub fn is_structural_children(expr: &Rc, param_name: &String, vars: &Rc>, si: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - (is_children_of_param(expr.clone(), param_name.clone(), vars.clone(), si.clone()) - || match (*expr.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(expr.clone()); - let field = field_access_field_at(expr.clone(), si.clone()); - (is_children_list_field(field) - && match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(base.clone(), si.clone())) - } - _ => false, - }) - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => match method_size_effect(ms.clone()) { - Some(CollectionSizeEffect::ShrinkEffect) => is_structural_children( - &method_receiver(expr.clone()), - ¶m_name, - &vars, - &si, - ), - Some(CollectionSizeEffect::IdentityEffect) => is_structural_children( - &method_receiver(expr.clone()), - ¶m_name, - &vars, - &si, - ), - _ => false, - }, - _ => false, - }) + (is_children_of_param(expr.clone(), param_name.clone(), vars.clone(), si.clone()) || match (*expr.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(expr.clone()); +let field = field_access_field_at(expr.clone(), si.clone()); +(is_children_list_field(field) && match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(base.clone(), si.clone())), + _ => false, +}) +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => match method_size_effect(ms.clone()) { + Some(CollectionSizeEffect::ShrinkEffect) => is_structural_children(&method_receiver(expr.clone()), ¶m_name, &vars, &si), + Some(CollectionSizeEffect::IdentityEffect) => is_structural_children(&method_receiver(expr.clone()), ¶m_name, &vars, &si), + _ => false, +}, + _ => false, +}) }) } -pub fn is_child_descent_expr( - expr: &Rc, - param_name: &String, - vars: &Rc>, - si: &Rc>>, -) -> bool { +pub fn is_child_descent_expr(expr: &Rc, param_name: &String, vars: &Rc>, si: &Rc>>) -> bool { if is_accessor_of_param(&expr, param_name.clone(), vars.clone(), &si) { true } else { match (*expr.expr_data.clone()).clone() { - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => match method_size_effect(ms.clone()) { - Some(CollectionSizeEffect::ProjectionEffect) => is_children_of_param( - method_receiver(expr.clone()), - param_name.clone(), - vars.clone(), - si.clone(), - ), - _ => false, - }, - _ => false, - } + ExprData::ExprMethodCall { method_semantics: ms, .. } => match method_size_effect(ms.clone()) { + Some(CollectionSizeEffect::ProjectionEffect) => is_children_of_param(method_receiver(expr.clone()), param_name.clone(), vars.clone(), si.clone()), + _ => false, +}, + _ => false, +} } } -pub fn is_tree_size_preserving_wrapper( - expr: &Rc, - si: Rc>>, -) -> bool { +pub fn is_tree_size_preserving_wrapper(expr: &Rc, si: Rc>>) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let callee = expr_call_func_at(expr.clone(), si); - is_tree_size_preserving(callee) - } - _ => false, - } + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(expr.clone(), si); +is_tree_size_preserving(callee) +}, + _ => false, +} } pub fn wrapper_inner_arg(expr: Rc) -> Rc { match expr.children.clone().first().cloned() { - Some(arg_node) => arg_value(&arg_node), - None => expr.clone(), - } + Some(arg_node) => arg_value(&arg_node), + None => expr.clone(), +} } pub fn is_sub_value_extractor(expr: &Rc, si: Rc>>) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let callee = expr_call_func_at(expr.clone(), si); - is_tree_size_reducing(callee) - } - _ => false, - } + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(expr.clone(), si); +is_tree_size_reducing(callee) +}, + _ => false, +} } pub fn extractor_inner_arg(expr: Rc) -> Rc { match expr.children.clone().first().cloned() { - Some(arg_node) => arg_value(&arg_node), - None => expr.clone(), - } + Some(arg_node) => arg_value(&arg_node), + None => expr.clone(), +} } -pub fn is_list_shrink_expr( - expr: &Rc, - param_name: String, - si: Rc>>, -) -> bool { +pub fn is_list_shrink_expr(expr: &Rc, param_name: String, si: Rc>>) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let is_shrink = match method_size_effect(ms.clone()) { - Some(CollectionSizeEffect::ShrinkEffect) => true, - _ => false, - }; - ((is_shrink - && match (*method_receiver(expr.clone()).expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(method_receiver(expr.clone()), si).as_str() - == param_name.as_str()) - } - _ => false, - }) - && match method_arg_nodes(expr.clone()).first().cloned() { - Some(arg_node) => match (*arg_value(&arg_node).expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: n, .. } = value.as_ref() else { - unreachable!() - }; - (n.clone() > 0) - } - _ => false, - }, - None => false, - }) - } - _ => false, - } + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let is_shrink = match method_size_effect(ms.clone()) { + Some(CollectionSizeEffect::ShrinkEffect) => true, + _ => false, +}; +((is_shrink && match (*method_receiver(expr.clone()).expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(method_receiver(expr.clone()), si).as_str() == param_name.as_str()), + _ => false, +}) && match method_arg_nodes(expr.clone()).first().cloned() { + Some(arg_node) => match (*arg_value(&arg_node).expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: n, .. } = value.as_ref() else { unreachable!() }; (n.clone() > 0) }, + _ => false, +}, + None => false, +}) +}, + _ => false, +} } pub fn is_generalized_shrink(expr: &Rc, si: Rc>>) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let is_shrink = match method_size_effect(ms.clone()) { - Some(CollectionSizeEffect::ShrinkEffect) => true, - _ => false, - }; - (is_shrink - && match method_arg_nodes(expr.clone()).first().cloned() { - Some(arg_node) => match (*arg_value(&arg_node).expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: n, .. } = value.as_ref() else { - unreachable!() - }; - (n.clone() > 0) - } - _ => false, - }, - None => false, - }) - } - _ => false, - } + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let is_shrink = match method_size_effect(ms.clone()) { + Some(CollectionSizeEffect::ShrinkEffect) => true, + _ => false, +}; +(is_shrink && match method_arg_nodes(expr.clone()).first().cloned() { + Some(arg_node) => match (*arg_value(&arg_node).expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: n, .. } = value.as_ref() else { unreachable!() }; (n.clone() > 0) }, + _ => false, +}, + None => false, +}) +}, + _ => false, +} } -pub fn list_passthrough_inner( - expr: Rc, - si: Rc>>, -) -> Option> { +pub fn list_passthrough_inner(expr: Rc, si: Rc>>) -> Option> { parser_passthrough_state_expr(&expr, &si) } @@ -2795,2789 +1384,1370 @@ pub fn is_list_passthrough_call(expr: Rc, si: Rc, - si: Rc>>, -) -> Option> { +pub fn list_passthrough_inner_arg(expr: Rc, si: Rc>>) -> Option> { list_passthrough_inner(expr, si) } -pub fn is_tokens_consuming_call( - expr: &Rc, - param_name: String, - vars: Rc>, - si: &Rc>>, -) -> bool { +pub fn is_tokens_consuming_call(expr: &Rc, param_name: String, vars: Rc>, si: &Rc>>) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => match consuming_tokens_arg(expr.clone(), si.clone()) { - Some(tokens_arg) => { - is_tokens_input_expr(tokens_arg.clone(), param_name, vars, si.clone()) - } - None => false, - }, - _ => false, - } + ExprData::ExprCall { .. } => match consuming_tokens_arg(expr.clone(), si.clone()) { + Some(tokens_arg) => is_tokens_input_expr(tokens_arg.clone(), param_name, vars, si.clone()), + None => false, +}, + _ => false, +} } -pub fn consuming_tokens_arg( - expr: Rc, - si: Rc>>, -) -> Option> { - expr.children - .clone() - .iter() - .cloned() - .fold(None, |acc: _, child: Rc| match acc.clone() { - Some(_) => acc.clone(), - None => match arg_name_at(child.clone(), si.clone()) { - Some(name) => { - if (name.clone().as_str() == "tokens".to_string().as_str()) { - Some(arg_value(&child)) - } else { - None - } - } - None => None, - }, - }) +pub fn consuming_tokens_arg(expr: Rc, si: Rc>>) -> Option> { + expr.children.clone().iter().cloned().fold(None, |acc: _, child: Rc| match acc.clone() { + Some(_) => acc.clone(), + None => match arg_name_at(child.clone(), si.clone()) { + Some(name) => if (name.clone().as_str() == "tokens".to_string().as_str()) { + Some(arg_value(&child)) + } else { + None + }, + None => None, +}, +}) } -pub fn is_tokens_input_expr( - mut expr: Rc, - mut param_name: String, - mut vars: Rc>, - mut si: Rc>>, -) -> bool { +pub fn is_tokens_input_expr(mut expr: Rc, mut param_name: String, mut vars: Rc>, mut si: Rc>>) -> bool { loop { match (*expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at(expr.clone(), si.clone()); - break ((vname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars, vname.clone())); - } - ExprData::ExprFieldAccess { .. } => { - let field = field_access_field_at(expr.clone(), si.clone()); - if (field.as_str() == param_name.clone().as_str()) { - break true; - } else { - let base = field_access_base(expr.clone()); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at(base.clone(), si.clone()); - break ((bname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars, bname.clone())); - } - _ => { - break false; - } - } - } - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => match method_size_effect(ms.clone()) { - Some(CollectionSizeEffect::ShrinkEffect) => { - let __tco_0 = method_receiver(expr); - expr = __tco_0; - continue; - } - _ => { - break false; - } - }, - ExprData::ExprCall { .. } => { - if is_list_passthrough_call(expr.clone(), si.clone()) { - match list_passthrough_inner_arg(expr.clone(), si.clone()) { - Some(inner) => { - let __tco_0 = inner.clone(); - expr = __tco_0; - continue; - } - None => { - break false; - } - } - } else { - match consuming_tokens_arg(expr.clone(), si.clone()) { - Some(tokens_arg) => { - let __tco_0 = tokens_arg.clone(); - expr = __tco_0; - continue; - } - None => { - break false; - } - } - } - } - _ => { - break false; - } - } - } -} - -pub fn is_descent_arg( - expr: &Rc, - param_name: &String, - descent_vars: Rc>, - check_child: bool, - check_list: bool, - si: &Rc>>, -) -> bool { + ExprData::ExprVar { .. } => { let vname = expr_var_name_at(expr.clone(), si.clone()); +break ((vname.clone().as_str() == param_name.clone().as_str()) || set_has(vars, vname.clone())); }, + ExprData::ExprFieldAccess { .. } => { let field = field_access_field_at(expr.clone(), si.clone()); +if (field.as_str() == param_name.clone().as_str()) { + break true; +} else { + let base = field_access_base(expr.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { let bname = expr_var_name_at(base.clone(), si.clone()); +break ((bname.clone().as_str() == param_name.clone().as_str()) || set_has(vars, bname.clone())); }, + _ => { break false; }, +} +} }, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { match method_size_effect(ms.clone()) { + Some(CollectionSizeEffect::ShrinkEffect) => { { + let __tco_0 = method_receiver(expr); +expr = __tco_0; +continue; +} }, + _ => { break false; }, +} }, + ExprData::ExprCall { .. } => { if is_list_passthrough_call(expr.clone(), si.clone()) { + match list_passthrough_inner_arg(expr.clone(), si.clone()) { + Some(inner) => { { + let __tco_0 = inner.clone(); +expr = __tco_0; +continue; +} }, + None => { break false; }, +} +} else { + match consuming_tokens_arg(expr.clone(), si.clone()) { + Some(tokens_arg) => { { + let __tco_0 = tokens_arg.clone(); +expr = __tco_0; +continue; +} }, + None => { break false; }, +} +} }, + _ => { break false; }, +} +} +} + +pub fn is_descent_arg(expr: &Rc, param_name: &String, descent_vars: Rc>, check_child: bool, check_list: bool, si: &Rc>>) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at(expr.clone(), si.clone()); - set_has(descent_vars, vname) - } - _ => { - ((check_child && is_child_descent_expr(&expr, ¶m_name, &descent_vars, &si)) - || (check_list && is_list_shrink_expr(&expr, param_name.clone(), si.clone()))) - } - } + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(expr.clone(), si.clone()); +set_has(descent_vars, vname) +}, + _ => ((check_child && is_child_descent_expr(&expr, ¶m_name, &descent_vars, &si)) || (check_list && is_list_shrink_expr(&expr, param_name.clone(), si.clone()))), +} } -pub fn expr_contains_descent( - expr: &Rc, - param_name: &String, - vars: &Rc>, - check_child: bool, - check_list: bool, - si: &Rc>>, -) -> bool { +pub fn expr_contains_descent(expr: &Rc, param_name: &String, vars: &Rc>, check_child: bool, check_list: bool, si: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - if ((check_child.clone() && is_child_descent_expr(&expr, ¶m_name, &vars, &si)) - || (check_list.clone() && is_list_shrink_expr(&expr, param_name.clone(), si.clone()))) - { + if ((check_child.clone() && is_child_descent_expr(&expr, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&expr, param_name.clone(), si.clone()))) { true } else { match (*expr.expr_data.clone()).clone() { - ExprData::ExprIf => { - (expr_contains_descent( - &if_then_branch(expr.clone()), - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ) && match if_else_branch(expr.clone()) { - Some(eb) => expr_contains_descent( - &eb, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => false, - }) - } - ExprData::ExprBlock => match expr.children.clone().last().cloned() { - Some(last_stmt) => expr_contains_descent( - &last_stmt, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => false, - }, - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(expr.clone(), si.clone())) - } - ExprData::ExprFieldAccess { .. } => { - let field = field_access_field_at(expr.clone(), si.clone()); - let base = field_access_base(expr.clone()); - (is_sub_value_field(field) - && match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at(base.clone(), si.clone()); - ((bname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars.clone(), bname.clone())) - } - _ => false, - }) - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let receiver = method_receiver(expr.clone()); - match method_size_effect(ms.clone()) { - Some(CollectionSizeEffect::ShrinkEffect) => expr_contains_descent( - &receiver, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - Some(CollectionSizeEffect::ProjectionEffect) => expr_contains_descent( - &receiver, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - Some(CollectionSizeEffect::IdentityEffect) => expr_contains_descent( - &receiver, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => false, - } - } - _ => false, - } + ExprData::ExprIf => (expr_contains_descent(&if_then_branch(expr.clone()), ¶m_name, &vars, check_child.clone(), check_list.clone(), &si) && match if_else_branch(expr.clone()) { + Some(eb) => expr_contains_descent(&eb, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), + None => false, +}), + ExprData::ExprBlock => match expr.children.clone().last().cloned() { + Some(last_stmt) => expr_contains_descent(&last_stmt, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), + None => false, +}, + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(expr.clone(), si.clone())), + ExprData::ExprFieldAccess { .. } => { + let field = field_access_field_at(expr.clone(), si.clone()); +let base = field_access_base(expr.clone()); +(is_sub_value_field(field) && match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), si.clone()); +((bname.clone().as_str() == param_name.clone().as_str()) || set_has(vars.clone(), bname.clone())) +}, + _ => false, +}) +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let receiver = method_receiver(expr.clone()); +match method_size_effect(ms.clone()) { + Some(CollectionSizeEffect::ShrinkEffect) => expr_contains_descent(&receiver, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), + Some(CollectionSizeEffect::ProjectionEffect) => expr_contains_descent(&receiver, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), + Some(CollectionSizeEffect::IdentityEffect) => expr_contains_descent(&receiver, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), + None => false, +} +}, + _ => false, +} } }) } -pub fn collect_field_binding_names( - fb: Rc, - vars: Rc>, -) -> Rc> { - stacker::maybe_grow( - 512 * 1024, - 2 * 1024 * 1024, - || match (*field_binding_pattern(fb)).clone() { - MatchPattern::Bind { - name: binding_name, .. - } => v2_rt::rc_map_insert(vars, binding_name.clone(), true), - MatchPattern::VariantPattern { - field_bindings: nested, - .. - } => nested.clone().iter().cloned().fold( - vars, - |inner: Rc>, nested_fb: Rc| { - collect_field_binding_names(nested_fb.clone(), inner) - }, - ), - _ => vars, - }, - ) +pub fn collect_field_binding_names(fb: Rc, vars: Rc>) -> Rc> { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*field_binding_pattern(fb)).clone() { + MatchPattern::Bind { name: binding_name, .. } => v2_rt::rc_map_insert(vars, binding_name.clone(), true), + MatchPattern::VariantPattern { field_bindings: nested, .. } => nested.clone().iter().cloned().fold(vars, |inner: Rc>, nested_fb: Rc| collect_field_binding_names(nested_fb.clone(), inner)), + _ => vars, +} + }) } -pub fn is_if_option_descent( - val: &Rc, - param_name: String, - vars: Rc>, - check_child: bool, - check_list: bool, - si: &Rc>>, -) -> bool { +pub fn is_if_option_descent(val: &Rc, param_name: String, vars: Rc>, check_child: bool, check_list: bool, si: &Rc>>) -> bool { match (*val.expr_data.clone()).clone() { - ExprData::ExprIf => { - let then_branch = if_then_branch(val.clone()); - let then_has_descent = expr_contains_descent( - &then_branch, - ¶m_name, - &vars, - check_child, - check_list, - &si, - ); - let else_is_none = match if_else_branch(val.clone()) { - Some(eb) => match (*eb.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(eb.clone(), si.clone()).as_str() - == "none".to_string().as_str()) - } - ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitNull => true, - _ => false, - }, - _ => false, - }, - None => true, - }; - (then_has_descent && else_is_none) - } - _ => false, - } + ExprData::ExprIf => { + let then_branch = if_then_branch(val.clone()); +let then_has_descent = expr_contains_descent(&then_branch, ¶m_name, &vars, check_child, check_list, &si); +let else_is_none = match if_else_branch(val.clone()) { + Some(eb) => match (*eb.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(eb.clone(), si.clone()).as_str() == "none".to_string().as_str()), + ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitNull => true, + _ => false, +}, + _ => false, +}, + None => true, +}; +(then_has_descent && else_is_none) +}, + _ => false, +} } -pub fn is_match_option_descent( - val: &Rc, - param_name: &String, - vars: Rc>, - check_child: bool, - check_list: bool, - si: &Rc>>, -) -> bool { +pub fn is_match_option_descent(val: &Rc, param_name: &String, vars: Rc>, check_child: bool, check_list: bool, si: &Rc>>) -> bool { match (*val.expr_data.clone()).clone() { - ExprData::ExprMatch => { - let scrut = match_scrutinee(val.clone()); - let scrut_has_descent = - expr_contains_descent(&scrut, ¶m_name, &vars, check_child, check_list, &si); - if scrut_has_descent { - { - let has_extraction = { - let mut __found = false; - for arm_node in match_arm_nodes(val.clone()).iter().cloned() { - if match (*arm_pattern(arm_node.clone())).clone() { - MatchPattern::VariantPattern { - field_bindings: bindings, - .. - } => { - let binding_names = bindings.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, fb: Rc| { - collect_field_binding_names(fb.clone(), acc) - }, - ); - let arm_b = arm_body(&arm_node); - match (*arm_b.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => set_has( - binding_names.clone(), - expr_var_name_at(arm_b.clone(), si.clone()), - ), - _ => false, - } - } - _ => false, - } { - __found = true; - break; - } - } - __found - }; - let all_safe = { - let mut __all = true; - for arm_node in match_arm_nodes(val.clone()).iter().cloned() { - if !({ - let arm_b = arm_body(&arm_node); - match (*arm_b.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(arm_b.clone(), si.clone()).as_str() - != param_name.clone().as_str()) - } - _ => true, - } - }) { - __all = false; - break; - } - } - __all - }; - (has_extraction && all_safe) - } - } else { - false - } + ExprData::ExprMatch => { + let scrut = match_scrutinee(val.clone()); +let scrut_has_descent = expr_contains_descent(&scrut, ¶m_name, &vars, check_child, check_list, &si); +if scrut_has_descent { + { + let has_extraction = { let mut __found = false; for arm_node in match_arm_nodes(val.clone()).iter().cloned() { if match (*arm_pattern(arm_node.clone())).clone() { + MatchPattern::VariantPattern { field_bindings: bindings, .. } => { + let binding_names = bindings.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, fb: Rc| collect_field_binding_names(fb.clone(), acc)); +let arm_b = arm_body(&arm_node); +match (*arm_b.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(binding_names.clone(), expr_var_name_at(arm_b.clone(), si.clone())), + _ => false, +} +}, + _ => false, +} { __found = true; break; } } __found }; +let all_safe = { let mut __all = true; for arm_node in match_arm_nodes(val.clone()).iter().cloned() { if !({ + let arm_b = arm_body(&arm_node); +match (*arm_b.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(arm_b.clone(), si.clone()).as_str() != param_name.clone().as_str()), + _ => true, +} +}) { __all = false; break; } } __all }; +(has_extraction && all_safe) +} + } else { + false } - _ => false, - } +}, + _ => false, +} } -pub fn collect_descent_vars( - body: &Rc, - param_name: &String, - vars: &Rc>, - check_child: bool, - check_list: bool, - si: &Rc>>, -) -> Rc> { +pub fn collect_descent_vars(body: &Rc, param_name: &String, vars: &Rc>, check_child: bool, check_list: bool, si: &Rc>>) -> Rc> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprLet => { - let val = let_value(body.clone()); - let is_direct_descent = ((check_child.clone() - && is_child_descent_expr(&val, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&val, param_name.clone(), si.clone()))); - let is_descent_var = match (*val.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(val.clone(), si.clone())) - } - _ => false, - }; - let is_option_descent = is_if_option_descent( - &val, - param_name.clone(), - vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - let is_match_descent = is_match_option_descent( - &val, - ¶m_name, - vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - let is_wrapped_descent = if is_tree_size_preserving_wrapper(&val, si.clone()) { - { - let inner = wrapper_inner_arg(val.clone()); - let inner_is_descent = ((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); - let inner_is_var = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())) - } - _ => false, - }; - (inner_is_descent.clone() || inner_is_var.clone()) - } - } else { - false - }; - let is_extraction_descent = if is_sub_value_extractor(&val, si.clone()) { - { - let inner = extractor_inner_arg(val.clone()); - let inner_is_descent = ((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); - let inner_is_var = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())) - } - _ => false, - }; - let inner_is_param = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(inner.clone(), si.clone()).as_str() - == param_name.clone().as_str()) - } - _ => false, - }; - ((inner_is_descent.clone() || inner_is_var.clone()) || inner_is_param) - } - } else { - false - }; - let is_children_list = match (*val.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(val.clone()); - let field = field_access_field_at(val.clone(), si.clone()); - (is_children_list_field(field) - && match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at(base.clone(), si.clone()); - ((bname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars.clone(), bname.clone())) - } - _ => false, - }) - } - _ => false, - }; - let is_passthrough_descent = if is_list_passthrough_call(val.clone(), si.clone()) { - match list_passthrough_inner_arg(val.clone(), si.clone()) { - Some(inner) => { - (((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr( - &inner, - param_name.clone(), - si.clone(), - ))) - || match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => set_has( - vars.clone(), - expr_var_name_at(inner.clone(), si.clone()), - ), - _ => false, - }) - } - None => false, - } - } else { - false - }; - let is_consuming_helper = (check_list.clone() - && is_tokens_consuming_call(&val, param_name.clone(), vars.clone(), &si)); - let val_is_descent = ((((((((is_direct_descent || is_descent_var) - || is_option_descent) - || is_match_descent) - || is_wrapped_descent) - || is_extraction_descent) - || is_children_list) - || is_passthrough_descent) - || is_consuming_helper); - let next_vars = if val_is_descent { - v2_rt::rc_map_insert( - vars.clone(), - let_binding_name_at(body.clone(), si.clone()), - true, - ) - } else { - vars.clone() - }; - match let_body(body.clone()) { - Some(b) => collect_descent_vars( - &b, - ¶m_name, - &next_vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => next_vars, - } - } - ExprData::ExprMatch => { - let scrut = match_scrutinee(body.clone()); - let scrut_is_descent = expr_contains_descent( - &scrut, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let scrut_is_param = match (*scrut.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let sname = expr_var_name_at(scrut.clone(), si.clone()); - ((sname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars.clone(), sname.clone())) - } - _ => false, - }; - let with_patterns = if (scrut_is_descent.clone() || scrut_is_param) { - match_arm_nodes(body.clone()).iter().cloned().fold( - vars.clone(), - |acc: Rc>, arm_node: Rc| match (*arm_pattern( - arm_node.clone(), - )) - .clone() - { - MatchPattern::VariantPattern { - field_bindings: bindings, - .. - } => bindings.clone().iter().cloned().fold( - acc.clone(), - |inner: Rc>, fb: Rc| { - collect_field_binding_names(fb.clone(), inner) - }, - ), - MatchPattern::Bind { - name: binding_name, .. - } => { - if scrut_is_descent.clone() { - v2_rt::rc_map_insert(acc.clone(), binding_name.clone(), true) - } else { - acc.clone() - } - } - _ => acc.clone(), - }, - ) + ExprData::ExprLet => { + let val = let_value(body.clone()); +let is_direct_descent = ((check_child.clone() && is_child_descent_expr(&val, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&val, param_name.clone(), si.clone()))); +let is_descent_var = match (*val.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(val.clone(), si.clone())), + _ => false, +}; +let is_option_descent = is_if_option_descent(&val, param_name.clone(), vars.clone(), check_child.clone(), check_list.clone(), &si); +let is_match_descent = is_match_option_descent(&val, ¶m_name, vars.clone(), check_child.clone(), check_list.clone(), &si); +let is_wrapped_descent = if is_tree_size_preserving_wrapper(&val, si.clone()) { + { + let inner = wrapper_inner_arg(val.clone()); +let inner_is_descent = ((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); +let inner_is_var = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}; +(inner_is_descent.clone() || inner_is_var.clone()) +} + } else { + false + }; +let is_extraction_descent = if is_sub_value_extractor(&val, si.clone()) { + { + let inner = extractor_inner_arg(val.clone()); +let inner_is_descent = ((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); +let inner_is_var = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}; +let inner_is_param = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(inner.clone(), si.clone()).as_str() == param_name.clone().as_str()), + _ => false, +}; +((inner_is_descent.clone() || inner_is_var.clone()) || inner_is_param) +} + } else { + false + }; +let is_children_list = match (*val.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(val.clone()); +let field = field_access_field_at(val.clone(), si.clone()); +(is_children_list_field(field) && match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), si.clone()); +((bname.clone().as_str() == param_name.clone().as_str()) || set_has(vars.clone(), bname.clone())) +}, + _ => false, +}) +}, + _ => false, +}; +let is_passthrough_descent = if is_list_passthrough_call(val.clone(), si.clone()) { + match list_passthrough_inner_arg(val.clone(), si.clone()) { + Some(inner) => (((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))) || match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}), + None => false, +} + } else { + false + }; +let is_consuming_helper = (check_list.clone() && is_tokens_consuming_call(&val, param_name.clone(), vars.clone(), &si)); +let val_is_descent = ((((((((is_direct_descent || is_descent_var) || is_option_descent) || is_match_descent) || is_wrapped_descent) || is_extraction_descent) || is_children_list) || is_passthrough_descent) || is_consuming_helper); +let next_vars = if val_is_descent { + v2_rt::rc_map_insert(vars.clone(), let_binding_name_at(body.clone(), si.clone()), true) + } else { + vars.clone() + }; +match let_body(body.clone()) { + Some(b) => collect_descent_vars(&b, ¶m_name, &next_vars, check_child.clone(), check_list.clone(), &si), + None => next_vars, +} +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(body.clone()); +let scrut_is_descent = expr_contains_descent(&scrut, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let scrut_is_param = match (*scrut.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let sname = expr_var_name_at(scrut.clone(), si.clone()); +((sname.clone().as_str() == param_name.clone().as_str()) || set_has(vars.clone(), sname.clone())) +}, + _ => false, +}; +let with_patterns = if (scrut_is_descent.clone() || scrut_is_param) { + match_arm_nodes(body.clone()).iter().cloned().fold(vars.clone(), |acc: Rc>, arm_node: Rc| match (*arm_pattern(arm_node.clone())).clone() { + MatchPattern::VariantPattern { field_bindings: bindings, .. } => bindings.clone().iter().cloned().fold(acc.clone(), |inner: Rc>, fb: Rc| collect_field_binding_names(fb.clone(), inner)), + MatchPattern::Bind { name: binding_name, .. } => if scrut_is_descent.clone() { + v2_rt::rc_map_insert(acc.clone(), binding_name.clone(), true) } else { - vars.clone() - }; - match_arm_nodes(body.clone()).iter().cloned().fold( - with_patterns.clone(), - |acc: Rc>, arm_node: Rc| { - let arm_result = collect_descent_vars( - &arm_body(&arm_node), - ¶m_name, - &with_patterns, - check_child.clone(), - check_list.clone(), - &si, - ); - v2_rt::rc_map_merge(acc, arm_result.clone()) - }, - ) - } - ExprData::ExprIf => { - let then_vars = collect_descent_vars( - &if_then_branch(body.clone()), - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let else_vars = match if_else_branch(body.clone()) { - Some(eb) => collect_descent_vars( - &eb, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => vars.clone(), - }; - v2_rt::rc_map_merge(then_vars, else_vars) - } - ExprData::ExprBlock => body.children.clone().iter().cloned().fold( - vars.clone(), - |acc: Rc>, stmt: Rc| { - collect_descent_vars( - &stmt, - ¶m_name, - &acc, - check_child.clone(), - check_list.clone(), - &si, - ) + acc.clone() }, - ), - ExprData::ExprReturn => match body.children.clone().first().cloned() { - Some(inner) => collect_descent_vars( - &inner, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => vars.clone(), - }, - _ => vars.clone(), - } + _ => acc.clone(), +}) + } else { + vars.clone() + }; +match_arm_nodes(body.clone()).iter().cloned().fold(with_patterns.clone(), |acc: Rc>, arm_node: Rc| { + let arm_result = collect_descent_vars(&arm_body(&arm_node), ¶m_name, &with_patterns, check_child.clone(), check_list.clone(), &si); +v2_rt::rc_map_merge(acc, arm_result.clone()) +}) +}, + ExprData::ExprIf => { + let then_vars = collect_descent_vars(&if_then_branch(body.clone()), ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let else_vars = match if_else_branch(body.clone()) { + Some(eb) => collect_descent_vars(&eb, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), + None => vars.clone(), +}; +v2_rt::rc_map_merge(then_vars, else_vars) +}, + ExprData::ExprBlock => body.children.clone().iter().cloned().fold(vars.clone(), |acc: Rc>, stmt: Rc| collect_descent_vars(&stmt, ¶m_name, &acc, check_child.clone(), check_list.clone(), &si)), + ExprData::ExprReturn => match body.children.clone().first().cloned() { + Some(inner) => collect_descent_vars(&inner, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), + None => vars.clone(), +}, + _ => vars.clone(), +} }) } -pub fn all_self_calls_descend( - body: Rc, - func_name: String, - param_name: String, - check_child: bool, - check_list: bool, - si: Rc>>, -) -> bool { - all_self_calls_descend_inc( - &body, - &func_name, - ¶m_name, - &v2_rt::rc_empty_map::(), - check_child, - check_list, - &si, - ) -} - -pub fn all_self_calls_descend_inc( - body: &Rc, - func_name: &String, - param_name: &String, - vars: &Rc>, - check_child: bool, - check_list: bool, - si: &Rc>>, -) -> bool { +pub fn all_self_calls_descend(body: Rc, func_name: String, param_name: String, check_child: bool, check_list: bool, si: Rc>>) -> bool { + all_self_calls_descend_inc(&body, &func_name, ¶m_name, &v2_rt::rc_empty_map::(), check_child, check_list, &si) +} + +pub fn all_self_calls_descend_inc(body: &Rc, func_name: &String, param_name: &String, vars: &Rc>, check_child: bool, check_list: bool, si: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprLambda => true, - ExprData::ExprLet => { - let val = let_value(body.clone()); - let val_ok = all_self_calls_descend_inc( - &val, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let is_direct = ((check_child.clone() - && is_child_descent_expr(&val, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&val, param_name.clone(), si.clone()))); - let is_var = match (*val.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(val.clone(), si.clone())) - } - _ => false, - }; - let is_option = is_if_option_descent( - &val, - param_name.clone(), - vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - let is_children_list = match (*val.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(val.clone()); - let field = field_access_field_at(val.clone(), si.clone()); - (is_children_list_field(field) - && match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at(base.clone(), si.clone()); - ((bname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars.clone(), bname.clone())) - } - _ => false, - }) - } - _ => false, - }; - let next_vars = if (((is_direct || is_var) || is_option) || is_children_list) { - v2_rt::rc_map_insert( - vars.clone(), - let_binding_name_at(body.clone(), si.clone()), - true, - ) - } else { - vars.clone() - }; - let body_ok = match let_body(body.clone()) { - Some(b) => all_self_calls_descend_inc( - &b, - &func_name, - ¶m_name, - &next_vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => true, - }; - (val_ok && body_ok) - } - ExprData::ExprMatch => { - let scrut = match_scrutinee(body.clone()); - let scrut_ok = all_self_calls_descend_inc( - &scrut, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let scrut_is_descent = expr_contains_descent( - &scrut, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let scrut_is_param = match (*scrut.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let sname = expr_var_name_at(scrut.clone(), si.clone()); - ((sname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars.clone(), sname.clone())) - } - _ => false, - }; - let arms_ok = { - let mut __all = true; - for arm_node in match_arm_nodes(body.clone()).iter().cloned() { - if !({ - let arm_vars = if (scrut_is_descent.clone() || scrut_is_param.clone()) { - match (*arm_pattern(arm_node.clone())).clone() { - MatchPattern::VariantPattern { - field_bindings: bindings, - .. - } => bindings.clone().iter().cloned().fold( - vars.clone(), - |inner: Rc>, fb: Rc| { - collect_field_binding_names(fb.clone(), inner) - }, - ), - MatchPattern::Bind { - name: binding_name, .. - } => { - if scrut_is_descent.clone() { - v2_rt::rc_map_insert( - vars.clone(), - binding_name.clone(), - true, - ) - } else { - vars.clone() - } - } - _ => vars.clone(), - } - } else { - vars.clone() - }; - all_self_calls_descend_inc( - &arm_body(&arm_node), - &func_name, - ¶m_name, - &arm_vars, - check_child.clone(), - check_list.clone(), - &si, - ) - }) { - __all = false; - break; - } - } - __all - }; - (scrut_ok && arms_ok) - } - ExprData::ExprIf => { - let cond_ok = all_self_calls_descend_inc( - &if_condition(body.clone()), - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let then_ok = all_self_calls_descend_inc( - &if_then_branch(body.clone()), - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let else_ok = match if_else_branch(body.clone()) { - Some(eb) => all_self_calls_descend_inc( - &eb, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => true, - }; - ((cond_ok && then_ok) && else_ok) - } - ExprData::ExprBlock => { - let result = body.children.clone().iter().cloned().fold( - Rc::new(DescentCheckAcc { - ok: true, - vars: vars.clone(), - }), - |acc: Rc, stmt: Rc| { - if (acc.ok.clone() == false) { - acc.clone() - } else { - { - let stmt_ok = all_self_calls_descend_inc( - &stmt, - &func_name, - ¶m_name, - &acc.vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - let next_vars = collect_descent_vars( - &stmt, - ¶m_name, - &acc.vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - Rc::new(DescentCheckAcc { - ok: stmt_ok.clone(), - vars: next_vars.clone(), - }) - } - } + ExprData::ExprLambda => true, + ExprData::ExprLet => { + let val = let_value(body.clone()); +let val_ok = all_self_calls_descend_inc(&val, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let is_direct = ((check_child.clone() && is_child_descent_expr(&val, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&val, param_name.clone(), si.clone()))); +let is_var = match (*val.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(val.clone(), si.clone())), + _ => false, +}; +let is_option = is_if_option_descent(&val, param_name.clone(), vars.clone(), check_child.clone(), check_list.clone(), &si); +let is_children_list = match (*val.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(val.clone()); +let field = field_access_field_at(val.clone(), si.clone()); +(is_children_list_field(field) && match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), si.clone()); +((bname.clone().as_str() == param_name.clone().as_str()) || set_has(vars.clone(), bname.clone())) +}, + _ => false, +}) +}, + _ => false, +}; +let next_vars = if (((is_direct || is_var) || is_option) || is_children_list) { + v2_rt::rc_map_insert(vars.clone(), let_binding_name_at(body.clone(), si.clone()), true) + } else { + vars.clone() + }; +let body_ok = match let_body(body.clone()) { + Some(b) => all_self_calls_descend_inc(&b, &func_name, ¶m_name, &next_vars, check_child.clone(), check_list.clone(), &si), + None => true, +}; +(val_ok && body_ok) +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(body.clone()); +let scrut_ok = all_self_calls_descend_inc(&scrut, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let scrut_is_descent = expr_contains_descent(&scrut, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let scrut_is_param = match (*scrut.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let sname = expr_var_name_at(scrut.clone(), si.clone()); +((sname.clone().as_str() == param_name.clone().as_str()) || set_has(vars.clone(), sname.clone())) +}, + _ => false, +}; +let arms_ok = { let mut __all = true; for arm_node in match_arm_nodes(body.clone()).iter().cloned() { if !({ + let arm_vars = if (scrut_is_descent.clone() || scrut_is_param.clone()) { + match (*arm_pattern(arm_node.clone())).clone() { + MatchPattern::VariantPattern { field_bindings: bindings, .. } => bindings.clone().iter().cloned().fold(vars.clone(), |inner: Rc>, fb: Rc| collect_field_binding_names(fb.clone(), inner)), + MatchPattern::Bind { name: binding_name, .. } => if scrut_is_descent.clone() { + v2_rt::rc_map_insert(vars.clone(), binding_name.clone(), true) + } else { + vars.clone() }, - ); - result.ok.clone() - } - ExprData::ExprCall { .. } => { - let callee = expr_call_func_at(body.clone(), si.clone()); - let own_ok = if (callee.as_str() == func_name.clone().as_str()) { - { - let mut __found = false; - for arg_node in body.children.clone().iter().cloned() { - if { - let targets_param = (arg_name_at(arg_node.clone(), si.clone()) - .as_deref() - == Some(param_name.clone()).as_deref()); - if (targets_param.clone() == false) { - false - } else { - is_descent_arg( - &arg_value(&arg_node), - ¶m_name, - vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ) - } - } { - __found = true; - break; - } - } - __found - } + _ => vars.clone(), +} } else { - true + vars.clone() }; - (own_ok && { - let mut __all = true; - for child in body.children.clone().iter().cloned() { - if !(all_self_calls_descend_inc( - &child, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - )) { - __all = false; - break; - } - } - __all - }) - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let receiver = method_receiver(body.clone()); - let is_iter = is_algebra_iteration_method(ms.clone()); - let is_struct = is_structural_children(&receiver, ¶m_name, &vars, &si); - if (is_iter && is_struct) { - { - let recv_ok = all_self_calls_descend_inc( - &receiver, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let args_ok = { - let mut __all = true; - for arg_node in method_arg_nodes(body.clone()).iter().cloned() { - if !({ - let arg_val = arg_value(&arg_node); - match (*arg_val.expr_data.clone()).clone() { - ExprData::ExprLambda => match iteration_element_name( - ms.clone(), - arg_val.clone(), - si.clone(), - ) { - Some(iter_name) => { - let ext_vars = v2_rt::rc_map_insert( - vars.clone(), - iter_name.clone(), - true, - ); - all_self_calls_descend_inc( - &lambda_body(arg_val.clone()), - &func_name, - ¶m_name, - &ext_vars, - check_child.clone(), - check_list.clone(), - &si, - ) - } - None => true, - }, - _ => all_self_calls_descend_inc( - &arg_val, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ), - } - }) { - __all = false; - break; - } - } - __all - }; - (recv_ok && args_ok) - } - } else { - { - let mut __all = true; - for child in body.children.clone().iter().cloned() { - if !(all_self_calls_descend_inc( - &child, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - )) { - __all = false; - break; - } - } - __all - } - } - } - _ => { - let mut __all = true; - for child in body.children.clone().iter().cloned() { - if !(all_self_calls_descend_inc( - &child, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - )) { - __all = false; - break; +all_self_calls_descend_inc(&arm_body(&arm_node), &func_name, ¶m_name, &arm_vars, check_child.clone(), check_list.clone(), &si) +}) { __all = false; break; } } __all }; +(scrut_ok && arms_ok) +}, + ExprData::ExprIf => { + let cond_ok = all_self_calls_descend_inc(&if_condition(body.clone()), &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let then_ok = all_self_calls_descend_inc(&if_then_branch(body.clone()), &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let else_ok = match if_else_branch(body.clone()) { + Some(eb) => all_self_calls_descend_inc(&eb, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), + None => true, +}; +((cond_ok && then_ok) && else_ok) +}, + ExprData::ExprBlock => { + let result = body.children.clone().iter().cloned().fold(Rc::new(DescentCheckAcc { + ok: true, + vars: vars.clone(), +}), |acc: Rc, stmt: Rc| if (acc.ok.clone() == false) { + acc.clone() + } else { + { + let stmt_ok = all_self_calls_descend_inc(&stmt, &func_name, ¶m_name, &acc.vars.clone(), check_child.clone(), check_list.clone(), &si); +let next_vars = collect_descent_vars(&stmt, ¶m_name, &acc.vars.clone(), check_child.clone(), check_list.clone(), &si); +Rc::new(DescentCheckAcc { + ok: stmt_ok.clone(), + vars: next_vars.clone(), +}) +} + }); +result.ok.clone() +}, + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(body.clone(), si.clone()); +let own_ok = if (callee.as_str() == func_name.clone().as_str()) { + { let mut __found = false; for arg_node in body.children.clone().iter().cloned() { if { + let targets_param = (arg_name_at(arg_node.clone(), si.clone()).as_deref() == Some(param_name.clone()).as_deref()); +if (targets_param.clone() == false) { + false + } else { + is_descent_arg(&arg_value(&arg_node), ¶m_name, vars.clone(), check_child.clone(), check_list.clone(), &si) } - } - __all +} { __found = true; break; } } __found } + } else { + true + }; +(own_ok && { let mut __all = true; for child in body.children.clone().iter().cloned() { if !(all_self_calls_descend_inc(&child, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si)) { __all = false; break; } } __all }) +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let receiver = method_receiver(body.clone()); +let is_iter = is_algebra_iteration_method(ms.clone()); +let is_struct = is_structural_children(&receiver, ¶m_name, &vars, &si); +if (is_iter && is_struct) { + { + let recv_ok = all_self_calls_descend_inc(&receiver, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let args_ok = { let mut __all = true; for arg_node in method_arg_nodes(body.clone()).iter().cloned() { if !({ + let arg_val = arg_value(&arg_node); +match (*arg_val.expr_data.clone()).clone() { + ExprData::ExprLambda => match iteration_element_name(ms.clone(), arg_val.clone(), si.clone()) { + Some(iter_name) => { + let ext_vars = v2_rt::rc_map_insert(vars.clone(), iter_name.clone(), true); +all_self_calls_descend_inc(&lambda_body(arg_val.clone()), &func_name, ¶m_name, &ext_vars, check_child.clone(), check_list.clone(), &si) +}, + None => true, +}, + _ => all_self_calls_descend_inc(&arg_val, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si), +} +}) { __all = false; break; } } __all }; +(recv_ok && args_ok) +} + } else { + { let mut __all = true; for child in body.children.clone().iter().cloned() { if !(all_self_calls_descend_inc(&child, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si)) { __all = false; break; } } __all } } - } +}, + _ => { let mut __all = true; for child in body.children.clone().iter().cloned() { if !(all_self_calls_descend_inc(&child, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si)) { __all = false; break; } } __all }, +} }) } pub fn unwrap_to_match(mut body: Rc) -> Option> { loop { match (*body.expr_data.clone()).clone() { - ExprData::ExprMatch => { - break Some(body.clone()); - } - ExprData::ExprLet => match let_body(body.clone()) { - Some(b) => { - let __tco_0 = b.clone(); - body = __tco_0; - continue; - } - None => { - break None; - } - }, - ExprData::ExprBlock => match body.children.clone().last().cloned() { - Some(last_stmt) => { - let __tco_0 = last_stmt.clone(); - body = __tco_0; - continue; - } - None => { - break None; - } - }, - _ => { - break None; - } - } - } -} - -pub fn matches_on_sub_value_field( - body: Rc, - param_name: String, - si: &Rc>>, -) -> bool { + ExprData::ExprMatch => { break Some(body.clone()); }, + ExprData::ExprLet => { match let_body(body.clone()) { + Some(b) => { { + let __tco_0 = b.clone(); +body = __tco_0; +continue; +} }, + None => { break None; }, +} }, + ExprData::ExprBlock => { match body.children.clone().last().cloned() { + Some(last_stmt) => { { + let __tco_0 = last_stmt.clone(); +body = __tco_0; +continue; +} }, + None => { break None; }, +} }, + _ => { break None; }, +} +} +} + +pub fn matches_on_sub_value_field(body: Rc, param_name: String, si: &Rc>>) -> bool { match unwrap_to_match(body) { - Some(m) => { - let scrut = match_scrutinee(m.clone()); - match (*scrut.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(scrut.clone()); - let field = field_access_field_at(scrut.clone(), si.clone()); - (is_sub_value_field(field) - && match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(base.clone(), si.clone()).as_str() - == param_name.as_str()) - } - _ => false, - }) - } - _ => false, - } - } - None => false, - } + Some(m) => { + let scrut = match_scrutinee(m.clone()); +match (*scrut.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(scrut.clone()); +let field = field_access_field_at(scrut.clone(), si.clone()); +(is_sub_value_field(field) && match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(base.clone(), si.clone()).as_str() == param_name.as_str()), + _ => false, +}) +}, + _ => false, +} +}, + None => false, +} } -pub fn is_container_child_descent( - body: Rc, - func_name: String, - params: Rc>>, - si: Rc>>, -) -> bool { - { - let mut __found = false; - for p in params.iter().cloned() { - if { - let pname = param_node_name_at(p.clone(), si.clone()); - (matches_on_sub_value_field(body.clone(), pname.clone(), &si) - && all_self_calls_descend( - body.clone(), - func_name.clone(), - pname.clone(), - true, - false, - si.clone(), - )) - } { - __found = true; - break; - } - } - __found - } +pub fn is_container_child_descent(body: Rc, func_name: String, params: Rc>>, si: Rc>>) -> bool { + { let mut __found = false; for p in params.iter().cloned() { if { + let pname = param_node_name_at(p.clone(), si.clone()); +(matches_on_sub_value_field(body.clone(), pname.clone(), &si) && all_self_calls_descend(body.clone(), func_name.clone(), pname.clone(), true, false, si.clone())) +} { __found = true; break; } } __found } } -pub fn is_list_shrinkage_descent( - body: Rc, - func_name: String, - params: Rc>>, - si: Rc>>, -) -> bool { - { - let mut __found = false; - for p in params.iter().cloned() { - if { - let pname = param_node_name_at(p.clone(), si.clone()); - all_self_calls_descend( - body.clone(), - func_name.clone(), - pname.clone(), - false, - true, - si.clone(), - ) - } { - __found = true; - break; - } - } - __found - } +pub fn is_list_shrinkage_descent(body: Rc, func_name: String, params: Rc>>, si: Rc>>) -> bool { + { let mut __found = false; for p in params.iter().cloned() { if { + let pname = param_node_name_at(p.clone(), si.clone()); +all_self_calls_descend(body.clone(), func_name.clone(), pname.clone(), false, true, si.clone()) +} { __found = true; break; } } __found } } -pub fn is_arithmetic_descent_expr( - expr: &Rc, - param_name: String, - si: Rc>>, -) -> bool { +pub fn is_arithmetic_descent_expr(expr: &Rc, param_name: String, si: Rc>>) -> bool { match (*expr.expr_data.clone()).clone() { - ExprData::ExprBinOp { op: BinOp::Sub, .. } => { - let left = binop_left(expr.clone()); - let right = binop_right(expr.clone()); - match (*left.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - ((expr_var_name_at(left.clone(), si).as_str() == param_name.as_str()) - && match (*right.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: n, .. } = value.as_ref() else { - unreachable!() - }; - (n.clone() > 0) - } - _ => false, - }) - } - _ => false, - } - } - _ => false, - } + ExprData::ExprBinOp { op: BinOp::Sub, .. } => { + let left = binop_left(expr.clone()); +let right = binop_right(expr.clone()); +match (*left.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => ((expr_var_name_at(left.clone(), si).as_str() == param_name.as_str()) && match (*right.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: n, .. } = value.as_ref() else { unreachable!() }; (n.clone() > 0) }, + _ => false, +}), + _ => false, +} +}, + _ => false, +} } -pub fn classify_self_call_evidence( - arg_expr: &Rc, - param_name: &String, - descent_vars: &Rc>, - check_child: bool, - check_list: bool, - si: &Rc>>, -) -> DescentEvidence { +pub fn classify_self_call_evidence(arg_expr: &Rc, param_name: &String, descent_vars: &Rc>, check_child: bool, check_list: bool, si: &Rc>>) -> DescentEvidence { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - if (check_child.clone() - && is_child_descent_expr(&arg_expr, ¶m_name, &descent_vars, &si)) - { + if (check_child.clone() && is_child_descent_expr(&arg_expr, ¶m_name, &descent_vars, &si)) { DescentEvidence::Strict } else { - if (check_list.clone() - && is_list_shrink_expr(&arg_expr, param_name.clone(), si.clone())) - { + if (check_list.clone() && is_list_shrink_expr(&arg_expr, param_name.clone(), si.clone())) { DescentEvidence::Strict } else { - if (((check_child.clone() == false) && (check_list.clone() == false)) - && is_arithmetic_descent_expr(&arg_expr, param_name.clone(), si.clone())) - { + if (((check_child.clone() == false) && (check_list.clone() == false)) && is_arithmetic_descent_expr(&arg_expr, param_name.clone(), si.clone())) { DescentEvidence::Strict } else { match (*arg_expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at(arg_expr.clone(), si.clone()); - if set_has(descent_vars.clone(), vname.clone()) { - DescentEvidence::Strict + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(arg_expr.clone(), si.clone()); +if set_has(descent_vars.clone(), vname.clone()) { + DescentEvidence::Strict + } else { + if (vname.clone().as_str() == param_name.clone().as_str()) { + DescentEvidence::NonIncreasing } else { - if (vname.clone().as_str() == param_name.clone().as_str()) { - DescentEvidence::NonIncreasing - } else { - DescentEvidence::DescentUnknown - } + DescentEvidence::DescentUnknown } } - ExprData::ExprCall { .. } => { - if is_tree_size_preserving_wrapper(&arg_expr, si.clone()) { - classify_self_call_evidence( - &wrapper_inner_arg(arg_expr.clone()), - ¶m_name, - &descent_vars, - check_child.clone(), - check_list.clone(), - &si, - ) +}, + ExprData::ExprCall { .. } => if is_tree_size_preserving_wrapper(&arg_expr, si.clone()) { + classify_self_call_evidence(&wrapper_inner_arg(arg_expr.clone()), ¶m_name, &descent_vars, check_child.clone(), check_list.clone(), &si) + } else { + if is_sub_value_extractor(&arg_expr, si.clone()) { + { + let inner_ev = classify_self_call_evidence(&extractor_inner_arg(arg_expr.clone()), ¶m_name, &descent_vars, check_child.clone(), check_list.clone(), &si); +match inner_ev.clone() { + DescentEvidence::NonIncreasing => DescentEvidence::Strict, + _ => inner_ev.clone(), +} +} + } else { + if is_list_passthrough_call(arg_expr.clone(), si.clone()) { + match list_passthrough_inner_arg(arg_expr.clone(), si.clone()) { + Some(inner) => classify_self_call_evidence(&inner, ¶m_name, &descent_vars, check_child.clone(), check_list.clone(), &si), + None => DescentEvidence::DescentUnknown, +} } else { - if is_sub_value_extractor(&arg_expr, si.clone()) { - { - let inner_ev = classify_self_call_evidence( - &extractor_inner_arg(arg_expr.clone()), - ¶m_name, - &descent_vars, - check_child.clone(), - check_list.clone(), - &si, - ); - match inner_ev.clone() { - DescentEvidence::NonIncreasing => { - DescentEvidence::Strict - } - _ => inner_ev.clone(), - } - } - } else { - if is_list_passthrough_call(arg_expr.clone(), si.clone()) { - match list_passthrough_inner_arg( - arg_expr.clone(), - si.clone(), - ) { - Some(inner) => classify_self_call_evidence( - &inner, - ¶m_name, - &descent_vars, - check_child.clone(), - check_list.clone(), - &si, - ), - None => DescentEvidence::DescentUnknown, - } - } else { - DescentEvidence::DescentUnknown - } - } - } - } - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(arg_expr.clone()); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at(base.clone(), si.clone()); - if (set_has(descent_vars.clone(), bname.clone()) - || (bname.clone().as_str() == param_name.clone().as_str())) - { - DescentEvidence::Strict - } else { - { - let field = - field_access_field_at(arg_expr.clone(), si.clone()); - if (field.as_str() == param_name.clone().as_str()) { - DescentEvidence::NonIncreasing - } else { - DescentEvidence::DescentUnknown - } - } - } - } - _ => DescentEvidence::DescentUnknown, + DescentEvidence::DescentUnknown } } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - if is_generalized_shrink(&arg_expr, si.clone()) { + }, + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(arg_expr.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), si.clone()); +if (set_has(descent_vars.clone(), bname.clone()) || (bname.clone().as_str() == param_name.clone().as_str())) { + DescentEvidence::Strict + } else { { - let recv = method_receiver(arg_expr.clone()); - let recv_ev = classify_self_call_evidence( - &recv, - ¶m_name, - &descent_vars, - check_child.clone(), - check_list.clone(), - &si, - ); - match recv_ev { - DescentEvidence::Strict => DescentEvidence::Strict, - DescentEvidence::NonIncreasing => DescentEvidence::Strict, - DescentEvidence::DescentUnknown => { - DescentEvidence::DescentUnknown - } + let field = field_access_field_at(arg_expr.clone(), si.clone()); +if (field.as_str() == param_name.clone().as_str()) { + DescentEvidence::NonIncreasing + } else { + DescentEvidence::DescentUnknown } - } - } else { - DescentEvidence::DescentUnknown +} } - } - _ => DescentEvidence::DescentUnknown, - } +}, + _ => DescentEvidence::DescentUnknown, +} +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => if is_generalized_shrink(&arg_expr, si.clone()) { + { + let recv = method_receiver(arg_expr.clone()); +let recv_ev = classify_self_call_evidence(&recv, ¶m_name, &descent_vars, check_child.clone(), check_list.clone(), &si); +match recv_ev { + DescentEvidence::Strict => DescentEvidence::Strict, + DescentEvidence::NonIncreasing => DescentEvidence::Strict, + DescentEvidence::DescentUnknown => DescentEvidence::DescentUnknown, +} +} + } else { + DescentEvidence::DescentUnknown + }, + _ => DescentEvidence::DescentUnknown, +} } } } }) } -pub fn try_dimension_for_param( - body: Rc, - func_name: String, - param_name: String, - check_child: bool, - check_list: bool, - si: Rc>>, -) -> Option { - collect_evidence_incremental( - &body, - &func_name, - ¶m_name, - &v2_rt::rc_empty_map::(), - check_child, - check_list, - false, - &si, - ) -} - -pub fn try_branching_dimension_for_param( - body: Rc, - func_name: String, - param_name: String, - check_child: bool, - check_list: bool, - si: Rc>>, -) -> Option { - collect_evidence_incremental( - &body, - &func_name, - ¶m_name, - &v2_rt::rc_empty_map::(), - check_child, - check_list, - true, - &si, - ) -} - -pub fn merge_optional_evidence( - a: Option, - b: Option, -) -> Option { +pub fn try_dimension_for_param(body: Rc, func_name: String, param_name: String, check_child: bool, check_list: bool, si: Rc>>) -> Option { + collect_evidence_incremental(&body, &func_name, ¶m_name, &v2_rt::rc_empty_map::(), check_child, check_list, false, &si) +} + +pub fn try_branching_dimension_for_param(body: Rc, func_name: String, param_name: String, check_child: bool, check_list: bool, si: Rc>>) -> Option { + collect_evidence_incremental(&body, &func_name, ¶m_name, &v2_rt::rc_empty_map::(), check_child, check_list, true, &si) +} + +pub fn merge_optional_evidence(a: Option, b: Option) -> Option { optional_evidence_meet(a, b) } -pub fn collect_evidence_incremental( - body: &Rc, - func_name: &String, - param_name: &String, - vars: &Rc>, - check_child: bool, - check_list: bool, - branching_only: bool, - si: &Rc>>, -) -> Option { +pub fn collect_evidence_incremental(body: &Rc, func_name: &String, param_name: &String, vars: &Rc>, check_child: bool, check_list: bool, branching_only: bool, si: &Rc>>) -> Option { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprLambda => None, - ExprData::ExprLet => { - let val = let_value(body.clone()); - let val_ev = collect_evidence_incremental( - &val, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - let is_direct = ((check_child.clone() - && is_child_descent_expr(&val, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&val, param_name.clone(), si.clone()))); - let is_var = match (*val.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(val.clone(), si.clone())) - } - _ => false, - }; - let is_option = is_if_option_descent( - &val, - param_name.clone(), - vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - let is_match_descent = is_match_option_descent( - &val, - ¶m_name, - vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - let is_wrapped = if is_tree_size_preserving_wrapper(&val, si.clone()) { - { - let inner = wrapper_inner_arg(val.clone()); - let inner_d = ((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); - let inner_v = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())) - } - _ => false, - }; - (inner_d.clone() || inner_v.clone()) - } - } else { - false - }; - let is_extraction = if is_sub_value_extractor(&val, si.clone()) { - { - let inner = extractor_inner_arg(val.clone()); - let inner_d = ((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); - let inner_v = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())) - } - _ => false, - }; - let inner_p = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(inner.clone(), si.clone()).as_str() - == param_name.clone().as_str()) - } - _ => false, - }; - ((inner_d.clone() || inner_v.clone()) || inner_p) - } - } else { - false - }; - let is_children_list = match (*val.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(val.clone()); - let field = field_access_field_at(val.clone(), si.clone()); - (is_children_list_field(field) - && match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at(base.clone(), si.clone()); - ((bname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars.clone(), bname.clone())) - } - _ => false, - }) - } - _ => false, - }; - let is_passthrough = if is_list_passthrough_call(val.clone(), si.clone()) { - match list_passthrough_inner_arg(val.clone(), si.clone()) { - Some(inner) => { - (((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) - || (check_list.clone() - && is_list_shrink_expr( - &inner, - param_name.clone(), - si.clone(), - ))) - || match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => set_has( - vars.clone(), - expr_var_name_at(inner.clone(), si.clone()), - ), - _ => false, - }) - } - None => false, - } + ExprData::ExprLambda => None, + ExprData::ExprLet => { + let val = let_value(body.clone()); +let val_ev = collect_evidence_incremental(&val, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si); +let is_direct = ((check_child.clone() && is_child_descent_expr(&val, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&val, param_name.clone(), si.clone()))); +let is_var = match (*val.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(val.clone(), si.clone())), + _ => false, +}; +let is_option = is_if_option_descent(&val, param_name.clone(), vars.clone(), check_child.clone(), check_list.clone(), &si); +let is_match_descent = is_match_option_descent(&val, ¶m_name, vars.clone(), check_child.clone(), check_list.clone(), &si); +let is_wrapped = if is_tree_size_preserving_wrapper(&val, si.clone()) { + { + let inner = wrapper_inner_arg(val.clone()); +let inner_d = ((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); +let inner_v = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}; +(inner_d.clone() || inner_v.clone()) +} + } else { + false + }; +let is_extraction = if is_sub_value_extractor(&val, si.clone()) { + { + let inner = extractor_inner_arg(val.clone()); +let inner_d = ((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); +let inner_v = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}; +let inner_p = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(inner.clone(), si.clone()).as_str() == param_name.clone().as_str()), + _ => false, +}; +((inner_d.clone() || inner_v.clone()) || inner_p) +} + } else { + false + }; +let is_children_list = match (*val.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(val.clone()); +let field = field_access_field_at(val.clone(), si.clone()); +(is_children_list_field(field) && match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), si.clone()); +((bname.clone().as_str() == param_name.clone().as_str()) || set_has(vars.clone(), bname.clone())) +}, + _ => false, +}) +}, + _ => false, +}; +let is_passthrough = if is_list_passthrough_call(val.clone(), si.clone()) { + match list_passthrough_inner_arg(val.clone(), si.clone()) { + Some(inner) => (((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))) || match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}), + None => false, +} + } else { + false + }; +let is_consuming_helper = (check_list.clone() && is_tokens_consuming_call(&val, param_name.clone(), vars.clone(), &si)); +let next_vars = if ((((((((is_direct || is_var) || is_option) || is_match_descent) || is_wrapped) || is_extraction) || is_children_list) || is_passthrough) || is_consuming_helper) { + v2_rt::rc_map_insert(vars.clone(), let_binding_name_at(body.clone(), si.clone()), true) + } else { + vars.clone() + }; +let body_ev = match let_body(body.clone()) { + Some(b) => collect_evidence_incremental(&b, &func_name, ¶m_name, &next_vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si), + None => None, +}; +merge_optional_evidence(val_ev, body_ev) +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(body.clone()); +let scrut_ev = collect_evidence_incremental(&scrut, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si); +let scrut_is_descent = expr_contains_descent(&scrut, ¶m_name, &vars, check_child.clone(), check_list.clone(), &si); +let scrut_is_param = match (*scrut.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let sname = expr_var_name_at(scrut.clone(), si.clone()); +((sname.clone().as_str() == param_name.clone().as_str()) || set_has(vars.clone(), sname.clone())) +}, + _ => false, +}; +let arms_ev = match_arm_nodes(body.clone()).iter().cloned().fold(None, |acc: _, arm_node: Rc| { + let is_base_case = if branching_only.clone() { + (max_path_self_calls(arm_body(&arm_node), func_name.clone(), si.clone()) == 0) } else { false }; - let is_consuming_helper = (check_list.clone() - && is_tokens_consuming_call(&val, param_name.clone(), vars.clone(), &si)); - let next_vars = if ((((((((is_direct || is_var) || is_option) - || is_match_descent) - || is_wrapped) - || is_extraction) - || is_children_list) - || is_passthrough) - || is_consuming_helper) - { - v2_rt::rc_map_insert( - vars.clone(), - let_binding_name_at(body.clone(), si.clone()), - true, - ) +if is_base_case.clone() { + acc.clone() } else { - vars.clone() - }; - let body_ev = match let_body(body.clone()) { - Some(b) => collect_evidence_incremental( - &b, - &func_name, - ¶m_name, - &next_vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ), - None => None, - }; - merge_optional_evidence(val_ev, body_ev) - } - ExprData::ExprMatch => { - let scrut = match_scrutinee(body.clone()); - let scrut_ev = collect_evidence_incremental( - &scrut, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - let scrut_is_descent = expr_contains_descent( - &scrut, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ); - let scrut_is_param = match (*scrut.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let sname = expr_var_name_at(scrut.clone(), si.clone()); - ((sname.clone().as_str() == param_name.clone().as_str()) - || set_has(vars.clone(), sname.clone())) - } - _ => false, - }; - let arms_ev = match_arm_nodes(body.clone()).iter().cloned().fold( - None, - |acc: _, arm_node: Rc| { - let is_base_case = if branching_only.clone() { - (max_path_self_calls( - arm_body(&arm_node), - func_name.clone(), - si.clone(), - ) == 0) + { + let arm_vars = if (scrut_is_descent.clone() || scrut_is_param.clone()) { + match (*arm_pattern(arm_node.clone())).clone() { + MatchPattern::VariantPattern { field_bindings: bindings, .. } => bindings.clone().iter().cloned().fold(vars.clone(), |inner: Rc>, fb: Rc| collect_field_binding_names(fb.clone(), inner)), + MatchPattern::Bind { name: binding_name, .. } => if scrut_is_descent.clone() { + v2_rt::rc_map_insert(vars.clone(), binding_name.clone(), true) + } else { + vars.clone() + }, + _ => vars.clone(), +} } else { - false + vars.clone() }; - if is_base_case.clone() { - acc.clone() +let arm_ev = collect_evidence_incremental(&arm_body(&arm_node), &func_name, ¶m_name, &arm_vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si); +merge_optional_evidence(acc.clone(), arm_ev.clone()) +} + } +}); +merge_optional_evidence(scrut_ev, arms_ev) +}, + ExprData::ExprIf => { + let cond_ev = collect_evidence_incremental(&if_condition(body.clone()), &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si); +let then_branch = if_then_branch(body.clone()); +let else_opt = if_else_branch(body.clone()); +let then_path = if branching_only.clone() { + max_path_self_calls(then_branch.clone(), func_name.clone(), si.clone()) + } else { + 0 + }; +let else_path = if branching_only.clone() { + match else_opt.clone() { + Some(eb) => max_path_self_calls(eb.clone(), func_name.clone(), si.clone()), + None => 0, +} + } else { + 0 + }; +let then_ev = if (branching_only.clone() && (then_path == 0)) { + None + } else { + collect_evidence_incremental(&then_branch, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si) + }; +let else_ev = if (branching_only.clone() && (else_path == 0)) { + None + } else { + match else_opt.clone() { + Some(eb) => collect_evidence_incremental(&eb, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si), + None => None, +} + }; +merge_optional_evidence(cond_ev, merge_optional_evidence(then_ev, else_ev)) +}, + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(body.clone(), si.clone()); +let own_evidence = if (callee.as_str() == func_name.clone().as_str()) { + { + let arg_evidence = body.children.clone().iter().cloned().fold(DescentEvidence::DescentUnknown, |acc: DescentEvidence, arg_node: Rc| { + let aname = arg_name_at(arg_node.clone(), si.clone()); +if (aname.clone().as_deref() == Some(param_name.clone()).as_deref()) { + classify_self_call_evidence(&arg_value(&arg_node), ¶m_name, &vars, check_child.clone(), check_list.clone(), &si) } else { - { - let arm_vars = - if (scrut_is_descent.clone() || scrut_is_param.clone()) { - match (*arm_pattern(arm_node.clone())).clone() { - MatchPattern::VariantPattern { - field_bindings: bindings, - .. - } => bindings.clone().iter().cloned().fold( - vars.clone(), - |inner: Rc>, fb: Rc| { - collect_field_binding_names(fb.clone(), inner) - }, - ), - MatchPattern::Bind { - name: binding_name, .. - } => { - if scrut_is_descent.clone() { - v2_rt::rc_map_insert( - vars.clone(), - binding_name.clone(), - true, - ) - } else { - vars.clone() - } - } - _ => vars.clone(), - } - } else { - vars.clone() - }; - let arm_ev = collect_evidence_incremental( - &arm_body(&arm_node), - &func_name, - ¶m_name, - &arm_vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - merge_optional_evidence(acc.clone(), arm_ev.clone()) - } + acc } - }, - ); - merge_optional_evidence(scrut_ev, arms_ev) - } - ExprData::ExprIf => { - let cond_ev = collect_evidence_incremental( - &if_condition(body.clone()), - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - let then_branch = if_then_branch(body.clone()); - let else_opt = if_else_branch(body.clone()); - let then_path = if branching_only.clone() { - max_path_self_calls(then_branch.clone(), func_name.clone(), si.clone()) - } else { - 0 - }; - let else_path = if branching_only.clone() { - match else_opt.clone() { - Some(eb) => max_path_self_calls(eb.clone(), func_name.clone(), si.clone()), - None => 0, - } - } else { - 0 - }; - let then_ev = if (branching_only.clone() && (then_path == 0)) { - None - } else { - collect_evidence_incremental( - &then_branch, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ) - }; - let else_ev = if (branching_only.clone() && (else_path == 0)) { - None - } else { - match else_opt.clone() { - Some(eb) => collect_evidence_incremental( - &eb, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ), - None => None, - } - }; - merge_optional_evidence(cond_ev, merge_optional_evidence(then_ev, else_ev)) - } - ExprData::ExprCall { .. } => { - let callee = expr_call_func_at(body.clone(), si.clone()); - let own_evidence = if (callee.as_str() == func_name.clone().as_str()) { - { - let arg_evidence = body.children.clone().iter().cloned().fold( - DescentEvidence::DescentUnknown, - |acc: DescentEvidence, arg_node: Rc| { - let aname = arg_name_at(arg_node.clone(), si.clone()); - if (aname.clone().as_deref() == Some(param_name.clone()).as_deref()) - { - classify_self_call_evidence( - &arg_value(&arg_node), - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - &si, - ) - } else { - acc - } - }, - ); - Some(arg_evidence) - } - } else { - None - }; - let child_evidence = - body.children - .clone() - .iter() - .cloned() - .fold(None, |acc: _, child: Rc| { - let ce = collect_evidence_incremental( - &child, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - merge_optional_evidence(acc.clone(), ce.clone()) - }); - merge_optional_evidence(own_evidence, child_evidence) - } - ExprData::ExprBlock => { - let result = body.children.clone().iter().cloned().fold( - Rc::new(EvidenceBlockAcc { - evidence: None, - vars: vars.clone(), - }), - |acc: Rc, stmt: Rc| { - let stmt_ev = collect_evidence_incremental( - &stmt, - &func_name, - ¶m_name, - &acc.vars.clone(), - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - let next_vars = collect_descent_vars( - &stmt, - ¶m_name, - &acc.vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - Rc::new(EvidenceBlockAcc { - evidence: merge_optional_evidence( - acc.evidence.clone(), - stmt_ev.clone(), - ), - vars: next_vars.clone(), - }) - }, - ); - result.evidence.clone() - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let receiver = method_receiver(body.clone()); - let is_iter = is_algebra_iteration_method(ms.clone()); - let is_struct = is_structural_children(&receiver, ¶m_name, &vars, &si); - if (is_iter && is_struct) { - { - let recv_ev = collect_evidence_incremental( - &receiver, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - let args_ev = method_arg_nodes(body.clone()).iter().cloned().fold( - None, - |acc: _, arg_node: Rc| { - let arg_val = arg_value(&arg_node); - let ev = match (*arg_val.expr_data.clone()).clone() { - ExprData::ExprLambda => match iteration_element_name( - ms.clone(), - arg_val.clone(), - si.clone(), - ) { - Some(iter_name) => { - let ext_vars = v2_rt::rc_map_insert( - vars.clone(), - iter_name.clone(), - true, - ); - collect_evidence_incremental( - &lambda_body(arg_val.clone()), - &func_name, - ¶m_name, - &ext_vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ) - } - None => None, - }, - _ => collect_evidence_incremental( - &arg_val, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ), - }; - merge_optional_evidence(acc.clone(), ev.clone()) - }, - ); - merge_optional_evidence(recv_ev, args_ev) - } - } else { - body.children - .clone() - .iter() - .cloned() - .fold(None, |acc: _, child: Rc| { - let ce = collect_evidence_incremental( - &child, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - merge_optional_evidence(acc.clone(), ce.clone()) - }) - } +}); +Some(arg_evidence) +} + } else { + None + }; +let child_evidence = body.children.clone().iter().cloned().fold(None, |acc: _, child: Rc| { + let ce = collect_evidence_incremental(&child, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si); +merge_optional_evidence(acc.clone(), ce.clone()) +}); +merge_optional_evidence(own_evidence, child_evidence) +}, + ExprData::ExprBlock => { + let result = body.children.clone().iter().cloned().fold(Rc::new(EvidenceBlockAcc { + evidence: None, + vars: vars.clone(), +}), |acc: Rc, stmt: Rc| { + let stmt_ev = collect_evidence_incremental(&stmt, &func_name, ¶m_name, &acc.vars.clone(), check_child.clone(), check_list.clone(), branching_only.clone(), &si); +let next_vars = collect_descent_vars(&stmt, ¶m_name, &acc.vars.clone(), check_child.clone(), check_list.clone(), &si); +Rc::new(EvidenceBlockAcc { + evidence: merge_optional_evidence(acc.evidence.clone(), stmt_ev.clone()), + vars: next_vars.clone(), +}) +}); +result.evidence.clone() +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let receiver = method_receiver(body.clone()); +let is_iter = is_algebra_iteration_method(ms.clone()); +let is_struct = is_structural_children(&receiver, ¶m_name, &vars, &si); +if (is_iter && is_struct) { + { + let recv_ev = collect_evidence_incremental(&receiver, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si); +let args_ev = method_arg_nodes(body.clone()).iter().cloned().fold(None, |acc: _, arg_node: Rc| { + let arg_val = arg_value(&arg_node); +let ev = match (*arg_val.expr_data.clone()).clone() { + ExprData::ExprLambda => match iteration_element_name(ms.clone(), arg_val.clone(), si.clone()) { + Some(iter_name) => { + let ext_vars = v2_rt::rc_map_insert(vars.clone(), iter_name.clone(), true); +collect_evidence_incremental(&lambda_body(arg_val.clone()), &func_name, ¶m_name, &ext_vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si) +}, + None => None, +}, + _ => collect_evidence_incremental(&arg_val, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si), +}; +merge_optional_evidence(acc.clone(), ev.clone()) +}); +merge_optional_evidence(recv_ev, args_ev) +} + } else { + body.children.clone().iter().cloned().fold(None, |acc: _, child: Rc| { + let ce = collect_evidence_incremental(&child, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si); +merge_optional_evidence(acc.clone(), ce.clone()) +}) } - _ => body - .children - .clone() - .iter() - .cloned() - .fold(None, |acc: _, child: Rc| { - let ce = collect_evidence_incremental( - &child, - &func_name, - ¶m_name, - &vars, - check_child.clone(), - check_list.clone(), - branching_only.clone(), - &si, - ); - merge_optional_evidence(acc.clone(), ce.clone()) - }), - } +}, + _ => body.children.clone().iter().cloned().fold(None, |acc: _, child: Rc| { + let ce = collect_evidence_incremental(&child, &func_name, ¶m_name, &vars, check_child.clone(), check_list.clone(), branching_only.clone(), &si); +merge_optional_evidence(acc.clone(), ce.clone()) +}), +} }) } -pub fn try_type_directed_dimension( - body: Rc, - func_name: String, - param_name: &String, - dim: IterationDimension, - si: Rc>>, -) -> Option> { +pub fn try_type_directed_dimension(body: Rc, func_name: String, param_name: &String, dim: IterationDimension, si: Rc>>) -> Option> { match dim { - IterationDimension::TreeDescent => { - match try_dimension_for_param(body, func_name, param_name.clone(), true, false, si) { - Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { - param: param_name.clone(), - })]), - })), - _ => None, - } - } - IterationDimension::CollectionFold => { - match try_dimension_for_param(body, func_name, param_name.clone(), false, true, si) { - Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::ListLength { - param: param_name.clone(), - })]), - })), - _ => None, - } - } - IterationDimension::ArithmeticRepeat => { - match try_dimension_for_param(body, func_name, param_name.clone(), false, false, si) { - Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::ArithmeticValue { - param: param_name.clone(), - })]), - })), - _ => None, - } - } - } + IterationDimension::TreeDescent => match try_dimension_for_param(body, func_name, param_name.clone(), true, false, si) { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { + param: param_name.clone(), +})]), +})), + _ => None, +}, + IterationDimension::CollectionFold => match try_dimension_for_param(body, func_name, param_name.clone(), false, true, si) { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::ListLength { + param: param_name.clone(), +})]), +})), + _ => None, +}, + IterationDimension::ArithmeticRepeat => match try_dimension_for_param(body, func_name, param_name.clone(), false, false, si) { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::ArithmeticValue { + param: param_name.clone(), +})]), +})), + _ => None, +}, +} } -pub fn construct_termination_proof( - func_name: &String, - body: &Rc, - params: &Rc>>, - parser_always_advancing: Rc>, - si: &Rc>>, -) -> Option> { +pub fn construct_termination_proof(func_name: &String, body: &Rc, params: &Rc>>, parser_always_advancing: Rc>, si: &Rc>>) -> Option> { { - let structural_proof = params - .clone() - .iter() - .cloned() - .fold(None, |best: _, p: Rc| match best.clone() { - Some(_) => best.clone(), - None => { - let pname = param_node_name_at(p.clone(), si.clone()); - let type_name = authored_name_at(si.clone(), ¶m_node_type_expr(&p)); - match type_iteration_dimension(&type_name) { - Some(dim) => try_type_directed_dimension( - body.clone(), - func_name.clone(), - &pname, - dim.clone(), - si.clone(), - ), - None => { - let tree_evidence = try_dimension_for_param( - body.clone(), - func_name.clone(), - pname.clone(), - true, - false, - si.clone(), - ); - match tree_evidence.clone() { - Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new( - RankingDimension::TreeSize { - param: pname.clone(), - }, - )]), - })), - _ => { - let list_evidence = try_dimension_for_param( - body.clone(), - func_name.clone(), - pname.clone(), - false, - true, - si.clone(), - ); - match list_evidence.clone() { - Some(DescentEvidence::Strict) => { - Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new( - RankingDimension::ListLength { - param: pname.clone(), - }, - )]), - })) - } - _ => { - let arith_evidence = try_dimension_for_param( - body.clone(), - func_name.clone(), - pname.clone(), - false, - false, - si.clone(), - ); - match arith_evidence.clone() { - Some(DescentEvidence::Strict) => { - Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new( - RankingDimension::ArithmeticValue { - param: pname.clone(), - }, - )]), - })) - } - _ => None, - } - } - } - } - } - } - } - } - }); - let single_dim_proof = match structural_proof.clone() { - Some(_) => structural_proof.clone(), - None => match parser_state_param(params.clone(), si.clone()) { - Some(state_param) => { - let self_set = seed_bool_map(func_name.clone()); - let edges = collect_parser_progress_edges( - &func_name, - &body, - &state_param, - &self_set, - &empty_parser_progress_env(), - &parser_always_advancing, - &v2_rt::rc_empty_map::(), - &si, - ); - if (((edges.clone().len() as i64) > 0) && { - let mut __all = true; - for edge in edges.clone().iter().cloned() { - if !(edge.progress.clone() == DescentEvidence::Strict) { - __all = false; - break; - } - } - __all - }) { - Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::TokenPosition { - param: state_param.name.clone(), - })]), - })) - } else { - None - } - } - None => None, - }, - }; - match single_dim_proof.clone() { - Some(_) => single_dim_proof.clone(), - None => { - let self_set = seed_bool_map(func_name.clone()); - let func_entry = Rc::new(FuncEntry { - name: func_name.clone(), - body: body.clone(), - params: params.clone(), - span: body.span.clone(), - is_tail_recursive: false, - }); - let func_index = seed_func_entry_map(func_name.clone(), func_entry); - construct_scc_termination_proof( - &Rc::new(vec![func_name.clone()]), - &func_index, - &self_set, - &si, - ) + let structural_proof = params.clone().iter().cloned().fold(None, |best: _, p: Rc| match best.clone() { + Some(_) => best.clone(), + None => { + let pname = param_node_name_at(p.clone(), si.clone()); +let type_name = authored_name_at(si.clone(), ¶m_node_type_expr(&p)); +match type_iteration_dimension(&type_name) { + Some(dim) => try_type_directed_dimension(body.clone(), func_name.clone(), &pname, dim.clone(), si.clone()), + None => { + let tree_evidence = try_dimension_for_param(body.clone(), func_name.clone(), pname.clone(), true, false, si.clone()); +match tree_evidence.clone() { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { + param: pname.clone(), +})]), +})), + _ => { + let list_evidence = try_dimension_for_param(body.clone(), func_name.clone(), pname.clone(), false, true, si.clone()); +match list_evidence.clone() { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::ListLength { + param: pname.clone(), +})]), +})), + _ => { + let arith_evidence = try_dimension_for_param(body.clone(), func_name.clone(), pname.clone(), false, false, si.clone()); +match arith_evidence.clone() { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::ArithmeticValue { + param: pname.clone(), +})]), +})), + _ => None, +} +}, +} +}, +} +}, +} +}, +}); +let single_dim_proof = match structural_proof.clone() { + Some(_) => structural_proof.clone(), + None => match parser_state_param(params.clone(), si.clone()) { + Some(state_param) => { + let self_set = seed_bool_map(func_name.clone()); +let edges = collect_parser_progress_edges(&func_name, &body, &state_param, &self_set, &empty_parser_progress_env(), &parser_always_advancing, &v2_rt::rc_empty_map::(), &si); +if (((edges.clone().len() as i64) > 0) && { let mut __all = true; for edge in edges.clone().iter().cloned() { if !((edge.progress.clone() == DescentEvidence::Strict)) { __all = false; break; } } __all }) { + Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TokenPosition { + param: state_param.name.clone(), +})]), +})) + } else { + None } - } - } +}, + None => None, +}, +}; +match single_dim_proof.clone() { + Some(_) => single_dim_proof.clone(), + None => { + let self_set = seed_bool_map(func_name.clone()); +let func_entry = Rc::new(FuncEntry { + name: func_name.clone(), + body: body.clone(), + params: params.clone(), + span: body.span.clone(), + is_tail_recursive: false, +}); +let func_index = seed_func_entry_map(func_name.clone(), func_entry); +construct_scc_termination_proof(&Rc::new(vec![func_name.clone()]), &func_index, &self_set, &si) +}, +} +} } -pub fn construct_branching_termination_proof( - func_name: String, - body: Rc, - params: Rc>>, - si: Rc>>, -) -> Option> { - params - .iter() - .cloned() - .fold(None, |best: _, p: Rc| match best.clone() { - Some(_) => best.clone(), - None => { - let pname = param_node_name_at(p.clone(), si.clone()); - let type_name = authored_name_at(si.clone(), ¶m_node_type_expr(&p)); - match type_iteration_dimension(&type_name) { - Some(IterationDimension::TreeDescent) => { - match try_branching_dimension_for_param( - body.clone(), - func_name.clone(), - pname.clone(), - true, - false, - si.clone(), - ) { - Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { - param: pname.clone(), - })]), - })), - _ => None, - } - } - Some(IterationDimension::CollectionFold) => { - match try_branching_dimension_for_param( - body.clone(), - func_name.clone(), - pname.clone(), - false, - true, - si.clone(), - ) { - Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::ListLength { - param: pname.clone(), - })]), - })), - _ => None, - } - } - Some(IterationDimension::ArithmeticRepeat) => None, - None => { - let tree_ev = try_branching_dimension_for_param( - body.clone(), - func_name.clone(), - pname.clone(), - true, - false, - si.clone(), - ); - match tree_ev.clone() { - Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { - param: pname.clone(), - })]), - })), - _ => { - let list_ev = try_branching_dimension_for_param( - body.clone(), - func_name.clone(), - pname.clone(), - false, - true, - si.clone(), - ); - match list_ev.clone() { - Some(DescentEvidence::Strict) => { - Some(Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new( - RankingDimension::ListLength { - param: pname.clone(), - }, - )]), - })) - } - _ => None, - } - } - } - } - } - } - }) +pub fn construct_branching_termination_proof(func_name: String, body: Rc, params: Rc>>, si: Rc>>) -> Option> { + params.iter().cloned().fold(None, |best: _, p: Rc| match best.clone() { + Some(_) => best.clone(), + None => { + let pname = param_node_name_at(p.clone(), si.clone()); +let type_name = authored_name_at(si.clone(), ¶m_node_type_expr(&p)); +match type_iteration_dimension(&type_name) { + Some(IterationDimension::TreeDescent) => match try_branching_dimension_for_param(body.clone(), func_name.clone(), pname.clone(), true, false, si.clone()) { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { + param: pname.clone(), +})]), +})), + _ => None, +}, + Some(IterationDimension::CollectionFold) => match try_branching_dimension_for_param(body.clone(), func_name.clone(), pname.clone(), false, true, si.clone()) { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::ListLength { + param: pname.clone(), +})]), +})), + _ => None, +}, + Some(IterationDimension::ArithmeticRepeat) => None, + None => { + let tree_ev = try_branching_dimension_for_param(body.clone(), func_name.clone(), pname.clone(), true, false, si.clone()); +match tree_ev.clone() { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { + param: pname.clone(), +})]), +})), + _ => { + let list_ev = try_branching_dimension_for_param(body.clone(), func_name.clone(), pname.clone(), false, true, si.clone()); +match list_ev.clone() { + Some(DescentEvidence::Strict) => Some(Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::ListLength { + param: pname.clone(), +})]), +})), + _ => None, +} +}, +} +}, +} +}, +}) } pub fn proof_to_call_pattern(proof: Rc) -> Rc { match proof.dimensions.clone().first().cloned() { - Some(dim) => match (*dim.clone()).clone() { - RankingDimension::TreeSize { param: p, .. } => { - Rc::new(CallPattern::ChildAccessorCall { - accessor: p.clone(), - }) - } - RankingDimension::ListLength { param: p, .. } => { - Rc::new(CallPattern::CollectionShrinkCall { - amount: Rc::new(PositiveDescentAmount::OneStep), - collection: p.clone(), - }) - } - RankingDimension::ArithmeticValue { param: p, .. } => { - Rc::new(CallPattern::ArithmeticSubtractCall { - steps: Rc::new(PositiveDescentAmount::OneStep), - ring_param: p.clone(), - }) - } - RankingDimension::TokenPosition { param: p, .. } => { - Rc::new(CallPattern::ParserAdvanceCall { witness: p.clone() }) - } - RankingDimension::SetCardinality { param: p, .. } => { - Rc::new(CallPattern::WorklistDrainCall { element: p.clone() }) - } - }, - None => Rc::new(CallPattern::SameArgumentCall), - } + Some(dim) => match (*dim.clone()).clone() { + RankingDimension::TreeSize { param: p, .. } => Rc::new(CallPattern::ChildAccessorCall { + accessor: p.clone(), +}), + RankingDimension::ListLength { param: p, .. } => Rc::new(CallPattern::CollectionShrinkCall { + amount: Rc::new(PositiveDescentAmount::OneStep), + collection: p.clone(), +}), + RankingDimension::ArithmeticValue { param: p, .. } => Rc::new(CallPattern::ArithmeticSubtractCall { + steps: Rc::new(PositiveDescentAmount::OneStep), + ring_param: p.clone(), +}), + RankingDimension::TokenPosition { param: p, .. } => Rc::new(CallPattern::ParserAdvanceCall { + witness: p.clone(), +}), + RankingDimension::SetCardinality { param: p, .. } => Rc::new(CallPattern::WorklistDrainCall { + element: p.clone(), +}), +}, + None => Rc::new(CallPattern::SameArgumentCall), +} } -pub fn classify_recursion_pattern( - func_name: &String, - body: &Rc, - params: &Rc>>, - parser_always_advancing: Rc>, - si: &Rc>>, -) -> Rc { +pub fn classify_recursion_pattern(func_name: &String, body: &Rc, params: &Rc>>, parser_always_advancing: Rc>, si: &Rc>>) -> Rc { { let path_calls = max_path_self_calls(body.clone(), func_name.clone(), si.clone()); - if (path_calls.clone() == 0) { +if (path_calls.clone() == 0) { { let outer = match params.clone().first().cloned() { - Some(p0) => param_node_name_at(p0.clone(), si.clone()), - None => "_fold_body".to_string(), - }; - lower_call_pattern(Rc::new(CallPattern::FoldBodyCall { - outer_collection: outer, - })) - } + Some(p0) => param_node_name_at(p0.clone(), si.clone()), + None => "_fold_body".to_string(), +}; +lower_call_pattern(Rc::new(CallPattern::FoldBodyCall { + outer_collection: outer, +})) +} } else { { - let all_evidence = - collect_self_call_evidence(body.clone(), func_name.clone(), si.clone()); - let has_evidence = ((all_evidence.clone().len() as i64) > 0); - let all_structural = (has_evidence && { - let mut __all = true; - for call_ev in all_evidence.clone().iter().cloned() { - if !({ - let mut __found = false; - for rel in call_ev.clone().iter().cloned() { - if match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { .. } => true, - SubValueRelation::IteratedSubValue { .. } => true, - SubValueRelation::ArithmeticDescent { .. } => true, - _ => false, - } { - __found = true; - break; - } - } - __found - }) { - __all = false; - break; - } - } - __all - }); - if all_structural { + let all_evidence = collect_self_call_evidence(body.clone(), func_name.clone(), si.clone()); +let has_evidence = ((all_evidence.clone().len() as i64) > 0); +let all_structural = (has_evidence && { let mut __all = true; for call_ev in all_evidence.clone().iter().cloned() { if !({ let mut __found = false; for rel in call_ev.clone().iter().cloned() { if match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { .. } => true, + SubValueRelation::IteratedSubValue { .. } => true, + SubValueRelation::ArithmeticDescent { .. } => true, + _ => false, +} { __found = true; break; } } __found }) { __all = false; break; } } __all }); +if all_structural { { - let all_calls_arithmetic_only = { - let mut __all = true; - for call_ev in all_evidence.clone().iter().cloned() { - if !({ - let has_tree = { - let mut __found = false; - for rel in call_ev.clone().iter().cloned() { - if match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { .. } => true, - SubValueRelation::IteratedSubValue { .. } => true, - _ => false, - } { - __found = true; - break; - } - } - __found - }; - let has_arith = { - let mut __found = false; - for rel in call_ev.clone().iter().cloned() { - if match (*rel.clone()).clone() { - SubValueRelation::ArithmeticDescent { .. } => true, - _ => false, - } { - __found = true; - break; - } - } - __found - }; - (has_arith.clone() && !has_tree.clone()) - }) { - __all = false; - break; - } - } - __all - }; - let first_call = if all_calls_arithmetic_only { - Rc::new({ - let mut __result = Vec::new(); - for call_ev in all_evidence.clone().iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for rel in call_ev.clone().iter().cloned() { - if match (*rel.clone()).clone() { - SubValueRelation::ArithmeticDescent { - .. - } => true, - _ => false, - } { - __result.push(rel); - } - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }) - .first() - .cloned() + let all_calls_arithmetic_only = { let mut __all = true; for call_ev in all_evidence.clone().iter().cloned() { if !({ + let has_tree = { let mut __found = false; for rel in call_ev.clone().iter().cloned() { if match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { .. } => true, + SubValueRelation::IteratedSubValue { .. } => true, + _ => false, +} { __found = true; break; } } __found }; +let has_arith = { let mut __found = false; for rel in call_ev.clone().iter().cloned() { if match (*rel.clone()).clone() { + SubValueRelation::ArithmeticDescent { .. } => true, + _ => false, +} { __found = true; break; } } __found }; +(has_arith.clone() && !has_tree.clone()) +}) { __all = false; break; } } __all }; +let first_call = if all_calls_arithmetic_only { + Rc::new({ let mut __result = Vec::new(); for call_ev in all_evidence.clone().iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for rel in call_ev.clone().iter().cloned() { if match (*rel.clone()).clone() { + SubValueRelation::ArithmeticDescent { .. } => true, + _ => false, +} { __result.push(rel); } } __result })).iter().cloned()); } __result }).first().cloned() } else { { - let tree_rels = - Rc::new({ - let mut __result = Vec::new(); - for call_ev in all_evidence.clone().iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for rel in call_ev.clone().iter().cloned() { - if match (*rel.clone()).clone() { + let tree_rels = Rc::new({ let mut __result = Vec::new(); for call_ev in all_evidence.clone().iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for rel in call_ev.clone().iter().cloned() { if match (*rel.clone()).clone() { SubValueRelation::StrictSubValue { .. } => true, SubValueRelation::IteratedSubValue { .. } => true, _ => false, -} { __result.push(rel); } - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }); - match tree_rels.clone().first().cloned() { - Some(_) => tree_rels.clone().first().cloned(), - None => Rc::new({ - let mut __result = Vec::new(); - for call_ev in all_evidence.clone().iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for rel in call_ev.clone().iter().cloned() { - if match (*rel.clone()).clone() { +} { __result.push(rel); } } __result })).iter().cloned()); } __result }); +match tree_rels.clone().first().cloned() { + Some(_) => tree_rels.clone().first().cloned(), + None => Rc::new({ let mut __result = Vec::new(); for call_ev in all_evidence.clone().iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for rel in call_ev.clone().iter().cloned() { if match (*rel.clone()).clone() { SubValueRelation::ArithmeticDescent { .. } => true, _ => false, -} { __result.push(rel); } - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }) - .first() - .cloned(), - } - } - }; - let is_arithmetic_branching = match first_call.clone() { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::ArithmeticDescent { .. } => { - (path_calls.clone() > 1) - } - _ => false, - }, - None => false, +} { __result.push(rel); } } __result })).iter().cloned()); } __result }).first().cloned(), +} +} }; - if is_arithmetic_branching { +let is_arithmetic_branching = match first_call.clone() { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::ArithmeticDescent { .. } => (path_calls.clone() > 1), + _ => false, +}, + None => false, +}; +if is_arithmetic_branching { lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) } else { match first_call.clone() { - Some(rel) => match sub_value_to_lowering_target(rel.clone()) { - Some(target) => target.clone(), - None => { - lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) - } - }, - None => lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)), - } + Some(rel) => match sub_value_to_lowering_target(rel.clone()) { + Some(target) => target.clone(), + None => lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)), +}, + None => lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)), +} } - } +} } else { { - let proof = construct_termination_proof( - &func_name, - &body, - ¶ms, - parser_always_advancing, - &si, - ); - let proof_safe_for_branching = match proof.clone() { - Some(p) => { - if ((p.dimensions.clone().len() as i64) == 0) { - false - } else { - { - let mut __all = true; - for dim in p.dimensions.clone().iter().cloned() { - if !(match (*dim.clone()).clone() { - RankingDimension::TreeSize { .. } => true, - RankingDimension::ListLength { .. } => true, - _ => false, - }) { - __all = false; - break; - } - } - __all - } - } - } - None => false, - }; - let branching_proof = - if ((path_calls.clone() > 1) && !proof_safe_for_branching.clone()) { - construct_branching_termination_proof( - func_name.clone(), - body.clone(), - params.clone(), - si.clone(), - ) - } else { - None - }; - let branching_proof_safe = match branching_proof.clone() { - Some(bp) => { - if ((bp.dimensions.clone().len() as i64) == 0) { - false - } else { - { - let mut __all = true; - for dim in bp.dimensions.clone().iter().cloned() { - if !(match (*dim.clone()).clone() { - RankingDimension::TreeSize { .. } => true, - RankingDimension::ListLength { .. } => true, - _ => false, - }) { - __all = false; - break; - } - } - __all - } - } - } - None => false, + let proof = construct_termination_proof(&func_name, &body, ¶ms, parser_always_advancing, &si); +let proof_safe_for_branching = match proof.clone() { + Some(p) => if ((p.dimensions.clone().len() as i64) == 0) { + false + } else { + { let mut __all = true; for dim in p.dimensions.clone().iter().cloned() { if !(match (*dim.clone()).clone() { + RankingDimension::TreeSize { .. } => true, + RankingDimension::ListLength { .. } => true, + _ => false, +}) { __all = false; break; } } __all } + }, + None => false, +}; +let branching_proof = if ((path_calls.clone() > 1) && !proof_safe_for_branching.clone()) { + construct_branching_termination_proof(func_name.clone(), body.clone(), params.clone(), si.clone()) + } else { + None }; - match proof.clone() { - Some(p) => { - if ((path_calls.clone() == 1) || proof_safe_for_branching.clone()) { - lower_call_pattern(proof_to_call_pattern(p.clone())) - } else { - if branching_proof_safe { - match branching_proof.clone() { - Some(bp) => lower_call_pattern(proof_to_call_pattern( - bp.clone(), - )), - None => lower_call_pattern(Rc::new( - CallPattern::SameArgumentCall, - )), - } - } else { - lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) - } - } - } - None => { - if (path_calls.clone() > 1) { - match branching_proof.clone() { - Some(bp) => { - if branching_proof_safe { - lower_call_pattern(proof_to_call_pattern( - bp.clone(), - )) - } else { - lower_call_pattern(Rc::new( - CallPattern::SameArgumentCall, - )) - } - } - None => lower_call_pattern(Rc::new( - CallPattern::SameArgumentCall, - )), - } - } else { - lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) - } +let branching_proof_safe = match branching_proof.clone() { + Some(bp) => if ((bp.dimensions.clone().len() as i64) == 0) { + false + } else { + { let mut __all = true; for dim in bp.dimensions.clone().iter().cloned() { if !(match (*dim.clone()).clone() { + RankingDimension::TreeSize { .. } => true, + RankingDimension::ListLength { .. } => true, + _ => false, +}) { __all = false; break; } } __all } + }, + None => false, +}; +match proof.clone() { + Some(p) => if ((path_calls.clone() == 1) || proof_safe_for_branching.clone()) { + lower_call_pattern(proof_to_call_pattern(p.clone())) + } else { + if branching_proof_safe { + match branching_proof.clone() { + Some(bp) => lower_call_pattern(proof_to_call_pattern(bp.clone())), + None => lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)), +} + } else { + lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) } - } - } + }, + None => if (path_calls.clone() > 1) { + match branching_proof.clone() { + Some(bp) => if branching_proof_safe { + lower_call_pattern(proof_to_call_pattern(bp.clone())) + } else { + lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) + }, + None => lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)), +} + } else { + lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) + }, +} +} } - } +} } - } +} } -pub fn bounded_recursive_cost( - target: Rc, - per_iter: Rc, - func_name: String, -) -> Rc { +pub fn bounded_recursive_cost(target: Rc, per_iter: Rc, func_name: String) -> Rc { { let p = size_bound_param(target.bound.clone()); - match p { - Some(v) => { - let var = v2_rt::concat("n_".to_string(), v.clone()); - Rc::new(CostExpr::CostSum { - binder: var.clone(), - upper: Rc::new(SizeExpr::SizeVar { name: var.clone() }), - body: simplify_cost(per_iter), - }) - } - None => Rc::new(CostExpr::CostUnknown { - reason: v2_rt::concat("same-argument recursion in ".to_string(), func_name), - }), - } - } +match p { + Some(v) => { + let var = v2_rt::concat("n_".to_string(), v.clone()); +Rc::new(CostExpr::CostSum { + binder: var.clone(), + upper: Rc::new(SizeExpr::SizeVar { + name: var.clone(), +}), + body: simplify_cost(per_iter), +}) +}, + None => Rc::new(CostExpr::CostUnknown { + reason: v2_rt::concat("same-argument recursion in ".to_string(), func_name), +}), +} +} } -pub fn bounded_scc_cost( - target: Rc, - per_iter: Rc, - members: Rc>, -) -> Rc { +pub fn bounded_scc_cost(target: Rc, per_iter: Rc, members: Rc>) -> Rc { { let p = size_bound_param(target.bound.clone()); - match p { - Some(v) => { - let var = v2_rt::concat("n_".to_string(), v.clone()); - Rc::new(CostExpr::CostSum { - binder: var.clone(), - upper: Rc::new(SizeExpr::SizeVar { name: var.clone() }), - body: simplify_cost(per_iter), - }) - } - None => Rc::new(CostExpr::CostUnknown { - reason: v2_rt::concat( - "same-argument mutual recursion in ".to_string(), - match members.first().cloned() { - Some(n) => n.clone(), - None => "scc".to_string(), - }, - ), - }), - } - } +match p { + Some(v) => { + let var = v2_rt::concat("n_".to_string(), v.clone()); +Rc::new(CostExpr::CostSum { + binder: var.clone(), + upper: Rc::new(SizeExpr::SizeVar { + name: var.clone(), +}), + body: simplify_cost(per_iter), +}) +}, + None => Rc::new(CostExpr::CostUnknown { + reason: v2_rt::concat("same-argument mutual recursion in ".to_string(), match members.first().cloned() { + Some(n) => n.clone(), + None => "scc".to_string(), +}), +}), +} +} } pub fn is_unknown_cost(expr: Rc) -> bool { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*expr).clone() { - CostExpr::CostUnknown { .. } => true, - CostExpr::CostAdd { - left: l, right: r, .. - } => (is_unknown_cost(l.clone()) || is_unknown_cost(r.clone())), - CostExpr::CostMul { - left: l, right: r, .. - } => (is_unknown_cost(l.clone()) || is_unknown_cost(r.clone())), - CostExpr::CostMax { - left: l, right: r, .. - } => (is_unknown_cost(l.clone()) || is_unknown_cost(r.clone())), - CostExpr::CostSum { body: bd, .. } => is_unknown_cost(bd.clone()), - _ => false, + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*expr).clone() { + CostExpr::CostUnknown { .. } => true, + CostExpr::CostAdd { left: l, right: r, .. } => (is_unknown_cost(l.clone()) || is_unknown_cost(r.clone())), + CostExpr::CostMul { left: l, right: r, .. } => (is_unknown_cost(l.clone()) || is_unknown_cost(r.clone())), + CostExpr::CostMax { left: l, right: r, .. } => (is_unknown_cost(l.clone()) || is_unknown_cost(r.clone())), + CostExpr::CostSum { body: bd, .. } => is_unknown_cost(bd.clone()), + _ => false, +} }) } pub fn extract_unknown_reason(mut expr: Rc) -> String { loop { match (*expr).clone() { - CostExpr::CostUnknown { reason: r, .. } => { - break r.clone(); - } - CostExpr::CostAdd { - left: l, right: r, .. - } => { - if is_unknown_cost(l.clone()) { - { - let __tco_0 = l.clone(); - expr = __tco_0; - continue; - } - } else { - { - let __tco_0 = r.clone(); - expr = __tco_0; - continue; - } - } - } - CostExpr::CostMul { - left: l, right: r, .. - } => { - if is_unknown_cost(l.clone()) { - { - let __tco_0 = l.clone(); - expr = __tco_0; - continue; - } - } else { - { - let __tco_0 = r.clone(); - expr = __tco_0; - continue; - } - } - } - CostExpr::CostMax { - left: l, right: r, .. - } => { - if is_unknown_cost(l.clone()) { - { - let __tco_0 = l.clone(); - expr = __tco_0; - continue; - } - } else { - { - let __tco_0 = r.clone(); - expr = __tco_0; - continue; - } - } - } - CostExpr::CostSum { body: bd, .. } => { - let __tco_0 = bd.clone(); - expr = __tco_0; - continue; - } - _ => { - break "unknown".to_string(); - } - } - } + CostExpr::CostUnknown { reason: r, .. } => { break r.clone(); }, + CostExpr::CostAdd { left: l, right: r, .. } => { if is_unknown_cost(l.clone()) { + { + let __tco_0 = l.clone(); +expr = __tco_0; +continue; +} +} else { + { + let __tco_0 = r.clone(); +expr = __tco_0; +continue; +} +} }, + CostExpr::CostMul { left: l, right: r, .. } => { if is_unknown_cost(l.clone()) { + { + let __tco_0 = l.clone(); +expr = __tco_0; +continue; +} +} else { + { + let __tco_0 = r.clone(); +expr = __tco_0; +continue; +} +} }, + CostExpr::CostMax { left: l, right: r, .. } => { if is_unknown_cost(l.clone()) { + { + let __tco_0 = l.clone(); +expr = __tco_0; +continue; +} +} else { + { + let __tco_0 = r.clone(); +expr = __tco_0; +continue; +} +} }, + CostExpr::CostSum { body: bd, .. } => { { + let __tco_0 = bd.clone(); +expr = __tco_0; +continue; +} }, + _ => { break "unknown".to_string(); }, +} +} } -pub fn collect_local_call_edges_in_expr( - caller: &String, - body: &Rc, - local_func_set: &Rc>, - si: &Rc>>, -) -> Rc>> { +pub fn collect_local_call_edges_in_expr(caller: &String, body: &Rc, local_func_set: &Rc>, si: &Rc>>) -> Rc>> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let this_edges = match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { + { + let this_edges = match (*body.expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { let callee = expr_call_func_at(body.clone(), si.clone()); - if set_has(local_func_set.clone(), callee.clone()) { +if set_has(local_func_set.clone(), callee.clone()) { Rc::new(vec![Rc::new(CallEdge { - caller: caller.clone(), - callee: callee.clone(), - })]) + caller: caller.clone(), + callee: callee.clone(), +})]) } else { Rc::new(vec![]) } - } - _ => Rc::new(vec![]), - }; - let child_edges = Rc::new({ - let mut __result = Vec::new(); - for child in body.children.clone().iter().cloned() { - __result.extend( - (*collect_local_call_edges_in_expr(&caller, &child, &local_func_set, &si)) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat(this_edges, child_edges) +}, + _ => Rc::new(vec![]), +}; +let child_edges = Rc::new({ let mut __result = Vec::new(); for child in body.children.clone().iter().cloned() { __result.extend((*collect_local_call_edges_in_expr(&caller, &child, &local_func_set, &si)).iter().cloned()); } __result }); +v2_rt::concat(this_edges, child_edges) +} }) } -pub fn build_call_graph( - func_entries: &Rc>>, - si: Rc>>, -) -> Rc { +pub fn build_call_graph(func_entries: &Rc>>, si: Rc>>) -> Rc { { - let names = Rc::new({ - let mut __result = Vec::new(); - for entry in func_entries.clone().iter().cloned() { - __result.push(entry.name.clone()); - } - __result - }); - let local_func_set = names.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let edges = Rc::new({ - let mut __result = Vec::new(); - for entry in func_entries.clone().iter().cloned() { - __result.extend( - (*collect_local_call_edges_in_expr( - &entry.name.clone(), - &entry.body.clone(), - &local_func_set, - &si, - )) - .iter() - .cloned(), - ); - } - __result - }); - let initial_forward = seed_adjacency_map(names.clone()); - let initial_reverse = seed_adjacency_map(names.clone()); - edges.iter().cloned().fold( - Rc::new(CallGraph { - forward: initial_forward, - reverse: initial_reverse, - }), - |acc: Rc, edge: Rc| { - let forward_neighbors = - match v2_rt::map_get(&acc.forward.clone(), edge.caller.clone()) { - Some(ns) => ns.clone(), - None => Rc::new(vec![]), - }; - let reverse_neighbors = - match v2_rt::map_get(&acc.reverse.clone(), edge.callee.clone()) { - Some(ns) => ns.clone(), - None => Rc::new(vec![]), - }; - Rc::new(CallGraph { - forward: v2_rt::rc_map_insert( - acc.forward.clone(), - edge.caller.clone(), - v2_rt::rc_list_push(forward_neighbors.clone(), edge.callee.clone()), - ), - reverse: v2_rt::rc_map_insert( - acc.reverse.clone(), - edge.callee.clone(), - v2_rt::rc_list_push(reverse_neighbors.clone(), edge.caller.clone()), - ), - }) - }, - ) - } + let names = Rc::new({ let mut __result = Vec::new(); for entry in func_entries.clone().iter().cloned() { __result.push(entry.name.clone()); } __result }); +let local_func_set = names.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let edges = Rc::new({ let mut __result = Vec::new(); for entry in func_entries.clone().iter().cloned() { __result.extend((*collect_local_call_edges_in_expr(&entry.name.clone(), &entry.body.clone(), &local_func_set, &si)).iter().cloned()); } __result }); +let initial_forward = seed_adjacency_map(names.clone()); +let initial_reverse = seed_adjacency_map(names.clone()); +edges.iter().cloned().fold(Rc::new(CallGraph { + forward: initial_forward, + reverse: initial_reverse, +}), |acc: Rc, edge: Rc| { + let forward_neighbors = match v2_rt::map_get(&acc.forward.clone(), edge.caller.clone()) { + Some(ns) => ns.clone(), + None => Rc::new(vec![]), +}; +let reverse_neighbors = match v2_rt::map_get(&acc.reverse.clone(), edge.callee.clone()) { + Some(ns) => ns.clone(), + None => Rc::new(vec![]), +}; +Rc::new(CallGraph { + forward: v2_rt::rc_map_insert(acc.forward.clone(), edge.caller.clone(), v2_rt::rc_list_push(forward_neighbors.clone(), edge.callee.clone())), + reverse: v2_rt::rc_map_insert(acc.reverse.clone(), edge.callee.clone(), v2_rt::rc_list_push(reverse_neighbors.clone(), edge.caller.clone())), +}) +}) +} } pub fn scc_label(members: Rc>) -> String { match members.first().cloned() { - Some(name) => name.clone(), - None => "scc".to_string(), - } + Some(name) => name.clone(), + None => "scc".to_string(), +} } -pub fn classify_scc_call_progress( - arg_expr: &Rc, - param_name: &String, - descent_vars: &Rc>, - si: &Rc>>, -) -> DescentEvidence { +pub fn classify_scc_call_progress(arg_expr: &Rc, param_name: &String, descent_vars: &Rc>, si: &Rc>>) -> DescentEvidence { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { if is_child_descent_expr(&arg_expr, ¶m_name, &descent_vars, &si) { DescentEvidence::Strict @@ -5586,715 +2756,314 @@ pub fn classify_scc_call_progress( DescentEvidence::Strict } else { match (*arg_expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at(arg_expr.clone(), si.clone()); - if set_has(descent_vars.clone(), vname.clone()) { - DescentEvidence::Strict + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(arg_expr.clone(), si.clone()); +if set_has(descent_vars.clone(), vname.clone()) { + DescentEvidence::Strict + } else { + if (vname.clone().as_str() == param_name.clone().as_str()) { + DescentEvidence::NonIncreasing } else { - if (vname.clone().as_str() == param_name.clone().as_str()) { - DescentEvidence::NonIncreasing - } else { - DescentEvidence::DescentUnknown - } + DescentEvidence::DescentUnknown } } - ExprData::ExprCall { .. } => { - if is_tree_size_preserving_wrapper(&arg_expr, si.clone()) { - classify_scc_call_progress( - &wrapper_inner_arg(arg_expr.clone()), - ¶m_name, - &descent_vars, - &si, - ) +}, + ExprData::ExprCall { .. } => if is_tree_size_preserving_wrapper(&arg_expr, si.clone()) { + classify_scc_call_progress(&wrapper_inner_arg(arg_expr.clone()), ¶m_name, &descent_vars, &si) + } else { + if is_sub_value_extractor(&arg_expr, si.clone()) { + { + let inner_progress = classify_scc_call_progress(&extractor_inner_arg(arg_expr.clone()), ¶m_name, &descent_vars, &si); +match inner_progress.clone() { + DescentEvidence::NonIncreasing => DescentEvidence::Strict, + _ => inner_progress.clone(), +} +} + } else { + if is_list_passthrough_call(arg_expr.clone(), si.clone()) { + match list_passthrough_inner_arg(arg_expr.clone(), si.clone()) { + Some(inner) => classify_scc_call_progress(&inner, ¶m_name, &descent_vars, &si), + None => DescentEvidence::DescentUnknown, +} } else { - if is_sub_value_extractor(&arg_expr, si.clone()) { - { - let inner_progress = classify_scc_call_progress( - &extractor_inner_arg(arg_expr.clone()), - ¶m_name, - &descent_vars, - &si, - ); - match inner_progress.clone() { - DescentEvidence::NonIncreasing => DescentEvidence::Strict, - _ => inner_progress.clone(), - } - } - } else { - if is_list_passthrough_call(arg_expr.clone(), si.clone()) { - match list_passthrough_inner_arg(arg_expr.clone(), si.clone()) { - Some(inner) => classify_scc_call_progress( - &inner, - ¶m_name, - &descent_vars, - &si, - ), - None => DescentEvidence::DescentUnknown, - } - } else { - DescentEvidence::DescentUnknown - } - } - } - } - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(arg_expr.clone()); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at(base.clone(), si.clone()); - if (set_has(descent_vars.clone(), bname.clone()) - || (bname.clone().as_str() == param_name.clone().as_str())) - { - DescentEvidence::Strict - } else { - { - let field = - field_access_field_at(arg_expr.clone(), si.clone()); - if (field.as_str() == param_name.clone().as_str()) { - DescentEvidence::NonIncreasing - } else { - DescentEvidence::DescentUnknown - } - } - } - } - _ => DescentEvidence::DescentUnknown, + DescentEvidence::DescentUnknown } } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - if is_generalized_shrink(&arg_expr, si.clone()) { + }, + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(arg_expr.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), si.clone()); +if (set_has(descent_vars.clone(), bname.clone()) || (bname.clone().as_str() == param_name.clone().as_str())) { + DescentEvidence::Strict + } else { { - let recv = method_receiver(arg_expr.clone()); - let recv_progress = classify_scc_call_progress( - &recv, - ¶m_name, - &descent_vars, - &si, - ); - match recv_progress { - DescentEvidence::Strict => DescentEvidence::Strict, - DescentEvidence::NonIncreasing => DescentEvidence::Strict, - DescentEvidence::DescentUnknown => { - DescentEvidence::DescentUnknown - } + let field = field_access_field_at(arg_expr.clone(), si.clone()); +if (field.as_str() == param_name.clone().as_str()) { + DescentEvidence::NonIncreasing + } else { + DescentEvidence::DescentUnknown } - } - } else { - DescentEvidence::DescentUnknown +} } - } - _ => DescentEvidence::DescentUnknown, - } +}, + _ => DescentEvidence::DescentUnknown, +} +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => if is_generalized_shrink(&arg_expr, si.clone()) { + { + let recv = method_receiver(arg_expr.clone()); +let recv_progress = classify_scc_call_progress(&recv, ¶m_name, &descent_vars, &si); +match recv_progress { + DescentEvidence::Strict => DescentEvidence::Strict, + DescentEvidence::NonIncreasing => DescentEvidence::Strict, + DescentEvidence::DescentUnknown => DescentEvidence::DescentUnknown, +} +} + } else { + DescentEvidence::DescentUnknown + }, + _ => DescentEvidence::DescentUnknown, +} } } }) } -pub fn collect_scc_child_edges( - body: &Rc, - caller: &String, - param_name: &String, - descent_vars: &Rc>, - target_set: &Rc>, - check_child: bool, - check_list: bool, - scc_measure_params: &Rc>>>, - si: &Rc>>, -) -> Rc>> { +pub fn collect_scc_child_edges(body: &Rc, caller: &String, param_name: &String, descent_vars: &Rc>, target_set: &Rc>, check_child: bool, check_list: bool, scc_measure_params: &Rc>>>, si: &Rc>>) -> Rc>> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprLambda => Rc::new(vec![]), - ExprData::ExprCall { .. } => { - let callee = expr_call_func_at(body.clone(), si.clone()); - let own_edges = if set_has(target_set.clone(), callee.clone()) { - { - let callee_params = - match v2_rt::map_get(&scc_measure_params, callee.clone()) { - Some(p) => p.clone(), - None => v2_rt::rc_empty_map::(), - }; - let progress = body.children.clone().iter().cloned().fold( - DescentEvidence::DescentUnknown, - |acc: DescentEvidence, arg_node: Rc| { - let targets_measure = - match arg_name_at(arg_node.clone(), si.clone()) { - Some(aname) => { - (v2_rt::map_get(&callee_params, aname.clone()) != None) - } - None => false, - }; - if targets_measure.clone() { - { - let arg_progress = classify_scc_call_progress( - &arg_value(&arg_node), - ¶m_name, - &descent_vars, - &si, - ); - match arg_progress.clone() { - DescentEvidence::Strict => DescentEvidence::Strict, - DescentEvidence::NonIncreasing => match acc.clone() { - DescentEvidence::Strict => acc.clone(), - _ => DescentEvidence::NonIncreasing, - }, - DescentEvidence::DescentUnknown => acc.clone(), - } - } - } else { - acc.clone() - } - }, - ); - Rc::new(vec![Rc::new(ParserProgressEdge { - caller: caller.clone(), - callee: callee.clone(), - progress: progress, - })]) - } - } else { - Rc::new(vec![]) - }; - let child_edges = Rc::new({ - let mut __result = Vec::new(); - for child in body.children.clone().iter().cloned() { - __result.extend( - (*collect_scc_child_edges( - &child, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - )) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat(own_edges, child_edges) - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let receiver = method_receiver(body.clone()); - let is_iter = is_algebra_iteration_method(ms.clone()); - let is_struct = is_structural_children(&receiver, ¶m_name, &descent_vars, &si); - if (is_iter && is_struct) { - { - let recv_edges = collect_scc_child_edges( - &receiver, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ); - let args_edges = Rc::new({ - let mut __result = Vec::new(); - for arg_node in method_arg_nodes(body.clone()).iter().cloned() { - __result.extend( - (*{ - let arg_val = arg_value(&arg_node); - match (*arg_val.expr_data.clone()).clone() { - ExprData::ExprLambda => match iteration_element_name( - ms.clone(), - arg_val.clone(), - si.clone(), - ) { - Some(iter_name) => { - let ext_vars = v2_rt::rc_map_insert( - descent_vars.clone(), - iter_name.clone(), - true, - ); - collect_scc_child_edges( - &lambda_body(arg_val.clone()), - &caller, - ¶m_name, - &ext_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ) - } - None => Rc::new(vec![]), - }, - _ => collect_scc_child_edges( - &arg_val, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ), - } - }) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat(recv_edges, args_edges) - } - } else { - Rc::new({ - let mut __result = Vec::new(); - for child in body.children.clone().iter().cloned() { - __result.extend( - (*collect_scc_child_edges( - &child, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - )) - .iter() - .cloned(), - ); - } - __result - }) - } - } - ExprData::ExprLet => { - let val = let_value(body.clone()); - let val_edges = collect_scc_child_edges( - &val, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ); - let is_direct = ((check_child.clone() - && is_child_descent_expr(&val, ¶m_name, &descent_vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&val, param_name.clone(), si.clone()))); - let is_var = match (*val.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => set_has( - descent_vars.clone(), - expr_var_name_at(val.clone(), si.clone()), - ), - _ => false, - }; - let is_option = is_if_option_descent( - &val, - param_name.clone(), - descent_vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - let is_match_descent = is_match_option_descent( - &val, - ¶m_name, - descent_vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - let is_wrapped = if is_tree_size_preserving_wrapper(&val, si.clone()) { - { - let inner = wrapper_inner_arg(val.clone()); - let inner_d = ((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &descent_vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); - let inner_v = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => set_has( - descent_vars.clone(), - expr_var_name_at(inner.clone(), si.clone()), - ), - _ => false, - }; - (inner_d.clone() || inner_v.clone()) - } - } else { - false - }; - let is_extraction = if is_sub_value_extractor(&val, si.clone()) { - { - let inner = extractor_inner_arg(val.clone()); - let inner_d = ((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &descent_vars, &si)) - || (check_list.clone() - && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); - let inner_v = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => set_has( - descent_vars.clone(), - expr_var_name_at(inner.clone(), si.clone()), - ), - _ => false, - }; - let inner_p = match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(inner.clone(), si.clone()).as_str() - == param_name.clone().as_str()) - } - _ => false, - }; - ((inner_d.clone() || inner_v.clone()) || inner_p) - } - } else { - false - }; - let is_children_list = match (*val.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(val.clone()); - let field = field_access_field_at(val.clone(), si.clone()); - (is_children_list_field(field) - && match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at(base.clone(), si.clone()); - ((bname.clone().as_str() == param_name.clone().as_str()) - || set_has(descent_vars.clone(), bname.clone())) - } - _ => false, - }) - } - _ => false, - }; - let is_passthrough = if is_list_passthrough_call(val.clone(), si.clone()) { - match list_passthrough_inner_arg(val.clone(), si.clone()) { - Some(inner) => { - (((check_child.clone() - && is_child_descent_expr(&inner, ¶m_name, &descent_vars, &si)) - || (check_list.clone() - && is_list_shrink_expr( - &inner, - param_name.clone(), - si.clone(), - ))) - || match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => set_has( - descent_vars.clone(), - expr_var_name_at(inner.clone(), si.clone()), - ), - _ => false, - }) - } - None => false, - } - } else { - false - }; - let is_consuming_helper = (check_list.clone() - && is_tokens_consuming_call( - &val, - param_name.clone(), - descent_vars.clone(), - &si, - )); - let next_vars = if ((((((((is_direct || is_var) || is_option) - || is_match_descent) - || is_wrapped) - || is_extraction) - || is_children_list) - || is_passthrough) - || is_consuming_helper) + ExprData::ExprLambda => Rc::new(vec![]), + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(body.clone(), si.clone()); +let own_edges = if set_has(target_set.clone(), callee.clone()) { { - v2_rt::rc_map_insert( - descent_vars.clone(), - let_binding_name_at(body.clone(), si.clone()), - true, - ) - } else { - descent_vars.clone() - }; - let body_edges = match let_body(body.clone()) { - Some(b) => collect_scc_child_edges( - &b, - &caller, - ¶m_name, - &next_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ), - None => Rc::new(vec![]), - }; - v2_rt::concat(val_edges, body_edges) - } - ExprData::ExprMatch => { - let scrut = match_scrutinee(body.clone()); - let scrut_edges = collect_scc_child_edges( - &scrut, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ); - let arms_edges = Rc::new({ - let mut __result = Vec::new(); - for arm_node in match_arm_nodes(body.clone()).iter().cloned() { - __result.extend( - (*collect_scc_child_edges( - &arm_body(&arm_node), - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - )) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat(scrut_edges, arms_edges) - } - ExprData::ExprBlock => { - let result = body.children.clone().iter().cloned().fold( - Rc::new(SccEdgeBlockAcc { - edges: Rc::new(vec![]), - vars: descent_vars.clone(), - }), - |acc: Rc, stmt: Rc| { - let stmt_edges = collect_scc_child_edges( - &stmt, - &caller, - ¶m_name, - &acc.vars.clone(), - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ); - let next_vars = collect_descent_vars( - &stmt, - ¶m_name, - &acc.vars.clone(), - check_child.clone(), - check_list.clone(), - &si, - ); - Rc::new(SccEdgeBlockAcc { - edges: v2_rt::concat(acc.edges.clone(), stmt_edges.clone()), - vars: next_vars.clone(), - }) - }, - ); - result.edges.clone() - } - ExprData::ExprIf => { - let cond_edges = collect_scc_child_edges( - &if_condition(body.clone()), - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ); - let then_branch = if_then_branch(body.clone()); - let else_opt = if_else_branch(body.clone()); - let then_edges = collect_scc_child_edges( - &then_branch, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ); - let else_edges = match else_opt { - Some(eb) => collect_scc_child_edges( - &eb, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - ), - None => Rc::new(vec![]), - }; - v2_rt::concat(cond_edges, v2_rt::concat(then_edges, else_edges)) + let callee_params = match v2_rt::map_get(&scc_measure_params, callee.clone()) { + Some(p) => p.clone(), + None => v2_rt::rc_empty_map::(), +}; +let progress = body.children.clone().iter().cloned().fold(DescentEvidence::DescentUnknown, |acc: DescentEvidence, arg_node: Rc| { + let targets_measure = match arg_name_at(arg_node.clone(), si.clone()) { + Some(aname) => (v2_rt::map_get(&callee_params, aname.clone()) != None), + None => false, +}; +if targets_measure.clone() { + { + let arg_progress = classify_scc_call_progress(&arg_value(&arg_node), ¶m_name, &descent_vars, &si); +match arg_progress.clone() { + DescentEvidence::Strict => DescentEvidence::Strict, + DescentEvidence::NonIncreasing => match acc.clone() { + DescentEvidence::Strict => acc.clone(), + _ => DescentEvidence::NonIncreasing, +}, + DescentEvidence::DescentUnknown => acc.clone(), +} +} + } else { + acc.clone() + } +}); +Rc::new(vec![Rc::new(ParserProgressEdge { + caller: caller.clone(), + callee: callee.clone(), + progress: progress, +})]) +} + } else { + Rc::new(vec![]) + }; +let child_edges = Rc::new({ let mut __result = Vec::new(); for child in body.children.clone().iter().cloned() { __result.extend((*collect_scc_child_edges(&child, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si)).iter().cloned()); } __result }); +v2_rt::concat(own_edges, child_edges) +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let receiver = method_receiver(body.clone()); +let is_iter = is_algebra_iteration_method(ms.clone()); +let is_struct = is_structural_children(&receiver, ¶m_name, &descent_vars, &si); +if (is_iter && is_struct) { + { + let recv_edges = collect_scc_child_edges(&receiver, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si); +let args_edges = Rc::new({ let mut __result = Vec::new(); for arg_node in method_arg_nodes(body.clone()).iter().cloned() { __result.extend((*{ + let arg_val = arg_value(&arg_node); +match (*arg_val.expr_data.clone()).clone() { + ExprData::ExprLambda => match iteration_element_name(ms.clone(), arg_val.clone(), si.clone()) { + Some(iter_name) => { + let ext_vars = v2_rt::rc_map_insert(descent_vars.clone(), iter_name.clone(), true); +collect_scc_child_edges(&lambda_body(arg_val.clone()), &caller, ¶m_name, &ext_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si) +}, + None => Rc::new(vec![]), +}, + _ => collect_scc_child_edges(&arg_val, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si), +} +}).iter().cloned()); } __result }); +v2_rt::concat(recv_edges, args_edges) +} + } else { + Rc::new({ let mut __result = Vec::new(); for child in body.children.clone().iter().cloned() { __result.extend((*collect_scc_child_edges(&child, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si)).iter().cloned()); } __result }) } - _ => Rc::new({ - let mut __result = Vec::new(); - for child in body.children.clone().iter().cloned() { - __result.extend( - (*collect_scc_child_edges( - &child, - &caller, - ¶m_name, - &descent_vars, - &target_set, - check_child.clone(), - check_list.clone(), - &scc_measure_params, - &si, - )) - .iter() - .cloned(), - ); - } - __result - }), - } +}, + ExprData::ExprLet => { + let val = let_value(body.clone()); +let val_edges = collect_scc_child_edges(&val, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si); +let is_direct = ((check_child.clone() && is_child_descent_expr(&val, ¶m_name, &descent_vars, &si)) || (check_list.clone() && is_list_shrink_expr(&val, param_name.clone(), si.clone()))); +let is_var = match (*val.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(descent_vars.clone(), expr_var_name_at(val.clone(), si.clone())), + _ => false, +}; +let is_option = is_if_option_descent(&val, param_name.clone(), descent_vars.clone(), check_child.clone(), check_list.clone(), &si); +let is_match_descent = is_match_option_descent(&val, ¶m_name, descent_vars.clone(), check_child.clone(), check_list.clone(), &si); +let is_wrapped = if is_tree_size_preserving_wrapper(&val, si.clone()) { + { + let inner = wrapper_inner_arg(val.clone()); +let inner_d = ((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &descent_vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); +let inner_v = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(descent_vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}; +(inner_d.clone() || inner_v.clone()) +} + } else { + false + }; +let is_extraction = if is_sub_value_extractor(&val, si.clone()) { + { + let inner = extractor_inner_arg(val.clone()); +let inner_d = ((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &descent_vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))); +let inner_v = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(descent_vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}; +let inner_p = match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(inner.clone(), si.clone()).as_str() == param_name.clone().as_str()), + _ => false, +}; +((inner_d.clone() || inner_v.clone()) || inner_p) +} + } else { + false + }; +let is_children_list = match (*val.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(val.clone()); +let field = field_access_field_at(val.clone(), si.clone()); +(is_children_list_field(field) && match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), si.clone()); +((bname.clone().as_str() == param_name.clone().as_str()) || set_has(descent_vars.clone(), bname.clone())) +}, + _ => false, +}) +}, + _ => false, +}; +let is_passthrough = if is_list_passthrough_call(val.clone(), si.clone()) { + match list_passthrough_inner_arg(val.clone(), si.clone()) { + Some(inner) => (((check_child.clone() && is_child_descent_expr(&inner, ¶m_name, &descent_vars, &si)) || (check_list.clone() && is_list_shrink_expr(&inner, param_name.clone(), si.clone()))) || match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => set_has(descent_vars.clone(), expr_var_name_at(inner.clone(), si.clone())), + _ => false, +}), + None => false, +} + } else { + false + }; +let is_consuming_helper = (check_list.clone() && is_tokens_consuming_call(&val, param_name.clone(), descent_vars.clone(), &si)); +let next_vars = if ((((((((is_direct || is_var) || is_option) || is_match_descent) || is_wrapped) || is_extraction) || is_children_list) || is_passthrough) || is_consuming_helper) { + v2_rt::rc_map_insert(descent_vars.clone(), let_binding_name_at(body.clone(), si.clone()), true) + } else { + descent_vars.clone() + }; +let body_edges = match let_body(body.clone()) { + Some(b) => collect_scc_child_edges(&b, &caller, ¶m_name, &next_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si), + None => Rc::new(vec![]), +}; +v2_rt::concat(val_edges, body_edges) +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(body.clone()); +let scrut_edges = collect_scc_child_edges(&scrut, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si); +let arms_edges = Rc::new({ let mut __result = Vec::new(); for arm_node in match_arm_nodes(body.clone()).iter().cloned() { __result.extend((*collect_scc_child_edges(&arm_body(&arm_node), &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si)).iter().cloned()); } __result }); +v2_rt::concat(scrut_edges, arms_edges) +}, + ExprData::ExprBlock => { + let result = body.children.clone().iter().cloned().fold(Rc::new(SccEdgeBlockAcc { + edges: Rc::new(vec![]), + vars: descent_vars.clone(), +}), |acc: Rc, stmt: Rc| { + let stmt_edges = collect_scc_child_edges(&stmt, &caller, ¶m_name, &acc.vars.clone(), &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si); +let next_vars = collect_descent_vars(&stmt, ¶m_name, &acc.vars.clone(), check_child.clone(), check_list.clone(), &si); +Rc::new(SccEdgeBlockAcc { + edges: v2_rt::concat(acc.edges.clone(), stmt_edges.clone()), + vars: next_vars.clone(), +}) +}); +result.edges.clone() +}, + ExprData::ExprIf => { + let cond_edges = collect_scc_child_edges(&if_condition(body.clone()), &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si); +let then_branch = if_then_branch(body.clone()); +let else_opt = if_else_branch(body.clone()); +let then_edges = collect_scc_child_edges(&then_branch, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si); +let else_edges = match else_opt { + Some(eb) => collect_scc_child_edges(&eb, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si), + None => Rc::new(vec![]), +}; +v2_rt::concat(cond_edges, v2_rt::concat(then_edges, else_edges)) +}, + _ => Rc::new({ let mut __result = Vec::new(); for child in body.children.clone().iter().cloned() { __result.extend((*collect_scc_child_edges(&child, &caller, ¶m_name, &descent_vars, &target_set, check_child.clone(), check_list.clone(), &scc_measure_params, &si)).iter().cloned()); } __result }), +} }) } -pub fn is_scc_container_child_descent( - members: &Rc>, - func_index: &Rc>>, - scc_name_set: Rc>, - si: &Rc>>, -) -> bool { +pub fn is_scc_container_child_descent(members: &Rc>, func_index: &Rc>>, scc_name_set: Rc>, si: &Rc>>) -> bool { { - let measure_params = - build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); - let edges = Rc::new({ - let mut __result = Vec::new(); - for name in members.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&func_index, name.clone()) { - Some(entry) => { - let best_edges = entry.params.clone().iter().cloned().fold( - Rc::new(vec![]), - |best: _, p: Rc| { - let pname = param_node_name_at(p.clone(), si.clone()); - let descent_vars = collect_descent_vars( - &entry.body.clone(), - &pname, - &v2_rt::rc_empty_map::(), - true, - true, - &si, - ); - let param_edges = collect_scc_child_edges( - &entry.body.clone(), - &name, - &pname, - &descent_vars, - &scc_name_set, - true, - true, - &measure_params, - &si, - ); - let unknown_count = - count_unknown_progress_edges(param_edges.clone()); - let best_unknown = count_unknown_progress_edges(best.clone()); - if (((best.clone().len() as i64) == 0) - || (unknown_count.clone() < best_unknown.clone())) - { - param_edges.clone() - } else { - best.clone() - } - }, - ); - best_edges.clone() - } - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let unknown_edge_count = count_unknown_progress_edges(edges.clone()); - (((unknown_edge_count == 0) && ((edges.clone().len() as i64) > 0)) - && (same_progress_subgraph_has_cycle(&members, edges.clone()) == false)) - } + let measure_params = build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); +let edges = Rc::new({ let mut __result = Vec::new(); for name in members.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => { + let best_edges = entry.params.clone().iter().cloned().fold(Rc::new(vec![]), |best: _, p: Rc| { + let pname = param_node_name_at(p.clone(), si.clone()); +let descent_vars = collect_descent_vars(&entry.body.clone(), &pname, &v2_rt::rc_empty_map::(), true, true, &si); +let param_edges = collect_scc_child_edges(&entry.body.clone(), &name, &pname, &descent_vars, &scc_name_set, true, true, &measure_params, &si); +let unknown_count = count_unknown_progress_edges(param_edges.clone()); +let best_unknown = count_unknown_progress_edges(best.clone()); +if (((best.clone().len() as i64) == 0) || (unknown_count.clone() < best_unknown.clone())) { + param_edges.clone() + } else { + best.clone() + } +}); +best_edges.clone() +}, + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let unknown_edge_count = count_unknown_progress_edges(edges.clone()); +(((unknown_edge_count == 0) && ((edges.clone().len() as i64) > 0)) && (same_progress_subgraph_has_cycle(&members, edges.clone()) == false)) +} } pub fn progress_edge_to_proof_edge(pe: &Rc) -> Rc { Rc::new(ProofEdge { - caller: pe.caller.clone(), - callee: pe.callee.clone(), - evidence: Rc::new(vec![pe.progress.clone()]), - }) + caller: pe.caller.clone(), + callee: pe.callee.clone(), + evidence: Rc::new(vec![pe.progress.clone()]), +}) } pub fn count_unknown_progress_edges(edges: Rc>>) -> i64 { - (Rc::new({ - let mut __result = Vec::new(); - for e in edges.iter().cloned() { - if (e.progress.clone() == DescentEvidence::DescentUnknown) { - __result.push(e); - } - } - __result - }) - .len() as i64) + (Rc::new({ let mut __result = Vec::new(); for e in edges.iter().cloned() { if (e.progress.clone() == DescentEvidence::DescentUnknown) { __result.push(e); } } __result }).len() as i64) } pub fn count_unknown_proof_edges(edges: Rc>>) -> i64 { - (Rc::new({ - let mut __result = Vec::new(); - for e in edges.iter().cloned() { - if match e.evidence.clone().first().cloned() { - Some(DescentEvidence::DescentUnknown) => true, - _ => false, - } { - __result.push(e); - } - } - __result - }) - .len() as i64) + (Rc::new({ let mut __result = Vec::new(); for e in edges.iter().cloned() { if match e.evidence.clone().first().cloned() { + Some(DescentEvidence::DescentUnknown) => true, + _ => false, +} { __result.push(e); } } __result }).len() as i64) } -pub fn collect_scc_proof_edges_for_dim( - members: &Rc>, - func_index: &Rc>>, - scc_name_set: Rc>, - check_child: bool, - check_list: bool, - si: &Rc>>, -) -> Rc>> { +pub fn collect_scc_proof_edges_for_dim(members: &Rc>, func_index: &Rc>>, scc_name_set: Rc>, check_child: bool, check_list: bool, si: &Rc>>) -> Rc>> { { - let measure_params = - build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); - Rc::new({ - let mut __result = Vec::new(); - for name in members.clone().iter().cloned() { - __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { + let measure_params = build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); +Rc::new({ let mut __result = Vec::new(); for name in members.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { Some(entry) => { let best_map = entry.params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |best: Rc>, p: Rc| { let pname = param_node_name_at(p.clone(), si.clone()); @@ -6316,40 +3085,22 @@ Rc::new(ProofEdge { }); } __result }) }, None => Rc::new(vec![]), -}).iter().cloned()); - } - __result - }) - } +}).iter().cloned()); } __result }) +} } -pub fn merge_edge_evidence( - acc_map: Rc>, - pe: &Rc, -) -> Rc> { +pub fn merge_edge_evidence(acc_map: Rc>, pe: &Rc) -> Rc> { map_evidence_merge_at(&acc_map, &pe.callee.clone(), pe.progress.clone()) } pub fn count_known_in_edge_map(m: &Rc>) -> i64 { - (Rc::new({ - let mut __result = Vec::new(); - for k in Rc::new(v2_rt::map_keys(&m)).iter().cloned() { - if match v2_rt::map_get(&m, k.clone()) { - Some(DescentEvidence::DescentUnknown) => false, - _ => true, - } { - __result.push(k); - } - } - __result - }) - .len() as i64) + (Rc::new({ let mut __result = Vec::new(); for k in Rc::new(v2_rt::map_keys(&m)).iter().cloned() { if match v2_rt::map_get(&m, k.clone()) { + Some(DescentEvidence::DescentUnknown) => false, + _ => true, +} { __result.push(k); } } __result }).len() as i64) } -pub fn pick_best_param_edges( - current: Rc>, - candidate: Rc>, -) -> Rc> { +pub fn pick_best_param_edges(current: Rc>, candidate: Rc>) -> Rc> { if (count_known_in_edge_map(&candidate) > count_known_in_edge_map(¤t)) { candidate.clone() } else { @@ -6357,19 +3108,10 @@ pub fn pick_best_param_edges( } } -pub fn collect_scc_independent_dim_edges( - members: &Rc>, - func_index: &Rc>>, - scc_name_set: Rc>, - si: &Rc>>, -) -> Rc>> { +pub fn collect_scc_independent_dim_edges(members: &Rc>, func_index: &Rc>>, scc_name_set: Rc>, si: &Rc>>) -> Rc>> { { - let measure_params = - build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); - Rc::new({ - let mut __result = Vec::new(); - for name in members.clone().iter().cloned() { - __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { + let measure_params = build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); +Rc::new({ let mut __result = Vec::new(); for name in members.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { Some(entry) => { let tree_edge_map = entry.params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |best_map: Rc>, p: Rc| { let pname = param_node_name_at(p.clone(), si.clone()); @@ -6404,50 +3146,26 @@ Rc::new(ProofEdge { }); } __result }) }, None => Rc::new(vec![]), -}).iter().cloned()); - } - __result - }) - } +}).iter().cloned()); } __result }) +} } -pub fn collect_scc_parser_proof_edges( - members: Rc>, - func_index: Rc>>, - scc_name_set: Rc>, - si: Rc>>, -) -> Rc>> { +pub fn collect_scc_parser_proof_edges(members: Rc>, func_index: Rc>>, scc_name_set: Rc>, si: Rc>>) -> Rc>> { { let edges = collect_parser_edges_for_scc(&members, &func_index, scc_name_set, &si); - Rc::new({ - let mut __result = Vec::new(); - for pe in edges.iter().cloned() { - __result.push(progress_edge_to_proof_edge(&pe)); - } - __result - }) - } +Rc::new({ let mut __result = Vec::new(); for pe in edges.iter().cloned() { __result.push(progress_edge_to_proof_edge(&pe)); } __result }) +} } -pub fn collect_scc_tree_parser_dim_edges( - members: &Rc>, - func_index: &Rc>>, - scc_name_set: &Rc>, - si: &Rc>>, -) -> Rc>> { +pub fn collect_scc_tree_parser_dim_edges(members: &Rc>, func_index: &Rc>>, scc_name_set: &Rc>, si: &Rc>>) -> Rc>> { { - let all_parser_edges = - collect_parser_edges_for_scc(&members, &func_index, scc_name_set.clone(), &si); - if ((all_parser_edges.clone().len() as i64) == 0) { + let all_parser_edges = collect_parser_edges_for_scc(&members, &func_index, scc_name_set.clone(), &si); +if ((all_parser_edges.clone().len() as i64) == 0) { Rc::new(vec![]) } else { { - let measure_params = - build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); - Rc::new({ - let mut __result = Vec::new(); - for name in members.clone().iter().cloned() { - __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { + let measure_params = build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); +Rc::new({ let mut __result = Vec::new(); for name in members.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { Some(entry) => { let tree_edge_map = entry.params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |best_map: Rc>, p: Rc| { let pname = param_node_name_at(p.clone(), si.clone()); @@ -6477,28 +3195,16 @@ Rc::new(ProofEdge { }); } __result }) }, None => Rc::new(vec![]), -}).iter().cloned()); - } - __result - }) - } +}).iter().cloned()); } __result }) +} } - } +} } -pub fn collect_scc_cx_l2_tree_edges( - members: &Rc>, - func_index: &Rc>>, - scc_name_set: Rc>, - si: &Rc>>, -) -> Rc>> { +pub fn collect_scc_cx_l2_tree_edges(members: &Rc>, func_index: &Rc>>, scc_name_set: Rc>, si: &Rc>>) -> Rc>> { { - let measure_params = - build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); - Rc::new({ - let mut __result = Vec::new(); - for name in members.clone().iter().cloned() { - __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { + let measure_params = build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); +Rc::new({ let mut __result = Vec::new(); for name in members.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&func_index, name.clone()) { Some(entry) => { let self_evidence = collect_self_call_evidence(entry.body.clone(), name.clone(), si.clone()); let self_has_calls = ((self_evidence.clone().len() as i64) > 0); @@ -6572,562 +3278,301 @@ Rc::new(vec![Rc::new(ProofEdge { v2_rt::concat(self_edge.clone(), cross_edges.clone()) }, None => Rc::new(vec![]), -}).iter().cloned()); - } - __result - }) - } +}).iter().cloned()); } __result }) +} } -pub fn scc_descending_param( - members: Rc>, - func_index: Rc>>, - si: Rc>>, -) -> String { - members - .iter() - .cloned() - .fold("".to_string(), |found: String, name: String| { - if (found.clone().as_str() != "".to_string().as_str()) { - found.clone() +pub fn scc_descending_param(members: Rc>, func_index: Rc>>, si: Rc>>) -> String { + members.iter().cloned().fold("".to_string(), |found: String, name: String| if (found.clone().as_str() != "".to_string().as_str()) { + found.clone() + } else { + match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => { + let evidence = collect_self_call_evidence(entry.body.clone(), name.clone(), si.clone()); +match evidence.clone().first().cloned() { + Some(call_ev) => call_ev.clone().iter().cloned().fold("".to_string(), |p: String, rel: Rc| if (p.clone().as_str() != "".to_string().as_str()) { + p.clone() } else { - match v2_rt::map_get(&func_index, name.clone()) { - Some(entry) => { - let evidence = collect_self_call_evidence( - entry.body.clone(), - name.clone(), - si.clone(), - ); - match evidence.clone().first().cloned() { - Some(call_ev) => call_ev.clone().iter().cloned().fold( - "".to_string(), - |p: String, rel: Rc| { - if (p.clone().as_str() != "".to_string().as_str()) { - p.clone() - } else { - match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { - field: f, .. - } => f.element_type.clone(), - SubValueRelation::IteratedSubValue { - field: f, .. - } => f.element_type.clone(), - SubValueRelation::ArithmeticDescent { - param: ap, - .. - } => ap.clone(), - _ => "".to_string(), - } - } - }, - ), - None => "".to_string(), - } - } - None => "".to_string(), - } - } - }) + match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::ArithmeticDescent { param: ap, .. } => ap.clone(), + _ => "".to_string(), +} + }), + None => "".to_string(), +} +}, + None => "".to_string(), +} + }) } -pub fn construct_scc_termination_proof( - members: &Rc>, - func_index: &Rc>>, - scc_name_set: &Rc>, - si: &Rc>>, -) -> Option> { +pub fn construct_scc_termination_proof(members: &Rc>, func_index: &Rc>>, scc_name_set: &Rc>, si: &Rc>>) -> Option> { { - let cx_l2_edges = - collect_scc_cx_l2_tree_edges(&members, &func_index, scc_name_set.clone(), &si); - let cx_l2_all_known = { - let mut __all = true; - for e in cx_l2_edges.clone().iter().cloned() { - if !(match e.evidence.clone().first().cloned() { - Some(DescentEvidence::DescentUnknown) => false, - _ => true, - }) { - __all = false; - break; - } - } - __all - }; - let cx_l2_param = scc_descending_param(members.clone(), func_index.clone(), si.clone()); - let cx_l2_proof = Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { - param: if (cx_l2_param.clone().as_str() != "".to_string().as_str()) { - cx_l2_param.clone() - } else { - "scc".to_string() - }, - })]), - }); - if ((cx_l2_all_known && ((cx_l2_edges.clone().len() as i64) > 0)) - && (proof_has_non_descending_cycle( - cx_l2_proof.clone(), - members.clone(), - cx_l2_edges.clone(), - ) == false)) - { + let cx_l2_edges = collect_scc_cx_l2_tree_edges(&members, &func_index, scc_name_set.clone(), &si); +let cx_l2_all_known = { let mut __all = true; for e in cx_l2_edges.clone().iter().cloned() { if !(match e.evidence.clone().first().cloned() { + Some(DescentEvidence::DescentUnknown) => false, + _ => true, +}) { __all = false; break; } } __all }; +let cx_l2_param = scc_descending_param(members.clone(), func_index.clone(), si.clone()); +let cx_l2_proof = Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { + param: if (cx_l2_param.clone().as_str() != "".to_string().as_str()) { + cx_l2_param.clone() + } else { + "scc".to_string() + }, +})]), +}); +if ((cx_l2_all_known && ((cx_l2_edges.clone().len() as i64) > 0)) && (proof_has_non_descending_cycle(cx_l2_proof.clone(), members.clone(), cx_l2_edges.clone()) == false)) { Some(cx_l2_proof.clone()) } else { { - let tree_edges = collect_scc_proof_edges_for_dim( - &members, - &func_index, - scc_name_set.clone(), - true, - false, - &si, - ); - let tree_all_known = { - let mut __all = true; - for e in tree_edges.clone().iter().cloned() { - if !(match e.evidence.clone().first().cloned() { - Some(DescentEvidence::DescentUnknown) => false, - _ => true, - }) { - __all = false; - break; - } - } - __all - }; - let tree_proof = Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { - param: "scc".to_string(), - })]), - }); - if ((tree_all_known && ((tree_edges.clone().len() as i64) > 0)) - && (proof_has_non_descending_cycle( - tree_proof.clone(), - members.clone(), - tree_edges.clone(), - ) == false)) - { + let tree_edges = collect_scc_proof_edges_for_dim(&members, &func_index, scc_name_set.clone(), true, false, &si); +let tree_all_known = { let mut __all = true; for e in tree_edges.clone().iter().cloned() { if !(match e.evidence.clone().first().cloned() { + Some(DescentEvidence::DescentUnknown) => false, + _ => true, +}) { __all = false; break; } } __all }; +let tree_proof = Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { + param: "scc".to_string(), +})]), +}); +if ((tree_all_known && ((tree_edges.clone().len() as i64) > 0)) && (proof_has_non_descending_cycle(tree_proof.clone(), members.clone(), tree_edges.clone()) == false)) { Some(tree_proof.clone()) } else { { - let list_edges = collect_scc_proof_edges_for_dim( - &members, - &func_index, - scc_name_set.clone(), - false, - true, - &si, - ); - let list_all_known = { - let mut __all = true; - for e in list_edges.clone().iter().cloned() { - if !(match e.evidence.clone().first().cloned() { - Some(DescentEvidence::DescentUnknown) => false, - _ => true, - }) { - __all = false; - break; - } - } - __all - }; - let list_proof = Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new(RankingDimension::ListLength { - param: "scc".to_string(), - })]), - }); - if ((list_all_known && ((list_edges.clone().len() as i64) > 0)) - && (proof_has_non_descending_cycle( - list_proof.clone(), - members.clone(), - list_edges.clone(), - ) == false)) - { + let list_edges = collect_scc_proof_edges_for_dim(&members, &func_index, scc_name_set.clone(), false, true, &si); +let list_all_known = { let mut __all = true; for e in list_edges.clone().iter().cloned() { if !(match e.evidence.clone().first().cloned() { + Some(DescentEvidence::DescentUnknown) => false, + _ => true, +}) { __all = false; break; } } __all }; +let list_proof = Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::ListLength { + param: "scc".to_string(), +})]), +}); +if ((list_all_known && ((list_edges.clone().len() as i64) > 0)) && (proof_has_non_descending_cycle(list_proof.clone(), members.clone(), list_edges.clone()) == false)) { Some(list_proof.clone()) } else { { - let parser_edges = collect_scc_parser_proof_edges( - members.clone(), - func_index.clone(), - scc_name_set.clone(), - si.clone(), - ); - let parser_all_known = { - let mut __all = true; - for e in parser_edges.clone().iter().cloned() { - if !(match e.evidence.clone().first().cloned() { - Some(DescentEvidence::DescentUnknown) => false, - _ => true, - }) { - __all = false; - break; - } - } - __all - }; - let parser_proof = Rc::new(TerminationProof { - dimensions: Rc::new(vec![Rc::new( - RankingDimension::TokenPosition { - param: "scc".to_string(), - }, - )]), - }); - if ((parser_all_known && ((parser_edges.clone().len() as i64) > 0)) - && (proof_has_non_descending_cycle( - parser_proof.clone(), - members.clone(), - parser_edges.clone(), - ) == false)) - { + let parser_edges = collect_scc_parser_proof_edges(members.clone(), func_index.clone(), scc_name_set.clone(), si.clone()); +let parser_all_known = { let mut __all = true; for e in parser_edges.clone().iter().cloned() { if !(match e.evidence.clone().first().cloned() { + Some(DescentEvidence::DescentUnknown) => false, + _ => true, +}) { __all = false; break; } } __all }; +let parser_proof = Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TokenPosition { + param: "scc".to_string(), +})]), +}); +if ((parser_all_known && ((parser_edges.clone().len() as i64) > 0)) && (proof_has_non_descending_cycle(parser_proof.clone(), members.clone(), parser_edges.clone()) == false)) { Some(parser_proof.clone()) } else { { - let lex_edges = collect_scc_independent_dim_edges( - &members, - &func_index, - scc_name_set.clone(), - &si, - ); - let lex_all_known = { - let mut __all = true; - for e in lex_edges.clone().iter().cloned() { - if !(match e.evidence.clone().first().cloned() { - Some(ev) => match ev.clone() { - DescentEvidence::DescentUnknown => false, - _ => true, - }, - None => false, - }) { - __all = false; - break; - } - } - __all - }; - let lex_proof = Rc::new(TerminationProof { - dimensions: Rc::new(vec![ - Rc::new(RankingDimension::TreeSize { - param: "scc".to_string(), - }), - Rc::new(RankingDimension::ListLength { - param: "scc".to_string(), - }), - ]), - }); - if ((lex_all_known - && ((lex_edges.clone().len() as i64) > 0)) - && (proof_has_non_descending_cycle( - lex_proof.clone(), - members.clone(), - lex_edges.clone(), - ) == false)) - { + let lex_edges = collect_scc_independent_dim_edges(&members, &func_index, scc_name_set.clone(), &si); +let lex_all_known = { let mut __all = true; for e in lex_edges.clone().iter().cloned() { if !(match e.evidence.clone().first().cloned() { + Some(ev) => match ev.clone() { + DescentEvidence::DescentUnknown => false, + _ => true, +}, + None => false, +}) { __all = false; break; } } __all }; +let lex_proof = Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { + param: "scc".to_string(), +}), Rc::new(RankingDimension::ListLength { + param: "scc".to_string(), +})]), +}); +if ((lex_all_known && ((lex_edges.clone().len() as i64) > 0)) && (proof_has_non_descending_cycle(lex_proof.clone(), members.clone(), lex_edges.clone()) == false)) { Some(lex_proof.clone()) } else { { - let tree_parser_edges = - collect_scc_tree_parser_dim_edges( - &members, - &func_index, - &scc_name_set, - &si, - ); - let tp_all_known = { - let mut __all = true; - for e in - tree_parser_edges.clone().iter().cloned() - { - if !(match e - .evidence - .clone() - .first() - .cloned() - { - Some(ev) => match ev.clone() { - DescentEvidence::DescentUnknown => { - false - } - _ => true, - }, - None => false, - }) { - __all = false; - break; - } - } - __all - }; - let tp_proof = Rc::new(TerminationProof { - dimensions: Rc::new(vec![ - Rc::new(RankingDimension::TreeSize { - param: "scc".to_string(), - }), - Rc::new(RankingDimension::TokenPosition { - param: "scc".to_string(), - }), - ]), - }); - if ((tp_all_known - && ((tree_parser_edges.clone().len() as i64) - > 0)) - && (proof_has_non_descending_cycle( - tp_proof.clone(), - members.clone(), - tree_parser_edges.clone(), - ) == false)) - { + let tree_parser_edges = collect_scc_tree_parser_dim_edges(&members, &func_index, &scc_name_set, &si); +let tp_all_known = { let mut __all = true; for e in tree_parser_edges.clone().iter().cloned() { if !(match e.evidence.clone().first().cloned() { + Some(ev) => match ev.clone() { + DescentEvidence::DescentUnknown => false, + _ => true, +}, + None => false, +}) { __all = false; break; } } __all }; +let tp_proof = Rc::new(TerminationProof { + dimensions: Rc::new(vec![Rc::new(RankingDimension::TreeSize { + param: "scc".to_string(), +}), Rc::new(RankingDimension::TokenPosition { + param: "scc".to_string(), +})]), +}); +if ((tp_all_known && ((tree_parser_edges.clone().len() as i64) > 0)) && (proof_has_non_descending_cycle(tp_proof.clone(), members.clone(), tree_parser_edges.clone()) == false)) { Some(tp_proof.clone()) } else { None } - } +} } - } +} } - } +} } - } +} } - } +} } - } +} } -pub fn classify_scc_recursion_pattern( - members: &Rc>, - func_index: &Rc>>, - si: &Rc>>, -) -> Rc { +pub fn classify_scc_recursion_pattern(members: &Rc>, func_index: &Rc>>, si: &Rc>>) -> Rc { { - let scc_name_set = members.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let proof = construct_scc_termination_proof(&members, &func_index, &scc_name_set, &si); - match proof { - Some(p) => lower_call_pattern(proof_to_call_pattern(p.clone())), - None => { - let scc_measure_params = - build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); - match classify_parser_scc_recursion_pattern( - &members, - func_index.clone(), - si.clone(), - ) { - Some(parser_target) => parser_target.clone(), - None => { - let all_arithmetic = { - let mut __all = true; - for name in members.clone().iter().cloned() { - if !(match v2_rt::map_get(&func_index, name.clone()) { - Some(entry) => { - ((max_path_target_calls( - entry.body.clone(), - scc_name_set.clone(), - si.clone(), - ) <= 1) - && scc_calls_have_arithmetic_descent( - &entry.body.clone(), - &scc_name_set, - &func_index, - &scc_measure_params, - &si, - )) - } - None => false, - }) { - __all = false; - break; - } - } - __all - }; - if all_arithmetic { - { - let ring_param = match members.clone().first().cloned() { - Some(m0) => { - match v2_rt::map_get(&scc_measure_params, m0.clone()) { - Some(pmap) => match Rc::new(v2_rt::map_keys(&pmap)) - .first() - .cloned() - { - Some(k) => k.clone(), - None => "_scc_arithmetic".to_string(), - }, - None => "_scc_arithmetic".to_string(), - } - } - None => "_scc_arithmetic".to_string(), - }; - lower_call_pattern(Rc::new(CallPattern::ArithmeticSubtractCall { - steps: Rc::new(PositiveDescentAmount::OneStep), - ring_param: ring_param, - })) - } - } else { - lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) - } - } + let scc_name_set = members.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let proof = construct_scc_termination_proof(&members, &func_index, &scc_name_set, &si); +match proof { + Some(p) => lower_call_pattern(proof_to_call_pattern(p.clone())), + None => { + let scc_measure_params = build_scc_measure_params(members.clone(), func_index.clone(), si.clone()); +match classify_parser_scc_recursion_pattern(&members, func_index.clone(), si.clone()) { + Some(parser_target) => parser_target.clone(), + None => { + let all_arithmetic = { let mut __all = true; for name in members.clone().iter().cloned() { if !(match v2_rt::map_get(&func_index, name.clone()) { + Some(entry) => ((max_path_target_calls(entry.body.clone(), scc_name_set.clone(), si.clone()) <= 1) && scc_calls_have_arithmetic_descent(&entry.body.clone(), &scc_name_set, &func_index, &scc_measure_params, &si)), + None => false, +}) { __all = false; break; } } __all }; +if all_arithmetic { + { + let ring_param = match members.clone().first().cloned() { + Some(m0) => match v2_rt::map_get(&scc_measure_params, m0.clone()) { + Some(pmap) => match Rc::new(v2_rt::map_keys(&pmap)).first().cloned() { + Some(k) => k.clone(), + None => "_scc_arithmetic".to_string(), +}, + None => "_scc_arithmetic".to_string(), +}, + None => "_scc_arithmetic".to_string(), +}; +lower_call_pattern(Rc::new(CallPattern::ArithmeticSubtractCall { + steps: Rc::new(PositiveDescentAmount::OneStep), + ring_param: ring_param, +})) +} + } else { + lower_call_pattern(Rc::new(CallPattern::SameArgumentCall)) } - } - } - } +}, +} +}, +} +} } -pub fn build_scc_index( - func_entries: &Rc>>, - func_index: Rc>>, - si: &Rc>>, -) -> Rc { +pub fn build_scc_index(func_entries: &Rc>>, func_index: Rc>>, si: &Rc>>) -> Rc { { - let names = Rc::new({ - let mut __result = Vec::new(); - for entry in func_entries.clone().iter().cloned() { - __result.push(entry.name.clone()); - } - __result - }); - let graph = build_call_graph(&func_entries, si.clone()); - let finish = names.clone().iter().cloned().fold( - Rc::new(DfsFinishAcc { - visited: v2_rt::rc_empty_map::(), - order: Rc::new(vec![]), - }), - |acc: Rc, name: String| { - dfs_finish_order(&name, &graph.forward.clone(), &acc) - }, - ); - let topo_order = v2_rt::reverse(finish.order.clone()); - let result = topo_order.clone().iter().cloned().fold( - Rc::new(SccBuildAcc { - assigned: v2_rt::rc_empty_map::(), - index: v2_rt::rc_empty_map::>(), - }), - |acc: Rc, name: String| { - if set_has(acc.assigned.clone(), name.clone()) { - acc.clone() - } else { + let names = Rc::new({ let mut __result = Vec::new(); for entry in func_entries.clone().iter().cloned() { __result.push(entry.name.clone()); } __result }); +let graph = build_call_graph(&func_entries, si.clone()); +let finish = names.clone().iter().cloned().fold(Rc::new(DfsFinishAcc { + visited: v2_rt::rc_empty_map::(), + order: Rc::new(vec![]), +}), |acc: Rc, name: String| dfs_finish_order(&name, &graph.forward.clone(), &acc)); +let topo_order = v2_rt::reverse(finish.order.clone()); +let result = topo_order.clone().iter().cloned().fold(Rc::new(SccBuildAcc { + assigned: v2_rt::rc_empty_map::(), + index: v2_rt::rc_empty_map::>(), +}), |acc: Rc, name: String| if set_has(acc.assigned.clone(), name.clone()) { + acc.clone() + } else { + { + let component = dfs_collect_component(&name, &graph.reverse.clone(), &Rc::new(SccComponentAcc { + visited: acc.assigned.clone(), + members: Rc::new(vec![]), +})); +let member_set = component.members.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |inner: Rc>, member: String| v2_rt::rc_map_insert(inner, member.clone(), true)); +let members = Rc::new({ let mut __result = Vec::new(); for member in names.clone().iter().cloned() { if set_has(member_set.clone(), member.clone()) { __result.push(member); } } __result }); +let next_assigned = component.visited.clone(); +if ((members.clone().len() as i64) > 1) { { - let component = dfs_collect_component( - &name, - &graph.reverse.clone(), - &Rc::new(SccComponentAcc { - visited: acc.assigned.clone(), - members: Rc::new(vec![]), - }), - ); - let member_set = component.members.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |inner: Rc>, member: String| { - v2_rt::rc_map_insert(inner, member.clone(), true) - }, - ); - let members = Rc::new({ - let mut __result = Vec::new(); - for member in names.clone().iter().cloned() { - if set_has(member_set.clone(), member.clone()) { - __result.push(member); - } - } - __result - }); - let next_assigned = component.visited.clone(); - if ((members.clone().len() as i64) > 1) { - { - let info = Rc::new(SccInfo { - members: members.clone(), - member_set: member_set.clone(), - pattern: classify_scc_recursion_pattern( - &members, - &func_index, - &si, - ), - }); - let next_index = members.clone().iter().cloned().fold( - acc.index.clone(), - |inner: Rc>>, member: String| { - v2_rt::rc_map_insert(inner, member.clone(), info.clone()) - }, - ); - Rc::new(SccBuildAcc { - assigned: next_assigned.clone(), - index: next_index.clone(), - }) - } - } else { - Rc::new(SccBuildAcc { - assigned: next_assigned.clone(), - index: acc.index.clone(), - }) - } - } + let info = Rc::new(SccInfo { + members: members.clone(), + member_set: member_set.clone(), + pattern: classify_scc_recursion_pattern(&members, &func_index, &si), +}); +let next_index = members.clone().iter().cloned().fold(acc.index.clone(), |inner: Rc>>, member: String| v2_rt::rc_map_insert(inner, member.clone(), info.clone())); +Rc::new(SccBuildAcc { + assigned: next_assigned.clone(), + index: next_index.clone(), +}) +} + } else { + Rc::new(SccBuildAcc { + assigned: next_assigned.clone(), + index: acc.index.clone(), +}) } - }, - ); - Rc::new(SccResult { - index: result.index.clone(), - topo_order: topo_order.clone(), - processing_order: finish.order.clone(), - call_graph: graph.clone(), - }) - } +} + }); +Rc::new(SccResult { + index: result.index.clone(), + topo_order: topo_order.clone(), + processing_order: finish.order.clone(), + call_graph: graph.clone(), +}) +} } pub fn cost_seq(a: Rc, b: &Rc) -> Rc { match (*a.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => b.clone(), - _ => match (*b.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => a.clone(), - _ => Rc::new(CostExpr::CostAdd { - left: a.clone(), - right: b.clone(), - }), - }, - } + CostExpr::CostConst { value: 0, .. } => b.clone(), + _ => match (*b.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => a.clone(), + _ => Rc::new(CostExpr::CostAdd { + left: a.clone(), + right: b.clone(), +}), +}, +} } pub fn cost_par(a: Rc, b: &Rc) -> Rc { match (*a.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => b.clone(), - _ => match (*b.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => a.clone(), - _ => Rc::new(CostExpr::CostMax { - left: a.clone(), - right: b.clone(), - }), - }, - } + CostExpr::CostConst { value: 0, .. } => b.clone(), + _ => match (*b.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => a.clone(), + _ => Rc::new(CostExpr::CostMax { + left: a.clone(), + right: b.clone(), +}), +}, +} } pub fn cost_loop(binder: String, iterations: Rc, body: &Rc) -> Rc { match (*body.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => Rc::new(CostExpr::CostConst { value: 0 }), - _ => Rc::new(CostExpr::CostSum { - binder: binder, - upper: iterations, - body: body.clone(), - }), - } + CostExpr::CostConst { value: 0, .. } => Rc::new(CostExpr::CostConst { + value: 0, +}), + _ => Rc::new(CostExpr::CostSum { + binder: binder, + upper: iterations, + body: body.clone(), +}), +} } pub fn cost_conditional(condition: Rc, branches: Rc>>) -> Rc { { - let max_branch = branches.iter().cloned().fold( - Rc::new(CostExpr::CostConst { value: 0 }), - |acc: Rc, b: Rc| cost_par(acc, &b), - ); - cost_seq(condition, &max_branch) - } + let max_branch = branches.iter().cloned().fold(Rc::new(CostExpr::CostConst { + value: 0, +}), |acc: Rc, b: Rc| cost_par(acc, &b)); +cost_seq(condition, &max_branch) +} } pub fn collection_output(binder: String, size: Rc) -> Rc>> { { - let result = seed_cost_map( - "result".to_string(), - cost_loop(binder, size, &Rc::new(CostExpr::CostConst { value: 1 })), - ); - result - } + let result = seed_cost_map("result".to_string(), cost_loop(binder, size, &Rc::new(CostExpr::CostConst { + value: 1, +}))); +result +} } pub fn scalar_output() -> Rc>> { @@ -7139,305 +3584,194 @@ pub fn method_preserves_collection_size(method_semantics: &Option match se.clone() { - Some(CollectionSizeEffect::ShrinkEffect) => true, - Some(CollectionSizeEffect::IdentityEffect) => true, - _ => false, - }, - _ => false, - } + MethodSemantics::AlgebraMethodSemantics { size_effect: se, .. } => match se.clone() { + Some(CollectionSizeEffect::ShrinkEffect) => true, + Some(CollectionSizeEffect::IdentityEffect) => true, + _ => false, +}, + _ => false, +} } } -pub fn receiver_size_var( - mut recv: Rc, - mut si: Rc>>, -) -> Rc { +pub fn receiver_size_var(mut recv: Rc, mut si: Rc>>) -> Rc { loop { - match (*recv.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - break Rc::new(SizeExpr::SizeLen { - collection: expr_var_name_at(recv.clone(), si), - }); - } - ExprData::ExprFieldAccess { .. } => { - break Rc::new(SizeExpr::SizeLen { - collection: field_access_field_at(recv.clone(), si), - }); - } - ExprData::ExprMethodCall { - method_semantics, .. - } => { - let inner_recv = match recv.children.clone().first().cloned() { - Some(r) => r.clone(), - None => recv.clone(), - }; - if method_preserves_collection_size(&method_semantics) { - { - let __tco_0 = inner_recv; - recv = __tco_0; - continue; - } - } else { - break Rc::new(SizeExpr::SizeLen { - collection: "__expr".to_string(), - }); - } - } - _ => { - break Rc::new(SizeExpr::SizeLen { - collection: "__expr".to_string(), - }); - } - } - } + match (*recv.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { break Rc::new(SizeExpr::SizeLen { + collection: expr_var_name_at(recv.clone(), si), +}); }, + ExprData::ExprFieldAccess { .. } => { break Rc::new(SizeExpr::SizeLen { + collection: field_access_field_at(recv.clone(), si), +}); }, + ExprData::ExprMethodCall { method_semantics, .. } => { let inner_recv = match recv.children.clone().first().cloned() { + Some(r) => r.clone(), + None => recv.clone(), +}; +if method_preserves_collection_size(&method_semantics) { + { + let __tco_0 = inner_recv; +recv = __tco_0; +continue; +} +} else { + break Rc::new(SizeExpr::SizeLen { + collection: "__expr".to_string(), +}); +} }, + _ => { break Rc::new(SizeExpr::SizeLen { + collection: "__expr".to_string(), +}); }, +} +} } pub fn size_binder_name(size: Rc) -> String { match (*size).clone() { - SizeExpr::SizeLen { collection: c, .. } => v2_rt::concat("_".to_string(), c.clone()), - SizeExpr::SizeVar { name: n, .. } => n.clone(), - _ => "_i".to_string(), - } + SizeExpr::SizeLen { collection: c, .. } => v2_rt::concat("_".to_string(), c.clone()), + SizeExpr::SizeVar { name: n, .. } => n.clone(), + _ => "_i".to_string(), +} } -pub fn resolve_lambda_arg( - mc_arg_nodes: &Rc>>, - si: Rc>>, -) -> Option> { +pub fn resolve_lambda_arg(mc_arg_nodes: &Rc>>, si: Rc>>) -> Option> { { - let f_arg = Rc::new({ - let mut __result = Vec::new(); - for a in mc_arg_nodes.clone().iter().cloned() { - if (authored_name_at(si.clone(), &a).as_str() == "f".to_string().as_str()) { - __result.push(a); - } - } - __result - }) - .first() - .cloned(); - match f_arg { - Some(fa) => Some(arg_value(&fa)), - None => Rc::new({ - let mut __result = Vec::new(); - for a in mc_arg_nodes.clone().iter().cloned() { - __result.push(arg_value(&a)); - } - __result - }) - .first() - .cloned(), - } - } + let f_arg = Rc::new({ let mut __result = Vec::new(); for a in mc_arg_nodes.clone().iter().cloned() { if (authored_name_at(si.clone(), &a).as_str() == "f".to_string().as_str()) { __result.push(a); } } __result }).first().cloned(); +match f_arg { + Some(fa) => Some(arg_value(&fa)), + None => Rc::new({ let mut __result = Vec::new(); for a in mc_arg_nodes.clone().iter().cloned() { __result.push(arg_value(&a)); } __result }).first().cloned(), +} +} } -pub fn resolve_callback_cost( - lambda_arg: Option>, - recv_r: Rc, - func_index: &Rc>>, - scc_index: Rc>>, - parser_always_advancing: Rc>, - recursion_ctx: RecursionContext, - si: &Rc>>, -) -> Rc { +pub fn resolve_callback_cost(lambda_arg: Option>, recv_r: Rc, func_index: &Rc>>, scc_index: Rc>>, parser_always_advancing: Rc>, recursion_ctx: RecursionContext, si: &Rc>>) -> Rc { match lambda_arg { - Some(la) => match (*la.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let fn_ref = expr_var_name_at(la.clone(), si.clone()); - match v2_rt::map_get(&func_index, fn_ref.clone()) { - Some(_) => get_or_compute_summary( - &fn_ref, - &func_index, - &scc_index, - &recv_r.table.clone(), - parser_always_advancing, - recursion_ctx, - si.clone(), - ), - None => cost_of_expr( - &la, - &func_index, - &scc_index, - recv_r.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ), - } - } - _ => cost_of_expr( - &la, - &func_index, - &scc_index, - recv_r.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ), - }, - None => Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 1 }), - span: Rc::new(CostExpr::CostConst { value: 1 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Conservative, - }), - table: recv_r.table.clone(), - }), - } + Some(la) => match (*la.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let fn_ref = expr_var_name_at(la.clone(), si.clone()); +match v2_rt::map_get(&func_index, fn_ref.clone()) { + Some(_) => get_or_compute_summary(&fn_ref, &func_index, &scc_index, &recv_r.table.clone(), parser_always_advancing, recursion_ctx, si.clone()), + None => cost_of_expr(&la, &func_index, &scc_index, recv_r.table.clone(), &parser_always_advancing, &recursion_ctx, &si), } - -pub fn cost_of_method_by_shape( - shape: CostShape, - produces_collection: bool, - recv_r: &Rc, - mc_args: Rc>>, - size: &Rc, - binder: &String, - func_index: Rc>>, - scc_index: Rc>>, - parser_always_advancing: Rc>, - recursion_ctx: RecursionContext, - si: &Rc>>, -) -> Rc { +}, + _ => cost_of_expr(&la, &func_index, &scc_index, recv_r.table.clone(), &parser_always_advancing, &recursion_ctx, &si), +}, + None => Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 1, +}), + span: Rc::new(CostExpr::CostConst { + value: 1, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Conservative, +}), + table: recv_r.table.clone(), +}), +} +} + +pub fn cost_of_method_by_shape(shape: CostShape, produces_collection: bool, recv_r: &Rc, mc_args: Rc>>, size: &Rc, binder: &String, func_index: Rc>>, scc_index: Rc>>, parser_always_advancing: Rc>, recursion_ctx: RecursionContext, si: &Rc>>) -> Rc { match shape { - CostShape::ShapeIterateBody => { - let lambda_arg = resolve_lambda_arg(&mc_args, si.clone()); - let body_result = resolve_callback_cost( - lambda_arg, - recv_r.clone(), - &func_index, - scc_index, - parser_always_advancing, - recursion_ctx, - &si, - ); - let loop_work = cost_loop( - binder.clone(), - size.clone(), - &body_result.summary.clone().work.clone(), - ); - let os = if (produces_collection == false) { - body_result.summary.clone().output_size.clone() - } else { - { - let r = seed_cost_map( - "result".to_string(), - cost_loop( - binder.clone(), - size.clone(), - &Rc::new(CostExpr::CostConst { value: 1 }), - ), - ); - r - } - }; - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq(recv_r.summary.clone().work.clone(), &loop_work), - span: cost_seq(recv_r.summary.clone().span.clone(), &loop_work), - output_size: os, - certainty: body_result.summary.clone().certainty.clone(), - }), - table: body_result.table.clone(), - }) - } - CostShape::ShapeSortBody => { - let lambda_arg = resolve_lambda_arg(&mc_args, si.clone()); - let key_result = match lambda_arg { - Some(la) => cost_of_expr( - &la, - &func_index, - &scc_index, - recv_r.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ), - None => Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 1 }), - span: Rc::new(CostExpr::CostConst { value: 1 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: recv_r.table.clone(), - }), - }; - let log_factor = Rc::new(CostExpr::CostLog { - base: 2, - argument: size.clone(), - }); - let per_comparison = key_result.summary.clone().work.clone(); - let sort_work = Rc::new(CostExpr::CostMul { - left: cost_loop(binder.clone(), size.clone(), &per_comparison), - right: log_factor, - }); - let sort_os = seed_cost_map( - "result".to_string(), - cost_loop( - binder.clone(), - size.clone(), - &Rc::new(CostExpr::CostConst { value: 1 }), - ), - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq(recv_r.summary.clone().work.clone(), &sort_work), - span: cost_seq(recv_r.summary.clone().span.clone(), &sort_work), - output_size: sort_os, - certainty: key_result.summary.clone().certainty.clone(), - }), - table: key_result.table.clone(), - }) - } - CostShape::ShapeLinearScan => { - let loop_work = cost_loop( - binder.clone(), - size.clone(), - &Rc::new(CostExpr::CostConst { value: 1 }), - ); - let scan_os = if produces_collection { - seed_cost_map( - "result".to_string(), - cost_loop( - binder.clone(), - size.clone(), - &Rc::new(CostExpr::CostConst { value: 1 }), - ), - ) - } else { - v2_rt::rc_empty_map::>() - }; - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq(recv_r.summary.clone().work.clone(), &loop_work), - span: cost_seq(recv_r.summary.clone().span.clone(), &loop_work), - output_size: scan_os, - certainty: recv_r.summary.clone().certainty.clone(), - }), - table: recv_r.table.clone(), - }) - } - CostShape::ShapeConstant => Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - recv_r.summary.clone().work.clone(), - &Rc::new(CostExpr::CostConst { value: 1 }), - ), - span: cost_seq( - recv_r.summary.clone().span.clone(), - &Rc::new(CostExpr::CostConst { value: 1 }), - ), - output_size: v2_rt::rc_empty_map::>(), - certainty: recv_r.summary.clone().certainty.clone(), - }), - table: recv_r.table.clone(), - }), - } + CostShape::ShapeIterateBody => { + let lambda_arg = resolve_lambda_arg(&mc_args, si.clone()); +let body_result = resolve_callback_cost(lambda_arg, recv_r.clone(), &func_index, scc_index, parser_always_advancing, recursion_ctx, &si); +let loop_work = cost_loop(binder.clone(), size.clone(), &body_result.summary.clone().work.clone()); +let os = if (produces_collection == false) { + body_result.summary.clone().output_size.clone() + } else { + { + let r = seed_cost_map("result".to_string(), cost_loop(binder.clone(), size.clone(), &Rc::new(CostExpr::CostConst { + value: 1, +}))); +r +} + }; +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(recv_r.summary.clone().work.clone(), &loop_work), + span: cost_seq(recv_r.summary.clone().span.clone(), &loop_work), + output_size: os, + certainty: body_result.summary.clone().certainty.clone(), +}), + table: body_result.table.clone(), +}) +}, + CostShape::ShapeSortBody => { + let lambda_arg = resolve_lambda_arg(&mc_args, si.clone()); +let key_result = match lambda_arg { + Some(la) => cost_of_expr(&la, &func_index, &scc_index, recv_r.table.clone(), &parser_always_advancing, &recursion_ctx, &si), + None => Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 1, +}), + span: Rc::new(CostExpr::CostConst { + value: 1, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: recv_r.table.clone(), +}), +}; +let log_factor = Rc::new(CostExpr::CostLog { + base: 2, + argument: size.clone(), +}); +let per_comparison = key_result.summary.clone().work.clone(); +let sort_work = Rc::new(CostExpr::CostMul { + left: cost_loop(binder.clone(), size.clone(), &per_comparison), + right: log_factor, +}); +let sort_os = seed_cost_map("result".to_string(), cost_loop(binder.clone(), size.clone(), &Rc::new(CostExpr::CostConst { + value: 1, +}))); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(recv_r.summary.clone().work.clone(), &sort_work), + span: cost_seq(recv_r.summary.clone().span.clone(), &sort_work), + output_size: sort_os, + certainty: key_result.summary.clone().certainty.clone(), +}), + table: key_result.table.clone(), +}) +}, + CostShape::ShapeLinearScan => { + let loop_work = cost_loop(binder.clone(), size.clone(), &Rc::new(CostExpr::CostConst { + value: 1, +})); +let scan_os = if produces_collection { + seed_cost_map("result".to_string(), cost_loop(binder.clone(), size.clone(), &Rc::new(CostExpr::CostConst { + value: 1, +}))) + } else { + v2_rt::rc_empty_map::>() + }; +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(recv_r.summary.clone().work.clone(), &loop_work), + span: cost_seq(recv_r.summary.clone().span.clone(), &loop_work), + output_size: scan_os, + certainty: recv_r.summary.clone().certainty.clone(), +}), + table: recv_r.table.clone(), +}) +}, + CostShape::ShapeConstant => Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(recv_r.summary.clone().work.clone(), &Rc::new(CostExpr::CostConst { + value: 1, +})), + span: cost_seq(recv_r.summary.clone().span.clone(), &Rc::new(CostExpr::CostConst { + value: 1, +})), + output_size: v2_rt::rc_empty_map::>(), + certainty: recv_r.summary.clone().certainty.clone(), +}), + table: recv_r.table.clone(), +}), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -7465,413 +3799,283 @@ pub struct ComplexityReport { pub fn empty_complexity_report() -> Rc { Rc::new(ComplexityReport { - function_classes: v2_rt::rc_empty_map::(), - violations: Rc::new(vec![]), - structural_bounds: Rc::new(vec![]), - }) + function_classes: v2_rt::rc_empty_map::(), + violations: Rc::new(vec![]), + structural_bounds: Rc::new(vec![]), +}) } pub fn simplify_cost(expr: Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*expr.clone()).clone() { - CostExpr::CostConst { .. } => expr.clone(), - CostExpr::CostAdd { - left: l, right: r, .. - } => { - let sl = simplify_cost(l.clone()); - let sr = simplify_cost(r.clone()); - let simplified = match (*sl.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => sr.clone(), - CostExpr::CostConst { value: a, .. } => match (*sr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => sl.clone(), - CostExpr::CostConst { value: b, .. } => Rc::new(CostExpr::CostConst { - value: (a.clone() + b.clone()), - }), - _ => Rc::new(CostExpr::CostAdd { - left: sl.clone(), - right: sr.clone(), - }), - }, - _ => match (*sr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => sl.clone(), - _ => Rc::new(CostExpr::CostAdd { - left: sl.clone(), - right: sr.clone(), - }), - }, - }; - simplified - } - CostExpr::CostMul { - left: l, right: r, .. - } => { - let sl = simplify_cost(l.clone()); - let sr = simplify_cost(r.clone()); - let simplified = match (*sl.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => { - Rc::new(CostExpr::CostConst { value: 0 }) - } - CostExpr::CostConst { value: 1, .. } => sr.clone(), - _ => match (*sr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => { - Rc::new(CostExpr::CostConst { value: 0 }) - } - CostExpr::CostConst { value: 1, .. } => sl.clone(), - _ => Rc::new(CostExpr::CostMul { - left: sl.clone(), - right: sr.clone(), - }), - }, - }; - simplified - } - CostExpr::CostMax { - left: l, right: r, .. - } => { - let sl = simplify_cost(l.clone()); - let sr = simplify_cost(r.clone()); - let simplified = match (*sl.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => sr.clone(), - CostExpr::CostConst { value: a, .. } => match (*sr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => sl.clone(), - CostExpr::CostConst { value: b, .. } => { - if (a.clone() > b.clone()) { - sl.clone() - } else { - sr.clone() - } - } - _ => Rc::new(CostExpr::CostMax { - left: sl.clone(), - right: sr.clone(), - }), - }, - _ => match (*sr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => sl.clone(), - _ => Rc::new(CostExpr::CostMax { - left: sl.clone(), - right: sr.clone(), - }), - }, - }; - simplified - } - CostExpr::CostSum { - binder: b, - upper: u, - body: bd, - .. - } => { - let sbd = simplify_cost(bd.clone()); - match (*sbd.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => { - Rc::new(CostExpr::CostConst { value: 0 }) - } - _ => Rc::new(CostExpr::CostSum { - binder: b.clone(), - upper: u.clone(), - body: sbd.clone(), - }), - } - } - CostExpr::CostLog { - base: b, - argument: a, - .. - } => Rc::new(CostExpr::CostLog { - base: b.clone(), - argument: a.clone(), - }), - CostExpr::CostExtern { .. } => expr.clone(), - CostExpr::CostUnknown { .. } => expr.clone(), - } + CostExpr::CostConst { .. } => expr.clone(), + CostExpr::CostAdd { left: l, right: r, .. } => { + let sl = simplify_cost(l.clone()); +let sr = simplify_cost(r.clone()); +let simplified = match (*sl.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => sr.clone(), + CostExpr::CostConst { value: a, .. } => match (*sr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => sl.clone(), + CostExpr::CostConst { value: b, .. } => Rc::new(CostExpr::CostConst { + value: (a.clone() + b.clone()), +}), + _ => Rc::new(CostExpr::CostAdd { + left: sl.clone(), + right: sr.clone(), +}), +}, + _ => match (*sr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => sl.clone(), + _ => Rc::new(CostExpr::CostAdd { + left: sl.clone(), + right: sr.clone(), +}), +}, +}; +simplified +}, + CostExpr::CostMul { left: l, right: r, .. } => { + let sl = simplify_cost(l.clone()); +let sr = simplify_cost(r.clone()); +let simplified = match (*sl.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => Rc::new(CostExpr::CostConst { + value: 0, +}), + CostExpr::CostConst { value: 1, .. } => sr.clone(), + _ => match (*sr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => Rc::new(CostExpr::CostConst { + value: 0, +}), + CostExpr::CostConst { value: 1, .. } => sl.clone(), + _ => Rc::new(CostExpr::CostMul { + left: sl.clone(), + right: sr.clone(), +}), +}, +}; +simplified +}, + CostExpr::CostMax { left: l, right: r, .. } => { + let sl = simplify_cost(l.clone()); +let sr = simplify_cost(r.clone()); +let simplified = match (*sl.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => sr.clone(), + CostExpr::CostConst { value: a, .. } => match (*sr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => sl.clone(), + CostExpr::CostConst { value: b, .. } => if (a.clone() > b.clone()) { + sl.clone() + } else { + sr.clone() + }, + _ => Rc::new(CostExpr::CostMax { + left: sl.clone(), + right: sr.clone(), +}), +}, + _ => match (*sr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => sl.clone(), + _ => Rc::new(CostExpr::CostMax { + left: sl.clone(), + right: sr.clone(), +}), +}, +}; +simplified +}, + CostExpr::CostSum { binder: b, upper: u, body: bd, .. } => { + let sbd = simplify_cost(bd.clone()); +match (*sbd.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => Rc::new(CostExpr::CostConst { + value: 0, +}), + _ => Rc::new(CostExpr::CostSum { + binder: b.clone(), + upper: u.clone(), + body: sbd.clone(), +}), +} +}, + CostExpr::CostLog { base: b, argument: a, .. } => Rc::new(CostExpr::CostLog { + base: b.clone(), + argument: a.clone(), +}), + CostExpr::CostExtern { .. } => expr.clone(), + CostExpr::CostUnknown { .. } => expr.clone(), +} }) } pub fn format_size(size: Rc) -> String { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*size).clone() { - SizeExpr::SizeLen { collection: c, .. } => { - v2_rt::concat(v2_rt::concat("|".to_string(), c.clone()), "|".to_string()) - } - SizeExpr::SizeVar { name: n, .. } => n.clone(), - SizeExpr::SizeConst { value: v, .. } => (v.clone()).to_string(), - SizeExpr::SizeAdd { - left: l, right: r, .. - } => v2_rt::concat( - v2_rt::concat(format_size(l.clone()), " + ".to_string()), - format_size(r.clone()), - ), - SizeExpr::SizeMax { - left: l, right: r, .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("max(".to_string(), format_size(l.clone())), - ", ".to_string(), - ), - format_size(r.clone()), - ), - ")".to_string(), - ), + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*size).clone() { + SizeExpr::SizeLen { collection: c, .. } => v2_rt::concat(v2_rt::concat("|".to_string(), c.clone()), "|".to_string()), + SizeExpr::SizeVar { name: n, .. } => n.clone(), + SizeExpr::SizeConst { value: v, .. } => (v.clone()).to_string(), + SizeExpr::SizeAdd { left: l, right: r, .. } => v2_rt::concat(v2_rt::concat(format_size(l.clone()), " + ".to_string()), format_size(r.clone())), + SizeExpr::SizeMax { left: l, right: r, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("max(".to_string(), format_size(l.clone())), ", ".to_string()), format_size(r.clone())), ")".to_string()), +} }) } pub fn normalize_asymptotic(expr: Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*expr.clone()).clone() { - CostExpr::CostConst { value: v, .. } => { - if (v.clone() <= 0) { - Rc::new(CostExpr::CostConst { value: 0 }) - } else { - Rc::new(CostExpr::CostConst { value: 1 }) - } - } - CostExpr::CostAdd { - left: l, right: r, .. - } => { - let nl = normalize_asymptotic(l.clone()); - let nr = normalize_asymptotic(r.clone()); - if (nl.clone() == nr.clone()) { - nl.clone() - } else { - match (*nl.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => nr.clone(), - CostExpr::CostConst { .. } => match (*nr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => nl.clone(), - CostExpr::CostConst { .. } => Rc::new(CostExpr::CostConst { value: 1 }), - _ => nr.clone(), - }, - _ => match (*nr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => nl.clone(), - CostExpr::CostConst { .. } => nl.clone(), - _ => Rc::new(CostExpr::CostAdd { - left: nl.clone(), - right: nr.clone(), - }), - }, - } - } - } - CostExpr::CostMax { - left: l, right: r, .. - } => { - let nl = normalize_asymptotic(l.clone()); - let nr = normalize_asymptotic(r.clone()); - if (nl.clone() == nr.clone()) { - nl.clone() - } else { - match (*nl.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => nr.clone(), - CostExpr::CostConst { .. } => match (*nr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => nl.clone(), - CostExpr::CostConst { .. } => Rc::new(CostExpr::CostConst { value: 1 }), - _ => nr.clone(), - }, - _ => match (*nr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => nl.clone(), - CostExpr::CostConst { .. } => nl.clone(), - _ => Rc::new(CostExpr::CostMax { - left: nl.clone(), - right: nr.clone(), - }), - }, - } - } - } - CostExpr::CostMul { - left: l, right: r, .. - } => { - let nl = normalize_asymptotic(l.clone()); - let nr = normalize_asymptotic(r.clone()); + CostExpr::CostConst { value: v, .. } => if (v.clone() <= 0) { + Rc::new(CostExpr::CostConst { + value: 0, +}) + } else { + Rc::new(CostExpr::CostConst { + value: 1, +}) + }, + CostExpr::CostAdd { left: l, right: r, .. } => { + let nl = normalize_asymptotic(l.clone()); +let nr = normalize_asymptotic(r.clone()); +if (nl.clone() == nr.clone()) { + nl.clone() + } else { match (*nl.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => { - Rc::new(CostExpr::CostConst { value: 0 }) - } - CostExpr::CostConst { .. } => nr.clone(), - _ => match (*nr.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => { - Rc::new(CostExpr::CostConst { value: 0 }) - } - CostExpr::CostConst { .. } => nl.clone(), - _ => Rc::new(CostExpr::CostMul { - left: nl.clone(), - right: nr.clone(), - }), - }, - } + CostExpr::CostConst { value: 0, .. } => nr.clone(), + CostExpr::CostConst { .. } => match (*nr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => nl.clone(), + CostExpr::CostConst { .. } => Rc::new(CostExpr::CostConst { + value: 1, +}), + _ => nr.clone(), +}, + _ => match (*nr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => nl.clone(), + CostExpr::CostConst { .. } => nl.clone(), + _ => Rc::new(CostExpr::CostAdd { + left: nl.clone(), + right: nr.clone(), +}), +}, +} } - CostExpr::CostSum { - binder: b, - upper: u, - body: bd, - .. - } => { - let nbd = normalize_asymptotic(bd.clone()); - match (*nbd.clone()).clone() { - CostExpr::CostConst { value: 0, .. } => { - Rc::new(CostExpr::CostConst { value: 0 }) - } - _ => match (*u.clone()).clone() { - SizeExpr::SizeConst { .. } => nbd.clone(), - _ => Rc::new(CostExpr::CostSum { - binder: b.clone(), - upper: u.clone(), - body: nbd.clone(), - }), - }, - } +}, + CostExpr::CostMax { left: l, right: r, .. } => { + let nl = normalize_asymptotic(l.clone()); +let nr = normalize_asymptotic(r.clone()); +if (nl.clone() == nr.clone()) { + nl.clone() + } else { + match (*nl.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => nr.clone(), + CostExpr::CostConst { .. } => match (*nr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => nl.clone(), + CostExpr::CostConst { .. } => Rc::new(CostExpr::CostConst { + value: 1, +}), + _ => nr.clone(), +}, + _ => match (*nr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => nl.clone(), + CostExpr::CostConst { .. } => nl.clone(), + _ => Rc::new(CostExpr::CostMax { + left: nl.clone(), + right: nr.clone(), +}), +}, +} } - CostExpr::CostLog { - base: b, - argument: a, - .. - } => Rc::new(CostExpr::CostLog { - base: b.clone(), - argument: a.clone(), - }), - CostExpr::CostExtern { .. } => expr.clone(), - CostExpr::CostUnknown { .. } => expr.clone(), - } +}, + CostExpr::CostMul { left: l, right: r, .. } => { + let nl = normalize_asymptotic(l.clone()); +let nr = normalize_asymptotic(r.clone()); +match (*nl.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => Rc::new(CostExpr::CostConst { + value: 0, +}), + CostExpr::CostConst { .. } => nr.clone(), + _ => match (*nr.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => Rc::new(CostExpr::CostConst { + value: 0, +}), + CostExpr::CostConst { .. } => nl.clone(), + _ => Rc::new(CostExpr::CostMul { + left: nl.clone(), + right: nr.clone(), +}), +}, +} +}, + CostExpr::CostSum { binder: b, upper: u, body: bd, .. } => { + let nbd = normalize_asymptotic(bd.clone()); +match (*nbd.clone()).clone() { + CostExpr::CostConst { value: 0, .. } => Rc::new(CostExpr::CostConst { + value: 0, +}), + _ => match (*u.clone()).clone() { + SizeExpr::SizeConst { .. } => nbd.clone(), + _ => Rc::new(CostExpr::CostSum { + binder: b.clone(), + upper: u.clone(), + body: nbd.clone(), +}), +}, +} +}, + CostExpr::CostLog { base: b, argument: a, .. } => Rc::new(CostExpr::CostLog { + base: b.clone(), + argument: a.clone(), +}), + CostExpr::CostExtern { .. } => expr.clone(), + CostExpr::CostUnknown { .. } => expr.clone(), +} }) } pub fn format_cost_class(expr: Rc) -> String { match (*expr).clone() { - CostExpr::CostConst { .. } => "O(1)".to_string(), - CostExpr::CostExtern { name: n, .. } => v2_rt::concat( - v2_rt::concat("O(extern(".to_string(), n.clone()), - "))".to_string(), - ), - CostExpr::CostUnknown { .. } => "O(?)".to_string(), - CostExpr::CostSum { - upper: u, body: bd, .. - } => match (*bd.clone()).clone() { - CostExpr::CostConst { .. } => v2_rt::concat( - v2_rt::concat("O(".to_string(), format_size(u.clone())), - ")".to_string(), - ), - _ => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("O(".to_string(), format_size(u.clone())), - " * ".to_string(), - ), - format_cost_inner(bd.clone()), - ), - ")".to_string(), - ), - }, - CostExpr::CostAdd { - left: l, right: r, .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("O(".to_string(), format_cost_inner(l.clone())), - " + ".to_string(), - ), - format_cost_inner(r.clone()), - ), - ")".to_string(), - ), - CostExpr::CostMul { - left: l, right: r, .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("O(".to_string(), parenthesize_additive_cost(&l)), - " * ".to_string(), - ), - parenthesize_additive_cost(&r), - ), - ")".to_string(), - ), - CostExpr::CostMax { - left: l, right: r, .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("O(max(".to_string(), format_cost_inner(l.clone())), - ", ".to_string(), - ), - format_cost_inner(r.clone()), - ), - "))".to_string(), - ), - CostExpr::CostLog { argument: a, .. } => v2_rt::concat( - v2_rt::concat("O(log ".to_string(), format_size(a.clone())), - ")".to_string(), - ), - } + CostExpr::CostConst { .. } => "O(1)".to_string(), + CostExpr::CostExtern { name: n, .. } => v2_rt::concat(v2_rt::concat("O(extern(".to_string(), n.clone()), "))".to_string()), + CostExpr::CostUnknown { .. } => "O(?)".to_string(), + CostExpr::CostSum { upper: u, body: bd, .. } => match (*bd.clone()).clone() { + CostExpr::CostConst { .. } => v2_rt::concat(v2_rt::concat("O(".to_string(), format_size(u.clone())), ")".to_string()), + _ => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("O(".to_string(), format_size(u.clone())), " * ".to_string()), format_cost_inner(bd.clone())), ")".to_string()), +}, + CostExpr::CostAdd { left: l, right: r, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("O(".to_string(), format_cost_inner(l.clone())), " + ".to_string()), format_cost_inner(r.clone())), ")".to_string()), + CostExpr::CostMul { left: l, right: r, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("O(".to_string(), parenthesize_additive_cost(&l)), " * ".to_string()), parenthesize_additive_cost(&r)), ")".to_string()), + CostExpr::CostMax { left: l, right: r, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("O(max(".to_string(), format_cost_inner(l.clone())), ", ".to_string()), format_cost_inner(r.clone())), "))".to_string()), + CostExpr::CostLog { argument: a, .. } => v2_rt::concat(v2_rt::concat("O(log ".to_string(), format_size(a.clone())), ")".to_string()), +} } pub fn format_cost_inner(expr: Rc) -> String { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*expr).clone() { - CostExpr::CostConst { .. } => "1".to_string(), - CostExpr::CostSum { - upper: u, body: bd, .. - } => match (*bd.clone()).clone() { - CostExpr::CostConst { .. } => format_size(u.clone()), - _ => v2_rt::concat( - v2_rt::concat(format_size(u.clone()), " * ".to_string()), - format_cost_inner(bd.clone()), - ), - }, - CostExpr::CostAdd { - left: l, right: r, .. - } => v2_rt::concat( - v2_rt::concat(format_cost_inner(l.clone()), " + ".to_string()), - format_cost_inner(r.clone()), - ), - CostExpr::CostMul { - left: l, right: r, .. - } => { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*expr).clone() { + CostExpr::CostConst { .. } => "1".to_string(), + CostExpr::CostSum { upper: u, body: bd, .. } => match (*bd.clone()).clone() { + CostExpr::CostConst { .. } => format_size(u.clone()), + _ => v2_rt::concat(v2_rt::concat(format_size(u.clone()), " * ".to_string()), format_cost_inner(bd.clone())), +}, + CostExpr::CostAdd { left: l, right: r, .. } => v2_rt::concat(v2_rt::concat(format_cost_inner(l.clone()), " + ".to_string()), format_cost_inner(r.clone())), + CostExpr::CostMul { left: l, right: r, .. } => { let left_str = match (*l.clone()).clone() { - CostExpr::CostAdd { .. } => v2_rt::concat( - v2_rt::concat("(".to_string(), format_cost_inner(l.clone())), - ")".to_string(), - ), - _ => format_cost_inner(l.clone()), - }; - let right_str = match (*r.clone()).clone() { - CostExpr::CostAdd { .. } => v2_rt::concat( - v2_rt::concat("(".to_string(), format_cost_inner(r.clone())), - ")".to_string(), - ), - _ => format_cost_inner(r.clone()), - }; - v2_rt::concat(v2_rt::concat(left_str, " * ".to_string()), right_str) - } - CostExpr::CostMax { - left: l, right: r, .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("max(".to_string(), format_cost_inner(l.clone())), - ", ".to_string(), - ), - format_cost_inner(r.clone()), - ), - ")".to_string(), - ), - CostExpr::CostLog { argument: a, .. } => { - v2_rt::concat("log ".to_string(), format_size(a.clone())) - } - CostExpr::CostExtern { name: n, .. } => v2_rt::concat( - v2_rt::concat("extern(".to_string(), n.clone()), - ")".to_string(), - ), - CostExpr::CostUnknown { .. } => "?".to_string(), + CostExpr::CostAdd { .. } => v2_rt::concat(v2_rt::concat("(".to_string(), format_cost_inner(l.clone())), ")".to_string()), + _ => format_cost_inner(l.clone()), +}; +let right_str = match (*r.clone()).clone() { + CostExpr::CostAdd { .. } => v2_rt::concat(v2_rt::concat("(".to_string(), format_cost_inner(r.clone())), ")".to_string()), + _ => format_cost_inner(r.clone()), +}; +v2_rt::concat(v2_rt::concat(left_str, " * ".to_string()), right_str) +}, + CostExpr::CostMax { left: l, right: r, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("max(".to_string(), format_cost_inner(l.clone())), ", ".to_string()), format_cost_inner(r.clone())), ")".to_string()), + CostExpr::CostLog { argument: a, .. } => v2_rt::concat("log ".to_string(), format_size(a.clone())), + CostExpr::CostExtern { name: n, .. } => v2_rt::concat(v2_rt::concat("extern(".to_string(), n.clone()), ")".to_string()), + CostExpr::CostUnknown { .. } => "?".to_string(), +} }) } pub fn parenthesize_additive_cost(expr: &Rc) -> String { match (*expr.clone()).clone() { - CostExpr::CostAdd { .. } => v2_rt::concat( - v2_rt::concat("(".to_string(), format_cost_inner(expr.clone())), - ")".to_string(), - ), - _ => format_cost_inner(expr.clone()), - } + CostExpr::CostAdd { .. } => v2_rt::concat(v2_rt::concat("(".to_string(), format_cost_inner(expr.clone())), ")".to_string()), + _ => format_cost_inner(expr.clone()), +} } pub fn short_var_name(index: i64) -> String { @@ -7905,10 +4109,7 @@ pub fn short_var_name(index: i64) -> String { if (index.clone() == 9) { "w".to_string() } else { - v2_rt::concat( - "x".to_string(), - (index.clone()).to_string(), - ) + v2_rt::concat("x".to_string(), (index.clone()).to_string()) } } } @@ -7930,214 +4131,146 @@ pub struct Legend { pub fn build_legend(size_names: Rc>) -> Rc { { let unique = deduplicate(size_names); - if ((unique.clone().len() as i64) == 0) { +if ((unique.clone().len() as i64) == 0) { Rc::new(Legend { - substitution: v2_rt::rc_empty_map::(), - suffix: "".to_string(), - }) + substitution: v2_rt::rc_empty_map::(), + suffix: "".to_string(), +}) } else { if ((unique.clone().len() as i64) == 1) { match unique.clone().first().cloned() { - Some(name) => Rc::new(Legend { - substitution: v2_rt::rc_map_insert( - v2_rt::rc_empty_map::(), - name.clone(), - "n".to_string(), - ), - suffix: "".to_string(), - }), - None => Rc::new(Legend { - substitution: v2_rt::rc_empty_map::(), - suffix: "".to_string(), - }), - } + Some(name) => Rc::new(Legend { + substitution: v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), name.clone(), "n".to_string()), + suffix: "".to_string(), +}), + None => Rc::new(Legend { + substitution: v2_rt::rc_empty_map::(), + suffix: "".to_string(), +}), +} } else { { - let indexed = unique.clone().iter().cloned().fold( - Rc::new(Legend { - substitution: v2_rt::rc_empty_map::(), - suffix: "".to_string(), - }), - |acc: Rc, name: String| { - let idx = - (Rc::new(v2_rt::map_keys(&acc.substitution.clone())).len() as i64); - let short = short_var_name(idx.clone()); - Rc::new(Legend { - substitution: v2_rt::rc_map_insert( - acc.substitution.clone(), - name.clone(), - short.clone(), - ), - suffix: if (acc.suffix.clone().as_str() == "".to_string().as_str()) - { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" where ".to_string(), short.clone()), - " = ".to_string(), - ), - name.clone(), - ) - } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(acc.suffix.clone(), ", ".to_string()), - short.clone(), - ), - " = ".to_string(), - ), - name.clone(), - ) - }, - }) + let indexed = unique.clone().iter().cloned().fold(Rc::new(Legend { + substitution: v2_rt::rc_empty_map::(), + suffix: "".to_string(), +}), |acc: Rc, name: String| { + let idx = (Rc::new(v2_rt::map_keys(&acc.substitution.clone())).len() as i64); +let short = short_var_name(idx.clone()); +Rc::new(Legend { + substitution: v2_rt::rc_map_insert(acc.substitution.clone(), name.clone(), short.clone()), + suffix: if (acc.suffix.clone().as_str() == "".to_string().as_str()) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(" where ".to_string(), short.clone()), " = ".to_string()), name.clone()) + } else { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(acc.suffix.clone(), ", ".to_string()), short.clone()), " = ".to_string()), name.clone()) }, - ); - indexed - } +}) +}); +indexed +} } } - } +} } pub fn substitute_size(size: Rc, legend: &Rc>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*size.clone()).clone() { - SizeExpr::SizeLen { collection: c, .. } => match v2_rt::map_get(&legend, c.clone()) { - Some(short) => Rc::new(SizeExpr::SizeVar { - name: short.clone(), - }), - None => size.clone(), - }, - SizeExpr::SizeVar { name: n, .. } => match v2_rt::map_get(&legend, n.clone()) { - Some(short) => Rc::new(SizeExpr::SizeVar { - name: short.clone(), - }), - None => size.clone(), - }, - SizeExpr::SizeAdd { - left: l, right: r, .. - } => Rc::new(SizeExpr::SizeAdd { - left: substitute_size(l.clone(), &legend), - right: substitute_size(r.clone(), &legend), - }), - SizeExpr::SizeMax { - left: l, right: r, .. - } => Rc::new(SizeExpr::SizeMax { - left: substitute_size(l.clone(), &legend), - right: substitute_size(r.clone(), &legend), - }), - SizeExpr::SizeConst { .. } => size.clone(), - } + SizeExpr::SizeLen { collection: c, .. } => match v2_rt::map_get(&legend, c.clone()) { + Some(short) => Rc::new(SizeExpr::SizeVar { + name: short.clone(), +}), + None => size.clone(), +}, + SizeExpr::SizeVar { name: n, .. } => match v2_rt::map_get(&legend, n.clone()) { + Some(short) => Rc::new(SizeExpr::SizeVar { + name: short.clone(), +}), + None => size.clone(), +}, + SizeExpr::SizeAdd { left: l, right: r, .. } => Rc::new(SizeExpr::SizeAdd { + left: substitute_size(l.clone(), &legend), + right: substitute_size(r.clone(), &legend), +}), + SizeExpr::SizeMax { left: l, right: r, .. } => Rc::new(SizeExpr::SizeMax { + left: substitute_size(l.clone(), &legend), + right: substitute_size(r.clone(), &legend), +}), + SizeExpr::SizeConst { .. } => size.clone(), +} }) } pub fn substitute_cost(expr: Rc, legend: &Rc>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*expr.clone()).clone() { - CostExpr::CostConst { .. } => expr.clone(), - CostExpr::CostAdd { - left: l, right: r, .. - } => Rc::new(CostExpr::CostAdd { - left: substitute_cost(l.clone(), &legend), - right: substitute_cost(r.clone(), &legend), - }), - CostExpr::CostMul { - left: l, right: r, .. - } => Rc::new(CostExpr::CostMul { - left: substitute_cost(l.clone(), &legend), - right: substitute_cost(r.clone(), &legend), - }), - CostExpr::CostMax { - left: l, right: r, .. - } => Rc::new(CostExpr::CostMax { - left: substitute_cost(l.clone(), &legend), - right: substitute_cost(r.clone(), &legend), - }), - CostExpr::CostSum { - binder: b, - upper: u, - body: bd, - .. - } => Rc::new(CostExpr::CostSum { - binder: b.clone(), - upper: substitute_size(u.clone(), &legend), - body: substitute_cost(bd.clone(), &legend), - }), - CostExpr::CostLog { - base: b, - argument: a, - .. - } => Rc::new(CostExpr::CostLog { - base: b.clone(), - argument: substitute_size(a.clone(), &legend), - }), - CostExpr::CostExtern { .. } => expr.clone(), - CostExpr::CostUnknown { .. } => expr.clone(), - } + CostExpr::CostConst { .. } => expr.clone(), + CostExpr::CostAdd { left: l, right: r, .. } => Rc::new(CostExpr::CostAdd { + left: substitute_cost(l.clone(), &legend), + right: substitute_cost(r.clone(), &legend), +}), + CostExpr::CostMul { left: l, right: r, .. } => Rc::new(CostExpr::CostMul { + left: substitute_cost(l.clone(), &legend), + right: substitute_cost(r.clone(), &legend), +}), + CostExpr::CostMax { left: l, right: r, .. } => Rc::new(CostExpr::CostMax { + left: substitute_cost(l.clone(), &legend), + right: substitute_cost(r.clone(), &legend), +}), + CostExpr::CostSum { binder: b, upper: u, body: bd, .. } => Rc::new(CostExpr::CostSum { + binder: b.clone(), + upper: substitute_size(u.clone(), &legend), + body: substitute_cost(bd.clone(), &legend), +}), + CostExpr::CostLog { base: b, argument: a, .. } => Rc::new(CostExpr::CostLog { + base: b.clone(), + argument: substitute_size(a.clone(), &legend), +}), + CostExpr::CostExtern { .. } => expr.clone(), + CostExpr::CostUnknown { .. } => expr.clone(), +} }) } pub fn classify_complexity(expr: Rc) -> String { { let normalized = normalize_asymptotic(simplify_cost(expr)); - let size_names = collect_size_vars(normalized.clone()); - let legend = build_legend(size_names); - let substituted = substitute_cost(normalized.clone(), &legend.substitution.clone()); - v2_rt::concat(format_cost_class(substituted), legend.suffix.clone()) - } +let size_names = collect_size_vars(normalized.clone()); +let legend = build_legend(size_names); +let substituted = substitute_cost(normalized.clone(), &legend.substitution.clone()); +v2_rt::concat(format_cost_class(substituted), legend.suffix.clone()) +} } pub fn collect_size_vars_from_size(size: Rc) -> Rc> { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*size).clone() { - SizeExpr::SizeLen { collection: c, .. } => { - if (c.clone().as_str() == "__expr".to_string().as_str()) { - Rc::new(vec![]) - } else { - Rc::new(vec![c.clone()]) - } - } - SizeExpr::SizeVar { name: n, .. } => { - if (n.clone().as_str() == "__k".to_string().as_str()) { - Rc::new(vec![]) - } else { - Rc::new(vec![n.clone()]) - } - } - SizeExpr::SizeAdd { - left: l, right: r, .. - } => v2_rt::concat( - collect_size_vars_from_size(l.clone()), - collect_size_vars_from_size(r.clone()), - ), - SizeExpr::SizeMax { - left: l, right: r, .. - } => v2_rt::concat( - collect_size_vars_from_size(l.clone()), - collect_size_vars_from_size(r.clone()), - ), - _ => Rc::new(vec![]), + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*size).clone() { + SizeExpr::SizeLen { collection: c, .. } => if (c.clone().as_str() == "__expr".to_string().as_str()) { + Rc::new(vec![]) + } else { + Rc::new(vec![c.clone()]) + }, + SizeExpr::SizeVar { name: n, .. } => if (n.clone().as_str() == "__k".to_string().as_str()) { + Rc::new(vec![]) + } else { + Rc::new(vec![n.clone()]) + }, + SizeExpr::SizeAdd { left: l, right: r, .. } => v2_rt::concat(collect_size_vars_from_size(l.clone()), collect_size_vars_from_size(r.clone())), + SizeExpr::SizeMax { left: l, right: r, .. } => v2_rt::concat(collect_size_vars_from_size(l.clone()), collect_size_vars_from_size(r.clone())), + _ => Rc::new(vec![]), +} }) } pub fn collect_size_vars(expr: Rc) -> Rc> { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*expr).clone() { - CostExpr::CostSum { - upper: u, body: bd, .. - } => v2_rt::concat( - collect_size_vars_from_size(u.clone()), - collect_size_vars(bd.clone()), - ), - CostExpr::CostAdd { - left: l, right: r, .. - } => v2_rt::concat(collect_size_vars(l.clone()), collect_size_vars(r.clone())), - CostExpr::CostMul { - left: l, right: r, .. - } => v2_rt::concat(collect_size_vars(l.clone()), collect_size_vars(r.clone())), - CostExpr::CostMax { - left: l, right: r, .. - } => v2_rt::concat(collect_size_vars(l.clone()), collect_size_vars(r.clone())), - CostExpr::CostLog { argument: a, .. } => collect_size_vars_from_size(a.clone()), - _ => Rc::new(vec![]), + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*expr).clone() { + CostExpr::CostSum { upper: u, body: bd, .. } => v2_rt::concat(collect_size_vars_from_size(u.clone()), collect_size_vars(bd.clone())), + CostExpr::CostAdd { left: l, right: r, .. } => v2_rt::concat(collect_size_vars(l.clone()), collect_size_vars(r.clone())), + CostExpr::CostMul { left: l, right: r, .. } => v2_rt::concat(collect_size_vars(l.clone()), collect_size_vars(r.clone())), + CostExpr::CostMax { left: l, right: r, .. } => v2_rt::concat(collect_size_vars(l.clone()), collect_size_vars(r.clone())), + CostExpr::CostLog { argument: a, .. } => collect_size_vars_from_size(a.clone()), + _ => Rc::new(vec![]), +} }) } @@ -8149,24 +4282,18 @@ pub struct DeduplicateAcc { pub fn deduplicate(items: Rc>) -> Rc> { { - let result = items.iter().cloned().fold( - Rc::new(DeduplicateAcc { - seen: v2_rt::rc_empty_map::(), - out: Rc::new(vec![]), - }), - |acc: Rc, item: String| match v2_rt::map_get( - &acc.seen.clone(), - item.clone(), - ) { - Some(_) => acc.clone(), - None => Rc::new(DeduplicateAcc { - seen: v2_rt::rc_map_insert(acc.seen.clone(), item.clone(), true), - out: v2_rt::rc_list_push(acc.out.clone(), item.clone()), - }), - }, - ); - result.out.clone() - } + let result = items.iter().cloned().fold(Rc::new(DeduplicateAcc { + seen: v2_rt::rc_empty_map::(), + out: Rc::new(vec![]), +}), |acc: Rc, item: String| match v2_rt::map_get(&acc.seen.clone(), item.clone()) { + Some(_) => acc.clone(), + None => Rc::new(DeduplicateAcc { + seen: v2_rt::rc_map_insert(acc.seen.clone(), item.clone(), true), + out: v2_rt::rc_list_push(acc.out.clone(), item.clone()), +}), +}); +result.out.clone() +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -8202,623 +4329,385 @@ pub struct MatchCostAccum { pub branch_costs: Rc>>, } -pub fn cost_of_expr( - texpr: &Rc, - func_index: &Rc>>, - scc_index: &Rc>>, - table: Rc, - parser_always_advancing: &Rc>, - recursion_ctx: &RecursionContext, - si: &Rc>>, -) -> Rc { +pub fn cost_of_expr(texpr: &Rc, func_index: &Rc>>, scc_index: &Rc>>, table: Rc, parser_always_advancing: &Rc>, recursion_ctx: &RecursionContext, si: &Rc>>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprLiteral { .. } => Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 1 }), - span: Rc::new(CostExpr::CostConst { value: 1 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: table, - }), - ExprData::ExprError { .. } => Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: table, - }), - ExprData::ExprVar { .. } => Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 1 }), - span: Rc::new(CostExpr::CostConst { value: 1 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: table, - }), - ExprData::ExprBinOp { .. } => { - let l = binop_left(texpr.clone()); - let r = binop_right(texpr.clone()); - let lr = cost_of_expr( - &l, - &func_index, - &scc_index, - table, - &parser_always_advancing, - &recursion_ctx, - &si, - ); - let rr = cost_of_expr( - &r, - &func_index, - &scc_index, - lr.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - lr.summary.clone().work.clone(), - &cost_seq( - Rc::new(CostExpr::CostConst { value: 1 }), - &rr.summary.clone().work.clone(), - ), - ), - span: cost_seq( - lr.summary.clone().span.clone(), - &cost_seq( - Rc::new(CostExpr::CostConst { value: 1 }), - &rr.summary.clone().span.clone(), - ), - ), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: rr.table.clone(), - }) - } - ExprData::ExprCall { .. } => { - let fname = expr_call_func_at(texpr.clone(), si.clone()); - let callee_result = match v2_rt::map_get(&func_index, fname.clone()) { - Some(entry) => get_or_compute_summary( - &fname, - &func_index, - &scc_index, - &table, - parser_always_advancing.clone(), - recursion_ctx.clone(), - si.clone(), - ), - None => Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 1 }), - span: Rc::new(CostExpr::CostConst { value: 1 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: table, - }), - }; - let args_result = texpr.children.clone().iter().cloned().fold( - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: callee_result.table.clone(), - }), - |acc: Rc, a: Rc| { - let ar = cost_of_expr( - &arg_value(&a), - &func_index, - &scc_index, - acc.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - acc.summary.clone().work.clone(), - &ar.summary.clone().work.clone(), - ), - span: cost_seq( - acc.summary.clone().span.clone(), - &ar.summary.clone().span.clone(), - ), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: ar.table.clone(), - }) - }, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - args_result.summary.clone().work.clone(), - &callee_result.summary.clone().work.clone(), - ), - span: cost_seq( - args_result.summary.clone().span.clone(), - &callee_result.summary.clone().span.clone(), - ), - output_size: callee_result.summary.clone().output_size.clone(), - certainty: callee_result.summary.clone().certainty.clone(), - }), - table: args_result.table.clone(), - }) - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let recv = method_receiver(texpr.clone()); - let mc_args = method_arg_nodes(texpr.clone()); - let recv_r = cost_of_expr( - &recv, - &func_index, - &scc_index, - table, - &parser_always_advancing, - &recursion_ctx, - &si, - ); - let size = receiver_size_var(recv.clone(), si.clone()); - let binder = size_binder_name(size.clone()); - let method_cost_result = if (ms.clone() == None) { - None - } else { - match (*ms.clone().unwrap()).clone() { - MethodSemantics::AlgebraMethodSemantics { - method_def: md, - cost_shape: cs, - .. - } => { - let pc = node_is_collection(&resolved_type(texpr.clone()), si.clone()); - match cs.clone() { - Some(shape) => Some(cost_of_method_by_shape( - shape.clone(), - pc, - &recv_r, - mc_args.clone(), - &size, - &binder, - func_index.clone(), - scc_index.clone(), - parser_always_advancing.clone(), - recursion_ctx.clone(), - &si, - )), - None => Some(Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - recv_r.summary.clone().work.clone(), - &Rc::new(CostExpr::CostConst { value: 1 }), - ), - span: cost_seq( - recv_r.summary.clone().span.clone(), - &Rc::new(CostExpr::CostConst { value: 1 }), - ), - output_size: v2_rt::rc_empty_map::>(), - certainty: recv_r.summary.clone().certainty.clone(), - }), - table: recv_r.table.clone(), - })), - } - } - _ => None, - } - }; - match method_cost_result { - Some(result) => result.clone(), - _ => { - let args_result = mc_args.clone().iter().cloned().fold( - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: recv_r.table.clone(), - }), - |acc: Rc, a: Rc| { - let ar = cost_of_expr( - &arg_value(&a), - &func_index, - &scc_index, - acc.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - acc.summary.clone().work.clone(), - &ar.summary.clone().work.clone(), - ), - span: cost_seq( - acc.summary.clone().span.clone(), - &ar.summary.clone().span.clone(), - ), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: ar.table.clone(), - }) - }, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - recv_r.summary.clone().work.clone(), - &cost_seq( - Rc::new(CostExpr::CostConst { value: 1 }), - &args_result.summary.clone().work.clone(), - ), - ), - span: cost_seq( - recv_r.summary.clone().span.clone(), - &cost_seq( - Rc::new(CostExpr::CostConst { value: 1 }), - &args_result.summary.clone().span.clone(), - ), - ), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: args_result.table.clone(), - }) - } - } - } - ExprData::ExprMatch => { - let scrut = match_scrutinee(texpr.clone()); - let arm_nodes = match_arm_nodes(texpr.clone()); - let s_r = cost_of_expr( - &scrut, - &func_index, - &scc_index, - table, - &parser_always_advancing, - &recursion_ctx, - &si, - ); - let arms_accum = arm_nodes.iter().cloned().fold( - Rc::new(MatchCostAccum { - result: Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: s_r.table.clone(), - }), - branch_costs: Rc::new(vec![]), - }), - |acc: Rc, arm_node: Rc| { - let ar = cost_of_expr( - &arm_body(&arm_node), - &func_index, - &scc_index, - acc.result.clone().table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(MatchCostAccum { - result: Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_par( - acc.result.clone().summary.clone().work.clone(), - &ar.summary.clone().work.clone(), - ), - span: cost_par( - acc.result.clone().summary.clone().span.clone(), - &ar.summary.clone().span.clone(), - ), - output_size: ar.summary.clone().output_size.clone(), - certainty: ar.summary.clone().certainty.clone(), - }), - table: ar.table.clone(), - }), - branch_costs: v2_rt::concat( - acc.branch_costs.clone(), - Rc::new(vec![ar.summary.clone().work.clone()]), - ), - }) - }, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_conditional( - s_r.summary.clone().work.clone(), - arms_accum.branch_costs.clone(), - ), - span: cost_conditional( - s_r.summary.clone().span.clone(), - Rc::new(vec![arms_accum.result.clone().summary.clone().span.clone()]), - ), - output_size: arms_accum - .result - .clone() - .summary - .clone() - .output_size - .clone(), - certainty: arms_accum.result.clone().summary.clone().certainty.clone(), - }), - table: arms_accum.result.clone().table.clone(), - }) - } - ExprData::ExprIf => { - let c = if_condition(texpr.clone()); - let t = if_then_branch(texpr.clone()); - let c_r = cost_of_expr( - &c, - &func_index, - &scc_index, - table, - &parser_always_advancing, - &recursion_ctx, - &si, - ); - let t_r = cost_of_expr( - &t, - &func_index, - &scc_index, - c_r.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - let e_result = match if_else_branch(texpr.clone()) { - Some(eb) => { - let er = cost_of_expr( - &eb, - &func_index, - &scc_index, - t_r.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(SummaryResult { - summary: er.summary.clone(), - table: er.table.clone(), - }) - } - None => Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: t_r.table.clone(), - }), - }; - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_conditional( - c_r.summary.clone().work.clone(), - Rc::new(vec![ - t_r.summary.clone().work.clone(), - e_result.summary.clone().work.clone(), - ]), - ), - span: cost_conditional( - c_r.summary.clone().span.clone(), - Rc::new(vec![ - t_r.summary.clone().span.clone(), - e_result.summary.clone().span.clone(), - ]), - ), - output_size: t_r.summary.clone().output_size.clone(), - certainty: Certainty::Proven, - }), - table: e_result.table.clone(), - }) - } - ExprData::ExprLet => { - let v = let_value(texpr.clone()); - let v_r = cost_of_expr( - &v, - &func_index, - &scc_index, - table, - &parser_always_advancing, - &recursion_ctx, - &si, - ); - match let_body(texpr.clone()) { - Some(b) => { - let b_r = cost_of_expr( - &b, - &func_index, - &scc_index, - v_r.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - v_r.summary.clone().work.clone(), - &b_r.summary.clone().work.clone(), - ), - span: cost_seq( - v_r.summary.clone().span.clone(), - &b_r.summary.clone().span.clone(), - ), - output_size: b_r.summary.clone().output_size.clone(), - certainty: b_r.summary.clone().certainty.clone(), - }), - table: b_r.table.clone(), - }) - } - None => v_r.clone(), - } - } - ExprData::ExprBlock => texpr.children.clone().iter().cloned().fold( - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: table, - }), - |acc: Rc, s: Rc| { - let sr = cost_of_expr( - &s, - &func_index, - &scc_index, - acc.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - acc.summary.clone().work.clone(), - &sr.summary.clone().work.clone(), - ), - span: cost_seq( - acc.summary.clone().span.clone(), - &sr.summary.clone().span.clone(), - ), - output_size: sr.summary.clone().output_size.clone(), - certainty: sr.summary.clone().certainty.clone(), - }), - table: sr.table.clone(), - }) - }, - ), - ExprData::ExprForEach => { - let c = foreach_collection(texpr.clone()); - let bd = foreach_body(texpr.clone()); - let c_r = cost_of_expr( - &c, - &func_index, - &scc_index, - table, - &parser_always_advancing, - &recursion_ctx, - &si, - ); - let bd_r = cost_of_expr( - &bd, - &func_index, - &scc_index, - c_r.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - let size = receiver_size_var(c.clone(), si.clone()); - let binder = size_binder_name(size.clone()); - let loop_work = cost_loop(binder, size.clone(), &bd_r.summary.clone().work.clone()); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq(c_r.summary.clone().work.clone(), &loop_work), - span: cost_seq(c_r.summary.clone().span.clone(), &loop_work), - output_size: v2_rt::rc_empty_map::>(), - certainty: bd_r.summary.clone().certainty.clone(), - }), - table: bd_r.table.clone(), - }) - } - ExprData::NoExprData => texpr.children.clone().iter().cloned().fold( - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: table, - }), - |acc: Rc, child: Rc| { - let cr = cost_of_expr( - &child, - &func_index, - &scc_index, - acc.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - acc.summary.clone().work.clone(), - &cr.summary.clone().work.clone(), - ), - span: cost_seq( - acc.summary.clone().span.clone(), - &cr.summary.clone().span.clone(), - ), - output_size: cr.summary.clone().output_size.clone(), - certainty: cr.summary.clone().certainty.clone(), - }), - table: cr.table.clone(), - }) - }, - ), - _ => texpr.children.clone().iter().cloned().fold( - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 1 }), - span: Rc::new(CostExpr::CostConst { value: 1 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Proven, - }), - table: table, - }), - |acc: Rc, child: Rc| { - let cr = cost_of_expr( - &child, - &func_index, - &scc_index, - acc.table.clone(), - &parser_always_advancing, - &recursion_ctx, - &si, - ); - Rc::new(SummaryResult { - summary: Rc::new(ComplexitySummary { - work: cost_seq( - acc.summary.clone().work.clone(), - &cr.summary.clone().work.clone(), - ), - span: cost_seq( - acc.summary.clone().span.clone(), - &cr.summary.clone().span.clone(), - ), - output_size: cr.summary.clone().output_size.clone(), - certainty: cr.summary.clone().certainty.clone(), - }), - table: cr.table.clone(), - }) - }, - ), - } + ExprData::ExprLiteral { .. } => Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 1, +}), + span: Rc::new(CostExpr::CostConst { + value: 1, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: table, +}), + ExprData::ExprError { .. } => Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: table, +}), + ExprData::ExprVar { .. } => Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 1, +}), + span: Rc::new(CostExpr::CostConst { + value: 1, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: table, +}), + ExprData::ExprBinOp { .. } => { + let l = binop_left(texpr.clone()); +let r = binop_right(texpr.clone()); +let lr = cost_of_expr(&l, &func_index, &scc_index, table, &parser_always_advancing, &recursion_ctx, &si); +let rr = cost_of_expr(&r, &func_index, &scc_index, lr.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(lr.summary.clone().work.clone(), &cost_seq(Rc::new(CostExpr::CostConst { + value: 1, +}), &rr.summary.clone().work.clone())), + span: cost_seq(lr.summary.clone().span.clone(), &cost_seq(Rc::new(CostExpr::CostConst { + value: 1, +}), &rr.summary.clone().span.clone())), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: rr.table.clone(), +}) +}, + ExprData::ExprCall { .. } => { + let fname = expr_call_func_at(texpr.clone(), si.clone()); +let callee_result = match v2_rt::map_get(&func_index, fname.clone()) { + Some(entry) => get_or_compute_summary(&fname, &func_index, &scc_index, &table, parser_always_advancing.clone(), recursion_ctx.clone(), si.clone()), + None => Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 1, +}), + span: Rc::new(CostExpr::CostConst { + value: 1, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: table, +}), +}; +let args_result = texpr.children.clone().iter().cloned().fold(Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: callee_result.table.clone(), +}), |acc: Rc, a: Rc| { + let ar = cost_of_expr(&arg_value(&a), &func_index, &scc_index, acc.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(acc.summary.clone().work.clone(), &ar.summary.clone().work.clone()), + span: cost_seq(acc.summary.clone().span.clone(), &ar.summary.clone().span.clone()), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: ar.table.clone(), +}) +}); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(args_result.summary.clone().work.clone(), &callee_result.summary.clone().work.clone()), + span: cost_seq(args_result.summary.clone().span.clone(), &callee_result.summary.clone().span.clone()), + output_size: callee_result.summary.clone().output_size.clone(), + certainty: callee_result.summary.clone().certainty.clone(), +}), + table: args_result.table.clone(), +}) +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let recv = method_receiver(texpr.clone()); +let mc_args = method_arg_nodes(texpr.clone()); +let recv_r = cost_of_expr(&recv, &func_index, &scc_index, table, &parser_always_advancing, &recursion_ctx, &si); +let size = receiver_size_var(recv.clone(), si.clone()); +let binder = size_binder_name(size.clone()); +let method_cost_result = if (ms.clone() == None) { + None + } else { + match (*ms.clone().unwrap()).clone() { + MethodSemantics::AlgebraMethodSemantics { method_def: md, cost_shape: cs, .. } => { + let pc = node_is_collection(&resolved_type(texpr.clone()), si.clone()); +match cs.clone() { + Some(shape) => Some(cost_of_method_by_shape(shape.clone(), pc, &recv_r, mc_args.clone(), &size, &binder, func_index.clone(), scc_index.clone(), parser_always_advancing.clone(), recursion_ctx.clone(), &si)), + None => Some(Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(recv_r.summary.clone().work.clone(), &Rc::new(CostExpr::CostConst { + value: 1, +})), + span: cost_seq(recv_r.summary.clone().span.clone(), &Rc::new(CostExpr::CostConst { + value: 1, +})), + output_size: v2_rt::rc_empty_map::>(), + certainty: recv_r.summary.clone().certainty.clone(), +}), + table: recv_r.table.clone(), +})), +} +}, + _ => None, +} + }; +match method_cost_result { + Some(result) => result.clone(), + _ => { + let args_result = mc_args.clone().iter().cloned().fold(Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: recv_r.table.clone(), +}), |acc: Rc, a: Rc| { + let ar = cost_of_expr(&arg_value(&a), &func_index, &scc_index, acc.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(acc.summary.clone().work.clone(), &ar.summary.clone().work.clone()), + span: cost_seq(acc.summary.clone().span.clone(), &ar.summary.clone().span.clone()), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: ar.table.clone(), +}) +}); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(recv_r.summary.clone().work.clone(), &cost_seq(Rc::new(CostExpr::CostConst { + value: 1, +}), &args_result.summary.clone().work.clone())), + span: cost_seq(recv_r.summary.clone().span.clone(), &cost_seq(Rc::new(CostExpr::CostConst { + value: 1, +}), &args_result.summary.clone().span.clone())), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: args_result.table.clone(), +}) +}, +} +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(texpr.clone()); +let arm_nodes = match_arm_nodes(texpr.clone()); +let s_r = cost_of_expr(&scrut, &func_index, &scc_index, table, &parser_always_advancing, &recursion_ctx, &si); +let arms_accum = arm_nodes.iter().cloned().fold(Rc::new(MatchCostAccum { + result: Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: s_r.table.clone(), +}), + branch_costs: Rc::new(vec![]), +}), |acc: Rc, arm_node: Rc| { + let ar = cost_of_expr(&arm_body(&arm_node), &func_index, &scc_index, acc.result.clone().table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(MatchCostAccum { + result: Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_par(acc.result.clone().summary.clone().work.clone(), &ar.summary.clone().work.clone()), + span: cost_par(acc.result.clone().summary.clone().span.clone(), &ar.summary.clone().span.clone()), + output_size: ar.summary.clone().output_size.clone(), + certainty: ar.summary.clone().certainty.clone(), +}), + table: ar.table.clone(), +}), + branch_costs: v2_rt::concat(acc.branch_costs.clone(), Rc::new(vec![ar.summary.clone().work.clone()])), +}) +}); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_conditional(s_r.summary.clone().work.clone(), arms_accum.branch_costs.clone()), + span: cost_conditional(s_r.summary.clone().span.clone(), Rc::new(vec![arms_accum.result.clone().summary.clone().span.clone()])), + output_size: arms_accum.result.clone().summary.clone().output_size.clone(), + certainty: arms_accum.result.clone().summary.clone().certainty.clone(), +}), + table: arms_accum.result.clone().table.clone(), +}) +}, + ExprData::ExprIf => { + let c = if_condition(texpr.clone()); +let t = if_then_branch(texpr.clone()); +let c_r = cost_of_expr(&c, &func_index, &scc_index, table, &parser_always_advancing, &recursion_ctx, &si); +let t_r = cost_of_expr(&t, &func_index, &scc_index, c_r.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +let e_result = match if_else_branch(texpr.clone()) { + Some(eb) => { + let er = cost_of_expr(&eb, &func_index, &scc_index, t_r.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(SummaryResult { + summary: er.summary.clone(), + table: er.table.clone(), +}) +}, + None => Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: t_r.table.clone(), +}), +}; +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_conditional(c_r.summary.clone().work.clone(), Rc::new(vec![t_r.summary.clone().work.clone(), e_result.summary.clone().work.clone()])), + span: cost_conditional(c_r.summary.clone().span.clone(), Rc::new(vec![t_r.summary.clone().span.clone(), e_result.summary.clone().span.clone()])), + output_size: t_r.summary.clone().output_size.clone(), + certainty: Certainty::Proven, +}), + table: e_result.table.clone(), +}) +}, + ExprData::ExprLet => { + let v = let_value(texpr.clone()); +let v_r = cost_of_expr(&v, &func_index, &scc_index, table, &parser_always_advancing, &recursion_ctx, &si); +match let_body(texpr.clone()) { + Some(b) => { + let b_r = cost_of_expr(&b, &func_index, &scc_index, v_r.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(v_r.summary.clone().work.clone(), &b_r.summary.clone().work.clone()), + span: cost_seq(v_r.summary.clone().span.clone(), &b_r.summary.clone().span.clone()), + output_size: b_r.summary.clone().output_size.clone(), + certainty: b_r.summary.clone().certainty.clone(), +}), + table: b_r.table.clone(), +}) +}, + None => v_r.clone(), +} +}, + ExprData::ExprBlock => texpr.children.clone().iter().cloned().fold(Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: table, +}), |acc: Rc, s: Rc| { + let sr = cost_of_expr(&s, &func_index, &scc_index, acc.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(acc.summary.clone().work.clone(), &sr.summary.clone().work.clone()), + span: cost_seq(acc.summary.clone().span.clone(), &sr.summary.clone().span.clone()), + output_size: sr.summary.clone().output_size.clone(), + certainty: sr.summary.clone().certainty.clone(), +}), + table: sr.table.clone(), +}) +}), + ExprData::ExprForEach => { + let c = foreach_collection(texpr.clone()); +let bd = foreach_body(texpr.clone()); +let c_r = cost_of_expr(&c, &func_index, &scc_index, table, &parser_always_advancing, &recursion_ctx, &si); +let bd_r = cost_of_expr(&bd, &func_index, &scc_index, c_r.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +let size = receiver_size_var(c.clone(), si.clone()); +let binder = size_binder_name(size.clone()); +let loop_work = cost_loop(binder, size.clone(), &bd_r.summary.clone().work.clone()); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(c_r.summary.clone().work.clone(), &loop_work), + span: cost_seq(c_r.summary.clone().span.clone(), &loop_work), + output_size: v2_rt::rc_empty_map::>(), + certainty: bd_r.summary.clone().certainty.clone(), +}), + table: bd_r.table.clone(), +}) +}, + ExprData::NoExprData => texpr.children.clone().iter().cloned().fold(Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: table, +}), |acc: Rc, child: Rc| { + let cr = cost_of_expr(&child, &func_index, &scc_index, acc.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(acc.summary.clone().work.clone(), &cr.summary.clone().work.clone()), + span: cost_seq(acc.summary.clone().span.clone(), &cr.summary.clone().span.clone()), + output_size: cr.summary.clone().output_size.clone(), + certainty: cr.summary.clone().certainty.clone(), +}), + table: cr.table.clone(), +}) +}), + _ => texpr.children.clone().iter().cloned().fold(Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 1, +}), + span: Rc::new(CostExpr::CostConst { + value: 1, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Proven, +}), + table: table, +}), |acc: Rc, child: Rc| { + let cr = cost_of_expr(&child, &func_index, &scc_index, acc.table.clone(), &parser_always_advancing, &recursion_ctx, &si); +Rc::new(SummaryResult { + summary: Rc::new(ComplexitySummary { + work: cost_seq(acc.summary.clone().work.clone(), &cr.summary.clone().work.clone()), + span: cost_seq(acc.summary.clone().span.clone(), &cr.summary.clone().span.clone()), + output_size: cr.summary.clone().output_size.clone(), + certainty: cr.summary.clone().certainty.clone(), +}), + table: cr.table.clone(), +}) +}), +} }) } @@ -8827,736 +4716,436 @@ pub fn estimate_expr_size(texpr: Rc, budget: i64) -> i64 { if (budget.clone() <= 0) { 0 } else { - texpr - .children - .clone() - .iter() - .cloned() - .fold((budget.clone() - 1), |acc: i64, child: Rc| { - estimate_expr_size(child.clone(), acc) - }) + texpr.children.clone().iter().cloned().fold((budget.clone() - 1), |acc: i64, child: Rc| estimate_expr_size(child.clone(), acc)) } }) } -pub fn get_or_compute_summary( - func_name: &String, - func_index: &Rc>>, - scc_index: &Rc>>, - table: &Rc, - parser_always_advancing: Rc>, - recursion_ctx: RecursionContext, - si: Rc>>, -) -> Rc { +pub fn get_or_compute_summary(func_name: &String, func_index: &Rc>>, scc_index: &Rc>>, table: &Rc, parser_always_advancing: Rc>, recursion_ctx: RecursionContext, si: Rc>>) -> Rc { match lookup_summary(table.clone(), func_name.clone()) { - Some(cached) => Rc::new(SummaryResult { - summary: cached.clone(), - table: table.clone(), - }), - None => match v2_rt::map_get(&func_index, func_name.clone()) { - Some(entry) => { - let target = match v2_rt::map_get(&scc_index, func_name.clone()) { - Some(info) => Some(info.pattern.clone()), - None => None, - }; - let is_recursive = (target.clone() != None); - let zero_placeholder = Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostConst { value: 0 }), - span: Rc::new(CostExpr::CostConst { value: 0 }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Conservative, - }); - let table_prepped = if is_recursive { - cache_summary(table.clone(), func_name.clone(), zero_placeholder) - } else { - table.clone() - }; - let result = cost_of_expr( - &entry.body.clone(), - &func_index, - &scc_index, - table_prepped, - &parser_always_advancing, - &recursion_ctx, - &si, - ); - let scc_members = match v2_rt::map_get(&scc_index, func_name.clone()) { - Some(info) => info.members.clone(), - None => Rc::new(vec![]), - }; - let is_scc = ((scc_members.clone().len() as i64) > 1); - let bounded = match target.clone() { - Some(t) => { - if is_scc { - Rc::new(ComplexitySummary { - work: bounded_scc_cost( - t.clone(), - result.summary.clone().work.clone(), - scc_members.clone(), - ), - span: bounded_scc_cost( - t.clone(), - result.summary.clone().span.clone(), - scc_members.clone(), - ), - output_size: result.summary.clone().output_size.clone(), - certainty: Certainty::Conservative, - }) - } else { - Rc::new(ComplexitySummary { - work: bounded_recursive_cost( - t.clone(), - result.summary.clone().work.clone(), - func_name.clone(), - ), - span: bounded_recursive_cost( - t.clone(), - result.summary.clone().span.clone(), - func_name.clone(), - ), - output_size: result.summary.clone().output_size.clone(), - certainty: Certainty::Conservative, - }) - } - } - None => result.summary.clone(), - }; - let simplified = Rc::new(ComplexitySummary { - work: simplify_cost(bounded.work.clone()), - span: simplify_cost(bounded.span.clone()), - output_size: bounded.output_size.clone(), - certainty: bounded.certainty.clone(), - }); - let final_table = - cache_summary(result.table.clone(), func_name.clone(), simplified.clone()); - Rc::new(SummaryResult { - summary: simplified.clone(), - table: final_table, - }) - } - None => { - let is_unexpected_miss = (v2_rt::map_get(&scc_index, func_name.clone()) != None); - if is_unexpected_miss { - { - let miss_summary = Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostUnknown { - reason: v2_rt::concat( - "internal function missing from index: ".to_string(), - func_name.clone(), - ), - }), - span: Rc::new(CostExpr::CostUnknown { - reason: v2_rt::concat( - "internal function missing from index: ".to_string(), - func_name.clone(), - ), - }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Conservative, - }); - Rc::new(SummaryResult { - summary: miss_summary, - table: table.clone(), - }) - } - } else { - { - let external_summary = Rc::new(ComplexitySummary { - work: Rc::new(CostExpr::CostExtern { - name: func_name.clone(), - }), - span: Rc::new(CostExpr::CostExtern { - name: func_name.clone(), - }), - output_size: v2_rt::rc_empty_map::>(), - certainty: Certainty::Conservative, - }); - Rc::new(SummaryResult { - summary: external_summary, - table: table.clone(), - }) - } - } - } + Some(cached) => Rc::new(SummaryResult { + summary: cached.clone(), + table: table.clone(), +}), + None => match v2_rt::map_get(&func_index, func_name.clone()) { + Some(entry) => { + let target = match v2_rt::map_get(&scc_index, func_name.clone()) { + Some(info) => Some(info.pattern.clone()), + None => None, +}; +let is_recursive = (target.clone() != None); +let zero_placeholder = Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostConst { + value: 0, +}), + span: Rc::new(CostExpr::CostConst { + value: 0, +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Conservative, +}); +let table_prepped = if is_recursive { + cache_summary(table.clone(), func_name.clone(), zero_placeholder) + } else { + table.clone() + }; +let result = cost_of_expr(&entry.body.clone(), &func_index, &scc_index, table_prepped, &parser_always_advancing, &recursion_ctx, &si); +let scc_members = match v2_rt::map_get(&scc_index, func_name.clone()) { + Some(info) => info.members.clone(), + None => Rc::new(vec![]), +}; +let is_scc = ((scc_members.clone().len() as i64) > 1); +let bounded = match target.clone() { + Some(t) => if is_scc { + Rc::new(ComplexitySummary { + work: bounded_scc_cost(t.clone(), result.summary.clone().work.clone(), scc_members.clone()), + span: bounded_scc_cost(t.clone(), result.summary.clone().span.clone(), scc_members.clone()), + output_size: result.summary.clone().output_size.clone(), + certainty: Certainty::Conservative, +}) + } else { + Rc::new(ComplexitySummary { + work: bounded_recursive_cost(t.clone(), result.summary.clone().work.clone(), func_name.clone()), + span: bounded_recursive_cost(t.clone(), result.summary.clone().span.clone(), func_name.clone()), + output_size: result.summary.clone().output_size.clone(), + certainty: Certainty::Conservative, +}) }, - } + None => result.summary.clone(), +}; +let simplified = Rc::new(ComplexitySummary { + work: simplify_cost(bounded.work.clone()), + span: simplify_cost(bounded.span.clone()), + output_size: bounded.output_size.clone(), + certainty: bounded.certainty.clone(), +}); +let final_table = cache_summary(result.table.clone(), func_name.clone(), simplified.clone()); +Rc::new(SummaryResult { + summary: simplified.clone(), + table: final_table, +}) +}, + None => { + let is_unexpected_miss = (v2_rt::map_get(&scc_index, func_name.clone()) != None); +if is_unexpected_miss { + { + let miss_summary = Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostUnknown { + reason: v2_rt::concat("internal function missing from index: ".to_string(), func_name.clone()), +}), + span: Rc::new(CostExpr::CostUnknown { + reason: v2_rt::concat("internal function missing from index: ".to_string(), func_name.clone()), +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Conservative, +}); +Rc::new(SummaryResult { + summary: miss_summary, + table: table.clone(), +}) +} + } else { + { + let external_summary = Rc::new(ComplexitySummary { + work: Rc::new(CostExpr::CostExtern { + name: func_name.clone(), +}), + span: Rc::new(CostExpr::CostExtern { + name: func_name.clone(), +}), + output_size: v2_rt::rc_empty_map::>(), + certainty: Certainty::Conservative, +}); +Rc::new(SummaryResult { + summary: external_summary, + table: table.clone(), +}) +} + } +}, +}, +} } -pub fn collect_call_evidence( - body: &Rc, - target_set: &Rc>, - si: &Rc>>, -) -> Rc>>>> { +pub fn collect_call_evidence(body: &Rc, target_set: &Rc>, si: &Rc>>) -> Rc>>>> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { - descent_evidence: de, - .. - } => { - let callee = expr_call_func_at(body.clone(), si.clone()); - let own = if (v2_rt::map_get(&target_set, callee) != None) { - match de.clone() { - Some(evidence) => Rc::new(vec![evidence.clone()]), - None => Rc::new(vec![]), - } - } else { - Rc::new(vec![]) - }; - let from_children = body.children.clone().iter().cloned().fold( - Rc::new(vec![]), - |acc: _, child: Rc| { - v2_rt::concat(acc, collect_call_evidence(&child, &target_set, &si)) - }, - ); - v2_rt::concat(own, from_children) - } - _ => body.children.clone().iter().cloned().fold( - Rc::new(vec![]), - |acc: Rc>>>>, child: Rc| { - v2_rt::concat(acc, collect_call_evidence(&child, &target_set, &si)) - }, - ), - } + ExprData::ExprCall { descent_evidence: de, .. } => { + let callee = expr_call_func_at(body.clone(), si.clone()); +let own = if (v2_rt::map_get(&target_set, callee) != None) { + match de.clone() { + Some(evidence) => Rc::new(vec![evidence.clone()]), + None => Rc::new(vec![]), +} + } else { + Rc::new(vec![]) + }; +let from_children = body.children.clone().iter().cloned().fold(Rc::new(vec![]), |acc: _, child: Rc| v2_rt::concat(acc, collect_call_evidence(&child, &target_set, &si))); +v2_rt::concat(own, from_children) +}, + _ => body.children.clone().iter().cloned().fold(Rc::new(vec![]), |acc: Rc>>>>, child: Rc| v2_rt::concat(acc, collect_call_evidence(&child, &target_set, &si))), +} }) } -pub fn collect_self_call_evidence( - body: Rc, - fn_name: String, - si: Rc>>, -) -> Rc>>>> { - collect_call_evidence( - &body, - &v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), fn_name, true), - &si, - ) +pub fn collect_self_call_evidence(body: Rc, fn_name: String, si: Rc>>) -> Rc>>>> { + collect_call_evidence(&body, &v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), fn_name, true), &si) } -pub fn collect_callee_evidence( - body: Rc, - callee_name: String, - si: Rc>>, -) -> Rc>>>> { - collect_call_evidence( - &body, - &v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), callee_name, true), - &si, - ) +pub fn collect_callee_evidence(body: Rc, callee_name: String, si: Rc>>) -> Rc>>>> { + collect_call_evidence(&body, &v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), callee_name, true), &si) } pub fn derive_edge_evidence(all_calls: Rc>>>>) -> DescentEvidence { - all_calls.iter().cloned().fold( - DescentEvidence::Strict, - |worst: DescentEvidence, call_ev: Rc>>| { - let call_best = call_ev.clone().iter().cloned().fold( - DescentEvidence::DescentUnknown, - |best: DescentEvidence, rel: Rc| { - let ev = sub_value_to_evidence(rel.clone()); - match ev.clone() { - DescentEvidence::Strict => DescentEvidence::Strict, - _ => match best { - DescentEvidence::Strict => DescentEvidence::Strict, - DescentEvidence::NonIncreasing => DescentEvidence::NonIncreasing, - _ => ev.clone(), - }, - } - }, - ); - merge_evidence(worst, call_best.clone()) - }, - ) -} - -pub fn merge_param_evidence( - all_calls: Rc>>>>, - param_index: i64, -) -> DescentEvidence { - all_calls.iter().cloned().fold( - DescentEvidence::Strict, - |acc: DescentEvidence, call_evidence: Rc>>| match call_evidence - .clone() - .get(param_index.clone() as usize) - .cloned() - { - Some(rel) => merge_evidence(acc.clone(), sub_value_to_evidence(rel.clone())), - None => acc.clone(), - }, - ) + all_calls.iter().cloned().fold(DescentEvidence::Strict, |worst: DescentEvidence, call_ev: Rc>>| { + let call_best = call_ev.clone().iter().cloned().fold(DescentEvidence::DescentUnknown, |best: DescentEvidence, rel: Rc| { + let ev = sub_value_to_evidence(rel.clone()); +match ev.clone() { + DescentEvidence::Strict => DescentEvidence::Strict, + _ => match best { + DescentEvidence::Strict => DescentEvidence::Strict, + DescentEvidence::NonIncreasing => DescentEvidence::NonIncreasing, + _ => ev.clone(), +}, +} +}); +merge_evidence(worst, call_best.clone()) +}) } -pub fn extract_shrink_factor( - all_calls: Rc>>>>, - param_index: i64, -) -> Option> { - all_calls.iter().cloned().fold( - Some(Rc::new(ShrinkFactor::UnitShrink)), - |acc: Option>, call_evidence: Rc>>| match acc - .clone() - { - None => None, - Some(prev) => match call_evidence - .clone() - .get(param_index.clone() as usize) - .cloned() - { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { factor: f, .. } => { - match (*prev.clone()).clone() { - ShrinkFactor::UnitShrink => Some(f.clone()), - _ => { - if (prev.clone() == f.clone()) { - acc.clone() - } else { - None - } - } - } - } - SubValueRelation::ArithmeticDescent { factor: f, .. } => { - match (*prev.clone()).clone() { - ShrinkFactor::UnitShrink => Some(f.clone()), - _ => { - if (prev.clone() == f.clone()) { - acc.clone() - } else { - None - } - } - } - } - _ => acc.clone(), - }, - None => acc.clone(), - }, - }, - ) +pub fn merge_param_evidence(all_calls: Rc>>>>, param_index: i64) -> DescentEvidence { + all_calls.iter().cloned().fold(DescentEvidence::Strict, |acc: DescentEvidence, call_evidence: Rc>>| match call_evidence.clone().get(param_index.clone() as usize).cloned() { + Some(rel) => merge_evidence(acc.clone(), sub_value_to_evidence(rel.clone())), + None => acc.clone(), +}) +} + +pub fn extract_shrink_factor(all_calls: Rc>>>>, param_index: i64) -> Option> { + all_calls.iter().cloned().fold(Some(Rc::new(ShrinkFactor::UnitShrink)), |acc: Option>, call_evidence: Rc>>| match acc.clone() { + None => None, + Some(prev) => match call_evidence.clone().get(param_index.clone() as usize).cloned() { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { factor: f, .. } => match (*prev.clone()).clone() { + ShrinkFactor::UnitShrink => Some(f.clone()), + _ => if (prev.clone() == f.clone()) { + acc.clone() + } else { + None + }, +}, + SubValueRelation::ArithmeticDescent { factor: f, .. } => match (*prev.clone()).clone() { + ShrinkFactor::UnitShrink => Some(f.clone()), + _ => if (prev.clone() == f.clone()) { + acc.clone() + } else { + None + }, +}, + _ => acc.clone(), +}, + None => acc.clone(), +}, +}) } -pub fn max_path_descending( - body: &Rc, - fn_name: &String, - param_index: i64, - si: &Rc>>, -) -> i64 { +pub fn max_path_descending(body: &Rc, fn_name: &String, param_index: i64, si: &Rc>>) -> i64 { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { - descent_evidence: de, - .. - } => { - let callee = expr_call_func_at(body.clone(), si.clone()); - let own = if (callee.as_str() == fn_name.clone().as_str()) { - match de.clone() { - Some(evidence) => { - match evidence.clone().get(param_index.clone() as usize).cloned() { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { .. } => 1, - SubValueRelation::IteratedSubValue { .. } => 1, - SubValueRelation::ArithmeticDescent { .. } => 1, - _ => 0, - }, - None => 0, - } - } - None => 0, - } - } else { - 0 - }; - let from_children = - body.children - .clone() - .iter() - .cloned() - .fold(0, |acc: i64, child: Rc| { - (acc + max_path_descending(&child, &fn_name, param_index.clone(), &si)) - }); - (own + from_children) - } - ExprData::ExprIf => { - let cond_count = max_path_descending( - &if_condition(body.clone()), - &fn_name, - param_index.clone(), - &si, - ); - let then_count = max_path_descending( - &if_then_branch(body.clone()), - &fn_name, - param_index.clone(), - &si, - ); - let else_branch = if_else_branch(body.clone()); - let else_count = match else_branch { - Some(eb) => max_path_descending(&eb, &fn_name, param_index.clone(), &si), - None => 0, - }; - let branch_max = if (then_count.clone() > else_count.clone()) { - then_count.clone() + ExprData::ExprCall { descent_evidence: de, .. } => { + let callee = expr_call_func_at(body.clone(), si.clone()); +let own = if (callee.as_str() == fn_name.clone().as_str()) { + match de.clone() { + Some(evidence) => match evidence.clone().get(param_index.clone() as usize).cloned() { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { .. } => 1, + SubValueRelation::IteratedSubValue { .. } => 1, + SubValueRelation::ArithmeticDescent { .. } => 1, + _ => 0, +}, + None => 0, +}, + None => 0, +} + } else { + 0 + }; +let from_children = body.children.clone().iter().cloned().fold(0, |acc: i64, child: Rc| (acc + max_path_descending(&child, &fn_name, param_index.clone(), &si))); +(own + from_children) +}, + ExprData::ExprIf => { + let cond_count = max_path_descending(&if_condition(body.clone()), &fn_name, param_index.clone(), &si); +let then_count = max_path_descending(&if_then_branch(body.clone()), &fn_name, param_index.clone(), &si); +let else_branch = if_else_branch(body.clone()); +let else_count = match else_branch { + Some(eb) => max_path_descending(&eb, &fn_name, param_index.clone(), &si), + None => 0, +}; +let branch_max = if (then_count.clone() > else_count.clone()) { + then_count.clone() + } else { + else_count.clone() + }; +(cond_count + branch_max) +}, + ExprData::ExprMatch => { + let scrut_count = max_path_descending(&match_scrutinee(body.clone()), &fn_name, param_index.clone(), &si); +let arms = match_arm_nodes(body.clone()); +let arm_max = arms.iter().cloned().fold(0, |acc: i64, arm: Rc| { + let arm_count = max_path_descending(&arm_body(&arm), &fn_name, param_index.clone(), &si); +if (arm_count.clone() > acc.clone()) { + arm_count.clone() } else { - else_count.clone() - }; - (cond_count + branch_max) - } - ExprData::ExprMatch => { - let scrut_count = max_path_descending( - &match_scrutinee(body.clone()), - &fn_name, - param_index.clone(), - &si, - ); - let arms = match_arm_nodes(body.clone()); - let arm_max = arms.iter().cloned().fold(0, |acc: i64, arm: Rc| { - let arm_count = - max_path_descending(&arm_body(&arm), &fn_name, param_index.clone(), &si); - if (arm_count.clone() > acc.clone()) { - arm_count.clone() - } else { - acc.clone() - } - }); - (scrut_count + arm_max) - } - _ => body - .children - .clone() - .iter() - .cloned() - .fold(0, |acc: i64, child: Rc| { - (acc + max_path_descending(&child, &fn_name, param_index.clone(), &si)) - }), - } + acc.clone() + } +}); +(scrut_count + arm_max) +}, + _ => body.children.clone().iter().cloned().fold(0, |acc: i64, child: Rc| (acc + max_path_descending(&child, &fn_name, param_index.clone(), &si))), +} }) } -pub fn distinct_descended_fields( - all_calls: Rc>>>>, - param_index: i64, -) -> i64 { +pub fn distinct_descended_fields(all_calls: Rc>>>>, param_index: i64) -> i64 { { - let field_set = all_calls.iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, call_evidence: Rc>>| { - match call_evidence - .clone() - .get(param_index.clone() as usize) - .cloned() - { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { field: f, .. } => { - v2_rt::rc_map_insert(acc.clone(), f.field_name.clone(), true) - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - v2_rt::rc_map_insert(acc.clone(), f.field_name.clone(), true) - } - _ => acc.clone(), - }, - None => acc.clone(), - } - }, - ); - (Rc::new(v2_rt::map_keys(&field_set)).len() as i64) - } + let field_set = all_calls.iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, call_evidence: Rc>>| match call_evidence.clone().get(param_index.clone() as usize).cloned() { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => v2_rt::rc_map_insert(acc.clone(), f.field_name.clone(), true), + SubValueRelation::IteratedSubValue { field: f, .. } => v2_rt::rc_map_insert(acc.clone(), f.field_name.clone(), true), + _ => acc.clone(), +}, + None => acc.clone(), +}); +(Rc::new(v2_rt::map_keys(&field_set)).len() as i64) +} } -pub fn analyze_structural_bounds( - func_entries: Rc>>, - si: Rc>>, -) -> Rc>> { - func_entries.iter().cloned().fold( - Rc::new(vec![]), - |acc: Rc>>, entry: Rc| { - let all_calls = - collect_self_call_evidence(entry.body.clone(), entry.name.clone(), si.clone()); - if ((all_calls.clone().len() as i64) == 0) { - acc.clone() - } else { - { - let param_results = Rc::new( - entry - .params - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold(Rc::new(vec![]), |pacc: _, pair: (i64, Rc)| { - let param_index = pair.0.clone(); - let param_node = pair.1.clone(); - let evidence = merge_param_evidence(all_calls.clone(), param_index.clone()); - match evidence.clone() { - DescentEvidence::Strict => { - let param_name = param_node_name_at(param_node.clone(), si.clone()); - let factor_opt = - extract_shrink_factor(all_calls.clone(), param_index.clone()); - match factor_opt.clone() { - Some(factor) => { - let branches = max_path_descending( - &entry.body.clone(), - &entry.name.clone(), - param_index.clone(), - &si, - ); - let recurrence = match (*factor.clone()).clone() { - ShrinkFactor::UnitShrink => { - let distinct_fields = distinct_descended_fields( - all_calls.clone(), - param_index.clone(), - ); - if (branches.clone() <= distinct_fields.clone()) { - catamorphism_bound(param_name.clone(), 1) - } else { - derive_bound( - param_name.clone(), - branches.clone(), - factor.clone(), - 0, - ) - } - } - ShrinkFactor::ConstantShrink { .. } => { - let distinct_fields = distinct_descended_fields( - all_calls.clone(), - param_index.clone(), - ); - if (branches.clone() <= distinct_fields.clone()) { - catamorphism_bound(param_name.clone(), 1) - } else { - derive_bound( - param_name.clone(), - branches.clone(), - factor.clone(), - 0, - ) - } - } - ShrinkFactor::ProportionalShrink { .. } => { - derive_bound( - param_name.clone(), - branches.clone(), - factor.clone(), - 0, - ) - } - }; - let stack_bound = if entry.is_tail_recursive.clone() { - Rc::new(CostBound::ConstantBound) - } else { - derive_bound(param_name.clone(), 1, factor.clone(), 0) - }; - v2_rt::concat( - pacc.clone(), - Rc::new(vec![Rc::new(StructuralBoundResult { - func_name: entry.name.clone(), - param: param_name.clone(), - recurrence_bound: recurrence.clone(), - stack_bound: stack_bound.clone(), - span: entry.span.clone(), - })]), - ) - } - None => pacc.clone(), +pub fn analyze_structural_bounds(func_entries: Rc>>, si: Rc>>) -> Rc>> { + func_entries.iter().cloned().fold(Rc::new(vec![]), |acc: Rc>>, entry: Rc| { + let all_calls = collect_self_call_evidence(entry.body.clone(), entry.name.clone(), si.clone()); +if ((all_calls.clone().len() as i64) == 0) { + acc.clone() + } else { + { + let param_results = Rc::new(entry.params.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(Rc::new(vec![]), |pacc: _, pair: (i64, Rc)| { + let param_index = pair.0.clone(); +let param_node = pair.1.clone(); +let evidence = merge_param_evidence(all_calls.clone(), param_index.clone()); +match evidence.clone() { + DescentEvidence::Strict => { + let param_name = param_node_name_at(param_node.clone(), si.clone()); +let factor_opt = extract_shrink_factor(all_calls.clone(), param_index.clone()); +match factor_opt.clone() { + Some(factor) => { + let branches = max_path_descending(&entry.body.clone(), &entry.name.clone(), param_index.clone(), &si); +let recurrence = match (*factor.clone()).clone() { + ShrinkFactor::UnitShrink => { + let distinct_fields = distinct_descended_fields(all_calls.clone(), param_index.clone()); +if (branches.clone() <= distinct_fields.clone()) { + catamorphism_bound(param_name.clone(), 1) + } else { + derive_bound(param_name.clone(), branches.clone(), factor.clone(), 0) } - } - _ => pacc.clone(), - } - }); - v2_rt::concat(acc.clone(), param_results.clone()) - } - } - }, - ) +}, + ShrinkFactor::ConstantShrink { .. } => { + let distinct_fields = distinct_descended_fields(all_calls.clone(), param_index.clone()); +if (branches.clone() <= distinct_fields.clone()) { + catamorphism_bound(param_name.clone(), 1) + } else { + derive_bound(param_name.clone(), branches.clone(), factor.clone(), 0) + } +}, + ShrinkFactor::ProportionalShrink { .. } => derive_bound(param_name.clone(), branches.clone(), factor.clone(), 0), +}; +let stack_bound = if entry.is_tail_recursive.clone() { + Rc::new(CostBound::ConstantBound) + } else { + derive_bound(param_name.clone(), 1, factor.clone(), 0) + }; +v2_rt::concat(pacc.clone(), Rc::new(vec![Rc::new(StructuralBoundResult { + func_name: entry.name.clone(), + param: param_name.clone(), + recurrence_bound: recurrence.clone(), + stack_bound: stack_bound.clone(), + span: entry.span.clone(), +})])) +}, + None => pacc.clone(), +} +}, + _ => pacc.clone(), +} +}); +v2_rt::concat(acc.clone(), param_results.clone()) +} + } +}) } -pub fn build_complexity_report( - func_entries: &Rc>>, - recursion_ctx: RecursionContext, - source_indices: Rc>>, -) -> Rc { +pub fn build_complexity_report(func_entries: &Rc>>, recursion_ctx: RecursionContext, source_indices: Rc>>) -> Rc { { let si = source_indices; - let func_index = func_entries.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, entry: Rc| { - v2_rt::rc_map_insert(acc, entry.name.clone(), entry.clone()) - }, - ); - let scc_result = build_scc_index(&func_entries, func_index.clone(), &si); - let parser_always_advancing = infer_all_parser_always_advancing(&func_index, &si); - let full_scc_index = func_entries.clone().iter().cloned().fold( - scc_result.index.clone(), - |acc: Rc>>, entry: Rc| match v2_rt::map_get( - &acc, - entry.name.clone(), - ) { - Some(_) => acc.clone(), - None => { - if (max_path_self_calls(entry.body.clone(), entry.name.clone(), si.clone()) > 0) - { - { - let pattern = classify_recursion_pattern( - &entry.name.clone(), - &entry.body.clone(), - &entry.params.clone(), - parser_always_advancing.clone(), - &si, - ); - let info = Rc::new(SccInfo { - members: Rc::new(vec![entry.name.clone()]), - member_set: v2_rt::rc_map_insert( - v2_rt::rc_empty_map::(), - entry.name.clone(), - true, - ), - pattern: pattern.clone(), - }); - v2_rt::rc_map_insert(acc.clone(), entry.name.clone(), info.clone()) - } - } else { - acc.clone() - } - } - }, - ); - let fan_in = func_entries.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, entry: Rc| { - let callees = match v2_rt::map_get( - &scc_result.call_graph.clone().forward.clone(), - entry.name.clone(), - ) { - Some(cs) => cs.clone(), - None => Rc::new(vec![]), - }; - let unique_set = callees.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |s: Rc>, c: String| { - v2_rt::rc_map_insert(s, c.clone(), true) - }, - ); - Rc::new(v2_rt::map_keys(&unique_set)).iter().cloned().fold( - acc, - |inner: Rc>, callee: String| { - let current = match v2_rt::map_get(&inner, callee.clone()) { - Some(v) => v.clone(), - None => 0, - }; - v2_rt::rc_map_insert(inner.clone(), callee.clone(), (current.clone() + 1)) - }, - ) - }, - ); - let result = scc_result.processing_order.clone().iter().cloned().fold( - Rc::new(TopoBuildAcc { - table: empty_intern_table(), - classes: v2_rt::rc_empty_map::(), - violations: Rc::new(vec![]), - fan_in: fan_in, - processed: v2_rt::rc_empty_map::(), - }), - |acc: Rc, func_name: String| match v2_rt::map_get( - &func_index, - func_name.clone(), - ) { - Some(entry) => { - let sr = get_or_compute_summary( - &func_name, - &func_index, - &full_scc_index, - &acc.table.clone(), - parser_always_advancing.clone(), - recursion_ctx.clone(), - si.clone(), - ); - let class_str = classify_complexity(sr.summary.clone().work.clone()); - let new_classes = v2_rt::rc_map_insert( - acc.classes.clone(), - func_name.clone(), - class_str.clone(), - ); - let new_processed = - v2_rt::rc_map_insert(acc.processed.clone(), func_name.clone(), true); - let new_violations = if is_unknown_cost(sr.summary.clone().work.clone()) { - v2_rt::concat( - acc.violations.clone(), - Rc::new(vec![Rc::new(ComplexityViolation { - func_name: func_name.clone(), - reason: extract_unknown_reason(sr.summary.clone().work.clone()), - span: entry.span.clone(), - })]), - ) - } else { - acc.violations.clone() - }; - let callees = match v2_rt::map_get( - &scc_result.call_graph.clone().forward.clone(), - func_name.clone(), - ) { - Some(cs) => cs.clone(), - None => Rc::new(vec![]), - }; - let unique_set = callees.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |s: Rc>, c: String| { - v2_rt::rc_map_insert(s, c.clone(), true) - }, - ); - let unique_callees = Rc::new(v2_rt::map_keys(&unique_set)); - let new_fan_in = unique_callees.clone().iter().cloned().fold( - acc.fan_in.clone(), - |fi: Rc>, callee: String| { - let current = match v2_rt::map_get(&fi, callee.clone()) { - Some(v) => v.clone(), - None => 0, - }; - v2_rt::rc_map_insert(fi.clone(), callee.clone(), (current.clone() - 1)) - }, - ); - let evicted_table = unique_callees.clone().iter().cloned().fold( - sr.table.clone(), - |t: Rc, callee: String| { - let remaining = match v2_rt::map_get(&new_fan_in, callee.clone()) { - Some(v) => v.clone(), - None => 0, - }; - if ((remaining.clone() <= 0) - && set_has(new_processed.clone(), callee.clone())) - { - evict_summary(t.clone(), callee.clone()) - } else { - t.clone() - } - }, - ); - let self_fan_in = match v2_rt::map_get(&new_fan_in, func_name.clone()) { - Some(v) => v.clone(), - None => 0, - }; - let final_table = if (self_fan_in.clone() <= 0) { - evict_summary(evicted_table.clone(), func_name.clone()) - } else { - evicted_table.clone() - }; - Rc::new(TopoBuildAcc { - table: final_table.clone(), - classes: new_classes.clone(), - violations: new_violations.clone(), - fan_in: new_fan_in.clone(), - processed: new_processed.clone(), - }) +let func_index = func_entries.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, entry: Rc| v2_rt::rc_map_insert(acc, entry.name.clone(), entry.clone())); +let scc_result = build_scc_index(&func_entries, func_index.clone(), &si); +let parser_always_advancing = infer_all_parser_always_advancing(&func_index, &si); +let full_scc_index = func_entries.clone().iter().cloned().fold(scc_result.index.clone(), |acc: Rc>>, entry: Rc| match v2_rt::map_get(&acc, entry.name.clone()) { + Some(_) => acc.clone(), + None => if (max_path_self_calls(entry.body.clone(), entry.name.clone(), si.clone()) > 0) { + { + let pattern = classify_recursion_pattern(&entry.name.clone(), &entry.body.clone(), &entry.params.clone(), parser_always_advancing.clone(), &si); +let info = Rc::new(SccInfo { + members: Rc::new(vec![entry.name.clone()]), + member_set: v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), entry.name.clone(), true), + pattern: pattern.clone(), +}); +v2_rt::rc_map_insert(acc.clone(), entry.name.clone(), info.clone()) +} + } else { + acc.clone() + }, +}); +let fan_in = func_entries.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, entry: Rc| { + let callees = match v2_rt::map_get(&scc_result.call_graph.clone().forward.clone(), entry.name.clone()) { + Some(cs) => cs.clone(), + None => Rc::new(vec![]), +}; +let unique_set = callees.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |s: Rc>, c: String| v2_rt::rc_map_insert(s, c.clone(), true)); +Rc::new(v2_rt::map_keys(&unique_set)).iter().cloned().fold(acc, |inner: Rc>, callee: String| { + let current = match v2_rt::map_get(&inner, callee.clone()) { + Some(v) => v.clone(), + None => 0, +}; +v2_rt::rc_map_insert(inner.clone(), callee.clone(), (current.clone() + 1)) +}) +}); +let result = scc_result.processing_order.clone().iter().cloned().fold(Rc::new(TopoBuildAcc { + table: empty_intern_table(), + classes: v2_rt::rc_empty_map::(), + violations: Rc::new(vec![]), + fan_in: fan_in, + processed: v2_rt::rc_empty_map::(), +}), |acc: Rc, func_name: String| match v2_rt::map_get(&func_index, func_name.clone()) { + Some(entry) => { + let sr = get_or_compute_summary(&func_name, &func_index, &full_scc_index, &acc.table.clone(), parser_always_advancing.clone(), recursion_ctx.clone(), si.clone()); +let class_str = classify_complexity(sr.summary.clone().work.clone()); +let new_classes = v2_rt::rc_map_insert(acc.classes.clone(), func_name.clone(), class_str.clone()); +let new_processed = v2_rt::rc_map_insert(acc.processed.clone(), func_name.clone(), true); +let new_violations = if is_unknown_cost(sr.summary.clone().work.clone()) { + v2_rt::concat(acc.violations.clone(), Rc::new(vec![Rc::new(ComplexityViolation { + func_name: func_name.clone(), + reason: extract_unknown_reason(sr.summary.clone().work.clone()), + span: entry.span.clone(), +})])) + } else { + acc.violations.clone() + }; +let callees = match v2_rt::map_get(&scc_result.call_graph.clone().forward.clone(), func_name.clone()) { + Some(cs) => cs.clone(), + None => Rc::new(vec![]), +}; +let unique_set = callees.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |s: Rc>, c: String| v2_rt::rc_map_insert(s, c.clone(), true)); +let unique_callees = Rc::new(v2_rt::map_keys(&unique_set)); +let new_fan_in = unique_callees.clone().iter().cloned().fold(acc.fan_in.clone(), |fi: Rc>, callee: String| { + let current = match v2_rt::map_get(&fi, callee.clone()) { + Some(v) => v.clone(), + None => 0, +}; +v2_rt::rc_map_insert(fi.clone(), callee.clone(), (current.clone() - 1)) +}); +let evicted_table = unique_callees.clone().iter().cloned().fold(sr.table.clone(), |t: Rc, callee: String| { + let remaining = match v2_rt::map_get(&new_fan_in, callee.clone()) { + Some(v) => v.clone(), + None => 0, +}; +if ((remaining.clone() <= 0) && set_has(new_processed.clone(), callee.clone())) { + evict_summary(t.clone(), callee.clone()) + } else { + t.clone() } - None => acc.clone(), - }, - ); - let structural_bounds = analyze_structural_bounds(func_entries.clone(), si.clone()); - Rc::new(ComplexityReport { - function_classes: result.classes.clone(), - violations: result.violations.clone(), - structural_bounds: structural_bounds, - }) - } +}); +let self_fan_in = match v2_rt::map_get(&new_fan_in, func_name.clone()) { + Some(v) => v.clone(), + None => 0, +}; +let final_table = if (self_fan_in.clone() <= 0) { + evict_summary(evicted_table.clone(), func_name.clone()) + } else { + evicted_table.clone() + }; +Rc::new(TopoBuildAcc { + table: final_table.clone(), + classes: new_classes.clone(), + violations: new_violations.clone(), + fan_in: new_fan_in.clone(), + processed: new_processed.clone(), +}) +}, + None => acc.clone(), +}); +let structural_bounds = analyze_structural_bounds(func_entries.clone(), si.clone()); +Rc::new(ComplexityReport { + function_classes: result.classes.clone(), + violations: result.violations.clone(), + structural_bounds: structural_bounds, +}) +} } diff --git a/src/v2/stage0/src/v2_compiler_effect_derivation.rs b/src/v2/stage0/src/v2_compiler_effect_derivation.rs index d94a7701862..c3249dc60df 100644 --- a/src/v2/stage0/src/v2_compiler_effect_derivation.rs +++ b/src/v2/stage0/src/v2_compiler_effect_derivation.rs @@ -1,49 +1,28 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.effect_derivation -use crate::std_effects::DeriveOpEffectResult::{ - DerivedEffect, MalformedPathInput, UnknownHttpMethodInput, -}; -use crate::std_effects::EffectShape::{ - AppendEffect, CreateEffect, DeleteEffect, ReadEffect, UpsertEffect, -}; -use crate::std_effects::IdempotencyEvidence::{IdentityEffect, LatticeEffect, NonIdempotent}; -use crate::std_effects::KeySource::{CompositeKey, InputField, PathParam}; -use crate::std_effects::ModifierAgreement::{Agrees, DerivationUnknown, Disagrees}; -pub use crate::std_effects::{ - check_modifier_vs_derivation, compose_effects, derive_effect_shape, derive_op_effect, - generate_idempotency_obligations, is_idempotent_effect, parse_http_method, ComposedEffect, - DeriveOpEffectResult, DerivedOpEffect, EffectShape, IdempotencyEvidence, - IdempotencyTestObligation, KeySource, ModifierAgreement, ModifierCheck, OperationEffect, - WorkflowEffectConcern, -}; -use crate::std_http_path::PathTemplateParseResult::{MalformedPathTemplate, ParsedPathTemplate}; -use crate::std_http_path::UrlPathToken::{LiteralToken, ParamToken}; -pub use crate::std_http_path::{ - has_path_params, last_path_param, parse_path_template, PathTemplate, PathTemplateParseResult, - UrlPathToken, -}; -pub use crate::std_types::HttpMethod; -use crate::std_types::HttpMethod::{DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{HttpMethod}; +use crate::std_types::HttpMethod::{GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS}; +pub use crate::std_effects::{EffectShape, KeySource, DerivedOpEffect, DeriveOpEffectResult, ModifierAgreement, ModifierCheck, IdempotencyTestObligation, WorkflowEffectConcern, parse_http_method, derive_effect_shape, derive_op_effect, check_modifier_vs_derivation, generate_idempotency_obligations, is_idempotent_effect, compose_effects, OperationEffect, ComposedEffect, IdempotencyEvidence}; +use crate::std_effects::EffectShape::{ReadEffect, UpsertEffect, DeleteEffect, CreateEffect, AppendEffect}; +use crate::std_effects::KeySource::{PathParam, InputField, CompositeKey}; +use crate::std_effects::DeriveOpEffectResult::{DerivedEffect, UnknownHttpMethodInput, MalformedPathInput}; +use crate::std_effects::ModifierAgreement::{Agrees, Disagrees, DerivationUnknown}; +use crate::std_effects::IdempotencyEvidence::{LatticeEffect, IdentityEffect, NonIdempotent}; +pub use crate::std_http_path::{UrlPathToken, PathTemplate, PathTemplateParseResult, parse_path_template, has_path_params, last_path_param}; +use crate::std_http_path::UrlPathToken::{LiteralToken, ParamToken}; +use crate::std_http_path::PathTemplateParseResult::{ParsedPathTemplate, MalformedPathTemplate}; -pub fn re_export_derive_op_effect( - operation_name: String, - method: HttpMethod, - path: Rc, -) -> Rc { - derive_op_effect(operation_name, method, path) +pub fn re_export_derive_op_effect(operation_name: String, method_str: String, path_str: String) -> Rc { + derive_op_effect(operation_name, &method_str, path_str) } -pub fn re_export_check_modifier( - op: Rc, - declared_idempotent: bool, - declared_readonly: bool, -) -> Rc { +pub fn re_export_check_modifier(op: Rc, declared_idempotent: bool, declared_readonly: bool) -> Rc { check_modifier_vs_derivation(&op, &declared_idempotent, &declared_readonly) } diff --git a/src/v2/stage0/src/v2_compiler_emit.rs b/src/v2/stage0/src/v2_compiler_emit.rs index df72c0995f7..3ec4298eb70 100644 --- a/src/v2/stage0/src/v2_compiler_emit.rs +++ b/src/v2/stage0/src/v2_compiler_emit.rs @@ -1,102 +1,57 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.emit -use self::BackendCapability::*; -use self::ExprCategory::*; -use self::FuncBodyShape::*; -use self::TcoExprShape::*; -pub use crate::generated_method_template_projection::{ - go_method_template_emit, python_method_template_emit, rust_method_template_emit, -}; -use crate::std_induction::SubValueRelation::SubValueUnknown; -pub use crate::std_induction::{InductiveField, SubValueRelation}; -pub use crate::std_types::{container_template_algebra, is_container_type}; -pub use crate::v2_compiler_artifact::RenderTarget; -use crate::v2_compiler_artifact::RenderTarget::{Dag, Go, Python, Rust}; -pub use crate::v2_compiler_coercion::{ - can_cast, coerce_container_template, coerce_primitive_type, literal_suffix, render_cast, - target_callable, target_optional_template, -}; -pub use crate::v2_compiler_infer::{build_params_scope, extend_scope, InferScope}; -pub use crate::v2_compiler_infer_emit_info::{EmitGraphInfo, TypeSummary}; -pub use crate::v2_compiler_infer_env::{authored_name, TypeBinding, TypeEnv}; -pub use crate::v2_compiler_infer_items::{ItemInfo, ResolvedGraph, TypedModule}; -pub use crate::v2_compiler_infer_service::{ - extract_typed_service_name, is_typed_service_call_receiver, OpEntry, UniqueAccum, -}; -pub use crate::v2_compiler_infer_sigs::{ResolvedFuncEnv, ResolvedFuncSig}; -pub use crate::v2_compiler_infer_types::{ - child_type_node, emit_map_has, for_each_element_type_node, is_unit_like, node_is_collection, - node_is_element_collection, node_is_keyed_collection, normalize_access_type_node, - resolved_type, -}; -use crate::v2_compiler_languages::IfValueForm::{ConditionalTernary, IfExpression, IfStatement}; -use crate::v2_compiler_languages::ImportTrigger::{ - AsyncUsageTrigger, ContainerUsageTrigger, DeriveMacroTrigger, TraitImplTrigger, - TypeUsageTrigger, -}; -use crate::v2_compiler_languages::InterpStyle::{FormatArgs, InlineExpr}; -use crate::v2_compiler_languages::NamingCase::{AsAuthored, CamelCase, PascalCase, SnakeCase}; -use crate::v2_compiler_languages::ReservedWordStrategy::{NoEscape, PrefixEscape, SuffixEscape}; -use crate::v2_compiler_languages::TestNameStyle::{PascalCaseTestNames, SnakeCaseTestNames}; -use crate::v2_compiler_languages::VisibilitySpec::{CaseVisibility, KeywordVisibility}; -pub use crate::v2_compiler_languages::{ - binop_symbol, is_string_like, language_spec_for_target, service_method_depth, - service_methods_inside_class, service_receiver_str, service_return_str, service_self_param, - target_keyword, test_conventions_for_target, wrap_shared_type, BlockSyntax, EscapePair, - ExpressionSemantics, IfValueForm, ImportRule, ImportTrigger, InterpStyle, LanguageSpec, - NamingCase, RecordLitSyntax, ReservedWordStrategy, ServiceFieldTemplates, StringInterpSyntax, - TcoSyntax, TestConventions, TestNameStyle, VariantPatternSyntax, VisibilitySpec, -}; +use std::collections::HashMap; +use std::rc::Rc; use crate::v2_rt; -use crate::v2_std_core::AlgebraFieldKind::*; -use crate::v2_std_core::BinOp::NullCoalesce; -use crate::v2_std_core::Cardinality::CardOptional; -use crate::v2_std_core::Connective::{Arrow, Conj, Disj, NoConnective}; -use crate::v2_std_core::ExprData::{ - ExprBinOp, ExprBlock, ExprCall, ExprCast, ExprError, ExprFieldAccess, ExprForEach, ExprIf, - ExprIndex, ExprLambda, ExprLet, ExprListLit, ExprLiteral, ExprMatch, ExprMethodCall, - ExprRecordLit, ExprReturn, ExprSlice, ExprStringInterp, ExprUnaryOp, ExprVar, NoExprData, -}; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, ErrorNode, InferredNode, is_compiler_error, module_imports, module_items, param_node_name_at, param_node_type_expr, param_node_default_value, NewlineIndex, authored_name_at, empty_intern_table, expr_var_name_at, expr_call_func_at, let_binding_name_at, field_access_field_at, ExprData, VarBindingKind, StringPart, LiteralValue, TextFile, SourceSpan, BinOp, UnaryOpKind, AlgebraFieldKind, DeclaredFuncSig, MethodSemantics, MatchPattern, field_binding_name_at, field_binding_pattern, FieldSummary, expr_method_name_at, method_arg_nodes, expr_method_call_semantics, expr_field_access_summary, lambda_param_names_at, record_lit_type_name_at, arm_body, arm_pattern, arm_guard, arg_name_at, arg_value, field_init_node_name_at, field_init_node_value, if_condition, if_then_branch, if_else_branch, match_scrutinee, match_arm_nodes, let_value, let_body, field_access_base, method_receiver, lambda_body, cast_expr, cast_target, return_value, binop_left, binop_right, foreach_variable_at, foreach_collection, foreach_body, index_base, index_expr, slice_base, slice_start, slice_end, unaryop_operand, expr_has_self_call, expr_has_non_tail_self_call, local_transport_node, is_rest_transport, is_shell_transport, is_file_transport, is_local_transport, transport_has_auth, field_init_operation_modifier, operation_modifier_name, with_required_cardinality, tuple_type_name, find_child_named, Connective, FieldAccessStyle, Cardinality}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit, ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp, ExprBlock, ExprCast, ExprForEach, ExprIndex, ExprSlice, ExprError, ExprReturn}; +use crate::v2_std_core::StringPart::{Text, Interpolation}; +use crate::v2_std_core::BinOp::{NullCoalesce}; +use crate::v2_std_core::MethodSemantics::{PlainMethodSemantics, AlgebraMethodSemantics, ServiceMethodSemantics}; +use crate::v2_std_core::MatchPattern::{Wildcard, Bind, LitPattern, VariantPattern}; use crate::v2_std_core::FieldAccessStyle::{TupleFirst, TupleSecond}; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; +use crate::v2_std_core::Connective::{Conj, Disj, NoConnective, Arrow}; +use crate::v2_std_core::Cardinality::{CardOptional}; +use crate::v2_std_core::VarBindingKind::*; use crate::v2_std_core::LiteralValue::*; -use crate::v2_std_core::MatchPattern::{Bind, LitPattern, VariantPattern, Wildcard}; -use crate::v2_std_core::MethodSemantics::{ - AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics, -}; -use crate::v2_std_core::StringPart::{Interpolation, Text}; use crate::v2_std_core::UnaryOpKind::*; -use crate::v2_std_core::VarBindingKind::*; -pub use crate::v2_std_core::{ - arg_name_at, arg_value, arm_body, arm_guard, arm_pattern, authored_name_at, binop_left, - binop_right, cast_expr, cast_target, empty_intern_table, expr_call_func_at, - expr_field_access_summary, expr_has_non_tail_self_call, expr_has_self_call, - expr_method_call_semantics, 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_init_operation_modifier, find_child_named, foreach_body, - foreach_collection, foreach_variable_at, if_condition, if_else_branch, if_then_branch, - index_base, index_expr, is_compiler_error, is_file_transport, is_local_transport, - is_rest_transport, is_shell_transport, lambda_body, lambda_param_names_at, let_binding_name_at, - let_body, let_value, local_transport_node, match_arm_nodes, match_scrutinee, method_arg_nodes, - method_receiver, module_imports, module_items, operation_modifier_name, - param_node_default_value, param_node_name_at, param_node_type_expr, record_lit_type_name_at, - return_value, slice_base, slice_end, slice_start, transport_has_auth, tuple_type_name, - unaryop_operand, with_required_cardinality, AlgebraFieldKind, BinOp, Cardinality, Connective, - DeclaredFuncSig, ErrorNode, ExprData, FieldAccessStyle, FieldSummary, InferredNode, - LiteralValue, MatchPattern, MethodSemantics, NewlineIndex, Node, SourceSpan, StringPart, - TextFile, UnaryOpKind, VarBindingKind, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +use crate::v2_std_core::AlgebraFieldKind::*; +pub use crate::v2_compiler_infer_env::{TypeEnv, TypeBinding, authored_name}; +pub use crate::std_induction::{InductiveField, SubValueRelation}; +use crate::std_induction::SubValueRelation::{SubValueUnknown}; +pub use crate::v2_compiler_infer_types::{resolved_type, child_type_node, emit_map_has, node_is_collection, node_is_keyed_collection, node_is_element_collection, normalize_access_type_node, for_each_element_type_node, is_unit_like}; +pub use crate::std_types::{is_container_type, container_template_algebra}; +pub use crate::v2_compiler_coercion::{coerce_primitive_type, coerce_container_template, target_optional_template, target_callable, can_cast, render_cast, literal_suffix}; +pub use crate::v2_compiler_infer_sigs::{ResolvedFuncSig, ResolvedFuncEnv}; +pub use crate::v2_compiler_infer_items::{TypedModule, ResolvedGraph, ItemInfo}; +pub use crate::v2_compiler_infer_service::{UniqueAccum, OpEntry, is_typed_service_call_receiver, extract_typed_service_name}; +pub use crate::v2_compiler_infer::{InferScope, build_params_scope, extend_scope}; +pub use crate::v2_compiler_infer_emit_info::{TypeSummary, EmitGraphInfo}; +pub use crate::v2_compiler_artifact::{RenderTarget}; +use crate::v2_compiler_artifact::RenderTarget::{Rust, Python, Go, Dag}; +pub use crate::generated_method_template_projection::{rust_method_template_emit, python_method_template_emit, go_method_template_emit}; +pub use crate::v2_compiler_languages::{LanguageSpec, TestConventions, ServiceFieldTemplates, BlockSyntax, TcoSyntax, ExpressionSemantics, VariantPatternSyntax, IfValueForm, VisibilitySpec, NamingCase, ReservedWordStrategy, StringInterpSyntax, InterpStyle, EscapePair, RecordLitSyntax, ImportRule, language_spec_for_target, is_string_like, test_conventions_for_target, target_keyword, binop_symbol, wrap_shared_type, service_self_param, service_receiver_str, service_method_depth, service_methods_inside_class, service_return_str, TestNameStyle, ImportTrigger}; +use crate::v2_compiler_languages::TestNameStyle::{SnakeCaseTestNames, PascalCaseTestNames}; +use crate::v2_compiler_languages::IfValueForm::{IfExpression, ConditionalTernary, IfStatement}; +use crate::v2_compiler_languages::VisibilitySpec::{KeywordVisibility, CaseVisibility}; +use crate::v2_compiler_languages::NamingCase::{PascalCase, SnakeCase, CamelCase, AsAuthored}; +use crate::v2_compiler_languages::ReservedWordStrategy::{PrefixEscape, SuffixEscape, NoEscape}; +use crate::v2_compiler_languages::InterpStyle::{FormatArgs, InlineExpr}; +use crate::v2_compiler_languages::ImportTrigger::{TypeUsageTrigger, TraitImplTrigger, DeriveMacroTrigger, ContainerUsageTrigger, AsyncUsageTrigger}; +use self::BackendCapability::*; +use self::ExprCategory::*; +use self::FuncBodyShape::*; +use self::TcoExprShape::*; pub fn is_type_variable(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::TypeVariable { .. } => true, - _ => false, - } + InferredNode::TypeVariable { .. } => true, + _ => false, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -161,210 +116,46 @@ pub fn has_mock_prefix(name: &String) -> bool { } pub fn extract_test_projections(typed: Rc) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for tm in typed.modules.clone().iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in tm.items.clone().iter().cloned() { - if is_service_item(&item) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for c in Rc::new({ - let mut __result = Vec::new(); - for c in item.children.clone().iter().cloned() { - if { - let mut __found = false; - for p in c.properties.clone().iter().cloned() { - if has_mock_prefix(&field_init_node_name_at( - p.clone(), - tm.type_env.clone().source_indices.clone(), - )) { - __found = true; - break; - } - } - __found - } { - __result.push(c); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(Rc::new(TestProjection { - module_name: authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ), - service_name: authored_name_at( - tm.type_env.clone().source_indices.clone(), - &item, - ), - operation_name: authored_name_at( - tm.type_env.clone().source_indices.clone(), - &c, - ), - inferred: resolved_type(c.clone()), - params: c.params.clone(), - mock_field_inits: Rc::new({ - let mut __result = Vec::new(); - for p in c.properties.clone().iter().cloned() { - if has_mock_prefix(&field_init_node_name_at( - p.clone(), - tm.type_env.clone().source_indices.clone(), - )) { - __result.push(p); - } - } - __result - }), - source_indices: tm.type_env.clone().source_indices.clone(), - })); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for tm in typed.modules.clone().iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in tm.items.clone().iter().cloned() { if is_service_item(&item) { __result.push(item); } } __result }).iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for c in Rc::new({ let mut __result = Vec::new(); for c in item.children.clone().iter().cloned() { if { let mut __found = false; for p in c.properties.clone().iter().cloned() { if has_mock_prefix(&field_init_node_name_at(p.clone(), tm.type_env.clone().source_indices.clone())) { __found = true; break; } } __found } { __result.push(c); } } __result }).iter().cloned() { __result.push(Rc::new(TestProjection { + module_name: authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()), + service_name: authored_name_at(tm.type_env.clone().source_indices.clone(), &item), + operation_name: authored_name_at(tm.type_env.clone().source_indices.clone(), &c), + inferred: resolved_type(c.clone()), + params: c.params.clone(), + mock_field_inits: Rc::new({ let mut __result = Vec::new(); for p in c.properties.clone().iter().cloned() { if has_mock_prefix(&field_init_node_name_at(p.clone(), tm.type_env.clone().source_indices.clone())) { __result.push(p); } } __result }), + source_indices: tm.type_env.clone().source_indices.clone(), +})); } __result })).iter().cloned()); } __result })).iter().cloned()); } __result }) } -pub fn derive_module_imports( - items: &Rc>>, - import_rules: Rc>>, - target: RenderTarget, - source_indices: Rc>>, -) -> Rc> { +pub fn derive_module_imports(items: &Rc>>, import_rules: Rc>>, target: RenderTarget, source_indices: Rc>>) -> Rc> { { - let has_async = { - let mut __found = false; - for item in items.clone().iter().cloned() { - if ((item.uses.clone().len() as i64) > 0) { - __found = true; - break; - } - } - __found - }; - let type_names = collect_type_names_from_items(items.clone(), source_indices); - Rc::new({ - let mut __result = Vec::new(); - for path in Rc::new({ - let mut __result = Vec::new(); - for rule in Rc::new({ - let mut __result = Vec::new(); - for rule in import_rules.iter().cloned() { - if match (*rule.trigger.clone()).clone() { - ImportTrigger::TypeUsageTrigger { type_name: t, .. } => { - let mut __found = false; - for n in type_names.clone().iter().cloned() { - if (n.clone().as_str() == t.clone().as_str()) { - __found = true; - break; - } - } - __found - } - ImportTrigger::TraitImplTrigger { .. } => false, - ImportTrigger::DeriveMacroTrigger { .. } => false, - ImportTrigger::ContainerUsageTrigger { container: c, .. } => { - let mut __found = false; - for n in type_names.clone().iter().cloned() { - if (n.clone().as_str() == c.clone().as_str()) { - __found = true; - break; - } - } - __found - } - ImportTrigger::AsyncUsageTrigger => has_async.clone(), - } { - __result.push(rule); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(rule.import_path.clone()); - } - __result - }) - .iter() - .cloned() - { - if (path.clone().as_str() != "".to_string().as_str()) { - __result.push(path); - } - } - __result - }) - } + let has_async = { let mut __found = false; for item in items.clone().iter().cloned() { if ((item.uses.clone().len() as i64) > 0) { __found = true; break; } } __found }; +let type_names = collect_type_names_from_items(items.clone(), source_indices); +Rc::new({ let mut __result = Vec::new(); for path in Rc::new({ let mut __result = Vec::new(); for rule in Rc::new({ let mut __result = Vec::new(); for rule in import_rules.iter().cloned() { if match (*rule.trigger.clone()).clone() { + ImportTrigger::TypeUsageTrigger { type_name: t, .. } => { let mut __found = false; for n in type_names.clone().iter().cloned() { if (n.clone().as_str() == t.clone().as_str()) { __found = true; break; } } __found }, + ImportTrigger::TraitImplTrigger { .. } => false, + ImportTrigger::DeriveMacroTrigger { .. } => false, + ImportTrigger::ContainerUsageTrigger { container: c, .. } => { let mut __found = false; for n in type_names.clone().iter().cloned() { if (n.clone().as_str() == c.clone().as_str()) { __found = true; break; } } __found }, + ImportTrigger::AsyncUsageTrigger => has_async.clone(), +} { __result.push(rule); } } __result }).iter().cloned() { __result.push(rule.import_path.clone()); } __result }).iter().cloned() { if (path.clone().as_str() != "".to_string().as_str()) { __result.push(path); } } __result }) +} } -pub fn collect_type_names_from_items( - items: Rc>>, - source_indices: Rc>>, -) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for item in items.iter().cloned() { - __result.extend( - (*collect_type_names_from_node(&item, &source_indices)) - .iter() - .cloned(), - ); - } - __result - }) +pub fn collect_type_names_from_items(items: Rc>>, source_indices: Rc>>) -> Rc> { + Rc::new({ let mut __result = Vec::new(); for item in items.iter().cloned() { __result.extend((*collect_type_names_from_node(&item, &source_indices)).iter().cloned()); } __result }) } -pub fn collect_type_names_from_node( - n: &Rc, - source_indices: &Rc>>, -) -> Rc> { +pub fn collect_type_names_from_node(n: &Rc, source_indices: &Rc>>) -> Rc> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let self_name = if (n.ident_span.clone() != None) { - Rc::new(vec![authored_name_at(source_indices.clone(), &n)]) - } else { - Rc::new(vec![]) - }; - let child_names = Rc::new({ - let mut __result = Vec::new(); - for child in n.children.clone().iter().cloned() { - __result.extend( - (*collect_type_names_from_node(&child, &source_indices)) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat(self_name, child_names) + { + let self_name = if (n.ident_span.clone() != None) { + Rc::new(vec![authored_name_at(source_indices.clone(), &n)]) + } else { + Rc::new(vec![]) + }; +let child_names = Rc::new({ let mut __result = Vec::new(); for child in n.children.clone().iter().cloned() { __result.extend((*collect_type_names_from_node(&child, &source_indices)).iter().cloned()); } __result }); +v2_rt::concat(self_name, child_names) +} }) } @@ -374,650 +165,345 @@ pub struct InterpPart { pub arg_expr: String, } -pub fn emit_simple_expr( - expr: &Rc, - target: &RenderTarget, - source_indices: &Rc>>, -) -> String { +pub fn emit_simple_expr(expr: &Rc, target: &RenderTarget, source_indices: &Rc>>) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*expr.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: v, .. } => emit_literal(v.clone(), &target), - ExprData::ExprError { message, .. } => emit_error_expr(message.clone(), target.clone()), - ExprData::ExprVar { .. } => emit_ident( - expr_var_name_at(expr.clone(), source_indices.clone()), - target.clone(), - ), - ExprData::ExprFieldAccess { .. } => { - let f = field_access_field_at(expr.clone(), source_indices.clone()); - let b = field_access_base(expr.clone()); - if is_typed_service_call_receiver(&expr, source_indices.clone()) { - match extract_typed_service_name(&expr, &source_indices) { - Some(svc_name) => service_var_name(svc_name.clone()), - None => v2_rt::concat( - v2_rt::concat( - emit_simple_expr(&b, &target, &source_indices), - ".".to_string(), - ), - emit_ident(f.clone(), target.clone()), - ), - } - } else { - { - let base_is_fn = match (*b.expr_data.clone()).clone() { - ExprData::ExprVar { - binding_kind: bk, .. - } => match bk.clone().as_deref().cloned() { - Some(VarBindingKind::MatchBoundBinding) => false, - Some(VarBindingKind::VariantValueBinding { .. }) => false, - _ => true, - }, - _ => false, - }; - let base_str = emit_simple_expr(&b, &target, &source_indices); - let base_call = if base_is_fn.clone() { - v2_rt::concat(base_str, "()".to_string()) - } else { - base_str - }; - let field_str = v2_rt::concat( - v2_rt::concat(base_call, ".".to_string()), - emit_ident(f.clone(), target.clone()), - ); - let needs_clone = (base_is_fn.clone() - && match target.clone() { - RenderTarget::Rust => true, - _ => false, - }); - if needs_clone { - v2_rt::concat(field_str, ".clone()".to_string()) - } else { - field_str - } - } - } - } - ExprData::ExprStringInterp => { - let ps = Rc::new({ - let mut __result = Vec::new(); - for child in expr.children.clone().iter().cloned() { - __result.push(match (*child.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: text, .. } = value.as_ref() - else { - unreachable!() - }; - Rc::new(StringPart::Text { - value: text.clone(), - }) - } - _ => Rc::new(StringPart::Interpolation { - expr: arg_value(&child), - }), - }); + ExprData::ExprLiteral { value: v, .. } => emit_literal(v.clone(), &target), + ExprData::ExprError { message, .. } => emit_error_expr(message.clone(), target.clone()), + ExprData::ExprVar { .. } => emit_ident(expr_var_name_at(expr.clone(), source_indices.clone()), target.clone()), + ExprData::ExprFieldAccess { .. } => { + let f = field_access_field_at(expr.clone(), source_indices.clone()); +let b = field_access_base(expr.clone()); +if is_typed_service_call_receiver(&expr, source_indices.clone()) { + match extract_typed_service_name(&expr, &source_indices) { + Some(svc_name) => service_var_name(svc_name.clone()), + None => v2_rt::concat(v2_rt::concat(emit_simple_expr(&b, &target, &source_indices), ".".to_string()), emit_ident(f.clone(), target.clone())), +} + } else { + { + let base_is_fn = match (*b.expr_data.clone()).clone() { + ExprData::ExprVar { binding_kind: bk, .. } => match bk.clone().as_deref().cloned() { + Some(VarBindingKind::MatchBoundBinding) => false, + Some(VarBindingKind::VariantValueBinding { .. }) => false, + _ => true, +}, + _ => false, +}; +let base_str = emit_simple_expr(&b, &target, &source_indices); +let base_call = if base_is_fn.clone() { + v2_rt::concat(base_str, "()".to_string()) + } else { + base_str + }; +let field_str = v2_rt::concat(v2_rt::concat(base_call, ".".to_string()), emit_ident(f.clone(), target.clone())); +let needs_clone = (base_is_fn.clone() && match target.clone() { + RenderTarget::Rust => true, + _ => false, +}); +if needs_clone { + v2_rt::concat(field_str, ".clone()".to_string()) + } else { + field_str } - __result - }); - emit_simple_string_interp(&ps, &target, source_indices.clone()) +} } - ExprData::ExprListLit => match target.clone() { - RenderTarget::Go => emit_error_expr( - "list literal in simple expr not yet supported for Go".to_string(), - target.clone(), - ), - _ => { - let el_strs = Rc::new({ - let mut __result = Vec::new(); - for e in expr.children.clone().iter().cloned() { - __result.push(emit_simple_expr(&e, &target, &source_indices)); - } - __result - }); - v2_rt::concat( - v2_rt::concat("[".to_string(), el_strs.join(&", ".to_string())), - "]".to_string(), - ) - } - }, - ExprData::ExprRecordLit { .. } => match target.clone() { - RenderTarget::Go => emit_error_expr( - "record literal in simple expr not yet supported for Go".to_string(), - target.clone(), - ), - _ => { - let field_strs = Rc::new({ - let mut __result = Vec::new(); - for f in expr.children.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "\"".to_string(), - field_init_node_name_at(f.clone(), source_indices.clone()), - ), - "\": ".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&f), - &target, - &source_indices, - ), - )); - } - __result - }); - v2_rt::concat( - v2_rt::concat("{".to_string(), field_strs.join(&", ".to_string())), - "}".to_string(), - ) - } - }, - _ => emit_error_expr( - "unsupported simple expr in test/mock binding".to_string(), - target.clone(), - ), - } +}, + ExprData::ExprStringInterp => { + let ps = Rc::new({ let mut __result = Vec::new(); for child in expr.children.clone().iter().cloned() { __result.push(match (*child.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: text, .. } = value.as_ref() else { unreachable!() }; Rc::new(StringPart::Text { + value: text.clone(), +}) }, + _ => Rc::new(StringPart::Interpolation { + expr: arg_value(&child), +}), +}); } __result }); +emit_simple_string_interp(&ps, &target, source_indices.clone()) +}, + ExprData::ExprListLit => match target.clone() { + RenderTarget::Go => emit_error_expr("list literal in simple expr not yet supported for Go".to_string(), target.clone()), + _ => { + let el_strs = Rc::new({ let mut __result = Vec::new(); for e in expr.children.clone().iter().cloned() { __result.push(emit_simple_expr(&e, &target, &source_indices)); } __result }); +v2_rt::concat(v2_rt::concat("[".to_string(), el_strs.join(&", ".to_string())), "]".to_string()) +}, +}, + ExprData::ExprRecordLit { .. } => match target.clone() { + RenderTarget::Go => emit_error_expr("record literal in simple expr not yet supported for Go".to_string(), target.clone()), + _ => { + let field_strs = Rc::new({ let mut __result = Vec::new(); for f in expr.children.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat("\"".to_string(), field_init_node_name_at(f.clone(), source_indices.clone())), "\": ".to_string()), emit_simple_expr(&field_init_node_value(&f), &target, &source_indices))); } __result }); +v2_rt::concat(v2_rt::concat("{".to_string(), field_strs.join(&", ".to_string())), "}".to_string()) +}, +}, + _ => emit_error_expr("unsupported simple expr in test/mock binding".to_string(), target.clone()), +} }) } -pub fn emit_simple_string_interp( - parts: &Rc>>, - target: &RenderTarget, - source_indices: Rc>>, -) -> String { +pub fn emit_simple_string_interp(parts: &Rc>>, target: &RenderTarget, source_indices: Rc>>) -> String { { let spec = language_spec(target.clone()); - let interp = spec.string_interp.clone(); - let has_interpolations = { - let mut __found = false; - for p in parts.clone().iter().cloned() { - if match (*p.clone()).clone() { - StringPart::Interpolation { .. } => true, - _ => false, - } { - __found = true; - break; - } +let interp = spec.string_interp.clone(); +let has_interpolations = { let mut __found = false; for p in parts.clone().iter().cloned() { if match (*p.clone()).clone() { + StringPart::Interpolation { .. } => true, + _ => false, +} { __found = true; break; } } __found }; +match (*interp.style.clone()).clone() { + InterpStyle::FormatArgs { placeholder: ph, .. } => { + let fmt_parts = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.push(match (*p.clone()).clone() { + StringPart::Text { value: v, .. } => { + let base = escape_string_literal_body(v.clone()); +let escaped = if has_interpolations.clone() { + apply_escape_pairs(base.clone(), interp.escape_pairs.clone()) + } else { + base.clone() + }; +Rc::new(InterpPart { + format_segment: escaped.clone(), + arg_expr: "".to_string(), +}) +}, + StringPart::Interpolation { expr: e, .. } => Rc::new(InterpPart { + format_segment: ph.clone(), + arg_expr: emit_simple_expr(&e, &target, &source_indices), +}), +}); } __result }); +let fmt_str = Rc::new({ let mut __result = Vec::new(); for p in fmt_parts.clone().iter().cloned() { __result.push(p.format_segment.clone()); } __result }).join(&"".to_string()); +let args = Rc::new({ let mut __result = Vec::new(); for a in Rc::new({ let mut __result = Vec::new(); for p in fmt_parts.clone().iter().cloned() { __result.push(p.arg_expr.clone()); } __result }).iter().cloned() { if (a.clone().as_str() != "".to_string().as_str()) { __result.push(a); } } __result }); +if ((args.clone().len() as i64) == 0) { + apply_type_template1(interp.plain_template.clone(), fmt_str) + } else { + { + let args_str = args.clone().join(&", ".to_string()); +apply_type_template2(interp.format_template.clone(), fmt_str, args_str) +} } - __found - }; - match (*interp.style.clone()).clone() { - InterpStyle::FormatArgs { - placeholder: ph, .. - } => { - let fmt_parts = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.push(match (*p.clone()).clone() { - StringPart::Text { value: v, .. } => { - let base = escape_string_literal_body(v.clone()); - let escaped = if has_interpolations.clone() { - apply_escape_pairs(base.clone(), interp.escape_pairs.clone()) - } else { - base.clone() - }; - Rc::new(InterpPart { - format_segment: escaped.clone(), - arg_expr: "".to_string(), - }) - } - StringPart::Interpolation { expr: e, .. } => Rc::new(InterpPart { - format_segment: ph.clone(), - arg_expr: emit_simple_expr(&e, &target, &source_indices), - }), - }); - } - __result - }); - let fmt_str = Rc::new({ - let mut __result = Vec::new(); - for p in fmt_parts.clone().iter().cloned() { - __result.push(p.format_segment.clone()); - } - __result - }) - .join(&"".to_string()); - let args = Rc::new({ - let mut __result = Vec::new(); - for a in Rc::new({ - let mut __result = Vec::new(); - for p in fmt_parts.clone().iter().cloned() { - __result.push(p.arg_expr.clone()); - } - __result - }) - .iter() - .cloned() - { - if (a.clone().as_str() != "".to_string().as_str()) { - __result.push(a); - } - } - __result - }); - if ((args.clone().len() as i64) == 0) { - apply_type_template1(interp.plain_template.clone(), fmt_str) +}, + InterpStyle::InlineExpr => { + let segments = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.push(match (*p.clone()).clone() { + StringPart::Text { value: v, .. } => { + let base = escape_string_literal_body(v.clone()); +if has_interpolations.clone() { + apply_escape_pairs(base.clone(), interp.escape_pairs.clone()) } else { - { - let args_str = args.clone().join(&", ".to_string()); - apply_type_template2(interp.format_template.clone(), fmt_str, args_str) - } + base.clone() } - } - InterpStyle::InlineExpr => { - let segments = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.push(match (*p.clone()).clone() { - StringPart::Text { value: v, .. } => { - let base = escape_string_literal_body(v.clone()); - if has_interpolations.clone() { - apply_escape_pairs(base.clone(), interp.escape_pairs.clone()) - } else { - base.clone() - } - } - StringPart::Interpolation { expr: e, .. } => v2_rt::concat( - v2_rt::concat( - "{".to_string(), - emit_simple_expr(&e, &target, &source_indices), - ), - "}".to_string(), - ), - }); - } - __result - }); - apply_type_template1( - interp.format_template.clone(), - segments.join(&"".to_string()), - ) - } - } - } +}, + StringPart::Interpolation { expr: e, .. } => v2_rt::concat(v2_rt::concat("{".to_string(), emit_simple_expr(&e, &target, &source_indices)), "}".to_string()), +}); } __result }); +apply_type_template1(interp.format_template.clone(), segments.join(&"".to_string())) +}, +} +} } pub fn empty_emit_scope() -> Rc { Rc::new(InferScope { - type_env: Rc::new(TypeEnv { - bindings: v2_rt::rc_empty_map::>(), - recursive_types: Rc::new(vec![]), - recursive_type_set: v2_rt::rc_empty_map::(), - inductive_fields: v2_rt::rc_empty_map::>>>(), - source_indices: v2_rt::rc_empty_map::>(), - intern_table: empty_intern_table(), - }), - func_env: Rc::new(ResolvedFuncEnv { - signatures: v2_rt::rc_empty_map::>(), - }), - locals: v2_rt::rc_empty_map::>(), - match_bound_names: v2_rt::rc_empty_map::(), - module_name: "".to_string(), - service_registry: v2_rt::rc_empty_map::>>>(), - item_registry: v2_rt::rc_empty_map::>(), - lambda_param_provenance: v2_rt::rc_empty_map::>(), - }) + type_env: Rc::new(TypeEnv { + bindings: v2_rt::rc_empty_map::>(), + recursive_types: Rc::new(vec![]), + recursive_type_set: v2_rt::rc_empty_map::(), + inductive_fields: v2_rt::rc_empty_map::>>>(), + source_indices: v2_rt::rc_empty_map::>(), + intern_table: empty_intern_table(), +}), + func_env: Rc::new(ResolvedFuncEnv { + signatures: v2_rt::rc_empty_map::>(), +}), + locals: v2_rt::rc_empty_map::>(), + match_bound_names: v2_rt::rc_empty_map::(), + module_name: "".to_string(), + service_registry: v2_rt::rc_empty_map::>>>(), + item_registry: v2_rt::rc_empty_map::>(), + lambda_param_provenance: v2_rt::rc_empty_map::>(), +}) } pub fn module_emit_scope(typed_module: &Rc) -> Rc { Rc::new(InferScope { - type_env: typed_module.type_env.clone(), - func_env: typed_module.func_env.clone(), - locals: v2_rt::rc_empty_map::>(), - match_bound_names: v2_rt::rc_empty_map::(), - module_name: authored_name_at( - typed_module.type_env.clone().source_indices.clone(), - &typed_module.module.clone(), - ), - service_registry: v2_rt::rc_empty_map::>>>(), - item_registry: typed_module.item_registry.clone(), - lambda_param_provenance: v2_rt::rc_empty_map::>(), - }) + type_env: typed_module.type_env.clone(), + func_env: typed_module.func_env.clone(), + locals: v2_rt::rc_empty_map::>(), + match_bound_names: v2_rt::rc_empty_map::(), + module_name: authored_name_at(typed_module.type_env.clone().source_indices.clone(), &typed_module.module.clone()), + service_registry: v2_rt::rc_empty_map::>>>(), + item_registry: typed_module.item_registry.clone(), + lambda_param_provenance: v2_rt::rc_empty_map::>(), +}) } pub fn scope_after_expr(texpr: &Rc, scope: &Rc) -> Rc { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprLet => { - let ch = texpr.children.clone(); - let has_body = ((ch.len() as i64) > 1); - if (has_body == false) { - { - let value = let_value(texpr.clone()); - extend_scope( - &scope, - &let_binding_name_at( - texpr.clone(), - scope.type_env.clone().source_indices.clone(), - ), - resolved_type(value), - Rc::new(SubValueRelation::SubValueUnknown), - ) - } - } else { - scope.clone() - } + ExprData::ExprLet => { + let ch = texpr.children.clone(); +let has_body = ((ch.len() as i64) > 1); +if (has_body == false) { + { + let value = let_value(texpr.clone()); +extend_scope(&scope, &let_binding_name_at(texpr.clone(), scope.type_env.clone().source_indices.clone()), resolved_type(value), Rc::new(SubValueRelation::SubValueUnknown)) +} + } else { + scope.clone() } - _ => scope.clone(), - } +}, + _ => scope.clone(), +} } -pub fn lookup_item( - registry: Rc>>, - name: String, -) -> Option> { +pub fn lookup_item(registry: Rc>>, name: String) -> Option> { v2_rt::map_get(®istry, name) } -pub fn lookup_func_sig_in_scope( - scope: Rc, - name: String, -) -> Option> { +pub fn lookup_func_sig_in_scope(scope: Rc, name: String) -> Option> { v2_rt::map_get(&scope.func_env.clone().signatures.clone(), name) } -pub fn typed_named_arg_matches( - arg: Rc, - name: String, - source_indices: Rc>>, -) -> bool { +pub fn typed_named_arg_matches(arg: Rc, name: String, source_indices: Rc>>) -> bool { { let n = arg_name_at(arg, source_indices); - if (n.clone() == None) { +if (n.clone() == None) { false } else { (n.clone().unwrap().as_str() == name.as_str()) } - } +} } -pub fn order_typed_call_args( - args: &Rc>>, - func: String, - scope: &Rc, -) -> Rc>> { +pub fn order_typed_call_args(args: &Rc>>, func: String, scope: &Rc) -> Rc>> { { - let has_unnamed = { - let mut __found = false; - for arg in args.clone().iter().cloned() { - if (arg_name_at(arg.clone(), scope.type_env.clone().source_indices.clone()) == None) - { - __found = true; - break; - } - } - __found - }; - if has_unnamed { + let has_unnamed = { let mut __found = false; for arg in args.clone().iter().cloned() { if (arg_name_at(arg.clone(), scope.type_env.clone().source_indices.clone()) == None) { __found = true; break; } } __found }; +if has_unnamed { args.clone() } else { match lookup_func_sig_in_scope(scope.clone(), func) { - None => args.clone(), - Some(sig) => { - let arg_map = args.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, arg: Rc| { - let n = arg_name_at( - arg.clone(), - scope.type_env.clone().source_indices.clone(), - ); - if (n.clone() != None) { - v2_rt::rc_map_insert(acc.clone(), n.clone().unwrap(), arg.clone()) - } else { - acc.clone() - } - }, - ); - let param_name_set = sig.params.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, param: Rc| { - v2_rt::rc_map_insert( - acc, - param_node_name_at( - param.clone(), - scope.type_env.clone().source_indices.clone(), - ), - true, - ) - }, - ); - let ordered = Rc::new({ - let mut __result = Vec::new(); - for param in sig.params.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get( - &arg_map, - param_node_name_at( - param.clone(), - scope.type_env.clone().source_indices.clone(), - ), - ) { - Some(arg) => Rc::new(vec![arg.clone()]), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let leftovers = Rc::new({ - let mut __result = Vec::new(); - for arg in args.clone().iter().cloned() { - if { - let n = arg_name_at( - arg.clone(), - scope.type_env.clone().source_indices.clone(), - ); - if (n.clone() == None) { - true - } else { - (emit_map_has(param_name_set.clone(), n.clone().unwrap()) - == false) - } - } { - __result.push(arg); - } - } - __result - }); - v2_rt::concat(ordered, leftovers) - } - } + None => args.clone(), + Some(sig) => { + let arg_map = args.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, arg: Rc| { + let n = arg_name_at(arg.clone(), scope.type_env.clone().source_indices.clone()); +if (n.clone() != None) { + v2_rt::rc_map_insert(acc.clone(), n.clone().unwrap(), arg.clone()) + } else { + acc.clone() + } +}); +let param_name_set = sig.params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, param: Rc| v2_rt::rc_map_insert(acc, param_node_name_at(param.clone(), scope.type_env.clone().source_indices.clone()), true)); +let ordered = Rc::new({ let mut __result = Vec::new(); for param in sig.params.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&arg_map, param_node_name_at(param.clone(), scope.type_env.clone().source_indices.clone())) { + Some(arg) => Rc::new(vec![arg.clone()]), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let leftovers = Rc::new({ let mut __result = Vec::new(); for arg in args.clone().iter().cloned() { if { + let n = arg_name_at(arg.clone(), scope.type_env.clone().source_indices.clone()); +if (n.clone() == None) { + true + } else { + (emit_map_has(param_name_set.clone(), n.clone().unwrap()) == false) + } +} { __result.push(arg); } } __result }); +v2_rt::concat(ordered, leftovers) +}, +} } - } +} } pub fn unique_strings(items: Rc>) -> Rc> { { - let result = items.iter().cloned().fold( + let result = items.iter().cloned().fold(Rc::new(UniqueAccum { + seen: v2_rt::rc_empty_map::(), + result: Rc::new(vec![]), +}), |acc: Rc, item: String| if emit_map_has(acc.seen.clone(), item.clone()) { + acc.clone() + } else { Rc::new(UniqueAccum { - seen: v2_rt::rc_empty_map::(), - result: Rc::new(vec![]), - }), - |acc: Rc, item: String| { - if emit_map_has(acc.seen.clone(), item.clone()) { - acc.clone() - } else { - Rc::new(UniqueAccum { - seen: v2_rt::rc_map_insert(acc.seen.clone(), item.clone(), true), - result: v2_rt::rc_list_push(acc.result.clone(), item.clone()), - }) - } - }, - ); - result.result.clone() - } + seen: v2_rt::rc_map_insert(acc.seen.clone(), item.clone(), true), + result: v2_rt::rc_list_push(acc.result.clone(), item.clone()), +}) + }); +result.result.clone() +} } -pub fn has_nested_records_node( - mut n: Rc, - mut source_indices: Rc>>, -) -> bool { +pub fn has_nested_records_node(mut n: Rc, mut source_indices: Rc>>) -> bool { loop { let is_product = (n.connective.clone() == Connective::Conj); - let is_coproduct = (n.connective.clone() == Connective::Disj); - if is_product { +let is_coproduct = (n.connective.clone() == Connective::Disj); +if is_product { break true; - } else { +} else { if is_coproduct { let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { +if is_optional { { let __tco_0 = with_required_cardinality(&n); - n = __tco_0; - continue; - } - } else { +n = __tco_0; +continue; +} +} else { break false; - } - } else { +} +} else { let is_map = node_is_keyed_collection(&n, source_indices.clone()); - if is_map { +if is_map { match n.children.clone().get(1 as usize).cloned() { - Some(val_child) => { - let __tco_0 = child_type_node(&val_child); - n = __tco_0; - continue; - } - None => { - break false; - } - } - } else { + Some(val_child) => { { + let __tco_0 = child_type_node(&val_child); +n = __tco_0; +continue; +} }, + None => { break false; }, +} +} else { if ((n.children.clone().len() as i64) == 1) { match n.children.clone().first().cloned() { - Some(el) => { - let __tco_0 = child_type_node(&el); - n = __tco_0; - continue; - } - None => { - break false; - } - } - } else { + Some(el) => { { + let __tco_0 = child_type_node(&el); +n = __tco_0; +continue; +} }, + None => { break false; }, +} +} else { break false; - } - } - } - } - } +} +} +} +} +} } -pub fn emit_data_value_json( - value: &Rc, - source_indices: Rc>>, -) -> String { +pub fn emit_data_value_json(value: &Rc, source_indices: Rc>>) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*value.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitStr { value: s, .. } => v2_rt::concat( - v2_rt::concat("\"".to_string(), escape_json_string(s.clone())), - "\"".to_string(), - ), - LiteralValue::LitInt { value: i, .. } => (i.clone()).to_string(), - LiteralValue::LitFloat { value: f, .. } => f.clone(), - LiteralValue::LitBool { value: b, .. } => { - if b.clone() { - "true".to_string() - } else { - "false".to_string() - } - } - LiteralValue::LitNull => "null".to_string(), - }, - ExprData::ExprListLit => { - let el_strs = Rc::new({ - let mut __result = Vec::new(); - for e in value.children.clone().iter().cloned() { - __result.push(emit_data_value_json(&e, source_indices.clone())); - } - __result - }); - v2_rt::concat( - v2_rt::concat("[".to_string(), el_strs.join(&", ".to_string())), - "]".to_string(), - ) - } - ExprData::ExprRecordLit { .. } => { - let field_strs = Rc::new({ - let mut __result = Vec::new(); - for f in value.children.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "\"".to_string(), - escape_json_string(field_init_node_name_at( - f.clone(), - source_indices.clone(), - )), - ), - "\": ".to_string(), - ), - emit_data_value_json( - &field_init_node_value(&f), - source_indices.clone(), - ), - )); - } - __result - }); - v2_rt::concat( - v2_rt::concat("{".to_string(), field_strs.join(&", ".to_string())), - "}".to_string(), - ) - } - ExprData::ExprVar { .. } => v2_rt::concat( - v2_rt::concat( - "\"".to_string(), - escape_json_string(expr_var_name_at(value.clone(), source_indices.clone())), - ), - "\"".to_string(), - ), - ExprData::ExprUnaryOp { - op: UnaryOpKind::Neg, - .. - } => v2_rt::concat( - "-".to_string(), - emit_data_value_json(&unaryop_operand(value.clone()), source_indices.clone()), - ), - _ => "\"compile_error!(unsupported mock expression)\"".to_string(), - } + ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitStr { value: s, .. } => v2_rt::concat(v2_rt::concat("\"".to_string(), escape_json_string(s.clone())), "\"".to_string()), + LiteralValue::LitInt { value: i, .. } => (i.clone()).to_string(), + LiteralValue::LitFloat { value: f, .. } => f.clone(), + LiteralValue::LitBool { value: b, .. } => if b.clone() { + "true".to_string() + } else { + "false".to_string() + }, + LiteralValue::LitNull => "null".to_string(), +}, + ExprData::ExprListLit => { + let el_strs = Rc::new({ let mut __result = Vec::new(); for e in value.children.clone().iter().cloned() { __result.push(emit_data_value_json(&e, source_indices.clone())); } __result }); +v2_rt::concat(v2_rt::concat("[".to_string(), el_strs.join(&", ".to_string())), "]".to_string()) +}, + ExprData::ExprRecordLit { .. } => { + let field_strs = Rc::new({ let mut __result = Vec::new(); for f in value.children.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat("\"".to_string(), escape_json_string(field_init_node_name_at(f.clone(), source_indices.clone()))), "\": ".to_string()), emit_data_value_json(&field_init_node_value(&f), source_indices.clone()))); } __result }); +v2_rt::concat(v2_rt::concat("{".to_string(), field_strs.join(&", ".to_string())), "}".to_string()) +}, + ExprData::ExprVar { .. } => v2_rt::concat(v2_rt::concat("\"".to_string(), escape_json_string(expr_var_name_at(value.clone(), source_indices.clone()))), "\"".to_string()), + ExprData::ExprUnaryOp { op: UnaryOpKind::Neg, .. } => v2_rt::concat("-".to_string(), emit_data_value_json(&unaryop_operand(value.clone()), source_indices.clone())), + _ => "\"compile_error!(unsupported mock expression)\"".to_string(), +} }) } pub fn escape_json_string(s: String) -> String { - Rc::new( - Rc::new( - Rc::new( - Rc::new( - s.split(&"\\".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\\\".to_string()) - .split(&"\"".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\\"".to_string()) - .split(&"\n".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\n".to_string()) - .split(&"\t".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\t".to_string()) + Rc::new(Rc::new(Rc::new(Rc::new(s.split(&"\\".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\\\".to_string()).split(&"\"".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\\"".to_string()).split(&"\n".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\n".to_string()).split(&"\t".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\t".to_string()) } pub fn module_to_filename(name: String) -> String { - Rc::new( - name.split(&".".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"_".to_string()) + Rc::new(name.split(&".".to_string()).map(|s| s.to_string()).collect::>()).join(&"_".to_string()) } pub fn make_indent(level: i64) -> String { @@ -1033,26 +519,15 @@ pub fn make_indent(level: i64) -> String { pub fn to_string(value: i64) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { if (value.clone() < 0) { - v2_rt::concat("-".to_string(), (0 - value.clone()).to_string()) + v2_rt::concat("-".to_string(), ((0 - value.clone())).to_string()) } else { if (value.clone() == 0) { "0".to_string() } else { { - let digit_chars = Rc::new(vec![ - "0".to_string(), - "1".to_string(), - "2".to_string(), - "3".to_string(), - "4".to_string(), - "5".to_string(), - "6".to_string(), - "7".to_string(), - "8".to_string(), - "9".to_string(), - ]); - to_string_helper(value.clone(), Rc::new(vec![])).join(&"".to_string()) - } + let digit_chars = Rc::new(vec!["0".to_string(), "1".to_string(), "2".to_string(), "3".to_string(), "4".to_string(), "5".to_string(), "6".to_string(), "7".to_string(), "8".to_string(), "9".to_string()]); +to_string_helper(value.clone(), Rc::new(vec![])).join(&"".to_string()) +} } } }) @@ -1062,169 +537,68 @@ pub fn to_string_helper(mut value: i64, mut acc: Rc>) -> Rc>(), - ) - .iter() - .cloned() - { - if (p.0.clone() == digit.clone()) { - __result.push(p); - } - } - __result - }) - .first() - .cloned() - { - Some(p) => p.1.clone(), - None => "?".to_string(), - }; - { +let digit = (value.clone() - (rest.clone() * 10)); +let digit_chars = Rc::new(vec!["0".to_string(), "1".to_string(), "2".to_string(), "3".to_string(), "4".to_string(), "5".to_string(), "6".to_string(), "7".to_string(), "8".to_string(), "9".to_string()]); +let ch = match Rc::new({ let mut __result = Vec::new(); for p in Rc::new(digit_chars.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (p.0.clone() == digit.clone()) { __result.push(p); } } __result }).first().cloned() { + Some(p) => p.1.clone(), + None => "?".to_string(), +}; +{ let __tco_0 = rest.clone(); - let __tco_1 = v2_rt::concat(Rc::new(vec![ch]), acc); - value = __tco_0; - acc = __tco_1; - continue; - } - } - } +let __tco_1 = v2_rt::concat(Rc::new(vec![ch]), acc); +value = __tco_0; +acc = __tco_1; +continue; +} +} +} } pub fn to_snake(name: String) -> String { { let chars_list = Rc::new(name.chars().map(|c| c as i64).collect::>()); - let result = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - chars_list - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let idx = pair.0.clone(); - let ch = pair.1.clone(); - if is_upper(ch.clone()) { - if (idx.clone() == 0) { - to_lower_char(ch.clone()) - } else { - v2_rt::concat("_".to_string(), to_lower_char(ch.clone())) - } - } else { - v2_rt::from_code_point(ch.clone()) - } - }); +let result = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(chars_list.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let idx = pair.0.clone(); +let ch = pair.1.clone(); +if is_upper(ch.clone()) { + if (idx.clone() == 0) { + to_lower_char(ch.clone()) + } else { + v2_rt::concat("_".to_string(), to_lower_char(ch.clone())) + } + } else { + v2_rt::from_code_point(ch.clone()) } - __result - }); - result.join(&"".to_string()) - } +}); } __result }); +result.join(&"".to_string()) +} } pub fn to_screaming_snake(name: String) -> String { { let snake = to_snake(name); - Rc::new({ - let mut __result = Vec::new(); - for ch in Rc::new(snake.chars().map(|c| c as i64).collect::>()) - .iter() - .cloned() - { - __result.push(to_upper_char(ch.clone())); - } - __result - }) - .join(&"".to_string()) - } +Rc::new({ let mut __result = Vec::new(); for ch in Rc::new(snake.chars().map(|c| c as i64).collect::>()).iter().cloned() { __result.push(to_upper_char(ch.clone())); } __result }).join(&"".to_string()) +} } pub fn to_camel(name: String) -> String { { - let parts = Rc::new( - name.clone() - .split(&"_".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - if ((parts.clone().len() as i64) == 0) { + let parts = Rc::new(name.clone().split(&"_".to_string()).map(|s| s.to_string()).collect::>()); +if ((parts.clone().len() as i64) == 0) { name.clone() } else { { let first_part = match parts.clone().first().cloned() { - Some(p) => Rc::new({ - let mut __result = Vec::new(); - for c in Rc::new(p.clone().chars().map(|c| c as i64).collect::>()) - .iter() - .cloned() - { - __result.push(to_lower_char(c.clone())); - } - __result - }) - .join(&"".to_string()), - None => "".to_string(), - }; - let rest_parts = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - parts - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (pair.0.clone() > 0) { - __result.push(pair); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(capitalize_first(pair.1.clone())); - } - __result - }); - v2_rt::concat(first_part, rest_parts.join(&"".to_string())) - } + Some(p) => Rc::new({ let mut __result = Vec::new(); for c in Rc::new(p.clone().chars().map(|c| c as i64).collect::>()).iter().cloned() { __result.push(to_lower_char(c.clone())); } __result }).join(&"".to_string()), + None => "".to_string(), +}; +let rest_parts = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(parts.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (pair.0.clone() > 0) { __result.push(pair); } } __result }).iter().cloned() { __result.push(capitalize_first(pair.1.clone())); } __result }); +v2_rt::concat(first_part, rest_parts.join(&"".to_string())) +} } - } +} } pub fn is_upper(ch: i64) -> bool { @@ -1234,123 +608,74 @@ pub fn is_upper(ch: i64) -> bool { pub fn to_lower_char(ch: i64) -> String { { let cp = ch.clone(); - if ((cp.clone() >= 65) && (cp.clone() <= 90)) { +if ((cp.clone() >= 65) && (cp.clone() <= 90)) { { let lower_cp = (cp.clone() + 32); - v2_rt::from_code_point(lower_cp) - } +v2_rt::from_code_point(lower_cp) +} } else { v2_rt::from_code_point(ch.clone()) } - } +} } pub fn to_upper_char(ch: i64) -> String { { let cp = ch.clone(); - if ((cp.clone() >= 97) && (cp.clone() <= 122)) { +if ((cp.clone() >= 97) && (cp.clone() <= 122)) { { let upper_cp = (cp.clone() - 32); - v2_rt::from_code_point(upper_cp) - } +v2_rt::from_code_point(upper_cp) +} } else { v2_rt::from_code_point(ch.clone()) } - } +} } pub fn sanitize_service_name(name: String) -> String { { - let parts = Rc::new( - name.split(&".".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - let pascal_parts = Rc::new({ - let mut __result = Vec::new(); - for p in parts.iter().cloned() { - __result.push(capitalize_first(p.clone())); - } - __result - }); - pascal_parts.join(&"".to_string()) - } + let parts = Rc::new(name.split(&".".to_string()).map(|s| s.to_string()).collect::>()); +let pascal_parts = Rc::new({ let mut __result = Vec::new(); for p in parts.iter().cloned() { __result.push(capitalize_first(p.clone())); } __result }); +pascal_parts.join(&"".to_string()) +} } pub fn capitalize_first(s: String) -> String { { let chars_list = Rc::new(s.chars().map(|c| c as i64).collect::>()); - if ((chars_list.clone().len() as i64) == 0) { +if ((chars_list.clone().len() as i64) == 0) { "".to_string() } else { - Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - chars_list - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push(if (pair.0.clone() == 0) { - to_upper_char(pair.1.clone()) - } else { - v2_rt::from_code_point(pair.1.clone()) - }); - } - __result - }) - .join(&"".to_string()) + Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(chars_list.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push(if (pair.0.clone() == 0) { + to_upper_char(pair.1.clone()) + } else { + v2_rt::from_code_point(pair.1.clone()) + }); } __result }).join(&"".to_string()) } - } +} } pub fn to_pascal(name: String) -> String { { let snake = to_snake(name); - let parts = Rc::new( - snake - .split(&"_".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - let pascal_parts = Rc::new({ - let mut __result = Vec::new(); - for p in parts.iter().cloned() { - __result.push(capitalize_first(p.clone())); - } - __result - }); - pascal_parts.join(&"".to_string()) - } +let parts = Rc::new(snake.split(&"_".to_string()).map(|s| s.to_string()).collect::>()); +let pascal_parts = Rc::new({ let mut __result = Vec::new(); for p in parts.iter().cloned() { __result.push(capitalize_first(p.clone())); } __result }); +pascal_parts.join(&"".to_string()) +} } pub fn apply_naming_case(name: String, case_style: NamingCase) -> String { match case_style { - NamingCase::PascalCase => { - let parts = Rc::new( - name.split(&"_".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - let pascal_parts = Rc::new({ - let mut __result = Vec::new(); - for p in parts.iter().cloned() { - __result.push(capitalize_first(p.clone())); - } - __result - }); - pascal_parts.join(&"".to_string()) - } - NamingCase::SnakeCase => to_snake(name), - NamingCase::CamelCase => to_camel(name), - NamingCase::AsAuthored => name, - } + NamingCase::PascalCase => { + let parts = Rc::new(name.split(&"_".to_string()).map(|s| s.to_string()).collect::>()); +let pascal_parts = Rc::new({ let mut __result = Vec::new(); for p in parts.iter().cloned() { __result.push(capitalize_first(p.clone())); } __result }); +pascal_parts.join(&"".to_string()) +}, + NamingCase::SnakeCase => to_snake(name), + NamingCase::CamelCase => to_camel(name), + NamingCase::AsAuthored => name, +} } pub fn service_var_name(service_name: String) -> String { @@ -1360,176 +685,71 @@ pub fn service_var_name(service_name: String) -> String { pub fn test_file_path(module_name: String, target: &RenderTarget) -> String { { let conventions = test_conventions_for_target(target.clone()); - let file_dir = match conventions.file_dir.clone() { - Some(dir) => dir.clone(), - None => "".to_string(), - }; - let filename = module_to_filename(module_name); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(file_dir, conventions.file_prefix.clone()), - filename, - ), - conventions.file_suffix.clone(), - ), - language_spec(target.clone()) - .scaffold - .clone() - .source_file_extension - .clone(), - ) - } +let file_dir = match conventions.file_dir.clone() { + Some(dir) => dir.clone(), + None => "".to_string(), +}; +let filename = module_to_filename(module_name); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(file_dir, conventions.file_prefix.clone()), filename), conventions.file_suffix.clone()), language_spec(target.clone()).scaffold.clone().source_file_extension.clone()) +} } pub fn test_function_name(projection: &Rc, target: RenderTarget) -> String { { let conventions = test_conventions_for_target(target); - let formatted = match conventions.name_style.clone() { - TestNameStyle::SnakeCaseTestNames => v2_rt::concat( - v2_rt::concat( - to_snake(sanitize_service_name(projection.service_name.clone())), - "_".to_string(), - ), - to_snake(projection.operation_name.clone()), - ), - TestNameStyle::PascalCaseTestNames => v2_rt::concat( - to_pascal(sanitize_service_name(projection.service_name.clone())), - to_pascal(projection.operation_name.clone()), - ), - }; - v2_rt::concat(conventions.function_prefix.clone(), formatted) - } +let formatted = match conventions.name_style.clone() { + TestNameStyle::SnakeCaseTestNames => v2_rt::concat(v2_rt::concat(to_snake(sanitize_service_name(projection.service_name.clone())), "_".to_string()), to_snake(projection.operation_name.clone())), + TestNameStyle::PascalCaseTestNames => v2_rt::concat(to_pascal(sanitize_service_name(projection.service_name.clone())), to_pascal(projection.operation_name.clone())), +}; +v2_rt::concat(conventions.function_prefix.clone(), formatted) +} } pub fn apply_type_template1(template: String, arg0: String) -> String { - Rc::new( - template - .split(&"{0}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&arg0) + Rc::new(template.split(&"{0}".to_string()).map(|s| s.to_string()).collect::>()).join(&arg0) } pub fn apply_type_template2(template: String, arg0: String, arg1: String) -> String { { - let parts = Rc::new( - template - .split(&"{0}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - let replaced = Rc::new({ - let mut __result = Vec::new(); - for p in parts.iter().cloned() { - __result.push( - Rc::new( - p.clone() - .split(&"{1}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&arg1.clone()), - ); - } - __result - }); - replaced.join(&arg0) - } + let parts = Rc::new(template.split(&"{0}".to_string()).map(|s| s.to_string()).collect::>()); +let replaced = Rc::new({ let mut __result = Vec::new(); for p in parts.iter().cloned() { __result.push(Rc::new(p.clone().split(&"{1}".to_string()).map(|s| s.to_string()).collect::>()).join(&arg1.clone())); } __result }); +replaced.join(&arg0) +} } pub fn apply_type_template3(template: String, arg0: String, arg1: String, arg2: String) -> String { { - let parts0 = Rc::new( - template - .split(&"{0}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - let replaced = Rc::new({ - let mut __result = Vec::new(); - for p0 in parts0.iter().cloned() { - __result.push({ - let parts1 = Rc::new( - p0.clone() - .split(&"{1}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - let inner = Rc::new({ - let mut __result = Vec::new(); - for p1 in parts1.clone().iter().cloned() { - __result.push( - Rc::new( - p1.clone() - .split(&"{2}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&arg2.clone()), - ); - } - __result - }); - inner.clone().join(&arg1.clone()) - }); - } - __result - }); - replaced.join(&arg0) - } + let parts0 = Rc::new(template.split(&"{0}".to_string()).map(|s| s.to_string()).collect::>()); +let replaced = Rc::new({ let mut __result = Vec::new(); for p0 in parts0.iter().cloned() { __result.push({ + let parts1 = Rc::new(p0.clone().split(&"{1}".to_string()).map(|s| s.to_string()).collect::>()); +let inner = Rc::new({ let mut __result = Vec::new(); for p1 in parts1.clone().iter().cloned() { __result.push(Rc::new(p1.clone().split(&"{2}".to_string()).map(|s| s.to_string()).collect::>()).join(&arg2.clone())); } __result }); +inner.clone().join(&arg1.clone()) +}); } __result }); +replaced.join(&arg0) +} } pub fn apply_named_template(template: String, bindings: &Rc>) -> String { apply_named_template_nested(template, &bindings, &Rc::new(v2_rt::map_keys(&bindings))) } -pub fn apply_named_template_nested( - template: String, - bindings: &Rc>, - keys: &Rc>, -) -> String { +pub fn apply_named_template_nested(template: String, bindings: &Rc>, keys: &Rc>) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match keys.clone().first().cloned() { - None => template, - Some(key) => { - let rest = Rc::new( - keys.clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let placeholder = - v2_rt::concat(v2_rt::concat("{".to_string(), key.clone()), "}".to_string()); - match v2_rt::map_get(&bindings, key.clone()) { - Some(val) => { - let parts = Rc::new( - template - .split(&placeholder) - .map(|s| s.to_string()) - .collect::>(), - ); - let processed = Rc::new({ - let mut __result = Vec::new(); - for part in parts.iter().cloned() { - __result.push(apply_named_template_nested( - part.clone(), - &bindings, - &rest, - )); - } - __result - }); - processed.join(&val.clone()) - } - None => { - v2_rt::concat("TEMPLATE_ERROR_MISSING_BINDING_".to_string(), key.clone()) - } - } - } - } + None => template, + Some(key) => { + let rest = Rc::new(keys.clone().iter().cloned().skip(1 as usize).collect::>()); +let placeholder = v2_rt::concat(v2_rt::concat("{".to_string(), key.clone()), "}".to_string()); +match v2_rt::map_get(&bindings, key.clone()) { + Some(val) => { + let parts = Rc::new(template.split(&placeholder).map(|s| s.to_string()).collect::>()); +let processed = Rc::new({ let mut __result = Vec::new(); for part in parts.iter().cloned() { __result.push(apply_named_template_nested(part.clone(), &bindings, &rest)); } __result }); +processed.join(&val.clone()) +}, + None => v2_rt::concat("TEMPLATE_ERROR_MISSING_BINDING_".to_string(), key.clone()), +} +}, +} }) } @@ -1538,163 +758,74 @@ pub fn language_spec(target: RenderTarget) -> Rc { } pub fn reserved_prefix(target: RenderTarget) -> String { - match (*language_spec(target) - .reserved_words - .clone() - .strategy - .clone()) - .clone() - { - ReservedWordStrategy::PrefixEscape { prefix, .. } => prefix.clone(), - _ => "".to_string(), - } + match (*language_spec(target).reserved_words.clone().strategy.clone()).clone() { + ReservedWordStrategy::PrefixEscape { prefix, .. } => prefix.clone(), + _ => "".to_string(), +} } pub fn reserved_suffix(target: RenderTarget) -> String { - match (*language_spec(target) - .reserved_words - .clone() - .strategy - .clone()) - .clone() - { - ReservedWordStrategy::SuffixEscape { suffix, .. } => suffix.clone(), - _ => "".to_string(), - } + match (*language_spec(target).reserved_words.clone().strategy.clone()).clone() { + ReservedWordStrategy::SuffixEscape { suffix, .. } => suffix.clone(), + _ => "".to_string(), +} } pub fn escape_string_literal_body(s: String) -> String { { - let escaped_backslash = Rc::new( - s.split(&"\\".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\\\".to_string()); - let escaped_quote = Rc::new( - escaped_backslash - .split(&"\"".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\\"".to_string()); - let escaped_newline = Rc::new( - escaped_quote - .split(&"\n".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\n".to_string()); - let escaped_return = Rc::new( - escaped_newline - .split(&"\\r".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\r".to_string()); - Rc::new( - escaped_return - .split(&"\t".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"\\t".to_string()) - } + let escaped_backslash = Rc::new(s.split(&"\\".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\\\".to_string()); +let escaped_quote = Rc::new(escaped_backslash.split(&"\"".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\\"".to_string()); +let escaped_newline = Rc::new(escaped_quote.split(&"\n".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\n".to_string()); +let escaped_return = Rc::new(escaped_newline.split(&"\\r".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\r".to_string()); +Rc::new(escaped_return.split(&"\t".to_string()).map(|s| s.to_string()).collect::>()).join(&"\\t".to_string()) +} } pub fn escape_rust_interp_text(s: String) -> String { { - let escaped = Rc::new( - escape_string_literal_body(s) - .split(&"{".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"{{".to_string()); - Rc::new( - escaped - .split(&"}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"}}".to_string()) - } + let escaped = Rc::new(escape_string_literal_body(s).split(&"{".to_string()).map(|s| s.to_string()).collect::>()).join(&"{{".to_string()); +Rc::new(escaped.split(&"}".to_string()).map(|s| s.to_string()).collect::>()).join(&"}}".to_string()) +} } pub fn escape_go_interp_text(s: String) -> String { - Rc::new( - escape_string_literal_body(s) - .split(&"%".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"%%".to_string()) + Rc::new(escape_string_literal_body(s).split(&"%".to_string()).map(|s| s.to_string()).collect::>()).join(&"%%".to_string()) } pub fn escape_python_interp_text(s: String) -> String { { - let escaped = Rc::new( - escape_string_literal_body(s) - .split(&"{".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"{{".to_string()); - Rc::new( - escaped - .split(&"}".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&"}}".to_string()) - } + let escaped = Rc::new(escape_string_literal_body(s).split(&"{".to_string()).map(|s| s.to_string()).collect::>()).join(&"{{".to_string()); +Rc::new(escaped.split(&"}".to_string()).map(|s| s.to_string()).collect::>()).join(&"}}".to_string()) +} } pub fn apply_escape_pairs(s: String, pairs: Rc>>) -> String { - pairs - .iter() - .cloned() - .fold(s.clone(), |acc: String, pair: Rc| { - Rc::new( - acc.split(&pair.from.clone()) - .map(|s| s.to_string()) - .collect::>(), - ) - .join(&pair.to.clone()) - }) + pairs.iter().cloned().fold(s.clone(), |acc: String, pair: Rc| Rc::new(acc.split(&pair.from.clone()).map(|s| s.to_string()).collect::>()).join(&pair.to.clone())) } pub fn emit_string_literal(s: String, suffix: String) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("\"".to_string(), escape_string_literal_body(s)), - "\"".to_string(), - ), - suffix, - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat("\"".to_string(), escape_string_literal_body(s)), "\"".to_string()), suffix) } pub fn is_null_coalesce(op: BinOp) -> bool { match op { - BinOp::NullCoalesce => true, - _ => false, - } + BinOp::NullCoalesce => true, + _ => false, +} } pub fn rust_literal_for_pattern(value: Rc) -> String { match (*value).clone() { - LiteralValue::LitStr { value: s, .. } => emit_string_literal(s.clone(), "".to_string()), - LiteralValue::LitInt { value: i, .. } => (i.clone()).to_string(), - LiteralValue::LitFloat { value: f, .. } => f.clone(), - LiteralValue::LitBool { value: b, .. } => { - if b.clone() { - emit_keyword("true".to_string(), RenderTarget::Rust) - } else { - emit_keyword("false".to_string(), RenderTarget::Rust) - } - } - LiteralValue::LitNull => emit_keyword("null".to_string(), RenderTarget::Rust), - } + LiteralValue::LitStr { value: s, .. } => emit_string_literal(s.clone(), "".to_string()), + LiteralValue::LitInt { value: i, .. } => (i.clone()).to_string(), + LiteralValue::LitFloat { value: f, .. } => f.clone(), + LiteralValue::LitBool { value: b, .. } => if b.clone() { + emit_keyword("true".to_string(), RenderTarget::Rust) + } else { + emit_keyword("false".to_string(), RenderTarget::Rust) + }, + LiteralValue::LitNull => emit_keyword("null".to_string(), RenderTarget::Rust), +} } pub fn emit_keyword(key: String, target: RenderTarget) -> String { @@ -1703,41 +834,29 @@ pub fn emit_keyword(key: String, target: RenderTarget) -> String { pub fn emit_literal(value: Rc, target: &RenderTarget) -> String { match (*value).clone() { - LiteralValue::LitStr { value: s, .. } => { - let suffix = match literal_suffix(target.clone(), "String".to_string()) { - Some(sfx) => sfx.clone(), - None => emit_error_expr( - "missing TypeCheckpoint for String literal suffix".to_string(), - target.clone(), - ), - }; - emit_string_literal(s.clone(), suffix) - } - LiteralValue::LitInt { value: i, .. } => (i.clone()).to_string(), - LiteralValue::LitFloat { value: f, .. } => f.clone(), - LiteralValue::LitBool { value: b, .. } => { - if b.clone() { - emit_keyword("true".to_string(), target.clone()) - } else { - emit_keyword("false".to_string(), target.clone()) - } - } - LiteralValue::LitNull => emit_keyword("null".to_string(), target.clone()), - } + LiteralValue::LitStr { value: s, .. } => { + let suffix = match literal_suffix(target.clone(), "String".to_string()) { + Some(sfx) => sfx.clone(), + None => emit_error_expr("missing TypeCheckpoint for String literal suffix".to_string(), target.clone()), +}; +emit_string_literal(s.clone(), suffix) +}, + LiteralValue::LitInt { value: i, .. } => (i.clone()).to_string(), + LiteralValue::LitFloat { value: f, .. } => f.clone(), + LiteralValue::LitBool { value: b, .. } => if b.clone() { + emit_keyword("true".to_string(), target.clone()) + } else { + emit_keyword("false".to_string(), target.clone()) + }, + LiteralValue::LitNull => emit_keyword("null".to_string(), target.clone()), +} } -pub fn emit_bin_op_symbol( - op: BinOp, - target: &RenderTarget, - algebra_field: Option, -) -> String { +pub fn emit_bin_op_symbol(op: BinOp, target: &RenderTarget, algebra_field: Option) -> String { match binop_symbol(target.clone(), op, algebra_field) { - Some(sym) => sym.clone(), - None => emit_error_expr( - "missing OperatorSpec for BinOp in target language".to_string(), - target.clone(), - ), - } + Some(sym) => sym.clone(), + None => emit_error_expr("missing OperatorSpec for BinOp in target language".to_string(), target.clone()), +} } pub fn emit_container(kind: &String, inner: String, target: &RenderTarget) -> String { @@ -1745,467 +864,303 @@ pub fn emit_container(kind: &String, inner: String, target: &RenderTarget) -> St apply_type_template1(target_optional_template(target.clone()), inner) } else { match coerce_container_template(target.clone(), kind.clone()) { - Some(template) => apply_type_template1(template.clone(), inner), - None => { - let spec = language_spec(target.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(kind.clone(), spec.type_arg_open.clone()), - inner, - ), - spec.type_arg_close.clone(), - ) - } - } + Some(template) => apply_type_template1(template.clone(), inner), + None => { + let spec = language_spec(target.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(kind.clone(), spec.type_arg_open.clone()), inner), spec.type_arg_close.clone()) +}, +} } } pub fn emit_map_type(key_type: String, val_type: String, target: RenderTarget) -> String { match coerce_container_template(target, "map".to_string()) { - Some(template) => apply_type_template2(template.clone(), key_type, val_type), - None => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("Map<".to_string(), key_type), - ", ".to_string(), - ), - val_type, - ), - ">".to_string(), - ), - } + Some(template) => apply_type_template2(template.clone(), key_type, val_type), + None => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Map<".to_string(), key_type), ", ".to_string()), val_type), ">".to_string()), +} +} + +pub fn emit_node_type(n: Rc, target: RenderTarget, source_indices: Rc>>) -> String { + render_node_type(&n, &target, &v2_rt::rc_empty_map::(), &source_indices) } -pub fn emit_node_type( - n: Rc, - target: RenderTarget, - source_indices: Rc>>, -) -> String { - render_node_type( - &n, - &target, - &v2_rt::rc_empty_map::(), - &source_indices, - ) -} - -pub fn render_node_type( - n: &Rc, - target: &RenderTarget, - shared_types: &Rc>, - source_indices: &Rc>>, -) -> String { +pub fn render_node_type(n: &Rc, target: &RenderTarget, shared_types: &Rc>, source_indices: &Rc>>) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let tn = authored_name_at(source_indices.clone(), &n); - let n_is_error = if (n.inferred.clone() != None) { - is_compiler_error(n.inferred.clone().clone().unwrap()) - } else { - false - }; - let n_is_type_var = if (n.inferred.clone() != None) { - is_type_variable(n.inferred.clone().clone().unwrap()) - } else { - false - }; - if ((n_is_type_var || n_is_error.clone()) && ((n.children.clone().len() as i64) == 0)) { - { - let label = if n_is_error.clone() { - "CompilerError".to_string() - } else { - "TypeVariable".to_string() - }; - let spec = language_spec(target.clone()); - let err_str = apply_type_template1( - spec.error_type_template.clone(), - v2_rt::concat("UNRESOLVED_".to_string(), label), - ); - return err_str; + { + let tn = authored_name_at(source_indices.clone(), &n); +let n_is_error = if (n.inferred.clone() != None) { + is_compiler_error(n.inferred.clone().clone().unwrap()) + } else { + false + }; +let n_is_type_var = if (n.inferred.clone() != None) { + is_type_variable(n.inferred.clone().clone().unwrap()) + } else { + false + }; +if ((n_is_type_var || n_is_error.clone()) && ((n.children.clone().len() as i64) == 0)) { + { + let label = if n_is_error.clone() { + "CompilerError".to_string() + } else { + "TypeVariable".to_string() + }; +let spec = language_spec(target.clone()); +let err_str = apply_type_template1(spec.error_type_template.clone(), v2_rt::concat("UNRESOLVED_".to_string(), label)); +return err_str +} } - } - let is_arrow = (n.connective.clone() == Connective::Arrow); - if is_arrow { - { - let repr = target_callable(target.clone()); - let param_strs = Rc::new({ - let mut __result = Vec::new(); - for p in n.params.clone().iter().cloned() { - __result.push(render_node_type( - ¶m_node_type_expr(&p), - &target, - &shared_types, - &source_indices, - )); - } - __result - }); - let param_str = param_strs.join(&repr.param_separator.clone()); - let ret_str = match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - render_node_type(&rt, &target, &shared_types, &source_indices) - } - _ => language_spec(target.clone()).void_type.clone(), - }; - let spec = language_spec(target.clone()); - let result = match spec.callable_type_template.clone() { - Some(t) => v2_rt::replace( - v2_rt::replace(t.clone(), "{params}".to_string(), param_str), - "{return}".to_string(), - ret_str.clone(), - ), - None => { - if (ret_str.clone().as_str() == "".to_string().as_str()) { - { - let void_template = v2_rt::replace( - repr.template.clone(), - v2_rt::concat( - repr.return_separator.clone(), - "{return}".to_string(), - ), - "".to_string(), - ); - v2_rt::replace(void_template, "{params}".to_string(), param_str) - } - } else { - v2_rt::replace( - v2_rt::replace( - repr.template.clone(), - "{params}".to_string(), - param_str, - ), - "{return}".to_string(), - ret_str.clone(), - ) - } - } - }; - return result; +let is_arrow = (n.connective.clone() == Connective::Arrow); +if is_arrow { + { + let repr = target_callable(target.clone()); +let param_strs = Rc::new({ let mut __result = Vec::new(); for p in n.params.clone().iter().cloned() { __result.push(render_node_type(¶m_node_type_expr(&p), &target, &shared_types, &source_indices)); } __result }); +let param_str = param_strs.join(&repr.param_separator.clone()); +let ret_str = match n.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => render_node_type(&rt, &target, &shared_types, &source_indices), + _ => language_spec(target.clone()).void_type.clone(), +}; +let spec = language_spec(target.clone()); +let result = match spec.callable_type_template.clone() { + Some(t) => v2_rt::replace(v2_rt::replace(t.clone(), "{params}".to_string(), param_str), "{return}".to_string(), ret_str.clone()), + None => if (ret_str.clone().as_str() == "".to_string().as_str()) { + { + let void_template = v2_rt::replace(repr.template.clone(), v2_rt::concat(repr.return_separator.clone(), "{return}".to_string()), "".to_string()); +v2_rt::replace(void_template, "{params}".to_string(), param_str) +} + } else { + v2_rt::replace(v2_rt::replace(repr.template.clone(), "{params}".to_string(), param_str), "{return}".to_string(), ret_str.clone()) + }, +}; +return result +} } - } - let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { - { - let inner_str = render_node_type( - &with_required_cardinality(&n), - &target, - &shared_types, - &source_indices, - ); - let opt_str = emit_container(&"optional".to_string(), inner_str, &target); - return opt_str; +let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); +if is_optional { + { + let inner_str = render_node_type(&with_required_cardinality(&n), &target, &shared_types, &source_indices); +let opt_str = emit_container(&"optional".to_string(), inner_str, &target); +return opt_str +} } - } - let is_conj = (n.connective.clone() == Connective::Conj); - let is_disj = (n.connective.clone() == Connective::Disj); - let shared = emit_map_has(shared_types.clone(), tn.clone()); - if is_disj { - { - let base = if (n.ident_span.clone() != None) { - coerce_primitive_type(target.clone(), tn.clone()) - } else { - { - let spec = language_spec(target.clone()); - apply_type_template1( - spec.error_type_template.clone(), - "ANONYMOUS_COPRODUCT".to_string(), - ) - } - }; - let disj_str = if shared.clone() { - wrap_shared_type(target.clone(), base.clone()) - } else { - base.clone() - }; - return disj_str; +let is_conj = (n.connective.clone() == Connective::Conj); +let is_disj = (n.connective.clone() == Connective::Disj); +let shared = emit_map_has(shared_types.clone(), tn.clone()); +if is_disj { + { + let base = if (n.ident_span.clone() != None) { + coerce_primitive_type(target.clone(), tn.clone()) + } else { + { + let spec = language_spec(target.clone()); +apply_type_template1(spec.error_type_template.clone(), "ANONYMOUS_COPRODUCT".to_string()) +} + }; +let disj_str = if shared.clone() { + wrap_shared_type(target.clone(), base.clone()) + } else { + base.clone() + }; +return disj_str +} } - } - if is_conj { - { - if (n.type_annotation.clone() != None) { - { - let refined_str = match n.children.clone().first().cloned() { - Some(base) => { - render_node_type(&base, &target, &shared_types, &source_indices) - } - None => coerce_primitive_type(target.clone(), "Refined".to_string()), - }; - return refined_str; +if is_conj { + { + if (n.type_annotation.clone() != None) { + { + let refined_str = match n.children.clone().first().cloned() { + Some(base) => render_node_type(&base, &target, &shared_types, &source_indices), + None => coerce_primitive_type(target.clone(), "Refined".to_string()), +}; +return refined_str +} } - } - let is_pair = (((n.connective.clone() == Connective::Conj) - && (n.ident_span.clone() == None)) - && ((n.children.clone().len() as i64) == 2)); - if is_pair { - { - let first_child = match n.children.clone().first().cloned() { - Some(c) => { - if (c.inferred.clone() != None) { - render_node_type( - &resolved_type(c.clone()), - &target, - &shared_types, - &source_indices, - ) - } else { - render_node_type(&c, &target, &shared_types, &source_indices) - } - } - None => "_".to_string(), - }; - let second_child = match n.children.clone().get(1 as usize).cloned() { - Some(c) => { - if (c.inferred.clone() != None) { - render_node_type( - &resolved_type(c.clone()), - &target, - &shared_types, - &source_indices, - ) - } else { - render_node_type(&c, &target, &shared_types, &source_indices) - } - } - None => "_".to_string(), - }; - let tuple_str = render_tuple_parts( - &Rc::new(vec![first_child, second_child]), - target.clone(), - ); - return tuple_str; +let is_pair = (((n.connective.clone() == Connective::Conj) && (n.ident_span.clone() == None)) && ((n.children.clone().len() as i64) == 2)); +if is_pair { + { + let first_child = match n.children.clone().first().cloned() { + Some(c) => if (c.inferred.clone() != None) { + render_node_type(&resolved_type(c.clone()), &target, &shared_types, &source_indices) + } else { + render_node_type(&c, &target, &shared_types, &source_indices) + }, + None => "_".to_string(), +}; +let second_child = match n.children.clone().get(1 as usize).cloned() { + Some(c) => if (c.inferred.clone() != None) { + render_node_type(&resolved_type(c.clone()), &target, &shared_types, &source_indices) + } else { + render_node_type(&c, &target, &shared_types, &source_indices) + }, + None => "_".to_string(), +}; +let tuple_str = render_tuple_parts(&Rc::new(vec![first_child, second_child]), target.clone()); +return tuple_str +} } - } - if (n.ident_span.clone() != None) { - { - let snake = to_snake(tn.clone()); - let has_template = match container_template_algebra(snake.clone()) { - Some(_) => true, - None => false, - }; - if has_template { - { - let base = if (snake.clone().as_str() == "map".to_string().as_str()) +if (n.ident_span.clone() != None) { + { + let snake = to_snake(tn.clone()); +let has_template = match container_template_algebra(snake.clone()) { + Some(_) => true, + None => false, +}; +if has_template { { - emit_map_type("_".to_string(), "_".to_string(), target.clone()) - } else { - emit_container(&snake, "_".to_string(), &target) - }; - let conj_container_str = if shared.clone() { - wrap_shared_type(target.clone(), base.clone()) - } else { - base.clone() - }; - return conj_container_str; + let base = if (snake.clone().as_str() == "map".to_string().as_str()) { + emit_map_type("_".to_string(), "_".to_string(), target.clone()) + } else { + emit_container(&snake, "_".to_string(), &target) + }; +let conj_container_str = if shared.clone() { + wrap_shared_type(target.clone(), base.clone()) + } else { + base.clone() + }; +return conj_container_str +} } - } - let base = coerce_primitive_type(target.clone(), tn.clone()); - let conj_named_str = if shared.clone() { - wrap_shared_type(target.clone(), base.clone()) - } else { - base.clone() - }; - return conj_named_str; - } - } - let parts = Rc::new({ - let mut __result = Vec::new(); - for child in n.children.clone().iter().cloned() { - __result.push(render_node_type( - &resolved_type(child.clone()), - &target, - &shared_types, - &source_indices, - )); +let base = coerce_primitive_type(target.clone(), tn.clone()); +let conj_named_str = if shared.clone() { + wrap_shared_type(target.clone(), base.clone()) + } else { + base.clone() + }; +return conj_named_str +} } - __result - }); - let anon_str = render_tuple_parts(&parts, target.clone()); - return anon_str; +let parts = Rc::new({ let mut __result = Vec::new(); for child in n.children.clone().iter().cloned() { __result.push(render_node_type(&resolved_type(child.clone()), &target, &shared_types, &source_indices)); } __result }); +let anon_str = render_tuple_parts(&parts, target.clone()); +return anon_str +} } - } - if ((n.children.clone().len() as i64) == 0) { - { - let bare_is_map = (is_container_type(tn.clone()) - && (to_snake(tn.clone()).as_str() == "map".to_string().as_str())); - let bare_is_collection = (is_container_type(tn.clone()) && !bare_is_map.clone()); - let has_container_template = match container_template_algebra(to_snake(tn.clone())) +if ((n.children.clone().len() as i64) == 0) { { - Some(_) => true, - None => false, - }; - let param_count = (n.params.clone().len() as i64); - let base = if bare_is_map.clone() { - emit_map_type("_".to_string(), "_".to_string(), target.clone()) - } else { - if bare_is_collection { - emit_container(&to_snake(tn.clone()), "_".to_string(), &target) + let bare_is_map = (is_container_type(tn.clone()) && (to_snake(tn.clone()).as_str() == "map".to_string().as_str())); +let bare_is_collection = (is_container_type(tn.clone()) && !bare_is_map.clone()); +let has_container_template = match container_template_algebra(to_snake(tn.clone())) { + Some(_) => true, + None => false, +}; +let param_count = (n.params.clone().len() as i64); +let base = if bare_is_map.clone() { + emit_map_type("_".to_string(), "_".to_string(), target.clone()) } else { - if (has_container_template && (param_count == 1)) { - { - let inner = match n.params.clone().first().cloned() { - Some(p) => render_node_type( - ¶m_node_type_expr(&p), - &target, - &shared_types, - &source_indices, - ), - None => "_".to_string(), - }; - emit_container(&to_snake(tn.clone()), inner, &target) - } + if bare_is_collection { + emit_container(&to_snake(tn.clone()), "_".to_string(), &target) } else { - if (tn.clone().as_str() == tuple_type_name().as_str()) { - render_tuple_parts(&Rc::new(vec![]), target.clone()) + if (has_container_template && (param_count == 1)) { + { + let inner = match n.params.clone().first().cloned() { + Some(p) => render_node_type(¶m_node_type_expr(&p), &target, &shared_types, &source_indices), + None => "_".to_string(), +}; +emit_container(&to_snake(tn.clone()), inner, &target) +} } else { - coerce_primitive_type(target.clone(), tn.clone()) + if (tn.clone().as_str() == tuple_type_name().as_str()) { + render_tuple_parts(&Rc::new(vec![]), target.clone()) + } else { + coerce_primitive_type(target.clone(), tn.clone()) + } } } - } - }; - let bare_str = if shared.clone() { - wrap_shared_type(target.clone(), base.clone()) - } else { - base.clone() - }; - return bare_str; + }; +let bare_str = if shared.clone() { + wrap_shared_type(target.clone(), base.clone()) + } else { + base.clone() + }; +return bare_str +} } - } - let is_map = node_is_keyed_collection(&n, source_indices.clone()); - if is_map { - { - let k = match n.children.clone().first().cloned() { - Some(kn) => render_node_type( - &child_type_node(&kn), - &target, - &shared_types, - &source_indices, - ), - None => "_".to_string(), - }; - let v = match n.children.clone().get(1 as usize).cloned() { - Some(vn) => render_node_type( - &child_type_node(&vn), - &target, - &shared_types, - &source_indices, - ), - None => "_".to_string(), - }; - let base = emit_map_type(k, v, target.clone()); - let map_str = if shared.clone() { - wrap_shared_type(target.clone(), base.clone()) - } else { - base.clone() - }; - return map_str; +let is_map = node_is_keyed_collection(&n, source_indices.clone()); +if is_map { + { + let k = match n.children.clone().first().cloned() { + Some(kn) => render_node_type(&child_type_node(&kn), &target, &shared_types, &source_indices), + None => "_".to_string(), +}; +let v = match n.children.clone().get(1 as usize).cloned() { + Some(vn) => render_node_type(&child_type_node(&vn), &target, &shared_types, &source_indices), + None => "_".to_string(), +}; +let base = emit_map_type(k, v, target.clone()); +let map_str = if shared.clone() { + wrap_shared_type(target.clone(), base.clone()) + } else { + base.clone() + }; +return map_str +} } - } - if ((n.children.clone().len() as i64) == 1) { - { - let child_str = match n.children.clone().first().cloned() { - Some(child) => render_node_type( - &child_type_node(&child), - &target, - &shared_types, - &source_indices, - ), - None => "_".to_string(), - }; - let is_container = node_is_collection(&n, source_indices.clone()); - let base = if is_container { - emit_container(&to_snake(tn.clone()), child_str, &target) - } else { - { - let type_base = coerce_primitive_type(target.clone(), tn.clone()); - let spec = language_spec(target.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(type_base.clone(), spec.type_arg_open.clone()), - child_str, - ), - spec.type_arg_close.clone(), - ) - } - }; - let single_str = if shared.clone() { - wrap_shared_type(target.clone(), base.clone()) - } else { - base.clone() - }; - return single_str; +if ((n.children.clone().len() as i64) == 1) { + { + let child_str = match n.children.clone().first().cloned() { + Some(child) => render_node_type(&child_type_node(&child), &target, &shared_types, &source_indices), + None => "_".to_string(), +}; +let is_container = node_is_collection(&n, source_indices.clone()); +let base = if is_container { + emit_container(&to_snake(tn.clone()), child_str, &target) + } else { + { + let type_base = coerce_primitive_type(target.clone(), tn.clone()); +let spec = language_spec(target.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(type_base.clone(), spec.type_arg_open.clone()), child_str), spec.type_arg_close.clone()) +} + }; +let single_str = if shared.clone() { + wrap_shared_type(target.clone(), base.clone()) + } else { + base.clone() + }; +return single_str +} } - } - let child_strs = Rc::new({ - let mut __result = Vec::new(); - for c in n.children.clone().iter().cloned() { - __result.push(render_node_type( - &child_type_node(&c), - &target, - &shared_types, - &source_indices, - )); +let child_strs = Rc::new({ let mut __result = Vec::new(); for c in n.children.clone().iter().cloned() { __result.push(render_node_type(&child_type_node(&c), &target, &shared_types, &source_indices)); } __result }); +if (tn.clone().as_str() == tuple_type_name().as_str()) { + { + let multi_tuple_str = render_tuple_parts(&child_strs, target.clone()); +return multi_tuple_str +} } - __result - }); - if (tn.clone().as_str() == tuple_type_name().as_str()) { - { - let multi_tuple_str = render_tuple_parts(&child_strs, target.clone()); - return multi_tuple_str; +let type_base = coerce_primitive_type(target.clone(), tn.clone()); +let args_joined = child_strs.clone().join(&", ".to_string()); +let spec = language_spec(target.clone()); +let base = v2_rt::concat(v2_rt::concat(v2_rt::concat(type_base.clone(), spec.type_arg_open.clone()), args_joined), spec.type_arg_close.clone()); +if shared.clone() { + wrap_shared_type(target.clone(), base.clone()) + } else { + base.clone() } - } - let type_base = coerce_primitive_type(target.clone(), tn.clone()); - let args_joined = child_strs.clone().join(&", ".to_string()); - let spec = language_spec(target.clone()); - let base = v2_rt::concat( - v2_rt::concat( - v2_rt::concat(type_base.clone(), spec.type_arg_open.clone()), - args_joined, - ), - spec.type_arg_close.clone(), - ); - if shared.clone() { - wrap_shared_type(target.clone(), base.clone()) - } else { - base.clone() - } +} }) } pub fn render_tuple_parts(parts: &Rc>, target: RenderTarget) -> String { { let spec = language_spec(target); - let ts = spec.tuple_syntax.clone(); - if ((parts.clone().len() as i64) > 0) { +let ts = spec.tuple_syntax.clone(); +if ((parts.clone().len() as i64) > 0) { if ((parts.clone().len() as i64) == 2) { match parts.clone().first().cloned() { - Some(p0) => match parts.clone().get(1 as usize).cloned() { - Some(p1) => { - apply_type_template2(ts.pair_template.clone(), p0.clone(), p1.clone()) - } - None => apply_type_template1( - ts.multi_template.clone(), - parts.clone().join(&ts.separator.clone()), - ), - }, - None => apply_type_template1( - ts.multi_template.clone(), - parts.clone().join(&ts.separator.clone()), - ), - } + Some(p0) => match parts.clone().get(1 as usize).cloned() { + Some(p1) => apply_type_template2(ts.pair_template.clone(), p0.clone(), p1.clone()), + None => apply_type_template1(ts.multi_template.clone(), parts.clone().join(&ts.separator.clone())), +}, + None => apply_type_template1(ts.multi_template.clone(), parts.clone().join(&ts.separator.clone())), +} } else { - apply_type_template1( - ts.multi_template.clone(), - parts.clone().join(&ts.separator.clone()), - ) + apply_type_template1(ts.multi_template.clone(), parts.clone().join(&ts.separator.clone())) } } else { ts.empty.clone() } - } +} } -pub fn is_type_alias_return_node( - n: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_type_alias_return_node(n: Rc, source_indices: Rc>>) -> bool { (authored_name_at(source_indices, &n).as_str() != "Unit".to_string().as_str()) } @@ -2214,25 +1169,7 @@ pub fn is_service_item(item: &Rc) -> bool { } pub fn has_service_items(typed: Rc) -> bool { - { - let mut __found = false; - for tm in typed.modules.clone().iter().cloned() { - if { - let mut __found = false; - for item in tm.items.clone().iter().cloned() { - if is_service_item(&item) { - __found = true; - break; - } - } - __found - } { - __found = true; - break; - } - } - __found - } + { let mut __found = false; for tm in typed.modules.clone().iter().cloned() { if { let mut __found = false; for item in tm.items.clone().iter().cloned() { if is_service_item(&item) { __found = true; break; } } __found } { __found = true; break; } } __found } } pub fn service_fallback_transport(item: &Rc) -> Rc { @@ -2245,144 +1182,76 @@ pub fn service_fallback_transport(item: &Rc) -> Rc { pub fn effective_operation_transport(op_node: Rc, fallback: Rc) -> Rc { match op_node.transport.clone() { - Some(op_transport) => op_transport.clone(), - None => fallback, - } + Some(op_transport) => op_transport.clone(), + None => fallback, +} } -pub fn service_has_rest( - fallback_transport: Rc, - op_children: Rc>>, - source_indices: &Rc>>, -) -> bool { +pub fn service_has_rest(fallback_transport: Rc, op_children: Rc>>, source_indices: &Rc>>) -> bool { { let from_fallback = is_rest_transport(fallback_transport, source_indices.clone()); - let from_ops = { - let mut __found = false; - for op in op_children.iter().cloned() { - if if (op.transport.clone() != None) { - is_rest_transport( - op.transport.clone().clone().unwrap(), - source_indices.clone(), - ) - } else { - false - } { - __found = true; - break; - } - } - __found - }; - (from_fallback || from_ops) - } +let from_ops = { let mut __found = false; for op in op_children.iter().cloned() { if if (op.transport.clone() != None) { + is_rest_transport(op.transport.clone().clone().unwrap(), source_indices.clone()) + } else { + false + } { __found = true; break; } } __found }; +(from_fallback || from_ops) +} } pub fn service_has_shell(fallback_transport: Rc, op_children: Rc>>) -> bool { { let from_fallback = is_shell_transport(fallback_transport); - let from_ops = { - let mut __found = false; - for op in op_children.iter().cloned() { - if if (op.transport.clone() != None) { - is_shell_transport(op.transport.clone().clone().unwrap()) - } else { - false - } { - __found = true; - break; - } - } - __found - }; - (from_fallback || from_ops) - } +let from_ops = { let mut __found = false; for op in op_children.iter().cloned() { if if (op.transport.clone() != None) { + is_shell_transport(op.transport.clone().clone().unwrap()) + } else { + false + } { __found = true; break; } } __found }; +(from_fallback || from_ops) +} } -pub fn service_has_file( - fallback_transport: Rc, - op_children: Rc>>, - source_indices: &Rc>>, -) -> bool { +pub fn service_has_file(fallback_transport: Rc, op_children: Rc>>, source_indices: &Rc>>) -> bool { { let from_fallback = is_file_transport(fallback_transport, source_indices.clone()); - let from_ops = { - let mut __found = false; - for op in op_children.iter().cloned() { - if if (op.transport.clone() != None) { - is_file_transport( - op.transport.clone().clone().unwrap(), - source_indices.clone(), - ) - } else { - false - } { - __found = true; - break; - } - } - __found - }; - (from_fallback || from_ops) - } +let from_ops = { let mut __found = false; for op in op_children.iter().cloned() { if if (op.transport.clone() != None) { + is_file_transport(op.transport.clone().clone().unwrap(), source_indices.clone()) + } else { + false + } { __found = true; break; } } __found }; +(from_fallback || from_ops) +} } -pub fn service_has_rest_auth( - fallback_transport: &Rc, - op_children: Rc>>, - source_indices: &Rc>>, -) -> bool { +pub fn service_has_rest_auth(fallback_transport: &Rc, op_children: Rc>>, source_indices: &Rc>>) -> bool { { - let fallback_is_rest = - is_rest_transport(fallback_transport.clone(), source_indices.clone()); - let from_fallback = if fallback_is_rest { + let fallback_is_rest = is_rest_transport(fallback_transport.clone(), source_indices.clone()); +let from_fallback = if fallback_is_rest { transport_has_auth(fallback_transport.clone(), source_indices.clone()) } else { false }; - let from_ops = { - let mut __found = false; - for op in op_children.iter().cloned() { - if if (op.transport.clone() != None) { - { - let t = op.transport.clone().clone().unwrap(); - if is_rest_transport(t.clone(), source_indices.clone()) { - transport_has_auth(t.clone(), source_indices.clone()) - } else { - false - } - } +let from_ops = { let mut __found = false; for op in op_children.iter().cloned() { if if (op.transport.clone() != None) { + { + let t = op.transport.clone().clone().unwrap(); +if is_rest_transport(t.clone(), source_indices.clone()) { + transport_has_auth(t.clone(), source_indices.clone()) } else { false - } { - __found = true; - break; } - } - __found - }; - (from_fallback || from_ops) - } +} + } else { + false + } { __found = true; break; } } __found }; +(from_fallback || from_ops) +} } -pub fn extract_modifier_names( - properties: Rc>>, - source_indices: Rc>>, -) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for p in properties.iter().cloned() { - __result.extend( - (*match field_init_operation_modifier(p.clone(), source_indices.clone()) { - Some(modifier) => Rc::new(vec![operation_modifier_name(modifier.clone())]), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }) +pub fn extract_modifier_names(properties: Rc>>, source_indices: Rc>>) -> Rc> { + Rc::new({ let mut __result = Vec::new(); for p in properties.iter().cloned() { __result.extend((*match field_init_operation_modifier(p.clone(), source_indices.clone()) { + Some(modifier) => Rc::new(vec![operation_modifier_name(modifier.clone())]), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }) } #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] @@ -2393,93 +1262,70 @@ pub struct ServiceFieldSet { pub has_auth: bool, } -pub fn compute_service_fields( - fallback_transport: &Rc, - op_children: &Rc>>, - source_indices: &Rc>>, -) -> ServiceFieldSet { +pub fn compute_service_fields(fallback_transport: &Rc, op_children: &Rc>>, source_indices: &Rc>>) -> ServiceFieldSet { ServiceFieldSet { - has_rest: service_has_rest( - fallback_transport.clone(), - op_children.clone(), - &source_indices, - ), - has_shell: service_has_shell(fallback_transport.clone(), op_children.clone()), - has_file: service_has_file( - fallback_transport.clone(), - op_children.clone(), - &source_indices, - ), - has_auth: service_has_rest_auth(&fallback_transport, op_children.clone(), &source_indices), - } + has_rest: service_has_rest(fallback_transport.clone(), op_children.clone(), &source_indices), + has_shell: service_has_shell(fallback_transport.clone(), op_children.clone()), + has_file: service_has_file(fallback_transport.clone(), op_children.clone(), &source_indices), + has_auth: service_has_rest_auth(&fallback_transport, op_children.clone(), &source_indices), +} } pub fn service_field_decls(fs: &ServiceFieldSet, t: &Rc) -> Rc> { { let result = Rc::new(vec![]); - let result = if fs.has_rest.clone() { +let result = if fs.has_rest.clone() { v2_rt::concat(result.clone(), Rc::new(vec![t.rest_decl.clone()])) } else { result.clone() }; - let result = if fs.has_auth.clone() { +let result = if fs.has_auth.clone() { v2_rt::concat(result.clone(), Rc::new(vec![t.auth_decl.clone()])) } else { result.clone() }; - let result = if fs.has_shell.clone() { +let result = if fs.has_shell.clone() { v2_rt::concat(result.clone(), Rc::new(vec![t.shell_decl.clone()])) } else { result.clone() }; - let result = if fs.has_file.clone() { +let result = if fs.has_file.clone() { v2_rt::concat(result.clone(), Rc::new(vec![t.file_decl.clone()])) } else { result.clone() }; - result.clone() - } +result.clone() +} } pub fn service_field_ctors(fs: &ServiceFieldSet, t: &Rc) -> Rc> { { let result = Rc::new(vec![]); - let result = if fs.has_rest.clone() { +let result = if fs.has_rest.clone() { v2_rt::concat(result.clone(), Rc::new(vec![t.rest_ctor.clone()])) } else { result.clone() }; - let result = if fs.has_auth.clone() { +let result = if fs.has_auth.clone() { v2_rt::concat(result.clone(), Rc::new(vec![t.auth_ctor.clone()])) } else { result.clone() }; - let result = if fs.has_shell.clone() { +let result = if fs.has_shell.clone() { v2_rt::concat(result.clone(), Rc::new(vec![t.shell_ctor.clone()])) } else { result.clone() }; - let result = if fs.has_file.clone() { +let result = if fs.has_file.clone() { v2_rt::concat(result.clone(), Rc::new(vec![t.file_ctor.clone()])) } else { result.clone() }; - result.clone() - } +result.clone() +} } -pub fn emit_unified_transport_dispatch( - transport: &Rc, - op_name: String, - source_indices: &Rc>>, - depth: i64, - target: RenderTarget, - render_rest: impl Fn(String, Rc, i64, Rc>>) -> String + Clone, - render_shell: impl Fn(String, Rc, i64, Rc>>) -> String - + Clone, - render_file: impl Fn(String, i64) -> String + Clone, - render_local: impl Fn(String, i64) -> String + Clone, -) -> String { +pub fn emit_unified_transport_dispatch(transport: &Rc, op_name: String, source_indices: &Rc>>, depth: i64, target: RenderTarget, render_rest: impl Fn(String, Rc, i64, Rc>>) -> String + Clone, render_shell: impl Fn(String, Rc, i64, Rc>>) -> String + Clone, render_file: impl Fn(String, i64) -> String + Clone, render_local: impl Fn(String, i64) -> String + Clone) -> String { if is_rest_transport(transport.clone(), source_indices.clone()) { render_rest(op_name, transport.clone(), depth, source_indices.clone()) } else { @@ -2499,167 +1345,56 @@ pub fn emit_unified_transport_dispatch( } } -pub fn emit_unified_operation_method( - service_name: String, - fallback_transport: Rc, - op_node: &Rc, - target: &RenderTarget, - registry: Rc>>, - env: &Rc, - render_transport_body: impl Fn(Rc, String, Rc>>, i64) -> String - + Clone, -) -> String { +pub fn emit_unified_operation_method(service_name: String, fallback_transport: Rc, op_node: &Rc, target: &RenderTarget, registry: Rc>>, env: &Rc, render_transport_body: impl Fn(Rc, String, Rc>>, i64) -> String + Clone) -> String { { let spec = language_spec(target.clone()); - let si = env.source_indices.clone(); - let op_text = authored_name(env.clone(), op_node.clone()); - let params_str = emit_params_shared(op_node.params.clone(), &target, si.clone()); - let sp = service_self_param(spec.clone()); - let all_params = if (sp.clone().as_str() == "".to_string().as_str()) { +let si = env.source_indices.clone(); +let op_text = authored_name(env.clone(), op_node.clone()); +let params_str = emit_params_shared(op_node.params.clone(), &target, si.clone()); +let sp = service_self_param(spec.clone()); +let all_params = if (sp.clone().as_str() == "".to_string().as_str()) { params_str.clone() } else { if (params_str.clone().as_str() == "".to_string().as_str()) { sp.clone() } else { - v2_rt::concat( - v2_rt::concat(sp.clone(), ", ".to_string()), - params_str.clone(), - ) + v2_rt::concat(v2_rt::concat(sp.clone(), ", ".to_string()), params_str.clone()) } }; - let receiver_str = service_receiver_str(spec.clone(), service_name); - let method_depth = service_method_depth(spec.clone()); - let ret_type = emit_node_type(resolved_type(op_node.clone()), target.clone(), si.clone()); - let ret_str = service_return_str(&spec, ret_type); - let method_name = match (*spec.visibility.clone()).clone() { - VisibilitySpec::CaseVisibility { .. } => emit_export_ident(op_text.clone(), &target), - _ => emit_ident(op_text.clone(), target.clone()), - }; - let eff_transport = effective_operation_transport(op_node.clone(), fallback_transport); - let body = render_transport_body( - eff_transport, - op_text.clone(), - si.clone(), - (method_depth.clone() + 1), - ); - let sig = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - spec.items.clone().async_prefix.clone(), - spec.items.clone().func_keyword.clone(), - ), - " ".to_string(), - ), - receiver_str, - ), - method_name, - ), - "(".to_string(), - ), - all_params, - ), - ")".to_string(), - ), - ret_str, - ); - if spec.block_syntax.clone().significant_whitespace.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(sig, spec.block_syntax.clone().block_open.clone()), - make_indent((method_depth.clone() + 1)), - ), - body, - ) +let receiver_str = service_receiver_str(spec.clone(), service_name); +let method_depth = service_method_depth(spec.clone()); +let ret_type = emit_node_type(resolved_type(op_node.clone()), target.clone(), si.clone()); +let ret_str = service_return_str(&spec, ret_type); +let method_name = match (*spec.visibility.clone()).clone() { + VisibilitySpec::CaseVisibility { .. } => emit_export_ident(op_text.clone(), &target), + _ => emit_ident(op_text.clone(), target.clone()), +}; +let eff_transport = effective_operation_transport(op_node.clone(), fallback_transport); +let body = render_transport_body(eff_transport, op_text.clone(), si.clone(), (method_depth.clone() + 1)); +let sig = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(spec.items.clone().async_prefix.clone(), spec.items.clone().func_keyword.clone()), " ".to_string()), receiver_str), method_name), "(".to_string()), all_params), ")".to_string()), ret_str); +if spec.block_syntax.clone().significant_whitespace.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(sig, spec.block_syntax.clone().block_open.clone()), make_indent((method_depth.clone() + 1))), body) } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(sig, spec.block_syntax.clone().block_open.clone()), - body, - ), - "\n".to_string(), - ), - make_indent(method_depth.clone()), - ), - spec.block_syntax.clone().block_close.clone(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(sig, spec.block_syntax.clone().block_open.clone()), body), "\n".to_string()), make_indent(method_depth.clone())), spec.block_syntax.clone().block_close.clone()) } - } +} } -pub fn emit_unified_service_def( - item: &Rc, - target: &RenderTarget, - registry: Rc>>, - env: &Rc, - render_service_fields: impl Fn(String, Rc, Rc>>, Rc>>) -> String - + Clone, - render_transport_body: impl Fn(Rc, String, Rc>>, i64) -> String - + Clone, -) -> String { +pub fn emit_unified_service_def(item: &Rc, target: &RenderTarget, registry: Rc>>, env: &Rc, render_service_fields: impl Fn(String, Rc, Rc>>, Rc>>) -> String + Clone, render_transport_body: impl Fn(Rc, String, Rc>>, i64) -> String + Clone) -> String { { let spec = language_spec(target.clone()); - let safe_name = sanitize_service_name(authored_name(env.clone(), item.clone())); - let transport = service_fallback_transport(&item); - let op_children = item.children.clone(); - let fields_str = render_service_fields( - safe_name.clone(), - transport.clone(), - op_children.clone(), - env.source_indices.clone(), - ); - let methods = Rc::new({ - let mut __result = Vec::new(); - for op_node in op_children.clone().iter().cloned() { - __result.push(emit_unified_operation_method( - safe_name.clone(), - transport.clone(), - &op_node, - &target, - registry.clone(), - &env, - render_transport_body.clone(), - )); - } - __result - }); - let methods_str = methods.join(&"\n\n".to_string()); - if service_methods_inside_class(spec.clone()) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - spec.items.clone().struct_keyword.clone(), - " ".to_string(), - ), - safe_name.clone(), - ), - ":\n".to_string(), - ), - make_indent(1), - ), - fields_str, - ), - "\n\n".to_string(), - ), - make_indent(1), - ), - methods_str, - ) +let safe_name = sanitize_service_name(authored_name(env.clone(), item.clone())); +let transport = service_fallback_transport(&item); +let op_children = item.children.clone(); +let fields_str = render_service_fields(safe_name.clone(), transport.clone(), op_children.clone(), env.source_indices.clone()); +let methods = Rc::new({ let mut __result = Vec::new(); for op_node in op_children.clone().iter().cloned() { __result.push(emit_unified_operation_method(safe_name.clone(), transport.clone(), &op_node, &target, registry.clone(), &env, render_transport_body.clone())); } __result }); +let methods_str = methods.join(&"\n\n".to_string()); +if service_methods_inside_class(spec.clone()) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(spec.items.clone().struct_keyword.clone(), " ".to_string()), safe_name.clone()), ":\n".to_string()), make_indent(1)), fields_str), "\n\n".to_string()), make_indent(1)), methods_str) } else { v2_rt::concat(v2_rt::concat(fields_str, "\n\n".to_string()), methods_str) } - } +} } pub fn is_type_def_item(item: &Rc) -> bool { @@ -2667,29 +1402,15 @@ pub fn is_type_def_item(item: &Rc) -> bool { } pub fn is_bare_leaf_item(item: &Rc) -> bool { - (((((item.connective.clone() == Connective::NoConnective) && (item.body.clone() == None)) - && ((item.params.clone().len() as i64) == 0)) - && (item.transport.clone() == None)) - && ((item.children.clone().len() as i64) == 0)) + (((((item.connective.clone() == Connective::NoConnective) && (item.body.clone() == None)) && ((item.params.clone().len() as i64) == 0)) && (item.transport.clone() == None)) && ((item.children.clone().len() as i64) == 0)) } -pub fn is_type_alias_item( - item: &Rc, - source_indices: Rc>>, -) -> bool { - (is_bare_leaf_item(&item) - && is_type_alias_return_node(resolved_type(item.clone()), source_indices)) +pub fn is_type_alias_item(item: &Rc, source_indices: Rc>>) -> bool { + (is_bare_leaf_item(&item) && is_type_alias_return_node(resolved_type(item.clone()), source_indices)) } -pub fn is_type_decl_item( - item: &Rc, - source_indices: Rc>>, -) -> bool { - ((is_bare_leaf_item(&item) - && !is_type_alias_return_node(resolved_type(item.clone()), source_indices)) - || (((((item.params.clone().len() as i64) > 0) && (item.body.clone() == None)) - && (item.transport.clone() == None)) - && ((item.children.clone().len() as i64) == 0))) +pub fn is_type_decl_item(item: &Rc, source_indices: Rc>>) -> bool { + ((is_bare_leaf_item(&item) && !is_type_alias_return_node(resolved_type(item.clone()), source_indices)) || (((((item.params.clone().len() as i64) > 0) && (item.body.clone() == None)) && (item.transport.clone() == None)) && ((item.children.clone().len() as i64) == 0))) } pub fn is_function_item(item: &Rc) -> bool { @@ -2705,10 +1426,7 @@ pub fn is_service_def_item(item: &Rc) -> bool { } pub fn is_resource_def_item(item: &Rc) -> bool { - (((item.transport.clone() == None) && ((item.children.clone().len() as i64) > 0)) - || ((((item.transport.clone() == None) && ((item.children.clone().len() as i64) == 0)) - && ((item.properties.clone().len() as i64) > 0)) - && (item.body.clone() == None))) + (((item.transport.clone() == None) && ((item.children.clone().len() as i64) > 0)) || ((((item.transport.clone() == None) && ((item.children.clone().len() as i64) == 0)) && ((item.properties.clone().len() as i64) > 0)) && (item.body.clone() == None))) } #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] @@ -2724,30 +1442,30 @@ pub enum ExprCategory { pub fn classify_expr(texpr: Rc) -> ExprCategory { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprLiteral { .. } => ExprCategory::ExprCatLeaf, - ExprData::ExprError { .. } => ExprCategory::ExprCatLeaf, - ExprData::ExprVar { .. } => ExprCategory::ExprCatLeaf, - ExprData::ExprFieldAccess { .. } => ExprCategory::ExprCatCompound, - ExprData::ExprCall { .. } => ExprCategory::ExprCatCompound, - ExprData::ExprMethodCall { .. } => ExprCategory::ExprCatCompound, - ExprData::ExprRecordLit { .. } => ExprCategory::ExprCatCompound, - ExprData::ExprListLit => ExprCategory::ExprCatCompound, - ExprData::ExprBinOp { .. } => ExprCategory::ExprCatCompound, - ExprData::ExprUnaryOp { .. } => ExprCategory::ExprCatCompound, - ExprData::ExprLambda => ExprCategory::ExprCatCompound, - ExprData::ExprStringInterp => ExprCategory::ExprCatCompound, - ExprData::ExprCast => ExprCategory::ExprCatCompound, - ExprData::ExprIndex => ExprCategory::ExprCatCompound, - ExprData::ExprSlice => ExprCategory::ExprCatCompound, - ExprData::ExprMatch => ExprCategory::ExprCatControlFlow, - ExprData::ExprIf => ExprCategory::ExprCatControlFlow, - ExprData::ExprForEach => ExprCategory::ExprCatControlFlow, - ExprData::ExprBlock => ExprCategory::ExprCatControlFlow, - ExprData::ExprLet => ExprCategory::ExprCatBinding, - ExprData::ExprReturn => ExprCategory::ExprCatControlFlow, - ExprData::NoExprData => ExprCategory::ExprCatNone, - _ => ExprCategory::ExprCatNone, - } + ExprData::ExprLiteral { .. } => ExprCategory::ExprCatLeaf, + ExprData::ExprError { .. } => ExprCategory::ExprCatLeaf, + ExprData::ExprVar { .. } => ExprCategory::ExprCatLeaf, + ExprData::ExprFieldAccess { .. } => ExprCategory::ExprCatCompound, + ExprData::ExprCall { .. } => ExprCategory::ExprCatCompound, + ExprData::ExprMethodCall { .. } => ExprCategory::ExprCatCompound, + ExprData::ExprRecordLit { .. } => ExprCategory::ExprCatCompound, + ExprData::ExprListLit => ExprCategory::ExprCatCompound, + ExprData::ExprBinOp { .. } => ExprCategory::ExprCatCompound, + ExprData::ExprUnaryOp { .. } => ExprCategory::ExprCatCompound, + ExprData::ExprLambda => ExprCategory::ExprCatCompound, + ExprData::ExprStringInterp => ExprCategory::ExprCatCompound, + ExprData::ExprCast => ExprCategory::ExprCatCompound, + ExprData::ExprIndex => ExprCategory::ExprCatCompound, + ExprData::ExprSlice => ExprCategory::ExprCatCompound, + ExprData::ExprMatch => ExprCategory::ExprCatControlFlow, + ExprData::ExprIf => ExprCategory::ExprCatControlFlow, + ExprData::ExprForEach => ExprCategory::ExprCatControlFlow, + ExprData::ExprBlock => ExprCategory::ExprCatControlFlow, + ExprData::ExprLet => ExprCategory::ExprCatBinding, + ExprData::ExprReturn => ExprCategory::ExprCatControlFlow, + ExprData::NoExprData => ExprCategory::ExprCatNone, + _ => ExprCategory::ExprCatNone, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -2766,26 +1484,25 @@ pub enum FuncBodyShape { }, } -pub fn classify_func_body( - body: &Rc, - source_indices: Rc>>, -) -> Rc { +pub fn classify_func_body(body: &Rc, source_indices: Rc>>) -> Rc { match (*body.expr_data.clone()).clone() { - ExprData::ExprLet => { - let n = let_binding_name_at(body.clone(), source_indices); - let v = let_value(body.clone()); - let rest = let_body(body.clone()); - Rc::new(FuncBodyShape::FuncBodyLet { - name: n, - value: v, - rest: rest, - }) - } - ExprData::ExprBlock => Rc::new(FuncBodyShape::FuncBodyBlock { - stmts: body.children.clone(), - }), - _ => Rc::new(FuncBodyShape::FuncBodyExpr { expr: body.clone() }), - } + ExprData::ExprLet => { + let n = let_binding_name_at(body.clone(), source_indices); +let v = let_value(body.clone()); +let rest = let_body(body.clone()); +Rc::new(FuncBodyShape::FuncBodyLet { + name: n, + value: v, + rest: rest, +}) +}, + ExprData::ExprBlock => Rc::new(FuncBodyShape::FuncBodyBlock { + stmts: body.children.clone(), +}), + _ => Rc::new(FuncBodyShape::FuncBodyExpr { + expr: body.clone(), +}), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -2817,1258 +1534,446 @@ pub enum TcoExprShape { }, } -pub fn classify_tco_expr( - texpr: &Rc, - source_indices: Rc>>, -) -> Rc { +pub fn classify_tco_expr(texpr: &Rc, source_indices: Rc>>) -> Rc { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => Rc::new(TcoExprShape::TcoCall { - func: expr_call_func_at(texpr.clone(), source_indices), - args: texpr.children.clone(), - }), - ExprData::ExprIf => { - let c = if_condition(texpr.clone()); - let t = if_then_branch(texpr.clone()); - let e = if_else_branch(texpr.clone()); - Rc::new(TcoExprShape::TcoIf { - condition: c, - then_branch: t, - else_branch: e, - }) - } - ExprData::ExprMatch => { - let scrut = match_scrutinee(texpr.clone()); - let arm_list = match_arm_nodes(texpr.clone()); - Rc::new(TcoExprShape::TcoMatch { - scrutinee: scrut, - arms: arm_list, - }) - } - ExprData::ExprLet => { - let n = let_binding_name_at(texpr.clone(), source_indices); - let v = let_value(texpr.clone()); - let bd = let_body(texpr.clone()); - Rc::new(TcoExprShape::TcoLet { - name: n, - value: v, - body: bd, - }) - } - ExprData::ExprBlock => Rc::new(TcoExprShape::TcoBlock { - stmts: texpr.children.clone(), - }), - _ => Rc::new(TcoExprShape::TcoOther { - expr: texpr.clone(), - }), - } + ExprData::ExprCall { .. } => Rc::new(TcoExprShape::TcoCall { + func: expr_call_func_at(texpr.clone(), source_indices), + args: texpr.children.clone(), +}), + ExprData::ExprIf => { + let c = if_condition(texpr.clone()); +let t = if_then_branch(texpr.clone()); +let e = if_else_branch(texpr.clone()); +Rc::new(TcoExprShape::TcoIf { + condition: c, + then_branch: t, + else_branch: e, +}) +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(texpr.clone()); +let arm_list = match_arm_nodes(texpr.clone()); +Rc::new(TcoExprShape::TcoMatch { + scrutinee: scrut, + arms: arm_list, +}) +}, + ExprData::ExprLet => { + let n = let_binding_name_at(texpr.clone(), source_indices); +let v = let_value(texpr.clone()); +let bd = let_body(texpr.clone()); +Rc::new(TcoExprShape::TcoLet { + name: n, + value: v, + body: bd, +}) +}, + ExprData::ExprBlock => Rc::new(TcoExprShape::TcoBlock { + stmts: texpr.children.clone(), +}), + _ => Rc::new(TcoExprShape::TcoOther { + expr: texpr.clone(), +}), +} } pub fn block_stmts_init(stmts: &Rc>>) -> Rc>> { if ((stmts.clone().len() as i64) <= 1) { Rc::new(vec![]) } else { - Rc::new( - stmts - .clone() - .iter() - .cloned() - .take(((stmts.clone().len() as i64) - 1) as usize) - .collect::>(), - ) + Rc::new(stmts.clone().iter().cloned().take(((stmts.clone().len() as i64) - 1) as usize).collect::>()) } } -pub fn is_tco_eligible( - name: &String, - body: &Rc, - registry: Rc>>, - source_indices: &Rc>>, -) -> bool { +pub fn is_tco_eligible(name: &String, body: &Rc, registry: Rc>>, source_indices: &Rc>>) -> bool { match lookup_item(registry, name.clone()) { - Some(info) => { - (info.is_self_recursive.clone() && (info.has_non_tail_self_call.clone() == false)) - } - None => { - (expr_has_self_call(&body, &name, &source_indices) - && (expr_has_non_tail_self_call(&body, &name, true, &source_indices) == false)) - } - } + Some(info) => (info.is_self_recursive.clone() && (info.has_non_tail_self_call.clone() == false)), + None => (expr_has_self_call(&body, &name, &source_indices) && (expr_has_non_tail_self_call(&body, &name, true, &source_indices) == false)), +} } -pub fn is_self_recursive( - name: &String, - body: Rc, - registry: Rc>>, - source_indices: Rc>>, -) -> bool { +pub fn is_self_recursive(name: &String, body: Rc, registry: Rc>>, source_indices: Rc>>) -> bool { match lookup_item(registry, name.clone()) { - Some(info) => info.is_self_recursive.clone(), - None => expr_has_self_call(&body, &name, &source_indices), - } + Some(info) => info.is_self_recursive.clone(), + None => expr_has_self_call(&body, &name, &source_indices), +} } -pub fn tco_reassign_core( - ordered_args: Rc>, - param_names: Rc>, - temp_var_prefix: String, - temp_decl_prefix: String, - temp_assign_op: String, - stmt_terminator: String, - continue_str: String, - line_prefix: &String, -) -> Rc> { +pub fn tco_reassign_core(ordered_args: Rc>, param_names: Rc>, temp_var_prefix: String, temp_decl_prefix: String, temp_assign_op: String, stmt_terminator: String, continue_str: String, line_prefix: &String) -> Rc> { { - let temp_lets = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - ordered_args - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(line_prefix.clone(), temp_decl_prefix.clone()), - temp_var_prefix.clone(), - ), - (pair.0.clone()).to_string(), - ), - temp_assign_op.clone(), - ), - pair.1.clone(), - ), - stmt_terminator.clone(), - )); - } - __result - }); - let assigns = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - param_names - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(line_prefix.clone(), pair.1.clone()), - " = ".to_string(), - ), - temp_var_prefix.clone(), - ), - (pair.0.clone()).to_string(), - ), - stmt_terminator.clone(), - )); - } - __result - }); - v2_rt::concat( - v2_rt::concat(temp_lets, assigns), - Rc::new(vec![v2_rt::concat(line_prefix.clone(), continue_str)]), - ) - } + let temp_lets = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(ordered_args.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(line_prefix.clone(), temp_decl_prefix.clone()), temp_var_prefix.clone()), (pair.0.clone()).to_string()), temp_assign_op.clone()), pair.1.clone()), stmt_terminator.clone())); } __result }); +let assigns = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(param_names.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(line_prefix.clone(), pair.1.clone()), " = ".to_string()), temp_var_prefix.clone()), (pair.0.clone()).to_string()), stmt_terminator.clone())); } __result }); +v2_rt::concat(v2_rt::concat(temp_lets, assigns), Rc::new(vec![v2_rt::concat(line_prefix.clone(), continue_str)])) +} } -pub fn emit_shared_tco_expr( - mut frame: Rc, - mut fn_name: String, - mut emit_self_call_reassign: impl Fn(Rc) -> String + Clone, - mut emit_non_self_call: impl Fn(Rc) -> String + Clone, - mut emit_if: impl Fn(Rc) -> String + Clone, - mut emit_match: impl Fn(Rc) -> String + Clone, - mut emit_let: impl Fn(Rc) -> String + Clone, - mut emit_block: impl Fn(Rc) -> String + Clone, - mut emit_default_return: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_shared_tco_expr(mut frame: Rc, mut fn_name: String, mut emit_self_call_reassign: impl Fn(Rc) -> String + Clone, mut emit_non_self_call: impl Fn(Rc) -> String + Clone, mut emit_if: impl Fn(Rc) -> String + Clone, mut emit_match: impl Fn(Rc) -> String + Clone, mut emit_let: impl Fn(Rc) -> String + Clone, mut emit_block: impl Fn(Rc) -> String + Clone, mut emit_default_return: impl Fn(Rc) -> String + Clone) -> String { loop { let si = frame.scope.clone().type_env.clone().source_indices.clone(); - match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - if (expr_call_func_at(frame.expr.clone(), si).as_str() == fn_name.as_str()) { - break emit_self_call_reassign(Rc::new(TcoReassignInput { - args: frame.expr.clone().children.clone(), - scope: frame.scope.clone(), - depth: frame.depth.clone(), - })); - } else { - break emit_non_self_call(frame.clone()); - } - } - ExprData::ExprReturn => { - let inner = return_value(frame.expr.clone()); - { - let __tco_0 = Rc::new(TcoFrame { - expr: inner, - scope: frame.scope.clone(), - depth: frame.depth.clone(), - }); - frame = __tco_0; - continue; - } - } - ExprData::ExprIf => { - break emit_if(frame.clone()); - } - ExprData::ExprMatch => { - break emit_match(frame.clone()); - } - ExprData::ExprLet => { - break emit_let(frame.clone()); - } - ExprData::ExprBlock => { - break emit_block(frame.clone()); - } - _ => { - break emit_default_return(frame.clone()); - } - } - } +match (*frame.expr.clone().expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { if (expr_call_func_at(frame.expr.clone(), si).as_str() == fn_name.as_str()) { + break emit_self_call_reassign(Rc::new(TcoReassignInput { + args: frame.expr.clone().children.clone(), + scope: frame.scope.clone(), + depth: frame.depth.clone(), +})); +} else { + break emit_non_self_call(frame.clone()); +} }, + ExprData::ExprReturn => { let inner = return_value(frame.expr.clone()); +{ + let __tco_0 = Rc::new(TcoFrame { + expr: inner, + scope: frame.scope.clone(), + depth: frame.depth.clone(), +}); +frame = __tco_0; +continue; +} }, + ExprData::ExprIf => { break emit_if(frame.clone()); }, + ExprData::ExprMatch => { break emit_match(frame.clone()); }, + ExprData::ExprLet => { break emit_let(frame.clone()); }, + ExprData::ExprBlock => { break emit_block(frame.clone()); }, + _ => { break emit_default_return(frame.clone()); }, +} +} } pub fn shared_tco_body(inner: String, depth: i64, spec: &Rc) -> String { { let syntax = spec.block_syntax.clone(); - let tco = spec.tco.clone(); - if syntax.significant_whitespace.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(tco.loop_keyword.clone(), syntax.block_open.clone()), - make_indent((depth + 1)), - ), - inner, - ) +let tco = spec.tco.clone(); +if syntax.significant_whitespace.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(tco.loop_keyword.clone(), syntax.block_open.clone()), make_indent((depth + 1))), inner) } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(tco.loop_keyword.clone(), syntax.block_open.clone()), - make_indent((depth + 1)), - ), - inner, - ), - "\n".to_string(), - ), - syntax.block_close.clone(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(tco.loop_keyword.clone(), syntax.block_open.clone()), make_indent((depth + 1))), inner), "\n".to_string()), syntax.block_close.clone()) } - } +} } -pub fn shared_tco_default_return( - frame: &Rc, - spec: Rc, - recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, -) -> String { +pub fn shared_tco_default_return(frame: &Rc, spec: Rc, recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone) -> String { { let val_str = recurse_expr(frame.expr.clone(), frame.scope.clone(), frame.depth.clone()); - v2_rt::concat( - v2_rt::concat(spec.tco.clone().break_return.clone(), " ".to_string()), - val_str, - ) - } +v2_rt::concat(v2_rt::concat(spec.tco.clone().break_return.clone(), " ".to_string()), val_str) +} } -pub fn shared_tco_non_self_call( - frame: &Rc, - target: RenderTarget, - spec: Rc, - recurse_call: impl Fn(String, Rc>>, Rc, i64) -> String + Clone, -) -> String { +pub fn shared_tco_non_self_call(frame: &Rc, target: RenderTarget, spec: Rc, recurse_call: impl Fn(String, Rc>>, Rc, i64) -> String + Clone) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let f = expr_call_func_at( - frame.expr.clone(), - frame.scope.clone().type_env.clone().source_indices.clone(), - ); - let call_str = recurse_call( - f, - frame.expr.clone().children.clone(), - frame.scope.clone(), - frame.depth.clone(), - ); - v2_rt::concat( - v2_rt::concat(spec.tco.clone().break_return.clone(), " ".to_string()), - call_str, - ) - } - _ => emit_error_expr( - "shared_tco_non_self_call expected ExprCall".to_string(), - target, - ), - } + ExprData::ExprCall { .. } => { + let f = expr_call_func_at(frame.expr.clone(), frame.scope.clone().type_env.clone().source_indices.clone()); +let call_str = recurse_call(f, frame.expr.clone().children.clone(), frame.scope.clone(), frame.depth.clone()); +v2_rt::concat(v2_rt::concat(spec.tco.clone().break_return.clone(), " ".to_string()), call_str) +}, + _ => emit_error_expr("shared_tco_non_self_call expected ExprCall".to_string(), target), +} } -pub fn shared_tco_if( - frame: &Rc, - fn_name: String, - params: Rc>>, - target: RenderTarget, - spec: Rc, - recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, - recurse_tco: impl Fn(Rc, Rc, i64) -> String + Clone, -) -> String { +pub fn shared_tco_if(frame: &Rc, fn_name: String, params: Rc>>, target: RenderTarget, spec: Rc, recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, recurse_tco: impl Fn(Rc, Rc, i64) -> String + Clone) -> String { { let syntax = spec.block_syntax.clone(); - match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprIf => { - let c = if_condition(frame.expr.clone()); - let t = if_then_branch(frame.expr.clone()); - let e = if_else_branch(frame.expr.clone()); - let cond_str = recurse_expr(c, frame.scope.clone(), frame.depth.clone()); - let then_str = recurse_tco(t, frame.scope.clone(), (frame.depth.clone() + 1)); - let else_prefix = if syntax.significant_whitespace.clone() { - make_indent(frame.depth.clone()) +match (*frame.expr.clone().expr_data.clone()).clone() { + ExprData::ExprIf => { + let c = if_condition(frame.expr.clone()); +let t = if_then_branch(frame.expr.clone()); +let e = if_else_branch(frame.expr.clone()); +let cond_str = recurse_expr(c, frame.scope.clone(), frame.depth.clone()); +let then_str = recurse_tco(t, frame.scope.clone(), (frame.depth.clone() + 1)); +let else_prefix = if syntax.significant_whitespace.clone() { + make_indent(frame.depth.clone()) + } else { + "".to_string() + }; +match e { + Some(eb) => { + let else_str = recurse_tco(eb.clone(), frame.scope.clone(), (frame.depth.clone() + 1)); +if syntax.significant_whitespace.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), syntax.block_open.clone()), make_indent((frame.depth.clone() + 1))), then_str), "\n".to_string()), else_prefix), syntax.else_clause.clone()), make_indent((frame.depth.clone() + 1))), else_str) } else { - "".to_string() - }; - match e { - Some(eb) => { - let else_str = - recurse_tco(eb.clone(), frame.scope.clone(), (frame.depth.clone() + 1)); - if syntax.significant_whitespace.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "if ".to_string(), - cond_str, - ), - syntax.block_open.clone(), - ), - make_indent((frame.depth.clone() + 1)), - ), - then_str, - ), - "\n".to_string(), - ), - else_prefix, - ), - syntax.else_clause.clone(), - ), - make_indent((frame.depth.clone() + 1)), - ), - else_str, - ) - } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "if ".to_string(), - cond_str, - ), - syntax.block_open.clone(), - ), - make_indent((frame.depth.clone() + 1)), - ), - then_str, - ), - "\n".to_string(), - ), - syntax.else_clause.clone(), - ), - make_indent((frame.depth.clone() + 1)), - ), - else_str, - ), - "\n".to_string(), - ), - syntax.block_close.clone(), - ) - } - } - None => { - if syntax.significant_whitespace.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("if ".to_string(), cond_str), - syntax.block_open.clone(), - ), - make_indent((frame.depth.clone() + 1)), - ), - then_str, - ) - } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("if ".to_string(), cond_str), - syntax.block_open.clone(), - ), - make_indent((frame.depth.clone() + 1)), - ), - then_str, - ), - "\n".to_string(), - ), - syntax.block_close.clone(), - ) - } - } + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), syntax.block_open.clone()), make_indent((frame.depth.clone() + 1))), then_str), "\n".to_string()), syntax.else_clause.clone()), make_indent((frame.depth.clone() + 1))), else_str), "\n".to_string()), syntax.block_close.clone()) } - } - _ => emit_error_expr("shared_tco_if expected ExprIf".to_string(), target), - } - } +}, + None => if syntax.significant_whitespace.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), syntax.block_open.clone()), make_indent((frame.depth.clone() + 1))), then_str) + } else { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), syntax.block_open.clone()), make_indent((frame.depth.clone() + 1))), then_str), "\n".to_string()), syntax.block_close.clone()) + }, +} +}, + _ => emit_error_expr("shared_tco_if expected ExprIf".to_string(), target), +} +} } -pub fn shared_tco_let( - frame: &Rc, - fn_name: String, - params: Rc>>, - target: RenderTarget, - recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, - recurse_tco: impl Fn(Rc, Rc, i64) -> String + Clone, -) -> String { +pub fn shared_tco_let(frame: &Rc, fn_name: String, params: Rc>>, target: RenderTarget, recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, recurse_tco: impl Fn(Rc, Rc, i64) -> String + Clone) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprLet => { - let n = let_binding_name_at( - frame.expr.clone(), - frame.scope.clone().type_env.clone().source_indices.clone(), - ); - let v = let_value(frame.expr.clone()); - let bd = let_body(frame.expr.clone()); - let val_str = recurse_expr(v.clone(), frame.scope.clone(), frame.depth.clone()); - let let_line = emit_let_binding(n.clone(), val_str, &target); - let next_scope = extend_scope( - &frame.scope.clone(), - &n, - resolved_type(v.clone()), - Rc::new(SubValueRelation::SubValueUnknown), - ); - match bd { - Some(b) => v2_rt::concat( - v2_rt::concat(let_line, "\n".to_string()), - recurse_tco(b.clone(), next_scope, frame.depth.clone()), - ), - None => let_line, - } - } - _ => emit_error_expr("shared_tco_let expected ExprLet".to_string(), target), - } + ExprData::ExprLet => { + let n = let_binding_name_at(frame.expr.clone(), frame.scope.clone().type_env.clone().source_indices.clone()); +let v = let_value(frame.expr.clone()); +let bd = let_body(frame.expr.clone()); +let val_str = recurse_expr(v.clone(), frame.scope.clone(), frame.depth.clone()); +let let_line = emit_let_binding(n.clone(), val_str, &target); +let next_scope = extend_scope(&frame.scope.clone(), &n, resolved_type(v.clone()), Rc::new(SubValueRelation::SubValueUnknown)); +match bd { + Some(b) => v2_rt::concat(v2_rt::concat(let_line, "\n".to_string()), recurse_tco(b.clone(), next_scope, frame.depth.clone())), + None => let_line, +} +}, + _ => emit_error_expr("shared_tco_let expected ExprLet".to_string(), target), +} } -pub fn shared_tco_block( - frame: &Rc, - fn_name: String, - params: Rc>>, - target: RenderTarget, - spec: Rc, - emit_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone, - recurse_tco: impl Fn(Rc, Rc, i64) -> String + Clone, -) -> String { +pub fn shared_tco_block(frame: &Rc, fn_name: String, params: Rc>>, target: RenderTarget, spec: Rc, emit_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone, recurse_tco: impl Fn(Rc, Rc, i64) -> String + Clone) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprBlock => { - let ss = frame.expr.clone().children.clone(); - if ((ss.clone().len() as i64) == 0) { - spec.tco.clone().break_return.clone() - } else { - { - let init_state = - emit_init_stmts(ss.clone(), frame.scope.clone(), frame.depth.clone()); - let last_str = match ss.clone().last().cloned() { - Some(last_expr) => recurse_tco( - last_expr.clone(), - init_state.scope.clone(), - frame.depth.clone(), - ), - None => spec.tco.clone().break_return.clone(), - }; - if ((init_state.text.clone().len() as i64) == 0) { - last_str - } else { - v2_rt::concat( - v2_rt::concat( - init_state.text.clone().join(&"\n".to_string()), - "\n".to_string(), - ), - last_str, - ) - } + ExprData::ExprBlock => { + let ss = frame.expr.clone().children.clone(); +if ((ss.clone().len() as i64) == 0) { + spec.tco.clone().break_return.clone() + } else { + { + let init_state = emit_init_stmts(ss.clone(), frame.scope.clone(), frame.depth.clone()); +let last_str = match ss.clone().last().cloned() { + Some(last_expr) => recurse_tco(last_expr.clone(), init_state.scope.clone(), frame.depth.clone()), + None => spec.tco.clone().break_return.clone(), +}; +if ((init_state.text.clone().len() as i64) == 0) { + last_str + } else { + v2_rt::concat(v2_rt::concat(init_state.text.clone().join(&"\n".to_string()), "\n".to_string()), last_str) } - } +} } - _ => emit_error_expr("shared_tco_block expected ExprBlock".to_string(), target), - } +}, + _ => emit_error_expr("shared_tco_block expected ExprBlock".to_string(), target), +} } -pub fn shared_tco_reassign( - ordered_args: Rc>, - param_names: Rc>, - spec: &Rc, -) -> String { +pub fn shared_tco_reassign(ordered_args: Rc>, param_names: Rc>, spec: &Rc) -> String { { - let all_lines = tco_reassign_core( - ordered_args, - param_names, - spec.tco.clone().temp_var_prefix.clone(), - spec.tco.clone().temp_decl_prefix.clone(), - spec.tco.clone().temp_assign_op.clone(), - spec.block_syntax.clone().stmt_terminator.clone(), - spec.tco.clone().continue_str.clone(), - &"".to_string(), - ); - all_lines.join(&"\n".to_string()) - } + let all_lines = tco_reassign_core(ordered_args, param_names, spec.tco.clone().temp_var_prefix.clone(), spec.tco.clone().temp_decl_prefix.clone(), spec.tco.clone().temp_assign_op.clone(), spec.block_syntax.clone().stmt_terminator.clone(), spec.tco.clone().continue_str.clone(), &"".to_string()); +all_lines.join(&"\n".to_string()) +} +} + +pub fn unified_tco_recurse(expr: Rc, scope: Rc, depth: i64, fn_name: String, params: Rc>>, target: RenderTarget, registry: Rc>>, recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, render_match: impl Fn(Rc) -> String + Clone, render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone) -> String { + emit_unified_tco_expr(&Rc::new(TcoFrame { + expr: expr, + scope: scope, + depth: depth, +}), &fn_name, params, &target, registry, recurse_expr, render_match, render_init_stmts) } -pub fn unified_tco_recurse( - expr: Rc, - scope: Rc, - depth: i64, - fn_name: String, - params: Rc>>, - target: RenderTarget, - registry: Rc>>, - recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, - render_match: impl Fn(Rc) -> String + Clone, - render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone, -) -> String { - emit_unified_tco_expr( - &Rc::new(TcoFrame { - expr: expr, - scope: scope, - depth: depth, - }), - &fn_name, - params, - &target, - registry, - recurse_expr, - render_match, - render_init_stmts, - ) -} - -pub fn emit_unified_tco_expr( - frame: &Rc, - fn_name: &String, - params: Rc>>, - target: &RenderTarget, - registry: Rc>>, - recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, - render_match: impl Fn(Rc) -> String + Clone, - render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone, -) -> String { +pub fn emit_unified_tco_expr(frame: &Rc, fn_name: &String, params: Rc>>, target: &RenderTarget, registry: Rc>>, recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, render_match: impl Fn(Rc) -> String + Clone, render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone) -> String { { let spec = language_spec(target.clone()); - emit_shared_tco_expr( - frame.clone(), - fn_name.clone(), - |input| { - emit_typed_tco_reassign_shared( - input.args.clone(), - params.clone(), - &target, - |child| recurse_expr(child.clone(), input.scope.clone(), input.depth.clone()), - input.scope.clone().type_env.clone().source_indices.clone(), - ) - }, - |frame| { - shared_tco_non_self_call( - &frame, - target.clone(), - spec.clone(), - |f, args, scope, depth| { - emit_typed_call_unified( - &f, - args.clone(), - &target, - registry.clone(), - scope.clone(), - |n| recurse_expr(n.clone(), scope.clone(), depth.clone()), - ) - }, - ) - }, - |frame| { - shared_tco_if( - &frame, - fn_name.clone(), - params.clone(), - target.clone(), - spec.clone(), - recurse_expr.clone(), - |expr, scope, depth| { - unified_tco_recurse( - expr.clone(), - scope.clone(), - depth.clone(), - fn_name.clone(), - params.clone(), - target.clone(), - registry.clone(), - recurse_expr.clone(), - render_match.clone(), - render_init_stmts.clone(), - ) - }, - ) - }, - render_match.clone(), - |frame| { - shared_tco_let( - &frame, - fn_name.clone(), - params.clone(), - target.clone(), - recurse_expr.clone(), - |expr, scope, depth| { - unified_tco_recurse( - expr.clone(), - scope.clone(), - depth.clone(), - fn_name.clone(), - params.clone(), - target.clone(), - registry.clone(), - recurse_expr.clone(), - render_match.clone(), - render_init_stmts.clone(), - ) - }, - ) - }, - |frame| { - shared_tco_block( - &frame, - fn_name.clone(), - params.clone(), - target.clone(), - spec.clone(), - render_init_stmts.clone(), - |expr, scope, depth| { - unified_tco_recurse( - expr.clone(), - scope.clone(), - depth.clone(), - fn_name.clone(), - params.clone(), - target.clone(), - registry.clone(), - recurse_expr.clone(), - render_match.clone(), - render_init_stmts.clone(), - ) - }, - ) - }, - |frame| shared_tco_default_return(&frame, spec.clone(), recurse_expr.clone()), - ) - } +emit_shared_tco_expr(frame.clone(), fn_name.clone(), |input| emit_typed_tco_reassign_shared(input.args.clone(), params.clone(), &target, |child| recurse_expr(child.clone(), input.scope.clone(), input.depth.clone()), input.scope.clone().type_env.clone().source_indices.clone()), |frame| shared_tco_non_self_call(&frame, target.clone(), spec.clone(), |f, args, scope, depth| emit_typed_call_unified(&f, args.clone(), &target, registry.clone(), scope.clone(), |n| recurse_expr(n.clone(), scope.clone(), depth.clone()))), |frame| shared_tco_if(&frame, fn_name.clone(), params.clone(), target.clone(), spec.clone(), recurse_expr.clone(), |expr, scope, depth| unified_tco_recurse(expr.clone(), scope.clone(), depth.clone(), fn_name.clone(), params.clone(), target.clone(), registry.clone(), recurse_expr.clone(), render_match.clone(), render_init_stmts.clone())), render_match.clone(), |frame| shared_tco_let(&frame, fn_name.clone(), params.clone(), target.clone(), recurse_expr.clone(), |expr, scope, depth| unified_tco_recurse(expr.clone(), scope.clone(), depth.clone(), fn_name.clone(), params.clone(), target.clone(), registry.clone(), recurse_expr.clone(), render_match.clone(), render_init_stmts.clone())), |frame| shared_tco_block(&frame, fn_name.clone(), params.clone(), target.clone(), spec.clone(), render_init_stmts.clone(), |expr, scope, depth| unified_tco_recurse(expr.clone(), scope.clone(), depth.clone(), fn_name.clone(), params.clone(), target.clone(), registry.clone(), recurse_expr.clone(), render_match.clone(), render_init_stmts.clone())), |frame| shared_tco_default_return(&frame, spec.clone(), recurse_expr.clone())) +} } -pub fn emit_unified_tco_body( - texpr: Rc, - fn_name: String, - params: Rc>>, - target: &RenderTarget, - registry: Rc>>, - scope: Rc, - depth: i64, - recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, - render_match: impl Fn(Rc) -> String + Clone, - render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone, -) -> String { +pub fn emit_unified_tco_body(texpr: Rc, fn_name: String, params: Rc>>, target: &RenderTarget, registry: Rc>>, scope: Rc, depth: i64, recurse_expr: impl Fn(Rc, Rc, i64) -> String + Clone, render_match: impl Fn(Rc) -> String + Clone, render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone) -> String { { let spec = language_spec(target.clone()); - let inner = emit_unified_tco_expr( - &Rc::new(TcoFrame { - expr: texpr, - scope: scope, - depth: (depth.clone() + 1), - }), - &fn_name, - params, - &target, - registry, - recurse_expr, - render_match, - render_init_stmts, - ); - shared_tco_body(inner, depth.clone(), &spec) - } +let inner = emit_unified_tco_expr(&Rc::new(TcoFrame { + expr: texpr, + scope: scope, + depth: (depth.clone() + 1), +}), &fn_name, params, &target, registry, recurse_expr, render_match, render_init_stmts); +shared_tco_body(inner, depth.clone(), &spec) +} } -pub fn emit_unified_init_block_stmts( - remaining: Rc>>, - text: Rc>, - scope: Rc, - depth: i64, - target: &RenderTarget, - registry: Rc>>, - render_pattern: impl Fn(Rc) -> String + Clone, -) -> Rc { +pub fn emit_unified_init_block_stmts(remaining: Rc>>, text: Rc>, scope: Rc, depth: i64, target: &RenderTarget, registry: Rc>>, render_pattern: impl Fn(Rc) -> String + Clone) -> Rc { { - let prepend = if language_spec(target.clone()) - .block_syntax - .clone() - .significant_whitespace - .clone() - { + let prepend = if language_spec(target.clone()).block_syntax.clone().significant_whitespace.clone() { false } else { true }; - emit_init_block_stmts_shared(remaining, text, scope, depth, prepend, |stmt, sc, d| { - emit_unified_typed_expr( - stmt.clone(), - &target, - registry.clone(), - &sc, - d.clone(), - 1024, - render_pattern.clone(), - ) - }) - } +emit_init_block_stmts_shared(remaining, text, scope, depth, prepend, |stmt, sc, d| emit_unified_typed_expr(stmt.clone(), &target, registry.clone(), &sc, d.clone(), 1024, render_pattern.clone())) +} } -pub fn emit_unified_tco_match( - frame: &Rc, - fn_name: String, - params: Rc>>, - target: &RenderTarget, - registry: &Rc>>, - render_pattern: impl Fn(Rc) -> String + Clone, - render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone, -) -> String { +pub fn emit_unified_tco_match(frame: &Rc, fn_name: String, params: Rc>>, target: &RenderTarget, registry: &Rc>>, render_pattern: impl Fn(Rc) -> String + Clone, render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprMatch => { - let s = match_scrutinee(frame.expr.clone()); - let arm_list = match_arm_nodes(frame.expr.clone()); - let scrut_str = emit_unified_typed_expr( - s, - &target, - registry.clone(), - &frame.scope.clone(), - frame.depth.clone(), - 1024, - render_pattern.clone(), - ); - let arm_strs = Rc::new({ - let mut __result = Vec::new(); - for arm in arm_list.iter().cloned() { - __result.push(emit_unified_tco_match_arm( - &arm, - &fn_name, - ¶ms, - &target, - ®istry, - &frame.scope.clone(), - frame.depth.clone(), - render_pattern.clone(), - render_init_stmts.clone(), - )); - } - __result - }); - let arms_str = arm_strs.join(&"\n".to_string()); - let bs = language_spec(target.clone()).block_syntax.clone(); - if (bs.block_close.clone().as_str() == "".to_string().as_str()) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(bs.match_keyword.clone(), scrut_str), - bs.block_open.clone(), - ), - arms_str, - ) - } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(bs.match_keyword.clone(), scrut_str), - bs.block_open.clone(), - ), - arms_str, - ), - "\n".to_string(), - ), - bs.block_close.clone(), - ) - } + ExprData::ExprMatch => { + let s = match_scrutinee(frame.expr.clone()); +let arm_list = match_arm_nodes(frame.expr.clone()); +let scrut_str = emit_unified_typed_expr(s, &target, registry.clone(), &frame.scope.clone(), frame.depth.clone(), 1024, render_pattern.clone()); +let arm_strs = Rc::new({ let mut __result = Vec::new(); for arm in arm_list.iter().cloned() { __result.push(emit_unified_tco_match_arm(&arm, &fn_name, ¶ms, &target, ®istry, &frame.scope.clone(), frame.depth.clone(), render_pattern.clone(), render_init_stmts.clone())); } __result }); +let arms_str = arm_strs.join(&"\n".to_string()); +let bs = language_spec(target.clone()).block_syntax.clone(); +if (bs.block_close.clone().as_str() == "".to_string().as_str()) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(bs.match_keyword.clone(), scrut_str), bs.block_open.clone()), arms_str) + } else { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(bs.match_keyword.clone(), scrut_str), bs.block_open.clone()), arms_str), "\n".to_string()), bs.block_close.clone()) } - _ => emit_error_expr( - "emit_unified_tco_match expected ExprMatch".to_string(), - target.clone(), - ), - } +}, + _ => emit_error_expr("emit_unified_tco_match expected ExprMatch".to_string(), target.clone()), +} } -pub fn emit_unified_tco_match_arm( - arm: &Rc, - fn_name: &String, - params: &Rc>>, - target: &RenderTarget, - registry: &Rc>>, - scope: &Rc, - depth: i64, - render_pattern: impl Fn(Rc) -> String + Clone, - render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone, -) -> String { +pub fn emit_unified_tco_match_arm(arm: &Rc, fn_name: &String, params: &Rc>>, target: &RenderTarget, registry: &Rc>>, scope: &Rc, depth: i64, render_pattern: impl Fn(Rc) -> String + Clone, render_init_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone) -> String { { let bs = language_spec(target.clone()).block_syntax.clone(); - let case_depth = if bs.significant_whitespace.clone() { +let case_depth = if bs.significant_whitespace.clone() { (depth.clone() + 1) } else { depth.clone() }; - let body_depth = (case_depth.clone() + 1); - let guard_str = emit_arm_guard(arm.clone(), &target, |g| { - emit_unified_typed_expr( - g.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }); - let body_str = emit_unified_tco_expr( - &Rc::new(TcoFrame { - expr: arm_body(&arm), - scope: scope.clone(), - depth: body_depth.clone(), - }), - &fn_name, - params.clone(), - &target, - registry.clone(), - |expr, scope, depth| { - emit_unified_typed_expr( - expr.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - |frame| { - emit_unified_tco_match( - &frame, - fn_name.clone(), - params.clone(), - &target, - ®istry, - render_pattern.clone(), - render_init_stmts.clone(), - ) - }, - render_init_stmts.clone(), - ); - emit_match_arm_line( - arm.clone(), - target.clone(), - case_depth.clone(), - body_depth.clone(), - body_str, - guard_str, - render_pattern.clone(), - ) - } +let body_depth = (case_depth.clone() + 1); +let guard_str = emit_arm_guard(arm.clone(), &target, |g| emit_unified_typed_expr(g.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone())); +let body_str = emit_unified_tco_expr(&Rc::new(TcoFrame { + expr: arm_body(&arm), + scope: scope.clone(), + depth: body_depth.clone(), +}), &fn_name, params.clone(), &target, registry.clone(), |expr, scope, depth| emit_unified_typed_expr(expr.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()), |frame| emit_unified_tco_match(&frame, fn_name.clone(), params.clone(), &target, ®istry, render_pattern.clone(), render_init_stmts.clone()), render_init_stmts.clone()); +emit_match_arm_line(arm.clone(), target.clone(), case_depth.clone(), body_depth.clone(), body_str, guard_str, render_pattern.clone()) +} } -pub fn emit_tco_unified( - texpr: Rc, - fn_name: &String, - params: &Rc>>, - target: &RenderTarget, - registry: &Rc>>, - scope: &Rc, - depth: i64, - render_pattern: impl Fn(Rc) -> String + Clone, -) -> String { - emit_unified_tco_body( - texpr, - fn_name.clone(), - params.clone(), - &target, - registry.clone(), - scope.clone(), - depth.clone(), - |expr, scope, depth| { - emit_unified_typed_expr( - expr.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - |frame| { - emit_unified_tco_match( - &frame, - fn_name.clone(), - params.clone(), - &target, - ®istry, - render_pattern.clone(), - |stmts, scope, depth| { - emit_unified_init_block_stmts( - stmts.clone(), - Rc::new(vec![]), - scope.clone(), - depth.clone(), - &target, - registry.clone(), - render_pattern.clone(), - ) - }, - ) - }, - |stmts, scope, depth| { - emit_unified_init_block_stmts( - stmts.clone(), - Rc::new(vec![]), - scope.clone(), - depth.clone(), - &target, - registry.clone(), - render_pattern.clone(), - ) - }, - ) +pub fn emit_tco_unified(texpr: Rc, fn_name: &String, params: &Rc>>, target: &RenderTarget, registry: &Rc>>, scope: &Rc, depth: i64, render_pattern: impl Fn(Rc) -> String + Clone) -> String { + emit_unified_tco_body(texpr, fn_name.clone(), params.clone(), &target, registry.clone(), scope.clone(), depth.clone(), |expr, scope, depth| emit_unified_typed_expr(expr.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()), |frame| emit_unified_tco_match(&frame, fn_name.clone(), params.clone(), &target, ®istry, render_pattern.clone(), |stmts, scope, depth| emit_unified_init_block_stmts(stmts.clone(), Rc::new(vec![]), scope.clone(), depth.clone(), &target, registry.clone(), render_pattern.clone())), |stmts, scope, depth| emit_unified_init_block_stmts(stmts.clone(), Rc::new(vec![]), scope.clone(), depth.clone(), &target, registry.clone(), render_pattern.clone())) } -pub fn emit_unified_typed_func_body( - body: &Rc, - target: &RenderTarget, - registry: &Rc>>, - scope: &Rc, - depth: i64, -) -> String { +pub fn emit_unified_typed_func_body(body: &Rc, target: &RenderTarget, registry: &Rc>>, scope: &Rc, depth: i64) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let es = language_spec(target.clone()).expression_semantics.clone(); - let bs = language_spec(target.clone()).block_syntax.clone(); - let si = scope.type_env.clone().source_indices.clone(); - let prefix = if bs.significant_whitespace.clone() { - "".to_string() - } else { - make_indent(depth.clone()) - }; - match (*body.expr_data.clone()).clone() { - ExprData::ExprLet => { + { + let es = language_spec(target.clone()).expression_semantics.clone(); +let bs = language_spec(target.clone()).block_syntax.clone(); +let si = scope.type_env.clone().source_indices.clone(); +let prefix = if bs.significant_whitespace.clone() { + "".to_string() + } else { + make_indent(depth.clone()) + }; +match (*body.expr_data.clone()).clone() { + ExprData::ExprLet => { let n = let_binding_name_at(body.clone(), si.clone()); - let ch = body.children.clone(); - let v = let_value(body.clone()); - let inner = let_body(body.clone()); - let val_str = emit_unified_typed_expr( - v.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - |pat| emit_unified_pattern(pat.clone(), target.clone(), si.clone()), - ); - let let_line = v2_rt::concat(prefix, emit_let_binding(n.clone(), val_str, &target)); - let next_scope = extend_scope( - &scope, - &n, - resolved_type(v.clone()), - Rc::new(SubValueRelation::SubValueUnknown), - ); - match inner { - Some(bd) => v2_rt::concat( - v2_rt::concat(let_line, "\n".to_string()), - emit_unified_typed_func_body( - &bd, - &target, - ®istry, - &next_scope, - depth.clone(), - ), - ), - None => let_line, - } - } - ExprData::ExprBlock => { +let ch = body.children.clone(); +let v = let_value(body.clone()); +let inner = let_body(body.clone()); +let val_str = emit_unified_typed_expr(v.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, |pat| emit_unified_pattern(pat.clone(), target.clone(), si.clone())); +let let_line = v2_rt::concat(prefix, emit_let_binding(n.clone(), val_str, &target)); +let next_scope = extend_scope(&scope, &n, resolved_type(v.clone()), Rc::new(SubValueRelation::SubValueUnknown)); +match inner { + Some(bd) => v2_rt::concat(v2_rt::concat(let_line, "\n".to_string()), emit_unified_typed_func_body(&bd, &target, ®istry, &next_scope, depth.clone())), + None => let_line, +} +}, + ExprData::ExprBlock => { let ss = body.children.clone(); - if ((ss.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat(prefix, "return ".to_string()), - es.empty_return_value.clone(), - ) +if ((ss.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat(prefix, "return ".to_string()), es.empty_return_value.clone()) } else { { - let init_state = emit_unified_init_block_stmts( - ss.clone(), - Rc::new(vec![]), - scope.clone(), - depth.clone(), - &target, - registry.clone(), - |pat| emit_unified_pattern(pat.clone(), target.clone(), si.clone()), - ); - let last_stmt = ss.clone().last().cloned(); - let last_str = match last_stmt { - Some(s) => v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix, "return ".to_string()), - emit_unified_typed_expr( - s.clone(), - &target, - registry.clone(), - &init_state.scope.clone(), - depth.clone(), - 1024, - |pat| { - emit_unified_pattern( - pat.clone(), - target.clone(), - si.clone(), - ) - }, - ), - ), - es.return_suffix.clone(), - ), - None => v2_rt::concat( - v2_rt::concat(prefix, "return ".to_string()), - es.empty_return_value.clone(), - ), - }; - if ((init_state.text.clone().len() as i64) == 0) { + let init_state = emit_unified_init_block_stmts(ss.clone(), Rc::new(vec![]), scope.clone(), depth.clone(), &target, registry.clone(), |pat| emit_unified_pattern(pat.clone(), target.clone(), si.clone())); +let last_stmt = ss.clone().last().cloned(); +let last_str = match last_stmt { + Some(s) => v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix, "return ".to_string()), emit_unified_typed_expr(s.clone(), &target, registry.clone(), &init_state.scope.clone(), depth.clone(), 1024, |pat| emit_unified_pattern(pat.clone(), target.clone(), si.clone()))), es.return_suffix.clone()), + None => v2_rt::concat(v2_rt::concat(prefix, "return ".to_string()), es.empty_return_value.clone()), +}; +if ((init_state.text.clone().len() as i64) == 0) { last_str } else { - v2_rt::concat( - v2_rt::concat( - init_state.text.clone().join(&"\n".to_string()), - "\n".to_string(), - ), - last_str, - ) + v2_rt::concat(v2_rt::concat(init_state.text.clone().join(&"\n".to_string()), "\n".to_string()), last_str) } - } +} } - } - _ => v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix, "return ".to_string()), - emit_unified_typed_expr( - body.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - |pat| emit_unified_pattern(pat.clone(), target.clone(), si.clone()), - ), - ), - es.return_suffix.clone(), - ), - } +}, + _ => v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix, "return ".to_string()), emit_unified_typed_expr(body.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, |pat| emit_unified_pattern(pat.clone(), target.clone(), si.clone()))), es.return_suffix.clone()), +} +} }) } -pub fn is_tco_candidate( - texpr: &Rc, - func_name: &String, - source_indices: &Rc>>, -) -> bool { +pub fn is_tco_candidate(texpr: &Rc, func_name: &String, source_indices: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - (expr_call_func_at(texpr.clone(), source_indices.clone()).as_str() - == func_name.clone().as_str()) - } - ExprData::ExprReturn => { - is_tco_candidate(&return_value(texpr.clone()), &func_name, &source_indices) - } - ExprData::ExprIf => { - let then_cand = - is_tco_candidate(&if_then_branch(texpr.clone()), &func_name, &source_indices); - let else_cand = match if_else_branch(texpr.clone()) { - Some(e) => is_tco_candidate(&e, &func_name, &source_indices), - None => false, - }; - (then_cand || else_cand) - } - ExprData::ExprMatch => { - let mut __found = false; - for arm_node in match_arm_nodes(texpr.clone()).iter().cloned() { - if is_tco_candidate(&arm_body(&arm_node), &func_name, &source_indices) { - __found = true; - break; - } - } - __found - } - ExprData::ExprLet => match let_body(texpr.clone()) { - Some(b) => is_tco_candidate(&b, &func_name, &source_indices), - None => false, - }, - ExprData::ExprBlock => { - let mut __found = false; - for s in texpr.children.clone().iter().cloned() { - if is_tco_candidate(&s, &func_name, &source_indices) { - __found = true; - break; - } - } - __found - } - ExprData::NoExprData => { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if is_tco_candidate(&child, &func_name, &source_indices) { - __found = true; - break; - } - } - __found - } - _ => false, - } + ExprData::ExprCall { .. } => (expr_call_func_at(texpr.clone(), source_indices.clone()).as_str() == func_name.clone().as_str()), + ExprData::ExprReturn => is_tco_candidate(&return_value(texpr.clone()), &func_name, &source_indices), + ExprData::ExprIf => { + let then_cand = is_tco_candidate(&if_then_branch(texpr.clone()), &func_name, &source_indices); +let else_cand = match if_else_branch(texpr.clone()) { + Some(e) => is_tco_candidate(&e, &func_name, &source_indices), + None => false, +}; +(then_cand || else_cand) +}, + ExprData::ExprMatch => { let mut __found = false; for arm_node in match_arm_nodes(texpr.clone()).iter().cloned() { if is_tco_candidate(&arm_body(&arm_node), &func_name, &source_indices) { __found = true; break; } } __found }, + ExprData::ExprLet => match let_body(texpr.clone()) { + Some(b) => is_tco_candidate(&b, &func_name, &source_indices), + None => false, +}, + ExprData::ExprBlock => { let mut __found = false; for s in texpr.children.clone().iter().cloned() { if is_tco_candidate(&s, &func_name, &source_indices) { __found = true; break; } } __found }, + ExprData::NoExprData => { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if is_tco_candidate(&child, &func_name, &source_indices) { __found = true; break; } } __found }, + _ => false, +} }) } pub fn emit_ident(name: String, target: RenderTarget) -> String { { let spec = language_spec(target); - let converted = match spec.naming_case.clone() { - NamingCase::SnakeCase => to_snake(name), - NamingCase::CamelCase => to_camel(name), - NamingCase::PascalCase => capitalize_first(to_camel(name)), - NamingCase::AsAuthored => name, - }; - let is_reserved = { - let mut __found = false; - for r in spec.reserved_words.clone().keywords.clone().iter().cloned() { - if (r.clone().as_str() == converted.clone().as_str()) { - __found = true; - break; - } - } - __found - }; - if is_reserved { +let converted = match spec.naming_case.clone() { + NamingCase::SnakeCase => to_snake(name), + NamingCase::CamelCase => to_camel(name), + NamingCase::PascalCase => capitalize_first(to_camel(name)), + NamingCase::AsAuthored => name, +}; +let is_reserved = { let mut __found = false; for r in spec.reserved_words.clone().keywords.clone().iter().cloned() { if (r.clone().as_str() == converted.clone().as_str()) { __found = true; break; } } __found }; +if is_reserved { match (*spec.reserved_words.clone().strategy.clone()).clone() { - ReservedWordStrategy::PrefixEscape { prefix: p, .. } => { - v2_rt::concat(p.clone(), converted.clone()) - } - ReservedWordStrategy::SuffixEscape { suffix: s, .. } => { - v2_rt::concat(converted.clone(), s.clone()) - } - ReservedWordStrategy::NoEscape => converted.clone(), - } + ReservedWordStrategy::PrefixEscape { prefix: p, .. } => v2_rt::concat(p.clone(), converted.clone()), + ReservedWordStrategy::SuffixEscape { suffix: s, .. } => v2_rt::concat(converted.clone(), s.clone()), + ReservedWordStrategy::NoEscape => converted.clone(), +} } else { converted.clone() } - } +} } pub fn emit_export_ident(name: String, target: &RenderTarget) -> String { { let spec = language_spec(target.clone()); - match (*spec.visibility.clone()).clone() { - VisibilitySpec::CaseVisibility { - export_case: ec, .. - } => { - let result = apply_naming_case(name, ec.clone()); - let is_reserved = { - let mut __found = false; - for r in spec.reserved_words.clone().keywords.clone().iter().cloned() { - if (r.clone().as_str() == result.clone().as_str()) { - __found = true; - break; - } - } - __found - }; - if is_reserved { - match (*spec.reserved_words.clone().strategy.clone()).clone() { - ReservedWordStrategy::SuffixEscape { suffix: s, .. } => { - v2_rt::concat(result.clone(), s.clone()) - } - ReservedWordStrategy::PrefixEscape { prefix: p, .. } => { - v2_rt::concat(p.clone(), result.clone()) - } - ReservedWordStrategy::NoEscape => result.clone(), - } - } else { - result.clone() - } +match (*spec.visibility.clone()).clone() { + VisibilitySpec::CaseVisibility { export_case: ec, .. } => { + let result = apply_naming_case(name, ec.clone()); +let is_reserved = { let mut __found = false; for r in spec.reserved_words.clone().keywords.clone().iter().cloned() { if (r.clone().as_str() == result.clone().as_str()) { __found = true; break; } } __found }; +if is_reserved { + match (*spec.reserved_words.clone().strategy.clone()).clone() { + ReservedWordStrategy::SuffixEscape { suffix: s, .. } => v2_rt::concat(result.clone(), s.clone()), + ReservedWordStrategy::PrefixEscape { prefix: p, .. } => v2_rt::concat(p.clone(), result.clone()), + ReservedWordStrategy::NoEscape => result.clone(), +} + } else { + result.clone() } - VisibilitySpec::KeywordVisibility { .. } => emit_ident(name, target.clone()), - } - } +}, + VisibilitySpec::KeywordVisibility { .. } => emit_ident(name, target.clone()), +} +} } -pub fn apply_bridge_method_overrides( - name: String, - overrides: Rc>, -) -> String { +pub fn apply_bridge_method_overrides(name: String, overrides: Rc>) -> String { match v2_rt::lookup(&overrides, name.clone()) { - Some(replacement) => replacement.clone(), - None => name.clone(), - } + Some(replacement) => replacement.clone(), + None => name.clone(), +} } pub fn emit_let_binding(name: String, value: String, target: &RenderTarget) -> String { { let spec = language_spec(target.clone()); - apply_type_template2( - spec.annotations.clone().let_binding_inferred.clone(), - emit_ident(name, target.clone()), - value, - ) - } +apply_type_template2(spec.annotations.clone().let_binding_inferred.clone(), emit_ident(name, target.clone()), value) +} } -pub fn emit_let_binding_annotated( - name: String, - type_str: String, - value: String, - target: &RenderTarget, -) -> String { +pub fn emit_let_binding_annotated(name: String, type_str: String, value: String, target: &RenderTarget) -> String { { let spec = language_spec(target.clone()); - apply_type_template3( - spec.annotations.clone().let_binding_annotated.clone(), - emit_ident(name, target.clone()), - type_str, - value, - ) - } +apply_type_template3(spec.annotations.clone().let_binding_annotated.clone(), emit_ident(name, target.clone()), type_str, value) +} } pub fn emit_return(value: String, target: RenderTarget) -> String { @@ -4077,2010 +1982,771 @@ pub fn emit_return(value: String, target: RenderTarget) -> String { pub fn emit_unary_op(op: UnaryOpKind, operand_str: String, target: RenderTarget) -> String { match op { - UnaryOpKind::Not => v2_rt::concat(emit_keyword("not".to_string(), target), operand_str), - UnaryOpKind::Neg => v2_rt::concat("-".to_string(), operand_str), - } + UnaryOpKind::Not => v2_rt::concat(emit_keyword("not".to_string(), target), operand_str), + UnaryOpKind::Neg => v2_rt::concat("-".to_string(), operand_str), +} } pub fn emit_lambda(params_str: String, body_str: String, target: RenderTarget) -> String { { let spec = language_spec(target); - apply_type_template2(spec.lambda_template.clone(), params_str, body_str) - } +apply_type_template2(spec.lambda_template.clone(), params_str, body_str) +} } pub fn emit_error_expr(message: String, target: RenderTarget) -> String { { let msg = emit_string_literal(message, "".to_string()); - let spec = language_spec(target); - apply_type_template1(spec.error_expr_template.clone(), msg) - } +let spec = language_spec(target); +apply_type_template1(spec.error_expr_template.clone(), msg) +} } pub fn emit_lambda_params(param_names: Rc>, target: &RenderTarget) -> String { { let spec = language_spec(target.clone()); - let param_strs = Rc::new({ - let mut __result = Vec::new(); - for p in param_names.iter().cloned() { - __result.push(apply_type_template1( - spec.annotations.clone().lambda_param_untyped.clone(), - emit_ident(p.clone(), target.clone()), - )); - } - __result - }); - param_strs.join(&", ".to_string()) - } +let param_strs = Rc::new({ let mut __result = Vec::new(); for p in param_names.iter().cloned() { __result.push(apply_type_template1(spec.annotations.clone().lambda_param_untyped.clone(), emit_ident(p.clone(), target.clone()))); } __result }); +param_strs.join(&", ".to_string()) +} } pub fn emit_list_lit_expr(element_strs: &Rc>, target: RenderTarget) -> String { { let spec = language_spec(target); - if ((element_strs.clone().len() as i64) == 0) { +if ((element_strs.clone().len() as i64) == 0) { spec.list_literal_empty.clone() } else { { let els_str = element_strs.clone().join(&", ".to_string()); - apply_type_template1(spec.list_literal_template.clone(), els_str) - } +apply_type_template1(spec.list_literal_template.clone(), els_str) +} } - } +} } pub fn emit_null_coalesce(l_str: String, r_str: String, target: RenderTarget) -> String { { let spec = language_spec(target); - apply_type_template2(spec.null_coalesce_template.clone(), l_str, r_str) - } +apply_type_template2(spec.null_coalesce_template.clone(), l_str, r_str) +} } -pub fn emit_expr_var_shared( - expr: Rc, - target: RenderTarget, - source_indices: Rc>>, -) -> String { +pub fn emit_expr_var_shared(expr: Rc, target: RenderTarget, source_indices: Rc>>) -> String { { let n = expr_var_name_at(expr, source_indices); - if (n.clone().as_str() == "none".to_string().as_str()) { +if (n.clone().as_str() == "none".to_string().as_str()) { emit_keyword("null".to_string(), target) } else { - if ((n.clone().as_str() == "true".to_string().as_str()) - || (n.clone().as_str() == "false".to_string().as_str())) - { + if ((n.clone().as_str() == "true".to_string().as_str()) || (n.clone().as_str() == "false".to_string().as_str())) { emit_keyword(n.clone(), target) } else { emit_ident(n.clone(), target) } } - } +} } -pub fn emit_expr_field_access_shared( - expr: &Rc, - target: RenderTarget, - emit_field: impl Fn(Rc) -> String + Clone, - source_indices: &Rc>>, -) -> String { +pub fn emit_expr_field_access_shared(expr: &Rc, target: RenderTarget, emit_field: impl Fn(Rc) -> String + Clone, source_indices: &Rc>>) -> String { if is_typed_service_call_receiver(&expr, source_indices.clone()) { match extract_typed_service_name(&expr, &source_indices) { - Some(svc_name) => service_var_name(svc_name.clone()), - None => emit_field(expr.clone()), - } + Some(svc_name) => service_var_name(svc_name.clone()), + None => emit_field(expr.clone()), +} } else { emit_field(expr.clone()) } } pub fn extract_string_interp_parts(expr: Rc) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for child in expr.children.clone().iter().cloned() { - __result.push(match (*child.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: text, .. } = value.as_ref() else { - unreachable!() - }; - Rc::new(StringPart::Text { - value: text.clone(), - }) - } - _ => Rc::new(StringPart::Interpolation { - expr: arg_value(&child), - }), - }); - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for child in expr.children.clone().iter().cloned() { __result.push(match (*child.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: text, .. } = value.as_ref() else { unreachable!() }; Rc::new(StringPart::Text { + value: text.clone(), +}) }, + _ => Rc::new(StringPart::Interpolation { + expr: arg_value(&child), +}), +}); } __result }) } -pub fn emit_typed_cast_shared( - expr: &Rc, - cast_target_node: Rc, - target: &RenderTarget, - recurse: impl Fn(Rc) -> String + Clone, - source_indices: &Rc>>, -) -> String { +pub fn emit_typed_cast_shared(expr: &Rc, cast_target_node: Rc, target: &RenderTarget, recurse: impl Fn(Rc) -> String + Clone, source_indices: &Rc>>) -> String { { let expr_str = recurse(expr.clone()); - let ty_str = emit_node_type(cast_target_node, target.clone(), source_indices.clone()); - let src_ty = match expr.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: n, .. }) => { - emit_node_type(n.clone(), target.clone(), source_indices.clone()) - } - _ => "".to_string(), - }; - if ((src_ty.clone().as_str() != "".to_string().as_str()) - && (src_ty.clone().as_str() == ty_str.clone().as_str())) - { +let ty_str = emit_node_type(cast_target_node, target.clone(), source_indices.clone()); +let src_ty = match expr.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: n, .. }) => emit_node_type(n.clone(), target.clone(), source_indices.clone()), + _ => "".to_string(), +}; +if ((src_ty.clone().as_str() != "".to_string().as_str()) && (src_ty.clone().as_str() == ty_str.clone().as_str())) { expr_str } else { if can_cast(target.clone(), src_ty.clone(), ty_str.clone()) { render_cast(expr_str, ty_str.clone(), target.clone()) } else { - emit_error_expr( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("unsupported cast from ".to_string(), src_ty.clone()), - " to ".to_string(), - ), - ty_str.clone(), - ), - target.clone(), - ) + emit_error_expr(v2_rt::concat(v2_rt::concat(v2_rt::concat("unsupported cast from ".to_string(), src_ty.clone()), " to ".to_string()), ty_str.clone()), target.clone()) } } - } +} } -pub fn emit_typed_for_each_shared( - variable: &String, - collection: &Rc, - body: Rc, - target: &RenderTarget, - depth: i64, - source_indices: Rc>>, - recurse: impl Fn(Rc, Rc, i64) -> String + Clone, - scope: &Rc, -) -> String { +pub fn emit_typed_for_each_shared(variable: &String, collection: &Rc, body: Rc, target: &RenderTarget, depth: i64, source_indices: Rc>>, recurse: impl Fn(Rc, Rc, i64) -> String + Clone, scope: &Rc) -> String { { let coll_str = recurse(collection.clone(), scope.clone(), depth.clone()); - let elem_type = - for_each_element_type_node(resolved_type(collection.clone()), source_indices); - let body_scope = extend_scope( - &scope, - &variable, - elem_type, - Rc::new(SubValueRelation::SubValueUnknown), - ); - let body_str = recurse(body, body_scope, (depth.clone() + 1)); - let var_str = emit_ident(variable.clone(), target.clone()); - let spec = language_spec(target.clone()); - let fes = spec.for_each_syntax.clone(); - let bs = spec.block_syntax.clone(); - let body_indent = make_indent((depth.clone() + 1)); - if bs.significant_whitespace.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(fes.prefix.clone(), var_str), - fes.separator.clone(), - ), - coll_str, - ), - bs.block_open.clone(), - ), - body_indent, - ), - body_str, - ) +let elem_type = for_each_element_type_node(resolved_type(collection.clone()), source_indices); +let body_scope = extend_scope(&scope, &variable, elem_type, Rc::new(SubValueRelation::SubValueUnknown)); +let body_str = recurse(body, body_scope, (depth.clone() + 1)); +let var_str = emit_ident(variable.clone(), target.clone()); +let spec = language_spec(target.clone()); +let fes = spec.for_each_syntax.clone(); +let bs = spec.block_syntax.clone(); +let body_indent = make_indent((depth.clone() + 1)); +if bs.significant_whitespace.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(fes.prefix.clone(), var_str), fes.separator.clone()), coll_str), bs.block_open.clone()), body_indent), body_str) } else { { let close_indent = make_indent(depth.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(fes.prefix.clone(), var_str), - fes.separator.clone(), - ), - coll_str, - ), - bs.block_open.clone(), - ), - body_indent, - ), - body_str, - ), - "\n".to_string(), - ), - close_indent, - ), - bs.block_close.clone(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(fes.prefix.clone(), var_str), fes.separator.clone()), coll_str), bs.block_open.clone()), body_indent), body_str), "\n".to_string()), close_indent), bs.block_close.clone()) +} } - } +} } -pub fn emit_typed_index_shared( - base: &Rc, - index: Rc, - target: &RenderTarget, - recurse: impl Fn(Rc) -> String + Clone, - source_indices: &Rc>>, -) -> String { +pub fn emit_typed_index_shared(base: &Rc, index: Rc, target: &RenderTarget, recurse: impl Fn(Rc) -> String + Clone, source_indices: &Rc>>) -> String { { let spec = language_spec(target.clone()); - let base_str = recurse(base.clone()); - let index_str = recurse(index); - let base_node = normalize_access_type_node(resolved_type(base.clone())); - let is_map = node_is_keyed_collection(&base_node, source_indices.clone()); - if is_string_like( - target.clone(), - authored_name_at(source_indices.clone(), &base_node), - ) { - apply_type_template2( - spec.indexing.clone().string_index.clone(), - base_str, - index_str, - ) +let base_str = recurse(base.clone()); +let index_str = recurse(index); +let base_node = normalize_access_type_node(resolved_type(base.clone())); +let is_map = node_is_keyed_collection(&base_node, source_indices.clone()); +if is_string_like(target.clone(), authored_name_at(source_indices.clone(), &base_node)) { + apply_type_template2(spec.indexing.clone().string_index.clone(), base_str, index_str) } else { if is_map { apply_type_template2(spec.indexing.clone().map_index.clone(), base_str, index_str) } else { - apply_type_template2( - spec.indexing.clone().list_index.clone(), - base_str, - index_str, - ) + apply_type_template2(spec.indexing.clone().list_index.clone(), base_str, index_str) } } - } +} } -pub fn emit_typed_slice_shared( - base: &Rc, - start: Rc, - end: Rc, - target: &RenderTarget, - recurse: impl Fn(Rc) -> String + Clone, - source_indices: Rc>>, -) -> String { +pub fn emit_typed_slice_shared(base: &Rc, start: Rc, end: Rc, target: &RenderTarget, recurse: impl Fn(Rc) -> String + Clone, source_indices: Rc>>) -> String { { let spec = language_spec(target.clone()); - let base_str = recurse(base.clone()); - let start_str = recurse(start); - let end_str = recurse(end); - let base_node = normalize_access_type_node(resolved_type(base.clone())); - if is_string_like(target.clone(), authored_name_at(source_indices, &base_node)) { +let base_str = recurse(base.clone()); +let start_str = recurse(start); +let end_str = recurse(end); +let base_node = normalize_access_type_node(resolved_type(base.clone())); +if is_string_like(target.clone(), authored_name_at(source_indices, &base_node)) { match spec.indexing.clone().string_slice.clone() { - Some(tmpl) => apply_type_template3(tmpl.clone(), base_str, start_str, end_str), - None => emit_error_expr( - "unsupported string slice for target".to_string(), - target.clone(), - ), - } + Some(tmpl) => apply_type_template3(tmpl.clone(), base_str, start_str, end_str), + None => emit_error_expr("unsupported string slice for target".to_string(), target.clone()), +} } else { match spec.indexing.clone().list_slice.clone() { - Some(tmpl) => apply_type_template3(tmpl.clone(), base_str, start_str, end_str), - None => emit_error_expr("unsupported slice for target".to_string(), target.clone()), - } - } - } + Some(tmpl) => apply_type_template3(tmpl.clone(), base_str, start_str, end_str), + None => emit_error_expr("unsupported slice for target".to_string(), target.clone()), } - -pub fn emit_shared_expr( - texpr: &Rc, - target: &RenderTarget, - source_indices: Rc>>, - wrap_result: impl Fn(String) -> String + Clone, - recurse: impl Fn(Rc) -> String + Clone, - emit_var: impl Fn(Rc) -> String + Clone, - emit_field_access: impl Fn(Rc) -> String + Clone, - emit_call: impl Fn(Rc) -> String + Clone, - emit_method_call: impl Fn(Rc) -> String + Clone, - emit_match: impl Fn(Rc) -> String + Clone, - emit_if: impl Fn(Rc) -> String + Clone, - emit_let: impl Fn(Rc) -> String + Clone, - emit_record_lit: impl Fn(Rc) -> String + Clone, - emit_string_interp: impl Fn(Rc) -> String + Clone, - emit_block: impl Fn(Rc) -> String + Clone, - emit_cast: impl Fn(Rc) -> String + Clone, - emit_for_each: impl Fn(Rc) -> String + Clone, - emit_index: impl Fn(Rc) -> String + Clone, - emit_slice: impl Fn(Rc) -> String + Clone, - emit_bin_op: impl Fn(Rc) -> String + Clone, -) -> String { - match (*texpr.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: v, .. } => wrap_result(emit_literal(v.clone(), &target)), - ExprData::ExprError { message, .. } => { - wrap_result(emit_error_expr(message.clone(), target.clone())) - } - ExprData::ExprVar { .. } => emit_var(texpr.clone()), - ExprData::ExprFieldAccess { .. } => emit_field_access(texpr.clone()), - ExprData::ExprCall { .. } => emit_call(texpr.clone()), - ExprData::ExprMethodCall { .. } => emit_method_call(texpr.clone()), - ExprData::ExprMatch => emit_match(texpr.clone()), - ExprData::ExprIf => emit_if(texpr.clone()), - ExprData::ExprLet => emit_let(texpr.clone()), - ExprData::ExprRecordLit { .. } => emit_record_lit(texpr.clone()), - ExprData::ExprBinOp { .. } => emit_bin_op(texpr.clone()), - ExprData::ExprUnaryOp { op, .. } => { - let operand = unaryop_operand(texpr.clone()); - wrap_result(emit_unary_op(op.clone(), recurse(operand), target.clone())) - } - ExprData::ExprLambda => { - let body = lambda_body(texpr.clone()); - wrap_result(emit_lambda( - emit_lambda_params( - lambda_param_names_at(texpr.clone(), source_indices), - &target, - ), - recurse(body), - target.clone(), - )) - } - ExprData::ExprStringInterp => emit_string_interp(texpr.clone()), - ExprData::ExprBlock => emit_block(texpr.clone()), - ExprData::ExprCast => emit_cast(texpr.clone()), - ExprData::ExprForEach => emit_for_each(texpr.clone()), - ExprData::ExprIndex => emit_index(texpr.clone()), - ExprData::ExprSlice => emit_slice(texpr.clone()), - ExprData::ExprListLit => wrap_result(emit_list_lit_expr( - &Rc::new({ - let mut __result = Vec::new(); - for el in texpr.children.clone().iter().cloned() { - __result.push(recurse(el.clone())); - } - __result - }), - target.clone(), - )), - ExprData::ExprReturn => { - let ret_val = return_value(texpr.clone()); - wrap_result(emit_return(recurse(ret_val), target.clone())) } - ExprData::NoExprData => wrap_result("".to_string()), - } +} } -pub fn emit_default_bin_op( - texpr: &Rc, - target: RenderTarget, - source_indices: Rc>>, - recurse: impl Fn(Rc) -> String + Clone, - wrap_result: impl Fn(String) -> String + Clone, -) -> String { +pub fn emit_shared_expr(texpr: &Rc, target: &RenderTarget, source_indices: Rc>>, wrap_result: impl Fn(String) -> String + Clone, recurse: impl Fn(Rc) -> String + Clone, emit_var: impl Fn(Rc) -> String + Clone, emit_field_access: impl Fn(Rc) -> String + Clone, emit_call: impl Fn(Rc) -> String + Clone, emit_method_call: impl Fn(Rc) -> String + Clone, emit_match: impl Fn(Rc) -> String + Clone, emit_if: impl Fn(Rc) -> String + Clone, emit_let: impl Fn(Rc) -> String + Clone, emit_record_lit: impl Fn(Rc) -> String + Clone, emit_string_interp: impl Fn(Rc) -> String + Clone, emit_block: impl Fn(Rc) -> String + Clone, emit_cast: impl Fn(Rc) -> String + Clone, emit_for_each: impl Fn(Rc) -> String + Clone, emit_index: impl Fn(Rc) -> String + Clone, emit_slice: impl Fn(Rc) -> String + Clone, emit_bin_op: impl Fn(Rc) -> String + Clone) -> String { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprBinOp { - op, - algebra_field: algebra, - .. - } => { - let left = binop_left(texpr.clone()); - let right = binop_right(texpr.clone()); - let left_str = recurse(left); - let right_str = recurse(right); - if is_null_coalesce(op.clone()) { - wrap_result(emit_null_coalesce(left_str, right_str, target)) - } else { - { - let op_str = emit_bin_op_symbol(op.clone(), &target, algebra.clone()); - wrap_result(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("(".to_string(), left_str), - " ".to_string(), - ), - op_str, - ), - " ".to_string(), - ), - right_str, - ), - ")".to_string(), - )) - } - } + ExprData::ExprLiteral { value: v, .. } => wrap_result(emit_literal(v.clone(), &target)), + ExprData::ExprError { message, .. } => wrap_result(emit_error_expr(message.clone(), target.clone())), + ExprData::ExprVar { .. } => emit_var(texpr.clone()), + ExprData::ExprFieldAccess { .. } => emit_field_access(texpr.clone()), + ExprData::ExprCall { .. } => emit_call(texpr.clone()), + ExprData::ExprMethodCall { .. } => emit_method_call(texpr.clone()), + ExprData::ExprMatch => emit_match(texpr.clone()), + ExprData::ExprIf => emit_if(texpr.clone()), + ExprData::ExprLet => emit_let(texpr.clone()), + ExprData::ExprRecordLit { .. } => emit_record_lit(texpr.clone()), + ExprData::ExprBinOp { .. } => emit_bin_op(texpr.clone()), + ExprData::ExprUnaryOp { op, .. } => { + let operand = unaryop_operand(texpr.clone()); +wrap_result(emit_unary_op(op.clone(), recurse(operand), target.clone())) +}, + ExprData::ExprLambda => { + let body = lambda_body(texpr.clone()); +wrap_result(emit_lambda(emit_lambda_params(lambda_param_names_at(texpr.clone(), source_indices), &target), recurse(body), target.clone())) +}, + ExprData::ExprStringInterp => emit_string_interp(texpr.clone()), + ExprData::ExprBlock => emit_block(texpr.clone()), + ExprData::ExprCast => emit_cast(texpr.clone()), + ExprData::ExprForEach => emit_for_each(texpr.clone()), + ExprData::ExprIndex => emit_index(texpr.clone()), + ExprData::ExprSlice => emit_slice(texpr.clone()), + ExprData::ExprListLit => wrap_result(emit_list_lit_expr(&Rc::new({ let mut __result = Vec::new(); for el in texpr.children.clone().iter().cloned() { __result.push(recurse(el.clone())); } __result }), target.clone())), + ExprData::ExprReturn => { + let ret_val = return_value(texpr.clone()); +wrap_result(emit_return(recurse(ret_val), target.clone())) +}, + ExprData::NoExprData => wrap_result("".to_string()), +} +} + +pub fn emit_default_bin_op(texpr: &Rc, target: RenderTarget, source_indices: Rc>>, recurse: impl Fn(Rc) -> String + Clone, wrap_result: impl Fn(String) -> String + Clone) -> String { + match (*texpr.expr_data.clone()).clone() { + ExprData::ExprBinOp { op, algebra_field: algebra, .. } => { + let left = binop_left(texpr.clone()); +let right = binop_right(texpr.clone()); +let left_str = recurse(left); +let right_str = recurse(right); +if is_null_coalesce(op.clone()) { + wrap_result(emit_null_coalesce(left_str, right_str, target)) + } else { + { + let op_str = emit_bin_op_symbol(op.clone(), &target, algebra.clone()); +wrap_result(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("(".to_string(), left_str), " ".to_string()), op_str), " ".to_string()), right_str), ")".to_string())) +} } - _ => wrap_result(emit_error_expr( - "emit_default_bin_op expected ExprBinOp".to_string(), - target, - )), - } +}, + _ => wrap_result(emit_error_expr("emit_default_bin_op expected ExprBinOp".to_string(), target)), +} } -pub fn emit_block_stmts_shared( - mut remaining: Rc>>, - mut text: Rc>, - mut scope: Rc, - mut depth: i64, - mut prepend_indent: bool, - mut emit_expr: impl Fn(Rc, Rc, i64) -> String + Clone, -) -> Rc { +pub fn emit_block_stmts_shared(mut remaining: Rc>>, mut text: Rc>, mut scope: Rc, mut depth: i64, mut prepend_indent: bool, mut emit_expr: impl Fn(Rc, Rc, i64) -> String + Clone) -> Rc { loop { match remaining.clone().first().cloned() { - None => { - break Rc::new(BlockEmitState { - text: text, - scope: scope.clone(), - }); - } - Some(stmt) => { - let raw = emit_expr(stmt.clone(), scope.clone(), depth.clone()); - let line = if prepend_indent.clone() { - v2_rt::concat(make_indent(depth.clone()), raw) - } else { - raw - }; - let next_scope = scope_after_expr(&stmt, &scope); - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = v2_rt::rc_list_push(text, line); - let __tco_2 = next_scope; - remaining = __tco_0; - text = __tco_1; - scope = __tco_2; - continue; - } - } - } - } + None => { break Rc::new(BlockEmitState { + text: text, + scope: scope.clone(), +}); }, + Some(stmt) => { let raw = emit_expr(stmt.clone(), scope.clone(), depth.clone()); +let line = if prepend_indent.clone() { + v2_rt::concat(make_indent(depth.clone()), raw) + } else { + raw + }; +let next_scope = scope_after_expr(&stmt, &scope); +{ + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(text, line); +let __tco_2 = next_scope; +remaining = __tco_0; +text = __tco_1; +scope = __tco_2; +continue; +} }, +} +} } -pub fn emit_init_block_stmts_shared( - mut remaining: Rc>>, - mut text: Rc>, - mut scope: Rc, - mut depth: i64, - mut prepend_indent: bool, - mut emit_expr: impl Fn(Rc, Rc, i64) -> String + Clone, -) -> Rc { +pub fn emit_init_block_stmts_shared(mut remaining: Rc>>, mut text: Rc>, mut scope: Rc, mut depth: i64, mut prepend_indent: bool, mut emit_expr: impl Fn(Rc, Rc, i64) -> String + Clone) -> Rc { loop { match remaining.clone().first().cloned() { - None => { - break Rc::new(BlockEmitState { - text: text, - scope: scope.clone(), - }); - } - Some(stmt) => { - let rest = Rc::new( - remaining - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - match rest.clone().first().cloned() { - None => { - break Rc::new(BlockEmitState { - text: text, - scope: scope.clone(), - }); - } - Some(_) => { - let raw = emit_expr(stmt.clone(), scope.clone(), depth.clone()); - let line = if prepend_indent.clone() { - v2_rt::concat(make_indent(depth.clone()), raw) - } else { - raw - }; - let next_scope = scope_after_expr(&stmt, &scope); - { - let __tco_0 = rest.clone(); - let __tco_1 = v2_rt::rc_list_push(text, line); - let __tco_2 = next_scope; - remaining = __tco_0; - text = __tco_1; - scope = __tco_2; - continue; - } - } - } - } - } - } + None => { break Rc::new(BlockEmitState { + text: text, + scope: scope.clone(), +}); }, + Some(stmt) => { let rest = Rc::new(remaining.clone().iter().cloned().skip(1 as usize).collect::>()); +match rest.clone().first().cloned() { + None => { break Rc::new(BlockEmitState { + text: text, + scope: scope.clone(), +}); }, + Some(_) => { let raw = emit_expr(stmt.clone(), scope.clone(), depth.clone()); +let line = if prepend_indent.clone() { + v2_rt::concat(make_indent(depth.clone()), raw) + } else { + raw + }; +let next_scope = scope_after_expr(&stmt, &scope); +{ + let __tco_0 = rest.clone(); +let __tco_1 = v2_rt::rc_list_push(text, line); +let __tco_2 = next_scope; +remaining = __tco_0; +text = __tco_1; +scope = __tco_2; +continue; +} }, +} }, +} +} } -pub fn emit_typed_let_shared( - name: &String, - value_str: String, - body: Option>, - target: RenderTarget, - recurse: impl Fn(Rc, Rc) -> String + Clone, - scope: Rc, - value_node: Rc, -) -> String { +pub fn emit_typed_let_shared(name: &String, value_str: String, body: Option>, target: RenderTarget, recurse: impl Fn(Rc, Rc) -> String + Clone, scope: Rc, value_node: Rc) -> String { { let let_line = emit_let_binding(name.clone(), value_str, &target); - match body { - Some(bd) => { - let next_scope = extend_scope( - &scope, - &name, - resolved_type(value_node), - Rc::new(SubValueRelation::SubValueUnknown), - ); - v2_rt::concat( - v2_rt::concat(let_line, "\n".to_string()), - recurse(bd.clone(), next_scope), - ) - } - None => let_line, - } - } +match body { + Some(bd) => { + let next_scope = extend_scope(&scope, &name, resolved_type(value_node), Rc::new(SubValueRelation::SubValueUnknown)); +v2_rt::concat(v2_rt::concat(let_line, "\n".to_string()), recurse(bd.clone(), next_scope)) +}, + None => let_line, +} +} } -pub fn emit_typed_if_shared( - cond_str: String, - then_branch: &Rc, - else_branch: Option>, - if_result_type: Option>, - depth: i64, - target: &RenderTarget, - source_indices: Rc>>, - recurse: impl Fn(Rc, i64) -> String + Clone, -) -> String { +pub fn emit_typed_if_shared(cond_str: String, then_branch: &Rc, else_branch: Option>, if_result_type: Option>, depth: i64, target: &RenderTarget, source_indices: Rc>>, recurse: impl Fn(Rc, i64) -> String + Clone) -> String { { let spec = language_spec(target.clone()); - let es = spec.expression_semantics.clone(); - let bs = spec.block_syntax.clone(); - match else_branch { - Some(eb) => match es.if_value_form.clone() { - IfValueForm::IfExpression => { - let then_str = recurse(then_branch.clone(), (depth.clone() + 1)); - let else_str = recurse(eb.clone(), (depth.clone() + 1)); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "if ".to_string(), - cond_str, - ), - bs.block_open.clone(), - ), - make_indent((depth.clone() + 1)), - ), - then_str, - ), - "\n".to_string(), - ), - make_indent(depth.clone()), - ), - bs.else_clause.clone(), - ), - make_indent((depth.clone() + 1)), - ), - else_str, - ), - "\n".to_string(), - ), - make_indent(depth.clone()), - ), - bs.block_close.clone(), - ) - } - IfValueForm::ConditionalTernary => { - let then_str = recurse(then_branch.clone(), depth.clone()); - let else_str = recurse(eb.clone(), depth.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("(".to_string(), then_str), - ") if (".to_string(), - ), - cond_str, - ), - ") else (".to_string(), - ), - else_str, - ), - ")".to_string(), - ) - } - IfValueForm::IfStatement => { - let result_type = match if_result_type { - Some(rt) => emit_node_type(rt.clone(), target.clone(), source_indices), - None => emit_node_type( - resolved_type(then_branch.clone()), - target.clone(), - source_indices, - ), - }; - let then_str = recurse(then_branch.clone(), depth.clone()); - let else_str = recurse(eb.clone(), depth.clone()); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("func() ".to_string(), result_type), " { if ".to_string()), cond_str), bs.block_open.clone()), make_indent((depth.clone() + 1))), "return ".to_string()), then_str), "\n".to_string()), make_indent(depth.clone())), bs.else_clause.clone()), make_indent((depth.clone() + 1))), "return ".to_string()), else_str), "\n".to_string()), make_indent(depth.clone())), bs.block_close.clone()), " }()".to_string()) - } - }, - None => { - if bs.significant_whitespace.clone() { - { - let then_str = recurse(then_branch.clone(), depth.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("if ".to_string(), cond_str), - bs.block_open.clone(), - ), - make_indent((depth.clone() + 1)), - ), - then_str, - ) - } - } else { - { - let then_str = recurse(then_branch.clone(), (depth.clone() + 1)); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("if ".to_string(), cond_str), - bs.block_open.clone(), - ), - make_indent((depth.clone() + 1)), - ), - then_str, - ), - "\n".to_string(), - ), - make_indent(depth.clone()), - ), - bs.block_close.clone(), - ) - } - } - } - } - } +let es = spec.expression_semantics.clone(); +let bs = spec.block_syntax.clone(); +match else_branch { + Some(eb) => match es.if_value_form.clone() { + IfValueForm::IfExpression => { + let then_str = recurse(then_branch.clone(), (depth.clone() + 1)); +let else_str = recurse(eb.clone(), (depth.clone() + 1)); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), bs.block_open.clone()), make_indent((depth.clone() + 1))), then_str), "\n".to_string()), make_indent(depth.clone())), bs.else_clause.clone()), make_indent((depth.clone() + 1))), else_str), "\n".to_string()), make_indent(depth.clone())), bs.block_close.clone()) +}, + IfValueForm::ConditionalTernary => { + let then_str = recurse(then_branch.clone(), depth.clone()); +let else_str = recurse(eb.clone(), depth.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("(".to_string(), then_str), ") if (".to_string()), cond_str), ") else (".to_string()), else_str), ")".to_string()) +}, + IfValueForm::IfStatement => { + let result_type = match if_result_type { + Some(rt) => emit_node_type(rt.clone(), target.clone(), source_indices), + None => emit_node_type(resolved_type(then_branch.clone()), target.clone(), source_indices), +}; +let then_str = recurse(then_branch.clone(), depth.clone()); +let else_str = recurse(eb.clone(), depth.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("func() ".to_string(), result_type), " { if ".to_string()), cond_str), bs.block_open.clone()), make_indent((depth.clone() + 1))), "return ".to_string()), then_str), "\n".to_string()), make_indent(depth.clone())), bs.else_clause.clone()), make_indent((depth.clone() + 1))), "return ".to_string()), else_str), "\n".to_string()), make_indent(depth.clone())), bs.block_close.clone()), " }()".to_string()) +}, +}, + None => if bs.significant_whitespace.clone() { + { + let then_str = recurse(then_branch.clone(), depth.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), bs.block_open.clone()), make_indent((depth.clone() + 1))), then_str) +} + } else { + { + let then_str = recurse(then_branch.clone(), (depth.clone() + 1)); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), bs.block_open.clone()), make_indent((depth.clone() + 1))), then_str), "\n".to_string()), make_indent(depth.clone())), bs.block_close.clone()) +} + }, +} +} } -pub fn emit_param_shared( - param: &Rc, - target: &RenderTarget, - source_indices: &Rc>>, -) -> String { +pub fn emit_param_shared(param: &Rc, target: &RenderTarget, source_indices: &Rc>>) -> String { { - let ty = emit_node_type( - param_node_type_expr(¶m), - target.clone(), - source_indices.clone(), - ); - v2_rt::concat( - v2_rt::concat( - emit_ident( - param_node_name_at(param.clone(), source_indices.clone()), - target.clone(), - ), - language_spec(target.clone()) - .items - .clone() - .param_type_sep - .clone(), - ), - ty, - ) - } + let ty = emit_node_type(param_node_type_expr(¶m), target.clone(), source_indices.clone()); +v2_rt::concat(v2_rt::concat(emit_ident(param_node_name_at(param.clone(), source_indices.clone()), target.clone()), language_spec(target.clone()).items.clone().param_type_sep.clone()), ty) +} } -pub fn emit_params_shared( - params: Rc>>, - target: &RenderTarget, - source_indices: Rc>>, -) -> String { +pub fn emit_params_shared(params: Rc>>, target: &RenderTarget, source_indices: Rc>>) -> String { { - let strs = Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - __result.push(emit_param_shared(&p, &target, &source_indices)); - } - __result - }); - strs.join( - &language_spec(target.clone()) - .items - .clone() - .param_separator - .clone(), - ) - } + let strs = Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { __result.push(emit_param_shared(&p, &target, &source_indices)); } __result }); +strs.join(&language_spec(target.clone()).items.clone().param_separator.clone()) +} } -pub fn emit_inferred_shared( - inferred: &Rc, - target: &RenderTarget, - source_indices: Rc>>, -) -> String { - if language_spec(target.clone()) - .expression_semantics - .clone() - .suppress_unit_return - .clone() - { +pub fn emit_inferred_shared(inferred: &Rc, target: &RenderTarget, source_indices: Rc>>) -> String { + if language_spec(target.clone()).expression_semantics.clone().suppress_unit_return.clone() { if is_unit_like(&inferred) { "".to_string() } else { - v2_rt::concat( - language_spec(target.clone()) - .items - .clone() - .return_arrow - .clone(), - emit_node_type(inferred.clone(), target.clone(), source_indices), - ) + v2_rt::concat(language_spec(target.clone()).items.clone().return_arrow.clone(), emit_node_type(inferred.clone(), target.clone(), source_indices)) } } else { - v2_rt::concat( - language_spec(target.clone()) - .items - .clone() - .return_arrow - .clone(), - emit_node_type(inferred.clone(), target.clone(), source_indices), - ) + v2_rt::concat(language_spec(target.clone()).items.clone().return_arrow.clone(), emit_node_type(inferred.clone(), target.clone(), source_indices)) } } -pub fn emit_typed_block_join( - stmts: Rc>>, - scope: Rc, - depth: i64, - emit_block_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone, -) -> String { +pub fn emit_typed_block_join(stmts: Rc>>, scope: Rc, depth: i64, emit_block_stmts: impl Fn(Rc>>, Rc, i64) -> Rc + Clone) -> String { { let state = emit_block_stmts(stmts, scope, depth); - state.text.clone().join(&"\n".to_string()) - } +state.text.clone().join(&"\n".to_string()) +} } -pub fn method_template_emit_for_target( - target: RenderTarget, -) -> Option>> { +pub fn method_template_emit_for_target(target: RenderTarget) -> Option>> { match target { - RenderTarget::Rust => Some(rust_method_template_emit()), - RenderTarget::Python => Some(python_method_template_emit()), - RenderTarget::Go => Some(go_method_template_emit()), - RenderTarget::Dag => None, - } + RenderTarget::Rust => Some(rust_method_template_emit()), + RenderTarget::Python => Some(python_method_template_emit()), + RenderTarget::Go => Some(go_method_template_emit()), + RenderTarget::Dag => None, +} } -pub fn emit_algebra_method_template( - method_name: String, - recv_str: String, - first_arg_str: String, - target: RenderTarget, -) -> Option { +pub fn emit_algebra_method_template(method_name: String, recv_str: String, first_arg_str: String, target: RenderTarget) -> Option { match method_template_emit_for_target(target) { - Some(templates) => match v2_rt::map_get(&templates, method_name) { - Some(tmpl) => { - let bindings = v2_rt::rc_map_insert( - seed_bindings("recv".to_string(), recv_str), - "arg".to_string(), - first_arg_str, - ); - Some(apply_named_template(tmpl.clone(), &bindings)) - } - None => None, - }, - None => None, - } + Some(templates) => match v2_rt::map_get(&templates, method_name) { + Some(tmpl) => { + let bindings = v2_rt::rc_map_insert(seed_bindings("recv".to_string(), recv_str), "arg".to_string(), first_arg_str); +Some(apply_named_template(tmpl.clone(), &bindings)) +}, + None => None, +}, + None => None, +} } -pub fn emit_typed_first_arg_shared( - args: Rc>>, - target: RenderTarget, - recurse: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_typed_first_arg_shared(args: Rc>>, target: RenderTarget, recurse: impl Fn(Rc) -> String + Clone) -> String { match args.first().cloned() { - Some(a) => recurse(arg_value(&a)), - None => emit_error_expr("missing method argument".to_string(), target), - } + Some(a) => recurse(arg_value(&a)), + None => emit_error_expr("missing method argument".to_string(), target), +} } -pub fn emit_typed_string_interp_unified( - parts: &Rc>>, - target: RenderTarget, - recurse: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_typed_string_interp_unified(parts: &Rc>>, target: RenderTarget, recurse: impl Fn(Rc) -> String + Clone) -> String { { let spec = language_spec(target); - let interp = spec.string_interp.clone(); - let has_interpolations = { - let mut __found = false; - for p in parts.clone().iter().cloned() { - if match (*p.clone()).clone() { - StringPart::Interpolation { .. } => true, - _ => false, - } { - __found = true; - break; - } +let interp = spec.string_interp.clone(); +let has_interpolations = { let mut __found = false; for p in parts.clone().iter().cloned() { if match (*p.clone()).clone() { + StringPart::Interpolation { .. } => true, + _ => false, +} { __found = true; break; } } __found }; +match (*interp.style.clone()).clone() { + InterpStyle::FormatArgs { placeholder: ph, .. } => { + let fmt_parts = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.push(match (*p.clone()).clone() { + StringPart::Text { value: v, .. } => { + let base = escape_string_literal_body(v.clone()); +let escaped = if has_interpolations.clone() { + apply_escape_pairs(base.clone(), interp.escape_pairs.clone()) + } else { + base.clone() + }; +Rc::new(InterpPart { + format_segment: escaped.clone(), + arg_expr: "".to_string(), +}) +}, + StringPart::Interpolation { expr: e, .. } => Rc::new(InterpPart { + format_segment: ph.clone(), + arg_expr: recurse(e.clone()), +}), +}); } __result }); +let fmt_str = Rc::new({ let mut __result = Vec::new(); for p in fmt_parts.clone().iter().cloned() { __result.push(p.format_segment.clone()); } __result }).join(&"".to_string()); +let args = Rc::new({ let mut __result = Vec::new(); for a in Rc::new({ let mut __result = Vec::new(); for p in fmt_parts.clone().iter().cloned() { __result.push(p.arg_expr.clone()); } __result }).iter().cloned() { if (a.clone().as_str() != "".to_string().as_str()) { __result.push(a); } } __result }); +if ((args.clone().len() as i64) == 0) { + apply_type_template1(interp.plain_template.clone(), fmt_str) + } else { + { + let args_str = args.clone().join(&", ".to_string()); +apply_type_template2(interp.format_template.clone(), fmt_str, args_str) +} } - __found - }; - match (*interp.style.clone()).clone() { - InterpStyle::FormatArgs { - placeholder: ph, .. - } => { - let fmt_parts = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.push(match (*p.clone()).clone() { - StringPart::Text { value: v, .. } => { - let base = escape_string_literal_body(v.clone()); - let escaped = if has_interpolations.clone() { - apply_escape_pairs(base.clone(), interp.escape_pairs.clone()) - } else { - base.clone() - }; - Rc::new(InterpPart { - format_segment: escaped.clone(), - arg_expr: "".to_string(), - }) - } - StringPart::Interpolation { expr: e, .. } => Rc::new(InterpPart { - format_segment: ph.clone(), - arg_expr: recurse(e.clone()), - }), - }); - } - __result - }); - let fmt_str = Rc::new({ - let mut __result = Vec::new(); - for p in fmt_parts.clone().iter().cloned() { - __result.push(p.format_segment.clone()); - } - __result - }) - .join(&"".to_string()); - let args = Rc::new({ - let mut __result = Vec::new(); - for a in Rc::new({ - let mut __result = Vec::new(); - for p in fmt_parts.clone().iter().cloned() { - __result.push(p.arg_expr.clone()); - } - __result - }) - .iter() - .cloned() - { - if (a.clone().as_str() != "".to_string().as_str()) { - __result.push(a); - } - } - __result - }); - if ((args.clone().len() as i64) == 0) { - apply_type_template1(interp.plain_template.clone(), fmt_str) +}, + InterpStyle::InlineExpr => { + let segments = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.push(match (*p.clone()).clone() { + StringPart::Text { value: v, .. } => { + let base = escape_string_literal_body(v.clone()); +if has_interpolations.clone() { + apply_escape_pairs(base.clone(), interp.escape_pairs.clone()) } else { - { - let args_str = args.clone().join(&", ".to_string()); - apply_type_template2(interp.format_template.clone(), fmt_str, args_str) - } + base.clone() } - } - InterpStyle::InlineExpr => { - let segments = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.push(match (*p.clone()).clone() { - StringPart::Text { value: v, .. } => { - let base = escape_string_literal_body(v.clone()); - if has_interpolations.clone() { - apply_escape_pairs(base.clone(), interp.escape_pairs.clone()) - } else { - base.clone() - } - } - StringPart::Interpolation { expr: e, .. } => v2_rt::concat( - v2_rt::concat("{".to_string(), recurse(e.clone())), - "}".to_string(), - ), - }); - } - __result - }); - apply_type_template1( - interp.format_template.clone(), - segments.join(&"".to_string()), - ) - } - } - } +}, + StringPart::Interpolation { expr: e, .. } => v2_rt::concat(v2_rt::concat("{".to_string(), recurse(e.clone())), "}".to_string()), +}); } __result }); +apply_type_template1(interp.format_template.clone(), segments.join(&"".to_string())) +}, +} +} } -pub fn emit_typed_record_lit_unified( - type_name: Option, - fields: &Rc>>, - target: &RenderTarget, - source_indices: Rc>>, - recurse: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_typed_record_lit_unified(type_name: Option, fields: &Rc>>, target: &RenderTarget, source_indices: Rc>>, recurse: impl Fn(Rc) -> String + Clone) -> String { { let rls = language_spec(target.clone()).record_lit.clone(); - match type_name { - None => { - if ((fields.clone().len() as i64) == 0) { - rls.anon_empty.clone() - } else { - { - let field_strs = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - rls.anon_field_indent.clone(), - "\"".to_string(), - ), - field_init_node_name_at( - f.clone(), - source_indices.clone(), - ), - ), - "\": ".to_string(), - ), - recurse(field_init_node_value(&f)), - ), - ",".to_string(), - )); - } - __result - }); - let fields_str = field_strs.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(rls.anon_prefix.clone(), fields_str), - "\n".to_string(), - ), - rls.anon_suffix.clone(), - ) - } - } - } - Some(tn) => { - if ((fields.clone().len() as i64) == 0) { - v2_rt::concat(tn.clone(), rls.named_empty.clone()) - } else { - { - let field_strs = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_export_ident( - field_init_node_name_at( - f.clone(), - source_indices.clone(), - ), - &target, - ), - rls.named_field_sep.clone(), - ), - recurse(field_init_node_value(&f)), - )); - } - __result - }); - let fields_str = field_strs.join(&rls.named_field_join.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(tn.clone(), rls.named_open.clone()), - fields_str, - ), - rls.named_close.clone(), - ) - } - } - } - } - } +match type_name { + None => if ((fields.clone().len() as i64) == 0) { + rls.anon_empty.clone() + } else { + { + let field_strs = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rls.anon_field_indent.clone(), "\"".to_string()), field_init_node_name_at(f.clone(), source_indices.clone())), "\": ".to_string()), recurse(field_init_node_value(&f))), ",".to_string())); } __result }); +let fields_str = field_strs.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(rls.anon_prefix.clone(), fields_str), "\n".to_string()), rls.anon_suffix.clone()) +} + }, + Some(tn) => if ((fields.clone().len() as i64) == 0) { + v2_rt::concat(tn.clone(), rls.named_empty.clone()) + } else { + { + let field_strs = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_export_ident(field_init_node_name_at(f.clone(), source_indices.clone()), &target), rls.named_field_sep.clone()), recurse(field_init_node_value(&f)))); } __result }); +let fields_str = field_strs.join(&rls.named_field_join.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(tn.clone(), rls.named_open.clone()), fields_str), rls.named_close.clone()) +} + }, +} +} } -pub fn emit_typed_call_unified( - func: &String, - args: Rc>>, - target: &RenderTarget, - registry: Rc>>, - scope: Rc, - recurse: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_typed_call_unified(func: &String, args: Rc>>, target: &RenderTarget, registry: Rc>>, scope: Rc, recurse: impl Fn(Rc) -> String + Clone) -> String { { let spec = language_spec(target.clone()); - let ordered_args = order_typed_call_args(&args, func.clone(), &scope); - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in ordered_args.iter().cloned() { - __result.push(recurse(arg_value(&a))); - } - __result - }); - let callee = lookup_item(registry, func.clone()); - let extra_args = match callee.clone() { - Some(info) => { - let has_effects = (((info.service_names.clone().len() as i64) > 0) - || ((info.resource_names.clone().len() as i64) > 0)); - if has_effects.clone() { - { - let resource_args = Rc::new({ - let mut __result = Vec::new(); - for rn in info.resource_names.clone().iter().cloned() { - __result.push(emit_ident(rn.clone(), target.clone())); - } - __result - }); - let service_args = Rc::new({ - let mut __result = Vec::new(); - for sn in info.service_names.clone().iter().cloned() { - __result.push(service_var_name(sn.clone())); - } - __result - }); - v2_rt::concat(resource_args, service_args) - } - } else { - Rc::new(vec![]) - } +let ordered_args = order_typed_call_args(&args, func.clone(), &scope); +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in ordered_args.iter().cloned() { __result.push(recurse(arg_value(&a))); } __result }); +let callee = lookup_item(registry, func.clone()); +let extra_args = match callee.clone() { + Some(info) => { + let has_effects = (((info.service_names.clone().len() as i64) > 0) || ((info.resource_names.clone().len() as i64) > 0)); +if has_effects.clone() { + { + let resource_args = Rc::new({ let mut __result = Vec::new(); for rn in info.resource_names.clone().iter().cloned() { __result.push(emit_ident(rn.clone(), target.clone())); } __result }); +let service_args = Rc::new({ let mut __result = Vec::new(); for sn in info.service_names.clone().iter().cloned() { __result.push(service_var_name(sn.clone())); } __result }); +v2_rt::concat(resource_args, service_args) +} + } else { + Rc::new(vec![]) } - None => Rc::new(vec![]), - }; - let all_args = v2_rt::concat(arg_strs, extra_args); - let args_str = all_args.join(&", ".to_string()); - let call_str = v2_rt::concat( - v2_rt::concat( - v2_rt::concat(emit_export_ident(func.clone(), &target), "(".to_string()), - args_str, - ), - ")".to_string(), - ); - match callee.clone() { - Some(info) => { - let has_effects = (((info.service_names.clone().len() as i64) > 0) - || ((info.resource_names.clone().len() as i64) > 0)); - if has_effects.clone() { - v2_rt::concat(spec.async_call_prefix.clone(), call_str) - } else { - call_str - } +}, + None => Rc::new(vec![]), +}; +let all_args = v2_rt::concat(arg_strs, extra_args); +let args_str = all_args.join(&", ".to_string()); +let call_str = v2_rt::concat(v2_rt::concat(v2_rt::concat(emit_export_ident(func.clone(), &target), "(".to_string()), args_str), ")".to_string()); +match callee.clone() { + Some(info) => { + let has_effects = (((info.service_names.clone().len() as i64) > 0) || ((info.resource_names.clone().len() as i64) > 0)); +if has_effects.clone() { + v2_rt::concat(spec.async_call_prefix.clone(), call_str) + } else { + call_str } - None => call_str, - } - } +}, + None => call_str, +} +} } pub fn bridge_method_name_unified(method_name: String, target: RenderTarget) -> String { { let spec = language_spec(target); - let overridden = - apply_bridge_method_overrides(method_name, spec.bridge_method_overrides.clone()); - apply_naming_case(overridden, spec.bridge_method_case.clone()) - } +let overridden = apply_bridge_method_overrides(method_name, spec.bridge_method_overrides.clone()); +apply_naming_case(overridden, spec.bridge_method_case.clone()) +} } -pub fn emit_algebra_method_call_unified( - method_name: &String, - receiver: Rc, - args: Rc>>, - target: &RenderTarget, - first_arg_str: String, - recurse: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_algebra_method_call_unified(method_name: &String, receiver: Rc, args: Rc>>, target: &RenderTarget, first_arg_str: String, recurse: impl Fn(Rc) -> String + Clone) -> String { { let spec = language_spec(target.clone()); - let recv_str = recurse(receiver); - match emit_algebra_method_template( - method_name.clone(), - recv_str.clone(), - first_arg_str, - target.clone(), - ) { - Some(result) => result.clone(), - None => { - let function_name = bridge_method_name_unified(method_name.clone(), target.clone()); - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in args.iter().cloned() { - __result.push(recurse(arg_value(&a))); - } - __result - }); - let all_args = v2_rt::concat(Rc::new(vec![recv_str.clone()]), arg_strs); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - spec.bridge_method_prefix.clone(), - emit_export_ident(function_name, &target), - ), - "(".to_string(), - ), - all_args.join(&", ".to_string()), - ), - ")".to_string(), - ) - } - } - } +let recv_str = recurse(receiver); +match emit_algebra_method_template(method_name.clone(), recv_str.clone(), first_arg_str, target.clone()) { + Some(result) => result.clone(), + None => { + let function_name = bridge_method_name_unified(method_name.clone(), target.clone()); +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in args.iter().cloned() { __result.push(recurse(arg_value(&a))); } __result }); +let all_args = v2_rt::concat(Rc::new(vec![recv_str.clone()]), arg_strs); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(spec.bridge_method_prefix.clone(), emit_export_ident(function_name, &target)), "(".to_string()), all_args.join(&", ".to_string())), ")".to_string()) +}, +} +} } -pub fn emit_plain_method_call_unified( - receiver: Rc, - method: String, - args: Rc>>, - target: RenderTarget, - recurse: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_plain_method_call_unified(receiver: Rc, method: String, args: Rc>>, target: RenderTarget, recurse: impl Fn(Rc) -> String + Clone) -> String { { let recv_str = recurse(receiver); - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in args.iter().cloned() { - __result.push(recurse(arg_value(&a))); - } - __result - }); - let args_str = arg_strs.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(recv_str, ".".to_string()), - emit_export_ident(method, &target), - ), - "(".to_string(), - ), - args_str, - ), - ")".to_string(), - ) - } +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in args.iter().cloned() { __result.push(recurse(arg_value(&a))); } __result }); +let args_str = arg_strs.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(recv_str, ".".to_string()), emit_export_ident(method, &target)), "(".to_string()), args_str), ")".to_string()) +} } -pub fn emit_typed_method_call_unified( - receiver: &Rc, - method: String, - args: &Rc>>, - method_semantics: &Option>, - target: &RenderTarget, - registry: Rc>>, - scope: Rc, - depth: i64, - recurse: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_typed_method_call_unified(receiver: &Rc, method: String, args: &Rc>>, method_semantics: &Option>, target: &RenderTarget, registry: Rc>>, scope: Rc, depth: i64, recurse: impl Fn(Rc) -> String + Clone) -> String { { let spec = language_spec(target.clone()); - let source_indices = scope.type_env.clone().source_indices.clone(); - if (method_semantics.clone() != None) { +let source_indices = scope.type_env.clone().source_indices.clone(); +if (method_semantics.clone() != None) { match (*method_semantics.clone().unwrap()).clone() { - MethodSemantics::ServiceMethodSemantics { - service_name: svc_name, - .. - } => { - let var_name = service_var_name(svc_name.clone()); - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in args.clone().iter().cloned() { - __result.push(recurse(arg_value(&a))); - } - __result - }); - let args_str = arg_strs.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(spec.async_call_prefix.clone(), var_name), - ".".to_string(), - ), - emit_export_ident(method, &target), - ), - "(".to_string(), - ), - args_str, - ), - ")".to_string(), - ) - } - MethodSemantics::AlgebraMethodSemantics { method_def, .. } => { - let mn = authored_name_at(source_indices.clone(), &method_def); - let first_arg_str = - emit_typed_first_arg_shared(args.clone(), target.clone(), recurse.clone()); - emit_algebra_method_call_unified( - &mn, - receiver.clone(), - args.clone(), - &target, - first_arg_str, - recurse.clone(), - ) - } - MethodSemantics::PlainMethodSemantics => emit_plain_method_call_unified( - receiver.clone(), - method, - args.clone(), - target.clone(), - recurse.clone(), - ), - } + MethodSemantics::ServiceMethodSemantics { service_name: svc_name, .. } => { + let var_name = service_var_name(svc_name.clone()); +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in args.clone().iter().cloned() { __result.push(recurse(arg_value(&a))); } __result }); +let args_str = arg_strs.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(spec.async_call_prefix.clone(), var_name), ".".to_string()), emit_export_ident(method, &target)), "(".to_string()), args_str), ")".to_string()) +}, + MethodSemantics::AlgebraMethodSemantics { method_def, .. } => { + let mn = authored_name_at(source_indices.clone(), &method_def); +let first_arg_str = emit_typed_first_arg_shared(args.clone(), target.clone(), recurse.clone()); +emit_algebra_method_call_unified(&mn, receiver.clone(), args.clone(), &target, first_arg_str, recurse.clone()) +}, + MethodSemantics::PlainMethodSemantics => emit_plain_method_call_unified(receiver.clone(), method, args.clone(), target.clone(), recurse.clone()), +} } else { if is_typed_service_call_receiver(&receiver, source_indices.clone()) { match extract_typed_service_name(&receiver, &source_indices) { - Some(svc_name) => { - let var_name = service_var_name(svc_name.clone()); - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in args.clone().iter().cloned() { - __result.push(recurse(arg_value(&a))); - } - __result - }); - let args_str = arg_strs.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(spec.async_call_prefix.clone(), var_name), - ".".to_string(), - ), - emit_export_ident(method, &target), - ), - "(".to_string(), - ), - args_str, - ), - ")".to_string(), - ) - } - None => { - emit_error_expr("unsupported service receiver".to_string(), target.clone()) - } - } + Some(svc_name) => { + let var_name = service_var_name(svc_name.clone()); +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in args.clone().iter().cloned() { __result.push(recurse(arg_value(&a))); } __result }); +let args_str = arg_strs.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(spec.async_call_prefix.clone(), var_name), ".".to_string()), emit_export_ident(method, &target)), "(".to_string()), args_str), ")".to_string()) +}, + None => emit_error_expr("unsupported service receiver".to_string(), target.clone()), +} } else { - emit_plain_method_call_unified( - receiver.clone(), - method, - args.clone(), - target.clone(), - recurse.clone(), - ) + emit_plain_method_call_unified(receiver.clone(), method, args.clone(), target.clone(), recurse.clone()) } } - } +} } -pub fn emit_unified_pattern( - pattern: Rc, - target: RenderTarget, - source_indices: Rc>>, -) -> String { +pub fn emit_unified_pattern(pattern: Rc, target: RenderTarget, source_indices: Rc>>) -> String { match (*pattern).clone() { - MatchPattern::Bind { name: n, .. } => emit_ident(n.clone(), target), - MatchPattern::LitPattern { value: v, .. } => emit_literal(v.clone(), &target), - MatchPattern::VariantPattern { - name: n, - field_bindings: fbs, - .. - } => emit_unified_variant_pattern(n.clone(), &fbs, &target, source_indices), - MatchPattern::Wildcard => "_".to_string(), - } + MatchPattern::Bind { name: n, .. } => emit_ident(n.clone(), target), + MatchPattern::LitPattern { value: v, .. } => emit_literal(v.clone(), &target), + MatchPattern::VariantPattern { name: n, field_bindings: fbs, .. } => emit_unified_variant_pattern(n.clone(), &fbs, &target, source_indices), + MatchPattern::Wildcard => "_".to_string(), +} } -pub fn emit_unified_variant_pattern( - name: String, - field_bindings: &Rc>>, - target: &RenderTarget, - source_indices: Rc>>, -) -> String { +pub fn emit_unified_variant_pattern(name: String, field_bindings: &Rc>>, target: &RenderTarget, source_indices: Rc>>) -> String { { let es = language_spec(target.clone()).expression_semantics.clone(); - match es.variant_pattern.clone() { - Some(vps) => { - if ((field_bindings.clone().len() as i64) == 0) { - v2_rt::concat(name, vps.empty_suffix.clone()) - } else { - { - let binding_strs = Rc::new({ - let mut __result = Vec::new(); - for fb in field_bindings.clone().iter().cloned() { - __result.push({ - let pat_str = emit_unified_pattern( - field_binding_pattern(fb.clone()), - target.clone(), - source_indices.clone(), - ); - v2_rt::concat( - v2_rt::concat( - emit_ident( - field_binding_name_at( - fb.clone(), - source_indices.clone(), - ), - target.clone(), - ), - vps.binding_sep.clone(), - ), - pat_str.clone(), - ) - }); - } - __result - }); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(name, vps.open.clone()), - binding_strs.join(&", ".to_string()), - ), - vps.close.clone(), - ) - } - } - } - None => { - if ((field_bindings.clone().len() as i64) > 0) { - emit_error_expr( - v2_rt::concat( - "variant pattern has bindings but target has no destructuring syntax: " - .to_string(), - name, - ), - target.clone(), - ) - } else { - name - } - } - } - } +match es.variant_pattern.clone() { + Some(vps) => if ((field_bindings.clone().len() as i64) == 0) { + v2_rt::concat(name, vps.empty_suffix.clone()) + } else { + { + let binding_strs = Rc::new({ let mut __result = Vec::new(); for fb in field_bindings.clone().iter().cloned() { __result.push({ + let pat_str = emit_unified_pattern(field_binding_pattern(fb.clone()), target.clone(), source_indices.clone()); +v2_rt::concat(v2_rt::concat(emit_ident(field_binding_name_at(fb.clone(), source_indices.clone()), target.clone()), vps.binding_sep.clone()), pat_str.clone()) +}); } __result }); +v2_rt::concat(v2_rt::concat(v2_rt::concat(name, vps.open.clone()), binding_strs.join(&", ".to_string())), vps.close.clone()) +} + }, + None => if ((field_bindings.clone().len() as i64) > 0) { + emit_error_expr(v2_rt::concat("variant pattern has bindings but target has no destructuring syntax: ".to_string(), name), target.clone()) + } else { + name + }, +} +} } -pub fn emit_match_arm_line( - arm: Rc, - target: RenderTarget, - case_depth: i64, - body_depth: i64, - body_str: String, - guard_str: String, - render_pattern: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_match_arm_line(arm: Rc, target: RenderTarget, case_depth: i64, body_depth: i64, body_str: String, guard_str: String, render_pattern: impl Fn(Rc) -> String + Clone) -> String { { let spec = language_spec(target); - let bs = spec.block_syntax.clone(); - let es = spec.expression_semantics.clone(); - let pat = arm_pattern(arm); - let case_kw = match (*pat.clone()).clone() { - MatchPattern::Wildcard => match es.wildcard_case.clone() { - Some(wc) => wc.clone(), - None => v2_rt::concat(bs.case_keyword.clone(), render_pattern(pat.clone())), - }, - _ => v2_rt::concat(bs.case_keyword.clone(), render_pattern(pat.clone())), - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(make_indent(case_depth), case_kw), guard_str), - ":\n".to_string(), - ), - make_indent(body_depth), - ), - body_str, - ) - } +let bs = spec.block_syntax.clone(); +let es = spec.expression_semantics.clone(); +let pat = arm_pattern(arm); +let case_kw = match (*pat.clone()).clone() { + MatchPattern::Wildcard => match es.wildcard_case.clone() { + Some(wc) => wc.clone(), + None => v2_rt::concat(bs.case_keyword.clone(), render_pattern(pat.clone())), +}, + _ => v2_rt::concat(bs.case_keyword.clone(), render_pattern(pat.clone())), +}; +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(make_indent(case_depth), case_kw), guard_str), ":\n".to_string()), make_indent(body_depth)), body_str) +} } -pub fn emit_arm_guard( - arm: Rc, - target: &RenderTarget, - render_guard_expr: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_arm_guard(arm: Rc, target: &RenderTarget, render_guard_expr: impl Fn(Rc) -> String + Clone) -> String { { let es = language_spec(target.clone()).expression_semantics.clone(); - match arm_guard(&arm) { - Some(g) => match es.guard_prefix.clone() { - Some(prefix) => v2_rt::concat(prefix.clone(), render_guard_expr(g.clone())), - None => emit_error_expr( - "target does not support pattern guards".to_string(), - target.clone(), - ), - }, - None => "".to_string(), - } - } +match arm_guard(&arm) { + Some(g) => match es.guard_prefix.clone() { + Some(prefix) => v2_rt::concat(prefix.clone(), render_guard_expr(g.clone())), + None => emit_error_expr("target does not support pattern guards".to_string(), target.clone()), +}, + None => "".to_string(), +} +} } -pub fn emit_typed_match_unified( - scrutinee_str: String, - arms: Rc>>, - target: &RenderTarget, - depth: i64, - recurse: impl Fn(Rc, i64) -> String + Clone, - render_pattern: impl Fn(Rc) -> String + Clone, - source_indices: Rc>>, -) -> String { +pub fn emit_typed_match_unified(scrutinee_str: String, arms: Rc>>, target: &RenderTarget, depth: i64, recurse: impl Fn(Rc, i64) -> String + Clone, render_pattern: impl Fn(Rc) -> String + Clone, source_indices: Rc>>) -> String { { let bs = language_spec(target.clone()).block_syntax.clone(); - let case_depth = if bs.significant_whitespace.clone() { +let case_depth = if bs.significant_whitespace.clone() { (depth.clone() + 1) } else { depth.clone() }; - let body_depth = (case_depth.clone() + 1); - let arm_strs = Rc::new({ - let mut __result = Vec::new(); - for arm in arms.iter().cloned() { - __result.push({ - let body_str = recurse(arm_body(&arm), body_depth.clone()); - let guard_str = - emit_arm_guard(arm.clone(), &target, |g| recurse(g.clone(), depth.clone())); - emit_match_arm_line( - arm.clone(), - target.clone(), - case_depth.clone(), - body_depth.clone(), - body_str.clone(), - guard_str.clone(), - render_pattern.clone(), - ) - }); - } - __result - }); - let arms_str = arm_strs.join(&"\n".to_string()); - if (bs.block_close.clone().as_str() == "".to_string().as_str()) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(bs.match_keyword.clone(), scrutinee_str), - bs.block_open.clone(), - ), - arms_str, - ) +let body_depth = (case_depth.clone() + 1); +let arm_strs = Rc::new({ let mut __result = Vec::new(); for arm in arms.iter().cloned() { __result.push({ + let body_str = recurse(arm_body(&arm), body_depth.clone()); +let guard_str = emit_arm_guard(arm.clone(), &target, |g| recurse(g.clone(), depth.clone())); +emit_match_arm_line(arm.clone(), target.clone(), case_depth.clone(), body_depth.clone(), body_str.clone(), guard_str.clone(), render_pattern.clone()) +}); } __result }); +let arms_str = arm_strs.join(&"\n".to_string()); +if (bs.block_close.clone().as_str() == "".to_string().as_str()) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(bs.match_keyword.clone(), scrutinee_str), bs.block_open.clone()), arms_str) } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(bs.match_keyword.clone(), scrutinee_str), - bs.block_open.clone(), - ), - arms_str, - ), - "\n".to_string(), - ), - make_indent(depth.clone()), - ), - bs.block_close.clone(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(bs.match_keyword.clone(), scrutinee_str), bs.block_open.clone()), arms_str), "\n".to_string()), make_indent(depth.clone())), bs.block_close.clone()) } - } +} } -pub fn emit_field_access_unified( - base_str: String, - field: String, - summary: Option>, - target: &RenderTarget, -) -> String { +pub fn emit_field_access_unified(base_str: String, field: String, summary: Option>, target: &RenderTarget) -> String { { let ts = language_spec(target.clone()).tuple_syntax.clone(); - match summary { - Some(fs) => match fs.access_style.clone() { - FieldAccessStyle::TupleFirst => v2_rt::concat(base_str, ts.first_accessor.clone()), - FieldAccessStyle::TupleSecond => { - v2_rt::concat(base_str, ts.second_accessor.clone()) - } - _ => v2_rt::concat( - v2_rt::concat(base_str, ".".to_string()), - emit_export_ident(field, &target), - ), - }, - None => v2_rt::concat( - v2_rt::concat(base_str, ".".to_string()), - emit_export_ident(field, &target), - ), - } - } +match summary { + Some(fs) => match fs.access_style.clone() { + FieldAccessStyle::TupleFirst => v2_rt::concat(base_str, ts.first_accessor.clone()), + FieldAccessStyle::TupleSecond => v2_rt::concat(base_str, ts.second_accessor.clone()), + _ => v2_rt::concat(v2_rt::concat(base_str, ".".to_string()), emit_export_ident(field, &target)), +}, + None => v2_rt::concat(v2_rt::concat(base_str, ".".to_string()), emit_export_ident(field, &target)), +} +} } -pub fn emit_unified_typed_expr( - texpr: Rc, - target: &RenderTarget, - registry: Rc>>, - scope: &Rc, - depth: i64, - fuel: i64, - render_pattern: impl Fn(Rc) -> String + Clone, -) -> String { +pub fn emit_unified_typed_expr(texpr: Rc, target: &RenderTarget, registry: Rc>>, scope: &Rc, depth: i64, fuel: i64, render_pattern: impl Fn(Rc) -> String + Clone) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let si = scope.type_env.clone().source_indices.clone(); - let spec = language_spec(target.clone()); - emit_shared_expr( - &texpr, - &target, - si.clone(), - |result| result.clone(), - |child| { - emit_unified_typed_expr( - child.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - (fuel.clone() - 1), - render_pattern.clone(), - ) - }, - |expr| emit_expr_var_shared(expr.clone(), target.clone(), si.clone()), - |expr| { + { + let si = scope.type_env.clone().source_indices.clone(); +let spec = language_spec(target.clone()); +emit_shared_expr(&texpr, &target, si.clone(), |result| result.clone(), |child| emit_unified_typed_expr(child.clone(), &target, registry.clone(), &scope, depth.clone(), (fuel.clone() - 1), render_pattern.clone()), |expr| emit_expr_var_shared(expr.clone(), target.clone(), si.clone()), |expr| { let fa_si = scope.type_env.clone().source_indices.clone(); - if is_typed_service_call_receiver(&expr, fa_si.clone()) { +if is_typed_service_call_receiver(&expr, fa_si.clone()) { match extract_typed_service_name(&expr, &fa_si) { - Some(svc_name) => service_var_name(svc_name.clone()), - None => { - let base_str = emit_unified_typed_expr( - field_access_base(expr.clone()), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ); - emit_field_access_unified( - base_str.clone(), - field_access_field_at(expr.clone(), fa_si.clone()), - expr_field_access_summary(expr.clone()), - &target, - ) - } - } + Some(svc_name) => service_var_name(svc_name.clone()), + None => { + let base_str = emit_unified_typed_expr(field_access_base(expr.clone()), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()); +emit_field_access_unified(base_str.clone(), field_access_field_at(expr.clone(), fa_si.clone()), expr_field_access_summary(expr.clone()), &target) +}, +} } else { { - let base_str = emit_unified_typed_expr( - field_access_base(expr.clone()), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ); - emit_field_access_unified( - base_str.clone(), - field_access_field_at(expr.clone(), fa_si.clone()), - expr_field_access_summary(expr.clone()), - &target, - ) - } - } - }, - |expr| { - emit_typed_call_unified( - &expr_call_func_at(expr.clone(), si.clone()), - expr.children.clone(), - &target, - registry.clone(), - scope.clone(), - |n| { - emit_unified_typed_expr( - n.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - ) - }, - |expr| { - emit_typed_method_call_unified( - &method_receiver(expr.clone()), - expr_method_name_at(expr.clone(), si.clone()), - &method_arg_nodes(expr.clone()), - &expr_method_call_semantics(expr.clone()), - &target, - registry.clone(), - scope.clone(), - depth.clone(), - |n| { - emit_unified_typed_expr( - n.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - ) - }, - |expr| { - let scrut_str = emit_unified_typed_expr( - match_scrutinee(expr.clone()), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ); - emit_typed_match_unified( - scrut_str.clone(), - match_arm_nodes(expr.clone()), - &target, - depth.clone(), - |node, d| { - emit_unified_typed_expr( - node.clone(), - &target, - registry.clone(), - &scope, - d.clone(), - 1024, - render_pattern.clone(), - ) - }, - render_pattern.clone(), - si.clone(), - ) - }, - |expr| { - let cond_str = emit_unified_typed_expr( - if_condition(expr.clone()), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ); - let if_result_type = match spec.expression_semantics.clone().if_value_form.clone() { - IfValueForm::IfStatement => Some(resolved_type(expr.clone())), - _ => None, + let base_str = emit_unified_typed_expr(field_access_base(expr.clone()), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()); +emit_field_access_unified(base_str.clone(), field_access_field_at(expr.clone(), fa_si.clone()), expr_field_access_summary(expr.clone()), &target) +} + } +}, |expr| emit_typed_call_unified(&expr_call_func_at(expr.clone(), si.clone()), expr.children.clone(), &target, registry.clone(), scope.clone(), |n| emit_unified_typed_expr(n.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone())), |expr| emit_typed_method_call_unified(&method_receiver(expr.clone()), expr_method_name_at(expr.clone(), si.clone()), &method_arg_nodes(expr.clone()), &expr_method_call_semantics(expr.clone()), &target, registry.clone(), scope.clone(), depth.clone(), |n| emit_unified_typed_expr(n.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone())), |expr| { + let scrut_str = emit_unified_typed_expr(match_scrutinee(expr.clone()), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()); +emit_typed_match_unified(scrut_str.clone(), match_arm_nodes(expr.clone()), &target, depth.clone(), |node, d| emit_unified_typed_expr(node.clone(), &target, registry.clone(), &scope, d.clone(), 1024, render_pattern.clone()), render_pattern.clone(), si.clone()) +}, |expr| { + let cond_str = emit_unified_typed_expr(if_condition(expr.clone()), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()); +let if_result_type = match spec.expression_semantics.clone().if_value_form.clone() { + IfValueForm::IfStatement => Some(resolved_type(expr.clone())), + _ => None, +}; +emit_typed_if_shared(cond_str.clone(), &if_then_branch(expr.clone()), if_else_branch(expr.clone()), if_result_type.clone(), depth.clone(), &target, si.clone(), |node, d| emit_unified_typed_expr(node.clone(), &target, registry.clone(), &scope, d.clone(), 1024, render_pattern.clone())) +}, |expr| { + let val_str = emit_unified_typed_expr(let_value(expr.clone()), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()); +emit_typed_let_shared(&let_binding_name_at(expr.clone(), si.clone()), val_str.clone(), let_body(expr.clone()), target.clone(), |bd, sc| emit_unified_typed_expr(bd.clone(), &target, registry.clone(), &sc, depth.clone(), 1024, render_pattern.clone()), scope.clone(), let_value(expr.clone())) +}, |expr| emit_typed_record_lit_unified(record_lit_type_name_at(expr.clone(), si.clone()), &expr.children.clone(), &target, si.clone(), |n| emit_unified_typed_expr(n.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone())), |expr| emit_typed_string_interp_unified(&extract_string_interp_parts(expr.clone()), target.clone(), |e| emit_unified_typed_expr(e.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone())), |expr| emit_typed_block_join(expr.children.clone(), scope.clone(), depth.clone(), |remaining, sc, d| { + let prepend = if spec.block_syntax.clone().significant_whitespace.clone() { + false + } else { + true }; - emit_typed_if_shared( - cond_str.clone(), - &if_then_branch(expr.clone()), - if_else_branch(expr.clone()), - if_result_type.clone(), - depth.clone(), - &target, - si.clone(), - |node, d| { - emit_unified_typed_expr( - node.clone(), - &target, - registry.clone(), - &scope, - d.clone(), - 1024, - render_pattern.clone(), - ) - }, - ) - }, - |expr| { - let val_str = emit_unified_typed_expr( - let_value(expr.clone()), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ); - emit_typed_let_shared( - &let_binding_name_at(expr.clone(), si.clone()), - val_str.clone(), - let_body(expr.clone()), - target.clone(), - |bd, sc| { - emit_unified_typed_expr( - bd.clone(), - &target, - registry.clone(), - &sc, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - scope.clone(), - let_value(expr.clone()), - ) - }, - |expr| { - emit_typed_record_lit_unified( - record_lit_type_name_at(expr.clone(), si.clone()), - &expr.children.clone(), - &target, - si.clone(), - |n| { - emit_unified_typed_expr( - n.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - ) - }, - |expr| { - emit_typed_string_interp_unified( - &extract_string_interp_parts(expr.clone()), - target.clone(), - |e| { - emit_unified_typed_expr( - e.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - ) - }, - |expr| { - emit_typed_block_join( - expr.children.clone(), - scope.clone(), - depth.clone(), - |remaining, sc, d| { - let prepend = if spec.block_syntax.clone().significant_whitespace.clone() { - false - } else { - true - }; - emit_block_stmts_shared( - remaining.clone(), - Rc::new(vec![]), - sc.clone(), - d.clone(), - prepend.clone(), - |stmt, s, dd| { - emit_unified_typed_expr( - stmt.clone(), - &target, - registry.clone(), - &s, - dd.clone(), - 1024, - render_pattern.clone(), - ) - }, - ) - }, - ) - }, - |expr| { - emit_typed_cast_shared( - &cast_expr(expr.clone()), - cast_target(expr.clone()), - &target, - |child| { - emit_unified_typed_expr( - child.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - &si, - ) - }, - |expr| { - emit_typed_for_each_shared( - &foreach_variable_at(expr.clone(), si.clone()), - &foreach_collection(expr.clone()), - foreach_body(expr.clone()), - &target, - depth.clone(), - si.clone(), - |child, s, d| { - emit_unified_typed_expr( - child.clone(), - &target, - registry.clone(), - &s, - d.clone(), - 1024, - render_pattern.clone(), - ) - }, - &scope, - ) - }, - |expr| { - emit_typed_index_shared( - &index_base(expr.clone()), - index_expr(expr.clone()), - &target, - |child| { - emit_unified_typed_expr( - child.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - &si, - ) - }, - |expr| { - emit_typed_slice_shared( - &slice_base(expr.clone()), - slice_start(expr.clone()), - slice_end(expr.clone()), - &target, - |child| { - emit_unified_typed_expr( - child.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - 1024, - render_pattern.clone(), - ) - }, - si.clone(), - ) - }, - |expr| { - emit_default_bin_op( - &expr, - target.clone(), - si.clone(), - |child| { - emit_unified_typed_expr( - child.clone(), - &target, - registry.clone(), - &scope, - depth.clone(), - (fuel.clone() - 1), - render_pattern.clone(), - ) - }, - |result| result.clone(), - ) - }, - ) +emit_block_stmts_shared(remaining.clone(), Rc::new(vec![]), sc.clone(), d.clone(), prepend.clone(), |stmt, s, dd| emit_unified_typed_expr(stmt.clone(), &target, registry.clone(), &s, dd.clone(), 1024, render_pattern.clone())) +}), |expr| emit_typed_cast_shared(&cast_expr(expr.clone()), cast_target(expr.clone()), &target, |child| emit_unified_typed_expr(child.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()), &si), |expr| emit_typed_for_each_shared(&foreach_variable_at(expr.clone(), si.clone()), &foreach_collection(expr.clone()), foreach_body(expr.clone()), &target, depth.clone(), si.clone(), |child, s, d| emit_unified_typed_expr(child.clone(), &target, registry.clone(), &s, d.clone(), 1024, render_pattern.clone()), &scope), |expr| emit_typed_index_shared(&index_base(expr.clone()), index_expr(expr.clone()), &target, |child| emit_unified_typed_expr(child.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()), &si), |expr| emit_typed_slice_shared(&slice_base(expr.clone()), slice_start(expr.clone()), slice_end(expr.clone()), &target, |child| emit_unified_typed_expr(child.clone(), &target, registry.clone(), &scope, depth.clone(), 1024, render_pattern.clone()), si.clone()), |expr| emit_default_bin_op(&expr, target.clone(), si.clone(), |child| emit_unified_typed_expr(child.clone(), &target, registry.clone(), &scope, depth.clone(), (fuel.clone() - 1), render_pattern.clone()), |result| result.clone())) +} }) } -pub fn is_tco_identity_passthrough( - arg_val: &Rc, - param_name: String, - si: Rc>>, -) -> bool { +pub fn is_tco_identity_passthrough(arg_val: &Rc, param_name: String, si: Rc>>) -> bool { match (*arg_val.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(arg_val.clone(), si).as_str() == param_name.as_str()) - } - _ => false, - } + ExprData::ExprVar { .. } => (expr_var_name_at(arg_val.clone(), si).as_str() == param_name.as_str()), + _ => false, +} } -pub fn emit_typed_tco_reassign_shared( - args: Rc>>, - params: Rc>>, - target: &RenderTarget, - recurse: impl Fn(Rc) -> String + Clone, - source_indices: Rc>>, -) -> String { +pub fn emit_typed_tco_reassign_shared(args: Rc>>, params: Rc>>, target: &RenderTarget, recurse: impl Fn(Rc) -> String + Clone, source_indices: Rc>>) -> String { { - let arg_values = Rc::new({ - let mut __result = Vec::new(); - for a in args.iter().cloned() { - __result.push(arg_value(&a)); - } - __result - }); - let pairs = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - params - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if { - let pname = param_node_name_at(pair.1.clone(), source_indices.clone()); - let av = match arg_values.clone().get(pair.0.clone() as usize).cloned() { - Some(v) => v.clone(), - None => pair.1.clone(), - }; - !is_tco_identity_passthrough(&av, pname.clone(), source_indices.clone()) - } { - __result.push(pair); - } - } - __result - }); - let filtered_arg_values = Rc::new({ - let mut __result = Vec::new(); - for pair in pairs.clone().iter().cloned() { - __result.push( - match arg_values.clone().get(pair.0.clone() as usize).cloned() { - Some(v) => v.clone(), - None => pair.1.clone(), - }, - ); - } - __result - }); - let ordered_args = Rc::new({ - let mut __result = Vec::new(); - for av in filtered_arg_values.iter().cloned() { - __result.push(recurse(av.clone())); - } - __result - }); - let param_names = Rc::new({ - let mut __result = Vec::new(); - for pair in pairs.clone().iter().cloned() { - __result.push(emit_ident( - param_node_name_at(pair.1.clone(), source_indices.clone()), - target.clone(), - )); - } - __result - }); - shared_tco_reassign(ordered_args, param_names, &language_spec(target.clone())) - } + let arg_values = Rc::new({ let mut __result = Vec::new(); for a in args.iter().cloned() { __result.push(arg_value(&a)); } __result }); +let pairs = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(params.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if { + let pname = param_node_name_at(pair.1.clone(), source_indices.clone()); +let av = match arg_values.clone().get(pair.0.clone() as usize).cloned() { + Some(v) => v.clone(), + None => pair.1.clone(), +}; +!is_tco_identity_passthrough(&av, pname.clone(), source_indices.clone()) +} { __result.push(pair); } } __result }); +let filtered_arg_values = Rc::new({ let mut __result = Vec::new(); for pair in pairs.clone().iter().cloned() { __result.push(match arg_values.clone().get(pair.0.clone() as usize).cloned() { + Some(v) => v.clone(), + None => pair.1.clone(), +}); } __result }); +let ordered_args = Rc::new({ let mut __result = Vec::new(); for av in filtered_arg_values.iter().cloned() { __result.push(recurse(av.clone())); } __result }); +let param_names = Rc::new({ let mut __result = Vec::new(); for pair in pairs.clone().iter().cloned() { __result.push(emit_ident(param_node_name_at(pair.1.clone(), source_indices.clone()), target.clone())); } __result }); +shared_tco_reassign(ordered_args, param_names, &language_spec(target.clone())) +} } pub fn seed_bindings(key: String, value: String) -> Rc> { diff --git a/src/v2/stage0/src/v2_compiler_emit_go.rs b/src/v2/stage0/src/v2_compiler_emit_go.rs index c84b2b03217..5dfc39fc302 100644 --- a/src/v2/stage0/src/v2_compiler_emit_go.rs +++ b/src/v2/stage0/src/v2_compiler_emit_go.rs @@ -1,683 +1,220 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.emit_go -pub use crate::extdeps_languages_go_emit::{go_reserved, go_reserved_escape_suffix}; -pub use crate::std_induction::SubValueRelation; -use crate::std_induction::SubValueRelation::SubValueUnknown; -pub use crate::v2_compiler_artifact::RenderTarget; -use crate::v2_compiler_artifact::RenderTarget::Go; -pub use crate::v2_compiler_emit::{ - apply_named_template, apply_naming_case, apply_type_template1, apply_type_template2, - apply_type_template3, capitalize_first, compute_service_fields, effective_operation_transport, - emit_algebra_method_template, emit_bin_op_symbol, emit_container, emit_default_bin_op, - emit_error_expr, emit_expr_field_access_shared, emit_expr_var_shared, emit_ident, - emit_inferred_shared, emit_keyword, emit_lambda, emit_lambda_params, emit_let_binding, - emit_list_lit_expr, emit_literal, emit_map_type, emit_node_type, emit_null_coalesce, - emit_param_shared, emit_params_shared, emit_return, emit_shared_expr, emit_simple_expr, - emit_string_literal, emit_tco_unified, emit_typed_block_join, emit_typed_call_unified, - emit_typed_cast_shared, emit_typed_first_arg_shared, emit_typed_for_each_shared, - emit_typed_if_shared, emit_typed_index_shared, emit_typed_let_shared, emit_typed_match_unified, - emit_typed_method_call_unified, emit_typed_record_lit_unified, emit_typed_slice_shared, - emit_typed_string_interp_unified, emit_unary_op, emit_unified_init_block_stmts, - emit_unified_operation_method, emit_unified_pattern, emit_unified_service_def, - emit_unified_transport_dispatch, emit_unified_typed_expr, emit_unified_typed_func_body, - empty_emit_scope, escape_go_interp_text, escape_json_string, escape_string_literal_body, - extract_string_interp_parts, extract_test_projections, has_nested_records_node, - is_data_def_item, is_function_item, is_null_coalesce, is_resource_def_item, - is_service_def_item, is_service_item, is_tco_eligible, is_type_alias_item, - is_type_alias_return_node, is_type_decl_item, is_type_def_item, is_upper, language_spec, - lookup_item, make_indent, module_emit_scope, module_to_filename, order_typed_call_args, - sanitize_service_name, scope_after_expr, seed_bindings, service_fallback_transport, - service_field_decls, service_var_name, test_file_path, test_function_name, to_lower_char, - to_screaming_snake, to_snake, to_string, to_string_helper, to_upper_char, - typed_named_arg_matches, unique_strings, BlockEmitState, EmitResult, InterpPart, - ServiceFieldSet, TestProjection, -}; -pub use crate::v2_compiler_infer::{build_params_scope, expr_span, extend_scope, InferScope}; -pub use crate::v2_compiler_infer_env::{authored_name, TypeBinding, TypeEnv}; -pub use crate::v2_compiler_infer_items::{ItemInfo, ResolvedGraph, TypedModule}; -pub use crate::v2_compiler_infer_service::{ - extract_typed_service_name, is_typed_service_call_receiver, -}; -pub use crate::v2_compiler_infer_sigs::{ResolvedFuncEnv, ResolvedFuncSig}; -pub use crate::v2_compiler_infer_types::{ - node_is_keyed_collection, normalize_access_type_node, resolved_type, -}; -use crate::v2_compiler_languages::VisibilitySpec::CaseVisibility; -pub use crate::v2_compiler_languages::{ - is_string_like, scaffold_for_target, test_conventions_for_target, ItemKeywords, - TestConventions, VisibilitySpec, -}; +use std::collections::HashMap; +use std::rc::Rc; use crate::v2_rt; -use crate::v2_std_core::BinOp::NullCoalesce; -use crate::v2_std_core::Cardinality::CardOptional; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, InferredNode, VarBindingKind, import_is_all, module_imports, module_items, param_node_type_expr, authored_name_at, NewlineIndex, expr_var_name_at, expr_call_func_at, expr_method_name_at, let_binding_name_at, param_node_name_at, resource_use_name_at, MatchPattern, LiteralValue, TextFile, SourceSpan, resource_use_resource, BinOp, UnaryOpKind, StringPart, DeclaredFuncSig, transport_has_auth, transport_auth_header_name, transport_headers, transport_env, ExprData, make_expr_node, MethodSemantics, FieldSummary, FieldAccessStyle, arg_value, arm_body, arm_pattern, arm_guard, field_init_node_name_at, field_init_node_value, if_condition, if_then_branch, if_else_branch, match_scrutinee, match_arm_nodes, let_value, let_body, field_access_base, field_access_field_at, method_receiver, expr_field_access_summary, expr_method_call_semantics, record_lit_type_name_at, lambda_body, cast_expr, cast_target, return_value, foreach_variable_at, foreach_collection, foreach_body, method_arg_nodes, index_base, index_expr, slice_base, slice_start, slice_end, with_required_cardinality, Connective, is_rest_transport, is_shell_transport, is_file_transport, Cardinality}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError}; +use crate::v2_std_core::VarBindingKind::{FunctionValueBinding}; +use crate::v2_std_core::BinOp::{NullCoalesce}; +use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprError, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit, ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp, ExprBlock, ExprCast, ExprForEach, ExprIndex, ExprSlice, ExprReturn}; +use crate::v2_std_core::MethodSemantics::{PlainMethodSemantics, AlgebraMethodSemantics, ServiceMethodSemantics}; +use crate::v2_std_core::StringPart::{Text, Interpolation}; +use crate::v2_std_core::FieldAccessStyle::{StoredField, EnumAccessor, OptionalUnwrap, TupleFirst, TupleSecond}; use crate::v2_std_core::Connective::{Conj, Disj}; -use crate::v2_std_core::ExprData::{ - ExprBinOp, ExprBlock, ExprCall, ExprCast, ExprError, ExprFieldAccess, ExprForEach, ExprIf, - ExprIndex, ExprLambda, ExprLet, ExprListLit, ExprLiteral, ExprMatch, ExprMethodCall, - ExprRecordLit, ExprReturn, ExprSlice, ExprStringInterp, ExprUnaryOp, ExprVar, NoExprData, -}; -use crate::v2_std_core::FieldAccessStyle::{ - EnumAccessor, OptionalUnwrap, StoredField, TupleFirst, TupleSecond, -}; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved}; -use crate::v2_std_core::LiteralValue::*; +use crate::v2_std_core::Cardinality::{CardOptional}; use crate::v2_std_core::MatchPattern::*; -use crate::v2_std_core::MethodSemantics::{ - AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics, -}; -use crate::v2_std_core::StringPart::{Interpolation, Text}; +use crate::v2_std_core::LiteralValue::*; use crate::v2_std_core::UnaryOpKind::*; -use crate::v2_std_core::VarBindingKind::FunctionValueBinding; -pub use crate::v2_std_core::{ - arg_value, arm_body, arm_guard, arm_pattern, authored_name_at, cast_expr, cast_target, - expr_call_func_at, expr_field_access_summary, expr_method_call_semantics, expr_method_name_at, - expr_var_name_at, field_access_base, field_access_field_at, field_init_node_name_at, - field_init_node_value, foreach_body, foreach_collection, foreach_variable_at, if_condition, - if_else_branch, if_then_branch, import_is_all, index_base, index_expr, is_file_transport, - is_rest_transport, is_shell_transport, lambda_body, let_binding_name_at, let_body, let_value, - make_expr_node, match_arm_nodes, match_scrutinee, method_arg_nodes, method_receiver, - module_imports, module_items, param_node_name_at, param_node_type_expr, - record_lit_type_name_at, resource_use_name_at, resource_use_resource, return_value, slice_base, - slice_end, slice_start, transport_auth_header_name, transport_env, transport_has_auth, - transport_headers, with_required_cardinality, BinOp, Cardinality, Connective, DeclaredFuncSig, - ExprData, FieldAccessStyle, FieldSummary, InferredNode, LiteralValue, MatchPattern, - MethodSemantics, NewlineIndex, Node, SourceSpan, StringPart, TextFile, UnaryOpKind, - VarBindingKind, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +pub use crate::v2_compiler_artifact::{RenderTarget}; +use crate::v2_compiler_artifact::RenderTarget::{Go}; +pub use crate::extdeps_languages_go_emit::{go_reserved, go_reserved_escape_suffix}; +pub use crate::v2_compiler_languages::{scaffold_for_target, TestConventions, ItemKeywords, test_conventions_for_target, is_string_like, VisibilitySpec}; +use crate::v2_compiler_languages::VisibilitySpec::{CaseVisibility}; +pub use crate::v2_compiler_infer_env::{TypeEnv, TypeBinding, authored_name}; +pub use crate::v2_compiler_infer_types::{resolved_type, normalize_access_type_node, node_is_keyed_collection}; +pub use crate::v2_compiler_infer_sigs::{ResolvedFuncSig, ResolvedFuncEnv}; +pub use crate::v2_compiler_infer_items::{ResolvedGraph, TypedModule, ItemInfo}; +pub use crate::v2_compiler_infer_service::{is_typed_service_call_receiver, extract_typed_service_name}; +pub use crate::v2_compiler_infer::{InferScope, build_params_scope, extend_scope, expr_span}; +pub use crate::std_induction::{SubValueRelation}; +use crate::std_induction::SubValueRelation::{SubValueUnknown}; +pub use crate::v2_compiler_emit::{EmitResult, BlockEmitState, InterpPart, TestProjection, emit_literal, emit_bin_op_symbol, emit_keyword, emit_container, emit_map_type, emit_node_type, emit_ident, emit_let_binding, emit_simple_expr, emit_unary_op, emit_lambda, emit_error_expr, emit_return, emit_lambda_params, emit_list_lit_expr, emit_shared_expr, emit_default_bin_op, emit_string_literal, escape_go_interp_text, escape_string_literal_body, empty_emit_scope, module_emit_scope, scope_after_expr, lookup_item, unique_strings, escape_json_string, module_to_filename, make_indent, to_string, to_string_helper, to_snake, to_screaming_snake, is_upper, to_lower_char, to_upper_char, capitalize_first, sanitize_service_name, service_var_name, test_function_name, apply_type_template1, apply_type_template2, apply_type_template3, apply_named_template, language_spec, is_null_coalesce, emit_null_coalesce, is_type_alias_return_node, has_nested_records_node, is_service_item, typed_named_arg_matches, order_typed_call_args, 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, extract_test_projections, is_tco_eligible, service_fallback_transport, effective_operation_transport, ServiceFieldSet, compute_service_fields, service_field_decls, seed_bindings, emit_expr_var_shared, emit_expr_field_access_shared, extract_string_interp_parts, emit_typed_cast_shared, emit_typed_for_each_shared, emit_typed_index_shared, emit_typed_slice_shared, emit_unified_init_block_stmts, emit_typed_if_shared, emit_typed_let_shared, emit_param_shared, emit_params_shared, apply_naming_case, emit_inferred_shared, emit_typed_block_join, emit_typed_first_arg_shared, emit_algebra_method_template, emit_typed_string_interp_unified, emit_typed_record_lit_unified, emit_typed_call_unified, emit_typed_method_call_unified, emit_typed_match_unified, emit_unified_typed_expr, emit_tco_unified, emit_unified_pattern, test_file_path, emit_unified_typed_func_body, emit_unified_service_def, emit_unified_operation_method, emit_unified_transport_dispatch}; pub fn emit_go(typed: &Rc) -> Rc { { let registry = typed.item_registry.clone(); - let test_projections = extract_test_projections(typed.clone()); - let module_files = Rc::new({ - let mut __result = Vec::new(); - for tm in typed.modules.clone().iter().cloned() { - __result.push(emit_go_module(&tm, registry.clone())); - } - __result - }); - let test_files = Rc::new({ - let mut __result = Vec::new(); - for f in Rc::new({ - let mut __result = Vec::new(); - for tm in typed.modules.clone().iter().cloned() { - __result.push(emit_go_test_file( - &authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ), - &Rc::new({ - let mut __result = Vec::new(); - for p in test_projections.clone().iter().cloned() { - if (p.module_name.clone().as_str() - == authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ) - .as_str()) - { - __result.push(p); - } - } - __result - }), - )); - } - __result - }) - .iter() - .cloned() - { - if (f.path.clone().as_str() != "".to_string().as_str()) { - __result.push(f); - } - } - __result - }); - let go_mod = emit_go_mod("generated".to_string()); - let files = v2_rt::concat( - v2_rt::concat(Rc::new(vec![go_mod]), module_files), - test_files, - ); - Rc::new(EmitResult { - files: files, - diagnostics: Rc::new(vec![]), - }) - } +let test_projections = extract_test_projections(typed.clone()); +let module_files = Rc::new({ let mut __result = Vec::new(); for tm in typed.modules.clone().iter().cloned() { __result.push(emit_go_module(&tm, registry.clone())); } __result }); +let test_files = Rc::new({ let mut __result = Vec::new(); for f in Rc::new({ let mut __result = Vec::new(); for tm in typed.modules.clone().iter().cloned() { __result.push(emit_go_test_file(&authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()), &Rc::new({ let mut __result = Vec::new(); for p in test_projections.clone().iter().cloned() { if (p.module_name.clone().as_str() == authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()).as_str()) { __result.push(p); } } __result }))); } __result }).iter().cloned() { if (f.path.clone().as_str() != "".to_string().as_str()) { __result.push(f); } } __result }); +let go_mod = emit_go_mod("generated".to_string()); +let files = v2_rt::concat(v2_rt::concat(Rc::new(vec![go_mod]), module_files), test_files); +Rc::new(EmitResult { + files: files, + diagnostics: Rc::new(vec![]), +}) +} } pub fn emit_go_mod(module_name: String) -> Rc { { let manifest_path = match scaffold_for_target(RenderTarget::Go).manifest_file.clone() { - Some(path) => path.clone(), - None => "go.mod".to_string(), - }; - let content = v2_rt::concat( - v2_rt::concat("module ".to_string(), module_name), - "\n\ngo 1.21\n".to_string(), - ); - Rc::new(TextFile { - path: manifest_path, - content: content, - }) - } + Some(path) => path.clone(), + None => "go.mod".to_string(), +}; +let content = v2_rt::concat(v2_rt::concat("module ".to_string(), module_name), "\n\ngo 1.21\n".to_string()); +Rc::new(TextFile { + path: manifest_path, + content: content, +}) +} } -pub fn go_mock_expr_uses_fmt( - expr: Rc, - source_indices: Rc>>, -) -> bool { +pub fn go_mock_expr_uses_fmt(expr: Rc, source_indices: Rc>>) -> bool { { let rendered = emit_simple_expr(&expr, &RenderTarget::Go, &source_indices); - ((Rc::new( - rendered - .split(&"fmt.Sprintf(".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .len() as i64) - > 1) - } +((Rc::new(rendered.split(&"fmt.Sprintf(".to_string()).map(|s| s.to_string()).collect::>()).len() as i64) > 1) +} } pub fn go_test_import_block(projections: Rc>>) -> String { { - let needs_fmt = { - let mut __found = false; - for p in projections.iter().cloned() { - if { - let mut __found = false; - for mp in p.mock_field_inits.clone().iter().cloned() { - if go_mock_expr_uses_fmt( - field_init_node_value(&mp), - p.source_indices.clone(), - ) { - __found = true; - break; - } - } - __found - } { - __found = true; - break; - } - } - __found - }; - if needs_fmt { + let needs_fmt = { let mut __found = false; for p in projections.iter().cloned() { if { let mut __found = false; for mp in p.mock_field_inits.clone().iter().cloned() { if go_mock_expr_uses_fmt(field_init_node_value(&mp), p.source_indices.clone()) { __found = true; break; } } __found } { __found = true; break; } } __found }; +if needs_fmt { "import (\n\t\"fmt\"\n\t\"testing\"\n)\n\n".to_string() } else { "import \"testing\"\n\n".to_string() } - } +} } pub fn go_test_signature_comment(projection: &Rc) -> String { { - let params_str = Rc::new({ - let mut __result = Vec::new(); - for p in projection.params.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - param_node_name_at(p.clone(), projection.source_indices.clone()), - " ".to_string(), - ), - emit_node_type( - param_node_type_expr(&p), - RenderTarget::Go, - projection.source_indices.clone(), - ), - )); - } - __result - }) - .join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "// Signature: ".to_string(), - sanitize_service_name(projection.service_name.clone()), - ), - ".".to_string(), - ), - projection.operation_name.clone(), - ), - "(".to_string(), - ), - params_str, - ), - ") ".to_string(), - ), - emit_node_type( - projection.inferred.clone(), - RenderTarget::Go, - projection.source_indices.clone(), - ), - ) - } + let params_str = Rc::new({ let mut __result = Vec::new(); for p in projection.params.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(param_node_name_at(p.clone(), projection.source_indices.clone()), " ".to_string()), emit_node_type(param_node_type_expr(&p), RenderTarget::Go, projection.source_indices.clone()))); } __result }).join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Signature: ".to_string(), sanitize_service_name(projection.service_name.clone())), ".".to_string()), projection.operation_name.clone()), "(".to_string()), params_str), ") ".to_string()), emit_node_type(projection.inferred.clone(), RenderTarget::Go, projection.source_indices.clone())) +} } -pub fn emit_go_test_file( - module_name: &String, - projections: &Rc>>, -) -> Rc { +pub fn emit_go_test_file(module_name: &String, projections: &Rc>>) -> Rc { if ((projections.clone().len() as i64) == 0) { Rc::new(TextFile { - path: "".to_string(), - content: "".to_string(), - }) + path: "".to_string(), + content: "".to_string(), +}) } else { { let package_name = go_package_name(module_name.clone()); - let tests_str = Rc::new({ - let mut __result = Vec::new(); - for p in projections.clone().iter().cloned() { - __result.push(emit_go_operation_test(&p, 0)); - } - __result - }) - .join(&"\n\n".to_string()); - let content = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "// Generated tests -- do not edit.\n" - .to_string(), - "// Source module: ".to_string(), - ), - module_name.clone(), - ), - "\n\n".to_string(), - ), - language_spec(RenderTarget::Go) - .items - .clone() - .module_keyword - .clone(), - ), - " ".to_string(), - ), - package_name, - ), - "\n\n".to_string(), - ), - go_test_import_block(projections.clone()), - ), - tests_str, - ), - "\n".to_string(), - ); - Rc::new(TextFile { - path: test_file_path(module_name.clone(), &RenderTarget::Go), - content: content, - }) - } +let tests_str = Rc::new({ let mut __result = Vec::new(); for p in projections.clone().iter().cloned() { __result.push(emit_go_operation_test(&p, 0)); } __result }).join(&"\n\n".to_string()); +let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Generated tests -- do not edit.\n".to_string(), "// Source module: ".to_string()), module_name.clone()), "\n\n".to_string()), language_spec(RenderTarget::Go).items.clone().module_keyword.clone()), " ".to_string()), package_name), "\n\n".to_string()), go_test_import_block(projections.clone())), tests_str), "\n".to_string()); +Rc::new(TextFile { + path: test_file_path(module_name.clone(), &RenderTarget::Go), + content: content, +}) +} } } pub fn emit_go_operation_test(projection: &Rc, depth: i64) -> String { { let test_name = test_function_name(&projection, RenderTarget::Go); - let struct_name = sanitize_service_name(projection.service_name.clone()); - let indent = make_indent((depth.clone() + 1)); - let mock_setup = Rc::new({ - let mut __result = Vec::new(); - for mp in projection.mock_field_inits.clone().iter().cloned() { - __result.push(emit_go_mock_prop_setup( - &mp, - (depth.clone() + 1), - &projection.source_indices.clone(), - )); - } - __result - }) - .join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec( - RenderTarget::Go, - ) - .items - .clone() - .func_keyword - .clone(), - " ".to_string(), - ), - test_name, - ), - "(t *testing.T) {\n".to_string(), - ), - indent.clone(), - ), - go_test_signature_comment(&projection), - ), - "\n".to_string(), - ), - indent.clone(), - ), - "_ = ".to_string(), - ), - struct_name, - ), - "{}\n".to_string(), - ), - indent.clone(), - ), - mock_setup, - ), - "\n".to_string(), - ), - indent.clone(), - ), - "// TODO: add dry-run support to Go service emission for full invocation tests\n" - .to_string(), - ), - "}".to_string(), - ) - } +let struct_name = sanitize_service_name(projection.service_name.clone()); +let indent = make_indent((depth.clone() + 1)); +let mock_setup = Rc::new({ let mut __result = Vec::new(); for mp in projection.mock_field_inits.clone().iter().cloned() { __result.push(emit_go_mock_prop_setup(&mp, (depth.clone() + 1), &projection.source_indices.clone())); } __result }).join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().func_keyword.clone(), " ".to_string()), test_name), "(t *testing.T) {\n".to_string()), indent.clone()), go_test_signature_comment(&projection)), "\n".to_string()), indent.clone()), "_ = ".to_string()), struct_name), "{}\n".to_string()), indent.clone()), mock_setup), "\n".to_string()), indent.clone()), "// TODO: add dry-run support to Go service emission for full invocation tests\n".to_string()), "}".to_string()) +} } -pub fn emit_go_mock_prop_setup( - mock_prop: &Rc, - depth: i64, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - emit_ident( - field_init_node_name_at(mock_prop.clone(), source_indices.clone()), - RenderTarget::Go, - ), - " := ".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&mock_prop), - &RenderTarget::Go, - &source_indices, - ), - ) +pub fn emit_go_mock_prop_setup(mock_prop: &Rc, depth: i64, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(emit_ident(field_init_node_name_at(mock_prop.clone(), source_indices.clone()), RenderTarget::Go), " := ".to_string()), emit_simple_expr(&field_init_node_value(&mock_prop), &RenderTarget::Go, &source_indices)) } -pub fn emit_go_module( - typed_module: &Rc, - registry: Rc>>, -) -> Rc { +pub fn emit_go_module(typed_module: &Rc, registry: Rc>>) -> Rc { { let m = typed_module.module.clone(); - let scope = module_emit_scope(&typed_module); - let si = typed_module.type_env.clone().source_indices.clone(); - let mod_name_str = authored_name_at(si.clone(), &m); - let pkg_name = go_package_name(mod_name_str.clone()); - let pkg_decl = v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .module_keyword - .clone(), - " ".to_string(), - ), - pkg_name, - ); - let imports_str = emit_go_imports( - &typed_module.items.clone(), - module_imports(m.clone()), - si.clone(), - ); - let imports_section = if (imports_str.clone().as_str() == "".to_string().as_str()) { +let scope = module_emit_scope(&typed_module); +let si = typed_module.type_env.clone().source_indices.clone(); +let mod_name_str = authored_name_at(si.clone(), &m); +let pkg_name = go_package_name(mod_name_str.clone()); +let pkg_decl = v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().module_keyword.clone(), " ".to_string()), pkg_name); +let imports_str = emit_go_imports(&typed_module.items.clone(), module_imports(m.clone()), si.clone()); +let imports_section = if (imports_str.clone().as_str() == "".to_string().as_str()) { "".to_string() } else { v2_rt::concat("\n\n".to_string(), imports_str.clone()) }; - let items_str = Rc::new({ - let mut __result = Vec::new(); - for item in typed_module.items.clone().iter().cloned() { - __result.push(emit_go_typed_item(&item, registry.clone(), &scope)); - } - __result - }) - .join(&"\n\n".to_string()); - let filename = module_to_filename(mod_name_str.clone()); - let content = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "// Generated by v2 compiler -- do not edit.\n".to_string(), - "// Source module: ".to_string(), - ), - mod_name_str.clone(), - ), - "\n\n".to_string(), - ), - pkg_decl, - ), - imports_section, - ), - "\n\n".to_string(), - ), - items_str, - ), - "\n".to_string(), - ); - Rc::new(TextFile { - path: v2_rt::concat( - filename, - scaffold_for_target(RenderTarget::Go) - .source_file_extension - .clone(), - ), - content: content, - }) - } +let items_str = Rc::new({ let mut __result = Vec::new(); for item in typed_module.items.clone().iter().cloned() { __result.push(emit_go_typed_item(&item, registry.clone(), &scope)); } __result }).join(&"\n\n".to_string()); +let filename = module_to_filename(mod_name_str.clone()); +let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Generated by v2 compiler -- do not edit.\n".to_string(), "// Source module: ".to_string()), mod_name_str.clone()), "\n\n".to_string()), pkg_decl), imports_section), "\n\n".to_string()), items_str), "\n".to_string()); +Rc::new(TextFile { + path: v2_rt::concat(filename, scaffold_for_target(RenderTarget::Go).source_file_extension.clone()), + content: content, +}) +} } pub fn go_package_name(module_name: String) -> String { { - let parts = Rc::new( - module_name - .split(&".".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - match parts.last().cloned() { - Some(last_part) => Rc::new({ - let mut __result = Vec::new(); - for c in Rc::new( - last_part - .clone() - .chars() - .map(|c| c as i64) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push(to_lower_char(c.clone())); - } - __result - }) - .join(&"".to_string()), - None => "main".to_string(), - } - } + let parts = Rc::new(module_name.split(&".".to_string()).map(|s| s.to_string()).collect::>()); +match parts.last().cloned() { + Some(last_part) => Rc::new({ let mut __result = Vec::new(); for c in Rc::new(last_part.clone().chars().map(|c| c as i64).collect::>()).iter().cloned() { __result.push(to_lower_char(c.clone())); } __result }).join(&"".to_string()), + None => "main".to_string(), +} +} } -pub fn emit_go_imports( - items: &Rc>>, - imports: Rc>>, - source_indices: Rc>>, -) -> String { +pub fn emit_go_imports(items: &Rc>>, imports: Rc>>, source_indices: Rc>>) -> String { { - let has_services = { - let mut __found = false; - for item in items.clone().iter().cloned() { - if is_service_item(&item) { - __found = true; - break; - } - } - __found - }; - let has_types = { - let mut __found = false; - for item in items.clone().iter().cloned() { - if is_type_def_item(&item) { - __found = true; - break; - } - } - __found - }; - let has_functions = { - let mut __found = false; - for item in items.clone().iter().cloned() { - if is_function_item(&item) { - __found = true; - break; - } - } - __found - }; - let std_imports = collect_go_std_imports(&has_services, has_types, has_functions); - let pkg_imports = Rc::new({ - let mut __result = Vec::new(); - for imp in imports.iter().cloned() { - __result.push({ - let mod_name = - module_to_filename(authored_name_at(source_indices.clone(), &imp)); - v2_rt::concat( - v2_rt::concat("\t\"generated/".to_string(), mod_name.clone()), - "\"".to_string(), - ) - }); - } - __result - }); - let all_imports = v2_rt::concat(std_imports, pkg_imports); - if ((all_imports.clone().len() as i64) == 0) { + let has_services = { let mut __found = false; for item in items.clone().iter().cloned() { if is_service_item(&item) { __found = true; break; } } __found }; +let has_types = { let mut __found = false; for item in items.clone().iter().cloned() { if is_type_def_item(&item) { __found = true; break; } } __found }; +let has_functions = { let mut __found = false; for item in items.clone().iter().cloned() { if is_function_item(&item) { __found = true; break; } } __found }; +let std_imports = collect_go_std_imports(&has_services, has_types, has_functions); +let pkg_imports = Rc::new({ let mut __result = Vec::new(); for imp in imports.iter().cloned() { __result.push({ + let mod_name = module_to_filename(authored_name_at(source_indices.clone(), &imp)); +v2_rt::concat(v2_rt::concat("\t\"generated/".to_string(), mod_name.clone()), "\"".to_string()) +}); } __result }); +let all_imports = v2_rt::concat(std_imports, pkg_imports); +if ((all_imports.clone().len() as i64) == 0) { "".to_string() } else { { let imports_str = all_imports.clone().join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat("import (\n".to_string(), imports_str), - "\n)".to_string(), - ) - } +v2_rt::concat(v2_rt::concat("import (\n".to_string(), imports_str), "\n)".to_string()) +} } - } +} } -pub fn collect_go_std_imports( - has_services: &bool, - has_types: bool, - has_functions: bool, -) -> Rc> { +pub fn collect_go_std_imports(has_services: &bool, has_types: bool, has_functions: bool) -> Rc> { { let fmt_import = if ((has_types || has_functions) || has_services.clone()) { Rc::new(vec!["\t\"fmt\"".to_string()]) } else { Rc::new(vec![]) }; - let net_imports = if has_services.clone() { - Rc::new(vec![ - "\t\"net/http\"".to_string(), - "\t\"encoding/json\"".to_string(), - "\t\"bytes\"".to_string(), - "\t\"io\"".to_string(), - ]) +let net_imports = if has_services.clone() { + Rc::new(vec!["\t\"net/http\"".to_string(), "\t\"encoding/json\"".to_string(), "\t\"bytes\"".to_string(), "\t\"io\"".to_string()]) } else { Rc::new(vec![]) }; - v2_rt::concat(fmt_import, net_imports) - } +v2_rt::concat(fmt_import, net_imports) +} } -pub fn emit_go_typed_item( - item: &Rc, - registry: Rc>>, - scope: &Rc, -) -> String { +pub fn emit_go_typed_item(item: &Rc, registry: Rc>>, scope: &Rc) -> String { { let env = scope.type_env.clone(); - let item_text = authored_name(env.clone(), item.clone()); - if is_type_def_item(&item) { +let item_text = authored_name(env.clone(), item.clone()); +if is_type_def_item(&item) { emit_go_type_def_from_connective(&item, &env) } else { if is_type_alias_item(&item, env.source_indices.clone()) { - emit_go_type_alias( - item_text, - resolved_type(item.clone()), - env.source_indices.clone(), - ) + emit_go_type_alias(item_text, resolved_type(item.clone()), env.source_indices.clone()) } else { if is_type_decl_item(&item, env.source_indices.clone()) { "".to_string() } else { if is_function_item(&item) { if ((item.uses.clone().len() as i64) > 0) { - emit_go_func_def( - &item_text, - &item.params.clone(), - resolved_type(item.clone()), - &item.uses.clone(), - item.body.clone().clone().unwrap(), - ®istry, - &scope, - ) + emit_go_func_def(&item_text, &item.params.clone(), resolved_type(item.clone()), &item.uses.clone(), item.body.clone().clone().unwrap(), ®istry, &scope) } else { - emit_go_fn_def( - &item_text, - &item.params.clone(), - resolved_type(item.clone()), - &item.body.clone().clone().unwrap(), - ®istry, - &scope, - ) + emit_go_fn_def(&item_text, &item.params.clone(), resolved_type(item.clone()), &item.body.clone().clone().unwrap(), ®istry, &scope) } } else { if is_data_def_item(&item) { - emit_go_data_def( - item_text, - item.type_annotation.clone().clone().unwrap(), - item.body.clone().clone().unwrap(), - registry, - &scope, - 0, - ) + emit_go_data_def(item_text, item.type_annotation.clone().clone().unwrap(), item.body.clone().clone().unwrap(), registry, &scope, 0) } else { if is_service_def_item(&item) { emit_go_service_def(item.clone(), registry, env.clone()) @@ -685,21 +222,7 @@ pub fn emit_go_typed_item( if is_resource_def_item(&item) { emit_go_resource_def(&item, &env) } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .func_keyword - .clone(), - " init() { panic(\"EMIT BUG: unhandled item: " - .to_string(), - ), - item_text, - ), - "\") }".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().func_keyword.clone(), " init() { panic(\"EMIT BUG: unhandled item: ".to_string()), item_text), "\") }".to_string()) } } } @@ -707,1065 +230,255 @@ pub fn emit_go_typed_item( } } } - } +} } pub fn emit_go_type_def_from_connective(item: &Rc, env: &Rc) -> String { { let item_text = authored_name(env.clone(), item.clone()); - let is_product = (item.connective.clone() == Connective::Conj); - if is_product { +let is_product = (item.connective.clone() == Connective::Conj); +if is_product { emit_go_struct_from_children(item_text, &item.children.clone(), env.clone()) } else { emit_go_sum_from_children(&item_text, &item.children.clone(), env.clone()) } - } +} } -pub fn emit_go_struct_from_children( - name: String, - children: &Rc>>, - env: Rc, -) -> String { +pub fn emit_go_struct_from_children(name: String, children: &Rc>>, env: Rc) -> String { if ((children.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - name, - ), - " ".to_string(), - ), - language_spec(RenderTarget::Go) - .items - .clone() - .struct_keyword - .clone(), - ), - "{}".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), name), " ".to_string()), language_spec(RenderTarget::Go).items.clone().struct_keyword.clone()), "{}".to_string()) } else { { - let field_lines = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push(emit_go_struct_field_from_child(&child, &env)); - } - __result - }); - let fields_str = field_lines.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - name, - ), - " ".to_string(), - ), - language_spec(RenderTarget::Go) - .items - .clone() - .struct_keyword - .clone(), - ), - " {\n".to_string(), - ), - fields_str, - ), - "\n}".to_string(), - ) - } + let field_lines = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push(emit_go_struct_field_from_child(&child, &env)); } __result }); +let fields_str = field_lines.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), name), " ".to_string()), language_spec(RenderTarget::Go).items.clone().struct_keyword.clone()), " {\n".to_string()), fields_str), "\n}".to_string()) +} } } pub fn emit_go_struct_field_from_child(child: &Rc, env: &Rc) -> String { { let child_text = authored_name(env.clone(), child.clone()); - let ty = emit_node_type( - resolved_type(child.clone()), - RenderTarget::Go, - env.source_indices.clone(), - ); - let json_tag = v2_rt::concat( - v2_rt::concat(" `json:\"".to_string(), to_snake(child_text.clone())), - "\"`".to_string(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("\t".to_string(), go_export_ident(child_text.clone())), - " ".to_string(), - ), - ty, - ), - json_tag, - ) - } +let ty = emit_node_type(resolved_type(child.clone()), RenderTarget::Go, env.source_indices.clone()); +let json_tag = v2_rt::concat(v2_rt::concat(" `json:\"".to_string(), to_snake(child_text.clone())), "\"`".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("\t".to_string(), go_export_ident(child_text.clone())), " ".to_string()), ty), json_tag) +} } -pub fn emit_go_sum_from_children( - name: &String, - children: &Rc>>, - env: Rc, -) -> String { +pub fn emit_go_sum_from_children(name: &String, children: &Rc>>, env: Rc) -> String { { - let has_data = { - let mut __found = false; - for child in children.clone().iter().cloned() { - if ((child.children.clone().len() as i64) > 0) { - __found = true; - break; - } - } - __found - }; - if has_data { + let has_data = { let mut __found = false; for child in children.clone().iter().cloned() { if ((child.children.clone().len() as i64) > 0) { __found = true; break; } } __found }; +if has_data { { - let iface = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - name.clone(), - ), - " interface {\n\tis".to_string(), - ), - name.clone(), - ), - "()\n}".to_string(), - ); - let variant_structs = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push(emit_go_variant_struct(&name, &child, &env)); - } - __result - }); - let structs_str = variant_structs.join(&"\n\n".to_string()); - v2_rt::concat(v2_rt::concat(iface, "\n\n".to_string()), structs_str) - } + let iface = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), name.clone()), " interface {\n\tis".to_string()), name.clone()), "()\n}".to_string()); +let variant_structs = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push(emit_go_variant_struct(&name, &child, &env)); } __result }); +let structs_str = variant_structs.join(&"\n\n".to_string()); +v2_rt::concat(v2_rt::concat(iface, "\n\n".to_string()), structs_str) +} } else { { - let type_decl = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .enum_keyword - .clone(), - " ".to_string(), - ), - name.clone(), - ), - " int".to_string(), - ); - let variant_consts = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let child = pair.1.clone(); - let child_text = authored_name(env.clone(), child.clone()); - if (pair.0.clone() == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("\t".to_string(), name.clone()), - child_text.clone(), - ), - " ".to_string(), - ), - name.clone(), - ), - " = iota".to_string(), - ) - } else { - v2_rt::concat( - v2_rt::concat("\t".to_string(), name.clone()), - child_text.clone(), - ) - } - }); + let type_decl = v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().enum_keyword.clone(), " ".to_string()), name.clone()), " int".to_string()); +let variant_consts = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let child = pair.1.clone(); +let child_text = authored_name(env.clone(), child.clone()); +if (pair.0.clone() == 0) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("\t".to_string(), name.clone()), child_text.clone()), " ".to_string()), name.clone()), " = iota".to_string()) + } else { + v2_rt::concat(v2_rt::concat("\t".to_string(), name.clone()), child_text.clone()) } - __result - }); - let consts_str = variant_consts.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(type_decl, "\n\nconst (\n".to_string()), - consts_str, - ), - "\n)".to_string(), - ) - } +}); } __result }); +let consts_str = variant_consts.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(type_decl, "\n\nconst (\n".to_string()), consts_str), "\n)".to_string()) +} } - } +} } pub fn emit_go_variant_struct(parent_name: &String, child: &Rc, env: &Rc) -> String { { - let struct_name = v2_rt::concat( - parent_name.clone(), - authored_name(env.clone(), child.clone()), - ); - let marker_method = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .func_keyword - .clone(), - " (".to_string(), - ), - struct_name.clone(), - ), - ") is".to_string(), - ), - parent_name.clone(), - ), - "() {}".to_string(), - ); - if ((child.children.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - struct_name.clone(), - ), - " ".to_string(), - ), - language_spec(RenderTarget::Go) - .items - .clone() - .struct_keyword - .clone(), - ), - "{}\n\n".to_string(), - ), - marker_method, - ) + let struct_name = v2_rt::concat(parent_name.clone(), authored_name(env.clone(), child.clone())); +let marker_method = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().func_keyword.clone(), " (".to_string()), struct_name.clone()), ") is".to_string()), parent_name.clone()), "() {}".to_string()); +if ((child.children.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), struct_name.clone()), " ".to_string()), language_spec(RenderTarget::Go).items.clone().struct_keyword.clone()), "{}\n\n".to_string()), marker_method) } else { { - let field_lines = Rc::new({ - let mut __result = Vec::new(); - for f in child.children.clone().iter().cloned() { - __result.push(emit_go_struct_field_from_child(&f, &env)); - } - __result - }); - let fields_str = field_lines.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - struct_name.clone(), - ), - " ".to_string(), - ), - language_spec(RenderTarget::Go) - .items - .clone() - .struct_keyword - .clone(), - ), - " {\n".to_string(), - ), - fields_str, - ), - "\n}\n\n".to_string(), - ), - marker_method, - ) - } + let field_lines = Rc::new({ let mut __result = Vec::new(); for f in child.children.clone().iter().cloned() { __result.push(emit_go_struct_field_from_child(&f, &env)); } __result }); +let fields_str = field_lines.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), struct_name.clone()), " ".to_string()), language_spec(RenderTarget::Go).items.clone().struct_keyword.clone()), " {\n".to_string()), fields_str), "\n}\n\n".to_string()), marker_method) +} } - } +} } -pub fn emit_go_type_alias( - name: String, - base: Rc, - source_indices: Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - name, - ), - " = ".to_string(), - ), - emit_node_type(base, RenderTarget::Go, source_indices), - ) +pub fn emit_go_type_alias(name: String, base: Rc, source_indices: Rc>>) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), name), " = ".to_string()), emit_node_type(base, RenderTarget::Go, source_indices)) } -pub fn emit_go_fn_def( - name: &String, - params: &Rc>>, - inferred: Rc, - body: &Rc, - registry: &Rc>>, - scope: &Rc, -) -> String { +pub fn emit_go_fn_def(name: &String, params: &Rc>>, inferred: Rc, body: &Rc, registry: &Rc>>, scope: &Rc) -> String { { let si = scope.type_env.clone().source_indices.clone(); - let params_str = emit_params_shared(params.clone(), &RenderTarget::Go, si.clone()); - let ret_str = emit_inferred_shared(&inferred, &RenderTarget::Go, si.clone()); - let body_scope = build_params_scope(&scope, params.clone()); - let use_tco = is_tco_eligible(&name, &body, registry.clone(), &si); - if use_tco { +let params_str = emit_params_shared(params.clone(), &RenderTarget::Go, si.clone()); +let ret_str = emit_inferred_shared(&inferred, &RenderTarget::Go, si.clone()); +let body_scope = build_params_scope(&scope, params.clone()); +let use_tco = is_tco_eligible(&name, &body, registry.clone(), &si); +if use_tco { { - let body_str = emit_tco_unified( - body.clone(), - &name, - ¶ms, - &RenderTarget::Go, - ®istry, - &body_scope, - 1, - |pat| emit_unified_pattern(pat.clone(), RenderTarget::Go, si.clone()), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .func_keyword - .clone(), - " ".to_string(), - ), - go_export_ident(name.clone()), - ), - "(".to_string(), - ), - params_str, - ), - ")".to_string(), - ), - ret_str, - ), - " {\n".to_string(), - ), - body_str, - ), - "\n}".to_string(), - ) - } + let body_str = emit_tco_unified(body.clone(), &name, ¶ms, &RenderTarget::Go, ®istry, &body_scope, 1, |pat| emit_unified_pattern(pat.clone(), RenderTarget::Go, si.clone())); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().func_keyword.clone(), " ".to_string()), go_export_ident(name.clone())), "(".to_string()), params_str), ")".to_string()), ret_str), " {\n".to_string()), body_str), "\n}".to_string()) +} } else { { - let body_str = - emit_go_typed_expr(body.clone(), registry.clone(), &body_scope, 1, 1024); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .func_keyword - .clone(), - " ".to_string(), - ), - go_export_ident(name.clone()), - ), - "(".to_string(), - ), - params_str, - ), - ")".to_string(), - ), - ret_str, - ), - " {\n".to_string(), - ), - make_indent(1), - ), - "return ".to_string(), - ), - body_str, - ), - "\n}".to_string(), - ) - } + let body_str = emit_go_typed_expr(body.clone(), registry.clone(), &body_scope, 1, 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().func_keyword.clone(), " ".to_string()), go_export_ident(name.clone())), "(".to_string()), params_str), ")".to_string()), ret_str), " {\n".to_string()), make_indent(1)), "return ".to_string()), body_str), "\n}".to_string()) +} } - } +} } -pub fn emit_go_func_def( - name: &String, - params: &Rc>>, - inferred: Rc, - uses: &Rc>>, - body: Rc, - registry: &Rc>>, - scope: &Rc, -) -> String { +pub fn emit_go_func_def(name: &String, params: &Rc>>, inferred: Rc, uses: &Rc>>, body: Rc, registry: &Rc>>, scope: &Rc) -> String { { let service_names = match lookup_item(registry.clone(), name.clone()) { - Some(info) => info.service_names.clone(), - None => Rc::new(vec![]), - }; - let params_str = emit_go_func_params( - params.clone(), - uses.clone(), - service_names, - scope.type_env.clone().source_indices.clone(), - ); - let ret_type = emit_node_type( - inferred, - RenderTarget::Go, - scope.type_env.clone().source_indices.clone(), - ); - let body_scope = build_params_scope(&scope, params.clone()); - let si = scope.type_env.clone().source_indices.clone(); - let body_scope = uses.clone().iter().cloned().fold( - body_scope.clone(), - |s: Rc, u: Rc| { - extend_scope( - &s, - &resource_use_name_at(u.clone(), si.clone()), - resource_use_resource(&u), - Rc::new(SubValueRelation::SubValueUnknown), - ) - }, - ); - let body_str = - emit_unified_typed_func_body(&body, &RenderTarget::Go, ®istry, &body_scope, 1); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .func_keyword - .clone(), - " ".to_string(), - ), - go_export_ident(name.clone()), - ), - "(".to_string(), - ), - params_str, - ), - ") (".to_string(), - ), - ret_type, - ), - ", error) {\n".to_string(), - ), - body_str, - ), - "\n}".to_string(), - ) - } + Some(info) => info.service_names.clone(), + None => Rc::new(vec![]), +}; +let params_str = emit_go_func_params(params.clone(), uses.clone(), service_names, scope.type_env.clone().source_indices.clone()); +let ret_type = emit_node_type(inferred, RenderTarget::Go, scope.type_env.clone().source_indices.clone()); +let body_scope = build_params_scope(&scope, params.clone()); +let si = scope.type_env.clone().source_indices.clone(); +let body_scope = uses.clone().iter().cloned().fold(body_scope.clone(), |s: Rc, u: Rc| extend_scope(&s, &resource_use_name_at(u.clone(), si.clone()), resource_use_resource(&u), Rc::new(SubValueRelation::SubValueUnknown))); +let body_str = emit_unified_typed_func_body(&body, &RenderTarget::Go, ®istry, &body_scope, 1); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().func_keyword.clone(), " ".to_string()), go_export_ident(name.clone())), "(".to_string()), params_str), ") (".to_string()), ret_type), ", error) {\n".to_string()), body_str), "\n}".to_string()) +} } -pub fn emit_go_func_params( - params: Rc>>, - uses: Rc>>, - service_names: Rc>, - source_indices: Rc>>, -) -> String { +pub fn emit_go_func_params(params: Rc>>, uses: Rc>>, service_names: Rc>, source_indices: Rc>>) -> String { { - let param_strs = Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - __result.push(emit_param_shared(&p, &RenderTarget::Go, &source_indices)); - } - __result - }); - let resource_strs = Rc::new({ - let mut __result = Vec::new(); - for u in uses.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - resource_use_name_at(u.clone(), source_indices.clone()), - RenderTarget::Go, - ), - " ".to_string(), - ), - emit_node_type( - resource_use_resource(&u), - RenderTarget::Go, - source_indices.clone(), - ), - )); - } - __result - }); - let service_strs = Rc::new({ - let mut __result = Vec::new(); - for sn in service_names.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat(service_var_name(sn.clone()), " *".to_string()), - sanitize_service_name(sn.clone()), - )); - } - __result - }); - let all_params = v2_rt::concat(v2_rt::concat(param_strs, resource_strs), service_strs); - all_params.join(&", ".to_string()) - } + let param_strs = Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { __result.push(emit_param_shared(&p, &RenderTarget::Go, &source_indices)); } __result }); +let resource_strs = Rc::new({ let mut __result = Vec::new(); for u in uses.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(resource_use_name_at(u.clone(), source_indices.clone()), RenderTarget::Go), " ".to_string()), emit_node_type(resource_use_resource(&u), RenderTarget::Go, source_indices.clone()))); } __result }); +let service_strs = Rc::new({ let mut __result = Vec::new(); for sn in service_names.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(service_var_name(sn.clone()), " *".to_string()), sanitize_service_name(sn.clone()))); } __result }); +let all_params = v2_rt::concat(v2_rt::concat(param_strs, resource_strs), service_strs); +all_params.join(&", ".to_string()) +} } -pub fn emit_go_typed_expr( - texpr: Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - fuel: i64, -) -> String { - emit_unified_typed_expr( - texpr, - &RenderTarget::Go, - registry, - &scope, - depth, - fuel, - |pat| { - emit_unified_pattern( - pat.clone(), - RenderTarget::Go, - scope.type_env.clone().source_indices.clone(), - ) - }, - ) +pub fn emit_go_typed_expr(texpr: Rc, registry: Rc>>, scope: &Rc, depth: i64, fuel: i64) -> String { + emit_unified_typed_expr(texpr, &RenderTarget::Go, registry, &scope, depth, fuel, |pat| emit_unified_pattern(pat.clone(), RenderTarget::Go, scope.type_env.clone().source_indices.clone())) } -pub fn emit_go_transport_body( - transport: Rc, - op_name: String, - source_indices: Rc>>, - depth: i64, -) -> String { - emit_unified_transport_dispatch( - &transport, - op_name, - &source_indices, - depth, - RenderTarget::Go, - |n, t, d, si| emit_go_rest_call(n.clone(), &t, d.clone(), &si), - |n, t, d, si| emit_go_shell_call(n.clone(), t.clone(), d.clone(), &si), - |n, d| emit_go_file_call(n.clone(), d.clone()), - |n, d| emit_go_local_call(n.clone(), d.clone()), - ) +pub fn emit_go_transport_body(transport: Rc, op_name: String, source_indices: Rc>>, depth: i64) -> String { + emit_unified_transport_dispatch(&transport, op_name, &source_indices, depth, RenderTarget::Go, |n, t, d, si| emit_go_rest_call(n.clone(), &t, d.clone(), &si), |n, t, d, si| emit_go_shell_call(n.clone(), t.clone(), d.clone(), &si), |n, d| emit_go_file_call(n.clone(), d.clone()), |n, d| emit_go_local_call(n.clone(), d.clone())) } -pub fn emit_go_service_def( - item: Rc, - registry: Rc>>, - env: Rc, -) -> String { - emit_unified_service_def( - &item, - &RenderTarget::Go, - registry, - &env, - |name, transport, ops, si| { - emit_go_service_struct(name.clone(), transport.clone(), ops.clone(), si.clone()) - }, - |transport, op_name, si, depth| { - emit_go_transport_body( - transport.clone(), - op_name.clone(), - si.clone(), - depth.clone(), - ) - }, - ) +pub fn emit_go_service_def(item: Rc, registry: Rc>>, env: Rc) -> String { + emit_unified_service_def(&item, &RenderTarget::Go, registry, &env, |name, transport, ops, si| emit_go_service_struct(name.clone(), transport.clone(), ops.clone(), si.clone()), |transport, op_name, si, depth| emit_go_transport_body(transport.clone(), op_name.clone(), si.clone(), depth.clone())) } -pub fn emit_go_service_struct( - name: String, - fallback_transport: Rc, - op_children: Rc>>, - source_indices: Rc>>, -) -> String { +pub fn emit_go_service_struct(name: String, fallback_transport: Rc, op_children: Rc>>, source_indices: Rc>>) -> String { { let fs = compute_service_fields(&fallback_transport, &op_children, &source_indices); - let decls = - service_field_decls(&fs, &language_spec(RenderTarget::Go).service_fields.clone()); - if ((decls.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - name, - ), - " ".to_string(), - ), - language_spec(RenderTarget::Go) - .items - .clone() - .struct_keyword - .clone(), - ), - "{}".to_string(), - ) +let decls = service_field_decls(&fs, &language_spec(RenderTarget::Go).service_fields.clone()); +if ((decls.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), name), " ".to_string()), language_spec(RenderTarget::Go).items.clone().struct_keyword.clone()), "{}".to_string()) } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - name, - ), - " ".to_string(), - ), - language_spec(RenderTarget::Go) - .items - .clone() - .struct_keyword - .clone(), - ), - " {\n".to_string(), - ), - decls.clone().join(&"\n".to_string()), - ), - "\n}".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), name), " ".to_string()), language_spec(RenderTarget::Go).items.clone().struct_keyword.clone()), " {\n".to_string()), decls.clone().join(&"\n".to_string())), "\n}".to_string()) } - } +} } -pub fn emit_go_rest_call( - op_name: String, - transport: &Rc, - depth: i64, - source_indices: &Rc>>, -) -> String { +pub fn emit_go_rest_call(op_name: String, transport: &Rc, depth: i64, source_indices: &Rc>>) -> String { { let prefix = make_indent(depth); - let url_line = v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix.clone(), "url := fmt.Sprintf(\"%s/".to_string()), - to_snake(op_name), - ), - "\", c.BaseURL)".to_string(), - ); - let body_line = v2_rt::concat( - prefix.clone(), - "reqBody := bytes.NewBuffer(nil)".to_string(), - ); - let req_line = v2_rt::concat( - v2_rt::concat( - prefix.clone(), - "req, err := http.NewRequest(\"POST\", url, reqBody)\n".to_string(), - ), - "if err != nil {\n\treturn nil, fmt.Errorf(\"creating request: %w\", err)\n}" - .to_string(), - ); - let auth_line = if transport_has_auth(transport.clone(), source_indices.clone()) { +let url_line = v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "url := fmt.Sprintf(\"%s/".to_string()), to_snake(op_name)), "\", c.BaseURL)".to_string()); +let body_line = v2_rt::concat(prefix.clone(), "reqBody := bytes.NewBuffer(nil)".to_string()); +let req_line = v2_rt::concat(v2_rt::concat(prefix.clone(), "req, err := http.NewRequest(\"POST\", url, reqBody)\n".to_string()), "if err != nil {\n\treturn nil, fmt.Errorf(\"creating request: %w\", err)\n}".to_string()); +let auth_line = if transport_has_auth(transport.clone(), source_indices.clone()) { { - let header_name = - match transport_auth_header_name(transport.clone(), source_indices.clone()) { - Some(h) => h.clone(), - None => "Authorization".to_string(), - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix.clone(), "req.Header.Set(\"".to_string()), - header_name, - ), - "\", c.AuthToken)".to_string(), - ) - } + let header_name = match transport_auth_header_name(transport.clone(), source_indices.clone()) { + Some(h) => h.clone(), + None => "Authorization".to_string(), +}; +v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "req.Header.Set(\"".to_string()), header_name), "\", c.AuthToken)".to_string()) +} } else { "".to_string() }; - let hdrs = transport_headers(transport.clone(), source_indices.clone()); - let header_lines = Rc::new({ - let mut __result = Vec::new(); - for h in hdrs.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix.clone(), "req.Header.Set(\"".to_string()), - field_init_node_name_at(h.clone(), source_indices.clone()), - ), - "\", ".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&h), - &RenderTarget::Go, - &source_indices, - ), - ), - ")".to_string(), - )); - } - __result - }); - let send_lines = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "resp, err := http.DefaultClient.Do(req)\n".to_string()), "if err != nil {\n\treturn nil, fmt.Errorf(\"sending request: %w\", err)\n}\n".to_string()), "defer resp.Body.Close()\n".to_string()), "body, err := io.ReadAll(resp.Body)\n".to_string()), "if err != nil {\n\treturn nil, fmt.Errorf(\"reading response: %w\", err)\n}\n".to_string()), "var result interface{}\n".to_string()), "if err := json.Unmarshal(body, &result); err != nil {\n".to_string()), "\treturn nil, fmt.Errorf(\"decoding response: %w\", err)\n}\n".to_string()), "return result, nil".to_string()); - let all_lines = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - Rc::new(vec![url_line, body_line, req_line]), - if (auth_line.clone().as_str() == "".to_string().as_str()) { - Rc::new(vec![]) - } else { - Rc::new(vec![auth_line.clone()]) - }, - ), - header_lines, - ), - Rc::new(vec![send_lines]), - ); - all_lines.join(&"\n".to_string()) - } +let hdrs = transport_headers(transport.clone(), source_indices.clone()); +let header_lines = Rc::new({ let mut __result = Vec::new(); for h in hdrs.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "req.Header.Set(\"".to_string()), field_init_node_name_at(h.clone(), source_indices.clone())), "\", ".to_string()), emit_simple_expr(&field_init_node_value(&h), &RenderTarget::Go, &source_indices)), ")".to_string())); } __result }); +let send_lines = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "resp, err := http.DefaultClient.Do(req)\n".to_string()), "if err != nil {\n\treturn nil, fmt.Errorf(\"sending request: %w\", err)\n}\n".to_string()), "defer resp.Body.Close()\n".to_string()), "body, err := io.ReadAll(resp.Body)\n".to_string()), "if err != nil {\n\treturn nil, fmt.Errorf(\"reading response: %w\", err)\n}\n".to_string()), "var result interface{}\n".to_string()), "if err := json.Unmarshal(body, &result); err != nil {\n".to_string()), "\treturn nil, fmt.Errorf(\"decoding response: %w\", err)\n}\n".to_string()), "return result, nil".to_string()); +let all_lines = v2_rt::concat(v2_rt::concat(v2_rt::concat(Rc::new(vec![url_line, body_line, req_line]), if (auth_line.clone().as_str() == "".to_string().as_str()) { + Rc::new(vec![]) + } else { + Rc::new(vec![auth_line.clone()]) + }), header_lines), Rc::new(vec![send_lines])); +all_lines.join(&"\n".to_string()) +} } -pub fn emit_go_shell_call( - op_name: String, - transport: Rc, - depth: i64, - source_indices: &Rc>>, -) -> String { +pub fn emit_go_shell_call(op_name: String, transport: Rc, depth: i64, source_indices: &Rc>>) -> String { { let prefix = make_indent(depth); - let cmd_line = v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix.clone(), "cmd := exec.Command(\"".to_string()), - to_snake(op_name), - ), - "\")".to_string(), - ); - let dir_line = v2_rt::concat(prefix.clone(), "cmd.Dir = c.WorkingDir".to_string()); - let envs = transport_env(transport, source_indices.clone()); - let env_lines = Rc::new({ - let mut __result = Vec::new(); - for e in envs.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - prefix.clone(), - "cmd.Env = append(cmd.Env, \"".to_string(), - ), - field_init_node_name_at(e.clone(), source_indices.clone()), - ), - "=\" + ".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&e), - &RenderTarget::Go, - &source_indices, - ), - ), - ")".to_string(), - )); - } - __result - }); - let run_lines = v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix.clone(), "output, err := cmd.Output()\n".to_string()), - "if err != nil {\n\treturn \"\", fmt.Errorf(\"running command: %w\", err)\n}\n" - .to_string(), - ), - "return string(output), nil".to_string(), - ); - let all_lines = v2_rt::concat( - v2_rt::concat(Rc::new(vec![cmd_line, dir_line]), env_lines), - Rc::new(vec![run_lines]), - ); - all_lines.join(&"\n".to_string()) - } +let cmd_line = v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "cmd := exec.Command(\"".to_string()), to_snake(op_name)), "\")".to_string()); +let dir_line = v2_rt::concat(prefix.clone(), "cmd.Dir = c.WorkingDir".to_string()); +let envs = transport_env(transport, source_indices.clone()); +let env_lines = Rc::new({ let mut __result = Vec::new(); for e in envs.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "cmd.Env = append(cmd.Env, \"".to_string()), field_init_node_name_at(e.clone(), source_indices.clone())), "=\" + ".to_string()), emit_simple_expr(&field_init_node_value(&e), &RenderTarget::Go, &source_indices)), ")".to_string())); } __result }); +let run_lines = v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "output, err := cmd.Output()\n".to_string()), "if err != nil {\n\treturn \"\", fmt.Errorf(\"running command: %w\", err)\n}\n".to_string()), "return string(output), nil".to_string()); +let all_lines = v2_rt::concat(v2_rt::concat(Rc::new(vec![cmd_line, dir_line]), env_lines), Rc::new(vec![run_lines])); +all_lines.join(&"\n".to_string()) +} } pub fn emit_go_file_call(op_name: String, depth: i64) -> String { { let prefix = make_indent(depth); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix, "path := fmt.Sprintf(\"%s/".to_string()), - to_snake(op_name), - ), - "\", c.BasePath)\n".to_string(), - ), - "data, err := os.ReadFile(path)\n".to_string(), - ), - "if err != nil {\n\treturn \"\", fmt.Errorf(\"reading file: %w\", err)\n}\n" - .to_string(), - ), - "return string(data), nil".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix, "path := fmt.Sprintf(\"%s/".to_string()), to_snake(op_name)), "\", c.BasePath)\n".to_string()), "data, err := os.ReadFile(path)\n".to_string()), "if err != nil {\n\treturn \"\", fmt.Errorf(\"reading file: %w\", err)\n}\n".to_string()), "return string(data), nil".to_string()) +} } pub fn emit_go_local_call(op_name: String, depth: i64) -> String { { let prefix = make_indent(depth); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - prefix, - "// Local binding -- direct function call\n".to_string(), - ), - "return ".to_string(), - ), - go_export_ident(op_name), - ), - "(), nil".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix, "// Local binding -- direct function call\n".to_string()), "return ".to_string()), go_export_ident(op_name)), "(), nil".to_string()) +} } pub fn emit_go_resource_def(item: &Rc, env: &Rc) -> String { { let item_text = authored_name(env.clone(), item.clone()); - let cap_children = Rc::new({ - let mut __result = Vec::new(); - for c in item.children.clone().iter().cloned() { - if ((c.params.clone().len() as i64) > 0) { - __result.push(c); - } - } - __result - }); - let methods = Rc::new({ - let mut __result = Vec::new(); - for c in cap_children.iter().cloned() { - __result.push(emit_go_capability_method(&c, 1, &env)); - } - __result - }); - let methods_str = methods.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Go) - .items - .clone() - .type_alias_keyword - .clone(), - " ".to_string(), - ), - item_text, - ), - " interface {\n".to_string(), - ), - methods_str, - ), - "\n}".to_string(), - ) - } +let cap_children = Rc::new({ let mut __result = Vec::new(); for c in item.children.clone().iter().cloned() { if ((c.params.clone().len() as i64) > 0) { __result.push(c); } } __result }); +let methods = Rc::new({ let mut __result = Vec::new(); for c in cap_children.iter().cloned() { __result.push(emit_go_capability_method(&c, 1, &env)); } __result }); +let methods_str = methods.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Go).items.clone().type_alias_keyword.clone(), " ".to_string()), item_text), " interface {\n".to_string()), methods_str), "\n}".to_string()) +} } pub fn emit_go_capability_method(cap_node: &Rc, depth: i64, env: &Rc) -> String { { - let input_params = Rc::new({ - let mut __result = Vec::new(); - for p in cap_node.params.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - param_node_name_at(p.clone(), env.source_indices.clone()), - RenderTarget::Go, - ), - " ".to_string(), - ), - emit_node_type( - param_node_type_expr(&p), - RenderTarget::Go, - env.source_indices.clone(), - ), - )); - } - __result - }); - let params_str = input_params.join(&", ".to_string()); - let ret = emit_node_type( - resolved_type(cap_node.clone()), - RenderTarget::Go, - env.source_indices.clone(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - make_indent(depth), - go_export_ident(authored_name(env.clone(), cap_node.clone())), - ), - "(".to_string(), - ), - params_str, - ), - ") (".to_string(), - ), - ret, - ), - ", error)".to_string(), - ) - } + let input_params = Rc::new({ let mut __result = Vec::new(); for p in cap_node.params.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(param_node_name_at(p.clone(), env.source_indices.clone()), RenderTarget::Go), " ".to_string()), emit_node_type(param_node_type_expr(&p), RenderTarget::Go, env.source_indices.clone()))); } __result }); +let params_str = input_params.join(&", ".to_string()); +let ret = emit_node_type(resolved_type(cap_node.clone()), RenderTarget::Go, env.source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(make_indent(depth), go_export_ident(authored_name(env.clone(), cap_node.clone()))), "(".to_string()), params_str), ") (".to_string()), ret), ", error)".to_string()) +} } -pub fn emit_go_data_def( - name: String, - type_node: Rc, - value: Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, -) -> String { +pub fn emit_go_data_def(name: String, type_node: Rc, value: Rc, registry: Rc>>, scope: &Rc, depth: i64) -> String { { - let ty_str = emit_node_type( - type_node, - RenderTarget::Go, - scope.type_env.clone().source_indices.clone(), - ); - let val_str = emit_go_typed_expr(value, registry, &scope, depth, 1024); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("var ".to_string(), go_export_ident(name)), - " ".to_string(), - ), - ty_str, - ), - " = ".to_string(), - ), - val_str, - ) - } + let ty_str = emit_node_type(type_node, RenderTarget::Go, scope.type_env.clone().source_indices.clone()); +let val_str = emit_go_typed_expr(value, registry, &scope, depth, 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("var ".to_string(), go_export_ident(name)), " ".to_string()), ty_str), " = ".to_string()), val_str) +} } pub fn go_export_ident(name: String) -> String { match (*language_spec(RenderTarget::Go).visibility.clone()).clone() { - VisibilitySpec::CaseVisibility { - export_case: ec, .. - } => { - let result = apply_naming_case(name, ec.clone()); - if { - let mut __found = false; - for r in go_reserved().iter().cloned() { - if (r.clone().as_str() == result.clone().as_str()) { - __found = true; - break; - } - } - __found - } { - v2_rt::concat(result.clone(), go_reserved_escape_suffix()) - } else { - result.clone() - } + VisibilitySpec::CaseVisibility { export_case: ec, .. } => { + let result = apply_naming_case(name, ec.clone()); +if { let mut __found = false; for r in go_reserved().iter().cloned() { if (r.clone().as_str() == result.clone().as_str()) { __found = true; break; } } __found } { + v2_rt::concat(result.clone(), go_reserved_escape_suffix()) + } else { + result.clone() } - _ => "__GO_VISIBILITY_SPEC_MISMATCH__".to_string(), - } +}, + _ => "__GO_VISIBILITY_SPEC_MISMATCH__".to_string(), +} } diff --git a/src/v2/stage0/src/v2_compiler_emit_python.rs b/src/v2/stage0/src/v2_compiler_emit_python.rs index 3ca12b846ae..280d452ed08 100644 --- a/src/v2/stage0/src/v2_compiler_emit_python.rs +++ b/src/v2/stage0/src/v2_compiler_emit_python.rs @@ -1,615 +1,229 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.emit_python -pub use crate::std_induction::SubValueRelation; -use crate::std_induction::SubValueRelation::SubValueUnknown; -pub use crate::v2_compiler_artifact::RenderTarget; -use crate::v2_compiler_artifact::RenderTarget::Python; -pub use crate::v2_compiler_emit::{ - apply_named_template, apply_type_template1, apply_type_template2, apply_type_template3, - capitalize_first, compute_service_fields, effective_operation_transport, - emit_algebra_method_template, emit_bin_op_symbol, emit_container, emit_default_bin_op, - emit_error_expr, emit_expr_field_access_shared, emit_expr_var_shared, emit_ident, - emit_inferred_shared, emit_keyword, emit_lambda, emit_lambda_params, emit_let_binding, - emit_list_lit_expr, emit_literal, emit_map_type, emit_node_type, emit_null_coalesce, - emit_param_shared, emit_params_shared, emit_return, emit_shared_expr, emit_simple_expr, - emit_string_literal, emit_tco_unified, emit_typed_block_join, emit_typed_call_unified, - emit_typed_cast_shared, emit_typed_first_arg_shared, emit_typed_for_each_shared, - emit_typed_if_shared, emit_typed_index_shared, emit_typed_let_shared, emit_typed_match_unified, - emit_typed_method_call_unified, emit_typed_record_lit_unified, emit_typed_slice_shared, - emit_typed_string_interp_unified, emit_unary_op, emit_unified_init_block_stmts, - emit_unified_operation_method, emit_unified_pattern, emit_unified_service_def, - emit_unified_transport_dispatch, emit_unified_typed_expr, emit_unified_typed_func_body, - empty_emit_scope, escape_json_string, escape_python_interp_text, escape_string_literal_body, - extract_string_interp_parts, extract_test_projections, has_nested_records_node, - has_service_items, is_data_def_item, is_function_item, is_null_coalesce, is_resource_def_item, - is_service_def_item, is_service_item, is_tco_eligible, is_type_alias_item, - is_type_alias_return_node, is_type_decl_item, is_type_def_item, is_upper, language_spec, - lookup_item, make_indent, module_emit_scope, module_to_filename, order_typed_call_args, - sanitize_service_name, scope_after_expr, seed_bindings, service_fallback_transport, - service_field_ctors, service_field_decls, service_var_name, test_file_path, test_function_name, - to_lower_char, to_screaming_snake, to_snake, to_string, to_string_helper, to_upper_char, - typed_named_arg_matches, unique_strings, BlockEmitState, EmitResult, InterpPart, - ServiceFieldSet, TestProjection, -}; -pub use crate::v2_compiler_infer::{build_params_scope, expr_span, extend_scope, InferScope}; -pub use crate::v2_compiler_infer_env::{authored_name, TypeBinding, TypeEnv}; -pub use crate::v2_compiler_infer_items::{ItemInfo, ResolvedGraph, TypedModule}; -pub use crate::v2_compiler_infer_service::{ - extract_typed_service_name, is_typed_service_call_receiver, -}; -pub use crate::v2_compiler_infer_sigs::{ResolvedFuncEnv, ResolvedFuncSig}; -pub use crate::v2_compiler_infer_types::{ - node_is_keyed_collection, normalize_access_type_node, resolved_type, -}; -pub use crate::v2_compiler_languages::{ - is_string_like, scaffold_for_target, serialization_for_target, test_conventions_for_target, - ItemKeywords, TestConventions, -}; +use std::collections::HashMap; +use std::rc::Rc; use crate::v2_rt; -use crate::v2_std_core::BinOp::NullCoalesce; -use crate::v2_std_core::Cardinality::CardOptional; -use crate::v2_std_core::Connective::{Conj, Disj}; -use crate::v2_std_core::ExprData::{ - ExprBinOp, ExprBlock, ExprCall, ExprCast, ExprError, ExprFieldAccess, ExprForEach, ExprIf, - ExprIndex, ExprLambda, ExprLet, ExprListLit, ExprLiteral, ExprMatch, ExprMethodCall, - ExprRecordLit, ExprReturn, ExprSlice, ExprStringInterp, ExprUnaryOp, ExprVar, NoExprData, -}; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, InferredNode, VarBindingKind, import_is_all, import_specific_names_at, module_imports, module_items, param_node_type_expr, authored_name_at, NewlineIndex, expr_var_name_at, expr_call_func_at, expr_method_name_at, let_binding_name_at, param_node_name_at, resource_use_name_at, MatchPattern, LiteralValue, TextFile, SourceSpan, resource_use_resource, BinOp, UnaryOpKind, StringPart, DeclaredFuncSig, transport_has_auth, transport_auth_header_name, transport_headers, transport_env, ExprData, make_expr_node, MethodSemantics, FieldSummary, arg_value, arm_body, arm_pattern, arm_guard, field_init_node_name_at, field_init_node_value, if_condition, if_then_branch, if_else_branch, match_scrutinee, match_arm_nodes, let_value, let_body, field_access_base, field_access_field_at, method_receiver, expr_field_access_summary, expr_method_call_semantics, record_lit_type_name_at, lambda_body, cast_expr, cast_target, return_value, foreach_variable_at, foreach_collection, foreach_body, method_arg_nodes, index_base, index_expr, slice_base, slice_start, slice_end, with_required_cardinality, Connective, is_rest_transport, is_shell_transport, is_file_transport, FieldAccessStyle, Cardinality}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError}; +use crate::v2_std_core::VarBindingKind::{FunctionValueBinding}; +use crate::v2_std_core::BinOp::{NullCoalesce}; +use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprError, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit, ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp, ExprBlock, ExprCast, ExprForEach, ExprIndex, ExprSlice, ExprReturn}; +use crate::v2_std_core::MethodSemantics::{PlainMethodSemantics, AlgebraMethodSemantics, ServiceMethodSemantics}; use crate::v2_std_core::FieldAccessStyle::{TupleFirst, TupleSecond}; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved}; -use crate::v2_std_core::LiteralValue::*; +use crate::v2_std_core::StringPart::{Text, Interpolation}; +use crate::v2_std_core::Connective::{Conj, Disj}; +use crate::v2_std_core::Cardinality::{CardOptional}; use crate::v2_std_core::MatchPattern::*; -use crate::v2_std_core::MethodSemantics::{ - AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics, -}; -use crate::v2_std_core::StringPart::{Interpolation, Text}; +use crate::v2_std_core::LiteralValue::*; use crate::v2_std_core::UnaryOpKind::*; -use crate::v2_std_core::VarBindingKind::FunctionValueBinding; -pub use crate::v2_std_core::{ - arg_value, arm_body, arm_guard, arm_pattern, authored_name_at, cast_expr, cast_target, - expr_call_func_at, expr_field_access_summary, expr_method_call_semantics, expr_method_name_at, - expr_var_name_at, field_access_base, field_access_field_at, field_init_node_name_at, - field_init_node_value, foreach_body, foreach_collection, foreach_variable_at, if_condition, - if_else_branch, if_then_branch, import_is_all, import_specific_names_at, index_base, - index_expr, is_file_transport, is_rest_transport, is_shell_transport, lambda_body, - let_binding_name_at, let_body, let_value, make_expr_node, match_arm_nodes, match_scrutinee, - method_arg_nodes, method_receiver, module_imports, module_items, param_node_name_at, - param_node_type_expr, record_lit_type_name_at, resource_use_name_at, resource_use_resource, - return_value, slice_base, slice_end, slice_start, transport_auth_header_name, transport_env, - transport_has_auth, transport_headers, with_required_cardinality, BinOp, Cardinality, - Connective, DeclaredFuncSig, ExprData, FieldAccessStyle, FieldSummary, InferredNode, - LiteralValue, MatchPattern, MethodSemantics, NewlineIndex, Node, SourceSpan, StringPart, - TextFile, UnaryOpKind, VarBindingKind, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +pub use crate::v2_compiler_artifact::{RenderTarget}; +use crate::v2_compiler_artifact::RenderTarget::{Python}; +pub use crate::v2_compiler_languages::{scaffold_for_target, serialization_for_target, TestConventions, ItemKeywords, test_conventions_for_target, is_string_like}; +pub use crate::v2_compiler_infer_env::{TypeEnv, TypeBinding, authored_name}; +pub use crate::v2_compiler_infer_types::{resolved_type, normalize_access_type_node, node_is_keyed_collection}; +pub use crate::v2_compiler_infer_sigs::{ResolvedFuncSig, ResolvedFuncEnv}; +pub use crate::v2_compiler_infer_items::{ResolvedGraph, TypedModule, ItemInfo}; +pub use crate::v2_compiler_infer_service::{is_typed_service_call_receiver, extract_typed_service_name}; +pub use crate::v2_compiler_infer::{InferScope, build_params_scope, extend_scope, expr_span}; +pub use crate::std_induction::{SubValueRelation}; +use crate::std_induction::SubValueRelation::{SubValueUnknown}; +pub use crate::v2_compiler_emit::{EmitResult, BlockEmitState, InterpPart, TestProjection, emit_literal, emit_bin_op_symbol, emit_keyword, emit_container, emit_map_type, emit_node_type, emit_ident, emit_let_binding, emit_simple_expr, emit_unary_op, emit_lambda, emit_error_expr, emit_return, emit_lambda_params, emit_list_lit_expr, emit_shared_expr, emit_default_bin_op, emit_string_literal, escape_python_interp_text, escape_string_literal_body, empty_emit_scope, module_emit_scope, scope_after_expr, lookup_item, typed_named_arg_matches, order_typed_call_args, unique_strings, has_nested_records_node, escape_json_string, module_to_filename, make_indent, to_string, to_string_helper, to_snake, to_screaming_snake, is_upper, to_lower_char, to_upper_char, capitalize_first, sanitize_service_name, service_var_name, test_function_name, apply_type_template1, apply_type_template2, apply_type_template3, apply_named_template, language_spec, is_null_coalesce, emit_null_coalesce, is_type_alias_return_node, is_service_item, has_service_items, 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, extract_test_projections, is_tco_eligible, service_fallback_transport, effective_operation_transport, ServiceFieldSet, compute_service_fields, service_field_decls, service_field_ctors, seed_bindings, emit_expr_var_shared, emit_expr_field_access_shared, extract_string_interp_parts, emit_typed_cast_shared, emit_typed_for_each_shared, emit_typed_index_shared, emit_typed_slice_shared, emit_unified_init_block_stmts, emit_typed_if_shared, emit_typed_let_shared, emit_param_shared, emit_params_shared, emit_inferred_shared, emit_typed_block_join, emit_typed_first_arg_shared, emit_algebra_method_template, emit_typed_string_interp_unified, emit_typed_record_lit_unified, emit_typed_call_unified, emit_typed_method_call_unified, emit_typed_match_unified, emit_unified_typed_expr, emit_tco_unified, emit_unified_pattern, test_file_path, emit_unified_typed_func_body, emit_unified_service_def, emit_unified_operation_method, emit_unified_transport_dispatch}; pub fn emit_python(typed: &Rc) -> Rc { { let registry = typed.item_registry.clone(); - let test_projections = extract_test_projections(typed.clone()); - let module_files = Rc::new({ - let mut __result = Vec::new(); - for tm in typed.modules.clone().iter().cloned() { - __result.push(emit_py_module(&tm, registry.clone())); - } - __result - }); - let test_files = Rc::new({ - let mut __result = Vec::new(); - for f in Rc::new({ - let mut __result = Vec::new(); - for tm in typed.modules.clone().iter().cloned() { - __result.push(emit_py_test_file( - &authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ), - &Rc::new({ - let mut __result = Vec::new(); - for p in test_projections.clone().iter().cloned() { - if (p.module_name.clone().as_str() - == authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ) - .as_str()) - { - __result.push(p); - } - } - __result - }), - )); - } - __result - }) - .iter() - .cloned() - { - if (f.path.clone().as_str() != "".to_string().as_str()) { - __result.push(f); - } - } - __result - }); - let init_file = emit_init_py(typed.modules.clone()); - let requirements = emit_requirements_txt(has_service_items(typed.clone())); - let files = v2_rt::concat( - v2_rt::concat(Rc::new(vec![requirements, init_file]), module_files), - test_files, - ); - Rc::new(EmitResult { - files: files, - diagnostics: Rc::new(vec![]), - }) - } +let test_projections = extract_test_projections(typed.clone()); +let module_files = Rc::new({ let mut __result = Vec::new(); for tm in typed.modules.clone().iter().cloned() { __result.push(emit_py_module(&tm, registry.clone())); } __result }); +let test_files = Rc::new({ let mut __result = Vec::new(); for f in Rc::new({ let mut __result = Vec::new(); for tm in typed.modules.clone().iter().cloned() { __result.push(emit_py_test_file(&authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()), &Rc::new({ let mut __result = Vec::new(); for p in test_projections.clone().iter().cloned() { if (p.module_name.clone().as_str() == authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()).as_str()) { __result.push(p); } } __result }))); } __result }).iter().cloned() { if (f.path.clone().as_str() != "".to_string().as_str()) { __result.push(f); } } __result }); +let init_file = emit_init_py(typed.modules.clone()); +let requirements = emit_requirements_txt(has_service_items(typed.clone())); +let files = v2_rt::concat(v2_rt::concat(Rc::new(vec![requirements, init_file]), module_files), test_files); +Rc::new(EmitResult { + files: files, + diagnostics: Rc::new(vec![]), +}) +} } pub fn py_derive_attribute() -> String { - match serialization_for_target(RenderTarget::Python) - .derive_attribute - .clone() - { - Some(attr) => attr.clone(), - None => "@dataclass".to_string(), - } + match serialization_for_target(RenderTarget::Python).derive_attribute.clone() { + Some(attr) => attr.clone(), + None => "@dataclass".to_string(), +} } pub fn py_default_value() -> String { - match serialization_for_target(RenderTarget::Python) - .default_value - .clone() - { - Some(value) => value.clone(), - None => "None".to_string(), - } + match serialization_for_target(RenderTarget::Python).default_value.clone() { + Some(value) => value.clone(), + None => "None".to_string(), +} } pub fn emit_init_py(modules: Rc>>) -> Rc { { - let import_lines = Rc::new({ - let mut __result = Vec::new(); - for tm in modules.iter().cloned() { - __result.push({ - let mod_name = module_to_filename(authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - )); - let items = language_spec(RenderTarget::Python).items.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(items.import_from_keyword.clone(), " . ".to_string()), - items.import_keyword.clone(), - ), - " ".to_string(), - ), - mod_name.clone(), - ) - }); - } - __result - }); - let content = v2_rt::concat( - v2_rt::concat( - "# Generated by v2 compiler -- do not edit.\n\n".to_string(), - import_lines.join(&"\n".to_string()), - ), - "\n".to_string(), - ); - let init_path = match scaffold_for_target(RenderTarget::Python) - .module_init_file - .clone() - { - Some(path) => path.clone(), - None => "__init__.py".to_string(), - }; - Rc::new(TextFile { - path: init_path, - content: content, - }) - } + let import_lines = Rc::new({ let mut __result = Vec::new(); for tm in modules.iter().cloned() { __result.push({ + let mod_name = module_to_filename(authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone())); +let items = language_spec(RenderTarget::Python).items.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(items.import_from_keyword.clone(), " . ".to_string()), items.import_keyword.clone()), " ".to_string()), mod_name.clone()) +}); } __result }); +let content = v2_rt::concat(v2_rt::concat("# Generated by v2 compiler -- do not edit.\n\n".to_string(), import_lines.join(&"\n".to_string())), "\n".to_string()); +let init_path = match scaffold_for_target(RenderTarget::Python).module_init_file.clone() { + Some(path) => path.clone(), + None => "__init__.py".to_string(), +}; +Rc::new(TextFile { + path: init_path, + content: content, +}) +} } pub fn python_test_signature_comment(projection: &Rc) -> String { { - let params_str = Rc::new({ - let mut __result = Vec::new(); - for p in projection.params.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - param_node_name_at(p.clone(), projection.source_indices.clone()), - ": ".to_string(), - ), - emit_node_type( - param_node_type_expr(&p), - RenderTarget::Python, - projection.source_indices.clone(), - ), - )); - } - __result - }) - .join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "# Signature: ".to_string(), - sanitize_service_name(projection.service_name.clone()), - ), - ".".to_string(), - ), - projection.operation_name.clone(), - ), - "(".to_string(), - ), - params_str, - ), - ") -> ".to_string(), - ), - emit_node_type( - projection.inferred.clone(), - RenderTarget::Python, - projection.source_indices.clone(), - ), - ) - } + let params_str = Rc::new({ let mut __result = Vec::new(); for p in projection.params.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(param_node_name_at(p.clone(), projection.source_indices.clone()), ": ".to_string()), emit_node_type(param_node_type_expr(&p), RenderTarget::Python, projection.source_indices.clone()))); } __result }).join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("# Signature: ".to_string(), sanitize_service_name(projection.service_name.clone())), ".".to_string()), projection.operation_name.clone()), "(".to_string()), params_str), ") -> ".to_string()), emit_node_type(projection.inferred.clone(), RenderTarget::Python, projection.source_indices.clone())) +} } -pub fn emit_py_test_file( - module_name: &String, - projections: &Rc>>, -) -> Rc { +pub fn emit_py_test_file(module_name: &String, projections: &Rc>>) -> Rc { if ((projections.clone().len() as i64) == 0) { Rc::new(TextFile { - path: "".to_string(), - content: "".to_string(), - }) + path: "".to_string(), + content: "".to_string(), +}) } else { { - let tests_str = Rc::new({ - let mut __result = Vec::new(); - for p in projections.clone().iter().cloned() { - __result.push(emit_py_operation_test(&p, 0)); - } - __result - }) - .join(&"\n\n".to_string()); - let content = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "# Generated tests -- do not edit.\n".to_string(), - "# Source module: ".to_string(), - ), - module_name.clone(), - ), - "\n\n".to_string(), - ), - tests_str, - ), - "\n".to_string(), - ); - Rc::new(TextFile { - path: test_file_path(module_name.clone(), &RenderTarget::Python), - content: content, - }) - } + let tests_str = Rc::new({ let mut __result = Vec::new(); for p in projections.clone().iter().cloned() { __result.push(emit_py_operation_test(&p, 0)); } __result }).join(&"\n\n".to_string()); +let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("# Generated tests -- do not edit.\n".to_string(), "# Source module: ".to_string()), module_name.clone()), "\n\n".to_string()), tests_str), "\n".to_string()); +Rc::new(TextFile { + path: test_file_path(module_name.clone(), &RenderTarget::Python), + content: content, +}) +} } } pub fn emit_py_operation_test(projection: &Rc, depth: i64) -> String { { let test_name = test_function_name(&projection, RenderTarget::Python); - let indent = make_indent((depth.clone() + 1)); - let mock_setup = Rc::new({ - let mut __result = Vec::new(); - for mp in projection.mock_field_inits.clone().iter().cloned() { - __result.push(emit_py_mock_prop_setup( - &mp, - (depth.clone() + 1), - &projection.source_indices.clone(), - )); - } - __result - }) - .join(&"\n".to_string()); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Python).items.clone().func_keyword.clone(), " ".to_string()), test_name), "() -> None:\n".to_string()), indent.clone()), python_test_signature_comment(&projection)), "\n".to_string()), indent.clone()), mock_setup), "\n".to_string()), indent.clone()), "# TODO: add dry-run support to Python service emission for full invocation tests\n".to_string()), indent.clone()), "assert True # mock data setup verified\n".to_string()) - } +let indent = make_indent((depth.clone() + 1)); +let mock_setup = Rc::new({ let mut __result = Vec::new(); for mp in projection.mock_field_inits.clone().iter().cloned() { __result.push(emit_py_mock_prop_setup(&mp, (depth.clone() + 1), &projection.source_indices.clone())); } __result }).join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Python).items.clone().func_keyword.clone(), " ".to_string()), test_name), "() -> None:\n".to_string()), indent.clone()), python_test_signature_comment(&projection)), "\n".to_string()), indent.clone()), mock_setup), "\n".to_string()), indent.clone()), "# TODO: add dry-run support to Python service emission for full invocation tests\n".to_string()), indent.clone()), "assert True # mock data setup verified\n".to_string()) +} } -pub fn emit_py_mock_prop_setup( - mock_prop: &Rc, - depth: i64, - source_indices: &Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - emit_ident( - field_init_node_name_at(mock_prop.clone(), source_indices.clone()), - RenderTarget::Python, - ), - " = ".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&mock_prop), - &RenderTarget::Python, - &source_indices, - ), - ) +pub fn emit_py_mock_prop_setup(mock_prop: &Rc, depth: i64, source_indices: &Rc>>) -> String { + v2_rt::concat(v2_rt::concat(emit_ident(field_init_node_name_at(mock_prop.clone(), source_indices.clone()), RenderTarget::Python), " = ".to_string()), emit_simple_expr(&field_init_node_value(&mock_prop), &RenderTarget::Python, &source_indices)) } -pub fn emit_py_module( - typed_module: &Rc, - registry: Rc>>, -) -> Rc { +pub fn emit_py_module(typed_module: &Rc, registry: Rc>>) -> Rc { { let m = typed_module.module.clone(); - let scope = module_emit_scope(&typed_module); - let si = scope.type_env.clone().source_indices.clone(); - let mod_name_str = authored_name_at(si.clone(), &m); - let prelude = emit_py_prelude(typed_module.clone()); - let imports_str = emit_py_imports(&module_imports(m.clone()), si.clone()); - let imports_section = if (imports_str.clone().as_str() == "".to_string().as_str()) { +let scope = module_emit_scope(&typed_module); +let si = scope.type_env.clone().source_indices.clone(); +let mod_name_str = authored_name_at(si.clone(), &m); +let prelude = emit_py_prelude(typed_module.clone()); +let imports_str = emit_py_imports(&module_imports(m.clone()), si.clone()); +let imports_section = if (imports_str.clone().as_str() == "".to_string().as_str()) { "".to_string() } else { v2_rt::concat("\n".to_string(), imports_str.clone()) }; - let items_str = Rc::new({ - let mut __result = Vec::new(); - for item in typed_module.items.clone().iter().cloned() { - __result.push(emit_py_typed_item(&item, registry.clone(), &scope)); - } - __result - }) - .join(&"\n\n\n".to_string()); - let filename = module_to_filename(mod_name_str.clone()); - let content = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "# Generated by v2 compiler -- do not edit.\n".to_string(), - "# Source module: ".to_string(), - ), - mod_name_str.clone(), - ), - "\n\n".to_string(), - ), - prelude, - ), - imports_section, - ), - "\n\n\n".to_string(), - ), - items_str, - ), - "\n".to_string(), - ); - Rc::new(TextFile { - path: v2_rt::concat( - filename, - scaffold_for_target(RenderTarget::Python) - .source_file_extension - .clone(), - ), - content: content, - }) - } +let items_str = Rc::new({ let mut __result = Vec::new(); for item in typed_module.items.clone().iter().cloned() { __result.push(emit_py_typed_item(&item, registry.clone(), &scope)); } __result }).join(&"\n\n\n".to_string()); +let filename = module_to_filename(mod_name_str.clone()); +let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("# Generated by v2 compiler -- do not edit.\n".to_string(), "# Source module: ".to_string()), mod_name_str.clone()), "\n\n".to_string()), prelude), imports_section), "\n\n\n".to_string()), items_str), "\n".to_string()); +Rc::new(TextFile { + path: v2_rt::concat(filename, scaffold_for_target(RenderTarget::Python).source_file_extension.clone()), + content: content, +}) +} } -pub fn emit_py_imports( - imports: &Rc>>, - source_indices: Rc>>, -) -> String { +pub fn emit_py_imports(imports: &Rc>>, source_indices: Rc>>) -> String { if ((imports.clone().len() as i64) == 0) { "".to_string() } else { { - let import_lines = Rc::new({ - let mut __result = Vec::new(); - for imp in imports.clone().iter().cloned() { - __result.push({ - let mod_name = - module_to_filename(authored_name_at(source_indices.clone(), &imp)); - let items = language_spec(RenderTarget::Python).items.clone(); - if import_is_all(imp.clone()) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - items.import_from_keyword.clone(), - " ".to_string(), - ), - mod_name.clone(), - ), - " ".to_string(), - ), - items.import_keyword.clone(), - ), - " *".to_string(), - ) + let import_lines = Rc::new({ let mut __result = Vec::new(); for imp in imports.clone().iter().cloned() { __result.push({ + let mod_name = module_to_filename(authored_name_at(source_indices.clone(), &imp)); +let items = language_spec(RenderTarget::Python).items.clone(); +if import_is_all(imp.clone()) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(items.import_from_keyword.clone(), " ".to_string()), mod_name.clone()), " ".to_string()), items.import_keyword.clone()), " *".to_string()) + } else { + { + let specific_names = import_specific_names_at(imp.clone(), source_indices.clone()); +if ((specific_names.clone().len() as i64) == 0) { + "".to_string() } else { { - let specific_names = - import_specific_names_at(imp.clone(), source_indices.clone()); - if ((specific_names.clone().len() as i64) == 0) { - "".to_string() - } else { - { - let names_str = - specific_names.clone().join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - items.import_from_keyword.clone(), - " ".to_string(), - ), - mod_name.clone(), - ), - " ".to_string(), - ), - items.import_keyword.clone(), - ), - " ".to_string(), - ), - names_str.clone(), - ) - } - } - } + let names_str = specific_names.clone().join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(items.import_from_keyword.clone(), " ".to_string()), mod_name.clone()), " ".to_string()), items.import_keyword.clone()), " ".to_string()), names_str.clone()) +} } - }); - } - __result - }); - Rc::new({ - let mut __result = Vec::new(); - for line in import_lines.iter().cloned() { - if (line.clone().as_str() != "".to_string().as_str()) { - __result.push(line); - } +} } - __result - }) - .join(&"\n".to_string()) - } +}); } __result }); +Rc::new({ let mut __result = Vec::new(); for line in import_lines.iter().cloned() { if (line.clone().as_str() != "".to_string().as_str()) { __result.push(line); } } __result }).join(&"\n".to_string()) +} } } pub fn emit_py_prelude(typed_module: Rc) -> String { { let items = typed_module.items.clone(); - let has_structs = { - let mut __found = false; - for item in items.clone().iter().cloned() { - if (is_type_def_item(&item) && (item.connective.clone() == Connective::Conj)) { - __found = true; - break; - } - } - __found - }; - let has_enums = { - let mut __found = false; - for item in items.clone().iter().cloned() { - if (is_type_def_item(&item) && (item.connective.clone() == Connective::Disj)) { - __found = true; - break; - } - } - __found - }; - let has_services = { - let mut __found = false; - for item in items.clone().iter().cloned() { - if is_service_item(&item) { - __found = true; - break; - } - } - __found - }; - let future_import = "from __future__ import annotations\n".to_string(); - let dc_import = if has_structs.clone() { +let has_structs = { let mut __found = false; for item in items.clone().iter().cloned() { if (is_type_def_item(&item) && (item.connective.clone() == Connective::Conj)) { __found = true; break; } } __found }; +let has_enums = { let mut __found = false; for item in items.clone().iter().cloned() { if (is_type_def_item(&item) && (item.connective.clone() == Connective::Disj)) { __found = true; break; } } __found }; +let has_services = { let mut __found = false; for item in items.clone().iter().cloned() { if is_service_item(&item) { __found = true; break; } } __found }; +let future_import = "from __future__ import annotations\n".to_string(); +let dc_import = if has_structs.clone() { "from dataclasses import dataclass, field\n".to_string() } else { "".to_string() }; - let enum_import = if has_enums.clone() { +let enum_import = if has_enums.clone() { "from enum import Enum, auto\n".to_string() } else { "".to_string() }; - let typing_import = if (has_structs.clone() || has_enums.clone()) { +let typing_import = if (has_structs.clone() || has_enums.clone()) { "from typing import Optional, Union\n".to_string() } else { "".to_string() }; - let async_import = if has_services { +let async_import = if has_services { "import aiohttp\n".to_string() } else { "".to_string() }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(future_import, dc_import), enum_import), - typing_import, - ), - async_import, - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(future_import, dc_import), enum_import), typing_import), async_import) +} } -pub fn emit_py_typed_item( - item: &Rc, - registry: Rc>>, - scope: &Rc, -) -> String { +pub fn emit_py_typed_item(item: &Rc, registry: Rc>>, scope: &Rc) -> String { { let env = scope.type_env.clone(); - let item_text = authored_name(env.clone(), item.clone()); - if is_type_def_item(&item) { +let item_text = authored_name(env.clone(), item.clone()); +if is_type_def_item(&item) { emit_py_type_def_from_connective(&item, &env) } else { if is_type_alias_item(&item, env.source_indices.clone()) { - v2_rt::concat( - v2_rt::concat(item_text, " = ".to_string()), - emit_node_type( - resolved_type(item.clone()), - RenderTarget::Python, - env.source_indices.clone(), - ), - ) + v2_rt::concat(v2_rt::concat(item_text, " = ".to_string()), emit_node_type(resolved_type(item.clone()), RenderTarget::Python, env.source_indices.clone())) } else { if is_type_decl_item(&item, env.source_indices.clone()) { "".to_string() } else { if is_function_item(&item) { if ((item.uses.clone().len() as i64) > 0) { - emit_py_func_def( - &item_text, - &item.params.clone(), - resolved_type(item.clone()), - &item.uses.clone(), - item.body.clone().clone().unwrap(), - ®istry, - &scope, - ) + emit_py_func_def(&item_text, &item.params.clone(), resolved_type(item.clone()), &item.uses.clone(), item.body.clone().clone().unwrap(), ®istry, &scope) } else { - emit_py_fn_def( - &item_text, - &item.params.clone(), - resolved_type(item.clone()), - &item.body.clone().clone().unwrap(), - ®istry, - &scope, - ) + emit_py_fn_def(&item_text, &item.params.clone(), resolved_type(item.clone()), &item.body.clone().clone().unwrap(), ®istry, &scope) } } else { if is_data_def_item(&item) { - emit_py_data_def( - item_text, - item.type_annotation.clone().clone().unwrap(), - item.body.clone().clone().unwrap(), - registry, - &scope, - ) + emit_py_data_def(item_text, item.type_annotation.clone().clone().unwrap(), item.body.clone().clone().unwrap(), registry, &scope) } else { if is_service_def_item(&item) { emit_py_service_def(item.clone(), registry, env.clone()) @@ -625,915 +239,262 @@ pub fn emit_py_typed_item( } } } - } +} } pub fn emit_py_type_def_from_connective(item: &Rc, env: &Rc) -> String { { let item_text = authored_name(env.clone(), item.clone()); - let is_product = (item.connective.clone() == Connective::Conj); - if is_product { +let is_product = (item.connective.clone() == Connective::Conj); +if is_product { emit_py_dataclass_from_children(item_text, &item.children.clone(), env.clone()) } else { emit_py_enum_from_children(&item_text, &item.children.clone(), env.clone()) } - } +} } -pub fn emit_py_dataclass_from_children( - name: String, - children: &Rc>>, - env: Rc, -) -> String { +pub fn emit_py_dataclass_from_children(name: String, children: &Rc>>, env: Rc) -> String { if ((children.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(py_derive_attribute(), "\nclass ".to_string()), - name, - ), - ":\n pass".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(py_derive_attribute(), "\nclass ".to_string()), name), ":\n pass".to_string()) } else { { - let field_lines = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push(emit_py_dataclass_field_from_child(&child, &env)); - } - __result - }); - let fields_str = field_lines.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(py_derive_attribute(), "\nclass ".to_string()), - name, - ), - ":\n".to_string(), - ), - fields_str, - ) - } + let field_lines = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push(emit_py_dataclass_field_from_child(&child, &env)); } __result }); +let fields_str = field_lines.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(py_derive_attribute(), "\nclass ".to_string()), name), ":\n".to_string()), fields_str) +} } } pub fn emit_py_dataclass_field_from_child(child: &Rc, env: &Rc) -> String { { - let ty = emit_node_type( - resolved_type(child.clone()), - RenderTarget::Python, - env.source_indices.clone(), - ); - let is_optional = - (resolved_type(child.clone()).return_cardinality.clone() == Cardinality::CardOptional); - let default_str = if is_optional { + let ty = emit_node_type(resolved_type(child.clone()), RenderTarget::Python, env.source_indices.clone()); +let is_optional = (resolved_type(child.clone()).return_cardinality.clone() == Cardinality::CardOptional); +let default_str = if is_optional { v2_rt::concat(" = ".to_string(), py_default_value()) } else { "".to_string() }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " ".to_string(), - emit_ident( - authored_name(env.clone(), child.clone()), - RenderTarget::Python, - ), - ), - ": ".to_string(), - ), - ty, - ), - default_str, - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), emit_ident(authored_name(env.clone(), child.clone()), RenderTarget::Python)), ": ".to_string()), ty), default_str) +} } -pub fn emit_py_enum_from_children( - name: &String, - children: &Rc>>, - env: Rc, -) -> String { +pub fn emit_py_enum_from_children(name: &String, children: &Rc>>, env: Rc) -> String { { - let has_data = { - let mut __found = false; - for child in children.clone().iter().cloned() { - if ((child.children.clone().len() as i64) > 0) { - __found = true; - break; - } - } - __found - }; - if has_data { + let has_data = { let mut __found = false; for child in children.clone().iter().cloned() { if ((child.children.clone().len() as i64) > 0) { __found = true; break; } } __found }; +if has_data { { - let variant_classes = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push(emit_py_variant_class_from_child(name.clone(), &child, &env)); - } - __result - }); - let variant_names = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push(v2_rt::concat( - name.clone(), - authored_name(env.clone(), child.clone()), - )); - } - __result - }); - let union_str = variant_names.join(&", ".to_string()); - let classes_str = variant_classes.join(&"\n\n\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(classes_str, "\n\n\n".to_string()), - name.clone(), - ), - " = Union[".to_string(), - ), - union_str, - ), - "]".to_string(), - ) - } + let variant_classes = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push(emit_py_variant_class_from_child(name.clone(), &child, &env)); } __result }); +let variant_names = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push(v2_rt::concat(name.clone(), authored_name(env.clone(), child.clone()))); } __result }); +let union_str = variant_names.join(&", ".to_string()); +let classes_str = variant_classes.join(&"\n\n\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(classes_str, "\n\n\n".to_string()), name.clone()), " = Union[".to_string()), union_str), "]".to_string()) +} } else { { - let variant_lines = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - " ".to_string(), - authored_name(env.clone(), child.clone()), - ), - " = auto()".to_string(), - )); - } - __result - }); - let variants_str = variant_lines.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - language_spec(RenderTarget::Python) - .items - .clone() - .enum_keyword - .clone(), - " ".to_string(), - ), - name.clone(), - ), - "(Enum):\n".to_string(), - ), - variants_str, - ) - } + let variant_lines = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(" ".to_string(), authored_name(env.clone(), child.clone())), " = auto()".to_string())); } __result }); +let variants_str = variant_lines.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(language_spec(RenderTarget::Python).items.clone().enum_keyword.clone(), " ".to_string()), name.clone()), "(Enum):\n".to_string()), variants_str) +} } - } +} } -pub fn emit_py_variant_class_from_child( - parent_name: String, - child: &Rc, - env: &Rc, -) -> String { +pub fn emit_py_variant_class_from_child(parent_name: String, child: &Rc, env: &Rc) -> String { { let class_name = v2_rt::concat(parent_name, authored_name(env.clone(), child.clone())); - if ((child.children.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(py_derive_attribute(), "\nclass ".to_string()), - class_name, - ), - ":\n pass".to_string(), - ) +if ((child.children.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(py_derive_attribute(), "\nclass ".to_string()), class_name), ":\n pass".to_string()) } else { { - let field_lines = Rc::new({ - let mut __result = Vec::new(); - for f in child.children.clone().iter().cloned() { - __result.push(emit_py_dataclass_field_from_child(&f, &env)); - } - __result - }); - let fields_str = field_lines.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(py_derive_attribute(), "\nclass ".to_string()), - class_name, - ), - ":\n".to_string(), - ), - fields_str, - ) - } + let field_lines = Rc::new({ let mut __result = Vec::new(); for f in child.children.clone().iter().cloned() { __result.push(emit_py_dataclass_field_from_child(&f, &env)); } __result }); +let fields_str = field_lines.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(py_derive_attribute(), "\nclass ".to_string()), class_name), ":\n".to_string()), fields_str) +} } - } +} } -pub fn emit_py_fn_def( - name: &String, - params: &Rc>>, - inferred: Rc, - body: &Rc, - registry: &Rc>>, - scope: &Rc, -) -> String { +pub fn emit_py_fn_def(name: &String, params: &Rc>>, inferred: Rc, body: &Rc, registry: &Rc>>, scope: &Rc) -> String { { let depth = 0; - let si = scope.type_env.clone().source_indices.clone(); - let params_str = emit_params_shared(params.clone(), &RenderTarget::Python, si.clone()); - let ret_str = emit_inferred_shared(&inferred, &RenderTarget::Python, si.clone()); - let body_scope = build_params_scope(&scope, params.clone()); - let use_tco = is_tco_eligible(&name, &body, registry.clone(), &si); - if use_tco { +let si = scope.type_env.clone().source_indices.clone(); +let params_str = emit_params_shared(params.clone(), &RenderTarget::Python, si.clone()); +let ret_str = emit_inferred_shared(&inferred, &RenderTarget::Python, si.clone()); +let body_scope = build_params_scope(&scope, params.clone()); +let use_tco = is_tco_eligible(&name, &body, registry.clone(), &si); +if use_tco { { - let body_str = emit_tco_unified( - body.clone(), - &name, - ¶ms, - &RenderTarget::Python, - ®istry, - &body_scope, - (depth.clone() + 1), - |pat| emit_unified_pattern(pat.clone(), RenderTarget::Python, si.clone()), - ); - let kw = language_spec(RenderTarget::Python) - .items - .clone() - .func_keyword - .clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(kw, " ".to_string()), - emit_ident(name.clone(), RenderTarget::Python), - ), - "(".to_string(), - ), - params_str, - ), - ")".to_string(), - ), - ret_str, - ), - ":\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - body_str, - ) - } + let body_str = emit_tco_unified(body.clone(), &name, ¶ms, &RenderTarget::Python, ®istry, &body_scope, (depth.clone() + 1), |pat| emit_unified_pattern(pat.clone(), RenderTarget::Python, si.clone())); +let kw = language_spec(RenderTarget::Python).items.clone().func_keyword.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(kw, " ".to_string()), emit_ident(name.clone(), RenderTarget::Python)), "(".to_string()), params_str), ")".to_string()), ret_str), ":\n".to_string()), make_indent((depth.clone() + 1))), body_str) +} } else { { - let body_str = emit_py_typed_expr( - body.clone(), - registry.clone(), - &body_scope, - (depth.clone() + 1), - 1024, - ); - let kw = language_spec(RenderTarget::Python) - .items - .clone() - .func_keyword - .clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(kw, " ".to_string()), - emit_ident(name.clone(), RenderTarget::Python), - ), - "(".to_string(), - ), - params_str, - ), - ")".to_string(), - ), - ret_str, - ), - ":\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - "return ".to_string(), - ), - body_str, - ) - } + let body_str = emit_py_typed_expr(body.clone(), registry.clone(), &body_scope, (depth.clone() + 1), 1024); +let kw = language_spec(RenderTarget::Python).items.clone().func_keyword.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(kw, " ".to_string()), emit_ident(name.clone(), RenderTarget::Python)), "(".to_string()), params_str), ")".to_string()), ret_str), ":\n".to_string()), make_indent((depth.clone() + 1))), "return ".to_string()), body_str) +} } - } +} } -pub fn emit_py_func_def( - name: &String, - params: &Rc>>, - inferred: Rc, - uses: &Rc>>, - body: Rc, - registry: &Rc>>, - scope: &Rc, -) -> String { +pub fn emit_py_func_def(name: &String, params: &Rc>>, inferred: Rc, uses: &Rc>>, body: Rc, registry: &Rc>>, scope: &Rc) -> String { { let depth = 0; - let service_names = match lookup_item(registry.clone(), name.clone()) { - Some(info) => info.service_names.clone(), - None => Rc::new(vec![]), - }; - let params_str = emit_py_func_params( - params.clone(), - uses.clone(), - service_names, - scope.type_env.clone().source_indices.clone(), - ); - let ret_str = emit_inferred_shared( - &inferred, - &RenderTarget::Python, - scope.type_env.clone().source_indices.clone(), - ); - let body_scope = build_params_scope(&scope, params.clone()); - let si = scope.type_env.clone().source_indices.clone(); - let body_scope = uses.clone().iter().cloned().fold( - body_scope.clone(), - |s: Rc, u: Rc| { - extend_scope( - &s, - &resource_use_name_at(u.clone(), si.clone()), - resource_use_resource(&u), - Rc::new(SubValueRelation::SubValueUnknown), - ) - }, - ); - let body_str = emit_unified_typed_func_body( - &body, - &RenderTarget::Python, - ®istry, - &body_scope, - (depth.clone() + 1), - ); - let items = language_spec(RenderTarget::Python).items.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - items.async_prefix.clone(), - items.func_keyword.clone(), - ), - " ".to_string(), - ), - emit_ident(name.clone(), RenderTarget::Python), - ), - "(".to_string(), - ), - params_str, - ), - ")".to_string(), - ), - ret_str, - ), - ":\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - body_str, - ) - } +let service_names = match lookup_item(registry.clone(), name.clone()) { + Some(info) => info.service_names.clone(), + None => Rc::new(vec![]), +}; +let params_str = emit_py_func_params(params.clone(), uses.clone(), service_names, scope.type_env.clone().source_indices.clone()); +let ret_str = emit_inferred_shared(&inferred, &RenderTarget::Python, scope.type_env.clone().source_indices.clone()); +let body_scope = build_params_scope(&scope, params.clone()); +let si = scope.type_env.clone().source_indices.clone(); +let body_scope = uses.clone().iter().cloned().fold(body_scope.clone(), |s: Rc, u: Rc| extend_scope(&s, &resource_use_name_at(u.clone(), si.clone()), resource_use_resource(&u), Rc::new(SubValueRelation::SubValueUnknown))); +let body_str = emit_unified_typed_func_body(&body, &RenderTarget::Python, ®istry, &body_scope, (depth.clone() + 1)); +let items = language_spec(RenderTarget::Python).items.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(items.async_prefix.clone(), items.func_keyword.clone()), " ".to_string()), emit_ident(name.clone(), RenderTarget::Python)), "(".to_string()), params_str), ")".to_string()), ret_str), ":\n".to_string()), make_indent((depth.clone() + 1))), body_str) +} } -pub fn emit_py_func_params( - params: Rc>>, - uses: Rc>>, - service_names: Rc>, - source_indices: Rc>>, -) -> String { +pub fn emit_py_func_params(params: Rc>>, uses: Rc>>, service_names: Rc>, source_indices: Rc>>) -> String { { - let param_strs = Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - __result.push(emit_param_shared( - &p, - &RenderTarget::Python, - &source_indices, - )); - } - __result - }); - let resource_strs = Rc::new({ - let mut __result = Vec::new(); - for u in uses.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - resource_use_name_at(u.clone(), source_indices.clone()), - RenderTarget::Python, - ), - ": ".to_string(), - ), - emit_node_type( - resource_use_resource(&u), - RenderTarget::Python, - source_indices.clone(), - ), - )); - } - __result - }); - let service_strs = Rc::new({ - let mut __result = Vec::new(); - for sn in service_names.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat(service_var_name(sn.clone()), ": ".to_string()), - sanitize_service_name(sn.clone()), - )); - } - __result - }); - let all_params = v2_rt::concat(v2_rt::concat(param_strs, resource_strs), service_strs); - all_params.join(&", ".to_string()) - } + let param_strs = Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { __result.push(emit_param_shared(&p, &RenderTarget::Python, &source_indices)); } __result }); +let resource_strs = Rc::new({ let mut __result = Vec::new(); for u in uses.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(resource_use_name_at(u.clone(), source_indices.clone()), RenderTarget::Python), ": ".to_string()), emit_node_type(resource_use_resource(&u), RenderTarget::Python, source_indices.clone()))); } __result }); +let service_strs = Rc::new({ let mut __result = Vec::new(); for sn in service_names.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(service_var_name(sn.clone()), ": ".to_string()), sanitize_service_name(sn.clone()))); } __result }); +let all_params = v2_rt::concat(v2_rt::concat(param_strs, resource_strs), service_strs); +all_params.join(&", ".to_string()) +} } -pub fn emit_py_typed_expr( - texpr: Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - fuel: i64, -) -> String { - emit_unified_typed_expr( - texpr, - &RenderTarget::Python, - registry, - &scope, - depth, - fuel, - |pat| { - emit_unified_pattern( - pat.clone(), - RenderTarget::Python, - scope.type_env.clone().source_indices.clone(), - ) - }, - ) +pub fn emit_py_typed_expr(texpr: Rc, registry: Rc>>, scope: &Rc, depth: i64, fuel: i64) -> String { + emit_unified_typed_expr(texpr, &RenderTarget::Python, registry, &scope, depth, fuel, |pat| emit_unified_pattern(pat.clone(), RenderTarget::Python, scope.type_env.clone().source_indices.clone())) } -pub fn emit_py_transport_body( - transport: Rc, - op_name: String, - source_indices: Rc>>, - depth: i64, -) -> String { - emit_unified_transport_dispatch( - &transport, - op_name, - &source_indices, - depth, - RenderTarget::Python, - |n, t, d, si| emit_py_rest_call(n.clone(), t.clone(), si.clone()), - |n, t, d, si| emit_py_shell_call(n.clone(), t.clone(), &si), - |n, d| emit_py_file_call(n.clone()), - |n, d| emit_py_local_call(n.clone()), - ) +pub fn emit_py_transport_body(transport: Rc, op_name: String, source_indices: Rc>>, depth: i64) -> String { + emit_unified_transport_dispatch(&transport, op_name, &source_indices, depth, RenderTarget::Python, |n, t, d, si| emit_py_rest_call(n.clone(), t.clone(), si.clone()), |n, t, d, si| emit_py_shell_call(n.clone(), t.clone(), &si), |n, d| emit_py_file_call(n.clone()), |n, d| emit_py_local_call(n.clone())) } -pub fn emit_py_service_def( - item: Rc, - registry: Rc>>, - env: Rc, -) -> String { - emit_unified_service_def( - &item, - &RenderTarget::Python, - registry, - &env, - |name, transport, ops, si| emit_py_service_init(transport.clone(), ops.clone(), si.clone()), - |transport, op_name, si, depth| { - emit_py_transport_body( - transport.clone(), - op_name.clone(), - si.clone(), - depth.clone(), - ) - }, - ) +pub fn emit_py_service_def(item: Rc, registry: Rc>>, env: Rc) -> String { + emit_unified_service_def(&item, &RenderTarget::Python, registry, &env, |name, transport, ops, si| emit_py_service_init(transport.clone(), ops.clone(), si.clone()), |transport, op_name, si, depth| emit_py_transport_body(transport.clone(), op_name.clone(), si.clone(), depth.clone())) } -pub fn emit_py_service_init( - fallback_transport: Rc, - op_children: Rc>>, - source_indices: Rc>>, -) -> String { +pub fn emit_py_service_init(fallback_transport: Rc, op_children: Rc>>, source_indices: Rc>>) -> String { { let fs = compute_service_fields(&fallback_transport, &op_children, &source_indices); - let params = service_field_decls( - &fs, - &language_spec(RenderTarget::Python).service_fields.clone(), - ); - let assigns = service_field_ctors( - &fs, - &language_spec(RenderTarget::Python).service_fields.clone(), - ); - if ((params.clone().len() as i64) == 0) { +let params = service_field_decls(&fs, &language_spec(RenderTarget::Python).service_fields.clone()); +let assigns = service_field_ctors(&fs, &language_spec(RenderTarget::Python).service_fields.clone()); +if ((params.clone().len() as i64) == 0) { "def __init__(self):\n pass".to_string() } else { { - let params_str = - v2_rt::concat("self, ".to_string(), params.clone().join(&", ".to_string())); - let assigns_str = Rc::new({ - let mut __result = Vec::new(); - for a in assigns.iter().cloned() { - __result.push(v2_rt::concat(" ".to_string(), a.clone())); - } - __result - }) - .join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("def __init__(".to_string(), params_str), - "):\n".to_string(), - ), - assigns_str, - ) - } + let params_str = v2_rt::concat("self, ".to_string(), params.clone().join(&", ".to_string())); +let assigns_str = Rc::new({ let mut __result = Vec::new(); for a in assigns.iter().cloned() { __result.push(v2_rt::concat(" ".to_string(), a.clone())); } __result }).join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat("def __init__(".to_string(), params_str), "):\n".to_string()), assigns_str) +} } - } +} } -pub fn emit_py_rest_call( - op_name: String, - transport: Rc, - source_indices: Rc>>, -) -> String { +pub fn emit_py_rest_call(op_name: String, transport: Rc, source_indices: Rc>>) -> String { { - let self_base_url = v2_rt::concat( - v2_rt::concat("{".to_string(), "self.base_url".to_string()), - "}".to_string(), - ); - let url_line = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("url = f\"".to_string(), self_base_url), - "/".to_string(), - ), - emit_ident(op_name, RenderTarget::Python), - ), - "\"".to_string(), - ); - let headers_dict = emit_py_headers_dict(&transport, &source_indices); - let session_lines = v2_rt::concat( - v2_rt::concat( - "async with aiohttp.ClientSession() as session:\n".to_string(), - " async with session.post(url, headers=headers) as response:\n".to_string(), - ), - " return await response.json()".to_string(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(url_line, "\n".to_string()), headers_dict), - "\n".to_string(), - ), - session_lines, - ) - } + let self_base_url = v2_rt::concat(v2_rt::concat("{".to_string(), "self.base_url".to_string()), "}".to_string()); +let url_line = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("url = f\"".to_string(), self_base_url), "/".to_string()), emit_ident(op_name, RenderTarget::Python)), "\"".to_string()); +let headers_dict = emit_py_headers_dict(&transport, &source_indices); +let session_lines = v2_rt::concat(v2_rt::concat("async with aiohttp.ClientSession() as session:\n".to_string(), " async with session.post(url, headers=headers) as response:\n".to_string()), " return await response.json()".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(url_line, "\n".to_string()), headers_dict), "\n".to_string()), session_lines) +} } -pub fn emit_py_headers_dict( - transport: &Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_py_headers_dict(transport: &Rc, source_indices: &Rc>>) -> String { { let auth_entry = if transport_has_auth(transport.clone(), source_indices.clone()) { { - let header_name = - match transport_auth_header_name(transport.clone(), source_indices.clone()) { - Some(h) => h.clone(), - None => "Authorization".to_string(), - }; - v2_rt::concat( - v2_rt::concat("\"".to_string(), header_name), - "\": self.auth_token, ".to_string(), - ) - } + let header_name = match transport_auth_header_name(transport.clone(), source_indices.clone()) { + Some(h) => h.clone(), + None => "Authorization".to_string(), +}; +v2_rt::concat(v2_rt::concat("\"".to_string(), header_name), "\": self.auth_token, ".to_string()) +} } else { "".to_string() }; - let hdrs = transport_headers(transport.clone(), source_indices.clone()); - let header_entries = Rc::new({ - let mut __result = Vec::new(); - for h in hdrs.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "\"".to_string(), - field_init_node_name_at(h.clone(), source_indices.clone()), - ), - "\": ".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&h), - &RenderTarget::Python, - &source_indices, - ), - )); - } - __result - }); - let all_entries = if (auth_entry.clone().as_str() == "".to_string().as_str()) { +let hdrs = transport_headers(transport.clone(), source_indices.clone()); +let header_entries = Rc::new({ let mut __result = Vec::new(); for h in hdrs.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat("\"".to_string(), field_init_node_name_at(h.clone(), source_indices.clone())), "\": ".to_string()), emit_simple_expr(&field_init_node_value(&h), &RenderTarget::Python, &source_indices))); } __result }); +let all_entries = if (auth_entry.clone().as_str() == "".to_string().as_str()) { header_entries.join(&", ".to_string()) } else { v2_rt::concat(auth_entry.clone(), header_entries.join(&", ".to_string())) }; - v2_rt::concat( - v2_rt::concat("headers = {".to_string(), all_entries), - "}".to_string(), - ) - } +v2_rt::concat(v2_rt::concat("headers = {".to_string(), all_entries), "}".to_string()) +} } -pub fn emit_py_shell_call( - op_name: String, - transport: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_py_shell_call(op_name: String, transport: Rc, source_indices: &Rc>>) -> String { { let envs = transport_env(transport, source_indices.clone()); - let env_dict_entries = Rc::new({ - let mut __result = Vec::new(); - for e in envs.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "\"".to_string(), - field_init_node_name_at(e.clone(), source_indices.clone()), - ), - "\": ".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&e), - &RenderTarget::Python, - &source_indices, - ), - )); - } - __result - }); - let env_str = v2_rt::concat( - v2_rt::concat("{".to_string(), env_dict_entries.join(&", ".to_string())), - "}".to_string(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "import subprocess\n".to_string(), - "result = subprocess.run(\n".to_string(), - ), - " [\"".to_string(), - ), - emit_ident(op_name, RenderTarget::Python), - ), - "\"],\n".to_string(), - ), - " cwd=self.working_dir or \".\",\n".to_string(), - ), - " env=".to_string(), - ), - env_str, - ), - ",\n".to_string(), - ), - " capture_output=True, text=True,\n".to_string(), - ), - ")\n".to_string(), - ), - "return result.stdout".to_string(), - ) - } +let env_dict_entries = Rc::new({ let mut __result = Vec::new(); for e in envs.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat("\"".to_string(), field_init_node_name_at(e.clone(), source_indices.clone())), "\": ".to_string()), emit_simple_expr(&field_init_node_value(&e), &RenderTarget::Python, &source_indices))); } __result }); +let env_str = v2_rt::concat(v2_rt::concat("{".to_string(), env_dict_entries.join(&", ".to_string())), "}".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("import subprocess\n".to_string(), "result = subprocess.run(\n".to_string()), " [\"".to_string()), emit_ident(op_name, RenderTarget::Python)), "\"],\n".to_string()), " cwd=self.working_dir or \".\",\n".to_string()), " env=".to_string()), env_str), ",\n".to_string()), " capture_output=True, text=True,\n".to_string()), ")\n".to_string()), "return result.stdout".to_string()) +} } pub fn emit_py_file_call(op_name: String) -> String { { - let self_base_path = v2_rt::concat( - v2_rt::concat("{".to_string(), "self.base_path".to_string()), - "}".to_string(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("path = f\"".to_string(), self_base_path), - "/".to_string(), - ), - emit_ident(op_name, RenderTarget::Python), - ), - "\"\n".to_string(), - ), - "with open(path) as f:\n".to_string(), - ), - " return f.read()".to_string(), - ) - } + let self_base_path = v2_rt::concat(v2_rt::concat("{".to_string(), "self.base_path".to_string()), "}".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("path = f\"".to_string(), self_base_path), "/".to_string()), emit_ident(op_name, RenderTarget::Python)), "\"\n".to_string()), "with open(path) as f:\n".to_string()), " return f.read()".to_string()) +} } pub fn emit_py_local_call(op_name: String) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "# Local binding -- direct function call\n".to_string(), - "return ".to_string(), - ), - emit_ident(op_name, RenderTarget::Python), - ), - "()".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat("# Local binding -- direct function call\n".to_string(), "return ".to_string()), emit_ident(op_name, RenderTarget::Python)), "()".to_string()) } pub fn emit_py_resource_def(item: &Rc, env: &Rc) -> String { { let item_text = authored_name(env.clone(), item.clone()); - let depth = 0; - let cap_children = item.children.clone(); - let methods = Rc::new({ - let mut __result = Vec::new(); - for c in cap_children.iter().cloned() { - __result.push(emit_py_capability_method(&c, &env)); - } - __result - }); - let methods_str = methods.join(&"\n\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "from abc import ABC, abstractmethod\n\n".to_string(), - language_spec(RenderTarget::Python) - .items - .clone() - .struct_keyword - .clone(), - ), - " ".to_string(), - ), - item_text, - ), - "(ABC):\n".to_string(), - ), - make_indent((depth + 1)), - ), - methods_str, - ) - } +let depth = 0; +let cap_children = item.children.clone(); +let methods = Rc::new({ let mut __result = Vec::new(); for c in cap_children.iter().cloned() { __result.push(emit_py_capability_method(&c, &env)); } __result }); +let methods_str = methods.join(&"\n\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("from abc import ABC, abstractmethod\n\n".to_string(), language_spec(RenderTarget::Python).items.clone().struct_keyword.clone()), " ".to_string()), item_text), "(ABC):\n".to_string()), make_indent((depth + 1))), methods_str) +} } pub fn emit_py_capability_method(cap_node: &Rc, env: &Rc) -> String { { - let input_params = Rc::new({ - let mut __result = Vec::new(); - for p in cap_node.params.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - param_node_name_at(p.clone(), env.source_indices.clone()), - RenderTarget::Python, - ), - ": ".to_string(), - ), - emit_node_type( - param_node_type_expr(&p), - RenderTarget::Python, - env.source_indices.clone(), - ), - )); - } - __result - }); - let params_str = input_params.join(&", ".to_string()); - let all_params = if (params_str.clone().as_str() == "".to_string().as_str()) { + let input_params = Rc::new({ let mut __result = Vec::new(); for p in cap_node.params.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(param_node_name_at(p.clone(), env.source_indices.clone()), RenderTarget::Python), ": ".to_string()), emit_node_type(param_node_type_expr(&p), RenderTarget::Python, env.source_indices.clone()))); } __result }); +let params_str = input_params.join(&", ".to_string()); +let all_params = if (params_str.clone().as_str() == "".to_string().as_str()) { "self".to_string() } else { v2_rt::concat("self, ".to_string(), params_str.clone()) }; - let ret = emit_node_type( - resolved_type(cap_node.clone()), - RenderTarget::Python, - env.source_indices.clone(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "@abstractmethod\n".to_string(), - language_spec(RenderTarget::Python) - .items - .clone() - .async_prefix - .clone(), - ), - language_spec(RenderTarget::Python) - .items - .clone() - .func_keyword - .clone(), - ), - " ".to_string(), - ), - emit_ident( - authored_name(env.clone(), cap_node.clone()), - RenderTarget::Python, - ), - ), - "(".to_string(), - ), - all_params, - ), - ") -> ".to_string(), - ), - ret, - ), - ":\n".to_string(), - ), - " ...".to_string(), - ) - } +let ret = emit_node_type(resolved_type(cap_node.clone()), RenderTarget::Python, env.source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("@abstractmethod\n".to_string(), language_spec(RenderTarget::Python).items.clone().async_prefix.clone()), language_spec(RenderTarget::Python).items.clone().func_keyword.clone()), " ".to_string()), emit_ident(authored_name(env.clone(), cap_node.clone()), RenderTarget::Python)), "(".to_string()), all_params), ") -> ".to_string()), ret), ":\n".to_string()), " ...".to_string()) +} } -pub fn emit_py_data_def( - name: String, - type_node: Rc, - value: Rc, - registry: Rc>>, - scope: &Rc, -) -> String { +pub fn emit_py_data_def(name: String, type_node: Rc, value: Rc, registry: Rc>>, scope: &Rc) -> String { { - let ty_str = emit_node_type( - type_node, - RenderTarget::Python, - scope.type_env.clone().source_indices.clone(), - ); - let upper_name = to_screaming_snake(name); - let val_str = emit_py_typed_expr(value, registry, &scope, 0, 1024); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(upper_name, ": ".to_string()), ty_str), - " = ".to_string(), - ), - val_str, - ) - } + let ty_str = emit_node_type(type_node, RenderTarget::Python, scope.type_env.clone().source_indices.clone()); +let upper_name = to_screaming_snake(name); +let val_str = emit_py_typed_expr(value, registry, &scope, 0, 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(upper_name, ": ".to_string()), ty_str), " = ".to_string()), val_str) +} } pub fn emit_requirements_txt(has_services: bool) -> Rc { { let base_deps = "".to_string(); - let async_deps = if has_services { +let async_deps = if has_services { "aiohttp>=3.9\n".to_string() } else { "".to_string() }; - Rc::new(TextFile { - path: "requirements.txt".to_string(), - content: v2_rt::concat(base_deps, async_deps), - }) - } +Rc::new(TextFile { + path: "requirements.txt".to_string(), + content: v2_rt::concat(base_deps, async_deps), +}) +} } diff --git a/src/v2/stage0/src/v2_compiler_emit_rust.rs b/src/v2/stage0/src/v2_compiler_emit_rust.rs index f8beb7fa92b..808074010a1 100644 --- a/src/v2/stage0/src/v2_compiler_emit_rust.rs +++ b/src/v2/stage0/src/v2_compiler_emit_rust.rs @@ -1,211 +1,121 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.emit_rust -pub use crate::extdeps_languages_rust_emit::{ - rt_bridge_function_names, rt_functions, rt_ref_map_functions, rt_wraps_result, - rust_container_templates, rust_enum_derives, rust_enum_derives_copy, rust_higher_order_methods, - rust_method_wraps_result, rust_struct_derives, rust_struct_derives_copy, HigherOrderMethodSpec, -}; -pub use crate::generated_method_template_projection::rust_method_template_emit; -pub use crate::std_induction::SubValueRelation; -use crate::std_induction::SubValueRelation::SubValueUnknown; -pub use crate::std_types::is_container_type; -pub use crate::v2_compiler_artifact::RenderTarget; -use crate::v2_compiler_artifact::RenderTarget::Rust; -pub use crate::v2_compiler_coercion::{coerce_primitive_type, is_copy, lookup_checkpoint}; -pub use crate::v2_compiler_compiler_tests_rust::compiler_tests_source; -pub use crate::v2_compiler_emit::{ - apply_named_template, apply_type_template1, apply_type_template2, apply_type_template3, - capitalize_first, compute_service_fields, effective_operation_transport, emit_bin_op_symbol, - emit_data_value_json, emit_error_expr, emit_ident, emit_keyword, emit_lambda, - emit_lambda_params, emit_let_binding, emit_let_binding_annotated, emit_list_lit_expr, - emit_literal, emit_node_type, emit_null_coalesce, emit_return, emit_shared_expr, - emit_shared_tco_expr, emit_simple_expr, emit_string_literal, emit_typed_cast_shared, - emit_typed_if_shared, emit_typed_let_shared, emit_unary_op, escape_json_string, - escape_rust_interp_text, escape_string_literal_body, extract_modifier_names, - extract_test_projections, has_mock_prefix, has_nested_records_node, has_service_items, - is_data_def_item, is_function_item, is_null_coalesce, is_resource_def_item, is_self_recursive, - is_service_def_item, is_service_item, is_tco_eligible, is_tco_identity_passthrough, - is_type_alias_item, is_type_alias_return_node, is_type_decl_item, is_type_def_item, is_upper, - language_spec, lookup_item, make_indent, module_emit_scope, module_to_filename, - order_typed_call_args, render_node_type, rust_literal_for_pattern, sanitize_service_name, - scope_after_expr, seed_bindings, service_fallback_transport, service_field_ctors, - service_field_decls, service_var_name, tco_reassign_core, test_function_name, to_lower_char, - to_pascal, to_screaming_snake, to_snake, to_string, to_string_helper, to_upper_char, - typed_named_arg_matches, unique_strings, BlockEmitState, EmitResult, InterpPart, - ServiceFieldSet, TcoFrame, TcoReassignInput, TestProjection, -}; -pub use crate::v2_compiler_infer::{ - build_emit_graph_info, build_params_scope, expr_span, extend_scope, InferScope, -}; -use crate::v2_compiler_infer_emit_info::TypeRepr::{EnumRepr, StructRepr}; -pub use crate::v2_compiler_infer_emit_info::{ - find_variant_parent, is_enum_in_summaries, is_known_variant, lookup_emit_type_summary, - variant_belongs_to_enum, EmitGraphInfo, TypeRepr, TypeSummary, -}; -pub use crate::v2_compiler_infer_env::{authored_name, lookup_type_by_name, TypeBinding, TypeEnv}; -use crate::v2_compiler_infer_items::ItemKind::DataItem; -pub use crate::v2_compiler_infer_items::{ItemInfo, ItemKind, ResolvedGraph, TypedModule}; -pub use crate::v2_compiler_infer_service::{ - extract_typed_service_name, is_typed_service_call_receiver, -}; -pub use crate::v2_compiler_infer_sigs::ResolvedFuncEnv; -pub use crate::v2_compiler_infer_types::{ - child_type_node, emit_map_has, for_each_element_type_node, is_coproduct_type, is_product_type, - is_unit_like, node_is_collection, node_is_element_collection, node_is_keyed_collection, - normalize_access_type_node, resolved_type, -}; -use crate::v2_compiler_languages::VisibilitySpec::KeywordVisibility; -pub use crate::v2_compiler_languages::{ - is_string_like, scaffold_for_target, serialization_for_target, sharing_for_target, - test_conventions_for_target, visibility_for_target, ItemKeywords, TestConventions, - VisibilitySpec, -}; -pub use crate::v2_compiler_ownership::{ - analyze_ownership, analyze_single_fold, build_movable_set, build_read_only_params, - collect_callable_refs, OwnershipProof, -}; -pub use crate::v2_compiler_runtime_rust::rust_runtime_source; +use std::collections::HashMap; +use std::rc::Rc; use crate::v2_rt; -use crate::v2_std_core::AlgebraFieldKind::*; -use crate::v2_std_core::BinOp::*; -use crate::v2_std_core::CallSemantics::{LookupCallSemantics, PlainCallSemantics}; -use crate::v2_std_core::Cardinality::{CardOptional, Required}; -use crate::v2_std_core::CompilerDiagnostic::InternalError; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, InferredNode, is_compiler_error, import_is_all, import_specific_names_at, module_imports, module_items, param_node_type_expr, param_node_default_value, authored_name_at, NewlineIndex, find_child_named, expr_var_name_at, expr_call_func_at, field_access_field_at, param_node_name_at, resource_use_name_at, field_binding_name_at, generic_param_name_at, LiteralValue, ExprData, make_expr_node, FieldSummary, VarBindingKind, CallSemantics, MethodSemantics, MatchPattern, field_binding_pattern, TextFile, ErrorNode, make_error_node, SourceSpan, resource_use_resource, BinOp, AlgebraFieldKind, UnaryOpKind, StringPart, transport_base_url, transport_has_auth, transport_auth_token, transport_auth_header_name, transport_headers, transport_env, transport_method, transport_path_template, transport_query, transport_request_body, transport_stdin, transport_response_format, service_config_auth, service_config_auth_input, service_config_auth_source, service_config_endpoint, expr_has_self_call, expr_has_non_tail_self_call, field_access_base, foreach_variable_at, expr_method_name_at, let_binding_name_at, record_lit_type_name_at, arg_name_at, arg_value, arm_body, arm_pattern, arm_guard, field_init_node_name_at, field_init_node_value, make_arg_node, make_named_expr_node, let_value, let_body, lambda_body, lambda_param_names_at, foreach_collection, foreach_body, method_receiver, method_arg_nodes, match_scrutinee, match_arm_nodes, if_condition, if_then_branch, if_else_branch, index_base, index_expr, slice_base, slice_start, slice_end, cast_target, cast_expr, return_value, binop_left, binop_right, make_span, with_required_cardinality, Connective, Cardinality, is_rest_transport, is_shell_transport, is_file_transport, FieldAccessStyle, FieldValueShape, CompilerDiagnostic}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprError, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit, ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp, ExprBlock, ExprCast, ExprForEach, ExprIndex, ExprSlice, ExprReturn}; +use crate::v2_std_core::FieldAccessStyle::{StoredField, EnumAccessor, OptionalUnwrap, TupleFirst, TupleSecond}; +use crate::v2_std_core::FieldValueShape::{OptionalValue}; +use crate::v2_std_core::VarBindingKind::{LocalValueBinding, FunctionValueBinding, VariantValueBinding, MatchBoundBinding}; +use crate::v2_std_core::CallSemantics::{PlainCallSemantics, LookupCallSemantics}; +use crate::v2_std_core::MethodSemantics::{PlainMethodSemantics, AlgebraMethodSemantics, ServiceMethodSemantics}; +use crate::v2_std_core::CompilerDiagnostic::{InternalError}; +use crate::v2_std_core::StringPart::{Text, Interpolation}; use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; -use crate::v2_std_core::ExprData::{ - ExprBinOp, ExprBlock, ExprCall, ExprCast, ExprError, ExprFieldAccess, ExprForEach, ExprIf, - ExprIndex, ExprLambda, ExprLet, ExprListLit, ExprLiteral, ExprMatch, ExprMethodCall, - ExprRecordLit, ExprReturn, ExprSlice, ExprStringInterp, ExprUnaryOp, ExprVar, NoExprData, -}; -use crate::v2_std_core::FieldAccessStyle::{ - EnumAccessor, OptionalUnwrap, StoredField, TupleFirst, TupleSecond, -}; -use crate::v2_std_core::FieldValueShape::OptionalValue; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; +use crate::v2_std_core::Cardinality::{Required, CardOptional}; use crate::v2_std_core::LiteralValue::*; use crate::v2_std_core::MatchPattern::*; -use crate::v2_std_core::MethodSemantics::{ - AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics, -}; -use crate::v2_std_core::StringPart::{Interpolation, Text}; +use crate::v2_std_core::BinOp::*; +use crate::v2_std_core::AlgebraFieldKind::*; use crate::v2_std_core::UnaryOpKind::*; -use crate::v2_std_core::VarBindingKind::{ - FunctionValueBinding, LocalValueBinding, MatchBoundBinding, VariantValueBinding, -}; -pub use crate::v2_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, find_child_named, 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, - service_config_endpoint, slice_base, slice_end, slice_start, transport_auth_header_name, - transport_auth_token, transport_base_url, transport_env, transport_has_auth, transport_headers, - transport_method, transport_path_template, transport_query, transport_request_body, - transport_response_format, transport_stdin, with_required_cardinality, AlgebraFieldKind, BinOp, - CallSemantics, Cardinality, CompilerDiagnostic, Connective, ErrorNode, ExprData, - FieldAccessStyle, FieldSummary, FieldValueShape, InferredNode, LiteralValue, MatchPattern, - MethodSemantics, NewlineIndex, Node, SourceSpan, StringPart, TextFile, UnaryOpKind, - VarBindingKind, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; - -pub fn render_rust_type( - n: Rc, - shared_types: Rc>, - source_indices: Rc>>, -) -> String { +pub use crate::v2_compiler_artifact::{RenderTarget}; +use crate::v2_compiler_artifact::RenderTarget::{Rust}; +pub use crate::generated_method_template_projection::{rust_method_template_emit}; +pub use crate::extdeps_languages_rust_emit::{rt_functions, rt_ref_map_functions, rt_wraps_result, rt_bridge_function_names, rust_container_templates, rust_method_wraps_result, rust_struct_derives, rust_struct_derives_copy, rust_enum_derives, rust_enum_derives_copy, HigherOrderMethodSpec, rust_higher_order_methods}; +pub use crate::v2_compiler_languages::{scaffold_for_target, serialization_for_target, TestConventions, ItemKeywords, test_conventions_for_target, visibility_for_target, sharing_for_target, is_string_like, VisibilitySpec}; +use crate::v2_compiler_languages::VisibilitySpec::{KeywordVisibility}; +pub use crate::v2_compiler_runtime_rust::{rust_runtime_source}; +pub use crate::v2_compiler_compiler_tests_rust::{compiler_tests_source}; +pub use crate::v2_compiler_coercion::{coerce_primitive_type, is_copy, lookup_checkpoint}; +pub use crate::std_types::{is_container_type}; +pub use crate::v2_compiler_infer_env::{TypeEnv, TypeBinding, authored_name, lookup_type_by_name}; +pub use crate::v2_compiler_infer_types::{resolved_type, normalize_access_type_node, for_each_element_type_node, child_type_node, emit_map_has, node_is_keyed_collection, node_is_element_collection, node_is_collection, is_product_type, is_coproduct_type, is_unit_like}; +pub use crate::v2_compiler_infer_sigs::{ResolvedFuncEnv}; +pub use crate::v2_compiler_infer_items::{ResolvedGraph, TypedModule, ItemInfo, ItemKind}; +use crate::v2_compiler_infer_items::ItemKind::{DataItem}; +pub use crate::v2_compiler_infer_service::{is_typed_service_call_receiver, extract_typed_service_name}; +pub use crate::v2_compiler_infer::{InferScope, build_params_scope, extend_scope, build_emit_graph_info, expr_span}; +pub use crate::v2_compiler_infer_emit_info::{EmitGraphInfo, TypeSummary, lookup_emit_type_summary, is_enum_in_summaries, find_variant_parent, is_known_variant, variant_belongs_to_enum, TypeRepr}; +use crate::v2_compiler_infer_emit_info::TypeRepr::{StructRepr, EnumRepr}; +pub use crate::v2_compiler_ownership::{OwnershipProof, analyze_ownership, analyze_single_fold, build_movable_set, build_read_only_params, collect_callable_refs}; +pub use crate::std_induction::{SubValueRelation}; +use crate::std_induction::SubValueRelation::{SubValueUnknown}; +pub use crate::v2_compiler_emit::{EmitResult, BlockEmitState, TestProjection, TcoFrame, TcoReassignInput, InterpPart, rust_literal_for_pattern, emit_literal, emit_bin_op_symbol, emit_keyword, emit_node_type, render_node_type, emit_ident, emit_let_binding, emit_let_binding_annotated, emit_return, emit_unary_op, emit_lambda, emit_error_expr, emit_lambda_params, emit_null_coalesce, emit_list_lit_expr, emit_shared_expr, emit_typed_cast_shared, emit_string_literal, emit_simple_expr, escape_rust_interp_text, escape_string_literal_body, module_emit_scope, scope_after_expr, lookup_item, unique_strings, has_nested_records_node, emit_data_value_json, escape_json_string, module_to_filename, make_indent, to_string, to_string_helper, to_snake, to_screaming_snake, to_pascal, is_upper, to_lower_char, to_upper_char, capitalize_first, sanitize_service_name, service_var_name, test_function_name, apply_type_template1, apply_type_template2, apply_type_template3, apply_named_template, language_spec, is_null_coalesce, is_type_alias_return_node, is_service_item, has_service_items, typed_named_arg_matches, order_typed_call_args, 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_tco_eligible, is_self_recursive, emit_shared_tco_expr, tco_reassign_core, is_tco_identity_passthrough, service_fallback_transport, effective_operation_transport, ServiceFieldSet, compute_service_fields, service_field_decls, service_field_ctors, extract_modifier_names, seed_bindings, emit_typed_if_shared, emit_typed_let_shared}; + +pub fn render_rust_type(n: Rc, shared_types: Rc>, source_indices: Rc>>) -> String { render_node_type(&n, &RenderTarget::Rust, &shared_types, &source_indices) } pub fn type_variable_node(id: String) -> Rc { Rc::new(Node { - name: "".to_string(), - span: make_span(0, 0), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::TypeVariable { id: id })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: "".to_string(), + span: make_span(0, 0), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::TypeVariable { + id: id, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn is_type_variable(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::TypeVariable { .. } => true, - _ => false, - } + InferredNode::TypeVariable { .. } => true, + _ => false, +} } -pub fn is_rust_value_type( - n: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_rust_value_type(n: Rc, source_indices: Rc>>) -> bool { { let normed = normalize_access_type_node(n); - match is_copy( - RenderTarget::Rust, - authored_name_at(source_indices, &normed), - ) { - Some(v) => v.clone(), - None => false, - } - } +match is_copy(RenderTarget::Rust, authored_name_at(source_indices, &normed)) { + Some(v) => v.clone(), + None => false, +} +} } -pub fn is_rust_string_like( - n: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_rust_string_like(n: Rc, source_indices: Rc>>) -> bool { { let normed = normalize_access_type_node(n); - is_string_like( - RenderTarget::Rust, - authored_name_at(source_indices, &normed), - ) - } +is_string_like(RenderTarget::Rust, authored_name_at(source_indices, &normed)) +} } pub fn rust_source_root() -> String { match scaffold_for_target(RenderTarget::Rust).source_dir.clone() { - Some(dir) => dir.clone(), - None => "".to_string(), - } + Some(dir) => dir.clone(), + None => "".to_string(), +} } pub fn rust_source_ext() -> String { - scaffold_for_target(RenderTarget::Rust) - .source_file_extension - .clone() + scaffold_for_target(RenderTarget::Rust).source_file_extension.clone() } pub fn rust_visibility_prefix() -> String { match (*visibility_for_target(RenderTarget::Rust)).clone() { - VisibilitySpec::KeywordVisibility { prefix: p, .. } => p.clone(), - _ => "__VISIBILITY_SPEC_MISMATCH__".to_string(), - } + VisibilitySpec::KeywordVisibility { prefix: p, .. } => p.clone(), + _ => "__VISIBILITY_SPEC_MISMATCH__".to_string(), +} } pub fn rust_items() -> Rc { @@ -229,16 +139,10 @@ pub fn rust_enum_derives_copy_text() -> String { } pub fn rust_serde_tag_attr() -> String { - match serialization_for_target(RenderTarget::Rust) - .tag_attribute - .clone() - { - Some(attr) => attr.clone(), - None => emit_error_expr( - "missing serde tag_attribute for Rust".to_string(), - RenderTarget::Rust, - ), - } + match serialization_for_target(RenderTarget::Rust).tag_attribute.clone() { + Some(attr) => attr.clone(), + None => emit_error_expr("missing serde tag_attribute for Rust".to_string(), RenderTarget::Rust), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -250,29 +154,24 @@ pub struct RustEnumWireSerde { pub error_message: Option, } -pub fn rust_serde_policy( - enum_attr: String, - rename_prefix: Option, - rename_suffix: Option, - rename_style: Option, -) -> Rc { +pub fn rust_serde_policy(enum_attr: String, rename_prefix: Option, rename_suffix: Option, rename_style: Option) -> Rc { Rc::new(RustEnumWireSerde { - enum_attr: enum_attr, - rename_prefix: rename_prefix, - rename_suffix: rename_suffix, - rename_style: rename_style, - error_message: None, - }) + enum_attr: enum_attr, + rename_prefix: rename_prefix, + rename_suffix: rename_suffix, + rename_style: rename_style, + error_message: None, +}) } pub fn rust_serde_policy_error(message: String) -> Rc { Rc::new(RustEnumWireSerde { - enum_attr: "".to_string(), - rename_prefix: None, - rename_suffix: None, - rename_style: None, - error_message: Some(message), - }) + enum_attr: "".to_string(), + rename_prefix: None, + rename_suffix: None, + rename_style: None, + error_message: Some(message), +}) } pub fn rust_tagged_object_policy() -> Rc { @@ -288,654 +187,303 @@ pub fn rust_string_as_authored_policy() -> Rc { } pub fn rust_snake_string_policy() -> Rc { - rust_serde_policy( - "#[serde(rename_all = \"snake_case\")]".to_string(), - None, - None, - None, - ) -} - -pub fn field_value_by_name( - record: Rc, - field_name: String, - source_indices: Rc>>, -) -> Option> { - 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()) - { - __result.push(fi); - } - } - __result - }) - .first() - .cloned() - { - Some(fi) => Some(field_init_node_value(&fi)), - None => None, - } + rust_serde_policy("#[serde(rename_all = \"snake_case\")]".to_string(), None, None, None) +} + +pub fn field_value_by_name(record: Rc, field_name: String, source_indices: Rc>>) -> Option> { + 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()) { __result.push(fi); } } __result }).first().cloned() { + Some(fi) => Some(field_init_node_value(&fi)), + None => None, +} } pub fn literal_string_value(n: Rc) -> Option { match (*n.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: lv, .. } => match (*lv.clone()).clone() { - LiteralValue::LitStr { value: s, .. } => Some(s.clone()), - _ => None, - }, - _ => None, - } + ExprData::ExprLiteral { value: lv, .. } => match (*lv.clone()).clone() { + LiteralValue::LitStr { value: s, .. } => Some(s.clone()), + _ => None, +}, + _ => None, +} } -pub fn record_string_field( - record: Rc, - field_name: String, - source_indices: Rc>>, -) -> Option { +pub fn record_string_field(record: Rc, field_name: String, source_indices: Rc>>) -> Option { match field_value_by_name(record, field_name, source_indices) { - Some(value_node) => literal_string_value(value_node.clone()), - None => None, - } + Some(value_node) => literal_string_value(value_node.clone()), + None => None, +} } -pub fn naming_policy_node( - encoding: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn naming_policy_node(encoding: Rc, source_indices: Rc>>) -> Option> { field_value_by_name(encoding, "naming".to_string(), source_indices) } -pub fn optional_string_record_field( - record: Rc, - field_name: String, - source_indices: Rc>>, -) -> Option { +pub fn optional_string_record_field(record: Rc, field_name: String, source_indices: Rc>>) -> Option { match field_value_by_name(record, field_name, source_indices) { - Some(n) => literal_string_value(n.clone()), - None => None, - } + Some(n) => literal_string_value(n.clone()), + None => None, +} } -pub fn required_literal_string_policy_field( - record: Rc, - field_name: String, - source_indices: Rc>>, -) -> Option { +pub fn required_literal_string_policy_field(record: Rc, field_name: String, source_indices: Rc>>) -> Option { match field_value_by_name(record, field_name, source_indices) { - Some(n) => literal_string_value(n.clone()), - None => None, - } + Some(n) => literal_string_value(n.clone()), + None => None, +} } -pub fn rust_string_policy_for_naming( - naming: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn rust_string_policy_for_naming(naming: &Rc, source_indices: &Rc>>) -> Rc { { let naming_name = authored_name_at(source_indices.clone(), &naming); - if (naming_name.clone().as_str() == "AsAuthored".to_string().as_str()) { +if (naming_name.clone().as_str() == "AsAuthored".to_string().as_str()) { rust_string_as_authored_policy() } else { if (naming_name.clone().as_str() == "SnakeCase".to_string().as_str()) { rust_snake_string_policy() } else { - if (naming_name.clone().as_str() == "StripPrefixAndSnakeCase".to_string().as_str()) - { - match required_literal_string_policy_field( - naming.clone(), - "prefix".to_string(), - source_indices.clone(), - ) { - Some(prefix) => rust_serde_policy( - "".to_string(), - Some(prefix.clone()), - None, - Some("StripAffixAndSnakeCase".to_string()), - ), - None => rust_serde_error_policy( - "StripPrefixAndSnakeCase requires a literal prefix".to_string(), - ), - } + if (naming_name.clone().as_str() == "StripPrefixAndSnakeCase".to_string().as_str()) { + match required_literal_string_policy_field(naming.clone(), "prefix".to_string(), source_indices.clone()) { + Some(prefix) => rust_serde_policy("".to_string(), Some(prefix.clone()), None, Some("StripAffixAndSnakeCase".to_string())), + None => rust_serde_error_policy("StripPrefixAndSnakeCase requires a literal prefix".to_string()), +} } else { - if (naming_name.clone().as_str() - == "StripSuffixAndSnakeCase".to_string().as_str()) - { - match required_literal_string_policy_field( - naming.clone(), - "suffix".to_string(), - source_indices.clone(), - ) { - Some(suffix) => rust_serde_policy( - "".to_string(), - None, - Some(suffix.clone()), - Some("StripAffixAndSnakeCase".to_string()), - ), - None => rust_serde_error_policy( - "StripSuffixAndSnakeCase requires a literal suffix".to_string(), - ), - } + if (naming_name.clone().as_str() == "StripSuffixAndSnakeCase".to_string().as_str()) { + match required_literal_string_policy_field(naming.clone(), "suffix".to_string(), source_indices.clone()) { + Some(suffix) => rust_serde_policy("".to_string(), None, Some(suffix.clone()), Some("StripAffixAndSnakeCase".to_string())), + None => rust_serde_error_policy("StripSuffixAndSnakeCase requires a literal suffix".to_string()), +} } else { - if (naming_name.clone().as_str() - == "StripPrefixSuffixAndSnakeCase".to_string().as_str()) - { - 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(), - ), - } + if (naming_name.clone().as_str() == "StripPrefixSuffixAndSnakeCase".to_string().as_str()) { + 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(v2_rt::concat( - "unsupported VariantNaming: ".to_string(), - naming_name.clone(), - )) + rust_serde_error_policy(v2_rt::concat("unsupported VariantNaming: ".to_string(), naming_name.clone())) } } } } } - } +} } -pub fn rust_internal_policy_for_naming( - tag_field: String, - naming: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn rust_internal_policy_for_naming(tag_field: String, naming: &Rc, source_indices: &Rc>>) -> Rc { { let naming_name = authored_name_at(source_indices.clone(), &naming); - if (naming_name.clone().as_str() == "AsAuthored".to_string().as_str()) { - rust_serde_policy( - v2_rt::concat( - v2_rt::concat("#[serde(tag = \"".to_string(), tag_field), - "\")]".to_string(), - ), - None, - None, - None, - ) +if (naming_name.clone().as_str() == "AsAuthored".to_string().as_str()) { + rust_serde_policy(v2_rt::concat(v2_rt::concat("#[serde(tag = \"".to_string(), tag_field), "\")]".to_string()), None, None, None) } else { if (naming_name.clone().as_str() == "SnakeCase".to_string().as_str()) { - rust_serde_policy( - v2_rt::concat( - v2_rt::concat("#[serde(tag = \"".to_string(), tag_field), - "\", rename_all = \"snake_case\")]".to_string(), - ), - None, - None, - None, - ) + rust_serde_policy(v2_rt::concat(v2_rt::concat("#[serde(tag = \"".to_string(), tag_field), "\", rename_all = \"snake_case\")]".to_string()), None, None, None) } else { - if (naming_name.clone().as_str() == "StripPrefixAndSnakeCase".to_string().as_str()) - { - match required_literal_string_policy_field( - naming.clone(), - "prefix".to_string(), - source_indices.clone(), - ) { - Some(prefix) => rust_serde_policy( - v2_rt::concat( - v2_rt::concat("#[serde(tag = \"".to_string(), tag_field), - "\")]".to_string(), - ), - Some(prefix.clone()), - None, - Some("StripAffixAndSnakeCase".to_string()), - ), - None => rust_serde_error_policy( - "StripPrefixAndSnakeCase requires a literal prefix".to_string(), - ), - } + if (naming_name.clone().as_str() == "StripPrefixAndSnakeCase".to_string().as_str()) { + match required_literal_string_policy_field(naming.clone(), "prefix".to_string(), source_indices.clone()) { + Some(prefix) => rust_serde_policy(v2_rt::concat(v2_rt::concat("#[serde(tag = \"".to_string(), tag_field), "\")]".to_string()), Some(prefix.clone()), None, Some("StripAffixAndSnakeCase".to_string())), + None => rust_serde_error_policy("StripPrefixAndSnakeCase requires a literal prefix".to_string()), +} } else { - if (naming_name.clone().as_str() - == "StripSuffixAndSnakeCase".to_string().as_str()) - { - match required_literal_string_policy_field( - naming.clone(), - "suffix".to_string(), - source_indices.clone(), - ) { - Some(suffix) => rust_serde_policy( - v2_rt::concat( - v2_rt::concat("#[serde(tag = \"".to_string(), tag_field), - "\")]".to_string(), - ), - None, - Some(suffix.clone()), - Some("StripAffixAndSnakeCase".to_string()), - ), - None => rust_serde_error_policy( - "StripSuffixAndSnakeCase requires a literal suffix".to_string(), - ), - } + if (naming_name.clone().as_str() == "StripSuffixAndSnakeCase".to_string().as_str()) { + match required_literal_string_policy_field(naming.clone(), "suffix".to_string(), source_indices.clone()) { + Some(suffix) => rust_serde_policy(v2_rt::concat(v2_rt::concat("#[serde(tag = \"".to_string(), tag_field), "\")]".to_string()), None, Some(suffix.clone()), Some("StripAffixAndSnakeCase".to_string())), + None => rust_serde_error_policy("StripSuffixAndSnakeCase requires a literal suffix".to_string()), +} } else { - if (naming_name.clone().as_str() - == "StripPrefixSuffixAndSnakeCase".to_string().as_str()) - { - 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( - v2_rt::concat( - v2_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(), - ), - } + if (naming_name.clone().as_str() == "StripPrefixSuffixAndSnakeCase".to_string().as_str()) { + 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(v2_rt::concat(v2_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(v2_rt::concat( - "unsupported VariantNaming: ".to_string(), - naming_name.clone(), - )) + rust_serde_error_policy(v2_rt::concat("unsupported VariantNaming: ".to_string(), naming_name.clone())) } } } } } - } +} } -pub fn rust_internal_policy_for_encoding( - encoding: &Rc, - source_indices: &Rc>>, -) -> Rc { - match record_string_field( - encoding.clone(), - "tag_field".to_string(), - source_indices.clone(), - ) { - Some(tag_field) => match naming_policy_node(encoding.clone(), source_indices.clone()) { - Some(naming) => { - rust_internal_policy_for_naming(tag_field.clone(), &naming, &source_indices) - } - None => rust_serde_error_policy( - "InternallyTaggedObject requires a naming policy".to_string(), - ), - }, - None => rust_serde_error_policy( - "InternallyTaggedObject requires a literal tag_field".to_string(), - ), - } +pub fn rust_internal_policy_for_encoding(encoding: &Rc, source_indices: &Rc>>) -> Rc { + match record_string_field(encoding.clone(), "tag_field".to_string(), source_indices.clone()) { + Some(tag_field) => match naming_policy_node(encoding.clone(), source_indices.clone()) { + Some(naming) => rust_internal_policy_for_naming(tag_field.clone(), &naming, &source_indices), + None => rust_serde_error_policy("InternallyTaggedObject requires a naming policy".to_string()), +}, + None => rust_serde_error_policy("InternallyTaggedObject requires a literal tag_field".to_string()), +} } -pub fn resolve_wire_serde_policy_from_encoding_node( - ve: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn resolve_wire_serde_policy_from_encoding_node(ve: &Rc, source_indices: &Rc>>) -> Rc { { let encoding_name = authored_name_at(source_indices.clone(), &ve); - if (encoding_name.clone().as_str() == "InternallyTaggedObject".to_string().as_str()) { +if (encoding_name.clone().as_str() == "InternallyTaggedObject".to_string().as_str()) { rust_internal_policy_for_encoding(&ve, &source_indices) } else { if (encoding_name.clone().as_str() == "StringVariant".to_string().as_str()) { match naming_policy_node(ve.clone(), source_indices.clone()) { - Some(nv) => rust_string_policy_for_naming(&nv, &source_indices), - None => rust_serde_error_policy( - "StringVariant requires a naming policy".to_string(), - ), - } + Some(nv) => rust_string_policy_for_naming(&nv, &source_indices), + None => rust_serde_error_policy("StringVariant requires a naming policy".to_string()), +} } else { if (encoding_name.clone().as_str() == "TaggedVariant".to_string().as_str()) { rust_tagged_object_policy() } else { - rust_serde_error_policy(v2_rt::concat( - "unsupported VariantEncoding: ".to_string(), - encoding_name.clone(), - )) + rust_serde_error_policy(v2_rt::concat("unsupported VariantEncoding: ".to_string(), encoding_name.clone())) } } } - } +} } -pub fn resolve_wire_serde_policy( - wire_item: &Rc, - source_indices: Rc>>, -) -> Rc { +pub fn resolve_wire_serde_policy(wire_item: &Rc, source_indices: Rc>>) -> Rc { match wire_item.body.clone() { - Some(ve) => resolve_wire_serde_policy_from_encoding_node(&ve, &source_indices), - None => match (*wire_item.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => { - resolve_wire_serde_policy_from_encoding_node(&wire_item, &source_indices) - } - _ => rust_tagged_object_policy(), - }, - } + Some(ve) => resolve_wire_serde_policy_from_encoding_node(&ve, &source_indices), + None => match (*wire_item.expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => resolve_wire_serde_policy_from_encoding_node(&wire_item, &source_indices), + _ => rust_tagged_object_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())) -} - -pub fn resolve_wire_serde_policy_for_coproduct( - wire_contract_item: Option>, - source_indices: Rc>>, - data_items: Rc>>>>, -) -> Rc { - resolve_wire_serde_policy_for_coproduct_seen( - wire_contract_item, - source_indices, - data_items, - v2_rt::rc_empty_map::(), - 32, - ) -} - -pub fn resolve_wire_serde_policy_for_coproduct_seen( - mut wire_contract_item: Option>, - mut source_indices: Rc>>, - mut data_items: Rc>>>>, - mut seen_aliases: Rc>, - mut fuel: i64, -) -> Rc { + ((authored_name(env, node.clone()).as_str() == name.clone().as_str()) || (node.name.clone().as_str() == name.clone().as_str())) +} + +pub fn resolve_wire_serde_policy_for_coproduct(wire_contract_item: Option>, source_indices: Rc>>, data_items: Rc>>>>) -> Rc { + resolve_wire_serde_policy_for_coproduct_seen(wire_contract_item, source_indices, data_items, v2_rt::rc_empty_map::(), 32) +} + +pub fn resolve_wire_serde_policy_for_coproduct_seen(mut wire_contract_item: Option>, mut source_indices: Rc>>, mut data_items: Rc>>>>, mut seen_aliases: Rc>, mut fuel: i64) -> Rc { loop { if (fuel.clone() <= 0) { - break rust_serde_error_policy( - "wire_contract: VariantEncoding alias chain exceeded recursion limit".to_string(), - ); - } else { + break rust_serde_error_policy("wire_contract: VariantEncoding alias chain exceeded recursion limit".to_string()); +} else { match wire_contract_item { - None => { - break rust_tagged_object_policy(); - } - Some(wc) => { - if is_data_def_item(&wc) { - match wc.body.clone() { - None => { - break rust_serde_error_policy( - "wire_contract: data item has no initializer body".to_string(), - ); - } - Some(init) => match (*init.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => { - break resolve_wire_serde_policy(&init, source_indices.clone()); - } - ExprData::ExprVar { .. } => { - let alias_name = - expr_var_name_at(init.clone(), source_indices.clone()); - if (v2_rt::map_get(&seen_aliases, alias_name.clone()) != None) { - break rust_serde_error_policy(v2_rt::concat( - "wire_contract: cyclic VariantEncoding alias: " - .to_string(), - alias_name.clone(), - )); - } else { - match v2_rt::map_get(&data_items, alias_name.clone()) { - Some(candidates) => { - if ((candidates.clone().len() as i64) == 1) { - match candidates.clone().first().cloned() { - Some(aliased_data) => { - let __tco_0 = - Some(aliased_data.clone()); - let __tco_1 = v2_rt::rc_map_insert( - seen_aliases, - alias_name.clone(), - true, - ); - let __tco_2 = (fuel - 1); - wire_contract_item = __tco_0; - seen_aliases = __tco_1; - fuel = __tco_2; - continue; - } - None => { - break rust_serde_error_policy(v2_rt::concat("wire_contract: missing VariantEncoding data alias: ".to_string(), alias_name.clone())); - } - } - } else { - break rust_serde_error_policy(v2_rt::concat("wire_contract: ambiguous VariantEncoding data alias: ".to_string(), alias_name.clone())); - } - } - None => match init.inferred.clone() { - None => { - break rust_serde_error_policy("wire_contract: missing type inference on initializer (cannot resolve VariantEncoding alias)".to_string()); - } - Some(inf) => match (*inf.clone()).clone() { - InferredNode::Resolved { node, .. } => { - if is_data_def_item(&node) { - { - let __tco_0 = Some(node.clone()); - let __tco_1 = v2_rt::rc_map_insert( - seen_aliases, - alias_name.clone(), - true, - ); - let __tco_2 = (fuel - 1); - wire_contract_item = __tco_0; - seen_aliases = __tco_1; - fuel = __tco_2; - continue; - } - } else { - break resolve_wire_serde_policy( - &node, - source_indices.clone(), - ); - } - } - InferredNode::CompilerError { - message, .. - } => { - break rust_serde_error_policy( - v2_rt::concat( - "wire_contract: ".to_string(), - message.clone(), - ), - ); - } - InferredNode::TypeVariable { .. } => { - break rust_serde_error_policy("wire_contract: unresolved type variable in wire_contract initializer".to_string()); - } - }, - }, - } - } - } - _ => match init.inferred.clone() { - None => { - break rust_serde_error_policy("wire_contract: missing type inference on initializer (cannot resolve VariantEncoding alias)".to_string()); - } - Some(inf) => match (*inf.clone()).clone() { - InferredNode::Resolved { node, .. } => { - if is_data_def_item(&node) { - { - let __tco_0 = Some(node.clone()); - let __tco_1 = (fuel - 1); - wire_contract_item = __tco_0; - fuel = __tco_1; - continue; - } - } else { - break resolve_wire_serde_policy( - &node, - source_indices.clone(), - ); - } - } - InferredNode::CompilerError { message, .. } => { - break rust_serde_error_policy(v2_rt::concat( - "wire_contract: ".to_string(), - message.clone(), - )); - } - InferredNode::TypeVariable { .. } => { - break rust_serde_error_policy("wire_contract: unresolved type variable in wire_contract initializer".to_string()); - } - }, - }, - }, - } - } else { - break resolve_wire_serde_policy(&wc, source_indices.clone()); - } - } - } - } - } + None => { break rust_tagged_object_policy(); }, + Some(wc) => { if is_data_def_item(&wc) { + match wc.body.clone() { + None => { break rust_serde_error_policy("wire_contract: data item has no initializer body".to_string()); }, + Some(init) => { match (*init.expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => { break resolve_wire_serde_policy(&init, source_indices.clone()); }, + ExprData::ExprVar { .. } => { let alias_name = expr_var_name_at(init.clone(), source_indices.clone()); +if (v2_rt::map_get(&seen_aliases, alias_name.clone()) != None) { + break rust_serde_error_policy(v2_rt::concat("wire_contract: cyclic VariantEncoding alias: ".to_string(), alias_name.clone())); +} else { + match v2_rt::map_get(&data_items, alias_name.clone()) { + Some(candidates) => { if ((candidates.clone().len() as i64) == 1) { + match candidates.clone().first().cloned() { + Some(aliased_data) => { { + let __tco_0 = Some(aliased_data.clone()); +let __tco_1 = v2_rt::rc_map_insert(seen_aliases, alias_name.clone(), true); +let __tco_2 = (fuel - 1); +wire_contract_item = __tco_0; +seen_aliases = __tco_1; +fuel = __tco_2; +continue; +} }, + None => { break rust_serde_error_policy(v2_rt::concat("wire_contract: missing VariantEncoding data alias: ".to_string(), alias_name.clone())); }, +} +} else { + break rust_serde_error_policy(v2_rt::concat("wire_contract: ambiguous VariantEncoding data alias: ".to_string(), alias_name.clone())); +} }, + None => { match init.inferred.clone() { + None => { break rust_serde_error_policy("wire_contract: missing type inference on initializer (cannot resolve VariantEncoding alias)".to_string()); }, + Some(inf) => { match (*inf.clone()).clone() { + InferredNode::Resolved { node, .. } => { if is_data_def_item(&node) { + { + let __tco_0 = Some(node.clone()); +let __tco_1 = v2_rt::rc_map_insert(seen_aliases, alias_name.clone(), true); +let __tco_2 = (fuel - 1); +wire_contract_item = __tco_0; +seen_aliases = __tco_1; +fuel = __tco_2; +continue; +} +} else { + break resolve_wire_serde_policy(&node, source_indices.clone()); +} }, + InferredNode::CompilerError { message, .. } => { break rust_serde_error_policy(v2_rt::concat("wire_contract: ".to_string(), message.clone())); }, + InferredNode::TypeVariable { .. } => { break rust_serde_error_policy("wire_contract: unresolved type variable in wire_contract initializer".to_string()); }, +} }, +} }, +} +} }, + _ => { match init.inferred.clone() { + None => { break rust_serde_error_policy("wire_contract: missing type inference on initializer (cannot resolve VariantEncoding alias)".to_string()); }, + Some(inf) => { match (*inf.clone()).clone() { + InferredNode::Resolved { node, .. } => { if is_data_def_item(&node) { + { + let __tco_0 = Some(node.clone()); +let __tco_1 = (fuel - 1); +wire_contract_item = __tco_0; +fuel = __tco_1; +continue; +} +} else { + break resolve_wire_serde_policy(&node, source_indices.clone()); +} }, + InferredNode::CompilerError { message, .. } => { break rust_serde_error_policy(v2_rt::concat("wire_contract: ".to_string(), message.clone())); }, + InferredNode::TypeVariable { .. } => { break rust_serde_error_policy("wire_contract: unresolved type variable in wire_contract initializer".to_string()); }, +} }, +} }, +} }, +} +} else { + break resolve_wire_serde_policy(&wc, source_indices.clone()); +} }, +} +} +} } -pub fn coproduct_wire_contract_encoding( - contract_item: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn coproduct_wire_contract_encoding(contract_item: Rc, source_indices: Rc>>) -> Option> { match contract_item.body.clone() { - Some(body) => field_value_by_name(body.clone(), "encoding".to_string(), source_indices), - None => None, - } + Some(body) => field_value_by_name(body.clone(), "encoding".to_string(), source_indices), + None => None, +} } -pub fn variant_encoding_is_string_variant( - encoding: Rc, - source_indices: Rc>>, -) -> bool { +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()) } -pub fn coproduct_wire_contract_targets( - contract_item: Rc, - coproduct_name: String, - source_indices: Rc>>, -) -> bool { +pub fn coproduct_wire_contract_targets(contract_item: Rc, coproduct_name: String, source_indices: Rc>>) -> bool { 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()), - None => false, - } - } - None => false, - } + 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()), + None => false, +}, + None => false, +} } pub fn emit_rust_compile_error_item(message: String) -> String { - v2_rt::concat( - v2_rt::concat("compile_error!(\"".to_string(), message), - "\");".to_string(), - ) -} - -pub fn module_imports_std_serialization_coproduct_wire_contract( - imports: Rc>>, - source_indices: Rc>>, -) -> bool { - { - let mut __found = false; - for imp in imports.iter().cloned() { - if ((authored_name_at(source_indices.clone(), &imp).as_str() - == "std.serialization".to_string().as_str()) - && (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()) { - __found = true; - break; - } - } - __found - })) - { - __found = true; - break; - } - } - __found - } + v2_rt::concat(v2_rt::concat("compile_error!(\"".to_string(), message), "\");".to_string()) +} + +pub fn module_imports_std_serialization_coproduct_wire_contract(imports: Rc>>, source_indices: Rc>>) -> bool { + { let mut __found = false; for imp in imports.iter().cloned() { if ((authored_name_at(source_indices.clone(), &imp).as_str() == "std.serialization".to_string().as_str()) && (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()) { __found = true; break; } } __found })) { __found = true; break; } } __found } } -pub fn data_item_type_is_coproduct_wire_contract( - item: Rc, - imports: Rc>>, - source_indices: &Rc>>, -) -> bool { +pub fn data_item_type_is_coproduct_wire_contract(item: Rc, imports: Rc>>, source_indices: &Rc>>) -> bool { match item.type_annotation.clone() { - Some(type_node) => { - ((authored_name_at(source_indices.clone(), &type_node).as_str() - == "CoproductWireContract".to_string().as_str()) - && module_imports_std_serialization_coproduct_wire_contract( - imports, - source_indices.clone(), - )) - } - None => false, - } + Some(type_node) => ((authored_name_at(source_indices.clone(), &type_node).as_str() == "CoproductWireContract".to_string().as_str()) && module_imports_std_serialization_coproduct_wire_contract(imports, source_indices.clone())), + None => false, +} } -pub fn module_defines_local_coproduct_wire_contract_type( - module_items: Rc>>, - source_indices: Rc>>, -) -> bool { - { - let mut __found = false; - for item in module_items.iter().cloned() { - if (((is_type_def_item(&item) || is_type_alias_item(&item, source_indices.clone())) - || is_type_decl_item(&item, source_indices.clone())) - && (authored_name_at(source_indices.clone(), &item).as_str() - == "CoproductWireContract".to_string().as_str())) - { - __found = true; - break; - } - } - __found - } +pub fn module_defines_local_coproduct_wire_contract_type(module_items: Rc>>, source_indices: Rc>>) -> bool { + { let mut __found = false; for item in module_items.iter().cloned() { if (((is_type_def_item(&item) || is_type_alias_item(&item, source_indices.clone())) || is_type_decl_item(&item, source_indices.clone())) && (authored_name_at(source_indices.clone(), &item).as_str() == "CoproductWireContract".to_string().as_str())) { __found = true; break; } } __found } } -pub fn is_coproduct_wire_contract_row( - item: &Rc, - module_items: Rc>>, - imports: Rc>>, - source_indices: &Rc>>, -) -> bool { +pub fn is_coproduct_wire_contract_row(item: &Rc, module_items: Rc>>, imports: Rc>>, source_indices: &Rc>>) -> bool { if !is_data_def_item(&item) { false } else { @@ -946,335 +494,116 @@ pub fn is_coproduct_wire_contract_row( false } else { match item.body.clone() { - Some(body) => { - ((field_value_by_name( - body.clone(), - "coproduct".to_string(), - source_indices.clone(), - ) != None) - && (field_value_by_name( - body.clone(), - "encoding".to_string(), - source_indices.clone(), - ) != None)) - } - None => false, - } + Some(body) => ((field_value_by_name(body.clone(), "coproduct".to_string(), source_indices.clone()) != None) && (field_value_by_name(body.clone(), "encoding".to_string(), source_indices.clone()) != None)), + None => false, +} } } } } -pub fn emit_coproduct_wire_contract_target_validation( - contract_item: Rc, - local_coproduct_names: Rc>, - source_indices: Rc>>, -) -> String { +pub fn emit_coproduct_wire_contract_target_validation(contract_item: Rc, local_coproduct_names: Rc>, source_indices: Rc>>) -> String { match contract_item.body.clone() { - Some(body) => { - match record_string_field(body.clone(), "coproduct".to_string(), source_indices) { - Some(target_name) => { - if { - let mut __found = false; - for name in local_coproduct_names.iter().cloned() { - if (name.clone().as_str() == target_name.clone().as_str()) { - __found = true; - break; - } - } - __found - } { - "".to_string() - } else { - emit_rust_compile_error_item(v2_rt::concat( - "CoproductWireContract target does not name a local coproduct: " - .to_string(), - target_name.clone(), - )) - } - } - None => emit_rust_compile_error_item( - "CoproductWireContract.coproduct must be a string declaration name".to_string(), - ), - } - } - None => emit_rust_compile_error_item( - "CoproductWireContract row missing initializer body".to_string(), - ), - } + Some(body) => match record_string_field(body.clone(), "coproduct".to_string(), source_indices) { + Some(target_name) => if { let mut __found = false; for name in local_coproduct_names.iter().cloned() { if (name.clone().as_str() == target_name.clone().as_str()) { __found = true; break; } } __found } { + "".to_string() + } else { + emit_rust_compile_error_item(v2_rt::concat("CoproductWireContract target does not name a local coproduct: ".to_string(), target_name.clone())) + }, + None => emit_rust_compile_error_item("CoproductWireContract.coproduct must be a string declaration name".to_string()), +}, + None => emit_rust_compile_error_item("CoproductWireContract row missing initializer body".to_string()), +} } -pub fn emit_coproduct_wire_contract_validations( - module_items: &Rc>>, - imports: Rc>>, - local_coproduct_names: Rc>, - source_indices: Rc>>, -) -> String { - Rc::new({ - let mut __result = Vec::new(); - for text in Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in module_items.clone().iter().cloned() { - if is_coproduct_wire_contract_row( - &item, - module_items.clone(), - imports.clone(), - &source_indices, - ) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(emit_coproduct_wire_contract_target_validation( - item.clone(), - local_coproduct_names.clone(), - source_indices.clone(), - )); - } - __result - }) - .iter() - .cloned() - { - if (text.clone().as_str() != "".to_string().as_str()) { - __result.push(text); - } - } - __result - }) - .join(&"\n".to_string()) -} - -pub fn resolve_local_coproduct_wire_policy( - coproduct_name: &String, - all_unit_variants: bool, - module_items: &Rc>>, - imports: Rc>>, - source_indices: &Rc>>, -) -> Option> { - { - let contracts = Rc::new({ - let mut __result = Vec::new(); - for item in module_items.clone().iter().cloned() { - if (is_coproduct_wire_contract_row( - &item, - module_items.clone(), - imports.clone(), - &source_indices, - ) && coproduct_wire_contract_targets( - item.clone(), - coproduct_name.clone(), - source_indices.clone(), - )) { - __result.push(item); - } - } - __result - }); - if ((contracts.clone().len() as i64) == 0) { +pub fn emit_coproduct_wire_contract_validations(module_items: &Rc>>, imports: Rc>>, local_coproduct_names: Rc>, source_indices: Rc>>) -> String { + Rc::new({ let mut __result = Vec::new(); for text in Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in module_items.clone().iter().cloned() { if is_coproduct_wire_contract_row(&item, module_items.clone(), imports.clone(), &source_indices) { __result.push(item); } } __result }).iter().cloned() { __result.push(emit_coproduct_wire_contract_target_validation(item.clone(), local_coproduct_names.clone(), source_indices.clone())); } __result }).iter().cloned() { if (text.clone().as_str() != "".to_string().as_str()) { __result.push(text); } } __result }).join(&"\n".to_string()) +} + +pub fn resolve_local_coproduct_wire_policy(coproduct_name: &String, all_unit_variants: bool, module_items: &Rc>>, imports: Rc>>, source_indices: &Rc>>) -> Option> { + { + let contracts = Rc::new({ let mut __result = Vec::new(); for item in module_items.clone().iter().cloned() { if (is_coproduct_wire_contract_row(&item, module_items.clone(), imports.clone(), &source_indices) && coproduct_wire_contract_targets(item.clone(), coproduct_name.clone(), source_indices.clone())) { __result.push(item); } } __result }); +if ((contracts.clone().len() as i64) == 0) { None } else { if ((contracts.clone().len() as i64) == 1) { match contracts.clone().first().cloned() { - Some(contract) => match coproduct_wire_contract_encoding( - contract.clone(), - source_indices.clone(), - ) { - Some(encoding) => { - if (variant_encoding_is_string_variant( - encoding.clone(), - source_indices.clone(), - ) && !all_unit_variants) - { - Some(rust_serde_error_policy(v2_rt::concat("CoproductWireContract StringVariant requires a nullary-only coproduct: ".to_string(), coproduct_name.clone()))) - } else { - Some(resolve_wire_serde_policy_from_encoding_node( - &encoding, - &source_indices, - )) - } - } - None => Some(rust_serde_error_policy(v2_rt::concat( - "CoproductWireContract missing encoding for ".to_string(), - coproduct_name.clone(), - ))), - }, - None => None, - } + Some(contract) => match coproduct_wire_contract_encoding(contract.clone(), source_indices.clone()) { + Some(encoding) => if (variant_encoding_is_string_variant(encoding.clone(), source_indices.clone()) && !all_unit_variants) { + Some(rust_serde_error_policy(v2_rt::concat("CoproductWireContract StringVariant requires a nullary-only coproduct: ".to_string(), coproduct_name.clone()))) + } else { + Some(resolve_wire_serde_policy_from_encoding_node(&encoding, &source_indices)) + }, + None => Some(rust_serde_error_policy(v2_rt::concat("CoproductWireContract missing encoding for ".to_string(), coproduct_name.clone()))), +}, + None => None, +} } else { - Some(rust_serde_error_policy(v2_rt::concat( - "ambiguous CoproductWireContract rows for ".to_string(), - coproduct_name.clone(), - ))) + Some(rust_serde_error_policy(v2_rt::concat("ambiguous CoproductWireContract rows for ".to_string(), coproduct_name.clone()))) } } - } +} } pub fn build_data_item_index(modules: Rc>>) -> Rc>> { - modules.iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, tm: Rc| { - let module_name = authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ); - Rc::new({ - let mut __result = Vec::new(); - for item in tm.items.clone().iter().cloned() { - if is_data_def_item(&item) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - .fold( - acc, - |item_acc: Rc>>, item: Rc| { - let item_name = - authored_name_at(tm.type_env.clone().source_indices.clone(), &item); - let qualified_name = v2_rt::concat( - v2_rt::concat(module_name.clone(), ".".to_string()), - item_name.clone(), - ); - v2_rt::rc_map_insert(item_acc, qualified_name.clone(), item.clone()) - }, - ) - }, - ) + modules.iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, tm: Rc| { + let module_name = authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()); +Rc::new({ let mut __result = Vec::new(); for item in tm.items.clone().iter().cloned() { if is_data_def_item(&item) { __result.push(item); } } __result }).iter().cloned().fold(acc, |item_acc: Rc>>, item: Rc| { + let item_name = authored_name_at(tm.type_env.clone().source_indices.clone(), &item); +let qualified_name = v2_rt::concat(v2_rt::concat(module_name.clone(), ".".to_string()), item_name.clone()); +v2_rt::rc_map_insert(item_acc, qualified_name.clone(), item.clone()) +}) +}) } -pub fn insert_scoped_data_item( - scoped: &Rc>>>>, - name: &String, - item: Rc, -) -> Rc>>>> { +pub fn insert_scoped_data_item(scoped: &Rc>>>>, name: &String, item: Rc) -> Rc>>>> { { let existing = match v2_rt::map_get(&scoped, name.clone()) { - Some(entries) => entries.clone(), - None => Rc::new(vec![]), - }; - v2_rt::rc_map_insert( - scoped.clone(), - name.clone(), - v2_rt::concat(existing, Rc::new(vec![item])), - ) - } + Some(entries) => entries.clone(), + None => Rc::new(vec![]), +}; +v2_rt::rc_map_insert(scoped.clone(), name.clone(), v2_rt::concat(existing, Rc::new(vec![item]))) +} } -pub fn build_scoped_data_item_index( - typed_module: &Rc, - data_items: Rc>>, -) -> Rc>>>> { - { - let module_name = authored_name_at( - typed_module.type_env.clone().source_indices.clone(), - &typed_module.module.clone(), - ); - let local = Rc::new({ - let mut __result = Vec::new(); - for item in typed_module.items.clone().iter().cloned() { - if is_data_def_item(&item) { - __result.push(item); - } +pub fn build_scoped_data_item_index(typed_module: &Rc, data_items: Rc>>) -> Rc>>>> { + { + let module_name = authored_name_at(typed_module.type_env.clone().source_indices.clone(), &typed_module.module.clone()); +let local = Rc::new({ let mut __result = Vec::new(); for item in typed_module.items.clone().iter().cloned() { if is_data_def_item(&item) { __result.push(item); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |acc: Rc>>>>, item: Rc| insert_scoped_data_item(&acc, &authored_name_at(typed_module.type_env.clone().source_indices.clone(), &item), item.clone())); +module_imports(typed_module.module.clone()).iter().cloned().fold(local.clone(), |acc: Rc>>>>, imp: Rc| { + let import_path = authored_name_at(typed_module.type_env.clone().source_indices.clone(), &imp); +if import_is_all(imp.clone()) { + acc.clone() + } else { + import_specific_names_at(imp.clone(), typed_module.type_env.clone().source_indices.clone()).iter().cloned().fold(acc.clone(), |inner: Rc>>>>, imported_name: String| { + let qualified = v2_rt::concat(v2_rt::concat(import_path.clone(), ".".to_string()), imported_name.clone()); +match v2_rt::map_get(&data_items, qualified.clone()) { + Some(imported_item) => insert_scoped_data_item(&inner, &imported_name, imported_item.clone()), + None => inner.clone(), +} +}) } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>>>(), - |acc: Rc>>>>, item: Rc| { - insert_scoped_data_item( - &acc, - &authored_name_at(typed_module.type_env.clone().source_indices.clone(), &item), - item.clone(), - ) - }, - ); - module_imports(typed_module.module.clone()) - .iter() - .cloned() - .fold( - local.clone(), - |acc: Rc>>>>, imp: Rc| { - let import_path = authored_name_at( - typed_module.type_env.clone().source_indices.clone(), - &imp, - ); - if import_is_all(imp.clone()) { - acc.clone() - } else { - import_specific_names_at( - imp.clone(), - typed_module.type_env.clone().source_indices.clone(), - ) - .iter() - .cloned() - .fold( - acc.clone(), - |inner: Rc>>>>, - imported_name: String| { - let qualified = v2_rt::concat( - v2_rt::concat(import_path.clone(), ".".to_string()), - imported_name.clone(), - ); - match v2_rt::map_get(&data_items, qualified.clone()) { - Some(imported_item) => insert_scoped_data_item( - &inner, - &imported_name, - imported_item.clone(), - ), - None => inner.clone(), - } - }, - ) - } - }, - ) - } +}) +} } pub fn rust_serde_rename_template_text() -> String { - match serialization_for_target(RenderTarget::Rust) - .rename_attribute_template - .clone() - { - Some(template) => template.clone(), - None => emit_error_expr( - "missing serde rename_attribute_template for Rust".to_string(), - RenderTarget::Rust, - ), - } + match serialization_for_target(RenderTarget::Rust).rename_attribute_template.clone() { + Some(template) => template.clone(), + None => emit_error_expr("missing serde rename_attribute_template for Rust".to_string(), RenderTarget::Rust), +} } pub fn rust_test_file_path(module_name: String) -> String { { let conventions = test_conventions_for_target(RenderTarget::Rust); - let file_dir = match conventions.file_dir.clone() { - Some(dir) => dir.clone(), - None => "".to_string(), - }; - let filename = module_to_filename(module_name); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(file_dir, conventions.file_prefix.clone()), - filename, - ), - conventions.file_suffix.clone(), - ), - rust_source_ext(), - ) - } +let file_dir = match conventions.file_dir.clone() { + Some(dir) => dir.clone(), + None => "".to_string(), +}; +let filename = module_to_filename(module_name); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(file_dir, conventions.file_prefix.clone()), filename), conventions.file_suffix.clone()), rust_source_ext()) +} } pub fn rust_test_name(projection: Rc) -> String { @@ -1282,285 +611,141 @@ pub fn rust_test_name(projection: Rc) -> String { } pub fn rust_async_test_decorator() -> String { - match test_conventions_for_target(RenderTarget::Rust) - .async_decorator - .clone() - { - Some(decorator) => decorator.clone(), - None => emit_error_expr( - "missing async_decorator for Rust test conventions".to_string(), - RenderTarget::Rust, - ), - } + match test_conventions_for_target(RenderTarget::Rust).async_decorator.clone() { + Some(decorator) => decorator.clone(), + None => emit_error_expr("missing async_decorator for Rust test conventions".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_block_stmts( - mut remaining: Rc>>, - mut text: Rc>, - mut scope: Rc, - mut registry: Rc>>, - mut depth: i64, - mut shared_types: Rc>, - mut emit_info: Rc, -) -> Rc { +pub fn emit_rust_block_stmts(mut remaining: Rc>>, mut text: Rc>, mut scope: Rc, mut registry: Rc>>, mut depth: i64, mut shared_types: Rc>, mut emit_info: Rc) -> Rc { loop { match remaining.clone().first().cloned() { - None => { - break Rc::new(BlockEmitState { - text: text, - scope: scope.clone(), - }); - } - Some(stmt) => { - let line = emit_typed_expr( - stmt.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let next_scope = scope_after_expr(&stmt, &scope); - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = v2_rt::rc_list_push(text, line); - let __tco_2 = next_scope; - remaining = __tco_0; - text = __tco_1; - scope = __tco_2; - continue; - } - } - } - } -} - -pub fn emit_rust_init_block_stmts( - mut remaining: Rc>>, - mut text: Rc>, - mut scope: Rc, - mut registry: Rc>>, - mut depth: i64, - mut shared_types: Rc>, - mut emit_info: Rc, -) -> Rc { + None => { break Rc::new(BlockEmitState { + text: text, + scope: scope.clone(), +}); }, + Some(stmt) => { let line = emit_typed_expr(stmt.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let next_scope = scope_after_expr(&stmt, &scope); +{ + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(text, line); +let __tco_2 = next_scope; +remaining = __tco_0; +text = __tco_1; +scope = __tco_2; +continue; +} }, +} +} +} + +pub fn emit_rust_init_block_stmts(mut remaining: Rc>>, mut text: Rc>, mut scope: Rc, mut registry: Rc>>, mut depth: i64, mut shared_types: Rc>, mut emit_info: Rc) -> Rc { loop { match remaining.clone().first().cloned() { - None => { - break Rc::new(BlockEmitState { - text: text, - scope: scope.clone(), - }); - } - Some(stmt) => { - let rest = Rc::new( - remaining - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - match rest.clone().first().cloned() { - None => { - break Rc::new(BlockEmitState { - text: text, - scope: scope.clone(), - }); - } - Some(_) => { - let raw_line = emit_typed_expr( - stmt.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let is_let = match (*stmt.expr_data.clone()).clone() { - ExprData::ExprLet => true, - _ => false, - }; - let line = if is_let { - raw_line - } else { - v2_rt::concat(raw_line, ";".to_string()) - }; - let next_scope = scope_after_expr(&stmt, &scope); - { - let __tco_0 = rest.clone(); - let __tco_1 = v2_rt::rc_list_push(text, line); - let __tco_2 = next_scope; - remaining = __tco_0; - text = __tco_1; - scope = __tco_2; - continue; - } - } - } - } - } - } + None => { break Rc::new(BlockEmitState { + text: text, + scope: scope.clone(), +}); }, + Some(stmt) => { let rest = Rc::new(remaining.clone().iter().cloned().skip(1 as usize).collect::>()); +match rest.clone().first().cloned() { + None => { break Rc::new(BlockEmitState { + text: text, + scope: scope.clone(), +}); }, + Some(_) => { let raw_line = emit_typed_expr(stmt.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let is_let = match (*stmt.expr_data.clone()).clone() { + ExprData::ExprLet => true, + _ => false, +}; +let line = if is_let { + raw_line + } else { + v2_rt::concat(raw_line, ";".to_string()) + }; +let next_scope = scope_after_expr(&stmt, &scope); +{ + let __tco_0 = rest.clone(); +let __tco_1 = v2_rt::rc_list_push(text, line); +let __tco_2 = next_scope; +remaining = __tco_0; +text = __tco_1; +scope = __tco_2; +continue; +} }, +} }, +} +} } pub fn has_complex_variants(item: &Rc) -> bool { if ((item.children.clone().len() as i64) == 0) { false } else { - { - let mut __found = false; - for c in item.children.clone().iter().cloned() { - if (c.connective.clone() != Connective::NoConnective) { - __found = true; - break; - } - } - __found - } + { let mut __found = false; for c in item.children.clone().iter().cloned() { if (c.connective.clone() != Connective::NoConnective) { __found = true; break; } } __found } } } pub fn is_simple_disj(item: Rc) -> bool { { - let complex = Rc::new({ - let mut __result = Vec::new(); - for v in item.children.clone().iter().cloned() { - if ((v.children.clone().len() as i64) > 0) { - __result.push(v); - } - } - __result - }); - ((complex.len() as i64) == 0) - } + let complex = Rc::new({ let mut __result = Vec::new(); for v in item.children.clone().iter().cloned() { if ((v.children.clone().len() as i64) > 0) { __result.push(v); } } __result }); +((complex.len() as i64) == 0) +} } pub fn is_dag_value_type_name(name: String) -> bool { match is_copy(RenderTarget::Rust, name) { - Some(v) => v.clone(), - None => false, - } + Some(v) => v.clone(), + None => false, +} } -pub fn is_type_constant( - summary: &Rc, - recursive_type_set: Rc>, -) -> bool { +pub fn is_type_constant(summary: &Rc, recursive_type_set: Rc>) -> bool { { let is_recursive = v2_rt::map_contains_key(&recursive_type_set, summary.name.clone()); - let has_generics = ((summary.generic_param_names.clone().len() as i64) > 0); - match (*summary.repr.clone()).clone() { - TypeRepr::EnumRepr { unit_only, .. } => { - (((unit_only.clone() && !is_recursive) && !has_generics) - && !summary.has_fn_fields.clone()) - } - TypeRepr::StructRepr => { - if ((is_recursive || has_generics) || summary.has_fn_fields.clone()) { +let has_generics = ((summary.generic_param_names.clone().len() as i64) > 0); +match (*summary.repr.clone()).clone() { + TypeRepr::EnumRepr { unit_only, .. } => (((unit_only.clone() && !is_recursive) && !has_generics) && !summary.has_fn_fields.clone()), + TypeRepr::StructRepr => if ((is_recursive || has_generics) || summary.has_fn_fields.clone()) { + false + } else { + { + let field_count = (Rc::new(v2_rt::map_keys(&summary.field_summaries.clone())).len() as i64); +let ft_count = (Rc::new(v2_rt::map_keys(&summary.field_type_map.clone())).len() as i64); +if (ft_count < field_count) { false } else { - { - let field_count = - (Rc::new(v2_rt::map_keys(&summary.field_summaries.clone())).len() - as i64); - let ft_count = (Rc::new(v2_rt::map_keys(&summary.field_type_map.clone())) - .len() as i64); - if (ft_count < field_count) { - false - } else { - { - let mut __all = true; - for tn in - Rc::new(v2_rt::map_values(&summary.field_type_map.clone())) - .iter() - .cloned() - { - if !(is_dag_value_type_name(tn.clone())) { - __all = false; - break; - } - } - __all - } - } - } + { let mut __all = true; for tn in Rc::new(v2_rt::map_values(&summary.field_type_map.clone())).iter().cloned() { if !(is_dag_value_type_name(tn.clone())) { __all = false; break; } } __all } } - } - } - } +} + }, +} +} } -pub fn maybe_mark_shared_type( - acc: Rc>, - summary: &Rc, - recursive_type_set: Rc>, - target_needs_sharing: bool, -) -> Rc> { +pub fn maybe_mark_shared_type(acc: Rc>, summary: &Rc, recursive_type_set: Rc>, target_needs_sharing: bool) -> Rc> { { - let needs_sharing = (target_needs_sharing - && match (*summary.repr.clone()).clone() { - TypeRepr::StructRepr => true, - TypeRepr::EnumRepr { unit_only, .. } => (unit_only.clone() == false), - }); - if (needs_sharing && !is_type_constant(&summary, recursive_type_set)) { + let needs_sharing = (target_needs_sharing && match (*summary.repr.clone()).clone() { + TypeRepr::StructRepr => true, + TypeRepr::EnumRepr { unit_only, .. } => (unit_only.clone() == false), +}); +if (needs_sharing && !is_type_constant(&summary, recursive_type_set)) { v2_rt::rc_map_insert(acc, summary.name.clone(), true) } else { acc } - } +} } -pub fn build_shared_types( - type_summaries: Rc>>, - recursive_type_set: Rc>, - target: RenderTarget, -) -> Rc> { +pub fn build_shared_types(type_summaries: Rc>>, recursive_type_set: Rc>, target: RenderTarget) -> Rc> { { let sharing = sharing_for_target(target); - let user_shared = Rc::new(v2_rt::map_values(&type_summaries)) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, summary: Rc| { - maybe_mark_shared_type( - acc, - &summary, - recursive_type_set.clone(), - sharing.needs_sharing.clone(), - ) - }, - ); - let collection_keys = Rc::new({ - let mut __result = Vec::new(); - for k in Rc::new(v2_rt::map_keys(&rust_container_templates())) - .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())) - { - __result.push(k); - } - } - __result - }); - collection_keys.iter().cloned().fold( - user_shared.clone(), - |acc: Rc>, key: String| { - let pascal = to_pascal(key.clone()); - v2_rt::rc_map_insert(acc, pascal.clone(), true) - }, - ) - } +let user_shared = Rc::new(v2_rt::map_values(&type_summaries)).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, summary: Rc| maybe_mark_shared_type(acc, &summary, recursive_type_set.clone(), sharing.needs_sharing.clone())); +let collection_keys = Rc::new({ let mut __result = Vec::new(); for k in Rc::new(v2_rt::map_keys(&rust_container_templates())).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())) { __result.push(k); } } __result }); +collection_keys.iter().cloned().fold(user_shared.clone(), |acc: Rc>, key: String| { + let pascal = to_pascal(key.clone()); +v2_rt::rc_map_insert(acc, pascal.clone(), true) +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -1578,1178 +763,394 @@ pub struct OwnershipBuildResult { pub fn build_ownership_results(modules: &Rc>>) -> Rc { { - let callable_set = modules.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, m: Rc| { - Rc::new({ - let mut __result = Vec::new(); - for item in m.items.clone().iter().cloned() { - if (item.body.clone() != None) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - .fold(acc, |inner: Rc>, item: Rc| { - v2_rt::rc_map_merge( - inner, - collect_callable_refs( - &item.body.clone().clone().unwrap(), - &m.type_env.clone().source_indices.clone(), - ), - ) - }) - }, - ); - let proofs = Rc::new({ - let mut __result = Vec::new(); - for m in modules.clone().iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in m.items.clone().iter().cloned() { - if (item.body.clone() != None) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push({ - let pnames = item.params.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, p: Rc| { - v2_rt::rc_map_insert( - acc, - param_node_name_at( - p.clone(), - m.type_env.clone().source_indices.clone(), - ), - true, - ) - }, - ); - let si = m.type_env.clone().source_indices.clone(); - let qualified = v2_rt::concat( - v2_rt::concat( - authored_name_at(si.clone(), &m.module.clone()), - ".".to_string(), - ), - authored_name_at(si.clone(), &item), - ); - Rc::new(OwnershipProofEntry { - name: qualified.clone(), - proof: analyze_ownership( - authored_name_at(si.clone(), &item), - item.params.clone(), - item.body.clone().clone().unwrap(), - &si, - ), - param_names: pnames.clone(), - }) - }); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }); - proofs.iter().cloned().fold( - Rc::new(OwnershipBuildResult { - ownership_index: v2_rt::rc_empty_map::>>(), - read_only_params_index: v2_rt::rc_empty_map::>>(), - }), - |acc: Rc, entry: Rc| { - let acc = Rc::try_unwrap(acc).unwrap_or_else(|rc| (*rc).clone()); - { - let read_only = if v2_rt::map_contains_key( - &callable_set, - entry.proof.clone().func_name.clone(), - ) { - v2_rt::rc_empty_map::() - } else { - build_read_only_params(entry.proof.clone(), entry.param_names.clone()) - }; - let movable = build_movable_set(entry.proof.clone()); - Rc::new(OwnershipBuildResult { - ownership_index: v2_rt::rc_map_insert( - acc.ownership_index, - entry.name.clone(), - movable.clone(), - ), - read_only_params_index: v2_rt::rc_map_insert( - acc.read_only_params_index, - entry.name.clone(), - read_only.clone(), - ), - }) - } - }, - ) - } + let callable_set = modules.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, m: Rc| Rc::new({ let mut __result = Vec::new(); for item in m.items.clone().iter().cloned() { if (item.body.clone() != None) { __result.push(item); } } __result }).iter().cloned().fold(acc, |inner: Rc>, item: Rc| v2_rt::rc_map_merge(inner, collect_callable_refs(&item.body.clone().clone().unwrap(), &m.type_env.clone().source_indices.clone())))); +let proofs = Rc::new({ let mut __result = Vec::new(); for m in modules.clone().iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in m.items.clone().iter().cloned() { if (item.body.clone() != None) { __result.push(item); } } __result }).iter().cloned() { __result.push({ + let pnames = item.params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, p: Rc| v2_rt::rc_map_insert(acc, param_node_name_at(p.clone(), m.type_env.clone().source_indices.clone()), true)); +let si = m.type_env.clone().source_indices.clone(); +let qualified = v2_rt::concat(v2_rt::concat(authored_name_at(si.clone(), &m.module.clone()), ".".to_string()), authored_name_at(si.clone(), &item)); +Rc::new(OwnershipProofEntry { + name: qualified.clone(), + proof: analyze_ownership(authored_name_at(si.clone(), &item), item.params.clone(), item.body.clone().clone().unwrap(), &si), + param_names: pnames.clone(), +}) +}); } __result })).iter().cloned()); } __result }); +proofs.iter().cloned().fold(Rc::new(OwnershipBuildResult { + ownership_index: v2_rt::rc_empty_map::>>(), + read_only_params_index: v2_rt::rc_empty_map::>>(), +}), |acc: Rc, entry: Rc| { let acc = Rc::try_unwrap(acc).unwrap_or_else(|rc| (*rc).clone()); { + let read_only = if v2_rt::map_contains_key(&callable_set, entry.proof.clone().func_name.clone()) { + v2_rt::rc_empty_map::() + } else { + build_read_only_params(entry.proof.clone(), entry.param_names.clone()) + }; +let movable = build_movable_set(entry.proof.clone()); +Rc::new(OwnershipBuildResult { + ownership_index: v2_rt::rc_map_insert(acc.ownership_index, entry.name.clone(), movable.clone()), + read_only_params_index: v2_rt::rc_map_insert(acc.read_only_params_index, entry.name.clone(), read_only.clone()), +}) +} }) +} } pub fn emit_rust(typed: &Rc) -> Rc { { let base_info = build_emit_graph_info(&typed.modules.clone()); - let ownership = build_ownership_results(&typed.modules.clone()); - let shared = build_shared_types( - base_info.type_summaries.clone(), - base_info.recursive_type_set.clone(), - RenderTarget::Rust, - ); - let emit_info = Rc::new(EmitGraphInfo { - type_summaries: base_info.type_summaries.clone(), - recursive_type_set: base_info.recursive_type_set.clone(), - fielded_variants: base_info.fielded_variants.clone(), - shared_types: shared, - ownership_index: ownership.ownership_index.clone(), - movable: v2_rt::rc_empty_map::(), - variant_to_enum: base_info.variant_to_enum.clone(), - owned_bindings: v2_rt::rc_empty_map::(), - read_only_params_index: ownership.read_only_params_index.clone(), - read_only_params: v2_rt::rc_empty_map::(), - }); - let shared_types = emit_info.shared_types.clone(); - let registry = typed.item_registry.clone(); - let data_items = build_data_item_index(typed.modules.clone()); - let workflow_funcs = collect_workflow_funcs( - typed.modules.clone(), - registry.clone(), - emit_info.read_only_params_index.clone(), - ); - let workflow_default_diags = validate_workflow_param_defaults(workflow_funcs.clone()); - if ((workflow_default_diags.clone().len() as i64) > 0) { +let ownership = build_ownership_results(&typed.modules.clone()); +let shared = build_shared_types(base_info.type_summaries.clone(), base_info.recursive_type_set.clone(), RenderTarget::Rust); +let emit_info = Rc::new(EmitGraphInfo { + type_summaries: base_info.type_summaries.clone(), + recursive_type_set: base_info.recursive_type_set.clone(), + fielded_variants: base_info.fielded_variants.clone(), + shared_types: shared, + ownership_index: ownership.ownership_index.clone(), + movable: v2_rt::rc_empty_map::(), + variant_to_enum: base_info.variant_to_enum.clone(), + owned_bindings: v2_rt::rc_empty_map::(), + read_only_params_index: ownership.read_only_params_index.clone(), + read_only_params: v2_rt::rc_empty_map::(), +}); +let shared_types = emit_info.shared_types.clone(); +let registry = typed.item_registry.clone(); +let data_items = build_data_item_index(typed.modules.clone()); +let workflow_funcs = collect_workflow_funcs(typed.modules.clone(), registry.clone(), emit_info.read_only_params_index.clone()); +let workflow_default_diags = validate_workflow_param_defaults(workflow_funcs.clone()); +if ((workflow_default_diags.clone().len() as i64) > 0) { return Rc::new(EmitResult { - files: Rc::new(vec![]), - diagnostics: workflow_default_diags.clone(), - }); - } - let svc_module_map = typed.modules.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, tm: Rc| { - let svc_items = Rc::new({ - let mut __result = Vec::new(); - for item in tm.items.clone().iter().cloned() { - if is_service_item(&item) { - __result.push(item); - } - } - __result - }); - let mod_filename = module_to_filename(authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - )); - svc_items.clone().iter().cloned().fold( - acc, - |a: Rc>, svc: Rc| { - v2_rt::rc_map_insert( - a, - authored_name_at(tm.type_env.clone().source_indices.clone(), &svc), - mod_filename.clone(), - ) - }, - ) - }, - ); - let test_projections = extract_test_projections(typed.clone()); - let module_files = Rc::new({ - let mut __result = Vec::new(); - for tm in typed.modules.clone().iter().cloned() { - __result.push(emit_module_full( - &tm, - ®istry, - &emit_info, - shared_types.clone(), - svc_module_map.clone(), - data_items.clone(), - )); - } - __result - }); - let test_files = Rc::new({ - let mut __result = Vec::new(); - for f in Rc::new({ - let mut __result = Vec::new(); - for tm in typed.modules.clone().iter().cloned() { - __result.push(emit_test_file( - &authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ), - Rc::new({ - let mut __result = Vec::new(); - for p in test_projections.clone().iter().cloned() { - if (p.module_name.clone().as_str() - == authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ) - .as_str()) - { - __result.push(p); - } - } - __result - }), - )); - } - __result - }) - .iter() - .cloned() - { - if (f.path.clone().as_str() != "".to_string().as_str()) { - __result.push(f); - } - } - __result - }); - let has_services = has_service_items(typed.clone()); - let has_pipeline = { - 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() - == "v2.compiler.compile".to_string().as_str()) - { - __found = true; - break; - } - } - __found - }; - let crate_name = if has_pipeline.clone() { + files: Rc::new(vec![]), + diagnostics: workflow_default_diags.clone(), +}) + } +let svc_module_map = typed.modules.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, tm: Rc| { + let svc_items = Rc::new({ let mut __result = Vec::new(); for item in tm.items.clone().iter().cloned() { if is_service_item(&item) { __result.push(item); } } __result }); +let mod_filename = module_to_filename(authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone())); +svc_items.clone().iter().cloned().fold(acc, |a: Rc>, svc: Rc| v2_rt::rc_map_insert(a, authored_name_at(tm.type_env.clone().source_indices.clone(), &svc), mod_filename.clone())) +}); +let test_projections = extract_test_projections(typed.clone()); +let module_files = Rc::new({ let mut __result = Vec::new(); for tm in typed.modules.clone().iter().cloned() { __result.push(emit_module_full(&tm, ®istry, &emit_info, shared_types.clone(), svc_module_map.clone(), data_items.clone())); } __result }); +let test_files = Rc::new({ let mut __result = Vec::new(); for f in Rc::new({ let mut __result = Vec::new(); for tm in typed.modules.clone().iter().cloned() { __result.push(emit_test_file(&authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()), Rc::new({ let mut __result = Vec::new(); for p in test_projections.clone().iter().cloned() { if (p.module_name.clone().as_str() == authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()).as_str()) { __result.push(p); } } __result }))); } __result }).iter().cloned() { if (f.path.clone().as_str() != "".to_string().as_str()) { __result.push(f); } } __result }); +let has_services = has_service_items(typed.clone()); +let has_pipeline = { 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() == "v2.compiler.compile".to_string().as_str()) { __found = true; break; } } __found }; +let crate_name = if has_pipeline.clone() { "v2_compiler".to_string() } else { "v2_compiled".to_string() }; - let cargo = emit_cargo_toml(crate_name.clone(), has_services.clone()); - let main_file = emit_main_rs( - &workflow_funcs, - &typed.modules.clone(), - &has_services, - &crate_name, - svc_module_map.clone(), - ); - let rt_file = emit_v2_rt_module(); - let compiler_tests_file = if has_pipeline.clone() { +let cargo = emit_cargo_toml(crate_name.clone(), has_services.clone()); +let main_file = emit_main_rs(&workflow_funcs, &typed.modules.clone(), &has_services, &crate_name, svc_module_map.clone()); +let rt_file = emit_v2_rt_module(); +let compiler_tests_file = if has_pipeline.clone() { Rc::new(vec![emit_compiler_tests_module()]) } else { Rc::new(vec![]) }; - let dry_run_file = if has_services.clone() { +let dry_run_file = if has_services.clone() { Rc::new(vec![emit_dry_run_module()]) } else { Rc::new(vec![]) }; - let all_mod_files = v2_rt::concat( - v2_rt::concat(module_files, Rc::new(vec![rt_file])), - dry_run_file, - ); - let lib_file = emit_lib_rs_from_files(all_mod_files.clone(), &has_pipeline); - let files = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - Rc::new(vec![cargo, lib_file, main_file]), - all_mod_files.clone(), - ), - compiler_tests_file, - ), - test_files, - ); - Rc::new(EmitResult { - files: files, - diagnostics: Rc::new(vec![]), - }) - } +let all_mod_files = v2_rt::concat(v2_rt::concat(module_files, Rc::new(vec![rt_file])), dry_run_file); +let lib_file = emit_lib_rs_from_files(all_mod_files.clone(), &has_pipeline); +let files = v2_rt::concat(v2_rt::concat(v2_rt::concat(Rc::new(vec![cargo, lib_file, main_file]), all_mod_files.clone()), compiler_tests_file), test_files); +Rc::new(EmitResult { + files: files, + diagnostics: Rc::new(vec![]), +}) +} } pub fn emit_v2_rt_module() -> Rc { Rc::new(TextFile { - path: v2_rt::concat( - v2_rt::concat(rust_source_root(), "v2_rt".to_string()), - rust_source_ext(), - ), - content: rust_runtime_source(), - }) + path: v2_rt::concat(v2_rt::concat(rust_source_root(), "v2_rt".to_string()), rust_source_ext()), + content: rust_runtime_source(), +}) } pub fn emit_compiler_tests_module() -> Rc { Rc::new(TextFile { - path: v2_rt::concat( - v2_rt::concat(rust_source_root(), "compiler_tests".to_string()), - rust_source_ext(), - ), - content: compiler_tests_source(), - }) + path: v2_rt::concat(v2_rt::concat(rust_source_root(), "compiler_tests".to_string()), rust_source_ext()), + content: compiler_tests_source(), +}) } -pub fn emit_lib_rs_from_files( - all_module_files: Rc>>, - has_compiler_tests: &bool, -) -> Rc { +pub fn emit_lib_rs_from_files(all_module_files: Rc>>, has_compiler_tests: &bool) -> Rc { { let src_prefix_len = v2_rt::string_length(&rust_source_root()); - let ext_len = v2_rt::string_length(&rust_source_ext()); - let mod_decls = Rc::new({ - let mut __result = Vec::new(); - for f in all_module_files.iter().cloned() { - __result.push({ - let path_len = v2_rt::string_length(&f.path.clone()); - let mod_name = v2_rt::substring( - &f.path.clone(), - src_prefix_len.clone(), - (path_len.clone() - ext_len.clone()), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - rust_visibility_prefix(), - rust_items().module_keyword.clone(), - ), - " ".to_string(), - ), - mod_name.clone(), - ), - ";".to_string(), - ) - }); - } - __result - }); - let hand_maintained_mods = if has_compiler_tests.clone() { +let ext_len = v2_rt::string_length(&rust_source_ext()); +let mod_decls = Rc::new({ let mut __result = Vec::new(); for f in all_module_files.iter().cloned() { __result.push({ + let path_len = v2_rt::string_length(&f.path.clone()); +let mod_name = v2_rt::substring(&f.path.clone(), src_prefix_len.clone(), (path_len.clone() - ext_len.clone())); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), rust_items().module_keyword.clone()), " ".to_string()), mod_name.clone()), ";".to_string()) +}); } __result }); +let hand_maintained_mods = if has_compiler_tests.clone() { "\npub mod v2_interpreter;\npub mod cli_run;\npub mod rest_transport_facts;".to_string() } else { "".to_string() }; - let test_mod = if has_compiler_tests.clone() { +let test_mod = if has_compiler_tests.clone() { "\n\n#[cfg(test)]\nmod compiler_tests;".to_string() } else { "".to_string() }; - let shared_types = emit_non_empty_wrappers(); - let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Generated by v2 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); - Rc::new(TextFile { - path: v2_rt::concat( - v2_rt::concat(rust_source_root(), "lib".to_string()), - rust_source_ext(), - ), - content: v2_rt::concat(content, "\n".to_string()), - }) - } +let shared_types = emit_non_empty_wrappers(); +let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Generated by v2 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); +Rc::new(TextFile { + path: v2_rt::concat(v2_rt::concat(rust_source_root(), "lib".to_string()), rust_source_ext()), + content: v2_rt::concat(content, "\n".to_string()), +}) +} } -pub fn emit_module( - typed_module: &Rc, - registry: Rc>>, -) -> Rc { +pub fn emit_module(typed_module: &Rc, registry: Rc>>) -> Rc { { let base_info = build_emit_graph_info(&Rc::new(vec![typed_module.clone()])); - let shared = build_shared_types( - base_info.type_summaries.clone(), - base_info.recursive_type_set.clone(), - RenderTarget::Rust, - ); - let emit_info = Rc::new(EmitGraphInfo { - type_summaries: base_info.type_summaries.clone(), - recursive_type_set: base_info.recursive_type_set.clone(), - fielded_variants: base_info.fielded_variants.clone(), - shared_types: shared, - ownership_index: base_info.ownership_index.clone(), - movable: base_info.movable.clone(), - variant_to_enum: base_info.variant_to_enum.clone(), - owned_bindings: v2_rt::rc_empty_map::(), - read_only_params_index: base_info.read_only_params_index.clone(), - read_only_params: v2_rt::rc_empty_map::(), - }); - let shared_types = emit_info.shared_types.clone(); - emit_module_full( - &typed_module, - ®istry, - &emit_info, - shared_types, - v2_rt::rc_empty_map::(), - build_data_item_index(Rc::new(vec![typed_module.clone()])), - ) - } +let shared = build_shared_types(base_info.type_summaries.clone(), base_info.recursive_type_set.clone(), RenderTarget::Rust); +let emit_info = Rc::new(EmitGraphInfo { + type_summaries: base_info.type_summaries.clone(), + recursive_type_set: base_info.recursive_type_set.clone(), + fielded_variants: base_info.fielded_variants.clone(), + shared_types: shared, + ownership_index: base_info.ownership_index.clone(), + movable: base_info.movable.clone(), + variant_to_enum: base_info.variant_to_enum.clone(), + owned_bindings: v2_rt::rc_empty_map::(), + read_only_params_index: base_info.read_only_params_index.clone(), + read_only_params: v2_rt::rc_empty_map::(), +}); +let shared_types = emit_info.shared_types.clone(); +emit_module_full(&typed_module, ®istry, &emit_info, shared_types, v2_rt::rc_empty_map::(), build_data_item_index(Rc::new(vec![typed_module.clone()]))) +} } -pub fn emit_module_full( - typed_module: &Rc, - registry: &Rc>>, - emit_info: &Rc, - shared_types: Rc>, - svc_module_map: Rc>, - data_items: Rc>>, -) -> Rc { +pub fn emit_module_full(typed_module: &Rc, registry: &Rc>>, emit_info: &Rc, shared_types: Rc>, svc_module_map: Rc>, data_items: Rc>>) -> Rc { { let m = typed_module.module.clone(); - let scope = module_emit_scope(&typed_module); - let scoped_data_items = build_scoped_data_item_index(&typed_module, data_items); - let prelude = emit_prelude(); - let local_type_names = Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in typed_module.items.clone().iter().cloned() { - if ((is_type_def_item(&item) - || is_type_alias_item( - &item, - scope.type_env.clone().source_indices.clone(), - )) - || is_type_decl_item(&item, scope.type_env.clone().source_indices.clone())) - { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(authored_name(scope.type_env.clone(), item.clone())); - } - __result - }); - let imports_str = emit_imports( - &module_imports(m.clone()), - emit_info.clone(), - registry.clone(), - local_type_names, - scope.type_env.clone().source_indices.clone(), - ); - let imports_section = if (imports_str.clone().as_str() == "".to_string().as_str()) { +let scope = module_emit_scope(&typed_module); +let scoped_data_items = build_scoped_data_item_index(&typed_module, data_items); +let prelude = emit_prelude(); +let local_type_names = Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in typed_module.items.clone().iter().cloned() { if ((is_type_def_item(&item) || is_type_alias_item(&item, scope.type_env.clone().source_indices.clone())) || is_type_decl_item(&item, scope.type_env.clone().source_indices.clone())) { __result.push(item); } } __result }).iter().cloned() { __result.push(authored_name(scope.type_env.clone(), item.clone())); } __result }); +let imports_str = emit_imports(&module_imports(m.clone()), emit_info.clone(), registry.clone(), local_type_names, scope.type_env.clone().source_indices.clone()); +let imports_section = if (imports_str.clone().as_str() == "".to_string().as_str()) { "".to_string() } else { v2_rt::concat("\n".to_string(), imports_str.clone()) }; - let this_mod_filename = - module_to_filename(authored_name(scope.type_env.clone(), m.clone())); - let all_svc_names = Rc::new({ - let mut __result = Vec::new(); - for item in typed_module.items.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get( - ®istry, - authored_name(scope.type_env.clone(), item.clone()), - ) { - Some(info) => info.service_names.clone(), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let extern_svc_imports = Rc::new({ - let mut __result = Vec::new(); - for sn in unique_strings(all_svc_names).iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&svc_module_map, sn.clone()) { - Some(mod_file) => { - if (mod_file.clone().as_str() == this_mod_filename.clone().as_str()) { - Rc::new(vec![]) - } else { - Rc::new(vec![v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - rust_visibility_prefix(), - "use crate::".to_string(), - ), - mod_file.clone(), - ), - "::".to_string(), - ), - sanitize_service_name(sn.clone()), - ), - ";".to_string(), - )]) - } - } - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let svc_imports_str = if ((extern_svc_imports.clone().len() as i64) == 0) { +let this_mod_filename = module_to_filename(authored_name(scope.type_env.clone(), m.clone())); +let all_svc_names = Rc::new({ let mut __result = Vec::new(); for item in typed_module.items.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(®istry, authored_name(scope.type_env.clone(), item.clone())) { + Some(info) => info.service_names.clone(), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let extern_svc_imports = Rc::new({ let mut __result = Vec::new(); for sn in unique_strings(all_svc_names).iter().cloned() { __result.extend((*match v2_rt::map_get(&svc_module_map, sn.clone()) { + Some(mod_file) => if (mod_file.clone().as_str() == this_mod_filename.clone().as_str()) { + Rc::new(vec![]) + } else { + Rc::new(vec![v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), "use crate::".to_string()), mod_file.clone()), "::".to_string()), sanitize_service_name(sn.clone())), ";".to_string())]) + }, + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let svc_imports_str = if ((extern_svc_imports.clone().len() as i64) == 0) { "".to_string() } else { - v2_rt::concat( - "\n".to_string(), - extern_svc_imports.clone().join(&"\n".to_string()), - ) + v2_rt::concat("\n".to_string(), extern_svc_imports.clone().join(&"\n".to_string())) }; - let local_enum_uses = Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in typed_module.items.clone().iter().cloned() { - if (is_type_def_item(&item) && is_coproduct_type(item.clone())) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(v2_rt::concat( - v2_rt::concat( - "use self::".to_string(), - authored_name(scope.type_env.clone(), item.clone()), - ), - "::*;".to_string(), - )); - } - __result - }); - let local_coproduct_names = Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in typed_module.items.clone().iter().cloned() { - if (is_type_def_item(&item) && is_coproduct_type(item.clone())) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(authored_name(scope.type_env.clone(), item.clone())); - } - __result - }); - let module_import_items = module_imports(m.clone()); - let coproduct_wire_contract_validations = emit_coproduct_wire_contract_validations( - &typed_module.items.clone(), - module_import_items.clone(), - local_coproduct_names, - 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()) { - "".to_string() - } else { - v2_rt::concat( - coproduct_wire_contract_validations.clone(), - "\n\n".to_string(), - ) - }; - let local_uses_str = if ((local_enum_uses.clone().len() as i64) == 0) { +let local_enum_uses = Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in typed_module.items.clone().iter().cloned() { if (is_type_def_item(&item) && is_coproduct_type(item.clone())) { __result.push(item); } } __result }).iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat("use self::".to_string(), authored_name(scope.type_env.clone(), item.clone())), "::*;".to_string())); } __result }); +let local_coproduct_names = Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in typed_module.items.clone().iter().cloned() { if (is_type_def_item(&item) && is_coproduct_type(item.clone())) { __result.push(item); } } __result }).iter().cloned() { __result.push(authored_name(scope.type_env.clone(), item.clone())); } __result }); +let module_import_items = module_imports(m.clone()); +let coproduct_wire_contract_validations = emit_coproduct_wire_contract_validations(&typed_module.items.clone(), module_import_items.clone(), local_coproduct_names, 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()) { "".to_string() } else { - v2_rt::concat( - "\n".to_string(), - local_enum_uses.clone().join(&"\n".to_string()), - ) + v2_rt::concat(coproduct_wire_contract_validations.clone(), "\n\n".to_string()) }; - let wire_contract_item = Rc::new({ - let mut __result = Vec::new(); - for i in typed_module.items.clone().iter().cloned() { - if (item_binding_is_named(scope.type_env.clone(), &i, &"wire_contract".to_string()) - && match v2_rt::map_get( - &scope.item_registry.clone(), - "wire_contract".to_string(), - ) { - Some(info) => (info.kind.clone() == ItemKind::DataItem), - None => false, - }) - { - __result.push(i); - } - } - __result - }) - .first() - .cloned(); - let items_str = Rc::new({ - let mut __result = Vec::new(); - for item in typed_module.items.clone().iter().cloned() { - __result.push(emit_typed_item( - &item, - authored_name(scope.type_env.clone(), m.clone()), - ®istry, - &scope, - shared_types.clone(), - &emit_info, - wire_contract_item.clone(), - scoped_data_items.clone(), - typed_module.items.clone(), - module_import_items.clone(), - )); - } - __result - }) - .join(&"\n\n".to_string()); - 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 local_uses_str = if ((local_enum_uses.clone().len() as i64) == 0) { + "".to_string() + } else { + v2_rt::concat("\n".to_string(), local_enum_uses.clone().join(&"\n".to_string())) + }; +let wire_contract_item = Rc::new({ let mut __result = Vec::new(); for i in typed_module.items.clone().iter().cloned() { if (item_binding_is_named(scope.type_env.clone(), &i, &"wire_contract".to_string()) && match v2_rt::map_get(&scope.item_registry.clone(), "wire_contract".to_string()) { + Some(info) => (info.kind.clone() == ItemKind::DataItem), + None => false, +}) { __result.push(i); } } __result }).first().cloned(); +let items_str = Rc::new({ let mut __result = Vec::new(); for item in typed_module.items.clone().iter().cloned() { __result.push(emit_typed_item(&item, authored_name(scope.type_env.clone(), m.clone()), ®istry, &scope, shared_types.clone(), &emit_info, wire_contract_item.clone(), scoped_data_items.clone(), typed_module.items.clone(), module_import_items.clone())); } __result }).join(&"\n\n".to_string()); +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()) { "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()).as_str() == "std.error_primitives".to_string().as_str()) { "#![allow(non_camel_case_types)]\n\n".to_string() } else { "".to_string() }; - let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Generated by v2 compiler -- do not edit.\n".to_string(), "// Source module: ".to_string()), authored_name(scope.type_env.clone(), m.clone())), "\n\n".to_string()), module_attrs), prelude), imports_section), svc_imports_str), local_uses_str), "\n\n".to_string()), coproduct_wire_contract_validation_section), items_str), "\n".to_string()); - Rc::new(TextFile { - path: v2_rt::concat( - v2_rt::concat(rust_source_root(), filename), - rust_source_ext(), - ), - content: content, - }) - } +let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Generated by v2 compiler -- do not edit.\n".to_string(), "// Source module: ".to_string()), authored_name(scope.type_env.clone(), m.clone())), "\n\n".to_string()), module_attrs), prelude), imports_section), svc_imports_str), local_uses_str), "\n\n".to_string()), coproduct_wire_contract_validation_section), items_str), "\n".to_string()); +Rc::new(TextFile { + path: v2_rt::concat(v2_rt::concat(rust_source_root(), filename), rust_source_ext()), + content: content, +}) +} } pub fn emit_import_name(n: &String, registry: Rc>>) -> String { { let is_data = match v2_rt::map_get(®istry, n.clone()) { - Some(info) => (info.kind.clone() == ItemKind::DataItem), - None => false, - }; - if is_data { + Some(info) => (info.kind.clone() == ItemKind::DataItem), + None => false, +}; +if is_data { to_snake(n.clone()) } else { n.clone() } - } +} } -pub fn emit_imports( - imports: &Rc>>, - emit_info: Rc, - registry: Rc>>, - local_names: Rc>, - source_indices: Rc>>, -) -> String { +pub fn emit_imports(imports: &Rc>>, emit_info: Rc, registry: Rc>>, local_names: Rc>, source_indices: Rc>>) -> String { if ((imports.clone().len() as i64) == 0) { "".to_string() } else { { let type_summaries = emit_info.type_summaries.clone(); - let import_lines = Rc::new({ - let mut __result = Vec::new(); - for imp in imports.clone().iter().cloned() { - __result.push({ - let mod_name = - module_to_filename(authored_name_at(source_indices.clone(), &imp)); - if import_is_all(imp.clone()) { - v2_rt::concat( - v2_rt::concat("use crate::".to_string(), mod_name.clone()), - "::*;".to_string(), - ) +let import_lines = Rc::new({ let mut __result = Vec::new(); for imp in imports.clone().iter().cloned() { __result.push({ + let mod_name = module_to_filename(authored_name_at(source_indices.clone(), &imp)); +if import_is_all(imp.clone()) { + v2_rt::concat(v2_rt::concat("use crate::".to_string(), mod_name.clone()), "::*;".to_string()) + } else { + { + let specific_names = import_specific_names_at(imp.clone(), source_indices.clone()); +let filtered_names = Rc::new({ let mut __result = Vec::new(); for n in specific_names.clone().iter().cloned() { if { let mut __all = true; for ln in local_names.clone().iter().cloned() { if !((ln.clone().as_str() != n.clone().as_str())) { __all = false; break; } } __all } { __result.push(n); } } __result }); +if ((filtered_names.clone().len() as i64) == 0) { + "".to_string() } else { { - let specific_names = - import_specific_names_at(imp.clone(), source_indices.clone()); - let filtered_names = Rc::new({ - let mut __result = Vec::new(); - for n in specific_names.clone().iter().cloned() { - if { - let mut __all = true; - for ln in local_names.clone().iter().cloned() { - if !(ln.clone().as_str() != n.clone().as_str()) { - __all = false; - break; - } - } - __all - } { - __result.push(n); - } - } - __result - }); - if ((filtered_names.clone().len() as i64) == 0) { + let deduped_names = unique_strings(filtered_names.clone()); +let top_level = Rc::new({ let mut __result = Vec::new(); for n in deduped_names.clone().iter().cloned() { if if is_known_variant(type_summaries.clone(), n.clone()) { + is_enum_in_summaries(type_summaries.clone(), n.clone()) + } else { + true + } { __result.push(n); } } __result }); +let all_enum_names = Rc::new({ let mut __result = Vec::new(); for n in Rc::new(v2_rt::map_keys(&type_summaries)).iter().cloned() { if is_enum_in_summaries(type_summaries.clone(), n.clone()) { __result.push(n); } } __result }); +let imported_enums = Rc::new({ let mut __result = Vec::new(); for n in deduped_names.clone().iter().cloned() { if is_enum_in_summaries(type_summaries.clone(), n.clone()) { __result.push(n); } } __result }); +let all_parents = Rc::new({ let mut __result = Vec::new(); for p in Rc::new({ let mut __result = Vec::new(); for n in deduped_names.clone().iter().cloned() { __result.push(if is_enum_in_summaries(type_summaries.clone(), n.clone()) { "".to_string() } else { + match find_variant_parent(type_summaries.clone(), n.clone(), imported_enums.clone()) { + Some(parent) => parent.clone(), + None => match find_variant_parent(type_summaries.clone(), n.clone(), all_enum_names.clone()) { + Some(parent) => parent.clone(), + None => "".to_string(), +}, +} + }); } __result }).iter().cloned() { if (p.clone().as_str() != "".to_string().as_str()) { __result.push(p); } } __result }); +let parent_list = unique_strings(all_parents.clone()); +let top_with_parents = unique_strings(v2_rt::concat(top_level.clone(), parent_list.clone())); +let main_line = if ((top_with_parents.clone().len() as i64) > 0) { { - let deduped_names = unique_strings(filtered_names.clone()); - let top_level = Rc::new({ - let mut __result = Vec::new(); - for n in deduped_names.clone().iter().cloned() { - if if is_known_variant( - type_summaries.clone(), - n.clone(), - ) { - is_enum_in_summaries( - type_summaries.clone(), - n.clone(), - ) - } else { - true - } { - __result.push(n); - } - } - __result - }); - let all_enum_names = Rc::new({ - let mut __result = Vec::new(); - for n in Rc::new(v2_rt::map_keys(&type_summaries)) - .iter() - .cloned() - { - if is_enum_in_summaries( - type_summaries.clone(), - n.clone(), - ) { - __result.push(n); - } - } - __result - }); - let imported_enums = Rc::new({ - let mut __result = Vec::new(); - for n in deduped_names.clone().iter().cloned() { - if is_enum_in_summaries( - type_summaries.clone(), - n.clone(), - ) { - __result.push(n); - } - } - __result - }); - let all_parents = Rc::new({ - let mut __result = Vec::new(); - for p in Rc::new({ - let mut __result = Vec::new(); - for n in deduped_names.clone().iter().cloned() { - __result.push( - if is_enum_in_summaries( - type_summaries.clone(), - n.clone(), - ) { - "".to_string() - } else { - match find_variant_parent( - type_summaries.clone(), - n.clone(), - imported_enums.clone(), - ) { - Some(parent) => parent.clone(), - None => match find_variant_parent( - type_summaries.clone(), - n.clone(), - all_enum_names.clone(), - ) { - Some(parent) => parent.clone(), - None => "".to_string(), - }, - } - }, - ); - } - __result - }) - .iter() - .cloned() - { - if (p.clone().as_str() != "".to_string().as_str()) { - __result.push(p); - } - } - __result - }); - let parent_list = unique_strings(all_parents.clone()); - let top_with_parents = unique_strings(v2_rt::concat( - top_level.clone(), - parent_list.clone(), - )); - let main_line = - if ((top_with_parents.clone().len() as i64) > 0) { - { - let names_str = Rc::new({ - let mut __result = Vec::new(); - for n in - top_with_parents.clone().iter().cloned() - { - __result.push(emit_import_name( - &n, - registry.clone(), - )); - } - __result - }) - .join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - rust_visibility_prefix(), - "use crate::".to_string(), - ), - mod_name.clone(), - ), - "::{".to_string(), - ), - names_str.clone(), - ), - "};".to_string(), - ) - } - } else { - "".to_string() - }; - let variant_lines = Rc::new({ - let mut __result = Vec::new(); - for parent in parent_list.clone().iter().cloned() { - __result.push({ - let variants = Rc::new({ - let mut __result = Vec::new(); - for n in - deduped_names.clone().iter().cloned() - { - if if is_enum_in_summaries( - type_summaries.clone(), - n.clone(), - ) { - false - } else { - match find_variant_parent( - type_summaries.clone(), - n.clone(), - Rc::new(vec![parent.clone()]), - ) { - Some(_) => true, - None => false, - } - } { - __result.push(n); - } - } - __result - }); - let vars_str = - variants.clone().join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "use crate::" - .to_string(), - mod_name.clone(), - ), - "::".to_string(), - ), - parent.clone(), - ), - "::{".to_string(), - ), - vars_str.clone(), - ), - "};".to_string(), - ) - }); - } - __result - }); - let imported_enums = Rc::new({ - let mut __result = Vec::new(); - for n in top_level.clone().iter().cloned() { - if is_enum_in_summaries( - type_summaries.clone(), - n.clone(), - ) { - __result.push(n); - } - } - __result - }); - let wildcard_enum_lines = Rc::new({ - let mut __result = Vec::new(); - for en in Rc::new({ - let mut __result = Vec::new(); - for en in imported_enums.clone().iter().cloned() { - if ({ - let mut __found = false; - for p in parent_list.clone().iter().cloned() - { - if (p.clone().as_str() - == en.clone().as_str()) - { - __found = true; - break; - } - } - __found - } == false) - { - __result.push(en); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "use crate::".to_string(), - mod_name.clone(), - ), - "::".to_string(), - ), - en.clone(), - ), - "::*;".to_string(), - )); - } - __result - }); - let all_lines = if (main_line.clone().as_str() - != "".to_string().as_str()) - { - v2_rt::concat( - v2_rt::concat( - Rc::new(vec![main_line.clone()]), - Rc::new({ - let mut __result = Vec::new(); - for l in - variant_lines.clone().iter().cloned() - { - if (l.clone().as_str() - != "".to_string().as_str()) - { - __result.push(l); - } - } - __result - }), - ), - wildcard_enum_lines.clone(), - ) - } else { - v2_rt::concat( - Rc::new({ - let mut __result = Vec::new(); - for l in variant_lines.clone().iter().cloned() { - if (l.clone().as_str() - != "".to_string().as_str()) - { - __result.push(l); - } - } - __result - }), - wildcard_enum_lines.clone(), - ) - }; - all_lines.clone().join(&"\n".to_string()) - } - } - } + let names_str = Rc::new({ let mut __result = Vec::new(); for n in top_with_parents.clone().iter().cloned() { __result.push(emit_import_name(&n, registry.clone())); } __result }).join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), "use crate::".to_string()), mod_name.clone()), "::{".to_string()), names_str.clone()), "};".to_string()) +} + } else { + "".to_string() + }; +let variant_lines = Rc::new({ let mut __result = Vec::new(); for parent in parent_list.clone().iter().cloned() { __result.push({ + let variants = Rc::new({ let mut __result = Vec::new(); for n in deduped_names.clone().iter().cloned() { if if is_enum_in_summaries(type_summaries.clone(), n.clone()) { + false + } else { + match find_variant_parent(type_summaries.clone(), n.clone(), Rc::new(vec![parent.clone()])) { + Some(_) => true, + None => false, +} + } { __result.push(n); } } __result }); +let vars_str = variants.clone().join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("use crate::".to_string(), mod_name.clone()), "::".to_string()), parent.clone()), "::{".to_string()), vars_str.clone()), "};".to_string()) +}); } __result }); +let imported_enums = Rc::new({ let mut __result = Vec::new(); for n in top_level.clone().iter().cloned() { if is_enum_in_summaries(type_summaries.clone(), n.clone()) { __result.push(n); } } __result }); +let wildcard_enum_lines = Rc::new({ let mut __result = Vec::new(); for en in Rc::new({ let mut __result = Vec::new(); for en in imported_enums.clone().iter().cloned() { if ({ let mut __found = false; for p in parent_list.clone().iter().cloned() { if (p.clone().as_str() == en.clone().as_str()) { __found = true; break; } } __found } == false) { __result.push(en); } } __result }).iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("use crate::".to_string(), mod_name.clone()), "::".to_string()), en.clone()), "::*;".to_string())); } __result }); +let all_lines = if (main_line.clone().as_str() != "".to_string().as_str()) { + v2_rt::concat(v2_rt::concat(Rc::new(vec![main_line.clone()]), Rc::new({ let mut __result = Vec::new(); for l in variant_lines.clone().iter().cloned() { if (l.clone().as_str() != "".to_string().as_str()) { __result.push(l); } } __result })), wildcard_enum_lines.clone()) + } else { + v2_rt::concat(Rc::new({ let mut __result = Vec::new(); for l in variant_lines.clone().iter().cloned() { if (l.clone().as_str() != "".to_string().as_str()) { __result.push(l); } } __result }), wildcard_enum_lines.clone()) + }; +all_lines.clone().join(&"\n".to_string()) +} } - }); - } - __result - }); - Rc::new({ - let mut __result = Vec::new(); - for line in import_lines.iter().cloned() { - if (line.clone().as_str() != "".to_string().as_str()) { - __result.push(line); - } +} } - __result - }) - .join(&"\n".to_string()) - } +}); } __result }); +Rc::new({ let mut __result = Vec::new(); for line in import_lines.iter().cloned() { if (line.clone().as_str() != "".to_string().as_str()) { __result.push(line); } } __result }).join(&"\n".to_string()) +} } } pub fn emit_prelude() -> String { { - let use_line = - "use std::collections::HashMap;\nuse std::rc::Rc;\nuse crate::v2_rt;".to_string(); - let wrapper_use = "use crate::NonEmptyVec;\nuse crate::NonEmptyBTreeSet;".to_string(); - v2_rt::concat(v2_rt::concat(use_line, "\n".to_string()), wrapper_use) - } + let use_line = "use std::collections::HashMap;\nuse std::rc::Rc;\nuse crate::v2_rt;".to_string(); +let wrapper_use = "use crate::NonEmptyVec;\nuse crate::NonEmptyBTreeSet;".to_string(); +v2_rt::concat(v2_rt::concat(use_line, "\n".to_string()), wrapper_use) +} } pub fn emit_non_empty_wrappers() -> String { { let vec_wrapper = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("#[derive(Debug, Clone, PartialEq)]\n".to_string(), "pub struct NonEmptyVec(Vec);\n\n".to_string()), "impl NonEmptyVec {\n".to_string()), " pub fn new(items: Vec) -> Result {\n".to_string()), " if items.is_empty() {\n".to_string()), " Err(\"NonEmptyVec requires at least one element\")\n".to_string()), " } else {\n".to_string()), " Ok(Self(items))\n".to_string()), " }\n".to_string()), " }\n\n".to_string()), " pub fn as_slice(&self) -> &[T] {\n".to_string()), " &self.0\n".to_string()), " }\n\n".to_string()), " pub fn into_vec(self) -> Vec {\n".to_string()), " self.0\n".to_string()), " }\n".to_string()), "}".to_string()); - let set_wrapper = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("#[derive(Debug, Clone, PartialEq)]\n".to_string(), "pub struct NonEmptyBTreeSet(std::collections::BTreeSet);\n\n".to_string()), "impl NonEmptyBTreeSet {\n".to_string()), " pub fn new(items: std::collections::BTreeSet) -> Result {\n".to_string()), " if items.is_empty() {\n".to_string()), " Err(\"NonEmptyBTreeSet requires at least one element\")\n".to_string()), " } else {\n".to_string()), " Ok(Self(items))\n".to_string()), " }\n".to_string()), " }\n\n".to_string()), " pub fn as_set(&self) -> &std::collections::BTreeSet {\n".to_string()), " &self.0\n".to_string()), " }\n\n".to_string()), " pub fn into_set(self) -> std::collections::BTreeSet {\n".to_string()), " self.0\n".to_string()), " }\n".to_string()), "}".to_string()); - v2_rt::concat(v2_rt::concat(vec_wrapper, "\n\n".to_string()), set_wrapper) - } +let set_wrapper = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("#[derive(Debug, Clone, PartialEq)]\n".to_string(), "pub struct NonEmptyBTreeSet(std::collections::BTreeSet);\n\n".to_string()), "impl NonEmptyBTreeSet {\n".to_string()), " pub fn new(items: std::collections::BTreeSet) -> Result {\n".to_string()), " if items.is_empty() {\n".to_string()), " Err(\"NonEmptyBTreeSet requires at least one element\")\n".to_string()), " } else {\n".to_string()), " Ok(Self(items))\n".to_string()), " }\n".to_string()), " }\n\n".to_string()), " pub fn as_set(&self) -> &std::collections::BTreeSet {\n".to_string()), " &self.0\n".to_string()), " }\n\n".to_string()), " pub fn into_set(self) -> std::collections::BTreeSet {\n".to_string()), " self.0\n".to_string()), " }\n".to_string()), "}".to_string()); +v2_rt::concat(v2_rt::concat(vec_wrapper, "\n\n".to_string()), set_wrapper) +} } -pub fn emit_typed_item( - item: &Rc, - module_name: String, - registry: &Rc>>, - scope: &Rc, - shared_types: Rc>, - emit_info: &Rc, - wire_contract_item: Option>, - data_items: Rc>>>>, - module_items: Rc>>, - imports: Rc>>, -) -> String { +pub fn emit_typed_item(item: &Rc, module_name: String, registry: &Rc>>, scope: &Rc, shared_types: Rc>, emit_info: &Rc, wire_contract_item: Option>, data_items: Rc>>>>, module_items: Rc>>, imports: Rc>>) -> String { { let env = scope.type_env.clone(); - let qualified_name = v2_rt::concat( - v2_rt::concat(module_name, ".".to_string()), - authored_name(env.clone(), item.clone()), - ); - let item_text = authored_name(env.clone(), item.clone()); - if is_type_def_item(&item) { - emit_type_def_from_connective( - &item, - emit_info.recursive_type_set.clone(), - shared_types, - &env, - emit_info.clone(), - &wire_contract_item, - data_items, - module_items, - imports, - ) +let qualified_name = v2_rt::concat(v2_rt::concat(module_name, ".".to_string()), authored_name(env.clone(), item.clone())); +let item_text = authored_name(env.clone(), item.clone()); +if is_type_def_item(&item) { + emit_type_def_from_connective(&item, emit_info.recursive_type_set.clone(), shared_types, &env, emit_info.clone(), &wire_contract_item, data_items, module_items, imports) } else { if is_type_alias_item(&item, env.source_indices.clone()) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - rust_visibility_prefix(), - rust_items().type_alias_keyword.clone(), - ), - " ".to_string(), - ), - item_text, - ), - " = ".to_string(), - ), - render_rust_type( - resolved_type(item.clone()), - shared_types, - env.source_indices.clone(), - ), - ), - ";".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), rust_items().type_alias_keyword.clone()), " ".to_string()), item_text), " = ".to_string()), render_rust_type(resolved_type(item.clone()), shared_types, env.source_indices.clone())), ";".to_string()) } else { if is_type_decl_item(&item, env.source_indices.clone()) { "".to_string() } else { if is_function_item(&item) { { - let fn_movable = match v2_rt::map_get( - &emit_info.ownership_index.clone(), - qualified_name.clone(), - ) { - Some(m) => m.clone(), - None => v2_rt::rc_empty_map::(), - }; - let item_is_tco = is_tco_eligible( - &authored_name(env.clone(), item.clone()), - &item.body.clone().clone().unwrap(), - registry.clone(), - &env.source_indices.clone(), - ); - let fn_read_only = if item_is_tco { + let fn_movable = match v2_rt::map_get(&emit_info.ownership_index.clone(), qualified_name.clone()) { + Some(m) => m.clone(), + None => v2_rt::rc_empty_map::(), +}; +let item_is_tco = is_tco_eligible(&authored_name(env.clone(), item.clone()), &item.body.clone().clone().unwrap(), registry.clone(), &env.source_indices.clone()); +let fn_read_only = if item_is_tco { v2_rt::rc_empty_map::() } else { - match v2_rt::map_get( - &emit_info.read_only_params_index.clone(), - qualified_name.clone(), - ) { - Some(m) => m.clone(), - None => v2_rt::rc_empty_map::(), - } - }; - let fn_emit_info = Rc::new(EmitGraphInfo { - type_summaries: emit_info.type_summaries.clone(), - recursive_type_set: emit_info.recursive_type_set.clone(), - fielded_variants: emit_info.fielded_variants.clone(), - shared_types: emit_info.shared_types.clone(), - ownership_index: emit_info.ownership_index.clone(), - movable: fn_movable, - variant_to_enum: emit_info.variant_to_enum.clone(), - owned_bindings: v2_rt::rc_empty_map::(), - read_only_params_index: emit_info.read_only_params_index.clone(), - read_only_params: fn_read_only, - }); - let is_effectful = match lookup_item( - registry.clone(), - authored_name(env.clone(), item.clone()), - ) { - Some(info) => { - (((info.service_names.clone().len() as i64) > 0) - || ((info.resource_names.clone().len() as i64) > 0)) - } - None => false, + match v2_rt::map_get(&emit_info.read_only_params_index.clone(), qualified_name.clone()) { + Some(m) => m.clone(), + None => v2_rt::rc_empty_map::(), +} }; - if is_effectful { - emit_func_def( - &item_text, - &item.params.clone(), - resolved_type(item.clone()), - &item.uses.clone(), - item.body.clone().clone().unwrap(), - ®istry, - &scope, - &shared_types, - &fn_emit_info, - ) +let fn_emit_info = Rc::new(EmitGraphInfo { + type_summaries: emit_info.type_summaries.clone(), + recursive_type_set: emit_info.recursive_type_set.clone(), + fielded_variants: emit_info.fielded_variants.clone(), + shared_types: emit_info.shared_types.clone(), + ownership_index: emit_info.ownership_index.clone(), + movable: fn_movable, + variant_to_enum: emit_info.variant_to_enum.clone(), + owned_bindings: v2_rt::rc_empty_map::(), + read_only_params_index: emit_info.read_only_params_index.clone(), + read_only_params: fn_read_only, +}); +let is_effectful = match lookup_item(registry.clone(), authored_name(env.clone(), item.clone())) { + Some(info) => (((info.service_names.clone().len() as i64) > 0) || ((info.resource_names.clone().len() as i64) > 0)), + None => false, +}; +if is_effectful { + emit_func_def(&item_text, &item.params.clone(), resolved_type(item.clone()), &item.uses.clone(), item.body.clone().clone().unwrap(), ®istry, &scope, &shared_types, &fn_emit_info) } else { - emit_fn_def( - &item_text, - &item.params.clone(), - resolved_type(item.clone()), - &item.body.clone().clone().unwrap(), - ®istry, - &scope, - &shared_types, - &fn_emit_info, - ) + emit_fn_def(&item_text, &item.params.clone(), resolved_type(item.clone()), &item.body.clone().clone().unwrap(), ®istry, &scope, &shared_types, &fn_emit_info) } - } +} } else { if is_data_def_item(&item) { - emit_data_def( - item_text, - &item.type_annotation.clone().clone().unwrap(), - item.body.clone().clone().unwrap(), - registry.clone(), - &scope, - 0, - &shared_types, - emit_info.clone(), - ) + emit_data_def(item_text, &item.type_annotation.clone().clone().unwrap(), item.body.clone().clone().unwrap(), registry.clone(), &scope, 0, &shared_types, emit_info.clone()) } else { if is_service_def_item(&item) { emit_service_def(&item, registry.clone(), shared_types, &env) @@ -2757,13 +1158,7 @@ pub fn emit_typed_item( if is_resource_def_item(&item) { emit_resource_def(&item, shared_types, &env) } else { - v2_rt::concat( - v2_rt::concat( - "compile_error!(\"unhandled item: ".to_string(), - item_text, - ), - "\");".to_string(), - ) + v2_rt::concat(v2_rt::concat("compile_error!(\"unhandled item: ".to_string(), item_text), "\");".to_string()) } } } @@ -2771,229 +1166,123 @@ pub fn emit_typed_item( } } } - } +} } -pub fn needs_box_wrapping( - mut n: Rc, - mut recursive_types: Rc>, - mut shared_types: Rc>, - mut source_indices: Rc>>, -) -> bool { +pub fn needs_box_wrapping(mut n: Rc, mut recursive_types: Rc>, mut shared_types: Rc>, mut source_indices: Rc>>) -> bool { loop { if ((n.children.clone().len() as i64) == 0) { let name = authored_name_at(source_indices, &n); - if emit_map_has(shared_types, name.clone()) { +if emit_map_has(shared_types, name.clone()) { break false; - } else { +} else { break emit_map_has(recursive_types, name.clone()); - } - } else { +} +} else { let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { +if is_optional { { let __tco_0 = with_required_cardinality(&n); - n = __tco_0; - continue; - } - } else { +n = __tco_0; +continue; +} +} else { break false; - } - } - } +} +} +} } -pub fn emit_type_params( - params: &Rc>>, - source_indices: Rc>>, -) -> String { +pub fn emit_type_params(params: &Rc>>, source_indices: Rc>>) -> String { if ((params.clone().len() as i64) == 0) { "".to_string() } else { { - let names = Rc::new({ - let mut __result = Vec::new(); - for p in params.clone().iter().cloned() { - __result.push(generic_param_name_at(p.clone(), source_indices.clone())); - } - __result - }); - v2_rt::concat( - v2_rt::concat("<".to_string(), names.join(&", ".to_string())), - ">".to_string(), - ) - } + let names = Rc::new({ let mut __result = Vec::new(); for p in params.clone().iter().cloned() { __result.push(generic_param_name_at(p.clone(), source_indices.clone())); } __result }); +v2_rt::concat(v2_rt::concat("<".to_string(), names.join(&", ".to_string())), ">".to_string()) +} } } pub fn is_function_type_param(param: &Rc) -> bool { { let type_expr = param_node_type_expr(¶m); - let type_expr_is_var = match type_expr.inferred.clone() { - Some(inf) => is_type_variable(inf.clone()), - None => false, - }; - ((type_expr_is_var && (param.name.clone().as_str() != "".to_string().as_str())) - && (param.name.clone().as_str() == type_expr.name.clone().as_str())) - } +let type_expr_is_var = match type_expr.inferred.clone() { + Some(inf) => is_type_variable(inf.clone()), + None => false, +}; +((type_expr_is_var && (param.name.clone().as_str() != "".to_string().as_str())) && (param.name.clone().as_str() == type_expr.name.clone().as_str())) +} } pub fn function_type_params(params: Rc>>) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - if is_function_type_param(&p) { - __result.push(p); - } - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { if is_function_type_param(&p) { __result.push(p); } } __result }) } pub fn function_value_params(params: Rc>>) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - if !is_function_type_param(&p) { - __result.push(p); - } - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { if !is_function_type_param(&p) { __result.push(p); } } __result }) } pub fn function_type_params_have_collision(type_params: Rc>>) -> bool { { - let names = Rc::new({ - let mut __result = Vec::new(); - for p in type_params.iter().cloned() { - __result.push(p.name.clone()); - } - __result - }); - ((names.clone().len() as i64) > (unique_strings(names.clone()).len() as i64)) - } + let names = Rc::new({ let mut __result = Vec::new(); for p in type_params.iter().cloned() { __result.push(p.name.clone()); } __result }); +((names.clone().len() as i64) > (unique_strings(names.clone()).len() as i64)) +} } -pub fn emit_type_def_from_connective( - item: &Rc, - recursive_types: Rc>, - shared_types: Rc>, - env: &Rc, - emit_info: Rc, - wire_contract_item: &Option>, - data_items: Rc>>>>, - module_items: Rc>>, - imports: Rc>>, -) -> String { +pub fn emit_type_def_from_connective(item: &Rc, recursive_types: Rc>, shared_types: Rc>, env: &Rc, emit_info: Rc, wire_contract_item: &Option>, data_items: Rc>>>>, module_items: Rc>>, imports: Rc>>) -> String { { let type_params = emit_type_params(&item.params.clone(), env.source_indices.clone()); - let item_text = authored_name(env.clone(), item.clone()); - let is_product = is_product_type(item.clone()); - if is_product { - emit_struct_from_children( - &item_text, - type_params, - &item.children.clone(), - recursive_types, - &shared_types, - env.clone(), - emit_info, - ) +let item_text = authored_name(env.clone(), item.clone()); +let is_product = is_product_type(item.clone()); +if is_product { + emit_struct_from_children(&item_text, type_params, &item.children.clone(), recursive_types, &shared_types, env.clone(), emit_info) } else { { - let all_unit_variants = { - let mut __all = true; - for child in item.children.clone().iter().cloned() { - if !((child.children.clone().len() as i64) == 0) { - __all = false; - break; - } - } - __all - }; - let serde_policy = match resolve_local_coproduct_wire_policy( - &item_text, - all_unit_variants.clone(), - &module_items, - imports, - &env.source_indices.clone(), - ) { - Some(local_policy) => local_policy.clone(), - None => { - if all_unit_variants.clone() { - match wire_contract_item.clone() { - Some(_) => resolve_wire_serde_policy_for_coproduct( - wire_contract_item.clone(), - env.source_indices.clone(), - data_items, - ), - None => rust_tagged_object_policy(), - } - } else { - rust_tagged_object_policy() - } - } - }; - let rename_validations = variant_rename_validations_for_policy( - item.children.clone(), - env.clone(), - serde_policy.clone(), - ); - let policy_validation = match serde_policy.error_message.clone() { - Some(message) => emit_rust_compile_error_item(message.clone()), - None => "".to_string(), - }; - let validations = if (policy_validation.clone().as_str() == "".to_string().as_str()) - { - rename_validations.clone() + let all_unit_variants = { let mut __all = true; for child in item.children.clone().iter().cloned() { if !(((child.children.clone().len() as i64) == 0)) { __all = false; break; } } __all }; +let serde_policy = match resolve_local_coproduct_wire_policy(&item_text, all_unit_variants.clone(), &module_items, imports, &env.source_indices.clone()) { + Some(local_policy) => local_policy.clone(), + None => if all_unit_variants.clone() { + match wire_contract_item.clone() { + Some(_) => resolve_wire_serde_policy_for_coproduct(wire_contract_item.clone(), env.source_indices.clone(), data_items), + None => rust_tagged_object_policy(), +} + } else { + rust_tagged_object_policy() + }, +}; +let rename_validations = variant_rename_validations_for_policy(item.children.clone(), env.clone(), serde_policy.clone()); +let policy_validation = match serde_policy.error_message.clone() { + Some(message) => emit_rust_compile_error_item(message.clone()), + None => "".to_string(), +}; +let validations = if (policy_validation.clone().as_str() == "".to_string().as_str()) { + rename_validations.clone() } else { if (rename_validations.clone().as_str() == "".to_string().as_str()) { policy_validation.clone() } else { - v2_rt::concat( - v2_rt::concat(policy_validation.clone(), "\n".to_string()), - rename_validations.clone(), - ) + v2_rt::concat(v2_rt::concat(policy_validation.clone(), "\n".to_string()), rename_validations.clone()) } }; - let enum_text = emit_enum_from_children( - &item_text, - &type_params, - &item.children.clone(), - &recursive_types, - &shared_types, - &env, - &serde_policy, - ); - if (validations.clone().as_str() == "".to_string().as_str()) { +let enum_text = emit_enum_from_children(&item_text, &type_params, &item.children.clone(), &recursive_types, &shared_types, &env, &serde_policy); +if (validations.clone().as_str() == "".to_string().as_str()) { enum_text } else { - v2_rt::concat( - v2_rt::concat(validations.clone(), "\n".to_string()), - enum_text, - ) + v2_rt::concat(v2_rt::concat(validations.clone(), "\n".to_string()), enum_text) } - } +} } - } +} } -pub fn emit_struct_from_children( - name: &String, - type_params: String, - children: &Rc>>, - recursive_types: Rc>, - shared_types: &Rc>, - env: Rc, - emit_info: Rc, -) -> String { +pub fn emit_struct_from_children(name: &String, type_params: String, children: &Rc>>, recursive_types: Rc>, shared_types: &Rc>, env: Rc, emit_info: Rc) -> String { { let has_fn_fields = match v2_rt::map_get(&emit_info.type_summaries.clone(), name.clone()) { - Some(ts) => ts.has_fn_fields.clone(), - None => false, - }; - let derives = if has_fn_fields { + Some(ts) => ts.has_fn_fields.clone(), + None => false, +}; +let derives = if has_fn_fields { "#[derive(Clone)]".to_string() } else { if emit_map_has(shared_types.clone(), name.clone()) { @@ -3002,614 +1291,171 @@ pub fn emit_struct_from_children( rust_struct_derives_copy_text() } }; - if ((children.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(derives, "\n".to_string()), - rust_visibility_prefix(), - ), - rust_items().struct_keyword.clone(), - ), - " ".to_string(), - ), - name.clone(), - ), - type_params, - ), - ";".to_string(), - ) +if ((children.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(derives, "\n".to_string()), rust_visibility_prefix()), rust_items().struct_keyword.clone()), " ".to_string()), name.clone()), type_params), ";".to_string()) } else { { - let field_lines = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push(emit_struct_field_from_child( - &child, - recursive_types.clone(), - &shared_types, - &env, - )); - } - __result - }); - let fields_str = field_lines.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(derives, "\n".to_string()), - rust_visibility_prefix(), - ), - rust_items().struct_keyword.clone(), - ), - " ".to_string(), - ), - name.clone(), - ), - type_params, - ), - " {\n".to_string(), - ), - fields_str, - ), - "\n}".to_string(), - ) - } + let field_lines = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push(emit_struct_field_from_child(&child, recursive_types.clone(), &shared_types, &env)); } __result }); +let fields_str = field_lines.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(derives, "\n".to_string()), rust_visibility_prefix()), rust_items().struct_keyword.clone()), " ".to_string()), name.clone()), type_params), " {\n".to_string()), fields_str), "\n}".to_string()) +} } - } +} } -pub fn emit_struct_field_from_child( - child: &Rc, - recursive_types: Rc>, - shared_types: &Rc>, - env: &Rc, -) -> String { +pub fn emit_struct_field_from_child(child: &Rc, recursive_types: Rc>, shared_types: &Rc>, env: &Rc) -> String { { let rt_child = resolved_type(child.clone()); - let ty = if ((is_product_type(rt_child.clone()) && (rt_child.ident_span.clone() != None)) - && ((rt_child.children.clone().len() as i64) > 2)) - { +let ty = if ((is_product_type(rt_child.clone()) && (rt_child.ident_span.clone() != None)) && ((rt_child.children.clone().len() as i64) > 2)) { { let rt_child_name = authored_name_at(env.source_indices.clone(), &rt_child); - match lookup_type_by_name(&env, rt_child_name.clone()) { - Some(resolved) => { - if ((resolved.params.clone().len() as i64) > 0) { - { - let base = coerce_primitive_type( - RenderTarget::Rust, - rt_child_name.clone(), - ); - let param_names = Rc::new({ - let mut __result = Vec::new(); - for p in resolved.params.clone().iter().cloned() { - __result.push(generic_param_name_at( - p.clone(), - env.source_indices.clone(), - )); - } - __result - }); - let with_params = v2_rt::concat( - v2_rt::concat( - v2_rt::concat(base, "<".to_string()), - param_names.join(&", ".to_string()), - ), - ">".to_string(), - ); - if emit_map_has(shared_types.clone(), rt_child_name.clone()) { - v2_rt::concat( - v2_rt::concat("Rc<".to_string(), with_params), - ">".to_string(), - ) - } else { - with_params - } - } +match lookup_type_by_name(&env, rt_child_name.clone()) { + Some(resolved) => if ((resolved.params.clone().len() as i64) > 0) { + { + let base = coerce_primitive_type(RenderTarget::Rust, rt_child_name.clone()); +let param_names = Rc::new({ let mut __result = Vec::new(); for p in resolved.params.clone().iter().cloned() { __result.push(generic_param_name_at(p.clone(), env.source_indices.clone())); } __result }); +let with_params = v2_rt::concat(v2_rt::concat(v2_rt::concat(base, "<".to_string()), param_names.join(&", ".to_string())), ">".to_string()); +if emit_map_has(shared_types.clone(), rt_child_name.clone()) { + v2_rt::concat(v2_rt::concat("Rc<".to_string(), with_params), ">".to_string()) } else { - render_rust_type( - rt_child.clone(), - shared_types.clone(), - env.source_indices.clone(), - ) + with_params } - } - None => render_rust_type( - rt_child.clone(), - shared_types.clone(), - env.source_indices.clone(), - ), - } - } +} + } else { + render_rust_type(rt_child.clone(), shared_types.clone(), env.source_indices.clone()) + }, + None => render_rust_type(rt_child.clone(), shared_types.clone(), env.source_indices.clone()), +} +} } else { - render_rust_type( - rt_child.clone(), - shared_types.clone(), - env.source_indices.clone(), - ) + render_rust_type(rt_child.clone(), shared_types.clone(), env.source_indices.clone()) }; - let final_ty = if needs_box_wrapping( - rt_child.clone(), - recursive_types, - shared_types.clone(), - env.source_indices.clone(), - ) { +let final_ty = if needs_box_wrapping(rt_child.clone(), recursive_types, shared_types.clone(), env.source_indices.clone()) { v2_rt::concat(v2_rt::concat("Box<".to_string(), ty), ">".to_string()) } else { ty }; - 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()) - { - __result.push(p); - } - } - __result - }) - .first() - .cloned() - { - Some(prop) => match (*field_init_node_value(&prop).expr_data.clone()).clone() { - ExprData::ExprLiteral { value: lv, .. } => match (*lv.clone()).clone() { - LiteralValue::LitStr { value: key, .. } => v2_rt::concat( - v2_rt::concat( - " ".to_string(), - apply_type_template1(rust_serde_rename_template_text(), key.clone()), - ), - "\n".to_string(), - ), - _ => "".to_string(), - }, - _ => "".to_string(), - }, - None => "".to_string(), - }; - let authored = authored_name(env.clone(), child.clone()); - let snake = to_snake(authored.clone()); - let is_reserved = { - let mut __found = false; - for r in language_spec(RenderTarget::Rust) - .reserved_words - .clone() - .keywords - .clone() - .iter() - .cloned() - { - if (r.clone().as_str() == snake.clone().as_str()) { - __found = true; - break; - } - } - __found +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()) { __result.push(p); } } __result }).first().cloned() { + Some(prop) => match (*field_init_node_value(&prop).expr_data.clone()).clone() { + ExprData::ExprLiteral { value: lv, .. } => match (*lv.clone()).clone() { + LiteralValue::LitStr { value: key, .. } => v2_rt::concat(v2_rt::concat(" ".to_string(), apply_type_template1(rust_serde_rename_template_text(), key.clone())), "\n".to_string()), + _ => "".to_string(), +}, + _ => "".to_string(), +}, + None => "".to_string(), +}; +let authored = authored_name(env.clone(), child.clone()); +let snake = to_snake(authored.clone()); +let is_reserved = { let mut __found = false; for r in language_spec(RenderTarget::Rust).reserved_words.clone().keywords.clone().iter().cloned() { if (r.clone().as_str() == snake.clone().as_str()) { __found = true; break; } } __found }; +let keyword_rename = if (is_reserved && (rename_attr.clone().as_str() == "".to_string().as_str())) { + v2_rt::concat(v2_rt::concat(" #[serde(rename = \"".to_string(), snake.clone()), "\")]\n".to_string()) + } else { + "".to_string() }; - let keyword_rename = - if (is_reserved && (rename_attr.clone().as_str() == "".to_string().as_str())) { - v2_rt::concat( - v2_rt::concat(" #[serde(rename = \"".to_string(), snake.clone()), - "\")]\n".to_string(), - ) - } else { - "".to_string() - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(keyword_rename, rename_attr.clone()), - " ".to_string(), - ), - rust_visibility_prefix(), - ), - emit_ident(authored.clone(), RenderTarget::Rust), - ), - ": ".to_string(), - ), - final_ty, - ), - ",".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(keyword_rename, rename_attr.clone()), " ".to_string()), rust_visibility_prefix()), emit_ident(authored.clone(), RenderTarget::Rust)), ": ".to_string()), final_ty), ",".to_string()) +} } pub fn enum_derives(children: Rc>>) -> String { { - let complex = Rc::new({ - let mut __result = Vec::new(); - for v in children.iter().cloned() { - if ((v.children.clone().len() as i64) > 0) { - __result.push(v); - } - } - __result - }); - match ((complex.len() as i64) == 0) { - true => rust_enum_derives_copy_text(), - false => rust_enum_derives_text(), - } - } + let complex = Rc::new({ let mut __result = Vec::new(); for v in children.iter().cloned() { if ((v.children.clone().len() as i64) > 0) { __result.push(v); } } __result }); +match ((complex.len() as i64) == 0) { + true => rust_enum_derives_copy_text(), + false => rust_enum_derives_text(), +} +} } -pub fn emit_enum_from_children( - name: &String, - type_params: &String, - children: &Rc>>, - recursive_types: &Rc>, - shared_types: &Rc>, - env: &Rc, - serde_policy: &Rc, -) -> String { +pub fn emit_enum_from_children(name: &String, type_params: &String, children: &Rc>>, recursive_types: &Rc>, shared_types: &Rc>, env: &Rc, serde_policy: &Rc) -> String { { let derives = enum_derives(children.clone()); - let variant_lines = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push(emit_variant_from_child( - &child, - recursive_types.clone(), - shared_types.clone(), - &env, - serde_policy.clone(), - )); - } - __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 variant_lines = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push(emit_variant_from_child(&child, recursive_types.clone(), shared_types.clone(), &env, serde_policy.clone())); } __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()) { "".to_string() } else { v2_rt::concat(serde_policy.enum_attr.clone(), "\n".to_string()) }; - let enum_def = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(derives, "\n".to_string()), - tag_line, - ), - rust_visibility_prefix(), - ), - rust_items().enum_keyword.clone(), - ), - " ".to_string(), - ), - name.clone(), - ), - type_params.clone(), - ), - " {\n".to_string(), - ), - variants_str, - ), - "\n}".to_string(), - ); - let accessor_impl = emit_enum_shared_accessors( - &name, - &type_params, - &children, - recursive_types.clone(), - shared_types.clone(), - &env, - ); - if (accessor_impl.clone().as_str() == "".to_string().as_str()) { +let enum_def = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(derives, "\n".to_string()), tag_line), rust_visibility_prefix()), rust_items().enum_keyword.clone()), " ".to_string()), name.clone()), type_params.clone()), " {\n".to_string()), variants_str), "\n}".to_string()); +let accessor_impl = emit_enum_shared_accessors(&name, &type_params, &children, recursive_types.clone(), shared_types.clone(), &env); +if (accessor_impl.clone().as_str() == "".to_string().as_str()) { enum_def } else { - v2_rt::concat( - v2_rt::concat(enum_def, "\n".to_string()), - accessor_impl.clone(), - ) + v2_rt::concat(v2_rt::concat(enum_def, "\n".to_string()), accessor_impl.clone()) } - } +} } pub fn find_shared_enum_fields(children: Rc>>, env: Rc) -> Rc> { { - let fielded = 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 - }); - if ((fielded.clone().len() as i64) == 0) { - return Rc::new(vec![]); + let fielded = 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 }); +if ((fielded.clone().len() as i64) == 0) { + return Rc::new(vec![]) } - let first_fields = match fielded.clone().first().cloned() { - Some(v) => Rc::new({ - let mut __result = Vec::new(); - for f in v.children.clone().iter().cloned() { - __result.push(authored_name(env.clone(), f.clone())); - } - __result - }), - None => Rc::new(vec![]), - }; - Rc::new({ - let mut __result = Vec::new(); - for fname in first_fields.iter().cloned() { - if { - let mut __all = true; - for variant in fielded.clone().iter().cloned() { - 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()) - { - __found = true; - break; - } - } - __found - }) { - __all = false; - break; - } - } - __all - } { - __result.push(fname); - } - } - __result - }) - } +let first_fields = match fielded.clone().first().cloned() { + Some(v) => Rc::new({ let mut __result = Vec::new(); for f in v.children.clone().iter().cloned() { __result.push(authored_name(env.clone(), f.clone())); } __result }), + None => Rc::new(vec![]), +}; +Rc::new({ let mut __result = Vec::new(); for fname in first_fields.iter().cloned() { if { let mut __all = true; for variant in fielded.clone().iter().cloned() { 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()) { __found = true; break; } } __found }) { __all = false; break; } } __all } { __result.push(fname); } } __result }) +} } -pub fn emit_enum_shared_accessors( - name: &String, - type_params: &String, - children: &Rc>>, - recursive_types: Rc>, - shared_types: Rc>, - env: &Rc, -) -> String { +pub fn emit_enum_shared_accessors(name: &String, type_params: &String, children: &Rc>>, recursive_types: Rc>, shared_types: Rc>, env: &Rc) -> String { { let all_shared = find_shared_enum_fields(children.clone(), env.clone()); - if ((all_shared.clone().len() as i64) == 0) { - return "".to_string(); +if ((all_shared.clone().len() as i64) == 0) { + return "".to_string() } - let fielded = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - if ((child.children.clone().len() as i64) > 0) { - __result.push(child); - } - } - __result - }); - if ((fielded.clone().len() as i64) == 0) { - return "compile_error!(\"enum shared accessor missing fielded variant\")".to_string(); +let fielded = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { if ((child.children.clone().len() as i64) > 0) { __result.push(child); } } __result }); +if ((fielded.clone().len() as i64) == 0) { + return "compile_error!(\"enum shared accessor missing fielded variant\")".to_string() } - let first_fielded = fielded.clone().first().cloned().clone().unwrap(); - let shared = Rc::new({ - let mut __result = Vec::new(); - for fname in all_shared.clone().iter().cloned() { - if { - let types = Rc::new({ - let mut __result = Vec::new(); - for variant in fielded.clone().iter().cloned() { - __result.push( - 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()) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned() - { - Some(f) => render_rust_type( - resolved_type(f.clone()), - shared_types.clone(), - env.source_indices.clone(), - ), - None => "".to_string(), - }, - ); - } - __result - }); - let first_type = match types.clone().first().cloned() { - Some(t) => t.clone(), - None => "".to_string(), - }; +let first_fielded = fielded.clone().first().cloned().clone().unwrap(); +let shared = Rc::new({ let mut __result = Vec::new(); for fname in all_shared.clone().iter().cloned() { if { + let types = Rc::new({ let mut __result = Vec::new(); for variant in fielded.clone().iter().cloned() { __result.push(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()) { __result.push(f); } } __result }).first().cloned() { + Some(f) => render_rust_type(resolved_type(f.clone()), shared_types.clone(), env.source_indices.clone()), + None => "".to_string(), +}); } __result }); +let first_type = match types.clone().first().cloned() { + Some(t) => t.clone(), + None => "".to_string(), +}; +{ let mut __all = true; for t in types.clone().iter().cloned() { if !((t.clone().as_str() == first_type.clone().as_str())) { __all = false; break; } } __all } +} { __result.push(fname); } } __result }); +if ((shared.clone().len() as i64) == 0) { + return "".to_string() + } +let accessor_fns = Rc::new({ let mut __result = Vec::new(); for fname in shared.clone().iter().cloned() { __result.push({ + 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()) { __result.push(f); } } __result }).first().cloned() { + Some(f) => render_rust_type(resolved_type(f.clone()), shared_types.clone(), env.source_indices.clone()), + None => "compile_error!(\"enum shared accessor missing field metadata\")".to_string(), +}; +let arms = Rc::new({ let mut __result = Vec::new(); for child in children.clone().iter().cloned() { __result.push({ + let child_text = authored_name(env.clone(), child.clone()); +if ((child.children.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), name.clone()), "::".to_string()), child_text.clone()), " => panic!(\"no ".to_string()), fname.clone()), " on unit variant\"),".to_string()) + } else { { - let mut __all = true; - for t in types.clone().iter().cloned() { - if !(t.clone().as_str() == first_type.clone().as_str()) { - __all = false; - break; - } - } - __all - } - } { - __result.push(fname); + let sharing = language_spec(RenderTarget::Rust).sharing.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), name.clone()), "::".to_string()), child_text.clone()), " { ".to_string()), emit_ident(fname.clone(), RenderTarget::Rust)), ": __val, .. } => ".to_string()), apply_type_template1(sharing.clone_value.clone(), "__val".to_string())), ",".to_string()) +} } - } - __result - }); - if ((shared.clone().len() as i64) == 0) { - return "".to_string(); - } - let accessor_fns = Rc::new({ - let mut __result = Vec::new(); - for fname in shared.clone().iter().cloned() { - __result.push({ - 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()) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned() - { - Some(f) => render_rust_type( - resolved_type(f.clone()), - shared_types.clone(), - env.source_indices.clone(), - ), - None => "compile_error!(\"enum shared accessor missing field metadata\")" - .to_string(), - }; - let arms = Rc::new({ - let mut __result = Vec::new(); - for child in children.clone().iter().cloned() { - __result.push({ - let child_text = authored_name(env.clone(), child.clone()); - if ((child.children.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " ".to_string(), - name.clone(), - ), - "::".to_string(), - ), - child_text.clone(), - ), - " => panic!(\"no ".to_string(), - ), - fname.clone(), - ), - " on unit variant\"),".to_string(), - ) - } else { - { - let sharing = - language_spec(RenderTarget::Rust).sharing.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " ".to_string(), - name.clone(), - ), - "::".to_string(), - ), - child_text.clone(), - ), - " { ".to_string(), - ), - emit_ident( - fname.clone(), - RenderTarget::Rust, - ), - ), - ": __val, .. } => ".to_string(), - ), - apply_type_template1( - sharing.clone_value.clone(), - "__val".to_string(), - ), - ), - ",".to_string(), - ) - } - } - }); - } - __result - }); - let arms_str = arms.clone().join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " pub fn ".to_string(), - emit_ident(fname.clone(), RenderTarget::Rust), - ), - "(&self) -> ".to_string(), - ), - ty.clone(), - ), - " {\n match self {\n".to_string(), - ), - arms_str.clone(), - ), - "\n }\n }".to_string(), - ) - }); - } - __result - }); - let fns_str = accessor_fns.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("impl".to_string(), type_params.clone()), - " ".to_string(), - ), - name.clone(), - ), - type_params.clone(), - ), - " {\n".to_string(), - ), - fns_str, - ), - "\n}".to_string(), - ) - } +}); } __result }); +let arms_str = arms.clone().join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" pub fn ".to_string(), emit_ident(fname.clone(), RenderTarget::Rust)), "(&self) -> ".to_string()), ty.clone()), " {\n match self {\n".to_string()), arms_str.clone()), "\n }\n }".to_string()) +}); } __result }); +let fns_str = accessor_fns.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("impl".to_string(), type_params.clone()), " ".to_string()), name.clone()), type_params.clone()), " {\n".to_string()), fns_str), "\n}".to_string()) +} } pub fn string_without_prefix(value: &String, prefix: &String) -> Option { if (v2_rt::string_length(&prefix) == 0) { None } else { - if ((v2_rt::string_length(&value) >= v2_rt::string_length(&prefix)) - && (v2_rt::substring(&value, 0, v2_rt::string_length(&prefix)).as_str() - == prefix.clone().as_str())) - { - Some(v2_rt::substring( - &value, - v2_rt::string_length(&prefix), - v2_rt::string_length(&value), - )) + if ((v2_rt::string_length(&value) >= v2_rt::string_length(&prefix)) && (v2_rt::substring(&value, 0, v2_rt::string_length(&prefix)).as_str() == prefix.clone().as_str())) { + Some(v2_rt::substring(&value, v2_rt::string_length(&prefix), v2_rt::string_length(&value))) } else { None } @@ -3620,1130 +1466,375 @@ pub fn string_without_suffix(value: &String, suffix: &String) -> Option if (v2_rt::string_length(&suffix) == 0) { None } else { - if ((v2_rt::string_length(&value) >= v2_rt::string_length(&suffix)) - && (v2_rt::substring( - &value, - (v2_rt::string_length(&value) - v2_rt::string_length(&suffix)), - v2_rt::string_length(&value), - ) - .as_str() - == suffix.clone().as_str())) - { - Some(v2_rt::substring( - &value, - 0, - (v2_rt::string_length(&value) - v2_rt::string_length(&suffix)), - )) + if ((v2_rt::string_length(&value) >= v2_rt::string_length(&suffix)) && (v2_rt::substring(&value, (v2_rt::string_length(&value) - v2_rt::string_length(&suffix)), v2_rt::string_length(&value)).as_str() == suffix.clone().as_str())) { + Some(v2_rt::substring(&value, 0, (v2_rt::string_length(&value) - v2_rt::string_length(&suffix)))) } else { None } } } -pub fn wire_variant_rename_attr_for_policy( - authored: String, - policy: &Rc, -) -> String { +pub fn wire_variant_rename_attr_for_policy(authored: String, policy: &Rc) -> String { match policy.rename_style.clone() { - Some(style) => { - if (style.clone().as_str() == "StripAffixAndSnakeCase".to_string().as_str()) { - { - let without_prefix = match policy.rename_prefix.clone() { - Some(prefix) => match string_without_prefix(&authored, &prefix) { - Some(stripped) => stripped.clone(), - None => return "".to_string(), - }, - None => authored, - }; - let without_suffix = match policy.rename_suffix.clone() { - Some(suffix) => match string_without_suffix(&without_prefix, &suffix) { - Some(stripped) => stripped.clone(), - None => return "".to_string(), - }, - None => without_prefix, - }; - v2_rt::concat( - v2_rt::concat( - " #[serde(rename = \"".to_string(), - to_snake(without_suffix), - ), - "\")]\n".to_string(), - ) - } - } else { - "".to_string() - } - } - None => "".to_string(), - } + Some(style) => if (style.clone().as_str() == "StripAffixAndSnakeCase".to_string().as_str()) { + { + let without_prefix = match policy.rename_prefix.clone() { + Some(prefix) => match string_without_prefix(&authored, &prefix) { + Some(stripped) => stripped.clone(), + None => return "".to_string(), +}, + None => authored, +}; +let without_suffix = match policy.rename_suffix.clone() { + Some(suffix) => match string_without_suffix(&without_prefix, &suffix) { + Some(stripped) => stripped.clone(), + None => return "".to_string(), +}, + None => without_prefix, +}; +v2_rt::concat(v2_rt::concat(" #[serde(rename = \"".to_string(), to_snake(without_suffix)), "\")]\n".to_string()) +} + } else { + "".to_string() + }, + None => "".to_string(), +} } -pub fn variant_rename_validation_for_policy( - authored: &String, - policy: &Rc, -) -> String { +pub fn variant_rename_validation_for_policy(authored: &String, policy: &Rc) -> String { match policy.rename_style.clone() { - Some(style) => { - if (style.clone().as_str() == "StripAffixAndSnakeCase".to_string().as_str()) { - { - let without_prefix = match policy.rename_prefix.clone() { - Some(prefix) => match string_without_prefix(&authored, &prefix) { - Some(stripped) => stripped.clone(), - None => { - return emit_rust_compile_error_item(v2_rt::concat( - v2_rt::concat( - v2_rt::concat("variant ".to_string(), authored.clone()), - " does not satisfy declared wire rename prefix: " - .to_string(), - ), - prefix.clone(), - )) - } - }, - None => authored.clone(), - }; - match policy.rename_suffix.clone() { - Some(suffix) => match string_without_suffix(&without_prefix, &suffix) { - Some(_) => "".to_string(), - None => emit_rust_compile_error_item(v2_rt::concat( - v2_rt::concat( - v2_rt::concat("variant ".to_string(), authored.clone()), - " does not satisfy declared wire rename suffix: ".to_string(), - ), - suffix.clone(), - )), - }, - None => "".to_string(), - } - } - } else { - "".to_string() - } - } - None => "".to_string(), - } + Some(style) => if (style.clone().as_str() == "StripAffixAndSnakeCase".to_string().as_str()) { + { + let without_prefix = match policy.rename_prefix.clone() { + Some(prefix) => match string_without_prefix(&authored, &prefix) { + Some(stripped) => stripped.clone(), + None => return emit_rust_compile_error_item(v2_rt::concat(v2_rt::concat(v2_rt::concat("variant ".to_string(), authored.clone()), " does not satisfy declared wire rename prefix: ".to_string()), prefix.clone())), +}, + None => authored.clone(), +}; +match policy.rename_suffix.clone() { + Some(suffix) => match string_without_suffix(&without_prefix, &suffix) { + Some(_) => "".to_string(), + None => emit_rust_compile_error_item(v2_rt::concat(v2_rt::concat(v2_rt::concat("variant ".to_string(), authored.clone()), " does not satisfy declared wire rename suffix: ".to_string()), suffix.clone())), +}, + None => "".to_string(), +} +} + } else { + "".to_string() + }, + None => "".to_string(), +} } -pub fn variant_rename_validations_for_policy( - children: Rc>>, - env: Rc, - serde_policy: Rc, -) -> String { - Rc::new({ - let mut __result = Vec::new(); - for text in Rc::new({ - let mut __result = Vec::new(); - for child in children.iter().cloned() { - __result.push(variant_rename_validation_for_policy( - &authored_name(env.clone(), child.clone()), - &serde_policy, - )); - } - __result - }) - .iter() - .cloned() - { - if (text.clone().as_str() != "".to_string().as_str()) { - __result.push(text); - } - } - __result - }) - .join(&"\n".to_string()) +pub fn variant_rename_validations_for_policy(children: Rc>>, env: Rc, serde_policy: Rc) -> String { + Rc::new({ let mut __result = Vec::new(); for text in Rc::new({ let mut __result = Vec::new(); for child in children.iter().cloned() { __result.push(variant_rename_validation_for_policy(&authored_name(env.clone(), child.clone()), &serde_policy)); } __result }).iter().cloned() { if (text.clone().as_str() != "".to_string().as_str()) { __result.push(text); } } __result }).join(&"\n".to_string()) } -pub fn emit_variant_from_child( - child: &Rc, - recursive_types: Rc>, - shared_types: Rc>, - env: &Rc, - serde_policy: Rc, -) -> String { +pub fn emit_variant_from_child(child: &Rc, recursive_types: Rc>, shared_types: Rc>, env: &Rc, serde_policy: Rc) -> String { { let child_text = authored_name(env.clone(), child.clone()); - let rename_attr = wire_variant_rename_attr_for_policy(child_text.clone(), &serde_policy); - if ((child.children.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(rename_attr, " ".to_string()), - child_text.clone(), - ), - ",".to_string(), - ) +let rename_attr = wire_variant_rename_attr_for_policy(child_text.clone(), &serde_policy); +if ((child.children.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(rename_attr, " ".to_string()), child_text.clone()), ",".to_string()) } else { { - let field_lines = Rc::new({ - let mut __result = Vec::new(); - for f in child.children.clone().iter().cloned() { - __result.push({ - let rt_f = resolved_type(f.clone()); - let ty = render_rust_type( - rt_f.clone(), - shared_types.clone(), - env.source_indices.clone(), - ); - let final_ty = if needs_box_wrapping( - rt_f.clone(), - recursive_types.clone(), - shared_types.clone(), - env.source_indices.clone(), - ) { - v2_rt::concat( - v2_rt::concat("Box<".to_string(), ty.clone()), - ">".to_string(), - ) - } else { - ty.clone() - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " ".to_string(), - emit_ident( - authored_name(env.clone(), f.clone()), - RenderTarget::Rust, - ), - ), - ": ".to_string(), - ), - final_ty.clone(), - ), - ",".to_string(), - ) - }); - } - __result - }); - let fields_str = field_lines.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(rename_attr, " ".to_string()), - child_text.clone(), - ), - " {\n".to_string(), - ), - fields_str, - ), - "\n },".to_string(), - ) - } + let field_lines = Rc::new({ let mut __result = Vec::new(); for f in child.children.clone().iter().cloned() { __result.push({ + let rt_f = resolved_type(f.clone()); +let ty = render_rust_type(rt_f.clone(), shared_types.clone(), env.source_indices.clone()); +let final_ty = if needs_box_wrapping(rt_f.clone(), recursive_types.clone(), shared_types.clone(), env.source_indices.clone()) { + v2_rt::concat(v2_rt::concat("Box<".to_string(), ty.clone()), ">".to_string()) + } else { + ty.clone() + }; +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), emit_ident(authored_name(env.clone(), f.clone()), RenderTarget::Rust)), ": ".to_string()), final_ty.clone()), ",".to_string()) +}); } __result }); +let fields_str = field_lines.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rename_attr, " ".to_string()), child_text.clone()), " {\n".to_string()), fields_str), "\n },".to_string()) +} } - } +} } -pub fn emit_fn_def( - name: &String, - params: &Rc>>, - inferred: Rc, - body: &Rc, - registry: &Rc>>, - scope: &Rc, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_fn_def(name: &String, params: &Rc>>, inferred: Rc, body: &Rc, registry: &Rc>>, scope: &Rc, shared_types: &Rc>, emit_info: &Rc) -> 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 v2_rt::concat(v2_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, si.clone()); - let params_str = emit_params( - value_params.clone(), - shared_types.clone(), - si.clone(), - emit_info.read_only_params.clone(), - ); - let ret_str = emit_inferred(inferred, shared_types.clone(), si.clone()); - let body_scope = build_params_scope(&scope, value_params.clone()); - let depth = 0; - let use_tco = is_tco_eligible(&name, &body, registry.clone(), &si); - let needs_stacker = (is_self_recursive(&name, body.clone(), registry.clone(), si.clone()) - && (use_tco.clone() == false)); - if use_tco.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 v2_rt::concat(v2_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, si.clone()); +let params_str = emit_params(value_params.clone(), shared_types.clone(), si.clone(), emit_info.read_only_params.clone()); +let ret_str = emit_inferred(inferred, shared_types.clone(), si.clone()); +let body_scope = build_params_scope(&scope, value_params.clone()); +let depth = 0; +let use_tco = is_tco_eligible(&name, &body, registry.clone(), &si); +let needs_stacker = (is_self_recursive(&name, body.clone(), registry.clone(), si.clone()) && (use_tco.clone() == false)); +if use_tco.clone() { { - let tco_params_str = - emit_tco_params(value_params.clone(), shared_types.clone(), si.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(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - rust_visibility_prefix(), - kw, - ), - " ".to_string(), - ), - emit_ident( - name.clone(), - RenderTarget::Rust, - ), - ), - type_params_str, - ), - "(".to_string(), - ), - tco_params_str, - ), - ")".to_string(), - ), - ret_str, - ), - " {\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - body_str, - ), - "\n}".to_string(), - ) - } + let tco_params_str = emit_tco_params(value_params.clone(), shared_types.clone(), si.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(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), kw), " ".to_string()), emit_ident(name.clone(), RenderTarget::Rust)), type_params_str), "(".to_string()), tco_params_str), ")".to_string()), ret_str), " {\n".to_string()), make_indent((depth.clone() + 1))), body_str), "\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, - ) + 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) } - } +} } -pub fn emit_fn_def_non_tco( - name: String, - type_params_str: String, - params_str: String, - ret_str: String, - body: Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, - needs_stacker: bool, -) -> String { +pub fn emit_fn_def_non_tco(name: String, type_params_str: String, params_str: String, ret_str: String, body: Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc, needs_stacker: bool) -> String { if needs_stacker { { - let body_str = emit_typed_expr( - body, - registry, - &scope, - (depth.clone() + 2), - shared_types, - emit_info, - 1024, - ); - let kw = rust_items().func_keyword.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - rust_visibility_prefix( - ), - kw, - ), - " ".to_string(), - ), - emit_ident( - name, - RenderTarget::Rust, - ), - ), - type_params_str, - ), - "(".to_string(), - ), - params_str, - ), - ")".to_string(), - ), - ret_str, - ), - " {\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - "stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || {\n" - .to_string(), - ), - make_indent((depth.clone() + 2)), - ), - body_str, - ), - "\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - "})\n}".to_string(), - ) - } + let body_str = emit_typed_expr(body, registry, &scope, (depth.clone() + 2), shared_types, emit_info, 1024); +let kw = rust_items().func_keyword.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), kw), " ".to_string()), emit_ident(name, RenderTarget::Rust)), type_params_str), "(".to_string()), params_str), ")".to_string()), ret_str), " {\n".to_string()), make_indent((depth.clone() + 1))), "stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || {\n".to_string()), make_indent((depth.clone() + 2))), body_str), "\n".to_string()), make_indent((depth.clone() + 1))), "})\n}".to_string()) +} } else { { - let body_str = emit_typed_expr( - body, - registry, - &scope, - (depth.clone() + 1), - shared_types, - emit_info, - 1024, - ); - let kw = rust_items().func_keyword.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(rust_visibility_prefix(), kw), - " ".to_string(), - ), - emit_ident(name, RenderTarget::Rust), - ), - type_params_str, - ), - "(".to_string(), - ), - params_str, - ), - ")".to_string(), - ), - ret_str, - ), - " {\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - body_str, - ), - "\n}".to_string(), - ) - } + let body_str = emit_typed_expr(body, registry, &scope, (depth.clone() + 1), shared_types, emit_info, 1024); +let kw = rust_items().func_keyword.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), kw), " ".to_string()), emit_ident(name, RenderTarget::Rust)), type_params_str), "(".to_string()), params_str), ")".to_string()), ret_str), " {\n".to_string()), make_indent((depth.clone() + 1))), body_str), "\n}".to_string()) +} } } -pub fn emit_func_def( - name: &String, - params: &Rc>>, - inferred: Rc, - uses: &Rc>>, - body: Rc, - registry: &Rc>>, - scope: &Rc, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_func_def(name: &String, params: &Rc>>, inferred: Rc, uses: &Rc>>, body: Rc, registry: &Rc>>, scope: &Rc, shared_types: &Rc>, emit_info: &Rc) -> String { { if ((function_type_params(params.clone()).len() as i64) > 0) { - return v2_rt::concat(v2_rt::concat("compile_error!(\"emit_func_def saw type params in `".to_string(), name.clone()), "` — func/pattern/interface don't route through the generic-fn split today; the parser invariant at parse_block_body_from_prefix has changed. Plumb type_params through this path or dissolve via ParamKind/params-slot partition.\");\n".to_string()); + return v2_rt::concat(v2_rt::concat("compile_error!(\"emit_func_def saw type params in `".to_string(), name.clone()), "` — func/pattern/interface don't route through the generic-fn split today; the parser invariant at parse_block_body_from_prefix has changed. Plumb type_params through this path or dissolve via ParamKind/params-slot partition.\");\n".to_string()) } - let depth = 0; - let service_names = match lookup_item(registry.clone(), name.clone()) { - Some(info) => info.service_names.clone(), - None => Rc::new(vec![]), - }; - let params_str = emit_func_params( - params.clone(), - uses.clone(), - service_names, - shared_types.clone(), - scope.type_env.clone().source_indices.clone(), - emit_info.read_only_params.clone(), - ); - let ret_str = emit_func_inferred( - inferred, - shared_types.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let body_scope = build_params_scope(&scope, params.clone()); - let si = scope.type_env.clone().source_indices.clone(); - let body_scope = uses.clone().iter().cloned().fold( - body_scope.clone(), - |s: Rc, u: Rc| { - extend_scope( - &s, - &resource_use_name_at(u.clone(), si.clone()), - resource_use_resource(&u), - Rc::new(SubValueRelation::SubValueUnknown), - ) - }, - ); - let body_str = emit_func_body( - &body, - ®istry, - &body_scope, - (depth.clone() + 1), - &shared_types, - &emit_info, - ); - let items = rust_items(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - rust_visibility_prefix(), - items.async_prefix.clone(), - ), - items.func_keyword.clone(), - ), - " ".to_string(), - ), - emit_ident(name.clone(), RenderTarget::Rust), - ), - "(".to_string(), - ), - params_str, - ), - ")".to_string(), - ), - ret_str, - ), - " {\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - body_str, - ), - "\n}".to_string(), - ) - } +let depth = 0; +let service_names = match lookup_item(registry.clone(), name.clone()) { + Some(info) => info.service_names.clone(), + None => Rc::new(vec![]), +}; +let params_str = emit_func_params(params.clone(), uses.clone(), service_names, shared_types.clone(), scope.type_env.clone().source_indices.clone(), emit_info.read_only_params.clone()); +let ret_str = emit_func_inferred(inferred, shared_types.clone(), scope.type_env.clone().source_indices.clone()); +let body_scope = build_params_scope(&scope, params.clone()); +let si = scope.type_env.clone().source_indices.clone(); +let body_scope = uses.clone().iter().cloned().fold(body_scope.clone(), |s: Rc, u: Rc| extend_scope(&s, &resource_use_name_at(u.clone(), si.clone()), resource_use_resource(&u), Rc::new(SubValueRelation::SubValueUnknown))); +let body_str = emit_func_body(&body, ®istry, &body_scope, (depth.clone() + 1), &shared_types, &emit_info); +let items = rust_items(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), items.async_prefix.clone()), items.func_keyword.clone()), " ".to_string()), emit_ident(name.clone(), RenderTarget::Rust)), "(".to_string()), params_str), ")".to_string()), ret_str), " {\n".to_string()), make_indent((depth.clone() + 1))), body_str), "\n}".to_string()) +} } -pub fn emit_func_body( - body: &Rc, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_func_body(body: &Rc, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let si = scope.type_env.clone().source_indices.clone(); - match (*body.expr_data.clone()).clone() { - ExprData::ExprLet => { + { + let si = scope.type_env.clone().source_indices.clone(); +match (*body.expr_data.clone()).clone() { + ExprData::ExprLet => { let n = let_binding_name_at(body.clone(), si); - let v = let_value(body.clone()); - let inner = let_body(body.clone()); - let val_str = emit_typed_expr( - v.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let let_line = emit_let_binding(n.clone(), val_str, &RenderTarget::Rust); - let next_scope = extend_scope( - &scope, - &n, - resolved_type(v.clone()), - Rc::new(SubValueRelation::SubValueUnknown), - ); - match inner { - Some(bd) => v2_rt::concat( - v2_rt::concat(let_line, "\n".to_string()), - emit_func_body( - &bd, - ®istry, - &next_scope, - depth.clone(), - &shared_types, - &emit_info, - ), - ), - None => let_line, - } - } - ExprData::ExprBlock => { +let v = let_value(body.clone()); +let inner = let_body(body.clone()); +let val_str = emit_typed_expr(v.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let let_line = emit_let_binding(n.clone(), val_str, &RenderTarget::Rust); +let next_scope = extend_scope(&scope, &n, resolved_type(v.clone()), Rc::new(SubValueRelation::SubValueUnknown)); +match inner { + Some(bd) => v2_rt::concat(v2_rt::concat(let_line, "\n".to_string()), emit_func_body(&bd, ®istry, &next_scope, depth.clone(), &shared_types, &emit_info)), + None => let_line, +} +}, + ExprData::ExprBlock => { let ss = body.children.clone(); - if ((ss.clone().len() as i64) == 0) { +if ((ss.clone().len() as i64) == 0) { "Ok(())".to_string() } else { { - let init_state = emit_rust_init_block_stmts( - ss.clone(), - Rc::new(vec![]), - scope.clone(), - registry.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - let last_stmt = ss.clone().last().cloned(); - let last_str = match last_stmt { - Some(s) => match (*s.expr_data.clone()).clone() { - ExprData::ExprReturn => v2_rt::concat( - v2_rt::concat( - "return Ok(".to_string(), - emit_typed_expr( - return_value(s.clone()), - registry.clone(), - &init_state.scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - ), - ")".to_string(), - ), - _ => v2_rt::concat( - v2_rt::concat( - "Ok(".to_string(), - emit_typed_expr( - s.clone(), - registry.clone(), - &init_state.scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - ), - ")".to_string(), - ), - }, - None => "Ok(())".to_string(), - }; - if ((init_state.text.clone().len() as i64) == 0) { + let init_state = emit_rust_init_block_stmts(ss.clone(), Rc::new(vec![]), scope.clone(), registry.clone(), depth.clone(), shared_types.clone(), emit_info.clone()); +let last_stmt = ss.clone().last().cloned(); +let last_str = match last_stmt { + Some(s) => match (*s.expr_data.clone()).clone() { + ExprData::ExprReturn => v2_rt::concat(v2_rt::concat("return Ok(".to_string(), emit_typed_expr(return_value(s.clone()), registry.clone(), &init_state.scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone(), 1024)), ")".to_string()), + _ => v2_rt::concat(v2_rt::concat("Ok(".to_string(), emit_typed_expr(s.clone(), registry.clone(), &init_state.scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone(), 1024)), ")".to_string()), +}, + None => "Ok(())".to_string(), +}; +if ((init_state.text.clone().len() as i64) == 0) { last_str } else { - v2_rt::concat( - v2_rt::concat( - init_state.text.clone().join(&"\n".to_string()), - "\n".to_string(), - ), - last_str, - ) + v2_rt::concat(v2_rt::concat(init_state.text.clone().join(&"\n".to_string()), "\n".to_string()), last_str) } - } +} } - } - ExprData::ExprReturn => v2_rt::concat( - v2_rt::concat( - "return Ok(".to_string(), - emit_typed_expr( - return_value(body.clone()), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - ), - ")".to_string(), - ), - _ => v2_rt::concat( - v2_rt::concat( - "Ok(".to_string(), - emit_typed_expr( - body.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - ), - ")".to_string(), - ), - } +}, + ExprData::ExprReturn => v2_rt::concat(v2_rt::concat("return Ok(".to_string(), emit_typed_expr(return_value(body.clone()), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024)), ")".to_string()), + _ => v2_rt::concat(v2_rt::concat("Ok(".to_string(), emit_typed_expr(body.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024)), ")".to_string()), +} +} }) } -pub fn emit_tco_params( - params: Rc>>, - shared_types: Rc>, - source_indices: Rc>>, -) -> String { +pub fn emit_tco_params(params: Rc>>, shared_types: Rc>, source_indices: Rc>>) -> String { { - let strs = Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - __result.push(emit_tco_param(&p, shared_types.clone(), &source_indices)); - } - __result - }); - strs.join(&", ".to_string()) - } + let strs = Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { __result.push(emit_tco_param(&p, shared_types.clone(), &source_indices)); } __result }); +strs.join(&", ".to_string()) +} } -pub fn emit_tco_param( - param: &Rc, - shared_types: Rc>, - source_indices: &Rc>>, -) -> String { +pub fn emit_tco_param(param: &Rc, shared_types: Rc>, source_indices: &Rc>>) -> String { { let n = param_node_type_expr(¶m); - let ty = emit_rust_param_type(&n, &shared_types, &source_indices); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "mut ".to_string(), - emit_ident( - param_node_name_at(param.clone(), source_indices.clone()), - RenderTarget::Rust, - ), - ), - rust_items().param_type_sep.clone(), - ), - ty, - ) - } +let ty = emit_rust_param_type(&n, &shared_types, &source_indices); +v2_rt::concat(v2_rt::concat(v2_rt::concat("mut ".to_string(), emit_ident(param_node_name_at(param.clone(), source_indices.clone()), RenderTarget::Rust)), rust_items().param_type_sep.clone()), ty) +} } -pub fn emit_func_params( - params: Rc>>, - uses: Rc>>, - service_names: Rc>, - shared_types: Rc>, - source_indices: Rc>>, - read_only_params: Rc>, -) -> String { - { - let param_strs = Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - __result.push(emit_param( - &p, - shared_types.clone(), - &source_indices, - read_only_params.clone(), - )); - } - __result - }); - let resource_strs = Rc::new({ - let mut __result = Vec::new(); - for u in uses.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - resource_use_name_at(u.clone(), source_indices.clone()), - RenderTarget::Rust, - ), - ": &".to_string(), - ), - render_rust_type( - resource_use_resource(&u), - shared_types.clone(), - source_indices.clone(), - ), - )); - } - __result - }); - let service_strs = Rc::new({ - let mut __result = Vec::new(); - for sn in service_names.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat(service_var_name(sn.clone()), ": &".to_string()), - sanitize_service_name(sn.clone()), - )); - } - __result - }); - let all_params = v2_rt::concat(v2_rt::concat(param_strs, resource_strs), service_strs); - all_params.join(&", ".to_string()) - } +pub fn emit_func_params(params: Rc>>, uses: Rc>>, service_names: Rc>, shared_types: Rc>, source_indices: Rc>>, read_only_params: Rc>) -> String { + { + let param_strs = Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { __result.push(emit_param(&p, shared_types.clone(), &source_indices, read_only_params.clone())); } __result }); +let resource_strs = Rc::new({ let mut __result = Vec::new(); for u in uses.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(resource_use_name_at(u.clone(), source_indices.clone()), RenderTarget::Rust), ": &".to_string()), render_rust_type(resource_use_resource(&u), shared_types.clone(), source_indices.clone()))); } __result }); +let service_strs = Rc::new({ let mut __result = Vec::new(); for sn in service_names.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(service_var_name(sn.clone()), ": &".to_string()), sanitize_service_name(sn.clone()))); } __result }); +let all_params = v2_rt::concat(v2_rt::concat(param_strs, resource_strs), service_strs); +all_params.join(&", ".to_string()) +} } -pub fn emit_func_inferred( - inferred: Rc, - shared_types: Rc>, - source_indices: Rc>>, -) -> String { - v2_rt::concat( - v2_rt::concat( - " -> Result<".to_string(), - render_rust_type(inferred, shared_types, source_indices), - ), - ", Box>".to_string(), - ) -} - -pub fn emit_params( - params: Rc>>, - shared_types: Rc>, - source_indices: Rc>>, - read_only_params: Rc>, -) -> String { - { - let strs = Rc::new({ - let mut __result = Vec::new(); - for p in params.iter().cloned() { - __result.push(emit_param( - &p, - shared_types.clone(), - &source_indices, - read_only_params.clone(), - )); - } - __result - }); - strs.join(&", ".to_string()) - } +pub fn emit_func_inferred(inferred: Rc, shared_types: Rc>, source_indices: Rc>>) -> String { + v2_rt::concat(v2_rt::concat(" -> Result<".to_string(), render_rust_type(inferred, shared_types, source_indices)), ", Box>".to_string()) +} + +pub fn emit_params(params: Rc>>, shared_types: Rc>, source_indices: Rc>>, read_only_params: Rc>) -> String { + { + let strs = Rc::new({ let mut __result = Vec::new(); for p in params.iter().cloned() { __result.push(emit_param(&p, shared_types.clone(), &source_indices, read_only_params.clone())); } __result }); +strs.join(&", ".to_string()) +} } -pub fn emit_rust_param_type( - n: &Rc, - shared_types: &Rc>, - source_indices: &Rc>>, -) -> String { +pub fn emit_rust_param_type(n: &Rc, shared_types: &Rc>, source_indices: &Rc>>) -> String { if ((n.params.clone().len() as i64) > 0) { { - let param_types = Rc::new({ - let mut __result = Vec::new(); - for p in n.params.clone().iter().cloned() { - __result.push(render_rust_type( - param_node_type_expr(&p), - shared_types.clone(), - source_indices.clone(), - )); - } - __result - }); - let param_str = param_types.join(&", ".to_string()); - let ret_str = match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - render_rust_type(rt.clone(), shared_types.clone(), source_indices.clone()) - } - _ => "()".to_string(), - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("impl Fn(".to_string(), param_str), - ") -> ".to_string(), - ), - ret_str, - ), - " + Clone".to_string(), - ) - } + let param_types = Rc::new({ let mut __result = Vec::new(); for p in n.params.clone().iter().cloned() { __result.push(render_rust_type(param_node_type_expr(&p), shared_types.clone(), source_indices.clone())); } __result }); +let param_str = param_types.join(&", ".to_string()); +let ret_str = match n.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => render_rust_type(rt.clone(), shared_types.clone(), source_indices.clone()), + _ => "()".to_string(), +}; +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("impl Fn(".to_string(), param_str), ") -> ".to_string()), ret_str), " + Clone".to_string()) +} } else { render_rust_type(n.clone(), shared_types.clone(), source_indices.clone()) } } -pub fn emit_param( - param: &Rc, - shared_types: Rc>, - source_indices: &Rc>>, - read_only_params: Rc>, -) -> String { +pub fn emit_param(param: &Rc, shared_types: Rc>, source_indices: &Rc>>, read_only_params: Rc>) -> String { { let n = param_node_type_expr(¶m); - let ty = emit_rust_param_type(&n, &shared_types, &source_indices); - let pname = param_node_name_at(param.clone(), source_indices.clone()); - let is_callable_param = ((n.params.clone().len() as i64) > 0); - let is_borrowable = ((v2_rt::map_contains_key(&read_only_params, pname.clone()) - && (is_callable_param == false)) - && needs_reference_node(&n, source_indices.clone())); - let final_ty = if is_borrowable { - apply_type_template1( - sharing_for_target(RenderTarget::Rust) - .borrow_param_template - .clone(), - ty, - ) +let ty = emit_rust_param_type(&n, &shared_types, &source_indices); +let pname = param_node_name_at(param.clone(), source_indices.clone()); +let is_callable_param = ((n.params.clone().len() as i64) > 0); +let is_borrowable = ((v2_rt::map_contains_key(&read_only_params, pname.clone()) && (is_callable_param == false)) && needs_reference_node(&n, source_indices.clone())); +let final_ty = if is_borrowable { + apply_type_template1(sharing_for_target(RenderTarget::Rust).borrow_param_template.clone(), ty) } else { ty }; - v2_rt::concat( - v2_rt::concat( - emit_ident(pname.clone(), RenderTarget::Rust), - rust_items().param_type_sep.clone(), - ), - final_ty, - ) - } +v2_rt::concat(v2_rt::concat(emit_ident(pname.clone(), RenderTarget::Rust), rust_items().param_type_sep.clone()), final_ty) +} } -pub fn emit_inferred( - inferred: Rc, - shared_types: Rc>, - source_indices: Rc>>, -) -> String { - v2_rt::concat( - rust_items().return_arrow.clone(), - render_rust_type(inferred, shared_types, source_indices), - ) +pub fn emit_inferred(inferred: Rc, shared_types: Rc>, source_indices: Rc>>) -> String { + v2_rt::concat(rust_items().return_arrow.clone(), render_rust_type(inferred, shared_types, source_indices)) } -pub fn needs_reference_node( - n: &Rc, - source_indices: Rc>>, -) -> bool { - if ((n.connective.clone() != Connective::NoConnective) - || ((n.children.clone().len() as i64) > 0)) - { +pub fn needs_reference_node(n: &Rc, source_indices: Rc>>) -> bool { + if ((n.connective.clone() != Connective::NoConnective) || ((n.children.clone().len() as i64) > 0)) { true } else { { - let is_copy = (is_rust_value_type(n.clone(), source_indices) - || (is_product_type(n.clone()) && ((n.children.clone().len() as i64) == 0))); - (is_copy == false) - } + let is_copy = (is_rust_value_type(n.clone(), source_indices) || (is_product_type(n.clone()) && ((n.children.clone().len() as i64) == 0))); +(is_copy == false) +} } } pub fn is_string_lit_pattern(p: Rc) -> bool { match (*p).clone() { - MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitStr { .. } => true, - _ => false, - }, - _ => false, - } + MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitStr { .. } => true, + _ => false, +}, + _ => false, +} } -pub fn collect_pattern_string_guards( - mut pattern: Rc, - mut source_indices: Rc>>, -) -> String { +pub fn collect_pattern_string_guards(mut pattern: Rc, mut source_indices: Rc>>) -> String { loop { match (*pattern).clone() { - MatchPattern::VariantPattern { - name: n, - field_bindings: fbs, - .. - } => { - if ((n.clone().as_str() == "Some".to_string().as_str()) - && ((fbs.clone().len() as i64) == 1)) + MatchPattern::VariantPattern { name: n, field_bindings: fbs, .. } => { if ((n.clone().as_str() == "Some".to_string().as_str()) && ((fbs.clone().len() as i64) == 1)) { + match fbs.clone().first().cloned() { + Some(fb) => { let fb_pat = field_binding_pattern(fb.clone()); +if is_string_lit_pattern(fb_pat.clone()) { + match (*fb_pat.clone()).clone() { + MatchPattern::LitPattern { ref value, .. } => { let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { unreachable!() }; break v2_rt::concat("__some_val == ".to_string(), emit_string_literal(s.clone(), "".to_string())); }, + _ => { break "".to_string(); }, +} +} else { { - match fbs.clone().first().cloned() { - Some(fb) => { - let fb_pat = field_binding_pattern(fb.clone()); - if is_string_lit_pattern(fb_pat.clone()) { - match (*fb_pat.clone()).clone() { - MatchPattern::LitPattern { ref value, .. } => { - let LiteralValue::LitStr { value: s, .. } = value.as_ref() - else { - unreachable!() - }; - break v2_rt::concat( - "__some_val == ".to_string(), - emit_string_literal(s.clone(), "".to_string()), - ); - } - _ => { - break "".to_string(); - } - } - } else { - { - let __tco_0 = fb_pat.clone(); - pattern = __tco_0; - continue; - } - } - } - None => { - break "".to_string(); - } - } - } else { - let str_bindings = Rc::new({ - let mut __result = Vec::new(); - for fb in fbs.clone().iter().cloned() { - if is_string_lit_pattern(field_binding_pattern(fb.clone())) { - __result.push(fb); - } - } - __result - }); - let guards = Rc::new({ - let mut __result = Vec::new(); - for fb in str_bindings.iter().cloned() { - __result.push(match (*field_binding_pattern(fb.clone())).clone() { - MatchPattern::LitPattern { ref value, .. } => { - let LiteralValue::LitStr { value: s, .. } = value.as_ref() - else { - unreachable!() - }; - v2_rt::concat( - v2_rt::concat( - emit_ident( - field_binding_name_at( - fb.clone(), - source_indices.clone(), - ), - RenderTarget::Rust, - ), - " == ".to_string(), - ), - emit_string_literal(s.clone(), "".to_string()), - ) - } - _ => "".to_string(), - }); - } - __result - }); - break guards.join(&" && ".to_string()); - } - } - _ => { - break "".to_string(); - } - } - } + let __tco_0 = fb_pat.clone(); +pattern = __tco_0; +continue; +} +} }, + None => { break "".to_string(); }, +} +} else { + let str_bindings = Rc::new({ let mut __result = Vec::new(); for fb in fbs.clone().iter().cloned() { if is_string_lit_pattern(field_binding_pattern(fb.clone())) { __result.push(fb); } } __result }); +let guards = Rc::new({ let mut __result = Vec::new(); for fb in str_bindings.iter().cloned() { __result.push(match (*field_binding_pattern(fb.clone())).clone() { + MatchPattern::LitPattern { ref value, .. } => { let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { unreachable!() }; v2_rt::concat(v2_rt::concat(emit_ident(field_binding_name_at(fb.clone(), source_indices.clone()), RenderTarget::Rust), " == ".to_string()), emit_string_literal(s.clone(), "".to_string())) }, + _ => "".to_string(), +}); } __result }); +break guards.join(&" && ".to_string()); +} }, + _ => { break "".to_string(); }, +} +} } pub fn all_arms_are_string_lit(arms: &Rc>>) -> bool { - ({ - let mut __all = true; - for arm in arms.clone().iter().cloned() { - if !(match (*arm_pattern(arm.clone())).clone() { - MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitStr { .. } => true, - _ => false, - }, - MatchPattern::Wildcard => true, - _ => false, - }) { - __all = false; - break; - } - } - __all - } && ((arms.clone().len() as i64) > 0)) + ({ let mut __all = true; for arm in arms.clone().iter().cloned() { if !(match (*arm_pattern(arm.clone())).clone() { + MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitStr { .. } => true, + _ => false, +}, + MatchPattern::Wildcard => true, + _ => false, +}) { __all = false; break; } } __all } && ((arms.clone().len() as i64) > 0)) } pub fn has_string_lit_with_bind(arms: &Rc>>) -> bool { { - let has_lit = { - let mut __found = false; - for arm in arms.clone().iter().cloned() { - if match (*arm_pattern(arm.clone())).clone() { - MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitStr { .. } => true, - _ => false, - }, - _ => false, - } { - __found = true; - break; - } - } - __found - }; - let has_bind = { - let mut __found = false; - for arm in arms.clone().iter().cloned() { - if match (*arm_pattern(arm.clone())).clone() { - MatchPattern::Bind { .. } => true, - _ => false, - } { - __found = true; - break; - } - } - __found - }; - (has_lit && has_bind) - } + let has_lit = { let mut __found = false; for arm in arms.clone().iter().cloned() { if match (*arm_pattern(arm.clone())).clone() { + MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitStr { .. } => true, + _ => false, +}, + _ => false, +} { __found = true; break; } } __found }; +let has_bind = { let mut __found = false; for arm in arms.clone().iter().cloned() { if match (*arm_pattern(arm.clone())).clone() { + MatchPattern::Bind { .. } => true, + _ => false, +} { __found = true; break; } } __found }; +(has_lit && has_bind) +} } -pub fn emit_pattern( - pattern: Rc, - shared_types: Rc>, - scrut_type: String, - source_indices: Rc>>, - emit_info: Rc, -) -> String { +pub fn emit_pattern(pattern: Rc, shared_types: Rc>, scrut_type: String, source_indices: Rc>>, emit_info: Rc) -> String { match (*pattern).clone() { - MatchPattern::Bind { name: n, .. } => emit_ident(n.clone(), RenderTarget::Rust), - MatchPattern::LitPattern { value: v, .. } => rust_literal_for_pattern(v.clone()), - MatchPattern::VariantPattern { - name: n, - parent_enum, - field_bindings: fbs, - .. - } => emit_variant_pattern( - &n, - parent_enum.clone(), - &fbs, - shared_types, - &scrut_type, - source_indices, - &emit_info, - ), - MatchPattern::Wildcard => "_".to_string(), - } + MatchPattern::Bind { name: n, .. } => emit_ident(n.clone(), RenderTarget::Rust), + MatchPattern::LitPattern { value: v, .. } => rust_literal_for_pattern(v.clone()), + MatchPattern::VariantPattern { name: n, parent_enum, field_bindings: fbs, .. } => emit_variant_pattern(&n, parent_enum.clone(), &fbs, shared_types, &scrut_type, source_indices, &emit_info), + MatchPattern::Wildcard => "_".to_string(), +} } -pub fn pattern_parent_enum( - name: &String, - parent_enum: Option, - scrut_type: &String, - type_summaries: Rc>>, -) -> Option { +pub fn pattern_parent_enum(name: &String, parent_enum: Option, scrut_type: &String, type_summaries: Rc>>) -> Option { { - let scrut_is_known_enum = ((scrut_type.clone().as_str() != "".to_string().as_str()) - && is_enum_type_name(scrut_type.clone(), type_summaries)); - if ((name.clone().as_str() == "Some".to_string().as_str()) - || (name.clone().as_str() == "None".to_string().as_str())) - { + let scrut_is_known_enum = ((scrut_type.clone().as_str() != "".to_string().as_str()) && is_enum_type_name(scrut_type.clone(), type_summaries)); +if ((name.clone().as_str() == "Some".to_string().as_str()) || (name.clone().as_str() == "None".to_string().as_str())) { None } else { if scrut_is_known_enum { @@ -4752,201 +1843,112 @@ pub fn pattern_parent_enum( parent_enum } } - } +} } -pub fn emit_variant_pattern( - name: &String, - parent_enum: Option, - field_bindings: &Rc>>, - shared_types: Rc>, - scrut_type: &String, - source_indices: Rc>>, - emit_info: &Rc, -) -> String { +pub fn emit_variant_pattern(name: &String, parent_enum: Option, field_bindings: &Rc>>, shared_types: Rc>, scrut_type: &String, source_indices: Rc>>, emit_info: &Rc) -> String { { - let resolved_parent = if ((name.clone().as_str() == "Some".to_string().as_str()) - || (name.clone().as_str() == "None".to_string().as_str())) - { + let resolved_parent = if ((name.clone().as_str() == "Some".to_string().as_str()) || (name.clone().as_str() == "None".to_string().as_str())) { None } else { - pattern_parent_enum( - &name, - parent_enum, - &scrut_type, - emit_info.type_summaries.clone(), - ) - }; - let qualified = match resolved_parent.clone() { - Some(parent) => v2_rt::concat( - v2_rt::concat(parent.clone(), "::".to_string()), - name.clone(), - ), - None => name.clone(), + pattern_parent_enum(&name, parent_enum, &scrut_type, emit_info.type_summaries.clone()) }; - if ((name.clone().as_str() == "Some".to_string().as_str()) - && ((field_bindings.clone().len() as i64) == 1)) - { +let qualified = match resolved_parent.clone() { + Some(parent) => v2_rt::concat(v2_rt::concat(parent.clone(), "::".to_string()), name.clone()), + None => name.clone(), +}; +if ((name.clone().as_str() == "Some".to_string().as_str()) && ((field_bindings.clone().len() as i64) == 1)) { match field_bindings.clone().first().cloned() { - Some(fb) => { - let fb_pat = field_binding_pattern(fb.clone()); - if is_string_lit_pattern(fb_pat.clone()) { - "Some(ref __some_val)".to_string() - } else { - { - let inner_pat = emit_pattern( - fb_pat.clone(), - shared_types.clone(), - scrut_type.clone(), - source_indices.clone(), - emit_info.clone(), - ); - v2_rt::concat( - v2_rt::concat("Some(".to_string(), inner_pat), - ")".to_string(), - ) - } - } + Some(fb) => { + let fb_pat = field_binding_pattern(fb.clone()); +if is_string_lit_pattern(fb_pat.clone()) { + "Some(ref __some_val)".to_string() + } else { + { + let inner_pat = emit_pattern(fb_pat.clone(), shared_types.clone(), scrut_type.clone(), source_indices.clone(), emit_info.clone()); +v2_rt::concat(v2_rt::concat("Some(".to_string(), inner_pat), ")".to_string()) +} } - None => qualified.clone(), - } +}, + None => qualified.clone(), +} } else { if ((field_bindings.clone().len() as i64) == 0) { { let fielded_key = match resolved_parent.clone() { - Some(parent) => v2_rt::concat( - v2_rt::concat(parent.clone(), "::".to_string()), - name.clone(), - ), - None => name.clone(), - }; - let is_fielded = - match v2_rt::map_get(&emit_info.fielded_variants.clone(), fielded_key) { - Some(true) => true, - _ => match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - qualified.clone(), - ) { - Some(true) => true, - _ => false, - }, - }; - if is_fielded { + Some(parent) => v2_rt::concat(v2_rt::concat(parent.clone(), "::".to_string()), name.clone()), + None => name.clone(), +}; +let is_fielded = match v2_rt::map_get(&emit_info.fielded_variants.clone(), fielded_key) { + Some(true) => true, + _ => match v2_rt::map_get(&emit_info.fielded_variants.clone(), qualified.clone()) { + Some(true) => true, + _ => false, +}, +}; +if is_fielded { v2_rt::concat(qualified.clone(), " { .. }".to_string()) } else { qualified.clone() } - } +} } else { { - let effective_bindings = Rc::new({ - let mut __result = Vec::new(); - for fb in field_bindings.clone().iter().cloned() { - if match (*field_binding_pattern(fb.clone())).clone() { - MatchPattern::Wildcard => false, - _ => true, - } { - __result.push(fb); - } - } - __result - }); - if ((effective_bindings.clone().len() as i64) == 0) { + let effective_bindings = Rc::new({ let mut __result = Vec::new(); for fb in field_bindings.clone().iter().cloned() { if match (*field_binding_pattern(fb.clone())).clone() { + MatchPattern::Wildcard => false, + _ => true, +} { __result.push(fb); } } __result }); +if ((effective_bindings.clone().len() as i64) == 0) { { let fielded_key2 = match resolved_parent.clone() { - Some(parent) => v2_rt::concat( - v2_rt::concat(parent.clone(), "::".to_string()), - name.clone(), - ), - None => name.clone(), - }; - let is_fielded2 = match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - fielded_key2, - ) { - Some(true) => true, - _ => match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - qualified.clone(), - ) { - Some(true) => true, - _ => false, - }, - }; - if is_fielded2 { + Some(parent) => v2_rt::concat(v2_rt::concat(parent.clone(), "::".to_string()), name.clone()), + None => name.clone(), +}; +let is_fielded2 = match v2_rt::map_get(&emit_info.fielded_variants.clone(), fielded_key2) { + Some(true) => true, + _ => match v2_rt::map_get(&emit_info.fielded_variants.clone(), qualified.clone()) { + Some(true) => true, + _ => false, +}, +}; +if is_fielded2 { v2_rt::concat(qualified.clone(), " { .. }".to_string()) } else { qualified.clone() } - } +} } else { { - let binding_strs = Rc::new({ - let mut __result = Vec::new(); - for fb in effective_bindings.clone().iter().cloned() { - __result.push({ - let fb_name = field_binding_name_at( - fb.clone(), - source_indices.clone(), - ); - let fb_pat = field_binding_pattern(fb.clone()); - if is_string_lit_pattern(fb_pat.clone()) { - v2_rt::concat( - "ref ".to_string(), - emit_ident(fb_name.clone(), RenderTarget::Rust), - ) + let binding_strs = Rc::new({ let mut __result = Vec::new(); for fb in effective_bindings.clone().iter().cloned() { __result.push({ + let fb_name = field_binding_name_at(fb.clone(), source_indices.clone()); +let fb_pat = field_binding_pattern(fb.clone()); +if is_string_lit_pattern(fb_pat.clone()) { + v2_rt::concat("ref ".to_string(), emit_ident(fb_name.clone(), RenderTarget::Rust)) + } else { + { + let is_shorthand = match (*fb_pat.clone()).clone() { + MatchPattern::Bind { name: n, .. } => (n.clone().as_str() == fb_name.clone().as_str()), + _ => false, +}; +if is_shorthand.clone() { + emit_ident(fb_name.clone(), RenderTarget::Rust) } else { { - let is_shorthand = match (*fb_pat.clone()).clone() { - MatchPattern::Bind { name: n, .. } => { - (n.clone().as_str() - == fb_name.clone().as_str()) - } - _ => false, - }; - if is_shorthand.clone() { - emit_ident(fb_name.clone(), RenderTarget::Rust) - } else { - { - let pat_str = emit_pattern( - fb_pat.clone(), - shared_types.clone(), - "".to_string(), - source_indices.clone(), - emit_info.clone(), - ); - v2_rt::concat( - v2_rt::concat( - emit_ident( - fb_name.clone(), - RenderTarget::Rust, - ), - ": ".to_string(), - ), - pat_str.clone(), - ) - } - } - } + let pat_str = emit_pattern(fb_pat.clone(), shared_types.clone(), "".to_string(), source_indices.clone(), emit_info.clone()); +v2_rt::concat(v2_rt::concat(emit_ident(fb_name.clone(), RenderTarget::Rust), ": ".to_string()), pat_str.clone()) +} } - }); +} } - __result - }); - let bindings_str = binding_strs.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(qualified.clone(), " { ".to_string()), - bindings_str, - ), - ", .. }".to_string(), - ) - } +}); } __result }); +let bindings_str = binding_strs.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(qualified.clone(), " { ".to_string()), bindings_str), ", .. }".to_string()) +} } - } +} } } - } +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -4965,574 +1967,269 @@ pub struct RcMatchAnalysis { pub fn empty_rc_pattern_analysis() -> Rc { Rc::new(RcPatternAnalysis { - matches_rc_variant: false, - matches_option_rc_variant: false, - needs_rc_pattern: false, - ref_bound_fields: Rc::new(vec![]), - }) + matches_rc_variant: false, + matches_option_rc_variant: false, + needs_rc_pattern: false, + ref_bound_fields: Rc::new(vec![]), +}) } pub fn field_needs_rc_ref(field_name: String, rc_analysis: Rc) -> bool { - { - 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()) { - __found = true; - break; - } - } - __found - } + { 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()) { __found = true; break; } } __found } } -pub fn analyze_rc_pattern( - pattern: Rc, - scrut_type: String, - shared_types: &Rc>, - emit_info: &Rc, - source_indices: Rc>>, -) -> Rc { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*pattern).clone() { - MatchPattern::VariantPattern { - name: n, - parent_enum, - field_bindings: fbs, - .. - } => { - if ((n.clone().as_str() == "Some".to_string().as_str()) - || (n.clone().as_str() == "None".to_string().as_str())) - { - if ((fbs.clone().len() as i64) == 1) { - match fbs.clone().first().cloned() { - Some(fb) => { - let inner = analyze_rc_pattern( - field_binding_pattern(fb.clone()), - "".to_string(), - &shared_types, - &emit_info, - source_indices.clone(), - ); - Rc::new(RcPatternAnalysis { - matches_rc_variant: false, - matches_option_rc_variant: ((n.clone().as_str() - == "Some".to_string().as_str()) - && inner.matches_rc_variant.clone()), - needs_rc_pattern: inner.needs_rc_pattern.clone(), - ref_bound_fields: Rc::new(vec![]), - }) - } - None => empty_rc_pattern_analysis(), - } - } else { - empty_rc_pattern_analysis() - } +pub fn analyze_rc_pattern(pattern: Rc, scrut_type: String, shared_types: &Rc>, emit_info: &Rc, source_indices: Rc>>) -> Rc { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*pattern).clone() { + MatchPattern::VariantPattern { name: n, parent_enum, field_bindings: fbs, .. } => if ((n.clone().as_str() == "Some".to_string().as_str()) || (n.clone().as_str() == "None".to_string().as_str())) { + if ((fbs.clone().len() as i64) == 1) { + match fbs.clone().first().cloned() { + Some(fb) => { + let inner = analyze_rc_pattern(field_binding_pattern(fb.clone()), "".to_string(), &shared_types, &emit_info, source_indices.clone()); +Rc::new(RcPatternAnalysis { + matches_rc_variant: false, + matches_option_rc_variant: ((n.clone().as_str() == "Some".to_string().as_str()) && inner.matches_rc_variant.clone()), + needs_rc_pattern: inner.needs_rc_pattern.clone(), + ref_bound_fields: Rc::new(vec![]), +}) +}, + None => empty_rc_pattern_analysis(), +} } else { - { - let matches_rc_variant = match pattern_parent_enum( - &n, - parent_enum.clone(), - &scrut_type, - emit_info.type_summaries.clone(), - ) { - Some(enum_name) => emit_map_has(shared_types.clone(), enum_name.clone()), - None => false, - }; - let ref_bound_fields = Rc::new({ - let mut __result = Vec::new(); - for fb in fbs.clone().iter().cloned() { - __result.extend( - (*if analyze_rc_pattern( - field_binding_pattern(fb.clone()), - "".to_string(), - &shared_types, - &emit_info, - source_indices.clone(), - ) - .matches_rc_variant - .clone() - { - Rc::new(vec![field_binding_name_at( - fb.clone(), - source_indices.clone(), - )]) - } else { - Rc::new(vec![]) - }) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(RcPatternAnalysis { - matches_rc_variant: matches_rc_variant, - matches_option_rc_variant: false, - needs_rc_pattern: ((ref_bound_fields.clone().len() as i64) > 0), - ref_bound_fields: ref_bound_fields.clone(), - }) - } + empty_rc_pattern_analysis() } - } - _ => empty_rc_pattern_analysis(), + } else { + { + let matches_rc_variant = match pattern_parent_enum(&n, parent_enum.clone(), &scrut_type, emit_info.type_summaries.clone()) { + Some(enum_name) => emit_map_has(shared_types.clone(), enum_name.clone()), + None => false, +}; +let ref_bound_fields = Rc::new({ let mut __result = Vec::new(); for fb in fbs.clone().iter().cloned() { __result.extend((*if analyze_rc_pattern(field_binding_pattern(fb.clone()), "".to_string(), &shared_types, &emit_info, source_indices.clone()).matches_rc_variant.clone() { + Rc::new(vec![field_binding_name_at(fb.clone(), source_indices.clone())]) + } else { + Rc::new(vec![]) + }).iter().cloned()); } __result }); +Rc::new(RcPatternAnalysis { + matches_rc_variant: matches_rc_variant, + matches_option_rc_variant: false, + needs_rc_pattern: ((ref_bound_fields.clone().len() as i64) > 0), + ref_bound_fields: ref_bound_fields.clone(), +}) +} + }, + _ => empty_rc_pattern_analysis(), +} }) } -pub fn analyze_rc_match( - scrutinee: &Rc, - arms: Rc>>, - scrut_type: String, - shared_types: &Rc>, - emit_info: Rc, - source_indices: &Rc>>, -) -> RcMatchAnalysis { - { - let arm_analyses = Rc::new({ - let mut __result = Vec::new(); - for arm in arms.iter().cloned() { - __result.push(analyze_rc_pattern( - arm_pattern(arm.clone()), - scrut_type.clone(), - &shared_types, - &emit_info, - source_indices.clone(), - )); - } - __result - }); - let scrutinee_is_optional = match scrutinee.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.return_cardinality.clone() == Cardinality::CardOptional) - } - _ => false, - }; - let scrutinee_is_rc_wrapped = match scrutinee.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - if (((rt.children.clone().len() as i64) == 0) && (rt.ident_span.clone() != None)) { - emit_map_has( - shared_types.clone(), - authored_name_at(source_indices.clone(), &rt), - ) - } else { - false - } - } - _ => false, - }; - let arms_want_option = { - let mut __found = false; - for a in arm_analyses.clone().iter().cloned() { - if a.matches_option_rc_variant.clone() { - __found = true; - break; - } - } - __found - }; - let arms_want_deref = { - let mut __found = false; - for a in arm_analyses.clone().iter().cloned() { - if a.matches_rc_variant.clone() { - __found = true; - break; - } - } - __found - }; - RcMatchAnalysis { - needs_option_deref: arms_want_option, - needs_deref: if scrutinee_is_optional { - false - } else { - (scrutinee_is_rc_wrapped || arms_want_deref) - }, - } - } +pub fn analyze_rc_match(scrutinee: &Rc, arms: Rc>>, scrut_type: String, shared_types: &Rc>, emit_info: Rc, source_indices: &Rc>>) -> RcMatchAnalysis { + { + let arm_analyses = Rc::new({ let mut __result = Vec::new(); for arm in arms.iter().cloned() { __result.push(analyze_rc_pattern(arm_pattern(arm.clone()), scrut_type.clone(), &shared_types, &emit_info, source_indices.clone())); } __result }); +let scrutinee_is_optional = match scrutinee.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (rt.return_cardinality.clone() == Cardinality::CardOptional), + _ => false, +}; +let scrutinee_is_rc_wrapped = match scrutinee.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => if (((rt.children.clone().len() as i64) == 0) && (rt.ident_span.clone() != None)) { + emit_map_has(shared_types.clone(), authored_name_at(source_indices.clone(), &rt)) + } else { + false + }, + _ => false, +}; +let arms_want_option = { let mut __found = false; for a in arm_analyses.clone().iter().cloned() { if a.matches_option_rc_variant.clone() { __found = true; break; } } __found }; +let arms_want_deref = { let mut __found = false; for a in arm_analyses.clone().iter().cloned() { if a.matches_rc_variant.clone() { __found = true; break; } } __found }; +RcMatchAnalysis { + needs_option_deref: arms_want_option, + needs_deref: if scrutinee_is_optional { + false + } else { + (scrutinee_is_rc_wrapped || arms_want_deref) + }, +} +} } -pub fn emit_pattern_rc_aware( - pattern: Rc, - rc_analysis: Rc, - shared_types: Rc>, - scrut_type: String, - source_indices: Rc>>, - emit_info: Rc, -) -> String { +pub fn emit_pattern_rc_aware(pattern: Rc, rc_analysis: Rc, shared_types: Rc>, scrut_type: String, source_indices: Rc>>, emit_info: Rc) -> String { match (*pattern).clone() { - MatchPattern::Bind { name: n, .. } => emit_ident(n.clone(), RenderTarget::Rust), - MatchPattern::LitPattern { value: v, .. } => rust_literal_for_pattern(v.clone()), - MatchPattern::VariantPattern { - name: n, - parent_enum, - field_bindings: fbs, - .. - } => emit_variant_pattern_rc_aware( - &n, - parent_enum.clone(), - &fbs, - rc_analysis, - &shared_types, - &scrut_type, - &source_indices, - &emit_info, - ), - MatchPattern::Wildcard => "_".to_string(), - } + MatchPattern::Bind { name: n, .. } => emit_ident(n.clone(), RenderTarget::Rust), + MatchPattern::LitPattern { value: v, .. } => rust_literal_for_pattern(v.clone()), + MatchPattern::VariantPattern { name: n, parent_enum, field_bindings: fbs, .. } => emit_variant_pattern_rc_aware(&n, parent_enum.clone(), &fbs, rc_analysis, &shared_types, &scrut_type, &source_indices, &emit_info), + MatchPattern::Wildcard => "_".to_string(), +} } -pub fn emit_variant_pattern_rc_aware( - name: &String, - parent_enum: Option, - field_bindings: &Rc>>, - rc_analysis: Rc, - shared_types: &Rc>, - scrut_type: &String, - source_indices: &Rc>>, - emit_info: &Rc, -) -> String { +pub fn emit_variant_pattern_rc_aware(name: &String, parent_enum: Option, field_bindings: &Rc>>, rc_analysis: Rc, shared_types: &Rc>, scrut_type: &String, source_indices: &Rc>>, emit_info: &Rc) -> String { { - let resolved_parent = if ((name.clone().as_str() == "Some".to_string().as_str()) - || (name.clone().as_str() == "None".to_string().as_str())) - { + let resolved_parent = if ((name.clone().as_str() == "Some".to_string().as_str()) || (name.clone().as_str() == "None".to_string().as_str())) { None } else { - pattern_parent_enum( - &name, - parent_enum, - &scrut_type, - emit_info.type_summaries.clone(), - ) + pattern_parent_enum(&name, parent_enum, &scrut_type, emit_info.type_summaries.clone()) }; - let qualified = match resolved_parent.clone() { - Some(parent) => v2_rt::concat( - v2_rt::concat(parent.clone(), "::".to_string()), - name.clone(), - ), - None => name.clone(), - }; - if ((name.clone().as_str() == "Some".to_string().as_str()) - && ((field_bindings.clone().len() as i64) == 1)) - { +let qualified = match resolved_parent.clone() { + Some(parent) => v2_rt::concat(v2_rt::concat(parent.clone(), "::".to_string()), name.clone()), + None => name.clone(), +}; +if ((name.clone().as_str() == "Some".to_string().as_str()) && ((field_bindings.clone().len() as i64) == 1)) { match field_bindings.clone().first().cloned() { - Some(fb) => { - let fb_pat = field_binding_pattern(fb.clone()); - if is_string_lit_pattern(fb_pat.clone()) { - "Some(ref __some_val)".to_string() - } else { - { - let inner_analysis = analyze_rc_pattern( - fb_pat.clone(), - scrut_type.clone(), - &shared_types, - &emit_info, - source_indices.clone(), - ); - let inner_pat = emit_pattern_rc_aware( - fb_pat.clone(), - inner_analysis.clone(), - shared_types.clone(), - scrut_type.clone(), - source_indices.clone(), - emit_info.clone(), - ); - v2_rt::concat( - v2_rt::concat("Some(".to_string(), inner_pat), - ")".to_string(), - ) - } - } + Some(fb) => { + let fb_pat = field_binding_pattern(fb.clone()); +if is_string_lit_pattern(fb_pat.clone()) { + "Some(ref __some_val)".to_string() + } else { + { + let inner_analysis = analyze_rc_pattern(fb_pat.clone(), scrut_type.clone(), &shared_types, &emit_info, source_indices.clone()); +let inner_pat = emit_pattern_rc_aware(fb_pat.clone(), inner_analysis.clone(), shared_types.clone(), scrut_type.clone(), source_indices.clone(), emit_info.clone()); +v2_rt::concat(v2_rt::concat("Some(".to_string(), inner_pat), ")".to_string()) +} } - None => qualified.clone(), - } +}, + None => qualified.clone(), +} } else { if ((field_bindings.clone().len() as i64) == 0) { { let fielded_key = match resolved_parent.clone() { - Some(parent) => v2_rt::concat( - v2_rt::concat(parent.clone(), "::".to_string()), - name.clone(), - ), - None => name.clone(), - }; - let is_fielded = - match v2_rt::map_get(&emit_info.fielded_variants.clone(), fielded_key) { - Some(true) => true, - _ => match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - qualified.clone(), - ) { - Some(true) => true, - _ => false, - }, - }; - if is_fielded { + Some(parent) => v2_rt::concat(v2_rt::concat(parent.clone(), "::".to_string()), name.clone()), + None => name.clone(), +}; +let is_fielded = match v2_rt::map_get(&emit_info.fielded_variants.clone(), fielded_key) { + Some(true) => true, + _ => match v2_rt::map_get(&emit_info.fielded_variants.clone(), qualified.clone()) { + Some(true) => true, + _ => false, +}, +}; +if is_fielded { v2_rt::concat(qualified.clone(), " { .. }".to_string()) } else { qualified.clone() } - } +} } else { { - let effective_bindings = Rc::new({ - let mut __result = Vec::new(); - for fb in field_bindings.clone().iter().cloned() { - if match (*field_binding_pattern(fb.clone())).clone() { - MatchPattern::Wildcard => false, - _ => true, - } { - __result.push(fb); - } - } - __result - }); - if ((effective_bindings.clone().len() as i64) == 0) { + let effective_bindings = Rc::new({ let mut __result = Vec::new(); for fb in field_bindings.clone().iter().cloned() { if match (*field_binding_pattern(fb.clone())).clone() { + MatchPattern::Wildcard => false, + _ => true, +} { __result.push(fb); } } __result }); +if ((effective_bindings.clone().len() as i64) == 0) { { let fielded_key2 = match resolved_parent.clone() { - Some(parent) => v2_rt::concat( - v2_rt::concat(parent.clone(), "::".to_string()), - name.clone(), - ), - None => name.clone(), - }; - let is_fielded2 = match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - fielded_key2, - ) { - Some(true) => true, - _ => match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - qualified.clone(), - ) { - Some(true) => true, - _ => false, - }, - }; - if is_fielded2 { + Some(parent) => v2_rt::concat(v2_rt::concat(parent.clone(), "::".to_string()), name.clone()), + None => name.clone(), +}; +let is_fielded2 = match v2_rt::map_get(&emit_info.fielded_variants.clone(), fielded_key2) { + Some(true) => true, + _ => match v2_rt::map_get(&emit_info.fielded_variants.clone(), qualified.clone()) { + Some(true) => true, + _ => false, +}, +}; +if is_fielded2 { v2_rt::concat(qualified.clone(), " { .. }".to_string()) } else { qualified.clone() } - } +} } else { { - let binding_strs = Rc::new({ - let mut __result = Vec::new(); - for fb in effective_bindings.clone().iter().cloned() { - __result.push({ - let fb_name = field_binding_name_at( - fb.clone(), - source_indices.clone(), - ); - let fb_pat = field_binding_pattern(fb.clone()); - if is_string_lit_pattern(fb_pat.clone()) { - v2_rt::concat( - "ref ".to_string(), - emit_ident(fb_name.clone(), RenderTarget::Rust), - ) - } else { - if field_needs_rc_ref( - fb_name.clone(), - rc_analysis.clone(), - ) { - v2_rt::concat( - "ref ".to_string(), - emit_ident(fb_name.clone(), RenderTarget::Rust), - ) + let binding_strs = Rc::new({ let mut __result = Vec::new(); for fb in effective_bindings.clone().iter().cloned() { __result.push({ + let fb_name = field_binding_name_at(fb.clone(), source_indices.clone()); +let fb_pat = field_binding_pattern(fb.clone()); +if is_string_lit_pattern(fb_pat.clone()) { + v2_rt::concat("ref ".to_string(), emit_ident(fb_name.clone(), RenderTarget::Rust)) + } else { + if field_needs_rc_ref(fb_name.clone(), rc_analysis.clone()) { + v2_rt::concat("ref ".to_string(), emit_ident(fb_name.clone(), RenderTarget::Rust)) + } else { + { + let is_shorthand = match (*fb_pat.clone()).clone() { + MatchPattern::Bind { name: n, .. } => (n.clone().as_str() == fb_name.clone().as_str()), + _ => false, +}; +if is_shorthand.clone() { + emit_ident(fb_name.clone(), RenderTarget::Rust) } else { { - let is_shorthand = match (*fb_pat.clone()) - .clone() - { - MatchPattern::Bind { name: n, .. } => { - (n.clone().as_str() - == fb_name.clone().as_str()) - } - _ => false, - }; - if is_shorthand.clone() { - emit_ident( - fb_name.clone(), - RenderTarget::Rust, - ) - } else { - { - let inner_analysis = analyze_rc_pattern( - fb_pat.clone(), - "".to_string(), - &shared_types, - &emit_info, - source_indices.clone(), - ); - let pat_str = emit_pattern_rc_aware( - fb_pat.clone(), - inner_analysis.clone(), - shared_types.clone(), - "".to_string(), - source_indices.clone(), - emit_info.clone(), - ); - v2_rt::concat( - v2_rt::concat( - emit_ident( - fb_name.clone(), - RenderTarget::Rust, - ), - ": ".to_string(), - ), - pat_str.clone(), - ) - } - } - } + let inner_analysis = analyze_rc_pattern(fb_pat.clone(), "".to_string(), &shared_types, &emit_info, source_indices.clone()); +let pat_str = emit_pattern_rc_aware(fb_pat.clone(), inner_analysis.clone(), shared_types.clone(), "".to_string(), source_indices.clone(), emit_info.clone()); +v2_rt::concat(v2_rt::concat(emit_ident(fb_name.clone(), RenderTarget::Rust), ": ".to_string()), pat_str.clone()) +} } - } - }); +} + } } - __result - }); - let bindings_str = binding_strs.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(qualified.clone(), " { ".to_string()), - bindings_str, - ), - ", .. }".to_string(), - ) - } +}); } __result }); +let bindings_str = binding_strs.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(qualified.clone(), " { ".to_string()), bindings_str), ", .. }".to_string()) +} } - } +} } } - } +} } -pub fn rc_pattern_preludes( - mut pattern: Rc, - mut rc_analysis: Rc, - mut shared_types: Rc>, - mut source_indices: Rc>>, - mut emit_info: Rc, -) -> String { +pub fn rc_pattern_preludes(mut pattern: Rc, mut rc_analysis: Rc, mut shared_types: Rc>, mut source_indices: Rc>>, mut emit_info: Rc) -> String { loop { match (*pattern).clone() { - MatchPattern::VariantPattern { - name: n, - field_bindings: fbs, - .. - } => { - if ((n.clone().as_str() == "Some".to_string().as_str()) - || (n.clone().as_str() == "None".to_string().as_str())) - { - if ((fbs.clone().len() as i64) == 1) { - match fbs.clone().first().cloned() { - Some(fb) => { - let fb_pat = field_binding_pattern(fb.clone()); - let inner_analysis = analyze_rc_pattern( - fb_pat.clone(), - "".to_string(), - &shared_types, - &emit_info, - source_indices.clone(), - ); - { - let __tco_0 = fb_pat.clone(); - let __tco_1 = inner_analysis; - pattern = __tco_0; - rc_analysis = __tco_1; - continue; - } - } - None => { - break "".to_string(); - } - } - } else { - break "".to_string(); - } - } else { - let preludes = Rc::new({ - let mut __result = Vec::new(); - for fb in fbs.clone().iter().cloned() { - __result.extend( - (*if field_needs_rc_ref( - field_binding_name_at(fb.clone(), source_indices.clone()), - rc_analysis.clone(), - ) { - Rc::new(vec![v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "let ".to_string(), - emit_pattern( - field_binding_pattern(fb.clone()), - shared_types.clone(), - "".to_string(), - source_indices.clone(), - emit_info.clone(), - ), - ), - " = ".to_string(), - ), - emit_ident( - field_binding_name_at( - fb.clone(), - source_indices.clone(), - ), - RenderTarget::Rust, - ), - ), - ".as_ref() else { unreachable!() };".to_string(), - )]) - } else { - Rc::new(vec![]) - }) - .iter() - .cloned(), - ); - } - __result - }); - break preludes.join(&" ".to_string()); - } - } - _ => { + MatchPattern::VariantPattern { name: n, field_bindings: fbs, .. } => { if ((n.clone().as_str() == "Some".to_string().as_str()) || (n.clone().as_str() == "None".to_string().as_str())) { + if ((fbs.clone().len() as i64) == 1) { + match fbs.clone().first().cloned() { + Some(fb) => { let fb_pat = field_binding_pattern(fb.clone()); +let inner_analysis = analyze_rc_pattern(fb_pat.clone(), "".to_string(), &shared_types, &emit_info, source_indices.clone()); +{ + let __tco_0 = fb_pat.clone(); +let __tco_1 = inner_analysis; +pattern = __tco_0; +rc_analysis = __tco_1; +continue; +} }, + None => { break "".to_string(); }, +} +} else { break "".to_string(); - } - } - } +} +} else { + let preludes = Rc::new({ let mut __result = Vec::new(); for fb in fbs.clone().iter().cloned() { __result.extend((*if field_needs_rc_ref(field_binding_name_at(fb.clone(), source_indices.clone()), rc_analysis.clone()) { + Rc::new(vec![v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let ".to_string(), emit_pattern(field_binding_pattern(fb.clone()), shared_types.clone(), "".to_string(), source_indices.clone(), emit_info.clone())), " = ".to_string()), emit_ident(field_binding_name_at(fb.clone(), source_indices.clone()), RenderTarget::Rust)), ".as_ref() else { unreachable!() };".to_string())]) + } else { + Rc::new(vec![]) + }).iter().cloned()); } __result }); +break preludes.join(&" ".to_string()); +} }, + _ => { break "".to_string(); }, +} +} } -pub fn explicit_record_struct_name( - type_name: Option, - inferred_node: &Rc, - shared_types: Rc>, - source_indices: Rc>>, -) -> Option { +pub fn explicit_record_struct_name(type_name: Option, inferred_node: &Rc, shared_types: Rc>, source_indices: Rc>>) -> Option { { let is_optional = (inferred_node.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { +if is_optional { { let result = type_name.clone(); - return result; - } +return result +} } - let has_structure = (inferred_node.connective.clone() != Connective::NoConnective); - let n = if ((inferred_node.type_annotation.clone() != None) && has_structure) { +let has_structure = (inferred_node.connective.clone() != Connective::NoConnective); +let n = if ((inferred_node.type_annotation.clone() != None) && has_structure) { match inferred_node.children.clone().first().cloned() { - Some(base) => base.clone(), - None => inferred_node.clone(), - } + Some(base) => base.clone(), + None => inferred_node.clone(), +} } else { inferred_node.clone() }; - let is_product = is_product_type(n.clone()); - let is_coproduct = is_coproduct_type(n.clone()); - let n_is_error = if (n.inferred.clone() != None) { +let is_product = is_product_type(n.clone()); +let is_coproduct = is_coproduct_type(n.clone()); +let n_is_error = if (n.inferred.clone() != None) { is_compiler_error(n.inferred.clone().clone().unwrap()) } else { false }; - let nname = authored_name_at(source_indices, &n); - if (nname.clone().as_str() == "__EmitTypeCacheMiss".to_string().as_str()) { +let nname = authored_name_at(source_indices, &n); +if (nname.clone().as_str() == "__EmitTypeCacheMiss".to_string().as_str()) { type_name.clone() } else { if n_is_error { @@ -5548,9 +2245,7 @@ pub fn explicit_record_struct_name( if is_coproduct { type_name.clone() } else { - if (((n.children.clone().len() as i64) == 0) - && (n.ident_span.clone() != None)) - { + if (((n.children.clone().len() as i64) == 0) && (n.ident_span.clone() != None)) { Some(nname.clone()) } else { type_name.clone() @@ -5559,502 +2254,293 @@ pub fn explicit_record_struct_name( } } } - } +} } -pub fn is_simple_type_node( - n: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_simple_type_node(n: Rc, source_indices: Rc>>) -> bool { is_rust_value_type(n, source_indices) } -pub fn variant_parent_from_binding_kind( - binding_kind: Option>, -) -> Option { +pub fn variant_parent_from_binding_kind(binding_kind: Option>) -> Option { match binding_kind.as_deref().cloned() { - Some(VarBindingKind::VariantValueBinding { parent_enum, .. }) => Some(parent_enum.clone()), - _ => None, - } + Some(VarBindingKind::VariantValueBinding { parent_enum, .. }) => Some(parent_enum.clone()), + _ => None, +} } pub fn apply_clone(expr: String) -> String { - apply_type_template1( - sharing_for_target(RenderTarget::Rust).clone_value.clone(), - expr, - ) + 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, - ) + 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, - ) + 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( - name: &String, - binding_kind: Option>, - resolved_type: Option>, - emit_info: &Rc, - source_indices: Rc>>, -) -> Option { +pub fn effective_variant_parent(name: &String, binding_kind: Option>, resolved_type: Option>, emit_info: &Rc, source_indices: Rc>>) -> Option { { let cached = match v2_rt::map_get(&emit_info.variant_to_enum.clone(), name.clone()) { - Some(p) => { - if (p.clone().as_str() != "".to_string().as_str()) { - Some(p.clone()) - } else { - None - } + Some(p) => if (p.clone().as_str() != "".to_string().as_str()) { + Some(p.clone()) + } else { + None + }, + None => None, +}; +match cached { + Some(parent) => Some(parent.clone()), + None => match resolved_type.as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => { + let rt_name = authored_name_at(source_indices, &rt); +if (((rt.ident_span.clone() != None) && (rt_name.clone().as_str() != name.clone().as_str())) && variant_belongs_to_enum(emit_info.type_summaries.clone(), name.clone(), rt_name.clone())) { + Some(rt_name.clone()) + } else { + variant_parent_from_binding_kind(binding_kind) } - None => None, - }; - match cached { - Some(parent) => Some(parent.clone()), - None => match resolved_type.as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - let rt_name = authored_name_at(source_indices, &rt); - if (((rt.ident_span.clone() != None) - && (rt_name.clone().as_str() != name.clone().as_str())) - && variant_belongs_to_enum( - emit_info.type_summaries.clone(), - name.clone(), - rt_name.clone(), - )) - { - Some(rt_name.clone()) - } else { - variant_parent_from_binding_kind(binding_kind) - } - } - _ => variant_parent_from_binding_kind(binding_kind), - }, - } - } +}, + _ => variant_parent_from_binding_kind(binding_kind), +}, +} +} } -pub fn emit_var_ref( - name: &String, - binding_kind: &Option>, - resolved_type: &Option>, - shared_types: Rc>, - registry: Rc>>, - 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())) - { +pub fn emit_var_ref(name: &String, binding_kind: &Option>, resolved_type: &Option>, shared_types: Rc>, registry: Rc>>, 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())) { 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().as_str() == "true".to_string().as_str()) || (name.clone().as_str() == "false".to_string().as_str())) { emit_keyword(name.clone(), RenderTarget::Rust) } else { { let moves_by_value = emit_map_has(emit_info.movable.clone(), name.clone()); - let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - let variant_parent = effective_variant_parent( - &name, - binding_kind.clone(), - resolved_type.clone(), - &emit_info, - source_indices, - ); - let ref_str = match variant_parent { - Some(enum_name) => { - let qualified = v2_rt::concat( - v2_rt::concat(enum_name.clone(), "::".to_string()), - name.clone(), - ); - if emit_map_has(shared_types, enum_name.clone()) { - v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), qualified), - ")".to_string(), - ) - } else { - qualified - } +let sharing = language_spec(RenderTarget::Rust).sharing.clone(); +let variant_parent = effective_variant_parent(&name, binding_kind.clone(), resolved_type.clone(), &emit_info, source_indices); +let ref_str = match variant_parent { + Some(enum_name) => { + let qualified = v2_rt::concat(v2_rt::concat(enum_name.clone(), "::".to_string()), name.clone()); +if emit_map_has(shared_types, enum_name.clone()) { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), qualified), ")".to_string()) + } else { + qualified } - None => match v2_rt::map_get(®istry, name.clone()) { - Some(info) => { - let is_data = (info.kind.clone() == ItemKind::DataItem); - if is_data { - v2_rt::concat(to_snake(name.clone()), "()".to_string()) +}, + None => match v2_rt::map_get(®istry, name.clone()) { + Some(info) => { + let is_data = (info.kind.clone() == ItemKind::DataItem); +if is_data { + v2_rt::concat(to_snake(name.clone()), "()".to_string()) + } else { + { + let is_function_value = match binding_kind.clone().as_deref().cloned() { + Some(VarBindingKind::FunctionValueBinding) => true, + _ => false, +}; +let ident = emit_ident(name.clone(), RenderTarget::Rust); +let ident_str = if is_function_value { + ident } else { - { - let is_function_value = - match binding_kind.clone().as_deref().cloned() { - Some(VarBindingKind::FunctionValueBinding) => true, - _ => false, - }; - let ident = emit_ident(name.clone(), RenderTarget::Rust); - let ident_str = if is_function_value { - ident - } else { - if moves_by_value { - ident - } else { - match resolved_type.clone() { - Some(_) => apply_type_template1( - sharing.clone_value.clone(), - ident, - ), - _ => ident, - } - } - }; - ident_str - } - } - } - None => { - let ident = emit_ident(name.clone(), RenderTarget::Rust); - let ident_str = if moves_by_value { - ident - } else { - match resolved_type.clone() { - Some(_) => { - apply_type_template1(sharing.clone_value.clone(), ident) - } - _ => ident, + if moves_by_value { + ident + } else { + match resolved_type.clone() { + Some(_) => apply_type_template1(sharing.clone_value.clone(), ident), + _ => ident, +} } }; - ident_str - } - }, - }; - ref_str - } +ident_str +} + } +}, + None => { + let ident = emit_ident(name.clone(), RenderTarget::Rust); +let ident_str = if moves_by_value { + ident + } else { + match resolved_type.clone() { + Some(_) => apply_type_template1(sharing.clone_value.clone(), ident), + _ => ident, +} + }; +ident_str +}, +}, +}; +ref_str +} } } } -pub fn emit_typed_expr_base( - texpr: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_typed_expr_base(texpr: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { { let si = scope.type_env.clone().source_indices.clone(); - match (*texpr.expr_data.clone()).clone() { - ExprData::ExprVar { binding_kind, .. } => { - 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())) - { - emit_keyword("null".to_string(), RenderTarget::Rust) +match (*texpr.expr_data.clone()).clone() { + ExprData::ExprVar { binding_kind, .. } => { + 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())) { + 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())) { + emit_keyword(n.clone(), RenderTarget::Rust) } else { - if ((n.clone().as_str() == "true".to_string().as_str()) - || (n.clone().as_str() == "false".to_string().as_str())) { - emit_keyword(n.clone(), RenderTarget::Rust) - } else { - { - let variant_parent = effective_variant_parent( - &n, - binding_kind.clone(), - texpr.inferred.clone(), - &emit_info, - si.clone(), - ); - match variant_parent { - Some(enum_name) => { - let qualified = v2_rt::concat( - v2_rt::concat(enum_name.clone(), "::".to_string()), - n.clone(), - ); - if emit_map_has(shared_types, enum_name.clone()) { - v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), qualified), - ")".to_string(), - ) - } else { - qualified - } - } - None => match v2_rt::map_get(®istry, n.clone()) { - Some(info) => { - let is_data = (info.kind.clone() == ItemKind::DataItem); - if is_data { - v2_rt::concat(to_snake(n.clone()), "()".to_string()) - } else { - emit_ident(n.clone(), RenderTarget::Rust) - } - } - None => emit_ident(n.clone(), RenderTarget::Rust), - }, + let variant_parent = effective_variant_parent(&n, binding_kind.clone(), texpr.inferred.clone(), &emit_info, si.clone()); +match variant_parent { + Some(enum_name) => { + let qualified = v2_rt::concat(v2_rt::concat(enum_name.clone(), "::".to_string()), n.clone()); +if emit_map_has(shared_types, enum_name.clone()) { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), qualified), ")".to_string()) + } else { + qualified } - } - } +}, + None => match v2_rt::map_get(®istry, n.clone()) { + Some(info) => { + let is_data = (info.kind.clone() == ItemKind::DataItem); +if is_data { + v2_rt::concat(to_snake(n.clone()), "()".to_string()) + } else { + emit_ident(n.clone(), RenderTarget::Rust) + } +}, + None => emit_ident(n.clone(), RenderTarget::Rust), +}, +} +} } } - _ => emit_typed_expr( - texpr.clone(), - registry, - &scope, - depth, - shared_types, - emit_info, - 1024, - ), - } - } +}, + _ => emit_typed_expr(texpr.clone(), registry, &scope, depth, shared_types, emit_info, 1024), +} +} } -pub fn emit_typed_field_access( - base: &Rc, - field: &String, - summary: Option>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let base_str = emit_typed_expr_base( - &base, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - let base_is_anon_record = match base.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: bt, .. }) => { - let is_product = is_product_type(bt.clone()); - if (is_product && (bt.ident_span.clone() == None)) { - true - } else { - false - } +pub fn emit_typed_field_access(base: &Rc, field: &String, summary: Option>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let base_str = emit_typed_expr_base(&base, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone()); +let base_is_anon_record = match base.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: bt, .. }) => { + let is_product = is_product_type(bt.clone()); +if (is_product && (bt.ident_span.clone() == None)) { + true + } else { + false } - _ => false, - }; - if base_is_anon_record { +}, + _ => false, +}; +if base_is_anon_record { { let bt = resolved_type(base.clone()); - if ((bt.children.clone().len() as i64) == 1) { - emit_typed_expr( - base.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ) +if ((bt.children.clone().len() as i64) == 1) { + emit_typed_expr(base.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024) } else { { - let matches = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - bt.children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (authored_name_at( - scope.type_env.clone().source_indices.clone(), - &pair.1.clone(), - ) - .as_str() - == field.clone().as_str()) - { - __result.push(pair); - } - } - __result - }); - match matches.first().cloned() { - Some(m) => { - let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - apply_type_template1( - sharing.clone_value.clone(), - v2_rt::concat( - v2_rt::concat(base_str, ".".to_string()), - (m.0.clone()).to_string(), - ), - ) - } - None => v2_rt::concat( - v2_rt::concat( - "compile_error!(\"anonymous record field not found: " - .to_string(), - field.clone(), - ), - "\")".to_string(), - ), - } - } + let matches = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(bt.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (authored_name_at(scope.type_env.clone().source_indices.clone(), &pair.1.clone()).as_str() == field.clone().as_str()) { __result.push(pair); } } __result }); +match matches.first().cloned() { + Some(m) => { + let sharing = language_spec(RenderTarget::Rust).sharing.clone(); +apply_type_template1(sharing.clone_value.clone(), v2_rt::concat(v2_rt::concat(base_str, ".".to_string()), (m.0.clone()).to_string())) +}, + None => v2_rt::concat(v2_rt::concat("compile_error!(\"anonymous record field not found: ".to_string(), field.clone()), "\")".to_string()), +} +} } - } +} } else { { let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - match summary { - Some(field_summary) => match field_summary.access_style.clone() { - FieldAccessStyle::TupleFirst => apply_type_template1( - sharing.clone_value.clone(), - v2_rt::concat(base_str, ".0".to_string()), - ), - FieldAccessStyle::TupleSecond => apply_type_template1( - sharing.clone_value.clone(), - v2_rt::concat(base_str, ".1".to_string()), - ), - FieldAccessStyle::OptionalUnwrap => v2_rt::concat( - apply_type_template1(sharing.clone_value.clone(), base_str), - ".unwrap()".to_string(), - ), - FieldAccessStyle::EnumAccessor => v2_rt::concat( - v2_rt::concat( - v2_rt::concat(base_str, ".".to_string()), - emit_ident(field.clone(), RenderTarget::Rust), - ), - "()".to_string(), - ), - FieldAccessStyle::StoredField => { - let base_is_owned = match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let base_name = expr_var_name_at( - base.clone(), - scope.type_env.clone().source_indices.clone(), - ); - emit_map_has(emit_info.owned_bindings.clone(), base_name) - } - _ => false, - }; - if base_is_owned { - v2_rt::concat( - v2_rt::concat(base_str, ".".to_string()), - emit_ident(field.clone(), RenderTarget::Rust), - ) - } else { - apply_type_template1( - sharing.clone_value.clone(), - v2_rt::concat( - v2_rt::concat(base_str, ".".to_string()), - emit_ident(field.clone(), RenderTarget::Rust), - ), - ) - } - } - }, - None => v2_rt::concat( - v2_rt::concat( - "compile_error!(\"field access missing reconcile summary for '" - .to_string(), - field.clone(), - ), - "'\")".to_string(), - ), - } - } +match summary { + Some(field_summary) => match field_summary.access_style.clone() { + FieldAccessStyle::TupleFirst => apply_type_template1(sharing.clone_value.clone(), v2_rt::concat(base_str, ".0".to_string())), + FieldAccessStyle::TupleSecond => apply_type_template1(sharing.clone_value.clone(), v2_rt::concat(base_str, ".1".to_string())), + FieldAccessStyle::OptionalUnwrap => v2_rt::concat(apply_type_template1(sharing.clone_value.clone(), base_str), ".unwrap()".to_string()), + FieldAccessStyle::EnumAccessor => v2_rt::concat(v2_rt::concat(v2_rt::concat(base_str, ".".to_string()), emit_ident(field.clone(), RenderTarget::Rust)), "()".to_string()), + FieldAccessStyle::StoredField => { + let base_is_owned = match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let base_name = expr_var_name_at(base.clone(), scope.type_env.clone().source_indices.clone()); +emit_map_has(emit_info.owned_bindings.clone(), base_name) +}, + _ => false, +}; +if base_is_owned { + v2_rt::concat(v2_rt::concat(base_str, ".".to_string()), emit_ident(field.clone(), RenderTarget::Rust)) + } else { + apply_type_template1(sharing.clone_value.clone(), v2_rt::concat(v2_rt::concat(base_str, ".".to_string()), emit_ident(field.clone(), RenderTarget::Rust))) + } +}, +}, + None => v2_rt::concat(v2_rt::concat("compile_error!(\"field access missing reconcile summary for '".to_string(), field.clone()), "'\")".to_string()), +} +} } - } +} } -pub fn type_needs_rc( - type_node: Rc, - source_indices: Rc>>, -) -> bool { - type_needs_rc_seen( - type_node, - v2_rt::rc_empty_map::(), - source_indices, - ) +pub fn type_needs_rc(type_node: Rc, source_indices: Rc>>) -> bool { + type_needs_rc_seen(type_node, v2_rt::rc_empty_map::(), source_indices) } -pub fn type_needs_rc_seen( - mut type_node: Rc, - mut seen: Rc>, - mut source_indices: Rc>>, -) -> bool { +pub fn type_needs_rc_seen(mut type_node: Rc, mut seen: Rc>, mut source_indices: Rc>>) -> bool { loop { let normed = normalize_access_type_node(type_node); - let is_product = is_product_type(normed.clone()); - let is_coproduct = is_coproduct_type(normed.clone()); - if is_product { +let is_product = is_product_type(normed.clone()); +let is_coproduct = is_coproduct_type(normed.clone()); +if is_product { break true; - } else { +} else { if is_coproduct { - break { - let mut __found = false; - for child in normed.children.clone().iter().cloned() { - if ((child.children.clone().len() as i64) > 0) { - __found = true; - break; - } - } - __found - }; - } else { + break { let mut __found = false; for child in normed.children.clone().iter().cloned() { if ((child.children.clone().len() as i64) > 0) { __found = true; break; } } __found }; +} else { let canonical = authored_name_at(source_indices.clone(), &normed); - if (normed.inferred.clone() != None) { +if (normed.inferred.clone() != None) { let next_seen = if (canonical.clone().as_str() == "".to_string().as_str()) { seen.clone() } else { v2_rt::rc_map_insert(seen.clone(), canonical.clone(), true) }; - { +{ let __tco_0 = resolved_type(normed.clone()); - let __tco_1 = next_seen; - type_node = __tco_0; - seen = __tco_1; - continue; - } - } else { - if ((canonical.clone().as_str() != "".to_string().as_str()) - && emit_map_has(seen.clone(), canonical.clone())) - { +let __tco_1 = next_seen; +type_node = __tco_0; +seen = __tco_1; +continue; +} +} else { + if ((canonical.clone().as_str() != "".to_string().as_str()) && emit_map_has(seen.clone(), canonical.clone())) { break false; - } else { +} else { let next_seen = if (canonical.clone().as_str() == "".to_string().as_str()) { seen.clone() } else { v2_rt::rc_map_insert(seen.clone(), canonical.clone(), true) }; - let has_structure = (normed.connective.clone() != Connective::NoConnective); - if (!has_structure && ((normed.children.clone().len() as i64) == 0)) { +let has_structure = (normed.connective.clone() != Connective::NoConnective); +if (!has_structure && ((normed.children.clone().len() as i64) == 0)) { break false; - } else { +} else { { let __tco_0 = normed.clone(); - let __tco_1 = next_seen; - type_node = __tco_0; - seen = __tco_1; - continue; - } - } - } - } - } - } - } +let __tco_1 = next_seen; +type_node = __tco_0; +seen = __tco_1; +continue; +} +} +} +} +} +} +} } pub fn rust_runtime_bridge_passes_receiver_by_ref(function_name: String) -> bool { @@ -6063,3701 +2549,1347 @@ pub fn rust_runtime_bridge_passes_receiver_by_ref(function_name: String) -> bool pub fn rust_runtime_bridge_name(function_name: String) -> String { match v2_rt::map_get(&rt_bridge_function_names(), function_name.clone()) { - Some(runtime_name) => runtime_name.clone(), - None => function_name.clone(), - } + Some(runtime_name) => runtime_name.clone(), + None => function_name.clone(), +} } -pub fn rust_empty_map_value_type_str( - map_type: Rc, - shared_types: Rc>, - source_indices: Rc>>, -) -> String { +pub fn rust_empty_map_value_type_str(map_type: Rc, shared_types: Rc>, source_indices: Rc>>) -> String { match map_type.children.clone().get(1 as usize).cloned() { - Some(value_child) => { - let rendered = - render_rust_type(child_type_node(&value_child), shared_types, source_indices); - if (rendered.clone().as_str() == "".to_string().as_str()) { - "".to_string() - } else { - rendered.clone() - } + Some(value_child) => { + let rendered = render_rust_type(child_type_node(&value_child), shared_types, source_indices); +if (rendered.clone().as_str() == "".to_string().as_str()) { + "".to_string() + } else { + rendered.clone() } - None => "".to_string(), - } +}, + None => "".to_string(), +} } -pub fn rust_empty_map_kv_type_str( - map_type: &Rc, - shared_types: &Rc>, - source_indices: &Rc>>, -) -> String { +pub fn rust_empty_map_kv_type_str(map_type: &Rc, shared_types: &Rc>, source_indices: &Rc>>) -> String { { let key_str = match map_type.children.clone().first().cloned() { - Some(key_child) => render_rust_type( - child_type_node(&key_child), - shared_types.clone(), - source_indices.clone(), - ), - None => "".to_string(), - }; - let val_str = rust_empty_map_value_type_str( - map_type.clone(), - shared_types.clone(), - source_indices.clone(), - ); - if ((key_str.clone().as_str() != "".to_string().as_str()) - && (val_str.clone().as_str() != "".to_string().as_str())) - { - v2_rt::concat( - v2_rt::concat(key_str.clone(), ", ".to_string()), - val_str.clone(), - ) + Some(key_child) => render_rust_type(child_type_node(&key_child), shared_types.clone(), source_indices.clone()), + None => "".to_string(), +}; +let val_str = rust_empty_map_value_type_str(map_type.clone(), shared_types.clone(), source_indices.clone()); +if ((key_str.clone().as_str() != "".to_string().as_str()) && (val_str.clone().as_str() != "".to_string().as_str())) { + v2_rt::concat(v2_rt::concat(key_str.clone(), ", ".to_string()), val_str.clone()) } else { "".to_string() } - } +} } pub fn rust_runtime_bridge_wraps_collection_result_in_rc(function_name: &String) -> bool { - (v2_rt::map_contains_key(&rt_wraps_result(), function_name.clone()) - || v2_rt::map_contains_key(&rust_method_wraps_result(), function_name.clone())) + (v2_rt::map_contains_key(&rt_wraps_result(), function_name.clone()) || v2_rt::map_contains_key(&rust_method_wraps_result(), function_name.clone())) } -pub fn rust_runtime_bridge_collection_result_needs_rc_elements( - function_name: String, - result_type: Option>, -) -> bool { +pub fn rust_runtime_bridge_collection_result_needs_rc_elements(function_name: String, result_type: Option>) -> bool { false } -pub fn rust_wrap_runtime_collection_result( - call_str: String, - function_name: &String, - result_type: Option>, -) -> String { +pub fn rust_wrap_runtime_collection_result(call_str: String, function_name: &String, result_type: Option>) -> String { if rust_runtime_bridge_wraps_collection_result_in_rc(&function_name) { - if rust_runtime_bridge_collection_result_needs_rc_elements( - function_name.clone(), - result_type, - ) { - v2_rt::concat( - v2_rt::concat("Rc::new((".to_string(), call_str), - ").into_iter().map(Rc::new).collect::>())".to_string(), - ) - } else { - v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), call_str), - ")".to_string(), - ) + if rust_runtime_bridge_collection_result_needs_rc_elements(function_name.clone(), result_type) { + v2_rt::concat(v2_rt::concat("Rc::new((".to_string(), call_str), ").into_iter().map(Rc::new).collect::>())".to_string()) + } else { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), call_str), ")".to_string()) } } else { call_str } } -pub fn emit_rust_expr_var( - expr: &Rc, - registry: Rc>>, - shared_types: Rc>, - emit_info: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_rust_expr_var(expr: &Rc, registry: Rc>>, shared_types: Rc>, emit_info: Rc, source_indices: &Rc>>) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprVar { binding_kind, .. } => { - let n = expr_var_name_at(expr.clone(), source_indices.clone()); - emit_var_ref( - &n, - &binding_kind, - &expr.inferred.clone(), - shared_types, - registry, - &emit_info, - source_indices.clone(), - ) - } - _ => emit_error_expr( - "emit_rust_expr_var expected ExprVar".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprVar { binding_kind, .. } => { + let n = expr_var_name_at(expr.clone(), source_indices.clone()); +emit_var_ref(&n, &binding_kind, &expr.inferred.clone(), shared_types, registry, &emit_info, source_indices.clone()) +}, + _ => emit_error_expr("emit_rust_expr_var expected ExprVar".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_field_access( - expr: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_field_access(expr: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { { let si = scope.type_env.clone().source_indices.clone(); - match (*expr.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { summary, .. } => { - let f = field_access_field_at(expr.clone(), si); - let b = field_access_base(expr.clone()); - if is_typed_service_call_receiver( - &expr, - scope.type_env.clone().source_indices.clone(), - ) { - match extract_typed_service_name( - &expr, - &scope.type_env.clone().source_indices.clone(), - ) { - Some(svc_name) => service_var_name(svc_name.clone()), - None => emit_typed_field_access( - &b, - &f, - summary.clone(), - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ), - } - } else { - emit_typed_field_access( - &b, - &f, - summary.clone(), - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ) - } +match (*expr.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { summary, .. } => { + let f = field_access_field_at(expr.clone(), si); +let b = field_access_base(expr.clone()); +if is_typed_service_call_receiver(&expr, scope.type_env.clone().source_indices.clone()) { + match extract_typed_service_name(&expr, &scope.type_env.clone().source_indices.clone()) { + Some(svc_name) => service_var_name(svc_name.clone()), + None => emit_typed_field_access(&b, &f, summary.clone(), ®istry, &scope, depth, &shared_types, &emit_info), +} + } else { + emit_typed_field_access(&b, &f, summary.clone(), ®istry, &scope, depth, &shared_types, &emit_info) } - _ => emit_error_expr( - "emit_rust_expr_field_access expected ExprFieldAccess".to_string(), - RenderTarget::Rust, - ), - } - } +}, + _ => emit_error_expr("emit_rust_expr_field_access expected ExprFieldAccess".to_string(), RenderTarget::Rust), +} +} } -pub fn emit_rust_expr_call( - expr: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_call(expr: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let f = expr_call_func_at(expr.clone(), scope.type_env.clone().source_indices.clone()); - emit_typed_call_expr( - &f, - expr.children.clone(), - expr.inferred.clone(), - registry, - scope.clone(), - depth, - shared_types, - emit_info, - ) - } - _ => emit_error_expr( - "emit_rust_expr_call expected ExprCall".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprCall { .. } => { + let f = expr_call_func_at(expr.clone(), scope.type_env.clone().source_indices.clone()); +emit_typed_call_expr(&f, expr.children.clone(), expr.inferred.clone(), registry, scope.clone(), depth, shared_types, emit_info) +}, + _ => emit_error_expr("emit_rust_expr_call expected ExprCall".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_method_call( - expr: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_method_call(expr: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprMethodCall { - method_semantics, .. - } => { - let r = method_receiver(expr.clone()); - let a = method_arg_nodes(expr.clone()); - let m = - expr_method_name_at(expr.clone(), scope.type_env.clone().source_indices.clone()); - emit_typed_method_call( - expr.clone(), - &r, - m, - &a, - expr.inferred.clone(), - &method_semantics, - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ) - } - _ => emit_error_expr( - "emit_rust_expr_method_call expected ExprMethodCall".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprMethodCall { method_semantics, .. } => { + let r = method_receiver(expr.clone()); +let a = method_arg_nodes(expr.clone()); +let m = expr_method_name_at(expr.clone(), scope.type_env.clone().source_indices.clone()); +emit_typed_method_call(expr.clone(), &r, m, &a, expr.inferred.clone(), &method_semantics, ®istry, &scope, depth, &shared_types, &emit_info) +}, + _ => emit_error_expr("emit_rust_expr_method_call expected ExprMethodCall".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_match( - expr: &Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_match(expr: &Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprMatch => { - let s = match_scrutinee(expr.clone()); - let arm_list = match_arm_nodes(expr.clone()); - emit_typed_match( - &s, - &arm_list, - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ) - } - _ => emit_error_expr( - "emit_rust_expr_match expected ExprMatch".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprMatch => { + let s = match_scrutinee(expr.clone()); +let arm_list = match_arm_nodes(expr.clone()); +emit_typed_match(&s, &arm_list, ®istry, &scope, depth, &shared_types, &emit_info) +}, + _ => emit_error_expr("emit_rust_expr_match expected ExprMatch".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_if( - expr: &Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_if(expr: &Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprIf => { - let c = if_condition(expr.clone()); - let t = if_then_branch(expr.clone()); - let e = if_else_branch(expr.clone()); - emit_typed_if(c, t, e, ®istry, &scope, depth, &shared_types, &emit_info) - } - _ => emit_error_expr( - "emit_rust_expr_if expected ExprIf".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprIf => { + let c = if_condition(expr.clone()); +let t = if_then_branch(expr.clone()); +let e = if_else_branch(expr.clone()); +emit_typed_if(c, t, e, ®istry, &scope, depth, &shared_types, &emit_info) +}, + _ => emit_error_expr("emit_rust_expr_if expected ExprIf".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_let( - expr: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_let(expr: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprLet => { - let n = - let_binding_name_at(expr.clone(), scope.type_env.clone().source_indices.clone()); - let v = let_value(expr.clone()); - let bd = let_body(expr.clone()); - emit_typed_let( - n, - &v, - bd, - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ) - } - _ => emit_error_expr( - "emit_rust_expr_let expected ExprLet".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprLet => { + let n = let_binding_name_at(expr.clone(), scope.type_env.clone().source_indices.clone()); +let v = let_value(expr.clone()); +let bd = let_body(expr.clone()); +emit_typed_let(n, &v, bd, ®istry, &scope, depth, &shared_types, &emit_info) +}, + _ => emit_error_expr("emit_rust_expr_let expected ExprLet".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_record_lit( - expr: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_record_lit(expr: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprRecordLit { parent_enum, .. } => { - let tn = record_lit_type_name_at( - expr.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let fs = expr.children.clone(); - let raw = emit_typed_record_lit( - &tn, - &fs, - &parent_enum, - &resolved_type(expr.clone()), - registry, - &scope, - depth, - &shared_types, - &emit_info, - ); - let rc_name = match parent_enum.clone() { - Some(en) => en.clone(), - None => match tn.clone() { - Some(n) => n.clone(), - None => "".to_string(), - }, - }; - if ((rc_name.clone().as_str() != "".to_string().as_str()) - && emit_map_has(shared_types.clone(), rc_name.clone())) - { - v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) - } else { - raw - } + ExprData::ExprRecordLit { parent_enum, .. } => { + let tn = record_lit_type_name_at(expr.clone(), scope.type_env.clone().source_indices.clone()); +let fs = expr.children.clone(); +let raw = emit_typed_record_lit(&tn, &fs, &parent_enum, &resolved_type(expr.clone()), registry, &scope, depth, &shared_types, &emit_info); +let rc_name = match parent_enum.clone() { + Some(en) => en.clone(), + None => match tn.clone() { + Some(n) => n.clone(), + None => "".to_string(), +}, +}; +if ((rc_name.clone().as_str() != "".to_string().as_str()) && emit_map_has(shared_types.clone(), rc_name.clone())) { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) + } else { + raw } - _ => emit_error_expr( - "emit_rust_expr_record_lit expected ExprRecordLit".to_string(), - RenderTarget::Rust, - ), - } +}, + _ => emit_error_expr("emit_rust_expr_record_lit expected ExprRecordLit".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_string_interp( - expr: &Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_string_interp(expr: &Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprStringInterp => { - let ps = Rc::new({ - let mut __result = Vec::new(); - for child in expr.children.clone().iter().cloned() { - __result.push(match (*child.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: text, .. } = value.as_ref() else { - unreachable!() - }; - Rc::new(StringPart::Text { - value: text.clone(), - }) - } - _ => Rc::new(StringPart::Interpolation { - expr: arg_value(&child), - }), - }); - } - __result - }); - emit_typed_string_interp(&ps, registry, scope, depth, shared_types, emit_info) - } - _ => emit_error_expr( - "emit_rust_expr_string_interp expected ExprStringInterp".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprStringInterp => { + let ps = Rc::new({ let mut __result = Vec::new(); for child in expr.children.clone().iter().cloned() { __result.push(match (*child.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: text, .. } = value.as_ref() else { unreachable!() }; Rc::new(StringPart::Text { + value: text.clone(), +}) }, + _ => Rc::new(StringPart::Interpolation { + expr: arg_value(&child), +}), +}); } __result }); +emit_typed_string_interp(&ps, registry, scope, depth, shared_types, emit_info) +}, + _ => emit_error_expr("emit_rust_expr_string_interp expected ExprStringInterp".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_block( - expr: &Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_block(expr: &Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprBlock => emit_typed_block( - expr.children.clone(), - registry, - scope, - depth, - shared_types, - emit_info, - ), - _ => emit_error_expr( - "emit_rust_expr_block expected ExprBlock".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprBlock => emit_typed_block(expr.children.clone(), registry, scope, depth, shared_types, emit_info), + _ => emit_error_expr("emit_rust_expr_block expected ExprBlock".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_cast( - expr: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_cast(expr: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCast => emit_typed_cast_shared( - &cast_expr(expr.clone()), - cast_target(expr.clone()), - &RenderTarget::Rust, - |child| { - emit_typed_expr( - child.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ) - }, - &scope.type_env.clone().source_indices.clone(), - ), - _ => emit_error_expr( - "emit_rust_expr_cast expected ExprCast".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprCast => emit_typed_cast_shared(&cast_expr(expr.clone()), cast_target(expr.clone()), &RenderTarget::Rust, |child| emit_typed_expr(child.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024), &scope.type_env.clone().source_indices.clone()), + _ => emit_error_expr("emit_rust_expr_cast expected ExprCast".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_for_each( - expr: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_for_each(expr: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprForEach => { - let v = - foreach_variable_at(expr.clone(), scope.type_env.clone().source_indices.clone()); - let c = foreach_collection(expr.clone()); - let bd = foreach_body(expr.clone()); - emit_typed_for_each( - &v, - &c, - bd, - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ) - } - _ => emit_error_expr( - "emit_rust_expr_for_each expected ExprForEach".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprForEach => { + let v = foreach_variable_at(expr.clone(), scope.type_env.clone().source_indices.clone()); +let c = foreach_collection(expr.clone()); +let bd = foreach_body(expr.clone()); +emit_typed_for_each(&v, &c, bd, ®istry, &scope, depth, &shared_types, &emit_info) +}, + _ => emit_error_expr("emit_rust_expr_for_each expected ExprForEach".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_index( - expr: &Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_index(expr: &Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprIndex => { - let b = index_base(expr.clone()); - let i = index_expr(expr.clone()); - emit_typed_index(&b, i, ®istry, &scope, depth, &shared_types, &emit_info) - } - _ => emit_error_expr( - "emit_rust_expr_index expected ExprIndex".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprIndex => { + let b = index_base(expr.clone()); +let i = index_expr(expr.clone()); +emit_typed_index(&b, i, ®istry, &scope, depth, &shared_types, &emit_info) +}, + _ => emit_error_expr("emit_rust_expr_index expected ExprIndex".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_slice( - expr: &Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_slice(expr: &Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprSlice => { - let b = slice_base(expr.clone()); - let s = slice_start(expr.clone()); - let e = slice_end(expr.clone()); - emit_typed_slice( - &b, - s, - e, - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ) - } - _ => emit_error_expr( - "emit_rust_expr_slice expected ExprSlice".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprSlice => { + let b = slice_base(expr.clone()); +let s = slice_start(expr.clone()); +let e = slice_end(expr.clone()); +emit_typed_slice(&b, s, e, ®istry, &scope, depth, &shared_types, &emit_info) +}, + _ => emit_error_expr("emit_rust_expr_slice expected ExprSlice".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_expr_bin_op( - expr: &Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_expr_bin_op(expr: &Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprBinOp { - op, - algebra_field: algebra, - .. - } => emit_typed_bin_op( - &op, - algebra.clone(), - &binop_left(expr.clone()), - &binop_right(expr.clone()), - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ), - _ => emit_error_expr( - "emit_rust_expr_bin_op expected ExprBinOp".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprBinOp { op, algebra_field: algebra, .. } => emit_typed_bin_op(&op, algebra.clone(), &binop_left(expr.clone()), &binop_right(expr.clone()), ®istry, &scope, depth, &shared_types, &emit_info), + _ => emit_error_expr("emit_rust_expr_bin_op expected ExprBinOp".to_string(), RenderTarget::Rust), +} } -pub fn emit_typed_expr( - texpr: Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, - fuel: i64, -) -> String { +pub fn emit_typed_expr(texpr: Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc, fuel: i64) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - emit_shared_expr( - &texpr, - &RenderTarget::Rust, - scope.type_env.clone().source_indices.clone(), - |result| result.clone(), - |child| { - emit_typed_expr( - child.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - (fuel.clone() - 1), - ) - }, - |expr| { - emit_rust_expr_var( - &expr, - registry.clone(), - shared_types.clone(), - emit_info.clone(), - &scope.type_env.clone().source_indices.clone(), - ) - }, - |expr| { - emit_rust_expr_field_access( - &expr, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_call( - &expr, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_method_call( - &expr, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_match( - &expr, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_if( - &expr, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_let( - &expr, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_record_lit( - &expr, - registry.clone(), - &scope, - depth.clone(), - &shared_types, - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_string_interp( - &expr, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_block( - &expr, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_cast( - &expr, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_for_each( - &expr, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_index( - &expr, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_slice( - &expr, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |expr| { - emit_rust_expr_bin_op( - &expr, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - ) + emit_shared_expr(&texpr, &RenderTarget::Rust, scope.type_env.clone().source_indices.clone(), |result| result.clone(), |child| emit_typed_expr(child.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), (fuel.clone() - 1)), |expr| emit_rust_expr_var(&expr, registry.clone(), shared_types.clone(), emit_info.clone(), &scope.type_env.clone().source_indices.clone()), |expr| emit_rust_expr_field_access(&expr, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_call(&expr, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_method_call(&expr, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_match(&expr, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_if(&expr, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_let(&expr, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_record_lit(&expr, registry.clone(), &scope, depth.clone(), &shared_types, emit_info.clone()), |expr| emit_rust_expr_string_interp(&expr, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_block(&expr, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_cast(&expr, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_for_each(&expr, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_index(&expr, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_slice(&expr, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()), |expr| emit_rust_expr_bin_op(&expr, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone())) }) } -pub fn emit_cloned_arg( - texpr: Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { - emit_typed_expr( - texpr, - registry, - &scope, - depth, - shared_types, - emit_info, - 1024, - ) -} - -pub fn is_enum_type_name( - type_name: String, - type_summaries: Rc>>, -) -> bool { +pub fn emit_cloned_arg(texpr: Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { + emit_typed_expr(texpr, registry, &scope, depth, shared_types, emit_info, 1024) +} + +pub fn is_enum_type_name(type_name: String, type_summaries: Rc>>) -> bool { is_enum_in_summaries(type_summaries, type_name) } -pub fn contextual_variant_parent( - variant_name: &String, - parent_enum: Option, - resolved_type: &Rc, - emit_info: Rc, - source_indices: Rc>>, -) -> Option { +pub fn contextual_variant_parent(variant_name: &String, parent_enum: Option, resolved_type: &Rc, emit_info: Rc, source_indices: Rc>>) -> Option { match parent_enum { - Some(explicit_parent) => { - if variant_belongs_to_enum( - emit_info.type_summaries.clone(), - variant_name.clone(), - explicit_parent.clone(), - ) { - Some(explicit_parent.clone()) - } else { - None - } - } - None => { - let rt_name = authored_name_at(source_indices, &resolved_type); - if (((resolved_type.ident_span.clone() != None) - && (rt_name.clone().as_str() != variant_name.clone().as_str())) - && variant_belongs_to_enum( - emit_info.type_summaries.clone(), - variant_name.clone(), - rt_name.clone(), - )) - { - Some(rt_name.clone()) - } else { - None - } + Some(explicit_parent) => if variant_belongs_to_enum(emit_info.type_summaries.clone(), variant_name.clone(), explicit_parent.clone()) { + Some(explicit_parent.clone()) + } else { + None + }, + None => { + let rt_name = authored_name_at(source_indices, &resolved_type); +if (((resolved_type.ident_span.clone() != None) && (rt_name.clone().as_str() != variant_name.clone().as_str())) && variant_belongs_to_enum(emit_info.type_summaries.clone(), variant_name.clone(), rt_name.clone())) { + Some(rt_name.clone()) + } else { + None } - } +}, +} } -pub fn is_map_typed_expr( - texpr: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_map_typed_expr(texpr: Rc, source_indices: Rc>>) -> bool { match texpr.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: n, .. }) => { - node_is_keyed_collection(&n, source_indices) - } - _ => false, - } + Some(InferredNode::Resolved { node: n, .. }) => node_is_keyed_collection(&n, source_indices), + _ => false, +} } -pub fn emit_typed_call_expr( - func: &String, - args: Rc>>, - inferred: Option>, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_typed_call_expr(func: &String, args: Rc>>, inferred: Option>, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { { let call_str = if (func.clone().as_str() == "empty_map".to_string().as_str()) { match inferred.as_deref().cloned() { - Some(InferredNode::Resolved { node: ret_type, .. }) => { - let kv_type_str = rust_empty_map_kv_type_str( - &ret_type, - &shared_types, - &scope.type_env.clone().source_indices.clone(), - ); - if (kv_type_str.clone().as_str() != "".to_string().as_str()) { - v2_rt::concat( - v2_rt::concat( - "v2_rt::rc_empty_map::<".to_string(), - kv_type_str.clone(), - ), - ">()".to_string(), - ) - } else { - "Rc::new(HashMap::new()) /* BRIDGE: empty_map value type unresolved */" - .to_string() - } + Some(InferredNode::Resolved { node: ret_type, .. }) => { + let kv_type_str = rust_empty_map_kv_type_str(&ret_type, &shared_types, &scope.type_env.clone().source_indices.clone()); +if (kv_type_str.clone().as_str() != "".to_string().as_str()) { + v2_rt::concat(v2_rt::concat("v2_rt::rc_empty_map::<".to_string(), kv_type_str.clone()), ">()".to_string()) + } else { + "Rc::new(HashMap::new()) /* BRIDGE: empty_map value type unresolved */".to_string() } - _ => "Rc::new(HashMap::new()) /* BRIDGE: empty_map return type unresolved */" - .to_string(), - } +}, + _ => "Rc::new(HashMap::new()) /* BRIDGE: empty_map return type unresolved */".to_string(), +} } else { - emit_typed_call( - &func, - &args, - ®istry, - &scope, - depth, - &shared_types, - &emit_info, - ) + emit_typed_call(&func, &args, ®istry, &scope, depth, &shared_types, &emit_info) }; - if rust_runtime_bridge_wraps_collection_result_in_rc(&func) { - v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), call_str), - ")".to_string(), - ) +if rust_runtime_bridge_wraps_collection_result_in_rc(&func) { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), call_str), ")".to_string()) } else { call_str } - } +} } -pub fn emit_typed_call( - func: &String, - args: &Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_typed_call(func: &String, args: &Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { { if (func.clone().as_str() == "get".to_string().as_str()) { { let get_args = order_typed_call_args(&args, func.clone(), &scope); - let get_list = get_args.clone().first().cloned(); - let get_idx = get_args.clone().get(1 as usize).cloned(); - let get_result = match get_list { - Some(list_arg) => match get_idx { - Some(idx_arg) => { - let list_str = emit_typed_expr( - arg_value(&list_arg), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let index_str = emit_typed_expr( - arg_value(&idx_arg), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(list_str, ".get((".to_string()), - index_str, - ), - ") as usize)".to_string(), - ), - clone_iterator_suffix(), - ) - } - None => "compile_error!(\"get call missing index argument\")".to_string(), - }, - None => "compile_error!(\"get call missing list argument\")".to_string(), - }; - return get_result; - } +let get_list = get_args.clone().first().cloned(); +let get_idx = get_args.clone().get(1 as usize).cloned(); +let get_result = match get_list { + Some(list_arg) => match get_idx { + Some(idx_arg) => { + let list_str = emit_typed_expr(arg_value(&list_arg), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let index_str = emit_typed_expr(arg_value(&idx_arg), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(list_str, ".get((".to_string()), index_str), ") as usize)".to_string()), clone_iterator_suffix()) +}, + None => "compile_error!(\"get call missing index argument\")".to_string(), +}, + None => "compile_error!(\"get call missing list argument\")".to_string(), +}; +return get_result +} } - if (func.clone().as_str() == "with".to_string().as_str()) { +if (func.clone().as_str() == "with".to_string().as_str()) { { let with_args = order_typed_call_args(&args, func.clone(), &scope); - if ((with_args.clone().len() as i64) == 0) { - return "compile_error!(\"with call missing base record\")".to_string(); +if ((with_args.clone().len() as i64) == 0) { + return "compile_error!(\"with call missing base record\")".to_string() } - let base_arg = arg_value(&with_args.clone().first().cloned().clone().unwrap()); - if ((with_args.clone().len() as i64) < 2) { - return "compile_error!(\"with call missing update record\")".to_string(); +let base_arg = arg_value(&with_args.clone().first().cloned().clone().unwrap()); +if ((with_args.clone().len() as i64) < 2) { + return "compile_error!(\"with call missing update record\")".to_string() } - let update_arg = - arg_value(&with_args.clone().get(1 as usize).cloned().clone().unwrap()); - let base_str = emit_typed_expr( - base_arg.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let type_name = if (base_arg.inferred.clone() != None) { - authored_name_at( - scope.type_env.clone().source_indices.clone(), - &resolved_type(base_arg.clone()), - ) +let update_arg = arg_value(&with_args.clone().get(1 as usize).cloned().clone().unwrap()); +let base_str = emit_typed_expr(base_arg.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let type_name = if (base_arg.inferred.clone() != None) { + authored_name_at(scope.type_env.clone().source_indices.clone(), &resolved_type(base_arg.clone())) } else { "compile_error!(\"with call missing resolved record type\")".to_string() }; - let field_strs = match (*update_arg.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => Rc::new({ - let mut __result = Vec::new(); - for f in update_arg.children.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - field_init_node_name_at( - f.clone(), - scope.type_env.clone().source_indices.clone(), - ), - RenderTarget::Rust, - ), - ": ".to_string(), - ), - emit_typed_expr( - field_init_node_value(&f), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - )); - } - __result - }), - _ => Rc::new(vec![emit_typed_expr( - update_arg.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - )]), - }; - let fields_str = field_strs.join(&", ".to_string()); - let needs_rc = emit_map_has(shared_types.clone(), type_name.clone()); - let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - let spread = if needs_rc.clone() { +let field_strs = match (*update_arg.expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => Rc::new({ let mut __result = Vec::new(); for f in update_arg.children.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(field_init_node_name_at(f.clone(), scope.type_env.clone().source_indices.clone()), RenderTarget::Rust), ": ".to_string()), emit_typed_expr(field_init_node_value(&f), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024))); } __result }), + _ => Rc::new(vec![emit_typed_expr(update_arg.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024)]), +}; +let fields_str = field_strs.join(&", ".to_string()); +let needs_rc = emit_map_has(shared_types.clone(), type_name.clone()); +let sharing = language_spec(RenderTarget::Rust).sharing.clone(); +let spread = if needs_rc.clone() { apply_type_template1(sharing.deref_clone.clone(), base_str) } else { apply_type_template1(sharing.clone_value.clone(), base_str) }; - let raw = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(type_name.clone(), " { ".to_string()), - fields_str, - ), - ", ..".to_string(), - ), - spread, - ), - " }".to_string(), - ); - if needs_rc.clone() { - return v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), raw), - ")".to_string(), - ); +let raw = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(type_name.clone(), " { ".to_string()), fields_str), ", ..".to_string()), spread), " }".to_string()); +if needs_rc.clone() { + return v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) } else { - return raw; + return raw } - } +} } - if (func.clone().as_str() == "to_string".to_string().as_str()) { +if (func.clone().as_str() == "to_string".to_string().as_str()) { { let to_string_args = order_typed_call_args(&args, func.clone(), &scope); - let ts_result = match to_string_args.first().cloned() { - Some(value_arg) => v2_rt::concat( - v2_rt::concat( - "(".to_string(), - emit_typed_expr( - arg_value(&value_arg), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - ), - ").to_string()".to_string(), - ), - None => "compile_error!(\"to_string call missing value argument\")".to_string(), - }; - return ts_result; - } +let ts_result = match to_string_args.first().cloned() { + Some(value_arg) => v2_rt::concat(v2_rt::concat("(".to_string(), emit_typed_expr(arg_value(&value_arg), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024)), ").to_string()".to_string()), + None => "compile_error!(\"to_string call missing value argument\")".to_string(), +}; +return ts_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().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 call_args = order_typed_call_args(&args, func.clone(), &scope); - match call_args.last().cloned() { - Some(a) => match (*arg_value(&a).expr_data.clone()).clone() { - ExprData::ExprLambda => { - let lps = lambda_param_names_at( - arg_value(&a), - scope.type_env.clone().source_indices.clone(), - ); - lambda_scope_from_children( - scope.clone(), - lps, - Rc::new( - arg_value(&a) - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ) - } - _ => scope.clone(), - }, - None => scope.clone(), - } - } +match call_args.last().cloned() { + Some(a) => match (*arg_value(&a).expr_data.clone()).clone() { + ExprData::ExprLambda => { + let lps = lambda_param_names_at(arg_value(&a), scope.type_env.clone().source_indices.clone()); +lambda_scope_from_children(scope.clone(), lps, Rc::new(arg_value(&a).children.clone().iter().cloned().skip(1 as usize).collect::>())) +}, + _ => scope.clone(), +}, + None => scope.clone(), +} +} } else { scope.clone() }; - let ordered_args = order_typed_call_args(&args, func.clone(), &collection_scope); - let callee = lookup_item(registry.clone(), func.clone()); - let filled_args = fill_default_args( - &ordered_args, - callee.clone(), - registry.clone(), - collection_scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - let is_rt = v2_rt::map_contains_key(&rt_functions(), func.clone()); - let is_rt_ref_map = v2_rt::map_contains_key(&rt_ref_map_functions(), func.clone()); - let callee_qualified = match callee.clone() { - Some(info) => v2_rt::concat( - v2_rt::concat(info.module_name.clone(), ".".to_string()), - func.clone(), - ), - None => func.clone(), - }; - let callee_read_only = - match v2_rt::map_get(&emit_info.read_only_params_index.clone(), callee_qualified) { - Some(m) => m.clone(), - None => v2_rt::rc_empty_map::(), - }; - let callee_is_tco = match callee.clone() { - Some(info) => { - (info.is_self_recursive.clone() && (info.has_non_tail_self_call.clone() == false)) - } - None => false, - }; - let callee_borrow_positions = if callee_is_tco { +let ordered_args = order_typed_call_args(&args, func.clone(), &collection_scope); +let callee = lookup_item(registry.clone(), func.clone()); +let filled_args = fill_default_args(&ordered_args, callee.clone(), registry.clone(), collection_scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()); +let is_rt = v2_rt::map_contains_key(&rt_functions(), func.clone()); +let is_rt_ref_map = v2_rt::map_contains_key(&rt_ref_map_functions(), func.clone()); +let callee_qualified = match callee.clone() { + Some(info) => v2_rt::concat(v2_rt::concat(info.module_name.clone(), ".".to_string()), func.clone()), + None => func.clone(), +}; +let callee_read_only = match v2_rt::map_get(&emit_info.read_only_params_index.clone(), callee_qualified) { + Some(m) => m.clone(), + None => v2_rt::rc_empty_map::(), +}; +let callee_is_tco = match callee.clone() { + Some(info) => (info.is_self_recursive.clone() && (info.has_non_tail_self_call.clone() == false)), + None => false, +}; +let callee_borrow_positions = if callee_is_tco { v2_rt::rc_empty_map::() } else { match callee.clone() { - Some(info) => Rc::new( - info.params - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, pair: (i64, Rc)| { - let pname = param_node_name_at( - pair.1.clone(), - collection_scope.type_env.clone().source_indices.clone(), - ); - let n = param_node_type_expr(&pair.1.clone()); - let is_callable = ((n.params.clone().len() as i64) > 0); - let is_borrowable = - ((v2_rt::map_contains_key(&callee_read_only, pname.clone()) - && (is_callable.clone() == false)) - && needs_reference_node( - &n, - collection_scope.type_env.clone().source_indices.clone(), - )); - if is_borrowable.clone() { - v2_rt::rc_map_insert(acc.clone(), (pair.0.clone()).to_string(), true) - } else { - acc.clone() - } - }, - ), - None => v2_rt::rc_empty_map::(), - } + Some(info) => Rc::new(info.params.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, pair: (i64, Rc)| { + let pname = param_node_name_at(pair.1.clone(), collection_scope.type_env.clone().source_indices.clone()); +let n = param_node_type_expr(&pair.1.clone()); +let is_callable = ((n.params.clone().len() as i64) > 0); +let is_borrowable = ((v2_rt::map_contains_key(&callee_read_only, pname.clone()) && (is_callable.clone() == false)) && needs_reference_node(&n, collection_scope.type_env.clone().source_indices.clone())); +if is_borrowable.clone() { + v2_rt::rc_map_insert(acc.clone(), (pair.0.clone()).to_string(), true) + } else { + acc.clone() + } +}), + None => v2_rt::rc_empty_map::(), +} }; - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - filled_args - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let idx = pair.0.clone(); - let a = pair.1.clone(); - if (is_rt_ref_map.clone() && (idx.clone() == 0)) { - { - let base = emit_typed_expr_base( - &arg_value(&a), - registry.clone(), - &collection_scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - v2_rt::concat("&".to_string(), base.clone()) - } - } else { - if v2_rt::map_contains_key( - &callee_borrow_positions, - (idx.clone()).to_string(), - ) { - { - let base = emit_typed_expr_base( - &arg_value(&a), - registry.clone(), - &collection_scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - apply_type_template1( - sharing_for_target(RenderTarget::Rust) - .borrow_arg_template - .clone(), - base.clone(), - ) - } - } else { - emit_cloned_arg( - arg_value(&a), - registry.clone(), - collection_scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) - } - } - }); - } - __result - }); - let extra_args = match callee.clone() { - Some(info) => { - let has_effects = (((info.service_names.clone().len() as i64) > 0) - || ((info.resource_names.clone().len() as i64) > 0)); - if has_effects.clone() { +let arg_strs = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(filled_args.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let idx = pair.0.clone(); +let a = pair.1.clone(); +if (is_rt_ref_map.clone() && (idx.clone() == 0)) { + { + let base = emit_typed_expr_base(&arg_value(&a), registry.clone(), &collection_scope, depth.clone(), shared_types.clone(), emit_info.clone()); +v2_rt::concat("&".to_string(), base.clone()) +} + } else { + if v2_rt::map_contains_key(&callee_borrow_positions, (idx.clone()).to_string()) { { - let resource_args = Rc::new({ - let mut __result = Vec::new(); - for rn in info.resource_names.clone().iter().cloned() { - __result.push(v2_rt::concat( - "&".to_string(), - emit_ident(rn.clone(), RenderTarget::Rust), - )); - } - __result - }); - let service_args = Rc::new({ - let mut __result = Vec::new(); - for sn in info.service_names.clone().iter().cloned() { - __result.push(service_var_name(sn.clone())); - } - __result - }); - v2_rt::concat(resource_args, service_args) - } + let base = emit_typed_expr_base(&arg_value(&a), registry.clone(), &collection_scope, depth.clone(), shared_types.clone(), emit_info.clone()); +apply_type_template1(sharing_for_target(RenderTarget::Rust).borrow_arg_template.clone(), base.clone()) +} } else { - Rc::new(vec![]) + emit_cloned_arg(arg_value(&a), registry.clone(), collection_scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()) } } - None => Rc::new(vec![]), - }; - let all_args = v2_rt::concat(arg_strs, extra_args); - let args_str = all_args.clone().join(&", ".to_string()); - let runtime_name = rust_runtime_bridge_name(func.clone()); - let func_name = if is_rt.clone() { - v2_rt::concat( - "v2_rt::".to_string(), - emit_ident(runtime_name, RenderTarget::Rust), - ) +}); } __result }); +let extra_args = match callee.clone() { + Some(info) => { + let has_effects = (((info.service_names.clone().len() as i64) > 0) || ((info.resource_names.clone().len() as i64) > 0)); +if has_effects.clone() { + { + let resource_args = Rc::new({ let mut __result = Vec::new(); for rn in info.resource_names.clone().iter().cloned() { __result.push(v2_rt::concat("&".to_string(), emit_ident(rn.clone(), RenderTarget::Rust))); } __result }); +let service_args = Rc::new({ let mut __result = Vec::new(); for sn in info.service_names.clone().iter().cloned() { __result.push(service_var_name(sn.clone())); } __result }); +v2_rt::concat(resource_args, service_args) +} + } else { + Rc::new(vec![]) + } +}, + None => Rc::new(vec![]), +}; +let all_args = v2_rt::concat(arg_strs, extra_args); +let args_str = all_args.clone().join(&", ".to_string()); +let runtime_name = rust_runtime_bridge_name(func.clone()); +let func_name = if is_rt.clone() { + v2_rt::concat("v2_rt::".to_string(), emit_ident(runtime_name, RenderTarget::Rust)) } else { emit_ident(func.clone(), RenderTarget::Rust) }; - let call_str = if ((is_rt.clone() - && (func.clone().as_str() == "concat".to_string().as_str())) - && ((all_args.clone().len() as i64) > 2)) - { +let call_str = if ((is_rt.clone() && (func.clone().as_str() == "concat".to_string().as_str())) && ((all_args.clone().len() as i64) > 2)) { emit_nested_rt_concat(all_args.clone(), "".to_string(), shared_types.clone()) } else { - v2_rt::concat( - v2_rt::concat(v2_rt::concat(func_name, "(".to_string()), args_str), - ")".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(func_name, "(".to_string()), args_str), ")".to_string()) }; - match callee.clone() { - Some(info) => { - let has_effects = (((info.service_names.clone().len() as i64) > 0) - || ((info.resource_names.clone().len() as i64) > 0)); - if has_effects.clone() { - v2_rt::concat(call_str, ".await?".to_string()) - } else { - call_str - } +match callee.clone() { + Some(info) => { + let has_effects = (((info.service_names.clone().len() as i64) > 0) || ((info.resource_names.clone().len() as i64) > 0)); +if has_effects.clone() { + v2_rt::concat(call_str, ".await?".to_string()) + } else { + call_str } - None => call_str, - } - } +}, + None => call_str, +} +} } -pub fn fill_default_args( - ordered: &Rc>>, - callee: Option>, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> Rc>> { +pub fn fill_default_args(ordered: &Rc>>, callee: Option>, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> Rc>> { match callee { - Some(info) => { - let provided_names = Rc::new({ - let mut __result = Vec::new(); - for a in ordered.clone().iter().cloned() { - __result.push( - match arg_name_at(a.clone(), scope.type_env.clone().source_indices.clone()) - { - Some(n) => n.clone(), - None => "".to_string(), - }, - ); - } - __result - }); - let missing_with_defaults = Rc::new({ - let mut __result = Vec::new(); - for p in info.params.clone().iter().cloned() { - if { - let is_provided = { - let mut __found = false; - for n in provided_names.clone().iter().cloned() { - if (n.clone().as_str() - == param_node_name_at( - p.clone(), - scope.type_env.clone().source_indices.clone(), - ) - .as_str()) - { - __found = true; - break; - } - } - __found - }; - if is_provided.clone() { - false - } else { - (param_node_default_value(&p) != None) - } - } { - __result.push(p); - } - } - __result - }); - let default_args = Rc::new({ - let mut __result = Vec::new(); - for p in missing_with_defaults.iter().cloned() { - __result.push(make_arg_node( - Some(param_node_name_at( - p.clone(), - scope.type_env.clone().source_indices.clone(), - )), - param_node_default_value(&p).clone().unwrap(), - p.span.clone(), - p.span.clone(), - )); - } - __result - }); - v2_rt::concat(ordered.clone(), default_args) - } - None => ordered.clone(), - } + Some(info) => { + let provided_names = Rc::new({ let mut __result = Vec::new(); for a in ordered.clone().iter().cloned() { __result.push(match arg_name_at(a.clone(), scope.type_env.clone().source_indices.clone()) { + Some(n) => n.clone(), + None => "".to_string(), +}); } __result }); +let missing_with_defaults = Rc::new({ let mut __result = Vec::new(); for p in info.params.clone().iter().cloned() { if { + let is_provided = { let mut __found = false; for n in provided_names.clone().iter().cloned() { if (n.clone().as_str() == param_node_name_at(p.clone(), scope.type_env.clone().source_indices.clone()).as_str()) { __found = true; break; } } __found }; +if is_provided.clone() { + false + } else { + (param_node_default_value(&p) != None) + } +} { __result.push(p); } } __result }); +let default_args = Rc::new({ let mut __result = Vec::new(); for p in missing_with_defaults.iter().cloned() { __result.push(make_arg_node(Some(param_node_name_at(p.clone(), scope.type_env.clone().source_indices.clone())), param_node_default_value(&p).clone().unwrap(), p.span.clone(), p.span.clone())); } __result }); +v2_rt::concat(ordered.clone(), default_args) +}, + None => ordered.clone(), +} } -pub fn fill_op_default_args( - ordered: &Rc>>, - op_params: Rc>>, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> Rc>> { +pub fn fill_op_default_args(ordered: &Rc>>, op_params: Rc>>, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> Rc>> { { let si = scope.type_env.clone().source_indices.clone(); - let arg_map = ordered.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, a: Rc| match arg_name_at( - a.clone(), - si.clone(), - ) { - Some(n) => v2_rt::rc_map_insert(acc.clone(), n.clone(), a.clone()), - None => acc.clone(), +let arg_map = ordered.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, a: Rc| match arg_name_at(a.clone(), si.clone()) { + Some(n) => v2_rt::rc_map_insert(acc.clone(), n.clone(), a.clone()), + None => acc.clone(), +}); +let unnamed_args = Rc::new({ let mut __result = Vec::new(); for a in ordered.clone().iter().cloned() { if (arg_name_at(a.clone(), si.clone()) == None) { __result.push(a); } } __result }); +let named_ordered = Rc::new({ let mut __result = Vec::new(); for p in op_params.iter().cloned() { __result.extend((*{ + let pname = param_node_name_at(p.clone(), si.clone()); +match v2_rt::map_get(&arg_map, pname.clone()) { + Some(arg) => Rc::new(vec![arg.clone()]), + None => if (param_node_default_value(&p) != None) { + Rc::new(vec![make_arg_node(Some(pname.clone()), param_node_default_value(&p).clone().unwrap(), p.span.clone(), p.span.clone())]) + } else { + Rc::new(vec![]) }, - ); - let unnamed_args = Rc::new({ - let mut __result = Vec::new(); - for a in ordered.clone().iter().cloned() { - if (arg_name_at(a.clone(), si.clone()) == None) { - __result.push(a); - } - } - __result - }); - let named_ordered = Rc::new({ - let mut __result = Vec::new(); - for p in op_params.iter().cloned() { - __result.extend( - (*{ - let pname = param_node_name_at(p.clone(), si.clone()); - match v2_rt::map_get(&arg_map, pname.clone()) { - Some(arg) => Rc::new(vec![arg.clone()]), - None => { - if (param_node_default_value(&p) != None) { - Rc::new(vec![make_arg_node( - Some(pname.clone()), - param_node_default_value(&p).clone().unwrap(), - p.span.clone(), - p.span.clone(), - )]) - } else { - Rc::new(vec![]) - } - } - } - }) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat(named_ordered, unnamed_args) - } +} +}).iter().cloned()); } __result }); +v2_rt::concat(named_ordered, unnamed_args) +} } -pub fn emit_nested_rt_concat( - mut remaining: Rc>, - mut acc: String, - mut shared_types: Rc>, -) -> String { +pub fn emit_nested_rt_concat(mut remaining: Rc>, mut acc: String, mut shared_types: Rc>) -> String { loop { match remaining.clone().first().cloned() { - None => { - break acc.clone(); - } - Some(arg) => { - let next_acc = if (acc.clone().as_str() == "".to_string().as_str()) { - arg.clone() - } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("v2_rt::concat(".to_string(), acc.clone()), - ", ".to_string(), - ), - arg.clone(), - ), - ")".to_string(), - ) - }; - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = next_acc; - remaining = __tco_0; - acc = __tco_1; - continue; - } - } - } - } + None => { break acc.clone(); }, + Some(arg) => { let next_acc = if (acc.clone().as_str() == "".to_string().as_str()) { + arg.clone() + } else { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("v2_rt::concat(".to_string(), acc.clone()), ", ".to_string()), arg.clone()), ")".to_string()) + }; +{ + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = next_acc; +remaining = __tco_0; +acc = __tco_1; +continue; +} }, +} +} } -pub fn emit_typed_for_each( - variable: &String, - collection: &Rc, - body: Rc, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_typed_for_each(variable: &String, collection: &Rc, body: Rc, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { { let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - let coll_str = emit_typed_expr( - collection.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let elem_type = for_each_element_type_node( - resolved_type(collection.clone()), - scope.type_env.clone().source_indices.clone(), - ); - let body_scope = extend_scope( - &scope, - &variable, - elem_type, - Rc::new(SubValueRelation::SubValueUnknown), - ); - let body_str = emit_typed_expr( - body, - registry.clone(), - &body_scope, - (depth.clone() + 2), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let ind1 = make_indent((depth.clone() + 1)); - let ind2 = make_indent((depth.clone() + 2)); - let ind0 = make_indent(depth.clone()); - let iter_str = apply_type_template1(sharing.iter_owned.clone(), coll_str); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\n".to_string(), ind1.clone()), "let mut __collect = Vec::new();\n".to_string()), ind1.clone()), "for ".to_string()), emit_ident(variable.clone(), RenderTarget::Rust)), " in ".to_string()), iter_str), " {\n".to_string()), ind2), "__collect.push(".to_string()), body_str), ");\n".to_string()), ind1.clone()), "}\n".to_string()), ind1.clone()), "Rc::new(__collect)\n".to_string()), ind0), "}".to_string()) - } +let coll_str = emit_typed_expr(collection.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let elem_type = for_each_element_type_node(resolved_type(collection.clone()), scope.type_env.clone().source_indices.clone()); +let body_scope = extend_scope(&scope, &variable, elem_type, Rc::new(SubValueRelation::SubValueUnknown)); +let body_str = emit_typed_expr(body, registry.clone(), &body_scope, (depth.clone() + 2), shared_types.clone(), emit_info.clone(), 1024); +let ind1 = make_indent((depth.clone() + 1)); +let ind2 = make_indent((depth.clone() + 2)); +let ind0 = make_indent(depth.clone()); +let iter_str = apply_type_template1(sharing.iter_owned.clone(), coll_str); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("{\n".to_string(), ind1.clone()), "let mut __collect = Vec::new();\n".to_string()), ind1.clone()), "for ".to_string()), emit_ident(variable.clone(), RenderTarget::Rust)), " in ".to_string()), iter_str), " {\n".to_string()), ind2), "__collect.push(".to_string()), body_str), ");\n".to_string()), ind1.clone()), "}\n".to_string()), ind1.clone()), "Rc::new(__collect)\n".to_string()), ind0), "}".to_string()) +} } -pub fn emit_typed_index( - base: &Rc, - index: Rc, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_typed_index(base: &Rc, index: Rc, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { { let spec = language_spec(RenderTarget::Rust); - let base_str = emit_typed_expr( - base.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let index_str = emit_typed_expr( - index, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let base_node = normalize_access_type_node(resolved_type(base.clone())); - let is_map = - node_is_keyed_collection(&base_node, scope.type_env.clone().source_indices.clone()); - if is_rust_string_like( - base_node.clone(), - scope.type_env.clone().source_indices.clone(), - ) { - apply_type_template2( - spec.indexing.clone().string_index.clone(), - base_str, - index_str, - ) +let base_str = emit_typed_expr(base.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let index_str = emit_typed_expr(index, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let base_node = normalize_access_type_node(resolved_type(base.clone())); +let is_map = node_is_keyed_collection(&base_node, scope.type_env.clone().source_indices.clone()); +if is_rust_string_like(base_node.clone(), scope.type_env.clone().source_indices.clone()) { + apply_type_template2(spec.indexing.clone().string_index.clone(), base_str, index_str) } else { if is_map { apply_type_template2(spec.indexing.clone().map_index.clone(), base_str, index_str) } else { - apply_type_template2( - spec.indexing.clone().list_index.clone(), - base_str, - index_str, - ) + apply_type_template2(spec.indexing.clone().list_index.clone(), base_str, index_str) } } - } +} } -pub fn emit_typed_slice( - base: &Rc, - start: Rc, - end: Rc, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_typed_slice(base: &Rc, start: Rc, end: Rc, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { { let spec = language_spec(RenderTarget::Rust); - let base_str = emit_typed_expr( - base.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let start_str = emit_typed_expr( - start, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let end_str = emit_typed_expr( - end, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let base_node = normalize_access_type_node(resolved_type(base.clone())); - if is_rust_string_like(base_node, scope.type_env.clone().source_indices.clone()) { +let base_str = emit_typed_expr(base.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let start_str = emit_typed_expr(start, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let end_str = emit_typed_expr(end, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let base_node = normalize_access_type_node(resolved_type(base.clone())); +if is_rust_string_like(base_node, scope.type_env.clone().source_indices.clone()) { match spec.indexing.clone().string_slice.clone() { - Some(tmpl) => apply_type_template3(tmpl.clone(), base_str, start_str, end_str), - None => emit_error_expr( - "unsupported string slice for target".to_string(), - RenderTarget::Rust, - ), - } + Some(tmpl) => apply_type_template3(tmpl.clone(), base_str, start_str, end_str), + None => emit_error_expr("unsupported string slice for target".to_string(), RenderTarget::Rust), +} } else { match spec.indexing.clone().list_slice.clone() { - Some(tmpl) => apply_type_template3(tmpl.clone(), base_str, start_str, end_str), - None => emit_error_expr( - "unsupported list slice for target".to_string(), - RenderTarget::Rust, - ), - } - } - } + Some(tmpl) => apply_type_template3(tmpl.clone(), base_str, start_str, end_str), + None => emit_error_expr("unsupported list slice for target".to_string(), RenderTarget::Rust), } - -pub fn collection_element_type( - receiver_type: Option>, - shared_types: Rc>, - source_indices: &Rc>>, -) -> String { - match receiver_type.as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - let __rt_is_container = node_is_element_collection(&rt, source_indices.clone()); - if __rt_is_container { - match rt.children.clone().first().cloned() { - Some(elem_child) => { - let elem_node = child_type_node(&elem_child); - let elem_is_error = if (elem_node.inferred.clone() != None) { - is_compiler_error(elem_node.inferred.clone().clone().unwrap()) - } else { - false - }; - let elem_is_type_var = if (elem_node.inferred.clone() != None) { - is_type_variable(elem_node.inferred.clone().clone().unwrap()) - } else { - false - }; - if (elem_is_error || elem_is_type_var) { - "_".to_string() - } else { - render_rust_type( - elem_node.clone(), - shared_types, - source_indices.clone(), - ) - } - } - None => "_".to_string(), - } - } else { - "_".to_string() - } } - _ => "_".to_string(), - } } - -pub fn lambda_scope_from_children( - scope: Rc, - params: Rc>, - param_nodes: Rc>>, -) -> Rc { - Rc::new( - params - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold(scope.clone(), |acc: Rc, pair: (i64, String)| { - let idx = pair.0.clone(); - let param_name = pair.1.clone(); - let param_type = match param_nodes.clone().get(idx.clone() as usize).cloned() { - Some(pn) => match pn.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: resolved_type, - .. - }) => resolved_type.clone(), - _ => type_variable_node("lambda_param".to_string()), - }, - None => type_variable_node("lambda_param".to_string()), - }; - extend_scope( - &acc, - ¶m_name, - param_type.clone(), - Rc::new(SubValueRelation::SubValueUnknown), - ) - }) } -pub fn lambda_param_type_strs( - params: Rc>, - param_nodes: Rc>>, - fallback_types: Rc>, - shared_types: Rc>, - source_indices: Rc>>, -) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - params - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let idx = pair.0.clone(); - let param_name = pair.1.clone(); - let inferred_type = match param_nodes.clone().get(idx.clone() as usize).cloned() { - Some(pn) => match pn.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: param_type, .. - }) => { - let param_is_error = if (param_type.inferred.clone() != None) { - is_compiler_error(param_type.inferred.clone().clone().unwrap()) - } else { - false - }; - let param_is_type_var = if (param_type.inferred.clone() != None) { - is_type_variable(param_type.inferred.clone().clone().unwrap()) - } else { - false - }; - if (param_is_type_var.clone() || param_is_error.clone()) { - None - } else { - Some(render_rust_type( - param_type.clone(), - shared_types.clone(), - source_indices.clone(), - )) - } - } - _ => None, - }, - None => None, +pub fn collection_element_type(receiver_type: Option>, shared_types: Rc>, source_indices: &Rc>>) -> String { + match receiver_type.as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => { + let __rt_is_container = node_is_element_collection(&rt, source_indices.clone()); +if __rt_is_container { + match rt.children.clone().first().cloned() { + Some(elem_child) => { + let elem_node = child_type_node(&elem_child); +let elem_is_error = if (elem_node.inferred.clone() != None) { + is_compiler_error(elem_node.inferred.clone().clone().unwrap()) + } else { + false }; - let fallback_type = match fallback_types.clone().get(idx.clone() as usize).cloned() - { - Some(ty) => ty.clone(), - None => "_".to_string(), +let elem_is_type_var = if (elem_node.inferred.clone() != None) { + is_type_variable(elem_node.inferred.clone().clone().unwrap()) + } else { + false }; - let spec = language_spec(RenderTarget::Rust); - let ident = emit_ident(param_name.clone(), RenderTarget::Rust); - match inferred_type.clone() { - Some(ty) => apply_type_template2( - spec.annotations.clone().lambda_param_typed.clone(), - ident.clone(), - ty.clone(), - ), - None => apply_type_template2( - spec.annotations.clone().lambda_param_typed.clone(), - ident.clone(), - fallback_type.clone(), - ), +if (elem_is_error || elem_is_type_var) { + "_".to_string() + } else { + render_rust_type(elem_node.clone(), shared_types, source_indices.clone()) } - }); +}, + None => "_".to_string(), +} + } else { + "_".to_string() } - __result - }) +}, + _ => "_".to_string(), +} } -pub fn emit_typed_collection_lambda( - lambda_expr: &Rc, - elem_type_str: String, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: Rc, -) -> String { - match (*lambda_expr.expr_data.clone()).clone() { - ExprData::ExprLambda => { - let ps = lambda_param_names_at( - lambda_expr.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let bd = lambda_body(lambda_expr.clone()); - let pn = Rc::new( - lambda_expr - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let param_strs = lambda_param_type_strs( - ps.clone(), - pn.clone(), - Rc::new(vec![elem_type_str]), - shared_types.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let params_str = param_strs.join(&", ".to_string()); - let lambda_scope = lambda_scope_from_children(scope.clone(), ps.clone(), pn.clone()); - let body_str = emit_typed_expr( - bd, - registry, - &lambda_scope, - depth, - shared_types.clone(), - emit_info, - 1024, - ); - v2_rt::concat( - v2_rt::concat(v2_rt::concat("|".to_string(), params_str), "| ".to_string()), - body_str, - ) - } - _ => emit_typed_expr( - lambda_expr.clone(), - registry, - &scope, - depth, - shared_types.clone(), - emit_info, - 1024, - ), - } +pub fn lambda_scope_from_children(scope: Rc, params: Rc>, param_nodes: Rc>>) -> Rc { + Rc::new(params.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(scope.clone(), |acc: Rc, pair: (i64, String)| { + let idx = pair.0.clone(); +let param_name = pair.1.clone(); +let param_type = match param_nodes.clone().get(idx.clone() as usize).cloned() { + Some(pn) => match pn.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: resolved_type, .. }) => resolved_type.clone(), + _ => type_variable_node("lambda_param".to_string()), +}, + None => type_variable_node("lambda_param".to_string()), +}; +extend_scope(&acc, ¶m_name, param_type.clone(), Rc::new(SubValueRelation::SubValueUnknown)) +}) } -pub fn emit_typed_fold_lambda( - lambda_expr: &Rc, - acc_type_str: &String, - elem_type_str: String, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - match (*lambda_expr.expr_data.clone()).clone() { - ExprData::ExprLambda => { - let ps = lambda_param_names_at( - lambda_expr.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let bd = lambda_body(lambda_expr.clone()); - let pn = Rc::new( - lambda_expr - .children - .clone() - .iter() - .cloned() - .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())) - { - "_".to_string() +pub fn lambda_param_type_strs(params: Rc>, param_nodes: Rc>>, fallback_types: Rc>, shared_types: Rc>, source_indices: Rc>>) -> Rc> { + Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(params.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let idx = pair.0.clone(); +let param_name = pair.1.clone(); +let inferred_type = match param_nodes.clone().get(idx.clone() as usize).cloned() { + Some(pn) => match pn.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: param_type, .. }) => { + let param_is_error = if (param_type.inferred.clone() != None) { + is_compiler_error(param_type.inferred.clone().clone().unwrap()) } else { - acc_type_str.clone() + false }; - let fallback_types = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - ps.clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push(if (pair.0.clone() == 0) { - safe_acc_type.clone() - } else { - elem_type_str.clone() - }); - } - __result - }); - let param_strs = lambda_param_type_strs( - ps.clone(), - Rc::new(vec![]), - fallback_types, - shared_types.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let params_str = param_strs.join(&", ".to_string()); - let lambda_scope = lambda_scope_from_children(scope.clone(), ps.clone(), pn); - let body_str = emit_typed_expr( - bd, - registry, - &lambda_scope, - depth, - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let acc_name = match ps.clone().first().cloned() { - Some(n) => n.clone(), - None => "".to_string(), +let param_is_type_var = if (param_type.inferred.clone() != None) { + is_type_variable(param_type.inferred.clone().clone().unwrap()) + } else { + false }; - let needs_unwrap = ((acc_name.clone().as_str() != "".to_string().as_str()) - && emit_map_has(emit_info.owned_bindings.clone(), acc_name.clone())); - if needs_unwrap { - { - let acc_ident = emit_ident(acc_name.clone(), RenderTarget::Rust); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("|".to_string(), params_str), - "| { let ".to_string(), - ), - acc_ident.clone(), - ), - " = Rc::try_unwrap(".to_string(), - ), - acc_ident.clone(), - ), - ").unwrap_or_else(|rc| (*rc).clone()); ".to_string(), - ), - body_str, - ), - " }".to_string(), - ) - } +if (param_is_type_var.clone() || param_is_error.clone()) { + None } else { - v2_rt::concat( - v2_rt::concat(v2_rt::concat("|".to_string(), params_str), "| ".to_string()), - body_str, - ) + Some(render_rust_type(param_type.clone(), shared_types.clone(), source_indices.clone())) } - } - _ => emit_typed_expr( - lambda_expr.clone(), - registry, - &scope, - depth, - shared_types.clone(), - emit_info.clone(), - 1024, - ), - } +}, + _ => None, +}, + None => None, +}; +let fallback_type = match fallback_types.clone().get(idx.clone() as usize).cloned() { + Some(ty) => ty.clone(), + None => "_".to_string(), +}; +let spec = language_spec(RenderTarget::Rust); +let ident = emit_ident(param_name.clone(), RenderTarget::Rust); +match inferred_type.clone() { + Some(ty) => apply_type_template2(spec.annotations.clone().lambda_param_typed.clone(), ident.clone(), ty.clone()), + None => apply_type_template2(spec.annotations.clone().lambda_param_typed.clone(), ident.clone(), fallback_type.clone()), +} +}); } __result }) } -pub fn emit_rust_fold_method_call( - method_call_node: Rc, - fold_accumulator_type: Option>, - result_type: Option>, - receiver: &Rc, - args: &Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let elem_type_str = collection_element_type( - receiver.inferred.clone(), - shared_types.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let contextual_acc_type = match result_type.as_deref().cloned() { - Some(InferredNode::Resolved { - node: method_result_type, - .. - }) => Some(method_result_type.clone()), - _ => None, - }; - let acc_type_node = match fold_accumulator_type { - Some(acc_type) => { - let acc_children_have_unit = ({ - let mut __found = false; - for c in acc_type.children.clone().iter().cloned() { - if (is_unit_like(&c) || (c.ident_span.clone() == None)) { - __found = true; - break; - } - } - __found - } || { - let mut __found = false; - for c in acc_type.children.clone().iter().cloned() { - if { - let mut __found = false; - for gc in c.children.clone().iter().cloned() { - if (is_unit_like(&gc) || (gc.ident_span.clone() == None)) { - __found = true; - break; - } - } - __found - } { - __found = true; - break; - } - } - __found - }); - let is_under_resolved_map = (node_is_keyed_collection( - &acc_type, - scope.type_env.clone().source_indices.clone(), - ) && (((acc_type.children.clone().len() as i64) - == 0) - || acc_children_have_unit)); - let is_under_resolved_list = (node_is_element_collection( - &acc_type, - scope.type_env.clone().source_indices.clone(), - ) && ((acc_type.children.clone().len() as i64) == 0)); - let is_under_resolved_non_collection = ((!node_is_keyed_collection( - &acc_type, - scope.type_env.clone().source_indices.clone(), - ) && !node_is_element_collection( - &acc_type, - scope.type_env.clone().source_indices.clone(), - )) && !node_is_collection( - &acc_type, - scope.type_env.clone().source_indices.clone(), - )); - if ((is_under_resolved_map || is_under_resolved_list) - || is_under_resolved_non_collection) - { - match contextual_acc_type { - Some(concrete_type) => concrete_type.clone(), - None => acc_type.clone(), - } - } else { - acc_type.clone() - } - } - None => match contextual_acc_type { - Some(concrete_type) => concrete_type.clone(), - None => match args.clone().first().cloned() { - Some(init_arg) => { - if (arg_value(&init_arg).inferred.clone() != None) { - resolved_type(arg_value(&init_arg)) - } else { - type_variable_node("fold_accum".to_string()) - } - } - None => type_variable_node("fold_accum".to_string()), - }, - }, - }; - let acc_type_name = authored_name_at( - scope.type_env.clone().source_indices.clone(), - &acc_type_node, - ); - let fold_lambda_node = match args.clone().get(1 as usize).cloned() { - Some(a) => arg_value(&a), - None => type_variable_node("".to_string()), +pub fn emit_typed_collection_lambda(lambda_expr: &Rc, elem_type_str: String, registry: Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: Rc) -> String { + match (*lambda_expr.expr_data.clone()).clone() { + ExprData::ExprLambda => { + let ps = lambda_param_names_at(lambda_expr.clone(), scope.type_env.clone().source_indices.clone()); +let bd = lambda_body(lambda_expr.clone()); +let pn = Rc::new(lambda_expr.children.clone().iter().cloned().skip(1 as usize).collect::>()); +let param_strs = lambda_param_type_strs(ps.clone(), pn.clone(), Rc::new(vec![elem_type_str]), shared_types.clone(), scope.type_env.clone().source_indices.clone()); +let params_str = param_strs.join(&", ".to_string()); +let lambda_scope = lambda_scope_from_children(scope.clone(), ps.clone(), pn.clone()); +let body_str = emit_typed_expr(bd, registry, &lambda_scope, depth, shared_types.clone(), emit_info, 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat("|".to_string(), params_str), "| ".to_string()), body_str) +}, + _ => emit_typed_expr(lambda_expr.clone(), registry, &scope, depth, shared_types.clone(), emit_info, 1024), +} +} + +pub fn emit_typed_fold_lambda(lambda_expr: &Rc, acc_type_str: &String, elem_type_str: String, registry: Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + match (*lambda_expr.expr_data.clone()).clone() { + ExprData::ExprLambda => { + let ps = lambda_param_names_at(lambda_expr.clone(), scope.type_env.clone().source_indices.clone()); +let bd = lambda_body(lambda_expr.clone()); +let pn = Rc::new(lambda_expr.children.clone().iter().cloned().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())) { + "_".to_string() + } else { + acc_type_str.clone() }; - let acc_param_name = match (*fold_lambda_node.expr_data.clone()).clone() { - ExprData::ExprLambda => match lambda_param_names_at( - fold_lambda_node.clone(), - scope.type_env.clone().source_indices.clone(), - ) - .first() - .cloned() +let fallback_types = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(ps.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push(if (pair.0.clone() == 0) { + safe_acc_type.clone() + } else { + elem_type_str.clone() + }); } __result }); +let param_strs = lambda_param_type_strs(ps.clone(), Rc::new(vec![]), fallback_types, shared_types.clone(), scope.type_env.clone().source_indices.clone()); +let params_str = param_strs.join(&", ".to_string()); +let lambda_scope = lambda_scope_from_children(scope.clone(), ps.clone(), pn); +let body_str = emit_typed_expr(bd, registry, &lambda_scope, depth, shared_types.clone(), emit_info.clone(), 1024); +let acc_name = match ps.clone().first().cloned() { + Some(n) => n.clone(), + None => "".to_string(), +}; +let needs_unwrap = ((acc_name.clone().as_str() != "".to_string().as_str()) && emit_map_has(emit_info.owned_bindings.clone(), acc_name.clone())); +if needs_unwrap { { - Some(n) => n.clone(), - None => "".to_string(), - }, - _ => "".to_string(), - }; - let fold_proof = analyze_single_fold( - &method_call_node, - &scope.type_env.clone().source_indices.clone(), - ); - let structural_unwrap = ((fold_proof.eligible.clone() - && fold_proof.body_constructs_acc.clone()) - && fold_proof.safe_field_moves.clone()); - let structural_move = - (fold_proof.eligible.clone() && fold_proof.whole_acc_single_use.clone()); - let acc_unwrap = - (structural_unwrap && emit_map_has(shared_types.clone(), acc_type_name.clone())); - let fold_emit_info = if acc_unwrap { - match (*fold_lambda_node.expr_data.clone()).clone() { - ExprData::ExprLambda => { - let ps = lambda_param_names_at( - fold_lambda_node.clone(), - scope.type_env.clone().source_indices.clone(), - ); - match ps.first().cloned() { - Some(acc_name) => Rc::new(EmitGraphInfo { - type_summaries: emit_info.type_summaries.clone(), - recursive_type_set: emit_info.recursive_type_set.clone(), - fielded_variants: emit_info.fielded_variants.clone(), - shared_types: emit_info.shared_types.clone(), - ownership_index: emit_info.ownership_index.clone(), - movable: emit_info.movable.clone(), - variant_to_enum: emit_info.variant_to_enum.clone(), - owned_bindings: v2_rt::rc_map_insert( - emit_info.owned_bindings.clone(), - acc_name.clone(), - true, - ), - read_only_params_index: emit_info.read_only_params_index.clone(), - read_only_params: emit_info.read_only_params.clone(), - }), - None => emit_info.clone(), - } - } - _ => emit_info.clone(), - } + let acc_ident = emit_ident(acc_name.clone(), RenderTarget::Rust); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("|".to_string(), params_str), "| { let ".to_string()), acc_ident.clone()), " = Rc::try_unwrap(".to_string()), acc_ident.clone()), ").unwrap_or_else(|rc| (*rc).clone()); ".to_string()), body_str), " }".to_string()) +} } else { - if structural_move { - match (*fold_lambda_node.expr_data.clone()).clone() { - ExprData::ExprLambda => { - let ps = lambda_param_names_at( - fold_lambda_node.clone(), - scope.type_env.clone().source_indices.clone(), - ); - match ps.first().cloned() { - Some(acc_name) => Rc::new(EmitGraphInfo { - type_summaries: emit_info.type_summaries.clone(), - recursive_type_set: emit_info.recursive_type_set.clone(), - fielded_variants: emit_info.fielded_variants.clone(), - shared_types: emit_info.shared_types.clone(), - ownership_index: emit_info.ownership_index.clone(), - movable: v2_rt::rc_map_insert( - emit_info.movable.clone(), - acc_name.clone(), - true, - ), - variant_to_enum: emit_info.variant_to_enum.clone(), - 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(), - }), - None => emit_info.clone(), - } - } - _ => emit_info.clone(), - } + v2_rt::concat(v2_rt::concat(v2_rt::concat("|".to_string(), params_str), "| ".to_string()), body_str) + } +}, + _ => emit_typed_expr(lambda_expr.clone(), registry, &scope, depth, shared_types.clone(), emit_info.clone(), 1024), +} +} + +pub fn emit_rust_fold_method_call(method_call_node: Rc, fold_accumulator_type: Option>, result_type: Option>, receiver: &Rc, args: &Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let elem_type_str = collection_element_type(receiver.inferred.clone(), shared_types.clone(), &scope.type_env.clone().source_indices.clone()); +let contextual_acc_type = match result_type.as_deref().cloned() { + Some(InferredNode::Resolved { node: method_result_type, .. }) => Some(method_result_type.clone()), + _ => None, +}; +let acc_type_node = match fold_accumulator_type { + Some(acc_type) => { + let acc_children_have_unit = ({ let mut __found = false; for c in acc_type.children.clone().iter().cloned() { if (is_unit_like(&c) || (c.ident_span.clone() == None)) { __found = true; break; } } __found } || { let mut __found = false; for c in acc_type.children.clone().iter().cloned() { if { let mut __found = false; for gc in c.children.clone().iter().cloned() { if (is_unit_like(&gc) || (gc.ident_span.clone() == None)) { __found = true; break; } } __found } { __found = true; break; } } __found }); +let is_under_resolved_map = (node_is_keyed_collection(&acc_type, scope.type_env.clone().source_indices.clone()) && (((acc_type.children.clone().len() as i64) == 0) || acc_children_have_unit)); +let is_under_resolved_list = (node_is_element_collection(&acc_type, scope.type_env.clone().source_indices.clone()) && ((acc_type.children.clone().len() as i64) == 0)); +let is_under_resolved_non_collection = ((!node_is_keyed_collection(&acc_type, scope.type_env.clone().source_indices.clone()) && !node_is_element_collection(&acc_type, scope.type_env.clone().source_indices.clone())) && !node_is_collection(&acc_type, scope.type_env.clone().source_indices.clone())); +if ((is_under_resolved_map || is_under_resolved_list) || is_under_resolved_non_collection) { + match contextual_acc_type { + Some(concrete_type) => concrete_type.clone(), + None => acc_type.clone(), +} } else { - emit_info.clone() + acc_type.clone() } - }; - let acc_type_str = render_rust_type( - acc_type_node.clone(), - shared_types.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let is_bare_container = (((acc_type_node.children.clone().len() as i64) == 0) - && is_container_type(acc_type_name.clone())); - let lambda_acc_type_str = if is_bare_container { +}, + None => match contextual_acc_type { + Some(concrete_type) => concrete_type.clone(), + None => match args.clone().first().cloned() { + Some(init_arg) => if (arg_value(&init_arg).inferred.clone() != None) { + resolved_type(arg_value(&init_arg)) + } else { + type_variable_node("fold_accum".to_string()) + }, + None => type_variable_node("fold_accum".to_string()), +}, +}, +}; +let acc_type_name = authored_name_at(scope.type_env.clone().source_indices.clone(), &acc_type_node); +let fold_lambda_node = match args.clone().get(1 as usize).cloned() { + Some(a) => arg_value(&a), + None => type_variable_node("".to_string()), +}; +let acc_param_name = match (*fold_lambda_node.expr_data.clone()).clone() { + ExprData::ExprLambda => match lambda_param_names_at(fold_lambda_node.clone(), scope.type_env.clone().source_indices.clone()).first().cloned() { + Some(n) => n.clone(), + None => "".to_string(), +}, + _ => "".to_string(), +}; +let fold_proof = analyze_single_fold(&method_call_node, &scope.type_env.clone().source_indices.clone()); +let structural_unwrap = ((fold_proof.eligible.clone() && fold_proof.body_constructs_acc.clone()) && fold_proof.safe_field_moves.clone()); +let structural_move = (fold_proof.eligible.clone() && fold_proof.whole_acc_single_use.clone()); +let acc_unwrap = (structural_unwrap && emit_map_has(shared_types.clone(), acc_type_name.clone())); +let fold_emit_info = if acc_unwrap { + match (*fold_lambda_node.expr_data.clone()).clone() { + ExprData::ExprLambda => { + let ps = lambda_param_names_at(fold_lambda_node.clone(), scope.type_env.clone().source_indices.clone()); +match ps.first().cloned() { + Some(acc_name) => Rc::new(EmitGraphInfo { + type_summaries: emit_info.type_summaries.clone(), + recursive_type_set: emit_info.recursive_type_set.clone(), + fielded_variants: emit_info.fielded_variants.clone(), + shared_types: emit_info.shared_types.clone(), + ownership_index: emit_info.ownership_index.clone(), + movable: emit_info.movable.clone(), + variant_to_enum: emit_info.variant_to_enum.clone(), + owned_bindings: v2_rt::rc_map_insert(emit_info.owned_bindings.clone(), acc_name.clone(), true), + read_only_params_index: emit_info.read_only_params_index.clone(), + read_only_params: emit_info.read_only_params.clone(), +}), + None => emit_info.clone(), +} +}, + _ => emit_info.clone(), +} + } else { + if structural_move { + match (*fold_lambda_node.expr_data.clone()).clone() { + ExprData::ExprLambda => { + let ps = lambda_param_names_at(fold_lambda_node.clone(), scope.type_env.clone().source_indices.clone()); +match ps.first().cloned() { + Some(acc_name) => Rc::new(EmitGraphInfo { + type_summaries: emit_info.type_summaries.clone(), + recursive_type_set: emit_info.recursive_type_set.clone(), + fielded_variants: emit_info.fielded_variants.clone(), + shared_types: emit_info.shared_types.clone(), + ownership_index: emit_info.ownership_index.clone(), + movable: v2_rt::rc_map_insert(emit_info.movable.clone(), acc_name.clone(), true), + variant_to_enum: emit_info.variant_to_enum.clone(), + 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(), +}), + None => emit_info.clone(), +} +}, + _ => emit_info.clone(), +} + } else { + emit_info.clone() + } + }; +let acc_type_str = render_rust_type(acc_type_node.clone(), shared_types.clone(), scope.type_env.clone().source_indices.clone()); +let is_bare_container = (((acc_type_node.children.clone().len() as i64) == 0) && is_container_type(acc_type_name.clone())); +let lambda_acc_type_str = if is_bare_container { "_".to_string() } else { acc_type_str.clone() }; - let acc_has_unit_child = ({ - let mut __found = false; - for c in acc_type_node.children.clone().iter().cloned() { - if (is_unit_like(&c) || (c.ident_span.clone() == None)) { - __found = true; - break; - } - } - __found - } || { - let mut __found = false; - for c in acc_type_node.children.clone().iter().cloned() { - if { - let mut __found = false; - for gc in c.children.clone().iter().cloned() { - if (is_unit_like(&gc) || (gc.ident_span.clone() == None)) { - __found = true; - break; - } - } - __found - } { - __found = true; - break; - } - } - __found - }); - let init_str = match args.clone().first().cloned() { - Some(init_arg) => match (*arg_value(&init_arg).expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let init_func = expr_call_func_at( - arg_value(&init_arg), - 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())) - && !acc_has_unit_child) - { - { - let kv_type_str = rust_empty_map_kv_type_str( - &acc_type_node, - &shared_types, - &scope.type_env.clone().source_indices.clone(), - ); - if (kv_type_str.clone().as_str() != "".to_string().as_str()) { - v2_rt::concat( - v2_rt::concat( - "v2_rt::rc_empty_map::<".to_string(), - kv_type_str.clone(), - ), - ">()".to_string(), - ) - } else { - "Rc::new(HashMap::new()) /* BRIDGE: fold empty_map value type unresolved */".to_string() - } - } +let acc_has_unit_child = ({ let mut __found = false; for c in acc_type_node.children.clone().iter().cloned() { if (is_unit_like(&c) || (c.ident_span.clone() == None)) { __found = true; break; } } __found } || { let mut __found = false; for c in acc_type_node.children.clone().iter().cloned() { if { let mut __found = false; for gc in c.children.clone().iter().cloned() { if (is_unit_like(&gc) || (gc.ident_span.clone() == None)) { __found = true; break; } } __found } { __found = true; break; } } __found }); +let init_str = match args.clone().first().cloned() { + Some(init_arg) => match (*arg_value(&init_arg).expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { + let init_func = expr_call_func_at(arg_value(&init_arg), 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())) && !acc_has_unit_child) { + { + let kv_type_str = rust_empty_map_kv_type_str(&acc_type_node, &shared_types, &scope.type_env.clone().source_indices.clone()); +if (kv_type_str.clone().as_str() != "".to_string().as_str()) { + v2_rt::concat(v2_rt::concat("v2_rt::rc_empty_map::<".to_string(), kv_type_str.clone()), ">()".to_string()) } else { - if (init_func.clone().as_str() == "empty_map".to_string().as_str()) { - "Rc::new(HashMap::new()) /* BRIDGE: fold empty_map accumulator type unresolved */".to_string() - } else { - emit_typed_expr( - arg_value(&init_arg), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - fold_emit_info.clone(), - 1024, - ) - } + "Rc::new(HashMap::new()) /* BRIDGE: fold empty_map value type unresolved */".to_string() } - } - _ => emit_typed_expr( - arg_value(&init_arg), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - fold_emit_info.clone(), - 1024, - ), - }, - None => "compile_error!(\"missing fold init argument\")".to_string(), - }; - let fold_fn = match args.clone().get(1 as usize).cloned() { - Some(a) => emit_typed_fold_lambda( - &arg_value(&a), - &lambda_acc_type_str, - elem_type_str, - registry.clone(), - &scope, - depth.clone(), - &shared_types, - &fold_emit_info, - ), - None => "compile_error!(\"missing fold function argument\")".to_string(), - }; - let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - apply_type_template1(sharing.iter_owned.clone(), recv_str), - ".fold(".to_string(), - ), - init_str, - ), - ", ".to_string(), - ), - fold_fn, - ), - ")".to_string(), - ) - } } - -pub fn emit_rust_sort_by_method_call( - receiver: &Rc, - args: Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let elem_type_str = match receiver.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - let resolved = rt.clone(); - let elem = for_each_element_type_node( - resolved, - scope.type_env.clone().source_indices.clone(), - ); - let elem_is_type_var = if (elem.inferred.clone() != None) { - is_type_variable(elem.inferred.clone().clone().unwrap()) - } else { - false - }; - if ((elem.ident_span.clone() != None) && !elem_is_type_var) { - render_rust_type( - elem.clone(), - shared_types.clone(), - scope.type_env.clone().source_indices.clone(), - ) + } else { + if (init_func.clone().as_str() == "empty_map".to_string().as_str()) { + "Rc::new(HashMap::new()) /* BRIDGE: fold empty_map accumulator type unresolved */".to_string() } else { - "_".to_string() + emit_typed_expr(arg_value(&init_arg), registry.clone(), &scope, depth.clone(), shared_types.clone(), fold_emit_info.clone(), 1024) } } - _ => "_".to_string(), - }; - let sort_key_fn = match args.first().cloned() { - Some(a) => emit_typed_collection_lambda( - &arg_value(&a), - elem_type_str.clone(), - registry.clone(), - &scope, - depth.clone(), - &shared_types, - emit_info.clone(), - ), - None => "compile_error!(\"missing sort_by key function argument\")".to_string(), - }; - let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - 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()) { +}, + _ => emit_typed_expr(arg_value(&init_arg), registry.clone(), &scope, depth.clone(), shared_types.clone(), fold_emit_info.clone(), 1024), +}, + None => "compile_error!(\"missing fold init argument\")".to_string(), +}; +let fold_fn = match args.clone().get(1 as usize).cloned() { + Some(a) => emit_typed_fold_lambda(&arg_value(&a), &lambda_acc_type_str, elem_type_str, registry.clone(), &scope, depth.clone(), &shared_types, &fold_emit_info), + None => "compile_error!(\"missing fold function argument\")".to_string(), +}; +let sharing = language_spec(RenderTarget::Rust).sharing.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(apply_type_template1(sharing.iter_owned.clone(), recv_str), ".fold(".to_string()), init_str), ", ".to_string()), fold_fn), ")".to_string()) +} +} + +pub fn emit_rust_sort_by_method_call(receiver: &Rc, args: Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let elem_type_str = match receiver.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => { + let resolved = rt.clone(); +let elem = for_each_element_type_node(resolved, scope.type_env.clone().source_indices.clone()); +let elem_is_type_var = if (elem.inferred.clone() != None) { + is_type_variable(elem.inferred.clone().clone().unwrap()) + } else { + false + }; +if ((elem.ident_span.clone() != None) && !elem_is_type_var) { + render_rust_type(elem.clone(), shared_types.clone(), scope.type_env.clone().source_indices.clone()) + } else { + "_".to_string() + } +}, + _ => "_".to_string(), +}; +let sort_key_fn = match args.first().cloned() { + Some(a) => emit_typed_collection_lambda(&arg_value(&a), elem_type_str.clone(), registry.clone(), &scope, depth.clone(), &shared_types, emit_info.clone()), + None => "compile_error!(\"missing sort_by key function argument\")".to_string(), +}; +let sharing = language_spec(RenderTarget::Rust).sharing.clone(); +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()) { v2_rt::concat(v2_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 { v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_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()) } - } +} } -pub fn emit_rust_map_method_call( - receiver: &Rc, - args: &Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let first_arg_str = emit_typed_first_arg( - args.clone(), - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - let recv_is_optional = match receiver.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.return_cardinality.clone() == Cardinality::CardOptional) - } - _ => false, - }; - if recv_is_optional { +pub fn emit_rust_map_method_call(receiver: &Rc, args: &Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let first_arg_str = emit_typed_first_arg(args.clone(), registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()); +let recv_is_optional = match receiver.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (rt.return_cardinality.clone() == Cardinality::CardOptional), + _ => false, +}; +if recv_is_optional { match args.clone().first().cloned() { - Some(a) => match (*arg_value(&a).expr_data.clone()).clone() { - ExprData::ExprLambda => { - let bd = match arg_value(&a).children.clone().first().cloned() { - Some(v) => v.clone(), - None => arg_value(&a), - }; - let ps = lambda_param_names_at( - arg_value(&a), - scope.type_env.clone().source_indices.clone(), - ); - let dag_name = match ps.clone().first().cloned() { - Some(n) => n.clone(), - None => "__x".to_string(), - }; - let p = emit_ident(dag_name, RenderTarget::Rust); - let lambda_scope = lambda_scope_from_children( - scope.clone(), - ps.clone(), - Rc::new( - arg_value(&a) - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ); - let body_str = emit_typed_expr( - bd, - registry.clone(), - &lambda_scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(recv_str, ".map(|".to_string()), p), - "| ".to_string(), - ), - body_str, - ), - ")".to_string(), - ) - } - _ => v2_rt::concat( - v2_rt::concat(v2_rt::concat(recv_str, ".map(".to_string()), first_arg_str), - ")".to_string(), - ), - }, - None => v2_rt::concat( - v2_rt::concat(v2_rt::concat(recv_str, ".map(".to_string()), first_arg_str), - ")".to_string(), - ), - } + Some(a) => match (*arg_value(&a).expr_data.clone()).clone() { + ExprData::ExprLambda => { + let bd = match arg_value(&a).children.clone().first().cloned() { + Some(v) => v.clone(), + None => arg_value(&a), +}; +let ps = lambda_param_names_at(arg_value(&a), scope.type_env.clone().source_indices.clone()); +let dag_name = match ps.clone().first().cloned() { + Some(n) => n.clone(), + None => "__x".to_string(), +}; +let p = emit_ident(dag_name, RenderTarget::Rust); +let lambda_scope = lambda_scope_from_children(scope.clone(), ps.clone(), Rc::new(arg_value(&a).children.clone().iter().cloned().skip(1 as usize).collect::>())); +let body_str = emit_typed_expr(bd, registry.clone(), &lambda_scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(recv_str, ".map(|".to_string()), p), "| ".to_string()), body_str), ")".to_string()) +}, + _ => v2_rt::concat(v2_rt::concat(v2_rt::concat(recv_str, ".map(".to_string()), first_arg_str), ")".to_string()), +}, + None => v2_rt::concat(v2_rt::concat(v2_rt::concat(recv_str, ".map(".to_string()), first_arg_str), ")".to_string()), +} } else { { let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - let iter_str = apply_type_template1(sharing.iter_owned.clone(), recv_str); - match args.clone().first().cloned() { - Some(a) => { - match (*arg_value(&a).expr_data.clone()).clone() { - ExprData::ExprLambda => { - let bd = match arg_value(&a).children.clone().first().cloned() { - Some(v) => v.clone(), - None => arg_value(&a), - }; - let ps = lambda_param_names_at( - arg_value(&a), - scope.type_env.clone().source_indices.clone(), - ); - let dag_name = match ps.clone().first().cloned() { - Some(n) => n.clone(), - None => "__x".to_string(), - }; - let p = emit_ident(dag_name, RenderTarget::Rust); - let lambda_scope = lambda_scope_from_children( - scope.clone(), - ps.clone(), - Rc::new( - arg_value(&a) - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ); - let body_str = emit_typed_expr( - bd, - registry.clone(), - &lambda_scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Rc::new({ let mut __result = Vec::new(); for ".to_string(), p), " in ".to_string()), iter_str), " { __result.push(".to_string()), body_str), "); } __result })".to_string()) - } - _ => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), iter_str), - ".map(".to_string(), - ), - first_arg_str, - ), - ").collect::>())".to_string(), - ), - } - } - None => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), iter_str), - ".map(".to_string(), - ), - first_arg_str, - ), - ").collect::>())".to_string(), - ), - } - } +let iter_str = apply_type_template1(sharing.iter_owned.clone(), recv_str); +match args.clone().first().cloned() { + Some(a) => match (*arg_value(&a).expr_data.clone()).clone() { + ExprData::ExprLambda => { + let bd = match arg_value(&a).children.clone().first().cloned() { + Some(v) => v.clone(), + None => arg_value(&a), +}; +let ps = lambda_param_names_at(arg_value(&a), scope.type_env.clone().source_indices.clone()); +let dag_name = match ps.clone().first().cloned() { + Some(n) => n.clone(), + None => "__x".to_string(), +}; +let p = emit_ident(dag_name, RenderTarget::Rust); +let lambda_scope = lambda_scope_from_children(scope.clone(), ps.clone(), Rc::new(arg_value(&a).children.clone().iter().cloned().skip(1 as usize).collect::>())); +let body_str = emit_typed_expr(bd, registry.clone(), &lambda_scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Rc::new({ let mut __result = Vec::new(); for ".to_string(), p), " in ".to_string()), iter_str), " { __result.push(".to_string()), body_str), "); } __result })".to_string()) +}, + _ => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), iter_str), ".map(".to_string()), first_arg_str), ").collect::>())".to_string()), +}, + None => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), iter_str), ".map(".to_string()), first_arg_str), ").collect::>())".to_string()), +} +} } - } +} } -pub fn emit_rust_higher_order_method( - ho_spec: &Rc, - receiver: Rc, - args: &Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_rust_higher_order_method(ho_spec: &Rc, receiver: Rc, args: &Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { { let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - let recv_str = emit_typed_expr( - receiver, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let first_arg_str = emit_typed_first_arg( - args.clone(), - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - let iter_str = apply_type_template1(sharing.iter_owned.clone(), recv_str); - match args.clone().first().cloned() { - Some(a) => match (*arg_value(&a).expr_data.clone()).clone() { - ExprData::ExprLambda => { - let bd = match arg_value(&a).children.clone().first().cloned() { - Some(v) => v.clone(), - None => arg_value(&a), - }; - let ps = lambda_param_names_at( - arg_value(&a), - scope.type_env.clone().source_indices.clone(), - ); - let dag_name = match ps.clone().first().cloned() { - Some(n) => n.clone(), - None => "__x".to_string(), - }; - let p = emit_ident(dag_name, RenderTarget::Rust); - let lambda_scope = lambda_scope_from_children( - scope.clone(), - ps.clone(), - Rc::new( - arg_value(&a) - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ); - let body_str = emit_typed_expr( - bd, - registry.clone(), - &lambda_scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let inner_iter = apply_type_template1( - sharing.iter_owned.clone(), - v2_rt::concat( - v2_rt::concat("(*".to_string(), body_str.clone()), - ")".to_string(), - ), - ); - let bindings = v2_rt::rc_map_insert( - v2_rt::rc_map_insert( - v2_rt::rc_map_insert( - seed_bindings("param".to_string(), p), - "body".to_string(), - body_str.clone(), - ), - "iter".to_string(), - iter_str, - ), - "inner_iter".to_string(), - inner_iter, - ); - let raw = apply_named_template(ho_spec.inline_template.clone(), &bindings); - if ho_spec.wraps_in_sharing.clone() { - v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) - } else { - raw - } - } - _ => { - let bindings = v2_rt::rc_map_insert( - seed_bindings("iter".to_string(), iter_str), - "arg".to_string(), - first_arg_str, - ); - let raw = apply_named_template(ho_spec.fn_ref_template.clone(), &bindings); - if ho_spec.wraps_in_sharing.clone() { - v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) - } else { - raw - } - } - }, - None => { - let bindings = v2_rt::rc_map_insert( - seed_bindings("iter".to_string(), iter_str), - "arg".to_string(), - first_arg_str, - ); - let raw = apply_named_template(ho_spec.fn_ref_template.clone(), &bindings); - if ho_spec.wraps_in_sharing.clone() { - v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) - } else { - raw - } +let recv_str = emit_typed_expr(receiver, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let first_arg_str = emit_typed_first_arg(args.clone(), registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()); +let iter_str = apply_type_template1(sharing.iter_owned.clone(), recv_str); +match args.clone().first().cloned() { + Some(a) => match (*arg_value(&a).expr_data.clone()).clone() { + ExprData::ExprLambda => { + let bd = match arg_value(&a).children.clone().first().cloned() { + Some(v) => v.clone(), + None => arg_value(&a), +}; +let ps = lambda_param_names_at(arg_value(&a), scope.type_env.clone().source_indices.clone()); +let dag_name = match ps.clone().first().cloned() { + Some(n) => n.clone(), + None => "__x".to_string(), +}; +let p = emit_ident(dag_name, RenderTarget::Rust); +let lambda_scope = lambda_scope_from_children(scope.clone(), ps.clone(), Rc::new(arg_value(&a).children.clone().iter().cloned().skip(1 as usize).collect::>())); +let body_str = emit_typed_expr(bd, registry.clone(), &lambda_scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let inner_iter = apply_type_template1(sharing.iter_owned.clone(), v2_rt::concat(v2_rt::concat("(*".to_string(), body_str.clone()), ")".to_string())); +let bindings = v2_rt::rc_map_insert(v2_rt::rc_map_insert(v2_rt::rc_map_insert(seed_bindings("param".to_string(), p), "body".to_string(), body_str.clone()), "iter".to_string(), iter_str), "inner_iter".to_string(), inner_iter); +let raw = apply_named_template(ho_spec.inline_template.clone(), &bindings); +if ho_spec.wraps_in_sharing.clone() { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) + } else { + raw } - } - } +}, + _ => { + let bindings = v2_rt::rc_map_insert(seed_bindings("iter".to_string(), iter_str), "arg".to_string(), first_arg_str); +let raw = apply_named_template(ho_spec.fn_ref_template.clone(), &bindings); +if ho_spec.wraps_in_sharing.clone() { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) + } else { + raw + } +}, +}, + None => { + let bindings = v2_rt::rc_map_insert(seed_bindings("iter".to_string(), iter_str), "arg".to_string(), first_arg_str); +let raw = apply_named_template(ho_spec.fn_ref_template.clone(), &bindings); +if ho_spec.wraps_in_sharing.clone() { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) + } else { + raw + } +}, +} +} } -pub fn emit_rust_get_method_call( - receiver: &Rc, - args: Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let index_str = match args.first().cloned() { - Some(a) => emit_typed_expr( - arg_value(&a), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - None => "compile_error!(\"get method missing index\")".to_string(), - }; - let receiver_resolved = match receiver.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { .. }) => true, - _ => false, - }; - if is_map_typed_expr( - receiver.clone(), - scope.type_env.clone().source_indices.clone(), - ) { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("v2_rt::map_get(&".to_string(), recv_str), - ", ".to_string(), - ), - index_str, - ), - ")".to_string(), - ) +pub fn emit_rust_get_method_call(receiver: &Rc, args: Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let index_str = match args.first().cloned() { + Some(a) => emit_typed_expr(arg_value(&a), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024), + None => "compile_error!(\"get method missing index\")".to_string(), +}; +let receiver_resolved = match receiver.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { .. }) => true, + _ => false, +}; +if is_map_typed_expr(receiver.clone(), scope.type_env.clone().source_indices.clone()) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("v2_rt::map_get(&".to_string(), recv_str), ", ".to_string()), index_str), ")".to_string()) } else { if receiver_resolved { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(recv_str, ".get((".to_string()), index_str), - ") as usize)".to_string(), - ), - clone_iterator_suffix(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(recv_str, ".get((".to_string()), index_str), ") as usize)".to_string()), clone_iterator_suffix()) } else { "compile_error!(\"get: receiver type unresolved\")".to_string() } } - } +} } -pub fn emit_rust_with_method_call( - receiver: &Rc, - args: &Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let base_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let type_name = match receiver.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - let rt_is_error = if (rt.inferred.clone() != None) { - is_compiler_error(rt.inferred.clone().clone().unwrap()) - } else { - false - }; - if (rt_is_error || (rt.ident_span.clone() == None)) { - "compile_error!(\"with method missing resolved record type\")".to_string() - } else { - authored_name_at(scope.type_env.clone().source_indices.clone(), &rt) - } +pub fn emit_rust_with_method_call(receiver: &Rc, args: &Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let base_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let type_name = match receiver.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => { + let rt_is_error = if (rt.inferred.clone() != None) { + is_compiler_error(rt.inferred.clone().clone().unwrap()) + } else { + false + }; +if (rt_is_error || (rt.ident_span.clone() == None)) { + "compile_error!(\"with method missing resolved record type\")".to_string() + } else { + authored_name_at(scope.type_env.clone().source_indices.clone(), &rt) } - _ => "compile_error!(\"with method missing resolved record type\")".to_string(), - }; - if ((args.clone().len() as i64) == 0) { - return "compile_error!(\"with method missing update record\")".to_string(); +}, + _ => "compile_error!(\"with method missing resolved record type\")".to_string(), +}; +if ((args.clone().len() as i64) == 0) { + return "compile_error!(\"with method missing update record\")".to_string() } - let update_arg = arg_value(&args.clone().first().cloned().clone().unwrap()); - let field_strs = match (*update_arg.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => Rc::new({ - let mut __result = Vec::new(); - for f in update_arg.children.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - field_init_node_name_at( - f.clone(), - scope.type_env.clone().source_indices.clone(), - ), - RenderTarget::Rust, - ), - ": ".to_string(), - ), - emit_typed_expr( - field_init_node_value(&f), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - )); - } - __result - }), - _ => Rc::new(vec![emit_typed_expr( - update_arg.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - )]), - }; - let fields_str = field_strs.join(&", ".to_string()); - let needs_rc = emit_map_has(shared_types.clone(), type_name.clone()); - let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - let spread = if needs_rc.clone() { +let update_arg = arg_value(&args.clone().first().cloned().clone().unwrap()); +let field_strs = match (*update_arg.expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => Rc::new({ let mut __result = Vec::new(); for f in update_arg.children.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(field_init_node_name_at(f.clone(), scope.type_env.clone().source_indices.clone()), RenderTarget::Rust), ": ".to_string()), emit_typed_expr(field_init_node_value(&f), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024))); } __result }), + _ => Rc::new(vec![emit_typed_expr(update_arg.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024)]), +}; +let fields_str = field_strs.join(&", ".to_string()); +let needs_rc = emit_map_has(shared_types.clone(), type_name.clone()); +let sharing = language_spec(RenderTarget::Rust).sharing.clone(); +let spread = if needs_rc.clone() { apply_type_template1(sharing.deref_clone.clone(), base_str) } else { apply_type_template1(sharing.clone_value.clone(), base_str) }; - let raw = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(type_name.clone(), " { ".to_string()), - fields_str, - ), - ", ..".to_string(), - ), - spread, - ), - " }".to_string(), - ); - if needs_rc.clone() { +let raw = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(type_name.clone(), " { ".to_string()), fields_str), ", ..".to_string()), spread), " }".to_string()); +if needs_rc.clone() { v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) } else { raw } - } +} } -pub fn emit_rust_first_method_call( - receiver: &Rc, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_rust_first_method_call(receiver: &Rc, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { match (*receiver.expr_data.clone()).clone() { - ExprData::ExprMethodCall { .. } => { - if (expr_method_name_at( - receiver.clone(), - scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == "skip".to_string().as_str()) - { - { - let skip_recv = method_receiver(receiver.clone()); - let skip_args = method_arg_nodes(receiver.clone()); - let recv_str = emit_typed_expr( - skip_recv, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let arg_str = emit_typed_first_arg( - skip_args, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - v2_rt::concat( - v2_rt::concat(v2_rt::concat(recv_str, ".get(".to_string()), arg_str), - " as usize).cloned()".to_string(), - ) - } - } else { - { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat(recv_str, ".first().cloned()".to_string()) - } - } - } - _ => { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat(recv_str, ".first().cloned()".to_string()) - } - } + ExprData::ExprMethodCall { .. } => if (expr_method_name_at(receiver.clone(), scope.type_env.clone().source_indices.clone()).as_str() == "skip".to_string().as_str()) { + { + let skip_recv = method_receiver(receiver.clone()); +let skip_args = method_arg_nodes(receiver.clone()); +let recv_str = emit_typed_expr(skip_recv, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let arg_str = emit_typed_first_arg(skip_args, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(recv_str, ".get(".to_string()), arg_str), " as usize).cloned()".to_string()) +} + } else { + { + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(recv_str, ".first().cloned()".to_string()) +} + }, + _ => { + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(recv_str, ".first().cloned()".to_string()) +}, +} } -pub fn emit_rust_generic_method_call( - method_name: String, - receiver: Rc, - args: Rc>>, - result_type: Option>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_rust_generic_method_call(method_name: String, receiver: Rc, args: Rc>>, result_type: Option>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { { let function_name = method_name; - let recv_str = if rust_runtime_bridge_passes_receiver_by_ref(function_name.clone()) { - v2_rt::concat( - "&".to_string(), - emit_typed_expr_base( - &receiver, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ), - ) - } else { - emit_cloned_arg( - receiver, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ) +let recv_str = if rust_runtime_bridge_passes_receiver_by_ref(function_name.clone()) { + v2_rt::concat("&".to_string(), emit_typed_expr_base(&receiver, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone())) + } else { + emit_cloned_arg(receiver, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()) }; - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in args.iter().cloned() { - __result.push(emit_cloned_arg( - arg_value(&a), - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - )); - } - __result - }); - let all_strs = v2_rt::concat(Rc::new(vec![recv_str]), arg_strs); - let bridge_name = rust_runtime_bridge_name(function_name.clone()); - let lowered = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "v2_rt::".to_string(), - emit_ident(bridge_name, RenderTarget::Rust), - ), - "(".to_string(), - ), - all_strs.join(&", ".to_string()), - ), - ")".to_string(), - ); - if rust_runtime_bridge_wraps_collection_result_in_rc(&function_name) { - v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), lowered), - ")".to_string(), - ) +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in args.iter().cloned() { __result.push(emit_cloned_arg(arg_value(&a), registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone())); } __result }); +let all_strs = v2_rt::concat(Rc::new(vec![recv_str]), arg_strs); +let bridge_name = rust_runtime_bridge_name(function_name.clone()); +let lowered = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("v2_rt::".to_string(), emit_ident(bridge_name, RenderTarget::Rust)), "(".to_string()), all_strs.join(&", ".to_string())), ")".to_string()); +if rust_runtime_bridge_wraps_collection_result_in_rc(&function_name) { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), lowered), ")".to_string()) } else { lowered } - } +} } -pub fn emit_typed_method_call( - method_call_node: Rc, - receiver: &Rc, - method: String, - args: &Rc>>, - result_type: Option>, - method_semantics: &Option>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_typed_method_call(method_call_node: Rc, receiver: &Rc, method: String, args: &Rc>>, result_type: Option>, method_semantics: &Option>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { if (method_semantics.clone() != None) { match (*method_semantics.clone().unwrap()).clone() { - MethodSemantics::ServiceMethodSemantics { - service_name: svc_name, - op_params, - .. - } => { - let var_name = service_var_name(svc_name.clone()); - let si = scope.type_env.clone().source_indices.clone(); - let filled_args = fill_op_default_args( - &args, - op_params.clone(), - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - let optional_param_set = Rc::new({ - let mut __result = Vec::new(); - for p in op_params.clone().iter().cloned() { - if (param_node_type_expr(&p).return_cardinality.clone() - == Cardinality::CardOptional) - { - __result.push(p); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, p: Rc| { - v2_rt::rc_map_insert(acc, param_node_name_at(p.clone(), si.clone()), true) - }, - ); - let json_param_set = Rc::new({ - let mut __result = Vec::new(); - for p in op_params.clone().iter().cloned() { - if (coerce_primitive_type( - RenderTarget::Rust, - authored_name_at(si.clone(), ¶m_node_type_expr(&p)), - ) - .as_str() - == "serde_json::Value".to_string().as_str()) - { - __result.push(p); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, p: Rc| { - v2_rt::rc_map_insert(acc, param_node_name_at(p.clone(), si.clone()), true) - }, - ); - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in filled_args.iter().cloned() { - __result.push({ - let arg_str = emit_typed_expr( - arg_value(&a), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let aname = match arg_name_at(a.clone(), si.clone()) { - Some(n) => n.clone(), - None => "".to_string(), - }; - let param_is_json = match v2_rt::map_get(&json_param_set, aname.clone()) - { - Some(_) => true, - None => false, - }; - let param_is_optional = - match v2_rt::map_get(&optional_param_set, aname.clone()) { - Some(_) => true, - None => false, - }; - let needs_optional = (param_is_optional.clone() - && (is_already_optional( - &arg_value(&a), - emit_info.clone(), - &scope, - ) == false)); - let coerced = if (param_is_json.clone() - && is_string_typed_expr(arg_value(&a), si.clone())) - { - v2_rt::concat( - v2_rt::concat( - "serde_json::from_str(&".to_string(), - arg_str.clone(), - ), - ").unwrap()".to_string(), - ) - } else { - arg_str.clone() - }; - if needs_optional.clone() { - v2_rt::concat( - v2_rt::concat("Some(".to_string(), coerced.clone()), - ")".to_string(), - ) - } else { - coerced.clone() - } - }); - } - __result - }); - let args_str = arg_strs.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(var_name, ".".to_string()), - emit_ident(method, RenderTarget::Rust), - ), - "(".to_string(), - ), - args_str, - ), - ").await?".to_string(), - ) - } - MethodSemantics::AlgebraMethodSemantics { - method_def, - fold_accumulator_type, - .. - } => { - let method_name = - authored_name_at(scope.type_env.clone().source_indices.clone(), &method_def); - if (method_name.clone().as_str() == "fold".to_string().as_str()) { - emit_rust_fold_method_call( - method_call_node, - fold_accumulator_type.clone(), - result_type, - &receiver, - &args, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ) + MethodSemantics::ServiceMethodSemantics { service_name: svc_name, op_params, .. } => { + let var_name = service_var_name(svc_name.clone()); +let si = scope.type_env.clone().source_indices.clone(); +let filled_args = fill_op_default_args(&args, op_params.clone(), registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()); +let optional_param_set = Rc::new({ let mut __result = Vec::new(); for p in op_params.clone().iter().cloned() { if (param_node_type_expr(&p).return_cardinality.clone() == Cardinality::CardOptional) { __result.push(p); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, p: Rc| v2_rt::rc_map_insert(acc, param_node_name_at(p.clone(), si.clone()), true)); +let json_param_set = Rc::new({ let mut __result = Vec::new(); for p in op_params.clone().iter().cloned() { if (coerce_primitive_type(RenderTarget::Rust, authored_name_at(si.clone(), ¶m_node_type_expr(&p))).as_str() == "serde_json::Value".to_string().as_str()) { __result.push(p); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, p: Rc| v2_rt::rc_map_insert(acc, param_node_name_at(p.clone(), si.clone()), true)); +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in filled_args.iter().cloned() { __result.push({ + let arg_str = emit_typed_expr(arg_value(&a), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let aname = match arg_name_at(a.clone(), si.clone()) { + Some(n) => n.clone(), + None => "".to_string(), +}; +let param_is_json = match v2_rt::map_get(&json_param_set, aname.clone()) { + Some(_) => true, + None => false, +}; +let param_is_optional = match v2_rt::map_get(&optional_param_set, aname.clone()) { + Some(_) => true, + None => false, +}; +let needs_optional = (param_is_optional.clone() && (is_already_optional(&arg_value(&a), emit_info.clone(), &scope) == false)); +let coerced = if (param_is_json.clone() && is_string_typed_expr(arg_value(&a), si.clone())) { + v2_rt::concat(v2_rt::concat("serde_json::from_str(&".to_string(), arg_str.clone()), ").unwrap()".to_string()) + } else { + arg_str.clone() + }; +if needs_optional.clone() { + v2_rt::concat(v2_rt::concat("Some(".to_string(), coerced.clone()), ")".to_string()) + } else { + coerced.clone() + } +}); } __result }); +let args_str = arg_strs.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(var_name, ".".to_string()), emit_ident(method, RenderTarget::Rust)), "(".to_string()), args_str), ").await?".to_string()) +}, + MethodSemantics::AlgebraMethodSemantics { method_def, fold_accumulator_type, .. } => { + let method_name = authored_name_at(scope.type_env.clone().source_indices.clone(), &method_def); +if (method_name.clone().as_str() == "fold".to_string().as_str()) { + emit_rust_fold_method_call(method_call_node, fold_accumulator_type.clone(), result_type, &receiver, &args, ®istry, &scope, depth.clone(), &shared_types, &emit_info) + } else { + if (method_name.clone().as_str() == "sort_by".to_string().as_str()) { + emit_rust_sort_by_method_call(&receiver, args.clone(), ®istry, &scope, depth.clone(), &shared_types, &emit_info) } else { - if (method_name.clone().as_str() == "sort_by".to_string().as_str()) { - emit_rust_sort_by_method_call( - &receiver, - args.clone(), - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ) + if (method_name.clone().as_str() == "map".to_string().as_str()) { + emit_rust_map_method_call(&receiver, &args, ®istry, &scope, depth.clone(), &shared_types, &emit_info) } else { - if (method_name.clone().as_str() == "map".to_string().as_str()) { - emit_rust_map_method_call( - &receiver, - &args, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ) + 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()) { __result.push(s); } } __result }).first().cloned() { + Some(ho_spec) => emit_rust_higher_order_method(&ho_spec, receiver.clone(), &args, ®istry, &scope, depth.clone(), &shared_types, &emit_info), + None => if (method_name.clone().as_str() == "get".to_string().as_str()) { + emit_rust_get_method_call(&receiver, args.clone(), ®istry, &scope, depth.clone(), &shared_types, &emit_info) } else { - 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()) - { - __result.push(s); - } - } - __result - }) - .first() - .cloned() - { - Some(ho_spec) => emit_rust_higher_order_method( - &ho_spec, - receiver.clone(), - &args, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ), - None => { - if (method_name.clone().as_str() == "get".to_string().as_str()) - { - emit_rust_get_method_call( - &receiver, - args.clone(), - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ) - } else { - if (method_name.clone().as_str() - == "with".to_string().as_str()) + if (method_name.clone().as_str() == "with".to_string().as_str()) { + emit_rust_with_method_call(&receiver, &args, ®istry, &scope, depth.clone(), &shared_types, &emit_info) + } else { + if (method_name.clone().as_str() == "string_contains".to_string().as_str()) { + emit_rust_generic_method_call("string_contains".to_string(), receiver.clone(), args.clone(), result_type, ®istry, &scope, depth.clone(), &shared_types, &emit_info) + } else { + if (method_name.clone().as_str() == "concat".to_string().as_str()) { { - emit_rust_with_method_call( - &receiver, - &args, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ) + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in args.clone().iter().cloned() { __result.push(emit_typed_expr(arg_value(&a), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024)); } __result }); +let all_arg_strs = v2_rt::concat(Rc::new(vec![recv_str]), arg_strs); +emit_nested_rt_concat(all_arg_strs, "".to_string(), shared_types.clone()) +} + } else { + if (method_name.clone().as_str() == "first".to_string().as_str()) { + emit_rust_first_method_call(&receiver, ®istry, &scope, depth.clone(), &shared_types, &emit_info) } else { - if (method_name.clone().as_str() - == "string_contains".to_string().as_str()) { - emit_rust_generic_method_call( - "string_contains".to_string(), - receiver.clone(), - args.clone(), - result_type, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ) - } else { - if (method_name.clone().as_str() - == "concat".to_string().as_str()) - { - { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in args.clone().iter().cloned() { - __result.push(emit_typed_expr( - arg_value(&a), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - )); - } - __result - }); - let all_arg_strs = v2_rt::concat( - Rc::new(vec![recv_str]), - arg_strs, - ); - emit_nested_rt_concat( - all_arg_strs, - "".to_string(), - shared_types.clone(), - ) - } - } else { - if (method_name.clone().as_str() - == "first".to_string().as_str()) - { - emit_rust_first_method_call( - &receiver, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ) - } else { - { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let first_arg_str = - emit_typed_first_arg( - args.clone(), - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - match v2_rt::map_get( - &rust_method_template_emit(), - method_name.clone(), - ) { - Some(tmpl) => { - let bindings = - v2_rt::rc_map_insert( - seed_bindings( - "recv".to_string(), - recv_str, - ), - "arg".to_string(), - first_arg_str, - ); - let raw = apply_named_template( - tmpl.clone(), - &bindings, - ); - if rust_runtime_bridge_wraps_collection_result_in_rc(&method_name) { + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let first_arg_str = emit_typed_first_arg(args.clone(), registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()); +match v2_rt::map_get(&rust_method_template_emit(), method_name.clone()) { + Some(tmpl) => { + let bindings = v2_rt::rc_map_insert(seed_bindings("recv".to_string(), recv_str), "arg".to_string(), first_arg_str); +let raw = apply_named_template(tmpl.clone(), &bindings); +if rust_runtime_bridge_wraps_collection_result_in_rc(&method_name) { v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) } else { raw } - } - None => { - emit_rust_generic_method_call( - method_name.clone(), - receiver.clone(), - args.clone(), - result_type, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - ) - } - } - } - } - } - } +}, + None => emit_rust_generic_method_call(method_name.clone(), receiver.clone(), args.clone(), result_type, ®istry, &scope, depth.clone(), &shared_types, &emit_info), +} +} } } } } - } + }, +} } } } - MethodSemantics::PlainMethodSemantics => { - let recv_str = emit_typed_expr( - receiver.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let arg_strs = Rc::new({ - let mut __result = Vec::new(); - for a in args.clone().iter().cloned() { - __result.push(emit_typed_expr( - arg_value(&a), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - )); - } - __result - }); - let args_str = arg_strs.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(recv_str, ".".to_string()), - emit_ident(method, RenderTarget::Rust), - ), - "(".to_string(), - ), - args_str, - ), - ")".to_string(), - ) - } - } +}, + MethodSemantics::PlainMethodSemantics => { + let recv_str = emit_typed_expr(receiver.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let arg_strs = Rc::new({ let mut __result = Vec::new(); for a in args.clone().iter().cloned() { __result.push(emit_typed_expr(arg_value(&a), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024)); } __result }); +let args_str = arg_strs.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(recv_str, ".".to_string()), emit_ident(method, RenderTarget::Rust)), "(".to_string()), args_str), ")".to_string()) +}, +} } else { "compile_error!(\"method call missing reconcile semantics\")".to_string() } } -pub fn emit_typed_first_arg( - args: Rc>>, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_typed_first_arg(args: Rc>>, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match args.first().cloned() { - Some(a) => emit_typed_expr( - arg_value(&a), - registry, - &scope, - depth, - shared_types, - emit_info, - 1024, - ), - None => "compile_error!(\"missing method argument\")".to_string(), - } + Some(a) => emit_typed_expr(arg_value(&a), registry, &scope, depth, shared_types, emit_info, 1024), + None => "compile_error!(\"missing method argument\")".to_string(), +} } -pub fn emit_typed_match( - scrutinee: &Rc, - arms: &Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let scrut_str = emit_typed_expr( - scrutinee.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let scrut_type = match scrutinee.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - let is_optional = (rt.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { - authored_name_at( - scope.type_env.clone().source_indices.clone(), - &with_required_cardinality(&rt), - ) - } else { - authored_name_at(scope.type_env.clone().source_indices.clone(), &rt) - } - } - _ => "".to_string(), - }; - let rc_match = analyze_rc_match( - &scrutinee, - arms.clone(), - scrut_type.clone(), - &shared_types, - emit_info.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let match_result_type = match arms.clone().first().cloned() { - Some(first_arm) => resolved_type(arm_body(&first_arm)), - None => type_variable_node("match_result".to_string()), - }; - let arm_strs = Rc::new({ - let mut __result = Vec::new(); - for arm in arms.clone().iter().cloned() { - __result.push(emit_typed_match_arm( - &arm, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - &scrut_type, - match_result_type.clone(), - false, - )); +pub fn emit_typed_match(scrutinee: &Rc, arms: &Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let scrut_str = emit_typed_expr(scrutinee.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let scrut_type = match scrutinee.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => { + let is_optional = (rt.return_cardinality.clone() == Cardinality::CardOptional); +if is_optional { + authored_name_at(scope.type_env.clone().source_indices.clone(), &with_required_cardinality(&rt)) + } else { + authored_name_at(scope.type_env.clone().source_indices.clone(), &rt) } - __result - }); - let arms_str = arm_strs.join(&"\n".to_string()); - let needs_as_str = (all_arms_are_string_lit(&arms) && ((arms.clone().len() as i64) > 0)); - let needs_string_from = has_string_lit_with_bind(&arms); - if rc_match.needs_option_deref.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("match ".to_string(), scrut_str), - ".as_deref()".to_string(), - ), - clone_iterator_suffix(), - ), - " {\n".to_string(), - ), - arms_str, - ), - "\n}".to_string(), - ) +}, + _ => "".to_string(), +}; +let rc_match = analyze_rc_match(&scrutinee, arms.clone(), scrut_type.clone(), &shared_types, emit_info.clone(), &scope.type_env.clone().source_indices.clone()); +let match_result_type = match arms.clone().first().cloned() { + Some(first_arm) => resolved_type(arm_body(&first_arm)), + None => type_variable_node("match_result".to_string()), +}; +let arm_strs = Rc::new({ let mut __result = Vec::new(); for arm in arms.clone().iter().cloned() { __result.push(emit_typed_match_arm(&arm, ®istry, &scope, depth.clone(), &shared_types, &emit_info, &scrut_type, match_result_type.clone(), false)); } __result }); +let arms_str = arm_strs.join(&"\n".to_string()); +let needs_as_str = (all_arms_are_string_lit(&arms) && ((arms.clone().len() as i64) > 0)); +let needs_string_from = has_string_lit_with_bind(&arms); +if rc_match.needs_option_deref.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), scrut_str), ".as_deref()".to_string()), clone_iterator_suffix()), " {\n".to_string()), arms_str), "\n}".to_string()) } else { if rc_match.needs_deref.clone() { { let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "match ".to_string(), - apply_type_template1(sharing.deref_clone.clone(), scrut_str), - ), - " {\n".to_string(), - ), - arms_str, - ), - "\n}".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), apply_type_template1(sharing.deref_clone.clone(), scrut_str)), " {\n".to_string()), arms_str), "\n}".to_string()) +} } else { if needs_as_str { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("match ".to_string(), scrut_str), - ".as_str() {\n".to_string(), - ), - arms_str, - ), - "\n}".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), scrut_str), ".as_str() {\n".to_string()), arms_str), "\n}".to_string()) } else { if needs_string_from { { - let sf_arm_strs = Rc::new({ - let mut __result = Vec::new(); - for arm in arms.clone().iter().cloned() { - __result.push(emit_typed_match_arm( - &arm, - ®istry, - &scope, - depth.clone(), - &shared_types, - &emit_info, - &scrut_type, - match_result_type.clone(), - true, - )); - } - __result - }); - let sf_arms_str = sf_arm_strs.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("match ".to_string(), scrut_str), - " {\n".to_string(), - ), - sf_arms_str, - ), - "\n}".to_string(), - ) - } + let sf_arm_strs = Rc::new({ let mut __result = Vec::new(); for arm in arms.clone().iter().cloned() { __result.push(emit_typed_match_arm(&arm, ®istry, &scope, depth.clone(), &shared_types, &emit_info, &scrut_type, match_result_type.clone(), true)); } __result }); +let sf_arms_str = sf_arm_strs.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), scrut_str), " {\n".to_string()), sf_arms_str), "\n}".to_string()) +} } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("match ".to_string(), scrut_str), - " {\n".to_string(), - ), - arms_str, - ), - "\n}".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), scrut_str), " {\n".to_string()), arms_str), "\n}".to_string()) } } } } - } +} } -pub fn emit_typed_match_arm( - arm: &Rc, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, - scrut_type: &String, - match_result_type: Rc, - string_from_mode: bool, -) -> String { +pub fn emit_typed_match_arm(arm: &Rc, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc, scrut_type: &String, match_result_type: Rc, string_from_mode: bool) -> String { { let arm_pat = arm_pattern(arm.clone()); - let arm_g = arm_guard(&arm); - let arm_b = arm_body(&arm); - let si = scope.type_env.clone().source_indices.clone(); - let rc_analysis = analyze_rc_pattern( - arm_pat.clone(), - scrut_type.clone(), - &shared_types, - &emit_info, - si.clone(), - ); - let pat_str = if string_from_mode { +let arm_g = arm_guard(&arm); +let arm_b = arm_body(&arm); +let si = scope.type_env.clone().source_indices.clone(); +let rc_analysis = analyze_rc_pattern(arm_pat.clone(), scrut_type.clone(), &shared_types, &emit_info, si.clone()); +let pat_str = if string_from_mode { match (*arm_pat.clone()).clone() { - MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitStr { value: s, .. } => v2_rt::concat( - v2_rt::concat( - "ref __s if __s == \"".to_string(), - escape_string_literal_body(s.clone()), - ), - "\"".to_string(), - ), - _ => rust_literal_for_pattern(v.clone()), - }, - _ => emit_pattern( - arm_pat.clone(), - shared_types.clone(), - scrut_type.clone(), - si.clone(), - emit_info.clone(), - ), - } + MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitStr { value: s, .. } => v2_rt::concat(v2_rt::concat("ref __s if __s == \"".to_string(), escape_string_literal_body(s.clone())), "\"".to_string()), + _ => rust_literal_for_pattern(v.clone()), +}, + _ => emit_pattern(arm_pat.clone(), shared_types.clone(), scrut_type.clone(), si.clone(), emit_info.clone()), +} } else { if rc_analysis.needs_rc_pattern.clone() { - emit_pattern_rc_aware( - arm_pat.clone(), - rc_analysis.clone(), - shared_types.clone(), - scrut_type.clone(), - si.clone(), - emit_info.clone(), - ) + emit_pattern_rc_aware(arm_pat.clone(), rc_analysis.clone(), shared_types.clone(), scrut_type.clone(), si.clone(), emit_info.clone()) } else { - emit_pattern( - arm_pat.clone(), - shared_types.clone(), - scrut_type.clone(), - si.clone(), - emit_info.clone(), - ) + emit_pattern(arm_pat.clone(), shared_types.clone(), scrut_type.clone(), si.clone(), emit_info.clone()) } }; - let field_guards = collect_pattern_string_guards(arm_pat.clone(), si.clone()); - let arm_guard_str = match arm_g { - Some(g) => emit_typed_expr( - g.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - 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())) - { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" if ".to_string(), field_guards.clone()), - " && ".to_string(), - ), - arm_guard_str.clone(), - ) +let field_guards = collect_pattern_string_guards(arm_pat.clone(), si.clone()); +let arm_guard_str = match arm_g { + Some(g) => emit_typed_expr(g.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024), + 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())) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(" if ".to_string(), field_guards.clone()), " && ".to_string()), arm_guard_str.clone()) } else { if (field_guards.clone().as_str() != "".to_string().as_str()) { v2_rt::concat(" if ".to_string(), field_guards.clone()) @@ -9769,878 +3901,376 @@ pub fn emit_typed_match_arm( } } }; - let body_str = match (*arm_b.expr_data.clone()).clone() { - ExprData::ExprVar { - binding_kind: body_binding_kind, - .. - } => { - let body_name = expr_var_name_at(arm_b.clone(), si.clone()); - if (variant_parent_from_binding_kind(body_binding_kind.clone()) != None) { - emit_var_ref( - &body_name, - &body_binding_kind, - &Some(Rc::new(InferredNode::Resolved { - node: match_result_type, - })), - shared_types.clone(), - registry.clone(), - &emit_info, - si.clone(), - ) - } else { - emit_typed_expr( - arm_b.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ) - } +let body_str = match (*arm_b.expr_data.clone()).clone() { + ExprData::ExprVar { binding_kind: body_binding_kind, .. } => { + let body_name = expr_var_name_at(arm_b.clone(), si.clone()); +if (variant_parent_from_binding_kind(body_binding_kind.clone()) != None) { + emit_var_ref(&body_name, &body_binding_kind, &Some(Rc::new(InferredNode::Resolved { + node: match_result_type, +})), shared_types.clone(), registry.clone(), &emit_info, si.clone()) + } else { + emit_typed_expr(arm_b.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024) } - _ => emit_typed_expr( - arm_b.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - }; - if rc_analysis.needs_rc_pattern.clone() { +}, + _ => emit_typed_expr(arm_b.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024), +}; +if rc_analysis.needs_rc_pattern.clone() { { - let prelude = rc_pattern_preludes( - arm_pat.clone(), - rc_analysis.clone(), - shared_types.clone(), - si.clone(), - emit_info.clone(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" ".to_string(), pat_str), - guard_str, - ), - " => { ".to_string(), - ), - prelude, - ), - " ".to_string(), - ), - body_str, - ), - " },".to_string(), - ) - } + let prelude = rc_pattern_preludes(arm_pat.clone(), rc_analysis.clone(), shared_types.clone(), si.clone(), emit_info.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), pat_str), guard_str), " => { ".to_string()), prelude), " ".to_string()), body_str), " },".to_string()) +} } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(" ".to_string(), pat_str), guard_str), - " => ".to_string(), - ), - body_str, - ), - ",".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), pat_str), guard_str), " => ".to_string()), body_str), ",".to_string()) } - } +} } -pub fn emit_typed_if( - condition: Rc, - then_branch: Rc, - else_branch: Option>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let cond_str = emit_typed_expr( - condition, - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - emit_typed_if_shared( - cond_str, - &then_branch, - else_branch, - None, - depth.clone(), - &RenderTarget::Rust, - scope.type_env.clone().source_indices.clone(), - |node, d| { - emit_typed_expr( - node.clone(), - registry.clone(), - &scope, - d.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ) - }, - ) - } +pub fn emit_typed_if(condition: Rc, then_branch: Rc, else_branch: Option>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let cond_str = emit_typed_expr(condition, registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +emit_typed_if_shared(cond_str, &then_branch, else_branch, None, depth.clone(), &RenderTarget::Rust, scope.type_env.clone().source_indices.clone(), |node, d| emit_typed_expr(node.clone(), registry.clone(), &scope, d.clone(), shared_types.clone(), emit_info.clone(), 1024)) +} } -pub fn emit_typed_let( - name: String, - value: &Rc, - body: Option>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let val_str = emit_typed_expr( - value.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - emit_typed_let_shared( - &name, - val_str, - body, - RenderTarget::Rust, - |bd, sc| { - emit_typed_expr( - bd.clone(), - registry.clone(), - &sc, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ) - }, - scope.clone(), - value.clone(), - ) - } +pub fn emit_typed_let(name: String, value: &Rc, body: Option>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let val_str = emit_typed_expr(value.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +emit_typed_let_shared(&name, val_str, body, RenderTarget::Rust, |bd, sc| emit_typed_expr(bd.clone(), registry.clone(), &sc, depth.clone(), shared_types.clone(), emit_info.clone(), 1024), scope.clone(), value.clone()) +} } -pub fn is_optional_struct_field( - emit_info: Rc, - struct_name: String, - field_name: String, -) -> bool { +pub fn is_optional_struct_field(emit_info: Rc, struct_name: String, field_name: String) -> bool { match lookup_emit_type_summary(emit_info, struct_name) { - Some(summary) => match v2_rt::map_get(&summary.field_summaries.clone(), field_name) { - Some(field_summary) => match field_summary.value_shape.clone() { - FieldValueShape::OptionalValue => true, - _ => false, - }, - None => false, - }, - None => false, - } + Some(summary) => match v2_rt::map_get(&summary.field_summaries.clone(), field_name) { + Some(field_summary) => match field_summary.value_shape.clone() { + FieldValueShape::OptionalValue => true, + _ => false, +}, + None => false, +}, + None => false, +} } -pub fn is_already_optional( - texpr: &Rc, - emit_info: Rc, - scope: &Rc, -) -> bool { +pub fn is_already_optional(texpr: &Rc, emit_info: Rc, scope: &Rc) -> bool { { let si = scope.type_env.clone().source_indices.clone(); - let n = expr_var_name_at(texpr.clone(), si.clone()); - let tn = record_lit_type_name_at(texpr.clone(), si.clone()); - let f = field_access_field_at(texpr.clone(), si.clone()); - match (*texpr.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitNull => true, - _ => false, - }, - ExprData::ExprVar { .. } => { - if ((n.clone().as_str() == "none".to_string().as_str()) - || (n.clone().as_str() == "None".to_string().as_str())) - { - true - } else { - match texpr.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.return_cardinality.clone() == Cardinality::CardOptional) - } - _ => match v2_rt::map_get(&scope.locals.clone(), n.clone()) { - Some(binding) => { - (binding.resolved.clone().return_cardinality.clone() - == Cardinality::CardOptional) - } - None => false, - }, - } - } - } - ExprData::ExprRecordLit { .. } => match tn { - Some(name) => { - ((name.clone().as_str() == "Some".to_string().as_str()) - || (name.clone().as_str() == "None".to_string().as_str())) - } - None => false, - }, - ExprData::ExprFieldAccess { - summary: fa_summary, - .. - } => { - let b = field_access_base(texpr.clone()); - let summary_says_optional = match fa_summary.clone() { - Some(fs) => match fs.value_shape.clone() { - FieldValueShape::OptionalValue => true, - _ => false, - }, - None => false, - }; - if summary_says_optional { - true - } else { - match b.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: base_type, .. - }) => { - let resolved_base = base_type.clone(); - if is_optional_struct_field( - emit_info, - authored_name_at( - scope.type_env.clone().source_indices.clone(), - &resolved_base, - ), - f, - ) { - true - } else { - match texpr.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.return_cardinality.clone() == Cardinality::CardOptional) - } - _ => false, - } - } - } - _ => match texpr.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.return_cardinality.clone() == Cardinality::CardOptional) - } - _ => false, - }, +let n = expr_var_name_at(texpr.clone(), si.clone()); +let tn = record_lit_type_name_at(texpr.clone(), si.clone()); +let f = field_access_field_at(texpr.clone(), si.clone()); +match (*texpr.expr_data.clone()).clone() { + ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitNull => true, + _ => false, +}, + ExprData::ExprVar { .. } => if ((n.clone().as_str() == "none".to_string().as_str()) || (n.clone().as_str() == "None".to_string().as_str())) { + true + } else { + match texpr.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (rt.return_cardinality.clone() == Cardinality::CardOptional), + _ => match v2_rt::map_get(&scope.locals.clone(), n.clone()) { + Some(binding) => (binding.resolved.clone().return_cardinality.clone() == Cardinality::CardOptional), + None => false, +}, +} + }, + ExprData::ExprRecordLit { .. } => match tn { + Some(name) => ((name.clone().as_str() == "Some".to_string().as_str()) || (name.clone().as_str() == "None".to_string().as_str())), + None => false, +}, + ExprData::ExprFieldAccess { summary: fa_summary, .. } => { + let b = field_access_base(texpr.clone()); +let summary_says_optional = match fa_summary.clone() { + Some(fs) => match fs.value_shape.clone() { + FieldValueShape::OptionalValue => true, + _ => false, +}, + None => false, +}; +if summary_says_optional { + true + } else { + match b.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: base_type, .. }) => { + let resolved_base = base_type.clone(); +if is_optional_struct_field(emit_info, authored_name_at(scope.type_env.clone().source_indices.clone(), &resolved_base), f) { + true + } else { + match texpr.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (rt.return_cardinality.clone() == Cardinality::CardOptional), + _ => false, +} } - } - } - _ => match texpr.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.return_cardinality.clone() == Cardinality::CardOptional) - } - _ => false, - }, - } - } +}, + _ => match texpr.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (rt.return_cardinality.clone() == Cardinality::CardOptional), + _ => false, +}, +} + } +}, + _ => match texpr.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (rt.return_cardinality.clone() == Cardinality::CardOptional), + _ => false, +}, +} +} } -pub fn lookup_struct_field_type_name( - struct_node: &Rc, - field_name: &String, - variant_name: Option, - source_indices: &Rc>>, -) -> Option { - { - let direct = match find_child_named( - struct_node.clone(), - field_name.clone(), - source_indices.clone(), - ) { - Some(field_child) => { - if (field_child.inferred.clone() != None) { - { - let field_type = resolved_type(field_child.clone()); - let ft_is_type_var = if (field_type.inferred.clone() != None) { - is_type_variable(field_type.inferred.clone().clone().unwrap()) - } else { - false - }; - if ((field_type.ident_span.clone() != None) && !ft_is_type_var.clone()) { - Some(authored_name_at(source_indices.clone(), &field_type)) - } else { - None - } - } +pub fn lookup_struct_field_type_name(struct_node: &Rc, field_name: &String, variant_name: Option, source_indices: &Rc>>) -> Option { + { + let direct = match find_child_named(struct_node.clone(), field_name.clone(), source_indices.clone()) { + Some(field_child) => if (field_child.inferred.clone() != None) { + { + let field_type = resolved_type(field_child.clone()); +let ft_is_type_var = if (field_type.inferred.clone() != None) { + is_type_variable(field_type.inferred.clone().clone().unwrap()) + } else { + false + }; +if ((field_type.ident_span.clone() != None) && !ft_is_type_var.clone()) { + Some(authored_name_at(source_indices.clone(), &field_type)) } else { None } - } - None => None, - }; - match direct.clone() { - Some(_) => direct.clone(), - None => match variant_name { - Some(vn) => { - match find_child_named(struct_node.clone(), vn.clone(), source_indices.clone()) - { - Some(variant_child) => match find_child_named( - variant_child.clone(), - field_name.clone(), - source_indices.clone(), - ) { - Some(field_child) => { - if (field_child.inferred.clone() != None) { - { - let field_type = resolved_type(field_child.clone()); - let ft_is_type_var = - if (field_type.inferred.clone() != None) { - is_type_variable( - field_type.inferred.clone().clone().unwrap(), - ) - } else { - false - }; - if ((field_type.ident_span.clone() != None) - && !ft_is_type_var.clone()) - { - Some(authored_name_at( - source_indices.clone(), - &field_type, - )) - } else { - None - } - } - } else { - None - } - } - None => None, - }, - None => None, - } +} + } else { + None + }, + None => None, +}; +match direct.clone() { + Some(_) => direct.clone(), + None => match variant_name { + Some(vn) => match find_child_named(struct_node.clone(), vn.clone(), source_indices.clone()) { + Some(variant_child) => match find_child_named(variant_child.clone(), field_name.clone(), source_indices.clone()) { + Some(field_child) => if (field_child.inferred.clone() != None) { + { + let field_type = resolved_type(field_child.clone()); +let ft_is_type_var = if (field_type.inferred.clone() != None) { + is_type_variable(field_type.inferred.clone().clone().unwrap()) + } else { + false + }; +if ((field_type.ident_span.clone() != None) && !ft_is_type_var.clone()) { + Some(authored_name_at(source_indices.clone(), &field_type)) + } else { + None } - None => None, - }, - } - } +} + } else { + None + }, + None => None, +}, + None => None, +}, + None => None, +}, +} +} } -pub fn emit_field_value_with_context( - field_value: &Rc, - struct_node: &Rc, - outer_type_name: Option, - field_name: &String, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_field_value_with_context(field_value: &Rc, struct_node: &Rc, outer_type_name: Option, field_name: &String, registry: Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { match (*field_value.expr_data.clone()).clone() { - ExprData::ExprRecordLit { - parent_enum: pe, .. - } => { - let inner_fields = field_value.children.clone(); - let tn = record_lit_type_name_at( - field_value.clone(), - scope.type_env.clone().source_indices.clone(), - ); - match tn.clone() { - Some(variant_name) => { - let node_lookup = lookup_struct_field_type_name( - &struct_node, - &field_name, - outer_type_name, - &scope.type_env.clone().source_indices.clone(), - ); - let expected_type = match node_lookup.clone() { - Some(_) => node_lookup.clone(), - None => { - if (struct_node.ident_span.clone() != None) { - match lookup_emit_type_summary( - emit_info.clone(), - authored_name_at( - scope.type_env.clone().source_indices.clone(), - &struct_node, - ), - ) { - Some(summary) => v2_rt::map_get( - &summary.field_type_map.clone(), - field_name.clone(), - ), - None => None, - } - } else { - None - } - } - }; - let corrected_parent = match expected_type { - Some(et) => { - if variant_belongs_to_enum( - emit_info.type_summaries.clone(), - variant_name.clone(), - et.clone(), - ) { - Some(et.clone()) - } else { - pe.clone() - } - } - None => pe.clone(), - }; - let raw = emit_typed_record_lit( - &tn, - &inner_fields, - &corrected_parent, - &resolved_type(field_value.clone()), - registry, - &scope, - depth, - &shared_types, - &emit_info, - ); - let rc_name = match corrected_parent.clone() { - Some(en) => en.clone(), - None => variant_name.clone(), - }; - if ((rc_name.clone().as_str() != "".to_string().as_str()) - && emit_map_has(shared_types.clone(), rc_name.clone())) - { - v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) - } else { - raw - } - } - None => emit_typed_expr( - field_value.clone(), - registry, - &scope, - depth, - shared_types.clone(), - emit_info.clone(), - 1024, - ), + ExprData::ExprRecordLit { parent_enum: pe, .. } => { + let inner_fields = field_value.children.clone(); +let tn = record_lit_type_name_at(field_value.clone(), scope.type_env.clone().source_indices.clone()); +match tn.clone() { + Some(variant_name) => { + let node_lookup = lookup_struct_field_type_name(&struct_node, &field_name, outer_type_name, &scope.type_env.clone().source_indices.clone()); +let expected_type = match node_lookup.clone() { + Some(_) => node_lookup.clone(), + None => if (struct_node.ident_span.clone() != None) { + match lookup_emit_type_summary(emit_info.clone(), authored_name_at(scope.type_env.clone().source_indices.clone(), &struct_node)) { + Some(summary) => v2_rt::map_get(&summary.field_type_map.clone(), field_name.clone()), + None => None, +} + } else { + None + }, +}; +let corrected_parent = match expected_type { + Some(et) => if variant_belongs_to_enum(emit_info.type_summaries.clone(), variant_name.clone(), et.clone()) { + Some(et.clone()) + } else { + pe.clone() + }, + None => pe.clone(), +}; +let raw = emit_typed_record_lit(&tn, &inner_fields, &corrected_parent, &resolved_type(field_value.clone()), registry, &scope, depth, &shared_types, &emit_info); +let rc_name = match corrected_parent.clone() { + Some(en) => en.clone(), + None => variant_name.clone(), +}; +if ((rc_name.clone().as_str() != "".to_string().as_str()) && emit_map_has(shared_types.clone(), rc_name.clone())) { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), raw), ")".to_string()) + } else { + raw } - } - _ => emit_typed_expr( - field_value.clone(), - registry, - &scope, - depth, - shared_types.clone(), - emit_info.clone(), - 1024, - ), - } +}, + None => emit_typed_expr(field_value.clone(), registry, &scope, depth, shared_types.clone(), emit_info.clone(), 1024), +} +}, + _ => emit_typed_expr(field_value.clone(), registry, &scope, depth, shared_types.clone(), emit_info.clone(), 1024), +} } -pub fn find_struct_name_by_fields( - field_names: &Rc>, - type_summaries: Rc>>, -) -> Option { +pub fn find_struct_name_by_fields(field_names: &Rc>, type_summaries: Rc>>) -> Option { { let n_fields = (field_names.clone().len() as i64); - if (n_fields.clone() == 0) { - return None; - } - let candidates = Rc::new({ - let mut __result = Vec::new(); - for summary in Rc::new(v2_rt::map_values(&type_summaries)).iter().cloned() { - if match (*summary.repr.clone()).clone() { - TypeRepr::StructRepr => { - let ftm_keys = Rc::new(v2_rt::map_keys(&summary.field_type_map.clone())); - if ((ftm_keys.clone().len() as i64) == n_fields.clone()) { - { - let mut __all = true; - for fn_name in field_names.clone().iter().cloned() { - if !(v2_rt::map_contains_key( - &summary.field_type_map.clone(), - fn_name.clone(), - )) { - __all = false; - break; - } - } - __all - } - } else { - false - } - } - _ => false, - } { - __result.push(summary); - } +if (n_fields.clone() == 0) { + return None + } +let candidates = Rc::new({ let mut __result = Vec::new(); for summary in Rc::new(v2_rt::map_values(&type_summaries)).iter().cloned() { if match (*summary.repr.clone()).clone() { + TypeRepr::StructRepr => { + let ftm_keys = Rc::new(v2_rt::map_keys(&summary.field_type_map.clone())); +if ((ftm_keys.clone().len() as i64) == n_fields.clone()) { + { let mut __all = true; for fn_name in field_names.clone().iter().cloned() { if !(v2_rt::map_contains_key(&summary.field_type_map.clone(), fn_name.clone())) { __all = false; break; } } __all } + } else { + false } - __result - }); - match candidates.first().cloned() { - Some(s) => Some(s.name.clone()), - None => None, - } - } +}, + _ => false, +} { __result.push(summary); } } __result }); +match candidates.first().cloned() { + Some(s) => Some(s.name.clone()), + None => None, +} +} } -pub fn emit_typed_record_lit( - type_name: &Option, - fields: &Rc>>, - parent_enum: &Option, - resolved_type: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let struct_name = explicit_record_struct_name( - type_name.clone(), - &resolved_type, - shared_types.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let qualified_name = match struct_name { - Some(sn) => Some(sn.clone()), - None => { - let rt_name = authored_name_at( - scope.type_env.clone().source_indices.clone(), - &resolved_type, - ); - if ((resolved_type.ident_span.clone() != None) - && v2_rt::map_contains_key(&emit_info.type_summaries.clone(), rt_name.clone())) - { - Some(rt_name.clone()) - } else { - None - } +pub fn emit_typed_record_lit(type_name: &Option, fields: &Rc>>, parent_enum: &Option, resolved_type: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let struct_name = explicit_record_struct_name(type_name.clone(), &resolved_type, shared_types.clone(), scope.type_env.clone().source_indices.clone()); +let qualified_name = match struct_name { + Some(sn) => Some(sn.clone()), + None => { + let rt_name = authored_name_at(scope.type_env.clone().source_indices.clone(), &resolved_type); +if ((resolved_type.ident_span.clone() != None) && v2_rt::map_contains_key(&emit_info.type_summaries.clone(), rt_name.clone())) { + Some(rt_name.clone()) + } else { + None } - }; - match qualified_name { - None => { - let is_product = is_product_type(resolved_type.clone()); - if (is_product && (resolved_type.ident_span.clone() == None)) { - if ((fields.clone().len() as i64) == 1) { - match fields.clone().first().cloned() { - Some(f) => emit_typed_expr( - field_init_node_value(&f), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - None => { - "compile_error!(\"empty anonymous record literal\")".to_string() - } - } - } else { - { - let lit_field_names = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - __result.push(field_init_node_name_at( - f.clone(), - scope.type_env.clone().source_indices.clone(), - )); - } - __result - }); - match find_struct_name_by_fields( - &lit_field_names, - emit_info.type_summaries.clone(), - ) { - Some(resolved_sn) => { - let field_strs = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - __result.push({ - let fname = field_init_node_name_at( - f.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let fval = emit_typed_expr( - field_init_node_value(&f), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " ".to_string(), - emit_ident( - fname.clone(), - RenderTarget::Rust, - ), - ), - ": ".to_string(), - ), - fval.clone(), - ), - ",".to_string(), - ) - }); - } - __result - }); - let body = field_strs.join(&"\n".to_string()); - let struct_lit = v2_rt::concat( - v2_rt::concat( - v2_rt::concat(resolved_sn.clone(), " {\n".to_string()), - body, - ), - "\n}".to_string(), - ); - if emit_map_has(shared_types.clone(), resolved_sn.clone()) { - v2_rt::concat( - v2_rt::concat("Rc::new(".to_string(), struct_lit), - ")".to_string(), - ) - } else { - struct_lit - } - } - None => { - let vals = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - __result.push(emit_typed_expr( - field_init_node_value(&f), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - )); - } - __result - }); - v2_rt::concat( - v2_rt::concat( - "(".to_string(), - vals.join(&", ".to_string()), - ), - ")".to_string(), - ) - } - } - } - } +}, +}; +match qualified_name { + None => { + let is_product = is_product_type(resolved_type.clone()); +if (is_product && (resolved_type.ident_span.clone() == None)) { + if ((fields.clone().len() as i64) == 1) { + match fields.clone().first().cloned() { + Some(f) => emit_typed_expr(field_init_node_value(&f), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024), + None => "compile_error!(\"empty anonymous record literal\")".to_string(), +} } else { - "compile_error!(\"cannot resolve anonymous record type in emitter\")" - .to_string() + { + let lit_field_names = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { __result.push(field_init_node_name_at(f.clone(), scope.type_env.clone().source_indices.clone())); } __result }); +match find_struct_name_by_fields(&lit_field_names, emit_info.type_summaries.clone()) { + Some(resolved_sn) => { + let field_strs = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { __result.push({ + let fname = field_init_node_name_at(f.clone(), scope.type_env.clone().source_indices.clone()); +let fval = emit_typed_expr(field_init_node_value(&f), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), emit_ident(fname.clone(), RenderTarget::Rust)), ": ".to_string()), fval.clone()), ",".to_string()) +}); } __result }); +let body = field_strs.join(&"\n".to_string()); +let struct_lit = v2_rt::concat(v2_rt::concat(v2_rt::concat(resolved_sn.clone(), " {\n".to_string()), body), "\n}".to_string()); +if emit_map_has(shared_types.clone(), resolved_sn.clone()) { + v2_rt::concat(v2_rt::concat("Rc::new(".to_string(), struct_lit), ")".to_string()) + } else { + struct_lit + } +}, + None => { + let vals = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { __result.push(emit_typed_expr(field_init_node_value(&f), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024)); } __result }); +v2_rt::concat(v2_rt::concat("(".to_string(), vals.join(&", ".to_string())), ")".to_string()) +}, +} +} } + } else { + "compile_error!(\"cannot resolve anonymous record type in emitter\")".to_string() } - Some(tn) => { - let si = scope.type_env.clone().source_indices.clone(); - let context_lookup = contextual_variant_parent( - &tn, - parent_enum.clone(), - &resolved_type, - emit_info.clone(), - si.clone(), - ); - let effective_parent = match context_lookup { - Some(context_parent) => Some(context_parent.clone()), - None => { - let rt_is_type_var = if (resolved_type.inferred.clone() != None) { - is_type_variable(resolved_type.inferred.clone().clone().unwrap()) - } else { - false - }; - let rt_name = authored_name_at(si.clone(), &resolved_type); - if ((((resolved_type.ident_span.clone() != None) - && (rt_name.clone().as_str() != tn.clone().as_str())) - && !rt_is_type_var) - && (rt_name.clone().as_str() != "Error".to_string().as_str())) - { - Some(rt_name.clone()) - } else { - parent_enum.clone() - } - } - }; - let display_tn = if ((tn.clone().as_str() == "Some".to_string().as_str()) - || (tn.clone().as_str() == "None".to_string().as_str())) - { - tn.clone() +}, + Some(tn) => { + let si = scope.type_env.clone().source_indices.clone(); +let context_lookup = contextual_variant_parent(&tn, parent_enum.clone(), &resolved_type, emit_info.clone(), si.clone()); +let effective_parent = match context_lookup { + Some(context_parent) => Some(context_parent.clone()), + None => { + let rt_is_type_var = if (resolved_type.inferred.clone() != None) { + is_type_variable(resolved_type.inferred.clone().clone().unwrap()) } else { - match effective_parent { - Some(resolved_parent_enum) => v2_rt::concat( - v2_rt::concat(resolved_parent_enum.clone(), "::".to_string()), - tn.clone(), - ), - None => tn.clone(), - } + false }; - if ((tn.clone().as_str() == "Some".to_string().as_str()) - && ((fields.clone().len() as i64) == 1)) - { - match fields.clone().first().cloned() { - Some(f) => { - let inner = emit_typed_expr( - field_init_node_value(&f), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat( - v2_rt::concat("Some(".to_string(), inner), - ")".to_string(), - ) - } - None => v2_rt::concat(display_tn, " {}".to_string()), - } +let rt_name = authored_name_at(si.clone(), &resolved_type); +if ((((resolved_type.ident_span.clone() != None) && (rt_name.clone().as_str() != tn.clone().as_str())) && !rt_is_type_var) && (rt_name.clone().as_str() != "Error".to_string().as_str())) { + Some(rt_name.clone()) } else { - if ((fields.clone().len() as i64) == 0) { - { - let empty_raw = v2_rt::concat(display_tn, " {}".to_string()); - let record_parent_enum = match parent_enum.clone() { - Some(en) => en.clone(), - None => "".to_string(), + parent_enum.clone() + } +}, +}; +let display_tn = if ((tn.clone().as_str() == "Some".to_string().as_str()) || (tn.clone().as_str() == "None".to_string().as_str())) { + tn.clone() + } else { + match effective_parent { + Some(resolved_parent_enum) => v2_rt::concat(v2_rt::concat(resolved_parent_enum.clone(), "::".to_string()), tn.clone()), + None => tn.clone(), +} + }; +if ((tn.clone().as_str() == "Some".to_string().as_str()) && ((fields.clone().len() as i64) == 1)) { + match fields.clone().first().cloned() { + Some(f) => { + let inner = emit_typed_expr(field_init_node_value(&f), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(v2_rt::concat("Some(".to_string(), inner), ")".to_string()) +}, + None => v2_rt::concat(display_tn, " {}".to_string()), +} + } else { + if ((fields.clone().len() as i64) == 0) { + { + let empty_raw = v2_rt::concat(display_tn, " {}".to_string()); +let record_parent_enum = match parent_enum.clone() { + Some(en) => en.clone(), + None => "".to_string(), +}; +empty_raw +} + } else { + { + let field_strs = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { __result.push({ + let f_name = field_init_node_name_at(f.clone(), scope.type_env.clone().source_indices.clone()); +let f_value = field_init_node_value(&f); +let val_str = emit_field_value_with_context(&f_value, &resolved_type, type_name.clone(), &f_name, registry.clone(), &scope, depth.clone(), &shared_types, &emit_info); +let needs_wrap = (is_optional_struct_field(emit_info.clone(), tn.clone(), f_name.clone()) && (is_already_optional(&f_value, emit_info.clone(), &scope) == false)); +let field_val = if needs_wrap.clone() { + v2_rt::concat(v2_rt::concat("Some(".to_string(), val_str.clone()), ")".to_string()) + } else { + val_str.clone() }; - empty_raw - } - } else { - { - let field_strs = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - __result.push({ - let f_name = field_init_node_name_at( - f.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let f_value = field_init_node_value(&f); - let val_str = emit_field_value_with_context( - &f_value, - &resolved_type, - type_name.clone(), - &f_name, - registry.clone(), - &scope, - depth.clone(), - &shared_types, - &emit_info, - ); - let needs_wrap = (is_optional_struct_field( - emit_info.clone(), - tn.clone(), - f_name.clone(), - ) && (is_already_optional( - &f_value, - emit_info.clone(), - &scope, - ) == false)); - let field_val = if needs_wrap.clone() { - v2_rt::concat( - v2_rt::concat("Some(".to_string(), val_str.clone()), - ")".to_string(), - ) - } else { - val_str.clone() - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " ".to_string(), - emit_ident( - f_name.clone(), - RenderTarget::Rust, - ), - ), - ": ".to_string(), - ), - field_val.clone(), - ), - ",".to_string(), - ) - }); - } - __result - }); - let provided_names = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - __result.push(field_init_node_name_at( - f.clone(), - scope.type_env.clone().source_indices.clone(), - )); - } - __result - }); - let provided_set = provided_names.iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, n: String| { - v2_rt::rc_map_insert(acc, n.clone(), true) - }, - ); - let summary = lookup_emit_type_summary(emit_info.clone(), tn.clone()); - let default_strs = match summary { - Some(s) => { - let fs = s.field_summaries.clone(); - let ftm = s.field_type_map.clone(); - let missing = Rc::new({ - let mut __result = Vec::new(); - for k in Rc::new(v2_rt::map_keys(&fs)).iter().cloned() { - if !emit_map_has(provided_set.clone(), k.clone()) { - __result.push(k); - } - } - __result - }); - let all_defaultable = { - let mut __all = true; - for fname in missing.clone().iter().cloned() { - if !({ - let has_zv = - match v2_rt::map_get(&ftm, fname.clone()) { - Some(ft) => match rust_zero_value(&ft) { - Some(_) => true, - None => false, - }, - None => false, - }; - (has_zv.clone() - || is_optional_struct_field( - emit_info.clone(), - tn.clone(), - fname.clone(), - )) - }) { - __all = false; - break; - } - } - __all - }; - if all_defaultable { - Rc::new({ - let mut __result = Vec::new(); - for fname in missing.clone().iter().cloned() { - __result.extend((*if is_optional_struct_field(emit_info.clone(), tn.clone(), fname.clone()) { +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), emit_ident(f_name.clone(), RenderTarget::Rust)), ": ".to_string()), field_val.clone()), ",".to_string()) +}); } __result }); +let provided_names = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { __result.push(field_init_node_name_at(f.clone(), scope.type_env.clone().source_indices.clone())); } __result }); +let provided_set = provided_names.iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, n: String| v2_rt::rc_map_insert(acc, n.clone(), true)); +let summary = lookup_emit_type_summary(emit_info.clone(), tn.clone()); +let default_strs = match summary { + Some(s) => { + let fs = s.field_summaries.clone(); +let ftm = s.field_type_map.clone(); +let missing = Rc::new({ let mut __result = Vec::new(); for k in Rc::new(v2_rt::map_keys(&fs)).iter().cloned() { if !emit_map_has(provided_set.clone(), k.clone()) { __result.push(k); } } __result }); +let all_defaultable = { let mut __all = true; for fname in missing.clone().iter().cloned() { if !({ + let has_zv = match v2_rt::map_get(&ftm, fname.clone()) { + Some(ft) => match rust_zero_value(&ft) { + Some(_) => true, + None => false, +}, + None => false, +}; +(has_zv.clone() || is_optional_struct_field(emit_info.clone(), tn.clone(), fname.clone())) +}) { __all = false; break; } } __all }; +if all_defaultable { + Rc::new({ let mut __result = Vec::new(); for fname in missing.clone().iter().cloned() { __result.extend((*if is_optional_struct_field(emit_info.clone(), tn.clone(), fname.clone()) { Rc::new(vec![v2_rt::concat(v2_rt::concat(" ".to_string(), emit_ident(fname.clone(), RenderTarget::Rust)), ": None,".to_string())]) } else { match v2_rt::map_get(&ftm, fname.clone()) { @@ -10650,32 +4280,23 @@ pub fn emit_typed_record_lit( }, None => Rc::new(vec![]), } - }).iter().cloned()); - } - __result - }) - } else { - Rc::new(vec![]) - } - } - None => Rc::new(vec![]), - }; - let all_field_strs = v2_rt::concat(field_strs, default_strs); - let fields_str = all_field_strs.join(&"\n".to_string()); - let raw = v2_rt::concat( - v2_rt::concat( - v2_rt::concat(display_tn, " {\n".to_string()), - fields_str, - ), - "\n}".to_string(), - ); - raw - } - } + }).iter().cloned()); } __result }) + } else { + Rc::new(vec![]) + } +}, + None => Rc::new(vec![]), +}; +let all_field_strs = v2_rt::concat(field_strs, default_strs); +let fields_str = all_field_strs.join(&"\n".to_string()); +let raw = v2_rt::concat(v2_rt::concat(v2_rt::concat(display_tn, " {\n".to_string()), fields_str), "\n}".to_string()); +raw +} } } - } - } +}, +} +} } pub fn rust_zero_value(type_name: &String) -> Option { @@ -10686,10 +4307,7 @@ pub fn rust_zero_value(type_name: &String) -> Option { Some("false".to_string()) } else { if (type_name.clone().as_str() == "String".to_string().as_str()) { - Some(v2_rt::concat( - "\"\"".to_string(), - ".to_string()".to_string(), - )) + Some(v2_rt::concat("\"\"".to_string(), ".to_string()".to_string())) } else { None } @@ -10697,1058 +4315,330 @@ pub fn rust_zero_value(type_name: &String) -> Option { } } -pub fn emit_typed_bin_op( - op: &BinOp, - algebra_field: Option, - left: &Rc, - right: &Rc, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { - { - let l_str = emit_typed_expr( - left.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let r_str = emit_typed_expr( - right.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - if is_null_coalesce(op.clone()) { +pub fn emit_typed_bin_op(op: &BinOp, algebra_field: Option, left: &Rc, right: &Rc, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc) -> String { + { + let l_str = emit_typed_expr(left.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let r_str = emit_typed_expr(right.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +if is_null_coalesce(op.clone()) { emit_null_coalesce(l_str, r_str, RenderTarget::Rust) } else { { let op_str = emit_bin_op_symbol(op.clone(), &RenderTarget::Rust, algebra_field); - if is_string_comparison( - op.clone(), - left.clone(), - right.clone(), - &scope.type_env.clone().source_indices.clone(), - ) { +if is_string_comparison(op.clone(), left.clone(), right.clone(), &scope.type_env.clone().source_indices.clone()) { { let l_optional = is_optional_typed_expr(left.clone()); - let r_optional = is_optional_typed_expr(right.clone()); - if (l_optional.clone() || r_optional.clone()) { +let r_optional = is_optional_typed_expr(right.clone()); +if (l_optional.clone() || r_optional.clone()) { { let l_cmp = if l_optional.clone() { v2_rt::concat(l_str, ".as_deref()".to_string()) } else { - v2_rt::concat( - v2_rt::concat("Some(".to_string(), l_str), - ".as_str())".to_string(), - ) + v2_rt::concat(v2_rt::concat("Some(".to_string(), l_str), ".as_str())".to_string()) }; - let r_cmp = if r_optional.clone() { +let r_cmp = if r_optional.clone() { v2_rt::concat(r_str, ".as_deref()".to_string()) } else { - v2_rt::concat( - v2_rt::concat("Some(".to_string(), r_str), - ".as_str())".to_string(), - ) + v2_rt::concat(v2_rt::concat("Some(".to_string(), r_str), ".as_str())".to_string()) }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("(".to_string(), l_cmp), - " ".to_string(), - ), - op_str, - ), - " ".to_string(), - ), - r_cmp, - ), - ")".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("(".to_string(), l_cmp), " ".to_string()), op_str), " ".to_string()), r_cmp), ")".to_string()) +} } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("(".to_string(), l_str), - ".as_str() ".to_string(), - ), - op_str, - ), - " ".to_string(), - ), - r_str, - ), - ".as_str())".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("(".to_string(), l_str), ".as_str() ".to_string()), op_str), " ".to_string()), r_str), ".as_str())".to_string()) } - } +} } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("(".to_string(), l_str), - " ".to_string(), - ), - op_str, - ), - " ".to_string(), - ), - r_str, - ), - ")".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("(".to_string(), l_str), " ".to_string()), op_str), " ".to_string()), r_str), ")".to_string()) } - } +} } - } +} } pub fn is_optional_typed_expr(e: Rc) -> bool { match e.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.return_cardinality.clone() == Cardinality::CardOptional) - } - _ => false, - } + Some(InferredNode::Resolved { node: rt, .. }) => (rt.return_cardinality.clone() == Cardinality::CardOptional), + _ => false, +} } -pub fn is_string_comparison( - op: BinOp, - left: Rc, - right: Rc, - source_indices: &Rc>>, -) -> bool { +pub fn is_string_comparison(op: BinOp, left: Rc, right: Rc, source_indices: &Rc>>) -> bool { match op { - BinOp::Eq => { - (is_string_typed_expr(left, source_indices.clone()) - && is_string_typed_expr(right, source_indices.clone())) - } - BinOp::Ne => { - (is_string_typed_expr(left, source_indices.clone()) - && is_string_typed_expr(right, source_indices.clone())) - } - _ => false, - } + BinOp::Eq => (is_string_typed_expr(left, source_indices.clone()) && is_string_typed_expr(right, source_indices.clone())), + BinOp::Ne => (is_string_typed_expr(left, source_indices.clone()) && is_string_typed_expr(right, source_indices.clone())), + _ => false, +} } -pub fn is_string_typed_expr( - e: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_string_typed_expr(e: Rc, source_indices: Rc>>) -> bool { match e.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - let is_optional = (rt.return_cardinality.clone() == Cardinality::CardOptional); - let inner = if is_optional { - with_required_cardinality(&rt) - } else { - rt.clone() - }; - is_rust_string_like(inner, source_indices) - } - _ => false, - } + Some(InferredNode::Resolved { node: rt, .. }) => { + let is_optional = (rt.return_cardinality.clone() == Cardinality::CardOptional); +let inner = if is_optional { + with_required_cardinality(&rt) + } else { + rt.clone() + }; +is_rust_string_like(inner, source_indices) +}, + _ => false, +} } -pub fn emit_typed_string_interp( - parts: &Rc>>, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { - { - let has_interpolations = { - let mut __found = false; - for p in parts.clone().iter().cloned() { - if match (*p.clone()).clone() { - StringPart::Interpolation { .. } => true, - _ => false, - } { - __found = true; - break; - } - } - __found - }; - let fmt_parts = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.push(typed_interp_format_part( - p.clone(), - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - has_interpolations.clone(), - )); - } - __result - }); - let fmt_str = Rc::new({ - let mut __result = Vec::new(); - for p in fmt_parts.clone().iter().cloned() { - __result.push(p.format_segment.clone()); - } - __result - }) - .join(&"".to_string()); - let args = Rc::new({ - let mut __result = Vec::new(); - for a in Rc::new({ - let mut __result = Vec::new(); - for p in fmt_parts.clone().iter().cloned() { - __result.push(p.arg_expr.clone()); - } - __result - }) - .iter() - .cloned() - { - if (a.clone().as_str() != "".to_string().as_str()) { - __result.push(a); - } - } - __result - }); - if ((args.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat("\"".to_string(), fmt_str), - "\".to_string()".to_string(), - ) +pub fn emit_typed_string_interp(parts: &Rc>>, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { + { + let has_interpolations = { let mut __found = false; for p in parts.clone().iter().cloned() { if match (*p.clone()).clone() { + StringPart::Interpolation { .. } => true, + _ => false, +} { __found = true; break; } } __found }; +let fmt_parts = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.push(typed_interp_format_part(p.clone(), registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone(), has_interpolations.clone())); } __result }); +let fmt_str = Rc::new({ let mut __result = Vec::new(); for p in fmt_parts.clone().iter().cloned() { __result.push(p.format_segment.clone()); } __result }).join(&"".to_string()); +let args = Rc::new({ let mut __result = Vec::new(); for a in Rc::new({ let mut __result = Vec::new(); for p in fmt_parts.clone().iter().cloned() { __result.push(p.arg_expr.clone()); } __result }).iter().cloned() { if (a.clone().as_str() != "".to_string().as_str()) { __result.push(a); } } __result }); +if ((args.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat("\"".to_string(), fmt_str), "\".to_string()".to_string()) } else { { let args_str = args.clone().join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("format!(\"".to_string(), fmt_str), - "\", ".to_string(), - ), - args_str, - ), - ")".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("format!(\"".to_string(), fmt_str), "\", ".to_string()), args_str), ")".to_string()) +} } - } +} } -pub fn typed_interp_format_part( - part: Rc, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, - has_interpolations: bool, -) -> Rc { +pub fn typed_interp_format_part(part: Rc, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc, has_interpolations: bool) -> Rc { match (*part).clone() { - StringPart::Text { value: v, .. } => { - let escaped = if has_interpolations { - escape_rust_interp_text(v.clone()) - } else { - escape_string_literal_body(v.clone()) - }; - Rc::new(InterpPart { - format_segment: escaped, - arg_expr: "".to_string(), - }) - } - StringPart::Interpolation { expr: e, .. } => Rc::new(InterpPart { - format_segment: "{}".to_string(), - arg_expr: emit_typed_expr( - e.clone(), - registry, - &scope, - depth, - shared_types, - emit_info, - 1024, - ), - }), - } + StringPart::Text { value: v, .. } => { + let escaped = if has_interpolations { + escape_rust_interp_text(v.clone()) + } else { + escape_string_literal_body(v.clone()) + }; +Rc::new(InterpPart { + format_segment: escaped, + arg_expr: "".to_string(), +}) +}, + StringPart::Interpolation { expr: e, .. } => Rc::new(InterpPart { + format_segment: "{}".to_string(), + arg_expr: emit_typed_expr(e.clone(), registry, &scope, depth, shared_types, emit_info, 1024), +}), +} } -pub fn emit_typed_block( - stmts: Rc>>, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { - { - let state = emit_rust_block_stmts( - stmts, - Rc::new(vec![]), - scope, - registry, - (depth.clone() + 1), - shared_types, - emit_info, - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("{\n".to_string(), make_indent((depth.clone() + 1))), - state.text.clone().join(&"\n".to_string()), - ), - "\n}".to_string(), - ) - } +pub fn emit_typed_block(stmts: Rc>>, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { + { + let state = emit_rust_block_stmts(stmts, Rc::new(vec![]), scope, registry, (depth.clone() + 1), shared_types, emit_info); +v2_rt::concat(v2_rt::concat(v2_rt::concat("{\n".to_string(), make_indent((depth.clone() + 1))), state.text.clone().join(&"\n".to_string())), "\n}".to_string()) +} } -pub fn emit_tco_init_block_stmts( - mut remaining: Rc>>, - mut text: Rc>, - mut scope: Rc, - mut registry: Rc>>, - mut depth: i64, - mut shared_types: Rc>, - mut emit_info: Rc, - mut params: Rc>>, -) -> Rc { +pub fn emit_tco_init_block_stmts(mut remaining: Rc>>, mut text: Rc>, mut scope: Rc, mut registry: Rc>>, mut depth: i64, mut shared_types: Rc>, mut emit_info: Rc, mut params: Rc>>) -> Rc { loop { match remaining.clone().first().cloned() { - None => { - break Rc::new(BlockEmitState { - text: text, - scope: scope.clone(), - }); - } - Some(stmt) => { - let rest = Rc::new( - remaining - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - match rest.clone().first().cloned() { - None => { - break Rc::new(BlockEmitState { - text: text, - scope: scope.clone(), - }); - } - Some(_) => { - let line = emit_tco_init_stmt( - &stmt, - params.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - let next_scope = scope_after_expr(&stmt, &scope); - { - let __tco_0 = rest.clone(); - let __tco_1 = v2_rt::rc_list_push(text, line); - let __tco_2 = next_scope; - remaining = __tco_0; - text = __tco_1; - scope = __tco_2; - continue; - } - } - } - } - } - } -} - -pub fn emit_tco_init_stmt( - stmt: &Rc, - params: Rc>>, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { + None => { break Rc::new(BlockEmitState { + text: text, + scope: scope.clone(), +}); }, + Some(stmt) => { let rest = Rc::new(remaining.clone().iter().cloned().skip(1 as usize).collect::>()); +match rest.clone().first().cloned() { + None => { break Rc::new(BlockEmitState { + text: text, + scope: scope.clone(), +}); }, + Some(_) => { let line = emit_tco_init_stmt(&stmt, params.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone()); +let next_scope = scope_after_expr(&stmt, &scope); +{ + let __tco_0 = rest.clone(); +let __tco_1 = v2_rt::rc_list_push(text, line); +let __tco_2 = next_scope; +remaining = __tco_0; +text = __tco_1; +scope = __tco_2; +continue; +} }, +} }, +} +} +} + +pub fn emit_tco_init_stmt(stmt: &Rc, params: Rc>>, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { match (*stmt.expr_data.clone()).clone() { - ExprData::ExprLet => { - let n = - let_binding_name_at(stmt.clone(), scope.type_env.clone().source_indices.clone()); - let v = let_value(stmt.clone()); - let val_str = - emit_typed_expr(v, registry, &scope, depth, shared_types, emit_info, 1024); - let is_param = { - let mut __found = false; - for p in params.iter().cloned() { - if (param_node_name_at( - p.clone(), - scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == n.clone().as_str()) - { - __found = true; - break; - } - } - __found - }; - if is_param { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(emit_ident(n.clone(), RenderTarget::Rust), " = ".to_string()), - val_str, - ), - ";".to_string(), - ) - } else { - emit_let_binding(n.clone(), val_str, &RenderTarget::Rust) - } + ExprData::ExprLet => { + let n = let_binding_name_at(stmt.clone(), scope.type_env.clone().source_indices.clone()); +let v = let_value(stmt.clone()); +let val_str = emit_typed_expr(v, registry, &scope, depth, shared_types, emit_info, 1024); +let is_param = { let mut __found = false; for p in params.iter().cloned() { if (param_node_name_at(p.clone(), scope.type_env.clone().source_indices.clone()).as_str() == n.clone().as_str()) { __found = true; break; } } __found }; +if is_param { + v2_rt::concat(v2_rt::concat(v2_rt::concat(emit_ident(n.clone(), RenderTarget::Rust), " = ".to_string()), val_str), ";".to_string()) + } else { + emit_let_binding(n.clone(), val_str, &RenderTarget::Rust) } - _ => emit_typed_expr( - stmt.clone(), - registry, - &scope, - depth, - shared_types, - emit_info, - 1024, - ), - } +}, + _ => emit_typed_expr(stmt.clone(), registry, &scope, depth, shared_types, emit_info, 1024), +} } -pub fn emit_typed_tco_body( - texpr: Rc, - fn_name: String, - params: Rc>>, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { - { - let inner = emit_typed_tco_expr( - texpr, - &fn_name, - params, - registry, - scope, - (depth.clone() + 1), - shared_types, - emit_info, - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("loop {\n".to_string(), make_indent((depth.clone() + 1))), - inner, - ), - "\n}".to_string(), - ) - } +pub fn emit_typed_tco_body(texpr: Rc, fn_name: String, params: Rc>>, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { + { + let inner = emit_typed_tco_expr(texpr, &fn_name, params, registry, scope, (depth.clone() + 1), shared_types, emit_info); +v2_rt::concat(v2_rt::concat(v2_rt::concat("loop {\n".to_string(), make_indent((depth.clone() + 1))), inner), "\n}".to_string()) +} } -pub fn emit_rust_tco_non_self_call( - frame: &Rc, - registry: Rc>>, - shared_types: Rc>, - emit_info: Rc, -) -> String { +pub fn emit_rust_tco_non_self_call(frame: &Rc, registry: Rc>>, shared_types: Rc>, emit_info: Rc) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let f = expr_call_func_at( - frame.expr.clone(), - frame.scope.clone().type_env.clone().source_indices.clone(), - ); - let call_str = emit_typed_call( - &f, - &frame.expr.clone().children.clone(), - ®istry, - &frame.scope.clone(), - frame.depth.clone(), - &shared_types, - &emit_info, - ); - v2_rt::concat( - v2_rt::concat("break ".to_string(), call_str), - ";".to_string(), - ) - } - _ => emit_error_expr( - "emit_rust_tco_non_self_call expected ExprCall".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprCall { .. } => { + let f = expr_call_func_at(frame.expr.clone(), frame.scope.clone().type_env.clone().source_indices.clone()); +let call_str = emit_typed_call(&f, &frame.expr.clone().children.clone(), ®istry, &frame.scope.clone(), frame.depth.clone(), &shared_types, &emit_info); +v2_rt::concat(v2_rt::concat("break ".to_string(), call_str), ";".to_string()) +}, + _ => emit_error_expr("emit_rust_tco_non_self_call expected ExprCall".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_tco_if( - frame: &Rc, - fn_name: &String, - params: &Rc>>, - registry: &Rc>>, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_rust_tco_if(frame: &Rc, fn_name: &String, params: &Rc>>, registry: &Rc>>, shared_types: &Rc>, emit_info: &Rc) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprIf => { - let c = if_condition(frame.expr.clone()); - let t = if_then_branch(frame.expr.clone()); - let e = if_else_branch(frame.expr.clone()); - let cond_str = emit_typed_expr( - c, - registry.clone(), - &frame.scope.clone(), - frame.depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let then_str = emit_typed_tco_expr( - t, - &fn_name, - params.clone(), - registry.clone(), - frame.scope.clone(), - (frame.depth.clone() + 1), - shared_types.clone(), - emit_info.clone(), - ); - match e { - Some(eb) => { - let else_str = emit_typed_tco_expr( - eb.clone(), - &fn_name, - params.clone(), - registry.clone(), - frame.scope.clone(), - (frame.depth.clone() + 1), - shared_types.clone(), - emit_info.clone(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("if ".to_string(), cond_str), - " {\n".to_string(), - ), - make_indent((frame.depth.clone() + 1)), - ), - then_str, - ), - "\n} else {\n".to_string(), - ), - make_indent((frame.depth.clone() + 1)), - ), - else_str, - ), - "\n}".to_string(), - ) - } - None => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("if ".to_string(), cond_str), - " {\n".to_string(), - ), - make_indent((frame.depth.clone() + 1)), - ), - then_str, - ), - "\n}".to_string(), - ), - } - } - _ => emit_error_expr( - "emit_rust_tco_if expected ExprIf".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprIf => { + let c = if_condition(frame.expr.clone()); +let t = if_then_branch(frame.expr.clone()); +let e = if_else_branch(frame.expr.clone()); +let cond_str = emit_typed_expr(c, registry.clone(), &frame.scope.clone(), frame.depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let then_str = emit_typed_tco_expr(t, &fn_name, params.clone(), registry.clone(), frame.scope.clone(), (frame.depth.clone() + 1), shared_types.clone(), emit_info.clone()); +match e { + Some(eb) => { + let else_str = emit_typed_tco_expr(eb.clone(), &fn_name, params.clone(), registry.clone(), frame.scope.clone(), (frame.depth.clone() + 1), shared_types.clone(), emit_info.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), " {\n".to_string()), make_indent((frame.depth.clone() + 1))), then_str), "\n} else {\n".to_string()), make_indent((frame.depth.clone() + 1))), else_str), "\n}".to_string()) +}, + None => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if ".to_string(), cond_str), " {\n".to_string()), make_indent((frame.depth.clone() + 1))), then_str), "\n}".to_string()), +} +}, + _ => emit_error_expr("emit_rust_tco_if expected ExprIf".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_tco_match( - frame: &Rc, - fn_name: String, - params: Rc>>, - registry: &Rc>>, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_rust_tco_match(frame: &Rc, fn_name: String, params: Rc>>, registry: &Rc>>, shared_types: &Rc>, emit_info: &Rc) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprMatch => { - let s = match_scrutinee(frame.expr.clone()); - let arm_list = match_arm_nodes(frame.expr.clone()); - let scrut_str = emit_typed_expr( - s.clone(), - registry.clone(), - &frame.scope.clone(), - frame.depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let tco_scrut_type = match s.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - let is_optional = (rt.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { - authored_name_at( - frame.scope.clone().type_env.clone().source_indices.clone(), - &with_required_cardinality(&rt), - ) - } else { - authored_name_at( - frame.scope.clone().type_env.clone().source_indices.clone(), - &rt, - ) - } - } - _ => "".to_string(), - }; - let rc_match = analyze_rc_match( - &s, - arm_list.clone(), - tco_scrut_type.clone(), - &shared_types, - emit_info.clone(), - &frame.scope.clone().type_env.clone().source_indices.clone(), - ); - let arm_strs = Rc::new({ - let mut __result = Vec::new(); - for arm in arm_list.clone().iter().cloned() { - __result.push(emit_typed_tco_match_arm( - &arm, - fn_name.clone(), - params.clone(), - ®istry, - &frame.scope.clone(), - frame.depth.clone(), - &shared_types, - &emit_info, - &tco_scrut_type, - )); - } - __result - }); - let arms_str = arm_strs.join(&"\n".to_string()); - let tco_needs_as_str = - (all_arms_are_string_lit(&arm_list) && ((arm_list.clone().len() as i64) > 0)); - if rc_match.needs_option_deref.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("match ".to_string(), scrut_str), - ".as_deref()".to_string(), - ), - clone_iterator_suffix(), - ), - " {\n".to_string(), - ), - arms_str, - ), - "\n}".to_string(), - ) + ExprData::ExprMatch => { + let s = match_scrutinee(frame.expr.clone()); +let arm_list = match_arm_nodes(frame.expr.clone()); +let scrut_str = emit_typed_expr(s.clone(), registry.clone(), &frame.scope.clone(), frame.depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let tco_scrut_type = match s.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => { + let is_optional = (rt.return_cardinality.clone() == Cardinality::CardOptional); +if is_optional { + authored_name_at(frame.scope.clone().type_env.clone().source_indices.clone(), &with_required_cardinality(&rt)) } else { - if rc_match.needs_deref.clone() { - { - let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "match ".to_string(), - apply_type_template1( - sharing.deref_clone.clone(), - scrut_str, - ), - ), - " {\n".to_string(), - ), - arms_str, - ), - "\n}".to_string(), - ) - } + authored_name_at(frame.scope.clone().type_env.clone().source_indices.clone(), &rt) + } +}, + _ => "".to_string(), +}; +let rc_match = analyze_rc_match(&s, arm_list.clone(), tco_scrut_type.clone(), &shared_types, emit_info.clone(), &frame.scope.clone().type_env.clone().source_indices.clone()); +let arm_strs = Rc::new({ let mut __result = Vec::new(); for arm in arm_list.clone().iter().cloned() { __result.push(emit_typed_tco_match_arm(&arm, fn_name.clone(), params.clone(), ®istry, &frame.scope.clone(), frame.depth.clone(), &shared_types, &emit_info, &tco_scrut_type)); } __result }); +let arms_str = arm_strs.join(&"\n".to_string()); +let tco_needs_as_str = (all_arms_are_string_lit(&arm_list) && ((arm_list.clone().len() as i64) > 0)); +if rc_match.needs_option_deref.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), scrut_str), ".as_deref()".to_string()), clone_iterator_suffix()), " {\n".to_string()), arms_str), "\n}".to_string()) + } else { + if rc_match.needs_deref.clone() { + { + let sharing = language_spec(RenderTarget::Rust).sharing.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), apply_type_template1(sharing.deref_clone.clone(), scrut_str)), " {\n".to_string()), arms_str), "\n}".to_string()) +} + } else { + if tco_needs_as_str { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), scrut_str), ".as_str() {\n".to_string()), arms_str), "\n}".to_string()) } else { - if tco_needs_as_str { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("match ".to_string(), scrut_str), - ".as_str() {\n".to_string(), - ), - arms_str, - ), - "\n}".to_string(), - ) - } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("match ".to_string(), scrut_str), - " {\n".to_string(), - ), - arms_str, - ), - "\n}".to_string(), - ) - } + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("match ".to_string(), scrut_str), " {\n".to_string()), arms_str), "\n}".to_string()) } } } - _ => emit_error_expr( - "emit_rust_tco_match expected ExprMatch".to_string(), - RenderTarget::Rust, - ), - } +}, + _ => emit_error_expr("emit_rust_tco_match expected ExprMatch".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_tco_let( - frame: &Rc, - fn_name: String, - params: &Rc>>, - registry: &Rc>>, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_rust_tco_let(frame: &Rc, fn_name: String, params: &Rc>>, registry: &Rc>>, shared_types: &Rc>, emit_info: &Rc) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprLet => { - let n = let_binding_name_at( - frame.expr.clone(), - frame.scope.clone().type_env.clone().source_indices.clone(), - ); - let v = let_value(frame.expr.clone()); - let bd = let_body(frame.expr.clone()); - let val_str = emit_typed_expr( - v.clone(), - registry.clone(), - &frame.scope.clone(), - frame.depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let is_param = { - let mut __found = false; - for p in params.clone().iter().cloned() { - if (param_node_name_at( - p.clone(), - frame.scope.clone().type_env.clone().source_indices.clone(), - ) - .as_str() - == n.clone().as_str()) - { - __found = true; - break; - } - } - __found - }; - let let_line = if is_param { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(emit_ident(n.clone(), RenderTarget::Rust), " = ".to_string()), - val_str, - ), - ";".to_string(), - ) - } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "let ".to_string(), - emit_ident(n.clone(), RenderTarget::Rust), - ), - " = ".to_string(), - ), - val_str, - ), - ";".to_string(), - ) - }; - let next_scope = extend_scope( - &frame.scope.clone(), - &n, - resolved_type(v.clone()), - Rc::new(SubValueRelation::SubValueUnknown), - ); - match bd { - Some(b) => v2_rt::concat( - v2_rt::concat(let_line, "\n".to_string()), - emit_typed_tco_expr( - b.clone(), - &fn_name, - params.clone(), - registry.clone(), - next_scope, - frame.depth.clone(), - shared_types.clone(), - emit_info.clone(), - ), - ), - None => let_line, - } - } - _ => emit_error_expr( - "emit_rust_tco_let expected ExprLet".to_string(), - RenderTarget::Rust, - ), - } + ExprData::ExprLet => { + let n = let_binding_name_at(frame.expr.clone(), frame.scope.clone().type_env.clone().source_indices.clone()); +let v = let_value(frame.expr.clone()); +let bd = let_body(frame.expr.clone()); +let val_str = emit_typed_expr(v.clone(), registry.clone(), &frame.scope.clone(), frame.depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let is_param = { let mut __found = false; for p in params.clone().iter().cloned() { if (param_node_name_at(p.clone(), frame.scope.clone().type_env.clone().source_indices.clone()).as_str() == n.clone().as_str()) { __found = true; break; } } __found }; +let let_line = if is_param { + v2_rt::concat(v2_rt::concat(v2_rt::concat(emit_ident(n.clone(), RenderTarget::Rust), " = ".to_string()), val_str), ";".to_string()) + } else { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let ".to_string(), emit_ident(n.clone(), RenderTarget::Rust)), " = ".to_string()), val_str), ";".to_string()) + }; +let next_scope = extend_scope(&frame.scope.clone(), &n, resolved_type(v.clone()), Rc::new(SubValueRelation::SubValueUnknown)); +match bd { + Some(b) => v2_rt::concat(v2_rt::concat(let_line, "\n".to_string()), emit_typed_tco_expr(b.clone(), &fn_name, params.clone(), registry.clone(), next_scope, frame.depth.clone(), shared_types.clone(), emit_info.clone())), + None => let_line, +} +}, + _ => emit_error_expr("emit_rust_tco_let expected ExprLet".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_tco_block( - frame: &Rc, - fn_name: String, - params: &Rc>>, - registry: &Rc>>, - shared_types: &Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_rust_tco_block(frame: &Rc, fn_name: String, params: &Rc>>, registry: &Rc>>, shared_types: &Rc>, emit_info: &Rc) -> String { match (*frame.expr.clone().expr_data.clone()).clone() { - ExprData::ExprBlock => { - let ss = frame.expr.clone().children.clone(); - if ((ss.clone().len() as i64) == 0) { - "break;".to_string() - } else { - { - let init_state = emit_tco_init_block_stmts( - ss.clone(), - Rc::new(vec![]), - frame.scope.clone(), - registry.clone(), - frame.depth.clone(), - shared_types.clone(), - emit_info.clone(), - params.clone(), - ); - let last_str = match ss.clone().last().cloned() { - Some(last_expr) => emit_typed_tco_expr( - last_expr.clone(), - &fn_name, - params.clone(), - registry.clone(), - init_state.scope.clone(), - frame.depth.clone(), - shared_types.clone(), - emit_info.clone(), - ), - None => "break;".to_string(), - }; - if ((init_state.text.clone().len() as i64) == 0) { - last_str - } else { - v2_rt::concat( - v2_rt::concat( - init_state.text.clone().join(&"\n".to_string()), - "\n".to_string(), - ), - last_str, - ) - } + ExprData::ExprBlock => { + let ss = frame.expr.clone().children.clone(); +if ((ss.clone().len() as i64) == 0) { + "break;".to_string() + } else { + { + let init_state = emit_tco_init_block_stmts(ss.clone(), Rc::new(vec![]), frame.scope.clone(), registry.clone(), frame.depth.clone(), shared_types.clone(), emit_info.clone(), params.clone()); +let last_str = match ss.clone().last().cloned() { + Some(last_expr) => emit_typed_tco_expr(last_expr.clone(), &fn_name, params.clone(), registry.clone(), init_state.scope.clone(), frame.depth.clone(), shared_types.clone(), emit_info.clone()), + None => "break;".to_string(), +}; +if ((init_state.text.clone().len() as i64) == 0) { + last_str + } else { + v2_rt::concat(v2_rt::concat(init_state.text.clone().join(&"\n".to_string()), "\n".to_string()), last_str) } - } +} } - _ => emit_error_expr( - "emit_rust_tco_block expected ExprBlock".to_string(), - RenderTarget::Rust, - ), - } +}, + _ => emit_error_expr("emit_rust_tco_block expected ExprBlock".to_string(), RenderTarget::Rust), +} } -pub fn emit_rust_tco_default_return( - frame: &Rc, - registry: Rc>>, - shared_types: Rc>, - emit_info: Rc, -) -> String { - { - let val_str = emit_typed_expr( - frame.expr.clone(), - registry, - &frame.scope.clone(), - frame.depth.clone(), - shared_types, - emit_info, - 1024, - ); - v2_rt::concat( - v2_rt::concat("break ".to_string(), val_str), - ";".to_string(), - ) - } +pub fn emit_rust_tco_default_return(frame: &Rc, registry: Rc>>, shared_types: Rc>, emit_info: Rc) -> String { + { + let val_str = emit_typed_expr(frame.expr.clone(), registry, &frame.scope.clone(), frame.depth.clone(), shared_types, emit_info, 1024); +v2_rt::concat(v2_rt::concat("break ".to_string(), val_str), ";".to_string()) +} } -pub fn emit_typed_tco_expr( - texpr: Rc, - fn_name: &String, - params: Rc>>, - registry: Rc>>, - scope: Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, -) -> String { - emit_shared_tco_expr( - Rc::new(TcoFrame { - expr: texpr, - scope: scope, - depth: depth, - }), - fn_name.clone(), - |input| { - emit_typed_tco_reassign( - input.args.clone(), - ¶ms, - registry.clone(), - &input.scope.clone(), - input.depth.clone(), - shared_types.clone(), - &emit_info, - ) - }, - |frame| { - emit_rust_tco_non_self_call( - &frame, - registry.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - |frame| { - emit_rust_tco_if( - &frame, - &fn_name, - ¶ms, - ®istry, - &shared_types, - &emit_info, - ) - }, - |frame| { - emit_rust_tco_match( - &frame, - fn_name.clone(), - params.clone(), - ®istry, - &shared_types, - &emit_info, - ) - }, - |frame| { - emit_rust_tco_let( - &frame, - fn_name.clone(), - ¶ms, - ®istry, - &shared_types, - &emit_info, - ) - }, - |frame| { - emit_rust_tco_block( - &frame, - fn_name.clone(), - ¶ms, - ®istry, - &shared_types, - &emit_info, - ) - }, - |frame| { - emit_rust_tco_default_return( - &frame, - registry.clone(), - shared_types.clone(), - emit_info.clone(), - ) - }, - ) +pub fn emit_typed_tco_expr(texpr: Rc, fn_name: &String, params: Rc>>, registry: Rc>>, scope: Rc, depth: i64, shared_types: Rc>, emit_info: Rc) -> String { + emit_shared_tco_expr(Rc::new(TcoFrame { + expr: texpr, + scope: scope, + depth: depth, +}), fn_name.clone(), |input| emit_typed_tco_reassign(input.args.clone(), ¶ms, registry.clone(), &input.scope.clone(), input.depth.clone(), shared_types.clone(), &emit_info), |frame| emit_rust_tco_non_self_call(&frame, registry.clone(), shared_types.clone(), emit_info.clone()), |frame| emit_rust_tco_if(&frame, &fn_name, ¶ms, ®istry, &shared_types, &emit_info), |frame| emit_rust_tco_match(&frame, fn_name.clone(), params.clone(), ®istry, &shared_types, &emit_info), |frame| emit_rust_tco_let(&frame, fn_name.clone(), ¶ms, ®istry, &shared_types, &emit_info), |frame| emit_rust_tco_block(&frame, fn_name.clone(), ¶ms, ®istry, &shared_types, &emit_info), |frame| emit_rust_tco_default_return(&frame, registry.clone(), shared_types.clone(), emit_info.clone())) } -pub fn emit_typed_tco_match_arm( - arm: &Rc, - fn_name: String, - params: Rc>>, - registry: &Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: &Rc, - scrut_type: &String, -) -> String { +pub fn emit_typed_tco_match_arm(arm: &Rc, fn_name: String, params: Rc>>, registry: &Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: &Rc, scrut_type: &String) -> String { { let arm_pat = arm_pattern(arm.clone()); - let arm_g = arm_guard(&arm); - let arm_b = arm_body(&arm); - let si = scope.type_env.clone().source_indices.clone(); - let rc_analysis = analyze_rc_pattern( - arm_pat.clone(), - scrut_type.clone(), - &shared_types, - &emit_info, - si.clone(), - ); - let pat_str = if rc_analysis.needs_rc_pattern.clone() { - emit_pattern_rc_aware( - arm_pat.clone(), - rc_analysis.clone(), - shared_types.clone(), - scrut_type.clone(), - si.clone(), - emit_info.clone(), - ) - } else { - emit_pattern( - arm_pat.clone(), - shared_types.clone(), - scrut_type.clone(), - si.clone(), - emit_info.clone(), - ) +let arm_g = arm_guard(&arm); +let arm_b = arm_body(&arm); +let si = scope.type_env.clone().source_indices.clone(); +let rc_analysis = analyze_rc_pattern(arm_pat.clone(), scrut_type.clone(), &shared_types, &emit_info, si.clone()); +let pat_str = if rc_analysis.needs_rc_pattern.clone() { + emit_pattern_rc_aware(arm_pat.clone(), rc_analysis.clone(), shared_types.clone(), scrut_type.clone(), si.clone(), emit_info.clone()) + } else { + emit_pattern(arm_pat.clone(), shared_types.clone(), scrut_type.clone(), si.clone(), emit_info.clone()) }; - let field_guards = collect_pattern_string_guards(arm_pat.clone(), si.clone()); - let arm_guard_str = match arm_g { - Some(g) => emit_typed_expr( - g.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ), - 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())) - { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" if ".to_string(), field_guards.clone()), - " && ".to_string(), - ), - arm_guard_str.clone(), - ) +let field_guards = collect_pattern_string_guards(arm_pat.clone(), si.clone()); +let arm_guard_str = match arm_g { + Some(g) => emit_typed_expr(g.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024), + 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())) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(" if ".to_string(), field_guards.clone()), " && ".to_string()), arm_guard_str.clone()) } else { if (field_guards.clone().as_str() != "".to_string().as_str()) { v2_rt::concat(" if ".to_string(), field_guards.clone()) @@ -11760,529 +4650,199 @@ pub fn emit_typed_tco_match_arm( } } }; - let body_str = emit_typed_tco_expr( - arm_b, - &fn_name, - params, - registry.clone(), - scope.clone(), - depth.clone(), - shared_types.clone(), - emit_info.clone(), - ); - if rc_analysis.needs_rc_pattern.clone() { +let body_str = emit_typed_tco_expr(arm_b, &fn_name, params, registry.clone(), scope.clone(), depth.clone(), shared_types.clone(), emit_info.clone()); +if rc_analysis.needs_rc_pattern.clone() { { - let prelude = rc_pattern_preludes( - arm_pat.clone(), - rc_analysis.clone(), - shared_types.clone(), - si.clone(), - emit_info.clone(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" ".to_string(), pat_str), - guard_str, - ), - " => { ".to_string(), - ), - prelude, - ), - " ".to_string(), - ), - body_str, - ), - " },".to_string(), - ) - } + let prelude = rc_pattern_preludes(arm_pat.clone(), rc_analysis.clone(), shared_types.clone(), si.clone(), emit_info.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), pat_str), guard_str), " => { ".to_string()), prelude), " ".to_string()), body_str), " },".to_string()) +} } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(" ".to_string(), pat_str), guard_str), - " => { ".to_string(), - ), - body_str, - ), - " },".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), pat_str), guard_str), " => { ".to_string()), body_str), " },".to_string()) } - } +} } -pub fn expr_references_var( - node: &Rc, - var_name: String, - source_indices: Rc>>, -) -> bool { +pub fn expr_references_var(node: &Rc, var_name: String, source_indices: Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*node.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(node.clone(), source_indices.clone()).as_str() - == var_name.clone().as_str()) - } - _ => { - let mut __found = false; - for c in node.children.clone().iter().cloned() { - if expr_references_var(&c, var_name.clone(), source_indices.clone()) { - __found = true; - break; - } - } - __found - } - } + ExprData::ExprVar { .. } => (expr_var_name_at(node.clone(), source_indices.clone()).as_str() == var_name.clone().as_str()), + _ => { let mut __found = false; for c in node.children.clone().iter().cloned() { if expr_references_var(&c, var_name.clone(), source_indices.clone()) { __found = true; break; } } __found }, +} }) } -pub fn emit_typed_tco_reassign( - args: Rc>>, - params: &Rc>>, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: &Rc, -) -> String { +pub fn emit_typed_tco_reassign(args: Rc>>, params: &Rc>>, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: &Rc) -> String { { let si = scope.type_env.clone().source_indices.clone(); - let arg_values = Rc::new({ - let mut __result = Vec::new(); - for a in args.iter().cloned() { - __result.push(arg_value(&a)); - } - __result - }); - let identity_params = Rc::new( - params - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |m: Rc>, pair: (i64, Rc)| { - let pname = param_node_name_at(pair.1.clone(), si.clone()); - let av = match arg_values.clone().get(pair.0.clone() as usize).cloned() { - Some(v) => v.clone(), - None => pair.1.clone(), - }; - if is_tco_identity_passthrough(&av, pname.clone(), si.clone()) { - v2_rt::rc_map_insert(m.clone(), pname.clone(), true) - } else { - m.clone() - } - }, - ); - let filtered_arg_values = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - params - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if match v2_rt::map_get( - &identity_params, - param_node_name_at(pair.1.clone(), si.clone()), - ) { - Some(_) => false, - None => true, - } { - __result.push(pair); - } - } - __result - }) - .iter() - .cloned() - { - __result.push( - match arg_values.clone().get(pair.0.clone() as usize).cloned() { - Some(v) => v.clone(), - None => pair.1.clone(), - }, - ); - } - __result - }); - let filtered_params = Rc::new({ - let mut __result = Vec::new(); - for p in params.clone().iter().cloned() { - if match v2_rt::map_get(&identity_params, param_node_name_at(p.clone(), si.clone())) - { - Some(_) => false, - None => true, - } { - __result.push(p); - } - } - __result - }); - let tco_movable = - filtered_params.clone().iter().cloned().fold( - emit_info.movable.clone(), - |m: Rc>, p: Rc| { - let pname = param_node_name_at(p.clone(), si.clone()); - let ref_count = filtered_arg_values.clone().iter().cloned().fold( - 0, - |n: i64, av: Rc| { - if expr_references_var(&av, pname.clone(), si.clone()) { - (n.clone() + 1) - } else { - n.clone() - } - }, - ); - if (ref_count.clone() <= 1) { - v2_rt::rc_map_insert(m.clone(), pname.clone(), true) - } else { - m.clone() - } - }, - ); - let tco_emit_info = Rc::new(EmitGraphInfo { - movable: tco_movable, - ..(*emit_info.clone()).clone() - }); - let ordered_args = Rc::new({ - let mut __result = Vec::new(); - for av in filtered_arg_values.clone().iter().cloned() { - __result.push(emit_typed_expr( - av.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - tco_emit_info.clone(), - 1024, - )); +let arg_values = Rc::new({ let mut __result = Vec::new(); for a in args.iter().cloned() { __result.push(arg_value(&a)); } __result }); +let identity_params = Rc::new(params.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(v2_rt::rc_empty_map::(), |m: Rc>, pair: (i64, Rc)| { + let pname = param_node_name_at(pair.1.clone(), si.clone()); +let av = match arg_values.clone().get(pair.0.clone() as usize).cloned() { + Some(v) => v.clone(), + None => pair.1.clone(), +}; +if is_tco_identity_passthrough(&av, pname.clone(), si.clone()) { + v2_rt::rc_map_insert(m.clone(), pname.clone(), true) + } else { + m.clone() } - __result - }); - let param_names = Rc::new({ - let mut __result = Vec::new(); - for p in filtered_params.clone().iter().cloned() { - __result.push(emit_ident( - param_node_name_at(p.clone(), si.clone()), - RenderTarget::Rust, - )); +}); +let filtered_arg_values = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(params.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if match v2_rt::map_get(&identity_params, param_node_name_at(pair.1.clone(), si.clone())) { + Some(_) => false, + None => true, +} { __result.push(pair); } } __result }).iter().cloned() { __result.push(match arg_values.clone().get(pair.0.clone() as usize).cloned() { + Some(v) => v.clone(), + None => pair.1.clone(), +}); } __result }); +let filtered_params = Rc::new({ let mut __result = Vec::new(); for p in params.clone().iter().cloned() { if match v2_rt::map_get(&identity_params, param_node_name_at(p.clone(), si.clone())) { + Some(_) => false, + None => true, +} { __result.push(p); } } __result }); +let tco_movable = filtered_params.clone().iter().cloned().fold(emit_info.movable.clone(), |m: Rc>, p: Rc| { + let pname = param_node_name_at(p.clone(), si.clone()); +let ref_count = filtered_arg_values.clone().iter().cloned().fold(0, |n: i64, av: Rc| if expr_references_var(&av, pname.clone(), si.clone()) { + (n.clone() + 1) + } else { + n.clone() + }); +if (ref_count.clone() <= 1) { + v2_rt::rc_map_insert(m.clone(), pname.clone(), true) + } else { + m.clone() } - __result - }); - let all_lines = tco_reassign_core( - ordered_args, - param_names, - "__tco_".to_string(), - "let ".to_string(), - " = ".to_string(), - ";".to_string(), - "continue;".to_string(), - &"".to_string(), - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("{\n".to_string(), make_indent((depth.clone() + 1))), - all_lines.join(&"\n".to_string()), - ), - "\n}".to_string(), - ) - } +}); +let tco_emit_info = Rc::new(EmitGraphInfo { movable: tco_movable, ..(*emit_info.clone()).clone() }); +let ordered_args = Rc::new({ let mut __result = Vec::new(); for av in filtered_arg_values.clone().iter().cloned() { __result.push(emit_typed_expr(av.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), tco_emit_info.clone(), 1024)); } __result }); +let param_names = Rc::new({ let mut __result = Vec::new(); for p in filtered_params.clone().iter().cloned() { __result.push(emit_ident(param_node_name_at(p.clone(), si.clone()), RenderTarget::Rust)); } __result }); +let all_lines = tco_reassign_core(ordered_args, param_names, "__tco_".to_string(), "let ".to_string(), " = ".to_string(), ";".to_string(), "continue;".to_string(), &"".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat("{\n".to_string(), make_indent((depth.clone() + 1))), all_lines.join(&"\n".to_string())), "\n}".to_string()) +} } -pub fn emit_service_def( - item: &Rc, - registry: Rc>>, - shared_types: Rc>, - env: &Rc, -) -> String { +pub fn emit_service_def(item: &Rc, registry: Rc>>, shared_types: Rc>, env: &Rc) -> String { { let safe_name = sanitize_service_name(authored_name(env.clone(), item.clone())); - let fallback_transport = service_fallback_transport(&item); - let op_children = item.children.clone(); - let struct_def = emit_service_struct( - safe_name.clone(), - fallback_transport.clone(), - op_children.clone(), - item.clone(), - env.source_indices.clone(), - ); - let impl_block = emit_service_impl( - &safe_name, - &fallback_transport, - &op_children, - registry, - shared_types, - &env, - &item, - ); - v2_rt::concat(v2_rt::concat(struct_def, "\n\n".to_string()), impl_block) - } +let fallback_transport = service_fallback_transport(&item); +let op_children = item.children.clone(); +let struct_def = emit_service_struct(safe_name.clone(), fallback_transport.clone(), op_children.clone(), item.clone(), env.source_indices.clone()); +let impl_block = emit_service_impl(&safe_name, &fallback_transport, &op_children, registry, shared_types, &env, &item); +v2_rt::concat(v2_rt::concat(struct_def, "\n\n".to_string()), impl_block) +} } -pub fn emit_service_struct( - name: String, - fallback_transport: Rc, - op_children: Rc>>, - service_item: Rc, - source_indices: Rc>>, -) -> String { +pub fn emit_service_struct(name: String, fallback_transport: Rc, op_children: Rc>>, service_item: Rc, source_indices: Rc>>) -> String { { let derives = "#[derive(Debug, Clone)]".to_string(); - let config_fields = emit_service_config_fields( - fallback_transport, - op_children, - service_item, - &source_indices, - ); - let dry_run_field = "\n pub dry_run: crate::dry_run::DryRunMode,".to_string(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(derives, "\npub struct ".to_string()), name), - " {\n".to_string(), - ), - config_fields, - ), - dry_run_field, - ), - "\n}".to_string(), - ) - } +let config_fields = emit_service_config_fields(fallback_transport, op_children, service_item, &source_indices); +let dry_run_field = "\n pub dry_run: crate::dry_run::DryRunMode,".to_string(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(derives, "\npub struct ".to_string()), name), " {\n".to_string()), config_fields), dry_run_field), "\n}".to_string()) +} } -pub fn emit_service_config_fields( - fallback_transport: Rc, - op_children: Rc>>, - service_item: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_service_config_fields(fallback_transport: Rc, op_children: Rc>>, service_item: Rc, source_indices: &Rc>>) -> String { { let fs = compute_service_fields(&fallback_transport, &op_children, &source_indices); - let has_svc_auth = match service_config_auth_source(service_item, source_indices.clone()) { - Some(_) => true, - None => false, - }; - let fs = if has_svc_auth { +let has_svc_auth = match service_config_auth_source(service_item, source_indices.clone()) { + Some(_) => true, + None => false, +}; +let fs = if has_svc_auth { ServiceFieldSet { - has_rest: fs.has_rest.clone(), - has_shell: fs.has_shell.clone(), - has_file: fs.has_file.clone(), - has_auth: true, - } + has_rest: fs.has_rest.clone(), + has_shell: fs.has_shell.clone(), + has_file: fs.has_file.clone(), + has_auth: true, +} } else { fs.clone() }; - let decls = service_field_decls( - &fs, - &language_spec(RenderTarget::Rust).service_fields.clone(), - ); - if ((decls.clone().len() as i64) == 0) { +let decls = service_field_decls(&fs, &language_spec(RenderTarget::Rust).service_fields.clone()); +if ((decls.clone().len() as i64) == 0) { " // No configuration needed for local binding.\n".to_string() } else { decls.clone().join(&"".to_string()) } - } +} } -pub fn emit_service_impl( - name: &String, - transport: &Rc, - op_children: &Rc>>, - registry: Rc>>, - shared_types: Rc>, - env: &Rc, - service_item: &Rc, -) -> String { +pub fn emit_service_impl(name: &String, transport: &Rc, op_children: &Rc>>, registry: Rc>>, shared_types: Rc>, env: &Rc, service_item: &Rc) -> String { { let depth = 0; - let new_method = emit_service_new_method( - name.clone(), - &transport, - op_children.clone(), - &service_item, - &env.source_indices.clone(), - ); - let method_strs = Rc::new({ - let mut __result = Vec::new(); - for op_node in op_children.clone().iter().cloned() { - __result.push(emit_operation_method( - name.clone(), - transport.clone(), - &op_node, - ®istry, - (depth.clone() + 1), - &shared_types, - &env, - service_item.clone(), - )); - } - __result - }); - let all_methods = v2_rt::concat(Rc::new(vec![new_method]), method_strs); - let methods_str = all_methods.join(&"\n\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("impl ".to_string(), name.clone()), - " {\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - methods_str, - ), - "\n}".to_string(), - ) - } +let new_method = emit_service_new_method(name.clone(), &transport, op_children.clone(), &service_item, &env.source_indices.clone()); +let method_strs = Rc::new({ let mut __result = Vec::new(); for op_node in op_children.clone().iter().cloned() { __result.push(emit_operation_method(name.clone(), transport.clone(), &op_node, ®istry, (depth.clone() + 1), &shared_types, &env, service_item.clone())); } __result }); +let all_methods = v2_rt::concat(Rc::new(vec![new_method]), method_strs); +let methods_str = all_methods.join(&"\n\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("impl ".to_string(), name.clone()), " {\n".to_string()), make_indent((depth.clone() + 1))), methods_str), "\n}".to_string()) +} } -pub fn emit_service_new_method( - name: String, - fallback_transport: &Rc, - op_children: Rc>>, - service_item: &Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_service_new_method(name: String, fallback_transport: &Rc, op_children: Rc>>, service_item: &Rc, source_indices: &Rc>>) -> String { { let fs = compute_service_fields(&fallback_transport, &op_children, &source_indices); - let has_svc_auth = - match service_config_auth_source(service_item.clone(), source_indices.clone()) { - Some(_) => true, - None => false, - }; - let fs = if has_svc_auth { +let has_svc_auth = match service_config_auth_source(service_item.clone(), source_indices.clone()) { + Some(_) => true, + None => false, +}; +let fs = if has_svc_auth { ServiceFieldSet { - has_rest: fs.has_rest.clone(), - has_shell: fs.has_shell.clone(), - has_file: fs.has_file.clone(), - has_auth: true, - } + has_rest: fs.has_rest.clone(), + has_shell: fs.has_shell.clone(), + has_file: fs.has_file.clone(), + has_auth: true, +} } else { fs.clone() }; - let from_config = - match service_config_endpoint(service_item.clone(), source_indices.clone()) { - Some(ep) => match (*ep.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { - unreachable!() - }; - s.clone() - } - _ => "".to_string(), - }, - None => "".to_string(), - }; - let base_url_default = if (from_config.clone().as_str() != "".to_string().as_str()) { +let from_config = match service_config_endpoint(service_item.clone(), source_indices.clone()) { + Some(ep) => match (*ep.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { unreachable!() }; s.clone() }, + _ => "".to_string(), +}, + None => "".to_string(), +}; +let base_url_default = if (from_config.clone().as_str() != "".to_string().as_str()) { from_config.clone() } else { if fs.has_rest.clone() { { - let fallback_is_rest = - is_rest_transport(fallback_transport.clone(), source_indices.clone()); - let from_fallback = if fallback_is_rest { - match transport_base_url(fallback_transport.clone(), source_indices.clone()) - { - Some(bu) => match (*bu.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: s, .. } = value.as_ref() - else { - unreachable!() - }; - s.clone() - } - _ => "".to_string(), - }, - None => "".to_string(), - } + let fallback_is_rest = is_rest_transport(fallback_transport.clone(), source_indices.clone()); +let from_fallback = if fallback_is_rest { + match transport_base_url(fallback_transport.clone(), source_indices.clone()) { + Some(bu) => match (*bu.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { unreachable!() }; s.clone() }, + _ => "".to_string(), +}, + None => "".to_string(), +} } else { "".to_string() }; - if (from_fallback.clone().as_str() != "".to_string().as_str()) { +if (from_fallback.clone().as_str() != "".to_string().as_str()) { from_fallback.clone() } else { "http://localhost".to_string() } - } +} } else { "".to_string() } }; - let ctors = service_field_ctors( - &fs, - &language_spec(RenderTarget::Rust).service_fields.clone(), - ); - let ctors = Rc::new({ - let mut __result = Vec::new(); - for c in ctors.clone().iter().cloned() { - __result.push(apply_type_template1(c.clone(), base_url_default.clone())); - } - __result - }); - let ctors = match service_config_auth_source(service_item.clone(), source_indices.clone()) { - Some(src) => Rc::new({ - let mut __result = Vec::new(); - for c in ctors.clone().iter().cloned() { - __result.push(if v2_rt::contains(c.clone(), "auth_token".to_string()) { - emit_auth_source_ctor(&src, source_indices.clone()) - } else { - c.clone() - }); - } - __result - }), - None => ctors.clone(), - }; - let inits = ctors.clone().join(&"".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "pub fn new(dry_run: crate::dry_run::DryRunMode) -> Self {\n" - .to_string(), - " ".to_string(), - ), - name, - ), - " {\n".to_string(), - ), - inits, - ), - " dry_run,\n".to_string(), - ), - " }\n".to_string(), - ), - "}".to_string(), - ) - } +let ctors = service_field_ctors(&fs, &language_spec(RenderTarget::Rust).service_fields.clone()); +let ctors = Rc::new({ let mut __result = Vec::new(); for c in ctors.clone().iter().cloned() { __result.push(apply_type_template1(c.clone(), base_url_default.clone())); } __result }); +let ctors = match service_config_auth_source(service_item.clone(), source_indices.clone()) { + Some(src) => Rc::new({ let mut __result = Vec::new(); for c in ctors.clone().iter().cloned() { __result.push(if v2_rt::contains(c.clone(), "auth_token".to_string()) { + emit_auth_source_ctor(&src, source_indices.clone()) + } else { + c.clone() + }); } __result }), + None => ctors.clone(), +}; +let inits = ctors.clone().join(&"".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("pub fn new(dry_run: crate::dry_run::DryRunMode) -> Self {\n".to_string(), " ".to_string()), name), " {\n".to_string()), inits), " dry_run,\n".to_string()), " }\n".to_string()), "}".to_string()) +} } -pub fn emit_auth_source_ctor( - source_expr: &Rc, - source_indices: Rc>>, -) -> String { +pub fn emit_auth_source_ctor(source_expr: &Rc, source_indices: Rc>>) -> 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()) { @@ -12302,195 +4862,47 @@ pub fn emit_auth_source_ctor( } } -pub fn emit_modifier_doc_from_props( - properties: Rc>>, - source_indices: Rc>>, -) -> String { +pub fn emit_modifier_doc_from_props(properties: Rc>>, source_indices: Rc>>) -> String { { let names = extract_modifier_names(properties, source_indices); - if ((names.clone().len() as i64) == 0) { +if ((names.clone().len() as i64) == 0) { "".to_string() } else { - v2_rt::concat( - v2_rt::concat( - "/// Modifiers: ".to_string(), - names.clone().join(&", ".to_string()), - ), - "\n".to_string(), - ) + v2_rt::concat(v2_rt::concat("/// Modifiers: ".to_string(), names.clone().join(&", ".to_string())), "\n".to_string()) } - } +} } -pub fn emit_operation_method( - service_name: String, - transport: Rc, - op_node: &Rc, - registry: &Rc>>, - depth: i64, - shared_types: &Rc>, - env: &Rc, - service_item: Rc, -) -> String { +pub fn emit_operation_method(service_name: String, transport: Rc, op_node: &Rc, registry: &Rc>>, depth: i64, shared_types: &Rc>, env: &Rc, service_item: Rc) -> String { { let op_text = authored_name(env.clone(), op_node.clone()); - let input_params = Rc::new({ - let mut __result = Vec::new(); - for p in op_node.params.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - param_node_name_at(p.clone(), env.source_indices.clone()), - RenderTarget::Rust, - ), - rust_items().param_type_sep.clone(), - ), - emit_rust_param_type( - ¶m_node_type_expr(&p), - &shared_types, - &env.source_indices.clone(), - ), - )); - } - __result - }); - let params_str = input_params.join(&", ".to_string()); - let all_params = if (params_str.clone().as_str() == "".to_string().as_str()) { +let input_params = Rc::new({ let mut __result = Vec::new(); for p in op_node.params.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(param_node_name_at(p.clone(), env.source_indices.clone()), RenderTarget::Rust), rust_items().param_type_sep.clone()), emit_rust_param_type(¶m_node_type_expr(&p), &shared_types, &env.source_indices.clone()))); } __result }); +let params_str = input_params.join(&", ".to_string()); +let all_params = if (params_str.clone().as_str() == "".to_string().as_str()) { "&self".to_string() } else { v2_rt::concat("&self, ".to_string(), params_str.clone()) }; - let ret_type = render_rust_type( - resolved_type(op_node.clone()), - shared_types.clone(), - env.source_indices.clone(), - ); - let eff_transport = effective_operation_transport(op_node.clone(), transport); - let op_inferred = resolved_type(op_node.clone()); - let real_body = emit_transport_call( - &eff_transport, - op_text.clone(), - registry.clone(), - (depth.clone() + 2), - op_inferred, - service_item, - op_node.clone(), - &env.source_indices.clone(), - shared_types.clone(), - env.clone(), - ); - let mock_props = Rc::new({ - let mut __result = Vec::new(); - for p in op_node.properties.clone().iter().cloned() { - if has_mock_prefix(&field_init_node_name_at( - p.clone(), - env.source_indices.clone(), - )) { - __result.push(p); - } - } - __result - }); - let dry_run_body = emit_dry_run_branch_from_props( - &op_text, - &resolved_type(op_node.clone()), - &mock_props, - registry.clone(), - &env.source_indices.clone(), - &op_node, - env.clone(), - shared_types.clone(), - ); - let body = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "if self.dry_run.is_dry_run() {\n".to_string(), - make_indent((depth.clone() + 2)), - ), - dry_run_body, - ), - "\n".to_string(), - ), - "} else {\n".to_string(), - ), - make_indent((depth.clone() + 2)), - ), - real_body, - ), - "\n".to_string(), - ), - "}".to_string(), - ); - let modifier_doc = - emit_modifier_doc_from_props(op_node.properties.clone(), env.source_indices.clone()); - let items = rust_items(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - modifier_doc, - rust_visibility_prefix(), - ), - items.async_prefix.clone(), - ), - items.func_keyword.clone(), - ), - " ".to_string(), - ), - emit_ident(op_text.clone(), RenderTarget::Rust), - ), - "(".to_string(), - ), - all_params, - ), - ") -> Result<".to_string(), - ), - ret_type, - ), - ", Box> {\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - body, - ), - "\n}".to_string(), - ) - } +let ret_type = render_rust_type(resolved_type(op_node.clone()), shared_types.clone(), env.source_indices.clone()); +let eff_transport = effective_operation_transport(op_node.clone(), transport); +let op_inferred = resolved_type(op_node.clone()); +let real_body = emit_transport_call(&eff_transport, op_text.clone(), registry.clone(), (depth.clone() + 2), op_inferred, service_item, op_node.clone(), &env.source_indices.clone(), shared_types.clone(), env.clone()); +let mock_props = Rc::new({ let mut __result = Vec::new(); for p in op_node.properties.clone().iter().cloned() { if has_mock_prefix(&field_init_node_name_at(p.clone(), env.source_indices.clone())) { __result.push(p); } } __result }); +let dry_run_body = emit_dry_run_branch_from_props(&op_text, &resolved_type(op_node.clone()), &mock_props, registry.clone(), &env.source_indices.clone(), &op_node, env.clone(), shared_types.clone()); +let body = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("if self.dry_run.is_dry_run() {\n".to_string(), make_indent((depth.clone() + 2))), dry_run_body), "\n".to_string()), "} else {\n".to_string()), make_indent((depth.clone() + 2))), real_body), "\n".to_string()), "}".to_string()); +let modifier_doc = emit_modifier_doc_from_props(op_node.properties.clone(), env.source_indices.clone()); +let items = rust_items(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(modifier_doc, rust_visibility_prefix()), items.async_prefix.clone()), items.func_keyword.clone()), " ".to_string()), emit_ident(op_text.clone(), RenderTarget::Rust)), "(".to_string()), all_params), ") -> Result<".to_string()), ret_type), ", Box> {\n".to_string()), make_indent((depth.clone() + 1))), body), "\n}".to_string()) +} } -pub fn emit_dry_run_branch_from_props( - op_name: &String, - inferred: &Rc, - mock_props: &Rc>>, - registry: Rc>>, - source_indices: &Rc>>, - op_node: &Rc, - env: Rc, - shared_types: Rc>, -) -> String { - { - let log_line = v2_rt::concat( - v2_rt::concat("eprintln!(\"[dry-run] ".to_string(), op_name.clone()), - "\");".to_string(), - ); - if ((mock_props.clone().len() as i64) > 0) { +pub fn emit_dry_run_branch_from_props(op_name: &String, inferred: &Rc, mock_props: &Rc>>, registry: Rc>>, source_indices: &Rc>>, op_node: &Rc, env: Rc, shared_types: Rc>) -> String { + { + let log_line = v2_rt::concat(v2_rt::concat("eprintln!(\"[dry-run] ".to_string(), op_name.clone()), "\");".to_string()); +if ((mock_props.clone().len() as i64) > 0) { { let first_mock = mock_props.clone().first().cloned(); - match first_mock { +match first_mock { Some(mp) => { let mock_json = emit_data_value_json(&field_init_node_value(&mp), source_indices.clone()); let is_multi_field_conj = ((inferred.connective.clone() == Connective::Conj) && ((inferred.children.clone().len() as i64) > 1)); @@ -12558,58 +4970,19 @@ v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::con }, None => v2_rt::concat(log_line, "\ncompile_error!(\"mock property list was non-empty but first() returned None\")".to_string()), } - } +} } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - log_line, - "\ncompile_error!(\"no mock data available for dry-run operation: " - .to_string(), - ), - op_name.clone(), - ), - "\")".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(log_line, "\ncompile_error!(\"no mock data available for dry-run operation: ".to_string()), op_name.clone()), "\")".to_string()) } - } +} } -pub fn emit_transport_call( - transport: &Rc, - op_name: String, - registry: Rc>>, - depth: i64, - inferred: Rc, - service_item: Rc, - op_node: Rc, - source_indices: &Rc>>, - shared_types: Rc>, - env: Rc, -) -> String { +pub fn emit_transport_call(transport: &Rc, op_name: String, registry: Rc>>, depth: i64, inferred: Rc, service_item: Rc, op_node: Rc, source_indices: &Rc>>, shared_types: Rc>, env: Rc) -> String { if is_rest_transport(transport.clone(), source_indices.clone()) { - emit_rest_call( - op_name, - &transport, - registry, - depth, - service_item, - op_node, - &source_indices, - shared_types, - env, - ) + emit_rest_call(op_name, &transport, registry, depth, service_item, op_node, &source_indices, shared_types, env) } else { if is_shell_transport(transport.clone()) { - emit_shell_call( - op_name, - &transport, - registry, - depth, - inferred, - &op_node, - &source_indices, - ) + emit_shell_call(op_name, &transport, registry, depth, inferred, &op_node, &source_indices) } else { if is_file_transport(transport.clone(), source_indices.clone()) { emit_file_call(op_name, inferred) @@ -12620,250 +4993,104 @@ pub fn emit_transport_call( } } -pub fn emit_rest_call( - op_name: String, - transport: &Rc, - registry: Rc>>, - depth: i64, - service_item: Rc, - op_node: Rc, - source_indices: &Rc>>, - shared_types: Rc>, - env: Rc, -) -> String { - { - let client_init = - "let client = reqwest::Client::builder().user_agent(\"gunbc/1.0\").build()?;" - .to_string(); - let url_line = emit_rest_url_line(transport.clone(), op_name, &source_indices); - let http_method = emit_rest_http_method(transport.clone(), &source_indices); - let auth_line = - emit_rest_auth_line(&transport, &service_item, http_method, &source_indices); - let query_line = emit_rest_query_line(transport.clone(), &source_indices); - let body_line = emit_rest_body_line(transport.clone(), &source_indices); - let headers = transport_headers(transport.clone(), source_indices.clone()); - let header_lines = Rc::new({ - let mut __result = Vec::new(); - for h in headers.iter().cloned() { - __result.push({ - let hval = field_init_node_value(&h); - let val_str = emit_simple_expr(&hval, &RenderTarget::Rust, &source_indices); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "let request = request.header(\"".to_string(), - field_init_node_name_at(h.clone(), source_indices.clone()), - ), - "\", ".to_string(), - ), - val_str.clone(), - ), - ");".to_string(), - ) - }); - } - __result - }); - let send_line = "let response = request.send().await?;".to_string(); - let response_handling = emit_response_code_handling( - &op_node, - transport.clone(), - &source_indices, - shared_types, - env, - ); - let all_lines = Rc::new({ - let mut __result = Vec::new(); - for l in v2_rt::concat( - v2_rt::concat( - Rc::new(vec![client_init, url_line, auth_line]), - header_lines, - ), - Rc::new(vec![query_line, body_line, send_line, response_handling]), - ) - .iter() - .cloned() - { - if (l.clone().as_str() != "".to_string().as_str()) { - __result.push(l); - } - } - __result - }); - all_lines.join(&"\n".to_string()) - } +pub fn emit_rest_call(op_name: String, transport: &Rc, registry: Rc>>, depth: i64, service_item: Rc, op_node: Rc, source_indices: &Rc>>, shared_types: Rc>, env: Rc) -> String { + { + let client_init = "let client = reqwest::Client::builder().user_agent(\"gunbc/1.0\").build()?;".to_string(); +let url_line = emit_rest_url_line(transport.clone(), op_name, &source_indices); +let http_method = emit_rest_http_method(transport.clone(), &source_indices); +let auth_line = emit_rest_auth_line(&transport, &service_item, http_method, &source_indices); +let query_line = emit_rest_query_line(transport.clone(), &source_indices); +let body_line = emit_rest_body_line(transport.clone(), &source_indices); +let headers = transport_headers(transport.clone(), source_indices.clone()); +let header_lines = Rc::new({ let mut __result = Vec::new(); for h in headers.iter().cloned() { __result.push({ + let hval = field_init_node_value(&h); +let val_str = emit_simple_expr(&hval, &RenderTarget::Rust, &source_indices); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let request = request.header(\"".to_string(), field_init_node_name_at(h.clone(), source_indices.clone())), "\", ".to_string()), val_str.clone()), ");".to_string()) +}); } __result }); +let send_line = "let response = request.send().await?;".to_string(); +let response_handling = emit_response_code_handling(&op_node, transport.clone(), &source_indices, shared_types, env); +let all_lines = Rc::new({ let mut __result = Vec::new(); for l in v2_rt::concat(v2_rt::concat(Rc::new(vec![client_init, url_line, auth_line]), header_lines), Rc::new(vec![query_line, body_line, send_line, response_handling])).iter().cloned() { if (l.clone().as_str() != "".to_string().as_str()) { __result.push(l); } } __result }); +all_lines.join(&"\n".to_string()) +} } -pub fn emit_rest_http_method( - transport: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_rest_http_method(transport: Rc, source_indices: &Rc>>) -> String { match transport_method(transport, source_indices.clone()) { - Some(m) => match m.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { .. }) => { - let method_name = expr_var_name_at(m.clone(), source_indices.clone()); - Rc::new({ - let mut __result = Vec::new(); - for ch in Rc::new(method_name.chars().map(|c| c as i64).collect::>()) - .iter() - .cloned() - { - __result.push(to_lower_char(ch.clone())); - } - __result - }) - .join(&"".to_string()) - } - _ => "compile_error!(\"transport method type not resolved\")".to_string(), - }, - None => "compile_error!(\"transport method not specified\")".to_string(), - } + Some(m) => match m.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { .. }) => { + let method_name = expr_var_name_at(m.clone(), source_indices.clone()); +Rc::new({ let mut __result = Vec::new(); for ch in Rc::new(method_name.chars().map(|c| c as i64).collect::>()).iter().cloned() { __result.push(to_lower_char(ch.clone())); } __result }).join(&"".to_string()) +}, + _ => "compile_error!(\"transport method type not resolved\")".to_string(), +}, + None => "compile_error!(\"transport method not specified\")".to_string(), +} } -pub fn emit_rest_url_line( - transport: Rc, - op_name: String, - source_indices: &Rc>>, -) -> String { +pub fn emit_rest_url_line(transport: Rc, op_name: String, source_indices: &Rc>>) -> String { match transport_path_template(transport, source_indices.clone()) { - Some(path_node) => match (*path_node.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { - value: path_str, .. - } = value.as_ref() - else { - unreachable!() - }; - v2_rt::concat( - v2_rt::concat( - "let url = format!(\"{}".to_string(), - escape_string_literal_body(path_str.clone()), - ), - "\", self.base_url);".to_string(), - ) - } - ExprData::ExprStringInterp => { - let parts = Rc::new({ - let mut __result = Vec::new(); - for child in path_node.children.clone().iter().cloned() { - __result.push(match (*child.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: text, .. } = value.as_ref() - else { - unreachable!() - }; - Rc::new(StringPart::Text { - value: text.clone(), - }) - } - _ => Rc::new(StringPart::Interpolation { - expr: arg_value(&child), - }), - }); - } - __result - }); - let fmt_segments = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.push(match (*p.clone()).clone() { - StringPart::Text { value: v, .. } => escape_rust_interp_text(v.clone()), - StringPart::Interpolation { .. } => "{}".to_string(), - }); - } - __result - }); - let fmt_str = fmt_segments.join(&"".to_string()); - let args = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.extend( - (*match (*p.clone()).clone() { - StringPart::Text { .. } => Rc::new(vec![]), - StringPart::Interpolation { expr: e, .. } => { - let var_name = emit_ident( - expr_var_name_at(e.clone(), source_indices.clone()), - RenderTarget::Rust, - ); - let is_opt = is_optional_typed_expr(e.clone()); - if is_opt.clone() { - Rc::new(vec![v2_rt::concat( - var_name.clone(), - ".as_deref().unwrap_or(\"\")".to_string(), - )]) - } else { - Rc::new(vec![var_name.clone()]) - } - } - }) - .iter() - .cloned(), - ); - } - __result - }); - if ((args.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat("let url = format!(\"{}".to_string(), fmt_str), - "\", self.base_url);".to_string(), - ) - } else { - { - let args_str = args.clone().join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("let url = format!(\"{}".to_string(), fmt_str), - "\", self.base_url, ".to_string(), - ), - args_str, - ), - ");".to_string(), - ) - } - } + Some(path_node) => match (*path_node.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: path_str, .. } = value.as_ref() else { unreachable!() }; v2_rt::concat(v2_rt::concat("let url = format!(\"{}".to_string(), escape_string_literal_body(path_str.clone())), "\", self.base_url);".to_string()) }, + ExprData::ExprStringInterp => { + let parts = Rc::new({ let mut __result = Vec::new(); for child in path_node.children.clone().iter().cloned() { __result.push(match (*child.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: text, .. } = value.as_ref() else { unreachable!() }; Rc::new(StringPart::Text { + value: text.clone(), +}) }, + _ => Rc::new(StringPart::Interpolation { + expr: arg_value(&child), +}), +}); } __result }); +let fmt_segments = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.push(match (*p.clone()).clone() { + StringPart::Text { value: v, .. } => escape_rust_interp_text(v.clone()), + StringPart::Interpolation { .. } => "{}".to_string(), +}); } __result }); +let fmt_str = fmt_segments.join(&"".to_string()); +let args = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.extend((*match (*p.clone()).clone() { + StringPart::Text { .. } => Rc::new(vec![]), + StringPart::Interpolation { expr: e, .. } => { + let var_name = emit_ident(expr_var_name_at(e.clone(), source_indices.clone()), RenderTarget::Rust); +let is_opt = is_optional_typed_expr(e.clone()); +if is_opt.clone() { + Rc::new(vec![v2_rt::concat(var_name.clone(), ".as_deref().unwrap_or(\"\")".to_string())]) + } else { + Rc::new(vec![var_name.clone()]) } - _ => "compile_error!(\"transport path must be a string literal or interpolation\");" - .to_string(), - }, - None => v2_rt::concat( - v2_rt::concat( - "let url = format!(\"{}/{}\", self.base_url, \"".to_string(), - emit_ident(op_name, RenderTarget::Rust), - ), - "\");".to_string(), - ), - } +}, +}).iter().cloned()); } __result }); +if ((args.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat("let url = format!(\"{}".to_string(), fmt_str), "\", self.base_url);".to_string()) + } else { + { + let args_str = args.clone().join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let url = format!(\"{}".to_string(), fmt_str), "\", self.base_url, ".to_string()), args_str), ");".to_string()) +} + } +}, + _ => "compile_error!(\"transport path must be a string literal or interpolation\");".to_string(), +}, + None => v2_rt::concat(v2_rt::concat("let url = format!(\"{}/{}\", self.base_url, \"".to_string(), emit_ident(op_name, RenderTarget::Rust)), "\");".to_string()), +} } -pub fn emit_rest_auth_line( - transport: &Rc, - service_item: &Rc, - http_method: String, - source_indices: &Rc>>, -) -> String { +pub fn emit_rest_auth_line(transport: &Rc, service_item: &Rc, http_method: String, source_indices: &Rc>>) -> String { { let auth_scheme = service_config_auth(service_item.clone(), source_indices.clone()); - let auth_input = service_config_auth_input(service_item.clone(), source_indices.clone()); - match auth_scheme { - Some(auth) => { - let has_auth_source = match service_config_auth_source( - service_item.clone(), - source_indices.clone(), - ) { - Some(_) => true, - None => false, - }; - let token_param = if has_auth_source { - "self.auth_token.clone()".to_string() - } else { - match auth_input { +let auth_input = service_config_auth_input(service_item.clone(), source_indices.clone()); +match auth_scheme { + Some(auth) => { + let has_auth_source = match service_config_auth_source(service_item.clone(), source_indices.clone()) { + Some(_) => true, + None => false, +}; +let token_param = if has_auth_source { + "self.auth_token.clone()".to_string() + } else { + match auth_input { Some(ai) => emit_simple_expr(&ai, &RenderTarget::Rust, &source_indices), None => "compile_error!(\"service config has auth but no auth_input or auth_source\")".to_string(), } - }; - match (*auth.expr_data.clone()).clone() { + }; +match (*auth.expr_data.clone()).clone() { ExprData::ExprVar { .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let request = client.".to_string(), http_method), "(&url)\n .header(\"Authorization\", format!(\"Bearer {}\", ".to_string()), token_param), "));".to_string()), ExprData::ExprCall { .. } => { let header_name = match auth.children.clone().first().cloned() { @@ -12877,104 +5104,41 @@ v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::con }, _ => v2_rt::concat(v2_rt::concat("compile_error!(\"unrecognized auth scheme expression shape\"); let request = client.".to_string(), http_method), "(&url);".to_string()), } - } - None => { - if transport_has_auth(transport.clone(), source_indices.clone()) { - { - let header_name = match transport_auth_header_name( - transport.clone(), - source_indices.clone(), - ) { - Some(h) => h.clone(), - None => "Authorization".to_string(), - }; - let token_node = - match transport_auth_token(transport.clone(), source_indices.clone()) { - Some(tn) => { - emit_simple_expr(&tn, &RenderTarget::Rust, &source_indices) - } - None => "\"\"".to_string(), - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "let request = client.".to_string(), - http_method, - ), - "(&url)\n .header(\"".to_string(), - ), - header_name, - ), - "\", ".to_string(), - ), - token_node, - ), - ");".to_string(), - ) - } - } else { - v2_rt::concat( - v2_rt::concat("let request = client.".to_string(), http_method), - "(&url);".to_string(), - ) - } - } - } - } +}, + None => if transport_has_auth(transport.clone(), source_indices.clone()) { + { + let header_name = match transport_auth_header_name(transport.clone(), source_indices.clone()) { + Some(h) => h.clone(), + None => "Authorization".to_string(), +}; +let token_node = match transport_auth_token(transport.clone(), source_indices.clone()) { + Some(tn) => emit_simple_expr(&tn, &RenderTarget::Rust, &source_indices), + None => "\"\"".to_string(), +}; +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let request = client.".to_string(), http_method), "(&url)\n .header(\"".to_string()), header_name), "\", ".to_string()), token_node), ");".to_string()) +} + } else { + v2_rt::concat(v2_rt::concat("let request = client.".to_string(), http_method), "(&url);".to_string()) + }, +} +} } -pub fn emit_rest_query_line( - transport: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_rest_query_line(transport: Rc, source_indices: &Rc>>) -> String { match transport_query(transport, source_indices.clone()) { - Some(q) => { - let pairs = Rc::new({ - let mut __result = Vec::new(); - for fi in q.children.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "(\"".to_string(), - field_init_node_name_at(fi.clone(), source_indices.clone()), - ), - "\", &".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&fi), - &RenderTarget::Rust, - &source_indices, - ), - ), - ".to_string())".to_string(), - )); - } - __result - }); - if ((pairs.clone().len() as i64) > 0) { - v2_rt::concat( - v2_rt::concat( - "let request = request.query(&[".to_string(), - pairs.clone().join(&", ".to_string()), - ), - "]);".to_string(), - ) - } else { - "".to_string() - } + Some(q) => { + let pairs = Rc::new({ let mut __result = Vec::new(); for fi in q.children.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("(\"".to_string(), field_init_node_name_at(fi.clone(), source_indices.clone())), "\", &".to_string()), emit_simple_expr(&field_init_node_value(&fi), &RenderTarget::Rust, &source_indices)), ".to_string())".to_string())); } __result }); +if ((pairs.clone().len() as i64) > 0) { + v2_rt::concat(v2_rt::concat("let request = request.query(&[".to_string(), pairs.clone().join(&", ".to_string())), "]);".to_string()) + } else { + "".to_string() } - None => "".to_string(), - } +}, + None => "".to_string(), +} } -pub fn emit_rest_body_line( - transport: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_rest_body_line(transport: Rc, source_indices: &Rc>>) -> String { match transport_request_body(transport, source_indices.clone()) { Some(b) => match (*b.expr_data.clone()).clone() { ExprData::ExprRecordLit { .. } => { @@ -13014,161 +5178,74 @@ pub fn has_response_prefix(name: &String) -> bool { } } -pub fn child_from_key( - ch: Rc, - source_indices: Rc>>, -) -> Option { - 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()) - { - __result.push(p); - } - } - __result - }) - .first() - .cloned() - { - Some(prop) => match (*field_init_node_value(&prop).expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { - unreachable!() - }; - Some(s.clone()) - } - _ => None, - }, - None => None, - } +pub fn child_from_key(ch: Rc, source_indices: Rc>>) -> Option { + 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()) { __result.push(p); } } __result }).first().cloned() { + Some(prop) => match (*field_init_node_value(&prop).expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { unreachable!() }; Some(s.clone()) }, + _ => None, +}, + None => None, +} } -pub fn has_from_key_fields( - op_node: Rc, - source_indices: Rc>>, -) -> bool { +pub fn has_from_key_fields(op_node: Rc, source_indices: Rc>>) -> bool { { let rt = resolved_type(op_node); - let is_conj = (rt.connective.clone() == Connective::Conj); - let from_key_count = (Rc::new({ - let mut __result = Vec::new(); - for ch in rt.children.clone().iter().cloned() { - if match child_from_key(ch.clone(), source_indices.clone()) { - Some(_) => true, - None => false, - } { - __result.push(ch); - } - } - __result - }) - .len() as i64); - (is_conj && (from_key_count > 0)) - } +let is_conj = (rt.connective.clone() == Connective::Conj); +let from_key_count = (Rc::new({ let mut __result = Vec::new(); for ch in rt.children.clone().iter().cloned() { if match child_from_key(ch.clone(), source_indices.clone()) { + Some(_) => true, + None => false, +} { __result.push(ch); } } __result }).len() as i64); +(is_conj && (from_key_count > 0)) +} } -pub fn has_response_200_property( - op_node: Rc, - source_indices: Rc>>, -) -> bool { - { - 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()) - { - __found = true; - break; - } - } - __found - } +pub fn has_response_200_property(op_node: Rc, source_indices: Rc>>) -> bool { + { 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()) { __found = true; break; } } __found } } -pub fn operation_response_200_resolved_type( - op_node: Rc, - source_indices: &Rc>>, - env: Rc, -) -> Option> { - 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()) - { - __result.push(p); - } - } - __result - }) - .first() - .cloned() - { - Some(p) => { - let v = field_init_node_value(&p); - match v.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: tn, .. }) => Some(tn.clone()), - _ => { - let type_name = authored_name_at( - source_indices.clone(), - &normalize_access_type_node(v.clone()), - ); - if (type_name.clone().as_str() == "".to_string().as_str()) { - None - } else { - lookup_type_by_name(&env, type_name.clone()) - } - } +pub fn operation_response_200_resolved_type(op_node: Rc, source_indices: &Rc>>, env: Rc) -> Option> { + 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()) { __result.push(p); } } __result }).first().cloned() { + Some(p) => { + let v = field_init_node_value(&p); +match v.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: tn, .. }) => Some(tn.clone()), + _ => { + let type_name = authored_name_at(source_indices.clone(), &normalize_access_type_node(v.clone())); +if (type_name.clone().as_str() == "".to_string().as_str()) { + None + } else { + lookup_type_by_name(&env, type_name.clone()) } - } - None => None, - } +}, +} +}, + None => None, +} } -pub fn is_json_wire_declaration_type( - t: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_json_wire_declaration_type(t: Rc, source_indices: Rc>>) -> 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().as_str() == "Json".to_string().as_str()) { true } else { { - let parts = Rc::new( - n.clone() - .split(&".".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ); - match parts.last().cloned() { - Some(last) => (last.clone().as_str() == "Json".to_string().as_str()), - None => false, - } - } + let parts = Rc::new(n.clone().split(&".".to_string()).map(|s| s.to_string()).collect::>()); +match parts.last().cloned() { + Some(last) => (last.clone().as_str() == "Json".to_string().as_str()), + None => false, +} +} } - } +} } pub fn path_segment_is_list_index(seg: &String) -> bool { if (v2_rt::string_length(&seg) == 0) { false } else { - { - let mut __all = true; - for c in Rc::new(seg.clone().chars().map(|c| c as i64).collect::>()) - .iter() - .cloned() - { - if !((c.clone() >= 48) && (c.clone() <= 57)) { - __all = false; - break; - } - } - __all - } + { let mut __all = true; for c in Rc::new(seg.clone().chars().map(|c| c as i64).collect::>()).iter().cloned() { if !(((c.clone() >= 48) && (c.clone() <= 57))) { __all = false; break; } } __all } } } @@ -13179,337 +5256,146 @@ pub struct WirePathProjection { pub ok: bool, } -pub fn wire_child_for_segment( - wire_node: Rc, - seg: String, - source_indices: Rc>>, -) -> Option> { +pub fn wire_child_for_segment(wire_node: Rc, seg: String, source_indices: Rc>>) -> Option> { { let normed = normalize_access_type_node(wire_node); - match Rc::new({ - let mut __result = Vec::new(); - for ch in normed.children.clone().iter().cloned() { - if { - let authored = authored_name_at(source_indices.clone(), &ch); - let wire_key = match child_from_key(ch.clone(), source_indices.clone()) { - Some(k) => k.clone(), - None => authored.clone(), - }; - (wire_key.clone().as_str() == seg.clone().as_str()) - } { - __result.push(ch); - } - } - __result - }) - .first() - .cloned() - { - Some(ch) => Some(ch.clone()), - None => None, - } - } +match Rc::new({ let mut __result = Vec::new(); for ch in normed.children.clone().iter().cloned() { if { + let authored = authored_name_at(source_indices.clone(), &ch); +let wire_key = match child_from_key(ch.clone(), source_indices.clone()) { + Some(k) => k.clone(), + None => authored.clone(), +}; +(wire_key.clone().as_str() == seg.clone().as_str()) +} { __result.push(ch); } } __result }).first().cloned() { + Some(ch) => Some(ch.clone()), + None => None, +} +} } -pub fn advance_wire_path_projection( - state: &Rc, - seg: &String, - full_path: String, - source_indices: &Rc>>, -) -> Rc { +pub fn advance_wire_path_projection(state: &Rc, seg: &String, full_path: String, source_indices: &Rc>>) -> Rc { if !state.ok.clone() { state.clone() } else { if path_segment_is_list_index(&seg) { { let next_node = match state.node.clone() { - Some(n) => Some(for_each_element_type_node( - n.clone(), - source_indices.clone(), - )), - None => None, - }; - Rc::new(WirePathProjection { - expr: v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("(".to_string(), state.expr.clone()), - ").get(".to_string(), - ), - seg.clone(), - ), - ").ok_or_else(|| format!(\"REST path missing index " - .to_string(), - ), - seg.clone(), - ), - " at ".to_string(), - ), - full_path, - ), - "\"))?".to_string(), - ), - node: next_node, - ok: true, - }) - } + Some(n) => Some(for_each_element_type_node(n.clone(), source_indices.clone())), + None => None, +}; +Rc::new(WirePathProjection { + expr: v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("(".to_string(), state.expr.clone()), ").get(".to_string()), seg.clone()), ").ok_or_else(|| format!(\"REST path missing index ".to_string()), seg.clone()), " at ".to_string()), full_path), "\"))?".to_string()), + node: next_node, + ok: true, +}) +} } else { match state.node.clone() { - Some(n) => { - match wire_child_for_segment(n.clone(), seg.clone(), source_indices.clone()) { - Some(ch) => Rc::new(WirePathProjection { - expr: v2_rt::concat( - v2_rt::concat( - v2_rt::concat("(".to_string(), state.expr.clone()), - ").".to_string(), - ), - emit_ident( - authored_name_at(source_indices.clone(), &ch), - RenderTarget::Rust, - ), - ), - node: Some(resolved_type(ch.clone())), - ok: true, - }), - None => Rc::new(WirePathProjection { - expr: state.expr.clone(), - node: None, - ok: false, - }), - } - } - None => Rc::new(WirePathProjection { - expr: state.expr.clone(), - node: None, - ok: false, - }), - } + Some(n) => match wire_child_for_segment(n.clone(), seg.clone(), source_indices.clone()) { + Some(ch) => Rc::new(WirePathProjection { + expr: v2_rt::concat(v2_rt::concat(v2_rt::concat("(".to_string(), state.expr.clone()), ").".to_string()), emit_ident(authored_name_at(source_indices.clone(), &ch), RenderTarget::Rust)), + node: Some(resolved_type(ch.clone())), + ok: true, +}), + None => Rc::new(WirePathProjection { + expr: state.expr.clone(), + node: None, + ok: false, +}), +}, + None => Rc::new(WirePathProjection { + expr: state.expr.clone(), + node: None, + ok: false, +}), +} } } } -pub fn emit_wire_struct_path_chain( - base: String, - wire_node: Rc, - from_path: &String, - source_indices: Rc>>, -) -> Rc { - { - let segs = Rc::new({ - let mut __result = Vec::new(); - for s in Rc::new( - from_path - .clone() - .split(&"/".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .iter() - .cloned() - { - if (s.clone().as_str() != "".to_string().as_str()) { - __result.push(s); - } - } - __result - }); - segs.iter().cloned().fold( - Rc::new(WirePathProjection { - expr: base, - node: Some(wire_node), - ok: true, - }), - |acc: Rc, seg: String| { - advance_wire_path_projection(&acc, &seg, from_path.clone(), &source_indices) - }, - ) - } +pub fn emit_wire_struct_path_chain(base: String, wire_node: Rc, from_path: &String, source_indices: Rc>>) -> Rc { + { + let segs = Rc::new({ let mut __result = Vec::new(); for s in Rc::new(from_path.clone().split(&"/".to_string()).map(|s| s.to_string()).collect::>()).iter().cloned() { if (s.clone().as_str() != "".to_string().as_str()) { __result.push(s); } } __result }); +segs.iter().cloned().fold(Rc::new(WirePathProjection { + expr: base, + node: Some(wire_node), + ok: true, +}), |acc: Rc, seg: String| advance_wire_path_projection(&acc, &seg, from_path.clone(), &source_indices)) +} } -pub fn emit_typed_wire_field_assign( - field_name: String, - from_path: &String, - wire_node: Rc, - source_indices: Rc>>, -) -> String { - { - let projection = emit_wire_struct_path_chain( - "__rest_wire".to_string(), - wire_node, - &from_path, - source_indices, - ); - if projection.ok.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("let ".to_string(), field_name), - " = ".to_string(), - ), - projection.expr.clone(), - ), - ".clone();\n".to_string(), - ) +pub fn emit_typed_wire_field_assign(field_name: String, from_path: &String, wire_node: Rc, source_indices: Rc>>) -> String { + { + let projection = emit_wire_struct_path_chain("__rest_wire".to_string(), wire_node, &from_path, source_indices); +if projection.ok.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let ".to_string(), field_name), " = ".to_string()), projection.expr.clone()), ".clone();\n".to_string()) } else { v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let ".to_string(), field_name), " = compile_error!(\"REST typed response path could not be resolved against declared 200 body: ".to_string()), from_path.clone()), "\");\n".to_string()) } - } +} } pub fn escape_json_pointer_segment(seg: String) -> String { - v2_rt::replace( - v2_rt::replace(seg, "~".to_string(), "~0".to_string()), - "/".to_string(), - "~1".to_string(), - ) -} - -pub fn emit_json_value_extract( - var_name: String, - from_path: &String, - dag_type_name: String, -) -> String { - { - let escaped_path = Rc::new({ - let mut __result = Vec::new(); - for seg in Rc::new( - from_path - .clone() - .split(&"/".to_string()) - .map(|s| s.to_string()) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push(escape_json_pointer_segment(seg.clone())); - } - __result - }) - .join(&"/".to_string()); - let pointer = v2_rt::concat("/".to_string(), escaped_path); - let rust_type = coerce_primitive_type(RenderTarget::Rust, dag_type_name); - let accessor = if (rust_type.clone().as_str() == "String".to_string().as_str()) { - v2_rt::concat( - v2_rt::concat( - ".and_then(|v| v.as_str()).map(|s| s.to_string()).ok_or(\"missing field: " - .to_string(), - from_path.clone(), - ), - "\")?".to_string(), - ) + v2_rt::replace(v2_rt::replace(seg, "~".to_string(), "~0".to_string()), "/".to_string(), "~1".to_string()) +} + +pub fn emit_json_value_extract(var_name: String, from_path: &String, dag_type_name: String) -> String { + { + let escaped_path = Rc::new({ let mut __result = Vec::new(); for seg in Rc::new(from_path.clone().split(&"/".to_string()).map(|s| s.to_string()).collect::>()).iter().cloned() { __result.push(escape_json_pointer_segment(seg.clone())); } __result }).join(&"/".to_string()); +let pointer = v2_rt::concat("/".to_string(), escaped_path); +let rust_type = coerce_primitive_type(RenderTarget::Rust, dag_type_name); +let accessor = if (rust_type.clone().as_str() == "String".to_string().as_str()) { + v2_rt::concat(v2_rt::concat(".and_then(|v| v.as_str()).map(|s| s.to_string()).ok_or(\"missing field: ".to_string(), from_path.clone()), "\")?".to_string()) } else { if (rust_type.clone().as_str() == "i64".to_string().as_str()) { - v2_rt::concat( - v2_rt::concat( - ".and_then(|v| v.as_i64()).ok_or(\"missing field: ".to_string(), - from_path.clone(), - ), - "\")?".to_string(), - ) + v2_rt::concat(v2_rt::concat(".and_then(|v| v.as_i64()).ok_or(\"missing field: ".to_string(), from_path.clone()), "\")?".to_string()) } else { if (rust_type.clone().as_str() == "f64".to_string().as_str()) { - v2_rt::concat( - v2_rt::concat( - ".and_then(|v| v.as_f64()).ok_or(\"missing field: ".to_string(), - from_path.clone(), - ), - "\")?".to_string(), - ) + v2_rt::concat(v2_rt::concat(".and_then(|v| v.as_f64()).ok_or(\"missing field: ".to_string(), from_path.clone()), "\")?".to_string()) } else { if (rust_type.clone().as_str() == "bool".to_string().as_str()) { - v2_rt::concat( - v2_rt::concat( - ".and_then(|v| v.as_bool()).ok_or(\"missing field: ".to_string(), - from_path.clone(), - ), - "\")?".to_string(), - ) + v2_rt::concat(v2_rt::concat(".and_then(|v| v.as_bool()).ok_or(\"missing field: ".to_string(), from_path.clone()), "\")?".to_string()) } else { v2_rt::concat(v2_rt::concat(".cloned().map(|v| serde_json::from_value(v)).transpose()?.ok_or(\"missing field: ".to_string(), from_path.clone()), "\")?".to_string()) } } } }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("let ".to_string(), var_name), - " = json_body.pointer(\"".to_string(), - ), - pointer, - ), - "\")".to_string(), - ), - accessor, - ), - ";".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let ".to_string(), var_name), " = json_body.pointer(\"".to_string()), pointer), "\")".to_string()), accessor), ";".to_string()) +} } -pub fn emit_from_key_extraction( - op_node: &Rc, - source_indices: &Rc>>, - shared_types: Rc>, - env: Rc, -) -> String { +pub fn emit_from_key_extraction(op_node: &Rc, source_indices: &Rc>>, shared_types: Rc>, env: Rc) -> String { { let rt = resolved_type(op_node.clone()); - let children = rt.children.clone(); - let wire_opt = operation_response_200_resolved_type(op_node.clone(), &source_indices, env); - if (has_response_200_property(op_node.clone(), source_indices.clone()) - && match wire_opt.clone() { - None => true, - Some(_) => false, - }) - { +let children = rt.children.clone(); +let wire_opt = operation_response_200_resolved_type(op_node.clone(), &source_indices, env); +if (has_response_200_property(op_node.clone(), source_indices.clone()) && match wire_opt.clone() { + None => true, + Some(_) => false, +}) { "compile_error!(\"REST response_200: declared HTTP 200 body type is present but could not be resolved (empty name, missing TypeEnv binding, or inference gap); illegal state\");\n".to_string() } else { { let use_typed_wire = match wire_opt.clone() { - Some(tn) => !is_json_wire_declaration_type(tn.clone(), source_indices.clone()), - None => false, - }; - let prelude = match wire_opt.clone() { - Some(tn) => { - if is_json_wire_declaration_type(tn.clone(), source_indices.clone()) { - "let json_body: serde_json::Value = response.json().await?;\n" - .to_string() - } else { - { - let wire_ty = match tn.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), - _ => tn.clone(), - }; - v2_rt::concat( - v2_rt::concat( - "let __rest_wire: ".to_string(), - render_rust_type( - wire_ty, - shared_types, - source_indices.clone(), - ), - ), - " = response.json().await?;\n".to_string(), - ) - } - } - } - None => { - "let json_body: serde_json::Value = response.json().await?;\n".to_string() - } - }; - let extract_lines = Rc::new({ - let mut __result = Vec::new(); - for ch in children.clone().iter().cloned() { - __result.push({ + Some(tn) => !is_json_wire_declaration_type(tn.clone(), source_indices.clone()), + None => false, +}; +let prelude = match wire_opt.clone() { + Some(tn) => if is_json_wire_declaration_type(tn.clone(), source_indices.clone()) { + "let json_body: serde_json::Value = response.json().await?;\n".to_string() + } else { + { + let wire_ty = match tn.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), + _ => tn.clone(), +}; +v2_rt::concat(v2_rt::concat("let __rest_wire: ".to_string(), render_rust_type(wire_ty, shared_types, source_indices.clone())), " = response.json().await?;\n".to_string()) +} + }, + None => "let json_body: serde_json::Value = response.json().await?;\n".to_string(), +}; +let extract_lines = Rc::new({ let mut __result = Vec::new(); for ch in children.clone().iter().cloned() { __result.push({ let ch_name = authored_name_at(source_indices.clone(), &ch); let field_name = emit_ident(ch_name.clone(), RenderTarget::Rust); let from_path = match child_from_key(ch.clone(), source_indices.clone()) { @@ -13527,201 +5413,83 @@ match ch.inferred.clone().as_deref().cloned() { }, _ => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let ".to_string(), field_name.clone()), " = compile_error!(\"unresolved type for output field: ".to_string()), ch_name.clone()), "\");".to_string()), } -}); - } - __result - }); - let field_names = Rc::new({ - let mut __result = Vec::new(); - for ch in children.clone().iter().cloned() { - __result.push(emit_ident( - authored_name_at(source_indices.clone(), &ch), - RenderTarget::Rust, - )); - } - __result - }); - let tuple_body = if ((field_names.clone().len() as i64) == 1) { - v2_rt::concat( - v2_rt::concat( - "(".to_string(), - field_names.clone().first().cloned().clone().unwrap(), - ), - ",)".to_string(), - ) +}); } __result }); +let field_names = Rc::new({ let mut __result = Vec::new(); for ch in children.clone().iter().cloned() { __result.push(emit_ident(authored_name_at(source_indices.clone(), &ch), RenderTarget::Rust)); } __result }); +let tuple_body = if ((field_names.clone().len() as i64) == 1) { + v2_rt::concat(v2_rt::concat("(".to_string(), field_names.clone().first().cloned().clone().unwrap()), ",)".to_string()) } else { - v2_rt::concat( - v2_rt::concat("(".to_string(), field_names.clone().join(&", ".to_string())), - ")".to_string(), - ) + v2_rt::concat(v2_rt::concat("(".to_string(), field_names.clone().join(&", ".to_string())), ")".to_string()) }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prelude, extract_lines.join(&"\n".to_string())), - "\nOk(".to_string(), - ), - tuple_body, - ), - ")".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(prelude, extract_lines.join(&"\n".to_string())), "\nOk(".to_string()), tuple_body), ")".to_string()) +} } - } +} } -pub fn emit_plain_response_body( - op_node: Rc, - transport: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_plain_response_body(op_node: Rc, transport: Rc, source_indices: &Rc>>) -> String { { let is_text = match transport_response_format(transport, source_indices.clone()) { - Some(fmt) => { - (authored_name_at(source_indices.clone(), &fmt).as_str() - == "Text".to_string().as_str()) - } - None => false, - }; - if is_text { + Some(fmt) => (authored_name_at(source_indices.clone(), &fmt).as_str() == "Text".to_string().as_str()), + None => false, +}; +if is_text { "let result = response.text().await?;\nOk(result)".to_string() } else { "let result = response.json().await?;\nOk(result)".to_string() } - } +} } -pub fn emit_response_code_handling( - op_node: &Rc, - transport: Rc, - source_indices: &Rc>>, - shared_types: Rc>, - env: Rc, -) -> String { +pub fn emit_response_code_handling(op_node: &Rc, transport: Rc, source_indices: &Rc>>, shared_types: Rc>, env: Rc) -> String { { let use_from_key = has_from_key_fields(op_node.clone(), source_indices.clone()); - let response_props = Rc::new({ - let mut __result = Vec::new(); - for p in op_node.properties.clone().iter().cloned() { - if has_response_prefix(&field_init_node_name_at(p.clone(), source_indices.clone())) - { - __result.push(p); - } - } - __result - }); - if ((response_props.clone().len() as i64) == 0) { +let response_props = Rc::new({ let mut __result = Vec::new(); for p in op_node.properties.clone().iter().cloned() { if has_response_prefix(&field_init_node_name_at(p.clone(), source_indices.clone())) { __result.push(p); } } __result }); +if ((response_props.clone().len() as i64) == 0) { if use_from_key.clone() { - emit_from_key_extraction( - &op_node, - &source_indices, - shared_types.clone(), - env.clone(), - ) + emit_from_key_extraction(&op_node, &source_indices, shared_types.clone(), env.clone()) } else { emit_plain_response_body(op_node.clone(), transport.clone(), &source_indices) } } else { { - let arms = Rc::new({ - let mut __result = Vec::new(); - for p in response_props.clone().iter().cloned() { - __result.push(emit_response_arm( - p.clone(), - op_node.clone(), - use_from_key.clone(), - transport.clone(), - &source_indices, - shared_types.clone(), - env.clone(), - )); - } - __result - }); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "let status = response.status().as_u16();\n".to_string(), - "match status {\n".to_string(), - ), - arms.join(&"\n".to_string()), - ), - "\n _ => Err(format!(\"unexpected status code: {}\", status).into())\n" - .to_string(), - ), - "}".to_string(), - ) - } + let arms = Rc::new({ let mut __result = Vec::new(); for p in response_props.clone().iter().cloned() { __result.push(emit_response_arm(p.clone(), op_node.clone(), use_from_key.clone(), transport.clone(), &source_indices, shared_types.clone(), env.clone())); } __result }); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let status = response.status().as_u16();\n".to_string(), "match status {\n".to_string()), arms.join(&"\n".to_string())), "\n _ => Err(format!(\"unexpected status code: {}\", status).into())\n".to_string()), "}".to_string()) +} } - } +} } -pub fn emit_response_arm( - prop: Rc, - op_node: Rc, - use_from_key: bool, - transport: Rc, - source_indices: &Rc>>, - shared_types: Rc>, - env: Rc, -) -> String { +pub fn emit_response_arm(prop: Rc, op_node: Rc, use_from_key: bool, transport: Rc, source_indices: &Rc>>, shared_types: Rc>, env: Rc) -> String { { let name = field_init_node_name_at(prop, source_indices.clone()); - let code_str = v2_rt::substring(&name, 9, v2_rt::string_length(&name)); - let is_success = if (v2_rt::string_length(&code_str) >= 1) { +let code_str = v2_rt::substring(&name, 9, v2_rt::string_length(&name)); +let is_success = if (v2_rt::string_length(&code_str) >= 1) { (v2_rt::substring(&code_str, 0, 1).as_str() == "2".to_string().as_str()) } else { false }; - let pattern = if (code_str.clone().as_str() == "nonzero".to_string().as_str()) { +let pattern = if (code_str.clone().as_str() == "nonzero".to_string().as_str()) { "_".to_string() } else { - if ((v2_rt::string_length(&code_str) == 3) - && (v2_rt::substring(&code_str, 1, 3).as_str() == "xx".to_string().as_str())) - { + if ((v2_rt::string_length(&code_str) == 3) && (v2_rt::substring(&code_str, 1, 3).as_str() == "xx".to_string().as_str())) { { let prefix = v2_rt::substring(&code_str, 0, 1); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(prefix.clone(), "00..=".to_string()), - prefix.clone(), - ), - "99".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(prefix.clone(), "00..=".to_string()), prefix.clone()), "99".to_string()) +} } else { code_str.clone() } }; - if is_success { +if is_success { if use_from_key { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" ".to_string(), pattern), - " => { ".to_string(), - ), - emit_from_key_extraction(&op_node, &source_indices, shared_types, env), - ), - " },".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), pattern), " => { ".to_string()), emit_from_key_extraction(&op_node, &source_indices, shared_types, env)), " },".to_string()) } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" ".to_string(), pattern), - " => { ".to_string(), - ), - emit_plain_response_body(op_node, transport, &source_indices), - ), - " },".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), pattern), " => { ".to_string()), emit_plain_response_body(op_node, transport, &source_indices)), " },".to_string()) } } else { v2_rt::concat(v2_rt::concat(" ".to_string(), pattern), " => { let err_body = response.text().await.unwrap_or_default(); Err(format!(\"HTTP {}: {}\", status, err_body).into()) },".to_string()) } - } +} } pub fn has_exit_prefix(name: &String) -> bool { @@ -13732,472 +5500,205 @@ pub fn has_exit_prefix(name: &String) -> bool { } } -pub fn emit_exit_code_handling( - op_node: Rc, - inferred: Rc, - source_indices: Rc>>, -) -> String { +pub fn emit_exit_code_handling(op_node: Rc, inferred: Rc, source_indices: Rc>>) -> String { { - let exit_props = Rc::new({ - let mut __result = Vec::new(); - for p in op_node.properties.clone().iter().cloned() { - if has_exit_prefix(&field_init_node_name_at(p.clone(), source_indices.clone())) { - __result.push(p); - } - } - __result - }); - if ((exit_props.clone().len() as i64) == 0) { + let exit_props = Rc::new({ let mut __result = Vec::new(); for p in op_node.properties.clone().iter().cloned() { if has_exit_prefix(&field_init_node_name_at(p.clone(), source_indices.clone())) { __result.push(p); } } __result }); +if ((exit_props.clone().len() as i64) == 0) { emit_shell_return(inferred.clone(), &source_indices) } else { { - 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()) - { - __found = true; - break; - } - } - __found - }; - let exit_arms = Rc::new({ - let mut __result = Vec::new(); - for p in exit_props.clone().iter().cloned() { - __result.push(emit_exit_arm(p.clone(), inferred.clone(), &source_indices)); - } - __result - }); - let default_arm = if has_nonzero { + 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()) { __found = true; break; } } __found }; +let exit_arms = Rc::new({ let mut __result = Vec::new(); for p in exit_props.clone().iter().cloned() { __result.push(emit_exit_arm(p.clone(), inferred.clone(), &source_indices)); } __result }); +let default_arm = if has_nonzero { "".to_string() } else { "\n _ => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(stderr.into()) },".to_string() }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "let exit_code = output.status.code().unwrap_or(-1);\n".to_string(), - "match exit_code {\n".to_string(), - ), - exit_arms.join(&"\n".to_string()), - ), - default_arm, - ), - "\n}".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let exit_code = output.status.code().unwrap_or(-1);\n".to_string(), "match exit_code {\n".to_string()), exit_arms.join(&"\n".to_string())), default_arm), "\n}".to_string()) +} } - } +} } -pub fn emit_exit_arm( - prop: Rc, - inferred: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_exit_arm(prop: Rc, inferred: Rc, source_indices: &Rc>>) -> String { { let name = field_init_node_name_at(prop, source_indices.clone()); - let code_str = v2_rt::substring(&name, 5, v2_rt::string_length(&name)); - let pattern = if (code_str.clone().as_str() == "nonzero".to_string().as_str()) { +let code_str = v2_rt::substring(&name, 5, v2_rt::string_length(&name)); +let pattern = if (code_str.clone().as_str() == "nonzero".to_string().as_str()) { "_".to_string() } else { code_str.clone() }; - let is_success = (code_str.clone().as_str() == "0".to_string().as_str()); - if is_success { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" ".to_string(), pattern), - " => { ".to_string(), - ), - emit_shell_return(inferred, &source_indices), - ), - " },".to_string(), - ) +let is_success = (code_str.clone().as_str() == "0".to_string().as_str()); +if is_success { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), pattern), " => { ".to_string()), emit_shell_return(inferred, &source_indices)), " },".to_string()) } else { v2_rt::concat(v2_rt::concat(" ".to_string(), pattern), " => { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); Err(stderr.into()) },".to_string()) } - } +} } -pub fn emit_shell_call( - op_name: String, - transport: &Rc, - registry: Rc>>, - depth: i64, - inferred: Rc, - op_node: &Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_shell_call(op_name: String, transport: &Rc, registry: Rc>>, depth: i64, inferred: Rc, op_node: &Rc, source_indices: &Rc>>) -> String { { let argv = transport.children.clone(); - let optional_params = Rc::new({ - let mut __result = Vec::new(); - for p in op_node.params.clone().iter().cloned() { - if (param_node_type_expr(&p).return_cardinality.clone() - == Cardinality::CardOptional) - { - __result.push(p); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, p: Rc| { - v2_rt::rc_map_insert( - acc, - param_node_name_at(p.clone(), source_indices.clone()), - true, - ) - }, - ); - let has_stdin = match transport_stdin(transport.clone(), source_indices.clone()) { - Some(_) => true, - None => false, - }; - let let_kw = if has_stdin.clone() { +let optional_params = Rc::new({ let mut __result = Vec::new(); for p in op_node.params.clone().iter().cloned() { if (param_node_type_expr(&p).return_cardinality.clone() == Cardinality::CardOptional) { __result.push(p); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, p: Rc| v2_rt::rc_map_insert(acc, param_node_name_at(p.clone(), source_indices.clone()), true)); +let has_stdin = match transport_stdin(transport.clone(), source_indices.clone()) { + Some(_) => true, + None => false, +}; +let let_kw = if has_stdin.clone() { "let mut output".to_string() } else { "let output".to_string() }; - let cmd_line = if ((argv.clone().len() as i64) > 0) { +let cmd_line = if ((argv.clone().len() as i64) > 0) { match argv.clone().first().cloned() { - Some(first_arg) => v2_rt::concat( - v2_rt::concat( - v2_rt::concat(let_kw, " = std::process::Command::new(".to_string()), - emit_shell_argv_element( - &first_arg, - optional_params.clone(), - source_indices.clone(), - ), - ), - ")".to_string(), - ), - None => v2_rt::concat( - v2_rt::concat( - v2_rt::concat(let_kw, " = std::process::Command::new(\"".to_string()), - emit_ident(op_name, RenderTarget::Rust), - ), - "\")".to_string(), - ), - } + Some(first_arg) => v2_rt::concat(v2_rt::concat(v2_rt::concat(let_kw, " = std::process::Command::new(".to_string()), emit_shell_argv_element(&first_arg, optional_params.clone(), source_indices.clone())), ")".to_string()), + None => v2_rt::concat(v2_rt::concat(v2_rt::concat(let_kw, " = std::process::Command::new(\"".to_string()), emit_ident(op_name, RenderTarget::Rust)), "\")".to_string()), +} } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(let_kw, " = std::process::Command::new(\"".to_string()), - emit_ident(op_name, RenderTarget::Rust), - ), - "\")".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(let_kw, " = std::process::Command::new(\"".to_string()), emit_ident(op_name, RenderTarget::Rust)), "\")".to_string()) }; - let arg_lines = if ((argv.clone().len() as i64) > 1) { - Rc::new({ - let mut __result = Vec::new(); - for arg in Rc::new( - argv.clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push(v2_rt::concat( - v2_rt::concat( - " .arg(".to_string(), - emit_shell_argv_element( - &arg, - optional_params.clone(), - source_indices.clone(), - ), - ), - ")".to_string(), - )); - } - __result - }) +let arg_lines = if ((argv.clone().len() as i64) > 1) { + Rc::new({ let mut __result = Vec::new(); for arg in Rc::new(argv.clone().iter().cloned().skip(1 as usize).collect::>()).iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(" .arg(".to_string(), emit_shell_argv_element(&arg, optional_params.clone(), source_indices.clone())), ")".to_string())); } __result }) } else { Rc::new(vec![]) }; - let env_entries = transport_env(transport.clone(), source_indices.clone()); - let env_lines = Rc::new({ - let mut __result = Vec::new(); - for e in env_entries.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " .env(\"".to_string(), - field_init_node_name_at(e.clone(), source_indices.clone()), - ), - "\", ".to_string(), - ), - emit_simple_expr( - &field_init_node_value(&e), - &RenderTarget::Rust, - &source_indices, - ), - ), - ")".to_string(), - )); - } - __result - }); - let wd_line = " .current_dir(self.working_dir.as_deref().unwrap_or(\".\"))".to_string(); - if has_stdin.clone() { +let env_entries = transport_env(transport.clone(), source_indices.clone()); +let env_lines = Rc::new({ let mut __result = Vec::new(); for e in env_entries.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" .env(\"".to_string(), field_init_node_name_at(e.clone(), source_indices.clone())), "\", ".to_string()), emit_simple_expr(&field_init_node_value(&e), &RenderTarget::Rust, &source_indices)), ")".to_string())); } __result }); +let wd_line = " .current_dir(self.working_dir.as_deref().unwrap_or(\".\"))".to_string(); +if has_stdin.clone() { { - let stdin_expr = transport_stdin(transport.clone(), source_indices.clone()) - .clone() - .unwrap(); - let stdin_var = match (*stdin_expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => emit_ident( - expr_var_name_at(stdin_expr.clone(), source_indices.clone()), - RenderTarget::Rust, - ), - _ => emit_simple_expr(&stdin_expr, &RenderTarget::Rust, &source_indices), - }; - let spawn_line = " .stdin(std::process::Stdio::piped())\n .stdout(std::process::Stdio::piped())\n .stderr(std::process::Stdio::piped())".to_string(); - let spawn_exec = " .spawn()?;".to_string(); - let write_block = v2_rt::concat(v2_rt::concat("{\n use std::io::Write;\n if let Some(mut stdin) = output.stdin.take() {\n stdin.write_all(".to_string(), stdin_var), ".as_bytes())?;\n }\n}".to_string()); - 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 all_lines = v2_rt::concat( - v2_rt::concat(v2_rt::concat(Rc::new(vec![cmd_line]), arg_lines), env_lines), - Rc::new(vec![ - wd_line, - spawn_line, - spawn_exec, - write_block, - wait_line, - check_line, - return_line, - ]), - ); - all_lines.join(&"\n".to_string()) - } + let stdin_expr = transport_stdin(transport.clone(), source_indices.clone()).clone().unwrap(); +let stdin_var = match (*stdin_expr.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => emit_ident(expr_var_name_at(stdin_expr.clone(), source_indices.clone()), RenderTarget::Rust), + _ => emit_simple_expr(&stdin_expr, &RenderTarget::Rust, &source_indices), +}; +let spawn_line = " .stdin(std::process::Stdio::piped())\n .stdout(std::process::Stdio::piped())\n .stderr(std::process::Stdio::piped())".to_string(); +let spawn_exec = " .spawn()?;".to_string(); +let write_block = v2_rt::concat(v2_rt::concat("{\n use std::io::Write;\n if let Some(mut stdin) = output.stdin.take() {\n stdin.write_all(".to_string(), stdin_var), ".as_bytes())?;\n }\n}".to_string()); +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 all_lines = v2_rt::concat(v2_rt::concat(v2_rt::concat(Rc::new(vec![cmd_line]), arg_lines), env_lines), Rc::new(vec![wd_line, spawn_line, spawn_exec, write_block, wait_line, check_line, return_line])); +all_lines.join(&"\n".to_string()) +} } else { { 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 all_lines = v2_rt::concat( - v2_rt::concat(v2_rt::concat(Rc::new(vec![cmd_line]), arg_lines), env_lines), - Rc::new(vec![wd_line, output_line, check_line, return_line]), - ); - all_lines.join(&"\n".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 all_lines = v2_rt::concat(v2_rt::concat(v2_rt::concat(Rc::new(vec![cmd_line]), arg_lines), env_lines), Rc::new(vec![wd_line, output_line, check_line, return_line])); +all_lines.join(&"\n".to_string()) +} } - } +} } -pub fn emit_shell_argv_element( - arg: &Rc, - optional_params: Rc>, - source_indices: Rc>>, -) -> String { +pub fn emit_shell_argv_element(arg: &Rc, optional_params: Rc>, source_indices: Rc>>) -> String { match (*arg.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { - unreachable!() - }; - v2_rt::concat( - v2_rt::concat("\"".to_string(), escape_string_literal_body(s.clone())), - "\"".to_string(), - ) - } - ExprData::ExprStringInterp => { - let parts = Rc::new({ - let mut __result = Vec::new(); - for child in arg.children.clone().iter().cloned() { - __result.push(match (*child.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: text, .. } = value.as_ref() else { - unreachable!() - }; - Rc::new(StringPart::Text { - value: text.clone(), - }) - } - _ => Rc::new(StringPart::Interpolation { - expr: arg_value(&child), - }), - }); - } - __result - }); - let fmt_segments = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.push(match (*p.clone()).clone() { - StringPart::Text { value: v, .. } => escape_rust_interp_text(v.clone()), - StringPart::Interpolation { .. } => "{}".to_string(), - }); - } - __result - }); - let fmt_str = fmt_segments.join(&"".to_string()); - let args = Rc::new({ - let mut __result = Vec::new(); - for p in parts.clone().iter().cloned() { - __result.extend( - (*match (*p.clone()).clone() { - StringPart::Text { .. } => Rc::new(vec![]), - StringPart::Interpolation { expr: e, .. } => { - let name = expr_var_name_at(e.clone(), source_indices.clone()); - let var_name = emit_ident(name.clone(), RenderTarget::Rust); - let is_opt = (is_optional_typed_expr(e.clone()) - || match v2_rt::map_get(&optional_params, name.clone()) { - Some(_) => true, - None => false, - }); - if is_opt.clone() { - Rc::new(vec![v2_rt::concat( - var_name.clone(), - ".as_deref().unwrap_or(\"\")".to_string(), - )]) - } else { - Rc::new(vec![var_name.clone()]) - } - } - }) - .iter() - .cloned(), - ); - } - __result - }); - let args_str = args.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("&format!(\"".to_string(), fmt_str), - "\", ".to_string(), - ), - args_str, - ), - ")".to_string(), - ) - } - ExprData::ExprVar { .. } => { - let name = expr_var_name_at(arg.clone(), source_indices.clone()); - let var_name = emit_ident(name.clone(), RenderTarget::Rust); - let is_opt = (is_optional_typed_expr(arg.clone()) - || match v2_rt::map_get(&optional_params, name.clone()) { - Some(_) => true, - None => false, - }); - if is_opt.clone() { - v2_rt::concat( - v2_rt::concat("&".to_string(), var_name.clone()), - ".as_deref().unwrap_or(\"\").to_string()".to_string(), - ) + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { unreachable!() }; v2_rt::concat(v2_rt::concat("\"".to_string(), escape_string_literal_body(s.clone())), "\"".to_string()) }, + ExprData::ExprStringInterp => { + let parts = Rc::new({ let mut __result = Vec::new(); for child in arg.children.clone().iter().cloned() { __result.push(match (*child.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: text, .. } = value.as_ref() else { unreachable!() }; Rc::new(StringPart::Text { + value: text.clone(), +}) }, + _ => Rc::new(StringPart::Interpolation { + expr: arg_value(&child), +}), +}); } __result }); +let fmt_segments = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.push(match (*p.clone()).clone() { + StringPart::Text { value: v, .. } => escape_rust_interp_text(v.clone()), + StringPart::Interpolation { .. } => "{}".to_string(), +}); } __result }); +let fmt_str = fmt_segments.join(&"".to_string()); +let args = Rc::new({ let mut __result = Vec::new(); for p in parts.clone().iter().cloned() { __result.extend((*match (*p.clone()).clone() { + StringPart::Text { .. } => Rc::new(vec![]), + StringPart::Interpolation { expr: e, .. } => { + let name = expr_var_name_at(e.clone(), source_indices.clone()); +let var_name = emit_ident(name.clone(), RenderTarget::Rust); +let is_opt = (is_optional_typed_expr(e.clone()) || match v2_rt::map_get(&optional_params, name.clone()) { + Some(_) => true, + None => false, +}); +if is_opt.clone() { + Rc::new(vec![v2_rt::concat(var_name.clone(), ".as_deref().unwrap_or(\"\")".to_string())]) } else { - v2_rt::concat( - v2_rt::concat("&".to_string(), var_name.clone()), - ".to_string()".to_string(), - ) + Rc::new(vec![var_name.clone()]) } +}, +}).iter().cloned()); } __result }); +let args_str = args.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("&format!(\"".to_string(), fmt_str), "\", ".to_string()), args_str), ")".to_string()) +}, + ExprData::ExprVar { .. } => { + let name = expr_var_name_at(arg.clone(), source_indices.clone()); +let var_name = emit_ident(name.clone(), RenderTarget::Rust); +let is_opt = (is_optional_typed_expr(arg.clone()) || match v2_rt::map_get(&optional_params, name.clone()) { + Some(_) => true, + None => false, +}); +if is_opt.clone() { + v2_rt::concat(v2_rt::concat("&".to_string(), var_name.clone()), ".as_deref().unwrap_or(\"\").to_string()".to_string()) + } else { + v2_rt::concat(v2_rt::concat("&".to_string(), var_name.clone()), ".to_string()".to_string()) } - _ => emit_simple_expr(&arg, &RenderTarget::Rust, &source_indices), - } +}, + _ => emit_simple_expr(&arg, &RenderTarget::Rust, &source_indices), +} } -pub fn emit_shell_return( - inferred: Rc, - source_indices: &Rc>>, -) -> String { +pub fn emit_shell_return(inferred: Rc, source_indices: &Rc>>) -> String { { let effective = unwrap_single_field_product(inferred); - let is_product = is_product_type(effective.clone()); - let single_from = - if (is_product.clone() && ((effective.children.clone().len() as i64) == 1)) { - match effective.children.clone().first().cloned() { - Some(ch) => child_from_key(ch.clone(), source_indices.clone()), - None => None, - } - } else { - None - }; - match single_from { - Some(channel) => { - let is_optional = - (effective.return_cardinality.clone() == Cardinality::CardOptional); - emit_shell_channel_expr(&channel, is_optional.clone()) - } - None => { - if (is_product.clone() && ((effective.children.clone().len() as i64) > 1)) { - { - let needs_stderr = { - let mut __found = false; - for ch in effective.children.clone().iter().cloned() { - if match child_from_key(ch.clone(), source_indices.clone()) { - Some(ref __some_val) if __some_val == "stderr" => true, - _ => false, - } { - __found = true; - break; - } - } - __found - }; - let stderr_line = if needs_stderr { - "let stderr = String::from_utf8_lossy(&output.stderr).to_string();" - .to_string() - } else { - "".to_string() - }; - let field_exprs = Rc::new({ - let mut __result = Vec::new(); - for ch in effective.children.clone().iter().cloned() { - __result.push({ - let is_optional = (ch.return_cardinality.clone() - == Cardinality::CardOptional); - let channel = - match child_from_key(ch.clone(), source_indices.clone()) { - Some(c) => c.clone(), - None => "stdout".to_string(), - }; - emit_shell_channel_expr(&channel, is_optional.clone()) - }); - } - __result - }); - let lines = if (stderr_line.clone().as_str() != "".to_string().as_str()) { - v2_rt::concat(stderr_line.clone(), "\n".to_string()) - } else { - "".to_string() - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(lines, "Ok((".to_string()), - field_exprs.join(&", ".to_string()), - ), - "))".to_string(), - ) - } +let is_product = is_product_type(effective.clone()); +let single_from = if (is_product.clone() && ((effective.children.clone().len() as i64) == 1)) { + match effective.children.clone().first().cloned() { + Some(ch) => child_from_key(ch.clone(), source_indices.clone()), + None => None, +} + } else { + None + }; +match single_from { + Some(channel) => { + let is_optional = (effective.return_cardinality.clone() == Cardinality::CardOptional); +emit_shell_channel_expr(&channel, is_optional.clone()) +}, + None => if (is_product.clone() && ((effective.children.clone().len() as i64) > 1)) { + { + let needs_stderr = { let mut __found = false; for ch in effective.children.clone().iter().cloned() { if match child_from_key(ch.clone(), source_indices.clone()) { + Some(ref __some_val) if __some_val == "stderr" => true, + _ => false, +} { __found = true; break; } } __found }; +let stderr_line = if needs_stderr { + "let stderr = String::from_utf8_lossy(&output.stderr).to_string();".to_string() } else { - { - let is_optional = - (effective.return_cardinality.clone() == Cardinality::CardOptional); - emit_shell_channel_expr(&"stdout".to_string(), is_optional.clone()) - } - } - } - } - } + "".to_string() + }; +let field_exprs = Rc::new({ let mut __result = Vec::new(); for ch in effective.children.clone().iter().cloned() { __result.push({ + let is_optional = (ch.return_cardinality.clone() == Cardinality::CardOptional); +let channel = match child_from_key(ch.clone(), source_indices.clone()) { + Some(c) => c.clone(), + None => "stdout".to_string(), +}; +emit_shell_channel_expr(&channel, is_optional.clone()) +}); } __result }); +let lines = if (stderr_line.clone().as_str() != "".to_string().as_str()) { + v2_rt::concat(stderr_line.clone(), "\n".to_string()) + } else { + "".to_string() + }; +v2_rt::concat(v2_rt::concat(v2_rt::concat(lines, "Ok((".to_string()), field_exprs.join(&", ".to_string())), "))".to_string()) +} + } else { + { + let is_optional = (effective.return_cardinality.clone() == Cardinality::CardOptional); +emit_shell_channel_expr(&"stdout".to_string(), is_optional.clone()) +} + }, +} +} } pub fn emit_shell_channel_expr(channel: &String, is_optional: bool) -> String { @@ -14215,709 +5716,252 @@ pub fn emit_shell_channel_expr(channel: &String, is_optional: bool) -> String { } } }; - if is_optional { +if is_optional { v2_rt::concat(v2_rt::concat("Some(".to_string(), base), ")".to_string()) } else { base } - } +} } pub fn unwrap_single_field_product(n: Rc) -> Rc { { let is_product = is_product_type(n.clone()); - if ((is_product && (n.ident_span.clone() == None)) - && ((n.children.clone().len() as i64) == 1)) - { +if ((is_product && (n.ident_span.clone() == None)) && ((n.children.clone().len() as i64) == 1)) { match n.children.clone().first().cloned() { - Some(field_node) => resolved_type(field_node.clone()), - None => n.clone(), - } + Some(field_node) => resolved_type(field_node.clone()), + None => n.clone(), +} } else { n.clone() } - } +} } pub fn emit_file_call(op_name: String, inferred: Rc) -> String { { let effective = unwrap_single_field_product(inferred); - let is_product = is_product_type(effective.clone()); - let parse_line = if (is_product && ((effective.children.clone().len() as i64) > 1)) { +let is_product = is_product_type(effective.clone()); +let parse_line = if (is_product && ((effective.children.clone().len() as i64) > 1)) { "let parsed: serde_json::Value = serde_json::from_str(&content)?;\nOk(serde_json::from_value(parsed)?)".to_string() } else { "Ok(content)".to_string() }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "let path = format!(\"{}/{}\", self.base_path, \"".to_string(), - emit_ident(op_name, RenderTarget::Rust), - ), - "\");\n".to_string(), - ), - "let content = std::fs::read_to_string(&path)?;\n".to_string(), - ), - parse_line, - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let path = format!(\"{}/{}\", self.base_path, \"".to_string(), emit_ident(op_name, RenderTarget::Rust)), "\");\n".to_string()), "let content = std::fs::read_to_string(&path)?;\n".to_string()), parse_line) +} } pub fn emit_local_call(op_name: String) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "// Local binding -- direct function call\n".to_string(), - "Ok(".to_string(), - ), - emit_ident(op_name, RenderTarget::Rust), - ), - "())".to_string(), - ) -} - -pub fn emit_resource_def( - item: &Rc, - shared_types: Rc>, - env: &Rc, -) -> String { + v2_rt::concat(v2_rt::concat(v2_rt::concat("// Local binding -- direct function call\n".to_string(), "Ok(".to_string()), emit_ident(op_name, RenderTarget::Rust)), "())".to_string()) +} + +pub fn emit_resource_def(item: &Rc, shared_types: Rc>, env: &Rc) -> String { { let item_text = authored_name(env.clone(), item.clone()); - let cap_children = item.children.clone(); - if ((cap_children.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat( - "#[derive(Debug, Clone)]\npub struct ".to_string(), - item_text, - ), - ";".to_string(), - ) +let cap_children = item.children.clone(); +if ((cap_children.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat("#[derive(Debug, Clone)]\npub struct ".to_string(), item_text), ";".to_string()) } else { { let depth = 0; - let cap_methods = Rc::new({ - let mut __result = Vec::new(); - for c in cap_children.clone().iter().cloned() { - __result.push(emit_capability_method(&c, &shared_types, &env)); - } - __result - }); - let methods_str = cap_methods.join(&"\n\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "#[async_trait::async_trait]\npub trait ".to_string(), - item_text, - ), - " {\n".to_string(), - ), - make_indent((depth + 1)), - ), - methods_str, - ), - "\n}".to_string(), - ) - } +let cap_methods = Rc::new({ let mut __result = Vec::new(); for c in cap_children.clone().iter().cloned() { __result.push(emit_capability_method(&c, &shared_types, &env)); } __result }); +let methods_str = cap_methods.join(&"\n\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("#[async_trait::async_trait]\npub trait ".to_string(), item_text), " {\n".to_string()), make_indent((depth + 1))), methods_str), "\n}".to_string()) +} } - } +} } -pub fn emit_capability_method( - cap_node: &Rc, - shared_types: &Rc>, - env: &Rc, -) -> String { - { - let input_params = Rc::new({ - let mut __result = Vec::new(); - for p in cap_node.params.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - emit_ident( - param_node_name_at(p.clone(), env.source_indices.clone()), - RenderTarget::Rust, - ), - rust_items().param_type_sep.clone(), - ), - emit_rust_param_type( - ¶m_node_type_expr(&p), - &shared_types, - &env.source_indices.clone(), - ), - )); - } - __result - }); - let params_str = input_params.join(&", ".to_string()); - let all_params = if (params_str.clone().as_str() == "".to_string().as_str()) { +pub fn emit_capability_method(cap_node: &Rc, shared_types: &Rc>, env: &Rc) -> String { + { + let input_params = Rc::new({ let mut __result = Vec::new(); for p in cap_node.params.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(emit_ident(param_node_name_at(p.clone(), env.source_indices.clone()), RenderTarget::Rust), rust_items().param_type_sep.clone()), emit_rust_param_type(¶m_node_type_expr(&p), &shared_types, &env.source_indices.clone()))); } __result }); +let params_str = input_params.join(&", ".to_string()); +let all_params = if (params_str.clone().as_str() == "".to_string().as_str()) { "&self".to_string() } else { v2_rt::concat("&self, ".to_string(), params_str.clone()) }; - let ret = render_rust_type( - resolved_type(cap_node.clone()), - shared_types.clone(), - env.source_indices.clone(), - ); - let items = rust_items(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - items.async_prefix.clone(), - items.func_keyword.clone(), - ), - " ".to_string(), - ), - emit_ident( - authored_name(env.clone(), cap_node.clone()), - RenderTarget::Rust, - ), - ), - "(".to_string(), - ), - all_params, - ), - ") -> Result<".to_string(), - ), - ret, - ), - ", Box>;".to_string(), - ) - } +let ret = render_rust_type(resolved_type(cap_node.clone()), shared_types.clone(), env.source_indices.clone()); +let items = rust_items(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(items.async_prefix.clone(), items.func_keyword.clone()), " ".to_string()), emit_ident(authored_name(env.clone(), cap_node.clone()), RenderTarget::Rust)), "(".to_string()), all_params), ") -> Result<".to_string()), ret), ", Box>;".to_string()) +} } pub fn data_value_has_cross_refs(value: &Rc) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*value.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => true, - ExprData::ExprListLit => { - let mut __found = false; - for c in value.children.clone().iter().cloned() { - if data_value_has_cross_refs(&c) { - __found = true; - break; - } - } - __found - } - ExprData::ExprRecordLit { .. } => { - let mut __found = false; - for f in value.children.clone().iter().cloned() { - if data_value_has_cross_refs(&field_init_node_value(&f)) { - __found = true; - break; - } - } - __found - } - _ => false, - } + ExprData::ExprVar { .. } => true, + ExprData::ExprListLit => { let mut __found = false; for c in value.children.clone().iter().cloned() { if data_value_has_cross_refs(&c) { __found = true; break; } } __found }, + ExprData::ExprRecordLit { .. } => { let mut __found = false; for f in value.children.clone().iter().cloned() { if data_value_has_cross_refs(&field_init_node_value(&f)) { __found = true; break; } } __found }, + _ => false, +} }) } -pub fn emit_data_def( - name: String, - type_node: &Rc, - value: Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: &Rc>, - emit_info: Rc, -) -> String { - { - let ty_str = render_rust_type( - type_node.clone(), - shared_types.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let fn_name = to_snake(name); - let needs_rc = v2_rt::map_contains_key( - &shared_types, - authored_name_at(scope.type_env.clone().source_indices.clone(), &type_node), - ); - if is_simple_type_node( - type_node.clone(), - scope.type_env.clone().source_indices.clone(), - ) { +pub fn emit_data_def(name: String, type_node: &Rc, value: Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: &Rc>, emit_info: Rc) -> String { + { + let ty_str = render_rust_type(type_node.clone(), shared_types.clone(), scope.type_env.clone().source_indices.clone()); +let fn_name = to_snake(name); +let needs_rc = v2_rt::map_contains_key(&shared_types, authored_name_at(scope.type_env.clone().source_indices.clone(), &type_node)); +if is_simple_type_node(type_node.clone(), scope.type_env.clone().source_indices.clone()) { { - let val_str = emit_typed_expr( - value, - registry, - &scope, - depth, - shared_types.clone(), - emit_info, - 1024, - ); - let kw = rust_items().func_keyword.clone(); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(rust_visibility_prefix(), kw), - " ".to_string(), - ), - fn_name, - ), - "() -> ".to_string(), - ), - ty_str.clone(), - ), - " { ".to_string(), - ), - val_str, - ), - " }".to_string(), - ) - } + let val_str = emit_typed_expr(value, registry, &scope, depth, shared_types.clone(), emit_info, 1024); +let kw = rust_items().func_keyword.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), kw), " ".to_string()), fn_name), "() -> ".to_string()), ty_str.clone()), " { ".to_string()), val_str), " }".to_string()) +} } else { { - let body = emit_data_def_body( - &type_node, - &value, - registry, - &scope, - depth, - shared_types.clone(), - emit_info, - &needs_rc, - ); - let kw = rust_items().func_keyword.clone(); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), kw), " ".to_string()), fn_name), "() -> ".to_string()), ty_str.clone()), " {\n".to_string()), " thread_local! {\n".to_string()), " static CACHED: ".to_string()), ty_str.clone()), " = {\n".to_string()), body), "\n".to_string()), " };\n".to_string()), " }\n".to_string()), " CACHED.with(|c| c.clone())\n".to_string()), "}".to_string()) - } + let body = emit_data_def_body(&type_node, &value, registry, &scope, depth, shared_types.clone(), emit_info, &needs_rc); +let kw = rust_items().func_keyword.clone(); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_visibility_prefix(), kw), " ".to_string()), fn_name), "() -> ".to_string()), ty_str.clone()), " {\n".to_string()), " thread_local! {\n".to_string()), " static CACHED: ".to_string()), ty_str.clone()), " = {\n".to_string()), body), "\n".to_string()), " };\n".to_string()), " }\n".to_string()), " CACHED.with(|c| c.clone())\n".to_string()), "}".to_string()) +} } - } +} } -pub fn emit_data_def_body( - type_node: &Rc, - value: &Rc, - registry: Rc>>, - scope: &Rc, - depth: i64, - shared_types: Rc>, - emit_info: Rc, - needs_rc: &bool, -) -> String { - if (has_nested_records_node( - type_node.clone(), - scope.type_env.clone().source_indices.clone(), - ) && !data_value_has_cross_refs(&value)) - { +pub fn emit_data_def_body(type_node: &Rc, value: &Rc, registry: Rc>>, scope: &Rc, depth: i64, shared_types: Rc>, emit_info: Rc, needs_rc: &bool) -> String { + if (has_nested_records_node(type_node.clone(), scope.type_env.clone().source_indices.clone()) && !data_value_has_cross_refs(&value)) { { - let json_str = - emit_data_value_json(&value, scope.type_env.clone().source_indices.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " serde_json::from_value(serde_json::json!(".to_string(), - json_str, - ), - "))\n".to_string(), - ), - " .expect(\"valid data definition\")".to_string(), - ) - } + let json_str = emit_data_value_json(&value, scope.type_env.clone().source_indices.clone()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(" serde_json::from_value(serde_json::json!(".to_string(), json_str), "))\n".to_string()), " .expect(\"valid data definition\")".to_string()) +} } else { { - let is_map = - node_is_keyed_collection(&type_node, scope.type_env.clone().source_indices.clone()); - if is_map { + let is_map = node_is_keyed_collection(&type_node, scope.type_env.clone().source_indices.clone()); +if is_map { match (*value.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => { - let inserts = Rc::new({ - let mut __result = Vec::new(); - for f in value.children.clone().iter().cloned() { - __result.push({ - let val_str = emit_typed_expr( - field_init_node_value(&f), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " __m.insert(\"".to_string(), - field_init_node_name_at( - f.clone(), - scope - .type_env - .clone() - .source_indices - .clone(), - ), - ), - "\".to_string(), ".to_string(), - ), - val_str.clone(), - ), - ");".to_string(), - ) - }); - } - __result - }); - let inserts_str = inserts.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - " let mut __m = HashMap::new();\n".to_string(), - inserts_str, - ), - "\n".to_string(), - ), - " Rc::new(__m)".to_string(), - ) - } - _ => { - let val_str = emit_typed_expr( - value.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - v2_rt::concat(" ".to_string(), val_str.clone()) - } - } + ExprData::ExprRecordLit { .. } => { + let inserts = Rc::new({ let mut __result = Vec::new(); for f in value.children.clone().iter().cloned() { __result.push({ + let val_str = emit_typed_expr(field_init_node_value(&f), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" __m.insert(\"".to_string(), field_init_node_name_at(f.clone(), scope.type_env.clone().source_indices.clone())), "\".to_string(), ".to_string()), val_str.clone()), ");".to_string()) +}); } __result }); +let inserts_str = inserts.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(" let mut __m = HashMap::new();\n".to_string(), inserts_str), "\n".to_string()), " Rc::new(__m)".to_string()) +}, + _ => { + let val_str = emit_typed_expr(value.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +v2_rt::concat(" ".to_string(), val_str.clone()) +}, +} } else { { - let val_str = emit_typed_expr( - value.clone(), - registry.clone(), - &scope, - depth.clone(), - shared_types.clone(), - emit_info.clone(), - 1024, - ); - let is_already_wrapped = match (*value.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => true, - ExprData::ExprListLit => true, - _ => false, - }; - let wrap_start = if (needs_rc.clone() && !is_already_wrapped.clone()) { + let val_str = emit_typed_expr(value.clone(), registry.clone(), &scope, depth.clone(), shared_types.clone(), emit_info.clone(), 1024); +let is_already_wrapped = match (*value.expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => true, + ExprData::ExprListLit => true, + _ => false, +}; +let wrap_start = if (needs_rc.clone() && !is_already_wrapped.clone()) { "Rc::new(".to_string() } else { "".to_string() }; - let wrap_end = if (needs_rc.clone() && !is_already_wrapped.clone()) { +let wrap_end = if (needs_rc.clone() && !is_already_wrapped.clone()) { ")".to_string() } else { "".to_string() }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(" ".to_string(), wrap_start), - val_str.clone(), - ), - wrap_end, - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(" ".to_string(), wrap_start), val_str.clone()), wrap_end) +} } - } +} } } -pub fn emit_test_file( - module_name: &String, - projections: Rc>>, -) -> Rc { +pub fn emit_test_file(module_name: &String, projections: Rc>>) -> 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, (depth.clone() + 1))); - } - __result - }); - if ((test_fns.clone().len() as i64) == 0) { +let test_fns = Rc::new({ let mut __result = Vec::new(); for p in projections.iter().cloned() { __result.push(emit_operation_test(&p, (depth.clone() + 1))); } __result }); +if ((test_fns.clone().len() as i64) == 0) { Rc::new(TextFile { - path: "".to_string(), - content: "".to_string(), - }) + path: "".to_string(), + content: "".to_string(), +}) } else { { let filename = module_to_filename(module_name.clone()); - let tests_str = test_fns.clone().join(&"\n\n".to_string()); - let content = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "// Generated tests -- do not edit.\n" - .to_string(), - "// Source module: ".to_string(), - ), - module_name.clone(), - ), - "\n\n".to_string(), - ), - "#[cfg(test)]\nmod tests {\n".to_string(), - ), - " use super::*;\n\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - tests_str, - ), - "\n".to_string(), - ), - "}\n".to_string(), - ); - Rc::new(TextFile { - path: rust_test_file_path(module_name.clone()), - content: content, - }) - } +let tests_str = test_fns.clone().join(&"\n\n".to_string()); +let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Generated tests -- do not edit.\n".to_string(), "// Source module: ".to_string()), module_name.clone()), "\n\n".to_string()), "#[cfg(test)]\nmod tests {\n".to_string()), " use super::*;\n\n".to_string()), make_indent((depth.clone() + 1))), tests_str), "\n".to_string()), "}\n".to_string()); +Rc::new(TextFile { + path: rust_test_file_path(module_name.clone()), + content: content, +}) +} } - } +} } pub fn rust_test_signature_comment(projection: &Rc) -> String { { - let params_str = Rc::new({ - let mut __result = Vec::new(); - for p in projection.params.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - param_node_name_at(p.clone(), projection.source_indices.clone()), - ": ".to_string(), - ), - emit_rust_param_type( - ¶m_node_type_expr(&p), - &v2_rt::rc_empty_map::(), - &projection.source_indices.clone(), - ), - )); - } - __result - }) - .join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "// Signature: ".to_string(), - sanitize_service_name(projection.service_name.clone()), - ), - ".".to_string(), - ), - projection.operation_name.clone(), - ), - "(".to_string(), - ), - params_str, - ), - ") -> ".to_string(), - ), - emit_node_type( - projection.inferred.clone(), - RenderTarget::Rust, - projection.source_indices.clone(), - ), - ) - } + let params_str = Rc::new({ let mut __result = Vec::new(); for p in projection.params.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(param_node_name_at(p.clone(), projection.source_indices.clone()), ": ".to_string()), emit_rust_param_type(¶m_node_type_expr(&p), &v2_rt::rc_empty_map::(), &projection.source_indices.clone()))); } __result }).join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Signature: ".to_string(), sanitize_service_name(projection.service_name.clone())), ".".to_string()), projection.operation_name.clone()), "(".to_string()), params_str), ") -> ".to_string()), emit_node_type(projection.inferred.clone(), RenderTarget::Rust, projection.source_indices.clone())) +} } pub fn emit_operation_test(projection: &Rc, depth: i64) -> String { { let test_name = rust_test_name(projection.clone()); - let struct_name = sanitize_service_name(projection.service_name.clone()); - let op_method = to_snake(projection.operation_name.clone()); - let indent = make_indent((depth + 1)); - let param_args = Rc::new({ - let mut __result = Vec::new(); - for p in projection.params.clone().iter().cloned() { - __result.push(emit_rust_default_value( - p.clone(), - projection.source_indices.clone(), - )); - } - __result - }); - let args_str = param_args.join(&", ".to_string()); - let call_args = if (args_str.clone().as_str() == "".to_string().as_str()) { +let struct_name = sanitize_service_name(projection.service_name.clone()); +let op_method = to_snake(projection.operation_name.clone()); +let indent = make_indent((depth + 1)); +let param_args = Rc::new({ let mut __result = Vec::new(); for p in projection.params.clone().iter().cloned() { __result.push(emit_rust_default_value(p.clone(), projection.source_indices.clone())); } __result }); +let args_str = param_args.join(&", ".to_string()); +let call_args = if (args_str.clone().as_str() == "".to_string().as_str()) { "".to_string() } else { args_str.clone() }; - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_async_test_decorator(), "\nasync fn ".to_string()), test_name), "() {\n".to_string()), indent.clone()), rust_test_signature_comment(&projection)), "\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()) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rust_async_test_decorator(), "\nasync fn ".to_string()), test_name), "() {\n".to_string()), indent.clone()), rust_test_signature_comment(&projection)), "\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()) +} } -pub fn emit_rust_default_value( - param: Rc, - source_indices: Rc>>, -) -> String { +pub fn emit_rust_default_value(param: Rc, source_indices: Rc>>) -> String { { let type_name = authored_name_at(source_indices, ¶m_node_type_expr(¶m)); - match lookup_checkpoint(RenderTarget::Rust, type_name.clone()) { - Some(cp) => match cp.default_expr.clone() { - Some(expr) => expr.clone(), - None => v2_rt::concat( - v2_rt::concat( - "compile_error!(\"no test default for type: ".to_string(), - type_name.clone(), - ), - "\")".to_string(), - ), - }, - None => v2_rt::concat( - v2_rt::concat( - "compile_error!(\"no test default for type: ".to_string(), - type_name.clone(), - ), - "\")".to_string(), - ), - } - } +match lookup_checkpoint(RenderTarget::Rust, type_name.clone()) { + Some(cp) => match cp.default_expr.clone() { + Some(expr) => expr.clone(), + None => v2_rt::concat(v2_rt::concat("compile_error!(\"no test default for type: ".to_string(), type_name.clone()), "\")".to_string()), +}, + None => v2_rt::concat(v2_rt::concat("compile_error!(\"no test default for type: ".to_string(), type_name.clone()), "\")".to_string()), +} +} } -pub fn emit_mock_prop_setup( - mock_prop: &Rc, - depth: i64, - source_indices: &Rc>>, -) -> String { - { - let body_str = emit_simple_expr( - &field_init_node_value(&mock_prop), - &RenderTarget::Rust, - &source_indices, - ); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "let ".to_string(), - field_init_node_name_at(mock_prop.clone(), source_indices.clone()), - ), - " = ".to_string(), - ), - body_str, - ), - ";".to_string(), - ) - } +pub fn emit_mock_prop_setup(mock_prop: &Rc, depth: i64, source_indices: &Rc>>) -> String { + { + let body_str = emit_simple_expr(&field_init_node_value(&mock_prop), &RenderTarget::Rust, &source_indices); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("let ".to_string(), field_init_node_name_at(mock_prop.clone(), source_indices.clone())), " = ".to_string()), body_str), ";".to_string()) +} } pub fn emit_cargo_dep(name: String, version: String, features: &Rc>) -> String { if ((features.clone().len() as i64) > 0) { { - let feat_strs = Rc::new({ - let mut __result = Vec::new(); - for f in features.clone().iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat("\"".to_string(), f.clone()), - "\"".to_string(), - )); - } - __result - }); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(name, " = { version = \"".to_string()), - version, - ), - "\", features = [".to_string(), - ), - feat_strs.join(&", ".to_string()), - ), - "] }\n".to_string(), - ) - } + let feat_strs = Rc::new({ let mut __result = Vec::new(); for f in features.clone().iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat("\"".to_string(), f.clone()), "\"".to_string())); } __result }); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(name, " = { version = \"".to_string()), version), "\", features = [".to_string()), feat_strs.join(&", ".to_string())), "] }\n".to_string()) +} } else { - v2_rt::concat( - v2_rt::concat(v2_rt::concat(name, " = \"".to_string()), version), - "\"\n".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(name, " = \"".to_string()), version), "\"\n".to_string()) } } pub fn emit_cargo_toml(crate_name: String, has_services: bool) -> Rc { { - let header = v2_rt::concat( - v2_rt::concat("[package]\nname = \"".to_string(), crate_name), - "\"\nversion = \"0.1.0\"\nedition = \"2021\"\n".to_string(), - ); - let workspace = "\n[workspace]\n".to_string(); - let base_deps = Rc::new(vec![ - emit_cargo_dep( - "serde".to_string(), - "1".to_string(), - &Rc::new(vec!["derive".to_string(), "rc".to_string()]), - ), - emit_cargo_dep("serde_json".to_string(), "1".to_string(), &Rc::new(vec![])), - emit_cargo_dep("stacker".to_string(), "0.1".to_string(), &Rc::new(vec![])), - emit_cargo_dep( - "clap".to_string(), - "4".to_string(), - &Rc::new(vec!["derive".to_string()]), - ), - emit_cargo_dep("lazy_static".to_string(), "1".to_string(), &Rc::new(vec![])), - ]); - let async_deps = if has_services { - Rc::new(vec![ - emit_cargo_dep( - "tokio".to_string(), - "1".to_string(), - &Rc::new(vec!["full".to_string()]), - ), - emit_cargo_dep( - "reqwest".to_string(), - "0.12".to_string(), - &Rc::new(vec!["json".to_string()]), - ), - emit_cargo_dep( - "async-trait".to_string(), - "0.1".to_string(), - &Rc::new(vec![]), - ), - ]) + let header = v2_rt::concat(v2_rt::concat("[package]\nname = \"".to_string(), crate_name), "\"\nversion = \"0.1.0\"\nedition = \"2021\"\n".to_string()); +let workspace = "\n[workspace]\n".to_string(); +let base_deps = Rc::new(vec![emit_cargo_dep("serde".to_string(), "1".to_string(), &Rc::new(vec!["derive".to_string(), "rc".to_string()])), emit_cargo_dep("serde_json".to_string(), "1".to_string(), &Rc::new(vec![])), emit_cargo_dep("stacker".to_string(), "0.1".to_string(), &Rc::new(vec![])), emit_cargo_dep("clap".to_string(), "4".to_string(), &Rc::new(vec!["derive".to_string()])), emit_cargo_dep("lazy_static".to_string(), "1".to_string(), &Rc::new(vec![]))]); +let async_deps = if has_services { + Rc::new(vec![emit_cargo_dep("tokio".to_string(), "1".to_string(), &Rc::new(vec!["full".to_string()])), emit_cargo_dep("reqwest".to_string(), "0.12".to_string(), &Rc::new(vec!["json".to_string()])), emit_cargo_dep("async-trait".to_string(), "0.1".to_string(), &Rc::new(vec![]))]) } else { Rc::new(vec![]) }; - let all_deps = v2_rt::concat(base_deps, async_deps); - Rc::new(TextFile { - path: "Cargo.toml".to_string(), - content: v2_rt::concat( - v2_rt::concat( - v2_rt::concat(header, workspace), - "\n[dependencies]\n".to_string(), - ), - all_deps.join(&"".to_string()), - ), - }) - } +let all_deps = v2_rt::concat(base_deps, async_deps); +Rc::new(TextFile { + path: "Cargo.toml".to_string(), + content: v2_rt::concat(v2_rt::concat(v2_rt::concat(header, workspace), "\n[dependencies]\n".to_string()), all_deps.join(&"".to_string())), +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -14935,119 +5979,73 @@ pub struct WorkflowFunc { pub fn extract_literal_string(expr: Rc) -> Option { match (*expr.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitStr { value: s, .. } => Some(s.clone()), - LiteralValue::LitBool { value: b, .. } => Some(if b.clone() { - "true".to_string() - } else { - "false".to_string() - }), - _ => None, - }, - _ => None, - } + ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitStr { value: s, .. } => Some(s.clone()), + LiteralValue::LitBool { value: b, .. } => Some(if b.clone() { + "true".to_string() + } else { + "false".to_string() + }), + _ => None, +}, + _ => None, +} } -pub fn resolve_param_default( - param: Rc, - registry: Rc>>, - module_items: Rc>>, - source_indices: &Rc>>, -) -> Option { +pub fn resolve_param_default(param: Rc, registry: Rc>>, module_items: Rc>>, source_indices: &Rc>>) -> Option { match param_node_default_value(¶m) { - Some(dv) => match (*dv.expr_data.clone()).clone() { - ExprData::ExprLiteral { .. } => extract_literal_string(dv.clone()), - ExprData::ExprVar { .. } => { - match lookup_item(registry, authored_name_at(source_indices.clone(), &dv)) { - Some(info) => match info.kind.clone() { - 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).as_str() - == authored_name_at(source_indices.clone(), &dv).as_str()) - { - __result.push(i); - } - } - __result - }) - .first() - .cloned() - { - Some(data_item) => match data_item.body.clone() { - Some(body) => extract_literal_string(body.clone()), - None => None, - }, - None => None, - }, - _ => None, - }, - None => None, - } - } - _ => None, - }, - None => None, - } + Some(dv) => match (*dv.expr_data.clone()).clone() { + ExprData::ExprLiteral { .. } => extract_literal_string(dv.clone()), + ExprData::ExprVar { .. } => match lookup_item(registry, authored_name_at(source_indices.clone(), &dv)) { + Some(info) => match info.kind.clone() { + 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).as_str() == authored_name_at(source_indices.clone(), &dv).as_str()) { __result.push(i); } } __result }).first().cloned() { + Some(data_item) => match data_item.body.clone() { + Some(body) => extract_literal_string(body.clone()), + None => None, +}, + None => None, +}, + _ => None, +}, + None => None, +}, + _ => None, +}, + None => None, +} } -pub fn to_workflow_func( - item: &Rc, - module_name: &String, - registry: &Rc>>, - module_items: Rc>>, - source_indices: &Rc>>, - read_only_params_index: Rc>>>, -) -> Rc { +pub fn to_workflow_func(item: &Rc, module_name: &String, registry: &Rc>>, module_items: Rc>>, source_indices: &Rc>>, read_only_params_index: Rc>>>) -> Rc { { let item_name = authored_name_at(source_indices.clone(), &item); - let svc_names = match lookup_item(registry.clone(), item_name.clone()) { - Some(info) => info.service_names.clone(), - None => Rc::new(vec![]), - }; - let defaults = item.params.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, p: Rc| match resolve_param_default( - p.clone(), - registry.clone(), - module_items.clone(), - &source_indices, - ) { - Some(lit) => v2_rt::rc_map_insert( - acc.clone(), - param_node_name_at(p.clone(), source_indices.clone()), - lit.clone(), - ), - None => acc.clone(), - }, - ); - let qualified = v2_rt::concat( - v2_rt::concat(module_name.clone(), ".".to_string()), - item_name.clone(), - ); - let ro_params = match v2_rt::map_get(&read_only_params_index, qualified) { - Some(m) => m.clone(), - None => v2_rt::rc_empty_map::(), - }; - Rc::new(WorkflowFunc { - name: item_name.clone(), - module_name: module_name.clone(), - params: item.params.clone(), - inferred: resolved_type(item.clone()), - uses: item.uses.clone(), - service_names: svc_names, - resolved_defaults: defaults, - read_only_params: ro_params, - source_indices: source_indices.clone(), - }) - } +let svc_names = match lookup_item(registry.clone(), item_name.clone()) { + Some(info) => info.service_names.clone(), + None => Rc::new(vec![]), +}; +let defaults = item.params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, p: Rc| match resolve_param_default(p.clone(), registry.clone(), module_items.clone(), &source_indices) { + Some(lit) => v2_rt::rc_map_insert(acc.clone(), param_node_name_at(p.clone(), source_indices.clone()), lit.clone()), + None => acc.clone(), +}); +let qualified = v2_rt::concat(v2_rt::concat(module_name.clone(), ".".to_string()), item_name.clone()); +let ro_params = match v2_rt::map_get(&read_only_params_index, qualified) { + Some(m) => m.clone(), + None => v2_rt::rc_empty_map::(), +}; +Rc::new(WorkflowFunc { + name: item_name.clone(), + module_name: module_name.clone(), + params: item.params.clone(), + inferred: resolved_type(item.clone()), + uses: item.uses.clone(), + service_names: svc_names, + resolved_defaults: defaults, + read_only_params: ro_params, + source_indices: source_indices.clone(), +}) +} } -pub fn is_workflow_item( - item: &Rc, - registry: Rc>>, - source_indices: Rc>>, -) -> bool { +pub fn is_workflow_item(item: &Rc, registry: Rc>>, source_indices: Rc>>) -> bool { if (item.body.clone() == None) { false } else { @@ -15055,89 +6053,36 @@ pub fn is_workflow_item( true } else { match lookup_item(registry, authored_name_at(source_indices, &item)) { - Some(info) => { - (((info.service_names.clone().len() as i64) > 0) - || ((info.resource_names.clone().len() as i64) > 0)) - } - None => true, - } + Some(info) => (((info.service_names.clone().len() as i64) > 0) || ((info.resource_names.clone().len() as i64) > 0)), + None => true, +} } } } -pub fn collect_workflow_funcs( - modules: Rc>>, - registry: Rc>>, - read_only_params_index: Rc>>>, -) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for tm in modules.iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in tm.items.clone().iter().cloned() { - if is_workflow_item( - &item, - registry.clone(), - tm.type_env.clone().source_indices.clone(), - ) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(to_workflow_func( - &item, - &authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - ), - ®istry, - tm.items.clone(), - &tm.type_env.clone().source_indices.clone(), - read_only_params_index.clone(), - )); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }) +pub fn collect_workflow_funcs(modules: Rc>>, registry: Rc>>, read_only_params_index: Rc>>>) -> Rc>> { + Rc::new({ let mut __result = Vec::new(); for tm in modules.iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in tm.items.clone().iter().cloned() { if is_workflow_item(&item, registry.clone(), tm.type_env.clone().source_indices.clone()) { __result.push(item); } } __result }).iter().cloned() { __result.push(to_workflow_func(&item, &authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone()), ®istry, tm.items.clone(), &tm.type_env.clone().source_indices.clone(), read_only_params_index.clone())); } __result })).iter().cloned()); } __result }) } pub fn cli_default_literal_value(expr: Rc) -> Option { match (*expr.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitStr { value: s, .. } => Some(s.clone()), - LiteralValue::LitInt { value: i, .. } => Some((i.clone()).to_string()), - LiteralValue::LitFloat { value: f, .. } => Some(f.clone()), - LiteralValue::LitBool { value: b, .. } => Some(if b.clone() { - emit_keyword("true".to_string(), RenderTarget::Rust) - } else { - emit_keyword("false".to_string(), RenderTarget::Rust) - }), - LiteralValue::LitNull => None, - }, - _ => None, - } + ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitStr { value: s, .. } => Some(s.clone()), + LiteralValue::LitInt { value: i, .. } => Some((i.clone()).to_string()), + LiteralValue::LitFloat { value: f, .. } => Some(f.clone()), + LiteralValue::LitBool { value: b, .. } => Some(if b.clone() { + emit_keyword("true".to_string(), RenderTarget::Rust) + } else { + emit_keyword("false".to_string(), RenderTarget::Rust) + }), + LiteralValue::LitNull => None, +}, + _ => None, +} } -pub fn validate_workflow_param_defaults( - workflow_funcs: Rc>>, -) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for wf in workflow_funcs.iter().cloned() { - __result.extend((*Rc::new({ let mut __result = Vec::new(); for param in wf.params.clone().iter().cloned() { __result.extend((*match param_node_default_value(¶m) { +pub fn validate_workflow_param_defaults(workflow_funcs: Rc>>) -> Rc>> { + Rc::new({ let mut __result = Vec::new(); for wf in workflow_funcs.iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for param in wf.params.clone().iter().cloned() { __result.extend((*match param_node_default_value(¶m) { Some(dv) => { let param_name = authored_name_at(wf.source_indices.clone(), ¶m); let resolved = match v2_rt::map_get(&wf.resolved_defaults.clone(), param_name.clone()) { @@ -15157,617 +6102,257 @@ if resolved.clone() { } }, None => Rc::new(vec![]), -}).iter().cloned()); } __result })).iter().cloned()); - } - __result - }) +}).iter().cloned()); } __result })).iter().cloned()); } __result }) } pub fn find_resource_module(resource_name: String, modules: Rc>>) -> String { { - let matching = Rc::new({ - let mut __result = Vec::new(); - for m in modules.iter().cloned() { - if { - let mut __found = false; - for item in m.items.clone().iter().cloned() { - if (authored_name_at(m.type_env.clone().source_indices.clone(), &item) - .as_str() - == resource_name.clone().as_str()) - { - __found = true; - break; - } - } - __found - } { - __result.push(m); - } - } - __result - }); - let result = match matching.first().cloned() { - Some(tm) => module_to_filename(authored_name_at( - tm.type_env.clone().source_indices.clone(), - &tm.module.clone(), - )), - None => "".to_string(), - }; - result - } + let matching = Rc::new({ let mut __result = Vec::new(); for m in modules.iter().cloned() { if { let mut __found = false; for item in m.items.clone().iter().cloned() { if (authored_name_at(m.type_env.clone().source_indices.clone(), &item).as_str() == resource_name.clone().as_str()) { __found = true; break; } } __found } { __result.push(m); } } __result }); +let result = match matching.first().cloned() { + Some(tm) => module_to_filename(authored_name_at(tm.type_env.clone().source_indices.clone(), &tm.module.clone())), + None => "".to_string(), +}; +result +} } -pub fn emit_main_rs( - workflow_funcs: &Rc>>, - modules: &Rc>>, - has_services: &bool, - crate_name: &String, - svc_module_map: Rc>, -) -> Rc { - { - let has_pipeline = { - let mut __found = false; - for m in modules.clone().iter().cloned() { - if (authored_name_at(m.type_env.clone().source_indices.clone(), &m.module.clone()) - .as_str() - == "v2.compiler.compile".to_string().as_str()) - { - __found = true; - break; - } - } - __found - }; - let resource_type_names = Rc::new({ - let mut __result = Vec::new(); - for wf in workflow_funcs.clone().iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for u in wf.uses.clone().iter().cloned() { - __result.push(authored_name_at( - wf.source_indices.clone(), - &resource_use_resource(&u), - )); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }); - let unique_resource_types = unique_strings(resource_type_names); - let resource_imports = Rc::new({ - let mut __result = Vec::new(); - for rname in unique_resource_types.iter().cloned() { - __result.extend( - (*{ - let mod_name = find_resource_module(rname.clone(), modules.clone()); - if (mod_name.clone().as_str() != "".to_string().as_str()) { - Rc::new(vec![v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "use ".to_string(), - crate_name.clone(), - ), - "::".to_string(), - ), - mod_name.clone(), - ), - "::".to_string(), - ), - rname.clone(), - ), - ";".to_string(), - )]) - } else { - Rc::new(vec![]) - } - }) - .iter() - .cloned(), - ); - } - __result - }); - let resource_imports_str = resource_imports.join(&"\n".to_string()); - let all_svc_names = Rc::new({ - let mut __result = Vec::new(); - for wf in workflow_funcs.clone().iter().cloned() { - __result.extend((*wf.service_names.clone()).iter().cloned()); - } - __result - }); - let unique_svc_names = unique_strings(all_svc_names); - let svc_imports = Rc::new({ - let mut __result = Vec::new(); - for sn in unique_svc_names.iter().cloned() { - __result.extend( - (*{ - let struct_name = sanitize_service_name(sn.clone()); - match v2_rt::map_get(&svc_module_map, sn.clone()) { - Some(mod_name) => Rc::new(vec![v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "use ".to_string(), - crate_name.clone(), - ), - "::".to_string(), - ), - mod_name.clone(), - ), - "::".to_string(), - ), - struct_name.clone(), - ), - ";".to_string(), - )]), - None => Rc::new(vec![]), - } - }) - .iter() - .cloned(), - ); - } - __result - }); - let svc_imports_str = svc_imports.join(&"\n".to_string()); - let header = v2_rt::concat( - v2_rt::concat( - "// Generated by v2 compiler -- do not edit.\n\n".to_string(), - "#![allow(unused_parens, clippy::all, clippy::disallowed_macros)]\n\n".to_string(), - ), - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("use clap::".to_string(), "{".to_string()), - "Parser, Subcommand".to_string(), - ), - "}".to_string(), - ), - ";\n".to_string(), - ), - ); - let crate_use = if has_services.clone() { - v2_rt::concat( - v2_rt::concat("use ".to_string(), crate_name.clone()), - "::dry_run::DryRunMode;\n".to_string(), - ) +pub fn emit_main_rs(workflow_funcs: &Rc>>, modules: &Rc>>, has_services: &bool, crate_name: &String, svc_module_map: Rc>) -> Rc { + { + let has_pipeline = { let mut __found = false; for m in modules.clone().iter().cloned() { if (authored_name_at(m.type_env.clone().source_indices.clone(), &m.module.clone()).as_str() == "v2.compiler.compile".to_string().as_str()) { __found = true; break; } } __found }; +let resource_type_names = Rc::new({ let mut __result = Vec::new(); for wf in workflow_funcs.clone().iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for u in wf.uses.clone().iter().cloned() { __result.push(authored_name_at(wf.source_indices.clone(), &resource_use_resource(&u))); } __result })).iter().cloned()); } __result }); +let unique_resource_types = unique_strings(resource_type_names); +let resource_imports = Rc::new({ let mut __result = Vec::new(); for rname in unique_resource_types.iter().cloned() { __result.extend((*{ + let mod_name = find_resource_module(rname.clone(), modules.clone()); +if (mod_name.clone().as_str() != "".to_string().as_str()) { + Rc::new(vec![v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("use ".to_string(), crate_name.clone()), "::".to_string()), mod_name.clone()), "::".to_string()), rname.clone()), ";".to_string())]) + } else { + Rc::new(vec![]) + } +}).iter().cloned()); } __result }); +let resource_imports_str = resource_imports.join(&"\n".to_string()); +let all_svc_names = Rc::new({ let mut __result = Vec::new(); for wf in workflow_funcs.clone().iter().cloned() { __result.extend((*wf.service_names.clone()).iter().cloned()); } __result }); +let unique_svc_names = unique_strings(all_svc_names); +let svc_imports = Rc::new({ let mut __result = Vec::new(); for sn in unique_svc_names.iter().cloned() { __result.extend((*{ + let struct_name = sanitize_service_name(sn.clone()); +match v2_rt::map_get(&svc_module_map, sn.clone()) { + Some(mod_name) => Rc::new(vec![v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("use ".to_string(), crate_name.clone()), "::".to_string()), mod_name.clone()), "::".to_string()), struct_name.clone()), ";".to_string())]), + None => Rc::new(vec![]), +} +}).iter().cloned()); } __result }); +let svc_imports_str = svc_imports.join(&"\n".to_string()); +let header = v2_rt::concat(v2_rt::concat("// Generated by v2 compiler -- do not edit.\n\n".to_string(), "#![allow(unused_parens, clippy::all, clippy::disallowed_macros)]\n\n".to_string()), v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("use clap::".to_string(), "{".to_string()), "Parser, Subcommand".to_string()), "}".to_string()), ";\n".to_string())); +let crate_use = if has_services.clone() { + v2_rt::concat(v2_rt::concat("use ".to_string(), crate_name.clone()), "::dry_run::DryRunMode;\n".to_string()) } else { "".to_string() }; - let resource_use = if (resource_imports_str.clone().as_str() != "".to_string().as_str()) { +let resource_use = if (resource_imports_str.clone().as_str() != "".to_string().as_str()) { v2_rt::concat(resource_imports_str.clone(), "\n".to_string()) } else { "".to_string() }; - let svc_use = if (svc_imports_str.clone().as_str() != "".to_string().as_str()) { +let svc_use = if (svc_imports_str.clone().as_str() != "".to_string().as_str()) { v2_rt::concat(svc_imports_str.clone(), "\n".to_string()) } else { "".to_string() }; - let mod_uses = - emit_main_mod_uses(workflow_funcs.clone(), has_pipeline.clone(), &crate_name); - let cli_struct = emit_cli_struct(workflow_funcs.clone()); - let subcommand_enum = emit_subcommand_enum(workflow_funcs.clone(), &has_pipeline); - let pipeline_fns = if has_pipeline.clone() { +let mod_uses = emit_main_mod_uses(workflow_funcs.clone(), has_pipeline.clone(), &crate_name); +let cli_struct = emit_cli_struct(workflow_funcs.clone()); +let subcommand_enum = emit_subcommand_enum(workflow_funcs.clone(), &has_pipeline); +let pipeline_fns = if has_pipeline.clone() { emit_main_pipeline_fns(crate_name.clone()) } else { "".to_string() }; - let main_fn = emit_main_fn( - workflow_funcs.clone(), - &has_services, - &has_pipeline, - &crate_name, - ); - let diagnostic_fns = if has_pipeline.clone() { +let main_fn = emit_main_fn(workflow_funcs.clone(), &has_services, &has_pipeline, &crate_name); +let diagnostic_fns = if has_pipeline.clone() { emit_main_diagnostic_fns(crate_name.clone()) } else { "".to_string() }; - let content = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(header, crate_use), - resource_use, - ), - svc_use, - ), - mod_uses, - ), - "\n".to_string(), - ), - cli_struct, - ), - "\n\n".to_string(), - ), - subcommand_enum, - ), - "\n\n".to_string(), - ), - pipeline_fns, - ), - main_fn, - ), - "\n".to_string(), - ), - diagnostic_fns, - ); - Rc::new(TextFile { - path: v2_rt::concat( - v2_rt::concat(rust_source_root(), "main".to_string()), - rust_source_ext(), - ), - content: content, - }) - } +let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(header, crate_use), resource_use), svc_use), mod_uses), "\n".to_string()), cli_struct), "\n\n".to_string()), subcommand_enum), "\n\n".to_string()), pipeline_fns), main_fn), "\n".to_string()), diagnostic_fns); +Rc::new(TextFile { + path: v2_rt::concat(v2_rt::concat(rust_source_root(), "main".to_string()), rust_source_ext()), + content: content, +}) +} } -pub fn emit_main_mod_uses( - workflow_funcs: Rc>>, - has_pipeline: bool, - crate_name: &String, -) -> String { +pub fn emit_main_mod_uses(workflow_funcs: Rc>>, has_pipeline: bool, crate_name: &String) -> String { { - let mod_names = Rc::new({ - let mut __result = Vec::new(); - for wf in workflow_funcs.iter().cloned() { - __result.push(module_to_filename(wf.module_name.clone())); - } - __result - }); - let unique_mods = unique_strings(mod_names); - let use_lines = Rc::new({ - let mut __result = Vec::new(); - for m in unique_mods.iter().cloned() { - __result.push(v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("use ".to_string(), crate_name.clone()), - "::".to_string(), - ), - m.clone(), - ), - ";".to_string(), - )); - } - __result - }); - let base = use_lines.join(&"\n".to_string()); - if has_pipeline { + let mod_names = Rc::new({ let mut __result = Vec::new(); for wf in workflow_funcs.iter().cloned() { __result.push(module_to_filename(wf.module_name.clone())); } __result }); +let unique_mods = unique_strings(mod_names); +let use_lines = Rc::new({ let mut __result = Vec::new(); for m in unique_mods.iter().cloned() { __result.push(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("use ".to_string(), crate_name.clone()), "::".to_string()), m.clone()), ";".to_string())); } __result }); +let base = use_lines.join(&"\n".to_string()); +if has_pipeline { { let pipeline_mod = module_to_filename("v2.compiler.compile".to_string()); - let artifact_mod = module_to_filename("v2.compiler.artifact".to_string()); - let core_mod = module_to_filename("v2.std.core".to_string()); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(base, "\nuse std::collections::HashMap;\n".to_string()), "use std::rc::Rc;\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), pipeline_mod.clone()), ";\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), pipeline_mod.clone()), "::PipelineResult;\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), artifact_mod), ";\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), core_mod), "::".to_string()), "{".to_string()), "\n diagnostic_to_message, diagnostic_to_span,\n".to_string()), " byte_to_line_col, source_line_at, NewlineIndex,\n".to_string()), " CompilerDiagnostic,\n".to_string()), "}".to_string()), ";\n".to_string()), "use ".to_string()), crate_name.clone()), "::cli_run;\n".to_string()) - } +let artifact_mod = module_to_filename("v2.compiler.artifact".to_string()); +let core_mod = module_to_filename("v2.std.core".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(base, "\nuse std::collections::HashMap;\n".to_string()), "use std::rc::Rc;\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), pipeline_mod.clone()), ";\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), pipeline_mod.clone()), "::PipelineResult;\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), artifact_mod), ";\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), core_mod), "::".to_string()), "{".to_string()), "\n diagnostic_to_message, diagnostic_to_span,\n".to_string()), " byte_to_line_col, source_line_at, NewlineIndex,\n".to_string()), " CompilerDiagnostic,\n".to_string()), "}".to_string()), ";\n".to_string()), "use ".to_string()), crate_name.clone()), "::cli_run;\n".to_string()) +} } else { base } - } +} } pub fn emit_cli_struct(workflow_funcs: Rc>>) -> String { v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("#[derive(Parser)]\n".to_string(), "#[command(name = \"v2-compiled\", about = \"Generated CLI from DAG compiler\")]\n".to_string()), "struct Cli {\n".to_string()), " #[command(subcommand)]\n".to_string()), " command: Commands,\n".to_string()), " /// Run in dry-run mode (mock all service calls)\n".to_string()), " #[arg(long, global = true)]\n".to_string()), " dry_run: bool,\n".to_string()), "}".to_string()) } -pub fn emit_subcommand_enum( - workflow_funcs: Rc>>, - has_pipeline: &bool, -) -> String { +pub fn emit_subcommand_enum(workflow_funcs: Rc>>, has_pipeline: &bool) -> String { { let depth = 0; - let variants = Rc::new({ - let mut __result = Vec::new(); - for wf in workflow_funcs.iter().cloned() { - __result.push(emit_subcommand_variant(&wf, (depth.clone() + 1))); - } - __result - }); - let compile_variant = if has_pipeline.clone() { +let variants = Rc::new({ let mut __result = Vec::new(); for wf in workflow_funcs.iter().cloned() { __result.push(emit_subcommand_variant(&wf, (depth.clone() + 1))); } __result }); +let compile_variant = if has_pipeline.clone() { v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("/// Compile .dag source files to a target language\n".to_string(), make_indent((depth.clone() + 1))), "Compile {\n".to_string()), make_indent((depth.clone() + 2))), "/// Source root directories (searched recursively for .dag files).\n".to_string()), make_indent((depth.clone() + 2))), "/// Module imports are resolved transitively from these roots.\n".to_string()), make_indent((depth.clone() + 2))), "#[arg(long = \"source-root\")]\n".to_string()), make_indent((depth.clone() + 2))), "source_roots: Vec,\n".to_string()), make_indent((depth.clone() + 2))), "/// Legacy: single source directory (all .dag files loaded, no import resolution)\n".to_string()), make_indent((depth.clone() + 2))), "#[arg(long = \"source-dir\")]\n".to_string()), make_indent((depth.clone() + 2))), "source_dir: Option,\n".to_string()), make_indent((depth.clone() + 2))), "#[arg(long)]\n".to_string()), make_indent((depth.clone() + 2))), "output_dir: String,\n".to_string()), make_indent((depth.clone() + 2))), "/// Target language: rust, python, go, dag\n".to_string()), make_indent((depth.clone() + 2))), "#[arg(long, default_value = \"rust\")]\n".to_string()), make_indent((depth.clone() + 2))), "target: String,\n".to_string()), make_indent((depth.clone() + 1))), "},".to_string()) } else { "".to_string() }; - let run_variant = if has_pipeline.clone() { +let run_variant = if has_pipeline.clone() { v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("/// Execute a .dag program directly (interpreter)\n".to_string(), make_indent((depth.clone() + 1))), "Run {\n".to_string()), make_indent((depth.clone() + 2))), "/// Source root directories (searched recursively for .dag files)\n".to_string()), make_indent((depth.clone() + 2))), "#[arg(long = \"source-root\")]\n".to_string()), make_indent((depth.clone() + 2))), "source_roots: Vec,\n".to_string()), make_indent((depth.clone() + 2))), "/// Entry function to execute (default: \"main\")\n".to_string()), make_indent((depth.clone() + 2))), "#[arg(long, default_value = \"main\")]\n".to_string()), make_indent((depth.clone() + 2))), "function: String,\n".to_string()), make_indent((depth.clone() + 1))), "},".to_string()) } else { "".to_string() }; - let all_variants = if has_pipeline.clone() { +let all_variants = if has_pipeline.clone() { v2_rt::concat(variants, Rc::new(vec![compile_variant, run_variant])) } else { variants }; - let variants_str = all_variants.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "#[derive(Subcommand)]\n".to_string(), - "enum Commands {\n".to_string(), - ), - make_indent((depth.clone() + 1)), - ), - variants_str, - ), - "\n".to_string(), - ), - "}".to_string(), - ) - } +let variants_str = all_variants.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("#[derive(Subcommand)]\n".to_string(), "enum Commands {\n".to_string()), make_indent((depth.clone() + 1))), variants_str), "\n".to_string()), "}".to_string()) +} } pub fn emit_subcommand_variant(wf: &Rc, depth: i64) -> String { { let variant_name = to_pascal(wf.name.clone()); - let doc_line = v2_rt::concat( - v2_rt::concat("/// Run the ".to_string(), wf.name.clone()), - " workflow".to_string(), - ); - if ((wf.params.clone().len() as i64) == 0) { - v2_rt::concat( - v2_rt::concat(v2_rt::concat(doc_line, "\n".to_string()), variant_name), - ",".to_string(), - ) +let doc_line = v2_rt::concat(v2_rt::concat("/// Run the ".to_string(), wf.name.clone()), " workflow".to_string()); +if ((wf.params.clone().len() as i64) == 0) { + v2_rt::concat(v2_rt::concat(v2_rt::concat(doc_line, "\n".to_string()), variant_name), ",".to_string()) } else { { - let fields = Rc::new({ - let mut __result = Vec::new(); - for p in wf.params.clone().iter().cloned() { - __result.push(emit_subcommand_field( - &p, - &wf.source_indices.clone(), - wf.resolved_defaults.clone(), - )); - } - __result - }); - let fields_str = fields.join(&"\n".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(doc_line, "\n".to_string()), - variant_name, - ), - " {\n".to_string(), - ), - make_indent((depth + 1)), - ), - fields_str, - ), - "\n".to_string(), - ), - "},".to_string(), - ) - } + let fields = Rc::new({ let mut __result = Vec::new(); for p in wf.params.clone().iter().cloned() { __result.push(emit_subcommand_field(&p, &wf.source_indices.clone(), wf.resolved_defaults.clone())); } __result }); +let fields_str = fields.join(&"\n".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(doc_line, "\n".to_string()), variant_name), " {\n".to_string()), make_indent((depth + 1))), fields_str), "\n".to_string()), "},".to_string()) +} } - } +} } -pub fn emit_subcommand_field( - param: &Rc, - source_indices: &Rc>>, - resolved_defaults: Rc>, -) -> String { - { - let field_name = emit_ident( - param_node_name_at(param.clone(), source_indices.clone()), - RenderTarget::Rust, - ); - let param_name = param_node_name_at(param.clone(), source_indices.clone()); - let field_type = - emit_cli_param_type_node(¶m_node_type_expr(¶m), source_indices.clone()); - let default_attr = match v2_rt::map_get(&resolved_defaults, param_name) { - Some(resolved) => v2_rt::concat( - v2_rt::concat( - "#[arg(long, default_value = \"".to_string(), - resolved.clone(), - ), - "\")]\n".to_string(), - ), - None => match param_node_default_value(¶m) { - Some(dv) => match cli_default_literal_value(dv.clone()) { - Some(default_value) => v2_rt::concat( - v2_rt::concat( - "#[arg(long, default_value = \"".to_string(), - default_value.clone(), - ), - "\")]\n".to_string(), - ), - None => "#[arg(long)]\n".to_string(), - }, - None => "#[arg(long)]\n".to_string(), - }, - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(default_attr, field_name), ": ".to_string()), - field_type, - ), - ",".to_string(), - ) - } +pub fn emit_subcommand_field(param: &Rc, source_indices: &Rc>>, resolved_defaults: Rc>) -> String { + { + let field_name = emit_ident(param_node_name_at(param.clone(), source_indices.clone()), RenderTarget::Rust); +let param_name = param_node_name_at(param.clone(), source_indices.clone()); +let field_type = emit_cli_param_type_node(¶m_node_type_expr(¶m), source_indices.clone()); +let default_attr = match v2_rt::map_get(&resolved_defaults, param_name) { + Some(resolved) => v2_rt::concat(v2_rt::concat("#[arg(long, default_value = \"".to_string(), resolved.clone()), "\")]\n".to_string()), + None => match param_node_default_value(¶m) { + Some(dv) => match cli_default_literal_value(dv.clone()) { + Some(default_value) => v2_rt::concat(v2_rt::concat("#[arg(long, default_value = \"".to_string(), default_value.clone()), "\")]\n".to_string()), + None => "#[arg(long)]\n".to_string(), +}, + None => "#[arg(long)]\n".to_string(), +}, +}; +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(default_attr, field_name), ": ".to_string()), field_type), ",".to_string()) +} } -pub fn emit_cli_param_type_node( - n: &Rc, - source_indices: Rc>>, -) -> String { +pub fn emit_cli_param_type_node(n: &Rc, source_indices: Rc>>) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); - let has_structure = (n.connective.clone() != Connective::NoConnective); - if is_optional { - v2_rt::concat( - v2_rt::concat( - "Option<".to_string(), - emit_cli_param_type_node(&with_required_cardinality(&n), source_indices), - ), - ">".to_string(), - ) - } else { - if has_structure { - "String".to_string() + { + let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); +let has_structure = (n.connective.clone() != Connective::NoConnective); +if is_optional { + v2_rt::concat(v2_rt::concat("Option<".to_string(), emit_cli_param_type_node(&with_required_cardinality(&n), source_indices)), ">".to_string()) } else { - if ((n.children.clone().len() as i64) == 0) { - { - let nname = authored_name_at(source_indices, &n); - let mapped = coerce_primitive_type(RenderTarget::Rust, nname.clone()); - if (mapped.clone().as_str() != nname.clone().as_str()) { - mapped.clone() - } else { - "String".to_string() - } - } - } else { + if has_structure { "String".to_string() + } else { + if ((n.children.clone().len() as i64) == 0) { + { + let nname = authored_name_at(source_indices, &n); +let mapped = coerce_primitive_type(RenderTarget::Rust, nname.clone()); +if (mapped.clone().as_str() != nname.clone().as_str()) { + mapped.clone() + } else { + "String".to_string() + } +} + } else { + "String".to_string() + } } } - } +} }) } -pub fn emit_main_fn( - workflow_funcs: Rc>>, - has_services: &bool, - has_pipeline: &bool, - crate_name: &String, -) -> String { +pub fn emit_main_fn(workflow_funcs: Rc>>, has_services: &bool, has_pipeline: &bool, crate_name: &String) -> String { { let depth = 0; - let async_attr = if has_services.clone() { +let async_attr = if has_services.clone() { "#[tokio::main]\nasync fn main() ".to_string() } else { "fn main() ".to_string() }; - let parse_line = "let cli = Cli::parse();".to_string(); - let dry_run_line = if has_services.clone() { +let parse_line = "let cli = Cli::parse();".to_string(); +let dry_run_line = if has_services.clone() { "let dry_run = DryRunMode(cli.dry_run);".to_string() } else { "".to_string() }; - let match_arms = Rc::new({ - let mut __result = Vec::new(); - for wf in workflow_funcs.iter().cloned() { - __result.push(emit_main_match_arm(&wf, &has_services)); - } - __result - }); - let compile_arm = if has_pipeline.clone() { +let match_arms = Rc::new({ let mut __result = Vec::new(); for wf in workflow_funcs.iter().cloned() { __result.push(emit_main_match_arm(&wf, &has_services)); } __result }); +let compile_arm = if has_pipeline.clone() { emit_compile_match_arm(crate_name.clone()) } else { "".to_string() }; - let run_arm = if has_pipeline.clone() { +let run_arm = if has_pipeline.clone() { emit_run_match_arm(crate_name.clone()) } else { "".to_string() }; - let all_arms = if has_pipeline.clone() { +let all_arms = if has_pipeline.clone() { v2_rt::concat(match_arms, Rc::new(vec![compile_arm, run_arm])) } else { match_arms }; - let arms_str = all_arms.join(&"\n".to_string()); - let match_block = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "match cli.command {\n".to_string(), - make_indent((depth.clone() + 2)), - ), - arms_str, - ), - "\n }".to_string(), - ); - let result_handling = if has_services.clone() { +let arms_str = all_arms.join(&"\n".to_string()); +let match_block = v2_rt::concat(v2_rt::concat(v2_rt::concat("match cli.command {\n".to_string(), make_indent((depth.clone() + 2))), arms_str), "\n }".to_string()); +let result_handling = if has_services.clone() { match_block } else { - v2_rt::concat( - v2_rt::concat("let _result = ".to_string(), match_block), - ";".to_string(), - ) + v2_rt::concat(v2_rt::concat("let _result = ".to_string(), match_block), ";".to_string()) }; - let body_lines = if (dry_run_line.clone().as_str() == "".to_string().as_str()) { +let body_lines = if (dry_run_line.clone().as_str() == "".to_string().as_str()) { v2_rt::concat(v2_rt::concat(parse_line, "\n".to_string()), result_handling) } else { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(parse_line, "\n".to_string()), - dry_run_line.clone(), - ), - "\n".to_string(), - ), - result_handling, - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(parse_line, "\n".to_string()), dry_run_line.clone()), "\n".to_string()), result_handling) }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(async_attr, "{\n".to_string()), - make_indent((depth.clone() + 1)), - ), - body_lines, - ), - "\n}".to_string(), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(async_attr, "{\n".to_string()), make_indent((depth.clone() + 1))), body_lines), "\n}".to_string()) +} } pub fn emit_compile_match_arm(crate_name: String) -> String { { let pipeline_mod = module_to_filename("v2.compiler.compile".to_string()); - let artifact_mod = module_to_filename("v2.compiler.artifact".to_string()); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Commands::Compile { source_roots, source_dir, output_dir, target } => {\n".to_string(), " let render_target = match target.as_str() {\n".to_string()), " \"rust\" => ".to_string()), artifact_mod.clone()), "::RenderTarget::Rust,\n".to_string()), " \"python\" => ".to_string()), artifact_mod.clone()), "::RenderTarget::Python,\n".to_string()), " \"go\" => ".to_string()), artifact_mod.clone()), "::RenderTarget::Go,\n".to_string()), " \"dag\" => ".to_string()), artifact_mod.clone()), "::RenderTarget::Dag,\n".to_string()), " other => {\n".to_string()), " eprintln!(\"unknown target: {}. supported: rust, python, go, dag\", other);\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " };\n".to_string()), "\n".to_string()), " let sources = if !source_roots.is_empty() {\n".to_string()), " // FF-9: Import-driven resolution from source roots\n".to_string()), " let index = build_module_index(&source_roots);\n".to_string()), " eprintln!(\"indexed {} modules from {} source roots\", index.len(), source_roots.len());\n".to_string()), "\n".to_string()), " // Entry modules: all .dag files in the FIRST source root.\n".to_string()), " // Additional roots are dependency pools resolved via imports.\n".to_string()), " // This is intentional: --source-root src/v2 --source-root dsl\n".to_string()), " // means 'compile src/v2, using dsl as a dependency pool.'\n".to_string()), " let first_root = std::path::Path::new(&source_roots[0]);\n".to_string()), " let mut entry_files = Vec::new();\n".to_string()), " if first_root.is_dir() {\n".to_string()), " let mut dag_paths = Vec::new();\n".to_string()), " collect_dag_files(first_root, &mut dag_paths);\n".to_string()), " for path in dag_paths {\n".to_string()), " let content = std::fs::read_to_string(&path)\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to read {:?}: {}\", path, e));\n".to_string()), " entry_files.push((path.to_string_lossy().to_string(), content));\n".to_string()), " }\n".to_string()), " }\n".to_string()), "\n".to_string()), " let mut seen: HashMap> = HashMap::new();\n".to_string()), " let mut entry_for_queue = Vec::new();\n".to_string()), " for (path, content) in &entry_files {\n".to_string()), " if let Some(mod_path) = extract_module_path(content) {\n".to_string()), " let source = Rc::new(".to_string()), pipeline_mod.clone()), "::SourceFile {\n".to_string()), " path: path.clone(),\n".to_string()), " content: content.clone(),\n".to_string()), " });\n".to_string()), " seen.insert(mod_path, source);\n".to_string()), " }\n".to_string()), " entry_for_queue.push((path.clone(), content.clone()));\n".to_string()), " }\n".to_string()), "\n".to_string()), " let mut resolved = resolve_transitively_with_seen(entry_for_queue, &index, seen);\n".to_string()), " for (path, content) in entry_files {\n".to_string()), " let already_there = resolved.iter().any(|s| s.path == path);\n".to_string()), " if !already_there {\n".to_string()), " resolved.push(Rc::new(".to_string()), pipeline_mod.clone()), "::SourceFile { path, content }));\n".to_string()), " }\n".to_string()), " }\n".to_string()), " eprintln!(\"resolved {} sources (transitive import closure)\", resolved.len());\n".to_string()), " resolved\n".to_string()), "\n".to_string()), " } else if let Some(dir) = source_dir {\n".to_string()), " // Legacy: flat directory scan (backward compatibility)\n".to_string()), " let mut dag_paths = Vec::new();\n".to_string()), " collect_dag_files(std::path::Path::new(&dir), &mut dag_paths);\n".to_string()), " let mut sources = Vec::new();\n".to_string()), " for path in &dag_paths {\n".to_string()), " let content = std::fs::read_to_string(path)\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to read {:?}: {}\", path, e));\n".to_string()), " let filename = path.file_name().unwrap().to_string_lossy().to_string();\n".to_string()), " sources.push(Rc::new(".to_string()), pipeline_mod.clone()), "::SourceFile {\n".to_string()), " path: filename,\n".to_string()), " content,\n".to_string()), " }));\n".to_string()), " }\n".to_string()), " eprintln!(\"compiling {} .dag files from {} (target: {})\", sources.len(), dir, target);\n".to_string()), " sources\n".to_string()), "\n".to_string()), " } else {\n".to_string()), " eprintln!(\"error: provide --source-root or --source-dir\");\n".to_string()), " std::process::exit(1);\n".to_string()), " };\n".to_string()), "\n".to_string()), " let result = ".to_string()), pipeline_mod.clone()), "::compile_sources(Rc::new(sources), render_target);\n".to_string()), "\n".to_string()), " std::fs::create_dir_all(format!(\"{}/src\", output_dir))\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to create output dir: {}\", e));\n".to_string()), " for file in result.files.iter() {\n".to_string()), " let out_path = format!(\"{}/{}\", output_dir, file.path);\n".to_string()), " if let Some(parent) = std::path::Path::new(&out_path).parent() {\n".to_string()), " std::fs::create_dir_all(parent).ok();\n".to_string()), " }\n".to_string()), " std::fs::write(&out_path, &*file.content)\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to write {}: {}\", file.path, e));\n".to_string()), " }\n".to_string()), " eprintln!(\"compiled: {} files emitted, {} diagnostics\",\n".to_string()), " result.files.len(), result.diagnostics.len());\n".to_string()), " render_diagnostics(&result);\n".to_string()), " // Complexity violations are non-blocking (analyzer limitations).\n".to_string()), " let hard_errors = result.diagnostics.iter().any(|d| {\n".to_string()), " !matches!(*d.diagnostic.clone(), CompilerDiagnostic::ComplexityUnknown { .. })\n".to_string()), " });\n".to_string()), " if hard_errors {\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " if result.files.is_empty() {\n".to_string()), " eprintln!(\"error: no files emitted\");\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " },".to_string()) - } +let artifact_mod = module_to_filename("v2.compiler.artifact".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Commands::Compile { source_roots, source_dir, output_dir, target } => {\n".to_string(), " let render_target = match target.as_str() {\n".to_string()), " \"rust\" => ".to_string()), artifact_mod.clone()), "::RenderTarget::Rust,\n".to_string()), " \"python\" => ".to_string()), artifact_mod.clone()), "::RenderTarget::Python,\n".to_string()), " \"go\" => ".to_string()), artifact_mod.clone()), "::RenderTarget::Go,\n".to_string()), " \"dag\" => ".to_string()), artifact_mod.clone()), "::RenderTarget::Dag,\n".to_string()), " other => {\n".to_string()), " eprintln!(\"unknown target: {}. supported: rust, python, go, dag\", other);\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " };\n".to_string()), "\n".to_string()), " let sources = if !source_roots.is_empty() {\n".to_string()), " // FF-9: Import-driven resolution from source roots\n".to_string()), " let index = build_module_index(&source_roots);\n".to_string()), " eprintln!(\"indexed {} modules from {} source roots\", index.len(), source_roots.len());\n".to_string()), "\n".to_string()), " // Entry modules: all .dag files in the FIRST source root.\n".to_string()), " // Additional roots are dependency pools resolved via imports.\n".to_string()), " // This is intentional: --source-root src/v2 --source-root dsl\n".to_string()), " // means 'compile src/v2, using dsl as a dependency pool.'\n".to_string()), " let first_root = std::path::Path::new(&source_roots[0]);\n".to_string()), " let mut entry_files = Vec::new();\n".to_string()), " if first_root.is_dir() {\n".to_string()), " let mut dag_paths = Vec::new();\n".to_string()), " collect_dag_files(first_root, &mut dag_paths);\n".to_string()), " for path in dag_paths {\n".to_string()), " let content = std::fs::read_to_string(&path)\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to read {:?}: {}\", path, e));\n".to_string()), " entry_files.push((path.to_string_lossy().to_string(), content));\n".to_string()), " }\n".to_string()), " }\n".to_string()), "\n".to_string()), " let mut seen: HashMap> = HashMap::new();\n".to_string()), " let mut entry_for_queue = Vec::new();\n".to_string()), " for (path, content) in &entry_files {\n".to_string()), " if let Some(mod_path) = extract_module_path(content) {\n".to_string()), " let source = Rc::new(".to_string()), pipeline_mod.clone()), "::SourceFile {\n".to_string()), " path: path.clone(),\n".to_string()), " content: content.clone(),\n".to_string()), " });\n".to_string()), " seen.insert(mod_path, source);\n".to_string()), " }\n".to_string()), " entry_for_queue.push((path.clone(), content.clone()));\n".to_string()), " }\n".to_string()), "\n".to_string()), " let mut resolved = resolve_transitively_with_seen(entry_for_queue, &index, seen);\n".to_string()), " for (path, content) in entry_files {\n".to_string()), " let already_there = resolved.iter().any(|s| s.path == path);\n".to_string()), " if !already_there {\n".to_string()), " resolved.push(Rc::new(".to_string()), pipeline_mod.clone()), "::SourceFile { path, content }));\n".to_string()), " }\n".to_string()), " }\n".to_string()), " eprintln!(\"resolved {} sources (transitive import closure)\", resolved.len());\n".to_string()), " resolved\n".to_string()), "\n".to_string()), " } else if let Some(dir) = source_dir {\n".to_string()), " // Legacy: flat directory scan (backward compatibility)\n".to_string()), " let mut dag_paths = Vec::new();\n".to_string()), " collect_dag_files(std::path::Path::new(&dir), &mut dag_paths);\n".to_string()), " let mut sources = Vec::new();\n".to_string()), " for path in &dag_paths {\n".to_string()), " let content = std::fs::read_to_string(path)\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to read {:?}: {}\", path, e));\n".to_string()), " let filename = path.file_name().unwrap().to_string_lossy().to_string();\n".to_string()), " sources.push(Rc::new(".to_string()), pipeline_mod.clone()), "::SourceFile {\n".to_string()), " path: filename,\n".to_string()), " content,\n".to_string()), " }));\n".to_string()), " }\n".to_string()), " eprintln!(\"compiling {} .dag files from {} (target: {})\", sources.len(), dir, target);\n".to_string()), " sources\n".to_string()), "\n".to_string()), " } else {\n".to_string()), " eprintln!(\"error: provide --source-root or --source-dir\");\n".to_string()), " std::process::exit(1);\n".to_string()), " };\n".to_string()), "\n".to_string()), " let result = ".to_string()), pipeline_mod.clone()), "::compile_sources(Rc::new(sources), render_target);\n".to_string()), "\n".to_string()), " std::fs::create_dir_all(format!(\"{}/src\", output_dir))\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to create output dir: {}\", e));\n".to_string()), " for file in result.files.iter() {\n".to_string()), " let out_path = format!(\"{}/{}\", output_dir, file.path);\n".to_string()), " if let Some(parent) = std::path::Path::new(&out_path).parent() {\n".to_string()), " std::fs::create_dir_all(parent).ok();\n".to_string()), " }\n".to_string()), " std::fs::write(&out_path, &*file.content)\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to write {}: {}\", file.path, e));\n".to_string()), " }\n".to_string()), " eprintln!(\"compiled: {} files emitted, {} diagnostics\",\n".to_string()), " result.files.len(), result.diagnostics.len());\n".to_string()), " render_diagnostics(&result);\n".to_string()), " // Complexity violations are non-blocking (analyzer limitations).\n".to_string()), " let hard_errors = result.diagnostics.iter().any(|d| {\n".to_string()), " !matches!(*d.diagnostic.clone(), CompilerDiagnostic::ComplexityUnknown { .. })\n".to_string()), " });\n".to_string()), " if hard_errors {\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " if result.files.is_empty() {\n".to_string()), " eprintln!(\"error: no files emitted\");\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " },".to_string()) +} } pub fn emit_run_match_arm(crate_name: String) -> String { - v2_rt::concat( - v2_rt::concat( - "\n Commands::Run { source_roots, function } => {\n".to_string(), - " cli_run::handle_run(source_roots, function);\n".to_string(), - ), - " },".to_string(), - ) + v2_rt::concat(v2_rt::concat("\n Commands::Run { source_roots, function } => {\n".to_string(), " cli_run::handle_run(source_roots, function);\n".to_string()), " },".to_string()) } pub fn emit_main_pipeline_fns(crate_name: String) -> String { { let pipeline_mod = module_to_filename("v2.compiler.compile".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(emit_collect_dag_files_fn(), emit_extract_module_path_fn()), - emit_extract_import_paths_fn(), - ), - emit_build_module_index_fn(), - ), - emit_resolve_transitively_fn(&crate_name, &pipeline_mod), - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(emit_collect_dag_files_fn(), emit_extract_module_path_fn()), emit_extract_import_paths_fn()), emit_build_module_index_fn()), emit_resolve_transitively_fn(&crate_name, &pipeline_mod)) +} } pub fn emit_collect_dag_files_fn() -> String { @@ -15793,183 +6378,96 @@ pub fn emit_resolve_transitively_fn(crate_name: &String, pipeline_mod: &String) pub fn emit_main_diagnostic_fns(crate_name: String) -> String { { let core_mod = module_to_filename("v2.std.core".to_string()); - v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("\nfn render_diagnostics(result: &PipelineResult) {\n".to_string(), " if result.diagnostics.is_empty() {\n".to_string()), " return;\n".to_string()), " }\n".to_string()), "\n".to_string()), " let index_map: HashMap> = result\n".to_string()), " .newline_indices\n".to_string()), " .iter()\n".to_string()), " .map(|idx| (idx.file.clone(), idx.clone()))\n".to_string()), " .collect();\n".to_string()), "\n".to_string()), " for d in result.diagnostics.iter() {\n".to_string()), " render_one_diagnostic(d, &index_map, \"\");\n".to_string()), " }\n".to_string()), "\n".to_string()), " eprintln!(\"\\n{} error(s)\", result.diagnostics.len());\n".to_string()), "}\n".to_string()), "\n".to_string()), "fn render_one_diagnostic(\n".to_string()), " d: &".to_string()), crate_name), "::".to_string()), core_mod), "::ErrorNode,\n".to_string()), " index_map: &HashMap>,\n".to_string()), " indent: &str,\n".to_string()), ") {\n".to_string()), " let severity = \"error\";\n".to_string()), " let message = diagnostic_to_message(d.diagnostic.clone());\n".to_string()), " let span = diagnostic_to_span(d.diagnostic.clone());\n".to_string()), "\n".to_string()), " let location = if !span.file.is_empty() {\n".to_string()), " if let Some(idx) = index_map.get(&span.file) {\n".to_string()), " let lc = byte_to_line_col(idx, span.start);\n".to_string()), " format!(\"{}:{}:{}\", span.file, lc.line, lc.col)\n".to_string()), " } else {\n".to_string()), " span.file.clone()\n".to_string()), " }\n".to_string()), " } else if !d.module_name.is_empty() {\n".to_string()), " d.module_name.clone()\n".to_string()), " } else {\n".to_string()), " String::new()\n".to_string()), " };\n".to_string()), "\n".to_string()), " if location.is_empty() {\n".to_string()), " eprintln!(\"{}{}: {}\", indent, severity, message);\n".to_string()), " } else {\n".to_string()), " eprintln!(\"{}{}[{}]: {}\", indent, severity, location, message);\n".to_string()), " }\n".to_string()), "\n".to_string()), " if !span.file.is_empty() {\n".to_string()), " if let Some(idx) = index_map.get(&span.file) {\n".to_string()), " let lc = byte_to_line_col(idx, span.start);\n".to_string()), " let line_text = source_line_at(idx, lc.line);\n".to_string()), " let line_num = format!(\"{}\", lc.line);\n".to_string()), " let gutter_width = line_num.len();\n".to_string()), " eprintln!(\"{} {} |\", indent, \" \".repeat(gutter_width));\n".to_string()), " eprintln!(\"{} {} | {}\", indent, line_num, line_text);\n".to_string()), "\n".to_string()), " let span_len = std::cmp::max(1, (span.end - span.start) as usize);\n".to_string()), " let col_offset = (lc.col - 1) as usize;\n".to_string()), " eprintln!(\n".to_string()), " \"{} {} | {}{}\",\n".to_string()), " indent,\n".to_string()), " \" \".repeat(gutter_width),\n".to_string()), " \" \".repeat(col_offset),\n".to_string()), " \"^\".repeat(std::cmp::min(span_len, line_text.len().saturating_sub(col_offset)))\n".to_string()), " );\n".to_string()), " }\n".to_string()), " }\n".to_string()), "}\n".to_string()) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("\nfn render_diagnostics(result: &PipelineResult) {\n".to_string(), " if result.diagnostics.is_empty() {\n".to_string()), " return;\n".to_string()), " }\n".to_string()), "\n".to_string()), " let index_map: HashMap> = result\n".to_string()), " .newline_indices\n".to_string()), " .iter()\n".to_string()), " .map(|idx| (idx.file.clone(), idx.clone()))\n".to_string()), " .collect();\n".to_string()), "\n".to_string()), " for d in result.diagnostics.iter() {\n".to_string()), " render_one_diagnostic(d, &index_map, \"\");\n".to_string()), " }\n".to_string()), "\n".to_string()), " eprintln!(\"\\n{} error(s)\", result.diagnostics.len());\n".to_string()), "}\n".to_string()), "\n".to_string()), "fn render_one_diagnostic(\n".to_string()), " d: &".to_string()), crate_name), "::".to_string()), core_mod), "::ErrorNode,\n".to_string()), " index_map: &HashMap>,\n".to_string()), " indent: &str,\n".to_string()), ") {\n".to_string()), " let severity = \"error\";\n".to_string()), " let message = diagnostic_to_message(d.diagnostic.clone());\n".to_string()), " let span = diagnostic_to_span(d.diagnostic.clone());\n".to_string()), "\n".to_string()), " let location = if !span.file.is_empty() {\n".to_string()), " if let Some(idx) = index_map.get(&span.file) {\n".to_string()), " let lc = byte_to_line_col(idx, span.start);\n".to_string()), " format!(\"{}:{}:{}\", span.file, lc.line, lc.col)\n".to_string()), " } else {\n".to_string()), " span.file.clone()\n".to_string()), " }\n".to_string()), " } else if !d.module_name.is_empty() {\n".to_string()), " d.module_name.clone()\n".to_string()), " } else {\n".to_string()), " String::new()\n".to_string()), " };\n".to_string()), "\n".to_string()), " if location.is_empty() {\n".to_string()), " eprintln!(\"{}{}: {}\", indent, severity, message);\n".to_string()), " } else {\n".to_string()), " eprintln!(\"{}{}[{}]: {}\", indent, severity, location, message);\n".to_string()), " }\n".to_string()), "\n".to_string()), " if !span.file.is_empty() {\n".to_string()), " if let Some(idx) = index_map.get(&span.file) {\n".to_string()), " let lc = byte_to_line_col(idx, span.start);\n".to_string()), " let line_text = source_line_at(idx, lc.line);\n".to_string()), " let line_num = format!(\"{}\", lc.line);\n".to_string()), " let gutter_width = line_num.len();\n".to_string()), " eprintln!(\"{} {} |\", indent, \" \".repeat(gutter_width));\n".to_string()), " eprintln!(\"{} {} | {}\", indent, line_num, line_text);\n".to_string()), "\n".to_string()), " let span_len = std::cmp::max(1, (span.end - span.start) as usize);\n".to_string()), " let col_offset = (lc.col - 1) as usize;\n".to_string()), " eprintln!(\n".to_string()), " \"{} {} | {}{}\",\n".to_string()), " indent,\n".to_string()), " \" \".repeat(gutter_width),\n".to_string()), " \" \".repeat(col_offset),\n".to_string()), " \"^\".repeat(std::cmp::min(span_len, line_text.len().saturating_sub(col_offset)))\n".to_string()), " );\n".to_string()), " }\n".to_string()), " }\n".to_string()), "}\n".to_string()) +} } pub fn emit_main_match_arm(wf: &Rc, has_services: &bool) -> String { { let variant_name = to_pascal(wf.name.clone()); - let mod_name = module_to_filename(wf.module_name.clone()); - let fn_name = emit_ident(wf.name.clone(), RenderTarget::Rust); - let await_suffix = if has_services.clone() { +let mod_name = module_to_filename(wf.module_name.clone()); +let fn_name = emit_ident(wf.name.clone(), RenderTarget::Rust); +let await_suffix = if has_services.clone() { ".await".to_string() } else { "".to_string() }; - let call_expr = if ((wf.params.clone().len() as i64) == 0) { +let call_expr = if ((wf.params.clone().len() as i64) == 0) { { let service_args = emit_main_service_args(wf.clone(), has_services.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(mod_name, "::".to_string()), fn_name), - "(".to_string(), - ), - service_args, - ), - ")".to_string(), - ), - await_suffix, - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(mod_name, "::".to_string()), fn_name), "(".to_string()), service_args), ")".to_string()), await_suffix) +} } else { { let call_args = emit_main_call_args(&wf, has_services.clone()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(mod_name, "::".to_string()), fn_name), - "(".to_string(), - ), - call_args, - ), - ")".to_string(), - ), - await_suffix, - ) - } +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(mod_name, "::".to_string()), fn_name), "(".to_string()), call_args), ")".to_string()), await_suffix) +} }; - let pattern = if ((wf.params.clone().len() as i64) == 0) { +let pattern = if ((wf.params.clone().len() as i64) == 0) { v2_rt::concat("Commands::".to_string(), variant_name) } else { { - let field_binds = Rc::new({ - let mut __result = Vec::new(); - for p in wf.params.clone().iter().cloned() { - __result.push(emit_ident( - param_node_name_at(p.clone(), wf.source_indices.clone()), - RenderTarget::Rust, - )); - } - __result - }); - let binds_str = field_binds.join(&", ".to_string()); - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("Commands::".to_string(), variant_name), - " { ".to_string(), - ), - binds_str, - ), - " }".to_string(), - ) - } + let field_binds = Rc::new({ let mut __result = Vec::new(); for p in wf.params.clone().iter().cloned() { __result.push(emit_ident(param_node_name_at(p.clone(), wf.source_indices.clone()), RenderTarget::Rust)); } __result }); +let binds_str = field_binds.join(&", ".to_string()); +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Commands::".to_string(), variant_name), " { ".to_string()), binds_str), " }".to_string()) +} }; - if has_services.clone() { +if has_services.clone() { v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(pattern, " => {\n".to_string()), " match ".to_string()), call_expr), " {\n".to_string()), " Ok(value) => {\n".to_string()), " let json = serde_json::to_string_pretty(&value).unwrap_or_else(|_| format!(\"{:?}\", value));\n".to_string()), " println!(\"{}\", json);\n".to_string()), " }\n".to_string()), " Err(e) => {\n".to_string()), " eprintln!(\"Error: {}\", e);\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }".to_string()) } else { - v2_rt::concat( - v2_rt::concat(v2_rt::concat(pattern, " => ".to_string()), call_expr), - ",".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(pattern, " => ".to_string()), call_expr), ",".to_string()) } - } +} } pub fn emit_main_call_args(wf: &Rc, has_services: bool) -> String { { - let param_args = Rc::new({ - let mut __result = Vec::new(); - for p in wf.params.clone().iter().cloned() { - __result.push({ - let pname = param_node_name_at(p.clone(), wf.source_indices.clone()); - let ident = emit_ident(pname.clone(), RenderTarget::Rust); - let n = param_node_type_expr(&p); - let is_borrowable = - ((v2_rt::map_contains_key(&wf.read_only_params.clone(), pname.clone()) - && ((n.params.clone().len() as i64) == 0)) - && needs_reference_node(&n, wf.source_indices.clone())); - if is_borrowable.clone() { - v2_rt::concat("&".to_string(), ident.clone()) - } else { - ident.clone() - } - }); + let param_args = Rc::new({ let mut __result = Vec::new(); for p in wf.params.clone().iter().cloned() { __result.push({ + let pname = param_node_name_at(p.clone(), wf.source_indices.clone()); +let ident = emit_ident(pname.clone(), RenderTarget::Rust); +let n = param_node_type_expr(&p); +let is_borrowable = ((v2_rt::map_contains_key(&wf.read_only_params.clone(), pname.clone()) && ((n.params.clone().len() as i64) == 0)) && needs_reference_node(&n, wf.source_indices.clone())); +if is_borrowable.clone() { + v2_rt::concat("&".to_string(), ident.clone()) + } else { + ident.clone() } - __result - }); - let service_args = emit_main_service_arg_list(&wf, has_services); - let all_args = v2_rt::concat(param_args, service_args); - all_args.join(&", ".to_string()) - } +}); } __result }); +let service_args = emit_main_service_arg_list(&wf, has_services); +let all_args = v2_rt::concat(param_args, service_args); +all_args.join(&", ".to_string()) +} } pub fn emit_main_service_args(wf: Rc, has_services: bool) -> String { { let service_args = emit_main_service_arg_list(&wf, has_services); - service_args.join(&", ".to_string()) - } +service_args.join(&", ".to_string()) +} } pub fn emit_main_service_arg_list(wf: &Rc, has_services: bool) -> Rc> { { let sharing = language_spec(RenderTarget::Rust).sharing.clone(); - let resource_args = Rc::new({ - let mut __result = Vec::new(); - for u in wf.uses.clone().iter().cloned() { - __result.push(v2_rt::concat( - "&".to_string(), - authored_name_at(wf.source_indices.clone(), &resource_use_resource(&u)), - )); - } - __result - }); - let svc_args = Rc::new({ - let mut __result = Vec::new(); - for sn in wf.service_names.clone().iter().cloned() { - __result.push({ - let struct_name = sanitize_service_name(sn.clone()); - if has_services.clone() { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("&".to_string(), struct_name.clone()), - "::new(".to_string(), - ), - apply_type_template1( - sharing.clone_value.clone(), - "dry_run".to_string(), - ), - ), - ")".to_string(), - ) - } else { - v2_rt::concat( - v2_rt::concat("&".to_string(), struct_name.clone()), - "::new()".to_string(), - ) - } - }); +let resource_args = Rc::new({ let mut __result = Vec::new(); for u in wf.uses.clone().iter().cloned() { __result.push(v2_rt::concat("&".to_string(), authored_name_at(wf.source_indices.clone(), &resource_use_resource(&u)))); } __result }); +let svc_args = Rc::new({ let mut __result = Vec::new(); for sn in wf.service_names.clone().iter().cloned() { __result.push({ + let struct_name = sanitize_service_name(sn.clone()); +if has_services.clone() { + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("&".to_string(), struct_name.clone()), "::new(".to_string()), apply_type_template1(sharing.clone_value.clone(), "dry_run".to_string())), ")".to_string()) + } else { + v2_rt::concat(v2_rt::concat("&".to_string(), struct_name.clone()), "::new()".to_string()) } - __result - }); - v2_rt::concat(resource_args, svc_args) - } +}); } __result }); +v2_rt::concat(resource_args, svc_args) +} } pub fn emit_dry_run_module() -> Rc { { let content = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("// Generated by v2 compiler -- do not edit.\n".to_string(), "//\n".to_string()), "// Dry-run support: when DryRunMode(true), service methods return\n".to_string()), "// mock data instead of performing real I/O.\n\n".to_string()), "#[derive(Debug, Clone)]\n".to_string()), "pub struct DryRunMode(pub bool);\n\n".to_string()), "impl DryRunMode {\n".to_string()), " pub fn is_dry_run(&self) -> bool {\n".to_string()), " self.0\n".to_string()), " }\n".to_string()), "}\n\n".to_string()), "impl Default for DryRunMode {\n".to_string()), " fn default() -> Self {\n".to_string()), " DryRunMode(false)\n".to_string()), " }\n".to_string()), "}\n".to_string()); - Rc::new(TextFile { - path: v2_rt::concat( - v2_rt::concat(rust_source_root(), "dry_run".to_string()), - rust_source_ext(), - ), - content: content, - }) - } +Rc::new(TextFile { + path: v2_rt::concat(v2_rt::concat(rust_source_root(), "dry_run".to_string()), rust_source_ext()), + content: content, +}) +} } diff --git a/src/v2/stage0/src/v2_compiler_infer.rs b/src/v2/stage0/src/v2_compiler_infer.rs index 8a2797bae99..e0c46e6d257 100644 --- a/src/v2/stage0/src/v2_compiler_infer.rs +++ b/src/v2/stage0/src/v2_compiler_infer.rs @@ -1,143 +1,56 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer -use self::SizeExpr::*; -pub use crate::std_algebra::CollectionSizeEffect; -use crate::std_algebra::CollectionSizeEffect::ShrinkEffect; -pub use crate::std_coercion::{dag_can_cast, is_dag_cast_domain_type}; -use crate::std_induction::RecursionShape::{ - DirectRecursion, ListRecursion, MapValueRecursion, OptionalRecursion, SetRecursion, -}; -use crate::std_induction::ShrinkFactor::{ConstantShrink, ProportionalShrink, UnitShrink}; -use crate::std_induction::SubValueRelation::{ - ArithmeticDescent, IteratedSubValue, PreservedValue, StrictSubValue, SubValueUnknown, -}; -pub use crate::std_induction::{ - compose_sub_value, compose_sub_value_relations, join_sub_value, meet_sub_value, - sub_value_to_evidence, InductiveField, RecursionShape, ShrinkFactor, SubValueRelation, -}; -pub use crate::std_node::{compiler_inductive_fields, compiler_recursive_types}; -use crate::std_termination::PositiveDescentAmount::OneStep; -pub use crate::std_termination::{ - positive_descent_amount_from_positive_int, proportional_divisor_from_int_at_least_two, - PositiveDescentAmount, -}; -pub use crate::std_types::{container_param_name, SourceSpan}; -pub use crate::v2_compiler_infer_access::{ - check_index_access_node, check_slice_access_node, AccessCheckResultNode, -}; -pub use crate::v2_compiler_infer_cycle::detect_type_cycles_kahn; -use crate::v2_compiler_infer_emit_info::TypeRepr::{EnumRepr, StructRepr}; -pub use crate::v2_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, EmitGraphInfo, - EmitInfoBuildState, TypeRepr, TypeSummary, -}; -pub use crate::v2_compiler_infer_env::{ - inductive_fields_for, inductive_fields_list_to_map, is_recursive_type, - is_recursive_type_by_name, lookup_type, lookup_type_by_name, lookup_type_for, merge_envs, - merge_inductive_fields, put_inductive_field, put_inductive_field_cross, TypeBinding, TypeEnv, -}; -use crate::v2_compiler_infer_items::ItemKind::{ - DataItem, FnItem, FuncItem, OtherItem, ServiceItem, TypeItem, -}; -pub use crate::v2_compiler_infer_items::{ - inferred_to_outputs, item_kind, variant_locals_from_items, ItemInfo, ItemKind, ResolvedGraph, - TypedGraph, TypedModule, -}; -pub use crate::v2_compiler_infer_lookup::{ - field_summary_for_type, lookup_coproduct_common_field_node, lookup_field_type_node, - lookup_func_sig, lookup_in_scope, map_key_type_in_env, map_value_type_in_env, - resolve_known_method_node, resolve_scrutinee_type_node, KnownMethodResolution, -}; -pub use crate::v2_compiler_infer_method::{ - builtin_kernel_seed_diagnostics, infer_builtin_call_type, resolve_builtin_call_type, -}; -use crate::v2_compiler_infer_patterns::PatternSubject::*; -pub use crate::v2_compiler_infer_patterns::{ - check_match_exhaustiveness, lookup_field_in_variant, lookup_result_subject, - lookup_variant_in_type, pattern_binding_type, pattern_subject_from_inferred, - pattern_subject_from_node, NodeLookupResult, PatternSubject, -}; -pub use crate::v2_compiler_infer_resolve::{ - resolve_item_types, resolve_node, ItemResult, NodeResolveResult, -}; -pub use crate::v2_compiler_infer_service::{ - check_service_field_access_node, check_service_method_call_node, collect_called_func_names, - collect_typed_service_calls, expand_transitive_services, extract_typed_service_name, - is_typed_service_call_receiver, service_op_entry, OpEntry, ServiceMethodResult, UniqueAccum, -}; -pub use crate::v2_compiler_infer_sigs::{ - resolve_func_sigs, ResolveFuncSigsResult, ResolvedFuncEnv, ResolvedFuncSig, -}; -pub use crate::v2_compiler_infer_types::{ - bare_map_node, callable_inferred, child_type_node, emit_map_has, extract_optional_inner_node, - for_each_element_type_node, infer_binop_type_node, infer_literal_node, is_fully_resolved, - make_callable_type, make_container_type, method_receiver_element_node, node_is_collection, - node_is_element_collection, node_is_keyed_collection, node_type_compatible, node_type_deps, - node_type_equals, node_type_shape, nominal_type_ref, normalize_access_type_node, - prefer_specific_type, resolve_type_variables_from_template, resolved_type, - template_return_has_variables, template_return_is_receiver_self, KernelTypeBuild, -}; -pub use crate::v2_compiler_resolve::{ModuleGraph, ResolvedImport, ResolvedModule}; +use std::collections::HashMap; +use std::rc::Rc; use crate::v2_rt; -use crate::v2_std_core::BinOp::{ - Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, NullCoalesce, Or, Sub, -}; -use crate::v2_std_core::CallSemantics::{LookupCallSemantics, PlainCallSemantics}; -use crate::v2_std_core::Cardinality::{CardOptional, Required}; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan, container_param_name}; +pub use crate::std_coercion::{dag_can_cast, is_dag_cast_domain_type}; +pub use crate::v2_std_core::{Node, InternTable, intern, intern_str, authored_name_at, NewlineIndex, has_child_named, build_newline_index, module_node, module_imports, module_items, import_is_all, make_param_node, param_node_name_at, param_node_type_expr, field_node_type_expr, Connective, ExprData, make_expr_node, make_named_expr_node, make_expr_error_node, expr_var_name_at, field_access_base, field_access_field_at, expr_call_func_at, expr_method_name_at, let_binding_name_at, foreach_variable_at, lambda_param_names_at, record_lit_type_name_at, make_arg_node, make_arm_node, arm_pattern, arm_guard, arm_body, make_field_init_node, field_init_node_name_at, field_init_node_value, make_text_part_node, make_interp_part_node, map_children, arg_value, arg_name_at, has_inferred, is_compiler_error, InferredNode, Cardinality, ErrorNode, make_error_node, is_error_diagnostic, resource_use_name_at, resource_use_resource, kernel_type_set, is_kernel_type, is_child_accessor_in_model, is_tree_size_reducing, is_property_contraction, expr_has_self_call, expr_has_non_tail_self_call, DeclaredFuncSig, DeclaredFuncEnv, LiteralValue, FieldAccessStyle, FieldValueShape, FieldSummary, VarBindingKind, CallSemantics, MethodSemantics, ExprErrorKind, BinOp, UnaryOpKind, unaryop_operand, MatchPattern, StringPart, make_field_binding_node, field_binding_name_at, field_binding_pattern, let_value, let_body, lambda_body, foreach_collection, foreach_body, method_receiver, method_arg_nodes, match_scrutinee, match_arm_nodes, if_condition, if_then_branch, if_else_branch, index_base, index_expr, slice_base, slice_start, slice_end, cast_target, cast_expr, return_value, binop_left, binop_right, make_transport_node, local_transport_node, with_optional_cardinality, with_required_cardinality, no_span, make_span, unit_type, bool_type, string_type, int_type, float_type, none_type, error_type, is_container_type, container_expected_arity, default_ident_span, node_name_span, CompilerDiagnostic}; +use crate::v2_std_core::Connective::{Conj, Disj, NoConnective, Arrow}; +use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprError, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit, ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp, ExprBlock, ExprCast, ExprForEach, ExprIndex, ExprSlice, ExprReturn}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::Cardinality::{Required, CardOptional}; use crate::v2_std_core::CompilerDiagnostic::{InternalError, TypeMismatch, VariantCollision}; -use crate::v2_std_core::Connective::{Arrow, Conj, Disj, NoConnective}; -use crate::v2_std_core::ExprData::{ - ExprBinOp, ExprBlock, ExprCall, ExprCast, ExprError, ExprFieldAccess, ExprForEach, ExprIf, - ExprIndex, ExprLambda, ExprLet, ExprListLit, ExprLiteral, ExprMatch, ExprMethodCall, - ExprRecordLit, ExprReturn, ExprSlice, ExprStringInterp, ExprUnaryOp, ExprVar, NoExprData, -}; -use crate::v2_std_core::ExprErrorKind::{InternalExprError, ParseRecoveryError, SemanticExprError}; -use crate::v2_std_core::FieldAccessStyle::{ - EnumAccessor, OptionalUnwrap, StoredField, TupleFirst, TupleSecond, -}; -use crate::v2_std_core::FieldValueShape::{OptionalValue, PlainValue}; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; -use crate::v2_std_core::LiteralValue::{LitBool, LitFloat, LitInt, LitNull, LitStr}; +use crate::v2_std_core::LiteralValue::{LitStr, LitInt, LitFloat, LitBool, LitNull}; +use crate::v2_std_core::FieldAccessStyle::{StoredField, EnumAccessor, OptionalUnwrap, TupleFirst, TupleSecond}; +use crate::v2_std_core::FieldValueShape::{PlainValue, OptionalValue}; +use crate::v2_std_core::VarBindingKind::{LocalValueBinding, FunctionValueBinding, VariantValueBinding, MatchBoundBinding}; +use crate::v2_std_core::CallSemantics::{PlainCallSemantics, LookupCallSemantics}; +use crate::v2_std_core::MethodSemantics::{PlainMethodSemantics, AlgebraMethodSemantics, ServiceMethodSemantics}; +use crate::v2_std_core::ExprErrorKind::{ParseRecoveryError, SemanticExprError, InternalExprError}; +use crate::v2_std_core::BinOp::{Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Gt, Le, Ge, And, Or, NullCoalesce}; +use crate::v2_std_core::UnaryOpKind::{Not, Neg}; use crate::v2_std_core::MatchPattern::{Bind, VariantPattern, Wildcard}; -use crate::v2_std_core::MethodSemantics::{ - AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics, -}; -use crate::v2_std_core::StringPart::{Interpolation, Text}; -use crate::v2_std_core::UnaryOpKind::{Neg, Not}; -use crate::v2_std_core::VarBindingKind::{ - FunctionValueBinding, LocalValueBinding, MatchBoundBinding, VariantValueBinding, -}; -pub use crate::v2_std_core::{ - arg_name_at, arg_value, arm_body, arm_guard, arm_pattern, authored_name_at, binop_left, - binop_right, bool_type, build_newline_index, cast_expr, cast_target, container_expected_arity, - default_ident_span, error_type, 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_type_expr, float_type, foreach_body, foreach_collection, - foreach_variable_at, has_child_named, has_inferred, if_condition, if_else_branch, - if_then_branch, import_is_all, index_base, index_expr, int_type, intern, intern_str, - is_child_accessor_in_model, is_compiler_error, is_container_type, is_error_diagnostic, - is_kernel_type, is_property_contraction, is_tree_size_reducing, kernel_type_set, lambda_body, - lambda_param_names_at, let_binding_name_at, let_body, let_value, local_transport_node, - make_arg_node, make_arm_node, make_error_node, make_expr_error_node, make_expr_node, - make_field_binding_node, make_field_init_node, make_interp_part_node, make_named_expr_node, - make_param_node, make_span, make_text_part_node, make_transport_node, map_children, - match_arm_nodes, match_scrutinee, method_arg_nodes, method_receiver, module_imports, - module_items, module_node, no_span, node_name_span, none_type, param_node_name_at, - param_node_type_expr, record_lit_type_name_at, resource_use_name_at, resource_use_resource, - return_value, slice_base, slice_end, slice_start, string_type, unaryop_operand, unit_type, - with_optional_cardinality, with_required_cardinality, BinOp, CallSemantics, Cardinality, - CompilerDiagnostic, Connective, DeclaredFuncEnv, DeclaredFuncSig, ErrorNode, ExprData, - ExprErrorKind, FieldAccessStyle, FieldSummary, FieldValueShape, InferredNode, InternTable, - LiteralValue, MatchPattern, MethodSemantics, NewlineIndex, Node, StringPart, UnaryOpKind, - VarBindingKind, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +use crate::v2_std_core::StringPart::{Text, Interpolation}; +pub use crate::v2_compiler_resolve::{ModuleGraph, ResolvedModule, ResolvedImport}; +pub use crate::v2_compiler_infer_types::{nominal_type_ref, make_container_type, make_callable_type, KernelTypeBuild, node_is_keyed_collection, node_is_element_collection, node_is_collection, is_fully_resolved, resolve_type_variables_from_template, template_return_has_variables, template_return_is_receiver_self, bare_map_node, callable_inferred, normalize_access_type_node, node_type_shape, node_type_compatible, node_type_equals, prefer_specific_type, node_type_deps, method_receiver_element_node, infer_literal_node, infer_binop_type_node, extract_optional_inner_node, for_each_element_type_node, resolved_type, child_type_node, emit_map_has}; +pub use crate::v2_compiler_infer_method::{builtin_kernel_seed_diagnostics, infer_builtin_call_type, resolve_builtin_call_type}; +pub use crate::v2_compiler_infer_cycle::{detect_type_cycles_kahn}; +pub use crate::v2_compiler_infer_env::{TypeEnv, TypeBinding, is_recursive_type, is_recursive_type_by_name, lookup_type, lookup_type_by_name, lookup_type_for, merge_envs, put_inductive_field, put_inductive_field_cross, merge_inductive_fields, inductive_fields_for, inductive_fields_list_to_map}; +pub use crate::std_node::{compiler_inductive_fields, compiler_recursive_types}; +pub use crate::std_induction::{InductiveField, RecursionShape, SubValueRelation, ShrinkFactor, sub_value_to_evidence, meet_sub_value, join_sub_value, compose_sub_value, compose_sub_value_relations}; +use crate::std_induction::RecursionShape::{DirectRecursion, ListRecursion, OptionalRecursion, SetRecursion, MapValueRecursion}; +use crate::std_induction::SubValueRelation::{StrictSubValue, IteratedSubValue, ArithmeticDescent, PreservedValue, SubValueUnknown}; +use crate::std_induction::ShrinkFactor::{UnitShrink, ConstantShrink, ProportionalShrink}; +pub use crate::std_termination::{positive_descent_amount_from_positive_int, proportional_divisor_from_int_at_least_two, PositiveDescentAmount}; +use crate::std_termination::PositiveDescentAmount::{OneStep}; +pub use crate::std_algebra::{CollectionSizeEffect}; +use crate::std_algebra::CollectionSizeEffect::{ShrinkEffect}; +pub use crate::v2_compiler_infer_resolve::{resolve_node, resolve_item_types, NodeResolveResult, ItemResult}; +pub use crate::v2_compiler_infer_sigs::{ResolvedFuncSig, ResolvedFuncEnv, ResolveFuncSigsResult, resolve_func_sigs}; +pub use crate::v2_compiler_infer_emit_info::{TypeRepr, TypeSummary, EmitGraphInfo, EmitInfoBuildState, empty_emit_graph_info, lookup_emit_type_summary, build_struct_field_summaries, build_enum_field_summaries, add_emit_item_summary, derive_variant_to_enum}; +use crate::v2_compiler_infer_emit_info::TypeRepr::{StructRepr, EnumRepr}; +pub use crate::v2_compiler_infer_items::{ItemKind, ItemInfo, TypedModule, TypedGraph, ResolvedGraph, inferred_to_outputs, item_kind, variant_locals_from_items}; +use crate::v2_compiler_infer_items::ItemKind::{FnItem, FuncItem, TypeItem, DataItem, ServiceItem, OtherItem}; +pub use crate::v2_compiler_infer_service::{UniqueAccum, OpEntry, ServiceMethodResult, is_typed_service_call_receiver, extract_typed_service_name, collect_typed_service_calls, collect_called_func_names, expand_transitive_services, check_service_field_access_node, check_service_method_call_node, service_op_entry}; +pub use crate::v2_compiler_infer_patterns::{NodeLookupResult, PatternSubject, lookup_variant_in_type, lookup_field_in_variant, pattern_subject_from_inferred, pattern_subject_from_node, lookup_result_subject, pattern_binding_type, check_match_exhaustiveness}; +use crate::v2_compiler_infer_patterns::PatternSubject::*; +pub use crate::v2_compiler_infer_lookup::{KnownMethodResolution, resolve_known_method_node, resolve_scrutinee_type_node, field_summary_for_type, lookup_field_type_node, lookup_coproduct_common_field_node, map_value_type_in_env, map_key_type_in_env, lookup_in_scope, lookup_func_sig}; +pub use crate::v2_compiler_infer_access::{AccessCheckResultNode, check_index_access_node, check_slice_access_node}; +use self::SizeExpr::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct ItemContribution { @@ -191,57 +104,43 @@ pub struct BlockInferState { pub typed_stmts: Rc>>, } -pub fn infer_block_stmts( - mut remaining: Rc>>, - mut remaining_count: i64, - mut scope: Rc, - mut typed_stmts: Rc>>, - mut diag_chunks: Rc>>>>, - mut last_type: Rc, - mut expected: Option>, -) -> Rc { +pub fn infer_block_stmts(mut remaining: Rc>>, mut remaining_count: i64, mut scope: Rc, mut typed_stmts: Rc>>, mut diag_chunks: Rc>>>>, mut last_type: Rc, mut expected: Option>) -> Rc { loop { match remaining.clone().first().cloned() { - None => { - break Rc::new(BlockInferState { - scope: scope.clone(), - diag_chunks: diag_chunks, - last_type: last_type, - typed_stmts: typed_stmts, - }); - } - Some(stmt) => { - let is_last = (remaining_count.clone() == 1); - let stmt_expected = if is_last { expected.clone() } else { None }; - let stmt_result = infer_expr(&stmt, &scope, &stmt_expected); - let stmt_typed = stmt_result.typed.clone(); - let stmt_diags = stmt_result.diagnostics.clone(); - let stmt_rt = resolved_type(stmt_typed.clone()); - let next_scope = scope_after_stmt_node(&stmt, stmt_rt.clone(), &scope); - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = (remaining_count - 1); - let __tco_2 = next_scope; - let __tco_3 = v2_rt::rc_list_push(typed_stmts, stmt_typed.clone()); - let __tco_4 = v2_rt::rc_list_push(diag_chunks, stmt_diags); - let __tco_5 = stmt_rt.clone(); - remaining = __tco_0; - remaining_count = __tco_1; - scope = __tco_2; - typed_stmts = __tco_3; - diag_chunks = __tco_4; - last_type = __tco_5; - continue; - } - } - } - } + None => { break Rc::new(BlockInferState { + scope: scope.clone(), + diag_chunks: diag_chunks, + last_type: last_type, + typed_stmts: typed_stmts, +}); }, + Some(stmt) => { let is_last = (remaining_count.clone() == 1); +let stmt_expected = if is_last { + expected.clone() + } else { + None + }; +let stmt_result = infer_expr(&stmt, &scope, &stmt_expected); +let stmt_typed = stmt_result.typed.clone(); +let stmt_diags = stmt_result.diagnostics.clone(); +let stmt_rt = resolved_type(stmt_typed.clone()); +let next_scope = scope_after_stmt_node(&stmt, stmt_rt.clone(), &scope); +{ + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = (remaining_count - 1); +let __tco_2 = next_scope; +let __tco_3 = v2_rt::rc_list_push(typed_stmts, stmt_typed.clone()); +let __tco_4 = v2_rt::rc_list_push(diag_chunks, stmt_diags); +let __tco_5 = stmt_rt.clone(); +remaining = __tco_0; +remaining_count = __tco_1; +scope = __tco_2; +typed_stmts = __tco_3; +diag_chunks = __tco_4; +last_type = __tco_5; +continue; +} }, +} +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -323,163 +222,81 @@ pub struct LocalContributionState { pub diag_chunks: Rc>>>>, } -pub fn merge_scope_from_imports( - mut remaining: Rc>>, - mut parent_index: Rc>>, - mut env: Rc, - mut func_sigs: Rc>>, - mut svc_registry: Rc>>>>, - mut svc_locals: Rc>>, -) -> Rc { +pub fn merge_scope_from_imports(mut remaining: Rc>>, mut parent_index: Rc>>, mut env: Rc, mut func_sigs: Rc>>, mut svc_registry: Rc>>>>, mut svc_locals: Rc>>) -> Rc { loop { match remaining.clone().first().cloned() { - None => { - break Rc::new(InferScopeComponents { - func_sigs: func_sigs, - svc_registry: svc_registry, - svc_locals: svc_locals, - }); + None => { break Rc::new(InferScopeComponents { + func_sigs: func_sigs, + svc_registry: svc_registry, + svc_locals: svc_locals, +}); }, + Some(imp) => { match v2_rt::map_get(&parent_index, imp.module_path.clone()) { + Some(typed_parent) => { let next_func_sigs = Rc::new(v2_rt::map_values(&typed_parent.func_env.clone().signatures.clone())).iter().cloned().fold(func_sigs, |acc: Rc>>, rsig: Rc| { + let sig_key = rsig.name.clone(); +let sig_params = rsig.params.clone(); +let sig_rt = rsig.inferred.clone(); +let sig_async = rsig.is_async.clone(); +v2_rt::rc_map_insert(acc, sig_key.clone(), Rc::new(DeclaredFuncSig { + name: sig_key.clone(), + params: sig_params.clone(), + inferred: Some(sig_rt.clone()), + is_async: sig_async.clone(), + output_provenance: rsig.output_provenance.clone(), + variant_provenance: rsig.variant_provenance.clone(), +})) +}); +let parent_result = typed_parent.items.clone().iter().cloned().fold(Rc::new(InferScopeComponents { + func_sigs: next_func_sigs, + svc_registry: svc_registry, + svc_locals: svc_locals, +}), |acc: Rc, titem: Rc| if ((titem.transport.clone() != None) && ((titem.children.clone().len() as i64) > 0)) { + { + let entries = Rc::new({ let mut __result = Vec::new(); for c in titem.children.clone().iter().cloned() { __result.push(Rc::new(OpEntry { + name: authored_name_at(env.source_indices.clone(), &c), + outputs: inferred_to_outputs(&c.inferred.clone(), c.span.clone(), env.source_indices.clone()), + params: c.params.clone(), +})); } __result }); +let root = namespace_root_from_properties(titem.properties.clone(), authored_name_at(env.source_indices.clone(), &titem), env.source_indices.clone()); +Rc::new(InferScopeComponents { + func_sigs: acc.func_sigs.clone(), + svc_registry: v2_rt::rc_map_insert(acc.svc_registry.clone(), authored_name_at(env.source_indices.clone(), &titem), entries.clone()), + svc_locals: v2_rt::rc_map_insert(acc.svc_locals.clone(), root.clone(), nominal_type_binding(&root)), +}) +} + } else { + if (((((titem.body.clone() != None) && ((titem.params.clone().len() as i64) == 0)) && (titem.transport.clone() == None)) && (titem.connective.clone() == Connective::NoConnective)) && (titem.inferred.clone() != None)) { + Rc::new(InferScopeComponents { + func_sigs: acc.func_sigs.clone(), + svc_registry: acc.svc_registry.clone(), + svc_locals: v2_rt::rc_map_insert(acc.svc_locals.clone(), authored_name_at(env.source_indices.clone(), &titem), Rc::new(TypeBinding { + name: authored_name_at(env.source_indices.clone(), &titem), + resolved: resolved_type(titem.clone()), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})), +}) + } else { + acc.clone() } - Some(imp) => match v2_rt::map_get(&parent_index, imp.module_path.clone()) { - Some(typed_parent) => { - let next_func_sigs = Rc::new(v2_rt::map_values( - &typed_parent.func_env.clone().signatures.clone(), - )) - .iter() - .cloned() - .fold( - func_sigs, - |acc: Rc>>, - rsig: Rc| { - let sig_key = rsig.name.clone(); - let sig_params = rsig.params.clone(); - let sig_rt = rsig.inferred.clone(); - let sig_async = rsig.is_async.clone(); - v2_rt::rc_map_insert( - acc, - sig_key.clone(), - Rc::new(DeclaredFuncSig { - name: sig_key.clone(), - params: sig_params.clone(), - inferred: Some(sig_rt.clone()), - is_async: sig_async.clone(), - output_provenance: rsig.output_provenance.clone(), - variant_provenance: rsig.variant_provenance.clone(), - }), - ) - }, - ); - let parent_result = typed_parent.items.clone().iter().cloned().fold( - Rc::new(InferScopeComponents { - func_sigs: next_func_sigs, - svc_registry: svc_registry, - svc_locals: svc_locals, - }), - |acc: Rc, titem: Rc| { - if ((titem.transport.clone() != None) - && ((titem.children.clone().len() as i64) > 0)) - { - { - let entries = Rc::new({ - let mut __result = Vec::new(); - for c in titem.children.clone().iter().cloned() { - __result.push(Rc::new(OpEntry { - name: authored_name_at( - env.source_indices.clone(), - &c, - ), - outputs: inferred_to_outputs( - &c.inferred.clone(), - c.span.clone(), - env.source_indices.clone(), - ), - params: c.params.clone(), - })); - } - __result - }); - let root = namespace_root_from_properties( - titem.properties.clone(), - authored_name_at(env.source_indices.clone(), &titem), - env.source_indices.clone(), - ); - Rc::new(InferScopeComponents { - func_sigs: acc.func_sigs.clone(), - svc_registry: v2_rt::rc_map_insert( - acc.svc_registry.clone(), - authored_name_at(env.source_indices.clone(), &titem), - entries.clone(), - ), - svc_locals: v2_rt::rc_map_insert( - acc.svc_locals.clone(), - root.clone(), - nominal_type_binding(&root), - ), - }) - } - } else { - if (((((titem.body.clone() != None) - && ((titem.params.clone().len() as i64) == 0)) - && (titem.transport.clone() == None)) - && (titem.connective.clone() == Connective::NoConnective)) - && (titem.inferred.clone() != None)) - { - Rc::new(InferScopeComponents { - func_sigs: acc.func_sigs.clone(), - svc_registry: acc.svc_registry.clone(), - svc_locals: v2_rt::rc_map_insert( - acc.svc_locals.clone(), - authored_name_at(env.source_indices.clone(), &titem), - Rc::new(TypeBinding { - name: authored_name_at( - env.source_indices.clone(), - &titem, - ), - resolved: resolved_type(titem.clone()), - provenance: Rc::new( - SubValueRelation::SubValueUnknown, - ), - }), - ), - }) - } else { - acc.clone() - } - } - }, - ); - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = parent_result.func_sigs.clone(); - let __tco_2 = parent_result.svc_registry.clone(); - let __tco_3 = parent_result.svc_locals.clone(); - remaining = __tco_0; - func_sigs = __tco_1; - svc_registry = __tco_2; - svc_locals = __tco_3; - continue; - } - } - None => { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - remaining = __tco_0; - continue; - } - }, - } - } + }); +{ + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = parent_result.func_sigs.clone(); +let __tco_2 = parent_result.svc_registry.clone(); +let __tco_3 = parent_result.svc_locals.clone(); +remaining = __tco_0; +func_sigs = __tco_1; +svc_registry = __tco_2; +svc_locals = __tco_3; +continue; +} }, + None => { { + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +remaining = __tco_0; +continue; +} }, +} }, +} +} } pub fn nominal_leaf_type(name: String) -> Rc { @@ -488,17 +305,17 @@ pub fn nominal_leaf_type(name: String) -> Rc { pub fn nominal_type_binding(name: &String) -> Rc { Rc::new(TypeBinding { - name: name.clone(), - resolved: nominal_leaf_type(name.clone()), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }) + name: name.clone(), + resolved: nominal_leaf_type(name.clone()), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +}) } pub fn set_has(m: Rc>, key: String) -> bool { match v2_rt::map_get(&m, key) { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -507,242 +324,147 @@ pub struct FieldRecursionResult { pub element_type: String, } -pub fn classify_field_recursion( - field_node: &Rc, - parent_name: &String, - recursive_type_set: Rc>, - source_indices: &Rc>>, -) -> Option> { +pub fn classify_field_recursion(field_node: &Rc, parent_name: &String, recursive_type_set: Rc>, source_indices: &Rc>>) -> Option> { { let type_expr = match field_node.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), - _ => field_node_type_expr(&field_node), - }; - let field_type_name = authored_name_at(source_indices.clone(), &type_expr); - if (field_type_name.clone().as_str() == parent_name.clone().as_str()) { + Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), + _ => field_node_type_expr(&field_node), +}; +let field_type_name = authored_name_at(source_indices.clone(), &type_expr); +if (field_type_name.clone().as_str() == parent_name.clone().as_str()) { match field_node.return_cardinality.clone() { - Cardinality::CardOptional => Some(Rc::new(FieldRecursionResult { - shape: RecursionShape::OptionalRecursion, - element_type: parent_name.clone(), - })), - _ => Some(Rc::new(FieldRecursionResult { - shape: RecursionShape::DirectRecursion, - element_type: parent_name.clone(), - })), - } + Cardinality::CardOptional => Some(Rc::new(FieldRecursionResult { + shape: RecursionShape::OptionalRecursion, + element_type: parent_name.clone(), +})), + _ => Some(Rc::new(FieldRecursionResult { + shape: RecursionShape::DirectRecursion, + element_type: parent_name.clone(), +})), +} } else { if is_container_type(field_type_name.clone()) { { let arity = match container_expected_arity(field_type_name.clone()) { - Some(a) => a.clone(), - None => 0, - }; - let value_index = if (arity == 2) { 1 } else { 0 }; - let value_type = match type_expr - .children - .clone() - .get(value_index as usize) - .cloned() - { - Some(t) => authored_name_at(source_indices.clone(), &t), - None => "".to_string(), + Some(a) => a.clone(), + None => 0, +}; +let value_index = if (arity == 2) { + 1 + } else { + 0 }; - let is_recursive_element = ((value_type.clone().as_str() - == parent_name.clone().as_str()) - || set_has(recursive_type_set, value_type.clone())); - if is_recursive_element { +let value_type = match type_expr.children.clone().get(value_index as usize).cloned() { + Some(t) => authored_name_at(source_indices.clone(), &t), + None => "".to_string(), +}; +let is_recursive_element = ((value_type.clone().as_str() == parent_name.clone().as_str()) || set_has(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() - }; - match field_type_name.clone().as_str() { - "List" => Some(Rc::new(FieldRecursionResult { - shape: RecursionShape::ListRecursion, - element_type: elem, - })), - "Set" => Some(Rc::new(FieldRecursionResult { - shape: RecursionShape::SetRecursion, - element_type: elem, - })), - "Map" => Some(Rc::new(FieldRecursionResult { - shape: RecursionShape::MapValueRecursion, - element_type: elem, - })), - _ => None, - } - } + let elem = if (value_type.clone().as_str() == parent_name.clone().as_str()) { + parent_name.clone() + } else { + value_type.clone() + }; +match field_type_name.clone().as_str() { + "List" => Some(Rc::new(FieldRecursionResult { + shape: RecursionShape::ListRecursion, + element_type: elem, +})), + "Set" => Some(Rc::new(FieldRecursionResult { + shape: RecursionShape::SetRecursion, + element_type: elem, +})), + "Map" => Some(Rc::new(FieldRecursionResult { + shape: RecursionShape::MapValueRecursion, + element_type: elem, +})), + _ => None, +} +} } else { None } - } +} } else { if set_has(recursive_type_set, field_type_name.clone()) { match field_node.return_cardinality.clone() { - Cardinality::CardOptional => Some(Rc::new(FieldRecursionResult { - shape: RecursionShape::OptionalRecursion, - element_type: field_type_name.clone(), - })), - _ => Some(Rc::new(FieldRecursionResult { - shape: RecursionShape::DirectRecursion, - element_type: field_type_name.clone(), - })), - } + Cardinality::CardOptional => Some(Rc::new(FieldRecursionResult { + shape: RecursionShape::OptionalRecursion, + element_type: field_type_name.clone(), +})), + _ => Some(Rc::new(FieldRecursionResult { + shape: RecursionShape::DirectRecursion, + element_type: field_type_name.clone(), +})), +} } else { None } } } - } +} } -pub fn collect_fields_inductive( - fields: Rc>>, - parent_name: String, - variant_name: String, - recursive_type_set: Rc>, - acc: Rc>>>>, - source_indices: Rc>>, -) -> Rc>>>> { - fields.iter().cloned().fold( - acc.clone(), - |field_acc: Rc>>>>, field_node: Rc| { - match classify_field_recursion( - &field_node, - &parent_name, - recursive_type_set.clone(), - &source_indices, - ) { - Some(result) => put_inductive_field_cross( - &field_acc, - &parent_name, - variant_name.clone(), - authored_name_at(source_indices.clone(), &field_node), - result.shape.clone(), - result.element_type.clone(), - ), - None => field_acc.clone(), - } - }, - ) +pub fn collect_fields_inductive(fields: Rc>>, parent_name: String, variant_name: String, recursive_type_set: Rc>, acc: Rc>>>>, source_indices: Rc>>) -> Rc>>>> { + fields.iter().cloned().fold(acc.clone(), |field_acc: Rc>>>>, field_node: Rc| match classify_field_recursion(&field_node, &parent_name, recursive_type_set.clone(), &source_indices) { + Some(result) => put_inductive_field_cross(&field_acc, &parent_name, variant_name.clone(), authored_name_at(source_indices.clone(), &field_node), result.shape.clone(), result.element_type.clone()), + None => field_acc.clone(), +}) } -pub fn collect_item_inductive_fields( - item: &Rc, - recursive_type_set: Rc>, - source_indices: &Rc>>, -) -> Rc>>>> { +pub fn collect_item_inductive_fields(item: &Rc, recursive_type_set: Rc>, source_indices: &Rc>>) -> Rc>>>> { { let item_name = authored_name_at(source_indices.clone(), &item); - match item.connective.clone() { - Connective::Disj => item.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>>>(), - |variant_acc: Rc>>>>, - variant_node: Rc| { - collect_fields_inductive( - variant_node.children.clone(), - item_name.clone(), - authored_name_at(source_indices.clone(), &variant_node), - recursive_type_set.clone(), - variant_acc, - source_indices.clone(), - ) - }, - ), - Connective::Conj => collect_fields_inductive( - item.children.clone(), - item_name.clone(), - "".to_string(), - recursive_type_set.clone(), - v2_rt::rc_empty_map::>>>(), - source_indices.clone(), - ), - _ => v2_rt::rc_empty_map::>>>(), - } - } +match item.connective.clone() { + Connective::Disj => item.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |variant_acc: Rc>>>>, variant_node: Rc| collect_fields_inductive(variant_node.children.clone(), item_name.clone(), authored_name_at(source_indices.clone(), &variant_node), recursive_type_set.clone(), variant_acc, source_indices.clone())), + Connective::Conj => collect_fields_inductive(item.children.clone(), item_name.clone(), "".to_string(), recursive_type_set.clone(), v2_rt::rc_empty_map::>>>(), source_indices.clone()), + _ => v2_rt::rc_empty_map::>>>(), +} +} } -pub fn build_item_inductive_fields( - items: Rc>>, - recursive_type_set: Rc>, - source_indices: Rc>>, -) -> Rc>>>> { - items.iter().cloned().fold( - v2_rt::rc_empty_map::>>>(), - |acc: Rc>>>>, item: Rc| { - merge_inductive_fields( - acc, - &collect_item_inductive_fields(&item, recursive_type_set.clone(), &source_indices), - ) - }, - ) +pub fn build_item_inductive_fields(items: Rc>>, recursive_type_set: Rc>, source_indices: Rc>>) -> Rc>>>> { + items.iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |acc: Rc>>>>, item: Rc| merge_inductive_fields(acc, &collect_item_inductive_fields(&item, recursive_type_set.clone(), &source_indices))) } -pub fn nominal_ref_node( - name: &String, - span: Rc, - ident_span: Option>, -) -> Rc { +pub fn nominal_ref_node(name: &String, span: Rc, ident_span: Option>) -> Rc { Rc::new(Node { - name: name.clone(), - span: span, - ident_span: ident_span, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { - node: nominal_leaf_type(name.clone()), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: name.clone(), + span: span, + ident_span: ident_span, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: nominal_leaf_type(name.clone()), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn resolved_callable_type(func_params: Rc>>, ret: Rc) -> Rc { make_callable_type(func_params, ret) } -pub fn namespace_root_from_properties( - properties: Rc>>, - name: String, - source_indices: Rc>>, -) -> String { - 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()) - { - __result.push(p); - } - } - __result - }) - .first() - .cloned() - { - Some(ns_prop) => match (*field_init_node_value(&ns_prop).expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: root, .. } = value.as_ref() else { - unreachable!() - }; - root.clone() - } - _ => name, - }, - None => name, - } +pub fn namespace_root_from_properties(properties: Rc>>, name: String, source_indices: Rc>>) -> String { + 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()) { __result.push(p); } } __result }).first().cloned() { + Some(ns_prop) => match (*field_init_node_value(&ns_prop).expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: root, .. } = value.as_ref() else { unreachable!() }; root.clone() }, + _ => name, +}, + None => name, +} } pub fn expr_span(texpr: Rc) -> Rc { @@ -751,9 +473,9 @@ pub fn expr_span(texpr: Rc) -> Rc { pub fn ok_infer(texpr: Rc) -> Rc { Rc::new(InferResult { - typed: texpr, - diagnostics: Rc::new(vec![]), - }) + typed: texpr, + diagnostics: Rc::new(vec![]), +}) } pub fn semantic_expr_error_node(message: String, span: Rc) -> Rc { @@ -766,137 +488,82 @@ pub fn internal_expr_error_node(message: String, span: Rc) -> Rc, name: &String) -> Option { match v2_rt::map_get(&scope.locals.clone(), name.clone()) { - Some(binding) => { - match lookup_type_for(&scope.type_env.clone(), &binding.resolved.clone()) { - Some(parent) => { - let is_coproduct = (parent.connective.clone() == Connective::Disj); - if is_coproduct { - if has_child_named( - parent.clone(), - name.clone(), - scope.type_env.clone().source_indices.clone(), - ) { - Some(authored_name_at( - scope.type_env.clone().source_indices.clone(), - &binding.resolved.clone(), - )) - } else { - None - } - } else { - None - } - } - None => None, + Some(binding) => match lookup_type_for(&scope.type_env.clone(), &binding.resolved.clone()) { + Some(parent) => { + let is_coproduct = (parent.connective.clone() == Connective::Disj); +if is_coproduct { + if has_child_named(parent.clone(), name.clone(), scope.type_env.clone().source_indices.clone()) { + Some(authored_name_at(scope.type_env.clone().source_indices.clone(), &binding.resolved.clone())) + } else { + None } + } else { + None } - None => None, - } +}, + None => None, +}, + None => None, +} } pub fn infer_var_binding_kind(scope: &Rc, name: &String) -> Rc { match lookup_variant_parent_enum(&scope, &name) { - Some(parent_enum) => Rc::new(VarBindingKind::VariantValueBinding { - parent_enum: parent_enum.clone(), - }), - None => match v2_rt::map_get(&scope.locals.clone(), name.clone()) { - Some(_) => { - if v2_rt::map_has(&scope.match_bound_names.clone(), name.clone()) { - Rc::new(VarBindingKind::MatchBoundBinding) - } else { - Rc::new(VarBindingKind::LocalValueBinding) - } - } - None => Rc::new(VarBindingKind::FunctionValueBinding), - }, - } + Some(parent_enum) => Rc::new(VarBindingKind::VariantValueBinding { + parent_enum: parent_enum.clone(), +}), + None => match v2_rt::map_get(&scope.locals.clone(), name.clone()) { + Some(_) => if v2_rt::map_has(&scope.match_bound_names.clone(), name.clone()) { + Rc::new(VarBindingKind::MatchBoundBinding) + } else { + Rc::new(VarBindingKind::LocalValueBinding) + }, + None => Rc::new(VarBindingKind::FunctionValueBinding), +}, +} +} + +pub fn inference_error(message: String, span: Rc, module_name: String) -> Rc { + make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: message, + span: span, +}), module_name) +} + +pub fn type_mismatch_error(expected: String, got: String, span: Rc, module_name: String) -> Rc { + make_error_node(Rc::new(CompilerDiagnostic::TypeMismatch { + expected: expected, + got: got, + span: span, +}), module_name) } -pub fn inference_error( - message: String, - span: Rc, - module_name: String, -) -> Rc { - make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: message, - span: span, - }), - module_name, - ) -} - -pub fn type_mismatch_error( - expected: String, - got: String, - span: Rc, - module_name: String, -) -> Rc { - make_error_node( - Rc::new(CompilerDiagnostic::TypeMismatch { - expected: expected, - got: got, - span: span, - }), - module_name, - ) -} - -pub fn rejects_string_for_optional_coproduct_field( - expected: &Rc, - got: Rc, - source_indices: Rc>>, -) -> bool { +pub fn rejects_string_for_optional_coproduct_field(expected: &Rc, got: Rc, source_indices: Rc>>) -> bool { { let expected_inner = with_required_cardinality(&expected); - 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()); - (expected_is_optional_coproduct && got_is_string) - } +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()); +(expected_is_optional_coproduct && got_is_string) +} } -pub fn record_lit_expected_fields( - type_name: Option, - scope: &Rc, -) -> Rc>> { +pub fn record_lit_expected_fields(type_name: Option, scope: &Rc) -> Rc>> { match type_name { - Some(tn) => match lookup_type_by_name(&scope.type_env.clone(), tn.clone()) { - Some(direct) => direct.children.clone(), - None => match lookup_variant_parent_enum(&scope, &tn) { - Some(parent_name) => { - match lookup_type_by_name(&scope.type_env.clone(), parent_name.clone()) { - Some(parent) => match Rc::new({ - let mut __result = Vec::new(); - for v in parent.children.clone().iter().cloned() { - if (authored_name_at( - scope.type_env.clone().source_indices.clone(), - &v, - ) - .as_str() - == tn.clone().as_str()) - { - __result.push(v); - } - } - __result - }) - .first() - .cloned() - { - Some(variant) => variant.children.clone(), - None => Rc::new(vec![]), - }, - None => Rc::new(vec![]), - } - } - None => Rc::new(vec![]), - }, - }, - None => Rc::new(vec![]), - } + Some(tn) => match lookup_type_by_name(&scope.type_env.clone(), tn.clone()) { + Some(direct) => direct.children.clone(), + None => match lookup_variant_parent_enum(&scope, &tn) { + Some(parent_name) => match lookup_type_by_name(&scope.type_env.clone(), parent_name.clone()) { + Some(parent) => match Rc::new({ let mut __result = Vec::new(); for v in parent.children.clone().iter().cloned() { if (authored_name_at(scope.type_env.clone().source_indices.clone(), &v).as_str() == tn.clone().as_str()) { __result.push(v); } } __result }).first().cloned() { + Some(variant) => variant.children.clone(), + None => Rc::new(vec![]), +}, + None => Rc::new(vec![]), +}, + None => Rc::new(vec![]), +}, +}, + None => Rc::new(vec![]), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -908,11 +575,11 @@ pub struct KernelListTyDiag { pub fn list_kernel_ty_from_element(element: Rc) -> Rc { { let b = make_container_type(&"List".to_string(), element); - Rc::new(KernelListTyDiag { - ty: b.ty.clone(), - miss_diags: b.diagnostics.clone(), - }) - } +Rc::new(KernelListTyDiag { + ty: b.ty.clone(), + miss_diags: b.diagnostics.clone(), +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -921,118 +588,80 @@ pub struct Tier2bBt { pub kernel_diags: Rc>>, } -pub fn infer_tier2b_builtin_with_kernel_diags( - func_name: &String, - typed_args: Rc>>, - 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())) - { +pub fn infer_tier2b_builtin_with_kernel_diags(func_name: &String, typed_args: Rc>>, 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())) { Rc::new(Tier2bBt { - bt: match typed_args.first().cloned() { - Some(receiver_arg) => match arg_value(&receiver_arg) - .inferred - .clone() - .as_deref() - .cloned() - { - Some(InferredNode::Resolved { - node: receiver_type, - .. - }) => { - match map_value_type_in_env(receiver_type.clone(), &scope.type_env.clone()) - { - Some(value_type) => with_optional_cardinality(&value_type), - None => resolve_builtin_call_type(func_name.clone()), - } - } - _ => resolve_builtin_call_type(func_name.clone()), - }, - None => resolve_builtin_call_type(func_name.clone()), - }, - kernel_diags: Rc::new(vec![]), - }) + bt: match typed_args.first().cloned() { + Some(receiver_arg) => match arg_value(&receiver_arg).inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: receiver_type, .. }) => match map_value_type_in_env(receiver_type.clone(), &scope.type_env.clone()) { + Some(value_type) => with_optional_cardinality(&value_type), + None => resolve_builtin_call_type(func_name.clone()), +}, + _ => resolve_builtin_call_type(func_name.clone()), +}, + None => resolve_builtin_call_type(func_name.clone()), +}, + kernel_diags: Rc::new(vec![]), +}) } else { if (func_name.clone().as_str() == "map_keys".to_string().as_str()) { match typed_args.first().cloned() { - Some(receiver_arg) => match arg_value(&receiver_arg) - .inferred - .clone() - .as_deref() - .cloned() - { - Some(InferredNode::Resolved { - node: receiver_type, - .. - }) => match map_key_type_in_env(receiver_type.clone(), &scope.type_env.clone()) - { - Some(key_type) => { - let lk = list_kernel_ty_from_element(key_type.clone()); - Rc::new(Tier2bBt { - bt: lk.ty.clone(), - kernel_diags: lk.miss_diags.clone(), - }) - } - None => Rc::new(Tier2bBt { - bt: resolve_builtin_call_type(func_name.clone()), - kernel_diags: Rc::new(vec![]), - }), - }, - _ => Rc::new(Tier2bBt { - bt: resolve_builtin_call_type(func_name.clone()), - kernel_diags: Rc::new(vec![]), - }), - }, - None => Rc::new(Tier2bBt { - bt: resolve_builtin_call_type(func_name.clone()), - kernel_diags: Rc::new(vec![]), - }), - } + Some(receiver_arg) => match arg_value(&receiver_arg).inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: receiver_type, .. }) => match map_key_type_in_env(receiver_type.clone(), &scope.type_env.clone()) { + Some(key_type) => { + let lk = list_kernel_ty_from_element(key_type.clone()); +Rc::new(Tier2bBt { + bt: lk.ty.clone(), + kernel_diags: lk.miss_diags.clone(), +}) +}, + None => Rc::new(Tier2bBt { + bt: resolve_builtin_call_type(func_name.clone()), + kernel_diags: Rc::new(vec![]), +}), +}, + _ => Rc::new(Tier2bBt { + bt: resolve_builtin_call_type(func_name.clone()), + kernel_diags: Rc::new(vec![]), +}), +}, + None => Rc::new(Tier2bBt { + bt: resolve_builtin_call_type(func_name.clone()), + kernel_diags: Rc::new(vec![]), +}), +} } else { if (func_name.clone().as_str() == "map_values".to_string().as_str()) { match typed_args.first().cloned() { - Some(receiver_arg) => match arg_value(&receiver_arg) - .inferred - .clone() - .as_deref() - .cloned() - { - Some(InferredNode::Resolved { - node: receiver_type, - .. - }) => match map_value_type_in_env( - receiver_type.clone(), - &scope.type_env.clone(), - ) { - Some(value_type) => { - let lv = list_kernel_ty_from_element(value_type.clone()); - Rc::new(Tier2bBt { - bt: lv.ty.clone(), - kernel_diags: lv.miss_diags.clone(), - }) - } - None => Rc::new(Tier2bBt { - bt: resolve_builtin_call_type(func_name.clone()), - kernel_diags: Rc::new(vec![]), - }), - }, - _ => Rc::new(Tier2bBt { - bt: resolve_builtin_call_type(func_name.clone()), - kernel_diags: Rc::new(vec![]), - }), - }, - None => Rc::new(Tier2bBt { - bt: resolve_builtin_call_type(func_name.clone()), - kernel_diags: Rc::new(vec![]), - }), - } + Some(receiver_arg) => match arg_value(&receiver_arg).inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: receiver_type, .. }) => match map_value_type_in_env(receiver_type.clone(), &scope.type_env.clone()) { + Some(value_type) => { + let lv = list_kernel_ty_from_element(value_type.clone()); +Rc::new(Tier2bBt { + bt: lv.ty.clone(), + kernel_diags: lv.miss_diags.clone(), +}) +}, + None => Rc::new(Tier2bBt { + bt: resolve_builtin_call_type(func_name.clone()), + kernel_diags: Rc::new(vec![]), +}), +}, + _ => Rc::new(Tier2bBt { + bt: resolve_builtin_call_type(func_name.clone()), + kernel_diags: Rc::new(vec![]), +}), +}, + None => Rc::new(Tier2bBt { + bt: resolve_builtin_call_type(func_name.clone()), + kernel_diags: Rc::new(vec![]), +}), +} } else { Rc::new(Tier2bBt { - bt: resolve_builtin_call_type(func_name.clone()), - kernel_diags: Rc::new(vec![]), - }) + bt: resolve_builtin_call_type(func_name.clone()), + kernel_diags: Rc::new(vec![]), +}) } } } @@ -1044,571 +673,344 @@ pub struct MethodPipeFallback { pub kernel_diags: Rc>>, } -pub fn method_pipe_map_keys_values_fallback( - recv_rt: &Rc, - method_name: &String, - scope: Rc, - span: Rc, -) -> Rc { +pub fn method_pipe_map_keys_values_fallback(recv_rt: &Rc, method_name: &String, scope: Rc, span: Rc) -> Rc { if (method_name.clone().as_str() == "map_keys".to_string().as_str()) { 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()); - Rc::new(MethodPipeFallback { - result_ty: lk.ty.clone(), - kernel_diags: lk.miss_diags.clone(), - }) - } - None => Rc::new(MethodPipeFallback { - result_ty: recv_rt.clone(), - kernel_diags: Rc::new(vec![]), - }), - } + Some(key_type) => { + let lk = list_kernel_ty_from_element(key_type.clone()); +Rc::new(MethodPipeFallback { + result_ty: lk.ty.clone(), + kernel_diags: lk.miss_diags.clone(), +}) +}, + None => Rc::new(MethodPipeFallback { + result_ty: recv_rt.clone(), + kernel_diags: Rc::new(vec![]), +}), +} } else { if (method_name.clone().as_str() == "map_values".to_string().as_str()) { 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()); - Rc::new(MethodPipeFallback { - result_ty: lv.ty.clone(), - kernel_diags: lv.miss_diags.clone(), - }) - } - None => Rc::new(MethodPipeFallback { - result_ty: recv_rt.clone(), - kernel_diags: Rc::new(vec![]), - }), - } + Some(value_type) => { + let lv = list_kernel_ty_from_element(value_type.clone()); +Rc::new(MethodPipeFallback { + result_ty: lv.ty.clone(), + kernel_diags: lv.miss_diags.clone(), +}) +}, + None => Rc::new(MethodPipeFallback { + result_ty: recv_rt.clone(), + kernel_diags: Rc::new(vec![]), +}), +} } else { Rc::new(MethodPipeFallback { - result_ty: recv_rt.clone(), - kernel_diags: Rc::new(vec![]), - }) + result_ty: recv_rt.clone(), + kernel_diags: Rc::new(vec![]), +}) } } } -pub fn categorized_error( - message: String, - span: Rc, - module_name: String, - category: String, -) -> Rc { - make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: message, - span: span, - }), - module_name, - ) -} - -pub fn validate_cast( - source_inferred: Option>, - target_name: &String, - span: Rc, - source_indices: Rc>>, - module_name: String, -) -> Option> { +pub fn categorized_error(message: String, span: Rc, module_name: String, category: String) -> Rc { + make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: message, + span: span, +}), module_name) +} + +pub fn validate_cast(source_inferred: Option>, target_name: &String, span: Rc, source_indices: Rc>>, module_name: String) -> Option> { match source_inferred.as_deref().cloned() { - Some(InferredNode::Resolved { node: src_node, .. }) => { - let source_name = authored_name_at(source_indices, &src_node); - if (source_name.clone().as_str() == target_name.clone().as_str()) { + Some(InferredNode::Resolved { node: src_node, .. }) => { + let source_name = authored_name_at(source_indices, &src_node); +if (source_name.clone().as_str() == target_name.clone().as_str()) { + None + } else { + if !is_dag_cast_domain_type(source_name.clone()) { None } else { - if !is_dag_cast_domain_type(source_name.clone()) { + if !is_dag_cast_domain_type(target_name.clone()) { None } else { - if !is_dag_cast_domain_type(target_name.clone()) { + if dag_can_cast(source_name.clone(), target_name.clone()) { None } else { - if dag_can_cast(source_name.clone(), target_name.clone()) { - None - } else { - { - let msg = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "invalid cast: ".to_string(), - source_name.clone(), - ), - " as ".to_string(), - ), - target_name.clone(), - ); - let diag = Rc::new(CompilerDiagnostic::InternalError { - message: msg, - span: span, - }); - Some(make_error_node(diag, module_name)) - } - } + { + let msg = v2_rt::concat(v2_rt::concat(v2_rt::concat("invalid cast: ".to_string(), source_name.clone()), " as ".to_string()), target_name.clone()); +let diag = Rc::new(CompilerDiagnostic::InternalError { + message: msg, + span: span, +}); +Some(make_error_node(diag, module_name)) +} } } } } - _ => None, - } +}, + _ => None, +} } pub fn type_variable_node(id: String) -> Rc { Rc::new(Node { - name: "".to_string(), - span: make_span(0, 0), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::TypeVariable { id: id })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: "".to_string(), + span: make_span(0, 0), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::TypeVariable { + id: id, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn is_type_variable(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::TypeVariable { .. } => true, - _ => false, - } + InferredNode::TypeVariable { .. } => true, + _ => false, +} } -pub fn inferred_or_error( - result: Option>, - fallback_message: String, - fallback_span: Rc, -) -> Rc { +pub fn inferred_or_error(result: Option>, fallback_message: String, fallback_span: Rc) -> Rc { match result { - Some(inferred) => inferred.clone(), - None => Rc::new(InferredNode::CompilerError { - message: fallback_message, - span: fallback_span, - }), - } + Some(inferred) => inferred.clone(), + None => Rc::new(InferredNode::CompilerError { + message: fallback_message, + span: fallback_span, +}), +} } -pub fn resolve_pattern_subject( - scope: Rc, - scrutinee_subject: Rc, -) -> Rc { +pub fn resolve_pattern_subject(scope: Rc, scrutinee_subject: Rc) -> Rc { match (*scrutinee_subject).clone() { - PatternSubject::PatternResolved { - node: scrutinee_type, - .. - } => pattern_subject_from_node(&resolve_scrutinee_type_node( - scope.type_env.clone(), - scrutinee_type.clone(), - )), - PatternSubject::PatternDynamic { - span: dynamic_span, .. - } => Rc::new(PatternSubject::PatternDynamic { - span: dynamic_span.clone(), - }), - PatternSubject::PatternLookupBlocked => Rc::new(PatternSubject::PatternLookupBlocked), - } + PatternSubject::PatternResolved { node: scrutinee_type, .. } => pattern_subject_from_node(&resolve_scrutinee_type_node(scope.type_env.clone(), scrutinee_type.clone())), + PatternSubject::PatternDynamic { span: dynamic_span, .. } => Rc::new(PatternSubject::PatternDynamic { + span: dynamic_span.clone(), +}), + PatternSubject::PatternLookupBlocked => Rc::new(PatternSubject::PatternLookupBlocked), +} } -pub fn annotate_pattern_parent_enums( - pattern: Rc, - scrutinee_subject: Rc, - scope: &Rc, -) -> Rc { +pub fn annotate_pattern_parent_enums(pattern: Rc, scrutinee_subject: Rc, scope: &Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*pattern.clone()).clone() { - MatchPattern::VariantPattern { - name: variant_name, - field_bindings: bindings, - .. - } => { - let resolved_scrut = resolve_pattern_subject(scope.clone(), scrutinee_subject); - let inferred_parent = match (*resolved_scrut.clone()).clone() { - PatternSubject::PatternResolved { - node: resolved_scrut_node, - .. - } => { - if ((resolved_scrut_node.return_cardinality.clone() - == Cardinality::CardOptional) - && ((variant_name.clone().as_str() == "Some".to_string().as_str()) - || (variant_name.clone().as_str() == "None".to_string().as_str()))) - { - Some("Optional".to_string()) - } else { - { - let is_coproduct = - (resolved_scrut_node.connective.clone() == Connective::Disj); - if is_coproduct { - Some(authored_name_at( - scope.type_env.clone().source_indices.clone(), - &resolved_scrut_node, - )) - } else { - None - } - } - } - } - PatternSubject::PatternDynamic { .. } => None, - PatternSubject::PatternLookupBlocked => None, - }; - let variant_lookup = lookup_variant_in_type( - resolved_scrut.clone(), - &variant_name, - scope.module_name.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let variant_subject = lookup_result_subject(variant_lookup); - let annotated_bindings = Rc::new({ - let mut __result = Vec::new(); - for binding in bindings.clone().iter().cloned() { - __result.push({ - let field_lookup = lookup_field_in_variant( - variant_subject.clone(), - &field_binding_name_at( - binding.clone(), - scope.type_env.clone().source_indices.clone(), - ), - scope.module_name.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let field_subject = lookup_result_subject(field_lookup.clone()); - make_field_binding_node( - &field_binding_name_at( - binding.clone(), - scope.type_env.clone().source_indices.clone(), - ), - annotate_pattern_parent_enums( - field_binding_pattern(binding.clone()), - field_subject.clone(), - &scope, - ), - binding.span.clone(), - node_name_span(&binding), - ) - }); + MatchPattern::VariantPattern { name: variant_name, field_bindings: bindings, .. } => { + let resolved_scrut = resolve_pattern_subject(scope.clone(), scrutinee_subject); +let inferred_parent = match (*resolved_scrut.clone()).clone() { + PatternSubject::PatternResolved { node: resolved_scrut_node, .. } => if ((resolved_scrut_node.return_cardinality.clone() == Cardinality::CardOptional) && ((variant_name.clone().as_str() == "Some".to_string().as_str()) || (variant_name.clone().as_str() == "None".to_string().as_str()))) { + Some("Optional".to_string()) + } else { + { + let is_coproduct = (resolved_scrut_node.connective.clone() == Connective::Disj); +if is_coproduct { + Some(authored_name_at(scope.type_env.clone().source_indices.clone(), &resolved_scrut_node)) + } else { + None } - __result - }); - match inferred_parent { - Some(parent_name) => Rc::new(MatchPattern::VariantPattern { - name: variant_name.clone(), - parent_enum: Some(parent_name.clone()), - field_bindings: annotated_bindings, - }), - None => Rc::new(MatchPattern::VariantPattern { - name: variant_name.clone(), - parent_enum: None, - field_bindings: annotated_bindings, - }), - } - } - _ => pattern.clone(), - } +} + }, + PatternSubject::PatternDynamic { .. } => None, + PatternSubject::PatternLookupBlocked => None, +}; +let variant_lookup = lookup_variant_in_type(resolved_scrut.clone(), &variant_name, scope.module_name.clone(), &scope.type_env.clone().source_indices.clone()); +let variant_subject = lookup_result_subject(variant_lookup); +let annotated_bindings = Rc::new({ let mut __result = Vec::new(); for binding in bindings.clone().iter().cloned() { __result.push({ + let field_lookup = lookup_field_in_variant(variant_subject.clone(), &field_binding_name_at(binding.clone(), scope.type_env.clone().source_indices.clone()), scope.module_name.clone(), &scope.type_env.clone().source_indices.clone()); +let field_subject = lookup_result_subject(field_lookup.clone()); +make_field_binding_node(&field_binding_name_at(binding.clone(), scope.type_env.clone().source_indices.clone()), annotate_pattern_parent_enums(field_binding_pattern(binding.clone()), field_subject.clone(), &scope), binding.span.clone(), node_name_span(&binding)) +}); } __result }); +match inferred_parent { + Some(parent_name) => Rc::new(MatchPattern::VariantPattern { + name: variant_name.clone(), + parent_enum: Some(parent_name.clone()), + field_bindings: annotated_bindings, +}), + None => Rc::new(MatchPattern::VariantPattern { + name: variant_name.clone(), + parent_enum: None, + field_bindings: annotated_bindings, +}), +} +}, + _ => pattern.clone(), +} }) } pub fn build_params_scope(scope: &Rc, params: Rc>>) -> Rc { { - let new_locals = params.iter().cloned().fold( - scope.locals.clone(), - |acc: Rc>>, p: Rc| { - v2_rt::rc_map_insert( - acc, - param_node_name_at(p.clone(), scope.type_env.clone().source_indices.clone()), - Rc::new(TypeBinding { - name: param_node_name_at( - p.clone(), - scope.type_env.clone().source_indices.clone(), - ), - resolved: param_node_type_expr(&p), - provenance: Rc::new(SubValueRelation::PreservedValue), - }), - ) - }, - ); - Rc::new(InferScope { - type_env: scope.type_env.clone(), - func_env: scope.func_env.clone(), - locals: new_locals, - match_bound_names: scope.match_bound_names.clone(), - module_name: scope.module_name.clone(), - service_registry: scope.service_registry.clone(), - item_registry: scope.item_registry.clone(), - lambda_param_provenance: v2_rt::rc_empty_map::>(), - }) - } + let new_locals = params.iter().cloned().fold(scope.locals.clone(), |acc: Rc>>, p: Rc| v2_rt::rc_map_insert(acc, param_node_name_at(p.clone(), scope.type_env.clone().source_indices.clone()), Rc::new(TypeBinding { + name: param_node_name_at(p.clone(), scope.type_env.clone().source_indices.clone()), + resolved: param_node_type_expr(&p), + provenance: Rc::new(SubValueRelation::PreservedValue), +}))); +Rc::new(InferScope { + type_env: scope.type_env.clone(), + func_env: scope.func_env.clone(), + locals: new_locals, + match_bound_names: scope.match_bound_names.clone(), + module_name: scope.module_name.clone(), + service_registry: scope.service_registry.clone(), + item_registry: scope.item_registry.clone(), + lambda_param_provenance: v2_rt::rc_empty_map::>(), +}) +} } -pub fn extend_scope( - scope: &Rc, - name: &String, - resolved: Rc, - provenance: Rc, -) -> Rc { +pub fn extend_scope(scope: &Rc, name: &String, resolved: Rc, provenance: Rc) -> Rc { Rc::new(InferScope { - type_env: scope.type_env.clone(), - func_env: scope.func_env.clone(), - locals: v2_rt::rc_map_insert( - scope.locals.clone(), - name.clone(), - Rc::new(TypeBinding { - name: name.clone(), - resolved: resolved, - provenance: provenance, - }), - ), - match_bound_names: scope.match_bound_names.clone(), - module_name: scope.module_name.clone(), - service_registry: scope.service_registry.clone(), - item_registry: scope.item_registry.clone(), - lambda_param_provenance: scope.lambda_param_provenance.clone(), - }) + type_env: scope.type_env.clone(), + func_env: scope.func_env.clone(), + locals: v2_rt::rc_map_insert(scope.locals.clone(), name.clone(), Rc::new(TypeBinding { + name: name.clone(), + resolved: resolved, + provenance: provenance, +})), + match_bound_names: scope.match_bound_names.clone(), + module_name: scope.module_name.clone(), + service_registry: scope.service_registry.clone(), + item_registry: scope.item_registry.clone(), + lambda_param_provenance: scope.lambda_param_provenance.clone(), +}) } -pub fn extend_scope_match_bound( - scope: &Rc, - name: &String, - resolved: Rc, - provenance: Rc, -) -> Rc { +pub fn extend_scope_match_bound(scope: &Rc, name: &String, resolved: Rc, provenance: Rc) -> Rc { Rc::new(InferScope { - type_env: scope.type_env.clone(), - func_env: scope.func_env.clone(), - locals: v2_rt::rc_map_insert( - scope.locals.clone(), - name.clone(), - Rc::new(TypeBinding { - name: name.clone(), - resolved: resolved, - provenance: provenance, - }), - ), - match_bound_names: v2_rt::rc_map_insert( - scope.match_bound_names.clone(), - name.clone(), - true, - ), - module_name: scope.module_name.clone(), - service_registry: scope.service_registry.clone(), - item_registry: scope.item_registry.clone(), - lambda_param_provenance: scope.lambda_param_provenance.clone(), - }) + type_env: scope.type_env.clone(), + func_env: scope.func_env.clone(), + locals: v2_rt::rc_map_insert(scope.locals.clone(), name.clone(), Rc::new(TypeBinding { + name: name.clone(), + resolved: resolved, + provenance: provenance, +})), + match_bound_names: v2_rt::rc_map_insert(scope.match_bound_names.clone(), name.clone(), true), + module_name: scope.module_name.clone(), + service_registry: scope.service_registry.clone(), + item_registry: scope.item_registry.clone(), + lambda_param_provenance: scope.lambda_param_provenance.clone(), +}) } pub fn extend_scope_with_params(scope: &Rc, params: Rc>) -> Rc { { - let new_locals = params.iter().cloned().fold( - scope.locals.clone(), - |acc: Rc>>, p: String| { - v2_rt::rc_map_insert( - acc, - p.clone(), - Rc::new(TypeBinding { - name: p.clone(), - resolved: type_variable_node("lambda_param".to_string()), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - }, - ); - Rc::new(InferScope { - type_env: scope.type_env.clone(), - func_env: scope.func_env.clone(), - locals: new_locals, - match_bound_names: scope.match_bound_names.clone(), - module_name: scope.module_name.clone(), - service_registry: scope.service_registry.clone(), - item_registry: scope.item_registry.clone(), - lambda_param_provenance: scope.lambda_param_provenance.clone(), - }) - } + let new_locals = params.iter().cloned().fold(scope.locals.clone(), |acc: Rc>>, p: String| v2_rt::rc_map_insert(acc, p.clone(), Rc::new(TypeBinding { + name: p.clone(), + resolved: type_variable_node("lambda_param".to_string()), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +}))); +Rc::new(InferScope { + type_env: scope.type_env.clone(), + func_env: scope.func_env.clone(), + locals: new_locals, + match_bound_names: scope.match_bound_names.clone(), + module_name: scope.module_name.clone(), + service_registry: scope.service_registry.clone(), + item_registry: scope.item_registry.clone(), + lambda_param_provenance: scope.lambda_param_provenance.clone(), +}) +} } -pub fn scope_after_stmt_node( - stmt: &Rc, - stmt_type: Rc, - scope: &Rc, -) -> Rc { +pub fn scope_after_stmt_node(stmt: &Rc, stmt_type: Rc, scope: &Rc) -> Rc { match (*stmt.expr_data.clone()).clone() { - ExprData::ExprLet => { - if ((stmt.children.clone().len() as i64) <= 1) { - { - let val = match stmt.children.clone().first().cloned() { - Some(v) => v.clone(), - None => stmt.clone(), - }; - extend_scope( - &scope, - &let_binding_name_at( - stmt.clone(), - scope.type_env.clone().source_indices.clone(), - ), - stmt_type, - classify_binding_provenance(&val, &scope), - ) - } - } else { - scope.clone() - } - } - _ => scope.clone(), - } + ExprData::ExprLet => if ((stmt.children.clone().len() as i64) <= 1) { + { + let val = match stmt.children.clone().first().cloned() { + Some(v) => v.clone(), + None => stmt.clone(), +}; +extend_scope(&scope, &let_binding_name_at(stmt.clone(), scope.type_env.clone().source_indices.clone()), stmt_type, classify_binding_provenance(&val, &scope)) +} + } else { + scope.clone() + }, + _ => scope.clone(), +} } -pub fn derive_field_provenance( - scope: &Rc, - scrutinee_provenance: &Rc, - scrutinee_subject: Rc, - variant_name: String, - field_name: String, -) -> Rc { +pub fn derive_field_provenance(scope: &Rc, scrutinee_provenance: &Rc, scrutinee_subject: Rc, variant_name: String, field_name: String) -> Rc { match (*scrutinee_provenance.clone()).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - _ => { - let scrut_type_name = match (*scrutinee_subject).clone() { - PatternSubject::PatternResolved { node: n, .. } => authored_name_at( - scope.type_env.clone().source_indices.clone(), - &resolved_type(n.clone()), - ), - _ => "".to_string(), - }; - if (scrut_type_name.clone().as_str() == "".to_string().as_str()) { - Rc::new(SubValueRelation::SubValueUnknown) - } else { - { - let ind_fields = - inductive_fields_for(scope.type_env.clone(), scrut_type_name.clone()); - 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())) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match matching { - Some(ind_field) => { - compose_sub_value(scrutinee_provenance.clone(), ind_field.clone()) - } - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - } + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + _ => { + let scrut_type_name = match (*scrutinee_subject).clone() { + PatternSubject::PatternResolved { node: n, .. } => authored_name_at(scope.type_env.clone().source_indices.clone(), &resolved_type(n.clone())), + _ => "".to_string(), +}; +if (scrut_type_name.clone().as_str() == "".to_string().as_str()) { + Rc::new(SubValueRelation::SubValueUnknown) + } else { + { + let ind_fields = inductive_fields_for(scope.type_env.clone(), scrut_type_name.clone()); +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())) { __result.push(f); } } __result }).first().cloned(); +match matching { + Some(ind_field) => compose_sub_value(scrutinee_provenance.clone(), ind_field.clone()), + None => Rc::new(SubValueRelation::SubValueUnknown), +} +} } - } +}, +} } -pub fn extend_scope_with_pattern_node( - scope: &Rc, - pattern: Rc, - scrutinee_subject: &Rc, - scrutinee_provenance: Rc, -) -> Rc { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*pattern).clone() { - MatchPattern::Bind { name: n, .. } => Rc::new(PatternScopeResult { - scope: extend_scope_match_bound( - &scope, - &n, - pattern_binding_type(scrutinee_subject.clone()), - scrutinee_provenance.clone(), - ), - diagnostics: Rc::new(vec![]), - }), - MatchPattern::Wildcard => Rc::new(PatternScopeResult { - scope: scope.clone(), - diagnostics: Rc::new(vec![]), - }), - MatchPattern::LitPattern { .. } => Rc::new(PatternScopeResult { - scope: scope.clone(), - diagnostics: Rc::new(vec![]), - }), - MatchPattern::VariantPattern { - name: vname, - field_bindings: bindings, - .. - } => { +pub fn extend_scope_with_pattern_node(scope: &Rc, pattern: Rc, scrutinee_subject: &Rc, scrutinee_provenance: Rc) -> Rc { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*pattern).clone() { + MatchPattern::Bind { name: n, .. } => Rc::new(PatternScopeResult { + scope: extend_scope_match_bound(&scope, &n, pattern_binding_type(scrutinee_subject.clone()), scrutinee_provenance.clone()), + diagnostics: Rc::new(vec![]), +}), + MatchPattern::Wildcard => Rc::new(PatternScopeResult { + scope: scope.clone(), + diagnostics: Rc::new(vec![]), +}), + MatchPattern::LitPattern { .. } => Rc::new(PatternScopeResult { + scope: scope.clone(), + diagnostics: Rc::new(vec![]), +}), + MatchPattern::VariantPattern { name: vname, field_bindings: bindings, .. } => { let resolved_scrut = resolve_pattern_subject(scope.clone(), scrutinee_subject.clone()); - let variant_lookup = lookup_variant_in_type( - resolved_scrut, - &vname, - scope.module_name.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let variant_subject = lookup_result_subject(variant_lookup.clone()); - let variant_diags = variant_lookup.diagnostics.clone(); - bindings.clone().iter().cloned().fold( - Rc::new(PatternScopeResult { - scope: scope.clone(), - diagnostics: variant_diags, - }), - |acc: Rc, fb: Rc| { - let field_name = field_binding_name_at( - fb.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let field_lookup = lookup_field_in_variant( - variant_subject.clone(), - &field_name, - scope.module_name.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let field_subject = lookup_result_subject(field_lookup.clone()); - let field_type = pattern_binding_type(field_subject.clone()); - let field_provenance = derive_field_provenance( - &scope, - &scrutinee_provenance, - scrutinee_subject.clone(), - vname.clone(), - field_name.clone(), - ); - let fb_pattern = field_binding_pattern(fb.clone()); - match (*fb_pattern.clone()).clone() { - MatchPattern::Bind { name: n, .. } => Rc::new(PatternScopeResult { - scope: extend_scope_match_bound( - &acc.scope.clone(), - &n, - field_type.clone(), - field_provenance.clone(), - ), - diagnostics: v2_rt::concat( - acc.diagnostics.clone(), - field_lookup.diagnostics.clone(), - ), - }), - _ => { - let nested = extend_scope_with_pattern_node( - &acc.scope.clone(), - fb_pattern.clone(), - &field_subject, - field_provenance.clone(), - ); - Rc::new(PatternScopeResult { - scope: nested.scope.clone(), - diagnostics: v2_rt::concat( - acc.diagnostics.clone(), - v2_rt::concat( - field_lookup.diagnostics.clone(), - nested.diagnostics.clone(), - ), - ), - }) - } - } - }, - ) - } +let variant_lookup = lookup_variant_in_type(resolved_scrut, &vname, scope.module_name.clone(), &scope.type_env.clone().source_indices.clone()); +let variant_subject = lookup_result_subject(variant_lookup.clone()); +let variant_diags = variant_lookup.diagnostics.clone(); +bindings.clone().iter().cloned().fold(Rc::new(PatternScopeResult { + scope: scope.clone(), + diagnostics: variant_diags, +}), |acc: Rc, fb: Rc| { + let field_name = field_binding_name_at(fb.clone(), scope.type_env.clone().source_indices.clone()); +let field_lookup = lookup_field_in_variant(variant_subject.clone(), &field_name, scope.module_name.clone(), &scope.type_env.clone().source_indices.clone()); +let field_subject = lookup_result_subject(field_lookup.clone()); +let field_type = pattern_binding_type(field_subject.clone()); +let field_provenance = derive_field_provenance(&scope, &scrutinee_provenance, scrutinee_subject.clone(), vname.clone(), field_name.clone()); +let fb_pattern = field_binding_pattern(fb.clone()); +match (*fb_pattern.clone()).clone() { + MatchPattern::Bind { name: n, .. } => Rc::new(PatternScopeResult { + scope: extend_scope_match_bound(&acc.scope.clone(), &n, field_type.clone(), field_provenance.clone()), + diagnostics: v2_rt::concat(acc.diagnostics.clone(), field_lookup.diagnostics.clone()), +}), + _ => { + let nested = extend_scope_with_pattern_node(&acc.scope.clone(), fb_pattern.clone(), &field_subject, field_provenance.clone()); +Rc::new(PatternScopeResult { + scope: nested.scope.clone(), + diagnostics: v2_rt::concat(acc.diagnostics.clone(), v2_rt::concat(field_lookup.diagnostics.clone(), nested.diagnostics.clone())), +}) +}, +} +}) +}, +} }) } @@ -1620,298 +1022,164 @@ pub fn method_name_is(opt: &Option, expected: String) -> bool { } } -pub fn arg_has_name( - arg: Rc, - name: String, - source_indices: Rc>>, -) -> bool { +pub fn arg_has_name(arg: Rc, name: String, source_indices: Rc>>) -> bool { { let n = arg_name_at(arg, source_indices); - if (n.clone() == None) { +if (n.clone() == None) { false } else { (n.clone().unwrap().as_str() == name.as_str()) } - } +} } -pub fn extract_fold_init_info( - method_name: Option, - method_args: &Rc>>, - min_args: i64, - scope: &Rc, - expected: Option>, -) -> Option> { +pub fn extract_fold_init_info(method_name: Option, method_args: &Rc>>, min_args: i64, scope: &Rc, expected: Option>) -> Option> { { let is_fold = method_name_is(&method_name, "fold".to_string()); - if (is_fold && ((method_args.clone().len() as i64) >= min_args)) { +if (is_fold && ((method_args.clone().len() as i64) >= min_args)) { { - let init_arg = match Rc::new({ - let mut __result = Vec::new(); - for a in method_args.clone().iter().cloned() { - if arg_has_name( - a.clone(), - "init".to_string(), - scope.type_env.clone().source_indices.clone(), - ) { - __result.push(a); - } - } - __result - }) - .first() - .cloned() - { - Some(a) => Some(a.clone()), - None => method_args.clone().first().cloned(), - }; - match init_arg { - Some(ia) => { - let init_result = infer_expr(&arg_value(&ia), &scope, &expected); - Some(Rc::new(ArgInferResult { - typed_arg: make_arg_node( - arg_name_at( - ia.clone(), - scope.type_env.clone().source_indices.clone(), - ), - init_result.typed.clone(), - ia.span.clone(), - ia.span.clone(), - ), - diagnostics: init_result.diagnostics.clone(), - })) - } - None => None, - } - } + let init_arg = match Rc::new({ let mut __result = Vec::new(); for a in method_args.clone().iter().cloned() { if arg_has_name(a.clone(), "init".to_string(), scope.type_env.clone().source_indices.clone()) { __result.push(a); } } __result }).first().cloned() { + Some(a) => Some(a.clone()), + None => method_args.clone().first().cloned(), +}; +match init_arg { + Some(ia) => { + let init_result = infer_expr(&arg_value(&ia), &scope, &expected); +Some(Rc::new(ArgInferResult { + typed_arg: make_arg_node(arg_name_at(ia.clone(), scope.type_env.clone().source_indices.clone()), init_result.typed.clone(), ia.span.clone(), ia.span.clone()), + diagnostics: init_result.diagnostics.clone(), +})) +}, + None => None, +} +} } else { None } - } +} } -pub fn derive_element_provenance( - coll_expr: Rc, - elem_type: &Rc, - scope: &Rc, -) -> Rc { +pub fn derive_element_provenance(coll_expr: Rc, elem_type: &Rc, scope: &Rc) -> Rc { { let coll_prov = classify_binding_provenance(&coll_expr, &scope); - match (*coll_prov).clone() { - SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), - _ => { - if (authored_name_at(scope.type_env.clone().source_indices.clone(), &elem_type) - .as_str() - == "".to_string().as_str()) - { - Rc::new(SubValueRelation::SubValueUnknown) - } else { - { - let ind_fields = inductive_fields_for( - scope.type_env.clone(), - authored_name_at( - scope.type_env.clone().source_indices.clone(), - &elem_type, - ), - ); - let list_field = Rc::new({ - let mut __result = Vec::new(); - for f in ind_fields.iter().cloned() { - if match f.shape.clone() { - RecursionShape::ListRecursion => true, - _ => false, - } { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match list_field { - Some(f) => { - Rc::new(SubValueRelation::IteratedSubValue { field: f.clone() }) - } - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - } - } - } - } +match (*coll_prov).clone() { + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), + _ => if (authored_name_at(scope.type_env.clone().source_indices.clone(), &elem_type).as_str() == "".to_string().as_str()) { + Rc::new(SubValueRelation::SubValueUnknown) + } else { + { + let ind_fields = inductive_fields_for(scope.type_env.clone(), authored_name_at(scope.type_env.clone().source_indices.clone(), &elem_type)); +let list_field = Rc::new({ let mut __result = Vec::new(); for f in ind_fields.iter().cloned() { if match f.shape.clone() { + RecursionShape::ListRecursion => true, + _ => false, +} { __result.push(f); } } __result }).first().cloned(); +match list_field { + Some(f) => Rc::new(SubValueRelation::IteratedSubValue { + field: f.clone(), +}), + None => Rc::new(SubValueRelation::SubValueUnknown), +} +} + }, +} +} } -pub fn infer_method_args_with_fold( - method_name: Option, - method_args: Rc>>, - fold_info: Option>, - fold_acc_type: Rc, - element_type: Rc, - elem_provenance: Rc, - scope: Rc, -) -> Rc>> { +pub fn infer_method_args_with_fold(method_name: Option, method_args: Rc>>, fold_info: Option>, fold_acc_type: Rc, element_type: Rc, elem_provenance: Rc, scope: Rc) -> Rc>> { { let is_fold = method_name_is(&method_name, "fold".to_string()); - Rc::new({ - let mut __result = Vec::new(); - for idx_pair in Rc::new( - method_args - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let a = idx_pair.1.clone(); - let idx = idx_pair.0.clone(); - let is_init_arg = (arg_has_name( - a.clone(), - "init".to_string(), - scope.type_env.clone().source_indices.clone(), - ) || ((arg_name_at( - a.clone(), - scope.type_env.clone().source_indices.clone(), - ) == None) - && (idx.clone() == 0))); - if ((is_fold.clone() && (fold_info.clone() != None)) && is_init_arg.clone()) { - match fold_info.clone() { - Some(fi) => fi.clone(), - None => infer_arg_with_element_type(&a, element_type.clone(), &scope), - } - } else { - if (is_fold.clone() && (fold_info.clone() != None)) { - { - let fold_params = Rc::new(vec![ - make_param_node( - &"acc".to_string(), - fold_acc_type.clone(), - None, - no_span(), - no_span(), - ), - make_param_node( - &"elem".to_string(), - element_type.clone(), - None, - no_span(), - no_span(), - ), - ]); - let fold_callable = Rc::new(Node { - name: "".to_string(), - span: no_span(), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: fold_params.clone(), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let lam_value = arg_value(&a); - let prov_map = match (*elem_provenance.clone()).clone() { - SubValueRelation::SubValueUnknown => { - v2_rt::rc_empty_map::>() - } - _ => v2_rt::rc_map_insert( - v2_rt::rc_empty_map::>(), - "elem".to_string(), - elem_provenance.clone(), - ), - }; - let fold_scope = Rc::new(InferScope { - type_env: scope.type_env.clone(), - func_env: scope.func_env.clone(), - locals: scope.locals.clone(), - match_bound_names: scope.match_bound_names.clone(), - module_name: scope.module_name.clone(), - service_registry: scope.service_registry.clone(), - item_registry: scope.item_registry.clone(), - lambda_param_provenance: prov_map.clone(), - }); - let ar = infer_expr( - &lam_value, - &fold_scope, - &Some(fold_callable.clone()), - ); - Rc::new(ArgInferResult { - typed_arg: make_arg_node( - arg_name_at( - a.clone(), - scope.type_env.clone().source_indices.clone(), - ), - ar.typed.clone(), - a.span.clone(), - a.span.clone(), - ), - diagnostics: ar.diagnostics.clone(), - }) - } +Rc::new({ let mut __result = Vec::new(); for idx_pair in Rc::new(method_args.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let a = idx_pair.1.clone(); +let idx = idx_pair.0.clone(); +let is_init_arg = (arg_has_name(a.clone(), "init".to_string(), scope.type_env.clone().source_indices.clone()) || ((arg_name_at(a.clone(), scope.type_env.clone().source_indices.clone()) == None) && (idx.clone() == 0))); +if ((is_fold.clone() && (fold_info.clone() != None)) && is_init_arg.clone()) { + match fold_info.clone() { + Some(fi) => fi.clone(), + None => infer_arg_with_element_type(&a, element_type.clone(), &scope), +} + } else { + if (is_fold.clone() && (fold_info.clone() != None)) { + { + let fold_params = Rc::new(vec![make_param_node(&"acc".to_string(), fold_acc_type.clone(), None, no_span(), no_span()), make_param_node(&"elem".to_string(), element_type.clone(), None, no_span(), no_span())]); +let fold_callable = Rc::new(Node { + name: "".to_string(), + span: no_span(), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: fold_params.clone(), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let lam_value = arg_value(&a); +let prov_map = match (*elem_provenance.clone()).clone() { + SubValueRelation::SubValueUnknown => v2_rt::rc_empty_map::>(), + _ => v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), "elem".to_string(), elem_provenance.clone()), +}; +let fold_scope = Rc::new(InferScope { + type_env: scope.type_env.clone(), + func_env: scope.func_env.clone(), + locals: scope.locals.clone(), + match_bound_names: scope.match_bound_names.clone(), + module_name: scope.module_name.clone(), + service_registry: scope.service_registry.clone(), + item_registry: scope.item_registry.clone(), + lambda_param_provenance: prov_map.clone(), +}); +let ar = infer_expr(&lam_value, &fold_scope, &Some(fold_callable.clone())); +Rc::new(ArgInferResult { + typed_arg: make_arg_node(arg_name_at(a.clone(), scope.type_env.clone().source_indices.clone()), ar.typed.clone(), a.span.clone(), a.span.clone()), + diagnostics: ar.diagnostics.clone(), +}) +} + } else { + { + let nf_lam_value = arg_value(&a); +let nf_prov_map = match (*elem_provenance.clone()).clone() { + SubValueRelation::SubValueUnknown => v2_rt::rc_empty_map::>(), + _ => v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), "elem".to_string(), elem_provenance.clone()), +}; +let nf_scope = if is_lambda_expr(nf_lam_value.clone()) { + Rc::new(InferScope { + type_env: scope.type_env.clone(), + func_env: scope.func_env.clone(), + locals: scope.locals.clone(), + match_bound_names: scope.match_bound_names.clone(), + module_name: scope.module_name.clone(), + service_registry: scope.service_registry.clone(), + item_registry: scope.item_registry.clone(), + lambda_param_provenance: nf_prov_map.clone(), +}) } else { - { - let nf_lam_value = arg_value(&a); - let nf_prov_map = match (*elem_provenance.clone()).clone() { - SubValueRelation::SubValueUnknown => { - v2_rt::rc_empty_map::>() - } - _ => v2_rt::rc_map_insert( - v2_rt::rc_empty_map::>(), - "elem".to_string(), - elem_provenance.clone(), - ), - }; - let nf_scope = if is_lambda_expr(nf_lam_value.clone()) { - Rc::new(InferScope { - type_env: scope.type_env.clone(), - func_env: scope.func_env.clone(), - locals: scope.locals.clone(), - match_bound_names: scope.match_bound_names.clone(), - module_name: scope.module_name.clone(), - service_registry: scope.service_registry.clone(), - item_registry: scope.item_registry.clone(), - lambda_param_provenance: nf_prov_map.clone(), - }) - } else { - scope.clone() - }; - infer_arg_with_element_type(&a, element_type.clone(), &nf_scope) - } - } - } - }); + scope.clone() + }; +infer_arg_with_element_type(&a, element_type.clone(), &nf_scope) +} + } } - __result - }) - } +}); } __result }) +} } pub fn is_lambda_expr(e: Rc) -> bool { match (*e.expr_data.clone()).clone() { - ExprData::ExprLambda => true, - _ => false, - } + ExprData::ExprLambda => true, + _ => false, +} } pub fn seed_override_map() -> Rc>> { - Rc::new(vec!["".to_string()]).iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, k: String| { - v2_rt::rc_map_insert(acc, k.clone(), unit_type()) - }, - ) + Rc::new(vec!["".to_string()]).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, k: String| v2_rt::rc_map_insert(acc, k.clone(), unit_type())) } pub fn fold_override_map(key: String, value: Rc) -> Rc>> { @@ -1922,704 +1190,355 @@ pub fn empty_override_map() -> Rc>> { seed_override_map() } -pub fn infer_arg_with_element_type( - arg: &Rc, - element_type: Rc, - scope: &Rc, -) -> Rc { +pub fn infer_arg_with_element_type(arg: &Rc, element_type: Rc, scope: &Rc) -> Rc { { let ar = infer_expr(&arg_value(&arg), &scope, &Some(element_type)); - Rc::new(ArgInferResult { - typed_arg: make_arg_node( - arg_name_at(arg.clone(), scope.type_env.clone().source_indices.clone()), - ar.typed.clone(), - arg.span.clone(), - arg.span.clone(), - ), - diagnostics: ar.diagnostics.clone(), - }) - } +Rc::new(ArgInferResult { + typed_arg: make_arg_node(arg_name_at(arg.clone(), scope.type_env.clone().source_indices.clone()), ar.typed.clone(), arg.span.clone(), arg.span.clone()), + diagnostics: ar.diagnostics.clone(), +}) +} } -pub fn infer_expr( - texpr: &Rc, - scope: &Rc, - expected: &Option>, -) -> Rc { +pub fn infer_expr(texpr: &Rc, scope: &Rc, expected: &Option>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: lit, .. } => { - let span = texpr.span.clone(); - ok_infer(make_expr_node( - Rc::new(ExprData::ExprLiteral { value: lit.clone() }), - Rc::new(vec![]), - Some(Rc::new(InferredNode::Resolved { - node: infer_literal_node(lit.clone()), - })), - span.clone(), - )) - } - ExprData::ExprError { kind, message, .. } => { - let span = texpr.span.clone(); + ExprData::ExprLiteral { value: lit, .. } => { + let span = texpr.span.clone(); +ok_infer(make_expr_node(Rc::new(ExprData::ExprLiteral { + value: lit.clone(), +}), Rc::new(vec![]), Some(Rc::new(InferredNode::Resolved { + node: infer_literal_node(lit.clone()), +})), span.clone())) +}, + ExprData::ExprError { kind, message, .. } => { + let span = texpr.span.clone(); +Rc::new(InferResult { + typed: make_expr_error_node(kind.clone(), &message, &span), + diagnostics: Rc::new(vec![]), +}) +}, + ExprData::ExprVar { .. } => { + let name = expr_var_name_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); +let span = texpr.span.clone(); +match v2_rt::map_get(&scope.locals.clone(), name.clone()) { + Some(binding) => { + let binding_kind = infer_var_binding_kind(&scope, &name); +ok_infer(make_named_expr_node(&name, Rc::new(ExprData::ExprVar { + binding_kind: Some(binding_kind), +}), Rc::new(vec![]), Some(Rc::new(InferredNode::Resolved { + node: binding.resolved.clone(), +})), span.clone(), span.clone())) +}, + None => match lookup_func_sig(scope.func_env.clone(), name.clone()) { + Some(fsig) => if ((fsig.params.clone().len() as i64) == 0) { + ok_infer(make_named_expr_node(&name, Rc::new(ExprData::ExprCall { + call_semantics: Some(CallSemantics::PlainCallSemantics), + descent_evidence: None, +}), Rc::new(vec![]), Some(Rc::new(InferredNode::Resolved { + node: fsig.inferred.clone(), +})), span.clone(), span.clone())) + } else { + ok_infer(make_named_expr_node(&name, Rc::new(ExprData::ExprVar { + binding_kind: Some(Rc::new(VarBindingKind::FunctionValueBinding)), +}), Rc::new(vec![]), Some(Rc::new(InferredNode::Resolved { + node: resolved_callable_type(fsig.params.clone(), fsig.inferred.clone()), +})), span.clone(), span.clone())) + }, + None => { + let err_texpr = make_named_expr_node(&name, Rc::new(ExprData::ExprVar { + binding_kind: None, +}), Rc::new(vec![]), Some(Rc::new(InferredNode::Resolved { + node: error_type(), +})), span.clone(), span.clone()); +Rc::new(InferResult { + typed: err_texpr, + diagnostics: Rc::new(vec![inference_error(v2_rt::concat(v2_rt::concat("undefined variable '".to_string(), name.clone()), "'".to_string()), span.clone(), scope.module_name.clone())]), +}) +}, +}, +} +}, + ExprData::ExprFieldAccess { .. } => { + let field_name = field_access_field_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); +let span = texpr.span.clone(); +let base_expr = field_access_base(texpr.clone()); +let base_result = infer_expr(&base_expr, &scope, &None); +let base_typed = base_result.typed.clone(); +let base_diags = base_result.diagnostics.clone(); +let base_rt = resolved_type(base_typed.clone()); +let resolved_base = resolve_scrutinee_type_node(scope.type_env.clone(), base_rt.clone()); +let resolved_base_is_error = if (resolved_base.inferred.clone() != None) { + is_compiler_error(resolved_base.inferred.clone().clone().unwrap()) + } else { + false + }; +if resolved_base_is_error { Rc::new(InferResult { - typed: make_expr_error_node(kind.clone(), &message, &span), - diagnostics: Rc::new(vec![]), - }) - } - ExprData::ExprVar { .. } => { - let name = - expr_var_name_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); - let span = texpr.span.clone(); - match v2_rt::map_get(&scope.locals.clone(), name.clone()) { - Some(binding) => { - let binding_kind = infer_var_binding_kind(&scope, &name); - ok_infer(make_named_expr_node( - &name, - Rc::new(ExprData::ExprVar { - binding_kind: Some(binding_kind), - }), - Rc::new(vec![]), - Some(Rc::new(InferredNode::Resolved { - node: binding.resolved.clone(), - })), - span.clone(), - span.clone(), - )) + typed: make_expr_error_node(ExprErrorKind::SemanticExprError, &"error type cascade".to_string(), &span), + diagnostics: base_diags, +}) + } else { + match lookup_field_type_node(&resolved_base, &field_name, scope.type_env.clone().source_indices.clone()) { + Some(field_type) => { + let field_summary = field_summary_for_type(base_rt.clone(), &scope.type_env.clone(), &field_name); +let fa_texpr = make_named_expr_node(&field_name, Rc::new(ExprData::ExprFieldAccess { + summary: field_summary, +}), Rc::new(vec![base_typed.clone()]), Some(Rc::new(InferredNode::Resolved { + node: field_type.clone(), +})), span.clone(), node_name_span(&texpr)); +Rc::new(InferResult { + typed: fa_texpr, + diagnostics: base_diags, +}) +}, + None => { + let base_is_type_var = if (resolved_base.inferred.clone() != None) { + is_type_variable(resolved_base.inferred.clone().clone().unwrap()) + } else { + false + }; +if base_is_type_var { + { + let fa_texpr = make_named_expr_node(&field_name, Rc::new(ExprData::ExprFieldAccess { + summary: Some(Rc::new(FieldSummary { + access_style: FieldAccessStyle::StoredField, + value_shape: FieldValueShape::PlainValue, +})), +}), Rc::new(vec![base_typed.clone()]), Some(Rc::new(InferredNode::TypeVariable { + id: "field_of_type_var".to_string(), +})), span.clone(), node_name_span(&texpr)); +Rc::new(InferResult { + typed: fa_texpr, + diagnostics: base_diags, +}) +} + } else { + match check_service_field_access_node(&base_rt, field_name.clone(), scope.service_registry.clone(), scope.type_env.clone().source_indices.clone()) { + Some(svc_type) => { + let fa_texpr = make_named_expr_node(&field_name, Rc::new(ExprData::ExprFieldAccess { + summary: Some(Rc::new(FieldSummary { + access_style: FieldAccessStyle::StoredField, + value_shape: FieldValueShape::PlainValue, +})), +}), Rc::new(vec![base_typed.clone()]), Some(Rc::new(InferredNode::Resolved { + node: svc_type.clone(), +})), span.clone(), node_name_span(&texpr)); +Rc::new(InferResult { + typed: fa_texpr, + diagnostics: base_diags, +}) +}, + None => { + let error_message = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("no field '".to_string(), field_name.clone()), "' on type '".to_string()), authored_name_at(scope.type_env.clone().source_indices.clone(), &resolved_base)), "'".to_string()); +let fa_texpr = make_expr_error_node(ExprErrorKind::SemanticExprError, &error_message, &span); +Rc::new(InferResult { + typed: fa_texpr, + diagnostics: v2_rt::concat(base_diags, Rc::new(vec![inference_error(error_message.clone(), span.clone(), scope.module_name.clone())])), +}) +}, +} } - None => match lookup_func_sig(scope.func_env.clone(), name.clone()) { - Some(fsig) => { - if ((fsig.params.clone().len() as i64) == 0) { - ok_infer(make_named_expr_node( - &name, - Rc::new(ExprData::ExprCall { - call_semantics: Some(CallSemantics::PlainCallSemantics), - descent_evidence: None, - }), - Rc::new(vec![]), - Some(Rc::new(InferredNode::Resolved { - node: fsig.inferred.clone(), - })), - span.clone(), - span.clone(), - )) - } else { - ok_infer(make_named_expr_node( - &name, - Rc::new(ExprData::ExprVar { - binding_kind: Some(Rc::new( - VarBindingKind::FunctionValueBinding, - )), - }), - Rc::new(vec![]), - Some(Rc::new(InferredNode::Resolved { - node: resolved_callable_type( - fsig.params.clone(), - fsig.inferred.clone(), - ), - })), - span.clone(), - span.clone(), - )) - } - } - None => { - let err_texpr = make_named_expr_node( - &name, - Rc::new(ExprData::ExprVar { binding_kind: None }), - Rc::new(vec![]), - Some(Rc::new(InferredNode::Resolved { node: error_type() })), - span.clone(), - span.clone(), - ); - Rc::new(InferResult { - typed: err_texpr, - diagnostics: Rc::new(vec![inference_error( - v2_rt::concat( - v2_rt::concat( - "undefined variable '".to_string(), - name.clone(), - ), - "'".to_string(), - ), - span.clone(), - scope.module_name.clone(), - )]), - }) - } - }, - } +}, +} } - ExprData::ExprFieldAccess { .. } => { - let field_name = field_access_field_at( - texpr.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let span = texpr.span.clone(); - let base_expr = field_access_base(texpr.clone()); - let base_result = infer_expr(&base_expr, &scope, &None); - let base_typed = base_result.typed.clone(); - let base_diags = base_result.diagnostics.clone(); - let base_rt = resolved_type(base_typed.clone()); - let resolved_base = - resolve_scrutinee_type_node(scope.type_env.clone(), base_rt.clone()); - let resolved_base_is_error = if (resolved_base.inferred.clone() != None) { - is_compiler_error(resolved_base.inferred.clone().clone().unwrap()) - } else { - false - }; - if resolved_base_is_error { - Rc::new(InferResult { - typed: make_expr_error_node( - ExprErrorKind::SemanticExprError, - &"error type cascade".to_string(), - &span, - ), - diagnostics: base_diags, - }) - } else { - match lookup_field_type_node( - &resolved_base, - &field_name, - scope.type_env.clone().source_indices.clone(), - ) { - Some(field_type) => { - let field_summary = field_summary_for_type( - base_rt.clone(), - &scope.type_env.clone(), - &field_name, - ); - let fa_texpr = make_named_expr_node( - &field_name, - Rc::new(ExprData::ExprFieldAccess { - summary: field_summary, - }), - Rc::new(vec![base_typed.clone()]), - Some(Rc::new(InferredNode::Resolved { - node: field_type.clone(), - })), - span.clone(), - node_name_span(&texpr), - ); - Rc::new(InferResult { - typed: fa_texpr, - diagnostics: base_diags, - }) - } - None => { - let base_is_type_var = if (resolved_base.inferred.clone() != None) { - is_type_variable(resolved_base.inferred.clone().clone().unwrap()) - } else { - false - }; - if base_is_type_var { - { - let fa_texpr = make_named_expr_node( - &field_name, - Rc::new(ExprData::ExprFieldAccess { - summary: Some(Rc::new(FieldSummary { - access_style: FieldAccessStyle::StoredField, - value_shape: FieldValueShape::PlainValue, - })), - }), - Rc::new(vec![base_typed.clone()]), - Some(Rc::new(InferredNode::TypeVariable { - id: "field_of_type_var".to_string(), - })), - span.clone(), - node_name_span(&texpr), - ); - Rc::new(InferResult { - typed: fa_texpr, - diagnostics: base_diags, - }) - } - } else { - match check_service_field_access_node( - &base_rt, - field_name.clone(), - scope.service_registry.clone(), - scope.type_env.clone().source_indices.clone(), - ) { - Some(svc_type) => { - let fa_texpr = make_named_expr_node( - &field_name, - Rc::new(ExprData::ExprFieldAccess { - summary: Some(Rc::new(FieldSummary { - access_style: FieldAccessStyle::StoredField, - value_shape: FieldValueShape::PlainValue, - })), - }), - Rc::new(vec![base_typed.clone()]), - Some(Rc::new(InferredNode::Resolved { - node: svc_type.clone(), - })), - span.clone(), - node_name_span(&texpr), - ); - Rc::new(InferResult { - typed: fa_texpr, - diagnostics: base_diags, - }) - } - None => { - let error_message = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "no field '".to_string(), - field_name.clone(), - ), - "' on type '".to_string(), - ), - authored_name_at( - scope.type_env.clone().source_indices.clone(), - &resolved_base, - ), - ), - "'".to_string(), - ); - let fa_texpr = make_expr_error_node( - ExprErrorKind::SemanticExprError, - &error_message, - &span, - ); - Rc::new(InferResult { - typed: fa_texpr, - diagnostics: v2_rt::concat( - base_diags, - Rc::new(vec![inference_error( - error_message.clone(), - span.clone(), - scope.module_name.clone(), - )]), - ), - }) - } - } - } - } - } - } - } - ExprData::ExprCall { .. } => { - let func_name = - expr_call_func_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); - let span = texpr.span.clone(); - let call_args = texpr.children.clone(); - let sig = lookup_func_sig(scope.func_env.clone(), func_name.clone()); - let sig_params = match sig.clone() { - Some(s) => s.params.clone(), - None => Rc::new(vec![]), - }; - let has_lambda = { - let mut __found = false; - for a in call_args.clone().iter().cloned() { - if is_lambda_expr(arg_value(&a)) { - __found = true; - break; - } - } - __found - }; - let call_method_args = Rc::new( - call_args - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let call_method_name = Some(func_name.clone()); - let call_fold_info = extract_fold_init_info( - call_method_name.clone(), - &call_method_args, - 2, - &scope, - expected.clone(), - ); - let call_fold_acc_type = match call_fold_info.clone() { - Some(fi) => resolved_type(arg_value(&fi.typed_arg.clone())), - None => error_type(), - }; - let arg_infer_results = if ((has_lambda && ((call_args.clone().len() as i64) >= 2)) - && (sig.clone() == None)) +}, + ExprData::ExprCall { .. } => { + let func_name = expr_call_func_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); +let span = texpr.span.clone(); +let call_args = texpr.children.clone(); +let sig = lookup_func_sig(scope.func_env.clone(), func_name.clone()); +let sig_params = match sig.clone() { + Some(s) => s.params.clone(), + None => Rc::new(vec![]), +}; +let has_lambda = { let mut __found = false; for a in call_args.clone().iter().cloned() { if is_lambda_expr(arg_value(&a)) { __found = true; break; } } __found }; +let call_method_args = Rc::new(call_args.clone().iter().cloned().skip(1 as usize).collect::>()); +let call_method_name = Some(func_name.clone()); +let call_fold_info = extract_fold_init_info(call_method_name.clone(), &call_method_args, 2, &scope, expected.clone()); +let call_fold_acc_type = match call_fold_info.clone() { + Some(fi) => resolved_type(arg_value(&fi.typed_arg.clone())), + None => error_type(), +}; +let arg_infer_results = if ((has_lambda && ((call_args.clone().len() as i64) >= 2)) && (sig.clone() == None)) { + match call_args.clone().first().cloned() { + Some(first_arg) => { + let first_result = infer_expr(&arg_value(&first_arg), &scope, &None); +let first_type = resolved_type(first_result.typed.clone()); +let elem_type = for_each_element_type_node(first_type, scope.type_env.clone().source_indices.clone()); +let call_elem_provenance = derive_element_provenance(first_result.typed.clone(), &elem_type, &scope); +let remaining_results = infer_method_args_with_fold(call_method_name.clone(), call_method_args.clone(), call_fold_info.clone(), call_fold_acc_type.clone(), elem_type.clone(), call_elem_provenance, scope.clone()); +v2_rt::concat(Rc::new(vec![Rc::new(ArgInferResult { + typed_arg: make_arg_node(arg_name_at(first_arg.clone(), scope.type_env.clone().source_indices.clone()), first_result.typed.clone(), first_arg.span.clone(), first_arg.span.clone()), + diagnostics: first_result.diagnostics.clone(), +})]), remaining_results) +}, + None => Rc::new(vec![]), +} + } else { + Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(call_args.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let a = pair.1.clone(); +let formal_param_type = match sig_params.clone().get(pair.0.clone() as usize).cloned() { + Some(p) => param_node_type_expr(&p), + None => type_variable_node("callable_param".to_string()), +}; +let has_formal = match sig_params.clone().get(pair.0.clone() as usize).cloned() { + Some(_) => true, + None => false, +}; +let expected = if has_formal.clone() { + Some(formal_param_type.clone()) + } else { + None + }; +let ar = infer_expr(&arg_value(&a), &scope, &expected); +Rc::new(ArgInferResult { + typed_arg: make_arg_node(arg_name_at(a.clone(), scope.type_env.clone().source_indices.clone()), ar.typed.clone(), a.span.clone(), a.span.clone()), + diagnostics: ar.diagnostics.clone(), +}) +}); } __result }) + }; +let typed_args = Rc::new({ let mut __result = Vec::new(); for air in arg_infer_results.clone().iter().cloned() { __result.push(air.typed_arg.clone()); } __result }); +let arg_diags = Rc::new({ let mut __result = Vec::new(); for air in arg_infer_results.clone().iter().cloned() { __result.extend((*air.diagnostics.clone()).iter().cloned()); } __result }); +let typed_arg_nodes = typed_args.clone(); +if (sig.clone() != None) { { - match call_args.clone().first().cloned() { - Some(first_arg) => { - let first_result = infer_expr(&arg_value(&first_arg), &scope, &None); - let first_type = resolved_type(first_result.typed.clone()); - let elem_type = for_each_element_type_node( - first_type, - scope.type_env.clone().source_indices.clone(), - ); - let call_elem_provenance = derive_element_provenance( - first_result.typed.clone(), - &elem_type, - &scope, - ); - let remaining_results = infer_method_args_with_fold( - call_method_name.clone(), - call_method_args.clone(), - call_fold_info.clone(), - call_fold_acc_type.clone(), - elem_type.clone(), - call_elem_provenance, - scope.clone(), - ); - v2_rt::concat( - Rc::new(vec![Rc::new(ArgInferResult { - typed_arg: make_arg_node( - arg_name_at( - first_arg.clone(), - scope.type_env.clone().source_indices.clone(), - ), - first_result.typed.clone(), - first_arg.span.clone(), - first_arg.span.clone(), - ), - diagnostics: first_result.diagnostics.clone(), - })]), - remaining_results, - ) - } - None => Rc::new(vec![]), - } - } else { - Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - call_args - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() + let resolved_type = match sig.clone() { + Some(s) => s.inferred.clone(), + None => error_type(), +}; +Rc::new(InferResult { + typed: make_named_expr_node(&func_name, Rc::new(ExprData::ExprCall { + call_semantics: Some(CallSemantics::PlainCallSemantics), + descent_evidence: None, +}), typed_arg_nodes, Some(Rc::new(InferredNode::Resolved { + node: resolved_type, +})), span.clone(), node_name_span(&texpr)), + diagnostics: arg_diags, +}) +} + } else { + { + let first_arg_type = match typed_args.clone().first().cloned() { + Some(ta) => resolved_type(arg_value(&ta)), + None => unit_type(), +}; +let method_receiver = match typed_args.clone().first().cloned() { + Some(ta) => arg_value(&ta), + None => internal_expr_error_node("method bridge missing receiver".to_string(), span.clone()), +}; +let call_acc_is_under_resolved = !is_fully_resolved(&call_fold_acc_type, &scope.type_env.clone().source_indices.clone()); +let refined_call_fold_acc_type = if ((call_fold_info.clone() != None) && call_acc_is_under_resolved) { + match Rc::new({ let mut __result = Vec::new(); for a in typed_args.clone().iter().cloned() { if is_lambda_expr(arg_value(&a)) { __result.push(a); } } __result }).first().cloned() { + Some(lambda_arg) => resolved_type(arg_value(&lambda_arg)), + None => call_fold_acc_type.clone(), +} + } else { + call_fold_acc_type.clone() + }; +let method_resolution = resolve_known_method_node(method_receiver.clone(), &first_arg_type, &func_name, if (call_fold_info.clone() != None) { + Some(refined_call_fold_acc_type.clone()) + } else { + None + }, scope.service_registry.clone(), &scope.type_env.clone().source_indices.clone()); +let is_known_method = (method_resolution.result_type.clone() != None); +if (is_known_method && ((typed_args.clone().len() as i64) > 0)) { { - __result.push({ - let a = pair.1.clone(); - let formal_param_type = match sig_params - .clone() - .get(pair.0.clone() as usize) - .cloned() - { - Some(p) => param_node_type_expr(&p), - None => type_variable_node("callable_param".to_string()), - }; - let has_formal = match sig_params - .clone() - .get(pair.0.clone() as usize) - .cloned() - { - Some(_) => true, - None => false, - }; - let expected = if has_formal.clone() { - Some(formal_param_type.clone()) + let receiver = method_receiver.clone(); +let remaining = Rc::new(typed_args.clone().iter().cloned().skip(1 as usize).collect::>()); +let base_result_type = match method_resolution.result_type.clone() { + Some(mt) => mt.clone(), + None => error_type(), +}; +let method_tv = if (method_resolution.semantics.clone() == None) { + Rc::new(KernelTypeBuild { + ty: base_result_type.clone(), + diagnostics: Rc::new(vec![]), +}) + } else { + match (*method_resolution.semantics.clone().clone().unwrap()).clone() { + MethodSemantics::AlgebraMethodSemantics { algebra_template: at, .. } => match at.clone() { + Some(t) => if (template_return_has_variables(t.clone()) || !is_fully_resolved(&base_result_type, &scope.type_env.clone().source_indices.clone())) { + { + let call_arg_types = Rc::new({ let mut __result = Vec::new(); for a in remaining.clone().iter().cloned() { __result.push(resolved_type(arg_value(&a))); } __result }); +let fold_overrides = if (call_fold_info.clone() != None) { + fold_override_map("FoldAccumulator".to_string(), refined_call_fold_acc_type.clone()) + } else { + empty_override_map() + }; +resolve_type_variables_from_template(&t, call_arg_types, &first_arg_type, fold_overrides, &scope.type_env.clone().source_indices.clone()) +} } else { - None - }; - let ar = infer_expr(&arg_value(&a), &scope, &expected); - Rc::new(ArgInferResult { - typed_arg: make_arg_node( - arg_name_at( - a.clone(), - scope.type_env.clone().source_indices.clone(), - ), - ar.typed.clone(), - a.span.clone(), - a.span.clone(), - ), - diagnostics: ar.diagnostics.clone(), - }) - }); - } - __result - }) - }; - let typed_args = Rc::new({ - let mut __result = Vec::new(); - for air in arg_infer_results.clone().iter().cloned() { - __result.push(air.typed_arg.clone()); - } - __result - }); - let arg_diags = Rc::new({ - let mut __result = Vec::new(); - for air in arg_infer_results.clone().iter().cloned() { - __result.extend((*air.diagnostics.clone()).iter().cloned()); - } - __result - }); - let typed_arg_nodes = typed_args.clone(); - if (sig.clone() != None) { - { - let resolved_type = match sig.clone() { - Some(s) => s.inferred.clone(), - None => error_type(), - }; - Rc::new(InferResult { - typed: make_named_expr_node( - &func_name, - Rc::new(ExprData::ExprCall { - call_semantics: Some(CallSemantics::PlainCallSemantics), - descent_evidence: None, - }), - typed_arg_nodes, - Some(Rc::new(InferredNode::Resolved { - node: resolved_type, - })), - span.clone(), - node_name_span(&texpr), - ), - diagnostics: arg_diags, - }) - } - } else { - { - let first_arg_type = match typed_args.clone().first().cloned() { - Some(ta) => resolved_type(arg_value(&ta)), - None => unit_type(), - }; - let method_receiver = match typed_args.clone().first().cloned() { - Some(ta) => arg_value(&ta), - None => internal_expr_error_node( - "method bridge missing receiver".to_string(), - span.clone(), - ), - }; - let call_acc_is_under_resolved = !is_fully_resolved( - &call_fold_acc_type, - &scope.type_env.clone().source_indices.clone(), - ); - let refined_call_fold_acc_type = - if ((call_fold_info.clone() != None) && call_acc_is_under_resolved) { - match Rc::new({ - let mut __result = Vec::new(); - for a in typed_args.clone().iter().cloned() { - if is_lambda_expr(arg_value(&a)) { - __result.push(a); - } - } - __result - }) - .first() - .cloned() - { - Some(lambda_arg) => resolved_type(arg_value(&lambda_arg)), - None => call_fold_acc_type.clone(), - } + Rc::new(KernelTypeBuild { + ty: base_result_type.clone(), + diagnostics: Rc::new(vec![]), +}) + }, + None => Rc::new(KernelTypeBuild { + ty: base_result_type.clone(), + diagnostics: Rc::new(vec![]), +}), +}, + _ => Rc::new(KernelTypeBuild { + ty: base_result_type.clone(), + diagnostics: Rc::new(vec![]), +}), +} + }; +let bridge_result_type = method_tv.ty.clone(); +let template_subst_diags = method_tv.diagnostics.clone(); +let returns_receiver_self = if (method_resolution.semantics.clone() == None) { + false } else { - call_fold_acc_type.clone() + match (*method_resolution.semantics.clone().clone().unwrap()).clone() { + MethodSemantics::AlgebraMethodSemantics { algebra_template: at, .. } => match at.clone() { + Some(t) => template_return_is_receiver_self(t.clone()), + None => false, +}, + _ => false, +} }; - let method_resolution = resolve_known_method_node( - method_receiver.clone(), - &first_arg_type, - &func_name, - if (call_fold_info.clone() != None) { - Some(refined_call_fold_acc_type.clone()) +let final_receiver = if ((returns_receiver_self && is_fully_resolved(&bridge_result_type, &scope.type_env.clone().source_indices.clone())) && !is_fully_resolved(&first_arg_type, &scope.type_env.clone().source_indices.clone())) { + Rc::new(Node { + name: receiver.name.clone(), + span: receiver.span.clone(), + ident_span: receiver.ident_span.clone(), + children: bridge_result_type.children.clone(), + connective: receiver.connective.clone(), + params: receiver.params.clone(), + inferred: Some(Rc::new(InferredNode::Resolved { + node: bridge_result_type.clone(), +})), + return_cardinality: receiver.return_cardinality.clone(), + uses: receiver.uses.clone(), + body: receiver.body.clone(), + transport: receiver.transport.clone(), + properties: receiver.properties.clone(), + type_annotation: receiver.type_annotation.clone(), + is_self_recursive: receiver.is_self_recursive.clone(), + has_non_tail_self_call: receiver.has_non_tail_self_call.clone(), + match_pattern: receiver.match_pattern.clone(), + expr_data: receiver.expr_data.clone(), + ident: None, +}) } else { - None - }, - scope.service_registry.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let is_known_method = (method_resolution.result_type.clone() != None); - if (is_known_method && ((typed_args.clone().len() as i64) > 0)) { + receiver.clone() + }; +let remaining_arg_nodes = Rc::new({ let mut __result = Vec::new(); for ta in remaining.clone().iter().cloned() { __result.push(make_arg_node(arg_name_at(ta.clone(), scope.type_env.clone().source_indices.clone()), arg_value(&ta), span.clone(), span.clone())); } __result }); +Rc::new(InferResult { + typed: make_named_expr_node(&func_name, Rc::new(ExprData::ExprMethodCall { + method_semantics: method_resolution.semantics.clone(), +}), v2_rt::concat(Rc::new(vec![final_receiver]), remaining_arg_nodes), Some(Rc::new(InferredNode::Resolved { + node: bridge_result_type.clone(), +})), span.clone(), node_name_span(&texpr)), + diagnostics: v2_rt::concat(v2_rt::concat(arg_diags, method_resolution.diagnostics.clone()), template_subst_diags), +}) +} + } else { + if (func_name.clone().as_str() == "empty_map".to_string().as_str()) { { - let receiver = method_receiver.clone(); - let remaining = Rc::new( - typed_args - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let base_result_type = match method_resolution.result_type.clone() { - Some(mt) => mt.clone(), - None => error_type(), - }; - let method_tv = if (method_resolution.semantics.clone() == None) { - Rc::new(KernelTypeBuild { - ty: base_result_type.clone(), - diagnostics: Rc::new(vec![]), - }) - } else { - match (*method_resolution.semantics.clone().clone().unwrap()) - .clone() - { - MethodSemantics::AlgebraMethodSemantics { - algebra_template: at, - .. - } => match at.clone() { - Some(t) => { - if (template_return_has_variables(t.clone()) - || !is_fully_resolved( - &base_result_type, - &scope - .type_env - .clone() - .source_indices - .clone(), - )) - { - { - let call_arg_types = Rc::new({ - let mut __result = Vec::new(); - for a in - remaining.clone().iter().cloned() - { - __result.push(resolved_type( - arg_value(&a), - )); - } - __result - }); - let fold_overrides = - if (call_fold_info.clone() != None) { - fold_override_map( - "FoldAccumulator".to_string(), - refined_call_fold_acc_type - .clone(), - ) - } else { - empty_override_map() - }; - resolve_type_variables_from_template( - &t, - call_arg_types, - &first_arg_type, - fold_overrides, - &scope - .type_env - .clone() - .source_indices - .clone(), - ) - } - } else { - Rc::new(KernelTypeBuild { - ty: base_result_type.clone(), - diagnostics: Rc::new(vec![]), - }) - } - } - None => Rc::new(KernelTypeBuild { - ty: base_result_type.clone(), - diagnostics: Rc::new(vec![]), - }), - }, - _ => Rc::new(KernelTypeBuild { - ty: base_result_type.clone(), - diagnostics: Rc::new(vec![]), - }), - } - }; - let bridge_result_type = method_tv.ty.clone(); - let template_subst_diags = method_tv.diagnostics.clone(); - let returns_receiver_self = if (method_resolution.semantics.clone() - == None) - { - false - } else { - match (*method_resolution.semantics.clone().clone().unwrap()) - .clone() - { - MethodSemantics::AlgebraMethodSemantics { - algebra_template: at, - .. - } => match at.clone() { - Some(t) => template_return_is_receiver_self(t.clone()), - None => false, - }, - _ => false, - } - }; - let final_receiver = if ((returns_receiver_self - && is_fully_resolved( - &bridge_result_type, - &scope.type_env.clone().source_indices.clone(), - )) - && !is_fully_resolved( - &first_arg_type, - &scope.type_env.clone().source_indices.clone(), - )) { - Rc::new(Node { - name: receiver.name.clone(), - span: receiver.span.clone(), - ident_span: receiver.ident_span.clone(), - children: bridge_result_type.children.clone(), - connective: receiver.connective.clone(), - params: receiver.params.clone(), - inferred: Some(Rc::new(InferredNode::Resolved { - node: bridge_result_type.clone(), - })), - return_cardinality: receiver.return_cardinality.clone(), - uses: receiver.uses.clone(), - body: receiver.body.clone(), - transport: receiver.transport.clone(), - properties: receiver.properties.clone(), - type_annotation: receiver.type_annotation.clone(), - is_self_recursive: receiver.is_self_recursive.clone(), - has_non_tail_self_call: receiver - .has_non_tail_self_call - .clone(), - match_pattern: receiver.match_pattern.clone(), - expr_data: receiver.expr_data.clone(), - ident: None, - }) - } else { - receiver.clone() - }; - let remaining_arg_nodes = Rc::new({ - let mut __result = Vec::new(); - for ta in remaining.clone().iter().cloned() { - __result.push(make_arg_node( - arg_name_at( - ta.clone(), - scope.type_env.clone().source_indices.clone(), - ), - arg_value(&ta), - span.clone(), - span.clone(), - )); - } - __result - }); - Rc::new(InferResult { - typed: make_named_expr_node( - &func_name, - Rc::new(ExprData::ExprMethodCall { - method_semantics: method_resolution.semantics.clone(), - }), - v2_rt::concat( - Rc::new(vec![final_receiver]), - remaining_arg_nodes, - ), - Some(Rc::new(InferredNode::Resolved { - node: bridge_result_type.clone(), - })), - span.clone(), - node_name_span(&texpr), - ), - diagnostics: v2_rt::concat( - v2_rt::concat( - arg_diags, - method_resolution.diagnostics.clone(), - ), - template_subst_diags, - ), - }) - } - } else { - if (func_name.clone().as_str() == "empty_map".to_string().as_str()) { - { - let bare_m = bare_map_node(); - match expected.clone() { + let bare_m = bare_map_node(); +match expected.clone() { Some(exp) => if node_is_keyed_collection(&exp, scope.type_env.clone().source_indices.clone()) { Rc::new(InferResult { typed: make_named_expr_node(&func_name, Rc::new(ExprData::ExprCall { @@ -2678,1777 +1597,980 @@ match bare_m { }), }, } - } +} + } else { + if (infer_builtin_call_type(func_name.clone()) != None) { + { + let tier2b = infer_tier2b_builtin_with_kernel_diags(&func_name, typed_args.clone(), scope.clone(), 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) + }; +Rc::new(InferResult { + typed: make_named_expr_node(&func_name, Rc::new(ExprData::ExprCall { + call_semantics: call_semantics, + descent_evidence: None, +}), typed_arg_nodes, Some(Rc::new(InferredNode::Resolved { + node: bt, +})), span.clone(), node_name_span(&texpr)), + diagnostics: v2_rt::concat(arg_diags, tier2b.kernel_diags.clone()), +}) +} } else { - if (infer_builtin_call_type(func_name.clone()) != None) { - { - let tier2b = infer_tier2b_builtin_with_kernel_diags( - &func_name, - typed_args.clone(), - scope.clone(), - span.clone(), - ); - let bt = tier2b.bt.clone(); - let call_semantics = if (func_name.clone().as_str() - == "lookup".to_string().as_str()) + { + let callable_local = match v2_rt::map_get(&scope.locals.clone(), func_name.clone()) { + Some(binding) => if ((binding.resolved.clone().params.clone().len() as i64) > 0) { + Some(binding.resolved.clone()) + } else { + None + }, + None => None, +}; +if (callable_local.clone() != None) { { - Some(CallSemantics::LookupCallSemantics) - } else { - Some(CallSemantics::PlainCallSemantics) - }; - Rc::new(InferResult { - typed: make_named_expr_node( - &func_name, - Rc::new(ExprData::ExprCall { - call_semantics: call_semantics, - descent_evidence: None, - }), - typed_arg_nodes, - Some(Rc::new(InferredNode::Resolved { node: bt })), - span.clone(), - node_name_span(&texpr), - ), - diagnostics: v2_rt::concat( - arg_diags, - tier2b.kernel_diags.clone(), - ), - }) - } - } else { - { - let callable_local = match v2_rt::map_get( - &scope.locals.clone(), - func_name.clone(), - ) { - Some(binding) => { - if ((binding.resolved.clone().params.clone().len() - as i64) - > 0) - { - Some(binding.resolved.clone()) - } else { - None - } - } - None => None, - }; - if (callable_local.clone() != None) { - { - let callable_type = match callable_local.clone() { - Some(ct) => ct.clone(), - None => error_type(), - }; - let resolved_type = - callable_inferred(&callable_type); - Rc::new(InferResult { - typed: make_named_expr_node( - &func_name, - Rc::new(ExprData::ExprCall { - call_semantics: Some( - CallSemantics::PlainCallSemantics, - ), - descent_evidence: None, - }), - typed_arg_nodes, - Some(Rc::new(InferredNode::Resolved { - node: resolved_type, - })), - span.clone(), - node_name_span(&texpr), - ), - diagnostics: arg_diags, - }) - } - } else { - { - let type_match = lookup_type_by_name( - &scope.type_env.clone(), - func_name.clone(), - ); - let resolved_type = match type_match.clone() { - Some(tn) => tn.clone(), - None => error_type(), - }; - let call_diags = match type_match.clone() { - Some(_) => Rc::new(vec![]), - None => Rc::new(vec![inference_error( - v2_rt::concat( - v2_rt::concat( - "function '".to_string(), - func_name.clone(), - ), - "' not found in scope".to_string(), - ), - span.clone(), - scope.module_name.clone(), - )]), - }; - Rc::new(InferResult { - typed: make_named_expr_node( - &func_name, - Rc::new(ExprData::ExprCall { - call_semantics: Some( - CallSemantics::PlainCallSemantics, - ), - descent_evidence: None, - }), - typed_arg_nodes, - Some(Rc::new(InferredNode::Resolved { - node: resolved_type, - })), - span.clone(), - node_name_span(&texpr), - ), - diagnostics: v2_rt::concat( - arg_diags, call_diags, - ), - }) - } - } + let callable_type = match callable_local.clone() { + Some(ct) => ct.clone(), + None => error_type(), +}; +let resolved_type = callable_inferred(&callable_type); +Rc::new(InferResult { + typed: make_named_expr_node(&func_name, Rc::new(ExprData::ExprCall { + call_semantics: Some(CallSemantics::PlainCallSemantics), + descent_evidence: None, +}), typed_arg_nodes, Some(Rc::new(InferredNode::Resolved { + node: resolved_type, +})), span.clone(), node_name_span(&texpr)), + diagnostics: arg_diags, +}) +} + } else { + { + let type_match = lookup_type_by_name(&scope.type_env.clone(), func_name.clone()); +let resolved_type = match type_match.clone() { + Some(tn) => tn.clone(), + None => error_type(), +}; +let call_diags = match type_match.clone() { + Some(_) => Rc::new(vec![]), + None => Rc::new(vec![inference_error(v2_rt::concat(v2_rt::concat("function '".to_string(), func_name.clone()), "' not found in scope".to_string()), span.clone(), scope.module_name.clone())]), +}; +Rc::new(InferResult { + typed: make_named_expr_node(&func_name, Rc::new(ExprData::ExprCall { + call_semantics: Some(CallSemantics::PlainCallSemantics), + descent_evidence: None, +}), typed_arg_nodes, Some(Rc::new(InferredNode::Resolved { + node: resolved_type, +})), span.clone(), node_name_span(&texpr)), + diagnostics: v2_rt::concat(arg_diags, call_diags), +}) +} } - } +} } } } - } +} } - ExprData::ExprMethodCall { .. } => { - let method_name = expr_method_name_at( - texpr.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let span = texpr.span.clone(); - let recv = method_receiver(texpr.clone()); - let mc_args = method_arg_nodes(texpr.clone()); - let recv_result = infer_expr(&recv, &scope, &None); - let recv_typed = recv_result.typed.clone(); - let recv_diags = recv_result.diagnostics.clone(); - let recv_rt = resolved_type(recv_typed.clone()); - let recv_elem_type = for_each_element_type_node( - recv_rt.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let mc_method_name = Some(method_name.clone()); - let fold_info = extract_fold_init_info( - mc_method_name.clone(), - &mc_args, - 2, - &scope, - expected.clone(), - ); - let fold_acc_type = match fold_info.clone() { - Some(fi) => resolved_type(arg_value(&fi.typed_arg.clone())), - None => error_type(), - }; - let mc_elem_provenance = - derive_element_provenance(recv_typed.clone(), &recv_elem_type, &scope); - let mc_arg_infer_results = infer_method_args_with_fold( - mc_method_name.clone(), - mc_args.clone(), - fold_info.clone(), - fold_acc_type.clone(), - recv_elem_type.clone(), - mc_elem_provenance, - scope.clone(), - ); - let typed_mc_args = Rc::new({ - let mut __result = Vec::new(); - for air in mc_arg_infer_results.clone().iter().cloned() { - __result.push(air.typed_arg.clone()); - } - __result - }); - let mc_arg_diags = Rc::new({ - let mut __result = Vec::new(); - for air in mc_arg_infer_results.clone().iter().cloned() { - __result.extend((*air.diagnostics.clone()).iter().cloned()); - } - __result - }); - let mc_acc_is_under_resolved = !is_fully_resolved( - &fold_acc_type, - &scope.type_env.clone().source_indices.clone(), - ); - let refined_fold_acc_type = - if ((fold_info.clone() != None) && mc_acc_is_under_resolved) { - match Rc::new({ - let mut __result = Vec::new(); - for a in typed_mc_args.clone().iter().cloned() { - if is_lambda_expr(arg_value(&a)) { - __result.push(a); - } - } - __result - }) - .first() - .cloned() - { - Some(lambda_arg) => resolved_type(arg_value(&lambda_arg)), - None => fold_acc_type.clone(), - } - } else { - fold_acc_type.clone() - }; - let method_resolution = resolve_known_method_node( - recv_typed.clone(), - &recv_rt, - &method_name, - if (fold_info.clone() != None) { - Some(refined_fold_acc_type.clone()) - } else { - None - }, - scope.service_registry.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let pipe_fb = match method_resolution.result_type.clone() { - Some(rt) => Rc::new(MethodPipeFallback { - result_ty: rt.clone(), - kernel_diags: Rc::new(vec![]), - }), - None => method_pipe_map_keys_values_fallback( - &recv_rt, - &method_name, - scope.clone(), - span.clone(), - ), - }; - let base_result_type = pipe_fb.result_ty.clone(); - let method_tv_mc = if (method_resolution.semantics.clone() == None) { +}, + ExprData::ExprMethodCall { .. } => { + let method_name = expr_method_name_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); +let span = texpr.span.clone(); +let recv = method_receiver(texpr.clone()); +let mc_args = method_arg_nodes(texpr.clone()); +let recv_result = infer_expr(&recv, &scope, &None); +let recv_typed = recv_result.typed.clone(); +let recv_diags = recv_result.diagnostics.clone(); +let recv_rt = resolved_type(recv_typed.clone()); +let recv_elem_type = for_each_element_type_node(recv_rt.clone(), scope.type_env.clone().source_indices.clone()); +let mc_method_name = Some(method_name.clone()); +let fold_info = extract_fold_init_info(mc_method_name.clone(), &mc_args, 2, &scope, expected.clone()); +let fold_acc_type = match fold_info.clone() { + Some(fi) => resolved_type(arg_value(&fi.typed_arg.clone())), + None => error_type(), +}; +let mc_elem_provenance = derive_element_provenance(recv_typed.clone(), &recv_elem_type, &scope); +let mc_arg_infer_results = infer_method_args_with_fold(mc_method_name.clone(), mc_args.clone(), fold_info.clone(), fold_acc_type.clone(), recv_elem_type.clone(), mc_elem_provenance, scope.clone()); +let typed_mc_args = Rc::new({ let mut __result = Vec::new(); for air in mc_arg_infer_results.clone().iter().cloned() { __result.push(air.typed_arg.clone()); } __result }); +let mc_arg_diags = Rc::new({ let mut __result = Vec::new(); for air in mc_arg_infer_results.clone().iter().cloned() { __result.extend((*air.diagnostics.clone()).iter().cloned()); } __result }); +let mc_acc_is_under_resolved = !is_fully_resolved(&fold_acc_type, &scope.type_env.clone().source_indices.clone()); +let refined_fold_acc_type = if ((fold_info.clone() != None) && mc_acc_is_under_resolved) { + match Rc::new({ let mut __result = Vec::new(); for a in typed_mc_args.clone().iter().cloned() { if is_lambda_expr(arg_value(&a)) { __result.push(a); } } __result }).first().cloned() { + Some(lambda_arg) => resolved_type(arg_value(&lambda_arg)), + None => fold_acc_type.clone(), +} + } else { + fold_acc_type.clone() + }; +let method_resolution = resolve_known_method_node(recv_typed.clone(), &recv_rt, &method_name, if (fold_info.clone() != None) { + Some(refined_fold_acc_type.clone()) + } else { + None + }, scope.service_registry.clone(), &scope.type_env.clone().source_indices.clone()); +let pipe_fb = match method_resolution.result_type.clone() { + Some(rt) => Rc::new(MethodPipeFallback { + result_ty: rt.clone(), + kernel_diags: Rc::new(vec![]), +}), + None => method_pipe_map_keys_values_fallback(&recv_rt, &method_name, scope.clone(), span.clone()), +}; +let base_result_type = pipe_fb.result_ty.clone(); +let method_tv_mc = if (method_resolution.semantics.clone() == None) { + Rc::new(KernelTypeBuild { + ty: base_result_type.clone(), + diagnostics: Rc::new(vec![]), +}) + } else { + match (*method_resolution.semantics.clone().clone().unwrap()).clone() { + MethodSemantics::AlgebraMethodSemantics { algebra_template: at, .. } => match at.clone() { + Some(t) => if (template_return_has_variables(t.clone()) || !is_fully_resolved(&base_result_type, &scope.type_env.clone().source_indices.clone())) { + { + let mc_arg_types = Rc::new({ let mut __result = Vec::new(); for a in typed_mc_args.clone().iter().cloned() { __result.push(resolved_type(arg_value(&a))); } __result }); +let mc_fold_overrides = if (fold_info.clone() != None) { + fold_override_map("FoldAccumulator".to_string(), refined_fold_acc_type.clone()) + } else { + empty_override_map() + }; +resolve_type_variables_from_template(&t, mc_arg_types, &recv_rt, mc_fold_overrides, &scope.type_env.clone().source_indices.clone()) +} + } else { Rc::new(KernelTypeBuild { - ty: base_result_type.clone(), - diagnostics: Rc::new(vec![]), - }) + ty: base_result_type.clone(), + diagnostics: Rc::new(vec![]), +}) + }, + None => Rc::new(KernelTypeBuild { + ty: base_result_type.clone(), + diagnostics: Rc::new(vec![]), +}), +}, + _ => Rc::new(KernelTypeBuild { + ty: base_result_type.clone(), + diagnostics: Rc::new(vec![]), +}), +} + }; +let result_type = method_tv_mc.ty.clone(); +let mc_template_diags = method_tv_mc.diagnostics.clone(); +let method_semantics = if (method_resolution.semantics.clone() != None) { + method_resolution.semantics.clone() + } else { + Some(Rc::new(MethodSemantics::PlainMethodSemantics)) + }; +let typed_mc_arg_nodes = typed_mc_args.clone(); +let mc_texpr = make_named_expr_node(&method_name, Rc::new(ExprData::ExprMethodCall { + method_semantics: method_semantics, +}), v2_rt::concat(Rc::new(vec![recv_typed.clone()]), typed_mc_arg_nodes), Some(Rc::new(InferredNode::Resolved { + node: result_type, +})), span.clone(), node_name_span(&texpr)); +Rc::new(InferResult { + typed: mc_texpr, + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(recv_diags, mc_arg_diags), pipe_fb.kernel_diags.clone()), v2_rt::concat(method_resolution.diagnostics.clone(), mc_template_diags)), +}) +}, + ExprData::ExprMatch => { + let span = texpr.span.clone(); +let scrut = match_scrutinee(texpr.clone()); +let arm_nodes = match_arm_nodes(texpr.clone()); +let scrut_result = infer_expr(&scrut, &scope, &None); +let scrut_typed = scrut_result.typed.clone(); +let scrut_diags = scrut_result.diagnostics.clone(); +let scrut_rt = resolved_type(scrut_typed.clone()); +let scrut_subject = pattern_subject_from_inferred(scrut_typed.inferred.clone()); +let scrut_provenance = classify_binding_provenance(&scrut, &scope); +let arm_infer_results = Rc::new({ let mut __result = Vec::new(); for arm_node in arm_nodes.clone().iter().cloned() { __result.push({ + let arm_pat = arm_pattern(arm_node.clone()); +let arm_g = arm_guard(&arm_node); +let arm_b = arm_body(&arm_node); +let typed_pattern = annotate_pattern_parent_enums(arm_pat.clone(), scrut_subject.clone(), &scope); +let pattern_result = extend_scope_with_pattern_node(&scope, typed_pattern.clone(), &scrut_subject, scrut_provenance.clone()); +let arm_scope = pattern_result.scope.clone(); +let pattern_diags = pattern_result.diagnostics.clone(); +let guard_result = if (arm_g.clone() != None) { + Some(infer_expr(&arm_g.clone().unwrap(), &arm_scope, &None)) } else { - match (*method_resolution.semantics.clone().clone().unwrap()).clone() { - MethodSemantics::AlgebraMethodSemantics { - algebra_template: at, - .. - } => match at.clone() { - Some(t) => { - if (template_return_has_variables(t.clone()) - || !is_fully_resolved( - &base_result_type, - &scope.type_env.clone().source_indices.clone(), - )) - { - { - let mc_arg_types = Rc::new({ - let mut __result = Vec::new(); - for a in typed_mc_args.clone().iter().cloned() { - __result.push(resolved_type(arg_value(&a))); - } - __result - }); - let mc_fold_overrides = if (fold_info.clone() != None) { - fold_override_map( - "FoldAccumulator".to_string(), - refined_fold_acc_type.clone(), - ) - } else { - empty_override_map() - }; - resolve_type_variables_from_template( - &t, - mc_arg_types, - &recv_rt, - mc_fold_overrides, - &scope.type_env.clone().source_indices.clone(), - ) - } - } else { - Rc::new(KernelTypeBuild { - ty: base_result_type.clone(), - diagnostics: Rc::new(vec![]), - }) - } - } - None => Rc::new(KernelTypeBuild { - ty: base_result_type.clone(), - diagnostics: Rc::new(vec![]), - }), - }, - _ => Rc::new(KernelTypeBuild { - ty: base_result_type.clone(), - diagnostics: Rc::new(vec![]), - }), - } + None }; - let result_type = method_tv_mc.ty.clone(); - let mc_template_diags = method_tv_mc.diagnostics.clone(); - let method_semantics = if (method_resolution.semantics.clone() != None) { - method_resolution.semantics.clone() +let body_result = infer_expr(&arm_b, &arm_scope, &expected); +let body_typed = body_result.typed.clone(); +let body_diags = body_result.diagnostics.clone(); +let guard_unwrapped = match guard_result.clone() { + Some(gr) => gr.clone(), + None => Rc::new(InferResult { + typed: arm_b.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let guard_diags = if (guard_result.clone() != None) { + guard_unwrapped.diagnostics.clone() } else { - Some(Rc::new(MethodSemantics::PlainMethodSemantics)) + Rc::new(vec![]) }; - let typed_mc_arg_nodes = typed_mc_args.clone(); - let mc_texpr = make_named_expr_node( - &method_name, - Rc::new(ExprData::ExprMethodCall { - method_semantics: method_semantics, - }), - v2_rt::concat(Rc::new(vec![recv_typed.clone()]), typed_mc_arg_nodes), - Some(Rc::new(InferredNode::Resolved { node: result_type })), - span.clone(), - node_name_span(&texpr), - ); - Rc::new(InferResult { - typed: mc_texpr, - diagnostics: v2_rt::concat( - v2_rt::concat( - v2_rt::concat(recv_diags, mc_arg_diags), - pipe_fb.kernel_diags.clone(), - ), - v2_rt::concat(method_resolution.diagnostics.clone(), mc_template_diags), - ), - }) - } - ExprData::ExprMatch => { - let span = texpr.span.clone(); - let scrut = match_scrutinee(texpr.clone()); - let arm_nodes = match_arm_nodes(texpr.clone()); - let scrut_result = infer_expr(&scrut, &scope, &None); - let scrut_typed = scrut_result.typed.clone(); - let scrut_diags = scrut_result.diagnostics.clone(); - let scrut_rt = resolved_type(scrut_typed.clone()); - let scrut_subject = pattern_subject_from_inferred(scrut_typed.inferred.clone()); - let scrut_provenance = classify_binding_provenance(&scrut, &scope); - let arm_infer_results = Rc::new({ - let mut __result = Vec::new(); - for arm_node in arm_nodes.clone().iter().cloned() { - __result.push({ +Rc::new(ArmInferResult { + typed_arm: make_arm_node(typed_pattern.clone(), if (guard_result.clone() != None) { + Some(guard_unwrapped.typed.clone()) + } else { + None + }, body_typed.clone(), span.clone()), + diagnostics: v2_rt::concat(pattern_diags.clone(), v2_rt::concat(guard_diags.clone(), body_diags.clone())), + body_type: resolved_type(body_typed.clone()), +}) +}); } __result }); +let arm_body_types = Rc::new({ let mut __result = Vec::new(); for ar in arm_infer_results.clone().iter().cloned() { __result.push(ar.body_type.clone()); } __result }); +let unified_arm_type = match arm_body_types.clone().first().cloned() { + Some(first_type) => Rc::new(arm_body_types.clone().iter().cloned().skip(1 as usize).collect::>()).iter().cloned().fold(first_type, |acc: Rc, t: Rc| prefer_specific_type(acc, t.clone(), &scope.type_env.clone().source_indices.clone())), + None => scrut_rt.clone(), +}; +let arm_infer_results = if is_fully_resolved(&unified_arm_type, &scope.type_env.clone().source_indices.clone()) { + Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(arm_nodes.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let idx = pair.0.clone(); +let arm_node = pair.1.clone(); +let original_list = Rc::new({ let mut __result = Vec::new(); for ap in Rc::new({ let mut __result = Vec::new(); for ap in Rc::new(arm_infer_results.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (ap.0.clone() == idx.clone()) { __result.push(ap); } } __result }).iter().cloned() { __result.push(ap.1.clone()); } __result }); +let original = match original_list.clone().first().cloned() { + Some(ar) => ar.clone(), + None => Rc::new(ArmInferResult { + typed_arm: arm_node.clone(), + diagnostics: Rc::new(vec![]), + body_type: scrut_rt.clone(), +}), +}; +if !is_fully_resolved(&original.body_type.clone(), &scope.type_env.clone().source_indices.clone()) { + { let arm_pat = arm_pattern(arm_node.clone()); - let arm_g = arm_guard(&arm_node); - let arm_b = arm_body(&arm_node); - let typed_pattern = annotate_pattern_parent_enums( - arm_pat.clone(), - scrut_subject.clone(), - &scope, - ); - let pattern_result = extend_scope_with_pattern_node( - &scope, - typed_pattern.clone(), - &scrut_subject, - scrut_provenance.clone(), - ); - let arm_scope = pattern_result.scope.clone(); - let pattern_diags = pattern_result.diagnostics.clone(); - let guard_result = if (arm_g.clone() != None) { +let arm_g = arm_guard(&arm_node); +let arm_b = arm_body(&arm_node); +let typed_pattern = annotate_pattern_parent_enums(arm_pat.clone(), scrut_subject.clone(), &scope); +let pattern_result = extend_scope_with_pattern_node(&scope, typed_pattern.clone(), &scrut_subject, scrut_provenance.clone()); +let arm_scope = pattern_result.scope.clone(); +let pattern_diags = pattern_result.diagnostics.clone(); +let guard_result = if (arm_g.clone() != None) { Some(infer_expr(&arm_g.clone().unwrap(), &arm_scope, &None)) } else { None }; - let body_result = infer_expr(&arm_b, &arm_scope, &expected); - let body_typed = body_result.typed.clone(); - let body_diags = body_result.diagnostics.clone(); - let guard_unwrapped = match guard_result.clone() { - Some(gr) => gr.clone(), - None => Rc::new(InferResult { - typed: arm_b.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let guard_diags = if (guard_result.clone() != None) { +let body_result = infer_expr(&arm_b, &arm_scope, &Some(unified_arm_type.clone())); +let body_typed = body_result.typed.clone(); +let body_diags = body_result.diagnostics.clone(); +let guard_unwrapped = match guard_result.clone() { + Some(gr) => gr.clone(), + None => Rc::new(InferResult { + typed: arm_b.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let guard_diags = if (guard_result.clone() != None) { guard_unwrapped.diagnostics.clone() } else { Rc::new(vec![]) }; - Rc::new(ArmInferResult { - typed_arm: make_arm_node( - typed_pattern.clone(), - if (guard_result.clone() != None) { - Some(guard_unwrapped.typed.clone()) - } else { - None - }, - body_typed.clone(), - span.clone(), - ), - diagnostics: v2_rt::concat( - pattern_diags.clone(), - v2_rt::concat(guard_diags.clone(), body_diags.clone()), - ), - body_type: resolved_type(body_typed.clone()), - }) - }); - } - __result - }); - let arm_body_types = Rc::new({ - let mut __result = Vec::new(); - for ar in arm_infer_results.clone().iter().cloned() { - __result.push(ar.body_type.clone()); +Rc::new(ArmInferResult { + typed_arm: make_arm_node(typed_pattern.clone(), if (guard_result.clone() != None) { + Some(guard_unwrapped.typed.clone()) + } else { + None + }, body_typed.clone(), span.clone()), + diagnostics: v2_rt::concat(pattern_diags.clone(), v2_rt::concat(guard_diags.clone(), body_diags.clone())), + body_type: resolved_type(body_typed.clone()), +}) +} + } else { + original.clone() } - __result - }); - let unified_arm_type = match arm_body_types.clone().first().cloned() { - Some(first_type) => Rc::new( - arm_body_types - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) - .iter() - .cloned() - .fold(first_type, |acc: Rc, t: Rc| { - prefer_specific_type( - acc, - t.clone(), - &scope.type_env.clone().source_indices.clone(), - ) - }), - None => scrut_rt.clone(), +}); } __result }) + } else { + arm_infer_results.clone() + }; +let typed_arms = Rc::new({ let mut __result = Vec::new(); for ar in arm_infer_results.clone().iter().cloned() { __result.push(ar.typed_arm.clone()); } __result }); +let arm_diags = Rc::new({ let mut __result = Vec::new(); for ar in arm_infer_results.clone().iter().cloned() { __result.extend((*ar.diagnostics.clone()).iter().cloned()); } __result }); +let result_type = unified_arm_type.clone(); +let empty_arms_diags = if ((arm_infer_results.clone().len() as i64) == 0) { + Rc::new(vec![inference_error("match expression has no arms".to_string(), span.clone(), scope.module_name.clone())]) + } else { + Rc::new(vec![]) + }; +let exhaustiveness_diags = match (*resolve_pattern_subject(scope.clone(), scrut_subject.clone())).clone() { + PatternSubject::PatternResolved { node: resolved_scrutinee, .. } => check_match_exhaustiveness(&resolved_scrutinee, &typed_arms, &scope.type_env.clone(), span.clone(), scope.module_name.clone()), + PatternSubject::PatternDynamic { .. } => Rc::new(vec![]), + PatternSubject::PatternLookupBlocked => Rc::new(vec![]), +}; +let match_texpr = make_expr_node(Rc::new(ExprData::ExprMatch), v2_rt::concat(Rc::new(vec![scrut_typed.clone()]), typed_arms.clone()), Some(Rc::new(InferredNode::Resolved { + node: result_type, +})), span.clone()); +Rc::new(InferResult { + typed: match_texpr, + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(scrut_diags, arm_diags), empty_arms_diags), exhaustiveness_diags), +}) +}, + ExprData::ExprIf => { + let span = texpr.span.clone(); +let cond = if_condition(texpr.clone()); +let then_expr = if_then_branch(texpr.clone()); +let else_expr = if_else_branch(texpr.clone()); +let cond_result = infer_expr(&cond, &scope, &None); +let cond_typed = cond_result.typed.clone(); +let cond_diags = cond_result.diagnostics.clone(); +let then_result = infer_expr(&then_expr, &scope, &expected); +let then_typed = then_result.typed.clone(); +let then_diags = then_result.diagnostics.clone(); +match else_expr { + Some(else_branch) => { + let else_result = infer_expr(&else_branch, &scope, &expected); +let then_rt = resolved_type(then_result.typed.clone()); +let else_rt = resolved_type(else_result.typed.clone()); +let then_result = if (!is_fully_resolved(&then_rt, &scope.type_env.clone().source_indices.clone()) && is_fully_resolved(&else_rt, &scope.type_env.clone().source_indices.clone())) { + infer_expr(&then_expr, &scope, &Some(else_rt.clone())) + } else { + then_result.clone() }; - let arm_infer_results = if is_fully_resolved( - &unified_arm_type, - &scope.type_env.clone().source_indices.clone(), - ) { - Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - arm_nodes - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let idx = pair.0.clone(); - let arm_node = pair.1.clone(); - let original_list = Rc::new({ - let mut __result = Vec::new(); - for ap in Rc::new({ - let mut __result = Vec::new(); - for ap in Rc::new( - arm_infer_results - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (ap.0.clone() == idx.clone()) { - __result.push(ap); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(ap.1.clone()); - } - __result - }); - let original = match original_list.clone().first().cloned() { - Some(ar) => ar.clone(), - None => Rc::new(ArmInferResult { - typed_arm: arm_node.clone(), - diagnostics: Rc::new(vec![]), - body_type: scrut_rt.clone(), - }), - }; - if !is_fully_resolved( - &original.body_type.clone(), - &scope.type_env.clone().source_indices.clone(), - ) { - { - let arm_pat = arm_pattern(arm_node.clone()); - let arm_g = arm_guard(&arm_node); - let arm_b = arm_body(&arm_node); - let typed_pattern = annotate_pattern_parent_enums( - arm_pat.clone(), - scrut_subject.clone(), - &scope, - ); - let pattern_result = extend_scope_with_pattern_node( - &scope, - typed_pattern.clone(), - &scrut_subject, - scrut_provenance.clone(), - ); - let arm_scope = pattern_result.scope.clone(); - let pattern_diags = pattern_result.diagnostics.clone(); - let guard_result = if (arm_g.clone() != None) { - Some(infer_expr( - &arm_g.clone().unwrap(), - &arm_scope, - &None, - )) - } else { - None - }; - let body_result = infer_expr( - &arm_b, - &arm_scope, - &Some(unified_arm_type.clone()), - ); - let body_typed = body_result.typed.clone(); - let body_diags = body_result.diagnostics.clone(); - let guard_unwrapped = match guard_result.clone() { - Some(gr) => gr.clone(), - None => Rc::new(InferResult { - typed: arm_b.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let guard_diags = if (guard_result.clone() != None) { - guard_unwrapped.diagnostics.clone() - } else { - Rc::new(vec![]) - }; - Rc::new(ArmInferResult { - typed_arm: make_arm_node( - typed_pattern.clone(), - if (guard_result.clone() != None) { - Some(guard_unwrapped.typed.clone()) - } else { - None - }, - body_typed.clone(), - span.clone(), - ), - diagnostics: v2_rt::concat( - pattern_diags.clone(), - v2_rt::concat( - guard_diags.clone(), - body_diags.clone(), - ), - ), - body_type: resolved_type(body_typed.clone()), - }) - } - } else { - original.clone() - } - }); - } - __result - }) +let else_result = if (!is_fully_resolved(&else_rt, &scope.type_env.clone().source_indices.clone()) && is_fully_resolved(&then_rt, &scope.type_env.clone().source_indices.clone())) { + infer_expr(&else_branch, &scope, &Some(then_rt.clone())) } else { - arm_infer_results.clone() + else_result.clone() }; - let typed_arms = Rc::new({ - let mut __result = Vec::new(); - for ar in arm_infer_results.clone().iter().cloned() { - __result.push(ar.typed_arm.clone()); - } - __result - }); - let arm_diags = Rc::new({ - let mut __result = Vec::new(); - for ar in arm_infer_results.clone().iter().cloned() { - __result.extend((*ar.diagnostics.clone()).iter().cloned()); - } - __result - }); - let result_type = unified_arm_type.clone(); - let empty_arms_diags = if ((arm_infer_results.clone().len() as i64) == 0) { - Rc::new(vec![inference_error( - "match expression has no arms".to_string(), - span.clone(), - scope.module_name.clone(), - )]) - } else { +let then_typed = then_result.typed.clone(); +let then_diags = then_result.diagnostics.clone(); +let else_typed = else_result.typed.clone(); +let else_diags = else_result.diagnostics.clone(); +let then_rt = resolved_type(then_typed.clone()); +let else_rt = resolved_type(else_typed.clone()); +let unified = prefer_specific_type(then_rt.clone(), else_rt.clone(), &scope.type_env.clone().source_indices.clone()); +let branch_diags = if node_type_compatible(then_rt.clone(), else_rt.clone(), scope.type_env.clone().source_indices.clone()) { Rc::new(vec![]) - }; - let exhaustiveness_diags = match (*resolve_pattern_subject( - scope.clone(), - scrut_subject.clone(), - )) - .clone() - { - PatternSubject::PatternResolved { - node: resolved_scrutinee, - .. - } => check_match_exhaustiveness( - &resolved_scrutinee, - &typed_arms, - &scope.type_env.clone(), - span.clone(), - scope.module_name.clone(), - ), - PatternSubject::PatternDynamic { .. } => Rc::new(vec![]), - PatternSubject::PatternLookupBlocked => Rc::new(vec![]), - }; - let match_texpr = make_expr_node( - Rc::new(ExprData::ExprMatch), - v2_rt::concat(Rc::new(vec![scrut_typed.clone()]), typed_arms.clone()), - Some(Rc::new(InferredNode::Resolved { node: result_type })), - span.clone(), - ); - Rc::new(InferResult { - typed: match_texpr, - diagnostics: v2_rt::concat( - v2_rt::concat(v2_rt::concat(scrut_diags, arm_diags), empty_arms_diags), - exhaustiveness_diags, - ), - }) - } - ExprData::ExprIf => { - let span = texpr.span.clone(); - let cond = if_condition(texpr.clone()); - let then_expr = if_then_branch(texpr.clone()); - let else_expr = if_else_branch(texpr.clone()); - let cond_result = infer_expr(&cond, &scope, &None); - let cond_typed = cond_result.typed.clone(); - let cond_diags = cond_result.diagnostics.clone(); - let then_result = infer_expr(&then_expr, &scope, &expected); - let then_typed = then_result.typed.clone(); - let then_diags = then_result.diagnostics.clone(); - match else_expr { - Some(else_branch) => { - let else_result = infer_expr(&else_branch, &scope, &expected); - let then_rt = resolved_type(then_result.typed.clone()); - let else_rt = resolved_type(else_result.typed.clone()); - let then_result = if (!is_fully_resolved( - &then_rt, - &scope.type_env.clone().source_indices.clone(), - ) && is_fully_resolved( - &else_rt, - &scope.type_env.clone().source_indices.clone(), - )) { - infer_expr(&then_expr, &scope, &Some(else_rt.clone())) - } else { - then_result.clone() - }; - let else_result = if (!is_fully_resolved( - &else_rt, - &scope.type_env.clone().source_indices.clone(), - ) && is_fully_resolved( - &then_rt, - &scope.type_env.clone().source_indices.clone(), - )) { - infer_expr(&else_branch, &scope, &Some(then_rt.clone())) - } else { - else_result.clone() - }; - let then_typed = then_result.typed.clone(); - let then_diags = then_result.diagnostics.clone(); - let else_typed = else_result.typed.clone(); - let else_diags = else_result.diagnostics.clone(); - let then_rt = resolved_type(then_typed.clone()); - let else_rt = resolved_type(else_typed.clone()); - let unified = prefer_specific_type( - then_rt.clone(), - else_rt.clone(), - &scope.type_env.clone().source_indices.clone(), - ); - let branch_diags = if node_type_compatible( - then_rt.clone(), - else_rt.clone(), - scope.type_env.clone().source_indices.clone(), - ) { - Rc::new(vec![]) - } else { - Rc::new(vec![inference_error( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "if branches resolve to incompatible types: " - .to_string(), - node_type_shape( - &then_rt, - &scope.type_env.clone().source_indices.clone(), - ), - ), - " vs ".to_string(), - ), - node_type_shape( - &else_rt, - &scope.type_env.clone().source_indices.clone(), - ), - ), - span.clone(), - scope.module_name.clone(), - )]) - }; - let if_texpr = make_expr_node( - Rc::new(ExprData::ExprIf), - Rc::new(vec![cond_typed, then_typed.clone(), else_typed.clone()]), - Some(Rc::new(InferredNode::Resolved { node: unified })), - span.clone(), - ); - Rc::new(InferResult { - typed: if_texpr, - diagnostics: v2_rt::concat( - v2_rt::concat(v2_rt::concat(cond_diags, then_diags), else_diags), - branch_diags, - ), - }) - } - None => { - let if_texpr2 = make_expr_node( - Rc::new(ExprData::ExprIf), - Rc::new(vec![cond_typed, then_typed.clone()]), - Some(Rc::new(InferredNode::Resolved { node: unit_type() })), - span.clone(), - ); - Rc::new(InferResult { - typed: if_texpr2, - diagnostics: v2_rt::concat(cond_diags, then_diags), - }) - } - } - } - ExprData::ExprLet => { - let let_name = let_binding_name_at( - texpr.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let span = texpr.span.clone(); - let val_expr = let_value(texpr.clone()); - let body_expr = let_body(texpr.clone()); - let is_tail_return = match body_expr.clone() { - Some(bd) => match (*bd.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (authored_name_at(scope.type_env.clone().source_indices.clone(), &bd) - .as_str() - == let_name.clone().as_str()) - } - _ => false, - }, - None => false, - }; - let val_expected = if is_tail_return { - expected.clone() } else { - None + Rc::new(vec![inference_error(v2_rt::concat(v2_rt::concat(v2_rt::concat("if branches resolve to incompatible types: ".to_string(), node_type_shape(&then_rt, &scope.type_env.clone().source_indices.clone())), " vs ".to_string()), node_type_shape(&else_rt, &scope.type_env.clone().source_indices.clone())), span.clone(), scope.module_name.clone())]) }; - let val_result = infer_expr(&val_expr, &scope, &val_expected); - let val_typed = val_result.typed.clone(); - let val_diags = val_result.diagnostics.clone(); - let val_type = resolved_type(val_typed.clone()); - if (body_expr.clone() == None) { - { - let let_texpr = make_named_expr_node( - &let_name, - Rc::new(ExprData::ExprLet), - Rc::new(vec![val_typed.clone()]), - Some(Rc::new(InferredNode::Resolved { node: val_type })), - span.clone(), - node_name_span(&texpr), - ); - Rc::new(InferResult { - typed: let_texpr, - diagnostics: val_diags, - }) - } - } else { - { - let extended = extend_scope( - &scope, - &let_name, - val_type, - classify_binding_provenance(&val_typed, &scope), - ); - let body_result = - infer_expr(&body_expr.clone().unwrap(), &extended, &expected); - let body_typed = body_result.typed.clone(); - let body_diags = body_result.diagnostics.clone(); - let let_texpr2 = make_named_expr_node( - &let_name, - Rc::new(ExprData::ExprLet), - Rc::new(vec![val_typed.clone(), body_typed.clone()]), - body_typed.inferred.clone(), - span.clone(), - node_name_span(&texpr), - ); - Rc::new(InferResult { - typed: let_texpr2, - diagnostics: v2_rt::concat(val_diags, body_diags.clone()), - }) - } - } - } - ExprData::ExprRecordLit { .. } => { - let span = texpr.span.clone(); - let field_inits = texpr.children.clone(); - infer_record_lit( - &record_lit_type_name_at( - texpr.clone(), - scope.type_env.clone().source_indices.clone(), - ), - field_inits, - &span, - node_name_span(&texpr), - &scope, - ) +let if_texpr = make_expr_node(Rc::new(ExprData::ExprIf), Rc::new(vec![cond_typed, then_typed.clone(), else_typed.clone()]), Some(Rc::new(InferredNode::Resolved { + node: unified, +})), span.clone()); +Rc::new(InferResult { + typed: if_texpr, + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(cond_diags, then_diags), else_diags), branch_diags), +}) +}, + None => { + let if_texpr2 = make_expr_node(Rc::new(ExprData::ExprIf), Rc::new(vec![cond_typed, then_typed.clone()]), Some(Rc::new(InferredNode::Resolved { + node: unit_type(), +})), span.clone()); +Rc::new(InferResult { + typed: if_texpr2, + diagnostics: v2_rt::concat(cond_diags, then_diags), +}) +}, +} +}, + ExprData::ExprLet => { + let let_name = let_binding_name_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); +let span = texpr.span.clone(); +let val_expr = let_value(texpr.clone()); +let body_expr = let_body(texpr.clone()); +let is_tail_return = match body_expr.clone() { + Some(bd) => match (*bd.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (authored_name_at(scope.type_env.clone().source_indices.clone(), &bd).as_str() == let_name.clone().as_str()), + _ => false, +}, + None => false, +}; +let val_expected = if is_tail_return { + expected.clone() + } else { + None + }; +let val_result = infer_expr(&val_expr, &scope, &val_expected); +let val_typed = val_result.typed.clone(); +let val_diags = val_result.diagnostics.clone(); +let val_type = resolved_type(val_typed.clone()); +if (body_expr.clone() == None) { + { + let let_texpr = make_named_expr_node(&let_name, Rc::new(ExprData::ExprLet), Rc::new(vec![val_typed.clone()]), Some(Rc::new(InferredNode::Resolved { + node: val_type, +})), span.clone(), node_name_span(&texpr)); +Rc::new(InferResult { + typed: let_texpr, + diagnostics: val_diags, +}) +} + } else { + { + let extended = extend_scope(&scope, &let_name, val_type, classify_binding_provenance(&val_typed, &scope)); +let body_result = infer_expr(&body_expr.clone().unwrap(), &extended, &expected); +let body_typed = body_result.typed.clone(); +let body_diags = body_result.diagnostics.clone(); +let let_texpr2 = make_named_expr_node(&let_name, Rc::new(ExprData::ExprLet), Rc::new(vec![val_typed.clone(), body_typed.clone()]), body_typed.inferred.clone(), span.clone(), node_name_span(&texpr)); +Rc::new(InferResult { + typed: let_texpr2, + diagnostics: v2_rt::concat(val_diags, body_diags.clone()), +}) +} } - ExprData::ExprListLit => { - let span = texpr.span.clone(); - let elements = texpr.children.clone(); - let elem_expected = match expected.clone() { - Some(exp) => { - if node_is_element_collection( - &exp, - scope.type_env.clone().source_indices.clone(), - ) { - match exp.children.clone().first().cloned() { - Some(elem) => Some(child_type_node(&elem)), - None => None, - } - } else { - None - } - } - None => None, - }; - let elem_results = Rc::new({ - let mut __result = Vec::new(); - for e in elements.iter().cloned() { - __result.push(infer_expr(&e, &scope, &elem_expected)); - } - __result - }); - let typed_elements = Rc::new({ - let mut __result = Vec::new(); - for r in elem_results.clone().iter().cloned() { - __result.push(r.typed.clone()); - } - __result - }); - let elem_diags = Rc::new({ - let mut __result = Vec::new(); - for r in elem_results.clone().iter().cloned() { - __result.extend((*r.diagnostics.clone()).iter().cloned()); - } - __result - }); - let elem_type_node = if ((elem_results.clone().len() as i64) > 0) { - match elem_results.clone().first().cloned() { - Some(r) => resolved_type(r.typed.clone()), - None => unit_type(), - } +}, + ExprData::ExprRecordLit { .. } => { + let span = texpr.span.clone(); +let field_inits = texpr.children.clone(); +infer_record_lit(&record_lit_type_name_at(texpr.clone(), scope.type_env.clone().source_indices.clone()), field_inits, &span, node_name_span(&texpr), &scope) +}, + ExprData::ExprListLit => { + let span = texpr.span.clone(); +let elements = texpr.children.clone(); +let elem_expected = match expected.clone() { + Some(exp) => if node_is_element_collection(&exp, scope.type_env.clone().source_indices.clone()) { + match exp.children.clone().first().cloned() { + Some(elem) => Some(child_type_node(&elem)), + None => None, +} + } else { + None + }, + None => None, +}; +let elem_results = Rc::new({ let mut __result = Vec::new(); for e in elements.iter().cloned() { __result.push(infer_expr(&e, &scope, &elem_expected)); } __result }); +let typed_elements = Rc::new({ let mut __result = Vec::new(); for r in elem_results.clone().iter().cloned() { __result.push(r.typed.clone()); } __result }); +let elem_diags = Rc::new({ let mut __result = Vec::new(); for r in elem_results.clone().iter().cloned() { __result.extend((*r.diagnostics.clone()).iter().cloned()); } __result }); +let elem_type_node = if ((elem_results.clone().len() as i64) > 0) { + match elem_results.clone().first().cloned() { + Some(r) => resolved_type(r.typed.clone()), + None => unit_type(), +} + } else { + match expected.clone() { + Some(exp) => if node_is_element_collection(&exp, scope.type_env.clone().source_indices.clone()) { + match exp.children.clone().first().cloned() { + Some(elem) => child_type_node(&elem), + None => unit_type(), +} } else { - match expected.clone() { - Some(exp) => { - if node_is_element_collection( - &exp, - scope.type_env.clone().source_indices.clone(), - ) { - match exp.children.clone().first().cloned() { - Some(elem) => child_type_node(&elem), - None => unit_type(), - } - } else { - unit_type() - } - } - None => unit_type(), - } - }; - let empty_list_diags = if ((elem_results.clone().len() as i64) == 0) { - match expected.clone() { - Some(exp) => { - if node_is_element_collection( - &exp, - scope.type_env.clone().source_indices.clone(), - ) { - match exp.children.clone().first().cloned() { - Some(_) => Rc::new(vec![]), - None => Rc::new(vec![inference_error( - "empty list literal: expected type has no element type" - .to_string(), - span.clone(), - scope.module_name.clone(), - )]), - } - } else { - Rc::new(vec![inference_error( - "empty list literal: expected type is not a collection" - .to_string(), - span.clone(), - scope.module_name.clone(), - )]) - } - } - None => Rc::new(vec![]), - } + unit_type() + }, + None => unit_type(), +} + }; +let empty_list_diags = if ((elem_results.clone().len() as i64) == 0) { + match expected.clone() { + Some(exp) => if node_is_element_collection(&exp, scope.type_env.clone().source_indices.clone()) { + match exp.children.clone().first().cloned() { + Some(_) => Rc::new(vec![]), + None => Rc::new(vec![inference_error("empty list literal: expected type has no element type".to_string(), span.clone(), scope.module_name.clone())]), +} } else { - Rc::new(vec![]) - }; - let list_k = list_kernel_ty_from_element(elem_type_node.clone()); - let ll_texpr = make_expr_node( - Rc::new(ExprData::ExprListLit), - typed_elements, - Some(Rc::new(InferredNode::Resolved { - node: list_k.ty.clone(), - })), - span.clone(), - ); - Rc::new(InferResult { - typed: ll_texpr, - diagnostics: v2_rt::concat( - v2_rt::concat(elem_diags, empty_list_diags), - list_k.miss_diags.clone(), - ), - }) - } - ExprData::ExprBinOp { op, .. } => { - let span = texpr.span.clone(); - let left_expr = binop_left(texpr.clone()); - let right_expr = binop_right(texpr.clone()); - let left_result = infer_expr(&left_expr, &scope, &None); - let left_typed = left_result.typed.clone(); - let left_diags = left_result.diagnostics.clone(); - let right_result = infer_expr(&right_expr, &scope, &None); - let right_typed = right_result.typed.clone(); - let right_diags = right_result.diagnostics.clone(); - let binop_info = infer_binop_type_node( - &op, - &resolved_type(left_typed.clone()), - scope.type_env.clone().source_indices.clone(), - ); - let bo_texpr = make_expr_node( - Rc::new(ExprData::ExprBinOp { - op: op.clone(), - algebra_field: binop_info.algebra_field.clone(), - }), - Rc::new(vec![left_typed.clone(), right_typed]), - Some(Rc::new(InferredNode::Resolved { - node: binop_info.result_type.clone(), - })), - span.clone(), - ); - Rc::new(InferResult { - typed: bo_texpr, - diagnostics: v2_rt::concat(left_diags, right_diags), - }) - } - ExprData::ExprUnaryOp { op, .. } => { - let span = texpr.span.clone(); - let operand_expr = unaryop_operand(texpr.clone()); - let operand_result = infer_expr(&operand_expr, &scope, &None); - let operand_typed = operand_result.typed.clone(); - let operand_diags = operand_result.diagnostics.clone(); - let result_type = match op.clone() { - UnaryOpKind::Not => bool_type(), - UnaryOpKind::Neg => resolved_type(operand_typed.clone()), - }; - let uo_texpr = make_expr_node( - Rc::new(ExprData::ExprUnaryOp { op: op.clone() }), - Rc::new(vec![operand_typed.clone()]), - Some(Rc::new(InferredNode::Resolved { node: result_type })), - span.clone(), - ); - Rc::new(InferResult { - typed: uo_texpr, - diagnostics: operand_diags, - }) - } - ExprData::ExprLambda => { - let span = texpr.span.clone(); - let lam_body = lambda_body(texpr.clone()); - let lam_params = lambda_param_names_at( - texpr.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let lam_param_nodes = Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let elem_prov = match v2_rt::map_get( - &scope.lambda_param_provenance.clone(), - "elem".to_string(), - ) { - Some(p) => p.clone(), - None => Rc::new(SubValueRelation::SubValueUnknown), - }; - let lam_scope = if (expected.clone() != None) { - { - let exp = expected.clone().unwrap(); - if ((exp.params.clone().len() as i64) > 0) { - Rc::new( - lam_params - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - scope.clone(), - |acc: Rc, pair: (i64, String)| { - let param_prov = if (pair.0.clone() - == ((lam_params.clone().len() as i64) - 1)) - { - elem_prov.clone() - } else { - Rc::new(SubValueRelation::SubValueUnknown) - }; - match exp.params.clone().get(pair.0.clone() as usize).cloned() { - Some(cp) => extend_scope( - &acc, - &pair.1.clone(), - param_node_type_expr(&cp), - param_prov.clone(), - ), - None => extend_scope( - &acc, - &pair.1.clone(), - type_variable_node("callable_param".to_string()), - param_prov.clone(), - ), - } - }, - ) - } else { - if ((lam_params.clone().len() as i64) == 1) { - match lam_params.clone().first().cloned() { - Some(p) => { - extend_scope(&scope, &p, exp.clone(), elem_prov.clone()) - } - None => scope.clone(), - } + Rc::new(vec![inference_error("empty list literal: expected type is not a collection".to_string(), span.clone(), scope.module_name.clone())]) + }, + None => Rc::new(vec![]), +} + } else { + Rc::new(vec![]) + }; +let list_k = list_kernel_ty_from_element(elem_type_node.clone()); +let ll_texpr = make_expr_node(Rc::new(ExprData::ExprListLit), typed_elements, Some(Rc::new(InferredNode::Resolved { + node: list_k.ty.clone(), +})), span.clone()); +Rc::new(InferResult { + typed: ll_texpr, + diagnostics: v2_rt::concat(v2_rt::concat(elem_diags, empty_list_diags), list_k.miss_diags.clone()), +}) +}, + ExprData::ExprBinOp { op, .. } => { + let span = texpr.span.clone(); +let left_expr = binop_left(texpr.clone()); +let right_expr = binop_right(texpr.clone()); +let left_result = infer_expr(&left_expr, &scope, &None); +let left_typed = left_result.typed.clone(); +let left_diags = left_result.diagnostics.clone(); +let right_result = infer_expr(&right_expr, &scope, &None); +let right_typed = right_result.typed.clone(); +let right_diags = right_result.diagnostics.clone(); +let binop_info = infer_binop_type_node(&op, &resolved_type(left_typed.clone()), scope.type_env.clone().source_indices.clone()); +let bo_texpr = make_expr_node(Rc::new(ExprData::ExprBinOp { + op: op.clone(), + algebra_field: binop_info.algebra_field.clone(), +}), Rc::new(vec![left_typed.clone(), right_typed]), Some(Rc::new(InferredNode::Resolved { + node: binop_info.result_type.clone(), +})), span.clone()); +Rc::new(InferResult { + typed: bo_texpr, + diagnostics: v2_rt::concat(left_diags, right_diags), +}) +}, + ExprData::ExprUnaryOp { op, .. } => { + let span = texpr.span.clone(); +let operand_expr = unaryop_operand(texpr.clone()); +let operand_result = infer_expr(&operand_expr, &scope, &None); +let operand_typed = operand_result.typed.clone(); +let operand_diags = operand_result.diagnostics.clone(); +let result_type = match op.clone() { + UnaryOpKind::Not => bool_type(), + UnaryOpKind::Neg => resolved_type(operand_typed.clone()), +}; +let uo_texpr = make_expr_node(Rc::new(ExprData::ExprUnaryOp { + op: op.clone(), +}), Rc::new(vec![operand_typed.clone()]), Some(Rc::new(InferredNode::Resolved { + node: result_type, +})), span.clone()); +Rc::new(InferResult { + typed: uo_texpr, + diagnostics: operand_diags, +}) +}, + ExprData::ExprLambda => { + let span = texpr.span.clone(); +let lam_body = lambda_body(texpr.clone()); +let lam_params = lambda_param_names_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); +let lam_param_nodes = Rc::new(texpr.children.clone().iter().cloned().skip(1 as usize).collect::>()); +let elem_prov = match v2_rt::map_get(&scope.lambda_param_provenance.clone(), "elem".to_string()) { + Some(p) => p.clone(), + None => Rc::new(SubValueRelation::SubValueUnknown), +}; +let lam_scope = if (expected.clone() != None) { + { + let exp = expected.clone().unwrap(); +if ((exp.params.clone().len() as i64) > 0) { + Rc::new(lam_params.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(scope.clone(), |acc: Rc, pair: (i64, String)| { + let param_prov = if (pair.0.clone() == ((lam_params.clone().len() as i64) - 1)) { + elem_prov.clone() } else { - Rc::new( - lam_params - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - scope.clone(), - |acc: Rc, pair: (i64, String)| { - let param_prov = if (pair.0.clone() - == ((lam_params.clone().len() as i64) - 1)) - { - elem_prov.clone() - } else { - Rc::new(SubValueRelation::SubValueUnknown) - }; - if (pair.0.clone() - == ((lam_params.clone().len() as i64) - 1)) - { - extend_scope( - &acc, - &pair.1.clone(), - exp.clone(), - param_prov.clone(), - ) - } else { - extend_scope( - &acc, - &pair.1.clone(), - type_variable_node("lambda_param".to_string()), - param_prov.clone(), - ) - } - }, - ) - } - } - } - } else { - extend_scope_with_params(&scope, lam_params.clone()) - }; - let body_expected = if (expected.clone() != None) { - { - let exp = expected.clone().unwrap(); - if ((exp.params.clone().len() as i64) > 0) { - Some(callable_inferred(&exp)) + Rc::new(SubValueRelation::SubValueUnknown) + }; +match exp.params.clone().get(pair.0.clone() as usize).cloned() { + Some(cp) => extend_scope(&acc, &pair.1.clone(), param_node_type_expr(&cp), param_prov.clone()), + None => extend_scope(&acc, &pair.1.clone(), type_variable_node("callable_param".to_string()), param_prov.clone()), +} +}) + } else { + if ((lam_params.clone().len() as i64) == 1) { + match lam_params.clone().first().cloned() { + Some(p) => extend_scope(&scope, &p, exp.clone(), elem_prov.clone()), + None => scope.clone(), +} } else { - None - } - } - } else { - None - }; - let body_scope = Rc::new(InferScope { - type_env: lam_scope.type_env.clone(), - func_env: lam_scope.func_env.clone(), - locals: lam_scope.locals.clone(), - match_bound_names: lam_scope.match_bound_names.clone(), - module_name: lam_scope.module_name.clone(), - service_registry: lam_scope.service_registry.clone(), - item_registry: lam_scope.item_registry.clone(), - lambda_param_provenance: v2_rt::rc_empty_map::>(), - }); - let body_result = infer_expr(&lam_body, &body_scope, &body_expected); - let body_typed = body_result.typed.clone(); - let body_diags = body_result.diagnostics.clone(); - let typed_param_nodes = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - lam_param_nodes - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let pn = pair.1.clone(); - let param_name = - match lam_params.clone().get(pair.0.clone() as usize).cloned() { - Some(n) => n.clone(), - None => "".to_string(), - }; - let param_type = - match v2_rt::map_get(&lam_scope.locals.clone(), param_name.clone()) - { - Some(binding) => Some(Rc::new(InferredNode::Resolved { - node: binding.resolved.clone(), - })), - None => None, + Rc::new(lam_params.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(scope.clone(), |acc: Rc, pair: (i64, String)| { + let param_prov = if (pair.0.clone() == ((lam_params.clone().len() as i64) - 1)) { + elem_prov.clone() + } else { + Rc::new(SubValueRelation::SubValueUnknown) }; - Rc::new(Node { - name: pn.name.clone(), - ident: pn.ident.clone(), - span: pn.span.clone(), - ident_span: pn.ident_span.clone(), - children: pn.children.clone(), - connective: pn.connective.clone(), - params: pn.params.clone(), - inferred: param_type.clone(), - return_cardinality: pn.return_cardinality.clone(), - uses: pn.uses.clone(), - body: pn.body.clone(), - transport: pn.transport.clone(), - properties: pn.properties.clone(), - type_annotation: pn.type_annotation.clone(), - is_self_recursive: pn.is_self_recursive.clone(), - has_non_tail_self_call: pn.has_non_tail_self_call.clone(), - match_pattern: pn.match_pattern.clone(), - expr_data: pn.expr_data.clone(), - }) - }); - } - __result - }); - let lam_texpr = make_expr_node( - Rc::new(ExprData::ExprLambda), - v2_rt::concat(Rc::new(vec![body_typed.clone()]), typed_param_nodes), - body_typed.inferred.clone(), - span.clone(), - ); - Rc::new(InferResult { - typed: lam_texpr, - diagnostics: body_diags.clone(), - }) - } - ExprData::ExprStringInterp => { - let span = texpr.span.clone(); - let typed_part_nodes = Rc::new({ - let mut __result = Vec::new(); - for part_node in texpr.children.clone().iter().cloned() { - __result.push(match (*part_node.expr_data.clone()).clone() { - ExprData::ExprLiteral { .. } => part_node.clone(), - _ => match part_node.children.clone().first().cloned() { - Some(inner) => { - let r = infer_expr(&inner, &scope, &None); - make_interp_part_node(r.typed.clone(), part_node.span.clone()) - } - None => part_node.clone(), - }, - }); - } - __result - }); - let interp_diags = Rc::new({ - let mut __result = Vec::new(); - for part_node in texpr.children.clone().iter().cloned() { - __result.extend( - (*match (*part_node.expr_data.clone()).clone() { - ExprData::ExprLiteral { .. } => Rc::new(vec![]), - _ => match part_node.children.clone().first().cloned() { - Some(inner) => { - let r = infer_expr(&inner, &scope, &None); - r.diagnostics.clone() - } - None => Rc::new(vec![]), - }, - }) - .iter() - .cloned(), - ); - } - __result - }); - let si_texpr = make_expr_node( - Rc::new(ExprData::ExprStringInterp), - typed_part_nodes, - Some(Rc::new(InferredNode::Resolved { - node: string_type(), - })), - span.clone(), - ); - Rc::new(InferResult { - typed: si_texpr, - diagnostics: interp_diags, - }) - } - ExprData::ExprBlock => { - let span = texpr.span.clone(); - let stmts = texpr.children.clone(); - if ((stmts.clone().len() as i64) > 0) { - { - let state = infer_block_stmts( - stmts.clone(), - (stmts.clone().len() as i64), - scope.clone(), - Rc::new(vec![]), - Rc::new(vec![]), - unit_type(), - expected.clone(), - ); - let blk_texpr = make_expr_node( - Rc::new(ExprData::ExprBlock), - state.typed_stmts.clone(), - Some(Rc::new(InferredNode::Resolved { - node: state.last_type.clone(), - })), - span.clone(), - ); - Rc::new(InferResult { - typed: blk_texpr, - diagnostics: Rc::new({ - let mut __result = Vec::new(); - for c in state.diag_chunks.clone().iter().cloned() { - __result.extend((*c.clone()).iter().cloned()); +if (pair.0.clone() == ((lam_params.clone().len() as i64) - 1)) { + extend_scope(&acc, &pair.1.clone(), exp.clone(), param_prov.clone()) + } else { + extend_scope(&acc, &pair.1.clone(), type_variable_node("lambda_param".to_string()), param_prov.clone()) } - __result - }), - }) +}) + } } - } else { - ok_infer(make_expr_node( - Rc::new(ExprData::ExprBlock), - Rc::new(vec![]), - Some(Rc::new(InferredNode::Resolved { node: unit_type() })), - span.clone(), - )) - } - } - ExprData::ExprCast => { - let span = texpr.span.clone(); - let cast_inner = cast_expr(texpr.clone()); - let target_type = cast_target(texpr.clone()); - let inner_result = infer_expr(&cast_inner, &scope, &None); - let inner_typed = inner_result.typed.clone(); - let inner_diags = inner_result.diagnostics.clone(); - let si = scope.type_env.clone().source_indices.clone(); - let target_name = authored_name_at(si.clone(), &target_type); - let cast_diag = validate_cast( - inner_typed.inferred.clone(), - &target_name, - span.clone(), - si.clone(), - scope.module_name.clone(), - ); - let cast_diags = match cast_diag { - Some(d) => Rc::new(vec![d.clone()]), - None => Rc::new(vec![]), - }; - let cast_texpr = make_expr_node( - Rc::new(ExprData::ExprCast), - Rc::new(vec![inner_typed.clone(), target_type.clone()]), - Some(Rc::new(InferredNode::Resolved { - node: target_type.clone(), - })), - span.clone(), - ); - Rc::new(InferResult { - typed: cast_texpr, - diagnostics: v2_rt::concat(inner_diags, cast_diags), - }) - } - ExprData::ExprForEach => { - let variable = foreach_variable_at( - texpr.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let span = texpr.span.clone(); - let coll = foreach_collection(texpr.clone()); - let body_expr = foreach_body(texpr.clone()); - let coll_result = infer_expr(&coll, &scope, &None); - let coll_typed = coll_result.typed.clone(); - let coll_diags = coll_result.diagnostics.clone(); - let elem_type_node = for_each_element_type_node( - resolved_type(coll_typed.clone()), - scope.type_env.clone().source_indices.clone(), - ); - let elem_provenance = - derive_element_provenance(coll_typed.clone(), &elem_type_node, &scope); - let body_scope = - extend_scope(&scope, &variable, elem_type_node.clone(), elem_provenance); - let body_result = infer_expr(&body_expr, &body_scope, &None); - let body_typed = body_result.typed.clone(); - let body_diags = body_result.diagnostics.clone(); - let fe_texpr = make_named_expr_node( - &variable, - Rc::new(ExprData::ExprForEach), - Rc::new(vec![coll_typed.clone(), body_typed.clone()]), - body_typed.inferred.clone(), - span.clone(), - node_name_span(&texpr), - ); - Rc::new(InferResult { - typed: fe_texpr, - diagnostics: v2_rt::concat(coll_diags, body_diags.clone()), - }) - } - ExprData::ExprIndex => { - let span = texpr.span.clone(); - let base_expr = index_base(texpr.clone()); - let idx_key = index_expr(texpr.clone()); - let base_result = infer_expr(&base_expr, &scope, &None); - let base_typed = base_result.typed.clone(); - let base_diags = base_result.diagnostics.clone(); - let index_result = infer_expr(&idx_key, &scope, &None); - let index_typed = index_result.typed.clone(); - let index_diags = index_result.diagnostics.clone(); - let index_check = match base_typed.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: base_type, .. - }) => match index_typed.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: index_type, .. - }) => Some(check_index_access_node( - base_type.clone(), - index_type.clone(), - &span, - scope.module_name.clone(), - &scope.type_env.clone().source_indices.clone(), - )), - _ => None, - }, - _ => None, - }; - let access_failure_inferred = match base_typed.inferred.clone().as_deref().cloned() - { - Some(InferredNode::Resolved { .. }) => index_typed.inferred.clone(), - _ => base_typed.inferred.clone(), - }; - let idx_inferred = match index_check.clone() { - Some(checked) => checked.inferred.clone(), - None => Some(inferred_or_error( - access_failure_inferred, - "invalid index access".to_string(), - span.clone(), - )), - }; - let index_access_diags = match index_check.clone() { - Some(checked) => checked.diagnostics.clone(), - None => Rc::new(vec![]), - }; - let idx_texpr = make_expr_node( - Rc::new(ExprData::ExprIndex), - Rc::new(vec![base_typed.clone(), index_typed.clone()]), - idx_inferred, - span.clone(), - ); - Rc::new(InferResult { - typed: idx_texpr, - diagnostics: v2_rt::concat( - v2_rt::concat(base_diags, index_diags), - index_access_diags, - ), - }) - } - ExprData::ExprSlice => { - let span = texpr.span.clone(); - let base_expr = slice_base(texpr.clone()); - let start_expr = slice_start(texpr.clone()); - let end_expr = slice_end(texpr.clone()); - let base_result = infer_expr(&base_expr, &scope, &None); - let base_typed = base_result.typed.clone(); - let base_diags = base_result.diagnostics.clone(); - let start_result = infer_expr(&start_expr, &scope, &None); - let start_typed = start_result.typed.clone(); - let start_diags = start_result.diagnostics.clone(); - let end_result = infer_expr(&end_expr, &scope, &None); - let end_typed = end_result.typed.clone(); - let end_diags = end_result.diagnostics.clone(); - let slice_check = match base_typed.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: base_type, .. - }) => match start_typed.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: start_type, .. - }) => match end_typed.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: end_type, .. }) => { - Some(check_slice_access_node( - base_type.clone(), - start_type.clone(), - end_type.clone(), - &span, - &scope.module_name.clone(), - &scope.type_env.clone().source_indices.clone(), - )) - } - _ => None, - }, - _ => None, - }, - _ => None, - }; - let access_failure_inferred = match base_typed.inferred.clone().as_deref().cloned() +} + } else { + extend_scope_with_params(&scope, lam_params.clone()) + }; +let body_expected = if (expected.clone() != None) { { - Some(InferredNode::Resolved { .. }) => { - match start_typed.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { .. }) => end_typed.inferred.clone(), - _ => start_typed.inferred.clone(), - } + let exp = expected.clone().unwrap(); +if ((exp.params.clone().len() as i64) > 0) { + Some(callable_inferred(&exp)) + } else { + None } - _ => base_typed.inferred.clone(), - }; - let slc_inferred = match slice_check.clone() { - Some(checked) => checked.inferred.clone(), - None => Some(inferred_or_error( - access_failure_inferred, - "invalid slice access".to_string(), - span.clone(), - )), - }; - let slice_access_diags = match slice_check.clone() { - Some(checked) => checked.diagnostics.clone(), - None => Rc::new(vec![]), - }; - let slc_texpr = make_expr_node( - Rc::new(ExprData::ExprSlice), - Rc::new(vec![ - base_typed.clone(), - start_typed.clone(), - end_typed.clone(), - ]), - slc_inferred, - span.clone(), - ); - Rc::new(InferResult { - typed: slc_texpr, - diagnostics: v2_rt::concat( - v2_rt::concat(v2_rt::concat(base_diags, start_diags), end_diags), - slice_access_diags, - ), - }) - } - ExprData::ExprReturn => { - let span = texpr.span.clone(); - let inner_expr = return_value(texpr.clone()); - let inner_result = infer_expr(&inner_expr, &scope, &expected); - let ret_texpr = make_expr_node( - Rc::new(ExprData::ExprReturn), - Rc::new(vec![inner_result.typed.clone()]), - inner_result.typed.clone().inferred.clone(), - span.clone(), - ); - Rc::new(InferResult { - typed: ret_texpr, - diagnostics: inner_result.diagnostics.clone(), - }) - } - _ => { - let span = texpr.span.clone(); - Rc::new(InferResult { - typed: make_expr_error_node( - ExprErrorKind::InternalExprError, - &"unhandled expression variant in infer_expr".to_string(), - &span, - ), - diagnostics: Rc::new(vec![inference_error( - "unhandled expression variant in infer_expr".to_string(), - span.clone(), - scope.module_name.clone(), - )]), - }) +} + } else { + None + }; +let body_scope = Rc::new(InferScope { + type_env: lam_scope.type_env.clone(), + func_env: lam_scope.func_env.clone(), + locals: lam_scope.locals.clone(), + match_bound_names: lam_scope.match_bound_names.clone(), + module_name: lam_scope.module_name.clone(), + service_registry: lam_scope.service_registry.clone(), + item_registry: lam_scope.item_registry.clone(), + lambda_param_provenance: v2_rt::rc_empty_map::>(), +}); +let body_result = infer_expr(&lam_body, &body_scope, &body_expected); +let body_typed = body_result.typed.clone(); +let body_diags = body_result.diagnostics.clone(); +let typed_param_nodes = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(lam_param_nodes.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let pn = pair.1.clone(); +let param_name = match lam_params.clone().get(pair.0.clone() as usize).cloned() { + Some(n) => n.clone(), + None => "".to_string(), +}; +let param_type = match v2_rt::map_get(&lam_scope.locals.clone(), param_name.clone()) { + Some(binding) => Some(Rc::new(InferredNode::Resolved { + node: binding.resolved.clone(), +})), + None => None, +}; +Rc::new(Node { + name: pn.name.clone(), + ident: pn.ident.clone(), + span: pn.span.clone(), + ident_span: pn.ident_span.clone(), + children: pn.children.clone(), + connective: pn.connective.clone(), + params: pn.params.clone(), + inferred: param_type.clone(), + return_cardinality: pn.return_cardinality.clone(), + uses: pn.uses.clone(), + body: pn.body.clone(), + transport: pn.transport.clone(), + properties: pn.properties.clone(), + type_annotation: pn.type_annotation.clone(), + is_self_recursive: pn.is_self_recursive.clone(), + has_non_tail_self_call: pn.has_non_tail_self_call.clone(), + match_pattern: pn.match_pattern.clone(), + expr_data: pn.expr_data.clone(), +}) +}); } __result }); +let lam_texpr = make_expr_node(Rc::new(ExprData::ExprLambda), v2_rt::concat(Rc::new(vec![body_typed.clone()]), typed_param_nodes), body_typed.inferred.clone(), span.clone()); +Rc::new(InferResult { + typed: lam_texpr, + diagnostics: body_diags.clone(), +}) +}, + ExprData::ExprStringInterp => { + let span = texpr.span.clone(); +let typed_part_nodes = Rc::new({ let mut __result = Vec::new(); for part_node in texpr.children.clone().iter().cloned() { __result.push(match (*part_node.expr_data.clone()).clone() { + ExprData::ExprLiteral { .. } => part_node.clone(), + _ => match part_node.children.clone().first().cloned() { + Some(inner) => { + let r = infer_expr(&inner, &scope, &None); +make_interp_part_node(r.typed.clone(), part_node.span.clone()) +}, + None => part_node.clone(), +}, +}); } __result }); +let interp_diags = Rc::new({ let mut __result = Vec::new(); for part_node in texpr.children.clone().iter().cloned() { __result.extend((*match (*part_node.expr_data.clone()).clone() { + ExprData::ExprLiteral { .. } => Rc::new(vec![]), + _ => match part_node.children.clone().first().cloned() { + Some(inner) => { + let r = infer_expr(&inner, &scope, &None); +r.diagnostics.clone() +}, + None => Rc::new(vec![]), +}, +}).iter().cloned()); } __result }); +let si_texpr = make_expr_node(Rc::new(ExprData::ExprStringInterp), typed_part_nodes, Some(Rc::new(InferredNode::Resolved { + node: string_type(), +})), span.clone()); +Rc::new(InferResult { + typed: si_texpr, + diagnostics: interp_diags, +}) +}, + ExprData::ExprBlock => { + let span = texpr.span.clone(); +let stmts = texpr.children.clone(); +if ((stmts.clone().len() as i64) > 0) { + { + let state = infer_block_stmts(stmts.clone(), (stmts.clone().len() as i64), scope.clone(), Rc::new(vec![]), Rc::new(vec![]), unit_type(), expected.clone()); +let blk_texpr = make_expr_node(Rc::new(ExprData::ExprBlock), state.typed_stmts.clone(), Some(Rc::new(InferredNode::Resolved { + node: state.last_type.clone(), +})), span.clone()); +Rc::new(InferResult { + typed: blk_texpr, + diagnostics: Rc::new({ let mut __result = Vec::new(); for c in state.diag_chunks.clone().iter().cloned() { __result.extend((*c.clone()).iter().cloned()); } __result }), +}) +} + } else { + ok_infer(make_expr_node(Rc::new(ExprData::ExprBlock), Rc::new(vec![]), Some(Rc::new(InferredNode::Resolved { + node: unit_type(), +})), span.clone())) } - } +}, + ExprData::ExprCast => { + let span = texpr.span.clone(); +let cast_inner = cast_expr(texpr.clone()); +let target_type = cast_target(texpr.clone()); +let inner_result = infer_expr(&cast_inner, &scope, &None); +let inner_typed = inner_result.typed.clone(); +let inner_diags = inner_result.diagnostics.clone(); +let si = scope.type_env.clone().source_indices.clone(); +let target_name = authored_name_at(si.clone(), &target_type); +let cast_diag = validate_cast(inner_typed.inferred.clone(), &target_name, span.clone(), si.clone(), scope.module_name.clone()); +let cast_diags = match cast_diag { + Some(d) => Rc::new(vec![d.clone()]), + None => Rc::new(vec![]), +}; +let cast_texpr = make_expr_node(Rc::new(ExprData::ExprCast), Rc::new(vec![inner_typed.clone(), target_type.clone()]), Some(Rc::new(InferredNode::Resolved { + node: target_type.clone(), +})), span.clone()); +Rc::new(InferResult { + typed: cast_texpr, + diagnostics: v2_rt::concat(inner_diags, cast_diags), +}) +}, + ExprData::ExprForEach => { + let variable = foreach_variable_at(texpr.clone(), scope.type_env.clone().source_indices.clone()); +let span = texpr.span.clone(); +let coll = foreach_collection(texpr.clone()); +let body_expr = foreach_body(texpr.clone()); +let coll_result = infer_expr(&coll, &scope, &None); +let coll_typed = coll_result.typed.clone(); +let coll_diags = coll_result.diagnostics.clone(); +let elem_type_node = for_each_element_type_node(resolved_type(coll_typed.clone()), scope.type_env.clone().source_indices.clone()); +let elem_provenance = derive_element_provenance(coll_typed.clone(), &elem_type_node, &scope); +let body_scope = extend_scope(&scope, &variable, elem_type_node.clone(), elem_provenance); +let body_result = infer_expr(&body_expr, &body_scope, &None); +let body_typed = body_result.typed.clone(); +let body_diags = body_result.diagnostics.clone(); +let fe_texpr = make_named_expr_node(&variable, Rc::new(ExprData::ExprForEach), Rc::new(vec![coll_typed.clone(), body_typed.clone()]), body_typed.inferred.clone(), span.clone(), node_name_span(&texpr)); +Rc::new(InferResult { + typed: fe_texpr, + diagnostics: v2_rt::concat(coll_diags, body_diags.clone()), +}) +}, + ExprData::ExprIndex => { + let span = texpr.span.clone(); +let base_expr = index_base(texpr.clone()); +let idx_key = index_expr(texpr.clone()); +let base_result = infer_expr(&base_expr, &scope, &None); +let base_typed = base_result.typed.clone(); +let base_diags = base_result.diagnostics.clone(); +let index_result = infer_expr(&idx_key, &scope, &None); +let index_typed = index_result.typed.clone(); +let index_diags = index_result.diagnostics.clone(); +let index_check = match base_typed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: base_type, .. }) => match index_typed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: index_type, .. }) => Some(check_index_access_node(base_type.clone(), index_type.clone(), &span, scope.module_name.clone(), &scope.type_env.clone().source_indices.clone())), + _ => None, +}, + _ => None, +}; +let access_failure_inferred = match base_typed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { .. }) => index_typed.inferred.clone(), + _ => base_typed.inferred.clone(), +}; +let idx_inferred = match index_check.clone() { + Some(checked) => checked.inferred.clone(), + None => Some(inferred_or_error(access_failure_inferred, "invalid index access".to_string(), span.clone())), +}; +let index_access_diags = match index_check.clone() { + Some(checked) => checked.diagnostics.clone(), + None => Rc::new(vec![]), +}; +let idx_texpr = make_expr_node(Rc::new(ExprData::ExprIndex), Rc::new(vec![base_typed.clone(), index_typed.clone()]), idx_inferred, span.clone()); +Rc::new(InferResult { + typed: idx_texpr, + diagnostics: v2_rt::concat(v2_rt::concat(base_diags, index_diags), index_access_diags), +}) +}, + ExprData::ExprSlice => { + let span = texpr.span.clone(); +let base_expr = slice_base(texpr.clone()); +let start_expr = slice_start(texpr.clone()); +let end_expr = slice_end(texpr.clone()); +let base_result = infer_expr(&base_expr, &scope, &None); +let base_typed = base_result.typed.clone(); +let base_diags = base_result.diagnostics.clone(); +let start_result = infer_expr(&start_expr, &scope, &None); +let start_typed = start_result.typed.clone(); +let start_diags = start_result.diagnostics.clone(); +let end_result = infer_expr(&end_expr, &scope, &None); +let end_typed = end_result.typed.clone(); +let end_diags = end_result.diagnostics.clone(); +let slice_check = match base_typed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: base_type, .. }) => match start_typed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: start_type, .. }) => match end_typed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: end_type, .. }) => Some(check_slice_access_node(base_type.clone(), start_type.clone(), end_type.clone(), &span, &scope.module_name.clone(), &scope.type_env.clone().source_indices.clone())), + _ => None, +}, + _ => None, +}, + _ => None, +}; +let access_failure_inferred = match base_typed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { .. }) => match start_typed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { .. }) => end_typed.inferred.clone(), + _ => start_typed.inferred.clone(), +}, + _ => base_typed.inferred.clone(), +}; +let slc_inferred = match slice_check.clone() { + Some(checked) => checked.inferred.clone(), + None => Some(inferred_or_error(access_failure_inferred, "invalid slice access".to_string(), span.clone())), +}; +let slice_access_diags = match slice_check.clone() { + Some(checked) => checked.diagnostics.clone(), + None => Rc::new(vec![]), +}; +let slc_texpr = make_expr_node(Rc::new(ExprData::ExprSlice), Rc::new(vec![base_typed.clone(), start_typed.clone(), end_typed.clone()]), slc_inferred, span.clone()); +Rc::new(InferResult { + typed: slc_texpr, + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(base_diags, start_diags), end_diags), slice_access_diags), +}) +}, + ExprData::ExprReturn => { + let span = texpr.span.clone(); +let inner_expr = return_value(texpr.clone()); +let inner_result = infer_expr(&inner_expr, &scope, &expected); +let ret_texpr = make_expr_node(Rc::new(ExprData::ExprReturn), Rc::new(vec![inner_result.typed.clone()]), inner_result.typed.clone().inferred.clone(), span.clone()); +Rc::new(InferResult { + typed: ret_texpr, + diagnostics: inner_result.diagnostics.clone(), +}) +}, + _ => { + let span = texpr.span.clone(); +Rc::new(InferResult { + typed: make_expr_error_node(ExprErrorKind::InternalExprError, &"unhandled expression variant in infer_expr".to_string(), &span), + diagnostics: Rc::new(vec![inference_error("unhandled expression variant in infer_expr".to_string(), span.clone(), scope.module_name.clone())]), +}) +}, +} }) } -pub fn infer_record_lit( - type_name: &Option, - field_inits: Rc>>, - span: &Rc, - name_span: Rc, - scope: &Rc, -) -> Rc { +pub fn infer_record_lit(type_name: &Option, field_inits: Rc>>, span: &Rc, name_span: Rc, scope: &Rc) -> Rc { { let struct_fields = record_lit_expected_fields(type_name.clone(), &scope); - let fi_infer_results = Rc::new({ - let mut __result = Vec::new(); - for fi in field_inits.iter().cloned() { - __result.push({ - let fi_name = field_init_node_name_at( - fi.clone(), - scope.type_env.clone().source_indices.clone(), - ); - let field_expected = match Rc::new({ - let mut __result = Vec::new(); - for sf in struct_fields.clone().iter().cloned() { - if (authored_name_at( - scope.type_env.clone().source_indices.clone(), - &sf, - ) - .as_str() - == fi_name.clone().as_str()) - { - __result.push(sf); - } - } - __result - }) - .first() - .cloned() - { - Some(sf) => { - let ft = resolved_type(sf.clone()); - if (ft.ident_span.clone() != None) { - Some(ft.clone()) - } else { - None - } - } - None => None, - }; - let ar = infer_expr(&field_init_node_value(&fi), &scope, &field_expected); - let ar_typed = ar.typed.clone(); - let ar_diags = ar.diagnostics.clone(); - let field_type_diags = match field_expected.clone() { - Some(expected_node) => { - let got_node = resolved_type(ar_typed.clone()); - if rejects_string_for_optional_coproduct_field( - &expected_node, - got_node.clone(), - scope.type_env.clone().source_indices.clone(), - ) { - Rc::new(vec![type_mismatch_error( - node_type_shape( - &expected_node, - &scope.type_env.clone().source_indices.clone(), - ), - node_type_shape( - &got_node, - &scope.type_env.clone().source_indices.clone(), - ), - ar_typed.span.clone(), - scope.module_name.clone(), - )]) - } else { - Rc::new(vec![]) - } - } - None => Rc::new(vec![]), - }; - Rc::new(FieldInferResult { - typed_field: make_field_init_node( - &fi_name, - ar_typed.clone(), - fi.span.clone(), - node_name_span(&fi), - ), - infer_result: ar.clone(), - diagnostics: v2_rt::concat(ar_diags.clone(), field_type_diags.clone()), - }) - }); - } - __result - }); - let typed_fields = Rc::new({ - let mut __result = Vec::new(); - for fir in fi_infer_results.clone().iter().cloned() { - __result.push(fir.typed_field.clone()); - } - __result - }); - let fi_diags = Rc::new({ - let mut __result = Vec::new(); - for fir in fi_infer_results.clone().iter().cloned() { - __result.extend((*fir.diagnostics.clone()).iter().cloned()); - } - __result - }); - if (type_name.clone() == None) { +let fi_infer_results = Rc::new({ let mut __result = Vec::new(); for fi in field_inits.iter().cloned() { __result.push({ + let fi_name = field_init_node_name_at(fi.clone(), scope.type_env.clone().source_indices.clone()); +let field_expected = match Rc::new({ let mut __result = Vec::new(); for sf in struct_fields.clone().iter().cloned() { if (authored_name_at(scope.type_env.clone().source_indices.clone(), &sf).as_str() == fi_name.clone().as_str()) { __result.push(sf); } } __result }).first().cloned() { + Some(sf) => { + let ft = resolved_type(sf.clone()); +if (ft.ident_span.clone() != None) { + Some(ft.clone()) + } else { + None + } +}, + None => None, +}; +let ar = infer_expr(&field_init_node_value(&fi), &scope, &field_expected); +let ar_typed = ar.typed.clone(); +let ar_diags = ar.diagnostics.clone(); +let field_type_diags = match field_expected.clone() { + Some(expected_node) => { + let got_node = resolved_type(ar_typed.clone()); +if rejects_string_for_optional_coproduct_field(&expected_node, got_node.clone(), scope.type_env.clone().source_indices.clone()) { + Rc::new(vec![type_mismatch_error(node_type_shape(&expected_node, &scope.type_env.clone().source_indices.clone()), node_type_shape(&got_node, &scope.type_env.clone().source_indices.clone()), ar_typed.span.clone(), scope.module_name.clone())]) + } else { + Rc::new(vec![]) + } +}, + None => Rc::new(vec![]), +}; +Rc::new(FieldInferResult { + typed_field: make_field_init_node(&fi_name, ar_typed.clone(), fi.span.clone(), node_name_span(&fi)), + infer_result: ar.clone(), + diagnostics: v2_rt::concat(ar_diags.clone(), field_type_diags.clone()), +}) +}); } __result }); +let typed_fields = Rc::new({ let mut __result = Vec::new(); for fir in fi_infer_results.clone().iter().cloned() { __result.push(fir.typed_field.clone()); } __result }); +let fi_diags = Rc::new({ let mut __result = Vec::new(); for fir in fi_infer_results.clone().iter().cloned() { __result.extend((*fir.diagnostics.clone()).iter().cloned()); } __result }); +if (type_name.clone() == None) { { - let child_nodes = Rc::new({ - let mut __result = Vec::new(); - for fir in fi_infer_results.clone().iter().cloned() { - __result.push(Rc::new(Node { - name: field_init_node_name_at( - fir.typed_field.clone(), - scope.type_env.clone().source_indices.clone(), - ), - span: fir.typed_field.clone().span.clone(), - ident_span: fir.typed_field.clone().ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: fir.infer_result.clone().typed.clone().inferred.clone(), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - })); - } - __result - }); - let anon_node = Rc::new(Node { - name: "".to_string(), - span: no_span(), - ident_span: None, - children: child_nodes, - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let typed_field_nodes = typed_fields; - let texpr = make_expr_node( - Rc::new(ExprData::ExprRecordLit { parent_enum: None }), - typed_field_nodes, - Some(Rc::new(InferredNode::Resolved { node: anon_node })), - span.clone(), - ); - Rc::new(InferResult { - typed: texpr, - diagnostics: fi_diags, - }) - } + let child_nodes = Rc::new({ let mut __result = Vec::new(); for fir in fi_infer_results.clone().iter().cloned() { __result.push(Rc::new(Node { + name: field_init_node_name_at(fir.typed_field.clone(), scope.type_env.clone().source_indices.clone()), + span: fir.typed_field.clone().span.clone(), + ident_span: fir.typed_field.clone().ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: fir.infer_result.clone().typed.clone().inferred.clone(), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})); } __result }); +let anon_node = Rc::new(Node { + name: "".to_string(), + span: no_span(), + ident_span: None, + children: child_nodes, + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let typed_field_nodes = typed_fields; +let texpr = make_expr_node(Rc::new(ExprData::ExprRecordLit { + parent_enum: None, +}), typed_field_nodes, Some(Rc::new(InferredNode::Resolved { + node: anon_node, +})), span.clone()); +Rc::new(InferResult { + typed: texpr, + diagnostics: fi_diags, +}) +} } else { { - let type_lookup = - lookup_type_by_name(&scope.type_env.clone(), type_name.clone().unwrap()); - let local_variant_parent = - lookup_variant_parent_enum(&scope, &type_name.clone().unwrap()); - let effective_lookup = match type_lookup.clone() { - Some(_) => type_lookup.clone(), - None => { - let local_lookup = - lookup_in_scope(scope.locals.clone(), type_name.clone().unwrap()); - match local_lookup { - Some(local_node) => { - lookup_type_for(&scope.type_env.clone(), &local_node) - } - None => None, - } - } - }; - let raw_resolved = match effective_lookup.clone() { - Some(tn) => tn.clone(), - None => error_type(), - }; - let expected_optional_parent = Some("Optional".to_string()); - let is_some_ctor = ((type_name.clone().unwrap().as_str() - == "Some".to_string().as_str()) - && (local_variant_parent.clone().as_deref() - == expected_optional_parent.as_deref())); - let resolved_node = if is_some_ctor { + let type_lookup = lookup_type_by_name(&scope.type_env.clone(), type_name.clone().unwrap()); +let local_variant_parent = lookup_variant_parent_enum(&scope, &type_name.clone().unwrap()); +let effective_lookup = match type_lookup.clone() { + Some(_) => type_lookup.clone(), + None => { + let local_lookup = lookup_in_scope(scope.locals.clone(), type_name.clone().unwrap()); +match local_lookup { + Some(local_node) => lookup_type_for(&scope.type_env.clone(), &local_node), + None => None, +} +}, +}; +let raw_resolved = match effective_lookup.clone() { + Some(tn) => tn.clone(), + None => error_type(), +}; +let expected_optional_parent = Some("Optional".to_string()); +let is_some_ctor = ((type_name.clone().unwrap().as_str() == "Some".to_string().as_str()) && (local_variant_parent.clone().as_deref() == expected_optional_parent.as_deref())); +let resolved_node = if is_some_ctor { { - let val_field = Rc::new({ - let mut __result = Vec::new(); - for fir in fi_infer_results.clone().iter().cloned() { - if (field_init_node_name_at( - fir.typed_field.clone(), - scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == "value".to_string().as_str()) - { - __result.push(fir); - } - } - __result - }) - .first() - .cloned(); - match val_field { - Some(val_fir) => with_optional_cardinality(&resolved_type( - val_fir.infer_result.clone().typed.clone(), - )), - None => raw_resolved, - } - } + let val_field = Rc::new({ let mut __result = Vec::new(); for fir in fi_infer_results.clone().iter().cloned() { if (field_init_node_name_at(fir.typed_field.clone(), scope.type_env.clone().source_indices.clone()).as_str() == "value".to_string().as_str()) { __result.push(fir); } } __result }).first().cloned(); +match val_field { + Some(val_fir) => with_optional_cardinality(&resolved_type(val_fir.infer_result.clone().typed.clone())), + None => raw_resolved, +} +} } else { raw_resolved }; - let type_diags = match effective_lookup.clone() { - Some(_) => Rc::new(vec![]), - None => Rc::new(vec![inference_error( - v2_rt::concat( - v2_rt::concat("type '".to_string(), type_name.clone().unwrap()), - "' not found in scope".to_string(), - ), - span.clone(), - scope.module_name.clone(), - )]), - }; - let typed_field_nodes2 = typed_fields; - let rl_name = match type_name.clone() { - Some(tn_val) => tn_val.clone(), - None => "".to_string(), - }; - let texpr = make_named_expr_node( - &rl_name, - Rc::new(ExprData::ExprRecordLit { - parent_enum: local_variant_parent.clone(), - }), - typed_field_nodes2, - Some(Rc::new(InferredNode::Resolved { - node: resolved_node, - })), - span.clone(), - name_span, - ); - Rc::new(InferResult { - typed: texpr, - diagnostics: v2_rt::concat(fi_diags, type_diags), - }) - } +let type_diags = match effective_lookup.clone() { + Some(_) => Rc::new(vec![]), + None => Rc::new(vec![inference_error(v2_rt::concat(v2_rt::concat("type '".to_string(), type_name.clone().unwrap()), "' not found in scope".to_string()), span.clone(), scope.module_name.clone())]), +}; +let typed_field_nodes2 = typed_fields; +let rl_name = match type_name.clone() { + Some(tn_val) => tn_val.clone(), + None => "".to_string(), +}; +let texpr = make_named_expr_node(&rl_name, Rc::new(ExprData::ExprRecordLit { + parent_enum: local_variant_parent.clone(), +}), typed_field_nodes2, Some(Rc::new(InferredNode::Resolved { + node: resolved_node, +})), span.clone(), name_span); +Rc::new(InferResult { + typed: texpr, + diagnostics: v2_rt::concat(fi_diags, type_diags), +}) +} } - } +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum SizeExpr { - ParamSize { param: String }, - DividedSize { param: String, divisor: i64 }, + ParamSize { + param: String, + }, + DividedSize { + param: String, + divisor: i64, + }, } impl SizeExpr { pub fn param(&self) -> String { @@ -4474,182 +2596,119 @@ pub struct DescentContext { pub fn classify_size_expr(val: &Rc, ctx: &Rc) -> Option> { match (*val.expr_data.clone()).clone() { - ExprData::ExprMethodCall { .. } => { - let mname = - expr_method_name_at(val.clone(), ctx.type_env.clone().source_indices.clone()); - if (mname.as_str() == "count".to_string().as_str()) { - { - let receiver = method_receiver(val.clone()); - match (*receiver.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let rname = expr_var_name_at( - receiver.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&ctx.param_names.clone(), rname.clone()) { - Some(_) => Some(Rc::new(SizeExpr::ParamSize { - param: rname.clone(), - })), - None => None, - } - } - _ => None, - } - } + ExprData::ExprMethodCall { .. } => { + let mname = expr_method_name_at(val.clone(), ctx.type_env.clone().source_indices.clone()); +if (mname.as_str() == "count".to_string().as_str()) { + { + let receiver = method_receiver(val.clone()); +match (*receiver.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let rname = expr_var_name_at(receiver.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.param_names.clone(), rname.clone()) { + Some(_) => Some(Rc::new(SizeExpr::ParamSize { + param: rname.clone(), +})), + None => None, +} +}, + _ => None, +} +} + } else { + None + } +}, + ExprData::ExprBinOp { .. } => { + let left = binop_left(val.clone()); +let right = binop_right(val.clone()); +match (*val.expr_data.clone()).clone() { + ExprData::ExprBinOp { op: BinOp::Div, .. } => match (*left.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let lname = expr_var_name_at(left.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.size_aliases.clone(), lname).as_deref().cloned() { + Some(SizeExpr::ParamSize { param: p, .. }) => match (*right.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: d, .. } = value.as_ref() else { unreachable!() }; if (d.clone() > 0) { + Some(Rc::new(SizeExpr::DividedSize { + param: p.clone(), + divisor: d.clone(), +})) } else { None - } - } - ExprData::ExprBinOp { .. } => { - let left = binop_left(val.clone()); - let right = binop_right(val.clone()); - match (*val.expr_data.clone()).clone() { - ExprData::ExprBinOp { op: BinOp::Div, .. } => match (*left.expr_data.clone()) - .clone() - { - ExprData::ExprVar { .. } => { - let lname = expr_var_name_at( - left.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&ctx.size_aliases.clone(), lname) - .as_deref() - .cloned() - { - Some(SizeExpr::ParamSize { param: p, .. }) => { - match (*right.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: d, .. } = value.as_ref() - else { - unreachable!() - }; - if (d.clone() > 0) { - Some(Rc::new(SizeExpr::DividedSize { - param: p.clone(), - divisor: d.clone(), - })) - } else { - None - } - } - _ => None, - } - } - _ => None, - } - } - _ => None, - }, - _ => None, - } - } - _ => None, - } + } }, + _ => None, +}, + _ => None, +} +}, + _ => None, +}, + _ => None, +} +}, + _ => None, +} } -pub fn proportional_skip_alias_plus_literal( - alias_expr: &Rc, - lit_expr: Rc, - param_name: &String, - ctx: &Rc, -) -> Option> { +pub fn proportional_skip_alias_plus_literal(alias_expr: &Rc, lit_expr: Rc, param_name: &String, ctx: &Rc) -> Option> { match (*alias_expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let aname = expr_var_name_at( - alias_expr.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&ctx.size_aliases.clone(), aname) - .as_deref() - .cloned() - { - Some(SizeExpr::DividedSize { - param: p, - divisor: d, - .. - }) => { - if (p.clone().as_str() == param_name.clone().as_str()) { - match (*lit_expr.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { - unreachable!() - }; - if (k.clone() > 0) { - match proportional_divisor_from_int_at_least_two(d.clone()) { - Some(div_w) => { - let synth_field = Rc::new(InductiveField { - type_name: param_name.clone(), - variant_name: "".to_string(), - field_name: "skip".to_string(), - shape: RecursionShape::ListRecursion, - element_type: param_name.clone(), - }); - Some(Rc::new(SubValueRelation::StrictSubValue { - field: synth_field, - factor: Rc::new(ShrinkFactor::ProportionalShrink { - divisor: div_w.clone(), - }), - })) - } - None => None, - } - } else { - None - } - } - _ => None, - } - } else { - None - } - } - _ => None, - } - } - _ => None, - } + ExprData::ExprVar { .. } => { + let aname = expr_var_name_at(alias_expr.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.size_aliases.clone(), aname).as_deref().cloned() { + Some(SizeExpr::DividedSize { param: p, divisor: d, .. }) => if (p.clone().as_str() == param_name.clone().as_str()) { + match (*lit_expr.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { unreachable!() }; if (k.clone() > 0) { + match proportional_divisor_from_int_at_least_two(d.clone()) { + Some(div_w) => { + let synth_field = Rc::new(InductiveField { + type_name: param_name.clone(), + variant_name: "".to_string(), + field_name: "skip".to_string(), + shape: RecursionShape::ListRecursion, + element_type: param_name.clone(), +}); +Some(Rc::new(SubValueRelation::StrictSubValue { + field: synth_field, + factor: Rc::new(ShrinkFactor::ProportionalShrink { + divisor: div_w.clone(), +}), +})) +}, + None => None, +} + } else { + None + } }, + _ => None, +} + } else { + None + }, + _ => None, +} +}, + _ => None, +} } -pub fn classify_collection_shrink( - arg_expr: &Rc, - param_name: &String, - ctx: &Rc, -) -> Rc { +pub fn classify_collection_shrink(arg_expr: &Rc, param_name: &String, ctx: &Rc) -> Rc { match (*arg_expr.expr_data.clone()).clone() { - ExprData::ExprMethodCall { .. } => { - let mname = expr_method_name_at( - 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())) + ExprData::ExprMethodCall { .. } => { + let mname = expr_method_name_at(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())) { { - { - let receiver = method_receiver(arg_expr.clone()); - match (*receiver.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let rname = expr_var_name_at( - receiver.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - if (rname.as_str() == param_name.clone().as_str()) { - { - let args = method_arg_nodes(arg_expr.clone()); - match args.first().cloned() { - Some(arg_node) => { - let arg_val = arg_value(&arg_node); - match (*arg_val.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: k, .. } = - value.as_ref() - else { - unreachable!() - }; - if ((k.clone() > 0) - && (mname.clone().as_str() - == "skip".to_string().as_str())) - { - match positive_descent_amount_from_positive_int(k.clone()) { + let receiver = method_receiver(arg_expr.clone()); +match (*receiver.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let rname = expr_var_name_at(receiver.clone(), ctx.type_env.clone().source_indices.clone()); +if (rname.as_str() == param_name.clone().as_str()) { + { + let args = method_arg_nodes(arg_expr.clone()); +match args.first().cloned() { + Some(arg_node) => { + let arg_val = arg_value(&arg_node); +match (*arg_val.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { unreachable!() }; if ((k.clone() > 0) && (mname.clone().as_str() == "skip".to_string().as_str())) { + match positive_descent_amount_from_positive_int(k.clone()) { Some(steps) => { let synth_field = Rc::new(InductiveField { type_name: param_name.clone(), @@ -4667,31 +2726,14 @@ Rc::new(SubValueRelation::StrictSubValue { }, None => Rc::new(SubValueRelation::SubValueUnknown), } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - ExprData::ExprVar { .. } => { - let aname = expr_var_name_at( - arg_val.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get( - &ctx.size_aliases.clone(), - aname, - ) - .as_deref() - .cloned() - { - Some(SizeExpr::DividedSize { - param: p, - divisor: d, - .. - }) => { - if (p.clone().as_str() - == param_name.clone().as_str()) - { - match proportional_divisor_from_int_at_least_two(d.clone()) { + } else { + Rc::new(SubValueRelation::SubValueUnknown) + } }, + ExprData::ExprVar { .. } => { + let aname = expr_var_name_at(arg_val.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.size_aliases.clone(), aname).as_deref().cloned() { + Some(SizeExpr::DividedSize { param: p, divisor: d, .. }) => if (p.clone().as_str() == param_name.clone().as_str()) { + match proportional_divisor_from_int_at_least_two(d.clone()) { Some(div_w) => { let synth_field = Rc::new(InductiveField { type_name: param_name.clone(), @@ -4709,66 +2751,50 @@ Rc::new(SubValueRelation::StrictSubValue { }, None => Rc::new(SubValueRelation::SubValueUnknown), } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - _ => Rc::new( - SubValueRelation::SubValueUnknown, - ), - } - } - ExprData::ExprBinOp { op, .. } => { - match op.clone() { - BinOp::Add => { - if (mname.clone().as_str() - == "skip".to_string().as_str()) - { - { - let left = - binop_left(arg_val.clone()); - let right = binop_right( - arg_val.clone(), - ); - match proportional_skip_alias_plus_literal(&left, right.clone(), ¶m_name, &ctx) { + } else { + Rc::new(SubValueRelation::SubValueUnknown) + }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + ExprData::ExprBinOp { op, .. } => match op.clone() { + BinOp::Add => if (mname.clone().as_str() == "skip".to_string().as_str()) { + { + let left = binop_left(arg_val.clone()); +let right = binop_right(arg_val.clone()); +match proportional_skip_alias_plus_literal(&left, right.clone(), ¶m_name, &ctx) { Some(rel) => rel.clone(), None => match proportional_skip_alias_plus_literal(&right, left.clone(), ¶m_name, &ctx) { Some(rel) => rel.clone(), None => Rc::new(SubValueRelation::SubValueUnknown), }, } - } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - BinOp::Sub => Rc::new( - SubValueRelation::SubValueUnknown, - ), - _ => Rc::new( - SubValueRelation::SubValueUnknown, - ), - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - } - } - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), +} + } else { + Rc::new(SubValueRelation::SubValueUnknown) + }, + BinOp::Sub => Rc::new(SubValueRelation::SubValueUnknown), + _ => Rc::new(SubValueRelation::SubValueUnknown), +}, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + None => Rc::new(SubValueRelation::SubValueUnknown), +} +} + } else { + Rc::new(SubValueRelation::SubValueUnknown) } - } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } +}, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} +} + } else { + Rc::new(SubValueRelation::SubValueUnknown) } - _ => Rc::new(SubValueRelation::SubValueUnknown), - } +}, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -4779,870 +2805,464 @@ pub struct BlockAnnotateAcc { pub fn method_callback_element_position(semantics: Option>) -> Option { match semantics.as_deref().cloned() { - Some(MethodSemantics::AlgebraMethodSemantics { - algebra_template: at, - .. - }) => match at.clone() { - Some(template) => template.callback_element_position.clone(), - None => None, - }, - _ => None, - } + Some(MethodSemantics::AlgebraMethodSemantics { algebra_template: at, .. }) => match at.clone() { + Some(template) => template.callback_element_position.clone(), + None => None, +}, + _ => None, +} } -pub fn maybe_insert_composed_field_relation( - acc: Rc>>, - fname: String, - composed: Option>, -) -> Rc>> { +pub fn maybe_insert_composed_field_relation(acc: Rc>>, fname: String, composed: Option>) -> Rc>> { match composed { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::SubValueUnknown => acc, - _ => v2_rt::rc_map_insert(acc, fname, rel.clone()), - }, - None => acc, - } + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::SubValueUnknown => acc, + _ => v2_rt::rc_map_insert(acc, fname, rel.clone()), +}, + None => acc, +} } -pub fn maybe_insert_output_field_relation( - acc: Rc>>, - idx: i64, - fname: String, - sig: Rc, - val: Rc, - ctx: Rc, -) -> Rc>> { +pub fn maybe_insert_output_field_relation(acc: Rc>>, idx: i64, fname: String, sig: Rc, val: Rc, ctx: Rc) -> Rc>> { { let composed = match sig.output_provenance.clone().get(idx as usize).cloned() { - Some(param_map) => classify_call_via_provenance(val, ¶m_map, ctx), - None => None, - }; - maybe_insert_composed_field_relation(acc, fname, composed) - } -} - -pub fn maybe_insert_match_field_relation( - fp_acc: Rc>>, - pname: &String, - field_label: String, - vname: String, - scrut_rel: Option>, - param_types: Rc>, - type_env: Rc, -) -> Rc>> { - match scrut_rel { - Some(rel) => { - let lookup_type = match (*rel.clone()).clone() { - SubValueRelation::PreservedValue => { - match v2_rt::map_get(¶m_types, pname.clone()) { - Some(t) => t.clone(), - None => "".to_string(), - } - } - SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), - SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), - _ => "".to_string(), - }; - if (lookup_type.clone().as_str() != "".to_string().as_str()) { - { - 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()))) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match matching { - Some(ind_field) => v2_rt::rc_map_insert( - fp_acc, - pname.clone(), - compose_sub_value(rel.clone(), ind_field.clone()), - ), - None => fp_acc, - } - } - } else { - fp_acc - } - } - None => fp_acc, - } + Some(param_map) => classify_call_via_provenance(val, ¶m_map, ctx), + None => None, +}; +maybe_insert_composed_field_relation(acc, fname, composed) } - -pub fn build_per_field_for_let( - val: &Rc, - binding_name: String, - ctx: &Rc, -) -> Rc>>>> { - match (*val.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let callee = - expr_call_func_at(val.clone(), ctx.type_env.clone().source_indices.clone()); - match v2_rt::map_get(&ctx.func_sigs.clone(), callee) { - Some(sig) => { - if ((sig.output_provenance.clone().len() as i64) > 1) { - { - let return_type = sig.inferred.clone(); - let field_map = Rc::new( - return_type - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, - pair: (i64, Rc)| { - let idx = pair.0.clone(); - let field_node = pair.1.clone(); - let fname = authored_name_at( - ctx.type_env.clone().source_indices.clone(), - &field_node, - ); - maybe_insert_output_field_relation( - acc, - idx.clone(), - fname.clone(), - sig.clone(), - val.clone(), - ctx.clone(), - ) - }, - ); - if ((Rc::new(v2_rt::map_keys(&field_map)).len() as i64) > 0) { - v2_rt::rc_map_insert( - ctx.per_field_vars.clone(), - binding_name, - field_map.clone(), - ) - } else { - ctx.per_field_vars.clone() - } - } - } else { - ctx.per_field_vars.clone() - } - } - None => ctx.per_field_vars.clone(), - } - } - ExprData::ExprMethodCall { .. } => { - let callee = - expr_method_name_at(val.clone(), ctx.type_env.clone().source_indices.clone()); - match v2_rt::map_get(&ctx.func_sigs.clone(), callee) { - Some(sig) => { - if ((sig.output_provenance.clone().len() as i64) > 1) { - { - let return_type = sig.inferred.clone(); - let field_map = Rc::new( - return_type - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, - pair: (i64, Rc)| { - let idx = pair.0.clone(); - let field_node = pair.1.clone(); - let fname = authored_name_at( - ctx.type_env.clone().source_indices.clone(), - &field_node, - ); - maybe_insert_output_field_relation( - acc, - idx.clone(), - fname.clone(), - sig.clone(), - val.clone(), - ctx.clone(), - ) - }, - ); - if ((Rc::new(v2_rt::map_keys(&field_map)).len() as i64) > 0) { - v2_rt::rc_map_insert( - ctx.per_field_vars.clone(), - binding_name, - field_map.clone(), - ) - } else { - ctx.per_field_vars.clone() - } - } - } else { - ctx.per_field_vars.clone() - } - } - None => ctx.per_field_vars.clone(), - } +} + +pub fn maybe_insert_match_field_relation(fp_acc: Rc>>, pname: &String, field_label: String, vname: String, scrut_rel: Option>, param_types: Rc>, type_env: Rc) -> Rc>> { + match scrut_rel { + Some(rel) => { + let lookup_type = match (*rel.clone()).clone() { + SubValueRelation::PreservedValue => match v2_rt::map_get(¶m_types, pname.clone()) { + Some(t) => t.clone(), + None => "".to_string(), +}, + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}; +if (lookup_type.clone().as_str() != "".to_string().as_str()) { + { + 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()))) { __result.push(f); } } __result }).first().cloned(); +match matching { + Some(ind_field) => v2_rt::rc_map_insert(fp_acc, pname.clone(), compose_sub_value(rel.clone(), ind_field.clone())), + None => fp_acc, +} +} + } else { + fp_acc } - _ => ctx.per_field_vars.clone(), - } +}, + None => fp_acc, +} } -pub fn resolve_collection_field( - mut expr: Rc, - mut ctx: Rc, -) -> Option> { - loop { - match (*expr.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(expr.clone()); - let fname = field_access_field_at( - expr.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at( - base.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let base_type = - match v2_rt::map_get(&ctx.param_names.clone(), bname.clone()) { - Some(t) => t.clone(), - None => { - match v2_rt::map_get(&ctx.sub_value_vars.clone(), bname.clone()) - { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { - field: f, .. - } => f.element_type.clone(), - SubValueRelation::IteratedSubValue { - field: f, .. - } => f.element_type.clone(), - _ => "".to_string(), - }, - None => "".to_string(), - } - } - }; - if (base_type.clone().as_str() != "".to_string().as_str()) { - break Rc::new({ - let mut __result = Vec::new(); - for f in Rc::new({ - let mut __result = Vec::new(); - for f in inductive_fields_for( - ctx.type_env.clone(), - base_type.clone(), - ) - .iter() - .cloned() - { - if (f.field_name.clone().as_str() == fname.clone().as_str()) - { - __result.push(f); - } - } - __result - }) - .iter() - .cloned() - { - if match f.shape.clone() { - RecursionShape::ListRecursion => true, - _ => false, - } { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - } else { - break None; - } - } - _ => { - break None; - } - } - } - ExprData::ExprVar { .. } => { - let rname = - expr_var_name_at(expr.clone(), ctx.type_env.clone().source_indices.clone()); - match v2_rt::map_get(&ctx.sub_value_vars.clone(), rname) { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { field: f, .. } => { - match f.shape.clone() { - RecursionShape::ListRecursion => { - break Some(f.clone()); - } - _ => { - break None; - } - } - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - match f.shape.clone() { - RecursionShape::ListRecursion => { - break Some(f.clone()); - } - _ => { - break None; - } - } - } - _ => { - break None; - } - }, - None => { - break None; - } +pub fn build_per_field_for_let(val: &Rc, binding_name: String, ctx: &Rc) -> Rc>>>> { + match (*val.expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(val.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.func_sigs.clone(), callee) { + Some(sig) => if ((sig.output_provenance.clone().len() as i64) > 1) { + { + let return_type = sig.inferred.clone(); +let field_map = Rc::new(return_type.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, pair: (i64, Rc)| { + let idx = pair.0.clone(); +let field_node = pair.1.clone(); +let fname = authored_name_at(ctx.type_env.clone().source_indices.clone(), &field_node); +maybe_insert_output_field_relation(acc, idx.clone(), fname.clone(), sig.clone(), val.clone(), ctx.clone()) +}); +if ((Rc::new(v2_rt::map_keys(&field_map)).len() as i64) > 0) { + v2_rt::rc_map_insert(ctx.per_field_vars.clone(), binding_name, field_map.clone()) + } else { + ctx.per_field_vars.clone() } - } - ExprData::ExprMethodCall { .. } => { - 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())); - if is_collection_preserving { - { - let __tco_0 = method_receiver(expr); - expr = __tco_0; - continue; - } +} + } else { + ctx.per_field_vars.clone() + }, + None => ctx.per_field_vars.clone(), +} +}, + ExprData::ExprMethodCall { .. } => { + let callee = expr_method_name_at(val.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.func_sigs.clone(), callee) { + Some(sig) => if ((sig.output_provenance.clone().len() as i64) > 1) { + { + let return_type = sig.inferred.clone(); +let field_map = Rc::new(return_type.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, pair: (i64, Rc)| { + let idx = pair.0.clone(); +let field_node = pair.1.clone(); +let fname = authored_name_at(ctx.type_env.clone().source_indices.clone(), &field_node); +maybe_insert_output_field_relation(acc, idx.clone(), fname.clone(), sig.clone(), val.clone(), ctx.clone()) +}); +if ((Rc::new(v2_rt::map_keys(&field_map)).len() as i64) > 0) { + v2_rt::rc_map_insert(ctx.per_field_vars.clone(), binding_name, field_map.clone()) } else { - break None; + ctx.per_field_vars.clone() } - } - _ => { - break None; - } - } - } +} + } else { + ctx.per_field_vars.clone() + }, + None => ctx.per_field_vars.clone(), +} +}, + _ => ctx.per_field_vars.clone(), +} +} + +pub fn resolve_collection_field(mut expr: Rc, mut ctx: Rc) -> Option> { + loop { + match (*expr.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { let base = field_access_base(expr.clone()); +let fname = field_access_field_at(expr.clone(), ctx.type_env.clone().source_indices.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { let bname = expr_var_name_at(base.clone(), ctx.type_env.clone().source_indices.clone()); +let base_type = match v2_rt::map_get(&ctx.param_names.clone(), bname.clone()) { + Some(t) => t.clone(), + None => match v2_rt::map_get(&ctx.sub_value_vars.clone(), bname.clone()) { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}, + None => "".to_string(), +}, +}; +if (base_type.clone().as_str() != "".to_string().as_str()) { + break Rc::new({ let mut __result = Vec::new(); for f in Rc::new({ let mut __result = Vec::new(); for f in inductive_fields_for(ctx.type_env.clone(), base_type.clone()).iter().cloned() { if (f.field_name.clone().as_str() == fname.clone().as_str()) { __result.push(f); } } __result }).iter().cloned() { if match f.shape.clone() { + RecursionShape::ListRecursion => true, + _ => false, +} { __result.push(f); } } __result }).first().cloned(); +} else { + break None; +} }, + _ => { break None; }, +} }, + ExprData::ExprVar { .. } => { let rname = expr_var_name_at(expr.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.sub_value_vars.clone(), rname) { + Some(rel) => { match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => { match f.shape.clone() { + RecursionShape::ListRecursion => { break Some(f.clone()); }, + _ => { break None; }, +} }, + SubValueRelation::IteratedSubValue { field: f, .. } => { match f.shape.clone() { + RecursionShape::ListRecursion => { break Some(f.clone()); }, + _ => { break None; }, +} }, + _ => { break None; }, +} }, + None => { break None; }, +} }, + ExprData::ExprMethodCall { .. } => { 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())); +if is_collection_preserving { + { + let __tco_0 = method_receiver(expr); +expr = __tco_0; +continue; +} +} else { + break None; +} }, + _ => { break None; }, +} +} } pub fn classify_binding_provenance(val: &Rc, scope: &Rc) -> Rc { match (*val.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = - expr_var_name_at(val.clone(), scope.type_env.clone().source_indices.clone()); - match v2_rt::map_get(&scope.locals.clone(), vname) { - Some(binding) => binding.provenance.clone(), - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(val.clone()); - let field = - field_access_field_at(val.clone(), scope.type_env.clone().source_indices.clone()); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at( - base.clone(), - scope.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&scope.locals.clone(), bname) { - Some(binding) => { - let fields = inductive_fields_for( - scope.type_env.clone(), - authored_name_at( - scope.type_env.clone().source_indices.clone(), - &binding.resolved.clone(), - ), - ); - 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()) { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match matching { - Some(ind_field) => { - compose_sub_value(binding.provenance.clone(), ind_field.clone()) - } - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - } + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(val.clone(), scope.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&scope.locals.clone(), vname) { + Some(binding) => binding.provenance.clone(), + None => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(val.clone()); +let field = field_access_field_at(val.clone(), scope.type_env.clone().source_indices.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), scope.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&scope.locals.clone(), bname) { + Some(binding) => { + let fields = inductive_fields_for(scope.type_env.clone(), authored_name_at(scope.type_env.clone().source_indices.clone(), &binding.resolved.clone())); +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()) { __result.push(f); } } __result }).first().cloned(); +match matching { + Some(ind_field) => compose_sub_value(binding.provenance.clone(), ind_field.clone()), + None => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + None => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} } -pub fn classify_let_value( - val: &Rc, - ctx: &Rc, -) -> Option> { +pub fn classify_let_value(val: &Rc, ctx: &Rc) -> Option> { match (*val.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at(val.clone(), ctx.type_env.clone().source_indices.clone()); - match v2_rt::map_get(&ctx.scope_locals.clone(), vname) { - Some(binding) => match (*binding.provenance.clone()).clone() { - SubValueRelation::SubValueUnknown => None, - _ => Some(binding.provenance.clone()), - }, - None => None, - } - } - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(val.clone()); - let field = - field_access_field_at(val.clone(), ctx.type_env.clone().source_indices.clone()); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = - expr_var_name_at(base.clone(), ctx.type_env.clone().source_indices.clone()); - let from_per_field = - match v2_rt::map_get(&ctx.per_field_vars.clone(), bname.clone()) { - Some(field_map) => v2_rt::map_get(&field_map, field.clone()), - None => None, - }; - match from_per_field { - Some(rel) => Some(rel.clone()), - None => { - let type_name = - match v2_rt::map_get(&ctx.scope_locals.clone(), bname.clone()) { - Some(binding) => authored_name_at( - ctx.type_env.clone().source_indices.clone(), - &binding.resolved.clone(), - ), - None => match v2_rt::map_get( - &ctx.param_names.clone(), - bname.clone(), - ) { - Some(t) => t.clone(), - None => "".to_string(), - }, - }; - if (type_name.clone().as_str() != "".to_string().as_str()) { - { - let fields = inductive_fields_for( - ctx.type_env.clone(), - type_name.clone(), - ); - 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()) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match matching { - Some(ind_field) => { - Some(Rc::new(SubValueRelation::StrictSubValue { - field: ind_field.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), - })) - } - None => None, - } - } - } else { - None - } - } - } - } - _ => None, - } - } - ExprData::ExprCall { .. } => { - let callee = - expr_call_func_at(val.clone(), ctx.type_env.clone().source_indices.clone()); - let from_provenance = match v2_rt::map_get(&ctx.func_sigs.clone(), callee.clone()) { - Some(sig) => match sig.output_provenance.clone().first().cloned() { - Some(param_map) => { - classify_call_via_provenance(val.clone(), ¶m_map, ctx.clone()) - } - None => None, - }, - None => None, - }; - match from_provenance.clone() { - Some(_) => from_provenance.clone(), - None => { - if (is_child_accessor_in_model(callee.clone()) - || is_tree_size_reducing(callee.clone())) + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(val.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.scope_locals.clone(), vname) { + Some(binding) => match (*binding.provenance.clone()).clone() { + SubValueRelation::SubValueUnknown => None, + _ => Some(binding.provenance.clone()), +}, + None => None, +} +}, + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(val.clone()); +let field = field_access_field_at(val.clone(), ctx.type_env.clone().source_indices.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), ctx.type_env.clone().source_indices.clone()); +let from_per_field = match v2_rt::map_get(&ctx.per_field_vars.clone(), bname.clone()) { + Some(field_map) => v2_rt::map_get(&field_map, field.clone()), + None => None, +}; +match from_per_field { + Some(rel) => Some(rel.clone()), + None => { + let type_name = match v2_rt::map_get(&ctx.scope_locals.clone(), bname.clone()) { + Some(binding) => authored_name_at(ctx.type_env.clone().source_indices.clone(), &binding.resolved.clone()), + None => match v2_rt::map_get(&ctx.param_names.clone(), bname.clone()) { + Some(t) => t.clone(), + None => "".to_string(), +}, +}; +if (type_name.clone().as_str() != "".to_string().as_str()) { { - { - let call_args = val.children.clone(); - match call_args.first().cloned() { - Some(first_arg) => { - let inner = arg_value(&first_arg); - match (*inner.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let iname = expr_var_name_at( - inner.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let inner_type = match v2_rt::map_get( - &ctx.param_names.clone(), - iname.clone(), - ) { - Some(t) => t.clone(), - None => match v2_rt::map_get( - &ctx.sub_value_vars.clone(), - iname.clone(), - ) { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { - field: f, - .. - } => f.element_type.clone(), - SubValueRelation::IteratedSubValue { - field: f, - .. - } => f.element_type.clone(), - _ => "".to_string(), - }, - None => "".to_string(), - }, - }; - if (inner_type.clone().as_str() - != "".to_string().as_str()) - { - { - let fields = inductive_fields_for( - ctx.type_env.clone(), - inner_type.clone(), - ); - let cf = - Rc::new({ - let mut __result = Vec::new(); - for f in fields.iter().cloned() { - if match f.shape.clone() { + let fields = inductive_fields_for(ctx.type_env.clone(), type_name.clone()); +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()) { __result.push(f); } } __result }).first().cloned(); +match matching { + Some(ind_field) => Some(Rc::new(SubValueRelation::StrictSubValue { + field: ind_field.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +})), + None => None, +} +} + } else { + None + } +}, +} +}, + _ => None, +} +}, + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(val.clone(), ctx.type_env.clone().source_indices.clone()); +let from_provenance = match v2_rt::map_get(&ctx.func_sigs.clone(), callee.clone()) { + Some(sig) => match sig.output_provenance.clone().first().cloned() { + Some(param_map) => classify_call_via_provenance(val.clone(), ¶m_map, ctx.clone()), + None => None, +}, + None => None, +}; +match from_provenance.clone() { + Some(_) => from_provenance.clone(), + None => if (is_child_accessor_in_model(callee.clone()) || is_tree_size_reducing(callee.clone())) { + { + let call_args = val.children.clone(); +match call_args.first().cloned() { + Some(first_arg) => { + let inner = arg_value(&first_arg); +match (*inner.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let iname = expr_var_name_at(inner.clone(), ctx.type_env.clone().source_indices.clone()); +let inner_type = match v2_rt::map_get(&ctx.param_names.clone(), iname.clone()) { + Some(t) => t.clone(), + None => match v2_rt::map_get(&ctx.sub_value_vars.clone(), iname.clone()) { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}, + None => "".to_string(), +}, +}; +if (inner_type.clone().as_str() != "".to_string().as_str()) { + { + let fields = inductive_fields_for(ctx.type_env.clone(), inner_type.clone()); +let cf = Rc::new({ let mut __result = Vec::new(); for f in fields.iter().cloned() { if match f.shape.clone() { RecursionShape::ListRecursion => true, _ => false, -} { __result.push(f); } - } - __result - }) - .first() - .cloned(); - match cf { - Some(ind_field) => Some(Rc::new( - SubValueRelation::StrictSubValue { - field: ind_field.clone(), - factor: Rc::new( - ShrinkFactor::UnitShrink, - ), - }, - )), - None => None, - } - } - } else { - None - } - } - _ => None, - } - } - None => None, - } +} { __result.push(f); } } __result }).first().cloned(); +match cf { + Some(ind_field) => Some(Rc::new(SubValueRelation::StrictSubValue { + field: ind_field.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +})), + None => None, +} +} + } else { + None } - } else { - None - } +}, + _ => None, +} +}, + None => None, +} +} + } else { + None + }, +} +}, + _ => { + let type_based = match val.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => if is_container_type(authored_name_at(ctx.type_env.clone().source_indices.clone(), &rt)) { + { + let elem = match rt.children.clone().first().cloned() { + Some(c) => authored_name_at(ctx.type_env.clone().source_indices.clone(), &c), + None => "".to_string(), +}; +if ((elem.clone().as_str() != "".to_string().as_str()) && is_recursive_type_by_name(&ctx.type_env.clone(), elem.clone())) { + { + let fields = inductive_fields_for(ctx.type_env.clone(), elem.clone()); +let cf = Rc::new({ let mut __result = Vec::new(); for f in fields.iter().cloned() { if match f.shape.clone() { + RecursionShape::ListRecursion => true, + _ => false, +} { __result.push(f); } } __result }).first().cloned(); +match cf { + Some(ind_field) => Some(Rc::new(SubValueRelation::StrictSubValue { + field: ind_field.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +})), + None => None, +} +} + } else { + None } - } - } - _ => { - let type_based = match val.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - if is_container_type(authored_name_at( - ctx.type_env.clone().source_indices.clone(), - &rt, - )) { - { - let elem = match rt.children.clone().first().cloned() { - Some(c) => authored_name_at( - ctx.type_env.clone().source_indices.clone(), - &c, - ), - None => "".to_string(), - }; - if ((elem.clone().as_str() != "".to_string().as_str()) - && is_recursive_type_by_name(&ctx.type_env.clone(), elem.clone())) - { - { - let fields = - inductive_fields_for(ctx.type_env.clone(), elem.clone()); - let cf = Rc::new({ - let mut __result = Vec::new(); - for f in fields.iter().cloned() { - if match f.shape.clone() { - RecursionShape::ListRecursion => true, - _ => false, - } { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match cf { - Some(ind_field) => { - Some(Rc::new(SubValueRelation::StrictSubValue { - field: ind_field.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), - })) - } - None => None, - } - } - } else { - None - } - } +} + } else { + None + }, + _ => None, +}; +match type_based.clone() { + Some(_) => type_based.clone(), + None => match (*val.expr_data.clone()).clone() { + ExprData::ExprBinOp { op, .. } => { + let left = binop_left(val.clone()); +let right = binop_right(val.clone()); +match op.clone() { + BinOp::Sub => match (*left.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let lname = expr_var_name_at(left.clone(), ctx.type_env.clone().source_indices.clone()); +if ((v2_rt::map_get(&ctx.param_names.clone(), lname.clone()) != None) || (v2_rt::map_get(&ctx.sub_value_vars.clone(), lname.clone()) != None)) { + match (*right.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { unreachable!() }; match positive_descent_amount_from_positive_int(k.clone()) { + Some(steps) => Some(Rc::new(SubValueRelation::ArithmeticDescent { + param: lname.clone(), + factor: Rc::new(ShrinkFactor::ConstantShrink { + steps: steps.clone(), +}), +})), + None => None, +} }, + _ => None, +} + } else { + None + } +}, + _ => None, +}, + BinOp::Div => { + let left_name = match (*left.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let lname = expr_var_name_at(left.clone(), ctx.type_env.clone().source_indices.clone()); +if ((v2_rt::map_get(&ctx.param_names.clone(), lname.clone()) != None) || (v2_rt::map_get(&ctx.sub_value_vars.clone(), lname.clone()) != None)) { + lname.clone() } else { - None + "".to_string() } - } - _ => None, - }; - match type_based.clone() { - Some(_) => type_based.clone(), - None => match (*val.expr_data.clone()).clone() { - ExprData::ExprBinOp { op, .. } => { - let left = binop_left(val.clone()); - let right = binop_right(val.clone()); - match op.clone() { - BinOp::Sub => match (*left.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let lname = expr_var_name_at( - left.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - if ((v2_rt::map_get(&ctx.param_names.clone(), lname.clone()) - != None) - || (v2_rt::map_get( - &ctx.sub_value_vars.clone(), - lname.clone(), - ) != None)) - { - match (*right.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: k, .. } = - value.as_ref() - else { - unreachable!() - }; - match positive_descent_amount_from_positive_int( - k.clone(), - ) { - Some(steps) => Some(Rc::new( - SubValueRelation::ArithmeticDescent { - param: lname.clone(), - factor: Rc::new( - ShrinkFactor::ConstantShrink { - steps: steps.clone(), - }, - ), - }, - )), - None => None, - } - } - _ => None, - } - } else { - None - } - } - _ => None, - }, - BinOp::Div => { - let left_name = match (*left.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let lname = expr_var_name_at( - left.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - if ((v2_rt::map_get( - &ctx.param_names.clone(), - lname.clone(), - ) != None) - || (v2_rt::map_get( - &ctx.sub_value_vars.clone(), - lname.clone(), - ) != None)) - { - lname.clone() - } else { - "".to_string() - } - } - ExprData::ExprBinOp { op: BinOp::Sub, .. } => { - let inner_left = binop_left(left.clone()); - match (*inner_left.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let lname = expr_var_name_at( - inner_left.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - if ((v2_rt::map_get( - &ctx.param_names.clone(), - lname.clone(), - ) != None) - || (v2_rt::map_get( - &ctx.sub_value_vars.clone(), - lname.clone(), - ) != None)) - { - lname.clone() - } else { - "".to_string() - } - } - _ => "".to_string(), - } - } - _ => "".to_string(), - }; - if (left_name.clone().as_str() != "".to_string().as_str()) { - match (*right.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: k, .. } = - value.as_ref() - else { - unreachable!() - }; - match proportional_divisor_from_int_at_least_two( - k.clone(), - ) { - Some(div_w) => Some(Rc::new( - SubValueRelation::ArithmeticDescent { - param: left_name.clone(), - factor: Rc::new( - ShrinkFactor::ProportionalShrink { - divisor: div_w.clone(), - }, - ), - }, - )), - None => None, - } - } - _ => None, - } - } else { - None - } - } - BinOp::Add => None, - _ => None, +}, + ExprData::ExprBinOp { op: BinOp::Sub, .. } => { + let inner_left = binop_left(left.clone()); +match (*inner_left.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let lname = expr_var_name_at(inner_left.clone(), ctx.type_env.clone().source_indices.clone()); +if ((v2_rt::map_get(&ctx.param_names.clone(), lname.clone()) != None) || (v2_rt::map_get(&ctx.sub_value_vars.clone(), lname.clone()) != None)) { + lname.clone() + } else { + "".to_string() } - } - ExprData::ExprMethodCall { .. } => { - let mname = expr_method_name_at( - val.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let is_collection_preserving = (((((mname.clone().as_str() - == "skip".to_string().as_str()) - || (mname.clone().as_str() == "filter".to_string().as_str())) - || (mname.clone().as_str() == "take".to_string().as_str())) - || (mname.clone().as_str() == "enumerate".to_string().as_str())) - || (mname.clone().as_str() == "reverse".to_string().as_str())); - if is_collection_preserving { - { - let receiver = method_receiver(val.clone()); - let coll_field = - resolve_collection_field(receiver.clone(), ctx.clone()); - match coll_field { - Some(ind_field) => { - Some(Rc::new(SubValueRelation::StrictSubValue { - field: ind_field.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), - })) - } - None => { - if (mname.clone().as_str() == "skip".to_string().as_str()) { - { - let skip_args = method_arg_nodes(val.clone()); - let skip_amount = match skip_args.first().cloned() { - Some(a) => match (*arg_value(&a) - .expr_data - .clone()) - .clone() - { - ExprData::ExprLiteral { - ref value, .. - } => { - let LiteralValue::LitInt { - value: k, - .. - } = value.as_ref() - else { - unreachable!() - }; - if (k.clone() > 0) { - k.clone() - } else { - 0 - } - } - _ => 0, - }, - None => 0, - }; - if (skip_amount.clone() > 0) { - match (*receiver.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let rname = expr_var_name_at( - receiver.clone(), - ctx.type_env - .clone() - .source_indices - .clone(), - ); - if ((v2_rt::map_get( - &ctx.param_names.clone(), - rname.clone(), - ) != None) - || (v2_rt::map_get( - &ctx.sub_value_vars.clone(), - rname.clone(), - ) != None)) - { - match positive_descent_amount_from_positive_int(skip_amount.clone()) { +}, + _ => "".to_string(), +} +}, + _ => "".to_string(), +}; +if (left_name.clone().as_str() != "".to_string().as_str()) { + match (*right.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { unreachable!() }; match proportional_divisor_from_int_at_least_two(k.clone()) { + Some(div_w) => Some(Rc::new(SubValueRelation::ArithmeticDescent { + param: left_name.clone(), + factor: Rc::new(ShrinkFactor::ProportionalShrink { + divisor: div_w.clone(), +}), +})), + None => None, +} }, + _ => None, +} + } else { + None + } +}, + BinOp::Add => None, + _ => None, +} +}, + ExprData::ExprMethodCall { .. } => { + let mname = expr_method_name_at(val.clone(), ctx.type_env.clone().source_indices.clone()); +let is_collection_preserving = (((((mname.clone().as_str() == "skip".to_string().as_str()) || (mname.clone().as_str() == "filter".to_string().as_str())) || (mname.clone().as_str() == "take".to_string().as_str())) || (mname.clone().as_str() == "enumerate".to_string().as_str())) || (mname.clone().as_str() == "reverse".to_string().as_str())); +if is_collection_preserving { + { + let receiver = method_receiver(val.clone()); +let coll_field = resolve_collection_field(receiver.clone(), ctx.clone()); +match coll_field { + Some(ind_field) => Some(Rc::new(SubValueRelation::StrictSubValue { + field: ind_field.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +})), + None => if (mname.clone().as_str() == "skip".to_string().as_str()) { + { + let skip_args = method_arg_nodes(val.clone()); +let skip_amount = match skip_args.first().cloned() { + Some(a) => match (*arg_value(&a).expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { unreachable!() }; if (k.clone() > 0) { + k.clone() + } else { + 0 + } }, + _ => 0, +}, + None => 0, +}; +if (skip_amount.clone() > 0) { + match (*receiver.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let rname = expr_var_name_at(receiver.clone(), ctx.type_env.clone().source_indices.clone()); +if ((v2_rt::map_get(&ctx.param_names.clone(), rname.clone()) != None) || (v2_rt::map_get(&ctx.sub_value_vars.clone(), rname.clone()) != None)) { + match positive_descent_amount_from_positive_int(skip_amount.clone()) { Some(steps) => { let synth_field = Rc::new(InductiveField { type_name: rname.clone(), @@ -5660,628 +3280,350 @@ Some(Rc::new(SubValueRelation::StrictSubValue { }, None => None, } - } else { - None - } - } - _ => None, - } - } else { - None - } - } - } else { - None - } + } else { + None } - } +}, + _ => None, +} + } else { + None } - } else { - None - } - } - _ => None, - }, +} + } else { + None + }, +} +} + } else { + None } - } - } +}, + _ => None, +}, +} +}, +} } -pub fn classify_call_via_provenance( - call: Rc, - param_map: &Rc>>, - ctx: Rc, -) -> Option> { +pub fn classify_call_via_provenance(call: Rc, param_map: &Rc>>, ctx: Rc) -> Option> { { let call_args = call.children.clone(); - let arg_by_name = call_args.iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, arg_node: Rc| match arg_name_at( - arg_node.clone(), - ctx.type_env.clone().source_indices.clone(), - ) { - Some(aname) => { - v2_rt::rc_map_insert(acc.clone(), aname.clone(), arg_value(&arg_node)) - } - None => acc.clone(), - }, - ); - Rc::new(v2_rt::map_keys(¶m_map)).iter().cloned().fold( - None, - |result: _, callee_pname: String| match v2_rt::map_get(¶m_map, callee_pname.clone()) - { - Some(callee_rel) => match v2_rt::map_get(&arg_by_name, callee_pname.clone()) { - Some(arg_expr) => { - let arg_rel = classify_call_arg_provenance(&arg_expr, &ctx); - match arg_rel.clone() { - Some(arel) => { - let composed = - compose_output_relations(arel.clone(), callee_rel.clone()); - match result.clone() { - Some(prev) => { - Some(meet_sub_value(prev.clone(), composed.clone())) - } - None => Some(composed.clone()), - } - } - None => result.clone(), - } - } - None => result.clone(), - }, - None => result.clone(), - }, - ) - } +let arg_by_name = call_args.iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, arg_node: Rc| match arg_name_at(arg_node.clone(), ctx.type_env.clone().source_indices.clone()) { + Some(aname) => v2_rt::rc_map_insert(acc.clone(), aname.clone(), arg_value(&arg_node)), + None => acc.clone(), +}); +Rc::new(v2_rt::map_keys(¶m_map)).iter().cloned().fold(None, |result: _, callee_pname: String| match v2_rt::map_get(¶m_map, callee_pname.clone()) { + Some(callee_rel) => match v2_rt::map_get(&arg_by_name, callee_pname.clone()) { + Some(arg_expr) => { + let arg_rel = classify_call_arg_provenance(&arg_expr, &ctx); +match arg_rel.clone() { + Some(arel) => { + let composed = compose_output_relations(arel.clone(), callee_rel.clone()); +match result.clone() { + Some(prev) => Some(meet_sub_value(prev.clone(), composed.clone())), + None => Some(composed.clone()), +} +}, + None => result.clone(), +} +}, + None => result.clone(), +}, + None => result.clone(), +}) +} } -pub fn classify_call_arg_provenance( - arg_expr: &Rc, - ctx: &Rc, -) -> Option> { +pub fn classify_call_arg_provenance(arg_expr: &Rc, ctx: &Rc) -> Option> { match (*arg_expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let name = expr_var_name_at( - arg_expr.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - if (v2_rt::map_get(&ctx.param_names.clone(), name.clone()) != None) { - Some(Rc::new(SubValueRelation::PreservedValue)) - } else { - v2_rt::map_get(&ctx.sub_value_vars.clone(), name.clone()) - } + ExprData::ExprVar { .. } => { + let name = expr_var_name_at(arg_expr.clone(), ctx.type_env.clone().source_indices.clone()); +if (v2_rt::map_get(&ctx.param_names.clone(), name.clone()) != None) { + Some(Rc::new(SubValueRelation::PreservedValue)) + } else { + v2_rt::map_get(&ctx.sub_value_vars.clone(), name.clone()) } - _ => classify_let_value(&arg_expr, &ctx), - } +}, + _ => classify_let_value(&arg_expr, &ctx), +} } pub fn merge_argument_relations(rels: &Rc>>) -> Rc { match rels.clone().first().cloned() { - None => Rc::new(SubValueRelation::SubValueUnknown), - Some(first_rel) => Rc::new( - rels.clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) - .iter() - .cloned() - .fold( - first_rel.clone(), - |acc: Rc, rel: Rc| meet_sub_value(acc, rel.clone()), - ), - } + None => Rc::new(SubValueRelation::SubValueUnknown), + Some(first_rel) => Rc::new(rels.clone().iter().cloned().skip(1 as usize).collect::>()).iter().cloned().fold(first_rel.clone(), |acc: Rc, rel: Rc| meet_sub_value(acc, rel.clone())), +} } -pub fn classify_argument( - arg_expr: &Rc, - param_name: &String, - ctx: &Rc, -) -> Rc { +pub fn classify_argument(arg_expr: &Rc, param_name: &String, ctx: &Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*arg_expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at( - arg_expr.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - if (vname.clone().as_str() == param_name.clone().as_str()) { - Rc::new(SubValueRelation::PreservedValue) - } else { - match v2_rt::map_get(&ctx.sub_value_vars.clone(), vname.clone()) { - Some(rel) => rel.clone(), - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - } - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(arg_expr.clone()); - let field = field_access_field_at( - arg_expr.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at( - base.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let type_name = - match v2_rt::map_get(&ctx.param_names.clone(), bname.clone()) { - Some(t) => t.clone(), - None => { - match v2_rt::map_get(&ctx.sub_value_vars.clone(), bname.clone()) - { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { - field: f, .. - } => f.element_type.clone(), - SubValueRelation::IteratedSubValue { - field: f, .. - } => f.element_type.clone(), - _ => "".to_string(), - }, - None => "".to_string(), - } - } - }; - let fields = inductive_fields_for(ctx.type_env.clone(), type_name); - 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()) { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match matching { - Some(ind_field) => Rc::new(SubValueRelation::StrictSubValue { - field: ind_field.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), - }), - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - } - } - ExprData::ExprCall { .. } => { - let call_args = arg_expr.children.clone(); - match call_args.first().cloned() { - Some(first_arg) => { - let inner = arg_value(&first_arg); - let inner_rel = classify_argument(&inner, ¶m_name, &ctx); - match (*inner_rel.clone()).clone() { - SubValueRelation::StrictSubValue { .. } => inner_rel.clone(), - SubValueRelation::IteratedSubValue { .. } => inner_rel.clone(), - SubValueRelation::ArithmeticDescent { .. } => inner_rel.clone(), - SubValueRelation::PreservedValue => { - let callee = expr_call_func_at( - arg_expr.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let from_provenance = - match v2_rt::map_get(&ctx.func_sigs.clone(), callee.clone()) { - Some(sig) => { - match sig.output_provenance.clone().first().cloned() { - Some(param_map) => classify_call_via_provenance( - arg_expr.clone(), - ¶m_map, - ctx.clone(), - ), - None => None, - } - } - None => None, - }; - match from_provenance { - Some(prov_rel) => prov_rel.clone(), - None => { - if (is_child_accessor_in_model(callee.clone()) - || is_tree_size_reducing(callee.clone())) - { - { - let type_name = match v2_rt::map_get( - &ctx.param_names.clone(), - param_name.clone(), - ) { - Some(t) => t.clone(), - None => "".to_string(), - }; - let fields = inductive_fields_for( - ctx.type_env.clone(), - type_name, - ); - let cf = Rc::new({ - let mut __result = Vec::new(); - for f in fields.iter().cloned() { - if match f.shape.clone() { - RecursionShape::ListRecursion => true, - _ => false, - } { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match cf { - Some(ind_field) => { - Rc::new(SubValueRelation::StrictSubValue { - field: ind_field.clone(), - factor: Rc::new( - ShrinkFactor::UnitShrink, - ), - }) - } - None => { - Rc::new(SubValueRelation::PreservedValue) - } - } - } - } else { - if is_property_contraction(callee.clone()) { - Rc::new(SubValueRelation::ArithmeticDescent { - param: param_name.clone(), - factor: Rc::new(ShrinkFactor::ConstantShrink { - steps: Rc::new( - PositiveDescentAmount::OneStep, - ), - }), - }) - } else { - Rc::new(SubValueRelation::PreservedValue) - } - } - } - } - } - SubValueRelation::SubValueUnknown => { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - } - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - ExprData::ExprMethodCall { .. } => { - classify_collection_shrink(&arg_expr, ¶m_name, &ctx) + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(arg_expr.clone(), ctx.type_env.clone().source_indices.clone()); +if (vname.clone().as_str() == param_name.clone().as_str()) { + Rc::new(SubValueRelation::PreservedValue) + } else { + match v2_rt::map_get(&ctx.sub_value_vars.clone(), vname.clone()) { + Some(rel) => rel.clone(), + None => Rc::new(SubValueRelation::SubValueUnknown), +} } - ExprData::ExprBinOp { op, .. } => { - let left = binop_left(arg_expr.clone()); - let right = binop_right(arg_expr.clone()); - match op.clone() { - BinOp::Sub => { - let left_is_param = match (*left.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - ((expr_var_name_at( - left.clone(), - ctx.type_env.clone().source_indices.clone(), - ) - .as_str() - == param_name.clone().as_str()) - || (v2_rt::map_get( - &ctx.sub_value_vars.clone(), - expr_var_name_at( - left.clone(), - ctx.type_env.clone().source_indices.clone(), - ), - ) != None)) - } - _ => false, - }; - if left_is_param { - match (*right.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: k, .. } = value.as_ref() - else { - unreachable!() - }; - match positive_descent_amount_from_positive_int(k.clone()) { - Some(steps) => { - Rc::new(SubValueRelation::ArithmeticDescent { - param: param_name.clone(), - factor: Rc::new(ShrinkFactor::ConstantShrink { - steps: steps.clone(), - }), - }) - } - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - } - } else { - Rc::new(SubValueRelation::SubValueUnknown) - } - } - BinOp::Div => { - let left_is_param = match (*left.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - ((expr_var_name_at( - left.clone(), - ctx.type_env.clone().source_indices.clone(), - ) - .as_str() - == param_name.clone().as_str()) - || (v2_rt::map_get( - &ctx.sub_value_vars.clone(), - expr_var_name_at( - left.clone(), - ctx.type_env.clone().source_indices.clone(), - ), - ) != None)) - } - ExprData::ExprBinOp { op: BinOp::Sub, .. } => { - let inner_left = binop_left(left.clone()); - match (*inner_left.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - ((expr_var_name_at( - inner_left.clone(), - ctx.type_env.clone().source_indices.clone(), - ) - .as_str() - == param_name.clone().as_str()) - || (v2_rt::map_get( - &ctx.sub_value_vars.clone(), - expr_var_name_at( - inner_left.clone(), - ctx.type_env.clone().source_indices.clone(), - ), - ) != None)) - } - _ => false, - } - } - _ => false, - }; - if left_is_param { - match (*right.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: k, .. } = value.as_ref() - else { - unreachable!() - }; - match proportional_divisor_from_int_at_least_two(k.clone()) { - Some(div_w) => { - Rc::new(SubValueRelation::ArithmeticDescent { - param: param_name.clone(), - factor: Rc::new(ShrinkFactor::ProportionalShrink { - divisor: div_w.clone(), - }), - }) - } - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - } +}, + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(arg_expr.clone()); +let field = field_access_field_at(arg_expr.clone(), ctx.type_env.clone().source_indices.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), ctx.type_env.clone().source_indices.clone()); +let type_name = match v2_rt::map_get(&ctx.param_names.clone(), bname.clone()) { + Some(t) => t.clone(), + None => match v2_rt::map_get(&ctx.sub_value_vars.clone(), bname.clone()) { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}, + None => "".to_string(), +}, +}; +let fields = inductive_fields_for(ctx.type_env.clone(), type_name); +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()) { __result.push(f); } } __result }).first().cloned(); +match matching { + Some(ind_field) => Rc::new(SubValueRelation::StrictSubValue { + field: ind_field.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +}), + None => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + ExprData::ExprCall { .. } => { + let call_args = arg_expr.children.clone(); +match call_args.first().cloned() { + Some(first_arg) => { + let inner = arg_value(&first_arg); +let inner_rel = classify_argument(&inner, ¶m_name, &ctx); +match (*inner_rel.clone()).clone() { + SubValueRelation::StrictSubValue { .. } => inner_rel.clone(), + SubValueRelation::IteratedSubValue { .. } => inner_rel.clone(), + SubValueRelation::ArithmeticDescent { .. } => inner_rel.clone(), + SubValueRelation::PreservedValue => { + let callee = expr_call_func_at(arg_expr.clone(), ctx.type_env.clone().source_indices.clone()); +let from_provenance = match v2_rt::map_get(&ctx.func_sigs.clone(), callee.clone()) { + Some(sig) => match sig.output_provenance.clone().first().cloned() { + Some(param_map) => classify_call_via_provenance(arg_expr.clone(), ¶m_map, ctx.clone()), + None => None, +}, + None => None, +}; +match from_provenance { + Some(prov_rel) => prov_rel.clone(), + None => if (is_child_accessor_in_model(callee.clone()) || is_tree_size_reducing(callee.clone())) { + { + let type_name = match v2_rt::map_get(&ctx.param_names.clone(), param_name.clone()) { + Some(t) => t.clone(), + None => "".to_string(), +}; +let fields = inductive_fields_for(ctx.type_env.clone(), type_name); +let cf = Rc::new({ let mut __result = Vec::new(); for f in fields.iter().cloned() { if match f.shape.clone() { + RecursionShape::ListRecursion => true, + _ => false, +} { __result.push(f); } } __result }).first().cloned(); +match cf { + Some(ind_field) => Rc::new(SubValueRelation::StrictSubValue { + field: ind_field.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +}), + None => Rc::new(SubValueRelation::PreservedValue), +} +} + } else { + if is_property_contraction(callee.clone()) { + Rc::new(SubValueRelation::ArithmeticDescent { + param: param_name.clone(), + factor: Rc::new(ShrinkFactor::ConstantShrink { + steps: Rc::new(PositiveDescentAmount::OneStep), +}), +}) } else { - Rc::new(SubValueRelation::SubValueUnknown) + Rc::new(SubValueRelation::PreservedValue) } - } - BinOp::Add => Rc::new(SubValueRelation::SubValueUnknown), - _ => Rc::new(SubValueRelation::SubValueUnknown), + }, +} +}, + SubValueRelation::SubValueUnknown => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + None => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + ExprData::ExprMethodCall { .. } => classify_collection_shrink(&arg_expr, ¶m_name, &ctx), + ExprData::ExprBinOp { op, .. } => { + let left = binop_left(arg_expr.clone()); +let right = binop_right(arg_expr.clone()); +match op.clone() { + BinOp::Sub => { + let left_is_param = match (*left.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => ((expr_var_name_at(left.clone(), ctx.type_env.clone().source_indices.clone()).as_str() == param_name.clone().as_str()) || (v2_rt::map_get(&ctx.sub_value_vars.clone(), expr_var_name_at(left.clone(), ctx.type_env.clone().source_indices.clone())) != None)), + _ => false, +}; +if left_is_param { + match (*right.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { unreachable!() }; match positive_descent_amount_from_positive_int(k.clone()) { + Some(steps) => Rc::new(SubValueRelation::ArithmeticDescent { + param: param_name.clone(), + factor: Rc::new(ShrinkFactor::ConstantShrink { + steps: steps.clone(), +}), +}), + None => Rc::new(SubValueRelation::SubValueUnknown), +} }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} + } else { + Rc::new(SubValueRelation::SubValueUnknown) } - } - ExprData::ExprMatch => { - let arm_rels = Rc::new({ - let mut __result = Vec::new(); - for arm in match_arm_nodes(arg_expr.clone()).iter().cloned() { - __result.push(classify_argument(&arm_body(&arm), ¶m_name, &ctx)); - } - __result - }); - merge_argument_relations(&arm_rels) - } - ExprData::ExprIf => { - let then_rel = - classify_argument(&if_then_branch(arg_expr.clone()), ¶m_name, &ctx); - let else_rel = match if_else_branch(arg_expr.clone()) { - Some(e) => classify_argument(&e, ¶m_name, &ctx), - None => Rc::new(SubValueRelation::SubValueUnknown), - }; - merge_argument_relations(&Rc::new(vec![then_rel, else_rel])) - } - ExprData::ExprBlock => match arg_expr.children.clone().last().cloned() { - Some(last_expr) => classify_argument(&last_expr, ¶m_name, &ctx), - None => Rc::new(SubValueRelation::SubValueUnknown), - }, - ExprData::ExprLet => match let_body(arg_expr.clone()) { - Some(body) => classify_argument(&body, ¶m_name, &ctx), - None => Rc::new(SubValueRelation::SubValueUnknown), - }, - ExprData::ExprCast => { - classify_argument(&cast_expr(arg_expr.clone()), ¶m_name, &ctx) - } - ExprData::ExprReturn => match arg_expr.children.clone().first().cloned() { - Some(inner) => classify_argument(&inner, ¶m_name, &ctx), - None => Rc::new(SubValueRelation::SubValueUnknown), - }, - _ => Rc::new(SubValueRelation::SubValueUnknown), - } +}, + BinOp::Div => { + let left_is_param = match (*left.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => ((expr_var_name_at(left.clone(), ctx.type_env.clone().source_indices.clone()).as_str() == param_name.clone().as_str()) || (v2_rt::map_get(&ctx.sub_value_vars.clone(), expr_var_name_at(left.clone(), ctx.type_env.clone().source_indices.clone())) != None)), + ExprData::ExprBinOp { op: BinOp::Sub, .. } => { + let inner_left = binop_left(left.clone()); +match (*inner_left.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => ((expr_var_name_at(inner_left.clone(), ctx.type_env.clone().source_indices.clone()).as_str() == param_name.clone().as_str()) || (v2_rt::map_get(&ctx.sub_value_vars.clone(), expr_var_name_at(inner_left.clone(), ctx.type_env.clone().source_indices.clone())) != None)), + _ => false, +} +}, + _ => false, +}; +if left_is_param { + match (*right.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: k, .. } = value.as_ref() else { unreachable!() }; match proportional_divisor_from_int_at_least_two(k.clone()) { + Some(div_w) => Rc::new(SubValueRelation::ArithmeticDescent { + param: param_name.clone(), + factor: Rc::new(ShrinkFactor::ProportionalShrink { + divisor: div_w.clone(), +}), +}), + None => Rc::new(SubValueRelation::SubValueUnknown), +} }, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} + } else { + Rc::new(SubValueRelation::SubValueUnknown) + } +}, + BinOp::Add => Rc::new(SubValueRelation::SubValueUnknown), + _ => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + ExprData::ExprMatch => { + let arm_rels = Rc::new({ let mut __result = Vec::new(); for arm in match_arm_nodes(arg_expr.clone()).iter().cloned() { __result.push(classify_argument(&arm_body(&arm), ¶m_name, &ctx)); } __result }); +merge_argument_relations(&arm_rels) +}, + ExprData::ExprIf => { + let then_rel = classify_argument(&if_then_branch(arg_expr.clone()), ¶m_name, &ctx); +let else_rel = match if_else_branch(arg_expr.clone()) { + Some(e) => classify_argument(&e, ¶m_name, &ctx), + None => Rc::new(SubValueRelation::SubValueUnknown), +}; +merge_argument_relations(&Rc::new(vec![then_rel, else_rel])) +}, + ExprData::ExprBlock => match arg_expr.children.clone().last().cloned() { + Some(last_expr) => classify_argument(&last_expr, ¶m_name, &ctx), + None => Rc::new(SubValueRelation::SubValueUnknown), +}, + ExprData::ExprLet => match let_body(arg_expr.clone()) { + Some(body) => classify_argument(&body, ¶m_name, &ctx), + None => Rc::new(SubValueRelation::SubValueUnknown), +}, + ExprData::ExprCast => classify_argument(&cast_expr(arg_expr.clone()), ¶m_name, &ctx), + ExprData::ExprReturn => match arg_expr.children.clone().first().cloned() { + Some(inner) => classify_argument(&inner, ¶m_name, &ctx), + None => Rc::new(SubValueRelation::SubValueUnknown), +}, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} }) } -pub fn read_arg_provenance( - arg_expr: &Rc, - param_name: String, - ctx: &Rc, -) -> Rc { +pub fn read_arg_provenance(arg_expr: &Rc, param_name: String, ctx: &Rc) -> Rc { match (*arg_expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at( - arg_expr.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&ctx.scope_locals.clone(), vname) { - Some(binding) => match (*binding.provenance.clone()).clone() { - SubValueRelation::SubValueUnknown => { - classify_argument(&arg_expr, ¶m_name, &ctx) - } - _ => binding.provenance.clone(), - }, - None => classify_argument(&arg_expr, ¶m_name, &ctx), - } - } - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(arg_expr.clone()); - let field = field_access_field_at( - arg_expr.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = - expr_var_name_at(base.clone(), ctx.type_env.clone().source_indices.clone()); - match v2_rt::map_get(&ctx.scope_locals.clone(), bname) { - Some(binding) => match (*binding.provenance.clone()).clone() { - SubValueRelation::SubValueUnknown => { - classify_argument(&arg_expr, ¶m_name, &ctx) - } - _ => { - let fields = inductive_fields_for( - ctx.type_env.clone(), - authored_name_at( - ctx.type_env.clone().source_indices.clone(), - &binding.resolved.clone(), - ), - ); - 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()) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match matching { - Some(ind_field) => compose_sub_value( - binding.provenance.clone(), - ind_field.clone(), - ), - None => Rc::new(SubValueRelation::SubValueUnknown), - } - } - }, - None => classify_argument(&arg_expr, ¶m_name, &ctx), - } - } - _ => Rc::new(SubValueRelation::SubValueUnknown), - } - } - ExprData::ExprCall { .. } => classify_argument(&arg_expr, ¶m_name, &ctx), - ExprData::ExprMethodCall { .. } => classify_argument(&arg_expr, ¶m_name, &ctx), - ExprData::ExprBinOp { .. } => classify_argument(&arg_expr, ¶m_name, &ctx), - ExprData::ExprMatch => classify_argument(&arg_expr, ¶m_name, &ctx), - ExprData::ExprIf => classify_argument(&arg_expr, ¶m_name, &ctx), - ExprData::ExprBlock => classify_argument(&arg_expr, ¶m_name, &ctx), - ExprData::ExprLet => classify_argument(&arg_expr, ¶m_name, &ctx), - ExprData::ExprCast => classify_argument(&arg_expr, ¶m_name, &ctx), - ExprData::ExprReturn => classify_argument(&arg_expr, ¶m_name, &ctx), - _ => Rc::new(SubValueRelation::SubValueUnknown), - } + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(arg_expr.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.scope_locals.clone(), vname) { + Some(binding) => match (*binding.provenance.clone()).clone() { + SubValueRelation::SubValueUnknown => classify_argument(&arg_expr, ¶m_name, &ctx), + _ => binding.provenance.clone(), +}, + None => classify_argument(&arg_expr, ¶m_name, &ctx), +} +}, + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(arg_expr.clone()); +let field = field_access_field_at(arg_expr.clone(), ctx.type_env.clone().source_indices.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.scope_locals.clone(), bname) { + Some(binding) => match (*binding.provenance.clone()).clone() { + SubValueRelation::SubValueUnknown => classify_argument(&arg_expr, ¶m_name, &ctx), + _ => { + let fields = inductive_fields_for(ctx.type_env.clone(), authored_name_at(ctx.type_env.clone().source_indices.clone(), &binding.resolved.clone())); +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()) { __result.push(f); } } __result }).first().cloned(); +match matching { + Some(ind_field) => compose_sub_value(binding.provenance.clone(), ind_field.clone()), + None => Rc::new(SubValueRelation::SubValueUnknown), +} +}, +}, + None => classify_argument(&arg_expr, ¶m_name, &ctx), +} +}, + _ => Rc::new(SubValueRelation::SubValueUnknown), +} +}, + ExprData::ExprCall { .. } => classify_argument(&arg_expr, ¶m_name, &ctx), + ExprData::ExprMethodCall { .. } => classify_argument(&arg_expr, ¶m_name, &ctx), + ExprData::ExprBinOp { .. } => classify_argument(&arg_expr, ¶m_name, &ctx), + ExprData::ExprMatch => classify_argument(&arg_expr, ¶m_name, &ctx), + ExprData::ExprIf => classify_argument(&arg_expr, ¶m_name, &ctx), + ExprData::ExprBlock => classify_argument(&arg_expr, ¶m_name, &ctx), + ExprData::ExprLet => classify_argument(&arg_expr, ¶m_name, &ctx), + ExprData::ExprCast => classify_argument(&arg_expr, ¶m_name, &ctx), + ExprData::ExprReturn => classify_argument(&arg_expr, ¶m_name, &ctx), + _ => Rc::new(SubValueRelation::SubValueUnknown), +} +} + +pub fn build_call_evidence(call_node: &Rc, ctx: &Rc) -> Rc>> { + { + let arg_map = Rc::new(call_node.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, pair: (i64, Rc)| { + let idx = pair.0.clone(); +let arg_node = pair.1.clone(); +let aname = arg_name_at(arg_node.clone(), ctx.type_env.clone().source_indices.clone()); +match aname.clone() { + Some(pname) => v2_rt::rc_map_insert(acc.clone(), pname.clone(), arg_value(&arg_node)), + None => acc.clone(), +} +}); +let positional_args = Rc::new({ let mut __result = Vec::new(); for arg_node in Rc::new({ let mut __result = Vec::new(); for arg_node in call_node.children.clone().iter().cloned() { if (arg_name_at(arg_node.clone(), ctx.type_env.clone().source_indices.clone()) == None) { __result.push(arg_node); } } __result }).iter().cloned() { __result.push(arg_value(&arg_node)); } __result }); +let positional_idx = 0; +Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(ctx.param_order.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let def_idx = pair.0.clone(); +let pname = pair.1.clone(); +match v2_rt::map_get(&arg_map, pname.clone()) { + Some(arg_val) => read_arg_provenance(&arg_val, pname.clone(), &ctx), + None => match positional_args.clone().get(def_idx.clone() as usize).cloned() { + Some(arg_val) => read_arg_provenance(&arg_val, pname.clone(), &ctx), + None => Rc::new(SubValueRelation::SubValueUnknown), +}, +} +}); } __result }) } - -pub fn build_call_evidence( - call_node: &Rc, - ctx: &Rc, -) -> Rc>> { - { - let arg_map = Rc::new( - call_node - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, pair: (i64, Rc)| { - let idx = pair.0.clone(); - let arg_node = pair.1.clone(); - let aname = arg_name_at( - arg_node.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match aname.clone() { - Some(pname) => { - v2_rt::rc_map_insert(acc.clone(), pname.clone(), arg_value(&arg_node)) - } - None => acc.clone(), - } - }, - ); - let positional_args = Rc::new({ - let mut __result = Vec::new(); - for arg_node in Rc::new({ - let mut __result = Vec::new(); - for arg_node in call_node.children.clone().iter().cloned() { - if (arg_name_at( - arg_node.clone(), - ctx.type_env.clone().source_indices.clone(), - ) == None) - { - __result.push(arg_node); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(arg_value(&arg_node)); - } - __result - }); - let positional_idx = 0; - Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - ctx.param_order - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let def_idx = pair.0.clone(); - let pname = pair.1.clone(); - match v2_rt::map_get(&arg_map, pname.clone()) { - Some(arg_val) => read_arg_provenance(&arg_val, pname.clone(), &ctx), - None => match positional_args - .clone() - .get(def_idx.clone() as usize) - .cloned() - { - Some(arg_val) => read_arg_provenance(&arg_val, pname.clone(), &ctx), - None => Rc::new(SubValueRelation::SubValueUnknown), - }, - } - }); - } - __result - }) - } } pub fn descent_source_type(found: String, arg_node: &Rc, ctx: &Rc) -> String { @@ -6289,334 +3631,188 @@ pub fn descent_source_type(found: String, arg_node: &Rc, ctx: &Rc found.clone(), - _ => { - let arg_val = arg_value(&arg_node); - match (*arg_val.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at( - arg_val.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&ctx.param_names.clone(), vname) { - Some(t) => t.clone(), - None => "".to_string(), - } - } - _ => "".to_string(), - } - } - } + ExprData::ExprLambda => found.clone(), + _ => { + let arg_val = arg_value(&arg_node); +match (*arg_val.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(arg_val.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.param_names.clone(), vname) { + Some(t) => t.clone(), + None => "".to_string(), +} +}, + _ => "".to_string(), +} +}, +} } } pub fn annotate_descent(body: &Rc, ctx: &Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprCall { - call_semantics: cs, .. - } => { - let evidence = build_call_evidence(&body, &ctx); - let source_type = - body.children.clone().iter().cloned().fold( - "".to_string(), - |found: String, arg_node: Rc| { - descent_source_type(found, &arg_node, &ctx) + ExprData::ExprCall { call_semantics: cs, .. } => { + let evidence = build_call_evidence(&body, &ctx); +let source_type = body.children.clone().iter().cloned().fold("".to_string(), |found: String, arg_node: Rc| descent_source_type(found, &arg_node, &ctx)); +let annotated_children = Rc::new({ let mut __result = Vec::new(); for child in body.children.clone().iter().cloned() { __result.push({ + let arg_val = arg_value(&child); +match (*arg_val.expr_data.clone()).clone() { + ExprData::ExprLambda => if (source_type.clone().as_str() != "".to_string().as_str()) { + { + let lparams = lambda_param_names_at(arg_val.clone(), ctx.type_env.clone().source_indices.clone()); +let p1 = match lparams.clone().first().cloned() { + Some(n) => n.clone(), + None => "".to_string(), +}; +let p2 = match lparams.clone().get(1 as usize).cloned() { + Some(n) => n.clone(), + None => "".to_string(), +}; +let lambda_ctx = Rc::new(DescentContext { + fn_name: ctx.fn_name.clone(), + param_names: if (p2.clone().as_str() != "".to_string().as_str()) { + v2_rt::rc_map_insert(v2_rt::rc_map_insert(ctx.param_names.clone(), p1.clone(), source_type.clone()), p2.clone(), source_type.clone()) + } else { + if (p1.clone().as_str() != "".to_string().as_str()) { + v2_rt::rc_map_insert(ctx.param_names.clone(), p1.clone(), source_type.clone()) + } else { + ctx.param_names.clone() + } }, - ); - let annotated_children = Rc::new({ - let mut __result = Vec::new(); - for child in body.children.clone().iter().cloned() { - __result.push({ - let arg_val = arg_value(&child); - match (*arg_val.expr_data.clone()).clone() { - ExprData::ExprLambda => { - if (source_type.clone().as_str() != "".to_string().as_str()) { - { - let lparams = lambda_param_names_at( - arg_val.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let p1 = match lparams.clone().first().cloned() { - Some(n) => n.clone(), - None => "".to_string(), - }; - let p2 = match lparams.clone().get(1 as usize).cloned() - { - Some(n) => n.clone(), - None => "".to_string(), - }; - let lambda_ctx = Rc::new(DescentContext { - fn_name: ctx.fn_name.clone(), - param_names: if (p2.clone().as_str() - != "".to_string().as_str()) - { - v2_rt::rc_map_insert( - v2_rt::rc_map_insert( - ctx.param_names.clone(), - p1.clone(), - source_type.clone(), - ), - p2.clone(), - source_type.clone(), - ) - } else { - if (p1.clone().as_str() - != "".to_string().as_str()) - { - v2_rt::rc_map_insert( - ctx.param_names.clone(), - p1.clone(), - source_type.clone(), - ) - } else { - ctx.param_names.clone() - } - }, - param_order: ctx.param_order.clone(), - type_env: ctx.type_env.clone(), - sub_value_vars: if (p1.clone().as_str() - != "".to_string().as_str()) - { - { - let source_fields = inductive_fields_for( - ctx.type_env.clone(), - source_type.clone(), - ); - let cf = Rc::new({ - let mut __result = Vec::new(); - for f in source_fields - .clone() - .iter() - .cloned() - { - if match f.shape.clone() { + param_order: ctx.param_order.clone(), + type_env: ctx.type_env.clone(), + sub_value_vars: if (p1.clone().as_str() != "".to_string().as_str()) { + { + let source_fields = inductive_fields_for(ctx.type_env.clone(), source_type.clone()); +let cf = Rc::new({ let mut __result = Vec::new(); for f in source_fields.clone().iter().cloned() { if match f.shape.clone() { RecursionShape::ListRecursion => true, _ => false, -} { __result.push(f); } - } - __result - }) - .first() - .cloned(); - let rel = match cf.clone() { +} { __result.push(f); } } __result }).first().cloned(); +let rel = match cf.clone() { Some(f) => Rc::new(SubValueRelation::IteratedSubValue { field: f.clone(), }), None => Rc::new(SubValueRelation::PreservedValue), }; - if (p2.clone().as_str() - != "".to_string().as_str()) - { - v2_rt::rc_map_insert( - v2_rt::rc_map_insert( - ctx.sub_value_vars.clone(), - p1.clone(), - rel.clone(), - ), - p2.clone(), - rel.clone(), - ) - } else { - v2_rt::rc_map_insert( - ctx.sub_value_vars.clone(), - p1.clone(), - rel.clone(), - ) - } - } - } else { - ctx.sub_value_vars.clone() - }, - size_aliases: ctx.size_aliases.clone(), - scope_locals: ctx.scope_locals.clone(), - func_sigs: ctx.func_sigs.clone(), - per_field_vars: ctx.per_field_vars.clone(), - }); - make_arg_node( - arg_name_at( - child.clone(), - ctx.type_env.clone().source_indices.clone(), - ), - annotate_descent(&arg_val, &lambda_ctx), - child.span.clone(), - child.span.clone(), - ) - } - } else { - make_arg_node( - arg_name_at( - child.clone(), - ctx.type_env.clone().source_indices.clone(), - ), - annotate_descent(&arg_val, &ctx), - child.span.clone(), - child.span.clone(), - ) - } - } - _ => make_arg_node( - arg_name_at( - child.clone(), - ctx.type_env.clone().source_indices.clone(), - ), - annotate_descent(&arg_val, &ctx), - child.span.clone(), - child.span.clone(), - ), - } - }); - } - __result - }); - Rc::new(Node { - name: body.name.clone(), - span: body.span.clone(), - ident_span: body.ident_span.clone(), - children: annotated_children, - connective: body.connective.clone(), - params: body.params.clone(), - inferred: body.inferred.clone(), - return_cardinality: body.return_cardinality.clone(), - uses: body.uses.clone(), - body: body.body.clone(), - transport: body.transport.clone(), - properties: body.properties.clone(), - type_annotation: body.type_annotation.clone(), - is_self_recursive: body.is_self_recursive.clone(), - has_non_tail_self_call: body.has_non_tail_self_call.clone(), - match_pattern: body.match_pattern.clone(), - expr_data: Rc::new(ExprData::ExprCall { - call_semantics: cs.clone(), - descent_evidence: Some(evidence), - }), - ident: None, - }) - } - ExprData::ExprMatch => { - let scrut = match_scrutinee(body.clone()); - let scrut_type = match (*scrut.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let sname = expr_var_name_at( - scrut.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&ctx.param_names.clone(), sname.clone()) { - Some(t) => t.clone(), - None => { - match v2_rt::map_get(&ctx.sub_value_vars.clone(), sname.clone()) { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { field: f, .. } => { - f.element_type.clone() - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - f.element_type.clone() - } - _ => "".to_string(), - }, - None => "".to_string(), - } - } - } - } - _ => "".to_string(), - }; - let scrut_inducing_field = match (*scrut.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(scrut.clone()); - let fname = field_access_field_at( - scrut.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at( - base.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let base_type = - match v2_rt::map_get(&ctx.param_names.clone(), bname.clone()) { - Some(t) => t.clone(), - None => "".to_string(), - }; - if (base_type.clone().as_str() != "".to_string().as_str()) { - { - let ind_fields = inductive_fields_for( - ctx.type_env.clone(), - base_type.clone(), - ); - 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()) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned() - } +if (p2.clone().as_str() != "".to_string().as_str()) { + v2_rt::rc_map_insert(v2_rt::rc_map_insert(ctx.sub_value_vars.clone(), p1.clone(), rel.clone()), p2.clone(), rel.clone()) } else { - None + v2_rt::rc_map_insert(ctx.sub_value_vars.clone(), p1.clone(), rel.clone()) } - } - _ => None, - } - } - ExprData::ExprMethodCall { .. } => { - let mname = expr_method_name_at( - 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())) - { - { - let receiver = method_receiver(scrut.clone()); - resolve_collection_field(receiver.clone(), ctx.clone()) - } +} } else { - None - } - } - _ => None, - }; - let scrut_has_inductive = (((scrut_type.clone().as_str() - != "".to_string().as_str()) - && ((inductive_fields_for(ctx.type_env.clone(), scrut_type.clone()).len() - as i64) - > 0)) - || (scrut_inducing_field.clone() != None)); - let scrut_variant_sig = match (*scrut.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - let callee = expr_call_func_at( - scrut.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&ctx.func_sigs.clone(), callee) { - Some(sig) => { - if ((Rc::new(v2_rt::map_keys(&sig.variant_provenance.clone())).len() - as i64) - > 0) - { - Some(sig.clone()) - } else { - None - } - } - None => None, - } + ctx.sub_value_vars.clone() + }, + size_aliases: ctx.size_aliases.clone(), + scope_locals: ctx.scope_locals.clone(), + func_sigs: ctx.func_sigs.clone(), + per_field_vars: ctx.per_field_vars.clone(), +}); +make_arg_node(arg_name_at(child.clone(), ctx.type_env.clone().source_indices.clone()), annotate_descent(&arg_val, &lambda_ctx), child.span.clone(), child.span.clone()) +} + } else { + make_arg_node(arg_name_at(child.clone(), ctx.type_env.clone().source_indices.clone()), annotate_descent(&arg_val, &ctx), child.span.clone(), child.span.clone()) + }, + _ => make_arg_node(arg_name_at(child.clone(), ctx.type_env.clone().source_indices.clone()), annotate_descent(&arg_val, &ctx), child.span.clone(), child.span.clone()), +} +}); } __result }); +Rc::new(Node { + name: body.name.clone(), + span: body.span.clone(), + ident_span: body.ident_span.clone(), + children: annotated_children, + connective: body.connective.clone(), + params: body.params.clone(), + inferred: body.inferred.clone(), + return_cardinality: body.return_cardinality.clone(), + uses: body.uses.clone(), + body: body.body.clone(), + transport: body.transport.clone(), + properties: body.properties.clone(), + type_annotation: body.type_annotation.clone(), + is_self_recursive: body.is_self_recursive.clone(), + has_non_tail_self_call: body.has_non_tail_self_call.clone(), + match_pattern: body.match_pattern.clone(), + expr_data: Rc::new(ExprData::ExprCall { + call_semantics: cs.clone(), + descent_evidence: Some(evidence), +}), + ident: None, +}) +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(body.clone()); +let scrut_type = match (*scrut.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let sname = expr_var_name_at(scrut.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.param_names.clone(), sname.clone()) { + Some(t) => t.clone(), + None => match v2_rt::map_get(&ctx.sub_value_vars.clone(), sname.clone()) { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}, + None => "".to_string(), +}, +} +}, + _ => "".to_string(), +}; +let scrut_inducing_field = match (*scrut.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(scrut.clone()); +let fname = field_access_field_at(scrut.clone(), ctx.type_env.clone().source_indices.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), ctx.type_env.clone().source_indices.clone()); +let base_type = match v2_rt::map_get(&ctx.param_names.clone(), bname.clone()) { + Some(t) => t.clone(), + None => "".to_string(), +}; +if (base_type.clone().as_str() != "".to_string().as_str()) { + { + let ind_fields = inductive_fields_for(ctx.type_env.clone(), base_type.clone()); +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()) { __result.push(f); } } __result }).first().cloned() +} + } else { + None } - _ => None, - }; - let annotated_scrut = annotate_descent(&scrut, &ctx); - let annotated_arms = Rc::new({ - let mut __result = Vec::new(); - for arm_node in match_arm_nodes(body.clone()).iter().cloned() { - __result.push({ +}, + _ => None, +} +}, + ExprData::ExprMethodCall { .. } => { + let mname = expr_method_name_at(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())) { + { + let receiver = method_receiver(scrut.clone()); +resolve_collection_field(receiver.clone(), ctx.clone()) +} + } else { + None + } +}, + _ => None, +}; +let scrut_has_inductive = (((scrut_type.clone().as_str() != "".to_string().as_str()) && ((inductive_fields_for(ctx.type_env.clone(), scrut_type.clone()).len() as i64) > 0)) || (scrut_inducing_field.clone() != None)); +let scrut_variant_sig = match (*scrut.expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(scrut.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.func_sigs.clone(), callee) { + Some(sig) => if ((Rc::new(v2_rt::map_keys(&sig.variant_provenance.clone())).len() as i64) > 0) { + Some(sig.clone()) + } else { + None + }, + None => None, +} +}, + _ => None, +}; +let annotated_scrut = annotate_descent(&scrut, &ctx); +let annotated_arms = Rc::new({ let mut __result = Vec::new(); for arm_node in match_arm_nodes(body.clone()).iter().cloned() { __result.push({ let variant_arm_ctx = match scrut_variant_sig.clone() { Some(sig) => arm_ctx_from_variant_provenance(arm_node.clone(), sig.clone(), scrut.clone(), &ctx), None => None, @@ -6723,933 +3919,578 @@ match matching.clone() { scope_locals: ctx.scope_locals.clone(), func_sigs: ctx.func_sigs.clone(), per_field_vars: ctx.per_field_vars.clone(), -}) - } else { - match scrut_inducing_field.clone() { - Some(ind_field) => Rc::new(DescentContext { +}) + } else { + match scrut_inducing_field.clone() { + Some(ind_field) => Rc::new(DescentContext { + fn_name: ctx.fn_name.clone(), + param_names: v2_rt::rc_map_insert(ctx.param_names.clone(), bname.clone(), ind_field.element_type.clone()), + param_order: ctx.param_order.clone(), + type_env: ctx.type_env.clone(), + sub_value_vars: v2_rt::rc_map_insert(ctx.sub_value_vars.clone(), bname.clone(), Rc::new(SubValueRelation::StrictSubValue { + field: ind_field.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +})), + size_aliases: ctx.size_aliases.clone(), + scope_locals: ctx.scope_locals.clone(), + func_sigs: ctx.func_sigs.clone(), + per_field_vars: ctx.per_field_vars.clone(), +}), + None => ctx.clone(), +} + }, + _ => ctx.clone(), +} + } else { + ctx.clone() + }, +}; +let annotated_body = annotate_descent(&arm_body(&arm_node), &arm_ctx); +make_arm_node(arm_pattern(arm_node.clone()), arm_guard(&arm_node), annotated_body.clone(), arm_node.span.clone()) +}); } __result }); +Rc::new(Node { + name: body.name.clone(), + span: body.span.clone(), + ident_span: body.ident_span.clone(), + children: v2_rt::concat(Rc::new(vec![annotated_scrut]), annotated_arms), + connective: body.connective.clone(), + params: body.params.clone(), + inferred: body.inferred.clone(), + return_cardinality: body.return_cardinality.clone(), + uses: body.uses.clone(), + body: body.body.clone(), + transport: body.transport.clone(), + properties: body.properties.clone(), + type_annotation: body.type_annotation.clone(), + is_self_recursive: body.is_self_recursive.clone(), + has_non_tail_self_call: body.has_non_tail_self_call.clone(), + match_pattern: body.match_pattern.clone(), + expr_data: body.expr_data.clone(), + ident: None, +}) +}, + ExprData::ExprLet => { + let val = let_value(body.clone()); +let binding_name = let_binding_name_at(body.clone(), ctx.type_env.clone().source_indices.clone()); +let val_relation = classify_let_value(&val, &ctx); +let size_alias = classify_size_expr(&val, &ctx); +let inner_size_aliases = match size_alias { + Some(se) => v2_rt::rc_map_insert(ctx.size_aliases.clone(), binding_name.clone(), se.clone()), + None => ctx.size_aliases.clone(), +}; +let inner_per_field = build_per_field_for_let(&val, binding_name.clone(), &ctx); +let inner_ctx = match val_relation { + Some(rel) => { + let sub_type = match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}; +Rc::new(DescentContext { + fn_name: ctx.fn_name.clone(), + param_names: if (sub_type.clone().as_str() != "".to_string().as_str()) { + v2_rt::rc_map_insert(ctx.param_names.clone(), binding_name.clone(), sub_type.clone()) + } else { + ctx.param_names.clone() + }, + param_order: ctx.param_order.clone(), + type_env: ctx.type_env.clone(), + sub_value_vars: v2_rt::rc_map_insert(ctx.sub_value_vars.clone(), binding_name.clone(), rel.clone()), + size_aliases: inner_size_aliases, + scope_locals: v2_rt::rc_map_insert(ctx.scope_locals.clone(), binding_name.clone(), Rc::new(TypeBinding { + name: binding_name.clone(), + resolved: resolved_type(val.clone()), + provenance: rel.clone(), +})), + func_sigs: ctx.func_sigs.clone(), + per_field_vars: inner_per_field, +}) +}, + None => Rc::new(DescentContext { + fn_name: ctx.fn_name.clone(), + param_names: ctx.param_names.clone(), + param_order: ctx.param_order.clone(), + type_env: ctx.type_env.clone(), + sub_value_vars: ctx.sub_value_vars.clone(), + size_aliases: inner_size_aliases, + scope_locals: v2_rt::rc_map_insert(ctx.scope_locals.clone(), binding_name.clone(), Rc::new(TypeBinding { + name: binding_name.clone(), + resolved: resolved_type(val.clone()), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})), + func_sigs: ctx.func_sigs.clone(), + per_field_vars: inner_per_field, +}), +}; +let annotated_value = annotate_descent(&val, &ctx); +let annotated_children = match let_body(body.clone()) { + Some(body_child) => Rc::new(vec![annotated_value, annotate_descent(&body_child, &inner_ctx)]), + None => Rc::new(vec![annotated_value]), +}; +Rc::new(Node { + name: body.name.clone(), + span: body.span.clone(), + ident_span: body.ident_span.clone(), + children: annotated_children, + connective: body.connective.clone(), + params: body.params.clone(), + inferred: body.inferred.clone(), + return_cardinality: body.return_cardinality.clone(), + uses: body.uses.clone(), + body: body.body.clone(), + transport: body.transport.clone(), + properties: body.properties.clone(), + type_annotation: body.type_annotation.clone(), + is_self_recursive: body.is_self_recursive.clone(), + has_non_tail_self_call: body.has_non_tail_self_call.clone(), + match_pattern: body.match_pattern.clone(), + expr_data: body.expr_data.clone(), + ident: None, +}) +}, + ExprData::ExprBlock => { + let threaded = body.children.clone().iter().cloned().fold(Rc::new(BlockAnnotateAcc { + ctx: ctx.clone(), + children: Rc::new(vec![]), +}), |acc: Rc, child: Rc| { + let annotated = annotate_descent(&child, &acc.ctx.clone()); +let next_ctx = match (*child.expr_data.clone()).clone() { + ExprData::ExprLet => { + let val = let_value(child.clone()); +let bname = let_binding_name_at(child.clone(), ctx.type_env.clone().source_indices.clone()); +let val_rel = classify_let_value(&val, &acc.ctx.clone()); +let sa = classify_size_expr(&val, &acc.ctx.clone()); +let new_sa = match sa.clone() { + Some(se) => v2_rt::rc_map_insert(acc.ctx.clone().size_aliases.clone(), bname.clone(), se.clone()), + None => acc.ctx.clone().size_aliases.clone(), +}; +match val_rel.clone() { + Some(rel) => { + let sub_type = match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}; +Rc::new(DescentContext { + fn_name: acc.ctx.clone().fn_name.clone(), + param_names: if (sub_type.clone().as_str() != "".to_string().as_str()) { + v2_rt::rc_map_insert(acc.ctx.clone().param_names.clone(), bname.clone(), sub_type.clone()) + } else { + acc.ctx.clone().param_names.clone() + }, + param_order: acc.ctx.clone().param_order.clone(), + type_env: acc.ctx.clone().type_env.clone(), + sub_value_vars: v2_rt::rc_map_insert(acc.ctx.clone().sub_value_vars.clone(), bname.clone(), rel.clone()), + size_aliases: new_sa.clone(), + scope_locals: v2_rt::rc_map_insert(acc.ctx.clone().scope_locals.clone(), bname.clone(), Rc::new(TypeBinding { + name: bname.clone(), + resolved: resolved_type(val.clone()), + provenance: rel.clone(), +})), + func_sigs: acc.ctx.clone().func_sigs.clone(), + per_field_vars: acc.ctx.clone().per_field_vars.clone(), +}) +}, + None => Rc::new(DescentContext { + fn_name: acc.ctx.clone().fn_name.clone(), + param_names: acc.ctx.clone().param_names.clone(), + param_order: acc.ctx.clone().param_order.clone(), + type_env: acc.ctx.clone().type_env.clone(), + sub_value_vars: acc.ctx.clone().sub_value_vars.clone(), + size_aliases: new_sa.clone(), + scope_locals: v2_rt::rc_map_insert(acc.ctx.clone().scope_locals.clone(), bname.clone(), Rc::new(TypeBinding { + name: bname.clone(), + resolved: resolved_type(val.clone()), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})), + func_sigs: acc.ctx.clone().func_sigs.clone(), + per_field_vars: acc.ctx.clone().per_field_vars.clone(), +}), +} +}, + _ => acc.ctx.clone(), +}; +Rc::new(BlockAnnotateAcc { + ctx: next_ctx.clone(), + children: v2_rt::concat(acc.children.clone(), Rc::new(vec![annotated.clone()])), +}) +}); +Rc::new(Node { + name: body.name.clone(), + span: body.span.clone(), + ident_span: body.ident_span.clone(), + children: threaded.children.clone(), + connective: body.connective.clone(), + params: body.params.clone(), + inferred: body.inferred.clone(), + return_cardinality: body.return_cardinality.clone(), + uses: body.uses.clone(), + body: body.body.clone(), + transport: body.transport.clone(), + properties: body.properties.clone(), + type_annotation: body.type_annotation.clone(), + is_self_recursive: body.is_self_recursive.clone(), + has_non_tail_self_call: body.has_non_tail_self_call.clone(), + match_pattern: body.match_pattern.clone(), + expr_data: body.expr_data.clone(), + ident: None, +}) +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let mname = expr_method_name_at(body.clone(), ctx.type_env.clone().source_indices.clone()); +let elem_position = method_callback_element_position(ms.clone()); +if (elem_position.clone() != None) { + { + let raw_receiver = method_receiver(body.clone()); +let receiver = match (*raw_receiver.expr_data.clone()).clone() { + ExprData::ExprMethodCall { .. } => { + let inner_mname = expr_method_name_at(raw_receiver.clone(), ctx.type_env.clone().source_indices.clone()); +if (inner_mname.as_str() == "enumerate".to_string().as_str()) { + method_receiver(raw_receiver.clone()) + } else { + raw_receiver.clone() + } +}, + _ => raw_receiver.clone(), +}; +let receiver_field = match (*receiver.expr_data.clone()).clone() { + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(receiver.clone()); +let fname = field_access_field_at(receiver.clone(), ctx.type_env.clone().source_indices.clone()); +match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let bname = expr_var_name_at(base.clone(), ctx.type_env.clone().source_indices.clone()); +let base_type = match v2_rt::map_get(&ctx.param_names.clone(), bname.clone()) { + Some(t) => t.clone(), + None => match v2_rt::map_get(&ctx.sub_value_vars.clone(), bname.clone()) { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}, + None => "".to_string(), +}, +}; +if (base_type.clone().as_str() != "".to_string().as_str()) { + Rc::new({ let mut __result = Vec::new(); for f in inductive_fields_for(ctx.type_env.clone(), base_type.clone()).iter().cloned() { if (f.field_name.clone().as_str() == fname.clone().as_str()) { __result.push(f); } } __result }).first().cloned() + } else { + None + } +}, + _ => None, +} +}, + ExprData::ExprVar { .. } => { + let rname = expr_var_name_at(receiver.clone(), ctx.type_env.clone().source_indices.clone()); +match v2_rt::map_get(&ctx.sub_value_vars.clone(), rname) { + Some(rel) => match (*rel.clone()).clone() { + SubValueRelation::StrictSubValue { field: f, .. } => match f.shape.clone() { + RecursionShape::ListRecursion => Some(f.clone()), + _ => None, +}, + SubValueRelation::IteratedSubValue { field: f, .. } => match f.shape.clone() { + RecursionShape::ListRecursion => Some(f.clone()), + _ => None, +}, + _ => None, +}, + None => None, +} +}, + _ => None, +}; +let method_args = method_arg_nodes(body.clone()); +let lambda_arg = Rc::new({ let mut __result = Vec::new(); for a in method_args.iter().cloned() { if match (*arg_value(&a).expr_data.clone()).clone() { + ExprData::ExprLambda => true, + _ => false, +} { __result.push(a); } } __result }).first().cloned(); +let lambda_elem_info = match lambda_arg { + Some(la) => { + let lambda_node = arg_value(&la); +let lparams = lambda_param_names_at(lambda_node, ctx.type_env.clone().source_indices.clone()); +lparams.clone().get(elem_position.clone().unwrap() as usize).cloned() +}, + None => None, +}; +let is_fold = (elem_position.clone().unwrap() > 0); +let inner_ctx = match lambda_elem_info { + Some(elem_name) => match receiver_field { + Some(ind_field) => Rc::new(DescentContext { + fn_name: ctx.fn_name.clone(), + param_names: v2_rt::rc_map_insert(ctx.param_names.clone(), elem_name.clone(), ind_field.element_type.clone()), + param_order: ctx.param_order.clone(), + type_env: ctx.type_env.clone(), + sub_value_vars: if is_fold { + v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), elem_name.clone(), Rc::new(SubValueRelation::IteratedSubValue { + field: ind_field.clone(), +})) + } else { + v2_rt::rc_map_insert(ctx.sub_value_vars.clone(), elem_name.clone(), Rc::new(SubValueRelation::IteratedSubValue { + field: ind_field.clone(), +})) + }, + size_aliases: ctx.size_aliases.clone(), + scope_locals: ctx.scope_locals.clone(), + func_sigs: ctx.func_sigs.clone(), + per_field_vars: ctx.per_field_vars.clone(), +}), + None => Rc::new(DescentContext { + fn_name: ctx.fn_name.clone(), + param_names: ctx.param_names.clone(), + param_order: ctx.param_order.clone(), + type_env: ctx.type_env.clone(), + sub_value_vars: if is_fold { + v2_rt::rc_empty_map::>() + } else { + ctx.sub_value_vars.clone() + }, + size_aliases: ctx.size_aliases.clone(), + scope_locals: ctx.scope_locals.clone(), + func_sigs: ctx.func_sigs.clone(), + per_field_vars: ctx.per_field_vars.clone(), +}), +}, + None => ctx.clone(), +}; +let annotated_receiver = annotate_descent(&method_receiver(body.clone()), &ctx); +let annotated_args = Rc::new({ let mut __result = Vec::new(); for arg_node in method_arg_nodes(body.clone()).iter().cloned() { __result.push({ + let arg_val = arg_value(&arg_node); +let is_lambda = match (*arg_val.expr_data.clone()).clone() { + ExprData::ExprLambda => true, + _ => false, +}; +if is_lambda.clone() { + make_arg_node(match arg_name_at(arg_node.clone(), ctx.type_env.clone().source_indices.clone()) { + Some(n) => Some(n.clone()), + None => None, +}, annotate_descent(&arg_val, &inner_ctx), arg_node.span.clone(), arg_node.span.clone()) + } else { + make_arg_node(match arg_name_at(arg_node.clone(), ctx.type_env.clone().source_indices.clone()) { + Some(n) => Some(n.clone()), + None => None, +}, annotate_descent(&arg_val, &ctx), arg_node.span.clone(), arg_node.span.clone()) + } +}); } __result }); +Rc::new(Node { + name: body.name.clone(), + span: body.span.clone(), + ident_span: body.ident_span.clone(), + children: v2_rt::concat(Rc::new(vec![annotated_receiver]), annotated_args), + connective: body.connective.clone(), + params: body.params.clone(), + inferred: body.inferred.clone(), + return_cardinality: body.return_cardinality.clone(), + uses: body.uses.clone(), + body: body.body.clone(), + transport: body.transport.clone(), + properties: body.properties.clone(), + type_annotation: body.type_annotation.clone(), + is_self_recursive: body.is_self_recursive.clone(), + has_non_tail_self_call: body.has_non_tail_self_call.clone(), + match_pattern: body.match_pattern.clone(), + expr_data: body.expr_data.clone(), + ident: None, +}) +} + } else { + map_children(&body, |child| annotate_descent(&child, &ctx)) + } +}, + ExprData::ExprForEach => { + let coll = foreach_collection(body.clone()); +let fe_body = foreach_body(body.clone()); +let fe_var = foreach_variable_at(body.clone(), ctx.type_env.clone().source_indices.clone()); +let coll_field = resolve_collection_field(coll.clone(), ctx.clone()); +let inner_ctx = match coll_field { + Some(ind_field) => Rc::new(DescentContext { + fn_name: ctx.fn_name.clone(), + param_names: v2_rt::rc_map_insert(ctx.param_names.clone(), fe_var.clone(), ind_field.element_type.clone()), + param_order: ctx.param_order.clone(), + type_env: ctx.type_env.clone(), + sub_value_vars: v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), fe_var.clone(), Rc::new(SubValueRelation::IteratedSubValue { + field: ind_field.clone(), +})), + size_aliases: ctx.size_aliases.clone(), + scope_locals: ctx.scope_locals.clone(), + func_sigs: ctx.func_sigs.clone(), + per_field_vars: ctx.per_field_vars.clone(), +}), + None => Rc::new(DescentContext { fn_name: ctx.fn_name.clone(), - param_names: v2_rt::rc_map_insert(ctx.param_names.clone(), bname.clone(), ind_field.element_type.clone()), + param_names: ctx.param_names.clone(), param_order: ctx.param_order.clone(), type_env: ctx.type_env.clone(), - sub_value_vars: v2_rt::rc_map_insert(ctx.sub_value_vars.clone(), bname.clone(), Rc::new(SubValueRelation::StrictSubValue { - field: ind_field.clone(), - factor: Rc::new(ShrinkFactor::UnitShrink), -})), + sub_value_vars: v2_rt::rc_empty_map::>(), size_aliases: ctx.size_aliases.clone(), scope_locals: ctx.scope_locals.clone(), func_sigs: ctx.func_sigs.clone(), per_field_vars: ctx.per_field_vars.clone(), }), - None => ctx.clone(), -} - }, - _ => ctx.clone(), -} - } else { - ctx.clone() - }, }; -let annotated_body = annotate_descent(&arm_body(&arm_node), &arm_ctx); -make_arm_node(arm_pattern(arm_node.clone()), arm_guard(&arm_node), annotated_body.clone(), arm_node.span.clone()) -}); - } - __result - }); - Rc::new(Node { - name: body.name.clone(), - span: body.span.clone(), - ident_span: body.ident_span.clone(), - children: v2_rt::concat(Rc::new(vec![annotated_scrut]), annotated_arms), - connective: body.connective.clone(), - params: body.params.clone(), - inferred: body.inferred.clone(), - return_cardinality: body.return_cardinality.clone(), - uses: body.uses.clone(), - body: body.body.clone(), - transport: body.transport.clone(), - properties: body.properties.clone(), - type_annotation: body.type_annotation.clone(), - is_self_recursive: body.is_self_recursive.clone(), - has_non_tail_self_call: body.has_non_tail_self_call.clone(), - match_pattern: body.match_pattern.clone(), - expr_data: body.expr_data.clone(), - ident: None, - }) - } - ExprData::ExprLet => { - let val = let_value(body.clone()); - let binding_name = - let_binding_name_at(body.clone(), ctx.type_env.clone().source_indices.clone()); - let val_relation = classify_let_value(&val, &ctx); - let size_alias = classify_size_expr(&val, &ctx); - let inner_size_aliases = match size_alias { - Some(se) => v2_rt::rc_map_insert( - ctx.size_aliases.clone(), - binding_name.clone(), - se.clone(), - ), - None => ctx.size_aliases.clone(), - }; - let inner_per_field = build_per_field_for_let(&val, binding_name.clone(), &ctx); - let inner_ctx = match val_relation { - Some(rel) => { - let sub_type = match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { field: f, .. } => { - f.element_type.clone() - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - f.element_type.clone() - } - _ => "".to_string(), - }; - Rc::new(DescentContext { - fn_name: ctx.fn_name.clone(), - param_names: if (sub_type.clone().as_str() != "".to_string().as_str()) { - v2_rt::rc_map_insert( - ctx.param_names.clone(), - binding_name.clone(), - sub_type.clone(), - ) - } else { - ctx.param_names.clone() - }, - param_order: ctx.param_order.clone(), - type_env: ctx.type_env.clone(), - sub_value_vars: v2_rt::rc_map_insert( - ctx.sub_value_vars.clone(), - binding_name.clone(), - rel.clone(), - ), - size_aliases: inner_size_aliases, - scope_locals: v2_rt::rc_map_insert( - ctx.scope_locals.clone(), - binding_name.clone(), - Rc::new(TypeBinding { - name: binding_name.clone(), - resolved: resolved_type(val.clone()), - provenance: rel.clone(), - }), - ), - func_sigs: ctx.func_sigs.clone(), - per_field_vars: inner_per_field, - }) - } - None => Rc::new(DescentContext { - fn_name: ctx.fn_name.clone(), - param_names: ctx.param_names.clone(), - param_order: ctx.param_order.clone(), - type_env: ctx.type_env.clone(), - sub_value_vars: ctx.sub_value_vars.clone(), - size_aliases: inner_size_aliases, - scope_locals: v2_rt::rc_map_insert( - ctx.scope_locals.clone(), - binding_name.clone(), - Rc::new(TypeBinding { - name: binding_name.clone(), - resolved: resolved_type(val.clone()), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ), - func_sigs: ctx.func_sigs.clone(), - per_field_vars: inner_per_field, - }), - }; - let annotated_value = annotate_descent(&val, &ctx); - let annotated_children = match let_body(body.clone()) { - Some(body_child) => Rc::new(vec![ - annotated_value, - annotate_descent(&body_child, &inner_ctx), - ]), - None => Rc::new(vec![annotated_value]), - }; - Rc::new(Node { - name: body.name.clone(), - span: body.span.clone(), - ident_span: body.ident_span.clone(), - children: annotated_children, - connective: body.connective.clone(), - params: body.params.clone(), - inferred: body.inferred.clone(), - return_cardinality: body.return_cardinality.clone(), - uses: body.uses.clone(), - body: body.body.clone(), - transport: body.transport.clone(), - properties: body.properties.clone(), - type_annotation: body.type_annotation.clone(), - is_self_recursive: body.is_self_recursive.clone(), - has_non_tail_self_call: body.has_non_tail_self_call.clone(), - match_pattern: body.match_pattern.clone(), - expr_data: body.expr_data.clone(), - ident: None, - }) - } - ExprData::ExprBlock => { - let threaded = body.children.clone().iter().cloned().fold( - Rc::new(BlockAnnotateAcc { - ctx: ctx.clone(), - children: Rc::new(vec![]), - }), - |acc: Rc, child: Rc| { - let annotated = annotate_descent(&child, &acc.ctx.clone()); - let next_ctx = match (*child.expr_data.clone()).clone() { - ExprData::ExprLet => { - let val = let_value(child.clone()); - let bname = let_binding_name_at( - child.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let val_rel = classify_let_value(&val, &acc.ctx.clone()); - let sa = classify_size_expr(&val, &acc.ctx.clone()); - let new_sa = match sa.clone() { - Some(se) => v2_rt::rc_map_insert( - acc.ctx.clone().size_aliases.clone(), - bname.clone(), - se.clone(), - ), - None => acc.ctx.clone().size_aliases.clone(), - }; - match val_rel.clone() { - Some(rel) => { - let sub_type = match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { - field: f, .. - } => f.element_type.clone(), - SubValueRelation::IteratedSubValue { - field: f, .. - } => f.element_type.clone(), - _ => "".to_string(), - }; - Rc::new(DescentContext { - fn_name: acc.ctx.clone().fn_name.clone(), - param_names: if (sub_type.clone().as_str() - != "".to_string().as_str()) - { - v2_rt::rc_map_insert( - acc.ctx.clone().param_names.clone(), - bname.clone(), - sub_type.clone(), - ) - } else { - acc.ctx.clone().param_names.clone() - }, - param_order: acc.ctx.clone().param_order.clone(), - type_env: acc.ctx.clone().type_env.clone(), - sub_value_vars: v2_rt::rc_map_insert( - acc.ctx.clone().sub_value_vars.clone(), - bname.clone(), - rel.clone(), - ), - size_aliases: new_sa.clone(), - scope_locals: v2_rt::rc_map_insert( - acc.ctx.clone().scope_locals.clone(), - bname.clone(), - Rc::new(TypeBinding { - name: bname.clone(), - resolved: resolved_type(val.clone()), - provenance: rel.clone(), - }), - ), - func_sigs: acc.ctx.clone().func_sigs.clone(), - per_field_vars: acc.ctx.clone().per_field_vars.clone(), - }) - } - None => Rc::new(DescentContext { - fn_name: acc.ctx.clone().fn_name.clone(), - param_names: acc.ctx.clone().param_names.clone(), - param_order: acc.ctx.clone().param_order.clone(), - type_env: acc.ctx.clone().type_env.clone(), - sub_value_vars: acc.ctx.clone().sub_value_vars.clone(), - size_aliases: new_sa.clone(), - scope_locals: v2_rt::rc_map_insert( - acc.ctx.clone().scope_locals.clone(), - bname.clone(), - Rc::new(TypeBinding { - name: bname.clone(), - resolved: resolved_type(val.clone()), - provenance: Rc::new( - SubValueRelation::SubValueUnknown, - ), - }), - ), - func_sigs: acc.ctx.clone().func_sigs.clone(), - per_field_vars: acc.ctx.clone().per_field_vars.clone(), - }), - } - } - _ => acc.ctx.clone(), - }; - Rc::new(BlockAnnotateAcc { - ctx: next_ctx.clone(), - children: v2_rt::concat( - acc.children.clone(), - Rc::new(vec![annotated.clone()]), - ), - }) - }, - ); - Rc::new(Node { - name: body.name.clone(), - span: body.span.clone(), - ident_span: body.ident_span.clone(), - children: threaded.children.clone(), - connective: body.connective.clone(), - params: body.params.clone(), - inferred: body.inferred.clone(), - return_cardinality: body.return_cardinality.clone(), - uses: body.uses.clone(), - body: body.body.clone(), - transport: body.transport.clone(), - properties: body.properties.clone(), - type_annotation: body.type_annotation.clone(), - is_self_recursive: body.is_self_recursive.clone(), - has_non_tail_self_call: body.has_non_tail_self_call.clone(), - match_pattern: body.match_pattern.clone(), - expr_data: body.expr_data.clone(), - ident: None, - }) - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let mname = - expr_method_name_at(body.clone(), ctx.type_env.clone().source_indices.clone()); - let elem_position = method_callback_element_position(ms.clone()); - if (elem_position.clone() != None) { - { - let raw_receiver = method_receiver(body.clone()); - let receiver = match (*raw_receiver.expr_data.clone()).clone() { - ExprData::ExprMethodCall { .. } => { - let inner_mname = expr_method_name_at( - raw_receiver.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - if (inner_mname.as_str() == "enumerate".to_string().as_str()) { - method_receiver(raw_receiver.clone()) - } else { - raw_receiver.clone() - } - } - _ => raw_receiver.clone(), - }; - let receiver_field = match (*receiver.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(receiver.clone()); - let fname = field_access_field_at( - receiver.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let bname = expr_var_name_at( - base.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let base_type = match v2_rt::map_get( - &ctx.param_names.clone(), - bname.clone(), - ) { - Some(t) => t.clone(), - None => match v2_rt::map_get( - &ctx.sub_value_vars.clone(), - bname.clone(), - ) { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { - field: f, - .. - } => f.element_type.clone(), - SubValueRelation::IteratedSubValue { - field: f, - .. - } => f.element_type.clone(), - _ => "".to_string(), - }, - None => "".to_string(), - }, - }; - if (base_type.clone().as_str() != "".to_string().as_str()) { - Rc::new({ - let mut __result = Vec::new(); - for f in inductive_fields_for( - ctx.type_env.clone(), - base_type.clone(), - ) - .iter() - .cloned() - { - if (f.field_name.clone().as_str() - == fname.clone().as_str()) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned() - } else { - None - } - } - _ => None, - } - } - ExprData::ExprVar { .. } => { - let rname = expr_var_name_at( - receiver.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - match v2_rt::map_get(&ctx.sub_value_vars.clone(), rname) { - Some(rel) => match (*rel.clone()).clone() { - SubValueRelation::StrictSubValue { field: f, .. } => { - match f.shape.clone() { - RecursionShape::ListRecursion => Some(f.clone()), - _ => None, - } - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - match f.shape.clone() { - RecursionShape::ListRecursion => Some(f.clone()), - _ => None, - } - } - _ => None, - }, - None => None, - } - } - _ => None, - }; - let method_args = method_arg_nodes(body.clone()); - let lambda_arg = Rc::new({ - let mut __result = Vec::new(); - for a in method_args.iter().cloned() { - if match (*arg_value(&a).expr_data.clone()).clone() { - ExprData::ExprLambda => true, - _ => false, - } { - __result.push(a); - } - } - __result - }) - .first() - .cloned(); - let lambda_elem_info = match lambda_arg { - Some(la) => { - let lambda_node = arg_value(&la); - let lparams = lambda_param_names_at( - lambda_node, - ctx.type_env.clone().source_indices.clone(), - ); - lparams - .clone() - .get(elem_position.clone().unwrap() as usize) - .cloned() - } - None => None, - }; - let is_fold = (elem_position.clone().unwrap() > 0); - let inner_ctx = match lambda_elem_info { - Some(elem_name) => match receiver_field { - Some(ind_field) => Rc::new(DescentContext { - fn_name: ctx.fn_name.clone(), - param_names: v2_rt::rc_map_insert( - ctx.param_names.clone(), - elem_name.clone(), - ind_field.element_type.clone(), - ), - param_order: ctx.param_order.clone(), - type_env: ctx.type_env.clone(), - sub_value_vars: if is_fold { - v2_rt::rc_map_insert( - v2_rt::rc_empty_map::>(), - elem_name.clone(), - Rc::new(SubValueRelation::IteratedSubValue { - field: ind_field.clone(), - }), - ) - } else { - v2_rt::rc_map_insert( - ctx.sub_value_vars.clone(), - elem_name.clone(), - Rc::new(SubValueRelation::IteratedSubValue { - field: ind_field.clone(), - }), - ) - }, - size_aliases: ctx.size_aliases.clone(), - scope_locals: ctx.scope_locals.clone(), - func_sigs: ctx.func_sigs.clone(), - per_field_vars: ctx.per_field_vars.clone(), - }), - None => Rc::new(DescentContext { - fn_name: ctx.fn_name.clone(), - param_names: ctx.param_names.clone(), - param_order: ctx.param_order.clone(), - type_env: ctx.type_env.clone(), - sub_value_vars: if is_fold { - v2_rt::rc_empty_map::>() - } else { - ctx.sub_value_vars.clone() - }, - size_aliases: ctx.size_aliases.clone(), - scope_locals: ctx.scope_locals.clone(), - func_sigs: ctx.func_sigs.clone(), - per_field_vars: ctx.per_field_vars.clone(), - }), - }, - None => ctx.clone(), - }; - let annotated_receiver = - annotate_descent(&method_receiver(body.clone()), &ctx); - let annotated_args = Rc::new({ - let mut __result = Vec::new(); - for arg_node in method_arg_nodes(body.clone()).iter().cloned() { - __result.push({ - let arg_val = arg_value(&arg_node); - let is_lambda = match (*arg_val.expr_data.clone()).clone() { - ExprData::ExprLambda => true, - _ => false, - }; - if is_lambda.clone() { - make_arg_node( - match arg_name_at( - arg_node.clone(), - ctx.type_env.clone().source_indices.clone(), - ) { - Some(n) => Some(n.clone()), - None => None, - }, - annotate_descent(&arg_val, &inner_ctx), - arg_node.span.clone(), - arg_node.span.clone(), - ) - } else { - make_arg_node( - match arg_name_at( - arg_node.clone(), - ctx.type_env.clone().source_indices.clone(), - ) { - Some(n) => Some(n.clone()), - None => None, - }, - annotate_descent(&arg_val, &ctx), - arg_node.span.clone(), - arg_node.span.clone(), - ) - } - }); - } - __result - }); - Rc::new(Node { - name: body.name.clone(), - span: body.span.clone(), - ident_span: body.ident_span.clone(), - children: v2_rt::concat( - Rc::new(vec![annotated_receiver]), - annotated_args, - ), - connective: body.connective.clone(), - params: body.params.clone(), - inferred: body.inferred.clone(), - return_cardinality: body.return_cardinality.clone(), - uses: body.uses.clone(), - body: body.body.clone(), - transport: body.transport.clone(), - properties: body.properties.clone(), - type_annotation: body.type_annotation.clone(), - is_self_recursive: body.is_self_recursive.clone(), - has_non_tail_self_call: body.has_non_tail_self_call.clone(), - match_pattern: body.match_pattern.clone(), - expr_data: body.expr_data.clone(), - ident: None, - }) - } - } else { - map_children(&body, |child| annotate_descent(&child, &ctx)) - } - } - ExprData::ExprForEach => { - let coll = foreach_collection(body.clone()); - let fe_body = foreach_body(body.clone()); - let fe_var = - foreach_variable_at(body.clone(), ctx.type_env.clone().source_indices.clone()); - let coll_field = resolve_collection_field(coll.clone(), ctx.clone()); - let inner_ctx = match coll_field { - Some(ind_field) => Rc::new(DescentContext { - fn_name: ctx.fn_name.clone(), - param_names: v2_rt::rc_map_insert( - ctx.param_names.clone(), - fe_var.clone(), - ind_field.element_type.clone(), - ), - param_order: ctx.param_order.clone(), - type_env: ctx.type_env.clone(), - sub_value_vars: v2_rt::rc_map_insert( - v2_rt::rc_empty_map::>(), - fe_var.clone(), - Rc::new(SubValueRelation::IteratedSubValue { - field: ind_field.clone(), - }), - ), - size_aliases: ctx.size_aliases.clone(), - scope_locals: ctx.scope_locals.clone(), - func_sigs: ctx.func_sigs.clone(), - per_field_vars: ctx.per_field_vars.clone(), - }), - None => Rc::new(DescentContext { - fn_name: ctx.fn_name.clone(), - param_names: ctx.param_names.clone(), - param_order: ctx.param_order.clone(), - type_env: ctx.type_env.clone(), - sub_value_vars: v2_rt::rc_empty_map::>(), - size_aliases: ctx.size_aliases.clone(), - scope_locals: ctx.scope_locals.clone(), - func_sigs: ctx.func_sigs.clone(), - per_field_vars: ctx.per_field_vars.clone(), - }), - }; - let annotated_coll = annotate_descent(&coll, &ctx); - let annotated_body = annotate_descent(&fe_body, &inner_ctx); - Rc::new(Node { - name: body.name.clone(), - span: body.span.clone(), - ident_span: body.ident_span.clone(), - children: Rc::new(vec![annotated_coll, annotated_body.clone()]), - connective: body.connective.clone(), - params: body.params.clone(), - inferred: body.inferred.clone(), - return_cardinality: body.return_cardinality.clone(), - uses: body.uses.clone(), - body: body.body.clone(), - transport: body.transport.clone(), - properties: body.properties.clone(), - type_annotation: body.type_annotation.clone(), - is_self_recursive: body.is_self_recursive.clone(), - has_non_tail_self_call: body.has_non_tail_self_call.clone(), - match_pattern: body.match_pattern.clone(), - expr_data: body.expr_data.clone(), - ident: None, - }) - } - _ => map_children(&body, |child| annotate_descent(&child, &ctx)), - } +let annotated_coll = annotate_descent(&coll, &ctx); +let annotated_body = annotate_descent(&fe_body, &inner_ctx); +Rc::new(Node { + name: body.name.clone(), + span: body.span.clone(), + ident_span: body.ident_span.clone(), + children: Rc::new(vec![annotated_coll, annotated_body.clone()]), + connective: body.connective.clone(), + params: body.params.clone(), + inferred: body.inferred.clone(), + return_cardinality: body.return_cardinality.clone(), + uses: body.uses.clone(), + body: body.body.clone(), + transport: body.transport.clone(), + properties: body.properties.clone(), + type_annotation: body.type_annotation.clone(), + is_self_recursive: body.is_self_recursive.clone(), + has_non_tail_self_call: body.has_non_tail_self_call.clone(), + match_pattern: body.match_pattern.clone(), + expr_data: body.expr_data.clone(), + ident: None, +}) +}, + _ => map_children(&body, |child| annotate_descent(&child, &ctx)), +} }) } -pub fn resolved_type_name( - n: &Rc, - source_indices: Rc>>, -) -> String { +pub fn resolved_type_name(n: &Rc, source_indices: Rc>>) -> String { match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => authored_name_at(source_indices, &rt), - _ => match n.children.clone().first().cloned() { - Some(c) => authored_name_at(source_indices, &c), - None => "".to_string(), - }, - } + Some(InferredNode::Resolved { node: rt, .. }) => authored_name_at(source_indices, &rt), + _ => match n.children.clone().first().cloned() { + Some(c) => authored_name_at(source_indices, &c), + None => "".to_string(), +}, +} } -pub fn infer_output_provenance( - body: &Rc, - params: &Rc>>, - type_env: &Rc, - scope_locals: Rc>>, - func_sigs: &Rc>>, -) -> Rc>>>> { +pub fn infer_output_provenance(body: &Rc, params: &Rc>>, type_env: &Rc, scope_locals: Rc>>, func_sigs: &Rc>>) -> Rc>>>> { { - let param_names = Rc::new({ - let mut __result = Vec::new(); - for p in params.clone().iter().cloned() { - __result.push(param_node_name_at( - p.clone(), - type_env.source_indices.clone(), - )); + let param_names = Rc::new({ let mut __result = Vec::new(); for p in params.clone().iter().cloned() { __result.push(param_node_name_at(p.clone(), type_env.source_indices.clone())); } __result }); +let param_types = params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, p: Rc| { + let pname = param_node_name_at(p.clone(), type_env.source_indices.clone()); +let ptype = resolved_type_name(&p, type_env.source_indices.clone()); +if ((pname.clone().as_str() != "".to_string().as_str()) && (ptype.clone().as_str() != "".to_string().as_str())) { + v2_rt::rc_map_insert(acc.clone(), pname.clone(), ptype.clone()) + } else { + acc.clone() } - __result - }); - let param_types = params.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, p: Rc| { - let pname = param_node_name_at(p.clone(), type_env.source_indices.clone()); - let ptype = resolved_type_name(&p, type_env.source_indices.clone()); - if ((pname.clone().as_str() != "".to_string().as_str()) - && (ptype.clone().as_str() != "".to_string().as_str())) - { - v2_rt::rc_map_insert(acc.clone(), pname.clone(), ptype.clone()) - } else { - acc.clone() - } - }, - ); - let scalar = classify_body_provenance( - &body, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &v2_rt::rc_empty_map::>>>(), - ); - if ((Rc::new(v2_rt::map_keys(&scalar)).len() as i64) > 0) { +}); +let scalar = classify_body_provenance(&body, ¶m_names, ¶m_types, &type_env, &func_sigs, &v2_rt::rc_empty_map::>>>()); +if ((Rc::new(v2_rt::map_keys(&scalar)).len() as i64) > 0) { Rc::new(vec![scalar.clone()]) } else { { - let per_field = classify_body_per_field( - body.clone(), - param_names.clone(), - param_types.clone(), - &type_env, - func_sigs.clone(), - v2_rt::rc_empty_map::>>>(), - ); - if (((per_field.clone().len() as i64) > 0) && { - let mut __found = false; - for m in per_field.clone().iter().cloned() { - if ((Rc::new(v2_rt::map_keys(&m)).len() as i64) > 0) { - __found = true; - break; - } - } - __found - }) { + let per_field = classify_body_per_field(body.clone(), param_names.clone(), param_types.clone(), &type_env, func_sigs.clone(), v2_rt::rc_empty_map::>>>()); +if (((per_field.clone().len() as i64) > 0) && { let mut __found = false; for m in per_field.clone().iter().cloned() { if ((Rc::new(v2_rt::map_keys(&m)).len() as i64) > 0) { __found = true; break; } } __found }) { per_field.clone() } else { Rc::new(vec![]) } - } +} } - } +} } -pub fn classify_body_provenance( - expr: &Rc, - param_names: &Rc>, - param_types: &Rc>, - type_env: &Rc, - func_sigs: &Rc>>, - let_prov: &Rc>>>>, -) -> Rc>> { +pub fn classify_body_provenance(expr: &Rc, param_names: &Rc>, param_types: &Rc>, type_env: &Rc, func_sigs: &Rc>>, let_prov: &Rc>>>>) -> Rc>> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*expr.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let vname = expr_var_name_at(expr.clone(), type_env.source_indices.clone()); - match v2_rt::map_get(&let_prov, vname.clone()) { - Some(prov) => prov.clone(), - None => { - if { - let mut __found = false; - for pn in param_names.clone().iter().cloned() { - if (pn.clone().as_str() == vname.clone().as_str()) { - __found = true; - break; - } - } - __found - } { - v2_rt::rc_map_insert( - v2_rt::rc_empty_map::>(), - vname.clone(), - Rc::new(SubValueRelation::PreservedValue), - ) - } else { - v2_rt::rc_empty_map::>() - } - } - } - } - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(expr.clone()); - let field = field_access_field_at(expr.clone(), type_env.source_indices.clone()); - let base_prov = classify_body_provenance( - &base, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - Rc::new(v2_rt::map_keys(&base_prov)).iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, pname: String| { - match v2_rt::map_get(&base_prov, pname.clone()) { - Some(base_rel) => { - let type_for_lookup = match (*base_rel.clone()).clone() { - SubValueRelation::PreservedValue => { - match v2_rt::map_get(¶m_types, pname.clone()) { - Some(t) => t.clone(), - None => "".to_string(), - } - } - SubValueRelation::StrictSubValue { field: f, .. } => { - f.element_type.clone() - } - SubValueRelation::IteratedSubValue { field: f, .. } => { - f.element_type.clone() - } - _ => "".to_string(), - }; - if (type_for_lookup.clone().as_str() != "".to_string().as_str()) { - { - let fields = inductive_fields_for( - type_env.clone(), - type_for_lookup.clone(), - ); - 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()) - { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match matching.clone() { - Some(ind_field) => v2_rt::rc_map_insert( - acc.clone(), - pname.clone(), - compose_sub_value( - base_rel.clone(), - ind_field.clone(), - ), - ), - None => acc.clone(), - } - } - } else { - acc.clone() - } - } - None => acc.clone(), - } - }, - ) - } - ExprData::ExprCall { .. } => { - let callee = expr_call_func_at(expr.clone(), type_env.source_indices.clone()); - compose_callee_provenance( - callee, - call_args_by_name(expr.clone(), type_env.source_indices.clone()), - param_names.clone(), - param_types.clone(), - type_env.clone(), - &func_sigs, - let_prov.clone(), - ) - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let mname = expr_method_name_at(expr.clone(), type_env.source_indices.clone()); - let callee_result = compose_callee_provenance( - mname.clone(), - method_call_args_by_name( - &expr, - func_sigs.clone(), - &type_env.source_indices.clone(), - ), - param_names.clone(), - param_types.clone(), - type_env.clone(), - &func_sigs, - let_prov.clone(), - ); - if ((Rc::new(v2_rt::map_keys(&callee_result)).len() as i64) > 0) { - callee_result.clone() - } else { + ExprData::ExprVar { .. } => { + let vname = expr_var_name_at(expr.clone(), type_env.source_indices.clone()); +match v2_rt::map_get(&let_prov, vname.clone()) { + Some(prov) => prov.clone(), + None => if { let mut __found = false; for pn in param_names.clone().iter().cloned() { if (pn.clone().as_str() == vname.clone().as_str()) { __found = true; break; } } __found } { + v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), vname.clone(), Rc::new(SubValueRelation::PreservedValue)) + } else { + v2_rt::rc_empty_map::>() + }, +} +}, + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(expr.clone()); +let field = field_access_field_at(expr.clone(), type_env.source_indices.clone()); +let base_prov = classify_body_provenance(&base, ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +Rc::new(v2_rt::map_keys(&base_prov)).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, pname: String| match v2_rt::map_get(&base_prov, pname.clone()) { + Some(base_rel) => { + let type_for_lookup = match (*base_rel.clone()).clone() { + SubValueRelation::PreservedValue => match v2_rt::map_get(¶m_types, pname.clone()) { + Some(t) => t.clone(), + None => "".to_string(), +}, + SubValueRelation::StrictSubValue { field: f, .. } => f.element_type.clone(), + SubValueRelation::IteratedSubValue { field: f, .. } => f.element_type.clone(), + _ => "".to_string(), +}; +if (type_for_lookup.clone().as_str() != "".to_string().as_str()) { { - let is_shrink = match ms.clone().as_deref().cloned() { - Some(MethodSemantics::AlgebraMethodSemantics { - size_effect: se, - .. - }) => match se.clone() { - Some(CollectionSizeEffect::ShrinkEffect) => true, - _ => false, - }, - _ => false, - }; - if (is_shrink - && match method_arg_nodes(expr.clone()).first().cloned() { - Some(arg_node) => match (*arg_value(&arg_node).expr_data.clone()) - .clone() - { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitInt { value: n, .. } = value.as_ref() - else { - unreachable!() - }; - (n.clone() > 0) - } - _ => false, - }, - None => false, - }) + let fields = inductive_fields_for(type_env.clone(), type_for_lookup.clone()); +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()) { __result.push(f); } } __result }).first().cloned(); +match matching.clone() { + Some(ind_field) => v2_rt::rc_map_insert(acc.clone(), pname.clone(), compose_sub_value(base_rel.clone(), ind_field.clone())), + None => acc.clone(), +} +} + } else { + acc.clone() + } +}, + None => acc.clone(), +}) +}, + ExprData::ExprCall { .. } => { + let callee = expr_call_func_at(expr.clone(), type_env.source_indices.clone()); +compose_callee_provenance(callee, call_args_by_name(expr.clone(), type_env.source_indices.clone()), param_names.clone(), param_types.clone(), type_env.clone(), &func_sigs, let_prov.clone()) +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let mname = expr_method_name_at(expr.clone(), type_env.source_indices.clone()); +let callee_result = compose_callee_provenance(mname.clone(), method_call_args_by_name(&expr, func_sigs.clone(), &type_env.source_indices.clone()), param_names.clone(), param_types.clone(), type_env.clone(), &func_sigs, let_prov.clone()); +if ((Rc::new(v2_rt::map_keys(&callee_result)).len() as i64) > 0) { + callee_result.clone() + } else { + { + let is_shrink = match ms.clone().as_deref().cloned() { + Some(MethodSemantics::AlgebraMethodSemantics { size_effect: se, .. }) => match se.clone() { + Some(CollectionSizeEffect::ShrinkEffect) => true, + _ => false, +}, + _ => false, +}; +if (is_shrink && match method_arg_nodes(expr.clone()).first().cloned() { + Some(arg_node) => match (*arg_value(&arg_node).expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitInt { value: n, .. } = value.as_ref() else { unreachable!() }; (n.clone() > 0) }, + _ => false, +}, + None => false, +}) { { - { - let recv = method_receiver(expr.clone()); - let recv_prov = classify_body_provenance( - &recv, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - Rc::new(v2_rt::map_keys(&recv_prov)).iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, - pname: String| { - match v2_rt::map_get(&recv_prov, pname.clone()) { - Some(recv_rel) => { - let synth_field = Rc::new(InductiveField { - type_name: pname.clone(), - variant_name: "".to_string(), - field_name: mname.clone(), - shape: RecursionShape::ListRecursion, - element_type: pname.clone(), - }); - v2_rt::rc_map_insert( - acc.clone(), - pname.clone(), - compose_sub_value( - recv_rel.clone(), - synth_field.clone(), - ), - ) - } - None => acc.clone(), - } - }, - ) - } - } else { - v2_rt::rc_empty_map::>() - } + let recv = method_receiver(expr.clone()); +let recv_prov = classify_body_provenance(&recv, ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +Rc::new(v2_rt::map_keys(&recv_prov)).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, pname: String| match v2_rt::map_get(&recv_prov, pname.clone()) { + Some(recv_rel) => { + let synth_field = Rc::new(InductiveField { + type_name: pname.clone(), + variant_name: "".to_string(), + field_name: mname.clone(), + shape: RecursionShape::ListRecursion, + element_type: pname.clone(), +}); +v2_rt::rc_map_insert(acc.clone(), pname.clone(), compose_sub_value(recv_rel.clone(), synth_field.clone())) +}, + None => acc.clone(), +}) +} + } else { + v2_rt::rc_empty_map::>() } - } +} } - ExprData::ExprMatch => { - let scrut = match_scrutinee(expr.clone()); - let scrut_prov = classify_body_provenance( - &scrut, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - let arms = match_arm_nodes(expr.clone()); - let arm_provs = Rc::new({ - let mut __result = Vec::new(); - for arm in arms.iter().cloned() { - __result.push({ +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(expr.clone()); +let scrut_prov = classify_body_provenance(&scrut, ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +let arms = match_arm_nodes(expr.clone()); +let arm_provs = Rc::new({ let mut __result = Vec::new(); for arm in arms.iter().cloned() { __result.push({ let arm_let_prov = match (*arm_pattern(arm.clone())).clone() { MatchPattern::VariantPattern { name: vname, field_bindings: bindings, .. } => bindings.clone().iter().cloned().fold(let_prov.clone(), |acc: Rc>>>>, binding: Rc| { let field_label = field_binding_name_at(binding.clone(), type_env.source_indices.clone()); @@ -7670,141 +4511,64 @@ v2_rt::rc_map_insert(acc.clone(), bind_name.clone(), field_prov.clone()) _ => let_prov.clone(), }; classify_body_provenance(&arm_body(&arm), ¶m_names, ¶m_types, &type_env, &func_sigs, &arm_let_prov) +}); } __result }); +meet_body_provenance_maps(&arm_provs) +}, + ExprData::ExprIf => { + let then_prov = classify_body_provenance(&if_then_branch(expr.clone()), ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +match if_else_branch(expr.clone()) { + Some(else_expr) => { + let else_prov = classify_body_provenance(&else_expr, ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +meet_body_provenance_maps(&Rc::new(vec![then_prov, else_prov])) +}, + None => then_prov, +} +}, + ExprData::ExprLet => { + let value = let_value(expr.clone()); +let bname = let_binding_name_at(expr.clone(), type_env.source_indices.clone()); +let value_prov = classify_body_provenance(&value, ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +let updated = v2_rt::rc_map_insert(let_prov.clone(), bname.clone(), value_prov.clone()); +match let_body(expr.clone()) { + Some(body) => classify_body_provenance(&body, ¶m_names, ¶m_types, &type_env, &func_sigs, &updated), + None => v2_rt::rc_empty_map::>(), +} +}, + ExprData::ExprBlock => { + let block_result = expr.children.clone().iter().cloned().fold(Rc::new(BlockProvFoldState { + prov: let_prov.clone(), + last: empty_prov_map(), +}), |state: Rc, stmt: Rc| match (*stmt.expr_data.clone()).clone() { + ExprData::ExprLet => { + let bname = let_binding_name_at(stmt.clone(), type_env.source_indices.clone()); +let value = let_value(stmt.clone()); +let value_prov = classify_body_provenance(&value, ¶m_names, ¶m_types, &type_env, &func_sigs, &state.prov.clone()); +let updated_prov = v2_rt::rc_map_insert(state.prov.clone(), bname.clone(), value_prov.clone()); +match let_body(stmt.clone()) { + Some(body) => Rc::new(BlockProvFoldState { + prov: state.prov.clone(), + last: classify_body_provenance(&body, ¶m_names, ¶m_types, &type_env, &func_sigs, &updated_prov), +}), + None => Rc::new(BlockProvFoldState { + prov: updated_prov.clone(), + last: value_prov.clone(), +}), +} +}, + _ => Rc::new(BlockProvFoldState { + prov: state.prov.clone(), + last: classify_body_provenance(&stmt, ¶m_names, ¶m_types, &type_env, &func_sigs, &state.prov.clone()), +}), }); - } - __result - }); - meet_body_provenance_maps(&arm_provs) - } - ExprData::ExprIf => { - let then_prov = classify_body_provenance( - &if_then_branch(expr.clone()), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - match if_else_branch(expr.clone()) { - Some(else_expr) => { - let else_prov = classify_body_provenance( - &else_expr, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - meet_body_provenance_maps(&Rc::new(vec![then_prov, else_prov])) - } - None => then_prov, - } - } - ExprData::ExprLet => { - let value = let_value(expr.clone()); - let bname = let_binding_name_at(expr.clone(), type_env.source_indices.clone()); - let value_prov = classify_body_provenance( - &value, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - let updated = - v2_rt::rc_map_insert(let_prov.clone(), bname.clone(), value_prov.clone()); - match let_body(expr.clone()) { - Some(body) => classify_body_provenance( - &body, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &updated, - ), - None => v2_rt::rc_empty_map::>(), - } - } - ExprData::ExprBlock => { - let block_result = expr.children.clone().iter().cloned().fold( - Rc::new(BlockProvFoldState { - prov: let_prov.clone(), - last: empty_prov_map(), - }), - |state: Rc, stmt: Rc| match (*stmt.expr_data.clone()) - .clone() - { - ExprData::ExprLet => { - let bname = - let_binding_name_at(stmt.clone(), type_env.source_indices.clone()); - let value = let_value(stmt.clone()); - let value_prov = classify_body_provenance( - &value, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &state.prov.clone(), - ); - let updated_prov = v2_rt::rc_map_insert( - state.prov.clone(), - bname.clone(), - value_prov.clone(), - ); - match let_body(stmt.clone()) { - Some(body) => Rc::new(BlockProvFoldState { - prov: state.prov.clone(), - last: classify_body_provenance( - &body, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &updated_prov, - ), - }), - None => Rc::new(BlockProvFoldState { - prov: updated_prov.clone(), - last: value_prov.clone(), - }), - } - } - _ => Rc::new(BlockProvFoldState { - prov: state.prov.clone(), - last: classify_body_provenance( - &stmt, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &state.prov.clone(), - ), - }), - }, - ); - block_result.last.clone() - } - ExprData::ExprCast => classify_body_provenance( - &cast_expr(expr.clone()), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ), - ExprData::ExprReturn => match expr.children.clone().first().cloned() { - Some(inner) => classify_body_provenance( - &inner, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ), - None => v2_rt::rc_empty_map::>(), - }, - _ => v2_rt::rc_empty_map::>(), - } +block_result.last.clone() +}, + ExprData::ExprCast => classify_body_provenance(&cast_expr(expr.clone()), ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov), + ExprData::ExprReturn => match expr.children.clone().first().cloned() { + Some(inner) => classify_body_provenance(&inner, ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov), + None => v2_rt::rc_empty_map::>(), +}, + _ => v2_rt::rc_empty_map::>(), +} }) } @@ -7814,275 +4578,112 @@ pub struct BlockProvFoldState { pub last: Rc>>, } -pub fn call_args_by_name( - call: Rc, - source_indices: Rc>>, -) -> Rc>> { - call.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, arg_node: Rc| match arg_name_at( - arg_node.clone(), - source_indices.clone(), - ) { - Some(aname) => v2_rt::rc_map_insert(acc.clone(), aname.clone(), arg_value(&arg_node)), - None => acc.clone(), - }, - ) +pub fn call_args_by_name(call: Rc, source_indices: Rc>>) -> Rc>> { + call.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, arg_node: Rc| match arg_name_at(arg_node.clone(), source_indices.clone()) { + Some(aname) => v2_rt::rc_map_insert(acc.clone(), aname.clone(), arg_value(&arg_node)), + None => acc.clone(), +}) } -pub fn method_call_args_by_name( - call: &Rc, - func_sigs: Rc>>, - source_indices: &Rc>>, -) -> Rc>> { +pub fn method_call_args_by_name(call: &Rc, func_sigs: Rc>>, source_indices: &Rc>>) -> Rc>> { { let mname = expr_method_name_at(call.clone(), source_indices.clone()); - let recv = method_receiver(call.clone()); - let mc_args = method_arg_nodes(call.clone()); - let base = match v2_rt::map_get(&func_sigs, mname) { - 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()) { - v2_rt::rc_map_insert( - v2_rt::rc_empty_map::>(), - first_pname.clone(), - recv, - ) - } else { - v2_rt::rc_empty_map::>() - } - } - None => v2_rt::rc_empty_map::>(), - }, - None => v2_rt::rc_empty_map::>(), - }; - mc_args.iter().cloned().fold( - base, - |acc: Rc>>, arg_node: Rc| match arg_name_at( - arg_node.clone(), - source_indices.clone(), - ) { - Some(aname) => { - v2_rt::rc_map_insert(acc.clone(), aname.clone(), arg_value(&arg_node)) - } - None => acc.clone(), - }, - ) - } +let recv = method_receiver(call.clone()); +let mc_args = method_arg_nodes(call.clone()); +let base = match v2_rt::map_get(&func_sigs, mname) { + 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()) { + v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), first_pname.clone(), recv) + } else { + v2_rt::rc_empty_map::>() + } +}, + None => v2_rt::rc_empty_map::>(), +}, + None => v2_rt::rc_empty_map::>(), +}; +mc_args.iter().cloned().fold(base, |acc: Rc>>, arg_node: Rc| match arg_name_at(arg_node.clone(), source_indices.clone()) { + Some(aname) => v2_rt::rc_map_insert(acc.clone(), aname.clone(), arg_value(&arg_node)), + None => acc.clone(), +}) +} } -pub fn compose_callee_provenance( - callee: String, - arg_by_name: Rc>>, - param_names: Rc>, - param_types: Rc>, - type_env: Rc, - func_sigs: &Rc>>, - let_prov: Rc>>>>, -) -> Rc>> { +pub fn compose_callee_provenance(callee: String, arg_by_name: Rc>>, param_names: Rc>, param_types: Rc>, type_env: Rc, func_sigs: &Rc>>, let_prov: Rc>>>>) -> Rc>> { match v2_rt::map_get(&func_sigs, callee) { - Some(sig) => match sig.output_provenance.clone().first().cloned() { - Some(callee_prov) => Rc::new(v2_rt::map_keys(&callee_prov)).iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, callee_pname: String| { - match v2_rt::map_get(&callee_prov, callee_pname.clone()) { - Some(callee_rel) => { - match v2_rt::map_get(&arg_by_name, callee_pname.clone()) { - Some(arg) => { - let arg_prov = classify_body_provenance( - &arg, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - Rc::new(v2_rt::map_keys(&arg_prov)).iter().cloned().fold( - acc.clone(), - |inner: Rc>>, - pname: String| { - match v2_rt::map_get(&arg_prov, pname.clone()) { - Some(arg_rel) => { - let composed = compose_sub_value_relations( - arg_rel.clone(), - callee_rel.clone(), - ); - match (*composed.clone()).clone() { - SubValueRelation::SubValueUnknown => { - inner.clone() - } - _ => match v2_rt::map_get( - &inner, - pname.clone(), - ) { - Some(existing) => v2_rt::rc_map_insert( - inner.clone(), - pname.clone(), - meet_sub_value( - existing.clone(), - composed.clone(), - ), - ), - None => v2_rt::rc_map_insert( - inner.clone(), - pname.clone(), - composed.clone(), - ), - }, - } - } - None => inner.clone(), - } - }, - ) - } - None => acc.clone(), - } - } - None => acc.clone(), - } - }, - ), - None => v2_rt::rc_empty_map::>(), - }, - None => v2_rt::rc_empty_map::>(), - } + Some(sig) => match sig.output_provenance.clone().first().cloned() { + Some(callee_prov) => Rc::new(v2_rt::map_keys(&callee_prov)).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, callee_pname: String| match v2_rt::map_get(&callee_prov, callee_pname.clone()) { + Some(callee_rel) => match v2_rt::map_get(&arg_by_name, callee_pname.clone()) { + Some(arg) => { + let arg_prov = classify_body_provenance(&arg, ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +Rc::new(v2_rt::map_keys(&arg_prov)).iter().cloned().fold(acc.clone(), |inner: Rc>>, pname: String| match v2_rt::map_get(&arg_prov, pname.clone()) { + Some(arg_rel) => { + let composed = compose_sub_value_relations(arg_rel.clone(), callee_rel.clone()); +match (*composed.clone()).clone() { + SubValueRelation::SubValueUnknown => inner.clone(), + _ => match v2_rt::map_get(&inner, pname.clone()) { + Some(existing) => v2_rt::rc_map_insert(inner.clone(), pname.clone(), meet_sub_value(existing.clone(), composed.clone())), + None => v2_rt::rc_map_insert(inner.clone(), pname.clone(), composed.clone()), +}, +} +}, + None => inner.clone(), +}) +}, + None => acc.clone(), +}, + None => acc.clone(), +}), + None => v2_rt::rc_empty_map::>(), +}, + None => v2_rt::rc_empty_map::>(), +} } -pub fn classify_body_per_field( - expr: Rc, - param_names: Rc>, - param_types: Rc>, - type_env: &Rc, - func_sigs: Rc>>, - let_prov: Rc>>>>, -) -> Rc>>>> { +pub fn classify_body_per_field(expr: Rc, param_names: Rc>, param_types: Rc>, type_env: &Rc, func_sigs: Rc>>, let_prov: Rc>>>>) -> Rc>>>> { { let unwrapped = unwrap_body_terminal(&expr, let_prov, type_env.clone()); - let terminal = unwrapped.expr.clone(); - let terminal_prov = unwrapped.let_prov.clone(); - classify_terminal_per_field( - &terminal, - param_names, - param_types, - &type_env, - func_sigs, - terminal_prov, - ) - } +let terminal = unwrapped.expr.clone(); +let terminal_prov = unwrapped.let_prov.clone(); +classify_terminal_per_field(&terminal, param_names, param_types, &type_env, func_sigs, terminal_prov) +} } -pub fn classify_terminal_per_field( - expr: &Rc, - param_names: Rc>, - param_types: Rc>, - type_env: &Rc, - func_sigs: Rc>>, - let_prov: Rc>>>>, -) -> Rc>>>> { +pub fn classify_terminal_per_field(expr: &Rc, param_names: Rc>, param_types: Rc>, type_env: &Rc, func_sigs: Rc>>, let_prov: Rc>>>>) -> Rc>>>> { match (*expr.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => Rc::new({ - let mut __result = Vec::new(); - for fi in expr.children.clone().iter().cloned() { - __result.push(classify_body_provenance( - &field_init_node_value(&fi), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - )); - } - __result - }), - ExprData::ExprMatch => { - let arm_results = Rc::new({ - let mut __result = Vec::new(); - for arm in match_arm_nodes(expr.clone()).iter().cloned() { - __result.push({ - let arm_unwrapped = unwrap_body_terminal( - &arm_body(&arm), - let_prov.clone(), - type_env.clone(), - ); - match (*arm_unwrapped.expr.clone().expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => Rc::new({ - let mut __result = Vec::new(); - for fi in - arm_unwrapped.expr.clone().children.clone().iter().cloned() - { - __result.push(classify_body_provenance( - &field_init_node_value(&fi), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &arm_unwrapped.let_prov.clone(), - )); - } - __result - }), - _ => Rc::new(vec![]), - } - }); - } - __result - }); - meet_per_field_results(&arm_results) - } - ExprData::ExprIf => { - let then_unwrapped = unwrap_body_terminal( - &if_then_branch(expr.clone()), - let_prov.clone(), - type_env.clone(), - ); - let then_result = match (*then_unwrapped.expr.clone().expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => Rc::new({ - let mut __result = Vec::new(); - for fi in then_unwrapped.expr.clone().children.clone().iter().cloned() { - __result.push(classify_body_provenance( - &field_init_node_value(&fi), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &then_unwrapped.let_prov.clone(), - )); - } - __result - }), - _ => Rc::new(vec![]), - }; - match if_else_branch(expr.clone()) { - Some(else_expr) => { - let else_unwrapped = - unwrap_body_terminal(&else_expr, let_prov.clone(), type_env.clone()); - let else_result = match (*else_unwrapped.expr.clone().expr_data.clone()).clone() - { - ExprData::ExprRecordLit { .. } => Rc::new({ - let mut __result = Vec::new(); - for fi in else_unwrapped.expr.clone().children.clone().iter().cloned() { - __result.push(classify_body_provenance( - &field_init_node_value(&fi), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &else_unwrapped.let_prov.clone(), - )); - } - __result - }), - _ => Rc::new(vec![]), - }; - meet_per_field_results(&Rc::new(vec![then_result, else_result])) - } - None => then_result, - } - } - _ => Rc::new(vec![]), - } + ExprData::ExprRecordLit { .. } => Rc::new({ let mut __result = Vec::new(); for fi in expr.children.clone().iter().cloned() { __result.push(classify_body_provenance(&field_init_node_value(&fi), ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov)); } __result }), + ExprData::ExprMatch => { + let arm_results = Rc::new({ let mut __result = Vec::new(); for arm in match_arm_nodes(expr.clone()).iter().cloned() { __result.push({ + let arm_unwrapped = unwrap_body_terminal(&arm_body(&arm), let_prov.clone(), type_env.clone()); +match (*arm_unwrapped.expr.clone().expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => Rc::new({ let mut __result = Vec::new(); for fi in arm_unwrapped.expr.clone().children.clone().iter().cloned() { __result.push(classify_body_provenance(&field_init_node_value(&fi), ¶m_names, ¶m_types, &type_env, &func_sigs, &arm_unwrapped.let_prov.clone())); } __result }), + _ => Rc::new(vec![]), +} +}); } __result }); +meet_per_field_results(&arm_results) +}, + ExprData::ExprIf => { + let then_unwrapped = unwrap_body_terminal(&if_then_branch(expr.clone()), let_prov.clone(), type_env.clone()); +let then_result = match (*then_unwrapped.expr.clone().expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => Rc::new({ let mut __result = Vec::new(); for fi in then_unwrapped.expr.clone().children.clone().iter().cloned() { __result.push(classify_body_provenance(&field_init_node_value(&fi), ¶m_names, ¶m_types, &type_env, &func_sigs, &then_unwrapped.let_prov.clone())); } __result }), + _ => Rc::new(vec![]), +}; +match if_else_branch(expr.clone()) { + Some(else_expr) => { + let else_unwrapped = unwrap_body_terminal(&else_expr, let_prov.clone(), type_env.clone()); +let else_result = match (*else_unwrapped.expr.clone().expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => Rc::new({ let mut __result = Vec::new(); for fi in else_unwrapped.expr.clone().children.clone().iter().cloned() { __result.push(classify_body_provenance(&field_init_node_value(&fi), ¶m_names, ¶m_types, &type_env, &func_sigs, &else_unwrapped.let_prov.clone())); } __result }), + _ => Rc::new(vec![]), +}; +meet_per_field_results(&Rc::new(vec![then_result, else_result])) +}, + None => then_result, +} +}, + _ => Rc::new(vec![]), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -8091,884 +4692,401 @@ pub struct BodyTerminal { pub let_prov: Rc>>>>, } -pub fn unwrap_body_terminal( - expr: &Rc, - let_prov: Rc>>>>, - type_env: Rc, -) -> Rc { +pub fn unwrap_body_terminal(expr: &Rc, let_prov: Rc>>>>, type_env: Rc) -> Rc { match (*expr.expr_data.clone()).clone() { - ExprData::ExprBlock => match expr.children.clone().last().cloned() { - Some(last_stmt) => Rc::new(BodyTerminal { - expr: last_stmt.clone(), - let_prov: let_prov, - }), - None => Rc::new(BodyTerminal { - expr: expr.clone(), - let_prov: let_prov, - }), - }, - _ => Rc::new(BodyTerminal { - expr: expr.clone(), - let_prov: let_prov, - }), - } + ExprData::ExprBlock => match expr.children.clone().last().cloned() { + Some(last_stmt) => Rc::new(BodyTerminal { + expr: last_stmt.clone(), + let_prov: let_prov, +}), + None => Rc::new(BodyTerminal { + expr: expr.clone(), + let_prov: let_prov, +}), +}, + _ => Rc::new(BodyTerminal { + expr: expr.clone(), + let_prov: let_prov, +}), +} } -pub fn meet_per_field_results( - results: &Rc>>>>>>, -) -> Rc>>>> { +pub fn meet_per_field_results(results: &Rc>>>>>>) -> Rc>>>> { match results.clone().first().cloned() { - None => Rc::new(vec![]), - Some(first_result) => { - if ((first_result.clone().len() as i64) == 0) { + None => Rc::new(vec![]), + Some(first_result) => if ((first_result.clone().len() as i64) == 0) { + Rc::new(vec![]) + } else { + { + let all_same_count = { let mut __all = true; for r in results.clone().iter().cloned() { if !(((r.clone().len() as i64) == (first_result.clone().len() as i64))) { __all = false; break; } } __all }; +if !all_same_count { Rc::new(vec![]) } else { - { - let all_same_count = { - let mut __all = true; - for r in results.clone().iter().cloned() { - if !((r.clone().len() as i64) == (first_result.clone().len() as i64)) { - __all = false; - break; - } - } - __all - }; - if !all_same_count { - Rc::new(vec![]) - } else { - Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - first_result - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push({ - let idx = pair.0.clone(); - let field_provs = Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - __result.push( - match r.clone().get(idx.clone() as usize).cloned() { - Some(m) => m.clone(), - None => empty_prov_map(), - }, - ); - } - __result - }); - meet_body_provenance_maps(&field_provs) - }); - } - __result - }) - } - } + Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(first_result.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let idx = pair.0.clone(); +let field_provs = Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { __result.push(match r.clone().get(idx.clone() as usize).cloned() { + Some(m) => m.clone(), + None => empty_prov_map(), +}); } __result }); +meet_body_provenance_maps(&field_provs) +}); } __result }) } - } - } +} + }, +} } pub fn empty_prov_map() -> Rc>> { v2_rt::rc_empty_map::>() } -pub fn meet_body_provenance_maps( - provs: &Rc>>>>, -) -> Rc>> { +pub fn meet_body_provenance_maps(provs: &Rc>>>>) -> Rc>> { match provs.clone().first().cloned() { - None => empty_prov_map(), - Some(first_prov) => Rc::new( - provs - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) - .iter() - .cloned() - .fold( - first_prov.clone(), - |acc: Rc>>, - prov: Rc>>| { - intersect_prov_maps(&acc, prov.clone()) - }, - ), - } + None => empty_prov_map(), + Some(first_prov) => Rc::new(provs.clone().iter().cloned().skip(1 as usize).collect::>()).iter().cloned().fold(first_prov.clone(), |acc: Rc>>, prov: Rc>>| intersect_prov_maps(&acc, prov.clone())), +} } -pub fn intersect_prov_maps( - a: &Rc>>, - b: Rc>>, -) -> Rc>> { - Rc::new(v2_rt::map_keys(&a)).iter().cloned().fold( - empty_prov_map(), - |result: Rc>>, key: String| match v2_rt::map_get( - &b, - key.clone(), - ) { - Some(b_rel) => match v2_rt::map_get(&a, key.clone()) { - Some(a_rel) => v2_rt::rc_map_insert( - result.clone(), - key.clone(), - meet_sub_value(a_rel.clone(), b_rel.clone()), - ), - None => result.clone(), - }, - None => result.clone(), - }, - ) +pub fn intersect_prov_maps(a: &Rc>>, b: Rc>>) -> Rc>> { + Rc::new(v2_rt::map_keys(&a)).iter().cloned().fold(empty_prov_map(), |result: Rc>>, key: String| match v2_rt::map_get(&b, key.clone()) { + Some(b_rel) => match v2_rt::map_get(&a, key.clone()) { + Some(a_rel) => v2_rt::rc_map_insert(result.clone(), key.clone(), meet_sub_value(a_rel.clone(), b_rel.clone())), + None => result.clone(), +}, + None => result.clone(), +}) } -pub fn arm_ctx_from_variant_provenance( - arm_node: Rc, - sig: Rc, - scrut: Rc, - ctx: &Rc, -) -> Option> { +pub fn arm_ctx_from_variant_provenance(arm_node: Rc, sig: Rc, scrut: Rc, ctx: &Rc) -> Option> { match (*arm_pattern(arm_node)).clone() { - MatchPattern::VariantPattern { - name: vname, - field_bindings: bindings, - .. - } => match v2_rt::map_get(&sig.variant_provenance.clone(), vname.clone()) { - Some(variant_field_map) => { - let call_args = - call_args_by_name(scrut, ctx.type_env.clone().source_indices.clone()); - let extended = bindings.clone().iter().cloned().fold( - ctx.clone(), - |c: Rc, fb: Rc| { - let field_label = field_binding_name_at( - fb.clone(), - ctx.type_env.clone().source_indices.clone(), - ); - let bind_name = match (*field_binding_pattern(fb.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())) - { - c.clone() - } else { - match v2_rt::map_get(&variant_field_map, field_label.clone()) { - Some(param_map) => { - let composed = compose_callee_param_map( - ¶m_map, - call_args.clone(), - c.param_order.clone(), - c.param_names.clone(), - c.type_env.clone(), - c.func_sigs.clone(), - v2_rt::rc_empty_map::< - String, - Rc>>, - >(), - ); - let all_rels = Rc::new({ - let mut __result = Vec::new(); - for k in Rc::new(v2_rt::map_keys(&composed)).iter().cloned() - { - __result.push( - match v2_rt::map_get(&composed, k.clone()) { - Some(r) => r.clone(), - None => { - Rc::new(SubValueRelation::SubValueUnknown) - } - }, - ); - } - __result - }); - let best = merge_argument_relations(&all_rels); - match (*best.clone()).clone() { - SubValueRelation::SubValueUnknown => c.clone(), - _ => Rc::new(DescentContext { - fn_name: c.fn_name.clone(), - param_names: c.param_names.clone(), - param_order: c.param_order.clone(), - type_env: c.type_env.clone(), - sub_value_vars: v2_rt::rc_map_insert( - c.sub_value_vars.clone(), - bind_name.clone(), - best.clone(), - ), - size_aliases: c.size_aliases.clone(), - scope_locals: c.scope_locals.clone(), - func_sigs: c.func_sigs.clone(), - per_field_vars: c.per_field_vars.clone(), - }), - } - } - None => c.clone(), - } - } - }, - ); - Some(extended) + MatchPattern::VariantPattern { name: vname, field_bindings: bindings, .. } => match v2_rt::map_get(&sig.variant_provenance.clone(), vname.clone()) { + Some(variant_field_map) => { + let call_args = call_args_by_name(scrut, ctx.type_env.clone().source_indices.clone()); +let extended = bindings.clone().iter().cloned().fold(ctx.clone(), |c: Rc, fb: Rc| { + let field_label = field_binding_name_at(fb.clone(), ctx.type_env.clone().source_indices.clone()); +let bind_name = match (*field_binding_pattern(fb.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())) { + c.clone() + } else { + match v2_rt::map_get(&variant_field_map, field_label.clone()) { + Some(param_map) => { + let composed = compose_callee_param_map(¶m_map, call_args.clone(), c.param_order.clone(), c.param_names.clone(), c.type_env.clone(), c.func_sigs.clone(), v2_rt::rc_empty_map::>>>()); +let all_rels = Rc::new({ let mut __result = Vec::new(); for k in Rc::new(v2_rt::map_keys(&composed)).iter().cloned() { __result.push(match v2_rt::map_get(&composed, k.clone()) { + Some(r) => r.clone(), + None => Rc::new(SubValueRelation::SubValueUnknown), +}); } __result }); +let best = merge_argument_relations(&all_rels); +match (*best.clone()).clone() { + SubValueRelation::SubValueUnknown => c.clone(), + _ => Rc::new(DescentContext { + fn_name: c.fn_name.clone(), + param_names: c.param_names.clone(), + param_order: c.param_order.clone(), + type_env: c.type_env.clone(), + sub_value_vars: v2_rt::rc_map_insert(c.sub_value_vars.clone(), bind_name.clone(), best.clone()), + size_aliases: c.size_aliases.clone(), + scope_locals: c.scope_locals.clone(), + func_sigs: c.func_sigs.clone(), + per_field_vars: c.per_field_vars.clone(), +}), +} +}, + None => c.clone(), +} } - None => None, - }, - _ => None, - } +}); +Some(extended) +}, + None => None, +}, + _ => None, +} } -pub fn compose_callee_param_map( - callee_prov: &Rc>>, - arg_by_name: Rc>>, - param_names: Rc>, - param_types: Rc>, - type_env: Rc, - func_sigs: Rc>>, - let_prov: Rc>>>>, -) -> Rc>> { - Rc::new(v2_rt::map_keys(&callee_prov)).iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, callee_pname: String| match v2_rt::map_get( - &callee_prov, - callee_pname.clone(), - ) { - Some(callee_rel) => match v2_rt::map_get(&arg_by_name, callee_pname.clone()) { - Some(arg) => { - let arg_prov = classify_body_provenance( - &arg, - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - Rc::new(v2_rt::map_keys(&arg_prov)).iter().cloned().fold( - acc.clone(), - |inner: Rc>>, pname: String| { - match v2_rt::map_get(&arg_prov, pname.clone()) { - Some(arg_rel) => { - let composed = compose_sub_value_relations( - arg_rel.clone(), - callee_rel.clone(), - ); - match (*composed.clone()).clone() { - SubValueRelation::SubValueUnknown => inner.clone(), - _ => v2_rt::rc_map_insert( - inner.clone(), - pname.clone(), - composed.clone(), - ), - } - } - None => inner.clone(), - } - }, - ) - } - None => acc.clone(), - }, - None => acc.clone(), - }, - ) +pub fn compose_callee_param_map(callee_prov: &Rc>>, arg_by_name: Rc>>, param_names: Rc>, param_types: Rc>, type_env: Rc, func_sigs: Rc>>, let_prov: Rc>>>>) -> Rc>> { + Rc::new(v2_rt::map_keys(&callee_prov)).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, callee_pname: String| match v2_rt::map_get(&callee_prov, callee_pname.clone()) { + Some(callee_rel) => match v2_rt::map_get(&arg_by_name, callee_pname.clone()) { + Some(arg) => { + let arg_prov = classify_body_provenance(&arg, ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +Rc::new(v2_rt::map_keys(&arg_prov)).iter().cloned().fold(acc.clone(), |inner: Rc>>, pname: String| match v2_rt::map_get(&arg_prov, pname.clone()) { + Some(arg_rel) => { + let composed = compose_sub_value_relations(arg_rel.clone(), callee_rel.clone()); +match (*composed.clone()).clone() { + SubValueRelation::SubValueUnknown => inner.clone(), + _ => v2_rt::rc_map_insert(inner.clone(), pname.clone(), composed.clone()), +} +}, + None => inner.clone(), +}) +}, + None => acc.clone(), +}, + None => acc.clone(), +}) } -pub fn compose_output_relations( - arg_rel: Rc, - callee_rel: Rc, -) -> Rc { +pub fn compose_output_relations(arg_rel: Rc, callee_rel: Rc) -> Rc { compose_sub_value_relations(arg_rel, callee_rel) } -pub fn compute_variant_provenance( - body: Rc, - return_type: Rc, - params: &Rc>>, - type_env: &Rc, - func_sigs: Rc>>, -) -> Rc>>>>>> { +pub fn compute_variant_provenance(body: Rc, return_type: Rc, params: &Rc>>, type_env: &Rc, func_sigs: Rc>>) -> Rc>>>>>> { { let rt_name = authored_name_at(type_env.source_indices.clone(), &return_type); - let rt_def = lookup_type_by_name(&type_env, rt_name.clone()); - match rt_def { - Some(def_node) => match def_node.connective.clone() { - Connective::Disj => { - let param_names = Rc::new({ - let mut __result = Vec::new(); - for p in params.clone().iter().cloned() { - __result.push(param_node_name_at( - p.clone(), - type_env.source_indices.clone(), - )); - } - __result - }); - let param_types = params.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, p: Rc| { - let pname = - param_node_name_at(p.clone(), type_env.source_indices.clone()); - let ptype = resolved_type_name(&p, type_env.source_indices.clone()); - if ((pname.clone().as_str() != "".to_string().as_str()) - && (ptype.clone().as_str() != "".to_string().as_str())) - { - v2_rt::rc_map_insert(acc.clone(), pname.clone(), ptype.clone()) - } else { - acc.clone() - } - }, - ); - collect_variant_constructors( - &body, - rt_name.clone(), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - v2_rt::rc_empty_map::>>>(), - &v2_rt::rc_empty_map::< - String, - Rc>>>>, - >(), - ) +let rt_def = lookup_type_by_name(&type_env, rt_name.clone()); +match rt_def { + Some(def_node) => match def_node.connective.clone() { + Connective::Disj => { + let param_names = Rc::new({ let mut __result = Vec::new(); for p in params.clone().iter().cloned() { __result.push(param_node_name_at(p.clone(), type_env.source_indices.clone())); } __result }); +let param_types = params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, p: Rc| { + let pname = param_node_name_at(p.clone(), type_env.source_indices.clone()); +let ptype = resolved_type_name(&p, type_env.source_indices.clone()); +if ((pname.clone().as_str() != "".to_string().as_str()) && (ptype.clone().as_str() != "".to_string().as_str())) { + v2_rt::rc_map_insert(acc.clone(), pname.clone(), ptype.clone()) + } else { + acc.clone() } - _ => v2_rt::rc_empty_map::< - String, - Rc>>>>, - >(), - }, - None => v2_rt::rc_empty_map::< - String, - Rc>>>>, - >(), - } - } +}); +collect_variant_constructors(&body, rt_name.clone(), ¶m_names, ¶m_types, &type_env, &func_sigs, v2_rt::rc_empty_map::>>>(), &v2_rt::rc_empty_map::>>>>>()) +}, + _ => v2_rt::rc_empty_map::>>>>>(), +}, + None => v2_rt::rc_empty_map::>>>>>(), +} +} } -pub fn collect_variant_constructors( - body: &Rc, - parent_enum: String, - param_names: &Rc>, - param_types: &Rc>, - type_env: &Rc, - func_sigs: &Rc>>, - let_prov: Rc>>>>, - acc: &Rc>>>>>>, -) -> Rc>>>>>> { +pub fn collect_variant_constructors(body: &Rc, parent_enum: String, param_names: &Rc>, param_types: &Rc>, type_env: &Rc, func_sigs: &Rc>>, let_prov: Rc>>>>, acc: &Rc>>>>>>) -> Rc>>>>>> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*body.expr_data.clone()).clone() { - ExprData::ExprRecordLit { - parent_enum: pe, .. - } => match pe.clone() { - Some(enum_name) => { - if (enum_name.clone().as_str() == parent_enum.clone().as_str()) { - { - let variant_name = body.name.clone(); - let field_prov_map = body.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::< - String, - Rc>>, - >(), - |m: Rc< - HashMap>>>, - >, - fi: Rc| { - let fname = field_init_node_name_at( - fi.clone(), - type_env.source_indices.clone(), - ); - let fprov = classify_body_provenance( - &field_init_node_value(&fi), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - if (fname.clone().as_str() != "".to_string().as_str()) { - v2_rt::rc_map_insert( - m.clone(), - fname.clone(), - fprov.clone(), - ) - } else { - m.clone() - } - }, - ); - match v2_rt::map_get(&acc, variant_name.clone()) { - Some(existing) => { - let merged = merge_field_prov_maps(&existing, &field_prov_map); - v2_rt::rc_map_insert(acc.clone(), variant_name.clone(), merged) - } - None => v2_rt::rc_map_insert( - acc.clone(), - variant_name.clone(), - field_prov_map, - ), - } - } + ExprData::ExprRecordLit { parent_enum: pe, .. } => match pe.clone() { + Some(enum_name) => if (enum_name.clone().as_str() == parent_enum.clone().as_str()) { + { + let variant_name = body.name.clone(); +let field_prov_map = body.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |m: Rc>>>>, fi: Rc| { + let fname = field_init_node_name_at(fi.clone(), type_env.source_indices.clone()); +let fprov = classify_body_provenance(&field_init_node_value(&fi), ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +if (fname.clone().as_str() != "".to_string().as_str()) { + v2_rt::rc_map_insert(m.clone(), fname.clone(), fprov.clone()) } else { - acc.clone() - } - } - None => acc.clone(), - }, - ExprData::ExprMatch => match_arm_nodes(body.clone()).iter().cloned().fold( - acc.clone(), - |a: Rc< - HashMap>>>>>, - >, - arm: Rc| { - collect_variant_constructors( - &arm_body(&arm), - parent_enum.clone(), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - let_prov.clone(), - &a, - ) - }, - ), - ExprData::ExprIf => { - let then_acc = collect_variant_constructors( - &if_then_branch(body.clone()), - parent_enum.clone(), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - let_prov.clone(), - &acc, - ); - match if_else_branch(body.clone()) { - Some(eb) => collect_variant_constructors( - &eb, - parent_enum.clone(), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - let_prov.clone(), - &then_acc, - ), - None => then_acc, - } - } - ExprData::ExprLet => match let_body(body.clone()) { - Some(b) => { - let bname = let_binding_name_at(body.clone(), type_env.source_indices.clone()); - let value_prov = classify_body_provenance( - &let_value(body.clone()), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &let_prov, - ); - let new_lp = v2_rt::rc_map_insert(let_prov.clone(), bname.clone(), value_prov); - collect_variant_constructors( - &b, - parent_enum.clone(), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - new_lp, - &acc, - ) - } - None => acc.clone(), - }, - ExprData::ExprBlock => { - let stmts = body.children.clone(); - let stmt_count = (stmts.clone().len() as i64); - if (stmt_count.clone() == 0) { - acc.clone() - } else { - { - let final_lp = Rc::new( - stmts - .clone() - .iter() - .cloned() - .take((stmt_count.clone() - 1) as usize) - .collect::>(), - ) - .iter() - .cloned() - .fold( - let_prov.clone(), - |lp: Rc>>>>, - stmt: Rc| match (*stmt - .expr_data - .clone()) - .clone() - { - ExprData::ExprLet => { - let bname = let_binding_name_at( - stmt.clone(), - type_env.source_indices.clone(), - ); - let vprov = classify_body_provenance( - &let_value(stmt.clone()), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - &lp, - ); - v2_rt::rc_map_insert(lp.clone(), bname.clone(), vprov.clone()) - } - _ => lp.clone(), - }, - ); - match stmts - .clone() - .get((stmt_count.clone() - 1) as usize) - .cloned() - { - Some(last) => collect_variant_constructors( - &last, - parent_enum.clone(), - ¶m_names, - ¶m_types, - &type_env, - &func_sigs, - final_lp, - &acc, - ), - None => acc.clone(), - } + m.clone() } - } +}); +match v2_rt::map_get(&acc, variant_name.clone()) { + Some(existing) => { + let merged = merge_field_prov_maps(&existing, &field_prov_map); +v2_rt::rc_map_insert(acc.clone(), variant_name.clone(), merged) +}, + None => v2_rt::rc_map_insert(acc.clone(), variant_name.clone(), field_prov_map), +} +} + } else { + acc.clone() + }, + None => acc.clone(), +}, + ExprData::ExprMatch => match_arm_nodes(body.clone()).iter().cloned().fold(acc.clone(), |a: Rc>>>>>>, arm: Rc| collect_variant_constructors(&arm_body(&arm), parent_enum.clone(), ¶m_names, ¶m_types, &type_env, &func_sigs, let_prov.clone(), &a)), + ExprData::ExprIf => { + let then_acc = collect_variant_constructors(&if_then_branch(body.clone()), parent_enum.clone(), ¶m_names, ¶m_types, &type_env, &func_sigs, let_prov.clone(), &acc); +match if_else_branch(body.clone()) { + Some(eb) => collect_variant_constructors(&eb, parent_enum.clone(), ¶m_names, ¶m_types, &type_env, &func_sigs, let_prov.clone(), &then_acc), + None => then_acc, +} +}, + ExprData::ExprLet => match let_body(body.clone()) { + Some(b) => { + let bname = let_binding_name_at(body.clone(), type_env.source_indices.clone()); +let value_prov = classify_body_provenance(&let_value(body.clone()), ¶m_names, ¶m_types, &type_env, &func_sigs, &let_prov); +let new_lp = v2_rt::rc_map_insert(let_prov.clone(), bname.clone(), value_prov); +collect_variant_constructors(&b, parent_enum.clone(), ¶m_names, ¶m_types, &type_env, &func_sigs, new_lp, &acc) +}, + None => acc.clone(), +}, + ExprData::ExprBlock => { + let stmts = body.children.clone(); +let stmt_count = (stmts.clone().len() as i64); +if (stmt_count.clone() == 0) { + acc.clone() + } else { + { + let final_lp = Rc::new(stmts.clone().iter().cloned().take((stmt_count.clone() - 1) as usize).collect::>()).iter().cloned().fold(let_prov.clone(), |lp: Rc>>>>, stmt: Rc| match (*stmt.expr_data.clone()).clone() { + ExprData::ExprLet => { + let bname = let_binding_name_at(stmt.clone(), type_env.source_indices.clone()); +let vprov = classify_body_provenance(&let_value(stmt.clone()), ¶m_names, ¶m_types, &type_env, &func_sigs, &lp); +v2_rt::rc_map_insert(lp.clone(), bname.clone(), vprov.clone()) +}, + _ => lp.clone(), +}); +match stmts.clone().get((stmt_count.clone() - 1) as usize).cloned() { + Some(last) => collect_variant_constructors(&last, parent_enum.clone(), ¶m_names, ¶m_types, &type_env, &func_sigs, final_lp, &acc), + None => acc.clone(), +} +} } - _ => acc.clone(), - } +}, + _ => acc.clone(), +} }) } -pub fn merge_field_prov_maps( - a: &Rc>>>>, - b: &Rc>>>>, -) -> Rc>>>> { +pub fn merge_field_prov_maps(a: &Rc>>>>, b: &Rc>>>>) -> Rc>>>> { { - let from_a = Rc::new(v2_rt::map_keys(&a)).iter().cloned().fold( - v2_rt::rc_empty_map::>>>(), - |result: Rc>>>>, - fname: String| match v2_rt::map_get(&a, fname.clone()) { - Some(a_prov) => match v2_rt::map_get(&b, fname.clone()) { - Some(b_prov) => v2_rt::rc_map_insert( - result.clone(), - fname.clone(), - union_prov_maps(&a_prov, &b_prov), - ), - None => v2_rt::rc_map_insert(result.clone(), fname.clone(), a_prov.clone()), - }, - None => result.clone(), - }, - ); - Rc::new(v2_rt::map_keys(&b)).iter().cloned().fold( - from_a, - |result: Rc>>>>, - fname: String| { - if (v2_rt::map_get(&result, fname.clone()) != None) { - result.clone() - } else { - match v2_rt::map_get(&b, fname.clone()) { - Some(b_prov) => { - v2_rt::rc_map_insert(result.clone(), fname.clone(), b_prov.clone()) - } - None => result.clone(), - } - } - }, - ) - } + let from_a = Rc::new(v2_rt::map_keys(&a)).iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |result: Rc>>>>, fname: String| match v2_rt::map_get(&a, fname.clone()) { + Some(a_prov) => match v2_rt::map_get(&b, fname.clone()) { + Some(b_prov) => v2_rt::rc_map_insert(result.clone(), fname.clone(), union_prov_maps(&a_prov, &b_prov)), + None => v2_rt::rc_map_insert(result.clone(), fname.clone(), a_prov.clone()), +}, + None => result.clone(), +}); +Rc::new(v2_rt::map_keys(&b)).iter().cloned().fold(from_a, |result: Rc>>>>, fname: String| if (v2_rt::map_get(&result, fname.clone()) != None) { + result.clone() + } else { + match v2_rt::map_get(&b, fname.clone()) { + Some(b_prov) => v2_rt::rc_map_insert(result.clone(), fname.clone(), b_prov.clone()), + None => result.clone(), +} + }) +} } -pub fn union_prov_maps( - a: &Rc>>, - b: &Rc>>, -) -> Rc>> { +pub fn union_prov_maps(a: &Rc>>, b: &Rc>>) -> Rc>> { { - let from_a = Rc::new(v2_rt::map_keys(&a)).iter().cloned().fold( - empty_prov_map(), - |result: Rc>>, key: String| match v2_rt::map_get( - &a, - key.clone(), - ) { - Some(a_rel) => match v2_rt::map_get(&b, key.clone()) { - Some(b_rel) => v2_rt::rc_map_insert( - result.clone(), - key.clone(), - join_sub_value(a_rel.clone(), b_rel.clone()), - ), - None => v2_rt::rc_map_insert(result.clone(), key.clone(), a_rel.clone()), - }, - None => result.clone(), - }, - ); - Rc::new(v2_rt::map_keys(&b)).iter().cloned().fold( - from_a, - |result: Rc>>, key: String| { - if (v2_rt::map_get(&result, key.clone()) != None) { - result.clone() - } else { - match v2_rt::map_get(&b, key.clone()) { - Some(b_rel) => { - v2_rt::rc_map_insert(result.clone(), key.clone(), b_rel.clone()) - } - None => result.clone(), - } - } - }, - ) - } + let from_a = Rc::new(v2_rt::map_keys(&a)).iter().cloned().fold(empty_prov_map(), |result: Rc>>, key: String| match v2_rt::map_get(&a, key.clone()) { + Some(a_rel) => match v2_rt::map_get(&b, key.clone()) { + Some(b_rel) => v2_rt::rc_map_insert(result.clone(), key.clone(), join_sub_value(a_rel.clone(), b_rel.clone())), + None => v2_rt::rc_map_insert(result.clone(), key.clone(), a_rel.clone()), +}, + None => result.clone(), +}); +Rc::new(v2_rt::map_keys(&b)).iter().cloned().fold(from_a, |result: Rc>>, key: String| if (v2_rt::map_get(&result, key.clone()) != None) { + result.clone() + } else { + match v2_rt::map_get(&b, key.clone()) { + Some(b_rel) => v2_rt::rc_map_insert(result.clone(), key.clone(), b_rel.clone()), + None => result.clone(), +} + }) +} } -pub fn populate_output_provenance( - typed_items: Rc>>, - func_env: Rc, - type_env: Rc, - locals: Rc>>, -) -> Rc { +pub fn populate_output_provenance(typed_items: Rc>>, func_env: Rc, type_env: Rc, locals: Rc>>) -> Rc { { - let updated_sigs = typed_items.iter().cloned().fold( - func_env.signatures.clone(), - |acc: Rc>>, item: Rc| { - if ((item.params.clone().len() as i64) > 0) { - { - let fn_name = authored_name_at(type_env.source_indices.clone(), &item); - if (is_child_accessor_in_model(fn_name.clone()) - || is_tree_size_reducing(fn_name.clone())) - { - match item.params.clone().first().cloned() { - Some(first_param) => { - let pname = param_node_name_at( - first_param.clone(), - type_env.source_indices.clone(), - ); - let ptype = resolved_type_name( - &first_param, - type_env.source_indices.clone(), - ); - if ((ptype.clone().as_str() != "".to_string().as_str()) - && (pname.clone().as_str() != "".to_string().as_str())) - { - { - let fields = inductive_fields_for( - type_env.clone(), - ptype.clone(), - ); - let list_field = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - if match f.shape.clone() { - RecursionShape::ListRecursion => true, - _ => false, - } { - __result.push(f); - } - } - __result - }) - .first() - .cloned(); - match list_field.clone() { - Some(ind_field) => { - let provenance = - Rc::new(vec![v2_rt::rc_map_insert( - v2_rt::rc_empty_map::< - String, - Rc, - >( - ), - pname.clone(), - Rc::new( - SubValueRelation::StrictSubValue { - field: ind_field.clone(), - factor: Rc::new( - ShrinkFactor::UnitShrink, - ), - }, - ), - )]); - match v2_rt::map_get(&acc, fn_name.clone()) { - Some(sig) => v2_rt::rc_map_insert( - acc.clone(), - fn_name.clone(), - Rc::new(ResolvedFuncSig { - name: sig.name.clone(), - params: sig.params.clone(), - inferred: sig.inferred.clone(), - is_async: sig.is_async.clone(), - output_provenance: provenance - .clone(), - variant_provenance: sig - .variant_provenance - .clone(), - }), - ), - None => acc.clone(), - } - } - None => acc.clone(), - } - } - } else { - acc.clone() - } - } - None => acc.clone(), - } + let updated_sigs = typed_items.iter().cloned().fold(func_env.signatures.clone(), |acc: Rc>>, item: Rc| if ((item.params.clone().len() as i64) > 0) { + { + let fn_name = authored_name_at(type_env.source_indices.clone(), &item); +if (is_child_accessor_in_model(fn_name.clone()) || is_tree_size_reducing(fn_name.clone())) { + match item.params.clone().first().cloned() { + Some(first_param) => { + let pname = param_node_name_at(first_param.clone(), type_env.source_indices.clone()); +let ptype = resolved_type_name(&first_param, type_env.source_indices.clone()); +if ((ptype.clone().as_str() != "".to_string().as_str()) && (pname.clone().as_str() != "".to_string().as_str())) { + { + let fields = inductive_fields_for(type_env.clone(), ptype.clone()); +let list_field = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { if match f.shape.clone() { + RecursionShape::ListRecursion => true, + _ => false, +} { __result.push(f); } } __result }).first().cloned(); +match list_field.clone() { + Some(ind_field) => { + let provenance = Rc::new(vec![v2_rt::rc_map_insert(v2_rt::rc_empty_map::>(), pname.clone(), Rc::new(SubValueRelation::StrictSubValue { + field: ind_field.clone(), + factor: Rc::new(ShrinkFactor::UnitShrink), +}))]); +match v2_rt::map_get(&acc, fn_name.clone()) { + Some(sig) => v2_rt::rc_map_insert(acc.clone(), fn_name.clone(), Rc::new(ResolvedFuncSig { + name: sig.name.clone(), + params: sig.params.clone(), + inferred: sig.inferred.clone(), + is_async: sig.is_async.clone(), + output_provenance: provenance.clone(), + variant_provenance: sig.variant_provenance.clone(), +})), + None => acc.clone(), +} +}, + None => acc.clone(), +} +} } else { - match item.body.clone() { - Some(body) => { - if !expr_has_self_call( - &body, - &fn_name, - &type_env.source_indices.clone(), - ) { - { - let provenance = infer_output_provenance( - &body, - &item.params.clone(), - &type_env, - locals.clone(), - &acc, - ); - let variant_prov = - match item.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: rt, - .. - }) => compute_variant_provenance( - body.clone(), - rt.clone(), - &item.params.clone(), - &type_env, - acc.clone(), - ), - _ => v2_rt::rc_empty_map::< - String, - Rc< - HashMap< - String, - Rc< - HashMap< - String, - Rc, - >, - >, - >, - >, - >( - ), - }; - let has_scalar = - ((provenance.clone().len() as i64) > 0); - let has_variant = - ((Rc::new(v2_rt::map_keys(&variant_prov)).len() - as i64) - > 0); - if (has_scalar.clone() || has_variant.clone()) { - match v2_rt::map_get(&acc, fn_name.clone()) { - Some(sig) => v2_rt::rc_map_insert( - acc.clone(), - fn_name.clone(), - Rc::new(ResolvedFuncSig { - name: sig.name.clone(), - params: sig.params.clone(), - inferred: sig.inferred.clone(), - is_async: sig.is_async.clone(), - output_provenance: if has_scalar.clone() - { - provenance.clone() - } else { - sig.output_provenance.clone() - }, - variant_provenance: if has_variant - .clone() - { - variant_prov.clone() - } else { - sig.variant_provenance.clone() - }, - }), - ), - None => acc.clone(), - } - } else { - acc.clone() - } - } - } else { - acc.clone() - } - } - None => acc.clone(), - } + acc.clone() } - } +}, + None => acc.clone(), +} } else { - acc.clone() + match item.body.clone() { + Some(body) => if !expr_has_self_call(&body, &fn_name, &type_env.source_indices.clone()) { + { + let provenance = infer_output_provenance(&body, &item.params.clone(), &type_env, locals.clone(), &acc); +let variant_prov = match item.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => compute_variant_provenance(body.clone(), rt.clone(), &item.params.clone(), &type_env, acc.clone()), + _ => v2_rt::rc_empty_map::>>>>>(), +}; +let has_scalar = ((provenance.clone().len() as i64) > 0); +let has_variant = ((Rc::new(v2_rt::map_keys(&variant_prov)).len() as i64) > 0); +if (has_scalar.clone() || has_variant.clone()) { + match v2_rt::map_get(&acc, fn_name.clone()) { + Some(sig) => v2_rt::rc_map_insert(acc.clone(), fn_name.clone(), Rc::new(ResolvedFuncSig { + name: sig.name.clone(), + params: sig.params.clone(), + inferred: sig.inferred.clone(), + is_async: sig.is_async.clone(), + output_provenance: if has_scalar.clone() { + provenance.clone() + } else { + sig.output_provenance.clone() + }, + variant_provenance: if has_variant.clone() { + variant_prov.clone() + } else { + sig.variant_provenance.clone() + }, +})), + None => acc.clone(), +} + } else { + acc.clone() + } +} + } else { + acc.clone() + }, + None => acc.clone(), +} } - }, - ); - Rc::new(ResolvedFuncEnv { - signatures: updated_sigs, - }) - } +} + } else { + acc.clone() + }); +Rc::new(ResolvedFuncEnv { + signatures: updated_sigs, +}) +} } -pub fn annotate_descent_evidence( - body: Rc, - fn_name: String, - params: &Rc>>, - type_env: &Rc, - scope_locals: Rc>>, - func_sigs: Rc>>, -) -> Rc { +pub fn annotate_descent_evidence(body: Rc, fn_name: String, params: &Rc>>, type_env: &Rc, scope_locals: Rc>>, func_sigs: Rc>>) -> Rc { { - let param_name_map = params.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, p: Rc| { - let pname = param_node_name_at(p.clone(), type_env.source_indices.clone()); - let ptype = resolved_type_name(&p, type_env.source_indices.clone()); - v2_rt::rc_map_insert(acc, pname.clone(), ptype.clone()) - }, - ); - let param_order_list = Rc::new({ - let mut __result = Vec::new(); - for p in params.clone().iter().cloned() { - __result.push(param_node_name_at( - p.clone(), - type_env.source_indices.clone(), - )); - } - __result - }); - let ctx = Rc::new(DescentContext { - fn_name: fn_name, - param_names: param_name_map, - param_order: param_order_list, - type_env: type_env.clone(), - sub_value_vars: v2_rt::rc_empty_map::>(), - size_aliases: v2_rt::rc_empty_map::>(), - scope_locals: scope_locals, - func_sigs: func_sigs, - per_field_vars: v2_rt::rc_empty_map::>>>( - ), - }); - annotate_descent(&body, &ctx) - } + let param_name_map = params.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, p: Rc| { + let pname = param_node_name_at(p.clone(), type_env.source_indices.clone()); +let ptype = resolved_type_name(&p, type_env.source_indices.clone()); +v2_rt::rc_map_insert(acc, pname.clone(), ptype.clone()) +}); +let param_order_list = Rc::new({ let mut __result = Vec::new(); for p in params.clone().iter().cloned() { __result.push(param_node_name_at(p.clone(), type_env.source_indices.clone())); } __result }); +let ctx = Rc::new(DescentContext { + fn_name: fn_name, + param_names: param_name_map, + param_order: param_order_list, + type_env: type_env.clone(), + sub_value_vars: v2_rt::rc_empty_map::>(), + size_aliases: v2_rt::rc_empty_map::>(), + scope_locals: scope_locals, + func_sigs: func_sigs, + per_field_vars: v2_rt::rc_empty_map::>>>(), +}); +annotate_descent(&body, &ctx) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -8982,1939 +5100,1147 @@ pub struct InferTransportResult { pub transport: Option>, pub diagnostics: Rc>>, } - -pub fn infer_property_values( - props: Rc>>, - scope: Rc, -) -> Rc { - { - let results = Rc::new({ - let mut __result = Vec::new(); - for p in props.iter().cloned() { - __result.push({ - let val = field_init_node_value(&p); - let val_result = infer_expr(&val, &scope, &None); - ( - Rc::new(Node { - name: p.name.clone(), - span: p.span.clone(), - ident_span: p.ident_span.clone(), - children: Rc::new(vec![val_result.typed.clone()]), - connective: p.connective.clone(), - params: p.params.clone(), - inferred: p.inferred.clone(), - return_cardinality: p.return_cardinality.clone(), - uses: p.uses.clone(), - body: p.body.clone(), - transport: p.transport.clone(), - properties: p.properties.clone(), - type_annotation: p.type_annotation.clone(), - is_self_recursive: p.is_self_recursive.clone(), - has_non_tail_self_call: p.has_non_tail_self_call.clone(), - match_pattern: p.match_pattern.clone(), - expr_data: p.expr_data.clone(), - ident: None, - }), - val_result.diagnostics.clone(), - ) - }); - } - __result - }); - Rc::new(InferPropertiesResult { - props: Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - __result.push(r.0.clone()); - } - __result - }), - diagnostics: Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - __result.extend((*r.1.clone()).iter().cloned()); - } - __result - }), - }) - } -} - -pub fn infer_auth_source_properties( - props: Rc>>, - scope: Rc, -) -> Rc { - { - let results = Rc::new({ - let mut __result = Vec::new(); - for p in props.iter().cloned() { - __result.push( - if (field_init_node_name_at( - p.clone(), - scope.type_env.clone().source_indices.clone(), - ) - .as_str() - == "svc_auth_source".to_string().as_str()) - { - { - let val = field_init_node_value(&p); - let val_result = infer_expr(&val, &scope, &None); - ( - Rc::new(Node { - name: p.name.clone(), - span: p.span.clone(), - ident_span: p.ident_span.clone(), - children: Rc::new(vec![val_result.typed.clone()]), - connective: p.connective.clone(), - params: p.params.clone(), - inferred: p.inferred.clone(), - return_cardinality: p.return_cardinality.clone(), - uses: p.uses.clone(), - body: p.body.clone(), - transport: p.transport.clone(), - properties: p.properties.clone(), - type_annotation: p.type_annotation.clone(), - is_self_recursive: p.is_self_recursive.clone(), - has_non_tail_self_call: p.has_non_tail_self_call.clone(), - match_pattern: p.match_pattern.clone(), - expr_data: p.expr_data.clone(), - ident: None, - }), - val_result.diagnostics.clone(), - ) - } - } else { - (p.clone(), Rc::new(vec![])) - }, - ); - } - __result - }); - Rc::new(InferPropertiesResult { - props: Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - __result.push(r.0.clone()); - } - __result - }), - diagnostics: Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - __result.extend((*r.1.clone()).iter().cloned()); - } - __result - }), - }) - } + +pub fn infer_property_values(props: Rc>>, scope: Rc) -> Rc { + { + let results = Rc::new({ let mut __result = Vec::new(); for p in props.iter().cloned() { __result.push({ + let val = field_init_node_value(&p); +let val_result = infer_expr(&val, &scope, &None); +(Rc::new(Node { + name: p.name.clone(), + span: p.span.clone(), + ident_span: p.ident_span.clone(), + children: Rc::new(vec![val_result.typed.clone()]), + connective: p.connective.clone(), + params: p.params.clone(), + inferred: p.inferred.clone(), + return_cardinality: p.return_cardinality.clone(), + uses: p.uses.clone(), + body: p.body.clone(), + transport: p.transport.clone(), + properties: p.properties.clone(), + type_annotation: p.type_annotation.clone(), + is_self_recursive: p.is_self_recursive.clone(), + has_non_tail_self_call: p.has_non_tail_self_call.clone(), + match_pattern: p.match_pattern.clone(), + expr_data: p.expr_data.clone(), + ident: None, +}), val_result.diagnostics.clone()) +}); } __result }); +Rc::new(InferPropertiesResult { + props: Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { __result.push(r.0.clone()); } __result }), + diagnostics: Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { __result.extend((*r.1.clone()).iter().cloned()); } __result }), +}) +} +} + +pub fn infer_auth_source_properties(props: Rc>>, scope: Rc) -> Rc { + { + let results = Rc::new({ let mut __result = Vec::new(); for p in props.iter().cloned() { __result.push(if (field_init_node_name_at(p.clone(), scope.type_env.clone().source_indices.clone()).as_str() == "svc_auth_source".to_string().as_str()) { + { + let val = field_init_node_value(&p); +let val_result = infer_expr(&val, &scope, &None); +(Rc::new(Node { + name: p.name.clone(), + span: p.span.clone(), + ident_span: p.ident_span.clone(), + children: Rc::new(vec![val_result.typed.clone()]), + connective: p.connective.clone(), + params: p.params.clone(), + inferred: p.inferred.clone(), + return_cardinality: p.return_cardinality.clone(), + uses: p.uses.clone(), + body: p.body.clone(), + transport: p.transport.clone(), + properties: p.properties.clone(), + type_annotation: p.type_annotation.clone(), + is_self_recursive: p.is_self_recursive.clone(), + has_non_tail_self_call: p.has_non_tail_self_call.clone(), + match_pattern: p.match_pattern.clone(), + expr_data: p.expr_data.clone(), + ident: None, +}), val_result.diagnostics.clone()) +} + } else { + (p.clone(), Rc::new(vec![])) + }); } __result }); +Rc::new(InferPropertiesResult { + props: Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { __result.push(r.0.clone()); } __result }), + diagnostics: Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { __result.extend((*r.1.clone()).iter().cloned()); } __result }), +}) +} } -pub fn infer_transport_node( - transport: Option>, - scope: Rc, -) -> Rc { +pub fn infer_transport_node(transport: Option>, scope: Rc) -> Rc { match transport { - None => Rc::new(InferTransportResult { - transport: None, - diagnostics: Rc::new(vec![]), - }), - Some(t) => { - let prop_result = infer_property_values(t.properties.clone(), scope); - Rc::new(InferTransportResult { - transport: Some(Rc::new(Node { - name: t.name.clone(), - span: t.span.clone(), - ident_span: t.ident_span.clone(), - children: t.children.clone(), - connective: t.connective.clone(), - params: t.params.clone(), - inferred: t.inferred.clone(), - return_cardinality: t.return_cardinality.clone(), - uses: t.uses.clone(), - body: t.body.clone(), - transport: t.transport.clone(), - properties: prop_result.props.clone(), - type_annotation: t.type_annotation.clone(), - is_self_recursive: t.is_self_recursive.clone(), - has_non_tail_self_call: t.has_non_tail_self_call.clone(), - match_pattern: t.match_pattern.clone(), - expr_data: t.expr_data.clone(), - ident: None, - })), - diagnostics: prop_result.diagnostics.clone(), - }) - } - } + None => Rc::new(InferTransportResult { + transport: None, + diagnostics: Rc::new(vec![]), +}), + Some(t) => { + let prop_result = infer_property_values(t.properties.clone(), scope); +Rc::new(InferTransportResult { + transport: Some(Rc::new(Node { + name: t.name.clone(), + span: t.span.clone(), + ident_span: t.ident_span.clone(), + children: t.children.clone(), + connective: t.connective.clone(), + params: t.params.clone(), + inferred: t.inferred.clone(), + return_cardinality: t.return_cardinality.clone(), + uses: t.uses.clone(), + body: t.body.clone(), + transport: t.transport.clone(), + properties: prop_result.props.clone(), + type_annotation: t.type_annotation.clone(), + is_self_recursive: t.is_self_recursive.clone(), + has_non_tail_self_call: t.has_non_tail_self_call.clone(), + match_pattern: t.match_pattern.clone(), + expr_data: t.expr_data.clone(), + ident: None, +})), + diagnostics: prop_result.diagnostics.clone(), +}) +}, +} } pub fn infer_item(item: &Rc, scope: &Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let typed_anno = item.type_annotation.clone(); - let transport_scope = if ((item.params.clone().len() as i64) > 0) { - build_params_scope(&scope, item.params.clone()) - } else { - scope.clone() - }; - let transport_result = infer_transport_node(item.transport.clone(), transport_scope); - let typed_transport = transport_result.transport.clone(); - let transport_diags = transport_result.diagnostics.clone(); - let props_result = infer_auth_source_properties(item.properties.clone(), scope.clone()); - let typed_properties = props_result.props.clone(); - let props_diags = props_result.diagnostics.clone(); - if ((item.connective.clone() != Connective::NoConnective) - && (item.transport.clone() == None)) { - Rc::new(TypedItemResult { - item: Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new({ - let mut __result = Vec::new(); - for c in item.children.clone().iter().cloned() { - __result.push(infer_item(&c, &scope).item.clone()); - } - __result - }), - params: item.params.clone(), - inferred: Some(Rc::new(InferredNode::Resolved { node: unit_type() })), - return_cardinality: item.return_cardinality.clone(), - uses: item.uses.clone(), - body: None, - connective: item.connective.clone(), - transport: typed_transport, - properties: typed_properties, - type_annotation: typed_anno, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: v2_rt::concat(transport_diags, props_diags), - }) - } else { - if ((item.body.clone() != None) && ((item.params.clone().len() as i64) > 0)) { - { - let fn_scope = build_params_scope(&scope, item.params.clone()); - let fn_scope = item.uses.clone().iter().cloned().fold( - fn_scope.clone(), - |s: Rc, u: Rc| { - extend_scope( - &s, - &resource_use_name_at( - u.clone(), - scope.type_env.clone().source_indices.clone(), - ), - resource_use_resource(&u), - Rc::new(SubValueRelation::SubValueUnknown), - ) - }, - ); - let fn_return_expected = if (item.inferred.clone() != None) { - Some(resolved_type(item.clone())) - } else { - None - }; - let body_result = infer_expr( - &item.body.clone().clone().unwrap(), - &fn_scope, - &fn_return_expected, - ); - let body_typed = body_result.typed.clone(); - let body_diags = body_result.diagnostics.clone(); - let inferred_ret = if (item.inferred.clone() != None) { - item.inferred.clone() - } else { - body_typed.inferred.clone() - }; - let is_recursive = expr_has_self_call( - &body_typed, - &authored_name_at(scope.type_env.clone().source_indices.clone(), &item), - &scope.type_env.clone().source_indices.clone(), - ); - let annotated_body = if is_recursive.clone() { - annotate_descent_evidence( - body_typed.clone(), - authored_name_at(scope.type_env.clone().source_indices.clone(), &item), - &item.params.clone(), - &scope.type_env.clone(), - fn_scope.locals.clone(), - scope.func_env.clone().signatures.clone(), - ) - } else { - body_typed.clone() - }; - Rc::new(TypedItemResult { - item: Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new({ - let mut __result = Vec::new(); - for c in item.children.clone().iter().cloned() { - __result.push(infer_item(&c, &scope).item.clone()); - } - __result - }), - params: item.params.clone(), - inferred: inferred_ret, - return_cardinality: item.return_cardinality.clone(), - uses: item.uses.clone(), - body: Some(annotated_body), - connective: Connective::NoConnective, - transport: typed_transport, - properties: typed_properties, - type_annotation: typed_anno, - is_self_recursive: is_recursive.clone(), - has_non_tail_self_call: expr_has_non_tail_self_call( - &body_typed, - &authored_name_at( - scope.type_env.clone().source_indices.clone(), - &item, - ), - true, - &scope.type_env.clone().source_indices.clone(), - ), - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: v2_rt::concat( - v2_rt::concat(transport_diags, props_diags), - body_diags, - ), - }) - } + let typed_anno = item.type_annotation.clone(); +let transport_scope = if ((item.params.clone().len() as i64) > 0) { + build_params_scope(&scope, item.params.clone()) } else { - if (((item.body.clone() != None) && ((item.params.clone().len() as i64) == 0)) - && (item.inferred.clone() != None)) - { + scope.clone() + }; +let transport_result = infer_transport_node(item.transport.clone(), transport_scope); +let typed_transport = transport_result.transport.clone(); +let transport_diags = transport_result.diagnostics.clone(); +let props_result = infer_auth_source_properties(item.properties.clone(), scope.clone()); +let typed_properties = props_result.props.clone(); +let props_diags = props_result.diagnostics.clone(); +if ((item.connective.clone() != Connective::NoConnective) && (item.transport.clone() == None)) { + Rc::new(TypedItemResult { + item: Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new({ let mut __result = Vec::new(); for c in item.children.clone().iter().cloned() { __result.push(infer_item(&c, &scope).item.clone()); } __result }), + params: item.params.clone(), + inferred: Some(Rc::new(InferredNode::Resolved { + node: unit_type(), +})), + return_cardinality: item.return_cardinality.clone(), + uses: item.uses.clone(), + body: None, + connective: item.connective.clone(), + transport: typed_transport, + properties: typed_properties, + type_annotation: typed_anno, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: v2_rt::concat(transport_diags, props_diags), +}) + } else { + if ((item.body.clone() != None) && ((item.params.clone().len() as i64) > 0)) { { - let fn_scope = scope.clone(); - let body_result = infer_expr( - &item.body.clone().clone().unwrap(), - &fn_scope, - &Some(resolved_type(item.clone())), - ); - let body_typed = body_result.typed.clone(); - let body_diags = body_result.diagnostics.clone(); - Rc::new(TypedItemResult { - item: Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: item.inferred.clone(), - return_cardinality: item.return_cardinality.clone(), - uses: Rc::new(vec![]), - body: Some(body_typed.clone()), - connective: Connective::NoConnective, - transport: typed_transport, - properties: typed_properties, - type_annotation: typed_anno, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: v2_rt::concat( - v2_rt::concat(transport_diags, props_diags), - body_diags, - ), - }) - } + let fn_scope = build_params_scope(&scope, item.params.clone()); +let fn_scope = item.uses.clone().iter().cloned().fold(fn_scope.clone(), |s: Rc, u: Rc| extend_scope(&s, &resource_use_name_at(u.clone(), scope.type_env.clone().source_indices.clone()), resource_use_resource(&u), Rc::new(SubValueRelation::SubValueUnknown))); +let fn_return_expected = if (item.inferred.clone() != None) { + Some(resolved_type(item.clone())) + } else { + None + }; +let body_result = infer_expr(&item.body.clone().clone().unwrap(), &fn_scope, &fn_return_expected); +let body_typed = body_result.typed.clone(); +let body_diags = body_result.diagnostics.clone(); +let inferred_ret = if (item.inferred.clone() != None) { + item.inferred.clone() + } else { + body_typed.inferred.clone() + }; +let is_recursive = expr_has_self_call(&body_typed, &authored_name_at(scope.type_env.clone().source_indices.clone(), &item), &scope.type_env.clone().source_indices.clone()); +let annotated_body = if is_recursive.clone() { + annotate_descent_evidence(body_typed.clone(), authored_name_at(scope.type_env.clone().source_indices.clone(), &item), &item.params.clone(), &scope.type_env.clone(), fn_scope.locals.clone(), scope.func_env.clone().signatures.clone()) + } else { + body_typed.clone() + }; +Rc::new(TypedItemResult { + item: Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new({ let mut __result = Vec::new(); for c in item.children.clone().iter().cloned() { __result.push(infer_item(&c, &scope).item.clone()); } __result }), + params: item.params.clone(), + inferred: inferred_ret, + return_cardinality: item.return_cardinality.clone(), + uses: item.uses.clone(), + body: Some(annotated_body), + connective: Connective::NoConnective, + transport: typed_transport, + properties: typed_properties, + type_annotation: typed_anno, + is_self_recursive: is_recursive.clone(), + has_non_tail_self_call: expr_has_non_tail_self_call(&body_typed, &authored_name_at(scope.type_env.clone().source_indices.clone(), &item), true, &scope.type_env.clone().source_indices.clone()), + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: v2_rt::concat(v2_rt::concat(transport_diags, props_diags), body_diags), +}) +} } else { - if ((item.body.clone() != None) && ((item.params.clone().len() as i64) == 0)) { + if (((item.body.clone() != None) && ((item.params.clone().len() as i64) == 0)) && (item.inferred.clone() != None)) { { - let data_expected = if (item.type_annotation.clone() != None) { - Some(item.type_annotation.clone().clone().unwrap()) - } else { - None - }; - let val_result = infer_expr( - &item.body.clone().clone().unwrap(), - &scope, - &data_expected, - ); - let val_typed = val_result.typed.clone(); - let val_diags = val_result.diagnostics.clone(); - let inferred_ret = if (item.type_annotation.clone() != None) { - Some(Rc::new(InferredNode::Resolved { - node: item.type_annotation.clone().clone().unwrap(), - })) - } else { - val_typed.inferred.clone() - }; - Rc::new(TypedItemResult { - item: Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: inferred_ret, - return_cardinality: item.return_cardinality.clone(), - uses: Rc::new(vec![]), - body: Some(val_typed.clone()), - connective: Connective::NoConnective, - transport: typed_transport, - properties: typed_properties, - type_annotation: typed_anno, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: v2_rt::concat( - v2_rt::concat(transport_diags, props_diags), - val_diags, - ), - }) - } + let fn_scope = scope.clone(); +let body_result = infer_expr(&item.body.clone().clone().unwrap(), &fn_scope, &Some(resolved_type(item.clone()))); +let body_typed = body_result.typed.clone(); +let body_diags = body_result.diagnostics.clone(); +Rc::new(TypedItemResult { + item: Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: item.inferred.clone(), + return_cardinality: item.return_cardinality.clone(), + uses: Rc::new(vec![]), + body: Some(body_typed.clone()), + connective: Connective::NoConnective, + transport: typed_transport, + properties: typed_properties, + type_annotation: typed_anno, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: v2_rt::concat(v2_rt::concat(transport_diags, props_diags), body_diags), +}) +} } else { - if (((item.params.clone().len() as i64) > 0) && (item.body.clone() == None)) - { - Rc::new(TypedItemResult { - item: Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new({ - let mut __result = Vec::new(); - for c in item.children.clone().iter().cloned() { - __result.push(infer_item(&c, &scope).item.clone()); - } - __result - }), - params: item.params.clone(), - inferred: if (item.inferred.clone() != None) { - item.inferred.clone() - } else { - Some(Rc::new(InferredNode::Resolved { node: unit_type() })) - }, - return_cardinality: item.return_cardinality.clone(), - uses: item.uses.clone(), - body: None, - connective: Connective::NoConnective, - transport: typed_transport, - properties: typed_properties, - type_annotation: typed_anno, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: v2_rt::concat(transport_diags, props_diags), - }) + if ((item.body.clone() != None) && ((item.params.clone().len() as i64) == 0)) { + { + let data_expected = if (item.type_annotation.clone() != None) { + Some(item.type_annotation.clone().clone().unwrap()) + } else { + None + }; +let val_result = infer_expr(&item.body.clone().clone().unwrap(), &scope, &data_expected); +let val_typed = val_result.typed.clone(); +let val_diags = val_result.diagnostics.clone(); +let inferred_ret = if (item.type_annotation.clone() != None) { + Some(Rc::new(InferredNode::Resolved { + node: item.type_annotation.clone().clone().unwrap(), +})) + } else { + val_typed.inferred.clone() + }; +Rc::new(TypedItemResult { + item: Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: inferred_ret, + return_cardinality: item.return_cardinality.clone(), + uses: Rc::new(vec![]), + body: Some(val_typed.clone()), + connective: Connective::NoConnective, + transport: typed_transport, + properties: typed_properties, + type_annotation: typed_anno, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: v2_rt::concat(v2_rt::concat(transport_diags, props_diags), val_diags), +}) +} } else { - Rc::new(TypedItemResult { - item: Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new({ - let mut __result = Vec::new(); - for c in item.children.clone().iter().cloned() { - __result.push(infer_item(&c, &scope).item.clone()); - } - __result - }), - params: item.params.clone(), - inferred: if (item.inferred.clone() != None) { - item.inferred.clone() - } else { - Some(Rc::new(InferredNode::Resolved { node: unit_type() })) - }, - return_cardinality: item.return_cardinality.clone(), - uses: item.uses.clone(), - body: None, - connective: item.connective.clone(), - transport: typed_transport, - properties: typed_properties, - type_annotation: typed_anno, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: v2_rt::concat(transport_diags, props_diags), - }) + if (((item.params.clone().len() as i64) > 0) && (item.body.clone() == None)) { + Rc::new(TypedItemResult { + item: Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new({ let mut __result = Vec::new(); for c in item.children.clone().iter().cloned() { __result.push(infer_item(&c, &scope).item.clone()); } __result }), + params: item.params.clone(), + inferred: if (item.inferred.clone() != None) { + item.inferred.clone() + } else { + Some(Rc::new(InferredNode::Resolved { + node: unit_type(), +})) + }, + return_cardinality: item.return_cardinality.clone(), + uses: item.uses.clone(), + body: None, + connective: Connective::NoConnective, + transport: typed_transport, + properties: typed_properties, + type_annotation: typed_anno, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: v2_rt::concat(transport_diags, props_diags), +}) + } else { + Rc::new(TypedItemResult { + item: Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new({ let mut __result = Vec::new(); for c in item.children.clone().iter().cloned() { __result.push(infer_item(&c, &scope).item.clone()); } __result }), + params: item.params.clone(), + inferred: if (item.inferred.clone() != None) { + item.inferred.clone() + } else { + Some(Rc::new(InferredNode::Resolved { + node: unit_type(), +})) + }, + return_cardinality: item.return_cardinality.clone(), + uses: item.uses.clone(), + body: None, + connective: item.connective.clone(), + transport: typed_transport, + properties: typed_properties, + type_annotation: typed_anno, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: v2_rt::concat(transport_diags, props_diags), +}) + } } } } } - } +} }) } -pub fn infer_items( - items: Rc>>, - scope: Rc, -) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for item in items.iter().cloned() { - __result.push(infer_item(&item, &scope)); - } - __result - }) +pub fn infer_items(items: Rc>>, scope: Rc) -> Rc>> { + Rc::new({ let mut __result = Vec::new(); for item in items.iter().cloned() { __result.push(infer_item(&item, &scope)); } __result }) } 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())) -} - -pub fn collect_parent_bindings_filtered( - envs: Rc>>, -) -> Rc>> { - envs.iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, env: Rc| { - Rc::new(v2_rt::map_keys(&env.bindings.clone())) - .iter() - .cloned() - .fold( - acc, - |bacc: Rc>>, ident: i64| { - let name = intern_str(env.intern_table.clone(), ident.clone()); - if is_type_variable_name(&name) { - bacc.clone() - } else { - match v2_rt::map_get(&env.bindings.clone(), ident.clone()) { - Some(binding) => v2_rt::rc_map_insert( - bacc.clone(), - ident.clone(), - binding.clone(), - ), - None => bacc.clone(), - } - } - }, - ) - }, - ) + (((((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())) +} + +pub fn collect_parent_bindings_filtered(envs: Rc>>) -> Rc>> { + envs.iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, env: Rc| Rc::new(v2_rt::map_keys(&env.bindings.clone())).iter().cloned().fold(acc, |bacc: Rc>>, ident: i64| { + let name = intern_str(env.intern_table.clone(), ident.clone()); +if is_type_variable_name(&name) { + bacc.clone() + } else { + match v2_rt::map_get(&env.bindings.clone(), ident.clone()) { + Some(binding) => v2_rt::rc_map_insert(bacc.clone(), ident.clone(), binding.clone()), + None => bacc.clone(), +} + } +})) } pub fn kernel_span(name: &String) -> Rc { Rc::new(SourceSpan { - file: v2_rt::concat( - v2_rt::concat("".to_string(), - ), - start: 0, - end: v2_rt::string_length(&name), - }) + file: v2_rt::concat(v2_rt::concat("".to_string()), + start: 0, + end: v2_rt::string_length(&name), +}) } -pub fn build_type_env( - module: &Rc, - parent_index: &Rc>>, - source_indices: &Rc>>, - intern_table: &Rc, -) -> Rc { +pub fn build_type_env(module: &Rc, parent_index: &Rc>>, source_indices: &Rc>>, intern_table: &Rc) -> Rc { { - let source_indices = Rc::new(v2_rt::map_keys(&kernel_type_set())) - .iter() - .cloned() - .fold( - source_indices.clone(), - |acc: Rc>>, name: String| { - v2_rt::rc_map_insert( - acc, - v2_rt::concat( - v2_rt::concat("".to_string(), - ), - build_newline_index( - v2_rt::concat( - v2_rt::concat("".to_string(), - ), - &name, - ), - ) - }, - ); - let source_indices = Rc::new(vec![ - "Optional".to_string(), - "Some".to_string(), - "None".to_string(), - "value".to_string(), - "none".to_string(), - ]) - .iter() - .cloned() - .fold( - source_indices.clone(), - |acc: Rc>>, name: String| { - v2_rt::rc_map_insert( - acc, - v2_rt::concat( - v2_rt::concat("".to_string(), - ), - build_newline_index( - v2_rt::concat( - v2_rt::concat("".to_string(), - ), - &name, - ), - ) - }, - ); - let intern_table = Rc::new(v2_rt::map_keys(&kernel_type_set())) - .iter() - .cloned() - .fold(intern_table.clone(), |t: Rc, name: String| { - intern(&t, &name).table.clone() - }); - let intern_table = Rc::new(vec![ - "Optional".to_string(), - "Some".to_string(), - "None".to_string(), - "value".to_string(), - "none".to_string(), - ]) - .iter() - .cloned() - .fold(intern_table.clone(), |t: Rc, name: String| { - intern(&t, &name).table.clone() - }); - let intern_table = Rc::new(v2_rt::map_keys(&compiler_recursive_types())) - .iter() - .cloned() - .fold(intern_table.clone(), |t: Rc, name: String| { - intern(&t, &name).table.clone() - }); - let kernel_bindings_base = Rc::new(v2_rt::map_keys(&kernel_type_set())) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, name: String| { - v2_rt::rc_map_insert( - acc, - intern(&intern_table, &name).id.clone(), - Rc::new(TypeBinding { - name: name.clone(), - resolved: Rc::new(Node { - name: name.clone(), - span: kernel_span(&name), - ident_span: Some(kernel_span(&name)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - }, - ); - let unit_span = kernel_span(&"Unit".to_string()); - let kernel_bindings = v2_rt::rc_map_insert( - kernel_bindings_base, - intern(&intern_table, &"Unit".to_string()).id.clone(), - Rc::new(TypeBinding { - name: "Unit".to_string(), - resolved: Rc::new(Node { - name: "Unit".to_string(), - span: unit_span.clone(), - ident_span: Some(unit_span.clone()), - children: Rc::new(vec![]), - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ); - let some_value_field = Rc::new(Node { - name: "value".to_string(), - span: kernel_span(&"value".to_string()), - ident_span: Some(kernel_span(&"value".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::TypeVariable { - id: "some_value".to_string(), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let some_variant = Rc::new(Node { - name: "Some".to_string(), - span: kernel_span(&"Some".to_string()), - ident_span: Some(kernel_span(&"Some".to_string())), - children: Rc::new(vec![some_value_field]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let kernel_optional = Rc::new(Node { - name: "Optional".to_string(), - span: kernel_span(&"Optional".to_string()), - ident_span: Some(kernel_span(&"Optional".to_string())), - children: Rc::new(vec![some_variant, none_type()]), - connective: Connective::Disj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let kernel_bindings = v2_rt::rc_map_insert( - kernel_bindings.clone(), - intern(&intern_table, &"Optional".to_string()).id.clone(), - Rc::new(TypeBinding { - name: "Optional".to_string(), - resolved: kernel_optional, - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ); - let node_fields = inductive_fields_list_to_map(compiler_inductive_fields()); - let kernel_recursive_types = Rc::new({ - let mut __result = Vec::new(); - for name in Rc::new(v2_rt::map_keys(&compiler_recursive_types())) - .iter() - .cloned() - { - __result.push(intern(&intern_table, &name).id.clone()); - } - __result - }); - let kernel_recursive_type_set = Rc::new(v2_rt::map_keys(&compiler_recursive_types())) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, intern(&intern_table, &name).id.clone(), true) - }, - ); - let kernel = Rc::new(TypeEnv { - bindings: kernel_bindings.clone(), - recursive_types: kernel_recursive_types, - recursive_type_set: kernel_recursive_type_set, - inductive_fields: node_fields, - source_indices: source_indices.clone(), - intern_table: intern_table.clone(), - }); - let imports_std_types = { - let mut __found = false; - for imp in module.resolved_imports.clone().iter().cloned() { - if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { - __found = true; - break; - } - } - __found - }; - let module_name_str = authored_name_at(source_indices.clone(), &module.module.clone()); - let std_types_parent_env = if ((module_name_str.clone().as_str() - != "std.types".to_string().as_str()) - && (imports_std_types == false)) - { + let source_indices = Rc::new(v2_rt::map_keys(&kernel_type_set())).iter().cloned().fold(source_indices.clone(), |acc: Rc>>, name: String| v2_rt::rc_map_insert(acc, v2_rt::concat(v2_rt::concat("".to_string()), build_newline_index(v2_rt::concat(v2_rt::concat("".to_string()), &name))); +let source_indices = Rc::new(vec!["Optional".to_string(), "Some".to_string(), "None".to_string(), "value".to_string(), "none".to_string()]).iter().cloned().fold(source_indices.clone(), |acc: Rc>>, name: String| v2_rt::rc_map_insert(acc, v2_rt::concat(v2_rt::concat("".to_string()), build_newline_index(v2_rt::concat(v2_rt::concat("".to_string()), &name))); +let intern_table = Rc::new(v2_rt::map_keys(&kernel_type_set())).iter().cloned().fold(intern_table.clone(), |t: Rc, name: String| intern(&t, &name).table.clone()); +let intern_table = Rc::new(vec!["Optional".to_string(), "Some".to_string(), "None".to_string(), "value".to_string(), "none".to_string()]).iter().cloned().fold(intern_table.clone(), |t: Rc, name: String| intern(&t, &name).table.clone()); +let intern_table = Rc::new(v2_rt::map_keys(&compiler_recursive_types())).iter().cloned().fold(intern_table.clone(), |t: Rc, name: String| intern(&t, &name).table.clone()); +let kernel_bindings_base = Rc::new(v2_rt::map_keys(&kernel_type_set())).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, name: String| v2_rt::rc_map_insert(acc, intern(&intern_table, &name).id.clone(), Rc::new(TypeBinding { + name: name.clone(), + resolved: Rc::new(Node { + name: name.clone(), + span: kernel_span(&name), + ident_span: Some(kernel_span(&name)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +}))); +let unit_span = kernel_span(&"Unit".to_string()); +let kernel_bindings = v2_rt::rc_map_insert(kernel_bindings_base, intern(&intern_table, &"Unit".to_string()).id.clone(), Rc::new(TypeBinding { + name: "Unit".to_string(), + resolved: Rc::new(Node { + name: "Unit".to_string(), + span: unit_span.clone(), + ident_span: Some(unit_span.clone()), + children: Rc::new(vec![]), + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})); +let some_value_field = Rc::new(Node { + name: "value".to_string(), + span: kernel_span(&"value".to_string()), + ident_span: Some(kernel_span(&"value".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::TypeVariable { + id: "some_value".to_string(), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let some_variant = Rc::new(Node { + name: "Some".to_string(), + span: kernel_span(&"Some".to_string()), + ident_span: Some(kernel_span(&"Some".to_string())), + children: Rc::new(vec![some_value_field]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let kernel_optional = Rc::new(Node { + name: "Optional".to_string(), + span: kernel_span(&"Optional".to_string()), + ident_span: Some(kernel_span(&"Optional".to_string())), + children: Rc::new(vec![some_variant, none_type()]), + connective: Connective::Disj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let kernel_bindings = v2_rt::rc_map_insert(kernel_bindings.clone(), intern(&intern_table, &"Optional".to_string()).id.clone(), Rc::new(TypeBinding { + name: "Optional".to_string(), + resolved: kernel_optional, + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})); +let node_fields = inductive_fields_list_to_map(compiler_inductive_fields()); +let kernel_recursive_types = Rc::new({ let mut __result = Vec::new(); for name in Rc::new(v2_rt::map_keys(&compiler_recursive_types())).iter().cloned() { __result.push(intern(&intern_table, &name).id.clone()); } __result }); +let kernel_recursive_type_set = Rc::new(v2_rt::map_keys(&compiler_recursive_types())).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, intern(&intern_table, &name).id.clone(), true)); +let kernel = Rc::new(TypeEnv { + bindings: kernel_bindings.clone(), + recursive_types: kernel_recursive_types, + recursive_type_set: kernel_recursive_type_set, + inductive_fields: node_fields, + source_indices: source_indices.clone(), + intern_table: intern_table.clone(), +}); +let imports_std_types = { let mut __found = false; for imp in module.resolved_imports.clone().iter().cloned() { if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { __found = true; break; } } __found }; +let module_name_str = authored_name_at(source_indices.clone(), &module.module.clone()); +let std_types_parent_env = if ((module_name_str.clone().as_str() != "std.types".to_string().as_str()) && (imports_std_types == false)) { match v2_rt::map_get(&parent_index, "std.types".to_string()) { - Some(typed_std) => Rc::new(vec![typed_std.type_env.clone()]), - None => Rc::new(vec![]), - } + Some(typed_std) => Rc::new(vec![typed_std.type_env.clone()]), + None => Rc::new(vec![]), +} } else { Rc::new(vec![]) }; - let imported_parent_envs = Rc::new({ - let mut __result = Vec::new(); - for imp in module.resolved_imports.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&parent_index, imp.module_path.clone()) { - Some(typed_parent) => Rc::new(vec![typed_parent.type_env.clone()]), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let parent_envs = v2_rt::concat(std_types_parent_env.clone(), imported_parent_envs); - let std_import_bindings = collect_parent_bindings_filtered(std_types_parent_env.clone()); - let import_bindings = module.resolved_imports.clone().iter().cloned().fold( - std_import_bindings, - |acc: Rc>>, imp: Rc| match v2_rt::map_get( - &parent_index, - imp.module_path.clone(), - ) { - Some(typed_parent) => { - if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { - Rc::new(v2_rt::map_keys( - &typed_parent.type_env.clone().bindings.clone(), - )) - .iter() - .cloned() - .fold( - acc.clone(), - |bacc: Rc>>, ident: i64| { - let name = intern_str( - typed_parent.type_env.clone().intern_table.clone(), - ident.clone(), - ); - if is_type_variable_name(&name) { - bacc.clone() - } else { - match v2_rt::map_get( - &typed_parent.type_env.clone().bindings.clone(), - ident.clone(), - ) { - Some(binding) => v2_rt::rc_map_insert( - bacc.clone(), - ident.clone(), - binding.clone(), - ), - None => bacc.clone(), - } - } - }, - ) - } else { - v2_rt::rc_map_merge( - acc.clone(), - typed_parent.type_env.clone().bindings.clone(), - ) - } +let imported_parent_envs = Rc::new({ let mut __result = Vec::new(); for imp in module.resolved_imports.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&parent_index, imp.module_path.clone()) { + Some(typed_parent) => Rc::new(vec![typed_parent.type_env.clone()]), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let parent_envs = v2_rt::concat(std_types_parent_env.clone(), imported_parent_envs); +let std_import_bindings = collect_parent_bindings_filtered(std_types_parent_env.clone()); +let import_bindings = module.resolved_imports.clone().iter().cloned().fold(std_import_bindings, |acc: Rc>>, imp: Rc| match v2_rt::map_get(&parent_index, imp.module_path.clone()) { + Some(typed_parent) => if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { + Rc::new(v2_rt::map_keys(&typed_parent.type_env.clone().bindings.clone())).iter().cloned().fold(acc.clone(), |bacc: Rc>>, ident: i64| { + let name = intern_str(typed_parent.type_env.clone().intern_table.clone(), ident.clone()); +if is_type_variable_name(&name) { + bacc.clone() + } else { + match v2_rt::map_get(&typed_parent.type_env.clone().bindings.clone(), ident.clone()) { + Some(binding) => v2_rt::rc_map_insert(bacc.clone(), ident.clone(), binding.clone()), + None => bacc.clone(), +} } - None => acc.clone(), - }, - ); - let import_recursive = parent_envs - .clone() - .iter() - .cloned() - .fold(Rc::new(vec![]), |acc: _, env: Rc| { - v2_rt::concat(acc, env.recursive_types.clone()) - }); - let import_recursive_set = parent_envs.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, env: Rc| { - v2_rt::rc_map_merge(acc, env.recursive_type_set.clone()) - }, - ); - let import_inductive_fields = parent_envs.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>>>(), - |acc: Rc>>>>, env: Rc| { - merge_inductive_fields(acc, &env.inductive_fields.clone()) - }, - ); - let import_env = Rc::new(TypeEnv { - bindings: import_bindings, - recursive_types: import_recursive, - recursive_type_set: import_recursive_set, - inductive_fields: import_inductive_fields, - source_indices: source_indices.clone(), - intern_table: intern_table.clone(), - }); - let import_diags = Rc::new({ - let mut __result = Vec::new(); - for imp in module.resolved_imports.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&parent_index, imp.module_path.clone()) { - Some(_) => Rc::new(vec![]), - None => Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "missing parent environment for imported module '" - .to_string(), - imp.module_path.clone(), - ), - "' while typechecking '".to_string(), - ), - module_name_str.clone(), - ), - "'".to_string(), - ), - span: imp.target_module.clone().clone().unwrap().span.clone(), - }), - module_name_str.clone(), - )]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let local_bindings = module_items(module.module.clone()).iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, item: Rc| { - let item_ident = intern( - &intern_table, - &authored_name_at(source_indices.clone(), &item), - ) - .id - .clone(); - let has_structure = (item.connective.clone() != Connective::NoConnective); - if has_structure.clone() { +}) + } else { + v2_rt::rc_map_merge(acc.clone(), typed_parent.type_env.clone().bindings.clone()) + }, + None => acc.clone(), +}); +let import_recursive = parent_envs.clone().iter().cloned().fold(Rc::new(vec![]), |acc: _, env: Rc| v2_rt::concat(acc, env.recursive_types.clone())); +let import_recursive_set = parent_envs.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, env: Rc| v2_rt::rc_map_merge(acc, env.recursive_type_set.clone())); +let import_inductive_fields = parent_envs.clone().iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |acc: Rc>>>>, env: Rc| merge_inductive_fields(acc, &env.inductive_fields.clone())); +let import_env = Rc::new(TypeEnv { + bindings: import_bindings, + recursive_types: import_recursive, + recursive_type_set: import_recursive_set, + inductive_fields: import_inductive_fields, + source_indices: source_indices.clone(), + intern_table: intern_table.clone(), +}); +let import_diags = Rc::new({ let mut __result = Vec::new(); for imp in module.resolved_imports.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&parent_index, imp.module_path.clone()) { + Some(_) => Rc::new(vec![]), + None => Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("missing parent environment for imported module '".to_string(), imp.module_path.clone()), "' while typechecking '".to_string()), module_name_str.clone()), "'".to_string()), + span: imp.target_module.clone().clone().unwrap().span.clone(), +}), module_name_str.clone())]), +}).iter().cloned()); } __result }); +let local_bindings = module_items(module.module.clone()).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, item: Rc| { + let item_ident = intern(&intern_table, &authored_name_at(source_indices.clone(), &item)).id.clone(); +let has_structure = (item.connective.clone() != Connective::NoConnective); +if has_structure.clone() { + { + let type_node = Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: item.children.clone(), + connective: item.connective.clone(), + params: item.params.clone(), + inferred: None, + return_cardinality: item.return_cardinality.clone(), + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), Rc::new(TypeBinding { + name: authored_name_at(source_indices.clone(), &item), + resolved: type_node.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) +} + } else { + if (((item.inferred.clone() != None) && ((item.params.clone().len() as i64) == 0)) && (item.body.clone() == None)) { { - let type_node = Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: item.children.clone(), - connective: item.connective.clone(), - params: item.params.clone(), - inferred: None, - return_cardinality: item.return_cardinality.clone(), - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - Rc::new(TypeBinding { - name: authored_name_at(source_indices.clone(), &item), - resolved: type_node.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - } + let alias_node = Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: item.inferred.clone(), + return_cardinality: item.return_cardinality.clone(), + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), Rc::new(TypeBinding { + name: authored_name_at(source_indices.clone(), &item), + resolved: alias_node.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) +} } else { - if (((item.inferred.clone() != None) - && ((item.params.clone().len() as i64) == 0)) - && (item.body.clone() == None)) - { + if ((item.transport.clone() == None) && ((item.children.clone().len() as i64) > 0)) { { - let alias_node = Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: item.inferred.clone(), - return_cardinality: item.return_cardinality.clone(), - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - Rc::new(TypeBinding { - name: authored_name_at(source_indices.clone(), &item), - resolved: alias_node.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - } + let ref_node = nominal_ref_node(&authored_name_at(source_indices.clone(), &item), item.span.clone(), item.ident_span.clone()); +v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), Rc::new(TypeBinding { + name: authored_name_at(source_indices.clone(), &item), + resolved: ref_node.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) +} } else { - if ((item.transport.clone() == None) - && ((item.children.clone().len() as i64) > 0)) - { + if (((((item.params.clone().len() as i64) > 0) && (item.connective.clone() == Connective::NoConnective)) && (item.body.clone() == None)) && (item.transport.clone() == None)) { { - let ref_node = nominal_ref_node( - &authored_name_at(source_indices.clone(), &item), - item.span.clone(), - item.ident_span.clone(), - ); - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - Rc::new(TypeBinding { - name: authored_name_at(source_indices.clone(), &item), - resolved: ref_node.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - } + let bare_node = Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: item.params.clone(), + inferred: item.inferred.clone(), + return_cardinality: item.return_cardinality.clone(), + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), Rc::new(TypeBinding { + name: authored_name_at(source_indices.clone(), &item), + resolved: bare_node.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) +} } else { - if (((((item.params.clone().len() as i64) > 0) - && (item.connective.clone() == Connective::NoConnective)) - && (item.body.clone() == None)) - && (item.transport.clone() == None)) - { - { - let bare_node = Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: item.params.clone(), - inferred: item.inferred.clone(), - return_cardinality: item.return_cardinality.clone(), - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - Rc::new(TypeBinding { - name: authored_name_at(source_indices.clone(), &item), - resolved: bare_node.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - } + if ((((((item.properties.clone().len() as i64) > 0) && (item.connective.clone() == Connective::NoConnective)) && (item.transport.clone() == None)) && (item.inferred.clone() == None)) && ((item.params.clone().len() as i64) == 0)) { + v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), nominal_type_binding(&authored_name_at(source_indices.clone(), &item))) } else { - if ((((((item.properties.clone().len() as i64) > 0) - && (item.connective.clone() == Connective::NoConnective)) - && (item.transport.clone() == None)) - && (item.inferred.clone() == None)) - && ((item.params.clone().len() as i64) == 0)) - { - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - nominal_type_binding(&authored_name_at( - source_indices.clone(), - &item, - )), - ) - } else { - acc.clone() - } + acc.clone() } } } } - }, - ); - let param_bindings = module_items(module.module.clone()).iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, item: Rc| { - let is_type_decl = match v2_rt::map_get( - &local_bindings, - intern( - &intern_table, - &authored_name_at(source_indices.clone(), &item), - ) - .id - .clone(), - ) { - Some(_) => true, - None => false, - }; - if (((item.params.clone().len() as i64) > 0) && is_type_decl.clone()) { - { - let result = item.params.clone().iter().cloned().fold( - acc.clone(), - |pacc: Rc>>, p: Rc| { - v2_rt::rc_map_insert( - pacc, - intern( - &intern_table, - &authored_name_at(source_indices.clone(), &p), - ) - .id - .clone(), - nominal_type_binding(&authored_name_at( - source_indices.clone(), - &p, - )), - ) - }, - ); - result.clone() - } - } else { - acc.clone() - } - }, - ); - let local_name_set = Rc::new(v2_rt::map_keys(&local_bindings)) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, ident: i64| { - v2_rt::rc_map_insert(acc, ident.clone(), true) - }, - ); - let all_local_bindings = v2_rt::rc_map_merge(local_bindings.clone(), param_bindings); - let pre_local_env = Rc::new(TypeEnv { - bindings: all_local_bindings, - recursive_types: Rc::new(vec![]), - recursive_type_set: v2_rt::rc_empty_map::(), - inductive_fields: v2_rt::rc_empty_map::>>>(), - source_indices: source_indices.clone(), - intern_table: intern_table.clone(), - }); - let merged = merge_envs(&Rc::new(vec![kernel, import_env, pre_local_env])); - let all_deps_map = Rc::new(v2_rt::map_values(&merged.bindings.clone())) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>>(), - |acc: Rc>>>, b: Rc| { - v2_rt::rc_map_insert( - acc, - b.name.clone(), - node_type_deps(&b.resolved.clone(), &source_indices), - ) - }, - ); - let str_bindings = Rc::new(v2_rt::map_values(&merged.bindings.clone())) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, b: Rc| { - v2_rt::rc_map_insert(acc, b.name.clone(), b.clone()) - }, - ); - let cycle_set_str = detect_type_cycles_kahn(&all_deps_map, str_bindings); - let cycle_set = Rc::new({ - let mut __result = Vec::new(); - for name in cycle_set_str.clone().iter().cloned() { - __result.push(intern(&intern_table, &name).id.clone()); } - __result - }); - let cycle_map = cycle_set_str.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let cross_type_set_str = v2_rt::rc_map_merge(cycle_map, compiler_recursive_types()); - let cross_type_set = Rc::new(v2_rt::map_keys(&cross_type_set_str)) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, intern(&intern_table, &name).id.clone(), true) - }, - ); - let local_inductive_fields = build_item_inductive_fields( - module_items(module.module.clone()), - cross_type_set_str.clone(), - source_indices.clone(), - ); - let merged_inductive_fields = - merge_inductive_fields(merged.inductive_fields.clone(), &local_inductive_fields); - let unresolved_env = Rc::new(TypeEnv { - bindings: merged.bindings.clone(), - recursive_types: cycle_set, - recursive_type_set: cross_type_set, - inductive_fields: merged_inductive_fields, - source_indices: source_indices.clone(), - intern_table: intern_table.clone(), - }); - let resolved = resolve_env_bindings( - &unresolved_env, - module_name_str.clone(), - &local_name_set, - all_deps_map.clone(), - ); - let resolved_env_out = resolved.env.clone(); - let resolved_diags = resolved.diagnostics.clone(); - let final_env = Rc::new(TypeEnv { - bindings: resolved_env_out.bindings.clone(), - recursive_types: resolved_env_out.recursive_types.clone(), - recursive_type_set: resolved_env_out.recursive_type_set.clone(), - inductive_fields: resolved_env_out.inductive_fields.clone(), - source_indices: resolved_env_out.source_indices.clone(), - intern_table: intern_table.clone(), - }); - Rc::new(BuildTypeEnvResult { - env: final_env, - diagnostics: v2_rt::concat(import_diags, resolved_diags), - }) - } +}); +let param_bindings = module_items(module.module.clone()).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, item: Rc| { + let is_type_decl = match v2_rt::map_get(&local_bindings, intern(&intern_table, &authored_name_at(source_indices.clone(), &item)).id.clone()) { + Some(_) => true, + None => false, +}; +if (((item.params.clone().len() as i64) > 0) && is_type_decl.clone()) { + { + let result = item.params.clone().iter().cloned().fold(acc.clone(), |pacc: Rc>>, p: Rc| v2_rt::rc_map_insert(pacc, intern(&intern_table, &authored_name_at(source_indices.clone(), &p)).id.clone(), nominal_type_binding(&authored_name_at(source_indices.clone(), &p)))); +result.clone() +} + } else { + acc.clone() + } +}); +let local_name_set = Rc::new(v2_rt::map_keys(&local_bindings)).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, ident: i64| v2_rt::rc_map_insert(acc, ident.clone(), true)); +let all_local_bindings = v2_rt::rc_map_merge(local_bindings.clone(), param_bindings); +let pre_local_env = Rc::new(TypeEnv { + bindings: all_local_bindings, + recursive_types: Rc::new(vec![]), + recursive_type_set: v2_rt::rc_empty_map::(), + inductive_fields: v2_rt::rc_empty_map::>>>(), + source_indices: source_indices.clone(), + intern_table: intern_table.clone(), +}); +let merged = merge_envs(&Rc::new(vec![kernel, import_env, pre_local_env])); +let all_deps_map = Rc::new(v2_rt::map_values(&merged.bindings.clone())).iter().cloned().fold(v2_rt::rc_empty_map::>>(), |acc: Rc>>>, b: Rc| v2_rt::rc_map_insert(acc, b.name.clone(), node_type_deps(&b.resolved.clone(), &source_indices))); +let str_bindings = Rc::new(v2_rt::map_values(&merged.bindings.clone())).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, b: Rc| v2_rt::rc_map_insert(acc, b.name.clone(), b.clone())); +let cycle_set_str = detect_type_cycles_kahn(&all_deps_map, str_bindings); +let cycle_set = Rc::new({ let mut __result = Vec::new(); for name in cycle_set_str.clone().iter().cloned() { __result.push(intern(&intern_table, &name).id.clone()); } __result }); +let cycle_map = cycle_set_str.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let cross_type_set_str = v2_rt::rc_map_merge(cycle_map, compiler_recursive_types()); +let cross_type_set = Rc::new(v2_rt::map_keys(&cross_type_set_str)).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, intern(&intern_table, &name).id.clone(), true)); +let local_inductive_fields = build_item_inductive_fields(module_items(module.module.clone()), cross_type_set_str.clone(), source_indices.clone()); +let merged_inductive_fields = merge_inductive_fields(merged.inductive_fields.clone(), &local_inductive_fields); +let unresolved_env = Rc::new(TypeEnv { + bindings: merged.bindings.clone(), + recursive_types: cycle_set, + recursive_type_set: cross_type_set, + inductive_fields: merged_inductive_fields, + source_indices: source_indices.clone(), + intern_table: intern_table.clone(), +}); +let resolved = resolve_env_bindings(&unresolved_env, module_name_str.clone(), &local_name_set, all_deps_map.clone()); +let resolved_env_out = resolved.env.clone(); +let resolved_diags = resolved.diagnostics.clone(); +let final_env = Rc::new(TypeEnv { + bindings: resolved_env_out.bindings.clone(), + recursive_types: resolved_env_out.recursive_types.clone(), + recursive_type_set: resolved_env_out.recursive_type_set.clone(), + inductive_fields: resolved_env_out.inductive_fields.clone(), + source_indices: resolved_env_out.source_indices.clone(), + intern_table: intern_table.clone(), +}); +Rc::new(BuildTypeEnvResult { + env: final_env, + diagnostics: v2_rt::concat(import_diags, resolved_diags), +}) +} } -pub fn build_type_env_unresolved( - module: &Rc, - parent_index: &Rc>>, - source_indices: &Rc>>, - intern_table: &Rc, -) -> Rc { +pub fn build_type_env_unresolved(module: &Rc, parent_index: &Rc>>, source_indices: &Rc>>, intern_table: &Rc) -> Rc { { - let intern_table = Rc::new(v2_rt::map_keys(&kernel_type_set())) - .iter() - .cloned() - .fold(intern_table.clone(), |t: Rc, name: String| { - intern(&t, &name).table.clone() - }); - let intern_table = Rc::new(vec!["Optional".to_string()]) - .iter() - .cloned() - .fold(intern_table.clone(), |t: Rc, name: String| { - intern(&t, &name).table.clone() - }); - let zero_span = make_span(0, 0); - let kernel_bindings = Rc::new(v2_rt::map_keys(&kernel_type_set())) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, name: String| { - v2_rt::rc_map_insert( - acc, - intern(&intern_table, &name).id.clone(), - Rc::new(TypeBinding { - name: name.clone(), - resolved: Rc::new(Node { - name: name.clone(), - span: kernel_span(&name), - ident_span: Some(kernel_span(&name)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - }, - ); - let some_value_field = Rc::new(Node { - name: "value".to_string(), - span: kernel_span(&"value".to_string()), - ident_span: Some(kernel_span(&"value".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::TypeVariable { - id: "some_value".to_string(), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let some_variant = Rc::new(Node { - name: "Some".to_string(), - span: kernel_span(&"Some".to_string()), - ident_span: Some(kernel_span(&"Some".to_string())), - children: Rc::new(vec![some_value_field]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let kernel_optional = Rc::new(Node { - name: "Optional".to_string(), - span: kernel_span(&"Optional".to_string()), - ident_span: Some(kernel_span(&"Optional".to_string())), - children: Rc::new(vec![some_variant, none_type()]), - connective: Connective::Disj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let kernel_bindings = v2_rt::rc_map_insert( - kernel_bindings.clone(), - intern(&intern_table, &"Optional".to_string()).id.clone(), - Rc::new(TypeBinding { - name: "Optional".to_string(), - resolved: kernel_optional, - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ); - let kernel = Rc::new(TypeEnv { - bindings: kernel_bindings.clone(), - recursive_types: Rc::new(vec![]), - recursive_type_set: v2_rt::rc_empty_map::(), - inductive_fields: v2_rt::rc_empty_map::>>>(), - source_indices: source_indices.clone(), - intern_table: intern_table.clone(), - }); - let imports_std_types = { - let mut __found = false; - for imp in module.resolved_imports.clone().iter().cloned() { - if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { - __found = true; - break; - } - } - __found - }; - let module_name_str = authored_name_at(source_indices.clone(), &module.module.clone()); - let std_types_parent_env = if ((module_name_str.as_str() - != "std.types".to_string().as_str()) - && (imports_std_types == false)) - { + let intern_table = Rc::new(v2_rt::map_keys(&kernel_type_set())).iter().cloned().fold(intern_table.clone(), |t: Rc, name: String| intern(&t, &name).table.clone()); +let intern_table = Rc::new(vec!["Optional".to_string()]).iter().cloned().fold(intern_table.clone(), |t: Rc, name: String| intern(&t, &name).table.clone()); +let zero_span = make_span(0, 0); +let kernel_bindings = Rc::new(v2_rt::map_keys(&kernel_type_set())).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, name: String| v2_rt::rc_map_insert(acc, intern(&intern_table, &name).id.clone(), Rc::new(TypeBinding { + name: name.clone(), + resolved: Rc::new(Node { + name: name.clone(), + span: kernel_span(&name), + ident_span: Some(kernel_span(&name)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +}))); +let some_value_field = Rc::new(Node { + name: "value".to_string(), + span: kernel_span(&"value".to_string()), + ident_span: Some(kernel_span(&"value".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::TypeVariable { + id: "some_value".to_string(), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let some_variant = Rc::new(Node { + name: "Some".to_string(), + span: kernel_span(&"Some".to_string()), + ident_span: Some(kernel_span(&"Some".to_string())), + children: Rc::new(vec![some_value_field]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let kernel_optional = Rc::new(Node { + name: "Optional".to_string(), + span: kernel_span(&"Optional".to_string()), + ident_span: Some(kernel_span(&"Optional".to_string())), + children: Rc::new(vec![some_variant, none_type()]), + connective: Connective::Disj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let kernel_bindings = v2_rt::rc_map_insert(kernel_bindings.clone(), intern(&intern_table, &"Optional".to_string()).id.clone(), Rc::new(TypeBinding { + name: "Optional".to_string(), + resolved: kernel_optional, + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})); +let kernel = Rc::new(TypeEnv { + bindings: kernel_bindings.clone(), + recursive_types: Rc::new(vec![]), + recursive_type_set: v2_rt::rc_empty_map::(), + inductive_fields: v2_rt::rc_empty_map::>>>(), + source_indices: source_indices.clone(), + intern_table: intern_table.clone(), +}); +let imports_std_types = { let mut __found = false; for imp in module.resolved_imports.clone().iter().cloned() { if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { __found = true; break; } } __found }; +let module_name_str = authored_name_at(source_indices.clone(), &module.module.clone()); +let std_types_parent_env = if ((module_name_str.as_str() != "std.types".to_string().as_str()) && (imports_std_types == false)) { match v2_rt::map_get(&parent_index, "std.types".to_string()) { - Some(typed_std) => Rc::new(vec![typed_std.type_env.clone()]), - None => Rc::new(vec![]), - } + Some(typed_std) => Rc::new(vec![typed_std.type_env.clone()]), + None => Rc::new(vec![]), +} } else { Rc::new(vec![]) }; - let imported_parent_envs = Rc::new({ - let mut __result = Vec::new(); - for imp in module.resolved_imports.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&parent_index, imp.module_path.clone()) { - Some(typed_parent) => Rc::new(vec![typed_parent.type_env.clone()]), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let parent_envs = v2_rt::concat(std_types_parent_env.clone(), imported_parent_envs); - let std_import_bindings = collect_parent_bindings_filtered(std_types_parent_env.clone()); - let import_bindings = module.resolved_imports.clone().iter().cloned().fold( - std_import_bindings, - |acc: Rc>>, imp: Rc| match v2_rt::map_get( - &parent_index, - imp.module_path.clone(), - ) { - Some(typed_parent) => { - if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { - Rc::new(v2_rt::map_keys( - &typed_parent.type_env.clone().bindings.clone(), - )) - .iter() - .cloned() - .fold( - acc.clone(), - |bacc: Rc>>, ident: i64| { - let name = intern_str( - typed_parent.type_env.clone().intern_table.clone(), - ident.clone(), - ); - if is_type_variable_name(&name) { - bacc.clone() - } else { - match v2_rt::map_get( - &typed_parent.type_env.clone().bindings.clone(), - ident.clone(), - ) { - Some(binding) => v2_rt::rc_map_insert( - bacc.clone(), - ident.clone(), - binding.clone(), - ), - None => bacc.clone(), - } - } - }, - ) - } else { - v2_rt::rc_map_merge( - acc.clone(), - typed_parent.type_env.clone().bindings.clone(), - ) - } +let imported_parent_envs = Rc::new({ let mut __result = Vec::new(); for imp in module.resolved_imports.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&parent_index, imp.module_path.clone()) { + Some(typed_parent) => Rc::new(vec![typed_parent.type_env.clone()]), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let parent_envs = v2_rt::concat(std_types_parent_env.clone(), imported_parent_envs); +let std_import_bindings = collect_parent_bindings_filtered(std_types_parent_env.clone()); +let import_bindings = module.resolved_imports.clone().iter().cloned().fold(std_import_bindings, |acc: Rc>>, imp: Rc| match v2_rt::map_get(&parent_index, imp.module_path.clone()) { + Some(typed_parent) => if (imp.module_path.clone().as_str() == "std.types".to_string().as_str()) { + Rc::new(v2_rt::map_keys(&typed_parent.type_env.clone().bindings.clone())).iter().cloned().fold(acc.clone(), |bacc: Rc>>, ident: i64| { + let name = intern_str(typed_parent.type_env.clone().intern_table.clone(), ident.clone()); +if is_type_variable_name(&name) { + bacc.clone() + } else { + match v2_rt::map_get(&typed_parent.type_env.clone().bindings.clone(), ident.clone()) { + Some(binding) => v2_rt::rc_map_insert(bacc.clone(), ident.clone(), binding.clone()), + None => bacc.clone(), +} } - None => acc.clone(), - }, - ); - let import_recursive = parent_envs - .clone() - .iter() - .cloned() - .fold(Rc::new(vec![]), |acc: _, env: Rc| { - v2_rt::concat(acc, env.recursive_types.clone()) - }); - let import_recursive_set = parent_envs.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, env: Rc| { - v2_rt::rc_map_merge(acc, env.recursive_type_set.clone()) - }, - ); - let import_inductive_fields = parent_envs.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>>>(), - |acc: Rc>>>>, env: Rc| { - merge_inductive_fields(acc, &env.inductive_fields.clone()) - }, - ); - let import_env = Rc::new(TypeEnv { - bindings: import_bindings, - recursive_types: import_recursive, - recursive_type_set: import_recursive_set, - inductive_fields: import_inductive_fields, - source_indices: source_indices.clone(), - intern_table: intern_table.clone(), - }); - let local_bindings = module_items(module.module.clone()).iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, item: Rc| { - let item_ident = intern( - &intern_table, - &authored_name_at(source_indices.clone(), &item), - ) - .id - .clone(); - let has_structure = (item.connective.clone() != Connective::NoConnective); - if has_structure.clone() { +}) + } else { + v2_rt::rc_map_merge(acc.clone(), typed_parent.type_env.clone().bindings.clone()) + }, + None => acc.clone(), +}); +let import_recursive = parent_envs.clone().iter().cloned().fold(Rc::new(vec![]), |acc: _, env: Rc| v2_rt::concat(acc, env.recursive_types.clone())); +let import_recursive_set = parent_envs.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, env: Rc| v2_rt::rc_map_merge(acc, env.recursive_type_set.clone())); +let import_inductive_fields = parent_envs.clone().iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |acc: Rc>>>>, env: Rc| merge_inductive_fields(acc, &env.inductive_fields.clone())); +let import_env = Rc::new(TypeEnv { + bindings: import_bindings, + recursive_types: import_recursive, + recursive_type_set: import_recursive_set, + inductive_fields: import_inductive_fields, + source_indices: source_indices.clone(), + intern_table: intern_table.clone(), +}); +let local_bindings = module_items(module.module.clone()).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, item: Rc| { + let item_ident = intern(&intern_table, &authored_name_at(source_indices.clone(), &item)).id.clone(); +let has_structure = (item.connective.clone() != Connective::NoConnective); +if has_structure.clone() { + { + let type_node = Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: item.children.clone(), + connective: item.connective.clone(), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: item.return_cardinality.clone(), + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), Rc::new(TypeBinding { + name: authored_name_at(source_indices.clone(), &item), + resolved: type_node.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) +} + } else { + if (((item.inferred.clone() != None) && ((item.params.clone().len() as i64) == 0)) && (item.body.clone() == None)) { { - let type_node = Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: item.children.clone(), - connective: item.connective.clone(), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: item.return_cardinality.clone(), - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - Rc::new(TypeBinding { - name: authored_name_at(source_indices.clone(), &item), - resolved: type_node.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - } + let alias_node = Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: item.inferred.clone(), + return_cardinality: item.return_cardinality.clone(), + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), Rc::new(TypeBinding { + name: authored_name_at(source_indices.clone(), &item), + resolved: alias_node.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) +} } else { - if (((item.inferred.clone() != None) - && ((item.params.clone().len() as i64) == 0)) - && (item.body.clone() == None)) - { + if ((item.transport.clone() == None) && ((item.children.clone().len() as i64) > 0)) { { - let alias_node = Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: item.inferred.clone(), - return_cardinality: item.return_cardinality.clone(), - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - Rc::new(TypeBinding { - name: authored_name_at(source_indices.clone(), &item), - resolved: alias_node.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - } + let ref_node = nominal_ref_node(&authored_name_at(source_indices.clone(), &item), item.span.clone(), item.ident_span.clone()); +v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), Rc::new(TypeBinding { + name: authored_name_at(source_indices.clone(), &item), + resolved: ref_node.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) +} } else { - if ((item.transport.clone() == None) - && ((item.children.clone().len() as i64) > 0)) - { - { - let ref_node = nominal_ref_node( - &authored_name_at(source_indices.clone(), &item), - item.span.clone(), - item.ident_span.clone(), - ); - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - Rc::new(TypeBinding { - name: authored_name_at(source_indices.clone(), &item), - resolved: ref_node.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - } + if ((((((item.properties.clone().len() as i64) > 0) && (item.connective.clone() == Connective::NoConnective)) && (item.transport.clone() == None)) && (item.inferred.clone() == None)) && ((item.params.clone().len() as i64) == 0)) { + v2_rt::rc_map_insert(acc.clone(), item_ident.clone(), nominal_type_binding(&authored_name_at(source_indices.clone(), &item))) } else { - if ((((((item.properties.clone().len() as i64) > 0) - && (item.connective.clone() == Connective::NoConnective)) - && (item.transport.clone() == None)) - && (item.inferred.clone() == None)) - && ((item.params.clone().len() as i64) == 0)) - { - v2_rt::rc_map_insert( - acc.clone(), - item_ident.clone(), - nominal_type_binding(&authored_name_at( - source_indices.clone(), - &item, - )), - ) - } else { - acc.clone() - } + acc.clone() } } } - }, - ); - let pre_local_env = Rc::new(TypeEnv { - bindings: local_bindings, - recursive_types: Rc::new(vec![]), - recursive_type_set: v2_rt::rc_empty_map::(), - inductive_fields: v2_rt::rc_empty_map::>>>(), - source_indices: source_indices.clone(), - intern_table: intern_table.clone(), - }); - let merged = merge_envs(&Rc::new(vec![kernel, import_env, pre_local_env])); - let all_deps_map = Rc::new(v2_rt::map_values(&merged.bindings.clone())) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>>(), - |acc: Rc>>>, b: Rc| { - v2_rt::rc_map_insert( - acc, - b.name.clone(), - node_type_deps(&b.resolved.clone(), &source_indices), - ) - }, - ); - let str_bindings = Rc::new(v2_rt::map_values(&merged.bindings.clone())) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, b: Rc| { - v2_rt::rc_map_insert(acc, b.name.clone(), b.clone()) - }, - ); - let cycle_set_str = detect_type_cycles_kahn(&all_deps_map, str_bindings); - let cycle_set = Rc::new({ - let mut __result = Vec::new(); - for name in cycle_set_str.clone().iter().cloned() { - __result.push(intern(&intern_table, &name).id.clone()); } - __result - }); - let cycle_map = cycle_set_str.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let cross_type_set_str = v2_rt::rc_map_merge(cycle_map, compiler_recursive_types()); - let cross_type_set = Rc::new(v2_rt::map_keys(&cross_type_set_str)) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, intern(&intern_table, &name).id.clone(), true) - }, - ); - let local_inductive_fields = build_item_inductive_fields( - module_items(module.module.clone()), - cross_type_set_str.clone(), - source_indices.clone(), - ); - let merged_inductive_fields = - merge_inductive_fields(merged.inductive_fields.clone(), &local_inductive_fields); - let unresolved_env = Rc::new(TypeEnv { - bindings: merged.bindings.clone(), - recursive_types: cycle_set, - recursive_type_set: cross_type_set, - inductive_fields: merged_inductive_fields, - source_indices: source_indices.clone(), - intern_table: intern_table.clone(), - }); - Rc::new(BuildTypeEnvResult { - env: unresolved_env, - diagnostics: Rc::new(vec![]), - }) - } +}); +let pre_local_env = Rc::new(TypeEnv { + bindings: local_bindings, + recursive_types: Rc::new(vec![]), + recursive_type_set: v2_rt::rc_empty_map::(), + inductive_fields: v2_rt::rc_empty_map::>>>(), + source_indices: source_indices.clone(), + intern_table: intern_table.clone(), +}); +let merged = merge_envs(&Rc::new(vec![kernel, import_env, pre_local_env])); +let all_deps_map = Rc::new(v2_rt::map_values(&merged.bindings.clone())).iter().cloned().fold(v2_rt::rc_empty_map::>>(), |acc: Rc>>>, b: Rc| v2_rt::rc_map_insert(acc, b.name.clone(), node_type_deps(&b.resolved.clone(), &source_indices))); +let str_bindings = Rc::new(v2_rt::map_values(&merged.bindings.clone())).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, b: Rc| v2_rt::rc_map_insert(acc, b.name.clone(), b.clone())); +let cycle_set_str = detect_type_cycles_kahn(&all_deps_map, str_bindings); +let cycle_set = Rc::new({ let mut __result = Vec::new(); for name in cycle_set_str.clone().iter().cloned() { __result.push(intern(&intern_table, &name).id.clone()); } __result }); +let cycle_map = cycle_set_str.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let cross_type_set_str = v2_rt::rc_map_merge(cycle_map, compiler_recursive_types()); +let cross_type_set = Rc::new(v2_rt::map_keys(&cross_type_set_str)).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, intern(&intern_table, &name).id.clone(), true)); +let local_inductive_fields = build_item_inductive_fields(module_items(module.module.clone()), cross_type_set_str.clone(), source_indices.clone()); +let merged_inductive_fields = merge_inductive_fields(merged.inductive_fields.clone(), &local_inductive_fields); +let unresolved_env = Rc::new(TypeEnv { + bindings: merged.bindings.clone(), + recursive_types: cycle_set, + recursive_type_set: cross_type_set, + inductive_fields: merged_inductive_fields, + source_indices: source_indices.clone(), + intern_table: intern_table.clone(), +}); +Rc::new(BuildTypeEnvResult { + env: unresolved_env, + diagnostics: Rc::new(vec![]), +}) +} } -pub fn build_item_info( - item: &Rc, - source_indices: &Rc>>, - module_name: String, -) -> Rc { +pub fn build_item_info(item: &Rc, source_indices: &Rc>>, module_name: String) -> Rc { { let kind = item_kind(&item); - let res_names = Rc::new({ - let mut __result = Vec::new(); - for u in item.uses.clone().iter().cloned() { - __result.push(resource_use_name_at(u.clone(), source_indices.clone())); - } - __result - }); - let item_name_str = authored_name_at(source_indices.clone(), &item); - match kind.clone() { - ItemKind::FuncItem => Rc::new(ItemInfo { - name: item_name_str.clone(), - module_name: module_name, - kind: kind.clone(), - service_names: if (item.body.clone() == None) { - Rc::new(vec![]) - } else { - collect_typed_service_calls( - item.body.clone().clone().unwrap(), - source_indices.clone(), - ) - }, - resource_names: res_names, - params: item.params.clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - }), - ItemKind::FnItem => Rc::new(ItemInfo { - name: item_name_str.clone(), - module_name: module_name, - kind: kind.clone(), - service_names: if (item.body.clone() == None) { - Rc::new(vec![]) - } else { - collect_typed_service_calls( - item.body.clone().clone().unwrap(), - source_indices.clone(), - ) - }, - resource_names: res_names, - params: item.params.clone(), - is_self_recursive: if (item.body.clone() == None) { - false - } else { - expr_has_self_call( - &item.body.clone().clone().unwrap(), - &item_name_str, - &source_indices, - ) - }, - has_non_tail_self_call: if (item.body.clone() == None) { - false - } else { - expr_has_non_tail_self_call( - &item.body.clone().clone().unwrap(), - &item_name_str, - true, - &source_indices, - ) - }, - }), - _ => Rc::new(ItemInfo { - name: item_name_str.clone(), - module_name: module_name, - kind: kind.clone(), - service_names: Rc::new(vec![]), - resource_names: res_names, - params: item.params.clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - }), - } - } +let res_names = Rc::new({ let mut __result = Vec::new(); for u in item.uses.clone().iter().cloned() { __result.push(resource_use_name_at(u.clone(), source_indices.clone())); } __result }); +let item_name_str = authored_name_at(source_indices.clone(), &item); +match kind.clone() { + ItemKind::FuncItem => Rc::new(ItemInfo { + name: item_name_str.clone(), + module_name: module_name, + kind: kind.clone(), + service_names: if (item.body.clone() == None) { + Rc::new(vec![]) + } else { + collect_typed_service_calls(item.body.clone().clone().unwrap(), source_indices.clone()) + }, + resource_names: res_names, + params: item.params.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, +}), + ItemKind::FnItem => Rc::new(ItemInfo { + name: item_name_str.clone(), + module_name: module_name, + kind: kind.clone(), + service_names: if (item.body.clone() == None) { + Rc::new(vec![]) + } else { + collect_typed_service_calls(item.body.clone().clone().unwrap(), source_indices.clone()) + }, + resource_names: res_names, + params: item.params.clone(), + is_self_recursive: if (item.body.clone() == None) { + false + } else { + expr_has_self_call(&item.body.clone().clone().unwrap(), &item_name_str, &source_indices) + }, + has_non_tail_self_call: if (item.body.clone() == None) { + false + } else { + expr_has_non_tail_self_call(&item.body.clone().clone().unwrap(), &item_name_str, true, &source_indices) + }, +}), + _ => Rc::new(ItemInfo { + name: item_name_str.clone(), + module_name: module_name, + kind: kind.clone(), + service_names: Rc::new(vec![]), + resource_names: res_names, + params: item.params.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, +}), +} +} } -pub fn analyze_item( - item: Rc, - env: &Rc, - module_name: &String, -) -> Rc { +pub fn analyze_item(item: Rc, env: &Rc, module_name: &String) -> Rc { { let resolved = resolve_item_types(&item, &env, &module_name); - let ritem = resolved.item.clone(); - let is_func = ((ritem.params.clone().len() as i64) > 0); - let is_zero_arg_func = ((((ritem.params.clone().len() as i64) == 0) - && (ritem.inferred.clone() != None)) - && (ritem.body.clone() != None)); - let func_sig = if (is_func || is_zero_arg_func) { +let ritem = resolved.item.clone(); +let is_func = ((ritem.params.clone().len() as i64) > 0); +let is_zero_arg_func = ((((ritem.params.clone().len() as i64) == 0) && (ritem.inferred.clone() != None)) && (ritem.body.clone() != None)); +let func_sig = if (is_func || is_zero_arg_func) { { let declared_rt = if (ritem.inferred.clone() != None) { Some(resolved_type(ritem.clone())) } else { None }; - Some(Rc::new(DeclaredFuncSig { - name: authored_name_at(env.source_indices.clone(), &ritem), - params: ritem.params.clone(), - inferred: declared_rt, - is_async: ((ritem.uses.clone().len() as i64) > 0), - output_provenance: Rc::new(vec![]), - variant_provenance: v2_rt::rc_empty_map::< - String, - Rc>>>>, - >(), - })) - } +Some(Rc::new(DeclaredFuncSig { + name: authored_name_at(env.source_indices.clone(), &ritem), + params: ritem.params.clone(), + inferred: declared_rt, + is_async: ((ritem.uses.clone().len() as i64) > 0), + output_provenance: Rc::new(vec![]), + variant_provenance: v2_rt::rc_empty_map::>>>>>(), +})) +} } else { None }; - let svc_entries = - if ((ritem.transport.clone() != None) && ((ritem.children.clone().len() as i64) > 0)) { - Rc::new({ - let mut __result = Vec::new(); - for c in ritem.children.clone().iter().cloned() { - __result.push(service_op_entry(&c, &env.source_indices.clone())); - } - __result - }) - } else { - Rc::new(vec![]) - }; - let svc_local = - if ((ritem.transport.clone() != None) && ((ritem.children.clone().len() as i64) > 0)) { - { - let root = namespace_root_from_properties( - ritem.properties.clone(), - authored_name_at(env.source_indices.clone(), &ritem), - env.source_indices.clone(), - ); - Some(nominal_type_binding(&root)) - } - } else { - None - }; - Rc::new(ItemContribution { - resolved_item: ritem.clone(), - resolve_diagnostics: resolved.diagnostics.clone(), - func_sig: func_sig, - svc_entries: svc_entries, - svc_local: svc_local, - item_info: build_item_info(&ritem, &env.source_indices.clone(), module_name.clone()), - }) - } +let svc_entries = if ((ritem.transport.clone() != None) && ((ritem.children.clone().len() as i64) > 0)) { + Rc::new({ let mut __result = Vec::new(); for c in ritem.children.clone().iter().cloned() { __result.push(service_op_entry(&c, &env.source_indices.clone())); } __result }) + } else { + Rc::new(vec![]) + }; +let svc_local = if ((ritem.transport.clone() != None) && ((ritem.children.clone().len() as i64) > 0)) { + { + let root = namespace_root_from_properties(ritem.properties.clone(), authored_name_at(env.source_indices.clone(), &ritem), env.source_indices.clone()); +Some(nominal_type_binding(&root)) +} + } else { + None + }; +Rc::new(ItemContribution { + resolved_item: ritem.clone(), + resolve_diagnostics: resolved.diagnostics.clone(), + func_sig: func_sig, + svc_entries: svc_entries, + svc_local: svc_local, + item_info: build_item_info(&ritem, &env.source_indices.clone(), module_name.clone()), +}) +} } -pub fn fold_module_contributions( - mut remaining: Rc>>, - mut resolved_items: Rc>>, - mut func_sigs: Rc>>, - mut svc_registry: Rc>>>>, - mut svc_locals: Rc>>, - mut item_registry: Rc>>, - mut diag_chunks: Rc>>>>, - mut source_indices: Rc>>, -) -> Rc { +pub fn fold_module_contributions(mut remaining: Rc>>, mut resolved_items: Rc>>, mut func_sigs: Rc>>, mut svc_registry: Rc>>>>, mut svc_locals: Rc>>, mut item_registry: Rc>>, mut diag_chunks: Rc>>>>, mut source_indices: Rc>>) -> Rc { loop { match remaining.clone().first().cloned() { - None => { - break Rc::new(LocalContributionState { - resolved_items: resolved_items, - func_sigs: func_sigs, - svc_registry: svc_registry, - svc_locals: svc_locals, - item_registry: item_registry, - diag_chunks: diag_chunks, - }); - } - Some(contribution) => { - let next_func_sigs = match contribution.func_sig.clone() { - Some(sig) => v2_rt::rc_map_insert(func_sigs, sig.name.clone(), sig.clone()), - None => func_sigs, - }; - let next_svc_registry = if ((contribution.svc_entries.clone().len() as i64) > 0) { - v2_rt::rc_map_insert( - svc_registry, - authored_name_at( - source_indices.clone(), - &contribution.resolved_item.clone(), - ), - contribution.svc_entries.clone(), - ) - } else { - svc_registry - }; - let next_svc_locals = match contribution.svc_local.clone() { - Some(binding) => { - v2_rt::rc_map_insert(svc_locals, binding.name.clone(), binding.clone()) - } - None => svc_locals, - }; - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = - v2_rt::rc_list_push(resolved_items, contribution.resolved_item.clone()); - let __tco_2 = next_func_sigs; - let __tco_3 = next_svc_registry; - let __tco_4 = next_svc_locals; - let __tco_5 = v2_rt::rc_map_insert( - item_registry, - contribution.item_info.clone().name.clone(), - contribution.item_info.clone(), - ); - let __tco_6 = - v2_rt::rc_list_push(diag_chunks, contribution.resolve_diagnostics.clone()); - remaining = __tco_0; - resolved_items = __tco_1; - func_sigs = __tco_2; - svc_registry = __tco_3; - svc_locals = __tco_4; - item_registry = __tco_5; - diag_chunks = __tco_6; - continue; - } - } - } - } -} - -pub fn build_module_context( - contributions: Rc>>, - parent_index: Rc>>, - resolved_imports: &Rc>>, - env: &Rc, - module_name: &String, -) -> Rc { + None => { break Rc::new(LocalContributionState { + resolved_items: resolved_items, + func_sigs: func_sigs, + svc_registry: svc_registry, + svc_locals: svc_locals, + item_registry: item_registry, + diag_chunks: diag_chunks, +}); }, + Some(contribution) => { let next_func_sigs = match contribution.func_sig.clone() { + Some(sig) => v2_rt::rc_map_insert(func_sigs, sig.name.clone(), sig.clone()), + None => func_sigs, +}; +let next_svc_registry = if ((contribution.svc_entries.clone().len() as i64) > 0) { + v2_rt::rc_map_insert(svc_registry, authored_name_at(source_indices.clone(), &contribution.resolved_item.clone()), contribution.svc_entries.clone()) + } else { + svc_registry + }; +let next_svc_locals = match contribution.svc_local.clone() { + Some(binding) => v2_rt::rc_map_insert(svc_locals, binding.name.clone(), binding.clone()), + None => svc_locals, +}; +{ + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(resolved_items, contribution.resolved_item.clone()); +let __tco_2 = next_func_sigs; +let __tco_3 = next_svc_registry; +let __tco_4 = next_svc_locals; +let __tco_5 = v2_rt::rc_map_insert(item_registry, contribution.item_info.clone().name.clone(), contribution.item_info.clone()); +let __tco_6 = v2_rt::rc_list_push(diag_chunks, contribution.resolve_diagnostics.clone()); +remaining = __tco_0; +resolved_items = __tco_1; +func_sigs = __tco_2; +svc_registry = __tco_3; +svc_locals = __tco_4; +item_registry = __tco_5; +diag_chunks = __tco_6; +continue; +} }, +} +} +} + +pub fn build_module_context(contributions: Rc>>, parent_index: Rc>>, resolved_imports: &Rc>>, env: &Rc, module_name: &String) -> Rc { { - let local = fold_module_contributions( - contributions, - Rc::new(vec![]), - v2_rt::rc_empty_map::>(), - v2_rt::rc_empty_map::>>>(), - v2_rt::rc_empty_map::>(), - v2_rt::rc_empty_map::>(), - Rc::new(vec![]), - env.source_indices.clone(), - ); - let imported_enum_names = resolved_imports.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, imp: Rc| { - imp.specific_names.clone().iter().cloned().fold( - acc, - |inner: Rc>, n: String| { - v2_rt::rc_map_insert(inner, n.clone(), true) - }, - ) - }, - ); - let variant_fold = Rc::new(v2_rt::map_values(&env.bindings.clone())).iter().cloned().fold(Rc::new(VariantFoldState { + let local = fold_module_contributions(contributions, Rc::new(vec![]), v2_rt::rc_empty_map::>(), v2_rt::rc_empty_map::>>>(), v2_rt::rc_empty_map::>(), v2_rt::rc_empty_map::>(), Rc::new(vec![]), env.source_indices.clone()); +let imported_enum_names = resolved_imports.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, imp: Rc| imp.specific_names.clone().iter().cloned().fold(acc, |inner: Rc>, n: String| v2_rt::rc_map_insert(inner, n.clone(), true))); +let variant_fold = Rc::new(v2_rt::map_values(&env.bindings.clone())).iter().cloned().fold(Rc::new(VariantFoldState { locals: v2_rt::rc_empty_map::>(), collision_errors: Rc::new(vec![]), }), |acc: Rc, binding: Rc| { @@ -10964,59 +6290,22 @@ if (curr_is_imported.clone() && prev_is_imported.clone()) { acc.clone() } }); - let imported_variant_locals = variant_fold.locals.clone(); - let variant_collision_errors = variant_fold.collision_errors.clone(); - let env_variant_locals = variant_locals_from_items( - local.resolved_items.clone(), - imported_variant_locals, - env.source_indices.clone(), - ); - let merged_scope = merge_scope_from_imports( - resolved_imports.clone(), - parent_index, - env.clone(), - v2_rt::rc_empty_map::>(), - local.svc_registry.clone(), - local.svc_locals.clone(), - ); - let all_declared_sigs = - v2_rt::rc_map_merge(merged_scope.func_sigs.clone(), local.func_sigs.clone()); - let resolve_result = resolve_func_sigs( - &all_declared_sigs, - &local.resolved_items.clone(), - module_name.clone(), - &env.source_indices.clone(), - ); - let all_locals = Rc::new(v2_rt::map_values(&merged_scope.svc_locals.clone())) - .iter() - .cloned() - .fold( - env_variant_locals, - |acc: Rc>>, binding: Rc| { - v2_rt::rc_map_insert(acc, binding.name.clone(), binding.clone()) - }, - ); - Rc::new(ModuleContext { - resolved_items: local.resolved_items.clone(), - func_env: resolve_result.func_env.clone(), - svc_registry: merged_scope.svc_registry.clone(), - locals: all_locals, - item_registry: local.item_registry.clone(), - diagnostics: v2_rt::concat( - v2_rt::concat( - Rc::new({ - let mut __result = Vec::new(); - for c in local.diag_chunks.clone().iter().cloned() { - __result.extend((*c.clone()).iter().cloned()); - } - __result - }), - resolve_result.diagnostics.clone(), - ), - variant_collision_errors, - ), - }) - } +let imported_variant_locals = variant_fold.locals.clone(); +let variant_collision_errors = variant_fold.collision_errors.clone(); +let env_variant_locals = variant_locals_from_items(local.resolved_items.clone(), imported_variant_locals, env.source_indices.clone()); +let merged_scope = merge_scope_from_imports(resolved_imports.clone(), parent_index, env.clone(), v2_rt::rc_empty_map::>(), local.svc_registry.clone(), local.svc_locals.clone()); +let all_declared_sigs = v2_rt::rc_map_merge(merged_scope.func_sigs.clone(), local.func_sigs.clone()); +let resolve_result = resolve_func_sigs(&all_declared_sigs, &local.resolved_items.clone(), module_name.clone(), &env.source_indices.clone()); +let all_locals = Rc::new(v2_rt::map_values(&merged_scope.svc_locals.clone())).iter().cloned().fold(env_variant_locals, |acc: Rc>>, binding: Rc| v2_rt::rc_map_insert(acc, binding.name.clone(), binding.clone())); +Rc::new(ModuleContext { + resolved_items: local.resolved_items.clone(), + func_env: resolve_result.func_env.clone(), + svc_registry: merged_scope.svc_registry.clone(), + locals: all_locals, + item_registry: local.item_registry.clone(), + diagnostics: v2_rt::concat(v2_rt::concat(Rc::new({ let mut __result = Vec::new(); for c in local.diag_chunks.clone().iter().cloned() { __result.extend((*c.clone()).iter().cloned()); } __result }), resolve_result.diagnostics.clone()), variant_collision_errors), +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -11025,174 +6314,90 @@ pub struct TypecheckModuleResult { pub diagnostics: Rc>>, } -pub fn typecheck_module( - resolved: &Rc, - parent_index: &Rc>>, - source_indices: &Rc>>, - intern_table: Rc, -) -> Rc { +pub fn typecheck_module(resolved: &Rc, parent_index: &Rc>>, source_indices: &Rc>>, intern_table: Rc) -> Rc { { let env_result = build_type_env(&resolved, &parent_index, &source_indices, &intern_table); - let env = env_result.env.clone(); - let env_diags = env_result.diagnostics.clone(); - let env_errors = Rc::new({ - let mut __result = Vec::new(); - for d in env_diags.clone().iter().cloned() { - if is_error_diagnostic(d.diagnostic.clone()) { - __result.push(d); - } - } - __result - }); - let seed_diags = builtin_kernel_seed_diagnostics(); - if ((env_errors.len() as i64) > 0) { +let env = env_result.env.clone(); +let env_diags = env_result.diagnostics.clone(); +let env_errors = Rc::new({ let mut __result = Vec::new(); for d in env_diags.clone().iter().cloned() { if is_error_diagnostic(d.diagnostic.clone()) { __result.push(d); } } __result }); +let seed_diags = builtin_kernel_seed_diagnostics(); +if ((env_errors.len() as i64) > 0) { return Rc::new(TypecheckModuleResult { - typed: Rc::new(TypedModule { - module: resolved.module.clone(), - items: Rc::new(vec![]), - type_env: env.clone(), - func_env: Rc::new(ResolvedFuncEnv { - signatures: v2_rt::rc_empty_map::>(), - }), - item_registry: v2_rt::rc_empty_map::>(), - }), - diagnostics: v2_rt::concat(env_diags.clone(), seed_diags.clone()), - }); + typed: Rc::new(TypedModule { + module: resolved.module.clone(), + items: Rc::new(vec![]), + type_env: env.clone(), + func_env: Rc::new(ResolvedFuncEnv { + signatures: v2_rt::rc_empty_map::>(), +}), + item_registry: v2_rt::rc_empty_map::>(), +}), + diagnostics: v2_rt::concat(env_diags.clone(), seed_diags.clone()), +}) } - let resolved_module_name = - authored_name_at(source_indices.clone(), &resolved.module.clone()); - let contributions = Rc::new({ - let mut __result = Vec::new(); - for item in module_items(resolved.module.clone()).iter().cloned() { - __result.push(analyze_item(item.clone(), &env, &resolved_module_name)); - } - __result - }); - let ctx = build_module_context( - contributions, - parent_index.clone(), - &resolved.resolved_imports.clone(), - &env, - &resolved_module_name, - ); - let data_locals = ctx.resolved_items.clone().iter().cloned().fold( - ctx.locals.clone(), - |acc: Rc>>, item: Rc| { - if ((((item.body.clone() != None) && ((item.params.clone().len() as i64) == 0)) - && (item.inferred.clone() == None)) - && (item.type_annotation.clone() != None)) - { - v2_rt::rc_map_insert( - acc.clone(), - authored_name_at(source_indices.clone(), &item), - Rc::new(TypeBinding { - name: authored_name_at(source_indices.clone(), &item), - resolved: item.type_annotation.clone().clone().unwrap(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - } else { - acc.clone() - } - }, - ); - let infer_scope = Rc::new(InferScope { - type_env: env.clone(), - func_env: ctx.func_env.clone(), - locals: data_locals.clone(), - match_bound_names: v2_rt::rc_empty_map::(), - module_name: resolved_module_name.clone(), - service_registry: ctx.svc_registry.clone(), - item_registry: ctx.item_registry.clone(), - lambda_param_provenance: v2_rt::rc_empty_map::>(), - }); - let typed_item_results = infer_items(ctx.resolved_items.clone(), infer_scope); - let typed_items = Rc::new({ - let mut __result = Vec::new(); - for tir in typed_item_results.clone().iter().cloned() { - __result.push(tir.item.clone()); - } - __result - }); - let infer_diags = Rc::new({ - let mut __result = Vec::new(); - for tir in typed_item_results.clone().iter().cloned() { - __result.extend((*tir.diagnostics.clone()).iter().cloned()); - } - __result - }); - let updated_func_env = populate_output_provenance( - typed_items.clone(), - ctx.func_env.clone(), - env.clone(), - data_locals.clone(), - ); - let reannotated_items = Rc::new({ - let mut __result = Vec::new(); - for item in typed_items.clone().iter().cloned() { - __result.push( - if (item.is_self_recursive.clone() && (item.body.clone() != None)) { - Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: item.children.clone(), - params: item.params.clone(), - inferred: item.inferred.clone(), - return_cardinality: item.return_cardinality.clone(), - uses: item.uses.clone(), - body: Some(annotate_descent_evidence( - item.body.clone().clone().unwrap(), - authored_name_at(source_indices.clone(), &item), - &item.params.clone(), - &env, - data_locals.clone(), - updated_func_env.signatures.clone(), - )), - connective: item.connective.clone(), - transport: item.transport.clone(), - properties: item.properties.clone(), - type_annotation: item.type_annotation.clone(), - is_self_recursive: item.is_self_recursive.clone(), - has_non_tail_self_call: item.has_non_tail_self_call.clone(), - match_pattern: item.match_pattern.clone(), - expr_data: item.expr_data.clone(), - ident: None, - }) - } else { - item.clone() - }, - ); - } - __result - }); - let typed_base = module_node( - &resolved_module_name, - module_imports(resolved.module.clone()), - ctx.resolved_items.clone(), - &resolved.module.clone().span.clone(), - ); - let typed_module = Rc::new(Node { - ident_span: resolved.module.clone().ident_span.clone(), - ..(*typed_base).clone() +let resolved_module_name = authored_name_at(source_indices.clone(), &resolved.module.clone()); +let contributions = Rc::new({ let mut __result = Vec::new(); for item in module_items(resolved.module.clone()).iter().cloned() { __result.push(analyze_item(item.clone(), &env, &resolved_module_name)); } __result }); +let ctx = build_module_context(contributions, parent_index.clone(), &resolved.resolved_imports.clone(), &env, &resolved_module_name); +let data_locals = ctx.resolved_items.clone().iter().cloned().fold(ctx.locals.clone(), |acc: Rc>>, item: Rc| if ((((item.body.clone() != None) && ((item.params.clone().len() as i64) == 0)) && (item.inferred.clone() == None)) && (item.type_annotation.clone() != None)) { + v2_rt::rc_map_insert(acc.clone(), authored_name_at(source_indices.clone(), &item), Rc::new(TypeBinding { + name: authored_name_at(source_indices.clone(), &item), + resolved: item.type_annotation.clone().clone().unwrap(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) + } else { + acc.clone() }); - Rc::new(TypecheckModuleResult { - typed: Rc::new(TypedModule { - module: typed_module, - items: reannotated_items, - type_env: env.clone(), - func_env: updated_func_env.clone(), - item_registry: ctx.item_registry.clone(), - }), - diagnostics: v2_rt::concat( - v2_rt::concat( - v2_rt::concat(env_diags.clone(), ctx.diagnostics.clone()), - infer_diags, - ), - seed_diags.clone(), - ), - }) - } +let infer_scope = Rc::new(InferScope { + type_env: env.clone(), + func_env: ctx.func_env.clone(), + locals: data_locals.clone(), + match_bound_names: v2_rt::rc_empty_map::(), + module_name: resolved_module_name.clone(), + service_registry: ctx.svc_registry.clone(), + item_registry: ctx.item_registry.clone(), + lambda_param_provenance: v2_rt::rc_empty_map::>(), +}); +let typed_item_results = infer_items(ctx.resolved_items.clone(), infer_scope); +let typed_items = Rc::new({ let mut __result = Vec::new(); for tir in typed_item_results.clone().iter().cloned() { __result.push(tir.item.clone()); } __result }); +let infer_diags = Rc::new({ let mut __result = Vec::new(); for tir in typed_item_results.clone().iter().cloned() { __result.extend((*tir.diagnostics.clone()).iter().cloned()); } __result }); +let updated_func_env = populate_output_provenance(typed_items.clone(), ctx.func_env.clone(), env.clone(), data_locals.clone()); +let reannotated_items = Rc::new({ let mut __result = Vec::new(); for item in typed_items.clone().iter().cloned() { __result.push(if (item.is_self_recursive.clone() && (item.body.clone() != None)) { + Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: item.children.clone(), + params: item.params.clone(), + inferred: item.inferred.clone(), + return_cardinality: item.return_cardinality.clone(), + uses: item.uses.clone(), + body: Some(annotate_descent_evidence(item.body.clone().clone().unwrap(), authored_name_at(source_indices.clone(), &item), &item.params.clone(), &env, data_locals.clone(), updated_func_env.signatures.clone())), + connective: item.connective.clone(), + transport: item.transport.clone(), + properties: item.properties.clone(), + type_annotation: item.type_annotation.clone(), + is_self_recursive: item.is_self_recursive.clone(), + has_non_tail_self_call: item.has_non_tail_self_call.clone(), + match_pattern: item.match_pattern.clone(), + expr_data: item.expr_data.clone(), + ident: None, +}) + } else { + item.clone() + }); } __result }); +let typed_base = module_node(&resolved_module_name, module_imports(resolved.module.clone()), ctx.resolved_items.clone(), &resolved.module.clone().span.clone()); +let typed_module = Rc::new(Node { ident_span: resolved.module.clone().ident_span.clone(), ..(*typed_base).clone() }); +Rc::new(TypecheckModuleResult { + typed: Rc::new(TypedModule { + module: typed_module, + items: reannotated_items, + type_env: env.clone(), + func_env: updated_func_env.clone(), + item_registry: ctx.item_registry.clone(), +}), + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(env_diags.clone(), ctx.diagnostics.clone()), infer_diags), seed_diags.clone()), +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -11213,494 +6418,227 @@ pub struct BindingsAccum { pub diagnostics: Rc>>, } -pub fn resolve_env_bindings( - env: &Rc, - module_name: String, - local_names: &Rc>, - deps_map: Rc>>>, -) -> Rc { +pub fn resolve_env_bindings(env: &Rc, module_name: String, local_names: &Rc>, deps_map: Rc>>>) -> Rc { { - let remaining = Rc::new({ - let mut __result = Vec::new(); - for b in Rc::new({ - let mut __result = Vec::new(); - for b in Rc::new(v2_rt::map_values(&env.bindings.clone())) - .iter() - .cloned() - { - if v2_rt::map_contains_key( - &local_names, - intern(&env.intern_table.clone(), &b.name.clone()) - .id - .clone(), - ) { - __result.push(b); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(b.name.clone()); - } - __result - }); - topo_resolve_types( - remaining.clone(), - env.clone(), - module_name, - Rc::new(vec![]), - local_names.clone(), - deps_map, - (remaining.clone().len() as i64), - ) - } + let remaining = Rc::new({ let mut __result = Vec::new(); for b in Rc::new({ let mut __result = Vec::new(); for b in Rc::new(v2_rt::map_values(&env.bindings.clone())).iter().cloned() { if v2_rt::map_contains_key(&local_names, intern(&env.intern_table.clone(), &b.name.clone()).id.clone()) { __result.push(b); } } __result }).iter().cloned() { __result.push(b.name.clone()); } __result }); +topo_resolve_types(remaining.clone(), env.clone(), module_name, Rc::new(vec![]), local_names.clone(), deps_map, (remaining.clone().len() as i64)) +} } -pub fn topo_resolve_types( - mut remaining: Rc>, - mut env: Rc, - mut module_name: String, - mut diagnostics: Rc>>, - mut local_names: Rc>, - mut deps_map: Rc>>>, - mut fuel: i64, -) -> Rc { +pub fn topo_resolve_types(mut remaining: Rc>, mut env: Rc, mut module_name: String, mut diagnostics: Rc>>, mut local_names: Rc>, mut deps_map: Rc>>>, mut fuel: i64) -> Rc { loop { if ((remaining.clone().len() as i64) == 0) { return Rc::new(EnvResolveResult { - env: env.clone(), - diagnostics: diagnostics.clone(), - }); + env: env.clone(), + diagnostics: diagnostics.clone(), +}) } - let remaining_set = remaining.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let ready = Rc::new({ - let mut __result = Vec::new(); - for name in remaining.clone().iter().cloned() { - if match v2_rt::map_get(&deps_map, name.clone()) { - Some(deps) => { - 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())) - || is_recursive_type_by_name(&env, dep.clone())) - || (emit_map_has(remaining_set.clone(), dep.clone()) == false)) - { - __all = false; - break; - } - } - __all - } - None => true, - } { - __result.push(name); - } - } - __result - }); - if ((ready.clone().len() as i64) == 0) { +let remaining_set = remaining.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let ready = Rc::new({ let mut __result = Vec::new(); for name in remaining.clone().iter().cloned() { if match v2_rt::map_get(&deps_map, name.clone()) { + Some(deps) => { 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())) || is_recursive_type_by_name(&env, dep.clone())) || (emit_map_has(remaining_set.clone(), dep.clone()) == false))) { __all = false; break; } } __all }, + None => true, +} { __result.push(name); } } __result }); +if ((ready.clone().len() as i64) == 0) { { - let stuck_accum = remaining.clone().iter().cloned().fold( - Rc::new(BindingsAccum { - bindings: env.bindings.clone(), - diagnostics: Rc::new(vec![]), - }), - |acc: Rc, name: String| { - let ident = intern(&env.intern_table.clone(), &name).id.clone(); - match v2_rt::map_get(&env.bindings.clone(), ident.clone()) { - Some(binding) => { - let result = resolve_node( - binding.resolved.clone(), - env.clone(), - module_name.clone(), - ); - Rc::new(BindingsAccum { - bindings: v2_rt::rc_map_insert( - acc.bindings.clone(), - ident.clone(), - Rc::new(TypeBinding { - name: name.clone(), - resolved: result.resolved.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ), - diagnostics: v2_rt::concat( - acc.diagnostics.clone(), - result.diagnostics.clone(), - ), - }) - } - None => acc.clone(), - } - }, - ); - return Rc::new(EnvResolveResult { - env: Rc::new(TypeEnv { - bindings: stuck_accum.bindings.clone(), - recursive_types: env.recursive_types.clone(), - recursive_type_set: env.recursive_type_set.clone(), - inductive_fields: env.inductive_fields.clone(), - source_indices: env.source_indices.clone(), - intern_table: env.intern_table.clone(), - }), - diagnostics: v2_rt::concat( - diagnostics.clone(), - stuck_accum.diagnostics.clone(), - ), - }); - } + let stuck_accum = remaining.clone().iter().cloned().fold(Rc::new(BindingsAccum { + bindings: env.bindings.clone(), + diagnostics: Rc::new(vec![]), +}), |acc: Rc, name: String| { + let ident = intern(&env.intern_table.clone(), &name).id.clone(); +match v2_rt::map_get(&env.bindings.clone(), ident.clone()) { + Some(binding) => { + let result = resolve_node(binding.resolved.clone(), env.clone(), module_name.clone()); +Rc::new(BindingsAccum { + bindings: v2_rt::rc_map_insert(acc.bindings.clone(), ident.clone(), Rc::new(TypeBinding { + name: name.clone(), + resolved: result.resolved.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})), + diagnostics: v2_rt::concat(acc.diagnostics.clone(), result.diagnostics.clone()), +}) +}, + None => acc.clone(), +} +}); +return Rc::new(EnvResolveResult { + env: Rc::new(TypeEnv { + bindings: stuck_accum.bindings.clone(), + recursive_types: env.recursive_types.clone(), + recursive_type_set: env.recursive_type_set.clone(), + inductive_fields: env.inductive_fields.clone(), + source_indices: env.source_indices.clone(), + intern_table: env.intern_table.clone(), +}), + diagnostics: v2_rt::concat(diagnostics.clone(), stuck_accum.diagnostics.clone()), +}) +} } - let ready_accum = ready.clone().iter().cloned().fold( - Rc::new(BindingsAccum { - bindings: env.bindings.clone(), - diagnostics: Rc::new(vec![]), - }), - |acc: Rc, name: String| { - let ident = intern(&env.intern_table.clone(), &name).id.clone(); - match v2_rt::map_get(&env.bindings.clone(), ident.clone()) { - Some(binding) => { - let result = resolve_node( - binding.resolved.clone(), - env.clone(), - module_name.clone(), - ); - Rc::new(BindingsAccum { - bindings: v2_rt::rc_map_insert( - acc.bindings.clone(), - ident.clone(), - Rc::new(TypeBinding { - name: name.clone(), - resolved: result.resolved.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ), - diagnostics: v2_rt::concat( - acc.diagnostics.clone(), - result.diagnostics.clone(), - ), - }) - } - None => acc.clone(), - } - }, - ); - let ready_set = ready.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let next_remaining = Rc::new({ - let mut __result = Vec::new(); - for name in remaining.clone().iter().cloned() { - if (emit_map_has(ready_set.clone(), name.clone()) == false) { - __result.push(name); - } - } - __result - }); - { +let ready_accum = ready.clone().iter().cloned().fold(Rc::new(BindingsAccum { + bindings: env.bindings.clone(), + diagnostics: Rc::new(vec![]), +}), |acc: Rc, name: String| { + let ident = intern(&env.intern_table.clone(), &name).id.clone(); +match v2_rt::map_get(&env.bindings.clone(), ident.clone()) { + Some(binding) => { + let result = resolve_node(binding.resolved.clone(), env.clone(), module_name.clone()); +Rc::new(BindingsAccum { + bindings: v2_rt::rc_map_insert(acc.bindings.clone(), ident.clone(), Rc::new(TypeBinding { + name: name.clone(), + resolved: result.resolved.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})), + diagnostics: v2_rt::concat(acc.diagnostics.clone(), result.diagnostics.clone()), +}) +}, + None => acc.clone(), +} +}); +let ready_set = ready.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let next_remaining = Rc::new({ let mut __result = Vec::new(); for name in remaining.clone().iter().cloned() { if (emit_map_has(ready_set.clone(), name.clone()) == false) { __result.push(name); } } __result }); +{ let __tco_0 = next_remaining; - let __tco_1 = Rc::new(TypeEnv { - bindings: ready_accum.bindings.clone(), - recursive_types: env.recursive_types.clone(), - recursive_type_set: env.recursive_type_set.clone(), - inductive_fields: env.inductive_fields.clone(), - source_indices: env.source_indices.clone(), - intern_table: env.intern_table.clone(), - }); - let __tco_2 = v2_rt::concat(diagnostics, ready_accum.diagnostics.clone()); - let __tco_3 = (fuel - 1); - remaining = __tco_0; - env = __tco_1; - diagnostics = __tco_2; - fuel = __tco_3; - continue; - } - } +let __tco_1 = Rc::new(TypeEnv { + bindings: ready_accum.bindings.clone(), + recursive_types: env.recursive_types.clone(), + recursive_type_set: env.recursive_type_set.clone(), + inductive_fields: env.inductive_fields.clone(), + source_indices: env.source_indices.clone(), + intern_table: env.intern_table.clone(), +}); +let __tco_2 = v2_rt::concat(diagnostics, ready_accum.diagnostics.clone()); +let __tco_3 = (fuel - 1); +remaining = __tco_0; +env = __tco_1; +diagnostics = __tco_2; +fuel = __tco_3; +continue; +} +} } -pub fn collect_parent_envs( - resolved: &Rc, - module_index: Rc>>, - source_indices: Rc>>, -) -> Rc { +pub fn collect_parent_envs(resolved: &Rc, module_index: Rc>>, source_indices: Rc>>) -> Rc { { - let modules = Rc::new({ - let mut __result = Vec::new(); - for imp in resolved.resolved_imports.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&module_index, imp.module_path.clone()) { - Some(typed) => Rc::new(vec![typed.clone()]), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let resolved_mod_name = authored_name_at(source_indices, &resolved.module.clone()); - let diagnostics = Rc::new({ - let mut __result = Vec::new(); - for imp in resolved.resolved_imports.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&module_index, imp.module_path.clone()) { - Some(_) => Rc::new(vec![]), - None => Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "missing parent environment for imported module '" - .to_string(), - imp.module_path.clone(), - ), - "' while ordering '".to_string(), - ), - resolved_mod_name.clone(), - ), - "'".to_string(), - ), - span: imp.target_module.clone().clone().unwrap().span.clone(), - }), - resolved_mod_name.clone(), - )]), - }) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(ParentModulesResult { - modules: modules, - diagnostics: diagnostics, - }) - } + let modules = Rc::new({ let mut __result = Vec::new(); for imp in resolved.resolved_imports.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&module_index, imp.module_path.clone()) { + Some(typed) => Rc::new(vec![typed.clone()]), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let resolved_mod_name = authored_name_at(source_indices, &resolved.module.clone()); +let diagnostics = Rc::new({ let mut __result = Vec::new(); for imp in resolved.resolved_imports.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&module_index, imp.module_path.clone()) { + Some(_) => Rc::new(vec![]), + None => Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("missing parent environment for imported module '".to_string(), imp.module_path.clone()), "' while ordering '".to_string()), resolved_mod_name.clone()), "'".to_string()), + span: imp.target_module.clone().clone().unwrap().span.clone(), +}), resolved_mod_name.clone())]), +}).iter().cloned()); } __result }); +Rc::new(ParentModulesResult { + modules: modules, + diagnostics: diagnostics, +}) +} } -pub fn build_fielded_variants( - modules: Rc>>, - type_summaries: Rc>>, -) -> Rc> { +pub fn build_fielded_variants(modules: Rc>>, type_summaries: Rc>>) -> Rc> { { - let result = modules.iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, m: Rc| { - let items = m.items.clone(); - let si = m.type_env.clone().source_indices.clone(); - items.clone().iter().cloned().fold( - acc, - |inner: Rc>, item: Rc| { - let is_enum = match v2_rt::map_get( - &type_summaries, - authored_name_at(si.clone(), &item), - ) { - Some(summary) => match (*summary.repr.clone()).clone() { - TypeRepr::EnumRepr { .. } => true, - _ => false, - }, - None => false, - }; - if is_enum.clone() { - { - let enum_name = authored_name_at(si.clone(), &item); - let variants = item.children.clone(); - variants.clone().iter().cloned().fold( - inner.clone(), - |vacc: Rc>, variant: Rc| { - let has_fields = - ((variant.children.clone().len() as i64) > 0); - if has_fields.clone() { - v2_rt::rc_map_insert( - vacc.clone(), - v2_rt::concat( - v2_rt::concat( - enum_name.clone(), - "::".to_string(), - ), - authored_name_at(si.clone(), &variant), - ), - true, - ) - } else { - vacc.clone() - } - }, - ) + let result = modules.iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, m: Rc| { + let items = m.items.clone(); +let si = m.type_env.clone().source_indices.clone(); +items.clone().iter().cloned().fold(acc, |inner: Rc>, item: Rc| { + let is_enum = match v2_rt::map_get(&type_summaries, authored_name_at(si.clone(), &item)) { + Some(summary) => match (*summary.repr.clone()).clone() { + TypeRepr::EnumRepr { .. } => true, + _ => false, +}, + None => false, +}; +if is_enum.clone() { + { + let enum_name = authored_name_at(si.clone(), &item); +let variants = item.children.clone(); +variants.clone().iter().cloned().fold(inner.clone(), |vacc: Rc>, variant: Rc| { + let has_fields = ((variant.children.clone().len() as i64) > 0); +if has_fields.clone() { + v2_rt::rc_map_insert(vacc.clone(), v2_rt::concat(v2_rt::concat(enum_name.clone(), "::".to_string()), authored_name_at(si.clone(), &variant)), true) + } else { + vacc.clone() } - } else { - inner.clone() - } - }, - ) - }, - ); - result - } +}) +} + } else { + inner.clone() + } +}) +}); +result +} } pub fn build_emit_graph_info(modules: &Rc>>) -> Rc { { let init = Rc::new(EmitInfoBuildState { - type_summaries: v2_rt::rc_empty_map::>(), - }); - let built = modules.clone().iter().cloned().fold( - init.clone(), - |state: Rc, typed_module: Rc| { - typed_module.items.clone().iter().cloned().fold( - state, - |inner_state: Rc, item: Rc| { - add_emit_item_summary( - inner_state, - &item, - &typed_module.type_env.clone().source_indices.clone(), - ) - }, - ) - }, - ); - let all_recursive = modules.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, m: Rc| { - Rc::new(v2_rt::map_keys( - &m.type_env.clone().recursive_type_set.clone(), - )) - .iter() - .cloned() - .fold(acc, |inner: Rc>, ident: i64| { - v2_rt::rc_map_insert( - inner, - intern_str(m.type_env.clone().intern_table.clone(), ident.clone()), - true, - ) - }) - }, - ); - let fielded = build_fielded_variants(modules.clone(), built.type_summaries.clone()); - let vtoe = derive_variant_to_enum(built.type_summaries.clone()); - Rc::new(EmitGraphInfo { - type_summaries: built.type_summaries.clone(), - recursive_type_set: all_recursive, - fielded_variants: fielded, - shared_types: v2_rt::rc_empty_map::(), - ownership_index: v2_rt::rc_empty_map::>>(), - movable: v2_rt::rc_empty_map::(), - variant_to_enum: vtoe, - owned_bindings: v2_rt::rc_empty_map::(), - read_only_params_index: v2_rt::rc_empty_map::>>(), - read_only_params: v2_rt::rc_empty_map::(), - }) - } + type_summaries: v2_rt::rc_empty_map::>(), +}); +let built = modules.clone().iter().cloned().fold(init.clone(), |state: Rc, typed_module: Rc| typed_module.items.clone().iter().cloned().fold(state, |inner_state: Rc, item: Rc| add_emit_item_summary(inner_state, &item, &typed_module.type_env.clone().source_indices.clone()))); +let all_recursive = modules.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, m: Rc| Rc::new(v2_rt::map_keys(&m.type_env.clone().recursive_type_set.clone())).iter().cloned().fold(acc, |inner: Rc>, ident: i64| v2_rt::rc_map_insert(inner, intern_str(m.type_env.clone().intern_table.clone(), ident.clone()), true))); +let fielded = build_fielded_variants(modules.clone(), built.type_summaries.clone()); +let vtoe = derive_variant_to_enum(built.type_summaries.clone()); +Rc::new(EmitGraphInfo { + type_summaries: built.type_summaries.clone(), + recursive_type_set: all_recursive, + fielded_variants: fielded, + shared_types: v2_rt::rc_empty_map::(), + ownership_index: v2_rt::rc_empty_map::>>(), + movable: v2_rt::rc_empty_map::(), + variant_to_enum: vtoe, + owned_bindings: v2_rt::rc_empty_map::(), + read_only_params_index: v2_rt::rc_empty_map::>>(), + read_only_params: v2_rt::rc_empty_map::(), +}) +} } -pub fn typecheck( - graph: Rc, - source_indices: Rc>>, - intern_table: Rc, -) -> Rc { - typecheck_modules( - graph.modules.clone(), - Rc::new(vec![]), - v2_rt::rc_empty_map::>(), - v2_rt::rc_empty_map::>(), - Rc::new(vec![]), - source_indices, - intern_table, - ) -} - -pub fn typecheck_modules( - mut remaining: Rc>>, - mut modules: Rc>>, - mut module_index: Rc>>, - mut item_registry: Rc>>, - mut diag_chunks: Rc>>>>, - mut source_indices: Rc>>, - mut intern_table: Rc, -) -> Rc { - loop { - match remaining.clone().first().cloned() { - None => { - let expanded_registry = - expand_transitive_services(modules.clone(), item_registry, 5); - break Rc::new(TypedGraph { - modules: modules.clone(), - item_registry: expanded_registry, - diagnostics: Rc::new({ - let mut __result = Vec::new(); - for c in diag_chunks.iter().cloned() { - __result.extend((*c.clone()).iter().cloned()); - } - __result - }), - }); - } - Some(resolved) => { - let parent_result = - collect_parent_envs(&resolved, module_index.clone(), source_indices.clone()); - let tc_result = typecheck_module( - &resolved, - &module_index, - &source_indices, - intern_table.clone(), - ); - let typed = tc_result.typed.clone(); - let tc_diags = tc_result.diagnostics.clone(); - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = v2_rt::rc_list_push(modules, typed.clone()); - let __tco_2 = v2_rt::rc_map_insert( - module_index, - authored_name_at(source_indices.clone(), &typed.module.clone()), - typed.clone(), - ); - let __tco_3 = v2_rt::rc_map_merge(item_registry, typed.item_registry.clone()); - let __tco_4 = v2_rt::rc_list_push( - v2_rt::rc_list_push(diag_chunks, parent_result.diagnostics.clone()), - tc_diags, - ); - remaining = __tco_0; - modules = __tco_1; - module_index = __tco_2; - item_registry = __tco_3; - diag_chunks = __tco_4; - continue; - } - } - } - } +pub fn typecheck(graph: Rc, source_indices: Rc>>, intern_table: Rc) -> Rc { + typecheck_modules(graph.modules.clone(), Rc::new(vec![]), v2_rt::rc_empty_map::>(), v2_rt::rc_empty_map::>(), Rc::new(vec![]), source_indices, intern_table) } -pub fn reconcile( - graph: Rc, - source_indices: Rc>>, - intern_table: Rc, -) -> Rc { +pub fn typecheck_modules(mut remaining: Rc>>, mut modules: Rc>>, mut module_index: Rc>>, mut item_registry: Rc>>, mut diag_chunks: Rc>>>>, mut source_indices: Rc>>, mut intern_table: Rc) -> Rc { + loop { + match remaining.clone().first().cloned() { + None => { let expanded_registry = expand_transitive_services(modules.clone(), item_registry, 5); +break Rc::new(TypedGraph { + modules: modules.clone(), + item_registry: expanded_registry, + diagnostics: Rc::new({ let mut __result = Vec::new(); for c in diag_chunks.iter().cloned() { __result.extend((*c.clone()).iter().cloned()); } __result }), +}); }, + Some(resolved) => { let parent_result = collect_parent_envs(&resolved, module_index.clone(), source_indices.clone()); +let tc_result = typecheck_module(&resolved, &module_index, &source_indices, intern_table.clone()); +let typed = tc_result.typed.clone(); +let tc_diags = tc_result.diagnostics.clone(); +{ + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(modules, typed.clone()); +let __tco_2 = v2_rt::rc_map_insert(module_index, authored_name_at(source_indices.clone(), &typed.module.clone()), typed.clone()); +let __tco_3 = v2_rt::rc_map_merge(item_registry, typed.item_registry.clone()); +let __tco_4 = v2_rt::rc_list_push(v2_rt::rc_list_push(diag_chunks, parent_result.diagnostics.clone()), tc_diags); +remaining = __tco_0; +modules = __tco_1; +module_index = __tco_2; +item_registry = __tco_3; +diag_chunks = __tco_4; +continue; +} }, +} +} +} + +pub fn reconcile(graph: Rc, source_indices: Rc>>, intern_table: Rc) -> Rc { { let typed = typecheck(graph, source_indices, intern_table); - let emit_info = build_emit_graph_info(&typed.modules.clone()); - Rc::new(ResolvedGraph { - modules: typed.modules.clone(), - item_registry: typed.item_registry.clone(), - diagnostics: typed.diagnostics.clone(), - emit_graph_info: emit_info, - }) - } +let emit_info = build_emit_graph_info(&typed.modules.clone()); +Rc::new(ResolvedGraph { + modules: typed.modules.clone(), + item_registry: typed.item_registry.clone(), + diagnostics: typed.diagnostics.clone(), + emit_graph_info: emit_info, +}) +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_access.rs b/src/v2/stage0/src/v2_compiler_infer_access.rs index 5351728cdb0..88ef0d55a1d 100644 --- a/src/v2/stage0/src/v2_compiler_infer_access.rs +++ b/src/v2/stage0/src/v2_compiler_infer_access.rs @@ -1,22 +1,16 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_access -pub use crate::std_types::{is_ordered_element_collection, SourceSpan}; -pub use crate::v2_compiler_infer_types::{ - for_each_element_type_node, node_is_element_collection, node_is_keyed_collection, - node_type_equals, normalize_access_type_node, resolved_type, -}; -use crate::v2_rt; -use crate::v2_std_core::CompilerDiagnostic::InternalError; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved}; -pub use crate::v2_std_core::{ - authored_name_at, diagnostic_to_message, int_type, make_error_node, string_type, unit_type, - with_optional_cardinality, CompilerDiagnostic, ErrorNode, InferredNode, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan, is_ordered_element_collection}; +pub use crate::v2_std_core::{Node, NewlineIndex, authored_name_at, InferredNode, ErrorNode, make_error_node, diagnostic_to_message, with_optional_cardinality, unit_type, string_type, int_type, CompilerDiagnostic}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError}; +use crate::v2_std_core::CompilerDiagnostic::{InternalError}; +pub use crate::v2_compiler_infer_types::{resolved_type, normalize_access_type_node, node_type_equals, node_is_keyed_collection, node_is_element_collection, for_each_element_type_node}; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct AccessCheckResultNode { @@ -31,210 +25,124 @@ pub struct KeyedCollectionParts { } pub fn access_error(message: String, span: Rc, module_name: String) -> Rc { - make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: message, - span: span, - }), - module_name, - ) + make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: message, + span: span, +}), module_name) } -pub fn access_result( - inferred: Rc, - diagnostics: &Rc>>, - span: Rc, - fallback_message: String, -) -> Rc { +pub fn access_result(inferred: Rc, diagnostics: &Rc>>, span: Rc, fallback_message: String) -> Rc { if ((diagnostics.clone().len() as i64) == 0) { Rc::new(AccessCheckResultNode { - inferred: Some(Rc::new(InferredNode::Resolved { node: inferred })), - diagnostics: diagnostics.clone(), - }) + inferred: Some(Rc::new(InferredNode::Resolved { + node: inferred, +})), + diagnostics: diagnostics.clone(), +}) } else { { let message = match diagnostics.clone().first().cloned() { - Some(diag) => diagnostic_to_message(diag.diagnostic.clone()), - None => fallback_message, - }; - Rc::new(AccessCheckResultNode { - inferred: Some(Rc::new(InferredNode::CompilerError { - message: message, - span: span, - })), - diagnostics: diagnostics.clone(), - }) - } + Some(diag) => diagnostic_to_message(diag.diagnostic.clone()), + None => fallback_message, +}; +Rc::new(AccessCheckResultNode { + inferred: Some(Rc::new(InferredNode::CompilerError { + message: message, + span: span, +})), + diagnostics: diagnostics.clone(), +}) +} } } -pub fn keyed_collection_parts( - n: &Rc, - source_indices: Rc>>, -) -> Option> { +pub fn keyed_collection_parts(n: &Rc, source_indices: Rc>>) -> Option> { if (node_is_keyed_collection(&n, source_indices) && ((n.children.clone().len() as i64) >= 2)) { match n.children.clone().first().cloned() { - Some(key_child) => match n.children.clone().get(1 as usize).cloned() { - Some(value_child) => Some(Rc::new(KeyedCollectionParts { - key_type: resolved_type(key_child.clone()), - value_type: resolved_type(value_child.clone()), - })), - None => None, - }, - None => None, - } + Some(key_child) => match n.children.clone().get(1 as usize).cloned() { + Some(value_child) => Some(Rc::new(KeyedCollectionParts { + key_type: resolved_type(key_child.clone()), + value_type: resolved_type(value_child.clone()), +})), + None => None, +}, + None => None, +} } else { None } } -pub fn check_index_access_node( - base_type: Rc, - index_type: Rc, - span: &Rc, - module_name: String, - source_indices: &Rc>>, -) -> Rc { +pub fn check_index_access_node(base_type: Rc, index_type: Rc, span: &Rc, module_name: String, source_indices: &Rc>>) -> Rc { { let normed = normalize_access_type_node(base_type); - let normed_index = normalize_access_type_node(index_type); - let base_is_string = node_type_equals(&normed, &string_type(), source_indices.clone()); - let index_is_int = node_type_equals(&normed_index, &int_type(), source_indices.clone()); - if base_is_string { +let normed_index = normalize_access_type_node(index_type); +let base_is_string = node_type_equals(&normed, &string_type(), source_indices.clone()); +let index_is_int = node_type_equals(&normed_index, &int_type(), source_indices.clone()); +if base_is_string { { let diags = if index_is_int { Rc::new(vec![]) } else { - Rc::new(vec![access_error( - "string index requires an Int index".to_string(), - span.clone(), - module_name, - )]) + Rc::new(vec![access_error("string index requires an Int index".to_string(), span.clone(), module_name)]) }; - access_result( - string_type(), - &diags, - span.clone(), - "invalid string index access".to_string(), - ) - } +access_result(string_type(), &diags, span.clone(), "invalid string index access".to_string()) +} } else { match keyed_collection_parts(&normed, source_indices.clone()) { - Some(parts) => { - let key_diags = if node_type_equals( - &parts.key_type.clone(), - &normed_index, - source_indices.clone(), - ) { - Rc::new(vec![]) - } else { - Rc::new(vec![access_error("keyed collection index key type does not match the collection key type".to_string(), span.clone(), module_name)]) - }; - access_result( - with_optional_cardinality(&parts.value_type.clone()), - &key_diags, - span.clone(), - "invalid keyed collection index access".to_string(), - ) - } - None => { - if node_is_keyed_collection(&normed, source_indices.clone()) { - { - let malformed_diags = Rc::new(vec![access_error( - "malformed keyed collection type in index access".to_string(), - span.clone(), - module_name, - )]); - access_result( - unit_type(), - &malformed_diags, - span.clone(), - "malformed keyed collection type in index access".to_string(), - ) - } - } else { - if ((is_ordered_element_collection(authored_name_at( - source_indices.clone(), - &normed, - )) && node_is_element_collection(&normed, source_indices.clone())) - && index_is_int) - { - { - let elem = for_each_element_type_node( - normed.clone(), - source_indices.clone(), - ); - access_result( - with_optional_cardinality(&elem), - &Rc::new(vec![]), - span.clone(), - "list index access".to_string(), - ) - } - } else { - { - let diags = Rc::new(vec![access_error("indexing is only supported for String, keyed collection, and list values".to_string(), span.clone(), module_name)]); - access_result( - unit_type(), - &diags, - span.clone(), - "invalid index access".to_string(), - ) - } - } - } + Some(parts) => { + let key_diags = if node_type_equals(&parts.key_type.clone(), &normed_index, source_indices.clone()) { + Rc::new(vec![]) + } else { + Rc::new(vec![access_error("keyed collection index key type does not match the collection key type".to_string(), span.clone(), module_name)]) + }; +access_result(with_optional_cardinality(&parts.value_type.clone()), &key_diags, span.clone(), "invalid keyed collection index access".to_string()) +}, + None => if node_is_keyed_collection(&normed, source_indices.clone()) { + { + let malformed_diags = Rc::new(vec![access_error("malformed keyed collection type in index access".to_string(), span.clone(), module_name)]); +access_result(unit_type(), &malformed_diags, span.clone(), "malformed keyed collection type in index access".to_string()) +} + } else { + if ((is_ordered_element_collection(authored_name_at(source_indices.clone(), &normed)) && node_is_element_collection(&normed, source_indices.clone())) && index_is_int) { + { + let elem = for_each_element_type_node(normed.clone(), source_indices.clone()); +access_result(with_optional_cardinality(&elem), &Rc::new(vec![]), span.clone(), "list index access".to_string()) +} + } else { + { + let diags = Rc::new(vec![access_error("indexing is only supported for String, keyed collection, and list values".to_string(), span.clone(), module_name)]); +access_result(unit_type(), &diags, span.clone(), "invalid index access".to_string()) +} } - } + }, +} } - } +} } -pub fn check_slice_access_node( - base_type: Rc, - start_type: Rc, - end_type: Rc, - span: &Rc, - module_name: &String, - source_indices: &Rc>>, -) -> Rc { +pub fn check_slice_access_node(base_type: Rc, start_type: Rc, end_type: Rc, span: &Rc, module_name: &String, source_indices: &Rc>>) -> Rc { { let normed_base = normalize_access_type_node(base_type); - let base_is_string = node_type_equals(&normed_base, &string_type(), source_indices.clone()); - let base_diags = if base_is_string { +let base_is_string = node_type_equals(&normed_base, &string_type(), source_indices.clone()); +let base_diags = if base_is_string { Rc::new(vec![]) } else { - Rc::new(vec![access_error( - "slice is only supported for String values".to_string(), - span.clone(), - module_name.clone(), - )]) + Rc::new(vec![access_error("slice is only supported for String values".to_string(), span.clone(), module_name.clone())]) }; - let normed_start = normalize_access_type_node(start_type); - let start_diags = if node_type_equals(&normed_start, &int_type(), source_indices.clone()) { +let normed_start = normalize_access_type_node(start_type); +let start_diags = if node_type_equals(&normed_start, &int_type(), source_indices.clone()) { Rc::new(vec![]) } else { - Rc::new(vec![access_error( - "slice start requires an Int index".to_string(), - span.clone(), - module_name.clone(), - )]) + Rc::new(vec![access_error("slice start requires an Int index".to_string(), span.clone(), module_name.clone())]) }; - let normed_end = normalize_access_type_node(end_type); - let end_diags = if node_type_equals(&normed_end, &int_type(), source_indices.clone()) { +let normed_end = normalize_access_type_node(end_type); +let end_diags = if node_type_equals(&normed_end, &int_type(), source_indices.clone()) { Rc::new(vec![]) } else { - Rc::new(vec![access_error( - "slice end requires an Int index".to_string(), - span.clone(), - module_name.clone(), - )]) + Rc::new(vec![access_error("slice end requires an Int index".to_string(), span.clone(), module_name.clone())]) }; - let all_diags = v2_rt::concat(v2_rt::concat(base_diags, start_diags), end_diags); - access_result( - string_type(), - &all_diags, - span.clone(), - "invalid slice access".to_string(), - ) - } +let all_diags = v2_rt::concat(v2_rt::concat(base_diags, start_diags), end_diags); +access_result(string_type(), &all_diags, span.clone(), "invalid slice access".to_string()) +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_cycle.rs b/src/v2/stage0/src/v2_compiler_infer_cycle.rs index f174744c84e..7ed18be2ecf 100644 --- a/src/v2/stage0/src/v2_compiler_infer_cycle.rs +++ b/src/v2/stage0/src/v2_compiler_infer_cycle.rs @@ -1,144 +1,77 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_cycle -pub use crate::v2_compiler_infer_env::TypeBinding; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_compiler_infer_env::{TypeBinding}; pub fn set_has(m: Rc>, key: String) -> bool { { let result = match v2_rt::map_get(&m, key) { - Some(_) => true, - None => false, - }; - result - } + Some(_) => true, + None => false, +}; +result +} } -pub fn compute_in_graph_deps( - all_names: Rc>, - deps_map: Rc>>>, - name_set: Rc>, -) -> Rc>>> { +pub fn compute_in_graph_deps(all_names: Rc>, deps_map: Rc>>>, name_set: Rc>) -> Rc>>> { { - let result = all_names.iter().cloned().fold( - v2_rt::rc_empty_map::>>(), - |acc: Rc>>>, name: String| match v2_rt::map_get( - &deps_map, - name.clone(), - ) { - Some(deps) => { - let local = Rc::new({ - let mut __result = Vec::new(); - for d in deps.clone().iter().cloned() { - if ((d.clone().as_str() != name.clone().as_str()) - && set_has(name_set.clone(), d.clone())) - { - __result.push(d); - } - } - __result - }); - v2_rt::rc_map_insert(acc.clone(), name.clone(), local.clone()) - } - None => v2_rt::rc_map_insert(acc.clone(), name.clone(), Rc::new(vec![])), - }, - ); - result - } + let result = all_names.iter().cloned().fold(v2_rt::rc_empty_map::>>(), |acc: Rc>>>, name: String| match v2_rt::map_get(&deps_map, name.clone()) { + Some(deps) => { + let local = Rc::new({ let mut __result = Vec::new(); for d in deps.clone().iter().cloned() { if ((d.clone().as_str() != name.clone().as_str()) && set_has(name_set.clone(), d.clone())) { __result.push(d); } } __result }); +v2_rt::rc_map_insert(acc.clone(), name.clone(), local.clone()) +}, + None => v2_rt::rc_map_insert(acc.clone(), name.clone(), Rc::new(vec![])), +}); +result +} } -pub fn build_reverse_adj( - all_names: Rc>, - local_deps: Rc>>>, -) -> Rc>>> { - all_names.iter().cloned().fold( - v2_rt::rc_empty_map::>>(), - |acc: Rc>>>, name: String| match v2_rt::map_get( - &local_deps, - name.clone(), - ) { - Some(deps) => deps.clone().iter().cloned().fold( - acc.clone(), - |inner_acc: Rc>>>, dep: String| { - let existing = match v2_rt::map_get(&inner_acc, dep.clone()) { - Some(v) => v.clone(), - None => Rc::new(vec![]), - }; - v2_rt::rc_map_insert( - inner_acc.clone(), - dep.clone(), - v2_rt::rc_list_push(existing.clone(), name.clone()), - ) - }, - ), - None => acc.clone(), - }, - ) +pub fn build_reverse_adj(all_names: Rc>, local_deps: Rc>>>) -> Rc>>> { + all_names.iter().cloned().fold(v2_rt::rc_empty_map::>>(), |acc: Rc>>>, name: String| match v2_rt::map_get(&local_deps, name.clone()) { + Some(deps) => deps.clone().iter().cloned().fold(acc.clone(), |inner_acc: Rc>>>, dep: String| { + let existing = match v2_rt::map_get(&inner_acc, dep.clone()) { + Some(v) => v.clone(), + None => Rc::new(vec![]), +}; +v2_rt::rc_map_insert(inner_acc.clone(), dep.clone(), v2_rt::rc_list_push(existing.clone(), name.clone())) +}), + None => acc.clone(), +}) } -pub fn build_in_degree( - all_names: Rc>, - local_deps: Rc>>>, -) -> Rc> { - all_names.iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - let deg = match v2_rt::map_get(&local_deps, name.clone()) { - Some(deps) => (deps.clone().len() as i64), - None => 0, - }; - v2_rt::rc_map_insert(acc, name.clone(), deg.clone()) - }, - ) +pub fn build_in_degree(all_names: Rc>, local_deps: Rc>>>) -> Rc> { + all_names.iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| { + let deg = match v2_rt::map_get(&local_deps, name.clone()) { + Some(deps) => (deps.clone().len() as i64), + None => 0, +}; +v2_rt::rc_map_insert(acc, name.clone(), deg.clone()) +}) } -pub fn kahn_remove_loop( - remaining: &Rc>, - local_deps: &Rc>>>, -) -> Rc> { +pub fn kahn_remove_loop(remaining: &Rc>, local_deps: &Rc>>>) -> Rc> { { let reverse_adj = build_reverse_adj(remaining.clone(), local_deps.clone()); - let in_degree = build_in_degree(remaining.clone(), local_deps.clone()); - let initial_queue = Rc::new({ - let mut __result = Vec::new(); - for n in remaining.clone().iter().cloned() { - if match v2_rt::map_get(&in_degree, n.clone()) { - Some(d) => (d.clone() == 0), - None => true, - } { - __result.push(n); - } - } - __result - }); - let final_state = kahn_cycle_drain( - initial_queue, - in_degree.clone(), - reverse_adj, - 0, - (remaining.clone().len() as i64), - ); - if (final_state.removed_count.clone() == (remaining.clone().len() as i64)) { +let in_degree = build_in_degree(remaining.clone(), local_deps.clone()); +let initial_queue = Rc::new({ let mut __result = Vec::new(); for n in remaining.clone().iter().cloned() { if match v2_rt::map_get(&in_degree, n.clone()) { + Some(d) => (d.clone() == 0), + None => true, +} { __result.push(n); } } __result }); +let final_state = kahn_cycle_drain(initial_queue, in_degree.clone(), reverse_adj, 0, (remaining.clone().len() as i64)); +if (final_state.removed_count.clone() == (remaining.clone().len() as i64)) { Rc::new(vec![]) } else { - Rc::new({ - let mut __result = Vec::new(); - for n in remaining.clone().iter().cloned() { - if match v2_rt::map_get(&final_state.in_degree.clone(), n.clone()) { - Some(d) => (d.clone() > 0), - None => false, - } { - __result.push(n); - } - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for n in remaining.clone().iter().cloned() { if match v2_rt::map_get(&final_state.in_degree.clone(), n.clone()) { + Some(d) => (d.clone() > 0), + None => false, +} { __result.push(n); } } __result }) } - } +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -147,147 +80,78 @@ pub struct KahnState { pub removed_count: i64, } -pub fn kahn_cycle_drain( - mut queue: Rc>, - mut in_degree: Rc>, - mut reverse_adj: Rc>>>, - mut removed_count: i64, - mut fuel: i64, -) -> Rc { +pub fn kahn_cycle_drain(mut queue: Rc>, mut in_degree: Rc>, mut reverse_adj: Rc>>>, mut removed_count: i64, mut fuel: i64) -> Rc { loop { if ((queue.clone().len() as i64) == 0) { return Rc::new(KahnState { - in_degree: in_degree.clone(), - removed_count: removed_count.clone(), - }); + in_degree: in_degree.clone(), + removed_count: removed_count.clone(), +}) } - let result = queue.clone().iter().cloned().fold( - Rc::new(KahnState { - in_degree: in_degree.clone(), - removed_count: removed_count.clone(), - }), - |state: Rc, node: String| { - let state = Rc::try_unwrap(state).unwrap_or_else(|rc| (*rc).clone()); - { - let dependents = match v2_rt::map_get(&reverse_adj, node.clone()) { - Some(v) => v.clone(), - None => Rc::new(vec![]), - }; - let new_deg = dependents.clone().iter().cloned().fold( - state.in_degree, - |deg_acc: Rc>, dep: String| { - let old = match v2_rt::map_get(°_acc, dep.clone()) { - Some(d) => d.clone(), - None => 0, - }; - v2_rt::rc_map_insert(deg_acc.clone(), dep.clone(), (old.clone() - 1)) - }, - ); - Rc::new(KahnState { - in_degree: new_deg.clone(), - removed_count: (state.removed_count + 1), - }) +let result = queue.clone().iter().cloned().fold(Rc::new(KahnState { + in_degree: in_degree.clone(), + removed_count: removed_count.clone(), +}), |state: Rc, node: String| { let state = Rc::try_unwrap(state).unwrap_or_else(|rc| (*rc).clone()); { + let dependents = match v2_rt::map_get(&reverse_adj, node.clone()) { + Some(v) => v.clone(), + None => Rc::new(vec![]), +}; +let new_deg = dependents.clone().iter().cloned().fold(state.in_degree, |deg_acc: Rc>, dep: String| { + let old = match v2_rt::map_get(°_acc, dep.clone()) { + Some(d) => d.clone(), + None => 0, +}; +v2_rt::rc_map_insert(deg_acc.clone(), dep.clone(), (old.clone() - 1)) +}); +Rc::new(KahnState { + in_degree: new_deg.clone(), + removed_count: (state.removed_count + 1), +}) +} }); +let next_queue = queue.clone().iter().cloned().fold(Rc::new(vec![]), |acc: _, node: String| { + let dependents = match v2_rt::map_get(&reverse_adj, node.clone()) { + Some(v) => v.clone(), + None => Rc::new(vec![]), +}; +dependents.clone().iter().cloned().fold(acc, |inner_acc: _, dep: String| { + let deg = match v2_rt::map_get(&result.in_degree.clone(), dep.clone()) { + Some(d) => d.clone(), + None => 0, +}; +if (deg.clone() == 0) { + v2_rt::rc_list_push(inner_acc.clone(), dep.clone()) + } else { + inner_acc.clone() } - }, - ); - let next_queue = - queue - .clone() - .iter() - .cloned() - .fold(Rc::new(vec![]), |acc: _, node: String| { - let dependents = match v2_rt::map_get(&reverse_adj, node.clone()) { - Some(v) => v.clone(), - None => Rc::new(vec![]), - }; - dependents - .clone() - .iter() - .cloned() - .fold(acc, |inner_acc: _, dep: String| { - let deg = match v2_rt::map_get(&result.in_degree.clone(), dep.clone()) { - Some(d) => d.clone(), - None => 0, - }; - if (deg.clone() == 0) { - v2_rt::rc_list_push(inner_acc.clone(), dep.clone()) - } else { - inner_acc.clone() - } - }) - }); - { +}) +}); +{ let __tco_0 = next_queue; - let __tco_1 = result.in_degree.clone(); - let __tco_2 = result.removed_count.clone(); - let __tco_3 = (fuel - 1); - queue = __tco_0; - in_degree = __tco_1; - removed_count = __tco_2; - fuel = __tco_3; - continue; - } - } +let __tco_1 = result.in_degree.clone(); +let __tco_2 = result.removed_count.clone(); +let __tco_3 = (fuel - 1); +queue = __tco_0; +in_degree = __tco_1; +removed_count = __tco_2; +fuel = __tco_3; +continue; +} +} } -pub fn detect_type_cycles_kahn( - deps_map: &Rc>>>, - bindings: Rc>>, -) -> Rc> { +pub fn detect_type_cycles_kahn(deps_map: &Rc>>>, bindings: Rc>>) -> Rc> { { - let all_names = Rc::new({ - let mut __result = Vec::new(); - for b in Rc::new(v2_rt::map_values(&bindings)).iter().cloned() { - __result.push(b.name.clone()); - } - __result - }); - let name_set = all_names.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, n: String| v2_rt::rc_map_insert(acc, n.clone(), true), - ); - let local_deps = compute_in_graph_deps(all_names.clone(), deps_map.clone(), name_set); - let self_refs = Rc::new({ - let mut __result = Vec::new(); - for name in all_names.clone().iter().cloned() { - if match v2_rt::map_get(&deps_map, name.clone()) { - Some(deps) => { - let mut __found = false; - for d in deps.clone().iter().cloned() { - if (d.clone().as_str() == name.clone().as_str()) { - __found = true; - break; - } - } - __found - } - None => false, - } { - __result.push(name); - } - } - __result - }); - let cycle_members = kahn_remove_loop(&all_names, &local_deps); - let sr_set = self_refs.iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, n: String| v2_rt::rc_map_insert(acc, n.clone(), true), - ); - let cm_set = cycle_members - .iter() - .cloned() - .fold(sr_set, |acc: Rc>, n: String| { - v2_rt::rc_map_insert(acc, n.clone(), true) - }); - let result = Rc::new({ - let mut __result = Vec::new(); - for n in all_names.clone().iter().cloned() { - if set_has(cm_set.clone(), n.clone()) { - __result.push(n); - } - } - __result - }); - result - } + let all_names = Rc::new({ let mut __result = Vec::new(); for b in Rc::new(v2_rt::map_values(&bindings)).iter().cloned() { __result.push(b.name.clone()); } __result }); +let name_set = all_names.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, n: String| v2_rt::rc_map_insert(acc, n.clone(), true)); +let local_deps = compute_in_graph_deps(all_names.clone(), deps_map.clone(), name_set); +let self_refs = Rc::new({ let mut __result = Vec::new(); for name in all_names.clone().iter().cloned() { if match v2_rt::map_get(&deps_map, name.clone()) { + Some(deps) => { let mut __found = false; for d in deps.clone().iter().cloned() { if (d.clone().as_str() == name.clone().as_str()) { __found = true; break; } } __found }, + None => false, +} { __result.push(name); } } __result }); +let cycle_members = kahn_remove_loop(&all_names, &local_deps); +let sr_set = self_refs.iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, n: String| v2_rt::rc_map_insert(acc, n.clone(), true)); +let cm_set = cycle_members.iter().cloned().fold(sr_set, |acc: Rc>, n: String| v2_rt::rc_map_insert(acc, n.clone(), true)); +let result = Rc::new({ let mut __result = Vec::new(); for n in all_names.clone().iter().cloned() { if set_has(cm_set.clone(), n.clone()) { __result.push(n); } } __result }); +result +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_emit_info.rs b/src/v2/stage0/src/v2_compiler_infer_emit_info.rs index 67d890b8ea6..228cb3dbe9d 100644 --- a/src/v2/stage0/src/v2_compiler_infer_emit_info.rs +++ b/src/v2/stage0/src/v2_compiler_infer_emit_info.rs @@ -1,46 +1,40 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_emit_info -use self::TypeRepr::*; -pub use crate::v2_compiler_infer_types::{ - child_type_node, emit_map_has, node_type_equals, normalize_access_type_node, -}; -use crate::v2_rt; -use crate::v2_std_core::Cardinality::CardOptional; -use crate::v2_std_core::Connective::{Arrow, Conj, NoConnective}; -use crate::v2_std_core::FieldAccessStyle::{EnumAccessor, StoredField, TupleFirst, TupleSecond}; -use crate::v2_std_core::FieldValueShape::{OptionalValue, PlainValue}; -use crate::v2_std_core::InferredNode::{Resolved, TypeVariable}; -pub use crate::v2_std_core::{ - authored_name_at, find_child_named, has_child_named, param_node_name_at, - with_required_cardinality, Cardinality, Connective, FieldAccessStyle, FieldSummary, - FieldValueShape, InferredNode, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, authored_name_at, NewlineIndex, find_child_named, has_child_named, InferredNode, FieldAccessStyle, FieldValueShape, FieldSummary, with_required_cardinality, Connective, param_node_name_at, Cardinality}; +use crate::v2_std_core::InferredNode::{Resolved, TypeVariable}; +use crate::v2_std_core::FieldAccessStyle::{StoredField, EnumAccessor, TupleFirst, TupleSecond}; +use crate::v2_std_core::FieldValueShape::{PlainValue, OptionalValue}; +use crate::v2_std_core::Connective::{Conj, NoConnective, Arrow}; +use crate::v2_std_core::Cardinality::{CardOptional}; +pub use crate::v2_compiler_infer_types::{normalize_access_type_node, child_type_node, emit_map_has, node_type_equals}; +use self::TypeRepr::*; pub fn is_type_variable(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::TypeVariable { .. } => true, - _ => false, - } + InferredNode::TypeVariable { .. } => true, + _ => false, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum TypeRepr { StructRepr, - EnumRepr { unit_only: bool }, + EnumRepr { + unit_only: bool, + }, } impl TypeRepr { pub fn unit_only(&self) -> bool { match self { TypeRepr::StructRepr => panic!("no unit_only on unit variant"), - TypeRepr::EnumRepr { - unit_only: __val, .. - } => __val.clone(), + TypeRepr::EnumRepr { unit_only: __val, .. } => __val.clone(), } } } @@ -77,532 +71,253 @@ pub struct EmitInfoBuildState { pub fn empty_emit_graph_info() -> Rc { Rc::new(EmitGraphInfo { - type_summaries: v2_rt::rc_empty_map::>(), - recursive_type_set: v2_rt::rc_empty_map::(), - fielded_variants: v2_rt::rc_empty_map::(), - shared_types: v2_rt::rc_empty_map::(), - ownership_index: v2_rt::rc_empty_map::>>(), - movable: v2_rt::rc_empty_map::(), - variant_to_enum: v2_rt::rc_empty_map::(), - owned_bindings: v2_rt::rc_empty_map::(), - read_only_params_index: v2_rt::rc_empty_map::>>(), - read_only_params: v2_rt::rc_empty_map::(), - }) + type_summaries: v2_rt::rc_empty_map::>(), + recursive_type_set: v2_rt::rc_empty_map::(), + fielded_variants: v2_rt::rc_empty_map::(), + shared_types: v2_rt::rc_empty_map::(), + ownership_index: v2_rt::rc_empty_map::>>(), + movable: v2_rt::rc_empty_map::(), + variant_to_enum: v2_rt::rc_empty_map::(), + owned_bindings: v2_rt::rc_empty_map::(), + read_only_params_index: v2_rt::rc_empty_map::>>(), + read_only_params: v2_rt::rc_empty_map::(), +}) } -pub fn variant_has_fields( - emit_info: Rc, - enum_name: String, - variant_name: String, -) -> bool { +pub fn variant_has_fields(emit_info: Rc, enum_name: String, variant_name: String) -> bool { { let key = v2_rt::concat(v2_rt::concat(enum_name, "::".to_string()), variant_name); - match v2_rt::map_get(&emit_info.fielded_variants.clone(), key) { - Some(v) => v.clone(), - None => false, - } - } +match v2_rt::map_get(&emit_info.fielded_variants.clone(), key) { + Some(v) => v.clone(), + None => false, +} +} } -pub fn lookup_emit_type_summary( - emit_info: Rc, - type_name: String, -) -> Option> { +pub fn lookup_emit_type_summary(emit_info: Rc, type_name: String) -> Option> { v2_rt::map_get(&emit_info.type_summaries.clone(), type_name) } -pub fn derive_variant_to_enum( - type_summaries: Rc>>, -) -> Rc> { - Rc::new(v2_rt::map_values(&type_summaries)) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, summary: Rc| match (*summary - .repr - .clone()) - .clone() - { - TypeRepr::EnumRepr { .. } => { - Rc::new(v2_rt::map_keys(&summary.variant_name_set.clone())) - .iter() - .cloned() - .fold( - acc.clone(), - |inner: Rc>, vn: String| match v2_rt::map_get( - &inner, - vn.clone(), - ) { - Some(_) => { - v2_rt::rc_map_insert(inner.clone(), vn.clone(), "".to_string()) - } - None => v2_rt::rc_map_insert( - inner.clone(), - vn.clone(), - summary.name.clone(), - ), - }, - ) - } - _ => acc.clone(), - }, - ) +pub fn derive_variant_to_enum(type_summaries: Rc>>) -> Rc> { + Rc::new(v2_rt::map_values(&type_summaries)).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, summary: Rc| match (*summary.repr.clone()).clone() { + TypeRepr::EnumRepr { .. } => Rc::new(v2_rt::map_keys(&summary.variant_name_set.clone())).iter().cloned().fold(acc.clone(), |inner: Rc>, vn: String| match v2_rt::map_get(&inner, vn.clone()) { + Some(_) => v2_rt::rc_map_insert(inner.clone(), vn.clone(), "".to_string()), + None => v2_rt::rc_map_insert(inner.clone(), vn.clone(), summary.name.clone()), +}), + _ => acc.clone(), +}) } -pub fn is_known_variant( - type_summaries: Rc>>, - name: String, -) -> bool { - { - let mut __found = false; - for summary in Rc::new(v2_rt::map_values(&type_summaries)).iter().cloned() { - if match (*summary.repr.clone()).clone() { - TypeRepr::EnumRepr { .. } => { - emit_map_has(summary.variant_name_set.clone(), name.clone()) - } - _ => false, - } { - __found = true; - break; - } - } - __found - } +pub fn is_known_variant(type_summaries: Rc>>, name: String) -> bool { + { let mut __found = false; for summary in Rc::new(v2_rt::map_values(&type_summaries)).iter().cloned() { if match (*summary.repr.clone()).clone() { + TypeRepr::EnumRepr { .. } => emit_map_has(summary.variant_name_set.clone(), name.clone()), + _ => false, +} { __found = true; break; } } __found } } -pub fn variant_belongs_to_enum( - type_summaries: Rc>>, - variant_name: String, - enum_name: String, -) -> bool { +pub fn variant_belongs_to_enum(type_summaries: Rc>>, variant_name: String, enum_name: String) -> bool { match v2_rt::map_get(&type_summaries, enum_name) { - Some(summary) => match (*summary.repr.clone()).clone() { - TypeRepr::EnumRepr { .. } => { - emit_map_has(summary.variant_name_set.clone(), variant_name) - } - _ => false, - }, - None => false, - } + Some(summary) => match (*summary.repr.clone()).clone() { + TypeRepr::EnumRepr { .. } => emit_map_has(summary.variant_name_set.clone(), variant_name), + _ => false, +}, + None => false, +} } -pub fn is_enum_in_summaries( - type_summaries: Rc>>, - type_name: String, -) -> bool { +pub fn is_enum_in_summaries(type_summaries: Rc>>, type_name: String) -> bool { match v2_rt::map_get(&type_summaries, type_name) { - Some(summary) => match (*summary.repr.clone()).clone() { - TypeRepr::EnumRepr { .. } => true, - _ => false, - }, - None => false, - } + Some(summary) => match (*summary.repr.clone()).clone() { + TypeRepr::EnumRepr { .. } => true, + _ => false, +}, + None => false, +} } -pub fn find_variant_parent( - type_summaries: Rc>>, - variant_name: String, - scope_enums: Rc>, -) -> Option { - Rc::new({ - let mut __result = Vec::new(); - for en in scope_enums.iter().cloned() { - if variant_belongs_to_enum(type_summaries.clone(), variant_name.clone(), en.clone()) { - __result.push(en); - } - } - __result - }) - .first() - .cloned() +pub fn find_variant_parent(type_summaries: Rc>>, variant_name: String, scope_enums: Rc>) -> Option { + Rc::new({ let mut __result = Vec::new(); for en in scope_enums.iter().cloned() { if variant_belongs_to_enum(type_summaries.clone(), variant_name.clone(), en.clone()) { __result.push(en); } } __result }).first().cloned() } pub fn field_value_shape_from_type_node(type_node: Rc) -> FieldValueShape { { let normed = normalize_access_type_node(type_node); - let is_optional = (normed.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { +let is_optional = (normed.return_cardinality.clone() == Cardinality::CardOptional); +if is_optional { FieldValueShape::OptionalValue } else { FieldValueShape::PlainValue } - } +} } pub fn is_tuple_type(n: &Rc) -> bool { - (((n.connective.clone() == Connective::Conj) && (n.ident_span.clone() == None)) - && ((n.children.clone().len() as i64) == 2)) + (((n.connective.clone() == Connective::Conj) && (n.ident_span.clone() == None)) && ((n.children.clone().len() as i64) == 2)) } -pub fn build_struct_field_summaries( - parent: &Rc, - source_indices: Rc>>, -) -> Rc>> { +pub fn build_struct_field_summaries(parent: &Rc, source_indices: Rc>>) -> Rc>> { { let is_pair = is_tuple_type(&parent); - Rc::new( - parent - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, pair: (i64, Rc)| { - let idx = pair.0.clone(); - let child = pair.1.clone(); - if (child.inferred.clone() == None) { - acc.clone() - } else { - { - let style = if is_pair.clone() { - if (idx.clone() == 0) { - FieldAccessStyle::TupleFirst - } else { - FieldAccessStyle::TupleSecond - } +Rc::new(parent.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, pair: (i64, Rc)| { + let idx = pair.0.clone(); +let child = pair.1.clone(); +if (child.inferred.clone() == None) { + acc.clone() + } else { + { + let style = if is_pair.clone() { + if (idx.clone() == 0) { + FieldAccessStyle::TupleFirst } else { - FieldAccessStyle::StoredField - }; - let key = authored_name_at(source_indices.clone(), &child); - v2_rt::rc_map_insert( - acc.clone(), - key.clone(), - Rc::new(FieldSummary { - access_style: style.clone(), - value_shape: field_value_shape_from_type_node(child_type_node( - &child, - )), - }), - ) - } - } - }, - ) - } + FieldAccessStyle::TupleSecond + } + } else { + FieldAccessStyle::StoredField + }; +let key = authored_name_at(source_indices.clone(), &child); +v2_rt::rc_map_insert(acc.clone(), key.clone(), Rc::new(FieldSummary { + access_style: style.clone(), + value_shape: field_value_shape_from_type_node(child_type_node(&child)), +})) +} + } +}) +} } -pub fn find_first_enum_field_node( - variants: Rc>>, - field_name: String, - source_indices: Rc>>, -) -> Option> { +pub fn find_first_enum_field_node(variants: Rc>>, field_name: String, source_indices: Rc>>) -> Option> { match variants.first().cloned() { - Some(variant) => match find_child_named(variant.clone(), field_name, source_indices) { - Some(field_child) => Some(field_child.clone()), - None => None, - }, - None => None, - } + Some(variant) => match find_child_named(variant.clone(), field_name, source_indices) { + Some(field_child) => Some(field_child.clone()), + None => None, +}, + None => None, +} } -pub fn enum_field_present_in_all_variants( - variants: Rc>>, - field_name: String, - source_indices: Rc>>, -) -> bool { - { - let mut __all = true; - for variant in variants.iter().cloned() { - if !(has_child_named(variant.clone(), field_name.clone(), source_indices.clone())) { - __all = false; - break; - } - } - __all - } +pub fn enum_field_present_in_all_variants(variants: Rc>>, field_name: String, source_indices: Rc>>) -> bool { + { let mut __all = true; for variant in variants.iter().cloned() { if !(has_child_named(variant.clone(), field_name.clone(), source_indices.clone())) { __all = false; break; } } __all } } -pub fn enum_field_type_consistent( - variants: Rc>>, - field_name: String, - expected: Rc, - source_indices: Rc>>, -) -> bool { - { - let mut __all = true; - for variant in variants.iter().cloned() { - if !(match find_child_named(variant.clone(), field_name.clone(), source_indices.clone()) - { - Some(field_child) => node_type_equals( - &child_type_node(&field_child), - &expected, - source_indices.clone(), - ), - None => false, - }) { - __all = false; - break; - } - } - __all - } +pub fn enum_field_type_consistent(variants: Rc>>, field_name: String, expected: Rc, source_indices: Rc>>) -> bool { + { let mut __all = true; for variant in variants.iter().cloned() { if !(match find_child_named(variant.clone(), field_name.clone(), source_indices.clone()) { + Some(field_child) => node_type_equals(&child_type_node(&field_child), &expected, source_indices.clone()), + None => false, +}) { __all = false; break; } } __all } } -pub fn build_enum_field_summaries( - variants: &Rc>>, - source_indices: Rc>>, -) -> Rc>> { +pub fn build_enum_field_summaries(variants: &Rc>>, source_indices: Rc>>) -> Rc>> { { let first_field_names = match variants.clone().first().cloned() { - Some(first_variant) => Rc::new({ - let mut __result = Vec::new(); - for f in first_variant.children.clone().iter().cloned() { - __result.push(authored_name_at(source_indices.clone(), &f)); - } - __result - }), - None => Rc::new(vec![]), - }; - let shared = Rc::new({ - let mut __result = Vec::new(); - for field_name in first_field_names.iter().cloned() { - if enum_field_present_in_all_variants( - variants.clone(), - field_name.clone(), - source_indices.clone(), - ) { - __result.push(field_name); - } - } - __result - }); - let consistent = Rc::new({ - let mut __result = Vec::new(); - for field_name in shared.iter().cloned() { - if match find_first_enum_field_node( - variants.clone(), - field_name.clone(), - source_indices.clone(), - ) { - Some(first_field) => enum_field_type_consistent( - variants.clone(), - field_name.clone(), - child_type_node(&first_field), - source_indices.clone(), - ), - None => false, - } { - __result.push(field_name); - } - } - __result - }); - consistent.iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, field_name: String| { - match find_first_enum_field_node( - variants.clone(), - field_name.clone(), - source_indices.clone(), - ) { - Some(first_field) => v2_rt::rc_map_insert( - acc.clone(), - field_name.clone(), - Rc::new(FieldSummary { - access_style: FieldAccessStyle::EnumAccessor, - value_shape: field_value_shape_from_type_node(child_type_node( - &first_field, - )), - }), - ), - None => acc.clone(), - } - }, - ) - } + Some(first_variant) => Rc::new({ let mut __result = Vec::new(); for f in first_variant.children.clone().iter().cloned() { __result.push(authored_name_at(source_indices.clone(), &f)); } __result }), + None => Rc::new(vec![]), +}; +let shared = Rc::new({ let mut __result = Vec::new(); for field_name in first_field_names.iter().cloned() { if enum_field_present_in_all_variants(variants.clone(), field_name.clone(), source_indices.clone()) { __result.push(field_name); } } __result }); +let consistent = Rc::new({ let mut __result = Vec::new(); for field_name in shared.iter().cloned() { if match find_first_enum_field_node(variants.clone(), field_name.clone(), source_indices.clone()) { + Some(first_field) => enum_field_type_consistent(variants.clone(), field_name.clone(), child_type_node(&first_field), source_indices.clone()), + None => false, +} { __result.push(field_name); } } __result }); +consistent.iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, field_name: String| match find_first_enum_field_node(variants.clone(), field_name.clone(), source_indices.clone()) { + Some(first_field) => v2_rt::rc_map_insert(acc.clone(), field_name.clone(), Rc::new(FieldSummary { + access_style: FieldAccessStyle::EnumAccessor, + value_shape: field_value_shape_from_type_node(child_type_node(&first_field)), +})), + None => acc.clone(), +}) +} } -pub fn build_field_type_map( - children: Rc>>, - source_indices: Rc>>, -) -> Rc> { - children.iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, child: Rc| match child - .inferred - .clone() - .as_deref() - .cloned() - { - Some(InferredNode::Resolved { node: ft, .. }) => { - let resolved_name = authored_name_at( - source_indices.clone(), - &normalize_access_type_node(ft.clone()), - ); - let ft_is_type_var = if (ft.inferred.clone() != None) { - is_type_variable(ft.inferred.clone().clone().unwrap()) - } else { - false - }; - let key = authored_name_at(source_indices.clone(), &child); - 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())) - { - v2_rt::rc_map_insert(acc.clone(), key.clone(), resolved_name.clone()) - } else { - acc.clone() - } - } - _ => acc.clone(), - }, - ) +pub fn build_field_type_map(children: Rc>>, source_indices: Rc>>) -> Rc> { + children.iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, child: Rc| match child.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: ft, .. }) => { + let resolved_name = authored_name_at(source_indices.clone(), &normalize_access_type_node(ft.clone())); +let ft_is_type_var = if (ft.inferred.clone() != None) { + is_type_variable(ft.inferred.clone().clone().unwrap()) + } else { + false + }; +let key = authored_name_at(source_indices.clone(), &child); +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())) { + v2_rt::rc_map_insert(acc.clone(), key.clone(), resolved_name.clone()) + } else { + acc.clone() + } +}, + _ => acc.clone(), +}) } -pub fn build_type_summary( - item: &Rc, - source_indices: &Rc>>, -) -> Option> { +pub fn build_type_summary(item: &Rc, source_indices: &Rc>>) -> Option> { { - if (((item.connective.clone() == Connective::NoConnective) - || (item.connective.clone() == Connective::Arrow)) - || (item.transport.clone() != None)) - { - return None; + if (((item.connective.clone() == Connective::NoConnective) || (item.connective.clone() == Connective::Arrow)) || (item.transport.clone() != None)) { + return None } - let gpn = Rc::new({ - let mut __result = Vec::new(); - for p in item.params.clone().iter().cloned() { - __result.push(param_node_name_at(p.clone(), source_indices.clone())); - } - __result - }); - let is_product = (item.connective.clone() == Connective::Conj); - let has_fn = { - let mut __found = false; - for child in item.children.clone().iter().cloned() { - if match child.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.connective.clone() == Connective::Arrow) - } - _ => false, - } { - __found = true; - break; - } - } - __found - }; - if is_product { +let gpn = Rc::new({ let mut __result = Vec::new(); for p in item.params.clone().iter().cloned() { __result.push(param_node_name_at(p.clone(), source_indices.clone())); } __result }); +let is_product = (item.connective.clone() == Connective::Conj); +let has_fn = { let mut __found = false; for child in item.children.clone().iter().cloned() { if match child.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (rt.connective.clone() == Connective::Arrow), + _ => false, +} { __found = true; break; } } __found }; +if is_product { Some(Rc::new(TypeSummary { - name: authored_name_at(source_indices.clone(), &item), - repr: Rc::new(TypeRepr::StructRepr), - field_summaries: build_struct_field_summaries(&item, source_indices.clone()), - field_type_map: build_field_type_map(item.children.clone(), source_indices.clone()), - variant_name_set: v2_rt::rc_empty_map::(), - generic_param_names: gpn, - has_fn_fields: has_fn, - })) + name: authored_name_at(source_indices.clone(), &item), + repr: Rc::new(TypeRepr::StructRepr), + field_summaries: build_struct_field_summaries(&item, source_indices.clone()), + field_type_map: build_field_type_map(item.children.clone(), source_indices.clone()), + variant_name_set: v2_rt::rc_empty_map::(), + generic_param_names: gpn, + has_fn_fields: has_fn, +})) } else { { - let unit_only = { - let mut __all = true; - for child in item.children.clone().iter().cloned() { - if !((child.children.clone().len() as i64) == 0) { - __all = false; - break; - } - } - __all - }; - Some(Rc::new(TypeSummary { - name: authored_name_at(source_indices.clone(), &item), - repr: Rc::new(TypeRepr::EnumRepr { - unit_only: unit_only, - }), - field_summaries: build_enum_field_summaries( - &item.children.clone(), - source_indices.clone(), - ), - field_type_map: v2_rt::rc_empty_map::(), - variant_name_set: item.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, child: Rc| { - v2_rt::rc_map_insert( - acc, - authored_name_at(source_indices.clone(), &child), - true, - ) - }, - ), - generic_param_names: gpn, - has_fn_fields: has_fn, - })) - } + let unit_only = { let mut __all = true; for child in item.children.clone().iter().cloned() { if !(((child.children.clone().len() as i64) == 0)) { __all = false; break; } } __all }; +Some(Rc::new(TypeSummary { + name: authored_name_at(source_indices.clone(), &item), + repr: Rc::new(TypeRepr::EnumRepr { + unit_only: unit_only, +}), + field_summaries: build_enum_field_summaries(&item.children.clone(), source_indices.clone()), + field_type_map: v2_rt::rc_empty_map::(), + variant_name_set: item.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, child: Rc| v2_rt::rc_map_insert(acc, authored_name_at(source_indices.clone(), &child), true)), + generic_param_names: gpn, + has_fn_fields: has_fn, +})) +} } - } +} } -pub fn add_emit_item_summary( - state: Rc, - item: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn add_emit_item_summary(state: Rc, item: &Rc, source_indices: &Rc>>) -> Rc { match build_type_summary(&item, &source_indices) { - Some(summary) => { - let with_variants = match (*summary.repr.clone()).clone() { - TypeRepr::EnumRepr { .. } => item.children.clone().iter().cloned().fold( - state.type_summaries.clone(), - |acc: Rc>>, variant: Rc| { - if ((variant.children.clone().len() as i64) > 0) { - { - let v_has_fn = { - let mut __found = false; - for vc in variant.children.clone().iter().cloned() { - if match vc.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (rt.connective.clone() == Connective::Arrow) - } - _ => false, - } { - __found = true; - break; - } - } - __found - }; - let vname = authored_name_at(source_indices.clone(), &variant); - v2_rt::rc_map_insert( - acc.clone(), - vname.clone(), - Rc::new(TypeSummary { - name: vname.clone(), - repr: Rc::new(TypeRepr::StructRepr), - field_summaries: build_struct_field_summaries( - &variant, - source_indices.clone(), - ), - field_type_map: build_field_type_map( - variant.children.clone(), - source_indices.clone(), - ), - variant_name_set: v2_rt::rc_empty_map::(), - generic_param_names: Rc::new(vec![]), - has_fn_fields: v_has_fn.clone(), - }), - ) - } - } else { - acc.clone() - } - }, - ), - _ => state.type_summaries.clone(), - }; - let next_summaries = - v2_rt::rc_map_insert(with_variants, summary.name.clone(), summary.clone()); - Rc::new(EmitInfoBuildState { - type_summaries: next_summaries, - }) - } - None => state, - } + Some(summary) => { + let with_variants = match (*summary.repr.clone()).clone() { + TypeRepr::EnumRepr { .. } => item.children.clone().iter().cloned().fold(state.type_summaries.clone(), |acc: Rc>>, variant: Rc| if ((variant.children.clone().len() as i64) > 0) { + { + let v_has_fn = { let mut __found = false; for vc in variant.children.clone().iter().cloned() { if match vc.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (rt.connective.clone() == Connective::Arrow), + _ => false, +} { __found = true; break; } } __found }; +let vname = authored_name_at(source_indices.clone(), &variant); +v2_rt::rc_map_insert(acc.clone(), vname.clone(), Rc::new(TypeSummary { + name: vname.clone(), + repr: Rc::new(TypeRepr::StructRepr), + field_summaries: build_struct_field_summaries(&variant, source_indices.clone()), + field_type_map: build_field_type_map(variant.children.clone(), source_indices.clone()), + variant_name_set: v2_rt::rc_empty_map::(), + generic_param_names: Rc::new(vec![]), + has_fn_fields: v_has_fn.clone(), +})) +} + } else { + acc.clone() + }), + _ => state.type_summaries.clone(), +}; +let next_summaries = v2_rt::rc_map_insert(with_variants, summary.name.clone(), summary.clone()); +Rc::new(EmitInfoBuildState { + type_summaries: next_summaries, +}) +}, + None => state, +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_env.rs b/src/v2/stage0/src/v2_compiler_infer_env.rs index 0fce851de90..d3dc148b5eb 100644 --- a/src/v2/stage0/src/v2_compiler_infer_env.rs +++ b/src/v2/stage0/src/v2_compiler_infer_env.rs @@ -1,18 +1,15 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_env -use crate::std_induction::RecursionShape::{DirectRecursion, ListRecursion, OptionalRecursion}; -use crate::std_induction::SubValueRelation::{PreservedValue, SubValueUnknown}; -pub use crate::std_induction::{InductiveField, RecursionShape, SubValueRelation}; -use crate::v2_rt; -pub use crate::v2_std_core::{ - authored_name_at, empty_intern_table, intern, intern_find, intern_str, merge_intern_tables, - source_text_at, InternTable, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, NewlineIndex, InternTable, empty_intern_table, merge_intern_tables, intern, intern_find, intern_str, source_text_at, authored_name_at}; +pub use crate::std_induction::{InductiveField, RecursionShape, SubValueRelation}; +use crate::std_induction::RecursionShape::{DirectRecursion, ListRecursion, OptionalRecursion}; +use crate::std_induction::SubValueRelation::{SubValueUnknown, PreservedValue}; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct TypeEnv { @@ -33,30 +30,30 @@ pub struct TypeBinding { pub fn is_recursive_type(env: Rc, ident: i64) -> bool { match v2_rt::map_get(&env.recursive_type_set.clone(), ident) { - Some(_) => true, - _ => false, - } + Some(_) => true, + _ => false, +} } pub fn is_recursive_type_by_name(env: &Rc, name: String) -> bool { match intern_find(env.intern_table.clone(), name) { - Some(id) => is_recursive_type(env.clone(), id.clone()), - None => false, - } + Some(id) => is_recursive_type(env.clone(), id.clone()), + None => false, +} } pub fn lookup_type(env: Rc, ident: i64) -> Option> { match v2_rt::map_get(&env.bindings.clone(), ident) { - Some(binding) => Some(binding.resolved.clone()), - None => None, - } + Some(binding) => Some(binding.resolved.clone()), + None => None, +} } pub fn lookup_type_by_name(env: &Rc, name: String) -> Option> { match intern_find(env.intern_table.clone(), name) { - Some(id) => lookup_type(env.clone(), id.clone()), - None => None, - } + Some(id) => lookup_type(env.clone(), id.clone()), + None => None, +} } pub fn authored_name(env: Rc, node: Rc) -> String { @@ -65,192 +62,102 @@ pub fn authored_name(env: Rc, node: Rc) -> String { pub fn lookup_type_for(env: &Rc, node: &Rc) -> Option> { match node.ident.clone() { - Some(id) => lookup_type(env.clone(), id.clone()), - None => lookup_type_by_name(&env, authored_name(env.clone(), node.clone())), - } + Some(id) => lookup_type(env.clone(), id.clone()), + None => lookup_type_by_name(&env, authored_name(env.clone(), node.clone())), +} } pub fn is_recursive_type_for(env: &Rc, node: &Rc) -> bool { match node.ident.clone() { - Some(id) => is_recursive_type(env.clone(), id.clone()), - None => is_recursive_type_by_name(&env, authored_name(env.clone(), node.clone())), - } + Some(id) => is_recursive_type(env.clone(), id.clone()), + None => is_recursive_type_by_name(&env, authored_name(env.clone(), node.clone())), +} } pub fn inductive_fields_for(env: Rc, type_name: String) -> Rc>> { match v2_rt::map_get(&env.inductive_fields.clone(), type_name) { - Some(fields) => fields.clone(), - None => Rc::new(vec![]), - } + Some(fields) => fields.clone(), + None => Rc::new(vec![]), +} } -pub fn is_inductive_field( - env: Rc, - type_name: String, - variant_name: String, - field_name: String, -) -> bool { - { - let mut __found = false; - for f in inductive_fields_for(env, type_name).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())) - { - __found = true; - break; - } - } - __found - } +pub fn is_inductive_field(env: Rc, type_name: String, variant_name: String, field_name: String) -> bool { + { let mut __found = false; for f in inductive_fields_for(env, type_name).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())) { __found = true; break; } } __found } } -pub fn put_inductive_field( - fields: &Rc>>>>, - type_name: &String, - variant_name: String, - field_name: String, - shape: RecursionShape, -) -> Rc>>>> { +pub fn put_inductive_field(fields: &Rc>>>>, type_name: &String, variant_name: String, field_name: String, shape: RecursionShape) -> Rc>>>> { { let existing = match v2_rt::map_get(&fields, type_name.clone()) { - Some(fs) => fs.clone(), - None => Rc::new(vec![]), - }; - v2_rt::rc_map_insert( - fields.clone(), - type_name.clone(), - v2_rt::concat( - existing, - Rc::new(vec![Rc::new(InductiveField { - type_name: type_name.clone(), - variant_name: variant_name, - field_name: field_name, - shape: shape, - element_type: type_name.clone(), - })]), - ), - ) - } + Some(fs) => fs.clone(), + None => Rc::new(vec![]), +}; +v2_rt::rc_map_insert(fields.clone(), type_name.clone(), v2_rt::concat(existing, Rc::new(vec![Rc::new(InductiveField { + type_name: type_name.clone(), + variant_name: variant_name, + field_name: field_name, + shape: shape, + element_type: type_name.clone(), +})]))) +} } -pub fn put_inductive_field_cross( - fields: &Rc>>>>, - type_name: &String, - variant_name: String, - field_name: String, - shape: RecursionShape, - element_type: String, -) -> Rc>>>> { +pub fn put_inductive_field_cross(fields: &Rc>>>>, type_name: &String, variant_name: String, field_name: String, shape: RecursionShape, element_type: String) -> Rc>>>> { { let existing = match v2_rt::map_get(&fields, type_name.clone()) { - Some(fs) => fs.clone(), - None => Rc::new(vec![]), - }; - v2_rt::rc_map_insert( - fields.clone(), - type_name.clone(), - v2_rt::concat( - existing, - Rc::new(vec![Rc::new(InductiveField { - type_name: type_name.clone(), - variant_name: variant_name, - field_name: field_name, - shape: shape, - element_type: element_type, - })]), - ), - ) - } -} - -pub fn merge_inductive_fields( - left: Rc>>>>, - right: &Rc>>>>, -) -> Rc>>>> { - Rc::new(v2_rt::map_keys(&right)).iter().cloned().fold( - left.clone(), - |acc: Rc>>>>, type_name: String| { - match v2_rt::map_get(&right, type_name.clone()) { - Some(incoming) => { - let existing = match v2_rt::map_get(&acc, type_name.clone()) { - Some(fs) => fs.clone(), - None => Rc::new(vec![]), - }; - v2_rt::rc_map_insert( - acc.clone(), - type_name.clone(), - v2_rt::concat(existing.clone(), incoming.clone()), - ) - } - None => acc.clone(), - } - }, - ) + Some(fs) => fs.clone(), + None => Rc::new(vec![]), +}; +v2_rt::rc_map_insert(fields.clone(), type_name.clone(), v2_rt::concat(existing, Rc::new(vec![Rc::new(InductiveField { + type_name: type_name.clone(), + variant_name: variant_name, + field_name: field_name, + shape: shape, + element_type: element_type, +})]))) +} +} + +pub fn merge_inductive_fields(left: Rc>>>>, right: &Rc>>>>) -> Rc>>>> { + Rc::new(v2_rt::map_keys(&right)).iter().cloned().fold(left.clone(), |acc: Rc>>>>, type_name: String| match v2_rt::map_get(&right, type_name.clone()) { + Some(incoming) => { + let existing = match v2_rt::map_get(&acc, type_name.clone()) { + Some(fs) => fs.clone(), + None => Rc::new(vec![]), +}; +v2_rt::rc_map_insert(acc.clone(), type_name.clone(), v2_rt::concat(existing.clone(), incoming.clone())) +}, + None => acc.clone(), +}) } -pub fn inductive_fields_list_to_map( - fields: Rc>>, -) -> Rc>>>> { - fields.iter().cloned().fold( - v2_rt::rc_empty_map::>>>(), - |acc: Rc>>>>, field: Rc| { - let existing = match v2_rt::map_get(&acc, field.type_name.clone()) { - Some(fs) => fs.clone(), - None => Rc::new(vec![]), - }; - v2_rt::rc_map_insert( - acc.clone(), - field.type_name.clone(), - v2_rt::concat(existing.clone(), Rc::new(vec![field.clone()])), - ) - }, - ) +pub fn inductive_fields_list_to_map(fields: Rc>>) -> Rc>>>> { + fields.iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |acc: Rc>>>>, field: Rc| { + let existing = match v2_rt::map_get(&acc, field.type_name.clone()) { + Some(fs) => fs.clone(), + None => Rc::new(vec![]), +}; +v2_rt::rc_map_insert(acc.clone(), field.type_name.clone(), v2_rt::concat(existing.clone(), Rc::new(vec![field.clone()]))) +}) } pub fn merge_envs(envs: &Rc>>) -> Rc { { - let merged_bindings = envs.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, env: Rc| { - v2_rt::rc_map_merge(acc, env.bindings.clone()) - }, - ); - let merged_recursive = envs - .clone() - .iter() - .cloned() - .fold(Rc::new(vec![]), |acc: _, env: Rc| { - v2_rt::concat(acc, env.recursive_types.clone()) - }); - let merged_recursive_set = envs.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, env: Rc| { - v2_rt::rc_map_merge(acc, env.recursive_type_set.clone()) - }, - ); - let merged_inductive_fields = envs.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>>>(), - |acc: Rc>>>>, env: Rc| { - merge_inductive_fields(acc, &env.inductive_fields.clone()) - }, - ); - let merged_source_indices = envs.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, env: Rc| { - v2_rt::rc_map_merge(acc, env.source_indices.clone()) - }, - ); - let merged_intern_table = match envs.clone().first().cloned() { - Some(first_env) => first_env.intern_table.clone(), - None => empty_intern_table(), - }; - Rc::new(TypeEnv { - bindings: merged_bindings, - recursive_types: merged_recursive, - recursive_type_set: merged_recursive_set, - inductive_fields: merged_inductive_fields, - source_indices: merged_source_indices, - intern_table: merged_intern_table, - }) - } + let merged_bindings = envs.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, env: Rc| v2_rt::rc_map_merge(acc, env.bindings.clone())); +let merged_recursive = envs.clone().iter().cloned().fold(Rc::new(vec![]), |acc: _, env: Rc| v2_rt::concat(acc, env.recursive_types.clone())); +let merged_recursive_set = envs.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, env: Rc| v2_rt::rc_map_merge(acc, env.recursive_type_set.clone())); +let merged_inductive_fields = envs.clone().iter().cloned().fold(v2_rt::rc_empty_map::>>>(), |acc: Rc>>>>, env: Rc| merge_inductive_fields(acc, &env.inductive_fields.clone())); +let merged_source_indices = envs.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, env: Rc| v2_rt::rc_map_merge(acc, env.source_indices.clone())); +let merged_intern_table = match envs.clone().first().cloned() { + Some(first_env) => first_env.intern_table.clone(), + None => empty_intern_table(), +}; +Rc::new(TypeEnv { + bindings: merged_bindings, + recursive_types: merged_recursive, + recursive_type_set: merged_recursive_set, + inductive_fields: merged_inductive_fields, + source_indices: merged_source_indices, + intern_table: merged_intern_table, +}) +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_items.rs b/src/v2/stage0/src/v2_compiler_infer_items.rs index 59c2ce01482..774ee8dfc9e 100644 --- a/src/v2/stage0/src/v2_compiler_infer_items.rs +++ b/src/v2/stage0/src/v2_compiler_infer_items.rs @@ -1,27 +1,23 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_items -use self::ItemKind::*; -pub use crate::std_induction::SubValueRelation; -use crate::std_induction::SubValueRelation::SubValueUnknown; -pub use crate::std_types::SourceSpan; -pub use crate::v2_compiler_infer_emit_info::EmitGraphInfo; -pub use crate::v2_compiler_infer_env::{TypeBinding, TypeEnv}; -pub use crate::v2_compiler_infer_sigs::ResolvedFuncEnv; -pub use crate::v2_compiler_infer_types::child_type_node; -use crate::v2_rt; -use crate::v2_std_core::Cardinality::Required; -use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; -pub use crate::v2_std_core::{ - authored_name_at, expr_has_non_tail_self_call, expr_has_self_call, make_field_node, - make_param_node, no_span, node_name_span, param_node_name_at, param_node_type_expr, - Cardinality, Connective, ErrorNode, InferredNode, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan}; +pub use crate::v2_std_core::{Node, ErrorNode, make_param_node, param_node_name_at, param_node_type_expr, make_field_node, InferredNode, Cardinality, expr_has_self_call, expr_has_non_tail_self_call, Connective, node_name_span, no_span, NewlineIndex, authored_name_at}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::Cardinality::{Required}; +use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; +pub use crate::v2_compiler_infer_types::{child_type_node}; +pub use crate::std_induction::{SubValueRelation}; +use crate::std_induction::SubValueRelation::{SubValueUnknown}; +pub use crate::v2_compiler_infer_env::{TypeEnv, TypeBinding}; +pub use crate::v2_compiler_infer_sigs::{ResolvedFuncEnv}; +pub use crate::v2_compiler_infer_emit_info::{EmitGraphInfo}; +use self::ItemKind::*; #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] @@ -70,92 +66,46 @@ pub struct ResolvedGraph { pub emit_graph_info: Rc, } -pub fn inferred_to_outputs( - inferred: &Option>, - span: Rc, - source_indices: Rc>>, -) -> Rc>> { +pub fn inferred_to_outputs(inferred: &Option>, span: Rc, source_indices: Rc>>) -> Rc>> { if (inferred.clone() == None) { Rc::new(vec![]) } else { match (*inferred.clone().unwrap()).clone() { - InferredNode::CompilerError { .. } => Rc::new(vec![]), - InferredNode::TypeVariable { .. } => Rc::new(vec![]), - InferredNode::Resolved { node: rt, .. } => { - let has_structure = (rt.connective.clone() != Connective::NoConnective); - if has_structure { - { - let is_product = (rt.connective.clone() == Connective::Conj); - if is_product { - if (rt.ident_span.clone() == None) { - Rc::new({ - let mut __result = Vec::new(); - for child in rt.children.clone().iter().cloned() { - __result.push({ - let child_type = child_type_node(&child); - make_field_node( - &authored_name_at(source_indices.clone(), &child), - child_type.clone(), - Cardinality::Required, - None, - None, - span.clone(), - node_name_span(&child), - ) - }); - } - __result - }) - } else { - Rc::new(vec![make_field_node( - &"value".to_string(), - rt.clone(), - Cardinality::Required, - None, - None, - span.clone(), - no_span(), - )]) - } + InferredNode::CompilerError { .. } => Rc::new(vec![]), + InferredNode::TypeVariable { .. } => Rc::new(vec![]), + InferredNode::Resolved { node: rt, .. } => { + let has_structure = (rt.connective.clone() != Connective::NoConnective); +if has_structure { + { + let is_product = (rt.connective.clone() == Connective::Conj); +if is_product { + if (rt.ident_span.clone() == None) { + Rc::new({ let mut __result = Vec::new(); for child in rt.children.clone().iter().cloned() { __result.push({ + let child_type = child_type_node(&child); +make_field_node(&authored_name_at(source_indices.clone(), &child), child_type.clone(), Cardinality::Required, None, None, span.clone(), node_name_span(&child)) +}); } __result }) } else { - Rc::new(vec![make_field_node( - &"value".to_string(), - rt.clone(), - Cardinality::Required, - None, - None, - span.clone(), - no_span(), - )]) + Rc::new(vec![make_field_node(&"value".to_string(), rt.clone(), Cardinality::Required, None, None, span.clone(), no_span())]) } - } - } else { - if ((rt.connective.clone() == Connective::Conj) - && ((rt.children.clone().len() as i64) == 0)) - { - Rc::new(vec![]) } else { - Rc::new(vec![make_field_node( - &"value".to_string(), - rt.clone(), - Cardinality::Required, - None, - None, - span.clone(), - no_span(), - )]) + Rc::new(vec![make_field_node(&"value".to_string(), rt.clone(), Cardinality::Required, None, None, span.clone(), no_span())]) } +} + } else { + if ((rt.connective.clone() == Connective::Conj) && ((rt.children.clone().len() as i64) == 0)) { + Rc::new(vec![]) + } else { + Rc::new(vec![make_field_node(&"value".to_string(), rt.clone(), Cardinality::Required, None, None, span.clone(), no_span())]) } } - } +}, +} } } pub fn item_kind(item: &Rc) -> ItemKind { { - let kind = if ((item.connective.clone() != Connective::NoConnective) - && (item.transport.clone() == None)) - { + let kind = if ((item.connective.clone() != Connective::NoConnective) && (item.transport.clone() == None)) { ItemKind::TypeItem } else { if (item.transport.clone() != None) { @@ -180,38 +130,24 @@ pub fn item_kind(item: &Rc) -> ItemKind { } } }; - kind - } +kind +} } -pub fn variant_locals_from_items( - items: Rc>>, - init: Rc>>, - source_indices: Rc>>, -) -> Rc>> { - items.iter().cloned().fold( - init, - |acc: Rc>>, item: Rc| { - let is_coproduct = (item.connective.clone() == Connective::Disj); - if is_coproduct.clone() { - item.children.clone().iter().cloned().fold( - acc.clone(), - |vacc: Rc>>, child: Rc| { - let child_name = authored_name_at(source_indices.clone(), &child); - v2_rt::rc_map_insert( - vacc, - child_name.clone(), - Rc::new(TypeBinding { - name: child_name.clone(), - resolved: item.clone(), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ) - }, - ) - } else { - acc.clone() - } - }, - ) +pub fn variant_locals_from_items(items: Rc>>, init: Rc>>, source_indices: Rc>>) -> Rc>> { + items.iter().cloned().fold(init, |acc: Rc>>, item: Rc| { + let is_coproduct = (item.connective.clone() == Connective::Disj); +if is_coproduct.clone() { + item.children.clone().iter().cloned().fold(acc.clone(), |vacc: Rc>>, child: Rc| { + let child_name = authored_name_at(source_indices.clone(), &child); +v2_rt::rc_map_insert(vacc, child_name.clone(), Rc::new(TypeBinding { + name: child_name.clone(), + resolved: item.clone(), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})) +}) + } else { + acc.clone() + } +}) } diff --git a/src/v2/stage0/src/v2_compiler_infer_lookup.rs b/src/v2/stage0/src/v2_compiler_infer_lookup.rs index 9b5cdb6a1fc..8acb05ae1b6 100644 --- a/src/v2/stage0/src/v2_compiler_infer_lookup.rs +++ b/src/v2/stage0/src/v2_compiler_infer_lookup.rs @@ -1,53 +1,34 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_lookup -use crate::std_algebra::AlgebraTypeTemplate::{ContainerOf, ReceiverSelf}; -use crate::std_algebra::CollectionSizeEffect::*; -use crate::std_algebra::ContainerSource::{Named, SameAsReceiver}; -use crate::std_algebra::CostShape::*; -pub use crate::std_algebra::{ - algebra_templates_for_profile, kernel_algebra_profile, AlgebraFieldTemplate, - AlgebraTypeTemplate, CollectionSizeEffect, ContainerSource, CostShape, -}; -pub use crate::v2_compiler_infer_emit_info::{ - build_enum_field_summaries, build_struct_field_summaries, -}; -pub use crate::v2_compiler_infer_env::{ - authored_name, is_recursive_type, lookup_type, lookup_type_for, TypeBinding, TypeEnv, -}; -pub use crate::v2_compiler_infer_service::{ - check_service_method_call_node, OpEntry, ServiceMethodResult, -}; -pub use crate::v2_compiler_infer_sigs::{ResolvedFuncEnv, ResolvedFuncSig}; -pub use crate::v2_compiler_infer_types::{ - child_type_node, emit_map_has, enrich_kernel_type, method_receiver_element_node, - node_is_keyed_collection, nominal_type_ref, normalize_access_type_node, -}; -use crate::v2_rt; -use crate::v2_std_core::Cardinality::{CardOptional, Required}; -use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; -use crate::v2_std_core::FieldAccessStyle::OptionalUnwrap; -use crate::v2_std_core::FieldValueShape::{OptionalValue, PlainValue}; -use crate::v2_std_core::InferredNode::{Resolved, TypeVariable}; -use crate::v2_std_core::MethodSemantics::{ - AlgebraMethodSemantics, PlainMethodSemantics, ServiceMethodSemantics, -}; -pub use crate::v2_std_core::{ - authored_name_at, find_child_named, has_child_named, param_node_type_expr, - with_optional_cardinality, with_required_cardinality, Cardinality, Connective, ErrorNode, - FieldAccessStyle, FieldSummary, FieldValueShape, InferredNode, MethodSemantics, NewlineIndex, - Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, param_node_type_expr, authored_name_at, NewlineIndex, find_child_named, has_child_named, InferredNode, Cardinality, MethodSemantics, FieldAccessStyle, FieldValueShape, FieldSummary, with_optional_cardinality, with_required_cardinality, Connective, ErrorNode}; +use crate::v2_std_core::InferredNode::{Resolved, TypeVariable}; +use crate::v2_std_core::Cardinality::{Required, CardOptional}; +use crate::v2_std_core::MethodSemantics::{PlainMethodSemantics, AlgebraMethodSemantics, ServiceMethodSemantics}; +use crate::v2_std_core::FieldAccessStyle::{OptionalUnwrap}; +use crate::v2_std_core::FieldValueShape::{PlainValue, OptionalValue}; +use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; +pub use crate::std_algebra::{CollectionSizeEffect, CostShape, AlgebraFieldTemplate, AlgebraTypeTemplate, ContainerSource, kernel_algebra_profile, algebra_templates_for_profile}; +use crate::std_algebra::AlgebraTypeTemplate::{ReceiverSelf, ContainerOf}; +use crate::std_algebra::ContainerSource::{SameAsReceiver, Named}; +use crate::std_algebra::CollectionSizeEffect::*; +use crate::std_algebra::CostShape::*; +pub use crate::v2_compiler_infer_types::{child_type_node, nominal_type_ref, normalize_access_type_node, node_is_keyed_collection, method_receiver_element_node, emit_map_has, enrich_kernel_type}; +pub use crate::v2_compiler_infer_env::{TypeEnv, TypeBinding, authored_name, is_recursive_type, lookup_type, lookup_type_for}; +pub use crate::v2_compiler_infer_emit_info::{build_struct_field_summaries, build_enum_field_summaries}; +pub use crate::v2_compiler_infer_sigs::{ResolvedFuncSig, ResolvedFuncEnv}; +pub use crate::v2_compiler_infer_service::{OpEntry, ServiceMethodResult, check_service_method_call_node}; pub fn is_type_variable(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::TypeVariable { .. } => true, - _ => false, - } + InferredNode::TypeVariable { .. } => true, + _ => false, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -57,296 +38,221 @@ pub struct KnownMethodResolution { pub diagnostics: Rc>>, } -pub fn lookup_in_scope( - locals: Rc>>, - name: String, -) -> Option> { +pub fn lookup_in_scope(locals: Rc>>, name: String) -> Option> { match v2_rt::map_get(&locals, name) { - Some(binding) => Some(binding.resolved.clone()), - None => None, - } + Some(binding) => Some(binding.resolved.clone()), + None => None, +} } pub fn lookup_func_sig(func_env: Rc, name: String) -> Option> { v2_rt::map_get(&func_env.signatures.clone(), name) } -pub fn lookup_field_type_node( - n: &Rc, - field_name: &String, - source_indices: Rc>>, -) -> Option> { +pub fn lookup_field_type_node(n: &Rc, field_name: &String, source_indices: Rc>>) -> Option> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { - { - let inner = with_required_cardinality(&n); - if (field_name.clone().as_str() == "value".to_string().as_str()) { - Some(inner) - } else { - match lookup_field_type_node(&inner, &field_name, source_indices) { - Some(inner_result) => Some(with_optional_cardinality(&inner_result)), - None => None, + { + let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); +if is_optional { + { + let inner = with_required_cardinality(&n); +if (field_name.clone().as_str() == "value".to_string().as_str()) { + Some(inner) + } else { + match lookup_field_type_node(&inner, &field_name, source_indices) { + Some(inner_result) => Some(with_optional_cardinality(&inner_result)), + None => None, +} } - } - } - } else { - { - let has_structure = (n.connective.clone() != Connective::NoConnective); - if has_structure { - { - let is_product = (n.connective.clone() == Connective::Conj); - if is_product { - match find_child_named(n.clone(), field_name.clone(), source_indices) { - Some(field_child) => Some(child_type_node(&field_child)), - None => None, +} + } else { + { + let has_structure = (n.connective.clone() != Connective::NoConnective); +if has_structure { + { + let is_product = (n.connective.clone() == Connective::Conj); +if is_product { + match find_child_named(n.clone(), field_name.clone(), source_indices) { + Some(field_child) => Some(child_type_node(&field_child)), + None => None, +} + } else { + lookup_coproduct_common_field_node(&n.children.clone(), &field_name, &source_indices) } - } else { - lookup_coproduct_common_field_node( - &n.children.clone(), - &field_name, - &source_indices, - ) - } +} + } else { + None } - } else { - None - } +} } - } +} }) } -pub fn lookup_coproduct_common_field_node( - variants: &Rc>>, - field_name: &String, - source_indices: &Rc>>, -) -> Option> { +pub fn lookup_coproduct_common_field_node(variants: &Rc>>, field_name: &String, source_indices: &Rc>>) -> Option> { { - let found_in_all = { - let mut __all = true; - for v in variants.clone().iter().cloned() { - if !(has_child_named(v.clone(), field_name.clone(), source_indices.clone())) { - __all = false; - break; - } - } - __all - }; - let first_field = if found_in_all { + let found_in_all = { let mut __all = true; for v in variants.clone().iter().cloned() { if !(has_child_named(v.clone(), field_name.clone(), source_indices.clone())) { __all = false; break; } } __all }; +let first_field = if found_in_all { match variants.clone().first().cloned() { - Some(first_variant) => find_child_named( - first_variant.clone(), - field_name.clone(), - source_indices.clone(), - ), - None => None, - } + Some(first_variant) => find_child_named(first_variant.clone(), field_name.clone(), source_indices.clone()), + None => None, +} } else { None }; - match first_field { - Some(field_child) => Some(child_type_node(&field_child)), - None => None, - } - } +match first_field { + Some(field_child) => Some(child_type_node(&field_child)), + None => None, +} +} } pub fn resolve_scrutinee_type_node(env: Rc, n: Rc) -> Rc { resolve_scrutinee_type_node_seen(&env, n, &v2_rt::rc_empty_map::()) } -pub fn resolve_scrutinee_type_node_seen( - env: &Rc, - n: Rc, - seen: &Rc>, -) -> Rc { +pub fn resolve_scrutinee_type_node_seen(env: &Rc, n: Rc, seen: &Rc>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let n_is_type_var = if (n.inferred.clone() != None) { - is_type_variable(n.inferred.clone().clone().unwrap()) - } else { - false - }; - if n_is_type_var { - return n.clone(); - } - let normed = normalize_access_type_node(n.clone()); - if ((normed.connective.clone() == Connective::NoConnective) - && ((normed.children.clone().len() as i64) == 0)) { - { - let canonical = authored_name(env.clone(), normed.clone()); - if (normed.inferred.clone() != None) { - { - let next_seen = if (canonical.clone().as_str() == "".to_string().as_str()) { - seen.clone() - } else { - v2_rt::rc_map_insert(seen.clone(), canonical.clone(), true) - }; - match normed.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: target, .. }) => { - if ((((authored_name(env.clone(), target.clone()).as_str() - == canonical.clone().as_str()) - && (target.inferred.clone() == None)) - && (target.connective.clone() == Connective::NoConnective)) - && ((target.children.clone().len() as i64) == 0)) - { - normed.clone() - } else { - resolve_scrutinee_type_node_seen( - &env, - target.clone(), - &next_seen, - ) - } - } - _ => normed.clone(), - } - } - } else { - if ((canonical.clone().as_str() != "".to_string().as_str()) - && emit_map_has(seen.clone(), canonical.clone())) - { - nominal_type_ref(&canonical) - } else { + let n_is_type_var = if (n.inferred.clone() != None) { + is_type_variable(n.inferred.clone().clone().unwrap()) + } else { + false + }; +if n_is_type_var { + return n.clone() + } +let normed = normalize_access_type_node(n.clone()); +if ((normed.connective.clone() == Connective::NoConnective) && ((normed.children.clone().len() as i64) == 0)) { + { + let canonical = authored_name(env.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().as_str() == "".to_string().as_str()) { + seen.clone() + } else { + v2_rt::rc_map_insert(seen.clone(), canonical.clone(), true) + }; +match normed.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: target, .. }) => if ((((authored_name(env.clone(), target.clone()).as_str() == canonical.clone().as_str()) && (target.inferred.clone() == None)) && (target.connective.clone() == Connective::NoConnective)) && ((target.children.clone().len() as i64) == 0)) { + normed.clone() + } else { + resolve_scrutinee_type_node_seen(&env, target.clone(), &next_seen) + }, + _ => normed.clone(), +} +} + } else { + if ((canonical.clone().as_str() != "".to_string().as_str()) && emit_map_has(seen.clone(), canonical.clone())) { + nominal_type_ref(&canonical) + } else { + { + let next_seen = if (canonical.clone().as_str() == "".to_string().as_str()) { seen.clone() } else { v2_rt::rc_map_insert(seen.clone(), canonical.clone(), true) }; - match lookup_type_for(&env, &normed) { - Some(resolved) => { - if ((((authored_name(env.clone(), resolved.clone()).as_str() - == canonical.clone().as_str()) - && (resolved.inferred.clone() == None)) - && (resolved.connective.clone() - == Connective::NoConnective)) - && ((resolved.children.clone().len() as i64) == 0)) +match lookup_type_for(&env, &normed) { + Some(resolved) => if ((((authored_name(env.clone(), resolved.clone()).as_str() == canonical.clone().as_str()) && (resolved.inferred.clone() == None)) && (resolved.connective.clone() == Connective::NoConnective)) && ((resolved.children.clone().len() as i64) == 0)) { + normed.clone() + } else { { - normed.clone() - } else { - { - let result = resolve_scrutinee_type_node_seen( - &env, - resolved.clone(), - &next_seen, - ); - let is_optional = (normed.return_cardinality.clone() - == Cardinality::CardOptional); - if is_optional { - with_optional_cardinality(&result) - } else { - result - } + let result = resolve_scrutinee_type_node_seen(&env, resolved.clone(), &next_seen); +let is_optional = (normed.return_cardinality.clone() == Cardinality::CardOptional); +if is_optional { + with_optional_cardinality(&result) + } else { + result } - } - } - None => normed.clone(), - } +} + }, + None => normed.clone(), +} +} } } - } +} + } else { + normed.clone() } - } else { - normed.clone() - } +} }) } pub fn map_value_type_in_env(type_node: Rc, env: &Rc) -> Option> { { let normed = normalize_access_type_node(type_node); - let resolved = resolve_scrutinee_type_node(env.clone(), normed); - let map_type = normalize_access_type_node(resolved); - if (node_is_keyed_collection(&map_type, env.source_indices.clone()) - && ((map_type.children.clone().len() as i64) >= 2)) - { +let resolved = resolve_scrutinee_type_node(env.clone(), normed); +let map_type = normalize_access_type_node(resolved); +if (node_is_keyed_collection(&map_type, env.source_indices.clone()) && ((map_type.children.clone().len() as i64) >= 2)) { match map_type.children.clone().get(1 as usize).cloned() { - Some(value_type) => Some(value_type.clone()), - None => None, - } + Some(value_type) => Some(value_type.clone()), + None => None, +} } else { None } - } +} } pub fn map_key_type_in_env(type_node: Rc, env: &Rc) -> Option> { { let normed = normalize_access_type_node(type_node); - let resolved = resolve_scrutinee_type_node(env.clone(), normed); - let map_type = normalize_access_type_node(resolved); - if (node_is_keyed_collection(&map_type, env.source_indices.clone()) - && ((map_type.children.clone().len() as i64) >= 1)) - { +let resolved = resolve_scrutinee_type_node(env.clone(), normed); +let map_type = normalize_access_type_node(resolved); +if (node_is_keyed_collection(&map_type, env.source_indices.clone()) && ((map_type.children.clone().len() as i64) >= 1)) { match map_type.children.clone().first().cloned() { - Some(key_type) => Some(key_type.clone()), - None => None, - } + Some(key_type) => Some(key_type.clone()), + None => None, +} } else { None } - } +} } -pub fn field_summary_for_type( - base_type: Rc, - env: &Rc, - field: &String, -) -> Option> { +pub fn field_summary_for_type(base_type: Rc, env: &Rc, field: &String) -> Option> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let resolved = resolve_scrutinee_type_node(env.clone(), base_type); - let normed = normalize_access_type_node(resolved.clone()); - let normed_opt = (normed.return_cardinality.clone() == Cardinality::CardOptional); - if ((field.clone().as_str() == "value".to_string().as_str()) && normed_opt.clone()) { - Some(Rc::new(FieldSummary { - access_style: FieldAccessStyle::OptionalUnwrap, - value_shape: FieldValueShape::PlainValue, - })) - } else { - if normed_opt.clone() { - { - let inner = with_required_cardinality(&normed); - match field_summary_for_type(inner, &env, &field) { - Some(inner_summary) => Some(Rc::new(FieldSummary { - access_style: inner_summary.access_style.clone(), - value_shape: FieldValueShape::OptionalValue, - })), - None => None, - } - } + { + let resolved = resolve_scrutinee_type_node(env.clone(), base_type); +let normed = normalize_access_type_node(resolved.clone()); +let normed_opt = (normed.return_cardinality.clone() == Cardinality::CardOptional); +if ((field.clone().as_str() == "value".to_string().as_str()) && normed_opt.clone()) { + Some(Rc::new(FieldSummary { + access_style: FieldAccessStyle::OptionalUnwrap, + value_shape: FieldValueShape::PlainValue, +})) } else { - { - let no_structure = (resolved.connective.clone() == Connective::NoConnective); - if no_structure { - None - } else { - { - let is_product = (resolved.connective.clone() == Connective::Conj); - if is_product { - v2_rt::map_get( - &build_struct_field_summaries( - &resolved, - env.source_indices.clone(), - ), - field.clone(), - ) - } else { - v2_rt::map_get( - &build_enum_field_summaries( - &resolved.children.clone(), - env.source_indices.clone(), - ), - field.clone(), - ) - } + if normed_opt.clone() { + { + let inner = with_required_cardinality(&normed); +match field_summary_for_type(inner, &env, &field) { + Some(inner_summary) => Some(Rc::new(FieldSummary { + access_style: inner_summary.access_style.clone(), + value_shape: FieldValueShape::OptionalValue, +})), + None => None, +} +} + } else { + { + let no_structure = (resolved.connective.clone() == Connective::NoConnective); +if no_structure { + None + } else { + { + let is_product = (resolved.connective.clone() == Connective::Conj); +if is_product { + v2_rt::map_get(&build_struct_field_summaries(&resolved, env.source_indices.clone()), field.clone()) + } else { + v2_rt::map_get(&build_enum_field_summaries(&resolved.children.clone(), env.source_indices.clone()), field.clone()) + } +} } - } +} } } - } +} }) } @@ -365,199 +271,136 @@ pub struct StructuralMethodLookup { pub kernel_diagnostics: Rc>>, } -pub fn lookup_field_in_product( - product: Rc, - method_name: String, - source_indices: Rc>>, -) -> Option> { +pub fn lookup_field_in_product(product: Rc, method_name: String, source_indices: Rc>>) -> Option> { { - let matching = Rc::new({ - let mut __result = Vec::new(); - for c in product.children.clone().iter().cloned() { - if (authored_name_at(source_indices.clone(), &c).as_str() - == method_name.clone().as_str()) - { - __result.push(c); - } - } - __result - }); - match matching.first().cloned() { - Some(field) => match field.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - if ((rt.params.clone().len() as i64) > 0) { - match rt.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: return_type, .. - }) => Some(Rc::new(MethodFieldResult { - field_node: field.clone(), - result_type: return_type.clone(), - size_effect: None, - cost_shape: None, - algebra_template: None, - })), - _ => Some(Rc::new(MethodFieldResult { - field_node: field.clone(), - result_type: rt.clone(), - size_effect: None, - cost_shape: None, - algebra_template: None, - })), - } - } else { - Some(Rc::new(MethodFieldResult { - field_node: field.clone(), - result_type: rt.clone(), - size_effect: None, - cost_shape: None, - algebra_template: None, - })) - } - } - _ => None, - }, - None => None, - } - } + let matching = Rc::new({ let mut __result = Vec::new(); for c in product.children.clone().iter().cloned() { if (authored_name_at(source_indices.clone(), &c).as_str() == method_name.clone().as_str()) { __result.push(c); } } __result }); +match matching.first().cloned() { + Some(field) => match field.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => if ((rt.params.clone().len() as i64) > 0) { + match rt.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: return_type, .. }) => Some(Rc::new(MethodFieldResult { + field_node: field.clone(), + result_type: return_type.clone(), + size_effect: None, + cost_shape: None, + algebra_template: None, +})), + _ => Some(Rc::new(MethodFieldResult { + field_node: field.clone(), + result_type: rt.clone(), + size_effect: None, + cost_shape: None, + algebra_template: None, +})), +} + } else { + Some(Rc::new(MethodFieldResult { + field_node: field.clone(), + result_type: rt.clone(), + size_effect: None, + cost_shape: None, + algebra_template: None, +})) + }, + _ => None, +}, + None => None, +} +} } -pub fn lookup_structural_method( - receiver_type: &Rc, - method_name: &String, - source_indices: &Rc>>, -) -> Rc { +pub fn lookup_structural_method(receiver_type: &Rc, method_name: &String, source_indices: &Rc>>) -> Rc { { let is_product = (receiver_type.connective.clone() == Connective::Conj); - if is_product { +if is_product { { - let direct = lookup_field_in_product( - receiver_type.clone(), - method_name.clone(), - source_indices.clone(), - ); - Rc::new(StructuralMethodLookup { - resolution: direct, - kernel_diagnostics: Rc::new(vec![]), - }) - } + let direct = lookup_field_in_product(receiver_type.clone(), method_name.clone(), source_indices.clone()); +Rc::new(StructuralMethodLookup { + resolution: direct, + kernel_diagnostics: Rc::new(vec![]), +}) +} } else { { - let enriched = enrich_kernel_type( - &authored_name_at(source_indices.clone(), &receiver_type), - &receiver_type, - source_indices.clone(), - ); - if ((enriched.ty.clone().connective.clone() == Connective::Conj) - && ((enriched.ty.clone().children.clone().len() as i64) > 0)) - { + let enriched = enrich_kernel_type(&authored_name_at(source_indices.clone(), &receiver_type), &receiver_type, source_indices.clone()); +if ((enriched.ty.clone().connective.clone() == Connective::Conj) && ((enriched.ty.clone().children.clone().len() as i64) > 0)) { { - let base_result = lookup_field_in_product( - enriched.ty.clone(), - method_name.clone(), - source_indices.clone(), - ); - match base_result.clone() { - Some(mfr) => { - let profile = v2_rt::map_get( - &kernel_algebra_profile(), - authored_name_at(source_indices.clone(), &receiver_type), - ); - let template_match = match profile { - Some(p) => { - let templates = algebra_templates_for_profile(p.clone()); - Rc::new({ - let mut __result = Vec::new(); - for t in templates.iter().cloned() { - if (t.name.clone().as_str() - == method_name.clone().as_str()) - { - __result.push(t); - } - } - __result - }) - .first() - .cloned() - } - None => None, - }; - let resolution = match template_match { - Some(t) => Some(Rc::new(MethodFieldResult { - field_node: mfr.field_node.clone(), - result_type: mfr.result_type.clone(), - size_effect: t.size_effect.clone(), - cost_shape: t.cost_shape.clone(), - algebra_template: Some(t.clone()), - })), - None => base_result.clone(), - }; - Rc::new(StructuralMethodLookup { - resolution: resolution, - kernel_diagnostics: enriched.diagnostics.clone(), - }) - } - None => Rc::new(StructuralMethodLookup { - resolution: None, - kernel_diagnostics: enriched.diagnostics.clone(), - }), - } - } + let base_result = lookup_field_in_product(enriched.ty.clone(), method_name.clone(), source_indices.clone()); +match base_result.clone() { + Some(mfr) => { + let profile = v2_rt::map_get(&kernel_algebra_profile(), authored_name_at(source_indices.clone(), &receiver_type)); +let template_match = match profile { + Some(p) => { + let templates = algebra_templates_for_profile(p.clone()); +Rc::new({ let mut __result = Vec::new(); for t in templates.iter().cloned() { if (t.name.clone().as_str() == method_name.clone().as_str()) { __result.push(t); } } __result }).first().cloned() +}, + None => None, +}; +let resolution = match template_match { + Some(t) => Some(Rc::new(MethodFieldResult { + field_node: mfr.field_node.clone(), + result_type: mfr.result_type.clone(), + size_effect: t.size_effect.clone(), + cost_shape: t.cost_shape.clone(), + algebra_template: Some(t.clone()), +})), + None => base_result.clone(), +}; +Rc::new(StructuralMethodLookup { + resolution: resolution, + kernel_diagnostics: enriched.diagnostics.clone(), +}) +}, + None => Rc::new(StructuralMethodLookup { + resolution: None, + kernel_diagnostics: enriched.diagnostics.clone(), +}), +} +} } else { Rc::new(StructuralMethodLookup { - resolution: None, - kernel_diagnostics: enriched.diagnostics.clone(), - }) + resolution: None, + kernel_diagnostics: enriched.diagnostics.clone(), +}) } - } +} } - } +} } -pub fn resolve_known_method_node( - receiver: Rc, - receiver_type: &Rc, - method_name: &String, - fold_accumulator_type: Option>, - service_registry: Rc>>>>, - source_indices: &Rc>>, -) -> Rc { +pub fn resolve_known_method_node(receiver: Rc, receiver_type: &Rc, method_name: &String, fold_accumulator_type: Option>, service_registry: Rc>>>>, source_indices: &Rc>>) -> Rc { { let tier0 = lookup_structural_method(&receiver_type, &method_name, &source_indices); - match tier0.resolution.clone() { - Some(mfr) => { - let semantics = Rc::new(MethodSemantics::AlgebraMethodSemantics { - method_def: mfr.field_node.clone(), - fold_accumulator_type: fold_accumulator_type, - size_effect: mfr.size_effect.clone(), - cost_shape: mfr.cost_shape.clone(), - algebra_template: mfr.algebra_template.clone(), - }); - Rc::new(KnownMethodResolution { - semantics: Some(semantics), - result_type: Some(mfr.result_type.clone()), - diagnostics: tier0.kernel_diagnostics.clone(), - }) - } - None => match check_service_method_call_node( - &receiver_type, - method_name.clone(), - service_registry, - source_indices.clone(), - ) { - Some(svc_result) => Rc::new(KnownMethodResolution { - semantics: Some(Rc::new(MethodSemantics::ServiceMethodSemantics { - service_name: authored_name_at(source_indices.clone(), &receiver_type), - op_params: svc_result.op_params.clone(), - })), - result_type: Some(svc_result.result_type.clone()), - diagnostics: tier0.kernel_diagnostics.clone(), - }), - None => Rc::new(KnownMethodResolution { - semantics: None, - result_type: None, - diagnostics: tier0.kernel_diagnostics.clone(), - }), - }, - } - } +match tier0.resolution.clone() { + Some(mfr) => { + let semantics = Rc::new(MethodSemantics::AlgebraMethodSemantics { + method_def: mfr.field_node.clone(), + fold_accumulator_type: fold_accumulator_type, + size_effect: mfr.size_effect.clone(), + cost_shape: mfr.cost_shape.clone(), + algebra_template: mfr.algebra_template.clone(), +}); +Rc::new(KnownMethodResolution { + semantics: Some(semantics), + result_type: Some(mfr.result_type.clone()), + diagnostics: tier0.kernel_diagnostics.clone(), +}) +}, + None => match check_service_method_call_node(&receiver_type, method_name.clone(), service_registry, source_indices.clone()) { + Some(svc_result) => Rc::new(KnownMethodResolution { + semantics: Some(Rc::new(MethodSemantics::ServiceMethodSemantics { + service_name: authored_name_at(source_indices.clone(), &receiver_type), + op_params: svc_result.op_params.clone(), +})), + result_type: Some(svc_result.result_type.clone()), + diagnostics: tier0.kernel_diagnostics.clone(), +}), + None => Rc::new(KnownMethodResolution { + semantics: None, + result_type: None, + diagnostics: tier0.kernel_diagnostics.clone(), +}), +}, +} +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_method.rs b/src/v2/stage0/src/v2_compiler_infer_method.rs index 9112905ccf9..18facf0ef9b 100644 --- a/src/v2/stage0/src/v2_compiler_infer_method.rs +++ b/src/v2/stage0/src/v2_compiler_infer_method.rs @@ -1,58 +1,50 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_method -pub use crate::std_types::SourceSpan; -pub use crate::v2_compiler_infer_types::{make_container_type, make_map_type}; -use crate::v2_rt; -use crate::v2_std_core::Cardinality::Required; -use crate::v2_std_core::Connective::NoConnective; -use crate::v2_std_core::ExprData::NoExprData; -use crate::v2_std_core::InferredNode::{Resolved, TypeVariable}; -pub use crate::v2_std_core::{ - bool_type, int_type, make_span, string_type, unit_type, with_optional_cardinality, Cardinality, - Connective, ErrorNode, ExprData, InferredNode, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan}; +pub use crate::v2_std_core::{Node, ErrorNode, make_span, with_optional_cardinality, unit_type, bool_type, string_type, int_type, InferredNode, Connective, Cardinality, ExprData}; +use crate::v2_std_core::InferredNode::{TypeVariable, Resolved}; +use crate::v2_std_core::Connective::{NoConnective}; +use crate::v2_std_core::Cardinality::{Required}; +use crate::v2_std_core::ExprData::{NoExprData}; +pub use crate::v2_compiler_infer_types::{make_container_type, make_map_type}; pub fn type_variable_node(id: String) -> Rc { Rc::new(Node { - name: "".to_string(), - span: make_span(0, 0), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::TypeVariable { id: id })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: "".to_string(), + span: make_span(0, 0), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::TypeVariable { + id: id, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn map_of_type_variables() -> Rc { - make_map_type( - type_variable_node("map_key".to_string()), - type_variable_node("map_value".to_string()), - ) - .ty - .clone() + make_map_type(type_variable_node("map_key".to_string()), type_variable_node("map_value".to_string())).ty.clone() } pub fn list_of_type_variable(id: String) -> Rc { - make_container_type(&"List".to_string(), type_variable_node(id)) - .ty - .clone() + make_container_type(&"List".to_string(), type_variable_node(id)).ty.clone() } pub fn list_of_element(element: Rc) -> Rc { @@ -64,86 +56,41 @@ pub fn seed_node_map(key: String, value: Rc) -> Rc Rc>> { - v2_rt::concat( - make_map_type( - type_variable_node("map_key".to_string()), - type_variable_node("map_value".to_string()), - ) - .diagnostics - .clone(), - make_container_type( - &"List".to_string(), - type_variable_node("collection_element".to_string()), - ) - .diagnostics - .clone(), - ) + v2_rt::concat(make_map_type(type_variable_node("map_key".to_string()), type_variable_node("map_value".to_string())).diagnostics.clone(), make_container_type(&"List".to_string(), type_variable_node("collection_element".to_string())).diagnostics.clone()) } pub fn builtin_function_registry() -> Rc>> { { let m = seed_node_map("count".to_string(), int_type()); - let m = v2_rt::rc_map_insert(m.clone(), "string_length".to_string(), int_type()); - let m = v2_rt::rc_map_insert(m.clone(), "code_point".to_string(), int_type()); - let m = v2_rt::rc_map_insert(m.clone(), "to_int".to_string(), int_type()); - let m = v2_rt::rc_map_insert(m.clone(), "scan_while".to_string(), int_type()); - let m = v2_rt::rc_map_insert(m.clone(), "scan_string_end".to_string(), int_type()); - let m = v2_rt::rc_map_insert(m.clone(), "scan_to_eol".to_string(), int_type()); - let m = v2_rt::rc_map_insert(m.clone(), "skip_horizontal_ws".to_string(), int_type()); - let m = v2_rt::rc_map_insert( - m.clone(), - "parse_int".to_string(), - with_optional_cardinality(&int_type()), - ); - let m = v2_rt::rc_map_insert(m.clone(), "char_at".to_string(), string_type()); - let m = v2_rt::rc_map_insert(m.clone(), "substring".to_string(), string_type()); - let m = v2_rt::rc_map_insert(m.clone(), "from_code_point".to_string(), string_type()); - let m = v2_rt::rc_map_insert(m.clone(), "chars_to_string".to_string(), string_type()); - let m = v2_rt::rc_map_insert(m.clone(), "to_string".to_string(), string_type()); - let m = v2_rt::rc_map_insert(m.clone(), "concat".to_string(), string_type()); - let m = v2_rt::rc_map_insert(m.clone(), "map_insert".to_string(), map_of_type_variables()); - let m = v2_rt::rc_map_insert(m.clone(), "map_merge".to_string(), map_of_type_variables()); - let m = v2_rt::rc_map_insert(m.clone(), "with".to_string(), map_of_type_variables()); - let m = v2_rt::rc_map_insert(m.clone(), "map_contains_key".to_string(), bool_type()); - let m = v2_rt::rc_map_insert(m.clone(), "map_has".to_string(), bool_type()); - let m = v2_rt::rc_map_insert(m.clone(), "emit_map_has".to_string(), bool_type()); - let m = v2_rt::rc_map_insert( - m.clone(), - "lookup".to_string(), - with_optional_cardinality(&type_variable_node("map_value".to_string())), - ); - let m = v2_rt::rc_map_insert( - m.clone(), - "map_get".to_string(), - with_optional_cardinality(&type_variable_node("map_value".to_string())), - ); - let m = v2_rt::rc_map_insert( - m.clone(), - "Some".to_string(), - with_optional_cardinality(&type_variable_node("some_inner".to_string())), - ); - let m = v2_rt::rc_map_insert( - m.clone(), - "map_keys".to_string(), - list_of_type_variable("collection_element".to_string()), - ); - let m = v2_rt::rc_map_insert( - m.clone(), - "map_values".to_string(), - list_of_type_variable("collection_element".to_string()), - ); - let m = v2_rt::rc_map_insert( - m.clone(), - "reverse".to_string(), - list_of_type_variable("collection_element".to_string()), - ); - let m = v2_rt::rc_map_insert( - m.clone(), - "list_push".to_string(), - list_of_type_variable("collection_element".to_string()), - ); - m.clone() - } +let m = v2_rt::rc_map_insert(m.clone(), "string_length".to_string(), int_type()); +let m = v2_rt::rc_map_insert(m.clone(), "code_point".to_string(), int_type()); +let m = v2_rt::rc_map_insert(m.clone(), "to_int".to_string(), int_type()); +let m = v2_rt::rc_map_insert(m.clone(), "scan_while".to_string(), int_type()); +let m = v2_rt::rc_map_insert(m.clone(), "scan_string_end".to_string(), int_type()); +let m = v2_rt::rc_map_insert(m.clone(), "scan_to_eol".to_string(), int_type()); +let m = v2_rt::rc_map_insert(m.clone(), "skip_horizontal_ws".to_string(), int_type()); +let m = v2_rt::rc_map_insert(m.clone(), "parse_int".to_string(), with_optional_cardinality(&int_type())); +let m = v2_rt::rc_map_insert(m.clone(), "char_at".to_string(), string_type()); +let m = v2_rt::rc_map_insert(m.clone(), "substring".to_string(), string_type()); +let m = v2_rt::rc_map_insert(m.clone(), "from_code_point".to_string(), string_type()); +let m = v2_rt::rc_map_insert(m.clone(), "chars_to_string".to_string(), string_type()); +let m = v2_rt::rc_map_insert(m.clone(), "to_string".to_string(), string_type()); +let m = v2_rt::rc_map_insert(m.clone(), "concat".to_string(), string_type()); +let m = v2_rt::rc_map_insert(m.clone(), "map_insert".to_string(), map_of_type_variables()); +let m = v2_rt::rc_map_insert(m.clone(), "map_merge".to_string(), map_of_type_variables()); +let m = v2_rt::rc_map_insert(m.clone(), "with".to_string(), map_of_type_variables()); +let m = v2_rt::rc_map_insert(m.clone(), "map_contains_key".to_string(), bool_type()); +let m = v2_rt::rc_map_insert(m.clone(), "map_has".to_string(), bool_type()); +let m = v2_rt::rc_map_insert(m.clone(), "emit_map_has".to_string(), bool_type()); +let m = v2_rt::rc_map_insert(m.clone(), "lookup".to_string(), with_optional_cardinality(&type_variable_node("map_value".to_string()))); +let m = v2_rt::rc_map_insert(m.clone(), "map_get".to_string(), with_optional_cardinality(&type_variable_node("map_value".to_string()))); +let m = v2_rt::rc_map_insert(m.clone(), "Some".to_string(), with_optional_cardinality(&type_variable_node("some_inner".to_string()))); +let m = v2_rt::rc_map_insert(m.clone(), "map_keys".to_string(), list_of_type_variable("collection_element".to_string())); +let m = v2_rt::rc_map_insert(m.clone(), "map_values".to_string(), list_of_type_variable("collection_element".to_string())); +let m = v2_rt::rc_map_insert(m.clone(), "reverse".to_string(), list_of_type_variable("collection_element".to_string())); +let m = v2_rt::rc_map_insert(m.clone(), "list_push".to_string(), list_of_type_variable("collection_element".to_string())); +m.clone() +} } pub fn infer_builtin_call_type(name: String) -> Option> { @@ -152,7 +99,7 @@ pub fn infer_builtin_call_type(name: String) -> Option> { pub fn resolve_builtin_call_type(name: String) -> Rc { match infer_builtin_call_type(name) { - Some(v) => v.clone(), - None => unit_type(), - } + Some(v) => v.clone(), + None => unit_type(), +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_patterns.rs b/src/v2/stage0/src/v2_compiler_infer_patterns.rs index 4bcb95f3031..54c48623cc0 100644 --- a/src/v2/stage0/src/v2_compiler_infer_patterns.rs +++ b/src/v2/stage0/src/v2_compiler_infer_patterns.rs @@ -1,31 +1,24 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_patterns -use self::NodeLookupStatus::*; -use self::PatternSubject::*; -pub use crate::std_types::SourceSpan; -pub use crate::v2_compiler_infer_env::{lookup_type, lookup_type_by_name, TypeEnv}; -pub use crate::v2_compiler_infer_types::{ - child_type_node, emit_map_has, extract_optional_inner_node, -}; -use crate::v2_rt; -use crate::v2_std_core::Cardinality::{CardOptional, Required}; -use crate::v2_std_core::CompilerDiagnostic::{FieldNotFound, NonExhaustiveMatch, VariantNotFound}; -use crate::v2_std_core::Connective::{Disj, NoConnective}; -use crate::v2_std_core::ExprData::NoExprData; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; -use crate::v2_std_core::LiteralValue::LitBool; -use crate::v2_std_core::MatchPattern::LitPattern; -pub use crate::v2_std_core::{ - arm_pattern, authored_name_at, error_type, find_child_named, is_compiler_error, kernel_span, - make_error_node, no_span, none_type, with_optional_cardinality, Cardinality, - CompilerDiagnostic, Connective, ErrorNode, ExprData, InferredNode, LiteralValue, MatchPattern, - NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan}; +pub use crate::v2_std_core::{Node, find_child_named, NewlineIndex, authored_name_at, ExprData, InferredNode, is_compiler_error, Cardinality, Connective, ErrorNode, make_error_node, MatchPattern, arm_pattern, LiteralValue, with_optional_cardinality, none_type, error_type, no_span, kernel_span, CompilerDiagnostic}; +use crate::v2_std_core::ExprData::{NoExprData}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::Cardinality::{Required, CardOptional}; +use crate::v2_std_core::Connective::{Disj, NoConnective}; +use crate::v2_std_core::CompilerDiagnostic::{VariantNotFound, FieldNotFound, NonExhaustiveMatch}; +use crate::v2_std_core::MatchPattern::{LitPattern}; +use crate::v2_std_core::LiteralValue::{LitBool}; +pub use crate::v2_compiler_infer_types::{child_type_node, extract_optional_inner_node, emit_map_has}; +pub use crate::v2_compiler_infer_env::{TypeEnv, lookup_type, lookup_type_by_name}; +use self::NodeLookupStatus::*; +use self::PatternSubject::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct NodeLookupResult { @@ -36,7 +29,9 @@ pub struct NodeLookupResult { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum NodeLookupStatus { - LookupResolved { node: Rc }, + LookupResolved { + node: Rc, + }, LookupFailed, } impl NodeLookupStatus { @@ -51,63 +46,69 @@ impl NodeLookupStatus { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum PatternSubject { - PatternResolved { node: Rc }, - PatternDynamic { span: Rc }, + PatternResolved { + node: Rc, + }, + PatternDynamic { + span: Rc, + }, PatternLookupBlocked, } pub fn is_type_variable(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::TypeVariable { .. } => true, - _ => false, - } + InferredNode::TypeVariable { .. } => true, + _ => false, +} } pub fn synthesize_optional_some_variant(scrut: &Rc) -> Rc { { let inner = extract_optional_inner_node(&scrut); - let value_field = Rc::new(Node { - name: "value".to_string(), - span: scrut.span.clone(), - ident_span: Some(kernel_span(&"value".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: inner })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let some_node = Rc::new(Node { - name: "Some".to_string(), - span: scrut.span.clone(), - ident_span: Some(kernel_span(&"Some".to_string())), - children: Rc::new(vec![value_field]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - some_node - } +let value_field = Rc::new(Node { + name: "value".to_string(), + span: scrut.span.clone(), + ident_span: Some(kernel_span(&"value".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: inner, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let some_node = Rc::new(Node { + name: "Some".to_string(), + span: scrut.span.clone(), + ident_span: Some(kernel_span(&"Some".to_string())), + children: Rc::new(vec![value_field]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +some_node +} } pub fn pattern_subject_from_node(n: &Rc) -> Rc { @@ -117,290 +118,179 @@ pub fn pattern_subject_from_node(n: &Rc) -> Rc { } else { false }; - if is_error { +if is_error { Rc::new(PatternSubject::PatternLookupBlocked) } else { - Rc::new(PatternSubject::PatternResolved { node: n.clone() }) + Rc::new(PatternSubject::PatternResolved { + node: n.clone(), +}) } - } +} } pub fn pattern_subject_from_inferred(n: Option>) -> Rc { match n.as_deref().cloned() { - Some(InferredNode::Resolved { node: resolved, .. }) => pattern_subject_from_node(&resolved), - _ => Rc::new(PatternSubject::PatternLookupBlocked), - } + Some(InferredNode::Resolved { node: resolved, .. }) => pattern_subject_from_node(&resolved), + _ => Rc::new(PatternSubject::PatternLookupBlocked), +} } pub fn node_lookup_resolved(node: Rc) -> Rc { Rc::new(NodeLookupResult { - status: Rc::new(NodeLookupStatus::LookupResolved { node: node }), - diagnostics: Rc::new(vec![]), - }) + status: Rc::new(NodeLookupStatus::LookupResolved { + node: node, +}), + diagnostics: Rc::new(vec![]), +}) } pub fn node_lookup_failed(diagnostics: Rc>>) -> Rc { Rc::new(NodeLookupResult { - status: Rc::new(NodeLookupStatus::LookupFailed), - diagnostics: diagnostics, - }) + status: Rc::new(NodeLookupStatus::LookupFailed), + diagnostics: diagnostics, +}) } pub fn lookup_result_subject(result: Rc) -> Rc { match (*result.status.clone()).clone() { - NodeLookupStatus::LookupResolved { node: resolved, .. } => { - pattern_subject_from_node(&resolved) - } - NodeLookupStatus::LookupFailed => Rc::new(PatternSubject::PatternLookupBlocked), - } + NodeLookupStatus::LookupResolved { node: resolved, .. } => pattern_subject_from_node(&resolved), + NodeLookupStatus::LookupFailed => Rc::new(PatternSubject::PatternLookupBlocked), +} } pub fn pattern_binding_type(subject: Rc) -> Rc { match (*subject).clone() { - PatternSubject::PatternResolved { node: resolved, .. } => resolved.clone(), - PatternSubject::PatternDynamic { .. } => error_type(), - PatternSubject::PatternLookupBlocked => error_type(), - } + PatternSubject::PatternResolved { node: resolved, .. } => resolved.clone(), + PatternSubject::PatternDynamic { .. } => error_type(), + PatternSubject::PatternLookupBlocked => error_type(), +} } -pub fn variant_not_found_result( - scrut: &Rc, - variant_name: String, - module_name: String, - source_indices: Rc>>, -) -> Rc { - node_lookup_failed(Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::VariantNotFound { - variant: variant_name, - type_name: authored_name_at(source_indices, &scrut), - span: scrut.span.clone(), - }), - module_name, - )])) +pub fn variant_not_found_result(scrut: &Rc, variant_name: String, module_name: String, source_indices: Rc>>) -> Rc { + node_lookup_failed(Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::VariantNotFound { + variant: variant_name, + type_name: authored_name_at(source_indices, &scrut), + span: scrut.span.clone(), +}), module_name)])) } -pub fn lookup_variant_in_type( - scrut: Rc, - variant_name: &String, - module_name: String, - source_indices: &Rc>>, -) -> Rc { +pub fn lookup_variant_in_type(scrut: Rc, variant_name: &String, module_name: String, source_indices: &Rc>>) -> Rc { match (*scrut).clone() { - PatternSubject::PatternLookupBlocked => node_lookup_failed(Rc::new(vec![])), - PatternSubject::PatternDynamic { - span: dynamic_span, .. - } => node_lookup_failed(Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::VariantNotFound { - variant: variant_name.clone(), - type_name: "unresolved".to_string(), - span: dynamic_span.clone(), - }), - module_name, - )])), - PatternSubject::PatternResolved { - node: scrut_node, .. - } => { - let scrut_opt = (scrut_node.return_cardinality.clone() == Cardinality::CardOptional); - if (((scrut_node.connective.clone() == Connective::NoConnective) - && ((scrut_node.children.clone().len() as i64) == 0)) - && (scrut_opt.clone() == false)) + PatternSubject::PatternLookupBlocked => node_lookup_failed(Rc::new(vec![])), + PatternSubject::PatternDynamic { span: dynamic_span, .. } => node_lookup_failed(Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::VariantNotFound { + variant: variant_name.clone(), + type_name: "unresolved".to_string(), + span: dynamic_span.clone(), +}), module_name)])), + PatternSubject::PatternResolved { node: scrut_node, .. } => { + let scrut_opt = (scrut_node.return_cardinality.clone() == Cardinality::CardOptional); +if (((scrut_node.connective.clone() == Connective::NoConnective) && ((scrut_node.children.clone().len() as i64) == 0)) && (scrut_opt.clone() == false)) { + node_lookup_failed(Rc::new(vec![])) + } else { { - node_lookup_failed(Rc::new(vec![])) - } else { - { - let direct_match = find_child_named( - scrut_node.clone(), - variant_name.clone(), - source_indices.clone(), - ); - let fallback = if (scrut_opt.clone() - && (variant_name.clone().as_str() == "Some".to_string().as_str())) - { - node_lookup_resolved(synthesize_optional_some_variant(&scrut_node)) + let direct_match = find_child_named(scrut_node.clone(), variant_name.clone(), source_indices.clone()); +let fallback = if (scrut_opt.clone() && (variant_name.clone().as_str() == "Some".to_string().as_str())) { + node_lookup_resolved(synthesize_optional_some_variant(&scrut_node)) + } else { + if (scrut_opt.clone() && (variant_name.clone().as_str() == "None".to_string().as_str())) { + node_lookup_resolved(none_type()) } else { - if (scrut_opt.clone() - && (variant_name.clone().as_str() == "None".to_string().as_str())) - { - node_lookup_resolved(none_type()) - } else { - variant_not_found_result( - &scrut_node, - variant_name.clone(), - module_name, - source_indices.clone(), - ) - } - }; - match direct_match { - Some(v) => node_lookup_resolved(v.clone()), - None => fallback, + variant_not_found_result(&scrut_node, variant_name.clone(), module_name, source_indices.clone()) } - } - } + }; +match direct_match { + Some(v) => node_lookup_resolved(v.clone()), + None => fallback, +} +} } - } +}, +} } -pub fn lookup_field_in_variant( - variant: Rc, - field_name: &String, - module_name: String, - source_indices: &Rc>>, -) -> Rc { +pub fn lookup_field_in_variant(variant: Rc, field_name: &String, module_name: String, source_indices: &Rc>>) -> Rc { match (*variant).clone() { - PatternSubject::PatternLookupBlocked => node_lookup_failed(Rc::new(vec![])), - PatternSubject::PatternDynamic { - span: dynamic_span, .. - } => node_lookup_failed(Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::FieldNotFound { - field: field_name.clone(), - type_name: "unresolved".to_string(), - span: dynamic_span.clone(), - }), - module_name, - )])), - PatternSubject::PatternResolved { - node: variant_node, .. - } => match find_child_named( - variant_node.clone(), - field_name.clone(), - source_indices.clone(), - ) { - Some(field_child) => { - let resolved = child_type_node(&field_child); - node_lookup_resolved(resolved) - } - None => node_lookup_failed(Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::FieldNotFound { - field: field_name.clone(), - type_name: authored_name_at(source_indices.clone(), &variant_node), - span: variant_node.span.clone(), - }), - module_name, - )])), - }, - } + PatternSubject::PatternLookupBlocked => node_lookup_failed(Rc::new(vec![])), + PatternSubject::PatternDynamic { span: dynamic_span, .. } => node_lookup_failed(Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::FieldNotFound { + field: field_name.clone(), + type_name: "unresolved".to_string(), + span: dynamic_span.clone(), +}), module_name)])), + PatternSubject::PatternResolved { node: variant_node, .. } => match find_child_named(variant_node.clone(), field_name.clone(), source_indices.clone()) { + Some(field_child) => { + let resolved = child_type_node(&field_child); +node_lookup_resolved(resolved) +}, + None => node_lookup_failed(Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::FieldNotFound { + field: field_name.clone(), + type_name: authored_name_at(source_indices.clone(), &variant_node), + span: variant_node.span.clone(), +}), module_name)])), +}, +} } -pub fn check_match_exhaustiveness( - scrutinee_type: &Rc, - arms: &Rc>>, - env: &Rc, - span: Rc, - module_name: String, -) -> Rc>> { +pub fn check_match_exhaustiveness(scrutinee_type: &Rc, arms: &Rc>>, env: &Rc, span: Rc, module_name: String) -> Rc>> { { - let scrut_is_optional = - (scrutinee_type.return_cardinality.clone() == Cardinality::CardOptional); - let has_structure = (scrutinee_type.connective.clone() != Connective::NoConnective); - let resolved_raw = if has_structure { + let scrut_is_optional = (scrutinee_type.return_cardinality.clone() == Cardinality::CardOptional); +let has_structure = (scrutinee_type.connective.clone() != Connective::NoConnective); +let resolved_raw = if has_structure { scrutinee_type.clone() } else { - match lookup_type_by_name( - &env, - authored_name_at(env.source_indices.clone(), &scrutinee_type), - ) { - Some(def) => def.clone(), - None => scrutinee_type.clone(), - } + match lookup_type_by_name(&env, authored_name_at(env.source_indices.clone(), &scrutinee_type)) { + Some(def) => def.clone(), + None => scrutinee_type.clone(), +} }; - let resolved = if scrut_is_optional { +let resolved = if scrut_is_optional { with_optional_cardinality(&resolved_raw) } else { resolved_raw }; - let is_coproduct = (resolved.connective.clone() == Connective::Disj); - let resolved_is_optional = - (resolved.return_cardinality.clone() == Cardinality::CardOptional); - if (is_coproduct || resolved_is_optional.clone()) { +let is_coproduct = (resolved.connective.clone() == Connective::Disj); +let resolved_is_optional = (resolved.return_cardinality.clone() == Cardinality::CardOptional); +if (is_coproduct || resolved_is_optional.clone()) { { let variant_names = if resolved_is_optional.clone() { Rc::new(vec!["Some".to_string(), "None".to_string()]) } else { - Rc::new({ - let mut __result = Vec::new(); - for c in resolved.children.clone().iter().cloned() { - __result.push(authored_name_at(env.source_indices.clone(), &c)); - } - __result - }) - }; - let has_catch_all = { - let mut __found = false; - for arm in arms.clone().iter().cloned() { - if match (*arm_pattern(arm.clone())).clone() { - MatchPattern::Wildcard => true, - MatchPattern::Bind { .. } => true, - _ => false, - } { - __found = true; - break; - } - } - __found + Rc::new({ let mut __result = Vec::new(); for c in resolved.children.clone().iter().cloned() { __result.push(authored_name_at(env.source_indices.clone(), &c)); } __result }) }; - if has_catch_all { +let has_catch_all = { let mut __found = false; for arm in arms.clone().iter().cloned() { if match (*arm_pattern(arm.clone())).clone() { + MatchPattern::Wildcard => true, + MatchPattern::Bind { .. } => true, + _ => false, +} { __found = true; break; } } __found }; +if has_catch_all { Rc::new(vec![]) } else { { - let covered_set = arms.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, arm: Rc| match (*arm_pattern( - arm.clone(), - )) - .clone() - { - MatchPattern::VariantPattern { name: n, .. } => { - v2_rt::rc_map_insert(acc.clone(), n.clone(), true) - } - MatchPattern::LitPattern { value: v, .. } => { - match (*v.clone()).clone() { - LiteralValue::LitBool { value: b, .. } => { - if b.clone() { - v2_rt::rc_map_insert( - acc.clone(), - "True".to_string(), - true, - ) - } else { - v2_rt::rc_map_insert( - acc.clone(), - "False".to_string(), - true, - ) - } - } - _ => acc.clone(), - } - } - _ => acc.clone(), - }, - ); - let uncovered = Rc::new({ - let mut __result = Vec::new(); - for v in variant_names.iter().cloned() { - if (emit_map_has(covered_set.clone(), v.clone()) == false) { - __result.push(v); - } - } - __result - }); - if ((uncovered.clone().len() as i64) > 0) { - Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::NonExhaustiveMatch { - missing: uncovered.clone(), - span: span, - }), - module_name, - )]) + let covered_set = arms.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, arm: Rc| match (*arm_pattern(arm.clone())).clone() { + MatchPattern::VariantPattern { name: n, .. } => v2_rt::rc_map_insert(acc.clone(), n.clone(), true), + MatchPattern::LitPattern { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitBool { value: b, .. } => if b.clone() { + v2_rt::rc_map_insert(acc.clone(), "True".to_string(), true) + } else { + v2_rt::rc_map_insert(acc.clone(), "False".to_string(), true) + }, + _ => acc.clone(), +}, + _ => acc.clone(), +}); +let uncovered = Rc::new({ let mut __result = Vec::new(); for v in variant_names.iter().cloned() { if (emit_map_has(covered_set.clone(), v.clone()) == false) { __result.push(v); } } __result }); +if ((uncovered.clone().len() as i64) > 0) { + Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::NonExhaustiveMatch { + missing: uncovered.clone(), + span: span, +}), module_name)]) } else { Rc::new(vec![]) } - } +} } - } +} } else { Rc::new(vec![]) } - } +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_resolve.rs b/src/v2/stage0/src/v2_compiler_infer_resolve.rs index 53f5cbf2aaf..7aa5398c202 100644 --- a/src/v2/stage0/src/v2_compiler_infer_resolve.rs +++ b/src/v2/stage0/src/v2_compiler_infer_resolve.rs @@ -1,55 +1,32 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_resolve -use self::AliasKind::*; -pub use crate::std_induction::SubValueRelation; -use crate::std_induction::SubValueRelation::SubValueUnknown; -pub use crate::std_types::{container_param_name, SourceSpan}; -pub use crate::v2_compiler_infer_env::{ - authored_name, is_recursive_type, is_recursive_type_by_name, is_recursive_type_for, - lookup_type, lookup_type_by_name, lookup_type_for, TypeBinding, TypeEnv, -}; -pub use crate::v2_compiler_infer_types::{ - child_type_node, node_is_keyed_collection, resolved_type, -}; -use crate::v2_rt; -use crate::v2_std_core::Cardinality::{CardOptional, Required}; -use crate::v2_std_core::CompilerDiagnostic::{ArityMismatch, InternalError, UnresolvedType}; -use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; -use crate::v2_std_core::ExprData::{ - ExprBinOp, ExprBlock, ExprCall, ExprCast, ExprError, ExprFieldAccess, ExprForEach, ExprIf, - ExprIndex, ExprLambda, ExprLet, ExprListLit, ExprLiteral, ExprMatch, ExprMethodCall, - ExprRecordLit, ExprReturn, ExprSlice, ExprStringInterp, ExprUnaryOp, ExprVar, NoExprData, -}; -use crate::v2_std_core::ExprErrorKind::SemanticExprError; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; -use crate::v2_std_core::MatchPattern::Wildcard; -use crate::v2_std_core::StringPart::{Interpolation, Text}; -pub use crate::v2_std_core::{ - arg_name_at, arg_value, arm_body, arm_guard, arm_pattern, authored_name_at, default_ident_span, - expr_call_func_at, expr_method_name_at, field_init_node_name_at, field_init_node_value, - field_node_cardinality, field_node_default_value, field_node_from_key, field_node_name_at, - field_node_type_expr, foreach_variable_at, intern, is_compiler_error, is_container_type, - is_kernel_type, is_local_transport, kernel_span, let_binding_name_at, local_transport_node, - make_arg_node, make_arm_node, make_error_node, make_expr_error_node, make_expr_node, - make_field_init_node, make_field_node, make_interp_part_node, make_named_expr_node, - make_param_node, make_resource_use_node, make_text_part_node, make_transport_node, - map_children, no_span, node_name_span, param_node_default_value, param_node_name_at, - param_node_type_expr, resource_use_name_at, resource_use_resource, string_type, - transport_request_body, unit_type, with_optional_cardinality, with_required_cardinality, - Cardinality, CompilerDiagnostic, Connective, ErrorNode, ExprData, ExprErrorKind, InferredNode, - MatchPattern, NewlineIndex, Node, StringPart, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan, container_param_name}; +pub use crate::v2_std_core::{Node, authored_name_at, NewlineIndex, make_param_node, param_node_name_at, param_node_type_expr, param_node_default_value, make_field_node, field_node_name_at, field_node_type_expr, field_node_cardinality, field_node_default_value, field_node_from_key, InferredNode, is_compiler_error, ErrorNode, make_error_node, Cardinality, StringPart, MatchPattern, ExprData, ExprErrorKind, make_expr_node, make_named_expr_node, make_expr_error_node, map_children, expr_call_func_at, expr_method_name_at, let_binding_name_at, foreach_variable_at, make_arg_node, arg_name_at, arg_value, make_arm_node, arm_pattern, arm_guard, arm_body, make_field_init_node, field_init_node_name_at, field_init_node_value, make_resource_use_node, resource_use_name_at, resource_use_resource, make_text_part_node, make_interp_part_node, make_transport_node, local_transport_node, is_local_transport, transport_request_body, is_kernel_type, is_container_type, with_optional_cardinality, with_required_cardinality, Connective, no_span, unit_type, string_type, default_ident_span, kernel_span, node_name_span, intern, CompilerDiagnostic}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::CompilerDiagnostic::{InternalError, ArityMismatch, UnresolvedType}; +use crate::v2_std_core::Cardinality::{Required, CardOptional}; +use crate::v2_std_core::StringPart::{Text, Interpolation}; +use crate::v2_std_core::MatchPattern::{Wildcard}; +use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprError, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit, ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp, ExprBlock, ExprCast, ExprForEach, ExprIndex, ExprSlice, ExprReturn}; +use crate::v2_std_core::ExprErrorKind::{SemanticExprError}; +use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; +pub use crate::v2_compiler_infer_types::{resolved_type, child_type_node, node_is_keyed_collection}; +pub use crate::std_induction::{SubValueRelation}; +use crate::std_induction::SubValueRelation::{SubValueUnknown}; +pub use crate::v2_compiler_infer_env::{TypeEnv, TypeBinding, lookup_type, lookup_type_by_name, lookup_type_for, is_recursive_type, is_recursive_type_by_name, is_recursive_type_for, authored_name}; +use self::AliasKind::*; pub fn is_type_variable(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::TypeVariable { .. } => true, - _ => false, - } + InferredNode::TypeVariable { .. } => true, + _ => false, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -125,139 +102,96 @@ pub fn resolve_node(n: Rc, env: Rc, module_name: String) -> Rc, env: &Rc) -> bool { { let has_structure = (n.connective.clone() != Connective::NoConnective); - if has_structure { +if has_structure { false } else { match lookup_type_for(&env, &n) { - Some(decl) => { - if ((decl.params.clone().len() as i64) > 0) { - if is_container_type(authored_name(env.clone(), n.clone())) { - false - } else { - if (decl.inferred.clone() != None) { - true - } else { - true - } - } + Some(decl) => if ((decl.params.clone().len() as i64) > 0) { + if is_container_type(authored_name(env.clone(), n.clone())) { + false + } else { + if (decl.inferred.clone() != None) { + true } else { - false + true } } - None => false, - } + } else { + false + }, + None => false, +} } - } +} } -pub fn substitute_type_slots( - n: &Rc, - slot_bindings: &Rc>>, - decl_name: &String, - source_indices: &Rc>>, -) -> Rc { +pub fn substitute_type_slots(n: &Rc, slot_bindings: &Rc>>, decl_name: &String, source_indices: &Rc>>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let is_slot = (((((n.children.clone().len() as i64) == 0) - && (n.connective.clone() == Connective::NoConnective)) - && (n.body.clone() == None)) - && (n.inferred.clone() == None)); - if is_slot { - match v2_rt::map_get(&slot_bindings, authored_name_at(source_indices.clone(), &n)) { - Some(concrete) => concrete.clone(), - None => n.clone(), - } - } else { - { - let new_children = Rc::new({ - let mut __result = Vec::new(); - for child in n.children.clone().iter().cloned() { - __result.push( - if (authored_name_at(source_indices.clone(), &child).as_str() - == decl_name.clone().as_str()) - { - { - let substituted_args = Rc::new({ - let mut __result = Vec::new(); - for arg in child.children.clone().iter().cloned() { - __result.push(substitute_type_slots( - &arg, - &slot_bindings, - &decl_name, - &source_indices, - )); - } - __result - }); - Rc::new(Node { - name: child.name.clone(), - span: child.span.clone(), - ident_span: child.ident_span.clone(), - children: substituted_args.clone(), - connective: child.connective.clone(), - params: child.params.clone(), - inferred: child.inferred.clone(), - return_cardinality: child.return_cardinality.clone(), - uses: child.uses.clone(), - body: child.body.clone(), - transport: child.transport.clone(), - properties: child.properties.clone(), - type_annotation: child.type_annotation.clone(), - is_self_recursive: child.is_self_recursive.clone(), - has_non_tail_self_call: child - .has_non_tail_self_call - .clone(), - match_pattern: child.match_pattern.clone(), - expr_data: child.expr_data.clone(), - ident: None, - }) - } - } else { - substitute_type_slots( - &child, - &slot_bindings, - &decl_name, - &source_indices, - ) - }, - ); - } - __result - }); - let new_inferred = match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - Some(Rc::new(InferredNode::Resolved { - node: substitute_type_slots( - &rt, - &slot_bindings, - &decl_name, - &source_indices, - ), - })) - } - _ => n.inferred.clone(), - }; - Rc::new(Node { - name: n.name.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: new_children, - connective: n.connective.clone(), - params: n.params.clone(), - inferred: new_inferred, - return_cardinality: n.return_cardinality.clone(), - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: n.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: n.is_self_recursive.clone(), - has_non_tail_self_call: n.has_non_tail_self_call.clone(), - match_pattern: n.match_pattern.clone(), - expr_data: n.expr_data.clone(), - ident: None, - }) + { + let is_slot = (((((n.children.clone().len() as i64) == 0) && (n.connective.clone() == Connective::NoConnective)) && (n.body.clone() == None)) && (n.inferred.clone() == None)); +if is_slot { + match v2_rt::map_get(&slot_bindings, authored_name_at(source_indices.clone(), &n)) { + Some(concrete) => concrete.clone(), + None => n.clone(), +} + } else { + { + let new_children = Rc::new({ let mut __result = Vec::new(); for child in n.children.clone().iter().cloned() { __result.push(if (authored_name_at(source_indices.clone(), &child).as_str() == decl_name.clone().as_str()) { + { + let substituted_args = Rc::new({ let mut __result = Vec::new(); for arg in child.children.clone().iter().cloned() { __result.push(substitute_type_slots(&arg, &slot_bindings, &decl_name, &source_indices)); } __result }); +Rc::new(Node { + name: child.name.clone(), + span: child.span.clone(), + ident_span: child.ident_span.clone(), + children: substituted_args.clone(), + connective: child.connective.clone(), + params: child.params.clone(), + inferred: child.inferred.clone(), + return_cardinality: child.return_cardinality.clone(), + uses: child.uses.clone(), + body: child.body.clone(), + transport: child.transport.clone(), + properties: child.properties.clone(), + type_annotation: child.type_annotation.clone(), + is_self_recursive: child.is_self_recursive.clone(), + has_non_tail_self_call: child.has_non_tail_self_call.clone(), + match_pattern: child.match_pattern.clone(), + expr_data: child.expr_data.clone(), + ident: None, +}) +} + } else { + substitute_type_slots(&child, &slot_bindings, &decl_name, &source_indices) + }); } __result }); +let new_inferred = match n.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => Some(Rc::new(InferredNode::Resolved { + node: substitute_type_slots(&rt, &slot_bindings, &decl_name, &source_indices), +})), + _ => n.inferred.clone(), +}; +Rc::new(Node { + name: n.name.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: new_children, + connective: n.connective.clone(), + params: n.params.clone(), + inferred: new_inferred, + return_cardinality: n.return_cardinality.clone(), + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: n.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: n.is_self_recursive.clone(), + has_non_tail_self_call: n.has_non_tail_self_call.clone(), + match_pattern: n.match_pattern.clone(), + expr_data: n.expr_data.clone(), + ident: None, +}) +} } - } +} }) } @@ -272,286 +206,185 @@ pub enum AliasKind { pub fn classify_alias(target: &Rc) -> AliasKind { { let nc = (target.connective.clone() == Connective::NoConnective); - if (((target.children.clone().len() as i64) > 0) && nc.clone()) { +if (((target.children.clone().len() as i64) > 0) && nc.clone()) { AliasKind::AliasParameterized } else { - if ((((target.children.clone().len() as i64) == 0) && nc.clone()) - && (target.ident_span.clone() != None)) - { + if ((((target.children.clone().len() as i64) == 0) && nc.clone()) && (target.ident_span.clone() != None)) { AliasKind::AliasLeaf } else { AliasKind::AliasPassthrough } } - } +} } -pub fn resolve_alias_target( - target: Rc, - env: &Rc, - module_name: String, - depth: i64, -) -> Rc { +pub fn resolve_alias_target(target: Rc, env: &Rc, module_name: String, depth: i64) -> Rc { match classify_alias(&target) { - AliasKind::AliasParameterized => { - resolve_node_bounded(&target, &env, &module_name, (depth + 1)) - .resolved - .clone() - } - AliasKind::AliasLeaf => { - match lookup_type_by_name(&env, authored_name_at(env.source_indices.clone(), &target)) { - Some(env_target) => env_target.clone(), - None => target.clone(), - } - } - AliasKind::AliasPassthrough => target.clone(), - } + AliasKind::AliasParameterized => resolve_node_bounded(&target, &env, &module_name, (depth + 1)).resolved.clone(), + AliasKind::AliasLeaf => match lookup_type_by_name(&env, authored_name_at(env.source_indices.clone(), &target)) { + Some(env_target) => env_target.clone(), + None => target.clone(), +}, + AliasKind::AliasPassthrough => target.clone(), +} } -pub fn resolve_node_bounded( - n: &Rc, - env: &Rc, - module_name: &String, - depth: i64, -) -> Rc { +pub fn resolve_node_bounded(n: &Rc, env: &Rc, module_name: &String, depth: i64) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - if (depth.clone() > 100) { - return Rc::new(NodeResolveResult { - resolved: n.clone(), - diagnostics: Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: v2_rt::concat( - v2_rt::concat( - "internal: type resolution exceeded depth 100 for '".to_string(), - authored_name(env.clone(), n.clone()), - ), - "'".to_string(), - ), - span: n.span.clone(), - }), - module_name.clone(), - )]), - }); - } - let has_structure = (n.connective.clone() != Connective::NoConnective); - if has_structure { - { - let is_product = (n.connective.clone() == Connective::Conj); - if is_product { - if (n.type_annotation.clone() != None) { - match n.children.clone().first().cloned() { - Some(base) => { - let base_result = resolve_node_bounded( - &base, - &env, - &module_name, - (depth.clone() + 1), - ); - let base_resolved = base_result.resolved.clone(); - let base_diags = base_result.diagnostics.clone(); - Rc::new(NodeResolveResult { - resolved: Rc::new(Node { - name: n.name.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: Rc::new(vec![base_resolved]), - connective: n.connective.clone(), - params: n.params.clone(), - inferred: n.inferred.clone(), - return_cardinality: n.return_cardinality.clone(), - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: n.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: base_diags, - }) - } - None => Rc::new(NodeResolveResult { - resolved: n.clone(), - diagnostics: Rc::new(vec![]), - }), + { + if (depth.clone() > 100) { + return Rc::new(NodeResolveResult { + resolved: n.clone(), + diagnostics: Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: v2_rt::concat(v2_rt::concat("internal: type resolution exceeded depth 100 for '".to_string(), authored_name(env.clone(), n.clone())), "'".to_string()), + span: n.span.clone(), +}), module_name.clone())]), +}) + } +let has_structure = (n.connective.clone() != Connective::NoConnective); +if has_structure { + { + let is_product = (n.connective.clone() == Connective::Conj); +if is_product { + if (n.type_annotation.clone() != None) { + match n.children.clone().first().cloned() { + Some(base) => { + let base_result = resolve_node_bounded(&base, &env, &module_name, (depth.clone() + 1)); +let base_resolved = base_result.resolved.clone(); +let base_diags = base_result.diagnostics.clone(); +Rc::new(NodeResolveResult { + resolved: Rc::new(Node { + name: n.name.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: Rc::new(vec![base_resolved]), + connective: n.connective.clone(), + params: n.params.clone(), + inferred: n.inferred.clone(), + return_cardinality: n.return_cardinality.clone(), + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: n.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: base_diags, +}) +}, + None => Rc::new(NodeResolveResult { + resolved: n.clone(), + diagnostics: Rc::new(vec![]), +}), +} + } else { + { + let child_results = Rc::new({ let mut __result = Vec::new(); for child in n.children.clone().iter().cloned() { __result.push(if (child.inferred.clone() == None) { + Rc::new(NodeResolveResult { + resolved: child.clone(), + diagnostics: Rc::new(vec![]), +}) + } else { + { + let child_rt = resolved_type(child.clone()); +let rt_result = resolve_node_bounded(&child_rt, &env, &module_name, (depth.clone() + 1)); +let rt_resolved = rt_result.resolved.clone(); +let rt_diags = rt_result.diagnostics.clone(); +Rc::new(NodeResolveResult { + resolved: Rc::new(Node { + name: child.name.clone(), + span: child.span.clone(), + ident_span: child.ident_span.clone(), + children: child.children.clone(), + connective: child.connective.clone(), + params: child.params.clone(), + inferred: Some(Rc::new(InferredNode::Resolved { + node: rt_resolved.clone(), +})), + return_cardinality: child.return_cardinality.clone(), + uses: child.uses.clone(), + body: child.body.clone(), + transport: child.transport.clone(), + properties: child.properties.clone(), + type_annotation: child.type_annotation.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: rt_diags.clone(), +}) +} + }); } __result }); +let resolved_children = Rc::new({ let mut __result = Vec::new(); for cr in child_results.clone().iter().cloned() { __result.push(cr.resolved.clone()); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for cr in child_results.clone().iter().cloned() { __result.extend((*cr.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(NodeResolveResult { + resolved: Rc::new(Node { + name: n.name.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: resolved_children, + connective: n.connective.clone(), + params: n.params.clone(), + inferred: n.inferred.clone(), + return_cardinality: n.return_cardinality.clone(), + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: n.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: all_diags, +}) +} } } else { { - let child_results = Rc::new({ - let mut __result = Vec::new(); - for child in n.children.clone().iter().cloned() { - __result.push(if (child.inferred.clone() == None) { - Rc::new(NodeResolveResult { - resolved: child.clone(), - diagnostics: Rc::new(vec![]), - }) - } else { - { - let child_rt = resolved_type(child.clone()); - let rt_result = resolve_node_bounded( - &child_rt, - &env, - &module_name, - (depth.clone() + 1), - ); - let rt_resolved = rt_result.resolved.clone(); - let rt_diags = rt_result.diagnostics.clone(); + let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); +if is_optional { + { + let inner = with_required_cardinality(&n); +let inner_result = resolve_node_bounded(&inner, &env, &module_name, (depth.clone() + 1)); +let inner_resolved = inner_result.resolved.clone(); +let inner_diags = inner_result.diagnostics.clone(); +Rc::new(NodeResolveResult { + resolved: with_optional_cardinality(&inner_resolved), + diagnostics: inner_diags, +}) +} + } else { + { + let variant_results = Rc::new({ let mut __result = Vec::new(); for variant_child in n.children.clone().iter().cloned() { __result.push({ + let field_results = Rc::new({ let mut __result = Vec::new(); for field_child in variant_child.children.clone().iter().cloned() { __result.push(if (field_child.inferred.clone() == None) { Rc::new(NodeResolveResult { - resolved: Rc::new(Node { - name: child.name.clone(), - span: child.span.clone(), - ident_span: child.ident_span.clone(), - children: child.children.clone(), - connective: child.connective.clone(), - params: child.params.clone(), - inferred: Some(Rc::new( - InferredNode::Resolved { - node: rt_resolved.clone(), - }, - )), - return_cardinality: child - .return_cardinality - .clone(), - uses: child.uses.clone(), - body: child.body.clone(), - transport: child.transport.clone(), - properties: child.properties.clone(), - type_annotation: child.type_annotation.clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: rt_diags.clone(), - }) - } - }); - } - __result - }); - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for cr in child_results.clone().iter().cloned() { - __result.push(cr.resolved.clone()); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for cr in child_results.clone().iter().cloned() { - __result.extend((*cr.diagnostics.clone()).iter().cloned()); - } - __result - }); - Rc::new(NodeResolveResult { - resolved: Rc::new(Node { - name: n.name.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: resolved_children, - connective: n.connective.clone(), - params: n.params.clone(), - inferred: n.inferred.clone(), - return_cardinality: n.return_cardinality.clone(), - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: n.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: all_diags, - }) - } - } - } else { - { - let is_optional = - (n.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { - { - let inner = with_required_cardinality(&n); - let inner_result = resolve_node_bounded( - &inner, - &env, - &module_name, - (depth.clone() + 1), - ); - let inner_resolved = inner_result.resolved.clone(); - let inner_diags = inner_result.diagnostics.clone(); - Rc::new(NodeResolveResult { - resolved: with_optional_cardinality(&inner_resolved), - diagnostics: inner_diags, - }) - } - } else { - { - let variant_results = Rc::new({ - let mut __result = Vec::new(); - for variant_child in n.children.clone().iter().cloned() { - __result.push({ - let field_results = Rc::new({ - let mut __result = Vec::new(); - for field_child in - variant_child.children.clone().iter().cloned() - { - __result.push( - if (field_child.inferred.clone() == None) { - Rc::new(NodeResolveResult { - resolved: field_child.clone(), - diagnostics: Rc::new(vec![]), - }) - } else { - { - let field_rt = resolved_type( - field_child.clone(), - ); - let is_self_ref = ((authored_name( - env.clone(), - field_rt.clone(), - ) - .as_str() - == authored_name( - env.clone(), - n.clone(), - ) - .as_str()) - && ((field_rt - .children - .clone() - .len() - as i64) - > 0)); - let rt_result = if is_self_ref - .clone() - { - Rc::new(NodeResolveResult { - resolved: field_rt.clone(), - diagnostics: Rc::new( - vec![], - ), - }) - } else { - resolve_node_bounded( - &field_rt, - &env, - &module_name, - (depth.clone() + 1), - ) - }; - let rt_resolved = - rt_result.resolved.clone(); - let rt_diags = - rt_result.diagnostics.clone(); - Rc::new(NodeResolveResult { + resolved: field_child.clone(), + diagnostics: Rc::new(vec![]), +}) + } else { + { + let field_rt = resolved_type(field_child.clone()); +let is_self_ref = ((authored_name(env.clone(), field_rt.clone()).as_str() == authored_name(env.clone(), n.clone()).as_str()) && ((field_rt.children.clone().len() as i64) > 0)); +let rt_result = if is_self_ref.clone() { + Rc::new(NodeResolveResult { + resolved: field_rt.clone(), + diagnostics: Rc::new(vec![]), +}) + } else { + resolve_node_bounded(&field_rt, &env, &module_name, (depth.clone() + 1)) + }; +let rt_resolved = rt_result.resolved.clone(); +let rt_diags = rt_result.diagnostics.clone(); +Rc::new(NodeResolveResult { resolved: Rc::new(Node { name: field_child.name.clone(), span: field_child.span.clone(), @@ -576,2106 +409,1249 @@ pub fn resolve_node_bounded( }), diagnostics: rt_diags.clone(), }) - } - }, - ); - } - __result - }); - let resolved_fields = Rc::new({ - let mut __result = Vec::new(); - for fr in field_results.clone().iter().cloned() { - __result.push(fr.resolved.clone()); - } - __result - }); - let field_diags = Rc::new({ - let mut __result = Vec::new(); - for fr in field_results.clone().iter().cloned() { - __result.extend( - (*fr.diagnostics.clone()).iter().cloned(), - ); - } - __result - }); - Rc::new(NodeResolveResult { - resolved: Rc::new(Node { - name: variant_child.name.clone(), - span: variant_child.span.clone(), - ident_span: variant_child.ident_span.clone(), - children: resolved_fields.clone(), - connective: variant_child.connective.clone(), - params: variant_child.params.clone(), - inferred: variant_child.inferred.clone(), - return_cardinality: variant_child - .return_cardinality - .clone(), - uses: variant_child.uses.clone(), - body: variant_child.body.clone(), - transport: variant_child.transport.clone(), - properties: variant_child.properties.clone(), - type_annotation: variant_child - .type_annotation - .clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: field_diags.clone(), - }) - }); - } - __result - }); - let resolved_variants = Rc::new({ - let mut __result = Vec::new(); - for vr in variant_results.clone().iter().cloned() { - __result.push(vr.resolved.clone()); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for vr in variant_results.clone().iter().cloned() { - __result.extend((*vr.diagnostics.clone()).iter().cloned()); - } - __result - }); - Rc::new(NodeResolveResult { - resolved: Rc::new(Node { - name: n.name.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: resolved_variants, - connective: n.connective.clone(), - params: n.params.clone(), - inferred: n.inferred.clone(), - return_cardinality: n.return_cardinality.clone(), - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: n.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: all_diags, - }) +} + }); } __result }); +let resolved_fields = Rc::new({ let mut __result = Vec::new(); for fr in field_results.clone().iter().cloned() { __result.push(fr.resolved.clone()); } __result }); +let field_diags = Rc::new({ let mut __result = Vec::new(); for fr in field_results.clone().iter().cloned() { __result.extend((*fr.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(NodeResolveResult { + resolved: Rc::new(Node { + name: variant_child.name.clone(), + span: variant_child.span.clone(), + ident_span: variant_child.ident_span.clone(), + children: resolved_fields.clone(), + connective: variant_child.connective.clone(), + params: variant_child.params.clone(), + inferred: variant_child.inferred.clone(), + return_cardinality: variant_child.return_cardinality.clone(), + uses: variant_child.uses.clone(), + body: variant_child.body.clone(), + transport: variant_child.transport.clone(), + properties: variant_child.properties.clone(), + type_annotation: variant_child.type_annotation.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: field_diags.clone(), +}) +}); } __result }); +let resolved_variants = Rc::new({ let mut __result = Vec::new(); for vr in variant_results.clone().iter().cloned() { __result.push(vr.resolved.clone()); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for vr in variant_results.clone().iter().cloned() { __result.extend((*vr.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(NodeResolveResult { + resolved: Rc::new(Node { + name: n.name.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: resolved_variants, + connective: n.connective.clone(), + params: n.params.clone(), + inferred: n.inferred.clone(), + return_cardinality: n.return_cardinality.clone(), + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: n.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: all_diags, +}) +} } - } +} } - } - } - } else { - if (((n.children.clone().len() as i64) > 0) && is_user_generic_use_site(&n, &env)) { - { - let type_name = authored_name(env.clone(), n.clone()); - let decl = match lookup_type_for(&env, &n) { - Some(d) => d.clone(), - None => n.clone(), - }; - let expected_arity = (decl.params.clone().len() as i64); - let actual_arity = (n.children.clone().len() as i64); - let arity_diags = if (expected_arity.clone() != actual_arity.clone()) { - Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::ArityMismatch { - name: type_name.clone(), - expected: expected_arity.clone(), - got: actual_arity.clone(), - span: n.span.clone(), - }), - module_name.clone(), - )]) - } else { - Rc::new(vec![]) - }; - let arg_results = Rc::new({ - let mut __result = Vec::new(); - for child in n.children.clone().iter().cloned() { - __result.push(resolve_node_bounded( - &child, - &env, - &module_name, - (depth.clone() + 1), - )); - } - __result - }); - let resolved_args = Rc::new({ - let mut __result = Vec::new(); - for ar in arg_results.clone().iter().cloned() { - __result.push(ar.resolved.clone()); - } - __result - }); - let arg_diags = Rc::new({ - let mut __result = Vec::new(); - for ar in arg_results.clone().iter().cloned() { - __result.extend((*ar.diagnostics.clone()).iter().cloned()); - } - __result - }); - let slot_bindings = Rc::new( - decl.params - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, pair: (i64, Rc)| { +} + } else { + if (((n.children.clone().len() as i64) > 0) && is_user_generic_use_site(&n, &env)) { + { + let type_name = authored_name(env.clone(), n.clone()); +let decl = match lookup_type_for(&env, &n) { + Some(d) => d.clone(), + None => n.clone(), +}; +let expected_arity = (decl.params.clone().len() as i64); +let actual_arity = (n.children.clone().len() as i64); +let arity_diags = if (expected_arity.clone() != actual_arity.clone()) { + Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::ArityMismatch { + name: type_name.clone(), + expected: expected_arity.clone(), + got: actual_arity.clone(), + span: n.span.clone(), +}), module_name.clone())]) + } else { + Rc::new(vec![]) + }; +let arg_results = Rc::new({ let mut __result = Vec::new(); for child in n.children.clone().iter().cloned() { __result.push(resolve_node_bounded(&child, &env, &module_name, (depth.clone() + 1))); } __result }); +let resolved_args = Rc::new({ let mut __result = Vec::new(); for ar in arg_results.clone().iter().cloned() { __result.push(ar.resolved.clone()); } __result }); +let arg_diags = Rc::new({ let mut __result = Vec::new(); for ar in arg_results.clone().iter().cloned() { __result.extend((*ar.diagnostics.clone()).iter().cloned()); } __result }); +let slot_bindings = Rc::new(decl.params.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, pair: (i64, Rc)| { let idx = pair.0.clone(); - let slot_name = - authored_name_at(env.source_indices.clone(), &pair.1.clone()); - match Rc::new({ - let mut __result = Vec::new(); - for p in Rc::new({ - let mut __result = Vec::new(); - for p in Rc::new( - resolved_args - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (p.0.clone() == idx.clone()) { - __result.push(p); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(p.1.clone()); - } - __result - }) - .first() - .cloned() +let slot_name = authored_name_at(env.source_indices.clone(), &pair.1.clone()); +match Rc::new({ let mut __result = Vec::new(); for p in Rc::new({ let mut __result = Vec::new(); for p in Rc::new(resolved_args.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (p.0.clone() == idx.clone()) { __result.push(p); } } __result }).iter().cloned() { __result.push(p.1.clone()); } __result }).first().cloned() { + Some(arg) => v2_rt::rc_map_insert(acc.clone(), slot_name.clone(), arg.clone()), + None => acc.clone(), +} +}); +let is_parameterized_alias = (((decl.inferred.clone() != None) && ((decl.children.clone().len() as i64) == 0)) && (decl.connective.clone() == Connective::NoConnective)); +if is_parameterized_alias { { - Some(arg) => v2_rt::rc_map_insert( - acc.clone(), - slot_name.clone(), - arg.clone(), - ), - None => acc.clone(), - } - }, - ); - let is_parameterized_alias = (((decl.inferred.clone() != None) - && ((decl.children.clone().len() as i64) == 0)) - && (decl.connective.clone() == Connective::NoConnective)); - if is_parameterized_alias { - { - let alias_target = match decl.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: target, .. }) => { - substitute_type_slots( - &target, - &slot_bindings, - &type_name, - &env.source_indices.clone(), - ) - } - _ => n.clone(), - }; - let target_result = resolve_node_bounded( - &alias_target, - &env, - &module_name, - (depth.clone() + 1), - ); - let is_recursive = is_recursive_type_by_name(&env, type_name.clone()); - let resolved_node = Rc::new(Node { - name: type_name.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: target_result.resolved.clone().children.clone(), - connective: target_result.resolved.clone().connective.clone(), - params: Rc::new(vec![]), - inferred: n.inferred.clone(), - return_cardinality: n.return_cardinality.clone(), - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: target_result.resolved.clone().properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: is_recursive, - has_non_tail_self_call: n.has_non_tail_self_call.clone(), - match_pattern: n.match_pattern.clone(), - expr_data: n.expr_data.clone(), - ident: None, - }); - Rc::new(NodeResolveResult { - resolved: resolved_node, - diagnostics: v2_rt::concat( - v2_rt::concat(arity_diags, arg_diags), - target_result.diagnostics.clone(), - ), - }) - } - } else { - { - let substituted_children = Rc::new({ - let mut __result = Vec::new(); - for child in decl.children.clone().iter().cloned() { - __result.push(substitute_type_slots( - &child, - &slot_bindings, - &type_name, - &env.source_indices.clone(), - )); - } - __result - }); - let is_recursive = is_recursive_type_by_name(&env, type_name.clone()); - let result = Rc::new(NodeResolveResult { - resolved: Rc::new(Node { - name: type_name.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: substituted_children, - connective: decl.connective.clone(), - params: Rc::new(vec![]), - inferred: n.inferred.clone(), - return_cardinality: n.return_cardinality.clone(), - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: decl.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: is_recursive, - has_non_tail_self_call: n.has_non_tail_self_call.clone(), - match_pattern: n.match_pattern.clone(), - expr_data: n.expr_data.clone(), - ident: None, - }), - diagnostics: v2_rt::concat(arity_diags, arg_diags), - }); - result - } - } - } - } else { - { - let is_map = node_is_keyed_collection(&n, env.source_indices.clone()); - if is_map { - { - let type_name = authored_name(env.clone(), n.clone()); - let key_child_node = match n.children.clone().first().cloned() { - Some(k) => k.clone(), - None => unit_type(), - }; - let val_child_node = match n.children.clone().get(1 as usize).cloned() { - Some(v) => v.clone(), - None => unit_type(), - }; - let key_type = child_type_node(&key_child_node); - let val_type = child_type_node(&val_child_node); - let key_result = resolve_node_bounded( - &key_type, - &env, - &module_name, - (depth.clone() + 1), - ); - let key_resolved = key_result.resolved.clone(); - let key_diags = key_result.diagnostics.clone(); - let val_result = resolve_node_bounded( - &val_type, - &env, - &module_name, - (depth.clone() + 1), - ); - let val_resolved = val_result.resolved.clone(); - let val_diags = val_result.diagnostics.clone(); - let key_param_name = if (key_child_node.inferred.clone() != None) { - authored_name(env.clone(), key_child_node.clone()) - } else { - match container_param_name(type_name.clone(), 0) { - Some(pn) => pn.clone(), - None => authored_name(env.clone(), key_child_node.clone()), - } - }; - let val_param_name = if (val_child_node.inferred.clone() != None) { - authored_name(env.clone(), val_child_node.clone()) - } else { - match container_param_name(type_name.clone(), 1) { - Some(pn) => pn.clone(), - None => authored_name(env.clone(), val_child_node.clone()), - } - }; - let resolved_key_child = Rc::new(Node { - name: key_param_name, - span: key_child_node.span.clone(), - ident_span: key_child_node.ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { - node: key_resolved, - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let resolved_val_child = Rc::new(Node { - name: val_param_name, - span: val_child_node.span.clone(), - ident_span: val_child_node.ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { - node: val_resolved, - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(NodeResolveResult { - resolved: Rc::new(Node { - name: type_name.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: Rc::new(vec![resolved_key_child, resolved_val_child]), - connective: n.connective.clone(), - params: n.params.clone(), - inferred: n.inferred.clone(), - return_cardinality: n.return_cardinality.clone(), - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: n.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: v2_rt::concat(key_diags, val_diags), - }) + let alias_target = match decl.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: target, .. }) => substitute_type_slots(&target, &slot_bindings, &type_name, &env.source_indices.clone()), + _ => n.clone(), +}; +let target_result = resolve_node_bounded(&alias_target, &env, &module_name, (depth.clone() + 1)); +let is_recursive = is_recursive_type_by_name(&env, type_name.clone()); +let resolved_node = Rc::new(Node { + name: type_name.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: target_result.resolved.clone().children.clone(), + connective: target_result.resolved.clone().connective.clone(), + params: Rc::new(vec![]), + inferred: n.inferred.clone(), + return_cardinality: n.return_cardinality.clone(), + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: target_result.resolved.clone().properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: is_recursive, + has_non_tail_self_call: n.has_non_tail_self_call.clone(), + match_pattern: n.match_pattern.clone(), + expr_data: n.expr_data.clone(), + ident: None, +}); +Rc::new(NodeResolveResult { + resolved: resolved_node, + diagnostics: v2_rt::concat(v2_rt::concat(arity_diags, arg_diags), target_result.diagnostics.clone()), +}) +} + } else { + { + let substituted_children = Rc::new({ let mut __result = Vec::new(); for child in decl.children.clone().iter().cloned() { __result.push(substitute_type_slots(&child, &slot_bindings, &type_name, &env.source_indices.clone())); } __result }); +let is_recursive = is_recursive_type_by_name(&env, type_name.clone()); +let result = Rc::new(NodeResolveResult { + resolved: Rc::new(Node { + name: type_name.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: substituted_children, + connective: decl.connective.clone(), + params: Rc::new(vec![]), + inferred: n.inferred.clone(), + return_cardinality: n.return_cardinality.clone(), + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: decl.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: is_recursive, + has_non_tail_self_call: n.has_non_tail_self_call.clone(), + match_pattern: n.match_pattern.clone(), + expr_data: n.expr_data.clone(), + ident: None, +}), + diagnostics: v2_rt::concat(arity_diags, arg_diags), +}); +result +} } - } else { - if ((n.children.clone().len() as i64) == 1) { +} + } else { + { + let is_map = node_is_keyed_collection(&n, env.source_indices.clone()); +if is_map { { let type_name = authored_name(env.clone(), n.clone()); - match n.children.clone().first().cloned() { - Some(child_node) => { +let key_child_node = match n.children.clone().first().cloned() { + Some(k) => k.clone(), + None => unit_type(), +}; +let val_child_node = match n.children.clone().get(1 as usize).cloned() { + Some(v) => v.clone(), + None => unit_type(), +}; +let key_type = child_type_node(&key_child_node); +let val_type = child_type_node(&val_child_node); +let key_result = resolve_node_bounded(&key_type, &env, &module_name, (depth.clone() + 1)); +let key_resolved = key_result.resolved.clone(); +let key_diags = key_result.diagnostics.clone(); +let val_result = resolve_node_bounded(&val_type, &env, &module_name, (depth.clone() + 1)); +let val_resolved = val_result.resolved.clone(); +let val_diags = val_result.diagnostics.clone(); +let key_param_name = if (key_child_node.inferred.clone() != None) { + authored_name(env.clone(), key_child_node.clone()) + } else { + match container_param_name(type_name.clone(), 0) { + Some(pn) => pn.clone(), + None => authored_name(env.clone(), key_child_node.clone()), +} + }; +let val_param_name = if (val_child_node.inferred.clone() != None) { + authored_name(env.clone(), val_child_node.clone()) + } else { + match container_param_name(type_name.clone(), 1) { + Some(pn) => pn.clone(), + None => authored_name(env.clone(), val_child_node.clone()), +} + }; +let resolved_key_child = Rc::new(Node { + name: key_param_name, + span: key_child_node.span.clone(), + ident_span: key_child_node.ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: key_resolved, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let resolved_val_child = Rc::new(Node { + name: val_param_name, + span: val_child_node.span.clone(), + ident_span: val_child_node.ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: val_resolved, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(NodeResolveResult { + resolved: Rc::new(Node { + name: type_name.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: Rc::new(vec![resolved_key_child, resolved_val_child]), + connective: n.connective.clone(), + params: n.params.clone(), + inferred: n.inferred.clone(), + return_cardinality: n.return_cardinality.clone(), + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: n.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: v2_rt::concat(key_diags, val_diags), +}) +} + } else { + if ((n.children.clone().len() as i64) == 1) { + { + let type_name = authored_name(env.clone(), n.clone()); +match n.children.clone().first().cloned() { + Some(child_node) => { let el_type = child_type_node(&child_node); - let el_result = resolve_node_bounded( - &el_type, - &env, - &module_name, - (depth.clone() + 1), - ); - let el_resolved = el_result.resolved.clone(); - let el_diags = el_result.diagnostics.clone(); - let el_param_name = if (child_node.inferred.clone() != None) - { +let el_result = resolve_node_bounded(&el_type, &env, &module_name, (depth.clone() + 1)); +let el_resolved = el_result.resolved.clone(); +let el_diags = el_result.diagnostics.clone(); +let el_param_name = if (child_node.inferred.clone() != None) { authored_name(env.clone(), child_node.clone()) } else { match container_param_name(type_name.clone(), 0) { - Some(pn) => pn.clone(), - None => { - authored_name(env.clone(), child_node.clone()) - } - } + Some(pn) => pn.clone(), + None => authored_name(env.clone(), child_node.clone()), +} }; - let resolved_child = Rc::new(Node { - name: el_param_name, - span: child_node.span.clone(), - ident_span: child_node.ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { - node: el_resolved, - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); +let resolved_child = Rc::new(Node { + name: el_param_name, + span: child_node.span.clone(), + ident_span: child_node.ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: el_resolved, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(NodeResolveResult { + resolved: Rc::new(Node { + name: type_name.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: Rc::new(vec![resolved_child]), + connective: n.connective.clone(), + params: n.params.clone(), + inferred: n.inferred.clone(), + return_cardinality: n.return_cardinality.clone(), + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: n.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: el_diags, +}) +}, + None => Rc::new(NodeResolveResult { + resolved: n.clone(), + diagnostics: Rc::new(vec![]), +}), +} +} + } else { + if ((n.children.clone().len() as i64) == 0) { + if is_recursive_type_for(&env, &n) { Rc::new(NodeResolveResult { - resolved: Rc::new(Node { - name: type_name.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: Rc::new(vec![resolved_child]), - connective: n.connective.clone(), - params: n.params.clone(), - inferred: n.inferred.clone(), - return_cardinality: n.return_cardinality.clone(), - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: n.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: el_diags, - }) - } - None => Rc::new(NodeResolveResult { - resolved: n.clone(), - diagnostics: Rc::new(vec![]), - }), - } - } - } else { - if ((n.children.clone().len() as i64) == 0) { - if is_recursive_type_for(&env, &n) { - Rc::new(NodeResolveResult { - resolved: n.clone(), - diagnostics: Rc::new(vec![]), - }) - } else { - match lookup_type_for(&env, &n) { - Some(resolved) => { - let structurally_resolved = if (((resolved - .connective - .clone() - == Connective::NoConnective) - && ((resolved.children.clone().len() as i64) == 0)) - && (resolved.inferred.clone() != None)) - { - match resolved.inferred.clone().as_deref().cloned() - { - Some(InferredNode::Resolved { - node: target, - .. - }) => target.clone(), - _ => resolved.clone(), - } + resolved: n.clone(), + diagnostics: Rc::new(vec![]), +}) + } else { + match lookup_type_for(&env, &n) { + Some(resolved) => { + let structurally_resolved = if (((resolved.connective.clone() == Connective::NoConnective) && ((resolved.children.clone().len() as i64) == 0)) && (resolved.inferred.clone() != None)) { + match resolved.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: target, .. }) => target.clone(), + _ => resolved.clone(), +} } else { resolved.clone() }; - let is_optional = (n.return_cardinality.clone() - == Cardinality::CardOptional); - let final_resolved = if is_optional { +let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); +let final_resolved = if is_optional { with_optional_cardinality(&structurally_resolved) } else { structurally_resolved }; - Rc::new(NodeResolveResult { - resolved: final_resolved, - diagnostics: Rc::new(vec![]), - }) - } - None => { +Rc::new(NodeResolveResult { + resolved: final_resolved, + diagnostics: Rc::new(vec![]), +}) +}, + None => { let n_is_error = if (n.inferred.clone() != None) { - is_compiler_error( - n.inferred.clone().clone().unwrap(), - ) + is_compiler_error(n.inferred.clone().clone().unwrap()) } else { false }; - let n_is_callable = - ((n.params.clone().len() as i64) > 0); - let n_is_type_var = if (n.inferred.clone() != None) { - is_type_variable( - n.inferred.clone().clone().unwrap(), - ) +let n_is_callable = ((n.params.clone().len() as i64) > 0); +let n_is_type_var = if (n.inferred.clone() != None) { + is_type_variable(n.inferred.clone().clone().unwrap()) } else { false }; - if (((is_kernel_type(authored_name( - env.clone(), - n.clone(), - )) || n_is_type_var) - || n_is_error) - || n_is_callable) - { +if (((is_kernel_type(authored_name(env.clone(), n.clone())) || n_is_type_var) || n_is_error) || n_is_callable) { Rc::new(NodeResolveResult { - resolved: n.clone(), - diagnostics: Rc::new(vec![]), - }) + resolved: n.clone(), + diagnostics: Rc::new(vec![]), +}) } else { Rc::new(NodeResolveResult { - resolved: n.clone(), - diagnostics: Rc::new(vec![make_error_node( - Rc::new( - CompilerDiagnostic::UnresolvedType { - name: authored_name( - env.clone(), - n.clone(), - ), - span: n.span.clone(), - }, - ), - module_name.clone(), - )]), - }) + resolved: n.clone(), + diagnostics: Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::UnresolvedType { + name: authored_name(env.clone(), n.clone()), + span: n.span.clone(), +}), module_name.clone())]), +}) } - } +}, +} } + } else { + Rc::new(NodeResolveResult { + resolved: n.clone(), + diagnostics: Rc::new(vec![]), +}) } - } else { - Rc::new(NodeResolveResult { - resolved: n.clone(), - diagnostics: Rc::new(vec![]), - }) } } - } +} } } - } +} }) } -pub fn resolve_optional_node( - n: &Option>, - env: Rc, - module_name: String, -) -> Rc { +pub fn resolve_optional_node(n: &Option>, env: Rc, module_name: String) -> Rc { if (n.clone() == None) { Rc::new(NodeResolveResult { - resolved: unit_type(), - diagnostics: Rc::new(vec![]), - }) + resolved: unit_type(), + diagnostics: Rc::new(vec![]), +}) } else { match (*n.clone().unwrap()).clone() { - InferredNode::Resolved { node: inner, .. } => { - resolve_node(inner.clone(), env, module_name) - } - InferredNode::CompilerError { - message: msg, - span: sp, - .. - } => Rc::new(NodeResolveResult { - resolved: make_expr_error_node(ExprErrorKind::SemanticExprError, &msg, &sp), - diagnostics: Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: msg.clone(), - span: sp.clone(), - }), - module_name, - )]), - }), - InferredNode::TypeVariable { .. } => Rc::new(NodeResolveResult { - resolved: unit_type(), - diagnostics: Rc::new(vec![]), - }), - } + InferredNode::Resolved { node: inner, .. } => resolve_node(inner.clone(), env, module_name), + InferredNode::CompilerError { message: msg, span: sp, .. } => Rc::new(NodeResolveResult { + resolved: make_expr_error_node(ExprErrorKind::SemanticExprError, &msg, &sp), + diagnostics: Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: msg.clone(), + span: sp.clone(), +}), module_name)]), +}), + InferredNode::TypeVariable { .. } => Rc::new(NodeResolveResult { + resolved: unit_type(), + diagnostics: Rc::new(vec![]), +}), +} } } pub fn resolve_field(field: &Rc, env: &Rc, module_name: &String) -> Rc { { - let type_result = resolve_node( - field_node_type_expr(&field), - env.clone(), - module_name.clone(), - ); - let type_resolved = type_result.resolved.clone(); - let type_diags = type_result.diagnostics.clone(); - let default_resolved = match field_node_default_value(&field) { - Some(default_value) => Some(resolve_expr_types( - &default_value, - &env, - module_name.clone(), - )), - None => None, - }; - let default_diags = match default_resolved.clone() { - Some(result) => result.diagnostics.clone(), - None => Rc::new(vec![]), - }; - Rc::new(FieldResult { - field: make_field_node( - &field_node_name_at(field.clone(), env.source_indices.clone()), - type_resolved, - field_node_cardinality(field.clone()), - match default_resolved.clone() { - Some(result) => Some(result.expr.clone()), - None => None, - }, - field_node_from_key(field.clone(), env.source_indices.clone()), - field.span.clone(), - node_name_span(&field), - ), - diagnostics: v2_rt::concat(type_diags, default_diags), - }) - } + let type_result = resolve_node(field_node_type_expr(&field), env.clone(), module_name.clone()); +let type_resolved = type_result.resolved.clone(); +let type_diags = type_result.diagnostics.clone(); +let default_resolved = match field_node_default_value(&field) { + Some(default_value) => Some(resolve_expr_types(&default_value, &env, module_name.clone())), + None => None, +}; +let default_diags = match default_resolved.clone() { + Some(result) => result.diagnostics.clone(), + None => Rc::new(vec![]), +}; +Rc::new(FieldResult { + field: make_field_node(&field_node_name_at(field.clone(), env.source_indices.clone()), type_resolved, field_node_cardinality(field.clone()), match default_resolved.clone() { + Some(result) => Some(result.expr.clone()), + None => None, +}, field_node_from_key(field.clone(), env.source_indices.clone()), field.span.clone(), node_name_span(&field)), + diagnostics: v2_rt::concat(type_diags, default_diags), +}) +} } pub fn resolve_param(param: &Rc, env: &Rc, module_name: &String) -> Rc { { - let type_result = resolve_node( - param_node_type_expr(¶m), - env.clone(), - module_name.clone(), - ); - let type_resolved = type_result.resolved.clone(); - let type_diags = type_result.diagnostics.clone(); - let default_resolved = match param_node_default_value(¶m) { - Some(default_value) => Some(resolve_expr_types( - &default_value, - &env, - module_name.clone(), - )), - None => None, - }; - let default_diags = match default_resolved.clone() { - Some(result) => result.diagnostics.clone(), - None => Rc::new(vec![]), - }; - Rc::new(ParamResult { - param: make_param_node( - ¶m_node_name_at(param.clone(), env.source_indices.clone()), - type_resolved, - match default_resolved.clone() { - Some(result) => Some(result.expr.clone()), - None => None, - }, - param.span.clone(), - node_name_span(¶m), - ), - diagnostics: v2_rt::concat(type_diags, default_diags), - }) - } + let type_result = resolve_node(param_node_type_expr(¶m), env.clone(), module_name.clone()); +let type_resolved = type_result.resolved.clone(); +let type_diags = type_result.diagnostics.clone(); +let default_resolved = match param_node_default_value(¶m) { + Some(default_value) => Some(resolve_expr_types(&default_value, &env, module_name.clone())), + None => None, +}; +let default_diags = match default_resolved.clone() { + Some(result) => result.diagnostics.clone(), + None => Rc::new(vec![]), +}; +Rc::new(ParamResult { + param: make_param_node(¶m_node_name_at(param.clone(), env.source_indices.clone()), type_resolved, match default_resolved.clone() { + Some(result) => Some(result.expr.clone()), + None => None, +}, param.span.clone(), node_name_span(¶m)), + diagnostics: v2_rt::concat(type_diags, default_diags), +}) +} } -pub fn resolve_resource_use( - ru: &Rc, - env: &Rc, - module_name: String, -) -> Rc { +pub fn resolve_resource_use(ru: &Rc, env: &Rc, module_name: String) -> Rc { { let type_result = resolve_node(resource_use_resource(&ru), env.clone(), module_name); - let type_resolved = type_result.resolved.clone(); - let type_diags = type_result.diagnostics.clone(); - Rc::new(ResourceUseResult { - resource_use: make_resource_use_node( - &resource_use_name_at(ru.clone(), env.source_indices.clone()), - type_resolved, - ru.span.clone(), - node_name_span(&ru), - ), - diagnostics: type_diags, - }) - } +let type_resolved = type_result.resolved.clone(); +let type_diags = type_result.diagnostics.clone(); +Rc::new(ResourceUseResult { + resource_use: make_resource_use_node(&resource_use_name_at(ru.clone(), env.source_indices.clone()), type_resolved, ru.span.clone(), node_name_span(&ru)), + diagnostics: type_diags, +}) +} } -pub fn resolve_named_arg( - arg: &Rc, - env: &Rc, - module_name: String, -) -> Rc { +pub fn resolve_named_arg(arg: &Rc, env: &Rc, module_name: String) -> Rc { { let value_result = resolve_expr_types(&arg_value(&arg), &env, module_name); - let value_expr = value_result.expr.clone(); - let value_diags = value_result.diagnostics.clone(); - Rc::new(NamedArgResolveResult { - arg: make_arg_node( - arg_name_at(arg.clone(), env.source_indices.clone()), - value_expr, - arg.span.clone(), - node_name_span(&arg), - ), - diagnostics: value_diags, - }) - } +let value_expr = value_result.expr.clone(); +let value_diags = value_result.diagnostics.clone(); +Rc::new(NamedArgResolveResult { + arg: make_arg_node(arg_name_at(arg.clone(), env.source_indices.clone()), value_expr, arg.span.clone(), node_name_span(&arg)), + diagnostics: value_diags, +}) +} } -pub fn resolve_field_init( - field_init: &Rc, - env: &Rc, - module_name: String, -) -> Rc { +pub fn resolve_field_init(field_init: &Rc, env: &Rc, module_name: String) -> Rc { { - let value_result = - resolve_expr_types(&field_init_node_value(&field_init), &env, module_name); - let value_expr = value_result.expr.clone(); - let value_diags = value_result.diagnostics.clone(); - Rc::new(FieldInitResolveResult { - field_init: make_field_init_node( - &field_init_node_name_at(field_init.clone(), env.source_indices.clone()), - value_expr, - field_init.span.clone(), - node_name_span(&field_init), - ), - diagnostics: value_diags, - }) - } + let value_result = resolve_expr_types(&field_init_node_value(&field_init), &env, module_name); +let value_expr = value_result.expr.clone(); +let value_diags = value_result.diagnostics.clone(); +Rc::new(FieldInitResolveResult { + field_init: make_field_init_node(&field_init_node_name_at(field_init.clone(), env.source_indices.clone()), value_expr, field_init.span.clone(), node_name_span(&field_init)), + diagnostics: value_diags, +}) +} } -pub fn resolve_match_arm( - arm: &Rc, - env: &Rc, - module_name: &String, -) -> Rc { +pub fn resolve_match_arm(arm: &Rc, env: &Rc, module_name: &String) -> Rc { { let arm_g = arm_guard(&arm); - let guard_result = match arm_g { - Some(guard) => Some(resolve_expr_types(&guard, &env, module_name.clone())), - None => None, - }; - let guard_diags = match guard_result.clone() { - Some(result) => result.diagnostics.clone(), - None => Rc::new(vec![]), - }; - let body_result = resolve_expr_types(&arm_body(&arm), &env, module_name.clone()); - let body_expr = body_result.expr.clone(); - let body_diags = body_result.diagnostics.clone(); - Rc::new(MatchArmResolveResult { - arm: make_arm_node( - arm_pattern(arm.clone()), - match guard_result.clone() { - Some(result) => Some(result.expr.clone()), - None => None, - }, - body_expr, - arm.span.clone(), - ), - diagnostics: v2_rt::concat(guard_diags, body_diags), - }) - } +let guard_result = match arm_g { + Some(guard) => Some(resolve_expr_types(&guard, &env, module_name.clone())), + None => None, +}; +let guard_diags = match guard_result.clone() { + Some(result) => result.diagnostics.clone(), + None => Rc::new(vec![]), +}; +let body_result = resolve_expr_types(&arm_body(&arm), &env, module_name.clone()); +let body_expr = body_result.expr.clone(); +let body_diags = body_result.diagnostics.clone(); +Rc::new(MatchArmResolveResult { + arm: make_arm_node(arm_pattern(arm.clone()), match guard_result.clone() { + Some(result) => Some(result.expr.clone()), + None => None, +}, body_expr, arm.span.clone()), + diagnostics: v2_rt::concat(guard_diags, body_diags), +}) +} } -pub fn resolve_string_part( - part: Rc, - env: Rc, - module_name: String, -) -> Rc { +pub fn resolve_string_part(part: Rc, env: Rc, module_name: String) -> Rc { match (*part).clone() { - StringPart::Text { value, .. } => Rc::new(StringPartResolveResult { - part: Rc::new(StringPart::Text { - value: value.clone(), - }), - diagnostics: Rc::new(vec![]), - }), - StringPart::Interpolation { expr, .. } => { - let expr_result = resolve_expr_types(&expr, &env, module_name); - let resolved_expr = expr_result.expr.clone(); - let expr_diags = expr_result.diagnostics.clone(); - Rc::new(StringPartResolveResult { - part: Rc::new(StringPart::Interpolation { - expr: resolved_expr, - }), - diagnostics: expr_diags, - }) - } - } + StringPart::Text { value, .. } => Rc::new(StringPartResolveResult { + part: Rc::new(StringPart::Text { + value: value.clone(), +}), + diagnostics: Rc::new(vec![]), +}), + StringPart::Interpolation { expr, .. } => { + let expr_result = resolve_expr_types(&expr, &env, module_name); +let resolved_expr = expr_result.expr.clone(); +let expr_diags = expr_result.diagnostics.clone(); +Rc::new(StringPartResolveResult { + part: Rc::new(StringPart::Interpolation { + expr: resolved_expr, +}), + diagnostics: expr_diags, +}) +}, +} } -pub fn resolve_transport_binding( - transport: &Rc, - env: &Rc, - module_name: &String, -) -> Rc { +pub fn resolve_transport_binding(transport: &Rc, env: &Rc, module_name: &String) -> Rc { if is_local_transport(&transport, &env.source_indices.clone()) { Rc::new(TransportResolveResult { - transport: transport.clone(), - diagnostics: Rc::new(vec![]), - }) + transport: transport.clone(), + diagnostics: Rc::new(vec![]), +}) } else { { - let prop_results = Rc::new({ - let mut __result = Vec::new(); - for p in transport.properties.clone().iter().cloned() { - __result.push({ - let val_result = resolve_expr_types( - &field_init_node_value(&p), - &env, - module_name.clone(), - ); - Rc::new(FieldInitResolveResult { - field_init: make_field_init_node( - &field_init_node_name_at(p.clone(), env.source_indices.clone()), - val_result.expr.clone(), - p.span.clone(), - node_name_span(&p), - ), - diagnostics: val_result.diagnostics.clone(), - }) - }); - } - __result - }); - let resolved_props = Rc::new({ - let mut __result = Vec::new(); - for pr in prop_results.clone().iter().cloned() { - __result.push(pr.field_init.clone()); - } - __result - }); - let prop_diags = Rc::new({ - let mut __result = Vec::new(); - for pr in prop_results.clone().iter().cloned() { - __result.extend((*pr.diagnostics.clone()).iter().cloned()); - } - __result - }); - let child_results = Rc::new({ - let mut __result = Vec::new(); - for c in transport.children.clone().iter().cloned() { - __result.push(resolve_expr_types(&c, &env, module_name.clone())); - } - __result - }); - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for cr in child_results.clone().iter().cloned() { - __result.push(cr.expr.clone()); - } - __result - }); - let child_diags = Rc::new({ - let mut __result = Vec::new(); - for cr in child_results.clone().iter().cloned() { - __result.extend((*cr.diagnostics.clone()).iter().cloned()); - } - __result - }); - let body_diags = - match transport_request_body(transport.clone(), env.source_indices.clone()) { - Some(b) => match (*b.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => Rc::new(vec![]), - _ => Rc::new( - vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { + let prop_results = Rc::new({ let mut __result = Vec::new(); for p in transport.properties.clone().iter().cloned() { __result.push({ + let val_result = resolve_expr_types(&field_init_node_value(&p), &env, module_name.clone()); +Rc::new(FieldInitResolveResult { + field_init: make_field_init_node(&field_init_node_name_at(p.clone(), env.source_indices.clone()), val_result.expr.clone(), p.span.clone(), node_name_span(&p)), + diagnostics: val_result.diagnostics.clone(), +}) +}); } __result }); +let resolved_props = Rc::new({ let mut __result = Vec::new(); for pr in prop_results.clone().iter().cloned() { __result.push(pr.field_init.clone()); } __result }); +let prop_diags = Rc::new({ let mut __result = Vec::new(); for pr in prop_results.clone().iter().cloned() { __result.extend((*pr.diagnostics.clone()).iter().cloned()); } __result }); +let child_results = Rc::new({ let mut __result = Vec::new(); for c in transport.children.clone().iter().cloned() { __result.push(resolve_expr_types(&c, &env, module_name.clone())); } __result }); +let resolved_children = Rc::new({ let mut __result = Vec::new(); for cr in child_results.clone().iter().cloned() { __result.push(cr.expr.clone()); } __result }); +let child_diags = Rc::new({ let mut __result = Vec::new(); for cr in child_results.clone().iter().cloned() { __result.extend((*cr.diagnostics.clone()).iter().cloned()); } __result }); +let body_diags = match transport_request_body(transport.clone(), env.source_indices.clone()) { + Some(b) => match (*b.expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => Rc::new(vec![]), + _ => Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { message: "transport body must be a record expression { field: value, ... }".to_string(), span: b.span.clone(), -}), module_name.clone())], - ), - }, - None => Rc::new(vec![]), - }; - Rc::new(TransportResolveResult { - transport: make_transport_node( - resolved_props, - resolved_children, - transport.body.clone(), - transport.span.clone(), - ), - diagnostics: v2_rt::concat(v2_rt::concat(prop_diags, child_diags), body_diags), - }) - } +}), module_name.clone())]), +}, + None => Rc::new(vec![]), +}; +Rc::new(TransportResolveResult { + transport: make_transport_node(resolved_props, resolved_children, transport.body.clone(), transport.span.clone()), + diagnostics: v2_rt::concat(v2_rt::concat(prop_diags, child_diags), body_diags), +}) +} } } -pub fn resolve_expr_types( - texpr: &Rc, - env: &Rc, - module_name: String, -) -> Rc { +pub fn resolve_expr_types(texpr: &Rc, env: &Rc, module_name: String) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprLiteral { .. } => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - ExprData::ExprError { kind, message, .. } => Rc::new(ExprResolveResult { - expr: make_expr_error_node(kind.clone(), &message, &texpr.span.clone()), - diagnostics: Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: message.clone(), - span: texpr.span.clone(), - }), - module_name.clone(), - )]), - }), - ExprData::ExprVar { .. } => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - ExprData::ExprFieldAccess { .. } => { - let r = match texpr.children.clone().first().cloned() { - Some(base) => resolve_expr_types(&base, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: map_children(&texpr, |child| r.expr.clone()), - diagnostics: r.diagnostics.clone(), - }) - } - ExprData::ExprCall { - call_semantics: cs, - descent_evidence: de, - .. - } => { - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for arg_node in texpr.children.clone().iter().cloned() { - __result.push({ - let val = match arg_node.children.clone().first().cloned() { - Some(v) => v.clone(), - None => arg_node.clone(), - }; - let vr = resolve_expr_types(&val, &env, module_name.clone()); - make_arg_node( - if (arg_node.ident_span.clone() == None) { - None - } else { - Some(authored_name(env.clone(), arg_node.clone())) - }, - vr.expr.clone(), - arg_node.span.clone(), - node_name_span(&arg_node), - ) - }); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for arg_node in texpr.children.clone().iter().cloned() { - __result.extend( - (*{ - let val = match arg_node.children.clone().first().cloned() { - Some(v) => v.clone(), - None => arg_node.clone(), - }; - let vr = resolve_expr_types(&val, &env, module_name.clone()); - vr.diagnostics.clone() - }) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(ExprResolveResult { - expr: make_named_expr_node( - &expr_call_func_at(texpr.clone(), env.source_indices.clone()), - Rc::new(ExprData::ExprCall { - call_semantics: cs.clone(), - descent_evidence: de.clone(), - }), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - node_name_span(&texpr), - ), - diagnostics: all_diags, - }) - } - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => { - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() + ExprData::ExprLiteral { .. } => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), + ExprData::ExprError { kind, message, .. } => Rc::new(ExprResolveResult { + expr: make_expr_error_node(kind.clone(), &message, &texpr.span.clone()), + diagnostics: Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: message.clone(), + span: texpr.span.clone(), +}), module_name.clone())]), +}), + ExprData::ExprVar { .. } => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), + ExprData::ExprFieldAccess { .. } => { + let r = match texpr.children.clone().first().cloned() { + Some(base) => resolve_expr_types(&base, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: map_children(&texpr, |child| r.expr.clone()), + diagnostics: r.diagnostics.clone(), +}) +}, + ExprData::ExprCall { call_semantics: cs, descent_evidence: de, .. } => { + let resolved_children = Rc::new({ let mut __result = Vec::new(); for arg_node in texpr.children.clone().iter().cloned() { __result.push({ + let val = match arg_node.children.clone().first().cloned() { + Some(v) => v.clone(), + None => arg_node.clone(), +}; +let vr = resolve_expr_types(&val, &env, module_name.clone()); +make_arg_node(if (arg_node.ident_span.clone() == None) { + None + } else { + Some(authored_name(env.clone(), arg_node.clone())) + }, vr.expr.clone(), arg_node.span.clone(), node_name_span(&arg_node)) +}); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for arg_node in texpr.children.clone().iter().cloned() { __result.extend((*{ + let val = match arg_node.children.clone().first().cloned() { + Some(v) => v.clone(), + None => arg_node.clone(), +}; +let vr = resolve_expr_types(&val, &env, module_name.clone()); +vr.diagnostics.clone() +}).iter().cloned()); } __result }); +Rc::new(ExprResolveResult { + expr: make_named_expr_node(&expr_call_func_at(texpr.clone(), env.source_indices.clone()), Rc::new(ExprData::ExprCall { + call_semantics: cs.clone(), + descent_evidence: de.clone(), +}), resolved_children, texpr.inferred.clone(), texpr.span.clone(), node_name_span(&texpr)), + diagnostics: all_diags, +}) +}, + ExprData::ExprMethodCall { method_semantics: ms, .. } => { + let resolved_children = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(texpr.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let idx = pair.0.clone(); +let child = pair.1.clone(); +if (idx.clone() == 0) { { - __result.push({ - let idx = pair.0.clone(); - let child = pair.1.clone(); - if (idx.clone() == 0) { - { - let rr = resolve_expr_types(&child, &env, module_name.clone()); - rr.expr.clone() - } - } else { - { - let val = match child.children.clone().first().cloned() { - Some(v) => v.clone(), - None => child.clone(), - }; - let vr = resolve_expr_types(&val, &env, module_name.clone()); - make_arg_node( - if (child.ident_span.clone() == None) { - None - } else { - Some(authored_name_at( - env.source_indices.clone(), - &child, - )) - }, - vr.expr.clone(), - child.span.clone(), - node_name_span(&child), - ) - } - } - }); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() + let rr = resolve_expr_types(&child, &env, module_name.clone()); +rr.expr.clone() +} + } else { { - __result.extend( - (*{ - let idx = pair.0.clone(); - let child = pair.1.clone(); - if (idx.clone() == 0) { - { - let rr = - resolve_expr_types(&child, &env, module_name.clone()); - rr.diagnostics.clone() - } - } else { - { - let val = match child.children.clone().first().cloned() { - Some(v) => v.clone(), - None => child.clone(), - }; - let vr = - resolve_expr_types(&val, &env, module_name.clone()); - vr.diagnostics.clone() - } - } - }) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(ExprResolveResult { - expr: make_named_expr_node( - &expr_method_name_at(texpr.clone(), env.source_indices.clone()), - Rc::new(ExprData::ExprMethodCall { - method_semantics: ms.clone(), - }), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - node_name_span(&texpr), - ), - diagnostics: all_diags, - }) - } - ExprData::ExprMatch => { - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() + let val = match child.children.clone().first().cloned() { + Some(v) => v.clone(), + None => child.clone(), +}; +let vr = resolve_expr_types(&val, &env, module_name.clone()); +make_arg_node(if (child.ident_span.clone() == None) { + None + } else { + Some(authored_name_at(env.source_indices.clone(), &child)) + }, vr.expr.clone(), child.span.clone(), node_name_span(&child)) +} + } +}); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(texpr.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.extend((*{ + let idx = pair.0.clone(); +let child = pair.1.clone(); +if (idx.clone() == 0) { { - __result.push({ - let idx = pair.0.clone(); - let child = pair.1.clone(); - if (idx.clone() == 0) { - { - let sr = resolve_expr_types(&child, &env, module_name.clone()); - sr.expr.clone() - } - } else { - { - let arm_ch = child.children.clone(); - let has_guard = ((arm_ch.clone().len() as i64) == 2); - if has_guard.clone() { - { - let guard_r = match arm_ch.clone().first().cloned() { - Some(g) => resolve_expr_types( - &g, - &env, - module_name.clone(), - ), - None => Rc::new(ExprResolveResult { - expr: child.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let body_r = - match arm_ch.clone().get(1 as usize).cloned() { - Some(b) => resolve_expr_types( - &b, - &env, - module_name.clone(), - ), - None => Rc::new(ExprResolveResult { - expr: child.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - make_arm_node( - match child.match_pattern.clone() { - Some(p) => p.clone(), - None => Rc::new(MatchPattern::Wildcard), - }, - Some(guard_r.expr.clone()), - body_r.expr.clone(), - child.span.clone(), - ) - } - } else { - { - let body_r = match arm_ch.clone().first().cloned() { - Some(b) => resolve_expr_types( - &b, - &env, - module_name.clone(), - ), - None => Rc::new(ExprResolveResult { - expr: child.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - make_arm_node( - match child.match_pattern.clone() { - Some(p) => p.clone(), - None => Rc::new(MatchPattern::Wildcard), - }, - None, - body_r.expr.clone(), - child.span.clone(), - ) - } - } - } - } - }); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() + let rr = resolve_expr_types(&child, &env, module_name.clone()); +rr.diagnostics.clone() +} + } else { { - __result.extend( - (*{ - let idx = pair.0.clone(); - let child = pair.1.clone(); - if (idx.clone() == 0) { - { - let sr = - resolve_expr_types(&child, &env, module_name.clone()); - sr.diagnostics.clone() - } - } else { - { - let arm_ch = child.children.clone(); - let has_guard = ((arm_ch.clone().len() as i64) == 2); - if has_guard.clone() { - { - let guard_r = match arm_ch.clone().first().cloned() - { - Some(g) => resolve_expr_types( - &g, - &env, - module_name.clone(), - ), - None => Rc::new(ExprResolveResult { - expr: child.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let body_r = - match arm_ch.clone().get(1 as usize).cloned() { - Some(b) => resolve_expr_types( - &b, - &env, - module_name.clone(), - ), - None => Rc::new(ExprResolveResult { - expr: child.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - v2_rt::concat( - guard_r.diagnostics.clone(), - body_r.diagnostics.clone(), - ) - } - } else { - { - let body_r = match arm_ch.clone().first().cloned() { - Some(b) => resolve_expr_types( - &b, - &env, - module_name.clone(), - ), - None => Rc::new(ExprResolveResult { - expr: child.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - body_r.diagnostics.clone() - } - } - } - } - }) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprMatch), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: all_diags, - }) - } - ExprData::ExprIf => { - let ch = texpr.children.clone(); - let cr = match ch.clone().first().cloned() { - Some(c) => resolve_expr_types(&c, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let tr = match ch.clone().get(1 as usize).cloned() { - Some(t) => resolve_expr_types(&t, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let er = match ch.clone().get(2 as usize).cloned() { - Some(e) => Some(resolve_expr_types(&e, &env, module_name.clone())), - None => None, - }; - let resolved_children = match er.clone() { - Some(r) => Rc::new(vec![cr.expr.clone(), tr.expr.clone(), r.expr.clone()]), - None => Rc::new(vec![cr.expr.clone(), tr.expr.clone()]), - }; - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprIf), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: v2_rt::concat( - v2_rt::concat(cr.diagnostics.clone(), tr.diagnostics.clone()), - match er.clone() { - Some(r) => r.diagnostics.clone(), - None => Rc::new(vec![]), - }, - ), - }) - } - ExprData::ExprLet => { - let ch = texpr.children.clone(); - let vr = match ch.clone().first().cloned() { - Some(v) => resolve_expr_types(&v, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let br = match ch.clone().get(1 as usize).cloned() { - Some(bd) => Some(resolve_expr_types(&bd, &env, module_name.clone())), - None => None, - }; - let resolved_children = match br.clone() { - Some(r) => Rc::new(vec![vr.expr.clone(), r.expr.clone()]), - None => Rc::new(vec![vr.expr.clone()]), - }; - Rc::new(ExprResolveResult { - expr: make_named_expr_node( - &let_binding_name_at(texpr.clone(), env.source_indices.clone()), - Rc::new(ExprData::ExprLet), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - node_name_span(&texpr), - ), - diagnostics: v2_rt::concat( - vr.diagnostics.clone(), - match br.clone() { - Some(r) => r.diagnostics.clone(), - None => Rc::new(vec![]), - }, - ), - }) - } - ExprData::ExprRecordLit { - parent_enum: pe, .. - } => { - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for fi_node in texpr.children.clone().iter().cloned() { - __result.push({ - let val = match fi_node.children.clone().first().cloned() { - Some(v) => v.clone(), - None => fi_node.clone(), - }; - let vr = resolve_expr_types(&val, &env, module_name.clone()); - make_field_init_node( - &authored_name(env.clone(), fi_node.clone()), - vr.expr.clone(), - fi_node.span.clone(), - node_name_span(&fi_node), - ) - }); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for fi_node in texpr.children.clone().iter().cloned() { - __result.extend( - (*{ - let val = match fi_node.children.clone().first().cloned() { - Some(v) => v.clone(), - None => fi_node.clone(), - }; - let vr = resolve_expr_types(&val, &env, module_name.clone()); - vr.diagnostics.clone() - }) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(ExprResolveResult { - expr: make_named_expr_node( - &authored_name_at(env.source_indices.clone(), &texpr), - Rc::new(ExprData::ExprRecordLit { - parent_enum: pe.clone(), - }), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - node_name_span(&texpr), - ), - diagnostics: all_diags, - }) - } - ExprData::ExprListLit => { - let el_results = Rc::new({ - let mut __result = Vec::new(); - for el in texpr.children.clone().iter().cloned() { - __result.push(resolve_expr_types(&el, &env, module_name.clone())); - } - __result - }); - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for r in el_results.clone().iter().cloned() { - __result.push(r.expr.clone()); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for r in el_results.clone().iter().cloned() { - __result.extend((*r.diagnostics.clone()).iter().cloned()); - } - __result - }); - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprListLit), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: all_diags, - }) - } - ExprData::ExprBinOp { - op, - algebra_field: af, - .. - } => { - let ch = texpr.children.clone(); - let lr = match ch.clone().first().cloned() { - Some(l) => resolve_expr_types(&l, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let rr = match ch.clone().get(1 as usize).cloned() { - Some(r) => resolve_expr_types(&r, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprBinOp { - op: op.clone(), - algebra_field: af.clone(), - }), - Rc::new(vec![lr.expr.clone(), rr.expr.clone()]), - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: v2_rt::concat(lr.diagnostics.clone(), rr.diagnostics.clone()), - }) - } - ExprData::ExprUnaryOp { op, .. } => { - let r = match texpr.children.clone().first().cloned() { - Some(o) => resolve_expr_types(&o, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprUnaryOp { op: op.clone() }), - Rc::new(vec![r.expr.clone()]), - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: r.diagnostics.clone(), - }) - } - ExprData::ExprLambda => { - let lam_param_nodes = Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let r = match texpr.children.clone().first().cloned() { - Some(b) => resolve_expr_types(&b, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLambda), - v2_rt::concat(Rc::new(vec![r.expr.clone()]), lam_param_nodes), - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: r.diagnostics.clone(), - }) - } - ExprData::ExprStringInterp => { - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for part_node in texpr.children.clone().iter().cloned() { - __result.push(match (*part_node.expr_data.clone()).clone() { - ExprData::ExprLiteral { .. } => part_node.clone(), - _ => match part_node.children.clone().first().cloned() { - Some(inner) => { - let r = resolve_expr_types(&inner, &env, module_name.clone()); - make_interp_part_node(r.expr.clone(), part_node.span.clone()) - } - None => part_node.clone(), - }, - }); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for part_node in texpr.children.clone().iter().cloned() { - __result.extend( - (*match (*part_node.expr_data.clone()).clone() { - ExprData::ExprLiteral { .. } => Rc::new(vec![]), - _ => match part_node.children.clone().first().cloned() { - Some(inner) => { - let r = - resolve_expr_types(&inner, &env, module_name.clone()); - r.diagnostics.clone() - } - None => Rc::new(vec![]), - }, - }) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprStringInterp), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: all_diags, - }) - } - ExprData::ExprBlock => { - let stmt_results = Rc::new({ - let mut __result = Vec::new(); - for s in texpr.children.clone().iter().cloned() { - __result.push(resolve_expr_types(&s, &env, module_name.clone())); - } - __result - }); - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for r in stmt_results.clone().iter().cloned() { - __result.push(r.expr.clone()); - } - __result - }); - let all_diags = Rc::new({ - let mut __result = Vec::new(); - for r in stmt_results.clone().iter().cloned() { - __result.extend((*r.diagnostics.clone()).iter().cloned()); - } - __result - }); - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprBlock), - resolved_children, - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: all_diags, - }) - } - ExprData::ExprCast => { - let ch = texpr.children.clone(); - let r = match ch.clone().first().cloned() { - Some(inner) => resolve_expr_types(&inner, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let tr = match ch.clone().get(1 as usize).cloned() { - Some(target) => resolve_node(target.clone(), env.clone(), module_name.clone()), - None => Rc::new(NodeResolveResult { - resolved: unit_type(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprCast), - Rc::new(vec![r.expr.clone(), tr.resolved.clone()]), - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: v2_rt::concat(r.diagnostics.clone(), tr.diagnostics.clone()), - }) - } - ExprData::ExprForEach => { - let ch = texpr.children.clone(); - let cr = match ch.clone().first().cloned() { - Some(c) => resolve_expr_types(&c, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let br = match ch.clone().get(1 as usize).cloned() { - Some(b) => resolve_expr_types(&b, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: make_named_expr_node( - &foreach_variable_at(texpr.clone(), env.source_indices.clone()), - Rc::new(ExprData::ExprForEach), - Rc::new(vec![cr.expr.clone(), br.expr.clone()]), - texpr.inferred.clone(), - texpr.span.clone(), - node_name_span(&texpr), - ), - diagnostics: v2_rt::concat(cr.diagnostics.clone(), br.diagnostics.clone()), - }) - } - ExprData::ExprIndex => { - let ch = texpr.children.clone(); - let br = match ch.clone().first().cloned() { - Some(base) => resolve_expr_types(&base, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let ir = match ch.clone().get(1 as usize).cloned() { - Some(index) => resolve_expr_types(&index, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprIndex), - Rc::new(vec![br.expr.clone(), ir.expr.clone()]), - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: v2_rt::concat(br.diagnostics.clone(), ir.diagnostics.clone()), - }) - } - ExprData::ExprSlice => { - let ch = texpr.children.clone(); - let br = match ch.clone().first().cloned() { - Some(base) => resolve_expr_types(&base, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let sr = match ch.clone().get(1 as usize).cloned() { - Some(start) => resolve_expr_types(&start, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - let er = match ch.clone().get(2 as usize).cloned() { - Some(end_e) => resolve_expr_types(&end_e, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprSlice), - Rc::new(vec![br.expr.clone(), sr.expr.clone(), er.expr.clone()]), - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: v2_rt::concat( - v2_rt::concat(br.diagnostics.clone(), sr.diagnostics.clone()), - er.diagnostics.clone(), - ), - }) - } - ExprData::ExprReturn => { - let r = match texpr.children.clone().first().cloned() { - Some(inner) => resolve_expr_types(&inner, &env, module_name.clone()), - None => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - }; - Rc::new(ExprResolveResult { - expr: make_expr_node( - Rc::new(ExprData::ExprReturn), - Rc::new(vec![r.expr.clone()]), - texpr.inferred.clone(), - texpr.span.clone(), - ), - diagnostics: r.diagnostics.clone(), - }) - } - ExprData::NoExprData => Rc::new(ExprResolveResult { - expr: texpr.clone(), - diagnostics: Rc::new(vec![]), - }), - } - }) + let val = match child.children.clone().first().cloned() { + Some(v) => v.clone(), + None => child.clone(), +}; +let vr = resolve_expr_types(&val, &env, module_name.clone()); +vr.diagnostics.clone() } - -pub fn fn_type_param_names( - item: Rc, - source_indices: Rc>>, -) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for p in Rc::new({ - let mut __result = Vec::new(); - for p in item.params.clone().iter().cloned() { - if (param_node_name_at(p.clone(), source_indices.clone()).as_str() - == authored_name_at(source_indices.clone(), ¶m_node_type_expr(&p)).as_str()) - { - __result.push(p); } - } - __result - }) - .iter() - .cloned() - { - __result.push(param_node_name_at(p.clone(), source_indices.clone())); - } - __result - }) +}).iter().cloned()); } __result }); +Rc::new(ExprResolveResult { + expr: make_named_expr_node(&expr_method_name_at(texpr.clone(), env.source_indices.clone()), Rc::new(ExprData::ExprMethodCall { + method_semantics: ms.clone(), +}), resolved_children, texpr.inferred.clone(), texpr.span.clone(), node_name_span(&texpr)), + diagnostics: all_diags, +}) +}, + ExprData::ExprMatch => { + let resolved_children = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(texpr.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.push({ + let idx = pair.0.clone(); +let child = pair.1.clone(); +if (idx.clone() == 0) { + { + let sr = resolve_expr_types(&child, &env, module_name.clone()); +sr.expr.clone() } - -pub fn has_duplicate_type_param_name(names: &Rc>) -> bool { - { - let mut __found = false; - for pair in Rc::new( - names - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if { + } else { + { + let arm_ch = child.children.clone(); +let has_guard = ((arm_ch.clone().len() as i64) == 2); +if has_guard.clone() { + { + let guard_r = match arm_ch.clone().first().cloned() { + Some(g) => resolve_expr_types(&g, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: child.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let body_r = match arm_ch.clone().get(1 as usize).cloned() { + Some(b) => resolve_expr_types(&b, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: child.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +make_arm_node(match child.match_pattern.clone() { + Some(p) => p.clone(), + None => Rc::new(MatchPattern::Wildcard), +}, Some(guard_r.expr.clone()), body_r.expr.clone(), child.span.clone()) +} + } else { + { + let body_r = match arm_ch.clone().first().cloned() { + Some(b) => resolve_expr_types(&b, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: child.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +make_arm_node(match child.match_pattern.clone() { + Some(p) => p.clone(), + None => Rc::new(MatchPattern::Wildcard), +}, None, body_r.expr.clone(), child.span.clone()) +} + } +} + } +}); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(texpr.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { __result.extend((*{ let idx = pair.0.clone(); - let s = pair.1.clone(); - { - let mut __found = false; - for other in Rc::new( - names - .clone() - .iter() - .cloned() - .skip((idx.clone() + 1) as usize) - .collect::>(), - ) - .iter() - .cloned() +let child = pair.1.clone(); +if (idx.clone() == 0) { { - if (other.clone().as_str() == s.clone().as_str()) { - __found = true; - break; + let sr = resolve_expr_types(&child, &env, module_name.clone()); +sr.diagnostics.clone() +} + } else { + { + let arm_ch = child.children.clone(); +let has_guard = ((arm_ch.clone().len() as i64) == 2); +if has_guard.clone() { + { + let guard_r = match arm_ch.clone().first().cloned() { + Some(g) => resolve_expr_types(&g, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: child.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let body_r = match arm_ch.clone().get(1 as usize).cloned() { + Some(b) => resolve_expr_types(&b, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: child.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +v2_rt::concat(guard_r.diagnostics.clone(), body_r.diagnostics.clone()) +} + } else { + { + let body_r = match arm_ch.clone().first().cloned() { + Some(b) => resolve_expr_types(&b, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: child.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +body_r.diagnostics.clone() +} } - } - __found +} } - } { - __found = true; - break; - } - } - __found - } +}).iter().cloned()); } __result }); +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprMatch), resolved_children, texpr.inferred.clone(), texpr.span.clone()), + diagnostics: all_diags, +}) +}, + ExprData::ExprIf => { + let ch = texpr.children.clone(); +let cr = match ch.clone().first().cloned() { + Some(c) => resolve_expr_types(&c, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let tr = match ch.clone().get(1 as usize).cloned() { + Some(t) => resolve_expr_types(&t, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let er = match ch.clone().get(2 as usize).cloned() { + Some(e) => Some(resolve_expr_types(&e, &env, module_name.clone())), + None => None, +}; +let resolved_children = match er.clone() { + Some(r) => Rc::new(vec![cr.expr.clone(), tr.expr.clone(), r.expr.clone()]), + None => Rc::new(vec![cr.expr.clone(), tr.expr.clone()]), +}; +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprIf), resolved_children, texpr.inferred.clone(), texpr.span.clone()), + diagnostics: v2_rt::concat(v2_rt::concat(cr.diagnostics.clone(), tr.diagnostics.clone()), match er.clone() { + Some(r) => r.diagnostics.clone(), + None => Rc::new(vec![]), +}), +}) +}, + ExprData::ExprLet => { + let ch = texpr.children.clone(); +let vr = match ch.clone().first().cloned() { + Some(v) => resolve_expr_types(&v, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let br = match ch.clone().get(1 as usize).cloned() { + Some(bd) => Some(resolve_expr_types(&bd, &env, module_name.clone())), + None => None, +}; +let resolved_children = match br.clone() { + Some(r) => Rc::new(vec![vr.expr.clone(), r.expr.clone()]), + None => Rc::new(vec![vr.expr.clone()]), +}; +Rc::new(ExprResolveResult { + expr: make_named_expr_node(&let_binding_name_at(texpr.clone(), env.source_indices.clone()), Rc::new(ExprData::ExprLet), resolved_children, texpr.inferred.clone(), texpr.span.clone(), node_name_span(&texpr)), + diagnostics: v2_rt::concat(vr.diagnostics.clone(), match br.clone() { + Some(r) => r.diagnostics.clone(), + None => Rc::new(vec![]), +}), +}) +}, + ExprData::ExprRecordLit { parent_enum: pe, .. } => { + let resolved_children = Rc::new({ let mut __result = Vec::new(); for fi_node in texpr.children.clone().iter().cloned() { __result.push({ + let val = match fi_node.children.clone().first().cloned() { + Some(v) => v.clone(), + None => fi_node.clone(), +}; +let vr = resolve_expr_types(&val, &env, module_name.clone()); +make_field_init_node(&authored_name(env.clone(), fi_node.clone()), vr.expr.clone(), fi_node.span.clone(), node_name_span(&fi_node)) +}); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for fi_node in texpr.children.clone().iter().cloned() { __result.extend((*{ + let val = match fi_node.children.clone().first().cloned() { + Some(v) => v.clone(), + None => fi_node.clone(), +}; +let vr = resolve_expr_types(&val, &env, module_name.clone()); +vr.diagnostics.clone() +}).iter().cloned()); } __result }); +Rc::new(ExprResolveResult { + expr: make_named_expr_node(&authored_name_at(env.source_indices.clone(), &texpr), Rc::new(ExprData::ExprRecordLit { + parent_enum: pe.clone(), +}), resolved_children, texpr.inferred.clone(), texpr.span.clone(), node_name_span(&texpr)), + diagnostics: all_diags, +}) +}, + ExprData::ExprListLit => { + let el_results = Rc::new({ let mut __result = Vec::new(); for el in texpr.children.clone().iter().cloned() { __result.push(resolve_expr_types(&el, &env, module_name.clone())); } __result }); +let resolved_children = Rc::new({ let mut __result = Vec::new(); for r in el_results.clone().iter().cloned() { __result.push(r.expr.clone()); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for r in el_results.clone().iter().cloned() { __result.extend((*r.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprListLit), resolved_children, texpr.inferred.clone(), texpr.span.clone()), + diagnostics: all_diags, +}) +}, + ExprData::ExprBinOp { op, algebra_field: af, .. } => { + let ch = texpr.children.clone(); +let lr = match ch.clone().first().cloned() { + Some(l) => resolve_expr_types(&l, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let rr = match ch.clone().get(1 as usize).cloned() { + Some(r) => resolve_expr_types(&r, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprBinOp { + op: op.clone(), + algebra_field: af.clone(), +}), Rc::new(vec![lr.expr.clone(), rr.expr.clone()]), texpr.inferred.clone(), texpr.span.clone()), + diagnostics: v2_rt::concat(lr.diagnostics.clone(), rr.diagnostics.clone()), +}) +}, + ExprData::ExprUnaryOp { op, .. } => { + let r = match texpr.children.clone().first().cloned() { + Some(o) => resolve_expr_types(&o, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprUnaryOp { + op: op.clone(), +}), Rc::new(vec![r.expr.clone()]), texpr.inferred.clone(), texpr.span.clone()), + diagnostics: r.diagnostics.clone(), +}) +}, + ExprData::ExprLambda => { + let lam_param_nodes = Rc::new(texpr.children.clone().iter().cloned().skip(1 as usize).collect::>()); +let r = match texpr.children.clone().first().cloned() { + Some(b) => resolve_expr_types(&b, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprLambda), v2_rt::concat(Rc::new(vec![r.expr.clone()]), lam_param_nodes), texpr.inferred.clone(), texpr.span.clone()), + diagnostics: r.diagnostics.clone(), +}) +}, + ExprData::ExprStringInterp => { + let resolved_children = Rc::new({ let mut __result = Vec::new(); for part_node in texpr.children.clone().iter().cloned() { __result.push(match (*part_node.expr_data.clone()).clone() { + ExprData::ExprLiteral { .. } => part_node.clone(), + _ => match part_node.children.clone().first().cloned() { + Some(inner) => { + let r = resolve_expr_types(&inner, &env, module_name.clone()); +make_interp_part_node(r.expr.clone(), part_node.span.clone()) +}, + None => part_node.clone(), +}, +}); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for part_node in texpr.children.clone().iter().cloned() { __result.extend((*match (*part_node.expr_data.clone()).clone() { + ExprData::ExprLiteral { .. } => Rc::new(vec![]), + _ => match part_node.children.clone().first().cloned() { + Some(inner) => { + let r = resolve_expr_types(&inner, &env, module_name.clone()); +r.diagnostics.clone() +}, + None => Rc::new(vec![]), +}, +}).iter().cloned()); } __result }); +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprStringInterp), resolved_children, texpr.inferred.clone(), texpr.span.clone()), + diagnostics: all_diags, +}) +}, + ExprData::ExprBlock => { + let stmt_results = Rc::new({ let mut __result = Vec::new(); for s in texpr.children.clone().iter().cloned() { __result.push(resolve_expr_types(&s, &env, module_name.clone())); } __result }); +let resolved_children = Rc::new({ let mut __result = Vec::new(); for r in stmt_results.clone().iter().cloned() { __result.push(r.expr.clone()); } __result }); +let all_diags = Rc::new({ let mut __result = Vec::new(); for r in stmt_results.clone().iter().cloned() { __result.extend((*r.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprBlock), resolved_children, texpr.inferred.clone(), texpr.span.clone()), + diagnostics: all_diags, +}) +}, + ExprData::ExprCast => { + let ch = texpr.children.clone(); +let r = match ch.clone().first().cloned() { + Some(inner) => resolve_expr_types(&inner, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let tr = match ch.clone().get(1 as usize).cloned() { + Some(target) => resolve_node(target.clone(), env.clone(), module_name.clone()), + None => Rc::new(NodeResolveResult { + resolved: unit_type(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprCast), Rc::new(vec![r.expr.clone(), tr.resolved.clone()]), texpr.inferred.clone(), texpr.span.clone()), + diagnostics: v2_rt::concat(r.diagnostics.clone(), tr.diagnostics.clone()), +}) +}, + ExprData::ExprForEach => { + let ch = texpr.children.clone(); +let cr = match ch.clone().first().cloned() { + Some(c) => resolve_expr_types(&c, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let br = match ch.clone().get(1 as usize).cloned() { + Some(b) => resolve_expr_types(&b, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: make_named_expr_node(&foreach_variable_at(texpr.clone(), env.source_indices.clone()), Rc::new(ExprData::ExprForEach), Rc::new(vec![cr.expr.clone(), br.expr.clone()]), texpr.inferred.clone(), texpr.span.clone(), node_name_span(&texpr)), + diagnostics: v2_rt::concat(cr.diagnostics.clone(), br.diagnostics.clone()), +}) +}, + ExprData::ExprIndex => { + let ch = texpr.children.clone(); +let br = match ch.clone().first().cloned() { + Some(base) => resolve_expr_types(&base, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let ir = match ch.clone().get(1 as usize).cloned() { + Some(index) => resolve_expr_types(&index, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprIndex), Rc::new(vec![br.expr.clone(), ir.expr.clone()]), texpr.inferred.clone(), texpr.span.clone()), + diagnostics: v2_rt::concat(br.diagnostics.clone(), ir.diagnostics.clone()), +}) +}, + ExprData::ExprSlice => { + let ch = texpr.children.clone(); +let br = match ch.clone().first().cloned() { + Some(base) => resolve_expr_types(&base, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let sr = match ch.clone().get(1 as usize).cloned() { + Some(start) => resolve_expr_types(&start, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +let er = match ch.clone().get(2 as usize).cloned() { + Some(end_e) => resolve_expr_types(&end_e, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprSlice), Rc::new(vec![br.expr.clone(), sr.expr.clone(), er.expr.clone()]), texpr.inferred.clone(), texpr.span.clone()), + diagnostics: v2_rt::concat(v2_rt::concat(br.diagnostics.clone(), sr.diagnostics.clone()), er.diagnostics.clone()), +}) +}, + ExprData::ExprReturn => { + let r = match texpr.children.clone().first().cloned() { + Some(inner) => resolve_expr_types(&inner, &env, module_name.clone()), + None => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +}; +Rc::new(ExprResolveResult { + expr: make_expr_node(Rc::new(ExprData::ExprReturn), Rc::new(vec![r.expr.clone()]), texpr.inferred.clone(), texpr.span.clone()), + diagnostics: r.diagnostics.clone(), +}) +}, + ExprData::NoExprData => Rc::new(ExprResolveResult { + expr: texpr.clone(), + diagnostics: Rc::new(vec![]), +}), +} + }) +} + +pub fn fn_type_param_names(item: Rc, source_indices: Rc>>) -> Rc> { + Rc::new({ let mut __result = Vec::new(); for p in Rc::new({ let mut __result = Vec::new(); for p in item.params.clone().iter().cloned() { if (param_node_name_at(p.clone(), source_indices.clone()).as_str() == authored_name_at(source_indices.clone(), ¶m_node_type_expr(&p)).as_str()) { __result.push(p); } } __result }).iter().cloned() { __result.push(param_node_name_at(p.clone(), source_indices.clone())); } __result }) +} + +pub fn has_duplicate_type_param_name(names: &Rc>) -> bool { + { let mut __found = false; for pair in Rc::new(names.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if { + let idx = pair.0.clone(); +let s = pair.1.clone(); +{ let mut __found = false; for other in Rc::new(names.clone().iter().cloned().skip((idx.clone() + 1) as usize).collect::>()).iter().cloned() { if (other.clone().as_str() == s.clone().as_str()) { __found = true; break; } } __found } +} { __found = true; break; } } __found } } -pub fn resolve_item_types( - item: &Rc, - env: &Rc, - module_name: &String, -) -> Rc { +pub fn resolve_item_types(item: &Rc, env: &Rc, module_name: &String) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let tp_names = fn_type_param_names(item.clone(), env.source_indices.clone()); - let collision_diags = if has_duplicate_type_param_name(&tp_names) { - Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { + { + let tp_names = fn_type_param_names(item.clone(), env.source_indices.clone()); +let collision_diags = if has_duplicate_type_param_name(&tp_names) { + Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::InternalError { message: v2_rt::concat(v2_rt::concat("type param name collides with a value param in fn '".to_string(), authored_name_at(env.source_indices.clone(), &item)), "' — a value param shares its name with a declared type param (e.g., `fn f(T: T)`). Rename the value param, or dissolve via ParamKind / params-slot partition.".to_string()), span: item.span.clone(), }), module_name.clone())]) - } else { - Rc::new(vec![]) - }; - let env = tp_names.clone().iter().cloned().fold( - env.clone(), - |e: Rc, tp_name: String| { - Rc::new(TypeEnv { - bindings: v2_rt::rc_map_insert( - e.bindings.clone(), - intern(&e.intern_table.clone(), &tp_name).id.clone(), - Rc::new(TypeBinding { - name: tp_name.clone(), - resolved: Rc::new(Node { - name: tp_name.clone(), - span: kernel_span(&tp_name), - ident_span: Some(kernel_span(&tp_name)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::TypeVariable { - id: tp_name.clone(), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - provenance: Rc::new(SubValueRelation::SubValueUnknown), - }), - ), - recursive_types: e.recursive_types.clone(), - recursive_type_set: e.recursive_type_set.clone(), - inductive_fields: e.inductive_fields.clone(), - source_indices: e.source_indices.clone(), - intern_table: e.intern_table.clone(), - }) - }, - ); - let param_results = Rc::new({ - let mut __result = Vec::new(); - for p in item.params.clone().iter().cloned() { - __result.push(resolve_param(&p, &env, &module_name)); - } - __result - }); - let resolved_params = Rc::new({ - let mut __result = Vec::new(); - for pr in param_results.clone().iter().cloned() { - __result.push(pr.param.clone()); - } - __result - }); - let param_diags = Rc::new({ - let mut __result = Vec::new(); - for pr in param_results.clone().iter().cloned() { - __result.extend((*pr.diagnostics.clone()).iter().cloned()); - } - __result - }); - let ret_result = - resolve_optional_node(&item.inferred.clone(), env.clone(), module_name.clone()); - let ret_resolved = ret_result.resolved.clone(); - let ret_diags = ret_result.diagnostics.clone(); - let resolved_ret = if (item.inferred.clone() == None) { - None - } else { - Some(Rc::new(InferredNode::Resolved { node: ret_resolved })) - }; - let use_results = Rc::new({ - let mut __result = Vec::new(); - for u in item.uses.clone().iter().cloned() { - __result.push(resolve_resource_use(&u, &env, module_name.clone())); - } - __result - }); - let resolved_uses = Rc::new({ - let mut __result = Vec::new(); - for ur in use_results.clone().iter().cloned() { - __result.push(ur.resource_use.clone()); - } - __result - }); - let use_diags = Rc::new({ - let mut __result = Vec::new(); - for ur in use_results.clone().iter().cloned() { - __result.extend((*ur.diagnostics.clone()).iter().cloned()); - } - __result - }); - let body_resolved = if (item.body.clone() == None) { - Rc::new(ExprResolveResult { - expr: item.clone(), - diagnostics: Rc::new(vec![]), - }) - } else { - resolve_expr_types( - &item.body.clone().clone().unwrap(), - &env, - module_name.clone(), - ) - }; - let resolved_body = if (item.body.clone() == None) { - None - } else { - Some(body_resolved.expr.clone()) - }; - let body_diags = if (item.body.clone() == None) { - Rc::new(vec![]) - } else { - body_resolved.diagnostics.clone() - }; - let anno_resolved = if (item.type_annotation.clone() == None) { - Rc::new(NodeResolveResult { - resolved: unit_type(), - diagnostics: Rc::new(vec![]), - }) - } else { - resolve_node( - item.type_annotation.clone().clone().unwrap(), - env.clone(), - module_name.clone(), - ) - }; - let resolved_anno = if (item.type_annotation.clone() == None) { - None - } else { - Some(anno_resolved.resolved.clone()) - }; - let anno_diags = anno_resolved.diagnostics.clone(); - let transport_resolved = if (item.transport.clone() == None) { - Rc::new(TransportResolveResult { - transport: local_transport_node(no_span()), - diagnostics: Rc::new(vec![]), - }) - } else { - resolve_transport_binding(&item.transport.clone().clone().unwrap(), &env, &module_name) - }; - let resolved_transport = if (item.transport.clone() == None) { - None - } else { - Some(transport_resolved.transport.clone()) - }; - let transport_diags = transport_resolved.diagnostics.clone(); - let prop_results = Rc::new({ - let mut __result = Vec::new(); - for p in item.properties.clone().iter().cloned() { - __result.push(resolve_field_init(&p, &env, module_name.clone())); - } - __result - }); - let resolved_props = Rc::new({ - let mut __result = Vec::new(); - for pr in prop_results.clone().iter().cloned() { - __result.push(pr.field_init.clone()); - } - __result - }); - let prop_diags = Rc::new({ - let mut __result = Vec::new(); - for pr in prop_results.clone().iter().cloned() { - __result.extend((*pr.diagnostics.clone()).iter().cloned()); - } - __result - }); - let child_results = Rc::new({ - let mut __result = Vec::new(); - for child in item.children.clone().iter().cloned() { - __result.push(resolve_item_types(&child, &env, &module_name)); - } - __result - }); - let resolved_children = Rc::new({ - let mut __result = Vec::new(); - for cr in child_results.clone().iter().cloned() { - __result.push(cr.item.clone()); - } - __result - }); - let child_diags = Rc::new({ - let mut __result = Vec::new(); - for cr in child_results.clone().iter().cloned() { - __result.extend((*cr.diagnostics.clone()).iter().cloned()); - } - __result - }); - Rc::new(ItemResult { - item: Rc::new(Node { - name: item.name.clone(), - span: item.span.clone(), - ident_span: item.ident_span.clone(), - children: resolved_children, - params: resolved_params, - inferred: resolved_ret, - return_cardinality: item.return_cardinality.clone(), - uses: resolved_uses, - body: resolved_body, - connective: item.connective.clone(), - transport: resolved_transport, - properties: resolved_props, - type_annotation: resolved_anno, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(collision_diags, param_diags), - ret_diags, - ), - use_diags, - ), - body_diags, - ), - anno_diags, - ), - transport_diags, - ), - prop_diags, - ), - child_diags, - ), - }) + } else { + Rc::new(vec![]) + }; +let env = tp_names.clone().iter().cloned().fold(env.clone(), |e: Rc, tp_name: String| Rc::new(TypeEnv { + bindings: v2_rt::rc_map_insert(e.bindings.clone(), intern(&e.intern_table.clone(), &tp_name).id.clone(), Rc::new(TypeBinding { + name: tp_name.clone(), + resolved: Rc::new(Node { + name: tp_name.clone(), + span: kernel_span(&tp_name), + ident_span: Some(kernel_span(&tp_name)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::TypeVariable { + id: tp_name.clone(), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + provenance: Rc::new(SubValueRelation::SubValueUnknown), +})), + recursive_types: e.recursive_types.clone(), + recursive_type_set: e.recursive_type_set.clone(), + inductive_fields: e.inductive_fields.clone(), + source_indices: e.source_indices.clone(), + intern_table: e.intern_table.clone(), +})); +let param_results = Rc::new({ let mut __result = Vec::new(); for p in item.params.clone().iter().cloned() { __result.push(resolve_param(&p, &env, &module_name)); } __result }); +let resolved_params = Rc::new({ let mut __result = Vec::new(); for pr in param_results.clone().iter().cloned() { __result.push(pr.param.clone()); } __result }); +let param_diags = Rc::new({ let mut __result = Vec::new(); for pr in param_results.clone().iter().cloned() { __result.extend((*pr.diagnostics.clone()).iter().cloned()); } __result }); +let ret_result = resolve_optional_node(&item.inferred.clone(), env.clone(), module_name.clone()); +let ret_resolved = ret_result.resolved.clone(); +let ret_diags = ret_result.diagnostics.clone(); +let resolved_ret = if (item.inferred.clone() == None) { + None + } else { + Some(Rc::new(InferredNode::Resolved { + node: ret_resolved, +})) + }; +let use_results = Rc::new({ let mut __result = Vec::new(); for u in item.uses.clone().iter().cloned() { __result.push(resolve_resource_use(&u, &env, module_name.clone())); } __result }); +let resolved_uses = Rc::new({ let mut __result = Vec::new(); for ur in use_results.clone().iter().cloned() { __result.push(ur.resource_use.clone()); } __result }); +let use_diags = Rc::new({ let mut __result = Vec::new(); for ur in use_results.clone().iter().cloned() { __result.extend((*ur.diagnostics.clone()).iter().cloned()); } __result }); +let body_resolved = if (item.body.clone() == None) { + Rc::new(ExprResolveResult { + expr: item.clone(), + diagnostics: Rc::new(vec![]), +}) + } else { + resolve_expr_types(&item.body.clone().clone().unwrap(), &env, module_name.clone()) + }; +let resolved_body = if (item.body.clone() == None) { + None + } else { + Some(body_resolved.expr.clone()) + }; +let body_diags = if (item.body.clone() == None) { + Rc::new(vec![]) + } else { + body_resolved.diagnostics.clone() + }; +let anno_resolved = if (item.type_annotation.clone() == None) { + Rc::new(NodeResolveResult { + resolved: unit_type(), + diagnostics: Rc::new(vec![]), +}) + } else { + resolve_node(item.type_annotation.clone().clone().unwrap(), env.clone(), module_name.clone()) + }; +let resolved_anno = if (item.type_annotation.clone() == None) { + None + } else { + Some(anno_resolved.resolved.clone()) + }; +let anno_diags = anno_resolved.diagnostics.clone(); +let transport_resolved = if (item.transport.clone() == None) { + Rc::new(TransportResolveResult { + transport: local_transport_node(no_span()), + diagnostics: Rc::new(vec![]), +}) + } else { + resolve_transport_binding(&item.transport.clone().clone().unwrap(), &env, &module_name) + }; +let resolved_transport = if (item.transport.clone() == None) { + None + } else { + Some(transport_resolved.transport.clone()) + }; +let transport_diags = transport_resolved.diagnostics.clone(); +let prop_results = Rc::new({ let mut __result = Vec::new(); for p in item.properties.clone().iter().cloned() { __result.push(resolve_field_init(&p, &env, module_name.clone())); } __result }); +let resolved_props = Rc::new({ let mut __result = Vec::new(); for pr in prop_results.clone().iter().cloned() { __result.push(pr.field_init.clone()); } __result }); +let prop_diags = Rc::new({ let mut __result = Vec::new(); for pr in prop_results.clone().iter().cloned() { __result.extend((*pr.diagnostics.clone()).iter().cloned()); } __result }); +let child_results = Rc::new({ let mut __result = Vec::new(); for child in item.children.clone().iter().cloned() { __result.push(resolve_item_types(&child, &env, &module_name)); } __result }); +let resolved_children = Rc::new({ let mut __result = Vec::new(); for cr in child_results.clone().iter().cloned() { __result.push(cr.item.clone()); } __result }); +let child_diags = Rc::new({ let mut __result = Vec::new(); for cr in child_results.clone().iter().cloned() { __result.extend((*cr.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(ItemResult { + item: Rc::new(Node { + name: item.name.clone(), + span: item.span.clone(), + ident_span: item.ident_span.clone(), + children: resolved_children, + params: resolved_params, + inferred: resolved_ret, + return_cardinality: item.return_cardinality.clone(), + uses: resolved_uses, + body: resolved_body, + connective: item.connective.clone(), + transport: resolved_transport, + properties: resolved_props, + type_annotation: resolved_anno, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(collision_diags, param_diags), ret_diags), use_diags), body_diags), anno_diags), transport_diags), prop_diags), child_diags), +}) +} }) } diff --git a/src/v2/stage0/src/v2_compiler_infer_service.rs b/src/v2/stage0/src/v2_compiler_infer_service.rs index 8dfabfec682..5049a189788 100644 --- a/src/v2/stage0/src/v2_compiler_infer_service.rs +++ b/src/v2/stage0/src/v2_compiler_infer_service.rs @@ -1,26 +1,20 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_service -pub use crate::std_types::SourceSpan; -use crate::v2_compiler_infer_items::ItemKind::FuncItem; -pub use crate::v2_compiler_infer_items::{inferred_to_outputs, ItemInfo, ItemKind, TypedModule}; -pub use crate::v2_compiler_infer_types::{emit_map_has, nominal_type_ref}; -use crate::v2_rt; -use crate::v2_std_core::Cardinality::Required; -use crate::v2_std_core::Connective::{Conj, NoConnective}; -use crate::v2_std_core::ExprData::{ - ExprCall, ExprFieldAccess, ExprMethodCall, ExprVar, NoExprData, -}; -use crate::v2_std_core::InferredNode::Resolved; -pub use crate::v2_std_core::{ - authored_name_at, expr_call_func_at, expr_var_name_at, field_access_base, - field_access_field_at, method_receiver, no_span, param_node_type_expr, unit_type, Cardinality, - Connective, ExprData, InferredNode, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan}; +pub use crate::v2_std_core::{Node, Connective, ExprData, Cardinality, InferredNode, NewlineIndex, no_span, unit_type, expr_var_name_at, expr_call_func_at, field_access_field_at, field_access_base, method_receiver, param_node_type_expr, authored_name_at}; +use crate::v2_std_core::Connective::{Conj, NoConnective}; +use crate::v2_std_core::ExprData::{NoExprData, ExprFieldAccess, ExprMethodCall, ExprCall, ExprVar}; +use crate::v2_std_core::Cardinality::{Required}; +use crate::v2_std_core::InferredNode::{Resolved}; +pub use crate::v2_compiler_infer_types::{emit_map_has, nominal_type_ref}; +pub use crate::v2_compiler_infer_items::{ItemInfo, ItemKind, TypedModule, inferred_to_outputs}; +use crate::v2_compiler_infer_items::ItemKind::{FuncItem}; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct UniqueAccum { @@ -41,165 +35,114 @@ pub struct ServiceMethodResult { pub op_params: Rc>>, } -pub fn is_typed_service_call_receiver( - receiver: &Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_typed_service_call_receiver(receiver: &Rc, source_indices: Rc>>) -> bool { match (*receiver.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let f = field_access_field_at(receiver.clone(), source_indices); - let b = field_access_base(receiver.clone()); - match (*b.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - match Rc::new(f.chars().map(|c| c as i64).collect::>()) - .first() - .cloned() - { - Some(ch) => ((ch.clone() >= 65) && (ch.clone() <= 90)), - None => false, - } - } - _ => false, - } - } - _ => false, - } + ExprData::ExprFieldAccess { .. } => { + let f = field_access_field_at(receiver.clone(), source_indices); +let b = field_access_base(receiver.clone()); +match (*b.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => match Rc::new(f.chars().map(|c| c as i64).collect::>()).first().cloned() { + Some(ch) => ((ch.clone() >= 65) && (ch.clone() <= 90)), + None => false, +}, + _ => false, +} +}, + _ => false, +} } -pub fn extract_typed_service_name( - receiver: &Rc, - source_indices: &Rc>>, -) -> Option { +pub fn extract_typed_service_name(receiver: &Rc, source_indices: &Rc>>) -> Option { match (*receiver.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let f = field_access_field_at(receiver.clone(), source_indices.clone()); - let b = field_access_base(receiver.clone()); - match (*b.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let ns = expr_var_name_at(b.clone(), source_indices.clone()); - Some(v2_rt::concat(v2_rt::concat(ns, ".".to_string()), f)) - } - _ => None, - } - } - _ => None, - } + ExprData::ExprFieldAccess { .. } => { + let f = field_access_field_at(receiver.clone(), source_indices.clone()); +let b = field_access_base(receiver.clone()); +match (*b.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let ns = expr_var_name_at(b.clone(), source_indices.clone()); +Some(v2_rt::concat(v2_rt::concat(ns, ".".to_string()), f)) +}, + _ => None, +} +}, + _ => None, +} } -pub fn collect_typed_service_calls( - texpr: Rc, - source_indices: Rc>>, -) -> Rc> { +pub fn collect_typed_service_calls(texpr: Rc, source_indices: Rc>>) -> Rc> { { - let result = collect_typed_service_calls_into( - &texpr, - &Rc::new(UniqueAccum { - seen: v2_rt::rc_empty_map::(), - result: Rc::new(vec![]), - }), - &source_indices, - ); - result.result.clone() - } + let result = collect_typed_service_calls_into(&texpr, &Rc::new(UniqueAccum { + seen: v2_rt::rc_empty_map::(), + result: Rc::new(vec![]), +}), &source_indices); +result.result.clone() +} } -pub fn collect_typed_service_calls_into( - texpr: &Rc, - acc: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn collect_typed_service_calls_into(texpr: &Rc, acc: &Rc, source_indices: &Rc>>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let this_acc = match (*texpr.expr_data.clone()).clone() { - ExprData::ExprMethodCall { .. } => { + { + let this_acc = match (*texpr.expr_data.clone()).clone() { + ExprData::ExprMethodCall { .. } => { let r = method_receiver(texpr.clone()); - if is_typed_service_call_receiver(&r, source_indices.clone()) { +if is_typed_service_call_receiver(&r, source_indices.clone()) { match extract_typed_service_name(&r, &source_indices) { - Some(service_name) => { - if emit_map_has(acc.seen.clone(), service_name.clone()) { - acc.clone() - } else { - Rc::new(UniqueAccum { - seen: v2_rt::rc_map_insert( - acc.seen.clone(), - service_name.clone(), - true, - ), - result: v2_rt::rc_list_push( - acc.result.clone(), - service_name.clone(), - ), - }) - } - } - None => acc.clone(), - } + Some(service_name) => if emit_map_has(acc.seen.clone(), service_name.clone()) { + acc.clone() + } else { + Rc::new(UniqueAccum { + seen: v2_rt::rc_map_insert(acc.seen.clone(), service_name.clone(), true), + result: v2_rt::rc_list_push(acc.result.clone(), service_name.clone()), +}) + }, + None => acc.clone(), +} } else { acc.clone() } - } - _ => acc.clone(), - }; - let result = texpr.children.clone().iter().cloned().fold( - this_acc.clone(), - |a: Rc, child: Rc| { - collect_typed_service_calls_into(&child, &a, &source_indices) - }, - ); - result +}, + _ => acc.clone(), +}; +let result = texpr.children.clone().iter().cloned().fold(this_acc.clone(), |a: Rc, child: Rc| collect_typed_service_calls_into(&child, &a, &source_indices)); +result +} }) } -pub fn collect_called_func_names_into( - texpr: &Rc, - acc: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn collect_called_func_names_into(texpr: &Rc, acc: &Rc, source_indices: &Rc>>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let this_acc = match (*texpr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { + { + let this_acc = match (*texpr.expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { let f = expr_call_func_at(texpr.clone(), source_indices.clone()); - if emit_map_has(acc.seen.clone(), f.clone()) { +if emit_map_has(acc.seen.clone(), f.clone()) { acc.clone() } else { Rc::new(UniqueAccum { - seen: v2_rt::rc_map_insert(acc.seen.clone(), f.clone(), true), - result: v2_rt::rc_list_push(acc.result.clone(), f.clone()), - }) + seen: v2_rt::rc_map_insert(acc.seen.clone(), f.clone(), true), + result: v2_rt::rc_list_push(acc.result.clone(), f.clone()), +}) } - } - _ => acc.clone(), - }; - let result = texpr.children.clone().iter().cloned().fold( - this_acc.clone(), - |a: Rc, child: Rc| { - collect_called_func_names_into(&child, &a, &source_indices) - }, - ); - result +}, + _ => acc.clone(), +}; +let result = texpr.children.clone().iter().cloned().fold(this_acc.clone(), |a: Rc, child: Rc| collect_called_func_names_into(&child, &a, &source_indices)); +result +} }) } -pub fn collect_called_func_names( - texpr: Rc, - source_indices: Rc>>, -) -> Rc> { +pub fn collect_called_func_names(texpr: Rc, source_indices: Rc>>) -> Rc> { { - let result = collect_called_func_names_into( - &texpr, - &Rc::new(UniqueAccum { - seen: v2_rt::rc_empty_map::(), - result: Rc::new(vec![]), - }), - &source_indices, - ); - result.result.clone() - } + let result = collect_called_func_names_into(&texpr, &Rc::new(UniqueAccum { + seen: v2_rt::rc_empty_map::(), + result: Rc::new(vec![]), +}), &source_indices); +result.result.clone() +} } -pub fn expand_transitive_services_once( - modules: Rc>>, - registry: Rc>>, -) -> Rc>> { +pub fn expand_transitive_services_once(modules: Rc>>, registry: Rc>>) -> Rc>> { modules.iter().cloned().fold(registry.clone(), |reg: Rc>>, m: Rc| m.items.clone().iter().cloned().fold(reg, |reg2: Rc>>, item: Rc| { let item_name = authored_name_at(m.type_env.clone().source_indices.clone(), &item); match v2_rt::map_get(®2, item_name.clone()) { @@ -243,172 +186,117 @@ if same_count.clone() { } pub fn total_service_count(registry: Rc>>) -> i64 { - Rc::new(v2_rt::map_values(®istry)) - .iter() - .cloned() - .fold(0, |acc: i64, info: Rc| { - (acc + (info.service_names.clone().len() as i64)) - }) + Rc::new(v2_rt::map_values(®istry)).iter().cloned().fold(0, |acc: i64, info: Rc| (acc + (info.service_names.clone().len() as i64))) } -pub fn expand_transitive_services( - mut modules: Rc>>, - mut registry: Rc>>, - mut remaining_passes: i64, -) -> Rc>> { +pub fn expand_transitive_services(mut modules: Rc>>, mut registry: Rc>>, mut remaining_passes: i64) -> Rc>> { loop { if (remaining_passes.clone() <= 0) { break registry.clone(); - } else { +} else { let before = total_service_count(registry.clone()); - let next = expand_transitive_services_once(modules.clone(), registry.clone()); - let after = total_service_count(next.clone()); - if (before == after) { +let next = expand_transitive_services_once(modules.clone(), registry.clone()); +let after = total_service_count(next.clone()); +if (before == after) { break registry.clone(); - } else { +} else { { let __tco_0 = next.clone(); - let __tco_1 = (remaining_passes - 1); - registry = __tco_0; - remaining_passes = __tco_1; - continue; - } - } - } - } +let __tco_1 = (remaining_passes - 1); +registry = __tco_0; +remaining_passes = __tco_1; +continue; +} +} +} +} } -pub fn check_service_field_access_node( - base_type: &Rc, - field: String, - service_registry: Rc>>>>, - source_indices: Rc>>, -) -> Option> { - if ((base_type.connective.clone() == Connective::NoConnective) - && ((base_type.children.clone().len() as i64) == 0)) - { +pub fn check_service_field_access_node(base_type: &Rc, field: String, service_registry: Rc>>>>, source_indices: Rc>>) -> Option> { + if ((base_type.connective.clone() == Connective::NoConnective) && ((base_type.children.clone().len() as i64) == 0)) { { - let path = v2_rt::concat( - v2_rt::concat( - authored_name_at(source_indices, &base_type), - ".".to_string(), - ), - field, - ); - match v2_rt::map_get(&service_registry, path.clone()) { - Some(_) => Some(nominal_type_ref(&path)), - None => None, - } - } + let path = v2_rt::concat(v2_rt::concat(authored_name_at(source_indices, &base_type), ".".to_string()), field); +match v2_rt::map_get(&service_registry, path.clone()) { + Some(_) => Some(nominal_type_ref(&path)), + None => None, +} +} } else { None } } -pub fn check_service_method_call_node( - receiver_type: &Rc, - method: String, - service_registry: Rc>>>>, - source_indices: Rc>>, -) -> Option> { - if ((receiver_type.connective.clone() == Connective::NoConnective) - && ((receiver_type.children.clone().len() as i64) == 0)) - { - match v2_rt::map_get( - &service_registry, - authored_name_at(source_indices, &receiver_type), - ) { - Some(ops) => { - let matching = Rc::new({ - let mut __result = Vec::new(); - for op in ops.clone().iter().cloned() { - if (op.name.clone().as_str() == method.clone().as_str()) { - __result.push(op); - } - } - __result - }); - match matching.first().cloned() { - Some(op) => { - if ((op.outputs.clone().len() as i64) == 0) { - Some(Rc::new(ServiceMethodResult { - result_type: unit_type(), - op_params: op.params.clone(), - })) - } else { - Some(Rc::new(ServiceMethodResult { - result_type: Rc::new(Node { - name: "".to_string(), - span: no_span(), - ident_span: None, - children: Rc::new({ - let mut __result = Vec::new(); - for f in op.outputs.clone().iter().cloned() { - __result.push(Rc::new(Node { - name: f.name.clone(), - span: f.span.clone(), - ident_span: f.ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { - node: param_node_type_expr(&f), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - })); - } - __result - }), - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - op_params: op.params.clone(), - })) - } - } - None => None, - } - } - None => None, - } +pub fn check_service_method_call_node(receiver_type: &Rc, method: String, service_registry: Rc>>>>, source_indices: Rc>>) -> Option> { + if ((receiver_type.connective.clone() == Connective::NoConnective) && ((receiver_type.children.clone().len() as i64) == 0)) { + match v2_rt::map_get(&service_registry, authored_name_at(source_indices, &receiver_type)) { + Some(ops) => { + let matching = Rc::new({ let mut __result = Vec::new(); for op in ops.clone().iter().cloned() { if (op.name.clone().as_str() == method.clone().as_str()) { __result.push(op); } } __result }); +match matching.first().cloned() { + Some(op) => if ((op.outputs.clone().len() as i64) == 0) { + Some(Rc::new(ServiceMethodResult { + result_type: unit_type(), + op_params: op.params.clone(), +})) + } else { + Some(Rc::new(ServiceMethodResult { + result_type: Rc::new(Node { + name: "".to_string(), + span: no_span(), + ident_span: None, + children: Rc::new({ let mut __result = Vec::new(); for f in op.outputs.clone().iter().cloned() { __result.push(Rc::new(Node { + name: f.name.clone(), + span: f.span.clone(), + ident_span: f.ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: param_node_type_expr(&f), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})); } __result }), + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + op_params: op.params.clone(), +})) + }, + None => None, +} +}, + None => None, +} } else { None } } -pub fn service_op_entry( - child: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn service_op_entry(child: &Rc, source_indices: &Rc>>) -> Rc { Rc::new(OpEntry { - name: authored_name_at(source_indices.clone(), &child), - outputs: inferred_to_outputs( - &child.inferred.clone(), - child.span.clone(), - source_indices.clone(), - ), - params: child.params.clone(), - }) + name: authored_name_at(source_indices.clone(), &child), + outputs: inferred_to_outputs(&child.inferred.clone(), child.span.clone(), source_indices.clone()), + params: child.params.clone(), +}) } diff --git a/src/v2/stage0/src/v2_compiler_infer_sigs.rs b/src/v2/stage0/src/v2_compiler_infer_sigs.rs index 31d6c47dcbe..5cdd9f3214c 100644 --- a/src/v2/stage0/src/v2_compiler_infer_sigs.rs +++ b/src/v2/stage0/src/v2_compiler_infer_sigs.rs @@ -1,20 +1,17 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_sigs -pub use crate::std_induction::SubValueRelation; -use crate::std_induction::SubValueRelation::*; -pub use crate::v2_compiler_infer_types::emit_map_has; -use crate::v2_rt; -use crate::v2_std_core::CompilerDiagnostic::MissingAnnotation; -use crate::v2_std_core::ExprData::ExprCall; -pub use crate::v2_std_core::{ - authored_name_at, expr_call_func_at, make_error_node, no_span, CompilerDiagnostic, - DeclaredFuncSig, ErrorNode, ExprData, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, ExprData, expr_call_func_at, ErrorNode, make_error_node, no_span, DeclaredFuncSig, NewlineIndex, authored_name_at, CompilerDiagnostic}; +use crate::v2_std_core::ExprData::{ExprCall}; +use crate::v2_std_core::CompilerDiagnostic::{MissingAnnotation}; +pub use crate::v2_compiler_infer_types::{emit_map_has}; +pub use crate::std_induction::{SubValueRelation}; +use crate::std_induction::SubValueRelation::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct ResolvedFuncSig { @@ -23,8 +20,7 @@ pub struct ResolvedFuncSig { pub inferred: Rc, pub is_async: bool, pub output_provenance: Rc>>>>, - pub variant_provenance: - Rc>>>>>>, + pub variant_provenance: Rc>>>>>>, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -50,457 +46,191 @@ pub struct CallEdge { pub callee: String, } -pub fn collect_func_call_edges( - items: Rc>>, - local_func_set: Rc>, - source_indices: Rc>>, -) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for item in items.iter().cloned() { - __result.extend( - (*if (((item.params.clone().len() as i64) > 0) && (item.body.clone() != None)) { - collect_calls_in_expr( - &authored_name_at(source_indices.clone(), &item), - &item.body.clone().clone().unwrap(), - &local_func_set, - &source_indices, - ) - } else { - Rc::new(vec![]) - }) - .iter() - .cloned(), - ); - } - __result - }) +pub fn collect_func_call_edges(items: Rc>>, local_func_set: Rc>, source_indices: Rc>>) -> Rc>> { + Rc::new({ let mut __result = Vec::new(); for item in items.iter().cloned() { __result.extend((*if (((item.params.clone().len() as i64) > 0) && (item.body.clone() != None)) { + collect_calls_in_expr(&authored_name_at(source_indices.clone(), &item), &item.body.clone().clone().unwrap(), &local_func_set, &source_indices) + } else { + Rc::new(vec![]) + }).iter().cloned()); } __result }) } -pub fn collect_calls_in_expr( - caller: &String, - texpr: &Rc, - local_func_set: &Rc>, - source_indices: &Rc>>, -) -> Rc>> { +pub fn collect_calls_in_expr(caller: &String, texpr: &Rc, local_func_set: &Rc>, source_indices: &Rc>>) -> Rc>> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let this_edges = match (*texpr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { + { + let this_edges = match (*texpr.expr_data.clone()).clone() { + ExprData::ExprCall { .. } => { let f = expr_call_func_at(texpr.clone(), source_indices.clone()); - if emit_map_has(local_func_set.clone(), f.clone()) { +if emit_map_has(local_func_set.clone(), f.clone()) { Rc::new(vec![Rc::new(CallEdge { - caller: caller.clone(), - callee: f.clone(), - })]) + caller: caller.clone(), + callee: f.clone(), +})]) } else { Rc::new(vec![]) } - } - _ => Rc::new(vec![]), - }; - let child_edges = Rc::new({ - let mut __result = Vec::new(); - for child in texpr.children.clone().iter().cloned() { - __result.extend( - (*collect_calls_in_expr(&caller, &child, &local_func_set, &source_indices)) - .iter() - .cloned(), - ); - } - __result - }); - let result = v2_rt::concat(this_edges, child_edges); - result +}, + _ => Rc::new(vec![]), +}; +let child_edges = Rc::new({ let mut __result = Vec::new(); for child in texpr.children.clone().iter().cloned() { __result.extend((*collect_calls_in_expr(&caller, &child, &local_func_set, &source_indices)).iter().cloned()); } __result }); +let result = v2_rt::concat(this_edges, child_edges); +result +} }) } -pub fn func_reaches_self( - root: String, - current: &String, - call_edges: &Rc>>, - visited: &Rc>, -) -> bool { +pub fn func_reaches_self(root: String, current: &String, call_edges: &Rc>>, visited: &Rc>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { if emit_map_has(visited.clone(), current.clone()) { false } else { { let next_visited = v2_rt::rc_map_insert(visited.clone(), current.clone(), true); - let callees = Rc::new({ - let mut __result = Vec::new(); - for e in Rc::new({ - let mut __result = Vec::new(); - for e in call_edges.clone().iter().cloned() { - if (e.caller.clone().as_str() == current.clone().as_str()) { - __result.push(e); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(e.callee.clone()); - } - __result - }); - { - let mut __found = false; - for c in callees.iter().cloned() { - if if (c.clone().as_str() == root.clone().as_str()) { - true - } else { - func_reaches_self(root.clone(), &c, &call_edges, &next_visited) - } { - __found = true; - break; - } - } - __found - } - } +let callees = Rc::new({ let mut __result = Vec::new(); for e in Rc::new({ let mut __result = Vec::new(); for e in call_edges.clone().iter().cloned() { if (e.caller.clone().as_str() == current.clone().as_str()) { __result.push(e); } } __result }).iter().cloned() { __result.push(e.callee.clone()); } __result }); +{ let mut __found = false; for c in callees.iter().cloned() { if if (c.clone().as_str() == root.clone().as_str()) { + true + } else { + func_reaches_self(root.clone(), &c, &call_edges, &next_visited) + } { __found = true; break; } } __found } +} } }) } pub fn build_name_set(names: Rc>) -> Rc> { - names.iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ) + names.iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)) } -pub fn collect_parent_resolved_sigs( - declared_sigs: Rc>>, - local_func_set: Rc>, -) -> Rc>> { - Rc::new(v2_rt::map_values(&declared_sigs)) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, dsig: Rc| { - if emit_map_has(local_func_set.clone(), dsig.name.clone()) { - acc.clone() - } else { - if (dsig.inferred.clone() != None) { - v2_rt::rc_map_insert( - acc.clone(), - dsig.name.clone(), - declared_to_resolved(&dsig), - ) - } else { - acc.clone() - } - } - }, - ) +pub fn collect_parent_resolved_sigs(declared_sigs: Rc>>, local_func_set: Rc>) -> Rc>> { + Rc::new(v2_rt::map_values(&declared_sigs)).iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, dsig: Rc| if emit_map_has(local_func_set.clone(), dsig.name.clone()) { + acc.clone() + } else { + if (dsig.inferred.clone() != None) { + v2_rt::rc_map_insert(acc.clone(), dsig.name.clone(), declared_to_resolved(&dsig)) + } else { + acc.clone() + } + }) } pub fn declared_to_resolved(dsig: &Rc) -> Rc { Rc::new(ResolvedFuncSig { - name: dsig.name.clone(), - params: dsig.params.clone(), - inferred: dsig.inferred.clone().clone().unwrap(), - is_async: dsig.is_async.clone(), - output_provenance: dsig.output_provenance.clone(), - variant_provenance: dsig.variant_provenance.clone(), - }) + name: dsig.name.clone(), + params: dsig.params.clone(), + inferred: dsig.inferred.clone().clone().unwrap(), + is_async: dsig.is_async.clone(), + output_provenance: dsig.output_provenance.clone(), + variant_provenance: dsig.variant_provenance.clone(), +}) } -pub fn merge_remaining_declared( - declared_sigs: Rc>>, - resolved: Rc>>, -) -> Rc>> { - Rc::new(v2_rt::map_values(&declared_sigs)) - .iter() - .cloned() - .fold( - resolved, - |acc: Rc>>, dsig: Rc| { - if (dsig.inferred.clone() != None) { - v2_rt::rc_map_insert( - acc.clone(), - dsig.name.clone(), - declared_to_resolved(&dsig), - ) - } else { - acc.clone() - } - }, - ) +pub fn merge_remaining_declared(declared_sigs: Rc>>, resolved: Rc>>) -> Rc>> { + Rc::new(v2_rt::map_values(&declared_sigs)).iter().cloned().fold(resolved, |acc: Rc>>, dsig: Rc| if (dsig.inferred.clone() != None) { + v2_rt::rc_map_insert(acc.clone(), dsig.name.clone(), declared_to_resolved(&dsig)) + } else { + acc.clone() + }) } -pub fn topo_resolve_loop( - mut remaining: Rc>, - mut resolved: Rc>>, - mut declared_sigs: Rc>>, - mut call_edges: Rc>>, - mut local_func_set: Rc>, - mut module_name: String, - mut diagnostics: Rc>>, - mut fuel: i64, -) -> Rc { +pub fn topo_resolve_loop(mut remaining: Rc>, mut resolved: Rc>>, mut declared_sigs: Rc>>, mut call_edges: Rc>>, mut local_func_set: Rc>, mut module_name: String, mut diagnostics: Rc>>, mut fuel: i64) -> Rc { loop { if ((remaining.clone().len() as i64) == 0) { { - let all_resolved = Rc::new(v2_rt::map_values(&declared_sigs)) - .iter() - .cloned() - .fold( - resolved.clone(), - |acc: Rc>>, - dsig: Rc| { - if (dsig.inferred.clone() != None) { - v2_rt::rc_map_insert( - acc.clone(), - dsig.name.clone(), - declared_to_resolved(&dsig), - ) - } else { - acc.clone() - } - }, - ); - return Rc::new(ResolveFuncSigsResult { - func_env: Rc::new(ResolvedFuncEnv { - signatures: all_resolved.clone(), - }), - diagnostics: diagnostics.clone(), + let all_resolved = Rc::new(v2_rt::map_values(&declared_sigs)).iter().cloned().fold(resolved.clone(), |acc: Rc>>, dsig: Rc| if (dsig.inferred.clone() != None) { + v2_rt::rc_map_insert(acc.clone(), dsig.name.clone(), declared_to_resolved(&dsig)) + } else { + acc.clone() }); - } +return Rc::new(ResolveFuncSigsResult { + func_env: Rc::new(ResolvedFuncEnv { + signatures: all_resolved.clone(), +}), + diagnostics: diagnostics.clone(), +}) +} } - let ready = Rc::new({ - let mut __result = Vec::new(); - for fn_name in remaining.clone().iter().cloned() { - if { - let local_callees = Rc::new({ - let mut __result = Vec::new(); - for c in Rc::new({ - let mut __result = Vec::new(); - for e in Rc::new({ - let mut __result = Vec::new(); - for e in call_edges.clone().iter().cloned() { - if (e.caller.clone().as_str() == fn_name.clone().as_str()) { - __result.push(e); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(e.callee.clone()); - } - __result - }) - .iter() - .cloned() - { - if emit_map_has(local_func_set.clone(), c.clone()) { - __result.push(c); - } - } - __result - }); - { - let mut __all = true; - for c in local_callees.clone().iter().cloned() { - if !(v2_rt::map_get(&resolved, c.clone()) != None) { - __all = false; - break; - } - } - __all - } - } { - __result.push(fn_name); - } - } - __result - }); - if ((ready.clone().len() as i64) == 0) { +let ready = Rc::new({ let mut __result = Vec::new(); for fn_name in remaining.clone().iter().cloned() { if { + let local_callees = Rc::new({ let mut __result = Vec::new(); for c in Rc::new({ let mut __result = Vec::new(); for e in Rc::new({ let mut __result = Vec::new(); for e in call_edges.clone().iter().cloned() { if (e.caller.clone().as_str() == fn_name.clone().as_str()) { __result.push(e); } } __result }).iter().cloned() { __result.push(e.callee.clone()); } __result }).iter().cloned() { if emit_map_has(local_func_set.clone(), c.clone()) { __result.push(c); } } __result }); +{ let mut __all = true; for c in local_callees.clone().iter().cloned() { if !((v2_rt::map_get(&resolved, c.clone()) != None)) { __all = false; break; } } __all } +} { __result.push(fn_name); } } __result }); +if ((ready.clone().len() as i64) == 0) { { - let cycle_accum = remaining.clone().iter().cloned().fold( + let cycle_accum = remaining.clone().iter().cloned().fold(Rc::new(SigsAccum { + signatures: resolved.clone(), + diagnostics: Rc::new(vec![]), +}), |acc: Rc, fn_name: String| match v2_rt::map_get(&declared_sigs, fn_name.clone()) { + Some(dsig) => if (dsig.inferred.clone() != None) { + Rc::new(SigsAccum { + signatures: v2_rt::rc_map_insert(acc.signatures.clone(), fn_name.clone(), declared_to_resolved(&dsig)), + diagnostics: acc.diagnostics.clone(), +}) + } else { Rc::new(SigsAccum { - signatures: resolved.clone(), - diagnostics: Rc::new(vec![]), - }), - |acc: Rc, fn_name: String| match v2_rt::map_get( - &declared_sigs, - fn_name.clone(), - ) { - Some(dsig) => { - if (dsig.inferred.clone() != None) { - Rc::new(SigsAccum { - signatures: v2_rt::rc_map_insert( - acc.signatures.clone(), - fn_name.clone(), - declared_to_resolved(&dsig), - ), - diagnostics: acc.diagnostics.clone(), - }) - } else { - Rc::new(SigsAccum { - signatures: acc.signatures.clone(), - diagnostics: v2_rt::rc_list_push( - acc.diagnostics.clone(), - make_error_node( - Rc::new(CompilerDiagnostic::MissingAnnotation { - fn_name: fn_name.clone(), - what: "return type (recursive)".to_string(), - span: no_span(), - }), - module_name.clone(), - ), - ), - }) - } - } - None => acc.clone(), - }, - ); - let all_resolved = Rc::new(v2_rt::map_values(&declared_sigs)) - .iter() - .cloned() - .fold( - cycle_accum.signatures.clone(), - |acc: Rc>>, - dsig: Rc| { - if (dsig.inferred.clone() != None) { - v2_rt::rc_map_insert( - acc.clone(), - dsig.name.clone(), - declared_to_resolved(&dsig), - ) - } else { - acc.clone() - } - }, - ); - return Rc::new(ResolveFuncSigsResult { - func_env: Rc::new(ResolvedFuncEnv { - signatures: all_resolved.clone(), - }), - diagnostics: v2_rt::concat( - diagnostics.clone(), - cycle_accum.diagnostics.clone(), - ), + signatures: acc.signatures.clone(), + diagnostics: v2_rt::rc_list_push(acc.diagnostics.clone(), make_error_node(Rc::new(CompilerDiagnostic::MissingAnnotation { + fn_name: fn_name.clone(), + what: "return type (recursive)".to_string(), + span: no_span(), +}), module_name.clone())), +}) + }, + None => acc.clone(), +}); +let all_resolved = Rc::new(v2_rt::map_values(&declared_sigs)).iter().cloned().fold(cycle_accum.signatures.clone(), |acc: Rc>>, dsig: Rc| if (dsig.inferred.clone() != None) { + v2_rt::rc_map_insert(acc.clone(), dsig.name.clone(), declared_to_resolved(&dsig)) + } else { + acc.clone() }); - } +return Rc::new(ResolveFuncSigsResult { + func_env: Rc::new(ResolvedFuncEnv { + signatures: all_resolved.clone(), +}), + diagnostics: v2_rt::concat(diagnostics.clone(), cycle_accum.diagnostics.clone()), +}) +} } - let ready_accum = ready.clone().iter().cloned().fold( +let ready_accum = ready.clone().iter().cloned().fold(Rc::new(SigsAccum { + signatures: resolved.clone(), + diagnostics: diagnostics.clone(), +}), |acc: Rc, fn_name: String| match v2_rt::map_get(&declared_sigs, fn_name.clone()) { + Some(dsig) => if (dsig.inferred.clone() != None) { Rc::new(SigsAccum { - signatures: resolved.clone(), - diagnostics: diagnostics.clone(), - }), - |acc: Rc, fn_name: String| match v2_rt::map_get( - &declared_sigs, - fn_name.clone(), - ) { - Some(dsig) => { - if (dsig.inferred.clone() != None) { - Rc::new(SigsAccum { - signatures: v2_rt::rc_map_insert( - acc.signatures.clone(), - fn_name.clone(), - declared_to_resolved(&dsig), - ), - diagnostics: acc.diagnostics.clone(), - }) - } else { - Rc::new(SigsAccum { - signatures: acc.signatures.clone(), - diagnostics: v2_rt::rc_list_push( - acc.diagnostics.clone(), - make_error_node( - Rc::new(CompilerDiagnostic::MissingAnnotation { - fn_name: fn_name.clone(), - what: "return type".to_string(), - span: no_span(), - }), - module_name.clone(), - ), - ), - }) - } - } - None => acc.clone(), - }, - ); - let ready_set = ready.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, fn_name: String| { - v2_rt::rc_map_insert(acc, fn_name.clone(), true) - }, - ); - let next_remaining = Rc::new({ - let mut __result = Vec::new(); - for fn_name in remaining.clone().iter().cloned() { - if (emit_map_has(ready_set.clone(), fn_name.clone()) == false) { - __result.push(fn_name); - } - } - __result - }); - { + signatures: v2_rt::rc_map_insert(acc.signatures.clone(), fn_name.clone(), declared_to_resolved(&dsig)), + diagnostics: acc.diagnostics.clone(), +}) + } else { + Rc::new(SigsAccum { + signatures: acc.signatures.clone(), + diagnostics: v2_rt::rc_list_push(acc.diagnostics.clone(), make_error_node(Rc::new(CompilerDiagnostic::MissingAnnotation { + fn_name: fn_name.clone(), + what: "return type".to_string(), + span: no_span(), +}), module_name.clone())), +}) + }, + None => acc.clone(), +}); +let ready_set = ready.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, fn_name: String| v2_rt::rc_map_insert(acc, fn_name.clone(), true)); +let next_remaining = Rc::new({ let mut __result = Vec::new(); for fn_name in remaining.clone().iter().cloned() { if (emit_map_has(ready_set.clone(), fn_name.clone()) == false) { __result.push(fn_name); } } __result }); +{ let __tco_0 = next_remaining; - let __tco_1 = ready_accum.signatures.clone(); - let __tco_2 = ready_accum.diagnostics.clone(); - let __tco_3 = (fuel - 1); - remaining = __tco_0; - resolved = __tco_1; - diagnostics = __tco_2; - fuel = __tco_3; - continue; - } - } +let __tco_1 = ready_accum.signatures.clone(); +let __tco_2 = ready_accum.diagnostics.clone(); +let __tco_3 = (fuel - 1); +remaining = __tco_0; +resolved = __tco_1; +diagnostics = __tco_2; +fuel = __tco_3; +continue; +} +} } -pub fn resolve_func_sigs( - declared_sigs: &Rc>>, - items: &Rc>>, - module_name: String, - source_indices: &Rc>>, -) -> Rc { +pub fn resolve_func_sigs(declared_sigs: &Rc>>, items: &Rc>>, module_name: String, source_indices: &Rc>>) -> Rc { { - let local_func_names = Rc::new({ - let mut __result = Vec::new(); - for item in Rc::new({ - let mut __result = Vec::new(); - for item in items.clone().iter().cloned() { - if (((item.params.clone().len() as i64) > 0) && (item.body.clone() != None)) { - __result.push(item); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(authored_name_at(source_indices.clone(), &item)); - } - __result - }); - let local_func_set = build_name_set(local_func_names.clone()); - let call_edges = collect_func_call_edges( - items.clone(), - local_func_set.clone(), - source_indices.clone(), - ); - let parent_resolved = - collect_parent_resolved_sigs(declared_sigs.clone(), local_func_set.clone()); - topo_resolve_loop( - local_func_names.clone(), - parent_resolved, - declared_sigs.clone(), - call_edges, - local_func_set.clone(), - module_name, - Rc::new(vec![]), - (local_func_names.clone().len() as i64), - ) - } + let local_func_names = Rc::new({ let mut __result = Vec::new(); for item in Rc::new({ let mut __result = Vec::new(); for item in items.clone().iter().cloned() { if (((item.params.clone().len() as i64) > 0) && (item.body.clone() != None)) { __result.push(item); } } __result }).iter().cloned() { __result.push(authored_name_at(source_indices.clone(), &item)); } __result }); +let local_func_set = build_name_set(local_func_names.clone()); +let call_edges = collect_func_call_edges(items.clone(), local_func_set.clone(), source_indices.clone()); +let parent_resolved = collect_parent_resolved_sigs(declared_sigs.clone(), local_func_set.clone()); +topo_resolve_loop(local_func_names.clone(), parent_resolved, declared_sigs.clone(), call_edges, local_func_set.clone(), module_name, Rc::new(vec![]), (local_func_names.clone().len() as i64)) +} } diff --git a/src/v2/stage0/src/v2_compiler_infer_types.rs b/src/v2/stage0/src/v2_compiler_infer_types.rs index 139b9825b17..28a9f85640a 100644 --- a/src/v2/stage0/src/v2_compiler_infer_types.rs +++ b/src/v2/stage0/src/v2_compiler_infer_types.rs @@ -1,83 +1,64 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.infer_types -use crate::std_algebra::AlgebraProfile::{ - ApproximateFieldProfile, BooleanAlgebraCollectionProfile, BooleanAlgebraProfile, - FreeMonoidCollectionProfile, FreeMonoidScalarProfile, OrderedRingProfile, - PartialFunctionProfile, -}; -use crate::std_algebra::AlgebraTypeTemplate::{ - AlgebraTypeVariable, ContainerOf, NamedTemplate, OptionalOf, ReceiverElement, ReceiverKey, - ReceiverSelf, ReceiverValue, TupleOf, -}; -use crate::std_algebra::ContainerSource::{Named, SameAsReceiver}; -pub use crate::std_algebra::{ - algebra_templates_for_profile, kernel_algebra_profile, AlgebraFieldTemplate, AlgebraProfile, - AlgebraTypeTemplate, ContainerSource, -}; -pub use crate::std_types::{ - container_expected_arity, container_param_name, is_container_type, SourceSpan, -}; -use crate::v2_rt; -use crate::v2_std_core::AlgebraFieldKind::{ - AlgAdd, AlgCompare, AlgJoin, AlgMeet, AlgMul, AlgQuotient, AlgReciprocal, AlgRemainder, -}; -use crate::v2_std_core::BinOp::{And, Eq, Ge, Gt, Le, Lt, Ne, NullCoalesce, Or}; -use crate::v2_std_core::Cardinality::{CardOptional, Required}; -use crate::v2_std_core::CompilerDiagnostic::InternalError; -use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; -use crate::v2_std_core::ExprData::{ExprError, ExprLiteral, NoExprData}; -use crate::v2_std_core::ExprErrorKind::{InternalExprError, SemanticExprError}; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; -use crate::v2_std_core::LiteralValue::{LitBool, LitFloat, LitInt, LitNull, LitStr}; -pub use crate::v2_std_core::{ - authored_name_at, bool_type, default_ident_span, error_type, find_child_named, float_type, - has_inferred, int_type, is_compiler_error, is_kernel_type, kernel_span, leaf_node_with_span, - make_error_node, make_expr_error_node, make_expr_node, make_param_node, make_span, no_span, - none_type, param_node_type_expr, string_type, unit_type, with_optional_cardinality, - with_required_cardinality, AlgebraFieldKind, BinOp, Cardinality, CompilerDiagnostic, - Connective, ErrorNode, ExprData, ExprErrorKind, InferredNode, LiteralValue, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan, is_container_type, container_expected_arity, container_param_name}; +pub use crate::std_algebra::{AlgebraProfile, AlgebraTypeTemplate, ContainerSource, AlgebraFieldTemplate, kernel_algebra_profile, algebra_templates_for_profile}; +use crate::std_algebra::AlgebraProfile::{OrderedRingProfile, ApproximateFieldProfile, BooleanAlgebraProfile, BooleanAlgebraCollectionProfile, FreeMonoidScalarProfile, FreeMonoidCollectionProfile, PartialFunctionProfile}; +use crate::std_algebra::AlgebraTypeTemplate::{ReceiverSelf, ReceiverElement, ReceiverKey, ReceiverValue, NamedTemplate, ContainerOf, OptionalOf, TupleOf, AlgebraTypeVariable}; +use crate::std_algebra::ContainerSource::{SameAsReceiver, Named}; +pub use crate::v2_std_core::{Node, make_param_node, param_node_type_expr, find_child_named, NewlineIndex, Connective, Cardinality, ExprErrorKind, make_expr_node, make_expr_error_node, LiteralValue, is_kernel_type, BinOp, AlgebraFieldKind, InferredNode, has_inferred, is_compiler_error, leaf_node_with_span, no_span, make_span, with_optional_cardinality, with_required_cardinality, unit_type, bool_type, string_type, int_type, float_type, none_type, error_type, default_ident_span, kernel_span, authored_name_at, ErrorNode, make_error_node, ExprData, CompilerDiagnostic}; +use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; +use crate::v2_std_core::Cardinality::{Required, CardOptional}; +use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprError}; +use crate::v2_std_core::ExprErrorKind::{SemanticExprError, InternalExprError}; +use crate::v2_std_core::LiteralValue::{LitStr, LitInt, LitFloat, LitBool, LitNull}; +use crate::v2_std_core::BinOp::{Eq, Ne, Lt, Gt, Le, Ge, And, Or, NullCoalesce}; +use crate::v2_std_core::AlgebraFieldKind::{AlgAdd, AlgMul, AlgReciprocal, AlgQuotient, AlgRemainder, AlgCompare, AlgMeet, AlgJoin}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::CompilerDiagnostic::{InternalError}; pub fn is_type_variable(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::TypeVariable { .. } => true, - _ => false, - } + InferredNode::TypeVariable { .. } => true, + _ => false, +} } pub fn type_variable_node(id: String) -> Rc { Rc::new(Node { - name: "".to_string(), - span: make_span(0, 0), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::TypeVariable { id: id })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: "".to_string(), + span: make_span(0, 0), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::TypeVariable { + id: id, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn resolved_type(n: Rc) -> Rc { match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), - _ => error_type(), - } + Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), + _ => error_type(), +} } pub fn child_type_node(ch: &Rc) -> Rc { @@ -90,31 +71,20 @@ pub fn child_type_node(ch: &Rc) -> Rc { pub fn child_type_at(n: Rc, index: i64) -> Option> { match n.children.clone().get(index as usize).cloned() { - Some(ch) => Some(child_type_node(&ch)), - None => None, - } + Some(ch) => Some(child_type_node(&ch)), + None => None, +} } -pub fn node_is_collection( - n: &Rc, - source_indices: Rc>>, -) -> bool { - ((((n.children.clone().len() as i64) > 0) - && (n.connective.clone() == Connective::NoConnective)) - && is_container_type(authored_name_at(source_indices, &n))) +pub fn node_is_collection(n: &Rc, source_indices: Rc>>) -> bool { + ((((n.children.clone().len() as i64) > 0) && (n.connective.clone() == Connective::NoConnective)) && is_container_type(authored_name_at(source_indices, &n))) } -pub fn node_is_keyed_collection( - n: &Rc, - source_indices: Rc>>, -) -> bool { +pub fn node_is_keyed_collection(n: &Rc, source_indices: Rc>>) -> bool { (node_is_collection(&n, source_indices) && ((n.children.clone().len() as i64) == 2)) } -pub fn node_is_element_collection( - n: &Rc, - source_indices: Rc>>, -) -> bool { +pub fn node_is_element_collection(n: &Rc, source_indices: Rc>>) -> bool { (node_is_collection(&n, source_indices) && ((n.children.clone().len() as i64) == 1)) } @@ -134,160 +104,143 @@ pub fn is_unit_like(n: &Rc) -> bool { ((n.connective.clone() == Connective::Conj) && ((n.children.clone().len() as i64) == 0)) } -pub fn is_fully_resolved( - n: &Rc, - source_indices: &Rc>>, -) -> bool { +pub fn is_fully_resolved(n: &Rc, source_indices: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let self_is_type_var = match n.inferred.clone() { - Some(inf) => is_type_variable(inf.clone()), - None => false, - }; - if self_is_type_var { - false - } else { - { - let under_param = - match container_expected_arity(authored_name_at(source_indices.clone(), &n)) { - Some(expected) => ((n.children.clone().len() as i64) < expected.clone()), - None => false, - }; - if under_param { - false - } else { - { - let mut __all = true; - for ch in n.children.clone().iter().cloned() { - if !(is_fully_resolved(&child_type_node(&ch), &source_indices)) { - __all = false; - break; - } - } - __all + { + let self_is_type_var = match n.inferred.clone() { + Some(inf) => is_type_variable(inf.clone()), + None => false, +}; +if self_is_type_var { + false + } else { + { + let under_param = match container_expected_arity(authored_name_at(source_indices.clone(), &n)) { + Some(expected) => ((n.children.clone().len() as i64) < expected.clone()), + None => false, +}; +if under_param { + false + } else { + { let mut __all = true; for ch in n.children.clone().iter().cloned() { if !(is_fully_resolved(&child_type_node(&ch), &source_indices)) { __all = false; break; } } __all } } - } +} } - } +} }) } pub fn bare_map_node() -> Option> { match container_param_name("Map".to_string(), 0) { - Some(key_id) => match container_param_name("Map".to_string(), 1) { - Some(val_id) => Some(Rc::new(Node { - name: "Map".to_string(), - span: make_span(0, 0), - ident_span: Some(make_span(0, 0)), - children: Rc::new(vec![ - Rc::new(Node { - name: key_id.clone(), - span: make_span(0, 0), - ident_span: Some(make_span(0, 0)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { - node: type_variable_node(key_id.clone()), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - Rc::new(Node { - name: val_id.clone(), - span: make_span(0, 0), - ident_span: Some(make_span(0, 0)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { - node: type_variable_node(val_id.clone()), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - ]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - })), - None => None, - }, - None => None, - } + Some(key_id) => match container_param_name("Map".to_string(), 1) { + Some(val_id) => Some(Rc::new(Node { + name: "Map".to_string(), + span: make_span(0, 0), + ident_span: Some(make_span(0, 0)), + children: Rc::new(vec![Rc::new(Node { + name: key_id.clone(), + span: make_span(0, 0), + ident_span: Some(make_span(0, 0)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: type_variable_node(key_id.clone()), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), Rc::new(Node { + name: val_id.clone(), + span: make_span(0, 0), + ident_span: Some(make_span(0, 0)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: type_variable_node(val_id.clone()), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})), + None => None, +}, + None => None, +} } pub fn kernel_container_profile_miss_diagnostic(kind_name: String) -> Rc { { let msg = v2_rt::concat("missing kernel container profile: ".to_string(), kind_name); - make_error_node( - Rc::new(CompilerDiagnostic::InternalError { - message: msg, - span: make_span(0, 0), - }), - "v2.compiler.infer_types".to_string(), - ) - } +make_error_node(Rc::new(CompilerDiagnostic::InternalError { + message: msg, + span: make_span(0, 0), +}), "v2.compiler.infer_types".to_string()) +} } pub fn missing_kernel_container_profile_type(kind_name: String) -> Rc { { let msg = v2_rt::concat("missing kernel container profile: ".to_string(), kind_name); - Rc::new(Node { - name: "".to_string(), - span: make_span(0, 0), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::CompilerError { - message: msg.clone(), - span: make_span(0, 0), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::ExprError { - kind: ExprErrorKind::InternalExprError, - message: msg.clone(), - }), - ident: None, - }) - } +Rc::new(Node { + name: "".to_string(), + span: make_span(0, 0), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::CompilerError { + message: msg.clone(), + span: make_span(0, 0), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::ExprError { + kind: ExprErrorKind::InternalExprError, + message: msg.clone(), +}), + ident: None, +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -298,318 +251,302 @@ pub struct KernelTypeBuild { pub fn make_container_type(kind_name: &String, element: Rc) -> Rc { match container_param_name(kind_name.clone(), 0) { - Some(param_name) => Rc::new(KernelTypeBuild { - ty: Rc::new(Node { - name: kind_name.clone(), - span: kernel_span(&kind_name), - ident_span: Some(kernel_span(&kind_name)), - children: Rc::new(vec![Rc::new(Node { - name: param_name.clone(), - span: kernel_span(¶m_name), - ident_span: Some(kernel_span(¶m_name)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: element })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - })]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: Rc::new(vec![]), - }), - None => Rc::new(KernelTypeBuild { - ty: missing_kernel_container_profile_type(kind_name.clone()), - diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic( - kind_name.clone(), - )]), - }), - } + Some(param_name) => Rc::new(KernelTypeBuild { + ty: Rc::new(Node { + name: kind_name.clone(), + span: kernel_span(&kind_name), + ident_span: Some(kernel_span(&kind_name)), + children: Rc::new(vec![Rc::new(Node { + name: param_name.clone(), + span: kernel_span(¶m_name), + ident_span: Some(kernel_span(¶m_name)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: element, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: Rc::new(vec![]), +}), + None => Rc::new(KernelTypeBuild { + ty: missing_kernel_container_profile_type(kind_name.clone()), + diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic(kind_name.clone())]), +}), +} } pub fn make_map_type(key: Rc, value: Rc) -> Rc { match container_param_name("Map".to_string(), 0) { - Some(key_name) => match container_param_name("Map".to_string(), 1) { - Some(val_name) => Rc::new(KernelTypeBuild { - ty: Rc::new(Node { - name: "Map".to_string(), - span: kernel_span(&"Map".to_string()), - ident_span: Some(kernel_span(&"Map".to_string())), - children: Rc::new(vec![ - Rc::new(Node { - name: key_name.clone(), - span: kernel_span(&key_name), - ident_span: Some(kernel_span(&key_name)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: key })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - Rc::new(Node { - name: val_name.clone(), - span: kernel_span(&val_name), - ident_span: Some(kernel_span(&val_name)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: value })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - ]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - diagnostics: Rc::new(vec![]), - }), - None => Rc::new(KernelTypeBuild { - ty: missing_kernel_container_profile_type("Map".to_string()), - diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic( - "Map".to_string(), - )]), - }), - }, - None => Rc::new(KernelTypeBuild { - ty: missing_kernel_container_profile_type("Map".to_string()), - diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic( - "Map".to_string(), - )]), - }), - } + Some(key_name) => match container_param_name("Map".to_string(), 1) { + Some(val_name) => Rc::new(KernelTypeBuild { + ty: Rc::new(Node { + name: "Map".to_string(), + span: kernel_span(&"Map".to_string()), + ident_span: Some(kernel_span(&"Map".to_string())), + children: Rc::new(vec![Rc::new(Node { + name: key_name.clone(), + span: kernel_span(&key_name), + ident_span: Some(kernel_span(&key_name)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: key, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), Rc::new(Node { + name: val_name.clone(), + span: kernel_span(&val_name), + ident_span: Some(kernel_span(&val_name)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: value, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), + diagnostics: Rc::new(vec![]), +}), + None => Rc::new(KernelTypeBuild { + ty: missing_kernel_container_profile_type("Map".to_string()), + diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic("Map".to_string())]), +}), +}, + None => Rc::new(KernelTypeBuild { + ty: missing_kernel_container_profile_type("Map".to_string()), + diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic("Map".to_string())]), +}), +} } pub fn make_callable_type(func_params: Rc>>, ret: Rc) -> Rc { Rc::new(Node { - name: "Callable".to_string(), - span: kernel_span(&"Callable".to_string()), - ident_span: Some(kernel_span(&"Callable".to_string())), - children: Rc::new(vec![]), - connective: Connective::Arrow, - params: func_params, - inferred: Some(Rc::new(InferredNode::Resolved { node: ret })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: "Callable".to_string(), + span: kernel_span(&"Callable".to_string()), + ident_span: Some(kernel_span(&"Callable".to_string())), + children: Rc::new(vec![]), + connective: Connective::Arrow, + params: func_params, + inferred: Some(Rc::new(InferredNode::Resolved { + node: ret, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn make_tuple_type(first: Rc, second: Rc) -> Rc { Rc::new(Node { - name: "".to_string(), - span: make_span(0, 0), - ident_span: None, - children: Rc::new(vec![ - Rc::new(Node { - name: "first".to_string(), - span: kernel_span(&"first".to_string()), - ident_span: Some(kernel_span(&"first".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: first })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - Rc::new(Node { - name: "second".to_string(), - span: kernel_span(&"second".to_string()), - ident_span: Some(kernel_span(&"second".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: second })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - ]), - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: "".to_string(), + span: make_span(0, 0), + ident_span: None, + children: Rc::new(vec![Rc::new(Node { + name: "first".to_string(), + span: kernel_span(&"first".to_string()), + ident_span: Some(kernel_span(&"first".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: first, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), Rc::new(Node { + name: "second".to_string(), + span: kernel_span(&"second".to_string()), + ident_span: Some(kernel_span(&"second".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: second, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})]), + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn algebra_value_field(name: &String, type_node: Rc) -> Rc { Rc::new(Node { - name: name.clone(), - span: kernel_span(&name), - ident_span: Some(kernel_span(&name)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: type_node })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: name.clone(), + span: kernel_span(&name), + ident_span: Some(kernel_span(&name)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: type_node, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } -pub fn algebra_method_field( - name: &String, - param_types: Rc>>, - return_type: Rc, -) -> Rc { +pub fn algebra_method_field(name: &String, param_types: Rc>>, return_type: Rc) -> Rc { { - let params = Rc::new({ - let mut __result = Vec::new(); - for t in param_types.iter().cloned() { - __result.push(make_param_node( - &"_".to_string(), - t.clone(), - None, - no_span(), - no_span(), - )); - } - __result - }); - let callable = make_callable_type(params, return_type); - Rc::new(Node { - name: name.clone(), - span: kernel_span(&name), - ident_span: Some(kernel_span(&name)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: callable })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } + let params = Rc::new({ let mut __result = Vec::new(); for t in param_types.iter().cloned() { __result.push(make_param_node(&"_".to_string(), t.clone(), None, no_span(), no_span())); } __result }); +let callable = make_callable_type(params, return_type); +Rc::new(Node { + name: name.clone(), + span: kernel_span(&name), + ident_span: Some(kernel_span(&name)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: callable, +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} } -pub fn enrich_base_with_fields( - name: String, - base: &Rc, - fields: Rc>>, -) -> Rc { +pub fn enrich_base_with_fields(name: String, base: &Rc, fields: Rc>>) -> Rc { Rc::new(Node { - name: name, - span: base.span.clone(), - ident_span: base.ident_span.clone(), - children: fields, - connective: Connective::Conj, - params: base.params.clone(), - inferred: base.inferred.clone(), - return_cardinality: base.return_cardinality.clone(), - uses: base.uses.clone(), - body: base.body.clone(), - transport: base.transport.clone(), - properties: base.properties.clone(), - type_annotation: base.type_annotation.clone(), - is_self_recursive: base.is_self_recursive.clone(), - has_non_tail_self_call: base.has_non_tail_self_call.clone(), - match_pattern: base.match_pattern.clone(), - expr_data: base.expr_data.clone(), - ident: None, - }) + name: name, + span: base.span.clone(), + ident_span: base.ident_span.clone(), + children: fields, + connective: Connective::Conj, + params: base.params.clone(), + inferred: base.inferred.clone(), + return_cardinality: base.return_cardinality.clone(), + uses: base.uses.clone(), + body: base.body.clone(), + transport: base.transport.clone(), + properties: base.properties.clone(), + type_annotation: base.type_annotation.clone(), + is_self_recursive: base.is_self_recursive.clone(), + has_non_tail_self_call: base.has_non_tail_self_call.clone(), + match_pattern: base.match_pattern.clone(), + expr_data: base.expr_data.clone(), + ident: None, +}) } pub fn placeholder_type_node(name: String) -> Rc { @@ -620,748 +557,410 @@ pub fn nominal_type_ref(name: &String) -> Rc { leaf_node_with_span(&name, &kernel_span(&name)) } -pub fn algebra_child_or_placeholder( - base: Rc, - child_index: i64, - placeholder: String, -) -> Rc { - match Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - base.children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (pair.0.clone() == child_index.clone()) { - __result.push(pair); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(pair.1.clone()); - } - __result - }) - .first() - .cloned() - { - Some(child) => child_type_node(&child), - None => type_variable_node(placeholder), - } +pub fn algebra_child_or_placeholder(base: Rc, child_index: i64, placeholder: String) -> Rc { + match Rc::new({ let mut __result = Vec::new(); for pair in Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(base.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (pair.0.clone() == child_index.clone()) { __result.push(pair); } } __result }).iter().cloned() { __result.push(pair.1.clone()); } __result }).first().cloned() { + Some(child) => child_type_node(&child), + None => type_variable_node(placeholder), +} } -pub fn instantiate_algebra_type( - template: Rc, - base: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn instantiate_algebra_type(template: Rc, base: &Rc, source_indices: &Rc>>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let elem = algebra_child_or_placeholder(base.clone(), 0, "T".to_string()); - let key_node = algebra_child_or_placeholder(base.clone(), 0, "K".to_string()); - let val_node = algebra_child_or_placeholder(base.clone(), 1, "V".to_string()); - match (*template).clone() { - AlgebraTypeTemplate::ReceiverSelf => Rc::new(KernelTypeBuild { - ty: base.clone(), - diagnostics: Rc::new(vec![]), - }), - AlgebraTypeTemplate::ReceiverElement => Rc::new(KernelTypeBuild { - ty: elem, - diagnostics: Rc::new(vec![]), - }), - AlgebraTypeTemplate::ReceiverKey => Rc::new(KernelTypeBuild { - ty: key_node, - diagnostics: Rc::new(vec![]), - }), - AlgebraTypeTemplate::ReceiverValue => Rc::new(KernelTypeBuild { - ty: val_node, - diagnostics: Rc::new(vec![]), - }), - AlgebraTypeTemplate::NamedTemplate { name: n, .. } => Rc::new(KernelTypeBuild { - ty: nominal_type_ref(&n), - diagnostics: Rc::new(vec![]), - }), - AlgebraTypeTemplate::AlgebraTypeVariable { id: var_id, .. } => { - Rc::new(KernelTypeBuild { - ty: type_variable_node(var_id.clone()), - diagnostics: Rc::new(vec![]), - }) - } - AlgebraTypeTemplate::ContainerOf { - source: src, - element: inner, - .. - } => { + { + let elem = algebra_child_or_placeholder(base.clone(), 0, "T".to_string()); +let key_node = algebra_child_or_placeholder(base.clone(), 0, "K".to_string()); +let val_node = algebra_child_or_placeholder(base.clone(), 1, "V".to_string()); +match (*template).clone() { + AlgebraTypeTemplate::ReceiverSelf => Rc::new(KernelTypeBuild { + ty: base.clone(), + diagnostics: Rc::new(vec![]), +}), + AlgebraTypeTemplate::ReceiverElement => Rc::new(KernelTypeBuild { + ty: elem, + diagnostics: Rc::new(vec![]), +}), + AlgebraTypeTemplate::ReceiverKey => Rc::new(KernelTypeBuild { + ty: key_node, + diagnostics: Rc::new(vec![]), +}), + AlgebraTypeTemplate::ReceiverValue => Rc::new(KernelTypeBuild { + ty: val_node, + diagnostics: Rc::new(vec![]), +}), + AlgebraTypeTemplate::NamedTemplate { name: n, .. } => Rc::new(KernelTypeBuild { + ty: nominal_type_ref(&n), + diagnostics: Rc::new(vec![]), +}), + AlgebraTypeTemplate::AlgebraTypeVariable { id: var_id, .. } => Rc::new(KernelTypeBuild { + ty: type_variable_node(var_id.clone()), + diagnostics: Rc::new(vec![]), +}), + AlgebraTypeTemplate::ContainerOf { source: src, element: inner, .. } => { let kind_name = match (*src.clone()).clone() { - ContainerSource::SameAsReceiver => { - authored_name_at(source_indices.clone(), &base) - } - ContainerSource::Named { name: n, .. } => n.clone(), - }; - let inner_b = instantiate_algebra_type(inner.clone(), &base, &source_indices); - let built = make_container_type(&kind_name, inner_b.ty.clone()); - Rc::new(KernelTypeBuild { - ty: built.ty.clone(), - diagnostics: v2_rt::concat( - inner_b.diagnostics.clone(), - built.diagnostics.clone(), - ), - }) - } - AlgebraTypeTemplate::OptionalOf { inner, .. } => { + ContainerSource::SameAsReceiver => authored_name_at(source_indices.clone(), &base), + ContainerSource::Named { name: n, .. } => n.clone(), +}; +let inner_b = instantiate_algebra_type(inner.clone(), &base, &source_indices); +let built = make_container_type(&kind_name, inner_b.ty.clone()); +Rc::new(KernelTypeBuild { + ty: built.ty.clone(), + diagnostics: v2_rt::concat(inner_b.diagnostics.clone(), built.diagnostics.clone()), +}) +}, + AlgebraTypeTemplate::OptionalOf { inner, .. } => { let ib = instantiate_algebra_type(inner.clone(), &base, &source_indices); - Rc::new(KernelTypeBuild { - ty: with_optional_cardinality(&ib.ty.clone()), - diagnostics: ib.diagnostics.clone(), - }) - } - AlgebraTypeTemplate::TupleOf { first, second, .. } => { +Rc::new(KernelTypeBuild { + ty: with_optional_cardinality(&ib.ty.clone()), + diagnostics: ib.diagnostics.clone(), +}) +}, + AlgebraTypeTemplate::TupleOf { first, second, .. } => { let fb = instantiate_algebra_type(first.clone(), &base, &source_indices); - let sb = instantiate_algebra_type(second.clone(), &base, &source_indices); - Rc::new(KernelTypeBuild { - ty: make_tuple_type(fb.ty.clone(), sb.ty.clone()), - diagnostics: v2_rt::concat(fb.diagnostics.clone(), sb.diagnostics.clone()), - }) - } - AlgebraTypeTemplate::CallableOf { - params: p, - return_type: r, - .. - } => { - let param_bs = Rc::new({ - let mut __result = Vec::new(); - for tp in p.clone().iter().cloned() { - __result.push(instantiate_algebra_type(tp.clone(), &base, &source_indices)); - } - __result - }); - let param_diags = Rc::new({ - let mut __result = Vec::new(); - for b in param_bs.clone().iter().cloned() { - __result.extend((*b.diagnostics.clone()).iter().cloned()); - } - __result - }); - let param_nodes = Rc::new({ - let mut __result = Vec::new(); - for b in param_bs.clone().iter().cloned() { - __result.push(b.ty.clone()); - } - __result - }); - let rb = instantiate_algebra_type(r.clone(), &base, &source_indices); - Rc::new(KernelTypeBuild { - ty: make_callable_type(param_nodes, rb.ty.clone()), - diagnostics: v2_rt::concat(param_diags, rb.diagnostics.clone()), - }) - } - } +let sb = instantiate_algebra_type(second.clone(), &base, &source_indices); +Rc::new(KernelTypeBuild { + ty: make_tuple_type(fb.ty.clone(), sb.ty.clone()), + diagnostics: v2_rt::concat(fb.diagnostics.clone(), sb.diagnostics.clone()), +}) +}, + AlgebraTypeTemplate::CallableOf { params: p, return_type: r, .. } => { + let param_bs = Rc::new({ let mut __result = Vec::new(); for tp in p.clone().iter().cloned() { __result.push(instantiate_algebra_type(tp.clone(), &base, &source_indices)); } __result }); +let param_diags = Rc::new({ let mut __result = Vec::new(); for b in param_bs.clone().iter().cloned() { __result.extend((*b.diagnostics.clone()).iter().cloned()); } __result }); +let param_nodes = Rc::new({ let mut __result = Vec::new(); for b in param_bs.clone().iter().cloned() { __result.push(b.ty.clone()); } __result }); +let rb = instantiate_algebra_type(r.clone(), &base, &source_indices); +Rc::new(KernelTypeBuild { + ty: make_callable_type(param_nodes, rb.ty.clone()), + diagnostics: v2_rt::concat(param_diags, rb.diagnostics.clone()), +}) +}, +} +} }) } -pub fn instantiate_algebra_field( - template: &Rc, - base: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn instantiate_algebra_field(template: &Rc, base: &Rc, source_indices: &Rc>>) -> Rc { { - let param_bs = Rc::new({ - let mut __result = Vec::new(); - for tp in template.param_types.clone().iter().cloned() { - __result.push(instantiate_algebra_type(tp.clone(), &base, &source_indices)); - } - __result - }); - let param_types = Rc::new({ - let mut __result = Vec::new(); - for b in param_bs.clone().iter().cloned() { - __result.push(b.ty.clone()); - } - __result - }); - let param_diags = Rc::new({ - let mut __result = Vec::new(); - for b in param_bs.clone().iter().cloned() { - __result.extend((*b.diagnostics.clone()).iter().cloned()); - } - __result - }); - let return_b = - instantiate_algebra_type(template.return_type.clone(), &base, &source_indices); - let field_ty = if ((param_types.clone().len() as i64) > 0) { - algebra_method_field( - &template.name.clone(), - param_types.clone(), - return_b.ty.clone(), - ) + let param_bs = Rc::new({ let mut __result = Vec::new(); for tp in template.param_types.clone().iter().cloned() { __result.push(instantiate_algebra_type(tp.clone(), &base, &source_indices)); } __result }); +let param_types = Rc::new({ let mut __result = Vec::new(); for b in param_bs.clone().iter().cloned() { __result.push(b.ty.clone()); } __result }); +let param_diags = Rc::new({ let mut __result = Vec::new(); for b in param_bs.clone().iter().cloned() { __result.extend((*b.diagnostics.clone()).iter().cloned()); } __result }); +let return_b = instantiate_algebra_type(template.return_type.clone(), &base, &source_indices); +let field_ty = if ((param_types.clone().len() as i64) > 0) { + algebra_method_field(&template.name.clone(), param_types.clone(), return_b.ty.clone()) } else { algebra_value_field(&template.name.clone(), return_b.ty.clone()) }; - Rc::new(KernelTypeBuild { - ty: field_ty, - diagnostics: v2_rt::concat(param_diags, return_b.diagnostics.clone()), - }) - } +Rc::new(KernelTypeBuild { + ty: field_ty, + diagnostics: v2_rt::concat(param_diags, return_b.diagnostics.clone()), +}) +} } -pub fn enrich_kernel_type( - name: &String, - base: &Rc, - source_indices: Rc>>, -) -> Rc { +pub fn enrich_kernel_type(name: &String, base: &Rc, source_indices: Rc>>) -> Rc { { let profile = v2_rt::map_get(&kernel_algebra_profile(), name.clone()); - match profile { - Some(p) => { - let field_bs = Rc::new({ - let mut __result = Vec::new(); - for template in algebra_templates_for_profile(p.clone()).iter().cloned() { - __result.push(instantiate_algebra_field(&template, &base, &source_indices)); - } - __result - }); - let fields = Rc::new({ - let mut __result = Vec::new(); - for b in field_bs.clone().iter().cloned() { - __result.push(b.ty.clone()); - } - __result - }); - let field_diags = Rc::new({ - let mut __result = Vec::new(); - for b in field_bs.clone().iter().cloned() { - __result.extend((*b.diagnostics.clone()).iter().cloned()); - } - __result - }); - Rc::new(KernelTypeBuild { - ty: enrich_base_with_fields(name.clone(), &base, fields), - diagnostics: field_diags, - }) - } - None => Rc::new(KernelTypeBuild { - ty: base.clone(), - diagnostics: Rc::new(vec![]), - }), - } - } +match profile { + Some(p) => { + let field_bs = Rc::new({ let mut __result = Vec::new(); for template in algebra_templates_for_profile(p.clone()).iter().cloned() { __result.push(instantiate_algebra_field(&template, &base, &source_indices)); } __result }); +let fields = Rc::new({ let mut __result = Vec::new(); for b in field_bs.clone().iter().cloned() { __result.push(b.ty.clone()); } __result }); +let field_diags = Rc::new({ let mut __result = Vec::new(); for b in field_bs.clone().iter().cloned() { __result.extend((*b.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(KernelTypeBuild { + ty: enrich_base_with_fields(name.clone(), &base, fields), + diagnostics: field_diags, +}) +}, + None => Rc::new(KernelTypeBuild { + ty: base.clone(), + diagnostics: Rc::new(vec![]), +}), +} +} } -pub fn unify_template( - template: Rc, - concrete: &Rc, - receiver: &Rc, - subst: Rc>>, - source_indices: &Rc>>, -) -> Rc>> { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*template).clone() { - AlgebraTypeTemplate::AlgebraTypeVariable { id: var_id, .. } => { - if (v2_rt::map_get(&subst, var_id.clone()) != None) { - subst.clone() - } else { - v2_rt::rc_map_insert(subst.clone(), var_id.clone(), concrete.clone()) - } - } - AlgebraTypeTemplate::ReceiverSelf => { +pub fn unify_template(template: Rc, concrete: &Rc, receiver: &Rc, subst: Rc>>, source_indices: &Rc>>) -> Rc>> { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*template).clone() { + AlgebraTypeTemplate::AlgebraTypeVariable { id: var_id, .. } => if (v2_rt::map_get(&subst, var_id.clone()) != None) { + subst.clone() + } else { + v2_rt::rc_map_insert(subst.clone(), var_id.clone(), concrete.clone()) + }, + AlgebraTypeTemplate::ReceiverSelf => { let s1 = match concrete.children.clone().first().cloned() { - Some(k) => { - if (v2_rt::map_get(&subst, "__key__".to_string()) != None) { - subst.clone() - } else { - v2_rt::rc_map_insert( - subst.clone(), - "__key__".to_string(), - child_type_node(&k), - ) - } - } - None => subst.clone(), - }; - match concrete.children.clone().get(1 as usize).cloned() { - Some(v) => { - if (v2_rt::map_get(&s1, "__value__".to_string()) != None) { - s1.clone() - } else { - v2_rt::rc_map_insert( - s1.clone(), - "__value__".to_string(), - child_type_node(&v), - ) - } - } - None => s1.clone(), - } - } - AlgebraTypeTemplate::ReceiverKey => { - if (v2_rt::map_get(&subst, "__key__".to_string()) != None) { - subst.clone() - } else { - v2_rt::rc_map_insert(subst.clone(), "__key__".to_string(), concrete.clone()) - } - } - AlgebraTypeTemplate::ReceiverValue => { - if (v2_rt::map_get(&subst, "__value__".to_string()) != None) { + Some(k) => if (v2_rt::map_get(&subst, "__key__".to_string()) != None) { subst.clone() } else { - v2_rt::rc_map_insert(subst.clone(), "__value__".to_string(), concrete.clone()) - } - } - AlgebraTypeTemplate::ReceiverElement => { - if (v2_rt::map_get(&subst, "__element__".to_string()) != None) { - subst.clone() + v2_rt::rc_map_insert(subst.clone(), "__key__".to_string(), child_type_node(&k)) + }, + None => subst.clone(), +}; +match concrete.children.clone().get(1 as usize).cloned() { + Some(v) => if (v2_rt::map_get(&s1, "__value__".to_string()) != None) { + s1.clone() } else { - v2_rt::rc_map_insert(subst.clone(), "__element__".to_string(), concrete.clone()) - } - } - AlgebraTypeTemplate::CallableOf { - return_type: ret_template, - .. - } => unify_template( - ret_template.clone(), - &concrete, - &receiver, - subst.clone(), - &source_indices, - ), - AlgebraTypeTemplate::ContainerOf { - source: src, - element: elem_template, - .. - } => { + v2_rt::rc_map_insert(s1.clone(), "__value__".to_string(), child_type_node(&v)) + }, + None => s1.clone(), +} +}, + AlgebraTypeTemplate::ReceiverKey => if (v2_rt::map_get(&subst, "__key__".to_string()) != None) { + subst.clone() + } else { + v2_rt::rc_map_insert(subst.clone(), "__key__".to_string(), concrete.clone()) + }, + AlgebraTypeTemplate::ReceiverValue => if (v2_rt::map_get(&subst, "__value__".to_string()) != None) { + subst.clone() + } else { + v2_rt::rc_map_insert(subst.clone(), "__value__".to_string(), concrete.clone()) + }, + AlgebraTypeTemplate::ReceiverElement => if (v2_rt::map_get(&subst, "__element__".to_string()) != None) { + subst.clone() + } else { + v2_rt::rc_map_insert(subst.clone(), "__element__".to_string(), concrete.clone()) + }, + AlgebraTypeTemplate::CallableOf { return_type: ret_template, .. } => unify_template(ret_template.clone(), &concrete, &receiver, subst.clone(), &source_indices), + AlgebraTypeTemplate::ContainerOf { source: src, element: elem_template, .. } => { let expected_name = match (*src.clone()).clone() { - ContainerSource::SameAsReceiver => { - authored_name_at(source_indices.clone(), &receiver) - } - ContainerSource::Named { name: n, .. } => n.clone(), - }; - if (authored_name_at(source_indices.clone(), &concrete).as_str() - != expected_name.as_str()) - { + ContainerSource::SameAsReceiver => authored_name_at(source_indices.clone(), &receiver), + ContainerSource::Named { name: n, .. } => n.clone(), +}; +if (authored_name_at(source_indices.clone(), &concrete).as_str() != expected_name.as_str()) { subst.clone() } else { match concrete.children.clone().first().cloned() { - Some(child) => unify_template( - elem_template.clone(), - &child_type_node(&child), - &receiver, - subst.clone(), - &source_indices, - ), - None => subst.clone(), - } + Some(child) => unify_template(elem_template.clone(), &child_type_node(&child), &receiver, subst.clone(), &source_indices), + None => subst.clone(), +} } - } - AlgebraTypeTemplate::OptionalOf { - inner: inner_template, - .. - } => match concrete.children.clone().first().cloned() { - Some(child) => unify_template( - inner_template.clone(), - &child_type_node(&child), - &receiver, - subst.clone(), - &source_indices, - ), - None => subst.clone(), - }, - AlgebraTypeTemplate::TupleOf { - first: ft, - second: st, - .. - } => { +}, + AlgebraTypeTemplate::OptionalOf { inner: inner_template, .. } => match concrete.children.clone().first().cloned() { + Some(child) => unify_template(inner_template.clone(), &child_type_node(&child), &receiver, subst.clone(), &source_indices), + None => subst.clone(), +}, + AlgebraTypeTemplate::TupleOf { first: ft, second: st, .. } => { let s2 = match concrete.children.clone().first().cloned() { - Some(c) => unify_template( - ft.clone(), - &child_type_node(&c), - &receiver, - subst.clone(), - &source_indices, - ), - None => subst.clone(), - }; - match concrete.children.clone().get(1 as usize).cloned() { - Some(c) => unify_template( - st.clone(), - &child_type_node(&c), - &receiver, - s2, - &source_indices, - ), - None => s2, - } - } - _ => subst.clone(), + Some(c) => unify_template(ft.clone(), &child_type_node(&c), &receiver, subst.clone(), &source_indices), + None => subst.clone(), +}; +match concrete.children.clone().get(1 as usize).cloned() { + Some(c) => unify_template(st.clone(), &child_type_node(&c), &receiver, s2, &source_indices), + None => s2, +} +}, + _ => subst.clone(), +} }) } pub fn is_receiver_self(t: Rc) -> bool { match (*t).clone() { - AlgebraTypeTemplate::ReceiverSelf => true, - _ => false, - } + AlgebraTypeTemplate::ReceiverSelf => true, + _ => false, +} } -pub fn build_type_substitution( - param_templates: &Rc>>, - arg_types: Rc>>, - receiver: Rc, - base_subst: Rc>>, - source_indices: Rc>>, -) -> Rc>> { +pub fn build_type_substitution(param_templates: &Rc>>, arg_types: Rc>>, receiver: Rc, base_subst: Rc>>, source_indices: Rc>>) -> Rc>> { { let first_is_self = match param_templates.clone().first().cloned() { - Some(t) => is_receiver_self(t.clone()), - None => false, - }; - let non_receiver_templates = if first_is_self { - Rc::new( - param_templates - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) + Some(t) => is_receiver_self(t.clone()), + None => false, +}; +let non_receiver_templates = if first_is_self { + Rc::new(param_templates.clone().iter().cloned().skip(1 as usize).collect::>()) } else { param_templates.clone() }; - let pairs = Rc::new({ - let mut __result = Vec::new(); - for pair in Rc::new( - non_receiver_templates - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (pair.0.clone() < (arg_types.clone().len() as i64)) { - __result.push(pair); - } - } - __result - }); - pairs.iter().cloned().fold( - base_subst.clone(), - |subst: Rc>>, pair: (i64, Rc)| { - let arg_type = match Rc::new({ - let mut __result = Vec::new(); - for ap in Rc::new({ - let mut __result = Vec::new(); - for ap in Rc::new( - arg_types - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (ap.0.clone() == pair.0.clone()) { - __result.push(ap); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(ap.1.clone()); - } - __result - }) - .first() - .cloned() - { - Some(a) => a.clone(), - None => error_type(), - }; - unify_template(pair.1.clone(), &arg_type, &receiver, subst, &source_indices) - }, - ) - } +let pairs = Rc::new({ let mut __result = Vec::new(); for pair in Rc::new(non_receiver_templates.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (pair.0.clone() < (arg_types.clone().len() as i64)) { __result.push(pair); } } __result }); +pairs.iter().cloned().fold(base_subst.clone(), |subst: Rc>>, pair: (i64, Rc)| { + let arg_type = match Rc::new({ let mut __result = Vec::new(); for ap in Rc::new({ let mut __result = Vec::new(); for ap in Rc::new(arg_types.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (ap.0.clone() == pair.0.clone()) { __result.push(ap); } } __result }).iter().cloned() { __result.push(ap.1.clone()); } __result }).first().cloned() { + Some(a) => a.clone(), + None => error_type(), +}; +unify_template(pair.1.clone(), &arg_type, &receiver, subst, &source_indices) +}) +} } -pub fn apply_type_substitution( - template: Rc, - subst: &Rc>>, - receiver: &Rc, - source_indices: &Rc>>, -) -> Rc { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*template).clone() { - AlgebraTypeTemplate::AlgebraTypeVariable { id: var_id, .. } => { - match v2_rt::map_get(&subst, var_id.clone()) { - Some(resolved) => Rc::new(KernelTypeBuild { - ty: resolved.clone(), - diagnostics: Rc::new(vec![]), - }), - None => Rc::new(KernelTypeBuild { - ty: type_variable_node(var_id.clone()), - diagnostics: Rc::new(vec![]), - }), - } - } - AlgebraTypeTemplate::ReceiverSelf => { +pub fn apply_type_substitution(template: Rc, subst: &Rc>>, receiver: &Rc, source_indices: &Rc>>) -> Rc { + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*template).clone() { + AlgebraTypeTemplate::AlgebraTypeVariable { id: var_id, .. } => match v2_rt::map_get(&subst, var_id.clone()) { + Some(resolved) => Rc::new(KernelTypeBuild { + ty: resolved.clone(), + diagnostics: Rc::new(vec![]), +}), + None => Rc::new(KernelTypeBuild { + ty: type_variable_node(var_id.clone()), + diagnostics: Rc::new(vec![]), +}), +}, + AlgebraTypeTemplate::ReceiverSelf => { let receiver_name_str = authored_name_at(source_indices.clone(), &receiver); - let is_bare = (is_container_type(receiver_name_str.clone()) && { - let mut __all = true; - for ch in receiver.children.clone().iter().cloned() { - if !({ - let inner = child_type_node(&ch); - if (inner.inferred.clone() != None) { - is_type_variable(inner.inferred.clone().clone().unwrap()) - } else { - ((inner.ident_span.clone() == None) - || !is_kernel_type(authored_name_at( - source_indices.clone(), - &inner, - ))) - } - }) { - __all = false; - break; - } +let is_bare = (is_container_type(receiver_name_str.clone()) && { let mut __all = true; for ch in receiver.children.clone().iter().cloned() { if !({ + let inner = child_type_node(&ch); +if (inner.inferred.clone() != None) { + is_type_variable(inner.inferred.clone().clone().unwrap()) + } else { + ((inner.ident_span.clone() == None) || !is_kernel_type(authored_name_at(source_indices.clone(), &inner))) } - __all - }); - if is_bare { +}) { __all = false; break; } } __all }); +if is_bare { { let arity = container_expected_arity(receiver_name_str.clone()); - if (arity.clone() == Some(2)) { +if (arity.clone() == Some(2)) { match v2_rt::map_get(&subst, "__key__".to_string()) { - Some(key) => { - let val = match v2_rt::map_get(&subst, "__value__".to_string()) { - Some(v) => v.clone(), - None => type_variable_node("V".to_string()), - }; - make_map_type(key.clone(), val) - } - None => Rc::new(KernelTypeBuild { - ty: receiver.clone(), - diagnostics: Rc::new(vec![]), - }), - } + Some(key) => { + let val = match v2_rt::map_get(&subst, "__value__".to_string()) { + Some(v) => v.clone(), + None => type_variable_node("V".to_string()), +}; +make_map_type(key.clone(), val) +}, + None => Rc::new(KernelTypeBuild { + ty: receiver.clone(), + diagnostics: Rc::new(vec![]), +}), +} } else { if (arity.clone() == Some(1)) { match v2_rt::map_get(&subst, "__element__".to_string()) { - Some(elem) => make_container_type(&receiver_name_str, elem.clone()), - None => Rc::new(KernelTypeBuild { - ty: receiver.clone(), - diagnostics: Rc::new(vec![]), - }), - } + Some(elem) => make_container_type(&receiver_name_str, elem.clone()), + None => Rc::new(KernelTypeBuild { + ty: receiver.clone(), + diagnostics: Rc::new(vec![]), +}), +} } else { Rc::new(KernelTypeBuild { - ty: receiver.clone(), - diagnostics: Rc::new(vec![]), - }) + ty: receiver.clone(), + diagnostics: Rc::new(vec![]), +}) } } - } +} } else { Rc::new(KernelTypeBuild { - ty: receiver.clone(), - diagnostics: Rc::new(vec![]), - }) + ty: receiver.clone(), + diagnostics: Rc::new(vec![]), +}) } - } - AlgebraTypeTemplate::ReceiverElement => match receiver.children.clone().first().cloned() { - Some(child) => Rc::new(KernelTypeBuild { - ty: child_type_node(&child), - diagnostics: Rc::new(vec![]), - }), - None => match v2_rt::map_get(&subst, "__element__".to_string()) { - Some(elem) => Rc::new(KernelTypeBuild { - ty: elem.clone(), - diagnostics: Rc::new(vec![]), - }), - None => { - let rname = authored_name_at(source_indices.clone(), &receiver); - match container_param_name(rname.clone(), 0) { - Some(n) => Rc::new(KernelTypeBuild { - ty: type_variable_node(n.clone()), - diagnostics: Rc::new(vec![]), - }), - None => Rc::new(KernelTypeBuild { - ty: missing_kernel_container_profile_type(rname.clone()), - diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic( - rname.clone(), - )]), - }), - } - } - }, - }, - AlgebraTypeTemplate::ReceiverKey => match receiver.children.clone().first().cloned() { - Some(child) => Rc::new(KernelTypeBuild { - ty: child_type_node(&child), - diagnostics: Rc::new(vec![]), - }), - None => match v2_rt::map_get(&subst, "__key__".to_string()) { - Some(key) => Rc::new(KernelTypeBuild { - ty: key.clone(), - diagnostics: Rc::new(vec![]), - }), - None => { - let rname = authored_name_at(source_indices.clone(), &receiver); - match container_param_name(rname.clone(), 0) { - Some(n) => Rc::new(KernelTypeBuild { - ty: type_variable_node(n.clone()), - diagnostics: Rc::new(vec![]), - }), - None => Rc::new(KernelTypeBuild { - ty: missing_kernel_container_profile_type(rname.clone()), - diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic( - rname.clone(), - )]), - }), - } - } - }, - }, - AlgebraTypeTemplate::ReceiverValue => { - match receiver.children.clone().get(1 as usize).cloned() { - Some(child) => Rc::new(KernelTypeBuild { - ty: child_type_node(&child), - diagnostics: Rc::new(vec![]), - }), - None => match v2_rt::map_get(&subst, "__value__".to_string()) { - Some(val) => Rc::new(KernelTypeBuild { - ty: val, - diagnostics: Rc::new(vec![]), - }), - None => { - let rname = authored_name_at(source_indices.clone(), &receiver); - match container_param_name(rname.clone(), 1) { - Some(n) => Rc::new(KernelTypeBuild { - ty: type_variable_node(n.clone()), - diagnostics: Rc::new(vec![]), - }), - None => Rc::new(KernelTypeBuild { - ty: missing_kernel_container_profile_type(rname.clone()), - diagnostics: Rc::new(vec![ - kernel_container_profile_miss_diagnostic(rname.clone()), - ]), - }), - } - } - }, - } - } - AlgebraTypeTemplate::NamedTemplate { name: n, .. } => Rc::new(KernelTypeBuild { - ty: nominal_type_ref(&n), - diagnostics: Rc::new(vec![]), - }), - AlgebraTypeTemplate::ContainerOf { - source: src, - element: inner, - .. - } => { +}, + AlgebraTypeTemplate::ReceiverElement => match receiver.children.clone().first().cloned() { + Some(child) => Rc::new(KernelTypeBuild { + ty: child_type_node(&child), + diagnostics: Rc::new(vec![]), +}), + None => match v2_rt::map_get(&subst, "__element__".to_string()) { + Some(elem) => Rc::new(KernelTypeBuild { + ty: elem.clone(), + diagnostics: Rc::new(vec![]), +}), + None => { + let rname = authored_name_at(source_indices.clone(), &receiver); +match container_param_name(rname.clone(), 0) { + Some(n) => Rc::new(KernelTypeBuild { + ty: type_variable_node(n.clone()), + diagnostics: Rc::new(vec![]), +}), + None => Rc::new(KernelTypeBuild { + ty: missing_kernel_container_profile_type(rname.clone()), + diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic(rname.clone())]), +}), +} +}, +}, +}, + AlgebraTypeTemplate::ReceiverKey => match receiver.children.clone().first().cloned() { + Some(child) => Rc::new(KernelTypeBuild { + ty: child_type_node(&child), + diagnostics: Rc::new(vec![]), +}), + None => match v2_rt::map_get(&subst, "__key__".to_string()) { + Some(key) => Rc::new(KernelTypeBuild { + ty: key.clone(), + diagnostics: Rc::new(vec![]), +}), + None => { + let rname = authored_name_at(source_indices.clone(), &receiver); +match container_param_name(rname.clone(), 0) { + Some(n) => Rc::new(KernelTypeBuild { + ty: type_variable_node(n.clone()), + diagnostics: Rc::new(vec![]), +}), + None => Rc::new(KernelTypeBuild { + ty: missing_kernel_container_profile_type(rname.clone()), + diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic(rname.clone())]), +}), +} +}, +}, +}, + AlgebraTypeTemplate::ReceiverValue => match receiver.children.clone().get(1 as usize).cloned() { + Some(child) => Rc::new(KernelTypeBuild { + ty: child_type_node(&child), + diagnostics: Rc::new(vec![]), +}), + None => match v2_rt::map_get(&subst, "__value__".to_string()) { + Some(val) => Rc::new(KernelTypeBuild { + ty: val, + diagnostics: Rc::new(vec![]), +}), + None => { + let rname = authored_name_at(source_indices.clone(), &receiver); +match container_param_name(rname.clone(), 1) { + Some(n) => Rc::new(KernelTypeBuild { + ty: type_variable_node(n.clone()), + diagnostics: Rc::new(vec![]), +}), + None => Rc::new(KernelTypeBuild { + ty: missing_kernel_container_profile_type(rname.clone()), + diagnostics: Rc::new(vec![kernel_container_profile_miss_diagnostic(rname.clone())]), +}), +} +}, +}, +}, + AlgebraTypeTemplate::NamedTemplate { name: n, .. } => Rc::new(KernelTypeBuild { + ty: nominal_type_ref(&n), + diagnostics: Rc::new(vec![]), +}), + AlgebraTypeTemplate::ContainerOf { source: src, element: inner, .. } => { let kind_name = match (*src.clone()).clone() { - ContainerSource::SameAsReceiver => { - authored_name_at(source_indices.clone(), &receiver) - } - ContainerSource::Named { name: n, .. } => n.clone(), - }; - let inner_applied = - apply_type_substitution(inner.clone(), &subst, &receiver, &source_indices); - let built = make_container_type(&kind_name, inner_applied.ty.clone()); - Rc::new(KernelTypeBuild { - ty: built.ty.clone(), - diagnostics: v2_rt::concat( - inner_applied.diagnostics.clone(), - built.diagnostics.clone(), - ), - }) - } - AlgebraTypeTemplate::OptionalOf { inner, .. } => { + ContainerSource::SameAsReceiver => authored_name_at(source_indices.clone(), &receiver), + ContainerSource::Named { name: n, .. } => n.clone(), +}; +let inner_applied = apply_type_substitution(inner.clone(), &subst, &receiver, &source_indices); +let built = make_container_type(&kind_name, inner_applied.ty.clone()); +Rc::new(KernelTypeBuild { + ty: built.ty.clone(), + diagnostics: v2_rt::concat(inner_applied.diagnostics.clone(), built.diagnostics.clone()), +}) +}, + AlgebraTypeTemplate::OptionalOf { inner, .. } => { let ib = apply_type_substitution(inner.clone(), &subst, &receiver, &source_indices); - Rc::new(KernelTypeBuild { - ty: with_optional_cardinality(&ib.ty.clone()), - diagnostics: ib.diagnostics.clone(), - }) - } - AlgebraTypeTemplate::TupleOf { - first: ft, - second: st, - .. - } => { +Rc::new(KernelTypeBuild { + ty: with_optional_cardinality(&ib.ty.clone()), + diagnostics: ib.diagnostics.clone(), +}) +}, + AlgebraTypeTemplate::TupleOf { first: ft, second: st, .. } => { let fb = apply_type_substitution(ft.clone(), &subst, &receiver, &source_indices); - let sb = apply_type_substitution(st.clone(), &subst, &receiver, &source_indices); - Rc::new(KernelTypeBuild { - ty: make_tuple_type(fb.ty.clone(), sb.ty.clone()), - diagnostics: v2_rt::concat(fb.diagnostics.clone(), sb.diagnostics.clone()), - }) - } - AlgebraTypeTemplate::CallableOf { - params: p, - return_type: r, - .. - } => { - let param_bs = Rc::new({ - let mut __result = Vec::new(); - for tp in p.clone().iter().cloned() { - __result.push(apply_type_substitution( - tp.clone(), - &subst, - &receiver, - &source_indices, - )); - } - __result - }); - let param_nodes = Rc::new({ - let mut __result = Vec::new(); - for b in param_bs.clone().iter().cloned() { - __result.push(b.ty.clone()); - } - __result - }); - let param_diags = Rc::new({ - let mut __result = Vec::new(); - for b in param_bs.clone().iter().cloned() { - __result.extend((*b.diagnostics.clone()).iter().cloned()); - } - __result - }); - let rb = apply_type_substitution(r.clone(), &subst, &receiver, &source_indices); - Rc::new(KernelTypeBuild { - ty: make_callable_type( - Rc::new({ - let mut __result = Vec::new(); - for pn in param_nodes.iter().cloned() { - __result.push(make_param_node( - &"_".to_string(), - pn.clone(), - None, - no_span(), - no_span(), - )); - } - __result - }), - rb.ty.clone(), - ), - diagnostics: v2_rt::concat(param_diags, rb.diagnostics.clone()), - }) - } +let sb = apply_type_substitution(st.clone(), &subst, &receiver, &source_indices); +Rc::new(KernelTypeBuild { + ty: make_tuple_type(fb.ty.clone(), sb.ty.clone()), + diagnostics: v2_rt::concat(fb.diagnostics.clone(), sb.diagnostics.clone()), +}) +}, + AlgebraTypeTemplate::CallableOf { params: p, return_type: r, .. } => { + let param_bs = Rc::new({ let mut __result = Vec::new(); for tp in p.clone().iter().cloned() { __result.push(apply_type_substitution(tp.clone(), &subst, &receiver, &source_indices)); } __result }); +let param_nodes = Rc::new({ let mut __result = Vec::new(); for b in param_bs.clone().iter().cloned() { __result.push(b.ty.clone()); } __result }); +let param_diags = Rc::new({ let mut __result = Vec::new(); for b in param_bs.clone().iter().cloned() { __result.extend((*b.diagnostics.clone()).iter().cloned()); } __result }); +let rb = apply_type_substitution(r.clone(), &subst, &receiver, &source_indices); +Rc::new(KernelTypeBuild { + ty: make_callable_type(Rc::new({ let mut __result = Vec::new(); for pn in param_nodes.iter().cloned() { __result.push(make_param_node(&"_".to_string(), pn.clone(), None, no_span(), no_span())); } __result }), rb.ty.clone()), + diagnostics: v2_rt::concat(param_diags, rb.diagnostics.clone()), +}) +}, +} }) } @@ -1374,341 +973,255 @@ pub fn template_return_has_variables(template: Rc) -> bool } pub fn has_type_variable(t: Rc) -> bool { - stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || match (*t).clone() { - AlgebraTypeTemplate::AlgebraTypeVariable { .. } => true, - AlgebraTypeTemplate::ContainerOf { element: inner, .. } => has_type_variable(inner.clone()), - AlgebraTypeTemplate::OptionalOf { inner, .. } => has_type_variable(inner.clone()), - AlgebraTypeTemplate::TupleOf { - first: f, - second: s, - .. - } => (has_type_variable(f.clone()) || has_type_variable(s.clone())), - AlgebraTypeTemplate::CallableOf { return_type: r, .. } => has_type_variable(r.clone()), - _ => false, + stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + match (*t).clone() { + AlgebraTypeTemplate::AlgebraTypeVariable { .. } => true, + AlgebraTypeTemplate::ContainerOf { element: inner, .. } => has_type_variable(inner.clone()), + AlgebraTypeTemplate::OptionalOf { inner, .. } => has_type_variable(inner.clone()), + AlgebraTypeTemplate::TupleOf { first: f, second: s, .. } => (has_type_variable(f.clone()) || has_type_variable(s.clone())), + AlgebraTypeTemplate::CallableOf { return_type: r, .. } => has_type_variable(r.clone()), + _ => false, +} }) } -pub fn resolve_type_variables_from_template( - template: &Rc, - arg_types: Rc>>, - receiver_type: &Rc, - overrides: Rc>>, - source_indices: &Rc>>, -) -> Rc { +pub fn resolve_type_variables_from_template(template: &Rc, arg_types: Rc>>, receiver_type: &Rc, overrides: Rc>>, source_indices: &Rc>>) -> Rc { { - let subst = build_type_substitution( - &template.param_types.clone(), - arg_types, - receiver_type.clone(), - overrides, - source_indices.clone(), - ); - apply_type_substitution( - template.return_type.clone(), - &subst, - &receiver_type, - &source_indices, - ) - } + let subst = build_type_substitution(&template.param_types.clone(), arg_types, receiver_type.clone(), overrides, source_indices.clone()); +apply_type_substitution(template.return_type.clone(), &subst, &receiver_type, &source_indices) +} } pub fn callable_inferred(n: &Rc) -> Rc { { let is_callable = ((n.params.clone().len() as i64) > 0); - if is_callable { +if is_callable { match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: ret, .. }) => ret.clone(), - None => error_type(), - _ => error_type(), - } + Some(InferredNode::Resolved { node: ret, .. }) => ret.clone(), + None => error_type(), + _ => error_type(), +} } else { n.clone() } - } +} } pub fn normalize_access_type_node(mut n: Rc) -> Rc { loop { let has_structure = (n.connective.clone() != Connective::NoConnective); - let unwrapped = if ((n.type_annotation.clone() != None) && has_structure) { +let unwrapped = if ((n.type_annotation.clone() != None) && has_structure) { n.children.clone().first().cloned() } else { None }; - match unwrapped { - Some(base) => { - let __tco_0 = base.clone(); - n = __tco_0; - continue; - } - None => { - break n.clone(); - } - } - } +match unwrapped { + Some(base) => { { + let __tco_0 = base.clone(); +n = __tco_0; +continue; +} }, + None => { break n.clone(); }, +} +} } -pub fn node_type_shape( - n: &Rc, - source_indices: &Rc>>, -) -> String { +pub fn node_type_shape(n: &Rc, source_indices: &Rc>>) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let __is_leaf = (((n.connective.clone() == Connective::NoConnective) - && ((n.children.clone().len() as i64) == 0)) - && ((n.properties.clone().len() as i64) == 0)); - let n_name = authored_name_at(source_indices.clone(), &n); - if __is_leaf { - { - let __is_named_ref = match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (((((rt.connective.clone() == Connective::NoConnective) - && ((rt.children.clone().len() as i64) == 0)) - && (rt.ident_span.clone() != None)) - && (authored_name_at(source_indices.clone(), &rt).as_str() - != "None".to_string().as_str())) - && (is_kernel_type(authored_name_at(source_indices.clone(), &rt)) - == false)) - } - _ => false, - }; - if __is_named_ref { - v2_rt::concat(v2_rt::concat("Named(".to_string(), n_name), ")".to_string()) - } else { - v2_rt::concat( - v2_rt::concat("Primitive(".to_string(), n_name), - ")".to_string(), - ) - } - } - } else { - { - let is_product = (n.connective.clone() == Connective::Conj); - let is_coproduct = (n.connective.clone() == Connective::Disj); - if is_product { - if (n.ident_span.clone() == None) { - "Product()".to_string() + { + let __is_leaf = (((n.connective.clone() == Connective::NoConnective) && ((n.children.clone().len() as i64) == 0)) && ((n.properties.clone().len() as i64) == 0)); +let n_name = authored_name_at(source_indices.clone(), &n); +if __is_leaf { + { + let __is_named_ref = match n.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (((((rt.connective.clone() == Connective::NoConnective) && ((rt.children.clone().len() as i64) == 0)) && (rt.ident_span.clone() != None)) && (authored_name_at(source_indices.clone(), &rt).as_str() != "None".to_string().as_str())) && (is_kernel_type(authored_name_at(source_indices.clone(), &rt)) == false)), + _ => false, +}; +if __is_named_ref { + v2_rt::concat(v2_rt::concat("Named(".to_string(), n_name), ")".to_string()) } else { - v2_rt::concat( - v2_rt::concat("Product(".to_string(), n_name), - ")".to_string(), - ) + v2_rt::concat(v2_rt::concat("Primitive(".to_string(), n_name), ")".to_string()) } - } else { - if is_coproduct { +} + } else { + { + let is_product = (n.connective.clone() == Connective::Conj); +let is_coproduct = (n.connective.clone() == Connective::Disj); +if is_product { if (n.ident_span.clone() == None) { - "Coproduct()".to_string() + "Product()".to_string() } else { - v2_rt::concat( - v2_rt::concat("Coproduct(".to_string(), n_name), - ")".to_string(), - ) + v2_rt::concat(v2_rt::concat("Product(".to_string(), n_name), ")".to_string()) } } else { - { - let __is_container = - node_is_element_collection(&n, source_indices.clone()); - let is_optional = - (n.return_cardinality.clone() == Cardinality::CardOptional); - let is_map = node_is_keyed_collection(&n, source_indices.clone()); - if __is_container { - { - let elem_shape = match n.children.clone().first().cloned() { - Some(el) => { - node_type_shape(&child_type_node(&el), &source_indices) - } - None => "?".to_string(), - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("Container(".to_string(), n_name), - ",".to_string(), - ), - elem_shape, - ), - ")".to_string(), - ) - } + if is_coproduct { + if (n.ident_span.clone() == None) { + "Coproduct()".to_string() } else { - if is_optional { + v2_rt::concat(v2_rt::concat("Coproduct(".to_string(), n_name), ")".to_string()) + } + } else { + { + let __is_container = node_is_element_collection(&n, source_indices.clone()); +let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); +let is_map = node_is_keyed_collection(&n, source_indices.clone()); +if __is_container { { - let inner_shape = node_type_shape( - &with_required_cardinality(&n), - &source_indices, - ); - v2_rt::concat( - v2_rt::concat("Optional(".to_string(), inner_shape), - ")".to_string(), - ) - } + let elem_shape = match n.children.clone().first().cloned() { + Some(el) => node_type_shape(&child_type_node(&el), &source_indices), + None => "?".to_string(), +}; +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("Container(".to_string(), n_name), ",".to_string()), elem_shape), ")".to_string()) +} } else { - if is_map { - "Map(...)".to_string() + if is_optional { + { + let inner_shape = node_type_shape(&with_required_cardinality(&n), &source_indices); +v2_rt::concat(v2_rt::concat("Optional(".to_string(), inner_shape), ")".to_string()) +} } else { - v2_rt::concat( - v2_rt::concat("Node(".to_string(), n_name), - ")".to_string(), - ) + if is_map { + "Map(...)".to_string() + } else { + v2_rt::concat(v2_rt::concat("Node(".to_string(), n_name), ")".to_string()) + } } } - } +} } } - } +} } - } +} }) } -pub fn node_type_compatible( - mut left: Rc, - mut right: Rc, - mut source_indices: Rc>>, -) -> bool { +pub fn node_type_compatible(mut left: Rc, mut right: Rc, mut source_indices: Rc>>) -> bool { loop { let left_err = if (left.inferred.clone() != None) { is_compiler_error(left.inferred.clone().clone().unwrap()) } else { false }; - let right_err = if (right.inferred.clone() != None) { +let right_err = if (right.inferred.clone() != None) { is_compiler_error(right.inferred.clone().clone().unwrap()) } else { false }; - let left_tv = if (left.inferred.clone() != None) { +let left_tv = if (left.inferred.clone() != None) { is_type_variable(left.inferred.clone().clone().unwrap()) } else { false }; - let right_tv = if (right.inferred.clone() != None) { +let right_tv = if (right.inferred.clone() != None) { is_type_variable(right.inferred.clone().clone().unwrap()) } else { false }; - let left_opt = (left.return_cardinality.clone() == Cardinality::CardOptional); - let right_opt = (right.return_cardinality.clone() == Cardinality::CardOptional); - let right_is_unit = is_unit_like(&right); - let left_is_unit = is_unit_like(&left); - if (left_err || right_err) { +let left_opt = (left.return_cardinality.clone() == Cardinality::CardOptional); +let right_opt = (right.return_cardinality.clone() == Cardinality::CardOptional); +let right_is_unit = is_unit_like(&right); +let left_is_unit = is_unit_like(&left); +if (left_err || right_err) { break true; - } else { +} else { if (left_tv || right_tv) { break true; - } else { +} else { if (left_opt.clone() && right_is_unit) { break true; - } else { +} else { if (left_is_unit && right_opt.clone()) { break true; - } else { - let left_is_container = - node_is_element_collection(&left, source_indices.clone()); - let right_is_container = - node_is_element_collection(&right, source_indices.clone()); - if (left_is_container && right_is_container) { - if (authored_name_at(source_indices.clone(), &left).as_str() - != authored_name_at(source_indices.clone(), &right).as_str()) - { +} else { + let left_is_container = node_is_element_collection(&left, source_indices.clone()); +let right_is_container = node_is_element_collection(&right, source_indices.clone()); +if (left_is_container && right_is_container) { + if (authored_name_at(source_indices.clone(), &left).as_str() != authored_name_at(source_indices.clone(), &right).as_str()) { break false; - } else { +} else { match left.children.clone().first().cloned() { - Some(left_ch) => { - match right.children.clone().first().cloned() { - Some(right_ch) => { - let left_el = child_type_node(&left_ch); - let right_el = child_type_node(&right_ch); - let left_el_is_unit = is_unit_like(&left_el); - let right_el_is_unit = is_unit_like(&right_el); - if (left_el_is_unit || right_el_is_unit) { - break true; - } else { - { - let __tco_0 = left_el.clone(); - let __tco_1 = right_el.clone(); - left = __tco_0; - right = __tco_1; - continue; - } - } - } - None => { - break true; - } - } - } - None => { - break true; - } - } - } - } else { + Some(left_ch) => { match right.children.clone().first().cloned() { + Some(right_ch) => { let left_el = child_type_node(&left_ch); +let right_el = child_type_node(&right_ch); +let left_el_is_unit = is_unit_like(&left_el); +let right_el_is_unit = is_unit_like(&right_el); +if (left_el_is_unit || right_el_is_unit) { + break true; +} else { + { + let __tco_0 = left_el.clone(); +let __tco_1 = right_el.clone(); +left = __tco_0; +right = __tco_1; +continue; +} +} }, + None => { break true; }, +} }, + None => { break true; }, +} +} +} else { if (left_opt.clone() && right_opt.clone()) { let left_inner = with_required_cardinality(&left); - let right_inner = with_required_cardinality(&right); - let left_inner_is_unit = is_unit_like(&left_inner); - let right_inner_is_unit = is_unit_like(&right_inner); - if (left_inner_is_unit || right_inner_is_unit) { +let right_inner = with_required_cardinality(&right); +let left_inner_is_unit = is_unit_like(&left_inner); +let right_inner_is_unit = is_unit_like(&right_inner); +if (left_inner_is_unit || right_inner_is_unit) { break true; - } else { +} else { { let __tco_0 = left_inner.clone(); - let __tco_1 = right_inner.clone(); - left = __tco_0; - right = __tco_1; - continue; - } - } - } else { +let __tco_1 = right_inner.clone(); +left = __tco_0; +right = __tco_1; +continue; +} +} +} else { if (left_opt.clone() || right_opt.clone()) { break false; - } else { - break (authored_name_at(source_indices.clone(), &left) - .as_str() - == authored_name_at(source_indices.clone(), &right) - .as_str()); - } - } - } - } - } - } - } - } +} else { + break (authored_name_at(source_indices.clone(), &left).as_str() == authored_name_at(source_indices.clone(), &right).as_str()); +} +} +} +} +} +} +} +} } -pub fn prefer_specific_type( - left: Rc, - right: Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn prefer_specific_type(left: Rc, right: Rc, source_indices: &Rc>>) -> Rc { { let left_is_container = node_is_element_collection(&left, source_indices.clone()); - let left_is_optional = (left.return_cardinality.clone() == Cardinality::CardOptional); - let left_first_child = left.children.clone().first().cloned(); - let left_norm_name = authored_name_at(source_indices.clone(), &left); - let left_is_unit_inner = if left_is_container.clone() { +let left_is_optional = (left.return_cardinality.clone() == Cardinality::CardOptional); +let left_first_child = left.children.clone().first().cloned(); +let left_norm_name = authored_name_at(source_indices.clone(), &left); +let left_is_unit_inner = if left_is_container.clone() { match left_first_child { - Some(ch) => { - let el = child_type_node(&ch); - let el_is_unit = is_unit_like(&el); - el_is_unit - } - None => false, - } + Some(ch) => { + let el = child_type_node(&ch); +let el_is_unit = is_unit_like(&el); +el_is_unit +}, + None => false, +} } else { if left_is_optional.clone() { { let left_is_unit = is_unit_like(&left); - left_is_unit - } +left_is_unit +} } else { false } }; - let right_is_container = node_is_element_collection(&right, source_indices.clone()); - let right_is_optional = (right.return_cardinality.clone() == Cardinality::CardOptional); - let same_kind = if (left_is_container.clone() && right_is_container) { +let right_is_container = node_is_element_collection(&right, source_indices.clone()); +let right_is_optional = (right.return_cardinality.clone() == Cardinality::CardOptional); +let same_kind = if (left_is_container.clone() && right_is_container) { (left_norm_name.as_str() == authored_name_at(source_indices.clone(), &right).as_str()) } else { if (left_is_optional.clone() && right_is_optional) { @@ -1717,51 +1230,45 @@ pub fn prefer_specific_type( false } }; - if (same_kind && left_is_unit_inner) { +if (same_kind && left_is_unit_inner) { right.clone() } else { - if (is_fully_resolved(&right, &source_indices) - && !is_fully_resolved(&left, &source_indices)) - { + if (is_fully_resolved(&right, &source_indices) && !is_fully_resolved(&left, &source_indices)) { right.clone() } else { left.clone() } } - } +} } -pub fn node_type_equals( - left: &Rc, - right: &Rc, - source_indices: Rc>>, -) -> bool { +pub fn node_type_equals(left: &Rc, right: &Rc, source_indices: Rc>>) -> bool { { let left_err = if (left.inferred.clone() != None) { is_compiler_error(left.inferred.clone().clone().unwrap()) } else { false }; - let right_err = if (right.inferred.clone() != None) { +let right_err = if (right.inferred.clone() != None) { is_compiler_error(right.inferred.clone().clone().unwrap()) } else { false }; - let left_tv = if (left.inferred.clone() != None) { +let left_tv = if (left.inferred.clone() != None) { is_type_variable(left.inferred.clone().clone().unwrap()) } else { false }; - let right_tv = if (right.inferred.clone() != None) { +let right_tv = if (right.inferred.clone() != None) { is_type_variable(right.inferred.clone().clone().unwrap()) } else { false }; - let left_opt = (left.return_cardinality.clone() == Cardinality::CardOptional); - let right_opt = (right.return_cardinality.clone() == Cardinality::CardOptional); - let right_is_unit_eq = is_unit_like(&right); - let left_is_unit_eq = is_unit_like(&left); - if (left_err || right_err) { +let left_opt = (left.return_cardinality.clone() == Cardinality::CardOptional); +let right_opt = (right.return_cardinality.clone() == Cardinality::CardOptional); +let right_is_unit_eq = is_unit_like(&right); +let left_is_unit_eq = is_unit_like(&left); +if (left_err || right_err) { true } else { if (left_tv.clone() && right_tv.clone()) { @@ -1777,11 +1284,7 @@ pub fn node_type_equals( true } else { if (left_opt.clone() && right_opt.clone()) { - node_type_equals_core( - &with_required_cardinality(&left), - &with_required_cardinality(&right), - &source_indices, - ) + node_type_equals_core(&with_required_cardinality(&left), &with_required_cardinality(&right), &source_indices) } else { node_type_equals_core(&left, &right, &source_indices) } @@ -1790,75 +1293,34 @@ pub fn node_type_equals( } } } - } +} } -pub fn node_type_equals_core( - left: &Rc, - right: &Rc, - source_indices: &Rc>>, -) -> bool { +pub fn node_type_equals_core(left: &Rc, right: &Rc, source_indices: &Rc>>) -> bool { { - let left_leaf = (((left.connective.clone() == Connective::NoConnective) - && ((left.children.clone().len() as i64) == 0)) - && ((left.properties.clone().len() as i64) == 0)); - let right_leaf = (((right.connective.clone() == Connective::NoConnective) - && ((right.children.clone().len() as i64) == 0)) - && ((right.properties.clone().len() as i64) == 0)); - let left_struct = (left.connective.clone() != Connective::NoConnective); - let right_struct = (right.connective.clone() != Connective::NoConnective); - let left_name = authored_name_at(source_indices.clone(), &left); - let right_name = authored_name_at(source_indices.clone(), &right); - if (left_leaf.clone() && right_leaf.clone()) { + let left_leaf = (((left.connective.clone() == Connective::NoConnective) && ((left.children.clone().len() as i64) == 0)) && ((left.properties.clone().len() as i64) == 0)); +let right_leaf = (((right.connective.clone() == Connective::NoConnective) && ((right.children.clone().len() as i64) == 0)) && ((right.properties.clone().len() as i64) == 0)); +let left_struct = (left.connective.clone() != Connective::NoConnective); +let right_struct = (right.connective.clone() != Connective::NoConnective); +let left_name = authored_name_at(source_indices.clone(), &left); +let right_name = authored_name_at(source_indices.clone(), &right); +if (left_leaf.clone() && right_leaf.clone()) { (left_name.as_str() == right_name.as_str()) } else { if (left_struct.clone() && right_struct.clone()) { if (left_name.as_str() != right_name.as_str()) { false } else { - if ((left.connective.clone() == Connective::Conj) - != (right.connective.clone() == Connective::Conj)) - { + if ((left.connective.clone() == Connective::Conj) != (right.connective.clone() == Connective::Conj)) { false } else { - if ((left.children.clone().len() as i64) - != (right.children.clone().len() as i64)) - { + if ((left.children.clone().len() as i64) != (right.children.clone().len() as i64)) { false } else { - { - let mut __all = true; - for pair in Rc::new( - left.children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if !(match right - .children - .clone() - .get(pair.0.clone() as usize) - .cloned() - { - Some(right_child) => node_type_equals( - &pair.1.clone(), - &right_child, - source_indices.clone(), - ), - None => false, - }) { - __all = false; - break; - } - } - __all - } + { let mut __all = true; for pair in Rc::new(left.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if !(match right.children.clone().get(pair.0.clone() as usize).cloned() { + Some(right_child) => node_type_equals(&pair.1.clone(), &right_child, source_indices.clone()), + None => false, +}) { __all = false; break; } } __all } } } } @@ -1870,370 +1332,222 @@ pub fn node_type_equals_core( (left_name.as_str() == right_name.as_str()) } else { { - let left_is_container = - node_is_element_collection(&left, source_indices.clone()); - let right_is_container = - node_is_element_collection(&right, source_indices.clone()); - if (left_is_container && right_is_container) { + let left_is_container = node_is_element_collection(&left, source_indices.clone()); +let right_is_container = node_is_element_collection(&right, source_indices.clone()); +if (left_is_container && right_is_container) { if (left_name.as_str() != right_name.as_str()) { false } else { match left.children.clone().first().cloned() { - Some(left_ch) => { - match right.children.clone().first().cloned() { - Some(right_ch) => node_type_equals( - &child_type_node(&left_ch), - &child_type_node(&right_ch), - source_indices.clone(), - ), - None => false, - } - } - None => false, - } + Some(left_ch) => match right.children.clone().first().cloned() { + Some(right_ch) => node_type_equals(&child_type_node(&left_ch), &child_type_node(&right_ch), source_indices.clone()), + None => false, +}, + None => false, +} } } else { { - let both_maps = - (node_is_keyed_collection(&left, source_indices.clone()) - && node_is_keyed_collection( - &right, - source_indices.clone(), - )); - if both_maps { - if (((left.children.clone().len() as i64) == 2) - && ((right.children.clone().len() as i64) == 2)) - { + let both_maps = (node_is_keyed_collection(&left, source_indices.clone()) && node_is_keyed_collection(&right, source_indices.clone())); +if both_maps { + if (((left.children.clone().len() as i64) == 2) && ((right.children.clone().len() as i64) == 2)) { match left.children.clone().first().cloned() { - Some(left_first) => match right - .children - .clone() - .first() - .cloned() - { - Some(right_first) => match left - .children - .clone() - .get(1 as usize) - .cloned() - { - Some(left_second) => match right - .children - .clone() - .get(1 as usize) - .cloned() - { - Some(right_second) => { - (node_type_equals( - &child_type_node(&left_first), - &child_type_node(&right_first), - source_indices.clone(), - ) && node_type_equals( - &child_type_node(&left_second), - &child_type_node(&right_second), - source_indices.clone(), - )) - } - None => false, - }, - None => false, - }, - None => false, - }, - None => false, - } + Some(left_first) => match right.children.clone().first().cloned() { + Some(right_first) => match left.children.clone().get(1 as usize).cloned() { + Some(left_second) => match right.children.clone().get(1 as usize).cloned() { + Some(right_second) => (node_type_equals(&child_type_node(&left_first), &child_type_node(&right_first), source_indices.clone()) && node_type_equals(&child_type_node(&left_second), &child_type_node(&right_second), source_indices.clone())), + None => false, +}, + None => false, +}, + None => false, +}, + None => false, +} } else { false } } else { - if (((left.params.clone().len() as i64) > 0) - && ((right.params.clone().len() as i64) > 0)) - { - if ((left.params.clone().len() as i64) - != (right.params.clone().len() as i64)) - { + if (((left.params.clone().len() as i64) > 0) && ((right.params.clone().len() as i64) > 0)) { + if ((left.params.clone().len() as i64) != (right.params.clone().len() as i64)) { false } else { { - let params_eq = { - let mut __all = true; - for pair in Rc::new( - left.params - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if !(match right - .params - .clone() - .get(pair.0.clone() as usize) - .cloned() - { - Some(right_param) => { - node_type_equals( - ¶m_node_type_expr( - &pair.1.clone(), - ), - ¶m_node_type_expr( - &right_param, - ), - source_indices.clone(), - ) - } - None => false, - }) { - __all = false; - break; - } - } - __all - }; - if (params_eq == false) { + let params_eq = { let mut __all = true; for pair in Rc::new(left.params.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if !(match right.params.clone().get(pair.0.clone() as usize).cloned() { + Some(right_param) => node_type_equals(¶m_node_type_expr(&pair.1.clone()), ¶m_node_type_expr(&right_param), source_indices.clone()), + None => false, +}) { __all = false; break; } } __all }; +if (params_eq == false) { false } else { - match left - .inferred - .clone() - .as_deref() - .cloned() - { - Some(InferredNode::Resolved { - node: left_ret, - .. - }) => match right - .inferred - .clone() - .as_deref() - .cloned() - { - Some(InferredNode::Resolved { - node: right_ret, - .. - }) => node_type_equals( - &left_ret, - &right_ret, - source_indices.clone(), - ), - None => false, - _ => false, - }, - None => { - (right.inferred.clone() == None) - } - _ => false, - } + match left.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: left_ret, .. }) => match right.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: right_ret, .. }) => node_type_equals(&left_ret, &right_ret, source_indices.clone()), + None => false, + _ => false, +}, + None => (right.inferred.clone() == None), + _ => false, +} } - } +} } } else { false } } - } +} } - } +} } } } } - } +} } -pub fn node_type_deps( - n: &Rc, - source_indices: &Rc>>, -) -> Rc> { +pub fn node_type_deps(n: &Rc, source_indices: &Rc>>) -> Rc> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let n_is_type_var = if (n.inferred.clone() != None) { - is_type_variable(n.inferred.clone().clone().unwrap()) - } else { - false - }; - if n_is_type_var { - return Rc::new(vec![]); - } - let __is_named_ref = if (n.inferred.clone() == None) { - false - } else { - match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - (((((rt.connective.clone() == Connective::NoConnective) - && ((rt.children.clone().len() as i64) == 0)) - && (rt.ident_span.clone() != None)) - && (authored_name_at(source_indices.clone(), &rt).as_str() - != "None".to_string().as_str())) - && (is_kernel_type(authored_name_at(source_indices.clone(), &rt)) == false)) - } - _ => false, - } - }; - let has_structure = (n.connective.clone() != Connective::NoConnective); - let n_name = authored_name_at(source_indices.clone(), &n); - if __is_named_ref { - match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - Rc::new(vec![authored_name_at(source_indices.clone(), &rt)]) - } - _ => Rc::new(vec![]), + { + let n_is_type_var = if (n.inferred.clone() != None) { + is_type_variable(n.inferred.clone().clone().unwrap()) + } else { + false + }; +if n_is_type_var { + return Rc::new(vec![]) } - } else { - if has_structure { - Rc::new({ - let mut __result = Vec::new(); - for child in n.children.clone().iter().cloned() { - __result.extend( - (*match child.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - node_type_deps(&rt, &source_indices) - } - _ => { - if (child.inferred.clone() == None) { - node_type_deps(&child, &source_indices) - } else { - Rc::new(vec![]) - } - } - }) - .iter() - .cloned(), - ); - } - __result - }) +let __is_named_ref = if (n.inferred.clone() == None) { + false } else { - if (n.inferred.clone() != None) { - match n.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - node_type_deps(&rt, &source_indices) - } - _ => Rc::new(vec![]), - } + match n.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => (((((rt.connective.clone() == Connective::NoConnective) && ((rt.children.clone().len() as i64) == 0)) && (rt.ident_span.clone() != None)) && (authored_name_at(source_indices.clone(), &rt).as_str() != "None".to_string().as_str())) && (is_kernel_type(authored_name_at(source_indices.clone(), &rt)) == false)), + _ => false, +} + }; +let has_structure = (n.connective.clone() != Connective::NoConnective); +let n_name = authored_name_at(source_indices.clone(), &n); +if __is_named_ref { + match n.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => Rc::new(vec![authored_name_at(source_indices.clone(), &rt)]), + _ => Rc::new(vec![]), +} + } else { + if has_structure { + Rc::new({ let mut __result = Vec::new(); for child in n.children.clone().iter().cloned() { __result.extend((*match child.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => node_type_deps(&rt, &source_indices), + _ => if (child.inferred.clone() == None) { + node_type_deps(&child, &source_indices) + } else { + Rc::new(vec![]) + }, +}).iter().cloned()); } __result }) } else { - if ((n.children.clone().len() as i64) > 0) { - { - let child_deps = Rc::new({ - let mut __result = Vec::new(); - for child in n.children.clone().iter().cloned() { - __result.extend( - (*node_type_deps(&child, &source_indices)).iter().cloned(), - ); - } - __result - }); - if ((n.ident_span.clone() != None) - && (is_kernel_type(n_name.clone()) == false)) + if (n.inferred.clone() != None) { + match n.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => node_type_deps(&rt, &source_indices), + _ => Rc::new(vec![]), +} + } else { + if ((n.children.clone().len() as i64) > 0) { { - v2_rt::concat(Rc::new(vec![n_name.clone()]), child_deps) + let child_deps = Rc::new({ let mut __result = Vec::new(); for child in n.children.clone().iter().cloned() { __result.extend((*node_type_deps(&child, &source_indices)).iter().cloned()); } __result }); +if ((n.ident_span.clone() != None) && (is_kernel_type(n_name.clone()) == false)) { + v2_rt::concat(Rc::new(vec![n_name.clone()]), child_deps) + } else { + child_deps + } +} + } else { + if ((is_kernel_type(n_name.clone()) || (n_name.clone().as_str() == "None".to_string().as_str())) || (n.ident_span.clone() == None)) { + Rc::new(vec![]) } else { - child_deps + Rc::new(vec![n_name.clone()]) } } - } else { - if ((is_kernel_type(n_name.clone()) - || (n_name.clone().as_str() == "None".to_string().as_str())) - || (n.ident_span.clone() == None)) - { - Rc::new(vec![]) - } else { - Rc::new(vec![n_name.clone()]) - } } } } - } +} }) } pub fn infer_literal_node(lit: Rc) -> Rc { match (*lit).clone() { - LiteralValue::LitStr { .. } => string_type(), - LiteralValue::LitInt { .. } => int_type(), - LiteralValue::LitFloat { .. } => float_type(), - LiteralValue::LitBool { .. } => bool_type(), - LiteralValue::LitNull => with_optional_cardinality(&unit_type()), - } + LiteralValue::LitStr { .. } => string_type(), + LiteralValue::LitInt { .. } => int_type(), + LiteralValue::LitFloat { .. } => float_type(), + LiteralValue::LitBool { .. } => bool_type(), + LiteralValue::LitNull => with_optional_cardinality(&unit_type()), +} } -pub fn method_receiver_element_node( - receiver_type: Rc, - source_indices: Rc>>, -) -> Rc { +pub fn method_receiver_element_node(receiver_type: Rc, source_indices: Rc>>) -> Rc { { let normed = normalize_access_type_node(receiver_type.clone()); - let maybe_element = if node_is_keyed_collection(&normed, source_indices) { +let maybe_element = if node_is_keyed_collection(&normed, source_indices) { match normed.children.clone().get(1 as usize).cloned() { - Some(ch) => Some(child_type_node(&ch)), - None => None, - } + Some(ch) => Some(child_type_node(&ch)), + None => None, +} } else { - if ((normed.connective.clone() == Connective::NoConnective) - && ((normed.children.clone().len() as i64) == 1)) - { + if ((normed.connective.clone() == Connective::NoConnective) && ((normed.children.clone().len() as i64) == 1)) { match normed.children.clone().first().cloned() { - Some(ch) => Some(child_type_node(&ch)), - None => None, - } + Some(ch) => Some(child_type_node(&ch)), + None => None, +} } else { None } }; - match maybe_element { - Some(el) => el.clone(), - None => receiver_type.clone(), - } - } +match maybe_element { + Some(el) => el.clone(), + None => receiver_type.clone(), +} +} } pub fn extract_optional_inner_node(n: &Rc) -> Rc { { let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); - if is_optional { +if is_optional { with_required_cardinality(&n) } else { n.clone() } - } +} } pub fn algebra_field_kind_name(kind: AlgebraFieldKind) -> String { match kind { - AlgebraFieldKind::AlgAdd => "add".to_string(), - AlgebraFieldKind::AlgMul => "mul".to_string(), - AlgebraFieldKind::AlgReciprocal => "reciprocal".to_string(), - AlgebraFieldKind::AlgQuotient => "quotient".to_string(), - AlgebraFieldKind::AlgRemainder => "remainder".to_string(), - AlgebraFieldKind::AlgCompare => "compare".to_string(), - AlgebraFieldKind::AlgMeet => "meet".to_string(), - AlgebraFieldKind::AlgJoin => "join".to_string(), - } + AlgebraFieldKind::AlgAdd => "add".to_string(), + AlgebraFieldKind::AlgMul => "mul".to_string(), + AlgebraFieldKind::AlgReciprocal => "reciprocal".to_string(), + AlgebraFieldKind::AlgQuotient => "quotient".to_string(), + AlgebraFieldKind::AlgRemainder => "remainder".to_string(), + AlgebraFieldKind::AlgCompare => "compare".to_string(), + AlgebraFieldKind::AlgMeet => "meet".to_string(), + AlgebraFieldKind::AlgJoin => "join".to_string(), +} } pub fn binop_algebra_fields(op: BinOp) -> Rc> { match op { - BinOp::Add => Rc::new(vec![AlgebraFieldKind::AlgAdd]), - BinOp::Sub => Rc::new(vec![AlgebraFieldKind::AlgAdd]), - BinOp::Mul => Rc::new(vec![AlgebraFieldKind::AlgMul]), - BinOp::Div => Rc::new(vec![ - AlgebraFieldKind::AlgReciprocal, - AlgebraFieldKind::AlgQuotient, - ]), - BinOp::Mod => Rc::new(vec![AlgebraFieldKind::AlgRemainder]), - BinOp::Eq => Rc::new(vec![AlgebraFieldKind::AlgCompare]), - BinOp::Ne => Rc::new(vec![AlgebraFieldKind::AlgCompare]), - BinOp::Lt => Rc::new(vec![AlgebraFieldKind::AlgCompare]), - BinOp::Gt => Rc::new(vec![AlgebraFieldKind::AlgCompare]), - BinOp::Le => Rc::new(vec![AlgebraFieldKind::AlgCompare]), - BinOp::Ge => Rc::new(vec![AlgebraFieldKind::AlgCompare]), - BinOp::And => Rc::new(vec![AlgebraFieldKind::AlgMeet]), - BinOp::Or => Rc::new(vec![AlgebraFieldKind::AlgJoin]), - BinOp::NullCoalesce => Rc::new(vec![]), - } + BinOp::Add => Rc::new(vec![AlgebraFieldKind::AlgAdd]), + BinOp::Sub => Rc::new(vec![AlgebraFieldKind::AlgAdd]), + BinOp::Mul => Rc::new(vec![AlgebraFieldKind::AlgMul]), + BinOp::Div => Rc::new(vec![AlgebraFieldKind::AlgReciprocal, AlgebraFieldKind::AlgQuotient]), + BinOp::Mod => Rc::new(vec![AlgebraFieldKind::AlgRemainder]), + BinOp::Eq => Rc::new(vec![AlgebraFieldKind::AlgCompare]), + BinOp::Ne => Rc::new(vec![AlgebraFieldKind::AlgCompare]), + BinOp::Lt => Rc::new(vec![AlgebraFieldKind::AlgCompare]), + BinOp::Gt => Rc::new(vec![AlgebraFieldKind::AlgCompare]), + BinOp::Le => Rc::new(vec![AlgebraFieldKind::AlgCompare]), + BinOp::Ge => Rc::new(vec![AlgebraFieldKind::AlgCompare]), + BinOp::And => Rc::new(vec![AlgebraFieldKind::AlgMeet]), + BinOp::Or => Rc::new(vec![AlgebraFieldKind::AlgJoin]), + BinOp::NullCoalesce => Rc::new(vec![]), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -2242,43 +1556,23 @@ pub struct AlgebraFieldMatch { pub field_node: Rc, } -pub fn first_matching_algebra_field( - mut n: Rc, - mut candidates: Rc>, - mut source_indices: Rc>>, -) -> Option> { +pub fn first_matching_algebra_field(mut n: Rc, mut candidates: Rc>, mut source_indices: Rc>>) -> Option> { loop { match candidates.clone().first().cloned() { - None => { - break None; - } - Some(kind) => { - match find_child_named( - n.clone(), - algebra_field_kind_name(kind.clone()), - source_indices.clone(), - ) { - Some(f) => { - break Some(Rc::new(AlgebraFieldMatch { - field_kind: kind.clone(), - field_node: f.clone(), - })); - } - None => { - let __tco_0 = Rc::new( - candidates - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - candidates = __tco_0; - continue; - } - } - } - } - } + None => { break None; }, + Some(kind) => { match find_child_named(n.clone(), algebra_field_kind_name(kind.clone()), source_indices.clone()) { + Some(f) => { break Some(Rc::new(AlgebraFieldMatch { + field_kind: kind.clone(), + field_node: f.clone(), +})); }, + None => { { + let __tco_0 = Rc::new(candidates.iter().cloned().skip(1 as usize).collect::>()); +candidates = __tco_0; +continue; +} }, +} }, +} +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -2287,132 +1581,113 @@ pub struct BinOpInferred { pub algebra_field: Option, } -pub fn infer_binop_type_node( - op: &BinOp, - left_type: &Rc, - source_indices: Rc>>, -) -> Rc { +pub fn infer_binop_type_node(op: &BinOp, left_type: &Rc, source_indices: Rc>>) -> Rc { match op.clone() { - BinOp::Eq => Rc::new(BinOpInferred { - result_type: bool_type(), - algebra_field: None, - }), - BinOp::Ne => Rc::new(BinOpInferred { - result_type: bool_type(), - algebra_field: None, - }), - BinOp::Lt => Rc::new(BinOpInferred { - result_type: bool_type(), - algebra_field: None, - }), - BinOp::Gt => Rc::new(BinOpInferred { - result_type: bool_type(), - algebra_field: None, - }), - BinOp::Le => Rc::new(BinOpInferred { - result_type: bool_type(), - algebra_field: None, - }), - BinOp::Ge => Rc::new(BinOpInferred { - result_type: bool_type(), - algebra_field: None, - }), - BinOp::And => Rc::new(BinOpInferred { - result_type: bool_type(), - algebra_field: None, - }), - BinOp::Or => Rc::new(BinOpInferred { - result_type: bool_type(), - algebra_field: None, - }), - BinOp::NullCoalesce => Rc::new(BinOpInferred { - result_type: extract_optional_inner_node(&left_type), - algebra_field: None, - }), - _ => { - let candidates = binop_algebra_fields(op.clone()); - let is_product = (left_type.connective.clone() == Connective::Conj); - if is_product { - match first_matching_algebra_field(left_type.clone(), candidates, source_indices) { - Some(m) => match m.field_node.clone().inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - if ((rt.params.clone().len() as i64) > 0) { - match rt.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: return_type, .. - }) => Rc::new(BinOpInferred { - result_type: return_type.clone(), - algebra_field: Some(m.field_kind.clone()), - }), - _ => Rc::new(BinOpInferred { - result_type: left_type.clone(), - algebra_field: Some(m.field_kind.clone()), - }), - } - } else { - Rc::new(BinOpInferred { - result_type: rt.clone(), - algebra_field: Some(m.field_kind.clone()), - }) - } - } - _ => Rc::new(BinOpInferred { - result_type: left_type.clone(), - algebra_field: None, - }), - }, - None => Rc::new(BinOpInferred { - result_type: left_type.clone(), - algebra_field: None, - }), - } + BinOp::Eq => Rc::new(BinOpInferred { + result_type: bool_type(), + algebra_field: None, +}), + BinOp::Ne => Rc::new(BinOpInferred { + result_type: bool_type(), + algebra_field: None, +}), + BinOp::Lt => Rc::new(BinOpInferred { + result_type: bool_type(), + algebra_field: None, +}), + BinOp::Gt => Rc::new(BinOpInferred { + result_type: bool_type(), + algebra_field: None, +}), + BinOp::Le => Rc::new(BinOpInferred { + result_type: bool_type(), + algebra_field: None, +}), + BinOp::Ge => Rc::new(BinOpInferred { + result_type: bool_type(), + algebra_field: None, +}), + BinOp::And => Rc::new(BinOpInferred { + result_type: bool_type(), + algebra_field: None, +}), + BinOp::Or => Rc::new(BinOpInferred { + result_type: bool_type(), + algebra_field: None, +}), + BinOp::NullCoalesce => Rc::new(BinOpInferred { + result_type: extract_optional_inner_node(&left_type), + algebra_field: None, +}), + _ => { + let candidates = binop_algebra_fields(op.clone()); +let is_product = (left_type.connective.clone() == Connective::Conj); +if is_product { + match first_matching_algebra_field(left_type.clone(), candidates, source_indices) { + Some(m) => match m.field_node.clone().inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => if ((rt.params.clone().len() as i64) > 0) { + match rt.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: return_type, .. }) => Rc::new(BinOpInferred { + result_type: return_type.clone(), + algebra_field: Some(m.field_kind.clone()), +}), + _ => Rc::new(BinOpInferred { + result_type: left_type.clone(), + algebra_field: Some(m.field_kind.clone()), +}), +} } else { Rc::new(BinOpInferred { - result_type: left_type.clone(), - algebra_field: None, - }) - } + result_type: rt.clone(), + algebra_field: Some(m.field_kind.clone()), +}) + }, + _ => Rc::new(BinOpInferred { + result_type: left_type.clone(), + algebra_field: None, +}), +}, + None => Rc::new(BinOpInferred { + result_type: left_type.clone(), + algebra_field: None, +}), +} + } else { + Rc::new(BinOpInferred { + result_type: left_type.clone(), + algebra_field: None, +}) } - } +}, +} } -pub fn for_each_element_type_node( - n: Rc, - source_indices: Rc>>, -) -> Rc { +pub fn for_each_element_type_node(n: Rc, source_indices: Rc>>) -> Rc { { let normed = normalize_access_type_node(n); - let is_single_child = ((normed.connective.clone() == Connective::NoConnective) - && ((normed.children.clone().len() as i64) == 1)); - let extracted = if is_single_child { +let is_single_child = ((normed.connective.clone() == Connective::NoConnective) && ((normed.children.clone().len() as i64) == 1)); +let extracted = if is_single_child { match normed.children.clone().first().cloned() { - Some(ch) => Some(child_type_node(&ch)), - None => None, - } + Some(ch) => Some(child_type_node(&ch)), + None => None, +} } else { None }; - match extracted { - Some(el) => el.clone(), - None => { - if ((((normed.connective.clone() == Connective::NoConnective) - && ((normed.children.clone().len() as i64) == 0)) - && ((normed.properties.clone().len() as i64) == 0)) - && (authored_name_at(source_indices, &normed).as_str() - == "String".to_string().as_str())) - { - string_type() - } else { - normed.clone() - } - } - } - } +match extracted { + Some(el) => el.clone(), + None => if ((((normed.connective.clone() == Connective::NoConnective) && ((normed.children.clone().len() as i64) == 0)) && ((normed.properties.clone().len() as i64) == 0)) && (authored_name_at(source_indices, &normed).as_str() == "String".to_string().as_str())) { + string_type() + } else { + normed.clone() + }, +} +} } pub fn emit_map_has(m: Rc>, key: String) -> bool { match v2_rt::map_get(&m, key) { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } diff --git a/src/v2/stage0/src/v2_compiler_languages.rs b/src/v2/stage0/src/v2_compiler_languages.rs index 5656cb0a11b..13c3f2be93f 100644 --- a/src/v2/stage0/src/v2_compiler_languages.rs +++ b/src/v2/stage0/src/v2_compiler_languages.rs @@ -1,89 +1,47 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.languages -use self::IfValueForm::*; +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_compiler_artifact::{RenderTarget}; +use crate::v2_compiler_artifact::RenderTarget::{Rust, Python, Go, Dag}; +pub use crate::v2_std_core::{BinOp, LiteralValue}; +use crate::v2_std_core::BinOp::{Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Gt, Le, Ge, And, Or, NullCoalesce}; +use crate::v2_std_core::LiteralValue::*; +pub use crate::std_syntax::{ItemForm, ItemFormKind, OperatorSpec, SyntaxSpec, AlgebraFieldKind, BodyKind}; +use crate::std_syntax::ItemFormKind::{FuncForm, StructForm, EnumForm, TypeAliasForm, ModuleForm, OtherForm}; +use crate::std_syntax::BodyKind::{ExprBody, BlockBody, TypeBody, ValueBody, NoBody, ServiceBody, ResourceBody}; +use crate::std_syntax::AlgebraFieldKind::*; +pub use crate::extdeps_languages_rust_syntax::{rust_operators, rust_item_forms}; +pub use crate::extdeps_languages_python_syntax::{python_operators, python_item_forms}; +pub use crate::extdeps_languages_go_syntax::{go_operators, go_item_forms}; +pub use crate::extdeps_languages_dag_syntax::{dag_operators}; +pub use crate::extdeps_languages_rust_emit::{rust_keywords, rust_container_templates, rust_reserved, rust_reserved_escape_prefix, rust_struct_derives, rust_struct_derives_copy, rust_enum_derives, rust_enum_derives_copy, rust_serde_tag, rust_serde_rename_template, rust_source_extension, rust_source_dir, rust_visibility, rust_string_types, rust_method_templates, rust_func_keyword, rust_async_prefix, rust_struct_keyword, rust_enum_keyword, rust_type_alias_keyword, rust_param_separator, rust_return_arrow, rust_param_type_sep, rust_module_keyword, rust_import_keyword, rust_import_from_keyword, rust_lambda_template, rust_error_expr_template, rust_list_literal_empty, rust_list_literal_template, rust_null_coalesce_template, rust_error_type_template, rust_type_arg_open, rust_type_arg_close, rust_void_type, rust_tuple_empty, rust_tuple_pair_template, rust_tuple_multi_template, rust_tuple_separator}; +pub use crate::extdeps_languages_python_emit::{python_keywords, python_reserved, python_reserved_escape_suffix, python_derive_attribute, python_default_value, python_source_extension, python_module_init, python_method_templates, python_string_types, python_func_keyword, python_async_prefix, python_struct_keyword, python_enum_keyword, python_type_alias_keyword, python_param_separator, python_return_arrow, python_param_type_sep, python_module_keyword, python_import_keyword, python_import_from_keyword, python_lambda_template, python_error_expr_template, python_list_literal_empty, python_list_literal_template, python_null_coalesce_template, python_error_type_template, python_type_arg_open, python_type_arg_close, python_void_type, python_tuple_empty, python_tuple_pair_template, python_tuple_multi_template, python_tuple_separator}; +pub use crate::extdeps_languages_go_emit::{go_keywords, go_reserved, go_reserved_escape_suffix, go_manifest_file, go_source_extension, go_method_templates, go_string_types, go_func_keyword, go_async_prefix, go_struct_keyword, go_enum_keyword, go_type_alias_keyword, go_param_separator, go_return_arrow, go_param_type_sep, go_module_keyword, go_import_keyword, go_import_from_keyword, go_lambda_template, go_error_expr_template, go_list_literal_empty, go_list_literal_template, go_null_coalesce_template, go_error_type_template, go_type_arg_open, go_type_arg_close, go_void_type, go_tuple_empty, go_tuple_pair_template, go_tuple_multi_template, go_tuple_separator}; +pub use crate::extdeps_languages_dag_emit::{dag_keywords, dag_container_templates, dag_reserved, dag_string_types, dag_func_keyword, dag_async_prefix, dag_struct_keyword, dag_enum_keyword, dag_type_alias_keyword, dag_param_separator, dag_return_arrow, dag_param_type_sep, dag_module_keyword, dag_import_keyword, dag_import_from_keyword, dag_source_extension, dag_lambda_template, dag_error_expr_template, dag_list_literal_empty, dag_list_literal_template, dag_null_coalesce_template, dag_error_type_template, dag_type_arg_open, dag_type_arg_close, dag_void_type, dag_tuple_empty, dag_tuple_pair_template, dag_tuple_multi_template, dag_tuple_separator}; +use self::ReservedWordStrategy::*; +use self::TestNameStyle::*; use self::ImportTrigger::*; -use self::InterpStyle::*; +use self::IfValueForm::*; use self::NamingCase::*; -use self::ReservedWordStrategy::*; +use self::VisibilitySpec::*; use self::ServiceMethodStrategy::*; use self::ServiceReturnStrategy::*; -use self::TestNameStyle::*; -use self::VisibilitySpec::*; -pub use crate::extdeps_languages_dag_emit::{ - dag_async_prefix, dag_container_templates, dag_enum_keyword, dag_error_expr_template, - dag_error_type_template, dag_func_keyword, dag_import_from_keyword, dag_import_keyword, - dag_keywords, dag_lambda_template, dag_list_literal_empty, dag_list_literal_template, - dag_module_keyword, dag_null_coalesce_template, dag_param_separator, dag_param_type_sep, - dag_reserved, dag_return_arrow, dag_source_extension, dag_string_types, dag_struct_keyword, - dag_tuple_empty, dag_tuple_multi_template, dag_tuple_pair_template, dag_tuple_separator, - dag_type_alias_keyword, dag_type_arg_close, dag_type_arg_open, dag_void_type, -}; -pub use crate::extdeps_languages_dag_syntax::dag_operators; -pub use crate::extdeps_languages_go_emit::{ - go_async_prefix, go_enum_keyword, go_error_expr_template, go_error_type_template, - go_func_keyword, go_import_from_keyword, go_import_keyword, go_keywords, go_lambda_template, - go_list_literal_empty, go_list_literal_template, go_manifest_file, go_method_templates, - go_module_keyword, go_null_coalesce_template, go_param_separator, go_param_type_sep, - go_reserved, go_reserved_escape_suffix, go_return_arrow, go_source_extension, go_string_types, - go_struct_keyword, go_tuple_empty, go_tuple_multi_template, go_tuple_pair_template, - go_tuple_separator, go_type_alias_keyword, go_type_arg_close, go_type_arg_open, go_void_type, -}; -pub use crate::extdeps_languages_go_syntax::{go_item_forms, go_operators}; -pub use crate::extdeps_languages_python_emit::{ - python_async_prefix, python_default_value, python_derive_attribute, python_enum_keyword, - python_error_expr_template, python_error_type_template, python_func_keyword, - python_import_from_keyword, python_import_keyword, python_keywords, python_lambda_template, - python_list_literal_empty, python_list_literal_template, python_method_templates, - python_module_init, python_module_keyword, python_null_coalesce_template, - python_param_separator, python_param_type_sep, python_reserved, python_reserved_escape_suffix, - python_return_arrow, python_source_extension, python_string_types, python_struct_keyword, - python_tuple_empty, python_tuple_multi_template, python_tuple_pair_template, - python_tuple_separator, python_type_alias_keyword, python_type_arg_close, python_type_arg_open, - python_void_type, -}; -pub use crate::extdeps_languages_python_syntax::{python_item_forms, python_operators}; -pub use crate::extdeps_languages_rust_emit::{ - rust_async_prefix, rust_container_templates, rust_enum_derives, rust_enum_derives_copy, - rust_enum_keyword, rust_error_expr_template, rust_error_type_template, rust_func_keyword, - rust_import_from_keyword, rust_import_keyword, rust_keywords, rust_lambda_template, - rust_list_literal_empty, rust_list_literal_template, rust_method_templates, - rust_module_keyword, rust_null_coalesce_template, rust_param_separator, rust_param_type_sep, - rust_reserved, rust_reserved_escape_prefix, rust_return_arrow, rust_serde_rename_template, - rust_serde_tag, rust_source_dir, rust_source_extension, rust_string_types, rust_struct_derives, - rust_struct_derives_copy, rust_struct_keyword, rust_tuple_empty, rust_tuple_multi_template, - rust_tuple_pair_template, rust_tuple_separator, rust_type_alias_keyword, rust_type_arg_close, - rust_type_arg_open, rust_visibility, rust_void_type, -}; -pub use crate::extdeps_languages_rust_syntax::{rust_item_forms, rust_operators}; -use crate::std_syntax::AlgebraFieldKind::*; -use crate::std_syntax::BodyKind::{ - BlockBody, ExprBody, NoBody, ResourceBody, ServiceBody, TypeBody, ValueBody, -}; -use crate::std_syntax::ItemFormKind::{ - EnumForm, FuncForm, ModuleForm, OtherForm, StructForm, TypeAliasForm, -}; -pub use crate::std_syntax::{ - AlgebraFieldKind, BodyKind, ItemForm, ItemFormKind, OperatorSpec, SyntaxSpec, -}; -pub use crate::v2_compiler_artifact::RenderTarget; -use crate::v2_compiler_artifact::RenderTarget::{Dag, Go, Python, Rust}; -use crate::v2_rt; -use crate::v2_std_core::BinOp::{ - Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, NullCoalesce, Or, Sub, -}; -use crate::v2_std_core::LiteralValue::*; -pub use crate::v2_std_core::{BinOp, LiteralValue}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +use self::InterpStyle::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum ReservedWordStrategy { - PrefixEscape { prefix: String }, - SuffixEscape { suffix: String }, + PrefixEscape { + prefix: String, + }, + SuffixEscape { + suffix: String, + }, NoEscape, } @@ -133,10 +91,18 @@ pub struct TestConventions { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum ImportTrigger { - TypeUsageTrigger { type_name: String }, - TraitImplTrigger { trait_name: String }, - DeriveMacroTrigger { macro_name: String }, - ContainerUsageTrigger { container: String }, + TypeUsageTrigger { + type_name: String, + }, + TraitImplTrigger { + trait_name: String, + }, + DeriveMacroTrigger { + macro_name: String, + }, + ContainerUsageTrigger { + container: String, + }, AsyncUsageTrigger, } @@ -245,8 +211,12 @@ pub enum NamingCase { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum VisibilitySpec { - KeywordVisibility { prefix: String }, - CaseVisibility { export_case: NamingCase }, + KeywordVisibility { + prefix: String, + }, + CaseVisibility { + export_case: NamingCase, + }, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -262,74 +232,64 @@ pub struct TcoSyntax { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum ServiceMethodStrategy { - SelfInParams { self_param: String }, - ExternalReceiver { var_name: String }, + SelfInParams { + self_param: String, + }, + ExternalReceiver { + var_name: String, + }, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum ServiceReturnStrategy { ArrowReturn, - ErrorTupleReturn { error_type: String }, + ErrorTupleReturn { + error_type: String, + }, } impl ServiceReturnStrategy { pub fn error_type(&self) -> String { match self { ServiceReturnStrategy::ArrowReturn => panic!("no error_type on unit variant"), - ServiceReturnStrategy::ErrorTupleReturn { - error_type: __val, .. - } => __val.clone(), + ServiceReturnStrategy::ErrorTupleReturn { error_type: __val, .. } => __val.clone(), } } } pub fn service_self_param(spec: Rc) -> String { match (*spec.service_method.clone()).clone() { - ServiceMethodStrategy::SelfInParams { self_param: sp, .. } => sp.clone(), - ServiceMethodStrategy::ExternalReceiver { .. } => "".to_string(), - } + ServiceMethodStrategy::SelfInParams { self_param: sp, .. } => sp.clone(), + ServiceMethodStrategy::ExternalReceiver { .. } => "".to_string(), +} } pub fn service_receiver_str(spec: Rc, service_name: String) -> String { match (*spec.service_method.clone()).clone() { - ServiceMethodStrategy::SelfInParams { .. } => "".to_string(), - ServiceMethodStrategy::ExternalReceiver { var_name: v, .. } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat("(".to_string(), v.clone()), " *".to_string()), - service_name, - ), - ") ".to_string(), - ), - } + ServiceMethodStrategy::SelfInParams { .. } => "".to_string(), + ServiceMethodStrategy::ExternalReceiver { var_name: v, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("(".to_string(), v.clone()), " *".to_string()), service_name), ") ".to_string()), +} } pub fn service_method_depth(spec: Rc) -> i64 { match (*spec.service_method.clone()).clone() { - ServiceMethodStrategy::SelfInParams { .. } => 1, - ServiceMethodStrategy::ExternalReceiver { .. } => 0, - } + ServiceMethodStrategy::SelfInParams { .. } => 1, + ServiceMethodStrategy::ExternalReceiver { .. } => 0, +} } pub fn service_methods_inside_class(spec: Rc) -> bool { match (*spec.service_method.clone()).clone() { - ServiceMethodStrategy::SelfInParams { .. } => true, - ServiceMethodStrategy::ExternalReceiver { .. } => false, - } + ServiceMethodStrategy::SelfInParams { .. } => true, + ServiceMethodStrategy::ExternalReceiver { .. } => false, +} } pub fn service_return_str(spec: &Rc, ret_type: String) -> String { match (*spec.service_return.clone()).clone() { - ServiceReturnStrategy::ArrowReturn => { - v2_rt::concat(spec.items.clone().return_arrow.clone(), ret_type) - } - ServiceReturnStrategy::ErrorTupleReturn { error_type: et, .. } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(" (".to_string(), ret_type), ", ".to_string()), - et.clone(), - ), - ")".to_string(), - ), - } + ServiceReturnStrategy::ArrowReturn => v2_rt::concat(spec.items.clone().return_arrow.clone(), ret_type), + ServiceReturnStrategy::ErrorTupleReturn { error_type: et, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(" (".to_string(), ret_type), ", ".to_string()), et.clone()), ")".to_string()), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -349,20 +309,12 @@ pub struct ItemKeywords { pub fn item_keyword_for_kind(forms: Rc>>, kind: ItemFormKind) -> String { { - let matching = Rc::new({ - let mut __result = Vec::new(); - for f in forms.iter().cloned() { - if (f.kind.clone() == kind.clone()) { - __result.push(f); - } - } - __result - }); - match matching.first().cloned() { - Some(f) => f.keyword.clone(), - None => "__MISSING_ITEM_KEYWORD__".to_string(), - } - } + let matching = Rc::new({ let mut __result = Vec::new(); for f in forms.iter().cloned() { if (f.kind.clone() == kind.clone()) { __result.push(f); } } __result }); +match matching.first().cloned() { + Some(f) => f.keyword.clone(), + None => "__MISSING_ITEM_KEYWORD__".to_string(), +} +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -431,15 +383,15 @@ pub struct RecordLitSyntax { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum InterpStyle { - FormatArgs { placeholder: String }, + FormatArgs { + placeholder: String, + }, InlineExpr, } impl InterpStyle { pub fn placeholder(&self) -> String { match self { - InterpStyle::FormatArgs { - placeholder: __val, .. - } => __val.clone(), + InterpStyle::FormatArgs { placeholder: __val, .. } => __val.clone(), InterpStyle::InlineExpr => panic!("no placeholder on unit variant"), } } @@ -461,838 +413,760 @@ pub struct StringInterpSyntax { pub fn rust_spec() -> Rc { Rc::new(LanguageSpec { - target_name: "rust".to_string(), - reserved_words: Rc::new(ReservedWords { - keywords: rust_reserved(), - strategy: Rc::new(ReservedWordStrategy::PrefixEscape { - prefix: rust_reserved_escape_prefix(), - }), - }), - scaffold: Rc::new(ProjectScaffold { - manifest_file: Some("Cargo.toml".to_string()), - module_init_file: None, - source_file_extension: rust_source_extension(), - source_dir: Some(rust_source_dir()), - }), - serialization: Rc::new(SerializationSpec { - struct_derives: Some(rust_struct_derives()), - struct_derives_copy: Some(rust_struct_derives_copy()), - enum_derives: Some(rust_enum_derives()), - enum_derives_copy: Some(rust_enum_derives_copy()), - tag_attribute: Some(rust_serde_tag()), - rename_attribute_template: Some(rust_serde_rename_template()), - derive_attribute: None, - default_value: None, - }), - test_conventions: Rc::new(TestConventions { - file_prefix: "".to_string(), - file_suffix: "_test".to_string(), - file_dir: Some("tests/".to_string()), - function_prefix: "test_".to_string(), - name_style: TestNameStyle::SnakeCaseTestNames, - async_decorator: Some("#[tokio::test]".to_string()), - }), - visibility: Rc::new(VisibilitySpec::KeywordVisibility { - prefix: rust_visibility(), - }), - sharing: Rc::new(SharingStrategy { - needs_sharing: true, - wrap_template: "Rc<{0}>".to_string(), - clone_value: "{0}.clone()".to_string(), - deref_clone: "(*{0}).clone()".to_string(), - field_clone: "{0}.{1}.clone()".to_string(), - iter_owned: "{0}.iter().cloned()".to_string(), - clone_suffix: ".cloned()".to_string(), - borrow_param_template: "&{0}".to_string(), - borrow_arg_template: "&{0}".to_string(), - }), - indexing: Rc::new(IndexingSemantics { - list_index: "{0}[({1}) as usize].clone()".to_string(), - map_index: "({0}).get(&{1}).cloned()".to_string(), - string_index: "v2_rt::char_at(&{0}, {1})".to_string(), - list_slice: None, - string_slice: Some("v2_rt::substring(&{0}, {1}, {2})".to_string()), - }), - annotations: Rc::new(AnnotationRequirements { - let_binding_inferred: "let {0} = {1};".to_string(), - let_binding_annotated: "let {0}: {1} = {2};".to_string(), - lambda_param_typed: "{0}: {1}".to_string(), - lambda_param_untyped: "{0}".to_string(), - }), - method_templates: Some(rust_method_templates()), - service_fields: Rc::new(ServiceFieldTemplates { - rest_decl: " pub base_url: String,\n".to_string(), - auth_decl: " pub auth_token: String,\n".to_string(), - shell_decl: " pub working_dir: Option,\n".to_string(), - file_decl: " pub base_path: String,\n".to_string(), - rest_ctor: " base_url: \"{0}\".to_string(),\n".to_string(), - auth_ctor: " auth_token: String::new(),\n".to_string(), - shell_ctor: " working_dir: None,\n".to_string(), - file_ctor: " base_path: \".\".to_string(),\n".to_string(), - }), - block_syntax: Rc::new(BlockSyntax { - block_open: " {\n".to_string(), - block_close: "}".to_string(), - else_clause: "} else {\n".to_string(), - match_keyword: "match ".to_string(), - case_keyword: "".to_string(), - arm_separator: ",".to_string(), - stmt_terminator: ";".to_string(), - significant_whitespace: false, - }), - for_each_syntax: Rc::new(ForEachSyntax { - prefix: "for ".to_string(), - separator: " in ".to_string(), - }), - tco: Rc::new(TcoSyntax { - loop_keyword: "loop".to_string(), - break_return: "break".to_string(), - continue_str: "continue;".to_string(), - temp_var_prefix: "__tco_".to_string(), - temp_decl_prefix: "let ".to_string(), - temp_assign_op: " = ".to_string(), - }), - items: Rc::new(ItemKeywords { - func_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::FuncForm), - async_prefix: rust_async_prefix(), - struct_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::StructForm), - enum_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::EnumForm), - type_alias_keyword: item_keyword_for_kind( - rust_item_forms(), - ItemFormKind::TypeAliasForm, - ), - param_separator: rust_param_separator(), - return_arrow: rust_return_arrow(), - param_type_sep: rust_param_type_sep(), - module_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::ModuleForm), - import_keyword: rust_import_keyword(), - import_from_keyword: rust_import_from_keyword(), - }), - expression_semantics: Rc::new(ExpressionSemantics { - if_value_form: IfValueForm::IfExpression, - wildcard_case: None, - variant_pattern: Some(Rc::new(VariantPatternSyntax { - open: " { ".to_string(), - close: " }".to_string(), - binding_sep: ": ".to_string(), - empty_suffix: "".to_string(), - })), - guard_prefix: Some(" if ".to_string()), - empty_return_value: "()".to_string(), - return_suffix: "".to_string(), - suppress_unit_return: false, - }), - lambda_template: rust_lambda_template(), - error_expr_template: rust_error_expr_template(), - list_literal_empty: rust_list_literal_empty(), - list_literal_template: rust_list_literal_template(), - null_coalesce_template: rust_null_coalesce_template(), - error_type_template: rust_error_type_template(), - type_arg_open: rust_type_arg_open(), - type_arg_close: rust_type_arg_close(), - void_type: rust_void_type(), - tuple_syntax: Rc::new(TupleSyntax { - empty: rust_tuple_empty(), - pair_template: rust_tuple_pair_template(), - multi_template: rust_tuple_multi_template(), - separator: rust_tuple_separator(), - first_accessor: ".0".to_string(), - second_accessor: ".1".to_string(), - }), - string_interp: Rc::new(StringInterpSyntax { - style: Rc::new(InterpStyle::FormatArgs { - placeholder: "{}".to_string(), - }), - format_template: "format!(\"{0}\", {1})".to_string(), - plain_template: "\"{0}\".to_string()".to_string(), - escape_pairs: Rc::new(vec![ - Rc::new(EscapePair { - from: "{".to_string(), - to: "{{".to_string(), - }), - Rc::new(EscapePair { - from: "}".to_string(), - to: "}}".to_string(), - }), - ]), - }), - callable_type_template: Some("Rc {return}>".to_string()), - naming_case: NamingCase::SnakeCase, - async_call_prefix: "".to_string(), - bridge_method_prefix: "".to_string(), - bridge_method_case: NamingCase::SnakeCase, - bridge_method_overrides: v2_rt::rc_empty_map::(), - record_lit: Rc::new(RecordLitSyntax { - named_open: " {".to_string(), - named_close: "}".to_string(), - named_empty: " {}".to_string(), - named_field_sep: ": ".to_string(), - named_field_join: ", ".to_string(), - anon_empty: "{}".to_string(), - anon_prefix: "{\n".to_string(), - anon_suffix: "}".to_string(), - anon_field_indent: " ".to_string(), - }), - service_method: Rc::new(ServiceMethodStrategy::SelfInParams { - self_param: "&self".to_string(), - }), - service_return: Rc::new(ServiceReturnStrategy::ArrowReturn), - }) + target_name: "rust".to_string(), + reserved_words: Rc::new(ReservedWords { + keywords: rust_reserved(), + strategy: Rc::new(ReservedWordStrategy::PrefixEscape { + prefix: rust_reserved_escape_prefix(), +}), +}), + scaffold: Rc::new(ProjectScaffold { + manifest_file: Some("Cargo.toml".to_string()), + module_init_file: None, + source_file_extension: rust_source_extension(), + source_dir: Some(rust_source_dir()), +}), + serialization: Rc::new(SerializationSpec { + struct_derives: Some(rust_struct_derives()), + struct_derives_copy: Some(rust_struct_derives_copy()), + enum_derives: Some(rust_enum_derives()), + enum_derives_copy: Some(rust_enum_derives_copy()), + tag_attribute: Some(rust_serde_tag()), + rename_attribute_template: Some(rust_serde_rename_template()), + derive_attribute: None, + default_value: None, +}), + test_conventions: Rc::new(TestConventions { + file_prefix: "".to_string(), + file_suffix: "_test".to_string(), + file_dir: Some("tests/".to_string()), + function_prefix: "test_".to_string(), + name_style: TestNameStyle::SnakeCaseTestNames, + async_decorator: Some("#[tokio::test]".to_string()), +}), + visibility: Rc::new(VisibilitySpec::KeywordVisibility { + prefix: rust_visibility(), +}), + sharing: Rc::new(SharingStrategy { + needs_sharing: true, + wrap_template: "Rc<{0}>".to_string(), + clone_value: "{0}.clone()".to_string(), + deref_clone: "(*{0}).clone()".to_string(), + field_clone: "{0}.{1}.clone()".to_string(), + iter_owned: "{0}.iter().cloned()".to_string(), + clone_suffix: ".cloned()".to_string(), + borrow_param_template: "&{0}".to_string(), + borrow_arg_template: "&{0}".to_string(), +}), + indexing: Rc::new(IndexingSemantics { + list_index: "{0}[({1}) as usize].clone()".to_string(), + map_index: "({0}).get(&{1}).cloned()".to_string(), + string_index: "v2_rt::char_at(&{0}, {1})".to_string(), + list_slice: None, + string_slice: Some("v2_rt::substring(&{0}, {1}, {2})".to_string()), +}), + annotations: Rc::new(AnnotationRequirements { + let_binding_inferred: "let {0} = {1};".to_string(), + let_binding_annotated: "let {0}: {1} = {2};".to_string(), + lambda_param_typed: "{0}: {1}".to_string(), + lambda_param_untyped: "{0}".to_string(), +}), + method_templates: Some(rust_method_templates()), + service_fields: Rc::new(ServiceFieldTemplates { + rest_decl: " pub base_url: String,\n".to_string(), + auth_decl: " pub auth_token: String,\n".to_string(), + shell_decl: " pub working_dir: Option,\n".to_string(), + file_decl: " pub base_path: String,\n".to_string(), + rest_ctor: " base_url: \"{0}\".to_string(),\n".to_string(), + auth_ctor: " auth_token: String::new(),\n".to_string(), + shell_ctor: " working_dir: None,\n".to_string(), + file_ctor: " base_path: \".\".to_string(),\n".to_string(), +}), + block_syntax: Rc::new(BlockSyntax { + block_open: " {\n".to_string(), + block_close: "}".to_string(), + else_clause: "} else {\n".to_string(), + match_keyword: "match ".to_string(), + case_keyword: "".to_string(), + arm_separator: ",".to_string(), + stmt_terminator: ";".to_string(), + significant_whitespace: false, +}), + for_each_syntax: Rc::new(ForEachSyntax { + prefix: "for ".to_string(), + separator: " in ".to_string(), +}), + tco: Rc::new(TcoSyntax { + loop_keyword: "loop".to_string(), + break_return: "break".to_string(), + continue_str: "continue;".to_string(), + temp_var_prefix: "__tco_".to_string(), + temp_decl_prefix: "let ".to_string(), + temp_assign_op: " = ".to_string(), +}), + items: Rc::new(ItemKeywords { + func_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::FuncForm), + async_prefix: rust_async_prefix(), + struct_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::StructForm), + enum_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::EnumForm), + type_alias_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::TypeAliasForm), + param_separator: rust_param_separator(), + return_arrow: rust_return_arrow(), + param_type_sep: rust_param_type_sep(), + module_keyword: item_keyword_for_kind(rust_item_forms(), ItemFormKind::ModuleForm), + import_keyword: rust_import_keyword(), + import_from_keyword: rust_import_from_keyword(), +}), + expression_semantics: Rc::new(ExpressionSemantics { + if_value_form: IfValueForm::IfExpression, + wildcard_case: None, + variant_pattern: Some(Rc::new(VariantPatternSyntax { + open: " { ".to_string(), + close: " }".to_string(), + binding_sep: ": ".to_string(), + empty_suffix: "".to_string(), +})), + guard_prefix: Some(" if ".to_string()), + empty_return_value: "()".to_string(), + return_suffix: "".to_string(), + suppress_unit_return: false, +}), + lambda_template: rust_lambda_template(), + error_expr_template: rust_error_expr_template(), + list_literal_empty: rust_list_literal_empty(), + list_literal_template: rust_list_literal_template(), + null_coalesce_template: rust_null_coalesce_template(), + error_type_template: rust_error_type_template(), + type_arg_open: rust_type_arg_open(), + type_arg_close: rust_type_arg_close(), + void_type: rust_void_type(), + tuple_syntax: Rc::new(TupleSyntax { + empty: rust_tuple_empty(), + pair_template: rust_tuple_pair_template(), + multi_template: rust_tuple_multi_template(), + separator: rust_tuple_separator(), + first_accessor: ".0".to_string(), + second_accessor: ".1".to_string(), +}), + string_interp: Rc::new(StringInterpSyntax { + style: Rc::new(InterpStyle::FormatArgs { + placeholder: "{}".to_string(), +}), + format_template: "format!(\"{0}\", {1})".to_string(), + plain_template: "\"{0}\".to_string()".to_string(), + escape_pairs: Rc::new(vec![Rc::new(EscapePair { + from: "{".to_string(), + to: "{{".to_string(), +}), Rc::new(EscapePair { + from: "}".to_string(), + to: "}}".to_string(), +})]), +}), + callable_type_template: Some("Rc {return}>".to_string()), + naming_case: NamingCase::SnakeCase, + async_call_prefix: "".to_string(), + bridge_method_prefix: "".to_string(), + bridge_method_case: NamingCase::SnakeCase, + bridge_method_overrides: v2_rt::rc_empty_map::(), + record_lit: Rc::new(RecordLitSyntax { + named_open: " {".to_string(), + named_close: "}".to_string(), + named_empty: " {}".to_string(), + named_field_sep: ": ".to_string(), + named_field_join: ", ".to_string(), + anon_empty: "{}".to_string(), + anon_prefix: "{\n".to_string(), + anon_suffix: "}".to_string(), + anon_field_indent: " ".to_string(), +}), + service_method: Rc::new(ServiceMethodStrategy::SelfInParams { + self_param: "&self".to_string(), +}), + service_return: Rc::new(ServiceReturnStrategy::ArrowReturn), +}) } pub fn python_spec() -> Rc { Rc::new(LanguageSpec { - target_name: "python".to_string(), - reserved_words: Rc::new(ReservedWords { - keywords: python_reserved(), - strategy: Rc::new(ReservedWordStrategy::SuffixEscape { - suffix: python_reserved_escape_suffix(), - }), - }), - scaffold: Rc::new(ProjectScaffold { - manifest_file: Some("requirements.txt".to_string()), - module_init_file: Some(python_module_init()), - source_file_extension: python_source_extension(), - source_dir: None, - }), - serialization: Rc::new(SerializationSpec { - struct_derives: None, - struct_derives_copy: None, - enum_derives: None, - enum_derives_copy: None, - tag_attribute: None, - rename_attribute_template: None, - derive_attribute: Some(python_derive_attribute()), - default_value: Some(python_default_value()), - }), - test_conventions: Rc::new(TestConventions { - file_prefix: "test_".to_string(), - file_suffix: "".to_string(), - file_dir: Some("tests/".to_string()), - function_prefix: "test_".to_string(), - name_style: TestNameStyle::SnakeCaseTestNames, - async_decorator: None, - }), - visibility: Rc::new(VisibilitySpec::KeywordVisibility { - prefix: "".to_string(), - }), - sharing: Rc::new(SharingStrategy { - needs_sharing: false, - wrap_template: "{0}".to_string(), - clone_value: "{0}".to_string(), - deref_clone: "{0}".to_string(), - field_clone: "{0}.{1}".to_string(), - iter_owned: "{0}".to_string(), - clone_suffix: "".to_string(), - borrow_param_template: "{0}".to_string(), - borrow_arg_template: "{0}".to_string(), - }), - indexing: Rc::new(IndexingSemantics { - list_index: "{0}[{1}]".to_string(), - map_index: "{0}[{1}]".to_string(), - string_index: "{0}[{1}]".to_string(), - list_slice: Some("{0}[{1}:{2}]".to_string()), - string_slice: Some("{0}[{1}:{2}]".to_string()), - }), - annotations: Rc::new(AnnotationRequirements { - let_binding_inferred: "{0} = {1}".to_string(), - let_binding_annotated: "{0}: {1} = {2}".to_string(), - lambda_param_typed: "{0}: {1}".to_string(), - lambda_param_untyped: "{0}".to_string(), - }), - method_templates: Some(python_method_templates()), - service_fields: Rc::new(ServiceFieldTemplates { - rest_decl: "base_url: str".to_string(), - auth_decl: "auth_token: str".to_string(), - shell_decl: "working_dir: str | None = None".to_string(), - file_decl: "base_path: str".to_string(), - rest_ctor: "self.base_url = base_url".to_string(), - auth_ctor: "self.auth_token = auth_token".to_string(), - shell_ctor: "self.working_dir = working_dir".to_string(), - file_ctor: "self.base_path = base_path".to_string(), - }), - block_syntax: Rc::new(BlockSyntax { - block_open: ":\n".to_string(), - block_close: "".to_string(), - else_clause: "else:\n".to_string(), - match_keyword: "match ".to_string(), - case_keyword: "case ".to_string(), - arm_separator: "\n".to_string(), - stmt_terminator: "".to_string(), - significant_whitespace: true, - }), - for_each_syntax: Rc::new(ForEachSyntax { - prefix: "for ".to_string(), - separator: " in ".to_string(), - }), - tco: Rc::new(TcoSyntax { - loop_keyword: "while True".to_string(), - break_return: "return".to_string(), - continue_str: "continue".to_string(), - temp_var_prefix: "__tco_".to_string(), - temp_decl_prefix: "".to_string(), - temp_assign_op: " = ".to_string(), - }), - items: Rc::new(ItemKeywords { - func_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::FuncForm), - async_prefix: python_async_prefix(), - struct_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::StructForm), - enum_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::EnumForm), - type_alias_keyword: item_keyword_for_kind( - python_item_forms(), - ItemFormKind::TypeAliasForm, - ), - param_separator: python_param_separator(), - return_arrow: python_return_arrow(), - param_type_sep: python_param_type_sep(), - module_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::ModuleForm), - import_keyword: python_import_keyword(), - import_from_keyword: python_import_from_keyword(), - }), - expression_semantics: Rc::new(ExpressionSemantics { - if_value_form: IfValueForm::ConditionalTernary, - wildcard_case: None, - variant_pattern: Some(Rc::new(VariantPatternSyntax { - open: "(".to_string(), - close: ")".to_string(), - binding_sep: "=".to_string(), - empty_suffix: "()".to_string(), - })), - guard_prefix: Some(" if ".to_string()), - empty_return_value: "None".to_string(), - return_suffix: "".to_string(), - suppress_unit_return: false, - }), - lambda_template: python_lambda_template(), - error_expr_template: python_error_expr_template(), - list_literal_empty: python_list_literal_empty(), - list_literal_template: python_list_literal_template(), - null_coalesce_template: python_null_coalesce_template(), - error_type_template: python_error_type_template(), - type_arg_open: python_type_arg_open(), - type_arg_close: python_type_arg_close(), - void_type: python_void_type(), - tuple_syntax: Rc::new(TupleSyntax { - empty: python_tuple_empty(), - pair_template: python_tuple_pair_template(), - multi_template: python_tuple_multi_template(), - separator: python_tuple_separator(), - first_accessor: "[0]".to_string(), - second_accessor: "[1]".to_string(), - }), - string_interp: Rc::new(StringInterpSyntax { - style: Rc::new(InterpStyle::InlineExpr), - format_template: "f\"{0}\"".to_string(), - plain_template: "f\"{0}\"".to_string(), - escape_pairs: Rc::new(vec![ - Rc::new(EscapePair { - from: "{".to_string(), - to: "{{".to_string(), - }), - Rc::new(EscapePair { - from: "}".to_string(), - to: "}}".to_string(), - }), - ]), - }), - callable_type_template: None, - naming_case: NamingCase::SnakeCase, - async_call_prefix: "await ".to_string(), - bridge_method_prefix: "".to_string(), - bridge_method_case: NamingCase::SnakeCase, - bridge_method_overrides: v2_rt::rc_map_insert( - v2_rt::rc_empty_map::(), - "with".to_string(), - "with_update".to_string(), - ), - record_lit: Rc::new(RecordLitSyntax { - named_open: "(".to_string(), - named_close: ")".to_string(), - named_empty: "()".to_string(), - named_field_sep: "=".to_string(), - named_field_join: ", ".to_string(), - anon_empty: "{}".to_string(), - anon_prefix: "{\n".to_string(), - anon_suffix: "}".to_string(), - anon_field_indent: " ".to_string(), - }), - service_method: Rc::new(ServiceMethodStrategy::SelfInParams { - self_param: "self".to_string(), - }), - service_return: Rc::new(ServiceReturnStrategy::ArrowReturn), - }) + target_name: "python".to_string(), + reserved_words: Rc::new(ReservedWords { + keywords: python_reserved(), + strategy: Rc::new(ReservedWordStrategy::SuffixEscape { + suffix: python_reserved_escape_suffix(), +}), +}), + scaffold: Rc::new(ProjectScaffold { + manifest_file: Some("requirements.txt".to_string()), + module_init_file: Some(python_module_init()), + source_file_extension: python_source_extension(), + source_dir: None, +}), + serialization: Rc::new(SerializationSpec { + struct_derives: None, + struct_derives_copy: None, + enum_derives: None, + enum_derives_copy: None, + tag_attribute: None, + rename_attribute_template: None, + derive_attribute: Some(python_derive_attribute()), + default_value: Some(python_default_value()), +}), + test_conventions: Rc::new(TestConventions { + file_prefix: "test_".to_string(), + file_suffix: "".to_string(), + file_dir: Some("tests/".to_string()), + function_prefix: "test_".to_string(), + name_style: TestNameStyle::SnakeCaseTestNames, + async_decorator: None, +}), + visibility: Rc::new(VisibilitySpec::KeywordVisibility { + prefix: "".to_string(), +}), + sharing: Rc::new(SharingStrategy { + needs_sharing: false, + wrap_template: "{0}".to_string(), + clone_value: "{0}".to_string(), + deref_clone: "{0}".to_string(), + field_clone: "{0}.{1}".to_string(), + iter_owned: "{0}".to_string(), + clone_suffix: "".to_string(), + borrow_param_template: "{0}".to_string(), + borrow_arg_template: "{0}".to_string(), +}), + indexing: Rc::new(IndexingSemantics { + list_index: "{0}[{1}]".to_string(), + map_index: "{0}[{1}]".to_string(), + string_index: "{0}[{1}]".to_string(), + list_slice: Some("{0}[{1}:{2}]".to_string()), + string_slice: Some("{0}[{1}:{2}]".to_string()), +}), + annotations: Rc::new(AnnotationRequirements { + let_binding_inferred: "{0} = {1}".to_string(), + let_binding_annotated: "{0}: {1} = {2}".to_string(), + lambda_param_typed: "{0}: {1}".to_string(), + lambda_param_untyped: "{0}".to_string(), +}), + method_templates: Some(python_method_templates()), + service_fields: Rc::new(ServiceFieldTemplates { + rest_decl: "base_url: str".to_string(), + auth_decl: "auth_token: str".to_string(), + shell_decl: "working_dir: str | None = None".to_string(), + file_decl: "base_path: str".to_string(), + rest_ctor: "self.base_url = base_url".to_string(), + auth_ctor: "self.auth_token = auth_token".to_string(), + shell_ctor: "self.working_dir = working_dir".to_string(), + file_ctor: "self.base_path = base_path".to_string(), +}), + block_syntax: Rc::new(BlockSyntax { + block_open: ":\n".to_string(), + block_close: "".to_string(), + else_clause: "else:\n".to_string(), + match_keyword: "match ".to_string(), + case_keyword: "case ".to_string(), + arm_separator: "\n".to_string(), + stmt_terminator: "".to_string(), + significant_whitespace: true, +}), + for_each_syntax: Rc::new(ForEachSyntax { + prefix: "for ".to_string(), + separator: " in ".to_string(), +}), + tco: Rc::new(TcoSyntax { + loop_keyword: "while True".to_string(), + break_return: "return".to_string(), + continue_str: "continue".to_string(), + temp_var_prefix: "__tco_".to_string(), + temp_decl_prefix: "".to_string(), + temp_assign_op: " = ".to_string(), +}), + items: Rc::new(ItemKeywords { + func_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::FuncForm), + async_prefix: python_async_prefix(), + struct_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::StructForm), + enum_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::EnumForm), + type_alias_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::TypeAliasForm), + param_separator: python_param_separator(), + return_arrow: python_return_arrow(), + param_type_sep: python_param_type_sep(), + module_keyword: item_keyword_for_kind(python_item_forms(), ItemFormKind::ModuleForm), + import_keyword: python_import_keyword(), + import_from_keyword: python_import_from_keyword(), +}), + expression_semantics: Rc::new(ExpressionSemantics { + if_value_form: IfValueForm::ConditionalTernary, + wildcard_case: None, + variant_pattern: Some(Rc::new(VariantPatternSyntax { + open: "(".to_string(), + close: ")".to_string(), + binding_sep: "=".to_string(), + empty_suffix: "()".to_string(), +})), + guard_prefix: Some(" if ".to_string()), + empty_return_value: "None".to_string(), + return_suffix: "".to_string(), + suppress_unit_return: false, +}), + lambda_template: python_lambda_template(), + error_expr_template: python_error_expr_template(), + list_literal_empty: python_list_literal_empty(), + list_literal_template: python_list_literal_template(), + null_coalesce_template: python_null_coalesce_template(), + error_type_template: python_error_type_template(), + type_arg_open: python_type_arg_open(), + type_arg_close: python_type_arg_close(), + void_type: python_void_type(), + tuple_syntax: Rc::new(TupleSyntax { + empty: python_tuple_empty(), + pair_template: python_tuple_pair_template(), + multi_template: python_tuple_multi_template(), + separator: python_tuple_separator(), + first_accessor: "[0]".to_string(), + second_accessor: "[1]".to_string(), +}), + string_interp: Rc::new(StringInterpSyntax { + style: Rc::new(InterpStyle::InlineExpr), + format_template: "f\"{0}\"".to_string(), + plain_template: "f\"{0}\"".to_string(), + escape_pairs: Rc::new(vec![Rc::new(EscapePair { + from: "{".to_string(), + to: "{{".to_string(), +}), Rc::new(EscapePair { + from: "}".to_string(), + to: "}}".to_string(), +})]), +}), + callable_type_template: None, + naming_case: NamingCase::SnakeCase, + async_call_prefix: "await ".to_string(), + bridge_method_prefix: "".to_string(), + bridge_method_case: NamingCase::SnakeCase, + bridge_method_overrides: v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), "with".to_string(), "with_update".to_string()), + record_lit: Rc::new(RecordLitSyntax { + named_open: "(".to_string(), + named_close: ")".to_string(), + named_empty: "()".to_string(), + named_field_sep: "=".to_string(), + named_field_join: ", ".to_string(), + anon_empty: "{}".to_string(), + anon_prefix: "{\n".to_string(), + anon_suffix: "}".to_string(), + anon_field_indent: " ".to_string(), +}), + service_method: Rc::new(ServiceMethodStrategy::SelfInParams { + self_param: "self".to_string(), +}), + service_return: Rc::new(ServiceReturnStrategy::ArrowReturn), +}) } pub fn go_spec() -> Rc { Rc::new(LanguageSpec { - target_name: "go".to_string(), - reserved_words: Rc::new(ReservedWords { - keywords: go_reserved(), - strategy: Rc::new(ReservedWordStrategy::SuffixEscape { - suffix: go_reserved_escape_suffix(), - }), - }), - scaffold: Rc::new(ProjectScaffold { - manifest_file: Some("go.mod".to_string()), - module_init_file: None, - source_file_extension: ".go".to_string(), - source_dir: None, - }), - serialization: Rc::new(SerializationSpec { - struct_derives: None, - struct_derives_copy: None, - enum_derives: None, - enum_derives_copy: None, - tag_attribute: None, - rename_attribute_template: None, - derive_attribute: None, - default_value: None, - }), - test_conventions: Rc::new(TestConventions { - file_prefix: "".to_string(), - file_suffix: "_test".to_string(), - file_dir: None, - function_prefix: "Test".to_string(), - name_style: TestNameStyle::PascalCaseTestNames, - async_decorator: None, - }), - visibility: Rc::new(VisibilitySpec::CaseVisibility { - export_case: NamingCase::PascalCase, - }), - sharing: Rc::new(SharingStrategy { - needs_sharing: false, - wrap_template: "{0}".to_string(), - clone_value: "{0}".to_string(), - deref_clone: "{0}".to_string(), - field_clone: "{0}.{1}".to_string(), - iter_owned: "{0}".to_string(), - clone_suffix: "".to_string(), - borrow_param_template: "{0}".to_string(), - borrow_arg_template: "{0}".to_string(), - }), - indexing: Rc::new(IndexingSemantics { - list_index: "{0}[{1}]".to_string(), - map_index: "{0}[{1}]".to_string(), - string_index: "{0}[{1}]".to_string(), - list_slice: Some("{0}[{1}:{2}]".to_string()), - string_slice: Some("{0}[{1}:{2}]".to_string()), - }), - annotations: Rc::new(AnnotationRequirements { - let_binding_inferred: "{0} := {1}".to_string(), - let_binding_annotated: "var {0} {1} = {2}".to_string(), - lambda_param_typed: "{0} {1}".to_string(), - lambda_param_untyped: "{0} interface{}".to_string(), - }), - method_templates: Some(go_method_templates()), - service_fields: Rc::new(ServiceFieldTemplates { - rest_decl: "\tBaseURL string".to_string(), - auth_decl: "\tAuthToken string".to_string(), - shell_decl: "\tWorkingDir string".to_string(), - file_decl: "\tBasePath string".to_string(), - rest_ctor: "".to_string(), - auth_ctor: "".to_string(), - shell_ctor: "".to_string(), - file_ctor: "".to_string(), - }), - block_syntax: Rc::new(BlockSyntax { - block_open: " {\n".to_string(), - block_close: "}".to_string(), - else_clause: "} else {\n".to_string(), - match_keyword: "switch ".to_string(), - case_keyword: "case ".to_string(), - arm_separator: "\n".to_string(), - stmt_terminator: "".to_string(), - significant_whitespace: false, - }), - for_each_syntax: Rc::new(ForEachSyntax { - prefix: "for _, ".to_string(), - separator: " := range ".to_string(), - }), - tco: Rc::new(TcoSyntax { - loop_keyword: "for".to_string(), - break_return: "return".to_string(), - continue_str: "continue".to_string(), - temp_var_prefix: "tco".to_string(), - temp_decl_prefix: "".to_string(), - temp_assign_op: " := ".to_string(), - }), - items: Rc::new(ItemKeywords { - func_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::FuncForm), - async_prefix: go_async_prefix(), - struct_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::StructForm), - enum_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::EnumForm), - type_alias_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::TypeAliasForm), - param_separator: go_param_separator(), - return_arrow: go_return_arrow(), - param_type_sep: go_param_type_sep(), - module_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::ModuleForm), - import_keyword: go_import_keyword(), - import_from_keyword: go_import_from_keyword(), - }), - expression_semantics: Rc::new(ExpressionSemantics { - if_value_form: IfValueForm::IfStatement, - wildcard_case: Some("default".to_string()), - variant_pattern: None, - guard_prefix: None, - empty_return_value: "struct{}{}, nil".to_string(), - return_suffix: ", nil".to_string(), - suppress_unit_return: true, - }), - lambda_template: go_lambda_template(), - error_expr_template: go_error_expr_template(), - list_literal_empty: go_list_literal_empty(), - list_literal_template: go_list_literal_template(), - null_coalesce_template: go_null_coalesce_template(), - error_type_template: go_error_type_template(), - type_arg_open: go_type_arg_open(), - type_arg_close: go_type_arg_close(), - void_type: go_void_type(), - tuple_syntax: Rc::new(TupleSyntax { - empty: go_tuple_empty(), - pair_template: go_tuple_pair_template(), - multi_template: go_tuple_multi_template(), - separator: go_tuple_separator(), - first_accessor: ".First".to_string(), - second_accessor: ".Second".to_string(), - }), - string_interp: Rc::new(StringInterpSyntax { - style: Rc::new(InterpStyle::FormatArgs { - placeholder: "%v".to_string(), - }), - format_template: "fmt.Sprintf(\"{0}\", {1})".to_string(), - plain_template: "\"{0}\"".to_string(), - escape_pairs: Rc::new(vec![Rc::new(EscapePair { - from: "%".to_string(), - to: "%%".to_string(), - })]), - }), - callable_type_template: None, - naming_case: NamingCase::CamelCase, - async_call_prefix: "".to_string(), - bridge_method_prefix: "v2rt.".to_string(), - bridge_method_case: NamingCase::PascalCase, - bridge_method_overrides: v2_rt::rc_empty_map::(), - record_lit: Rc::new(RecordLitSyntax { - named_open: "{".to_string(), - named_close: "}".to_string(), - named_empty: "{}".to_string(), - named_field_sep: ": ".to_string(), - named_field_join: ", ".to_string(), - anon_empty: "map[string]interface{}{}".to_string(), - anon_prefix: "map[string]interface{}{\n".to_string(), - anon_suffix: "}".to_string(), - anon_field_indent: "\t".to_string(), - }), - service_method: Rc::new(ServiceMethodStrategy::ExternalReceiver { - var_name: "c".to_string(), - }), - service_return: Rc::new(ServiceReturnStrategy::ErrorTupleReturn { - error_type: "error".to_string(), - }), - }) + target_name: "go".to_string(), + reserved_words: Rc::new(ReservedWords { + keywords: go_reserved(), + strategy: Rc::new(ReservedWordStrategy::SuffixEscape { + suffix: go_reserved_escape_suffix(), +}), +}), + scaffold: Rc::new(ProjectScaffold { + manifest_file: Some("go.mod".to_string()), + module_init_file: None, + source_file_extension: ".go".to_string(), + source_dir: None, +}), + serialization: Rc::new(SerializationSpec { + struct_derives: None, + struct_derives_copy: None, + enum_derives: None, + enum_derives_copy: None, + tag_attribute: None, + rename_attribute_template: None, + derive_attribute: None, + default_value: None, +}), + test_conventions: Rc::new(TestConventions { + file_prefix: "".to_string(), + file_suffix: "_test".to_string(), + file_dir: None, + function_prefix: "Test".to_string(), + name_style: TestNameStyle::PascalCaseTestNames, + async_decorator: None, +}), + visibility: Rc::new(VisibilitySpec::CaseVisibility { + export_case: NamingCase::PascalCase, +}), + sharing: Rc::new(SharingStrategy { + needs_sharing: false, + wrap_template: "{0}".to_string(), + clone_value: "{0}".to_string(), + deref_clone: "{0}".to_string(), + field_clone: "{0}.{1}".to_string(), + iter_owned: "{0}".to_string(), + clone_suffix: "".to_string(), + borrow_param_template: "{0}".to_string(), + borrow_arg_template: "{0}".to_string(), +}), + indexing: Rc::new(IndexingSemantics { + list_index: "{0}[{1}]".to_string(), + map_index: "{0}[{1}]".to_string(), + string_index: "{0}[{1}]".to_string(), + list_slice: Some("{0}[{1}:{2}]".to_string()), + string_slice: Some("{0}[{1}:{2}]".to_string()), +}), + annotations: Rc::new(AnnotationRequirements { + let_binding_inferred: "{0} := {1}".to_string(), + let_binding_annotated: "var {0} {1} = {2}".to_string(), + lambda_param_typed: "{0} {1}".to_string(), + lambda_param_untyped: "{0} interface{}".to_string(), +}), + method_templates: Some(go_method_templates()), + service_fields: Rc::new(ServiceFieldTemplates { + rest_decl: "\tBaseURL string".to_string(), + auth_decl: "\tAuthToken string".to_string(), + shell_decl: "\tWorkingDir string".to_string(), + file_decl: "\tBasePath string".to_string(), + rest_ctor: "".to_string(), + auth_ctor: "".to_string(), + shell_ctor: "".to_string(), + file_ctor: "".to_string(), +}), + block_syntax: Rc::new(BlockSyntax { + block_open: " {\n".to_string(), + block_close: "}".to_string(), + else_clause: "} else {\n".to_string(), + match_keyword: "switch ".to_string(), + case_keyword: "case ".to_string(), + arm_separator: "\n".to_string(), + stmt_terminator: "".to_string(), + significant_whitespace: false, +}), + for_each_syntax: Rc::new(ForEachSyntax { + prefix: "for _, ".to_string(), + separator: " := range ".to_string(), +}), + tco: Rc::new(TcoSyntax { + loop_keyword: "for".to_string(), + break_return: "return".to_string(), + continue_str: "continue".to_string(), + temp_var_prefix: "tco".to_string(), + temp_decl_prefix: "".to_string(), + temp_assign_op: " := ".to_string(), +}), + items: Rc::new(ItemKeywords { + func_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::FuncForm), + async_prefix: go_async_prefix(), + struct_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::StructForm), + enum_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::EnumForm), + type_alias_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::TypeAliasForm), + param_separator: go_param_separator(), + return_arrow: go_return_arrow(), + param_type_sep: go_param_type_sep(), + module_keyword: item_keyword_for_kind(go_item_forms(), ItemFormKind::ModuleForm), + import_keyword: go_import_keyword(), + import_from_keyword: go_import_from_keyword(), +}), + expression_semantics: Rc::new(ExpressionSemantics { + if_value_form: IfValueForm::IfStatement, + wildcard_case: Some("default".to_string()), + variant_pattern: None, + guard_prefix: None, + empty_return_value: "struct{}{}, nil".to_string(), + return_suffix: ", nil".to_string(), + suppress_unit_return: true, +}), + lambda_template: go_lambda_template(), + error_expr_template: go_error_expr_template(), + list_literal_empty: go_list_literal_empty(), + list_literal_template: go_list_literal_template(), + null_coalesce_template: go_null_coalesce_template(), + error_type_template: go_error_type_template(), + type_arg_open: go_type_arg_open(), + type_arg_close: go_type_arg_close(), + void_type: go_void_type(), + tuple_syntax: Rc::new(TupleSyntax { + empty: go_tuple_empty(), + pair_template: go_tuple_pair_template(), + multi_template: go_tuple_multi_template(), + separator: go_tuple_separator(), + first_accessor: ".First".to_string(), + second_accessor: ".Second".to_string(), +}), + string_interp: Rc::new(StringInterpSyntax { + style: Rc::new(InterpStyle::FormatArgs { + placeholder: "%v".to_string(), +}), + format_template: "fmt.Sprintf(\"{0}\", {1})".to_string(), + plain_template: "\"{0}\"".to_string(), + escape_pairs: Rc::new(vec![Rc::new(EscapePair { + from: "%".to_string(), + to: "%%".to_string(), +})]), +}), + callable_type_template: None, + naming_case: NamingCase::CamelCase, + async_call_prefix: "".to_string(), + bridge_method_prefix: "v2rt.".to_string(), + bridge_method_case: NamingCase::PascalCase, + bridge_method_overrides: v2_rt::rc_empty_map::(), + record_lit: Rc::new(RecordLitSyntax { + named_open: "{".to_string(), + named_close: "}".to_string(), + named_empty: "{}".to_string(), + named_field_sep: ": ".to_string(), + named_field_join: ", ".to_string(), + anon_empty: "map[string]interface{}{}".to_string(), + anon_prefix: "map[string]interface{}{\n".to_string(), + anon_suffix: "}".to_string(), + anon_field_indent: "\t".to_string(), +}), + service_method: Rc::new(ServiceMethodStrategy::ExternalReceiver { + var_name: "c".to_string(), +}), + service_return: Rc::new(ServiceReturnStrategy::ErrorTupleReturn { + error_type: "error".to_string(), +}), +}) } pub fn dag_spec() -> Rc { Rc::new(LanguageSpec { - target_name: "dag".to_string(), - reserved_words: Rc::new(ReservedWords { - keywords: dag_reserved(), - strategy: Rc::new(ReservedWordStrategy::NoEscape), - }), - scaffold: Rc::new(ProjectScaffold { - manifest_file: None, - module_init_file: None, - source_file_extension: dag_source_extension(), - source_dir: None, - }), - serialization: Rc::new(SerializationSpec { - struct_derives: None, - struct_derives_copy: None, - enum_derives: None, - enum_derives_copy: None, - tag_attribute: None, - rename_attribute_template: None, - derive_attribute: None, - default_value: None, - }), - test_conventions: Rc::new(TestConventions { - file_prefix: "test_".to_string(), - file_suffix: "".to_string(), - file_dir: Some("tests/".to_string()), - function_prefix: "test_".to_string(), - name_style: TestNameStyle::SnakeCaseTestNames, - async_decorator: None, - }), - visibility: Rc::new(VisibilitySpec::KeywordVisibility { - prefix: "".to_string(), - }), - sharing: Rc::new(SharingStrategy { - needs_sharing: true, - wrap_template: "Rc<{0}>".to_string(), - clone_value: "{0}.clone()".to_string(), - deref_clone: "(*{0}).clone()".to_string(), - field_clone: "{0}.{1}.clone()".to_string(), - iter_owned: "{0}.iter().cloned()".to_string(), - clone_suffix: ".cloned()".to_string(), - borrow_param_template: "&{0}".to_string(), - borrow_arg_template: "&{0}".to_string(), - }), - indexing: Rc::new(IndexingSemantics { - list_index: "{0}[({1}) as usize].clone()".to_string(), - map_index: "({0}).get(&{1}).cloned()".to_string(), - string_index: "v2_rt::char_at(&{0}, {1})".to_string(), - list_slice: None, - string_slice: Some("v2_rt::substring(&{0}, {1}, {2})".to_string()), - }), - annotations: Rc::new(AnnotationRequirements { - let_binding_inferred: "let {0} = {1}".to_string(), - let_binding_annotated: "let {0}: {1} = {2}".to_string(), - lambda_param_typed: "{0}: {1}".to_string(), - lambda_param_untyped: "{0}".to_string(), - }), - method_templates: Some(rust_method_templates()), - service_fields: Rc::new(ServiceFieldTemplates { - rest_decl: " pub base_url: String,\n".to_string(), - auth_decl: " pub auth_token: String,\n".to_string(), - shell_decl: " pub working_dir: Option,\n".to_string(), - file_decl: " pub base_path: String,\n".to_string(), - rest_ctor: " base_url: \"{0}\".to_string(),\n".to_string(), - auth_ctor: " auth_token: String::new(),\n".to_string(), - shell_ctor: " working_dir: None,\n".to_string(), - file_ctor: " base_path: \".\".to_string(),\n".to_string(), - }), - block_syntax: Rc::new(BlockSyntax { - block_open: " {\n".to_string(), - block_close: "}".to_string(), - else_clause: "} else {\n".to_string(), - match_keyword: "match ".to_string(), - case_keyword: "".to_string(), - arm_separator: ",".to_string(), - stmt_terminator: ";".to_string(), - significant_whitespace: false, - }), - for_each_syntax: Rc::new(ForEachSyntax { - prefix: "for ".to_string(), - separator: " in ".to_string(), - }), - tco: Rc::new(TcoSyntax { - loop_keyword: "loop".to_string(), - break_return: "break".to_string(), - continue_str: "continue;".to_string(), - temp_var_prefix: "__tco_".to_string(), - temp_decl_prefix: "let ".to_string(), - temp_assign_op: " = ".to_string(), - }), - items: Rc::new(ItemKeywords { - func_keyword: dag_func_keyword(), - async_prefix: dag_async_prefix(), - struct_keyword: dag_struct_keyword(), - enum_keyword: dag_enum_keyword(), - type_alias_keyword: dag_type_alias_keyword(), - param_separator: dag_param_separator(), - return_arrow: dag_return_arrow(), - param_type_sep: dag_param_type_sep(), - module_keyword: dag_module_keyword(), - import_keyword: dag_import_keyword(), - import_from_keyword: dag_import_from_keyword(), - }), - expression_semantics: Rc::new(ExpressionSemantics { - if_value_form: IfValueForm::IfExpression, - wildcard_case: None, - variant_pattern: Some(Rc::new(VariantPatternSyntax { - open: " { ".to_string(), - close: " }".to_string(), - binding_sep: ": ".to_string(), - empty_suffix: "".to_string(), - })), - guard_prefix: Some(" if ".to_string()), - empty_return_value: "()".to_string(), - return_suffix: "".to_string(), - suppress_unit_return: false, - }), - lambda_template: dag_lambda_template(), - error_expr_template: dag_error_expr_template(), - list_literal_empty: dag_list_literal_empty(), - list_literal_template: dag_list_literal_template(), - null_coalesce_template: dag_null_coalesce_template(), - error_type_template: dag_error_type_template(), - type_arg_open: dag_type_arg_open(), - type_arg_close: dag_type_arg_close(), - void_type: dag_void_type(), - tuple_syntax: Rc::new(TupleSyntax { - empty: dag_tuple_empty(), - pair_template: dag_tuple_pair_template(), - multi_template: dag_tuple_multi_template(), - separator: dag_tuple_separator(), - first_accessor: ".0".to_string(), - second_accessor: ".1".to_string(), - }), - string_interp: Rc::new(StringInterpSyntax { - style: Rc::new(InterpStyle::InlineExpr), - format_template: "\"{0}\"".to_string(), - plain_template: "\"{0}\"".to_string(), - escape_pairs: Rc::new(vec![ - Rc::new(EscapePair { - from: "{".to_string(), - to: "\\{".to_string(), - }), - Rc::new(EscapePair { - from: "}".to_string(), - to: "\\}".to_string(), - }), - ]), - }), - callable_type_template: None, - naming_case: NamingCase::AsAuthored, - async_call_prefix: "".to_string(), - bridge_method_prefix: "".to_string(), - bridge_method_case: NamingCase::SnakeCase, - bridge_method_overrides: v2_rt::rc_empty_map::(), - record_lit: Rc::new(RecordLitSyntax { - named_open: " {".to_string(), - named_close: "}".to_string(), - named_empty: " {}".to_string(), - named_field_sep: ": ".to_string(), - named_field_join: ", ".to_string(), - anon_empty: "{}".to_string(), - anon_prefix: "{\n".to_string(), - anon_suffix: "}".to_string(), - anon_field_indent: " ".to_string(), - }), - service_method: Rc::new(ServiceMethodStrategy::SelfInParams { - self_param: "".to_string(), - }), - service_return: Rc::new(ServiceReturnStrategy::ArrowReturn), - }) + target_name: "dag".to_string(), + reserved_words: Rc::new(ReservedWords { + keywords: dag_reserved(), + strategy: Rc::new(ReservedWordStrategy::NoEscape), +}), + scaffold: Rc::new(ProjectScaffold { + manifest_file: None, + module_init_file: None, + source_file_extension: dag_source_extension(), + source_dir: None, +}), + serialization: Rc::new(SerializationSpec { + struct_derives: None, + struct_derives_copy: None, + enum_derives: None, + enum_derives_copy: None, + tag_attribute: None, + rename_attribute_template: None, + derive_attribute: None, + default_value: None, +}), + test_conventions: Rc::new(TestConventions { + file_prefix: "test_".to_string(), + file_suffix: "".to_string(), + file_dir: Some("tests/".to_string()), + function_prefix: "test_".to_string(), + name_style: TestNameStyle::SnakeCaseTestNames, + async_decorator: None, +}), + visibility: Rc::new(VisibilitySpec::KeywordVisibility { + prefix: "".to_string(), +}), + sharing: Rc::new(SharingStrategy { + needs_sharing: true, + wrap_template: "Rc<{0}>".to_string(), + clone_value: "{0}.clone()".to_string(), + deref_clone: "(*{0}).clone()".to_string(), + field_clone: "{0}.{1}.clone()".to_string(), + iter_owned: "{0}.iter().cloned()".to_string(), + clone_suffix: ".cloned()".to_string(), + borrow_param_template: "&{0}".to_string(), + borrow_arg_template: "&{0}".to_string(), +}), + indexing: Rc::new(IndexingSemantics { + list_index: "{0}[({1}) as usize].clone()".to_string(), + map_index: "({0}).get(&{1}).cloned()".to_string(), + string_index: "v2_rt::char_at(&{0}, {1})".to_string(), + list_slice: None, + string_slice: Some("v2_rt::substring(&{0}, {1}, {2})".to_string()), +}), + annotations: Rc::new(AnnotationRequirements { + let_binding_inferred: "let {0} = {1}".to_string(), + let_binding_annotated: "let {0}: {1} = {2}".to_string(), + lambda_param_typed: "{0}: {1}".to_string(), + lambda_param_untyped: "{0}".to_string(), +}), + method_templates: Some(rust_method_templates()), + service_fields: Rc::new(ServiceFieldTemplates { + rest_decl: " pub base_url: String,\n".to_string(), + auth_decl: " pub auth_token: String,\n".to_string(), + shell_decl: " pub working_dir: Option,\n".to_string(), + file_decl: " pub base_path: String,\n".to_string(), + rest_ctor: " base_url: \"{0}\".to_string(),\n".to_string(), + auth_ctor: " auth_token: String::new(),\n".to_string(), + shell_ctor: " working_dir: None,\n".to_string(), + file_ctor: " base_path: \".\".to_string(),\n".to_string(), +}), + block_syntax: Rc::new(BlockSyntax { + block_open: " {\n".to_string(), + block_close: "}".to_string(), + else_clause: "} else {\n".to_string(), + match_keyword: "match ".to_string(), + case_keyword: "".to_string(), + arm_separator: ",".to_string(), + stmt_terminator: ";".to_string(), + significant_whitespace: false, +}), + for_each_syntax: Rc::new(ForEachSyntax { + prefix: "for ".to_string(), + separator: " in ".to_string(), +}), + tco: Rc::new(TcoSyntax { + loop_keyword: "loop".to_string(), + break_return: "break".to_string(), + continue_str: "continue;".to_string(), + temp_var_prefix: "__tco_".to_string(), + temp_decl_prefix: "let ".to_string(), + temp_assign_op: " = ".to_string(), +}), + items: Rc::new(ItemKeywords { + func_keyword: dag_func_keyword(), + async_prefix: dag_async_prefix(), + struct_keyword: dag_struct_keyword(), + enum_keyword: dag_enum_keyword(), + type_alias_keyword: dag_type_alias_keyword(), + param_separator: dag_param_separator(), + return_arrow: dag_return_arrow(), + param_type_sep: dag_param_type_sep(), + module_keyword: dag_module_keyword(), + import_keyword: dag_import_keyword(), + import_from_keyword: dag_import_from_keyword(), +}), + expression_semantics: Rc::new(ExpressionSemantics { + if_value_form: IfValueForm::IfExpression, + wildcard_case: None, + variant_pattern: Some(Rc::new(VariantPatternSyntax { + open: " { ".to_string(), + close: " }".to_string(), + binding_sep: ": ".to_string(), + empty_suffix: "".to_string(), +})), + guard_prefix: Some(" if ".to_string()), + empty_return_value: "()".to_string(), + return_suffix: "".to_string(), + suppress_unit_return: false, +}), + lambda_template: dag_lambda_template(), + error_expr_template: dag_error_expr_template(), + list_literal_empty: dag_list_literal_empty(), + list_literal_template: dag_list_literal_template(), + null_coalesce_template: dag_null_coalesce_template(), + error_type_template: dag_error_type_template(), + type_arg_open: dag_type_arg_open(), + type_arg_close: dag_type_arg_close(), + void_type: dag_void_type(), + tuple_syntax: Rc::new(TupleSyntax { + empty: dag_tuple_empty(), + pair_template: dag_tuple_pair_template(), + multi_template: dag_tuple_multi_template(), + separator: dag_tuple_separator(), + first_accessor: ".0".to_string(), + second_accessor: ".1".to_string(), +}), + string_interp: Rc::new(StringInterpSyntax { + style: Rc::new(InterpStyle::InlineExpr), + format_template: "\"{0}\"".to_string(), + plain_template: "\"{0}\"".to_string(), + escape_pairs: Rc::new(vec![Rc::new(EscapePair { + from: "{".to_string(), + to: "\\{".to_string(), +}), Rc::new(EscapePair { + from: "}".to_string(), + to: "\\}".to_string(), +})]), +}), + callable_type_template: None, + naming_case: NamingCase::AsAuthored, + async_call_prefix: "".to_string(), + bridge_method_prefix: "".to_string(), + bridge_method_case: NamingCase::SnakeCase, + bridge_method_overrides: v2_rt::rc_empty_map::(), + record_lit: Rc::new(RecordLitSyntax { + named_open: " {".to_string(), + named_close: "}".to_string(), + named_empty: " {}".to_string(), + named_field_sep: ": ".to_string(), + named_field_join: ", ".to_string(), + anon_empty: "{}".to_string(), + anon_prefix: "{\n".to_string(), + anon_suffix: "}".to_string(), + anon_field_indent: " ".to_string(), +}), + service_method: Rc::new(ServiceMethodStrategy::SelfInParams { + self_param: "".to_string(), +}), + service_return: Rc::new(ServiceReturnStrategy::ArrowReturn), +}) } pub fn language_spec_for_target(target: RenderTarget) -> Rc { match target { - RenderTarget::Rust => rust_spec(), - RenderTarget::Go => go_spec(), - RenderTarget::Python => python_spec(), - RenderTarget::Dag => dag_spec(), - } + RenderTarget::Rust => rust_spec(), + RenderTarget::Go => go_spec(), + RenderTarget::Python => python_spec(), + RenderTarget::Dag => dag_spec(), +} } pub fn target_keyword(target: RenderTarget, key: String) -> String { match target { - RenderTarget::Rust => match v2_rt::lookup(&rust_keywords(), key.clone()) { - Some(kw) => kw.clone(), - None => key.clone(), - }, - RenderTarget::Go => match v2_rt::lookup(&go_keywords(), key.clone()) { - Some(kw) => kw.clone(), - None => key.clone(), - }, - RenderTarget::Python => match v2_rt::lookup(&python_keywords(), key.clone()) { - Some(kw) => kw.clone(), - None => key.clone(), - }, - RenderTarget::Dag => key.clone(), - } + RenderTarget::Rust => match v2_rt::lookup(&rust_keywords(), key.clone()) { + Some(kw) => kw.clone(), + None => key.clone(), +}, + RenderTarget::Go => match v2_rt::lookup(&go_keywords(), key.clone()) { + Some(kw) => kw.clone(), + None => key.clone(), +}, + RenderTarget::Python => match v2_rt::lookup(&python_keywords(), key.clone()) { + Some(kw) => kw.clone(), + None => key.clone(), +}, + RenderTarget::Dag => key.clone(), +} } pub fn target_operators(target: RenderTarget) -> Rc>> { match target { - RenderTarget::Rust => rust_operators(), - RenderTarget::Python => python_operators(), - RenderTarget::Go => go_operators(), - RenderTarget::Dag => dag_operators(), - } + RenderTarget::Rust => rust_operators(), + RenderTarget::Python => python_operators(), + RenderTarget::Go => go_operators(), + RenderTarget::Dag => dag_operators(), +} } -pub fn binop_symbol( - target: RenderTarget, - op: BinOp, - algebra_field: Option, -) -> Option { +pub fn binop_symbol(target: RenderTarget, op: BinOp, algebra_field: Option) -> Option { { let ops = target_operators(target); - let op_matching = Rc::new({ - let mut __result = Vec::new(); - for spec in ops.iter().cloned() { - if match spec.binop.clone() { - Some(b) => (b.clone() == op.clone()), - None => false, - } { - __result.push(spec); - } - } - __result - }); - let specific = match algebra_field { - Some(af) => Rc::new({ - let mut __result = Vec::new(); - for spec in op_matching.clone().iter().cloned() { - if match spec.algebra_field.clone() { - Some(sf) => (sf.clone() == af.clone()), - _ => false, - } { - __result.push(spec); - } - } - __result - }) - .first() - .cloned(), - None => None, - }; - let result = match specific.clone() { - Some(_) => specific.clone(), - None => Rc::new({ - let mut __result = Vec::new(); - for spec in op_matching.clone().iter().cloned() { - if (spec.algebra_field.clone() == None) { - __result.push(spec); - } - } - __result - }) - .first() - .cloned(), - }; - match result { - Some(spec) => Some(spec.symbol.clone()), - None => None, - } - } +let op_matching = Rc::new({ let mut __result = Vec::new(); for spec in ops.iter().cloned() { if match spec.binop.clone() { + Some(b) => (b.clone() == op.clone()), + None => false, +} { __result.push(spec); } } __result }); +let specific = match algebra_field { + Some(af) => Rc::new({ let mut __result = Vec::new(); for spec in op_matching.clone().iter().cloned() { if match spec.algebra_field.clone() { + Some(sf) => (sf.clone() == af.clone()), + _ => false, +} { __result.push(spec); } } __result }).first().cloned(), + None => None, +}; +let result = match specific.clone() { + Some(_) => specific.clone(), + None => Rc::new({ let mut __result = Vec::new(); for spec in op_matching.clone().iter().cloned() { if (spec.algebra_field.clone() == None) { __result.push(spec); } } __result }).first().cloned(), +}; +match result { + Some(spec) => Some(spec.symbol.clone()), + None => None, +} +} } pub fn is_string_like(target: RenderTarget, name: String) -> bool { match target { - RenderTarget::Rust => { - let mut __found = false; - for t in rust_string_types().iter().cloned() { - if (t.clone().as_str() == name.clone().as_str()) { - __found = true; - break; - } - } - __found - } - RenderTarget::Go => { - let mut __found = false; - for t in go_string_types().iter().cloned() { - if (t.clone().as_str() == name.clone().as_str()) { - __found = true; - break; - } - } - __found - } - RenderTarget::Python => { - let mut __found = false; - for t in python_string_types().iter().cloned() { - if (t.clone().as_str() == name.clone().as_str()) { - __found = true; - break; - } - } - __found - } - RenderTarget::Dag => false, - } + RenderTarget::Rust => { let mut __found = false; for t in rust_string_types().iter().cloned() { if (t.clone().as_str() == name.clone().as_str()) { __found = true; break; } } __found }, + RenderTarget::Go => { let mut __found = false; for t in go_string_types().iter().cloned() { if (t.clone().as_str() == name.clone().as_str()) { __found = true; break; } } __found }, + RenderTarget::Python => { let mut __found = false; for t in python_string_types().iter().cloned() { if (t.clone().as_str() == name.clone().as_str()) { __found = true; break; } } __found }, + RenderTarget::Dag => false, +} } pub fn scaffold_for_target(target: RenderTarget) -> Rc { @@ -1316,14 +1190,12 @@ pub fn sharing_for_target(target: RenderTarget) -> Rc { } pub fn expression_semantics_for_target(target: RenderTarget) -> Rc { - language_spec_for_target(target) - .expression_semantics - .clone() + language_spec_for_target(target).expression_semantics.clone() } pub fn wrap_shared_type(target: RenderTarget, inner: String) -> String { { let tmpl = sharing_for_target(target).wrap_template.clone(); - v2_rt::replace(tmpl, "{0}".to_string(), inner) - } +v2_rt::replace(tmpl, "{0}".to_string(), inner) +} } diff --git a/src/v2/stage0/src/v2_compiler_normalize.rs b/src/v2/stage0/src/v2_compiler_normalize.rs index a3adf7bac7f..165dbb3cf6f 100644 --- a/src/v2/stage0/src/v2_compiler_normalize.rs +++ b/src/v2/stage0/src/v2_compiler_normalize.rs @@ -1,21 +1,18 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.normalize -pub use crate::std_types::container_expected_arity; -pub use crate::v2_compiler_resolve::{ModuleGraph, ResolvedModule}; -use crate::v2_rt; -use crate::v2_std_core::CompilerDiagnostic::ArityMismatch; -use crate::v2_std_core::Connective::NoConnective; -use crate::v2_std_core::ExprData::NoExprData; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved}; -pub use crate::v2_std_core::{ - authored_name_at, make_error_node, module_items, CompilerDiagnostic, Connective, ErrorNode, - ExprData, InferredNode, NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, ErrorNode, NewlineIndex, InferredNode, ExprData, make_error_node, module_items, authored_name_at, Connective, CompilerDiagnostic}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError}; +use crate::v2_std_core::ExprData::{NoExprData}; +use crate::v2_std_core::Connective::{NoConnective}; +use crate::v2_std_core::CompilerDiagnostic::{ArityMismatch}; +pub use crate::v2_compiler_resolve::{ModuleGraph, ResolvedModule}; +pub use crate::std_types::{container_expected_arity}; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct NormalizeResult { @@ -23,174 +20,72 @@ pub struct NormalizeResult { pub diagnostics: Rc>>, } -pub fn check_bare_containers( - n: &Rc, - module_name: &String, - source_indices: &Rc>>, -) -> Rc>> { +pub fn check_bare_containers(n: &Rc, module_name: &String, source_indices: &Rc>>) -> Rc>> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let has_structure = ((match n.body.clone() { - Some(_) => true, - None => false, - } || ((n.uses.clone().len() as i64) > 0)) - || ((n.properties.clone().len() as i64) > 0)); - let is_expr = match (*n.expr_data.clone()).clone() { - ExprData::NoExprData => false, - _ => true, - }; - let nname = authored_name_at(source_indices.clone(), &n); - let self_diags = if is_expr { - Rc::new(vec![]) - } else { - match container_expected_arity(nname.clone()) { - Some(expected) => { - if (((((n.children.clone().len() as i64) == 0) - && ((n.params.clone().len() as i64) == 0)) - && (n.connective.clone() == Connective::NoConnective)) - && !has_structure) - { - Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::ArityMismatch { - name: nname.clone(), - expected: expected.clone(), - got: 0, - span: n.span.clone(), - }), - module_name.clone(), - )]) - } else { - Rc::new(vec![]) - } - } - None => Rc::new(vec![]), - } - }; - let child_diags = Rc::new({ - let mut __result = Vec::new(); - for c in n.children.clone().iter().cloned() { - __result.extend( - (*check_bare_containers(&c, &module_name, &source_indices)) - .iter() - .cloned(), - ); - } - __result - }); - let param_diags = Rc::new({ - let mut __result = Vec::new(); - for p in n.params.clone().iter().cloned() { - __result.extend( - (*check_bare_containers(&p, &module_name, &source_indices)) - .iter() - .cloned(), - ); - } - __result - }); - let type_ann_diags = match n.type_annotation.clone() { - Some(ta) => check_bare_containers(&ta, &module_name, &source_indices), - None => Rc::new(vec![]), - }; - let body_diags = match n.body.clone() { - Some(b) => check_bare_containers(&b, &module_name, &source_indices), - None => Rc::new(vec![]), - }; - let inferred_diags = if ((n.params.clone().len() as i64) > 0) { - Rc::new(vec![]) - } else { - match n.inferred.clone() { - Some(inf) => match (*inf.clone()).clone() { - InferredNode::Resolved { node: rn, .. } => { - check_bare_containers(&rn, &module_name, &source_indices) - } - _ => Rc::new(vec![]), + { + let has_structure = ((match n.body.clone() { + Some(_) => true, + None => false, +} || ((n.uses.clone().len() as i64) > 0)) || ((n.properties.clone().len() as i64) > 0)); +let is_expr = match (*n.expr_data.clone()).clone() { + ExprData::NoExprData => false, + _ => true, +}; +let nname = authored_name_at(source_indices.clone(), &n); +let self_diags = if is_expr { + Rc::new(vec![]) + } else { + match container_expected_arity(nname.clone()) { + Some(expected) => if (((((n.children.clone().len() as i64) == 0) && ((n.params.clone().len() as i64) == 0)) && (n.connective.clone() == Connective::NoConnective)) && !has_structure) { + Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::ArityMismatch { + name: nname.clone(), + expected: expected.clone(), + got: 0, + span: n.span.clone(), +}), module_name.clone())]) + } else { + Rc::new(vec![]) }, - None => Rc::new(vec![]), - } - }; - let uses_diags = Rc::new({ - let mut __result = Vec::new(); - for u in n.uses.clone().iter().cloned() { - __result.extend( - (*check_bare_containers(&u, &module_name, &source_indices)) - .iter() - .cloned(), - ); - } - __result - }); - let prop_diags = Rc::new({ - let mut __result = Vec::new(); - for p in n.properties.clone().iter().cloned() { - __result.extend( - (*check_bare_containers(&p, &module_name, &source_indices)) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new({ - let mut __result = Vec::new(); - for d in Rc::new(vec![ - self_diags, - child_diags, - param_diags, - type_ann_diags, - inferred_diags, - body_diags, - uses_diags, - prop_diags, - ]) - .iter() - .cloned() - { - __result.extend((*d.clone()).iter().cloned()); - } - __result - }) + None => Rc::new(vec![]), +} + }; +let child_diags = Rc::new({ let mut __result = Vec::new(); for c in n.children.clone().iter().cloned() { __result.extend((*check_bare_containers(&c, &module_name, &source_indices)).iter().cloned()); } __result }); +let param_diags = Rc::new({ let mut __result = Vec::new(); for p in n.params.clone().iter().cloned() { __result.extend((*check_bare_containers(&p, &module_name, &source_indices)).iter().cloned()); } __result }); +let type_ann_diags = match n.type_annotation.clone() { + Some(ta) => check_bare_containers(&ta, &module_name, &source_indices), + None => Rc::new(vec![]), +}; +let body_diags = match n.body.clone() { + Some(b) => check_bare_containers(&b, &module_name, &source_indices), + None => Rc::new(vec![]), +}; +let inferred_diags = if ((n.params.clone().len() as i64) > 0) { + Rc::new(vec![]) + } else { + match n.inferred.clone() { + Some(inf) => match (*inf.clone()).clone() { + InferredNode::Resolved { node: rn, .. } => check_bare_containers(&rn, &module_name, &source_indices), + _ => Rc::new(vec![]), +}, + None => Rc::new(vec![]), +} + }; +let uses_diags = Rc::new({ let mut __result = Vec::new(); for u in n.uses.clone().iter().cloned() { __result.extend((*check_bare_containers(&u, &module_name, &source_indices)).iter().cloned()); } __result }); +let prop_diags = Rc::new({ let mut __result = Vec::new(); for p in n.properties.clone().iter().cloned() { __result.extend((*check_bare_containers(&p, &module_name, &source_indices)).iter().cloned()); } __result }); +Rc::new({ let mut __result = Vec::new(); for d in Rc::new(vec![self_diags, child_diags, param_diags, type_ann_diags, inferred_diags, body_diags, uses_diags, prop_diags]).iter().cloned() { __result.extend((*d.clone()).iter().cloned()); } __result }) +} }) } -pub fn normalize_graph( - graph: &Rc, - source_indices: Rc>>, -) -> Rc { +pub fn normalize_graph(graph: &Rc, source_indices: Rc>>) -> Rc { { - let diags = Rc::new({ - let mut __result = Vec::new(); - for m in graph.modules.clone().iter().cloned() { - __result.extend( - (*{ - let items = module_items(m.module.clone()); - Rc::new({ - let mut __result = Vec::new(); - for item in items.clone().iter().cloned() { - __result.extend( - (*check_bare_containers( - &item, - &authored_name_at( - source_indices.clone(), - &m.module.clone(), - ), - &source_indices, - )) - .iter() - .cloned(), - ); - } - __result - }) - }) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(NormalizeResult { - graph: graph.clone(), - diagnostics: diags, - }) - } + let diags = Rc::new({ let mut __result = Vec::new(); for m in graph.modules.clone().iter().cloned() { __result.extend((*{ + let items = module_items(m.module.clone()); +Rc::new({ let mut __result = Vec::new(); for item in items.clone().iter().cloned() { __result.extend((*check_bare_containers(&item, &authored_name_at(source_indices.clone(), &m.module.clone()), &source_indices)).iter().cloned()); } __result }) +}).iter().cloned()); } __result }); +Rc::new(NormalizeResult { + graph: graph.clone(), + diagnostics: diags, +}) +} } diff --git a/src/v2/stage0/src/v2_compiler_ownership.rs b/src/v2/stage0/src/v2_compiler_ownership.rs index 2abaab65c4d..192be95c9ec 100644 --- a/src/v2/stage0/src/v2_compiler_ownership.rs +++ b/src/v2/stage0/src/v2_compiler_ownership.rs @@ -1,28 +1,19 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.ownership -use self::EdgeKind::*; -use self::OwnershipDecision::*; -pub use crate::v2_compiler_emit::to_string; -use crate::v2_rt; -use crate::v2_std_core::Cardinality::Required; -use crate::v2_std_core::ExprData::{ - ExprBlock, ExprCall, ExprError, ExprFieldAccess, ExprForEach, ExprIf, ExprLambda, ExprLet, - ExprLiteral, ExprMatch, ExprMethodCall, ExprRecordLit, ExprReturn, ExprVar, NoExprData, -}; -use crate::v2_std_core::InferredNode::Resolved; -use crate::v2_std_core::VarBindingKind::{FunctionValueBinding, LocalValueBinding}; -pub use crate::v2_std_core::{ - arg_value, arm_body, authored_name_at, expr_call_func_at, expr_method_name_at, - expr_var_name_at, field_access_base, field_access_field_at, foreach_body, foreach_collection, - if_condition, if_else_branch, if_then_branch, lambda_body, lambda_param_names_at, let_body, - let_value, match_arm_nodes, match_scrutinee, method_arg_nodes, method_receiver, Cardinality, - ExprData, InferredNode, NewlineIndex, Node, VarBindingKind, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{Node, ExprData, VarBindingKind, InferredNode, Cardinality, arg_value, arm_body, field_access_base, if_condition, if_then_branch, if_else_branch, let_value, let_body, lambda_body, lambda_param_names_at, match_scrutinee, match_arm_nodes, method_receiver, method_arg_nodes, foreach_collection, foreach_body, expr_var_name_at, expr_call_func_at, expr_method_name_at, field_access_field_at, authored_name_at, NewlineIndex}; +use crate::v2_std_core::ExprData::{NoExprData, ExprError, ExprLiteral, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprBlock, ExprReturn, ExprLambda, ExprForEach, ExprRecordLit}; +use crate::v2_std_core::VarBindingKind::{LocalValueBinding, FunctionValueBinding}; +use crate::v2_std_core::InferredNode::{Resolved}; +use crate::v2_std_core::Cardinality::{Required}; +pub use crate::v2_compiler_emit::{to_string}; +use self::EdgeKind::*; +use self::OwnershipDecision::*; #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] @@ -48,35 +39,17 @@ pub struct BindingUsage { } pub fn semantic_consumer_count(usage: Rc) -> i64 { - (Rc::new({ - let mut __result = Vec::new(); - for c in usage.consumers.clone().iter().cloned() { - if match c.kind.clone() { - EdgeKind::Consumed => true, - _ => false, - } { - __result.push(c); - } - } - __result - }) - .len() as i64) + (Rc::new({ let mut __result = Vec::new(); for c in usage.consumers.clone().iter().cloned() { if match c.kind.clone() { + EdgeKind::Consumed => true, + _ => false, +} { __result.push(c); } } __result }).len() as i64) } pub fn binding_fan_out(usage: Rc) -> i64 { - (Rc::new({ - let mut __result = Vec::new(); - for c in usage.consumers.clone().iter().cloned() { - if match c.kind.clone() { - EdgeKind::Threaded => false, - _ => true, - } { - __result.push(c); - } - } - __result - }) - .len() as i64) + (Rc::new({ let mut __result = Vec::new(); for c in usage.consumers.clone().iter().cloned() { if match c.kind.clone() { + EdgeKind::Threaded => false, + _ => true, +} { __result.push(c); } } __result }).len() as i64) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -140,48 +113,41 @@ pub struct UsageAccum { pub fn empty_usage_accum() -> Rc { Rc::new(UsageAccum { - bindings: v2_rt::rc_empty_map::>(), - fold_call_nodes: Rc::new(vec![]), - }) + bindings: v2_rt::rc_empty_map::>(), + fold_call_nodes: Rc::new(vec![]), +}) } -pub fn record_use( - accum: &Rc, - name: &String, - kind: EdgeKind, - site: String, - binding_kind: Option>, - span_start: i64, -) -> Rc { +pub fn record_use(accum: &Rc, name: &String, kind: EdgeKind, site: String, binding_kind: Option>, span_start: i64) -> Rc { { let edge = Rc::new(EdgeClassification { - kind: kind, - site: site, - span_start: span_start, - }); - let existing = match v2_rt::map_get(&accum.bindings.clone(), name.clone()) { - Some(usage) => usage.clone(), - None => Rc::new(BindingUsage { - name: name.clone(), - binding_kind: None, - consumers: Rc::new(vec![]), - }), - }; - let effective_kind = if (existing.binding_kind.clone() != None) { + kind: kind, + site: site, + span_start: span_start, +}); +let existing = match v2_rt::map_get(&accum.bindings.clone(), name.clone()) { + Some(usage) => usage.clone(), + None => Rc::new(BindingUsage { + name: name.clone(), + binding_kind: None, + consumers: Rc::new(vec![]), +}), +}; +let effective_kind = if (existing.binding_kind.clone() != None) { existing.binding_kind.clone() } else { binding_kind }; - let updated = Rc::new(BindingUsage { - name: name.clone(), - binding_kind: effective_kind, - consumers: v2_rt::rc_list_push(existing.consumers.clone(), edge), - }); - Rc::new(UsageAccum { - bindings: v2_rt::rc_map_insert(accum.bindings.clone(), name.clone(), updated), - fold_call_nodes: accum.fold_call_nodes.clone(), - }) - } +let updated = Rc::new(BindingUsage { + name: name.clone(), + binding_kind: effective_kind, + consumers: v2_rt::rc_list_push(existing.consumers.clone(), edge), +}); +Rc::new(UsageAccum { + bindings: v2_rt::rc_map_insert(accum.bindings.clone(), name.clone(), updated), + fold_call_nodes: accum.fold_call_nodes.clone(), +}) +} } pub fn max_usage_by_fan_out(a: Rc, b: Rc) -> Rc { @@ -192,1014 +158,510 @@ pub fn max_usage_by_fan_out(a: Rc, b: Rc) -> Rc>>, - key: &String, - new_val: Rc, -) -> Rc>> { +pub fn map_usage_merge_at(base: &Rc>>, key: &String, new_val: Rc) -> Rc>> { match v2_rt::map_get(&base, key.clone()) { - Some(existing) => v2_rt::rc_map_insert( - base.clone(), - key.clone(), - max_usage_by_fan_out(existing.clone(), new_val), - ), - None => v2_rt::rc_map_insert(base.clone(), key.clone(), new_val), - } + Some(existing) => v2_rt::rc_map_insert(base.clone(), key.clone(), max_usage_by_fan_out(existing.clone(), new_val)), + None => v2_rt::rc_map_insert(base.clone(), key.clone(), new_val), +} } -pub fn merge_branch_usages( - base: &Rc, - branches: &Rc>>, -) -> Rc { +pub fn merge_branch_usages(base: &Rc, branches: &Rc>>) -> Rc { { - let binding_merged = branches.clone().iter().cloned().fold( - base.bindings.clone(), - |merged: Rc>>, branch: Rc| { - Rc::new(v2_rt::map_values(&branch.bindings.clone())) - .iter() - .cloned() - .fold( - merged, - |acc: Rc>>, usage: Rc| { - map_usage_merge_at(&acc, &usage.name.clone(), usage.clone()) - }, - ) - }, - ); - let base_fold_count = (base.fold_call_nodes.clone().len() as i64); - let branch_fold_nodes = Rc::new({ - let mut __result = Vec::new(); - for b in branches.clone().iter().cloned() { - __result.extend( - (*Rc::new( - b.fold_call_nodes - .clone() - .iter() - .cloned() - .skip(base_fold_count.clone() as usize) - .collect::>(), - )) - .iter() - .cloned(), - ); - } - __result - }); - Rc::new(UsageAccum { - bindings: binding_merged, - fold_call_nodes: v2_rt::concat(base.fold_call_nodes.clone(), branch_fold_nodes), - }) - } + let binding_merged = branches.clone().iter().cloned().fold(base.bindings.clone(), |merged: Rc>>, branch: Rc| Rc::new(v2_rt::map_values(&branch.bindings.clone())).iter().cloned().fold(merged, |acc: Rc>>, usage: Rc| map_usage_merge_at(&acc, &usage.name.clone(), usage.clone()))); +let base_fold_count = (base.fold_call_nodes.clone().len() as i64); +let branch_fold_nodes = Rc::new({ let mut __result = Vec::new(); for b in branches.clone().iter().cloned() { __result.extend((*Rc::new(b.fold_call_nodes.clone().iter().cloned().skip(base_fold_count.clone() as usize).collect::>())).iter().cloned()); } __result }); +Rc::new(UsageAccum { + bindings: binding_merged, + fold_call_nodes: v2_rt::concat(base.fold_call_nodes.clone(), branch_fold_nodes), +}) +} } -pub fn walk_expr( - accum: Rc, - texpr: &Rc, - in_tail: bool, - si: &Rc>>, -) -> Rc { +pub fn walk_expr(accum: Rc, texpr: &Rc, in_tail: bool, si: &Rc>>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprVar { - binding_kind: bk, .. - } => { - let n = expr_var_name_at(texpr.clone(), si.clone()); - if in_tail.clone() { - record_use( - &accum, - &n, - EdgeKind::Consumed, - "return".to_string(), - bk.clone(), - texpr.span.clone().start.clone(), - ) - } else { - record_use( - &accum, - &n, - EdgeKind::Read, - "read".to_string(), - bk.clone(), - texpr.span.clone().start.clone(), - ) - } - } - ExprData::ExprLiteral { .. } => accum, - ExprData::ExprFieldAccess { .. } => { - let base_node = field_access_base(texpr.clone()); - match (*base_node.expr_data.clone()).clone() { - ExprData::ExprVar { - binding_kind: bk, .. - } => { - let vn = expr_var_name_at(base_node.clone(), si.clone()); - let f = field_access_field_at(texpr.clone(), si.clone()); - record_use( - &accum, - &vn, - EdgeKind::Projected, - v2_rt::concat(".".to_string(), f), - bk.clone(), - texpr.span.clone().start.clone(), - ) - } - _ => walk_expr(accum, &base_node, false, &si), - } - } - ExprData::ExprCall { .. } => { - let fname = expr_call_func_at(texpr.clone(), si.clone()); - if (fname.as_str() == "fold".to_string().as_str()) { - { - let init_arg = Rc::new({ - let mut __result = Vec::new(); - for a in texpr.children.clone().iter().cloned() { - if (authored_name_at(si.clone(), &a).as_str() - == "init".to_string().as_str()) - { - __result.push(a); - } - } - __result - }) - .first() - .cloned(); - let threaded_accum = match init_arg { - Some(ia) => { - let ia_val = arg_value(&ia); - match (*ia_val.expr_data.clone()).clone() { - ExprData::ExprVar { - binding_kind: bk, .. - } => { - let vn = expr_var_name_at(ia_val.clone(), si.clone()); - record_use( - &accum, - &vn, - EdgeKind::Threaded, - "fold_init".to_string(), - bk.clone(), - ia_val.span.clone().start.clone(), - ) - } - _ => walk_expr(accum, &ia_val, false, &si), - } - } - None => accum, - }; - let non_init = Rc::new({ - let mut __result = Vec::new(); - for a in texpr.children.clone().iter().cloned() { - if (authored_name_at(si.clone(), &a).as_str() - != "init".to_string().as_str()) - { - __result.push(a); - } - } - __result - }); - non_init.iter().cloned().fold( - threaded_accum.clone(), - |acc: Rc, a: Rc| { - walk_expr(acc, &arg_value(&a), false, &si) - }, - ) - } - } else { - texpr.children.clone().iter().cloned().fold( - accum, - |acc: Rc, a: Rc| { - walk_expr(acc, &arg_value(&a), false, &si) - }, - ) - } - } - ExprData::ExprMethodCall { .. } => { - let recv = method_receiver(texpr.clone()); - let mc_args = method_arg_nodes(texpr.clone()); - let mname = expr_method_name_at(texpr.clone(), si.clone()); - if (mname.as_str() == "fold".to_string().as_str()) { - { - let recv_accum = walk_expr(accum, &recv, false, &si); - let init_arg = Rc::new({ - let mut __result = Vec::new(); - for a in mc_args.clone().iter().cloned() { - if (authored_name_at(si.clone(), &a).as_str() - == "init".to_string().as_str()) - { - __result.push(a); - } - } - __result - }) - .first() - .cloned(); - let threaded_accum = match init_arg { - Some(ia) => { - let ia_val = arg_value(&ia); - match (*ia_val.expr_data.clone()).clone() { - ExprData::ExprVar { - binding_kind: bk, .. - } => { - let vn = expr_var_name_at(ia_val.clone(), si.clone()); - record_use( - &recv_accum, - &vn, - EdgeKind::Threaded, - "fold_init".to_string(), - bk.clone(), - ia_val.span.clone().start.clone(), - ) - } - _ => walk_expr(recv_accum, &ia_val, false, &si), - } - } - None => recv_accum, - }; - let non_init = Rc::new({ - let mut __result = Vec::new(); - for a in mc_args.clone().iter().cloned() { - if (authored_name_at(si.clone(), &a).as_str() - != "init".to_string().as_str()) - { - __result.push(a); - } - } - __result - }); - let walked = non_init.iter().cloned().fold( - threaded_accum.clone(), - |acc: Rc, a: Rc| { - walk_expr(acc, &arg_value(&a), false, &si) - }, - ); - Rc::new(UsageAccum { - bindings: walked.bindings.clone(), - fold_call_nodes: v2_rt::rc_list_push( - walked.fold_call_nodes.clone(), - texpr.clone(), - ), - }) - } - } else { - { - let recv_accum = walk_expr(accum, &recv, false, &si); - mc_args.clone().iter().cloned().fold( - recv_accum, - |acc: Rc, a: Rc| { - walk_expr(acc, &arg_value(&a), false, &si) - }, - ) - } - } - } - ExprData::ExprMatch => { - let scrut = match_scrutinee(texpr.clone()); - let arm_nodes = match_arm_nodes(texpr.clone()); - let s_accum = walk_expr(accum, &scrut, false, &si); - let branch_accums = Rc::new({ - let mut __result = Vec::new(); - for arm_node in arm_nodes.iter().cloned() { - __result.push(walk_expr( - s_accum.clone(), - &arm_body(&arm_node), - in_tail.clone(), - &si, - )); - } - __result - }); - merge_branch_usages(&s_accum, &branch_accums) - } - ExprData::ExprIf => { - let c = if_condition(texpr.clone()); - let t = if_then_branch(texpr.clone()); - let c_accum = walk_expr(accum, &c, false, &si); - let t_accum = walk_expr(c_accum.clone(), &t, in_tail.clone(), &si); - let e_accum = match if_else_branch(texpr.clone()) { - Some(eb) => walk_expr(c_accum.clone(), &eb, in_tail.clone(), &si), - None => c_accum.clone(), - }; - merge_branch_usages(&c_accum, &Rc::new(vec![t_accum, e_accum])) - } - ExprData::ExprLet => { - let v = let_value(texpr.clone()); - let v_accum = walk_expr(accum, &v, false, &si); - match let_body(texpr.clone()) { - Some(b) => walk_expr(v_accum, &b, in_tail.clone(), &si), - None => v_accum, - } - } - ExprData::ExprBlock => { - let ss = texpr.children.clone(); - let ss_count = (ss.clone().len() as i64); - if (ss_count.clone() == 0) { - accum - } else { - { - let init_accum = Rc::new({ - let mut __result = Vec::new(); - for p in Rc::new( - ss.clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (p.0.clone() < (ss_count.clone() - 1)) { - __result.push(p); - } - } - __result - }) - .iter() - .cloned() - .fold( - accum, - |acc: Rc, p: (i64, Rc)| { - walk_expr(acc, &p.1.clone(), false, &si) - }, - ); - match ss.clone().last().cloned() { - Some(last_expr) => { - walk_expr(init_accum, &last_expr, in_tail.clone(), &si) - } - None => init_accum, - } - } - } - } - ExprData::ExprReturn => texpr - .children - .clone() - .iter() - .cloned() - .fold(accum, |acc: Rc, child: Rc| { - walk_expr(acc, &child, true, &si) - }), - ExprData::ExprLambda => { - let body = lambda_body(texpr.clone()); - let inner = walk_expr(empty_usage_accum(), &body, false, &si); - let binding_merged = Rc::new(v2_rt::map_values(&inner.bindings.clone())) - .iter() - .cloned() - .fold(accum, |acc: Rc, usage: Rc| { - let a1 = record_use( - &acc, - &usage.name.clone(), - EdgeKind::Read, - "lambda-capture".to_string(), - None, - 0, - ); - record_use( - &a1, - &usage.name.clone(), - EdgeKind::Read, - "lambda-capture".to_string(), - None, - 0, - ) - }); - Rc::new(UsageAccum { - bindings: binding_merged.bindings.clone(), - fold_call_nodes: v2_rt::concat( - binding_merged.fold_call_nodes.clone(), - inner.fold_call_nodes.clone(), - ), - }) - } - ExprData::ExprForEach => { - let coll = foreach_collection(texpr.clone()); - let coll_accum = walk_expr(accum, &coll, false, &si); - let body = foreach_body(texpr.clone()); - let inner = walk_expr(empty_usage_accum(), &body, false, &si); - let binding_merged = Rc::new(v2_rt::map_values(&inner.bindings.clone())) - .iter() - .cloned() - .fold( - coll_accum.clone(), - |acc: Rc, usage: Rc| { - let a1 = record_use( - &acc, - &usage.name.clone(), - EdgeKind::Read, - "foreach-capture".to_string(), - None, - 0, - ); - record_use( - &a1, - &usage.name.clone(), - EdgeKind::Read, - "foreach-capture".to_string(), - None, - 0, - ) - }, - ); - Rc::new(UsageAccum { - bindings: binding_merged.bindings.clone(), - fold_call_nodes: v2_rt::concat( - binding_merged.fold_call_nodes.clone(), - inner.fold_call_nodes.clone(), - ), - }) - } - _ => texpr - .children - .clone() - .iter() - .cloned() - .fold(accum, |acc: Rc, child: Rc| { - walk_expr(acc, &child, false, &si) - }), - } + ExprData::ExprVar { binding_kind: bk, .. } => { + let n = expr_var_name_at(texpr.clone(), si.clone()); +if in_tail.clone() { + record_use(&accum, &n, EdgeKind::Consumed, "return".to_string(), bk.clone(), texpr.span.clone().start.clone()) + } else { + record_use(&accum, &n, EdgeKind::Read, "read".to_string(), bk.clone(), texpr.span.clone().start.clone()) + } +}, + ExprData::ExprLiteral { .. } => accum, + ExprData::ExprFieldAccess { .. } => { + let base_node = field_access_base(texpr.clone()); +match (*base_node.expr_data.clone()).clone() { + ExprData::ExprVar { binding_kind: bk, .. } => { + let vn = expr_var_name_at(base_node.clone(), si.clone()); +let f = field_access_field_at(texpr.clone(), si.clone()); +record_use(&accum, &vn, EdgeKind::Projected, v2_rt::concat(".".to_string(), f), bk.clone(), texpr.span.clone().start.clone()) +}, + _ => walk_expr(accum, &base_node, false, &si), +} +}, + ExprData::ExprCall { .. } => { + let fname = expr_call_func_at(texpr.clone(), si.clone()); +if (fname.as_str() == "fold".to_string().as_str()) { + { + let init_arg = Rc::new({ let mut __result = Vec::new(); for a in texpr.children.clone().iter().cloned() { if (authored_name_at(si.clone(), &a).as_str() == "init".to_string().as_str()) { __result.push(a); } } __result }).first().cloned(); +let threaded_accum = match init_arg { + Some(ia) => { + let ia_val = arg_value(&ia); +match (*ia_val.expr_data.clone()).clone() { + ExprData::ExprVar { binding_kind: bk, .. } => { + let vn = expr_var_name_at(ia_val.clone(), si.clone()); +record_use(&accum, &vn, EdgeKind::Threaded, "fold_init".to_string(), bk.clone(), ia_val.span.clone().start.clone()) +}, + _ => walk_expr(accum, &ia_val, false, &si), +} +}, + None => accum, +}; +let non_init = Rc::new({ let mut __result = Vec::new(); for a in texpr.children.clone().iter().cloned() { if (authored_name_at(si.clone(), &a).as_str() != "init".to_string().as_str()) { __result.push(a); } } __result }); +non_init.iter().cloned().fold(threaded_accum.clone(), |acc: Rc, a: Rc| walk_expr(acc, &arg_value(&a), false, &si)) +} + } else { + texpr.children.clone().iter().cloned().fold(accum, |acc: Rc, a: Rc| walk_expr(acc, &arg_value(&a), false, &si)) + } +}, + ExprData::ExprMethodCall { .. } => { + let recv = method_receiver(texpr.clone()); +let mc_args = method_arg_nodes(texpr.clone()); +let mname = expr_method_name_at(texpr.clone(), si.clone()); +if (mname.as_str() == "fold".to_string().as_str()) { + { + let recv_accum = walk_expr(accum, &recv, false, &si); +let init_arg = Rc::new({ let mut __result = Vec::new(); for a in mc_args.clone().iter().cloned() { if (authored_name_at(si.clone(), &a).as_str() == "init".to_string().as_str()) { __result.push(a); } } __result }).first().cloned(); +let threaded_accum = match init_arg { + Some(ia) => { + let ia_val = arg_value(&ia); +match (*ia_val.expr_data.clone()).clone() { + ExprData::ExprVar { binding_kind: bk, .. } => { + let vn = expr_var_name_at(ia_val.clone(), si.clone()); +record_use(&recv_accum, &vn, EdgeKind::Threaded, "fold_init".to_string(), bk.clone(), ia_val.span.clone().start.clone()) +}, + _ => walk_expr(recv_accum, &ia_val, false, &si), +} +}, + None => recv_accum, +}; +let non_init = Rc::new({ let mut __result = Vec::new(); for a in mc_args.clone().iter().cloned() { if (authored_name_at(si.clone(), &a).as_str() != "init".to_string().as_str()) { __result.push(a); } } __result }); +let walked = non_init.iter().cloned().fold(threaded_accum.clone(), |acc: Rc, a: Rc| walk_expr(acc, &arg_value(&a), false, &si)); +Rc::new(UsageAccum { + bindings: walked.bindings.clone(), + fold_call_nodes: v2_rt::rc_list_push(walked.fold_call_nodes.clone(), texpr.clone()), +}) +} + } else { + { + let recv_accum = walk_expr(accum, &recv, false, &si); +mc_args.clone().iter().cloned().fold(recv_accum, |acc: Rc, a: Rc| walk_expr(acc, &arg_value(&a), false, &si)) +} + } +}, + ExprData::ExprMatch => { + let scrut = match_scrutinee(texpr.clone()); +let arm_nodes = match_arm_nodes(texpr.clone()); +let s_accum = walk_expr(accum, &scrut, false, &si); +let branch_accums = Rc::new({ let mut __result = Vec::new(); for arm_node in arm_nodes.iter().cloned() { __result.push(walk_expr(s_accum.clone(), &arm_body(&arm_node), in_tail.clone(), &si)); } __result }); +merge_branch_usages(&s_accum, &branch_accums) +}, + ExprData::ExprIf => { + let c = if_condition(texpr.clone()); +let t = if_then_branch(texpr.clone()); +let c_accum = walk_expr(accum, &c, false, &si); +let t_accum = walk_expr(c_accum.clone(), &t, in_tail.clone(), &si); +let e_accum = match if_else_branch(texpr.clone()) { + Some(eb) => walk_expr(c_accum.clone(), &eb, in_tail.clone(), &si), + None => c_accum.clone(), +}; +merge_branch_usages(&c_accum, &Rc::new(vec![t_accum, e_accum])) +}, + ExprData::ExprLet => { + let v = let_value(texpr.clone()); +let v_accum = walk_expr(accum, &v, false, &si); +match let_body(texpr.clone()) { + Some(b) => walk_expr(v_accum, &b, in_tail.clone(), &si), + None => v_accum, +} +}, + ExprData::ExprBlock => { + let ss = texpr.children.clone(); +let ss_count = (ss.clone().len() as i64); +if (ss_count.clone() == 0) { + accum + } else { + { + let init_accum = Rc::new({ let mut __result = Vec::new(); for p in Rc::new(ss.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (p.0.clone() < (ss_count.clone() - 1)) { __result.push(p); } } __result }).iter().cloned().fold(accum, |acc: Rc, p: (i64, Rc)| walk_expr(acc, &p.1.clone(), false, &si)); +match ss.clone().last().cloned() { + Some(last_expr) => walk_expr(init_accum, &last_expr, in_tail.clone(), &si), + None => init_accum, +} +} + } +}, + ExprData::ExprReturn => texpr.children.clone().iter().cloned().fold(accum, |acc: Rc, child: Rc| walk_expr(acc, &child, true, &si)), + ExprData::ExprLambda => { + let body = lambda_body(texpr.clone()); +let inner = walk_expr(empty_usage_accum(), &body, false, &si); +let binding_merged = Rc::new(v2_rt::map_values(&inner.bindings.clone())).iter().cloned().fold(accum, |acc: Rc, usage: Rc| { + let a1 = record_use(&acc, &usage.name.clone(), EdgeKind::Read, "lambda-capture".to_string(), None, 0); +record_use(&a1, &usage.name.clone(), EdgeKind::Read, "lambda-capture".to_string(), None, 0) +}); +Rc::new(UsageAccum { + bindings: binding_merged.bindings.clone(), + fold_call_nodes: v2_rt::concat(binding_merged.fold_call_nodes.clone(), inner.fold_call_nodes.clone()), +}) +}, + ExprData::ExprForEach => { + let coll = foreach_collection(texpr.clone()); +let coll_accum = walk_expr(accum, &coll, false, &si); +let body = foreach_body(texpr.clone()); +let inner = walk_expr(empty_usage_accum(), &body, false, &si); +let binding_merged = Rc::new(v2_rt::map_values(&inner.bindings.clone())).iter().cloned().fold(coll_accum.clone(), |acc: Rc, usage: Rc| { + let a1 = record_use(&acc, &usage.name.clone(), EdgeKind::Read, "foreach-capture".to_string(), None, 0); +record_use(&a1, &usage.name.clone(), EdgeKind::Read, "foreach-capture".to_string(), None, 0) +}); +Rc::new(UsageAccum { + bindings: binding_merged.bindings.clone(), + fold_call_nodes: v2_rt::concat(binding_merged.fold_call_nodes.clone(), inner.fold_call_nodes.clone()), +}) +}, + _ => texpr.children.clone().iter().cloned().fold(accum, |acc: Rc, child: Rc| walk_expr(acc, &child, false, &si)), +} }) } pub fn make_decision(usage: &Rc) -> Rc { { let sc = semantic_consumer_count(usage.clone()); - if (sc.clone() == 1) { +if (sc.clone() == 1) { { - let consumed_sites = Rc::new({ - let mut __result = Vec::new(); - for c in usage.consumers.clone().iter().cloned() { - if match c.kind.clone() { - EdgeKind::Consumed => true, - _ => false, - } { - __result.push(c); - } - } - __result - }); - let site = match consumed_sites.first().cloned() { - Some(c) => c.site.clone(), - None => "unknown".to_string(), - }; - Rc::new(OwnershipDecision::SoleOwner { - binding: usage.name.clone(), - site: site, - }) - } + let consumed_sites = Rc::new({ let mut __result = Vec::new(); for c in usage.consumers.clone().iter().cloned() { if match c.kind.clone() { + EdgeKind::Consumed => true, + _ => false, +} { __result.push(c); } } __result }); +let site = match consumed_sites.first().cloned() { + Some(c) => c.site.clone(), + None => "unknown".to_string(), +}; +Rc::new(OwnershipDecision::SoleOwner { + binding: usage.name.clone(), + site: site, +}) +} } else { if (sc.clone() > 1) { { - let sites = Rc::new({ - let mut __result = Vec::new(); - for c in Rc::new({ - let mut __result = Vec::new(); - for c in usage.consumers.clone().iter().cloned() { - if match c.kind.clone() { - EdgeKind::Consumed => true, - _ => false, - } { - __result.push(c); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(c.site.clone()); - } - __result - }); - Rc::new(OwnershipDecision::SharedError { - binding: usage.name.clone(), - consumer_count: sc.clone(), - sites: sites, - }) - } + let sites = Rc::new({ let mut __result = Vec::new(); for c in Rc::new({ let mut __result = Vec::new(); for c in usage.consumers.clone().iter().cloned() { if match c.kind.clone() { + EdgeKind::Consumed => true, + _ => false, +} { __result.push(c); } } __result }).iter().cloned() { __result.push(c.site.clone()); } __result }); +Rc::new(OwnershipDecision::SharedError { + binding: usage.name.clone(), + consumer_count: sc.clone(), + sites: sites, +}) +} } else { Rc::new(OwnershipDecision::Unclassified { - binding: usage.name.clone(), - reason: "no consumers found".to_string(), - }) + binding: usage.name.clone(), + reason: "no consumers found".to_string(), +}) } } - } +} } pub fn is_owned_local(kind: Option>) -> bool { match kind.as_deref().cloned() { - Some(VarBindingKind::LocalValueBinding) => true, - _ => false, - } + Some(VarBindingKind::LocalValueBinding) => true, + _ => false, +} } pub fn build_movable_set(proof: Rc) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for usage in Rc::new(v2_rt::map_values(&proof.bindings.clone())) - .iter() - .cloned() - { - if ((binding_fan_out(usage.clone()) == 1) && is_owned_local(usage.binding_kind.clone())) - { - __result.push(usage); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, usage: Rc| { - v2_rt::rc_map_insert(acc, usage.name.clone(), true) - }, - ) + Rc::new({ let mut __result = Vec::new(); for usage in Rc::new(v2_rt::map_values(&proof.bindings.clone())).iter().cloned() { if ((binding_fan_out(usage.clone()) == 1) && is_owned_local(usage.binding_kind.clone())) { __result.push(usage); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, usage: Rc| v2_rt::rc_map_insert(acc, usage.name.clone(), true)) } -pub fn build_read_only_params( - proof: Rc, - param_names: Rc>, -) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for usage in Rc::new(v2_rt::map_values(&proof.bindings.clone())) - .iter() - .cloned() - { - if (((v2_rt::map_contains_key(¶m_names, usage.name.clone()) - && is_owned_local(usage.binding_kind.clone())) - && (binding_fan_out(usage.clone()) > 1)) - && { - let mut __all = true; - for c in usage.consumers.clone().iter().cloned() { - if !(match c.kind.clone() { - EdgeKind::Read => true, - EdgeKind::Projected => true, - EdgeKind::Threaded => true, - _ => false, - }) { - __all = false; - break; - } - } - __all - }) - { - __result.push(usage); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, usage: Rc| { - v2_rt::rc_map_insert(acc, usage.name.clone(), true) - }, - ) +pub fn build_read_only_params(proof: Rc, param_names: Rc>) -> Rc> { + Rc::new({ let mut __result = Vec::new(); for usage in Rc::new(v2_rt::map_values(&proof.bindings.clone())).iter().cloned() { if (((v2_rt::map_contains_key(¶m_names, usage.name.clone()) && is_owned_local(usage.binding_kind.clone())) && (binding_fan_out(usage.clone()) > 1)) && { let mut __all = true; for c in usage.consumers.clone().iter().cloned() { if !(match c.kind.clone() { + EdgeKind::Read => true, + EdgeKind::Projected => true, + EdgeKind::Threaded => true, + _ => false, +}) { __all = false; break; } } __all }) { __result.push(usage); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, usage: Rc| v2_rt::rc_map_insert(acc, usage.name.clone(), true)) } -pub fn collect_callable_refs( - texpr: &Rc, - si: &Rc>>, -) -> Rc> { +pub fn collect_callable_refs(texpr: &Rc, si: &Rc>>) -> Rc> { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprVar { - binding_kind: bk, .. - } => match bk.clone().as_deref().cloned() { - Some(VarBindingKind::FunctionValueBinding) => { - let n = expr_var_name_at(texpr.clone(), si.clone()); - v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), n, true) - } - _ => v2_rt::rc_empty_map::(), - }, - ExprData::ExprLiteral { .. } => v2_rt::rc_empty_map::(), - ExprData::ExprFieldAccess { .. } => { - collect_callable_refs(&field_access_base(texpr.clone()), &si) - } - ExprData::ExprCall { .. } => texpr.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, a: Rc| { - v2_rt::rc_map_merge(acc, collect_callable_refs(&arg_value(&a), &si)) - }, - ), - ExprData::ExprMethodCall { .. } => { - let recv = collect_callable_refs(&method_receiver(texpr.clone()), &si); - method_arg_nodes(texpr.clone()).iter().cloned().fold( - recv.clone(), - |acc: Rc>, a: Rc| { - v2_rt::rc_map_merge(acc, collect_callable_refs(&arg_value(&a), &si)) - }, - ) - } - ExprData::ExprIf => { - let cond = collect_callable_refs(&if_condition(texpr.clone()), &si); - let then_br = collect_callable_refs(&if_then_branch(texpr.clone()), &si); - let else_br = match if_else_branch(texpr.clone()) { - Some(eb) => collect_callable_refs(&eb, &si), - None => v2_rt::rc_empty_map::(), - }; - v2_rt::rc_map_merge(v2_rt::rc_map_merge(cond, then_br), else_br) - } - ExprData::ExprMatch => { - let scrut = collect_callable_refs(&match_scrutinee(texpr.clone()), &si); - match_arm_nodes(texpr.clone()).iter().cloned().fold( - scrut.clone(), - |acc: Rc>, arm: Rc| { - v2_rt::rc_map_merge(acc, collect_callable_refs(&arm_body(&arm), &si)) - }, - ) - } - ExprData::ExprLet => { - let val = collect_callable_refs(&let_value(texpr.clone()), &si); - match let_body(texpr.clone()) { - Some(lb) => v2_rt::rc_map_merge(val, collect_callable_refs(&lb, &si)), - None => val, - } - } - ExprData::ExprBlock => texpr.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, child: Rc| { - v2_rt::rc_map_merge(acc, collect_callable_refs(&child, &si)) - }, - ), - ExprData::ExprReturn => match texpr.children.clone().first().cloned() { - Some(child) => collect_callable_refs(&child, &si), - None => v2_rt::rc_empty_map::(), - }, - ExprData::ExprLambda => collect_callable_refs(&lambda_body(texpr.clone()), &si), - ExprData::ExprForEach => { - let col = collect_callable_refs(&foreach_collection(texpr.clone()), &si); - v2_rt::rc_map_merge( - col, - collect_callable_refs(&foreach_body(texpr.clone()), &si), - ) - } - ExprData::ExprRecordLit { .. } => texpr.children.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, field: Rc| { - v2_rt::rc_map_merge(acc, collect_callable_refs(&arg_value(&field), &si)) - }, - ), - _ => v2_rt::rc_empty_map::(), - } + ExprData::ExprVar { binding_kind: bk, .. } => match bk.clone().as_deref().cloned() { + Some(VarBindingKind::FunctionValueBinding) => { + let n = expr_var_name_at(texpr.clone(), si.clone()); +v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), n, true) +}, + _ => v2_rt::rc_empty_map::(), +}, + ExprData::ExprLiteral { .. } => v2_rt::rc_empty_map::(), + ExprData::ExprFieldAccess { .. } => collect_callable_refs(&field_access_base(texpr.clone()), &si), + ExprData::ExprCall { .. } => texpr.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, a: Rc| v2_rt::rc_map_merge(acc, collect_callable_refs(&arg_value(&a), &si))), + ExprData::ExprMethodCall { .. } => { + let recv = collect_callable_refs(&method_receiver(texpr.clone()), &si); +method_arg_nodes(texpr.clone()).iter().cloned().fold(recv.clone(), |acc: Rc>, a: Rc| v2_rt::rc_map_merge(acc, collect_callable_refs(&arg_value(&a), &si))) +}, + ExprData::ExprIf => { + let cond = collect_callable_refs(&if_condition(texpr.clone()), &si); +let then_br = collect_callable_refs(&if_then_branch(texpr.clone()), &si); +let else_br = match if_else_branch(texpr.clone()) { + Some(eb) => collect_callable_refs(&eb, &si), + None => v2_rt::rc_empty_map::(), +}; +v2_rt::rc_map_merge(v2_rt::rc_map_merge(cond, then_br), else_br) +}, + ExprData::ExprMatch => { + let scrut = collect_callable_refs(&match_scrutinee(texpr.clone()), &si); +match_arm_nodes(texpr.clone()).iter().cloned().fold(scrut.clone(), |acc: Rc>, arm: Rc| v2_rt::rc_map_merge(acc, collect_callable_refs(&arm_body(&arm), &si))) +}, + ExprData::ExprLet => { + let val = collect_callable_refs(&let_value(texpr.clone()), &si); +match let_body(texpr.clone()) { + Some(lb) => v2_rt::rc_map_merge(val, collect_callable_refs(&lb, &si)), + None => val, +} +}, + ExprData::ExprBlock => texpr.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, child: Rc| v2_rt::rc_map_merge(acc, collect_callable_refs(&child, &si))), + ExprData::ExprReturn => match texpr.children.clone().first().cloned() { + Some(child) => collect_callable_refs(&child, &si), + None => v2_rt::rc_empty_map::(), +}, + ExprData::ExprLambda => collect_callable_refs(&lambda_body(texpr.clone()), &si), + ExprData::ExprForEach => { + let col = collect_callable_refs(&foreach_collection(texpr.clone()), &si); +v2_rt::rc_map_merge(col, collect_callable_refs(&foreach_body(texpr.clone()), &si)) +}, + ExprData::ExprRecordLit { .. } => texpr.children.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, field: Rc| v2_rt::rc_map_merge(acc, collect_callable_refs(&arg_value(&field), &si))), + _ => v2_rt::rc_empty_map::(), +} }) } pub fn fold_terminal_expr(mut body: Rc) -> Rc { loop { match (*body.expr_data.clone()).clone() { - ExprData::ExprLet => match let_body(body.clone()) { - Some(inner) => { - let __tco_0 = inner.clone(); - body = __tco_0; - continue; - } - None => { - break body.clone(); - } - }, - ExprData::ExprBlock => match body.children.clone().last().cloned() { - Some(last_child) => { - let __tco_0 = last_child.clone(); - body = __tco_0; - continue; - } - None => { - break body.clone(); - } - }, - _ => { - break body.clone(); - } - } - } + ExprData::ExprLet => { match let_body(body.clone()) { + Some(inner) => { { + let __tco_0 = inner.clone(); +body = __tco_0; +continue; +} }, + None => { break body.clone(); }, +} }, + ExprData::ExprBlock => { match body.children.clone().last().cloned() { + Some(last_child) => { { + let __tco_0 = last_child.clone(); +body = __tco_0; +continue; +} }, + None => { break body.clone(); }, +} }, + _ => { break body.clone(); }, +} +} } pub fn empty_fold_acc_use_summary() -> Rc { Rc::new(FoldAccUseSummary { - whole_acc_uses: 0, - field_moves: Rc::new(vec![]), - nested_acc_refs: false, - }) + whole_acc_uses: 0, + field_moves: Rc::new(vec![]), + nested_acc_refs: false, +}) } -pub fn merge_fold_acc_use_summaries( - left: &Rc, - right: &Rc, -) -> Rc { +pub fn merge_fold_acc_use_summaries(left: &Rc, right: &Rc) -> Rc { Rc::new(FoldAccUseSummary { - whole_acc_uses: (left.whole_acc_uses.clone() + right.whole_acc_uses.clone()), - field_moves: v2_rt::concat(left.field_moves.clone(), right.field_moves.clone()), - nested_acc_refs: (left.nested_acc_refs.clone() || right.nested_acc_refs.clone()), - }) + whole_acc_uses: (left.whole_acc_uses.clone() + right.whole_acc_uses.clone()), + field_moves: v2_rt::concat(left.field_moves.clone(), right.field_moves.clone()), + nested_acc_refs: (left.nested_acc_refs.clone() || right.nested_acc_refs.clone()), +}) } -pub fn summarize_fold_acc_uses( - node: &Rc, - acc_name: &String, - si: &Rc>>, - inside_nested: bool, -) -> Rc { +pub fn summarize_fold_acc_uses(node: &Rc, acc_name: &String, si: &Rc>>, inside_nested: bool) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*node.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - if (expr_var_name_at(node.clone(), si.clone()).as_str() - == acc_name.clone().as_str()) - { - if inside_nested.clone() { - Rc::new(FoldAccUseSummary { - whole_acc_uses: 0, - field_moves: Rc::new(vec![]), - nested_acc_refs: true, - }) - } else { - Rc::new(FoldAccUseSummary { - whole_acc_uses: 1, - field_moves: Rc::new(vec![]), - nested_acc_refs: false, - }) - } - } else { - empty_fold_acc_use_summary() - } - } - ExprData::ExprFieldAccess { .. } => { - let base = field_access_base(node.clone()); - let is_direct = match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - (expr_var_name_at(base.clone(), si.clone()).as_str() - == acc_name.clone().as_str()) - } - _ => false, - }; - if is_direct { - if inside_nested.clone() { - Rc::new(FoldAccUseSummary { - whole_acc_uses: 0, - field_moves: Rc::new(vec![]), - nested_acc_refs: true, - }) - } else { - Rc::new(FoldAccUseSummary { - whole_acc_uses: 0, - field_moves: Rc::new(vec![field_access_field_at( - node.clone(), - si.clone(), - )]), - nested_acc_refs: false, - }) - } - } else { - node.children.clone().iter().cloned().fold( - empty_fold_acc_use_summary(), - |acc: Rc, child: Rc| { - merge_fold_acc_use_summaries( - &acc, - &summarize_fold_acc_uses( - &child, - &acc_name, - &si, - inside_nested.clone(), - ), - ) - }, - ) - } + ExprData::ExprVar { .. } => if (expr_var_name_at(node.clone(), si.clone()).as_str() == acc_name.clone().as_str()) { + if inside_nested.clone() { + Rc::new(FoldAccUseSummary { + whole_acc_uses: 0, + field_moves: Rc::new(vec![]), + nested_acc_refs: true, +}) + } else { + Rc::new(FoldAccUseSummary { + whole_acc_uses: 1, + field_moves: Rc::new(vec![]), + nested_acc_refs: false, +}) } - ExprData::ExprLambda => { - let body_summary = - summarize_fold_acc_uses(&lambda_body(node.clone()), &acc_name, &si, true); - if (((body_summary.whole_acc_uses.clone() > 0) - || ((body_summary.field_moves.clone().len() as i64) > 0)) - || body_summary.nested_acc_refs.clone()) - { + } else { + empty_fold_acc_use_summary() + }, + ExprData::ExprFieldAccess { .. } => { + let base = field_access_base(node.clone()); +let is_direct = match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => (expr_var_name_at(base.clone(), si.clone()).as_str() == acc_name.clone().as_str()), + _ => false, +}; +if is_direct { + if inside_nested.clone() { Rc::new(FoldAccUseSummary { - whole_acc_uses: 0, - field_moves: Rc::new(vec![]), - nested_acc_refs: true, - }) + whole_acc_uses: 0, + field_moves: Rc::new(vec![]), + nested_acc_refs: true, +}) } else { - empty_fold_acc_use_summary() - } - } - ExprData::ExprForEach => { - let coll_summary = summarize_fold_acc_uses( - &foreach_collection(node.clone()), - &acc_name, - &si, - inside_nested.clone(), - ); - let body_summary = - summarize_fold_acc_uses(&foreach_body(node.clone()), &acc_name, &si, true); - let nested_summary = if (((body_summary.whole_acc_uses.clone() > 0) - || ((body_summary.field_moves.clone().len() as i64) > 0)) - || body_summary.nested_acc_refs.clone()) - { Rc::new(FoldAccUseSummary { - whole_acc_uses: 0, - field_moves: Rc::new(vec![]), - nested_acc_refs: true, - }) - } else { - empty_fold_acc_use_summary() - }; - merge_fold_acc_use_summaries(&coll_summary, &nested_summary) - } - _ => node.children.clone().iter().cloned().fold( - empty_fold_acc_use_summary(), - |acc: Rc, child: Rc| { - merge_fold_acc_use_summaries( - &acc, - &summarize_fold_acc_uses(&child, &acc_name, &si, inside_nested.clone()), - ) - }, - ), - } + whole_acc_uses: 0, + field_moves: Rc::new(vec![field_access_field_at(node.clone(), si.clone())]), + nested_acc_refs: false, +}) + } + } else { + node.children.clone().iter().cloned().fold(empty_fold_acc_use_summary(), |acc: Rc, child: Rc| merge_fold_acc_use_summaries(&acc, &summarize_fold_acc_uses(&child, &acc_name, &si, inside_nested.clone()))) + } +}, + ExprData::ExprLambda => { + let body_summary = summarize_fold_acc_uses(&lambda_body(node.clone()), &acc_name, &si, true); +if (((body_summary.whole_acc_uses.clone() > 0) || ((body_summary.field_moves.clone().len() as i64) > 0)) || body_summary.nested_acc_refs.clone()) { + Rc::new(FoldAccUseSummary { + whole_acc_uses: 0, + field_moves: Rc::new(vec![]), + nested_acc_refs: true, +}) + } else { + empty_fold_acc_use_summary() + } +}, + ExprData::ExprForEach => { + let coll_summary = summarize_fold_acc_uses(&foreach_collection(node.clone()), &acc_name, &si, inside_nested.clone()); +let body_summary = summarize_fold_acc_uses(&foreach_body(node.clone()), &acc_name, &si, true); +let nested_summary = if (((body_summary.whole_acc_uses.clone() > 0) || ((body_summary.field_moves.clone().len() as i64) > 0)) || body_summary.nested_acc_refs.clone()) { + Rc::new(FoldAccUseSummary { + whole_acc_uses: 0, + field_moves: Rc::new(vec![]), + nested_acc_refs: true, +}) + } else { + empty_fold_acc_use_summary() + }; +merge_fold_acc_use_summaries(&coll_summary, &nested_summary) +}, + _ => node.children.clone().iter().cloned().fold(empty_fold_acc_use_summary(), |acc: Rc, child: Rc| merge_fold_acc_use_summaries(&acc, &summarize_fold_acc_uses(&child, &acc_name, &si, inside_nested.clone()))), +} }) } -pub fn fold_lambda_acc_use_summary( - lambda_node: &Rc, - acc_name: String, - si: Rc>>, -) -> Rc { +pub fn fold_lambda_acc_use_summary(lambda_node: &Rc, acc_name: String, si: Rc>>) -> Rc { match (*lambda_node.expr_data.clone()).clone() { - ExprData::ExprLambda => { - summarize_fold_acc_uses(&lambda_body(lambda_node.clone()), &acc_name, &si, false) - } - _ => empty_fold_acc_use_summary(), - } + ExprData::ExprLambda => summarize_fold_acc_uses(&lambda_body(lambda_node.clone()), &acc_name, &si, false), + _ => empty_fold_acc_use_summary(), +} } -pub fn fold_body_constructs_acc_struct( - lambda_node: &Rc, - acc_type_name: String, - si: Rc>>, -) -> bool { +pub fn fold_body_constructs_acc_struct(lambda_node: &Rc, acc_type_name: String, si: Rc>>) -> bool { match (*lambda_node.expr_data.clone()).clone() { - ExprData::ExprLambda => { - let body = lambda_body(lambda_node.clone()); - let terminal = fold_terminal_expr(body); - match (*terminal.expr_data.clone()).clone() { - ExprData::ExprRecordLit { .. } => { - (authored_name_at(si, &terminal).as_str() == acc_type_name.as_str()) - } - _ => false, - } - } - _ => false, - } + ExprData::ExprLambda => { + let body = lambda_body(lambda_node.clone()); +let terminal = fold_terminal_expr(body); +match (*terminal.expr_data.clone()).clone() { + ExprData::ExprRecordLit { .. } => (authored_name_at(si, &terminal).as_str() == acc_type_name.as_str()), + _ => false, +} +}, + _ => false, +} } -pub fn fold_body_safe_field_moves( - lambda_node: Rc, - acc_name: String, - si: Rc>>, -) -> bool { +pub fn fold_body_safe_field_moves(lambda_node: Rc, acc_name: String, si: Rc>>) -> bool { { let summary = fold_lambda_acc_use_summary(&lambda_node, acc_name, si); - let deduped = summary.field_moves.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |seen: Rc>, field: String| { - v2_rt::rc_map_insert(seen, field.clone(), true) - }, - ); - ((!summary.nested_acc_refs.clone() && (summary.whole_acc_uses.clone() == 0)) - && ((Rc::new(v2_rt::map_keys(&deduped)).len() as i64) - == (summary.field_moves.clone().len() as i64))) - } +let deduped = summary.field_moves.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |seen: Rc>, field: String| v2_rt::rc_map_insert(seen, field.clone(), true)); +((!summary.nested_acc_refs.clone() && (summary.whole_acc_uses.clone() == 0)) && ((Rc::new(v2_rt::map_keys(&deduped)).len() as i64) == (summary.field_moves.clone().len() as i64))) +} } -pub fn fold_body_consumes_acc_once( - lambda_node: Rc, - acc_name: String, - si: Rc>>, -) -> bool { +pub fn fold_body_consumes_acc_once(lambda_node: Rc, acc_name: String, si: Rc>>) -> bool { { let summary = fold_lambda_acc_use_summary(&lambda_node, acc_name, si); - ((!summary.nested_acc_refs.clone() && (summary.whole_acc_uses.clone() == 1)) - && ((summary.field_moves.clone().len() as i64) == 0)) - } +((!summary.nested_acc_refs.clone() && (summary.whole_acc_uses.clone() == 1)) && ((summary.field_moves.clone().len() as i64) == 0)) +} } -pub fn analyze_single_fold( - method_call: &Rc, - si: &Rc>>, -) -> Rc { +pub fn analyze_single_fold(method_call: &Rc, si: &Rc>>) -> Rc { { let args = method_arg_nodes(method_call.clone()); - let init_arg_node = match args.clone().first().cloned() { - Some(a) => arg_value(&a), - None => method_call.clone(), - }; - let fold_lambda_node = match args.clone().get(1 as usize).cloned() { - Some(a) => arg_value(&a), - None => method_call.clone(), - }; - let acc_param_name = match (*fold_lambda_node.expr_data.clone()).clone() { - ExprData::ExprLambda => { - match lambda_param_names_at(fold_lambda_node.clone(), si.clone()) - .first() - .cloned() - { - Some(n) => n.clone(), - None => "".to_string(), - } - } - _ => "".to_string(), - }; - let acc_type_name = match init_arg_node.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: type_node, .. - }) => authored_name_at(si.clone(), &type_node), - _ => "".to_string(), - }; - let cond_required = match init_arg_node.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { - node: type_node, .. - }) => (type_node.return_cardinality.clone() == Cardinality::Required), - _ => false, - }; - let cond_struct = - fold_body_constructs_acc_struct(&fold_lambda_node, acc_type_name.clone(), si.clone()); - let cond_whole_acc = fold_body_consumes_acc_once( - fold_lambda_node.clone(), - acc_param_name.clone(), - si.clone(), - ); - let cond_safe = fold_body_safe_field_moves( - fold_lambda_node.clone(), - acc_param_name.clone(), - si.clone(), - ); - let eligible = ((cond_required - && (acc_type_name.clone().as_str() != "".to_string().as_str())) - && ((cond_struct.clone() && cond_safe.clone()) || cond_whole_acc.clone())); - Rc::new(FoldAccUnwrapProof { - site_key: (method_call.span.clone().start.clone()).to_string(), - acc_param_name: acc_param_name.clone(), - acc_type_name: acc_type_name.clone(), - body_constructs_acc: cond_struct.clone(), - whole_acc_single_use: cond_whole_acc.clone(), - safe_field_moves: cond_safe.clone(), - eligible: eligible, - }) - } -} - -pub fn analyze_ownership( - func_name: String, - params: Rc>>, - body: Rc, - si: &Rc>>, -) -> Rc { +let init_arg_node = match args.clone().first().cloned() { + Some(a) => arg_value(&a), + None => method_call.clone(), +}; +let fold_lambda_node = match args.clone().get(1 as usize).cloned() { + Some(a) => arg_value(&a), + None => method_call.clone(), +}; +let acc_param_name = match (*fold_lambda_node.expr_data.clone()).clone() { + ExprData::ExprLambda => match lambda_param_names_at(fold_lambda_node.clone(), si.clone()).first().cloned() { + Some(n) => n.clone(), + None => "".to_string(), +}, + _ => "".to_string(), +}; +let acc_type_name = match init_arg_node.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: type_node, .. }) => authored_name_at(si.clone(), &type_node), + _ => "".to_string(), +}; +let cond_required = match init_arg_node.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: type_node, .. }) => (type_node.return_cardinality.clone() == Cardinality::Required), + _ => false, +}; +let cond_struct = fold_body_constructs_acc_struct(&fold_lambda_node, acc_type_name.clone(), si.clone()); +let cond_whole_acc = fold_body_consumes_acc_once(fold_lambda_node.clone(), acc_param_name.clone(), si.clone()); +let cond_safe = fold_body_safe_field_moves(fold_lambda_node.clone(), acc_param_name.clone(), si.clone()); +let eligible = ((cond_required && (acc_type_name.clone().as_str() != "".to_string().as_str())) && ((cond_struct.clone() && cond_safe.clone()) || cond_whole_acc.clone())); +Rc::new(FoldAccUnwrapProof { + site_key: (method_call.span.clone().start.clone()).to_string(), + acc_param_name: acc_param_name.clone(), + acc_type_name: acc_type_name.clone(), + body_constructs_acc: cond_struct.clone(), + whole_acc_single_use: cond_whole_acc.clone(), + safe_field_moves: cond_safe.clone(), + eligible: eligible, +}) +} +} + +pub fn analyze_ownership(func_name: String, params: Rc>>, body: Rc, si: &Rc>>) -> Rc { { - let initial = - params - .iter() - .cloned() - .fold(empty_usage_accum(), |acc: Rc, p: Rc| { - let acc = Rc::try_unwrap(acc).unwrap_or_else(|rc| (*rc).clone()); - { - let p_name = authored_name_at(si.clone(), &p); - Rc::new(UsageAccum { - bindings: v2_rt::rc_map_insert( - acc.bindings, - p_name.clone(), - Rc::new(BindingUsage { - name: p_name.clone(), - binding_kind: None, - consumers: Rc::new(vec![]), - }), - ), - fold_call_nodes: acc.fold_call_nodes, - }) - } - }); - let result = walk_expr(initial, &body, true, &si); - let binding_list = Rc::new(v2_rt::map_values(&result.bindings.clone())); - let decisions = Rc::new({ - let mut __result = Vec::new(); - for usage in binding_list.iter().cloned() { - __result.push(make_decision(&usage)); - } - __result - }); - let fold_proofs = Rc::new({ - let mut __result = Vec::new(); - for n in result.fold_call_nodes.clone().iter().cloned() { - __result.push(analyze_single_fold(&n, &si)); - } - __result - }); - Rc::new(OwnershipProof { - func_name: func_name, - bindings: result.bindings.clone(), - decisions: decisions, - fold_acc_unwrap: fold_proofs, - }) - } + let initial = params.iter().cloned().fold(empty_usage_accum(), |acc: Rc, p: Rc| { let acc = Rc::try_unwrap(acc).unwrap_or_else(|rc| (*rc).clone()); { + let p_name = authored_name_at(si.clone(), &p); +Rc::new(UsageAccum { + bindings: v2_rt::rc_map_insert(acc.bindings, p_name.clone(), Rc::new(BindingUsage { + name: p_name.clone(), + binding_kind: None, + consumers: Rc::new(vec![]), +})), + fold_call_nodes: acc.fold_call_nodes, +}) +} }); +let result = walk_expr(initial, &body, true, &si); +let binding_list = Rc::new(v2_rt::map_values(&result.bindings.clone())); +let decisions = Rc::new({ let mut __result = Vec::new(); for usage in binding_list.iter().cloned() { __result.push(make_decision(&usage)); } __result }); +let fold_proofs = Rc::new({ let mut __result = Vec::new(); for n in result.fold_call_nodes.clone().iter().cloned() { __result.push(analyze_single_fold(&n, &si)); } __result }); +Rc::new(OwnershipProof { + func_name: func_name, + bindings: result.bindings.clone(), + decisions: decisions, + fold_acc_unwrap: fold_proofs, +}) +} } diff --git a/src/v2/stage0/src/v2_compiler_parse.rs b/src/v2/stage0/src/v2_compiler_parse.rs index 5b181394296..f7709af5dd5 100644 --- a/src/v2/stage0/src/v2_compiler_parse.rs +++ b/src/v2/stage0/src/v2_compiler_parse.rs @@ -1,68 +1,35 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.parse +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{module_node, import_node, Node, InferredNode, Connective, is_container_type, Cardinality, make_param_node, param_node_type_expr, param_node_default_value, make_field_node, field_node_name_at, field_node_type_expr, field_node_cardinality, field_node_default_value, field_node_from_key, make_variant_node, variant_node_name_at, variant_node_fields, leaf_node_with_span, ExprData, make_expr_node, make_named_expr_node, make_expr_error_node, expr_var_name_at, field_access_field_at, expr_call_func_at, make_arg_node, arg_name_at, arg_value, make_arm_node, make_field_init_node, make_resource_use_node, make_text_part_node, make_interp_part_node, MatchPattern, make_field_binding_node, field_binding_pattern, LiteralValue, ExprErrorKind, BinOp, UnaryOpKind, StringPart, local_transport_node, rest_transport_node, shell_transport_node, file_transport_node, transport_url_key, transport_path_key, transport_method_key, transport_path_template_key, transport_query_key, transport_body_key, transport_stdin_key, transport_response_format_key, transport_headers_key, service_config_properties, OperationModifier, Token, TokenShape, SourceSpan, make_span, ErrorNode, make_error_node, with_required_cardinality, error_type, is_compiler_error, node_name_span, no_span, NewlineIndex, authored_name_at, InternTable, InternResult, empty_intern_table, intern, pre_intern_tokens, CompilerDiagnostic}; +use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable}; +use crate::v2_std_core::Connective::{Conj, Disj, NoConnective, Arrow}; +use crate::v2_std_core::Cardinality::{Required, CardOptional}; +use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit, ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp, ExprBlock, ExprCast, ExprForEach, ExprIndex, ExprSlice, ExprReturn}; +use crate::v2_std_core::MatchPattern::{Bind, LitPattern, VariantPattern, Wildcard}; +use crate::v2_std_core::LiteralValue::{LitStr, LitInt, LitFloat, LitBool, LitNull}; +use crate::v2_std_core::ExprErrorKind::{ParseRecoveryError}; +use crate::v2_std_core::BinOp::{Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Gt, Le, Ge, And, Or, NullCoalesce}; +use crate::v2_std_core::UnaryOpKind::{Not, Neg}; +use crate::v2_std_core::StringPart::{Text, Interpolation}; +use crate::v2_std_core::OperationModifier::{Idempotent, Readonly, Hermetic}; +use crate::v2_std_core::TokenShape::{ShKeyword, ShLBrace, ShRBrace, ShLParen, ShRParen, ShLBracket, ShRBracket, ShLt, ShGt, ShLe, ShGe, ShFatArrow, ShArrow, ShColon, ShComma, ShDot, ShDotDot, ShEq, ShEqEq, ShNe, ShPlus, ShMinus, ShStar, ShSlash, ShPercent, ShBang, ShAnd, ShOr, ShQuestion, ShNullCoalesce, ShPipe, ShPipeArrow, ShLitStr, ShLitInt, ShLitFloat, ShIdent, ShStrBegin, ShStrMid, ShStrEnd, ShNewline, ShEof, ShUnknown}; +use crate::v2_std_core::CompilerDiagnostic::{ParseError}; +pub use crate::v2_compiler_languages::{ItemForm, ItemFormKind, BodyKind, OperatorSpec, SyntaxSpec}; +use crate::v2_compiler_languages::ItemFormKind::{OtherForm}; +use crate::v2_compiler_languages::BodyKind::{ExprBody, BlockBody, TypeBody, ValueBody, NoBody, ServiceBody, ResourceBody}; +pub use crate::extdeps_languages_dag_syntax::{dag_syntax_spec, dag_non_name_keywords}; use self::AdvanceResult::*; use self::EatResult::*; use self::ExpectedToken::*; -use self::ParserCallIdentity::*; use self::ParserHelperIdentity::*; +use self::ParserCallIdentity::*; use self::ParserResultWitness::*; -pub use crate::extdeps_languages_dag_syntax::{dag_non_name_keywords, dag_syntax_spec}; -use crate::v2_compiler_languages::BodyKind::{ - BlockBody, ExprBody, NoBody, ResourceBody, ServiceBody, TypeBody, ValueBody, -}; -use crate::v2_compiler_languages::ItemFormKind::OtherForm; -pub use crate::v2_compiler_languages::{ - BodyKind, ItemForm, ItemFormKind, OperatorSpec, SyntaxSpec, -}; -use crate::v2_rt; -use crate::v2_std_core::BinOp::{ - Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, NullCoalesce, Or, Sub, -}; -use crate::v2_std_core::Cardinality::{CardOptional, Required}; -use crate::v2_std_core::CompilerDiagnostic::ParseError; -use crate::v2_std_core::Connective::{Arrow, Conj, Disj, NoConnective}; -use crate::v2_std_core::ExprData::{ - ExprBinOp, ExprBlock, ExprCall, ExprCast, ExprFieldAccess, ExprForEach, ExprIf, ExprIndex, - ExprLambda, ExprLet, ExprListLit, ExprLiteral, ExprMatch, ExprMethodCall, ExprRecordLit, - ExprReturn, ExprSlice, ExprStringInterp, ExprUnaryOp, ExprVar, NoExprData, -}; -use crate::v2_std_core::ExprErrorKind::ParseRecoveryError; -use crate::v2_std_core::InferredNode::{CompilerError, Resolved, TypeVariable}; -use crate::v2_std_core::LiteralValue::{LitBool, LitFloat, LitInt, LitNull, LitStr}; -use crate::v2_std_core::MatchPattern::{Bind, LitPattern, VariantPattern, Wildcard}; -use crate::v2_std_core::OperationModifier::{Hermetic, Idempotent, Readonly}; -use crate::v2_std_core::StringPart::{Interpolation, Text}; -use crate::v2_std_core::TokenShape::{ - ShAnd, ShArrow, ShBang, ShColon, ShComma, ShDot, ShDotDot, ShEof, ShEq, ShEqEq, ShFatArrow, - ShGe, ShGt, ShIdent, ShKeyword, ShLBrace, ShLBracket, ShLParen, ShLe, ShLitFloat, ShLitInt, - ShLitStr, ShLt, ShMinus, ShNe, ShNewline, ShNullCoalesce, ShOr, ShPercent, ShPipe, ShPipeArrow, - ShPlus, ShQuestion, ShRBrace, ShRBracket, ShRParen, ShSlash, ShStar, ShStrBegin, ShStrEnd, - ShStrMid, ShUnknown, -}; -use crate::v2_std_core::UnaryOpKind::{Neg, Not}; -pub use crate::v2_std_core::{ - arg_name_at, arg_value, authored_name_at, empty_intern_table, error_type, expr_call_func_at, - expr_var_name_at, field_access_field_at, field_binding_pattern, field_node_cardinality, - field_node_default_value, field_node_from_key, field_node_name_at, field_node_type_expr, - file_transport_node, import_node, intern, is_compiler_error, is_container_type, - leaf_node_with_span, local_transport_node, make_arg_node, make_arm_node, make_error_node, - make_expr_error_node, make_expr_node, make_field_binding_node, make_field_init_node, - make_field_node, make_interp_part_node, make_named_expr_node, make_param_node, - make_resource_use_node, make_span, make_text_part_node, make_variant_node, module_node, - no_span, node_name_span, param_node_default_value, param_node_type_expr, pre_intern_tokens, - rest_transport_node, service_config_properties, shell_transport_node, transport_body_key, - transport_headers_key, transport_method_key, transport_path_key, transport_path_template_key, - transport_query_key, transport_response_format_key, transport_stdin_key, transport_url_key, - variant_node_fields, variant_node_name_at, with_required_cardinality, BinOp, Cardinality, - CompilerDiagnostic, Connective, ErrorNode, ExprData, ExprErrorKind, InferredNode, InternResult, - InternTable, LiteralValue, MatchPattern, NewlineIndex, Node, OperationModifier, SourceSpan, - StringPart, Token, TokenShape, UnaryOpKind, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct ParseContext { @@ -317,7 +284,9 @@ pub struct BindingPower { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum ExpectedToken { - ExpectKeyword { text: String }, + ExpectKeyword { + text: String, + }, ExpectLBrace, ExpectRBrace, ExpectLParen, @@ -511,6 +480,14 @@ pub struct FromKeyResult { pub err: Option>, } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct TypeInhabitsResult { + pub type_expr: Option>, + pub tokens: Rc>>, + pub ctx: Rc, + pub err: Option>, +} + #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct PostfixResult { pub expr: Rc, @@ -675,8 +652,12 @@ pub enum ParserHelperIdentity { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum ParserCallIdentity { - ParserCallHelper { helper: ParserHelperIdentity }, - ParserCallFunction { name: String }, + ParserCallHelper { + helper: ParserHelperIdentity, + }, + ParserCallFunction { + name: String, + }, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -685,7 +666,9 @@ pub enum ParserResultWitness { ParserWitnessAdvance, ParserWitnessExpect, ParserWitnessEat, - ParserWitnessCall { callee: Rc }, + ParserWitnessCall { + callee: Rc, + }, ParserWitnessOpaque, } impl ParserResultWitness { @@ -708,482 +691,424 @@ pub struct DescResult { pub fn token_span(tok: Option>) -> Rc { match tok { - Some(t) => t.span.clone(), - None => make_span(0, 0), - } + Some(t) => t.span.clone(), + None => make_span(0, 0), +} } pub fn advance(tokens: &Rc>>) -> Rc { match tokens.clone().first().cloned() { - Some(t) => Rc::new(AdvanceResult::AdvanceOk { - token: t.clone(), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - }), - None => Rc::new(AdvanceResult::AdvanceEof), - } + Some(t) => Rc::new(AdvanceResult::AdvanceOk { + token: t.clone(), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), +}), + None => Rc::new(AdvanceResult::AdvanceEof), +} } pub fn parse_error(msg: String, span: Rc) -> Rc { - make_error_node( - Rc::new(CompilerDiagnostic::ParseError { - message: msg, - span: span, - }), - "".to_string(), - ) + make_error_node(Rc::new(CompilerDiagnostic::ParseError { + message: msg, + span: span, +}), "".to_string()) } pub fn has_err(err: Option>) -> bool { match err { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } pub fn parse_string_literal_value(tokens: &Rc>>) -> Rc { { let tok = tokens.clone().first().cloned(); - match tok.clone() { - Some(t) => match t.shape.clone() { - TokenShape::ShLitStr => Rc::new(StringLitResult { - value: t.text.clone(), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - err: None, - }), - _ => Rc::new(StringLitResult { - value: "".to_string(), - tokens: tokens.clone(), - err: Some(parse_error( - "expected string literal".to_string(), - token_span(tok.clone()), - )), - }), - }, - None => Rc::new(StringLitResult { - value: "".to_string(), - tokens: tokens.clone(), - err: Some(parse_error( - "expected string literal".to_string(), - make_span(0, 0), - )), - }), - } - } +match tok.clone() { + Some(t) => match t.shape.clone() { + TokenShape::ShLitStr => Rc::new(StringLitResult { + value: t.text.clone(), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + err: None, +}), + _ => Rc::new(StringLitResult { + value: "".to_string(), + tokens: tokens.clone(), + err: Some(parse_error("expected string literal".to_string(), token_span(tok.clone()))), +}), +}, + None => Rc::new(StringLitResult { + value: "".to_string(), + tokens: tokens.clone(), + err: Some(parse_error("expected string literal".to_string(), make_span(0, 0))), +}), +} +} } pub fn parse_int_literal_value(tokens: &Rc>>) -> Rc { { let tok = tokens.clone().first().cloned(); - match tok.clone() { - Some(t) => match t.shape.clone() { - TokenShape::ShLitInt => { - let n_opt = v2_rt::parse_int(t.text.clone()); - match n_opt { - Some(n) => Rc::new(IntLitResult { - value: n.clone(), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - err: None, - }), - None => Rc::new(IntLitResult { - value: 0, - tokens: tokens.clone(), - err: Some(parse_error( - v2_rt::concat( - v2_rt::concat( - "internal: ShLitInt token text not parseable as int: '" - .to_string(), - t.text.clone(), - ), - "'".to_string(), - ), - token_span(tok.clone()), - )), - }), - } - } - _ => Rc::new(IntLitResult { - value: 0, - tokens: tokens.clone(), - err: Some(parse_error( - "expected integer literal".to_string(), - token_span(tok.clone()), - )), - }), - }, - None => Rc::new(IntLitResult { - value: 0, - tokens: tokens.clone(), - err: Some(parse_error( - "expected integer literal".to_string(), - make_span(0, 0), - )), - }), - } - } +match tok.clone() { + Some(t) => match t.shape.clone() { + TokenShape::ShLitInt => { + let n_opt = v2_rt::parse_int(t.text.clone()); +match n_opt { + Some(n) => Rc::new(IntLitResult { + value: n.clone(), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + err: None, +}), + None => Rc::new(IntLitResult { + value: 0, + tokens: tokens.clone(), + err: Some(parse_error(v2_rt::concat(v2_rt::concat("internal: ShLitInt token text not parseable as int: '".to_string(), t.text.clone()), "'".to_string()), token_span(tok.clone()))), +}), +} +}, + _ => Rc::new(IntLitResult { + value: 0, + tokens: tokens.clone(), + err: Some(parse_error("expected integer literal".to_string(), token_span(tok.clone()))), +}), +}, + None => Rc::new(IntLitResult { + value: 0, + tokens: tokens.clone(), + err: Some(parse_error("expected integer literal".to_string(), make_span(0, 0))), +}), +} +} } pub fn is_ident_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShIdent => true, - _ => false, - } + TokenShape::ShIdent => true, + _ => false, +} } pub fn is_lit_str_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShLitStr => true, - _ => false, - } + TokenShape::ShLitStr => true, + _ => false, +} } pub fn is_lit_int_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShLitInt => true, - _ => false, - } + TokenShape::ShLitInt => true, + _ => false, +} } pub fn is_lit_float_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShLitFloat => true, - _ => false, - } + TokenShape::ShLitFloat => true, + _ => false, +} } pub fn is_str_begin_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShStrBegin => true, - _ => false, - } + TokenShape::ShStrBegin => true, + _ => false, +} } pub fn is_str_mid_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShStrMid => true, - _ => false, - } + TokenShape::ShStrMid => true, + _ => false, +} } pub fn is_str_end_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShStrEnd => true, - _ => false, - } + TokenShape::ShStrEnd => true, + _ => false, +} } pub fn is_unknown_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShUnknown => true, - _ => false, - } + TokenShape::ShUnknown => true, + _ => false, +} } pub fn is_newline_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShNewline => true, - _ => false, - } + TokenShape::ShNewline => true, + _ => false, +} } pub fn is_eof_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShEof => true, - _ => false, - } + TokenShape::ShEof => true, + _ => false, +} } pub fn is_keyword_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShKeyword => true, - _ => false, - } + TokenShape::ShKeyword => true, + _ => false, +} } pub fn is_lbrace_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShLBrace => true, - _ => false, - } + TokenShape::ShLBrace => true, + _ => false, +} } pub fn is_rbrace_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShRBrace => true, - _ => false, - } + TokenShape::ShRBrace => true, + _ => false, +} } pub fn is_lparen_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShLParen => true, - _ => false, - } + TokenShape::ShLParen => true, + _ => false, +} } pub fn is_rparen_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShRParen => true, - _ => false, - } + TokenShape::ShRParen => true, + _ => false, +} } pub fn is_lbracket_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShLBracket => true, - _ => false, - } + TokenShape::ShLBracket => true, + _ => false, +} } pub fn is_rbracket_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShRBracket => true, - _ => false, - } + TokenShape::ShRBracket => true, + _ => false, +} } pub fn is_lt_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShLt => true, - _ => false, - } + TokenShape::ShLt => true, + _ => false, +} } pub fn is_gt_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShGt => true, - _ => false, - } + TokenShape::ShGt => true, + _ => false, +} } pub fn is_le_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShLe => true, - _ => false, - } + TokenShape::ShLe => true, + _ => false, +} } pub fn is_ge_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShGe => true, - _ => false, - } + TokenShape::ShGe => true, + _ => false, +} } pub fn is_fat_arrow_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShFatArrow => true, - _ => false, - } + TokenShape::ShFatArrow => true, + _ => false, +} } pub fn is_arrow_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShArrow => true, - _ => false, - } + TokenShape::ShArrow => true, + _ => false, +} } pub fn is_colon_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShColon => true, - _ => false, - } + TokenShape::ShColon => true, + _ => false, +} } pub fn is_comma_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShComma => true, - _ => false, - } + TokenShape::ShComma => true, + _ => false, +} } pub fn is_dot_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShDot => true, - _ => false, - } + TokenShape::ShDot => true, + _ => false, +} } pub fn is_dot_dot_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShDotDot => true, - _ => false, - } + TokenShape::ShDotDot => true, + _ => false, +} } pub fn is_eq_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShEq => true, - _ => false, - } + TokenShape::ShEq => true, + _ => false, +} } pub fn is_eq_eq_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShEqEq => true, - _ => false, - } + TokenShape::ShEqEq => true, + _ => false, +} } pub fn is_ne_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShNe => true, - _ => false, - } + TokenShape::ShNe => true, + _ => false, +} } pub fn is_plus_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShPlus => true, - _ => false, - } + TokenShape::ShPlus => true, + _ => false, +} } pub fn is_minus_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShMinus => true, - _ => false, - } + TokenShape::ShMinus => true, + _ => false, +} } pub fn is_star_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShStar => true, - _ => false, - } + TokenShape::ShStar => true, + _ => false, +} } pub fn is_slash_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShSlash => true, - _ => false, - } + TokenShape::ShSlash => true, + _ => false, +} } pub fn is_percent_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShPercent => true, - _ => false, - } + TokenShape::ShPercent => true, + _ => false, +} } pub fn is_bang_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShBang => true, - _ => false, - } + TokenShape::ShBang => true, + _ => false, +} } pub fn is_and_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShAnd => true, - _ => false, - } + TokenShape::ShAnd => true, + _ => false, +} } pub fn is_or_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShOr => true, - _ => false, - } + TokenShape::ShOr => true, + _ => false, +} } pub fn is_question_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShQuestion => true, - _ => false, - } + TokenShape::ShQuestion => true, + _ => false, +} } pub fn is_null_coalesce_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShNullCoalesce => true, - _ => false, - } + TokenShape::ShNullCoalesce => true, + _ => false, +} } pub fn is_pipe_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShPipe => true, - _ => false, - } + TokenShape::ShPipe => true, + _ => false, +} } pub fn is_pipe_arrow_shape(shape: TokenShape) -> bool { match shape { - TokenShape::ShPipeArrow => true, - _ => false, - } + TokenShape::ShPipeArrow => true, + _ => false, +} } pub fn tok_is_keyword(tok: Option>, kw: String) -> bool { match tok { - Some(t) => (is_keyword_shape(t.shape.clone()) && (t.text.clone().as_str() == kw.as_str())), - None => false, - } + Some(t) => (is_keyword_shape(t.shape.clone()) && (t.text.clone().as_str() == kw.as_str())), + None => false, +} } pub fn tok_keyword_text(tok: Option>) -> String { match tok { - Some(t) => { - if is_keyword_shape(t.shape.clone()) { - t.text.clone() - } else { - "".to_string() - } - } - None => "".to_string(), - } + Some(t) => if is_keyword_shape(t.shape.clone()) { + t.text.clone() + } else { + "".to_string() + }, + None => "".to_string(), +} } pub fn tok_is_ident(tok: Option>) -> bool { match tok { - Some(t) => is_ident_shape(t.shape.clone()), - None => false, - } + Some(t) => is_ident_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_ident_text(tok: Option>, text: String) -> bool { match tok { - Some(t) => (is_ident_shape(t.shape.clone()) && (t.text.clone().as_str() == text.as_str())), - None => false, - } + Some(t) => (is_ident_shape(t.shape.clone()) && (t.text.clone().as_str() == text.as_str())), + None => false, +} } -pub fn drop_leading_type_modifier( - tokens: &Rc>>, - modifier: String, -) -> Rc>> { +pub fn drop_leading_type_modifier(tokens: &Rc>>, modifier: String) -> Rc>> { if tok_is_ident_text(tokens.clone().first().cloned(), modifier) { - skip_newlines(Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - )) + skip_newlines(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>())) } else { tokens.clone() } @@ -1193,267 +1118,256 @@ pub fn type_body_tokens_after_modifiers(tokens: Rc>>) -> Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_optional_type_inhabits_clause(tokens: &Rc>>, ctx: Rc) -> Rc { if tok_is_ident_text(tokens.clone().first().cloned(), "inhabits".to_string()) { { - let r = parse_type_expr( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &ctx, - ); - Rc::new(TypeResult { - type_expr: r.type_expr.clone(), - tokens: skip_newlines(r.tokens.clone()), - ctx: r.ctx.clone(), - err: r.err.clone(), - }) - } + let r = parse_type_expr(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &ctx); +Rc::new(TypeInhabitsResult { + type_expr: Some(r.type_expr.clone()), + tokens: skip_newlines(r.tokens.clone()), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) +} } else { - Rc::new(TypeResult { - type_expr: leaf_type_node(&"".to_string(), &no_span()), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) + Rc::new(TypeInhabitsResult { + type_expr: None, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) } } +pub fn type_inhabits_properties(type_expr: Option>) -> Rc>> { + match type_expr { + Some(t) => Rc::new(vec![make_field_init_node(&"inhabits".to_string(), t.clone(), t.span.clone(), no_span())]), + None => Rc::new(vec![]), +} +} + pub fn tok_is_newline(tok: Option>) -> bool { match tok { - Some(t) => is_newline_shape(t.shape.clone()), - None => false, - } + Some(t) => is_newline_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_eof(tok: Option>) -> bool { match tok { - Some(t) => is_eof_shape(t.shape.clone()), - None => true, - } + Some(t) => is_eof_shape(t.shape.clone()), + None => true, +} } pub fn tok_is_lit_str(tok: Option>) -> bool { match tok { - Some(t) => is_lit_str_shape(t.shape.clone()), - None => false, - } + Some(t) => is_lit_str_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_lbrace(tok: Option>) -> bool { match tok { - Some(t) => is_lbrace_shape(t.shape.clone()), - None => false, - } + Some(t) => is_lbrace_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_rbrace(tok: Option>) -> bool { match tok { - Some(t) => is_rbrace_shape(t.shape.clone()), - None => false, - } + Some(t) => is_rbrace_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_lparen(tok: Option>) -> bool { match tok { - Some(t) => is_lparen_shape(t.shape.clone()), - None => false, - } + Some(t) => is_lparen_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_rparen(tok: Option>) -> bool { match tok { - Some(t) => is_rparen_shape(t.shape.clone()), - None => false, - } + Some(t) => is_rparen_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_lbracket(tok: Option>) -> bool { match tok { - Some(t) => is_lbracket_shape(t.shape.clone()), - None => false, - } + Some(t) => is_lbracket_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_rbracket(tok: Option>) -> bool { match tok { - Some(t) => is_rbracket_shape(t.shape.clone()), - None => false, - } + Some(t) => is_rbracket_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_colon(tok: Option>) -> bool { match tok { - Some(t) => is_colon_shape(t.shape.clone()), - None => false, - } + Some(t) => is_colon_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_comma(tok: Option>) -> bool { match tok { - Some(t) => is_comma_shape(t.shape.clone()), - None => false, - } + Some(t) => is_comma_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_dot(tok: Option>) -> bool { match tok { - Some(t) => is_dot_shape(t.shape.clone()), - None => false, - } + Some(t) => is_dot_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_dot_dot(tok: Option>) -> bool { match tok { - Some(t) => is_dot_dot_shape(t.shape.clone()), - None => false, - } + Some(t) => is_dot_dot_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_eq(tok: Option>) -> bool { match tok { - Some(t) => is_eq_shape(t.shape.clone()), - None => false, - } + Some(t) => is_eq_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_fat_arrow(tok: Option>) -> bool { match tok { - Some(t) => is_fat_arrow_shape(t.shape.clone()), - None => false, - } + Some(t) => is_fat_arrow_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_arrow(tok: Option>) -> bool { match tok { - Some(t) => is_arrow_shape(t.shape.clone()), - None => false, - } + Some(t) => is_arrow_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_lt(tok: Option>) -> bool { match tok { - Some(t) => is_lt_shape(t.shape.clone()), - None => false, - } + Some(t) => is_lt_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_gt(tok: Option>) -> bool { match tok { - Some(t) => is_gt_shape(t.shape.clone()), - None => false, - } + Some(t) => is_gt_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_pipe(tok: Option>) -> bool { match tok { - Some(t) => is_pipe_shape(t.shape.clone()), - None => false, - } + Some(t) => is_pipe_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_pipe_arrow(tok: Option>) -> bool { match tok { - Some(t) => is_pipe_arrow_shape(t.shape.clone()), - None => false, - } + Some(t) => is_pipe_arrow_shape(t.shape.clone()), + None => false, +} } pub fn tok_is_question(tok: Option>) -> bool { match tok { - Some(t) => is_question_shape(t.shape.clone()), - None => false, - } + Some(t) => is_question_shape(t.shape.clone()), + None => false, +} } pub fn tok_span(tok: Option>) -> Rc { match tok { - Some(t) => t.span.clone(), - None => make_span(0, 0), - } + Some(t) => t.span.clone(), + None => make_span(0, 0), +} } pub fn tok_keyword_to_name(tok: Option>) -> Option { match tok { - Some(t) => { - if is_name_keyword(&t) { - Some(t.text.clone()) - } else { - None - } - } - None => None, - } + Some(t) => if is_name_keyword(&t) { + Some(t.text.clone()) + } else { + None + }, + None => None, +} } pub fn tok_is_keyword_name(tok: Option>) -> bool { match tok_keyword_to_name(tok) { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } pub fn shape_display_name(shape: TokenShape) -> String { match shape { - TokenShape::ShKeyword => "keyword".to_string(), - TokenShape::ShLBrace => "LBrace".to_string(), - TokenShape::ShRBrace => "RBrace".to_string(), - TokenShape::ShLParen => "LParen".to_string(), - TokenShape::ShRParen => "RParen".to_string(), - TokenShape::ShLBracket => "LBracket".to_string(), - TokenShape::ShRBracket => "RBracket".to_string(), - TokenShape::ShLt => "Lt".to_string(), - TokenShape::ShGt => "Gt".to_string(), - TokenShape::ShLe => "Le".to_string(), - TokenShape::ShGe => "Ge".to_string(), - TokenShape::ShFatArrow => "FatArrow".to_string(), - TokenShape::ShArrow => "Arrow".to_string(), - TokenShape::ShColon => "Colon".to_string(), - TokenShape::ShComma => "Comma".to_string(), - TokenShape::ShDot => "Dot".to_string(), - TokenShape::ShDotDot => "DotDot".to_string(), - TokenShape::ShEq => "Eq".to_string(), - TokenShape::ShEqEq => "EqEq".to_string(), - TokenShape::ShNe => "Ne".to_string(), - TokenShape::ShPlus => "Plus".to_string(), - TokenShape::ShMinus => "Minus".to_string(), - TokenShape::ShStar => "Star".to_string(), - TokenShape::ShSlash => "Slash".to_string(), - TokenShape::ShPercent => "Percent".to_string(), - TokenShape::ShBang => "Bang".to_string(), - TokenShape::ShAnd => "And".to_string(), - TokenShape::ShOr => "Or".to_string(), - TokenShape::ShQuestion => "Question".to_string(), - TokenShape::ShNullCoalesce => "NullCoalesce".to_string(), - TokenShape::ShPipe => "Pipe".to_string(), - TokenShape::ShPipeArrow => "PipeArrow".to_string(), - TokenShape::ShLitStr => "LitStr".to_string(), - TokenShape::ShLitInt => "LitInt".to_string(), - TokenShape::ShLitFloat => "LitFloat".to_string(), - TokenShape::ShIdent => "Ident".to_string(), - TokenShape::ShStrBegin => "StrBegin".to_string(), - TokenShape::ShStrMid => "StrMid".to_string(), - TokenShape::ShStrEnd => "StrEnd".to_string(), - TokenShape::ShNewline => "Newline".to_string(), - TokenShape::ShEof => "Eof".to_string(), - TokenShape::ShUnknown => "Unknown".to_string(), - } + TokenShape::ShKeyword => "keyword".to_string(), + TokenShape::ShLBrace => "LBrace".to_string(), + TokenShape::ShRBrace => "RBrace".to_string(), + TokenShape::ShLParen => "LParen".to_string(), + TokenShape::ShRParen => "RParen".to_string(), + TokenShape::ShLBracket => "LBracket".to_string(), + TokenShape::ShRBracket => "RBracket".to_string(), + TokenShape::ShLt => "Lt".to_string(), + TokenShape::ShGt => "Gt".to_string(), + TokenShape::ShLe => "Le".to_string(), + TokenShape::ShGe => "Ge".to_string(), + TokenShape::ShFatArrow => "FatArrow".to_string(), + TokenShape::ShArrow => "Arrow".to_string(), + TokenShape::ShColon => "Colon".to_string(), + TokenShape::ShComma => "Comma".to_string(), + TokenShape::ShDot => "Dot".to_string(), + TokenShape::ShDotDot => "DotDot".to_string(), + TokenShape::ShEq => "Eq".to_string(), + TokenShape::ShEqEq => "EqEq".to_string(), + TokenShape::ShNe => "Ne".to_string(), + TokenShape::ShPlus => "Plus".to_string(), + TokenShape::ShMinus => "Minus".to_string(), + TokenShape::ShStar => "Star".to_string(), + TokenShape::ShSlash => "Slash".to_string(), + TokenShape::ShPercent => "Percent".to_string(), + TokenShape::ShBang => "Bang".to_string(), + TokenShape::ShAnd => "And".to_string(), + TokenShape::ShOr => "Or".to_string(), + TokenShape::ShQuestion => "Question".to_string(), + TokenShape::ShNullCoalesce => "NullCoalesce".to_string(), + TokenShape::ShPipe => "Pipe".to_string(), + TokenShape::ShPipeArrow => "PipeArrow".to_string(), + TokenShape::ShLitStr => "LitStr".to_string(), + TokenShape::ShLitInt => "LitInt".to_string(), + TokenShape::ShLitFloat => "LitFloat".to_string(), + TokenShape::ShIdent => "Ident".to_string(), + TokenShape::ShStrBegin => "StrBegin".to_string(), + TokenShape::ShStrMid => "StrMid".to_string(), + TokenShape::ShStrEnd => "StrEnd".to_string(), + TokenShape::ShNewline => "Newline".to_string(), + TokenShape::ShEof => "Eof".to_string(), + TokenShape::ShUnknown => "Unknown".to_string(), +} } pub fn token_display_name(token: &Rc) -> String { if is_keyword_shape(token.shape.clone()) { - v2_rt::concat( - "keyword '".to_string(), - v2_rt::concat(token.text.clone(), "'".to_string()), - ) + v2_rt::concat("keyword '".to_string(), v2_rt::concat(token.text.clone(), "'".to_string())) } else { shape_display_name(token.shape.clone()) } @@ -1461,213 +1375,170 @@ pub fn token_display_name(token: &Rc) -> String { pub fn expected_token_name(expected: Rc) -> String { match (*expected).clone() { - ExpectedToken::ExpectKeyword { text: kw, .. } => v2_rt::concat( - "keyword '".to_string(), - v2_rt::concat(kw.clone(), "'".to_string()), - ), - ExpectedToken::ExpectLBrace => "LBrace".to_string(), - ExpectedToken::ExpectRBrace => "RBrace".to_string(), - ExpectedToken::ExpectLParen => "LParen".to_string(), - ExpectedToken::ExpectRParen => "RParen".to_string(), - ExpectedToken::ExpectLBracket => "LBracket".to_string(), - ExpectedToken::ExpectRBracket => "RBracket".to_string(), - ExpectedToken::ExpectLt => "Lt".to_string(), - ExpectedToken::ExpectGt => "Gt".to_string(), - ExpectedToken::ExpectFatArrow => "FatArrow".to_string(), - ExpectedToken::ExpectArrow => "Arrow".to_string(), - ExpectedToken::ExpectColon => "Colon".to_string(), - ExpectedToken::ExpectComma => "Comma".to_string(), - ExpectedToken::ExpectDot => "Dot".to_string(), - ExpectedToken::ExpectEq => "Eq".to_string(), - ExpectedToken::ExpectQuestion => "Question".to_string(), - ExpectedToken::ExpectPipe => "Pipe".to_string(), - } + ExpectedToken::ExpectKeyword { text: kw, .. } => v2_rt::concat("keyword '".to_string(), v2_rt::concat(kw.clone(), "'".to_string())), + ExpectedToken::ExpectLBrace => "LBrace".to_string(), + ExpectedToken::ExpectRBrace => "RBrace".to_string(), + ExpectedToken::ExpectLParen => "LParen".to_string(), + ExpectedToken::ExpectRParen => "RParen".to_string(), + ExpectedToken::ExpectLBracket => "LBracket".to_string(), + ExpectedToken::ExpectRBracket => "RBracket".to_string(), + ExpectedToken::ExpectLt => "Lt".to_string(), + ExpectedToken::ExpectGt => "Gt".to_string(), + ExpectedToken::ExpectFatArrow => "FatArrow".to_string(), + ExpectedToken::ExpectArrow => "Arrow".to_string(), + ExpectedToken::ExpectColon => "Colon".to_string(), + ExpectedToken::ExpectComma => "Comma".to_string(), + ExpectedToken::ExpectDot => "Dot".to_string(), + ExpectedToken::ExpectEq => "Eq".to_string(), + ExpectedToken::ExpectQuestion => "Question".to_string(), + ExpectedToken::ExpectPipe => "Pipe".to_string(), +} } pub fn token_matches_expected(token: &Rc, expected: Rc) -> bool { match (*expected).clone() { - ExpectedToken::ExpectKeyword { text: kw, .. } => { - (is_keyword_shape(token.shape.clone()) - && (token.text.clone().as_str() == kw.clone().as_str())) - } - ExpectedToken::ExpectLBrace => is_lbrace_shape(token.shape.clone()), - ExpectedToken::ExpectRBrace => is_rbrace_shape(token.shape.clone()), - ExpectedToken::ExpectLParen => is_lparen_shape(token.shape.clone()), - ExpectedToken::ExpectRParen => is_rparen_shape(token.shape.clone()), - ExpectedToken::ExpectLBracket => is_lbracket_shape(token.shape.clone()), - ExpectedToken::ExpectRBracket => is_rbracket_shape(token.shape.clone()), - ExpectedToken::ExpectLt => is_lt_shape(token.shape.clone()), - ExpectedToken::ExpectGt => is_gt_shape(token.shape.clone()), - ExpectedToken::ExpectFatArrow => is_fat_arrow_shape(token.shape.clone()), - ExpectedToken::ExpectArrow => is_arrow_shape(token.shape.clone()), - ExpectedToken::ExpectColon => is_colon_shape(token.shape.clone()), - ExpectedToken::ExpectComma => is_comma_shape(token.shape.clone()), - ExpectedToken::ExpectDot => is_dot_shape(token.shape.clone()), - ExpectedToken::ExpectEq => is_eq_shape(token.shape.clone()), - ExpectedToken::ExpectQuestion => is_question_shape(token.shape.clone()), - ExpectedToken::ExpectPipe => is_pipe_shape(token.shape.clone()), - } + ExpectedToken::ExpectKeyword { text: kw, .. } => (is_keyword_shape(token.shape.clone()) && (token.text.clone().as_str() == kw.clone().as_str())), + ExpectedToken::ExpectLBrace => is_lbrace_shape(token.shape.clone()), + ExpectedToken::ExpectRBrace => is_rbrace_shape(token.shape.clone()), + ExpectedToken::ExpectLParen => is_lparen_shape(token.shape.clone()), + ExpectedToken::ExpectRParen => is_rparen_shape(token.shape.clone()), + ExpectedToken::ExpectLBracket => is_lbracket_shape(token.shape.clone()), + ExpectedToken::ExpectRBracket => is_rbracket_shape(token.shape.clone()), + ExpectedToken::ExpectLt => is_lt_shape(token.shape.clone()), + ExpectedToken::ExpectGt => is_gt_shape(token.shape.clone()), + ExpectedToken::ExpectFatArrow => is_fat_arrow_shape(token.shape.clone()), + ExpectedToken::ExpectArrow => is_arrow_shape(token.shape.clone()), + ExpectedToken::ExpectColon => is_colon_shape(token.shape.clone()), + ExpectedToken::ExpectComma => is_comma_shape(token.shape.clone()), + ExpectedToken::ExpectDot => is_dot_shape(token.shape.clone()), + ExpectedToken::ExpectEq => is_eq_shape(token.shape.clone()), + ExpectedToken::ExpectQuestion => is_question_shape(token.shape.clone()), + ExpectedToken::ExpectPipe => is_pipe_shape(token.shape.clone()), +} } pub fn expect(tokens: &Rc>>, expected: &Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let matches = match tok.clone() { - Some(t) => token_matches_expected(&t, expected.clone()), - None => false, - }; - if matches { +let matches = match tok.clone() { + Some(t) => token_matches_expected(&t, expected.clone()), + None => false, +}; +if matches { Rc::new(TokenResult { - token: tok.clone().unwrap(), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - err: None, - }) + token: tok.clone().unwrap(), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + err: None, +}) } else { { let found = match tok.clone() { - Some(t) => token_display_name(&t), - None => "EOF".to_string(), - }; - let wanted = expected_token_name(expected.clone()); - Rc::new(TokenResult { - token: Rc::new(Token { - text: "".to_string(), - span: make_span(0, 0), - shape: TokenShape::ShEof, - }), - tokens: tokens.clone(), - err: Some(parse_error( - format!("expected {}, found {}", wanted, found), - token_span(tok.clone()), - )), - }) - } + Some(t) => token_display_name(&t), + None => "EOF".to_string(), +}; +let wanted = expected_token_name(expected.clone()); +Rc::new(TokenResult { + token: Rc::new(Token { + text: "".to_string(), + span: make_span(0, 0), + shape: TokenShape::ShEof, +}), + tokens: tokens.clone(), + err: Some(parse_error(format!("expected {}, found {}", wanted, found), token_span(tok.clone()))), +}) +} } - } +} } pub fn expect_ident(tokens: &Rc>>) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh.clone() { - Some(TokenShape::ShIdent) => { - let n = tok.clone().unwrap().text.clone(); - let span = tok.clone().unwrap().span.clone(); - Rc::new(NameResult { - name: n, - span: span, - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - err: None, - }) - } - _ => { - let found = match sh.clone() { - Some(shape) => shape_display_name(shape.clone()), - None => "EOF".to_string(), - }; - Rc::new(NameResult { - name: "".to_string(), - span: token_span(tok.clone()), - tokens: tokens.clone(), - err: Some(parse_error( - v2_rt::concat("expected identifier, found ".to_string(), found), - token_span(tok.clone()), - )), - }) - } - } - } +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh.clone() { + Some(TokenShape::ShIdent) => { + let n = tok.clone().unwrap().text.clone(); +let span = tok.clone().unwrap().span.clone(); +Rc::new(NameResult { + name: n, + span: span, + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + err: None, +}) +}, + _ => { + let found = match sh.clone() { + Some(shape) => shape_display_name(shape.clone()), + None => "EOF".to_string(), +}; +Rc::new(NameResult { + name: "".to_string(), + span: token_span(tok.clone()), + tokens: tokens.clone(), + err: Some(parse_error(v2_rt::concat("expected identifier, found ".to_string(), found), token_span(tok.clone()))), +}) +}, +} +} } pub fn expect_name(tokens: &Rc>>) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShIdent) => { - let n = tok.clone().unwrap().text.clone(); +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShIdent) => { + let n = tok.clone().unwrap().text.clone(); +let span = tok.clone().unwrap().span.clone(); +Rc::new(NameResult { + name: n, + span: span, + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + err: None, +}) +}, + _ => { + let kw_name = tok_keyword_to_name(tok.clone()); +match kw_name { + Some(n) => { let span = tok.clone().unwrap().span.clone(); - Rc::new(NameResult { - name: n, - span: span, - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - err: None, - }) - } - _ => { - let kw_name = tok_keyword_to_name(tok.clone()); - match kw_name { - Some(n) => { - let span = tok.clone().unwrap().span.clone(); - Rc::new(NameResult { - name: n, - span: span, - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - err: None, - }) - } - None => { - let found = match tok.clone() { - Some(t) => token_display_name(&t), - None => "EOF".to_string(), - }; - Rc::new(NameResult { - name: "".to_string(), - span: token_span(tok.clone()), - tokens: tokens.clone(), - err: Some(parse_error( - v2_rt::concat("expected name, found ".to_string(), found), - token_span(tok.clone()), - )), - }) - } - } - } - } - } +Rc::new(NameResult { + name: n, + span: span, + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + err: None, +}) +}, + None => { + let found = match tok.clone() { + Some(t) => token_display_name(&t), + None => "EOF".to_string(), +}; +Rc::new(NameResult { + name: "".to_string(), + span: token_span(tok.clone()), + tokens: tokens.clone(), + err: Some(parse_error(v2_rt::concat("expected name, found ".to_string(), found), token_span(tok.clone()))), +}) +}, +} +}, +} +} } pub fn is_name_keyword(token: &Rc) -> bool { if is_keyword_shape(token.shape.clone()) { match v2_rt::lookup(&dag_non_name_keywords(), token.text.clone()) { - Some(_) => false, - None => true, - } + Some(_) => false, + None => true, +} } else { false } @@ -1676,153 +1547,109 @@ pub fn is_name_keyword(token: &Rc) -> bool { pub fn skip_newlines(mut tokens: Rc>>) -> Rc>> { loop { match tokens.clone().first().cloned() { - Some(t) => { - if is_newline_shape(t.shape.clone()) { - { - let __tco_0 = - Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); - tokens = __tco_0; - continue; - } - } else { - break tokens.clone(); - } - } - None => { - break tokens.clone(); - } - } - } + Some(t) => { if is_newline_shape(t.shape.clone()) { + { + let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); +tokens = __tco_0; +continue; +} +} else { + break tokens.clone(); +} }, + None => { break tokens.clone(); }, +} +} } pub fn is_continuation_shape(shape: &TokenShape) -> bool { - (((is_pipe_arrow_shape(shape.clone()) || is_dot_shape(shape.clone())) - || is_or_shape(shape.clone())) - || is_and_shape(shape.clone())) + (((is_pipe_arrow_shape(shape.clone()) || is_dot_shape(shape.clone())) || is_or_shape(shape.clone())) || is_and_shape(shape.clone())) } pub fn skip_continuation_newlines(tokens: &Rc>>) -> Rc>> { { let tok = tokens.clone().first().cloned(); - let is_continuation = if tok_is_newline(tok) { +let is_continuation = if tok_is_newline(tok) { { let after = skip_newlines(tokens.clone()); - match after.first().cloned() { - Some(next) => is_continuation_shape(&next.shape.clone()), - None => false, - } - } +match after.first().cloned() { + Some(next) => is_continuation_shape(&next.shape.clone()), + None => false, +} +} } else { false }; - if is_continuation { +if is_continuation { skip_newlines(tokens.clone()) } else { tokens.clone() } - } +} } pub fn eat(tokens: &Rc>>, expected: Rc) -> Rc { match tokens.clone().first().cloned() { - Some(t) => { - if token_matches_expected(&t, expected) { - Rc::new(EatResult::EatConsumed { - token: t.clone(), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - }) - } else { - Rc::new(EatResult::EatUnchanged { - tokens: tokens.clone(), - }) - } - } - None => Rc::new(EatResult::EatUnchanged { - tokens: tokens.clone(), - }), - } + Some(t) => if token_matches_expected(&t, expected) { + Rc::new(EatResult::EatConsumed { + token: t.clone(), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), +}) + } else { + Rc::new(EatResult::EatUnchanged { + tokens: tokens.clone(), +}) + }, + None => Rc::new(EatResult::EatUnchanged { + tokens: tokens.clone(), +}), +} } -pub fn parser_result_base_var( - expr: &Rc, - source_indices: Rc>>, -) -> Option { +pub fn parser_result_base_var(expr: &Rc, source_indices: Rc>>) -> Option { match (*expr.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => match expr.children.clone().first().cloned() { - Some(base) => match (*base.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => Some(expr_var_name_at(base.clone(), source_indices)), - _ => None, - }, - None => None, - }, - _ => None, - } + ExprData::ExprFieldAccess { .. } => match expr.children.clone().first().cloned() { + Some(base) => match (*base.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => Some(expr_var_name_at(base.clone(), source_indices)), + _ => None, +}, + None => None, +}, + _ => None, +} } -pub fn parser_helper_state_arg_expr( - call_node: Rc, - source_indices: Rc>>, -) -> Option> { - Rc::new( - call_node - .children - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold(None, |acc: _, pair: (i64, Rc)| { - if (acc.clone() != None) { - acc.clone() - } else { - { - let idx = pair.0.clone(); - let arg_node = pair.1.clone(); - let matches_state = match arg_name_at(arg_node.clone(), source_indices.clone()) { - Some(name) => { - ((name.clone().as_str() == "state".to_string().as_str()) - || (name.clone().as_str() == "tokens".to_string().as_str())) - } - None => (idx.clone() == 0), - }; - if matches_state.clone() { - Some(arg_value(&arg_node)) - } else { - None - } +pub fn parser_helper_state_arg_expr(call_node: Rc, source_indices: Rc>>) -> Option> { + Rc::new(call_node.children.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(None, |acc: _, pair: (i64, Rc)| if (acc.clone() != None) { + acc.clone() + } else { + { + let idx = pair.0.clone(); +let arg_node = pair.1.clone(); +let matches_state = match arg_name_at(arg_node.clone(), source_indices.clone()) { + Some(name) => ((name.clone().as_str() == "state".to_string().as_str()) || (name.clone().as_str() == "tokens".to_string().as_str())), + None => (idx.clone() == 0), +}; +if matches_state.clone() { + Some(arg_value(&arg_node)) + } else { + None } - } +} }) } -pub fn parser_progress_flag_var( - expr: &Rc, - source_indices: &Rc>>, -) -> Option { +pub fn parser_progress_flag_var(expr: &Rc, source_indices: &Rc>>) -> Option { match (*expr.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { .. } => { - let field = field_access_field_at(expr.clone(), source_indices.clone()); - if ((field.clone().as_str() == "consumed".to_string().as_str()) - || (field.clone().as_str() == "changed".to_string().as_str())) - { - parser_result_base_var(&expr, source_indices.clone()) - } else { - None - } + ExprData::ExprFieldAccess { .. } => { + let field = field_access_field_at(expr.clone(), source_indices.clone()); +if ((field.clone().as_str() == "consumed".to_string().as_str()) || (field.clone().as_str() == "changed".to_string().as_str())) { + parser_result_base_var(&expr, source_indices.clone()) + } else { + None } - _ => None, - } +}, + _ => None, +} } pub fn parser_helper_identity(callee: &String) -> Option { @@ -1841,83 +1668,69 @@ pub fn parser_helper_identity(callee: &String) -> Option { } } -pub fn parser_passthrough_state_expr( - expr: &Rc, - source_indices: &Rc>>, -) -> Option> { +pub fn parser_passthrough_state_expr(expr: &Rc, source_indices: &Rc>>) -> Option> { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - match parser_helper_identity(&expr_call_func_at(expr.clone(), source_indices.clone())) { - Some(ParserHelperIdentity::ParserHelperSkipNewlines) => { - parser_helper_state_arg_expr(expr.clone(), source_indices.clone()) - } - Some(ParserHelperIdentity::ParserHelperSkipContinuationNewlines) => { - parser_helper_state_arg_expr(expr.clone(), source_indices.clone()) - } - Some(ParserHelperIdentity::ParserHelperWith) => { - match expr.children.clone().first().cloned() { - Some(base_arg) => Some(arg_value(&base_arg)), - None => None, - } - } - None => None, - } - } - _ => None, - } + ExprData::ExprCall { .. } => match parser_helper_identity(&expr_call_func_at(expr.clone(), source_indices.clone())) { + Some(ParserHelperIdentity::ParserHelperSkipNewlines) => parser_helper_state_arg_expr(expr.clone(), source_indices.clone()), + Some(ParserHelperIdentity::ParserHelperSkipContinuationNewlines) => parser_helper_state_arg_expr(expr.clone(), source_indices.clone()), + Some(ParserHelperIdentity::ParserHelperWith) => match expr.children.clone().first().cloned() { + Some(base_arg) => Some(arg_value(&base_arg)), + None => None, +}, + None => None, +}, + _ => None, +} } -pub fn parser_result_witness( - expr: &Rc, - source_indices: Rc>>, -) -> Rc { +pub fn parser_result_witness(expr: &Rc, source_indices: Rc>>) -> Rc { match (*expr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => match expr_call_func_at(expr.clone(), source_indices) { - ref __s if __s == "advance" => Rc::new(ParserResultWitness::ParserWitnessAdvance), - ref __s if __s == "expect" => Rc::new(ParserResultWitness::ParserWitnessExpect), - ref __s if __s == "eat" => Rc::new(ParserResultWitness::ParserWitnessEat), - callee => match parser_helper_identity(&callee) { - Some(helper) => Rc::new(ParserResultWitness::ParserWitnessCall { - callee: Rc::new(ParserCallIdentity::ParserCallHelper { - helper: helper.clone(), - }), - }), - None => Rc::new(ParserResultWitness::ParserWitnessCall { - callee: Rc::new(ParserCallIdentity::ParserCallFunction { - name: callee.clone(), - }), - }), - }, - }, - _ => Rc::new(ParserResultWitness::ParserWitnessOpaque), - } + ExprData::ExprCall { .. } => match expr_call_func_at(expr.clone(), source_indices) { + ref __s if __s == "advance" => Rc::new(ParserResultWitness::ParserWitnessAdvance), + ref __s if __s == "expect" => Rc::new(ParserResultWitness::ParserWitnessExpect), + ref __s if __s == "eat" => Rc::new(ParserResultWitness::ParserWitnessEat), + callee => match parser_helper_identity(&callee) { + Some(helper) => Rc::new(ParserResultWitness::ParserWitnessCall { + callee: Rc::new(ParserCallIdentity::ParserCallHelper { + helper: helper.clone(), +}), +}), + None => Rc::new(ParserResultWitness::ParserWitnessCall { + callee: Rc::new(ParserCallIdentity::ParserCallFunction { + name: callee.clone(), +}), +}), +}, +}, + _ => Rc::new(ParserResultWitness::ParserWitnessOpaque), +} } pub fn leaf_type_node(name: &String, span: &Rc) -> Rc { Rc::new(Node { - name: name.clone(), - span: span.clone(), - ident_span: if (name.clone().as_str() == "".to_string().as_str()) { - None - } else { - Some(span.clone()) - }, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: name.clone(), + span: span.clone(), + ident_span: if (name.clone().as_str() == "".to_string().as_str()) { + None + } else { + Some(span.clone()) + }, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn is_conj_with_children(n: &Rc) -> bool { @@ -1926,455 +1739,338 @@ pub fn is_conj_with_children(n: &Rc) -> bool { pub fn child_inferred_or_empty(ch: Rc) -> Rc { match ch.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), - _ => error_type(), - } + Some(InferredNode::Resolved { node: rt, .. }) => rt.clone(), + _ => error_type(), +} } -pub fn node_inferred_to_outputs( - rt: &Rc, - source_indices: Rc>>, -) -> Rc>> { +pub fn node_inferred_to_outputs(rt: &Rc, source_indices: Rc>>) -> Rc>> { if is_conj_with_children(&rt) { { - let all_children_typed = { - let mut __all = true; - for ch in rt.children.clone().iter().cloned() { - if !(match ch.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { .. }) => true, - _ => false, - }) { - __all = false; - break; - } - } - __all - }; - if all_children_typed { - Rc::new({ - let mut __result = Vec::new(); - for ch in rt.children.clone().iter().cloned() { - __result.push(make_field_node( - &authored_name_at(source_indices.clone(), &ch), - child_inferred_or_empty(ch.clone()), - Cardinality::Required, - ch.body.clone(), - None, - ch.span.clone(), - node_name_span(&ch), - )); - } - __result - }) + let all_children_typed = { let mut __all = true; for ch in rt.children.clone().iter().cloned() { if !(match ch.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { .. }) => true, + _ => false, +}) { __all = false; break; } } __all }; +if all_children_typed { + Rc::new({ let mut __result = Vec::new(); for ch in rt.children.clone().iter().cloned() { __result.push(make_field_node(&authored_name_at(source_indices.clone(), &ch), child_inferred_or_empty(ch.clone()), Cardinality::Required, ch.body.clone(), None, ch.span.clone(), node_name_span(&ch))); } __result }) } else { Rc::new(vec![]) } - } +} } else { - Rc::new(vec![make_field_node( - &"value".to_string(), - rt.clone(), - Cardinality::Required, - None, - None, - rt.span.clone(), - no_span(), - )]) + Rc::new(vec![make_field_node(&"value".to_string(), rt.clone(), Cardinality::Required, None, None, rt.span.clone(), no_span())]) } } pub fn parse_dotted_ident(tokens: Rc>>) -> Rc { { let r = expect_name(&tokens); - if has_err(r.err.clone()) { - return r.clone(); +if has_err(r.err.clone()) { + return r.clone() } - parse_dotted_ident_rest(r.tokens.clone(), r.name.clone(), r.span.clone()) - } +parse_dotted_ident_rest(r.tokens.clone(), r.name.clone(), r.span.clone()) +} } -pub fn parse_dotted_ident_rest( - mut tokens: Rc>>, - mut acc: String, - mut span: Rc, -) -> Rc { +pub fn parse_dotted_ident_rest(mut tokens: Rc>>, mut acc: String, mut span: Rc) -> Rc { loop { match (*eat(&tokens, Rc::new(ExpectedToken::ExpectDot))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = expect_name(&__ec); - if has_err(r.err.clone()) { - return r.clone(); - } - let extended = Rc::new(SourceSpan { - file: span.file.clone(), - start: span.start.clone(), - end: r.span.clone().end.clone(), - }); - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = - v2_rt::concat(v2_rt::concat(acc, ".".to_string()), r.name.clone()); - let __tco_2 = extended; - tokens = __tco_0; - acc = __tco_1; - span = __tco_2; - continue; - } - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(NameResult { - name: acc, - span: span.clone(), - tokens: __eu.clone(), - err: None, - }); - } - } - } + EatResult::EatConsumed { tokens: __ec, .. } => { let r = expect_name(&__ec); +if has_err(r.err.clone()) { + return r.clone() + } +let extended = Rc::new(SourceSpan { + file: span.file.clone(), + start: span.start.clone(), + end: r.span.clone().end.clone(), +}); +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = v2_rt::concat(v2_rt::concat(acc, ".".to_string()), r.name.clone()); +let __tco_2 = extended; +tokens = __tco_0; +acc = __tco_1; +span = __tco_2; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(NameResult { + name: acc, + span: span.clone(), + tokens: __eu.clone(), + err: None, +}); }, +} +} } -pub fn parse_with_table( - tokens: &Rc>>, - source_indices: Rc>>, - intern_table: Rc, -) -> Rc { +pub fn parse_with_table(tokens: &Rc>>, source_indices: Rc>>, intern_table: Rc) -> Rc { { let pre_interned = pre_intern_tokens(tokens.clone(), intern_table); - let ctx = Rc::new(ParseContext { - source_indices: source_indices, - intern_table: pre_interned, - }); - let r = parse_module(&tokens, &ctx); - if has_err(r.err.clone()) { +let ctx = Rc::new(ParseContext { + source_indices: source_indices, + intern_table: pre_interned, +}); +let r = parse_module(&tokens, &ctx); +if has_err(r.err.clone()) { Rc::new(ParseWithTableResult { - result: Rc::new(ParseResult { - module: None, - error: r.err.clone(), - }), - intern_table: r.ctx.clone().intern_table.clone(), - }) + result: Rc::new(ParseResult { + module: None, + error: r.err.clone(), +}), + intern_table: r.ctx.clone().intern_table.clone(), +}) } else { Rc::new(ParseWithTableResult { - result: Rc::new(ParseResult { - module: Some(r.module.clone()), - error: None, - }), - intern_table: r.ctx.clone().intern_table.clone(), - }) + result: Rc::new(ParseResult { + module: Some(r.module.clone()), + error: None, +}), + intern_table: r.ctx.clone().intern_table.clone(), +}) } - } +} } -pub fn parse( - tokens: Rc>>, - source_indices: Rc>>, -) -> Rc { - parse_with_table(&tokens, source_indices, empty_intern_table()) - .result - .clone() +pub fn parse(tokens: Rc>>, source_indices: Rc>>) -> Rc { + parse_with_table(&tokens, source_indices, empty_intern_table()).result.clone() } pub fn parse_module(tokens: &Rc>>, ctx: &Rc) -> Rc { { let tokens = skip_newlines(tokens.clone()); - let start_span = token_span(tokens.clone().first().cloned()); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "module".to_string(), - }), - ); - if has_err(r.err.clone()) { +let start_span = token_span(tokens.clone().first().cloned()); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "module".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ModuleResult { - module: module_node( - &"".to_string(), - Rc::new(vec![]), - Rc::new(vec![]), - &start_span, - ), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = r.tokens.clone(); - let r = parse_dotted_ident(tokens.clone()); - if has_err(r.err.clone()) { + module: module_node(&"".to_string(), Rc::new(vec![]), Rc::new(vec![]), &start_span), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = r.tokens.clone(); +let r = parse_dotted_ident(tokens.clone()); +if has_err(r.err.clone()) { return Rc::new(ModuleResult { - module: module_node( - &"".to_string(), - Rc::new(vec![]), - Rc::new(vec![]), - &start_span, - ), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let mod_name = r.name.clone(); - let mod_name_span = r.span.clone(); - let tokens = skip_newlines(r.tokens.clone()); - let r = parse_imports(tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { + module: module_node(&"".to_string(), Rc::new(vec![]), Rc::new(vec![]), &start_span), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let mod_name = r.name.clone(); +let mod_name_span = r.span.clone(); +let tokens = skip_newlines(r.tokens.clone()); +let r = parse_imports(tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ModuleResult { - module: module_node( - &"".to_string(), - Rc::new(vec![]), - Rc::new(vec![]), - &start_span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let imports = r.imports.clone(); - let tokens = r.tokens.clone(); - let ctx = r.ctx.clone(); - let r = parse_items(tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { + module: module_node(&"".to_string(), Rc::new(vec![]), Rc::new(vec![]), &start_span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let imports = r.imports.clone(); +let tokens = r.tokens.clone(); +let ctx = r.ctx.clone(); +let r = parse_items(tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ModuleResult { - module: module_node( - &"".to_string(), - Rc::new(vec![]), - Rc::new(vec![]), - &start_span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let items = r.items.clone(); - let tokens = r.tokens.clone(); - let ctx = r.ctx.clone(); - let mod_ir = intern(&ctx.intern_table.clone(), &mod_name); - let ctx = Rc::new(ParseContext { - intern_table: mod_ir.table.clone(), - ..(*ctx.clone()).clone() - }); - let base_mod = Rc::new(Node { - name: mod_name.clone(), - span: start_span.clone(), - ident_span: Some(mod_name_span), - children: items, - connective: Connective::NoConnective, - params: imports, - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r#mod = Rc::new(Node { - ident: Some(mod_ir.id.clone()), - ..(*base_mod).clone() - }); - Rc::new(ModuleResult { - module: r#mod, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } + module: module_node(&"".to_string(), Rc::new(vec![]), Rc::new(vec![]), &start_span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let items = r.items.clone(); +let tokens = r.tokens.clone(); +let ctx = r.ctx.clone(); +let mod_ir = intern(&ctx.intern_table.clone(), &mod_name); +let ctx = Rc::new(ParseContext { intern_table: mod_ir.table.clone(), ..(*ctx.clone()).clone() }); +let base_mod = Rc::new(Node { + name: mod_name.clone(), + span: start_span.clone(), + ident_span: Some(mod_name_span), + children: items, + connective: Connective::NoConnective, + params: imports, + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r#mod = Rc::new(Node { ident: Some(mod_ir.id.clone()), ..(*base_mod).clone() }); +Rc::new(ModuleResult { + module: r#mod, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +} } pub fn parse_imports(tokens: Rc>>, ctx: Rc) -> Rc { parse_imports_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_imports_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_imports_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if tok_is_keyword(tokens.clone().first().cloned(), "import".to_string()) { +if tok_is_keyword(tokens.clone().first().cloned(), "import".to_string()) { let r = parse_import(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ImportsResult { - imports: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + imports: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - { +{ let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(acc, r.import.clone()); - tokens = __tco_0; - ctx = __tco_1; - acc = __tco_2; - continue; - } - } else { +let __tco_1 = r.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(acc, r.import.clone()); +tokens = __tco_0; +ctx = __tco_1; +acc = __tco_2; +continue; +} +} else { break Rc::new(ImportsResult { - imports: acc, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } - } + imports: acc, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} +} } pub fn parse_items(tokens: Rc>>, ctx: Rc) -> Rc { parse_items_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_items_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_items_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if tok_is_eof(tokens.clone().first().cloned()) { +if tok_is_eof(tokens.clone().first().cloned()) { break Rc::new(ItemsResult { - items: acc.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + items: acc.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { let r = parse_item(&tokens, ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ItemsResult { - items: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + items: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - { +{ let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(acc, r.item.clone()); - tokens = __tco_0; - ctx = __tco_1; - acc = __tco_2; - continue; - } - } - } +let __tco_1 = r.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(acc, r.item.clone()); +tokens = __tco_0; +ctx = __tco_1; +acc = __tco_2; +continue; +} +} +} } pub fn parse_import(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let err_import = import_node( - "".to_string(), - false, - Rc::new(vec![]), - &start_span, - start_span.clone(), - ); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "import".to_string(), - }), - ); - if has_err(r.err.clone()) { - return Rc::new(ImportResult { - import: err_import.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = r.tokens.clone(); - let r = parse_dotted_ident(tokens.clone()); - if has_err(r.err.clone()) { +let err_import = import_node("".to_string(), false, Rc::new(vec![]), &start_span, start_span.clone()); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "import".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ImportResult { - import: err_import.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let mod_path = r.name.clone(); - let mod_path_span = r.span.clone(); - let tokens = r.tokens.clone(); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = parse_import_names(__ec.clone(), ctx.clone()); - if has_err(r.err.clone()) { - return Rc::new(ImportResult { - import: err_import.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let names = r.names.clone(); - let tokens = r.tokens.clone(); - let ctx = r.ctx.clone(); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r.err.clone()) { - return Rc::new(ImportResult { - import: err_import.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let base_imp = - import_node(mod_path.clone(), false, names, &start_span, mod_path_span); - let imp_ir = intern(&ctx.intern_table.clone(), &mod_path); - let ctx = Rc::new(ParseContext { - intern_table: imp_ir.table.clone(), - ..(*ctx.clone()).clone() - }); - let imp = Rc::new(Node { - ident: Some(imp_ir.id.clone()), - ..(*base_imp).clone() - }); - Rc::new(ImportResult { - import: imp, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let tokens = skip_newlines(tokens.clone()); - let base_imp = import_node( - mod_path.clone(), - true, - Rc::new(vec![]), - &start_span, - mod_path_span, - ); - let imp_ir = intern(&ctx.intern_table.clone(), &mod_path); - let ctx = Rc::new(ParseContext { - intern_table: imp_ir.table.clone(), - ..(*ctx.clone()).clone() - }); - let imp = Rc::new(Node { - ident: Some(imp_ir.id.clone()), - ..(*base_imp).clone() - }); - Rc::new(ImportResult { - import: imp, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } + import: err_import.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - } +let tokens = r.tokens.clone(); +let r = parse_dotted_ident(tokens.clone()); +if has_err(r.err.clone()) { + return Rc::new(ImportResult { + import: err_import.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let mod_path = r.name.clone(); +let mod_path_span = r.span.clone(); +let tokens = r.tokens.clone(); +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let r = parse_import_names(__ec.clone(), ctx.clone()); +if has_err(r.err.clone()) { + return Rc::new(ImportResult { + import: err_import.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let names = r.names.clone(); +let tokens = r.tokens.clone(); +let ctx = r.ctx.clone(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r.err.clone()) { + return Rc::new(ImportResult { + import: err_import.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let base_imp = import_node(mod_path.clone(), false, names, &start_span, mod_path_span); +let imp_ir = intern(&ctx.intern_table.clone(), &mod_path); +let ctx = Rc::new(ParseContext { intern_table: imp_ir.table.clone(), ..(*ctx.clone()).clone() }); +let imp = Rc::new(Node { ident: Some(imp_ir.id.clone()), ..(*base_imp).clone() }); +Rc::new(ImportResult { + import: imp, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let tokens = skip_newlines(tokens.clone()); +let base_imp = import_node(mod_path.clone(), true, Rc::new(vec![]), &start_span, mod_path_span); +let imp_ir = intern(&ctx.intern_table.clone(), &mod_path); +let ctx = Rc::new(ParseContext { intern_table: imp_ir.table.clone(), ..(*ctx.clone()).clone() }); +let imp = Rc::new(Node { ident: Some(imp_ir.id.clone()), ..(*base_imp).clone() }); +Rc::new(ImportResult { + import: imp, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, +} +} } pub fn parse_import_names(tokens: Rc>>, ctx: Rc) -> Rc { @@ -2385,72 +2081,60 @@ pub fn parsed_name_leaf(name: String, span: Rc) -> Rc { leaf_node_with_span(&name, &span) } -pub fn parse_import_names_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_import_names_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if tok_is_rbrace(tokens.clone().first().cloned()) { +if tok_is_rbrace(tokens.clone().first().cloned()) { break Rc::new(NamesResult { - names: acc, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + names: acc, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let r = parse_dotted_ident(tokens.clone()); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(NamesResult { - names: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name_node = parsed_name_leaf(r.name.clone(), r.span.clone()); - tokens = skip_newlines(r.tokens.clone()); - let e = eat(&tokens, Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => tokens.clone(), - }); - { + names: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name_node = parsed_name_leaf(r.name.clone(), r.span.clone()); +tokens = skip_newlines(r.tokens.clone()); +let e = eat(&tokens, Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => tokens.clone(), +}); +{ let __tco_0 = v2_rt::rc_list_push(acc, name_node); - acc = __tco_0; - continue; - } - } - } +acc = __tco_0; +continue; +} +} +} } pub fn find_item_form(forms: Rc>>, keyword: String) -> Option> { { - let matches = Rc::new({ - let mut __result = Vec::new(); - for f in forms.iter().cloned() { - if (f.keyword.clone().as_str() == keyword.clone().as_str()) { - __result.push(f); - } - } - __result - }); - match (matches.clone().len() as i64) { - 0 => None, - _ => Some(matches.clone().first().cloned().clone().unwrap()), - } - } + let matches = Rc::new({ let mut __result = Vec::new(); for f in forms.iter().cloned() { if (f.keyword.clone().as_str() == keyword.clone().as_str()) { __result.push(f); } } __result }); +match (matches.clone().len() as i64) { + 0 => None, + _ => Some(matches.clone().first().cloned().clone().unwrap()), +} +} } pub fn parse_item(tokens: &Rc>>, ctx: Rc) -> Rc { { let tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - let kw = tok_keyword_text(tok.clone()); - let span = token_span(tok.clone()); - let form = find_item_form(dag_syntax_spec().item_forms.clone(), kw); - match form { +let tok = tokens.clone().first().cloned(); +let kw = tok_keyword_text(tok.clone()); +let span = token_span(tok.clone()); +let form = find_item_form(dag_syntax_spec().item_forms.clone(), kw); +match form { Some(f) => parse_item_by_form(&tokens, &ctx, &f), None => Rc::new(ItemResult { item: Rc::new(Node { @@ -2478,1149 +2162,971 @@ pub fn parse_item(tokens: &Rc>>, ctx: Rc) -> Rc>>, - ctx: &Rc, - form: &Rc, -) -> Rc { +pub fn parse_item_prefix(tokens: &Rc>>, ctx: &Rc, form: &Rc) -> Rc { { let r = expect_ident(&tokens); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ItemPrefixResult { - name: "".to_string(), - name_span: r.span.clone(), - type_params: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - uses: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let tokens = r.tokens.clone(); - let tp_result = if form.has_type_params.clone() { + name: "".to_string(), + name_span: r.span.clone(), + type_params: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + uses: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let tokens = r.tokens.clone(); +let tp_result = if form.has_type_params.clone() { parse_optional_type_params(&tokens, ctx.clone()) } else { Rc::new(TypeParamsResult { - params: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - }) + params: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), +}) }; - let tokens = tp_result.tokens.clone(); - let ctx = tp_result.ctx.clone(); - let params_result = if form.has_params.clone() { +let tokens = tp_result.tokens.clone(); +let ctx = tp_result.ctx.clone(); +let params_result = if form.has_params.clone() { parse_params(&tokens, &ctx) } else { Rc::new(ParamsResult { - params: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + params: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) }; - if has_err(params_result.err.clone()) { +if has_err(params_result.err.clone()) { return Rc::new(ItemPrefixResult { - name: name.clone(), - name_span: name_span.clone(), - type_params: tp_result.params.clone(), - params: Rc::new(vec![]), - inferred: None, - uses: Rc::new(vec![]), - tokens: params_result.tokens.clone(), - ctx: params_result.ctx.clone(), - err: params_result.err.clone(), - }); - } - let tokens = params_result.tokens.clone(); - let ctx = params_result.ctx.clone(); - let ret_result = if form.has_return_type.clone() { + name: name.clone(), + name_span: name_span.clone(), + type_params: tp_result.params.clone(), + params: Rc::new(vec![]), + inferred: None, + uses: Rc::new(vec![]), + tokens: params_result.tokens.clone(), + ctx: params_result.ctx.clone(), + err: params_result.err.clone(), +}) + } +let tokens = params_result.tokens.clone(); +let ctx = params_result.ctx.clone(); +let ret_result = if form.has_return_type.clone() { parse_optional_inferred(&tokens, ctx.clone()) } else { Rc::new(OptRetResult { - inferred: None, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + inferred: None, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) }; - if has_err(ret_result.err.clone()) { +if has_err(ret_result.err.clone()) { return Rc::new(ItemPrefixResult { - name: name.clone(), - name_span: name_span.clone(), - type_params: tp_result.params.clone(), - params: params_result.params.clone(), - inferred: None, - uses: Rc::new(vec![]), - tokens: ret_result.tokens.clone(), - ctx: ret_result.ctx.clone(), - err: ret_result.err.clone(), - }); - } - let tokens = ret_result.tokens.clone(); - let ctx = ret_result.ctx.clone(); - let missing_required_ret = (form.return_required.clone() - && match ret_result.inferred.clone() { - Some(_) => false, - None => true, - }); - if missing_required_ret { + name: name.clone(), + name_span: name_span.clone(), + type_params: tp_result.params.clone(), + params: params_result.params.clone(), + inferred: None, + uses: Rc::new(vec![]), + tokens: ret_result.tokens.clone(), + ctx: ret_result.ctx.clone(), + err: ret_result.err.clone(), +}) + } +let tokens = ret_result.tokens.clone(); +let ctx = ret_result.ctx.clone(); +let missing_required_ret = (form.return_required.clone() && match ret_result.inferred.clone() { + Some(_) => false, + None => true, +}); +if missing_required_ret { return Rc::new(ItemPrefixResult { - name: name.clone(), - name_span: name_span.clone(), - type_params: tp_result.params.clone(), - params: params_result.params.clone(), - inferred: None, - uses: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - v2_rt::concat( - "expected return type annotation (-> Type) for '".to_string(), - v2_rt::concat( - form.keyword.clone(), - v2_rt::concat(" ".to_string(), name.clone()), - ), - ), - token_span(tokens.clone().first().cloned()), - )), - }); - } - let uses_result = if form.has_uses.clone() { + name: name.clone(), + name_span: name_span.clone(), + type_params: tp_result.params.clone(), + params: params_result.params.clone(), + inferred: None, + uses: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error(v2_rt::concat("expected return type annotation (-> Type) for '".to_string(), v2_rt::concat(form.keyword.clone(), v2_rt::concat(" ".to_string(), name.clone()))), token_span(tokens.clone().first().cloned()))), +}) + } +let uses_result = if form.has_uses.clone() { parse_uses_clause(&skip_newlines(tokens.clone()), ctx.clone()) } else { Rc::new(UsesResult { - uses: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + uses: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) }; - if has_err(uses_result.err.clone()) { +if has_err(uses_result.err.clone()) { return Rc::new(ItemPrefixResult { - name: name.clone(), - name_span: name_span.clone(), - type_params: tp_result.params.clone(), - params: params_result.params.clone(), - inferred: ret_result.inferred.clone(), - uses: Rc::new(vec![]), - tokens: uses_result.tokens.clone(), - ctx: uses_result.ctx.clone(), - err: uses_result.err.clone(), - }); - } - Rc::new(ItemPrefixResult { - name: name.clone(), - name_span: name_span.clone(), - type_params: tp_result.params.clone(), - params: params_result.params.clone(), - inferred: ret_result.inferred.clone(), - uses: uses_result.uses.clone(), - tokens: uses_result.tokens.clone(), - ctx: uses_result.ctx.clone(), - err: None, - }) - } -} - -pub fn parse_item_by_form( - tokens: &Rc>>, - ctx: &Rc, - form: &Rc, -) -> Rc { + name: name.clone(), + name_span: name_span.clone(), + type_params: tp_result.params.clone(), + params: params_result.params.clone(), + inferred: ret_result.inferred.clone(), + uses: Rc::new(vec![]), + tokens: uses_result.tokens.clone(), + ctx: uses_result.ctx.clone(), + err: uses_result.err.clone(), +}) + } +Rc::new(ItemPrefixResult { + name: name.clone(), + name_span: name_span.clone(), + type_params: tp_result.params.clone(), + params: params_result.params.clone(), + inferred: ret_result.inferred.clone(), + uses: uses_result.uses.clone(), + tokens: uses_result.tokens.clone(), + ctx: uses_result.ctx.clone(), + err: None, +}) +} +} + +pub fn parse_item_by_form(tokens: &Rc>>, ctx: &Rc, form: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: form.keyword.clone(), - }), - ); - if has_err(r.err.clone()) { - return Rc::new(ItemResult { - item: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = r.tokens.clone(); - match form.body_kind.clone() { - BodyKind::TypeBody => { - let prefix = parse_item_prefix(&tokens, &ctx, &form); - if has_err(prefix.err.clone()) { - return Rc::new(ItemResult { - item: dummy.clone(), - tokens: prefix.tokens.clone(), - ctx: prefix.ctx.clone(), - err: prefix.err.clone(), - }); - } - parse_type_body_from_prefix(&prefix, &start_span) - } - BodyKind::ExprBody => { - let prefix = parse_item_prefix(&tokens, &ctx, &form); - if has_err(prefix.err.clone()) { - return Rc::new(ItemResult { - item: dummy.clone(), - tokens: prefix.tokens.clone(), - ctx: prefix.ctx.clone(), - err: prefix.err.clone(), - }); - } - parse_fn_body_from_prefix(&prefix, &start_span) - } - BodyKind::BlockBody => { - let prefix = parse_item_prefix(&tokens, &ctx, &form); - if has_err(prefix.err.clone()) { - return Rc::new(ItemResult { - item: dummy.clone(), - tokens: prefix.tokens.clone(), - ctx: prefix.ctx.clone(), - err: prefix.err.clone(), - }); - } - parse_block_body_from_prefix(&prefix, &start_span) - } - BodyKind::ServiceBody => parse_service_after_kw(&tokens, &ctx, &start_span), - BodyKind::ResourceBody => parse_resource_after_kw(tokens.clone(), &ctx, &start_span), - BodyKind::ValueBody => parse_data_after_kw(tokens.clone(), &ctx, &start_span), - BodyKind::NoBody => { - let prefix = parse_item_prefix(&tokens, &ctx, &form); - if has_err(prefix.err.clone()) { - return Rc::new(ItemResult { - item: dummy.clone(), - tokens: prefix.tokens.clone(), - ctx: prefix.ctx.clone(), - err: prefix.err.clone(), - }); - } - parse_no_body_from_prefix(&prefix, start_span.clone()) - } - } - } -} - -pub fn field_to_child_node( - field: &Rc, - source_indices: &Rc>>, -) -> Rc { +let dummy = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: form.keyword.clone(), +})); +if has_err(r.err.clone()) { + return Rc::new(ItemResult { + item: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = r.tokens.clone(); +match form.body_kind.clone() { + BodyKind::TypeBody => { + let prefix = parse_item_prefix(&tokens, &ctx, &form); +if has_err(prefix.err.clone()) { + return Rc::new(ItemResult { + item: dummy.clone(), + tokens: prefix.tokens.clone(), + ctx: prefix.ctx.clone(), + err: prefix.err.clone(), +}) + } +parse_type_body_from_prefix(&prefix, &start_span) +}, + BodyKind::ExprBody => { + let prefix = parse_item_prefix(&tokens, &ctx, &form); +if has_err(prefix.err.clone()) { + return Rc::new(ItemResult { + item: dummy.clone(), + tokens: prefix.tokens.clone(), + ctx: prefix.ctx.clone(), + err: prefix.err.clone(), +}) + } +parse_fn_body_from_prefix(&prefix, &start_span) +}, + BodyKind::BlockBody => { + let prefix = parse_item_prefix(&tokens, &ctx, &form); +if has_err(prefix.err.clone()) { + return Rc::new(ItemResult { + item: dummy.clone(), + tokens: prefix.tokens.clone(), + ctx: prefix.ctx.clone(), + err: prefix.err.clone(), +}) + } +parse_block_body_from_prefix(&prefix, &start_span) +}, + BodyKind::ServiceBody => parse_service_after_kw(&tokens, &ctx, &start_span), + BodyKind::ResourceBody => parse_resource_after_kw(tokens.clone(), &ctx, &start_span), + BodyKind::ValueBody => parse_data_after_kw(tokens.clone(), &ctx, &start_span), + BodyKind::NoBody => { + let prefix = parse_item_prefix(&tokens, &ctx, &form); +if has_err(prefix.err.clone()) { + return Rc::new(ItemResult { + item: dummy.clone(), + tokens: prefix.tokens.clone(), + ctx: prefix.ctx.clone(), + err: prefix.err.clone(), +}) + } +parse_no_body_from_prefix(&prefix, start_span.clone()) +}, +} +} +} + +pub fn field_to_child_node(field: &Rc, source_indices: &Rc>>) -> Rc { { let ret_type = field_node_type_expr(&field); - let props = match field_node_from_key(field.clone(), source_indices.clone()) { - Some(key) => Rc::new(vec![make_field_init_node( - &"from_key".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { value: key.clone() }), - }), - Rc::new(vec![]), - None, - field.span.clone(), - ), - field.span.clone(), - no_span(), - )]), - None => Rc::new(vec![]), - }; - Rc::new(Node { - name: field_node_name_at(field.clone(), source_indices.clone()), - span: field.span.clone(), - ident_span: field.ident_span.clone(), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::Resolved { node: ret_type })), - return_cardinality: field_node_cardinality(field.clone()), - uses: Rc::new(vec![]), - body: field_node_default_value(&field), - transport: None, - properties: props, - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } +let props = match field_node_from_key(field.clone(), source_indices.clone()) { + Some(key) => Rc::new(vec![make_field_init_node(&"from_key".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: key.clone(), +}), +}), Rc::new(vec![]), None, field.span.clone()), field.span.clone(), no_span())]), + None => Rc::new(vec![]), +}; +Rc::new(Node { + name: field_node_name_at(field.clone(), source_indices.clone()), + span: field.span.clone(), + ident_span: field.ident_span.clone(), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::Resolved { + node: ret_type, +})), + return_cardinality: field_node_cardinality(field.clone()), + uses: Rc::new(vec![]), + body: field_node_default_value(&field), + transport: None, + properties: props, + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} } -pub fn variant_to_child_node( - variant: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn variant_to_child_node(variant: &Rc, source_indices: &Rc>>) -> Rc { { let fields = variant_node_fields(variant.clone()); - let children = Rc::new({ - let mut __result = Vec::new(); - for f in fields.clone().iter().cloned() { - __result.push(field_to_child_node(&f, &source_indices)); - } - __result - }); - Rc::new(Node { - name: variant_node_name_at(variant.clone(), source_indices.clone()), - span: variant.span.clone(), - ident_span: variant.ident_span.clone(), - children: children, - connective: if ((fields.clone().len() as i64) > 0) { - Connective::Conj - } else { - Connective::NoConnective - }, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } +let children = Rc::new({ let mut __result = Vec::new(); for f in fields.clone().iter().cloned() { __result.push(field_to_child_node(&f, &source_indices)); } __result }); +Rc::new(Node { + name: variant_node_name_at(variant.clone(), source_indices.clone()), + span: variant.span.clone(), + ident_span: variant.ident_span.clone(), + children: children, + connective: if ((fields.clone().len() as i64) > 0) { + Connective::Conj + } else { + Connective::NoConnective + }, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} } -pub fn outputs_to_inferred( - outputs: &Rc>>, - span: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn outputs_to_inferred(outputs: &Rc>>, span: Rc, source_indices: Rc>>) -> Option> { if ((outputs.clone().len() as i64) > 0) { Some(Rc::new(InferredNode::Resolved { - node: Rc::new(Node { - name: "".to_string(), - span: span, - ident_span: None, - children: Rc::new({ - let mut __result = Vec::new(); - for f in outputs.clone().iter().cloned() { - __result.push(field_to_child_node(&f, &source_indices)); - } - __result - }), - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }), - })) + node: Rc::new(Node { + name: "".to_string(), + span: span, + ident_span: None, + children: Rc::new({ let mut __result = Vec::new(); for f in outputs.clone().iter().cloned() { __result.push(field_to_child_node(&f, &source_indices)); } __result }), + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}), +})) } else { None } } -pub fn make_operation_node( - name: String, - ident_span: Option>, - inputs: Rc>>, - outputs: Rc>>, - response_props: Rc>>, - mock_props: Rc>>, - exit_props: Rc>>, - modifier_props: Rc>>, - transport: Option>, - span: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn make_operation_node(name: String, ident_span: Option>, inputs: Rc>>, outputs: Rc>>, response_props: Rc>>, mock_props: Rc>>, exit_props: Rc>>, modifier_props: Rc>>, transport: Option>, span: &Rc, source_indices: &Rc>>) -> Rc { { - let all_props = v2_rt::concat( - v2_rt::concat(v2_rt::concat(modifier_props, response_props), exit_props), - mock_props, - ); - Rc::new(Node { - name: name, - span: span.clone(), - ident_span: ident_span, - children: Rc::new(vec![]), - params: Rc::new({ - let mut __result = Vec::new(); - for f in inputs.iter().cloned() { - __result.push(make_param_node( - &field_node_name_at(f.clone(), source_indices.clone()), - field_node_type_expr(&f), - field_node_default_value(&f), - f.span.clone(), - node_name_span(&f), - )); - } - __result - }), - inferred: outputs_to_inferred(&outputs, span.clone(), source_indices.clone()), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: transport, - properties: all_props, - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } + let all_props = v2_rt::concat(v2_rt::concat(v2_rt::concat(modifier_props, response_props), exit_props), mock_props); +Rc::new(Node { + name: name, + span: span.clone(), + ident_span: ident_span, + children: Rc::new(vec![]), + params: Rc::new({ let mut __result = Vec::new(); for f in inputs.iter().cloned() { __result.push(make_param_node(&field_node_name_at(f.clone(), source_indices.clone()), field_node_type_expr(&f), field_node_default_value(&f), f.span.clone(), node_name_span(&f))); } __result }), + inferred: outputs_to_inferred(&outputs, span.clone(), source_indices.clone()), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: transport, + properties: all_props, + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} } -pub fn make_capability_node( - name: String, - ident_span: Option>, - inputs: Rc>>, - outputs: Rc>>, - span: &Rc, - source_indices: &Rc>>, -) -> Rc { +pub fn make_capability_node(name: String, ident_span: Option>, inputs: Rc>>, outputs: Rc>>, span: &Rc, source_indices: &Rc>>) -> Rc { Rc::new(Node { - name: name, - span: span.clone(), - ident_span: ident_span, - children: Rc::new(vec![]), - params: Rc::new({ - let mut __result = Vec::new(); - for f in inputs.iter().cloned() { - __result.push(make_param_node( - &field_node_name_at(f.clone(), source_indices.clone()), - field_node_type_expr(&f), - field_node_default_value(&f), - f.span.clone(), - node_name_span(&f), - )); - } - __result - }), - inferred: outputs_to_inferred(&outputs, span.clone(), source_indices.clone()), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: name, + span: span.clone(), + ident_span: ident_span, + children: Rc::new(vec![]), + params: Rc::new({ let mut __result = Vec::new(); for f in inputs.iter().cloned() { __result.push(make_param_node(&field_node_name_at(f.clone(), source_indices.clone()), field_node_type_expr(&f), field_node_default_value(&f), f.span.clone(), node_name_span(&f))); } __result }), + inferred: outputs_to_inferred(&outputs, span.clone(), source_indices.clone()), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn parse_type_def(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "type".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "type".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - parse_type_after_kw(&r.tokens.clone(), &ctx, &start_span) - } +parse_type_after_kw(&r.tokens.clone(), &ctx, &start_span) +} } -pub fn parse_type_after_kw( - tokens: &Rc>>, - ctx: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_type_after_kw(tokens: &Rc>>, ctx: &Rc, start_span: &Rc) -> Rc { { let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect_ident(&tokens); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let tokens = r.tokens.clone(); - let type_params_result = parse_optional_type_params(&tokens, ctx.clone()); - let type_params = type_params_result.params.clone(); - let tokens = skip_newlines(type_params_result.tokens.clone()); - let ctx = type_params_result.ctx.clone(); - let tokens = type_body_tokens_after_modifiers(tokens.clone()); - let inhabits_result = parse_optional_type_inhabits_clause(&tokens, ctx.clone()); - if has_err(inhabits_result.err.clone()) { + item: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let tokens = r.tokens.clone(); +let type_params_result = parse_optional_type_params(&tokens, ctx.clone()); +let type_params = type_params_result.params.clone(); +let tokens = skip_newlines(type_params_result.tokens.clone()); +let ctx = type_params_result.ctx.clone(); +let tokens = type_body_tokens_after_modifiers(tokens.clone()); +let inhabits_result = parse_optional_type_inhabits_clause(&tokens, ctx.clone()); +if has_err(inhabits_result.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: inhabits_result.tokens.clone(), - ctx: inhabits_result.ctx.clone(), - err: inhabits_result.err.clone(), - }); - } - let tokens = inhabits_result.tokens.clone(); - let ctx = inhabits_result.ctx.clone(); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = parse_field_list(skip_newlines(__ec.clone()), ctx.clone()); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: type_params.clone(), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - if has_err(r.err.clone()) { - return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let ctx = r.ctx.clone(); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { - return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let type_children = Rc::new({ - let mut __result = Vec::new(); - for f in r.fields.clone().iter().cloned() { - __result.push(field_to_child_node(&f, &ctx.source_indices.clone())); - } - __result - }); - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: type_children, - connective: Connective::Conj, - params: type_params.clone(), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r2.tokens.clone()), - ctx: ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectEq))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let tokens = skip_newlines(__ec.clone()); - parse_type_body_after_eq( - &tokens, - &ctx, - &name, - &name_span, - &start_span, - &type_params, - ) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: type_params.clone(), - inferred: Some(Rc::new(InferredNode::Resolved { - node: leaf_type_node(&name, &name_span), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: __eu.clone(), - ctx: ctx.clone(), - err: None, - }) - } - } - } - } - } + item: dummy.clone(), + tokens: inhabits_result.tokens.clone(), + ctx: inhabits_result.ctx.clone(), + err: inhabits_result.err.clone(), +}) + } +let tokens = inhabits_result.tokens.clone(); +let ctx = inhabits_result.ctx.clone(); +let type_properties = type_inhabits_properties(inhabits_result.type_expr.clone()); +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let r = parse_field_list(skip_newlines(__ec.clone()), ctx.clone()); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: type_params.clone(), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: type_properties.clone(), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +if has_err(r.err.clone()) { + return Rc::new(ItemResult { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let ctx = r.ctx.clone(); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { + return Rc::new(ItemResult { + item: named_dummy.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let type_children = Rc::new({ let mut __result = Vec::new(); for f in r.fields.clone().iter().cloned() { __result.push(field_to_child_node(&f, &ctx.source_indices.clone())); } __result }); +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: type_children, + connective: Connective::Conj, + params: type_params.clone(), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: type_properties.clone(), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r2.tokens.clone()), + ctx: ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => match (*eat(&tokens, Rc::new(ExpectedToken::ExpectEq))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let tokens = skip_newlines(__ec.clone()); +parse_type_body_after_eq(&tokens, &ctx, &name, &name_span, &start_span, &type_params, &type_properties) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: type_params.clone(), + inferred: Some(Rc::new(InferredNode::Resolved { + node: leaf_type_node(&name, &name_span), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: type_properties.clone(), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: __eu.clone(), + ctx: ctx.clone(), + err: None, +}) +}, +}, +} +} } -pub fn parse_type_body_from_prefix( - prefix: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_type_body_from_prefix(prefix: &Rc, start_span: &Rc) -> Rc { { let name = prefix.name.clone(); - let name_span = prefix.name_span.clone(); - let type_params = prefix.type_params.clone(); - let ctx = prefix.ctx.clone(); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: type_params.clone(), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let tokens = type_body_tokens_after_modifiers(skip_newlines(prefix.tokens.clone())); - let inhabits_result = parse_optional_type_inhabits_clause(&tokens, ctx.clone()); - if has_err(inhabits_result.err.clone()) { +let name_span = prefix.name_span.clone(); +let type_params = prefix.type_params.clone(); +let ctx = prefix.ctx.clone(); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: type_params.clone(), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let tokens = type_body_tokens_after_modifiers(skip_newlines(prefix.tokens.clone())); +let inhabits_result = parse_optional_type_inhabits_clause(&tokens, ctx.clone()); +if has_err(inhabits_result.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: inhabits_result.tokens.clone(), - ctx: inhabits_result.ctx.clone(), - err: inhabits_result.err.clone(), - }); - } - let tokens = inhabits_result.tokens.clone(); - let ctx = inhabits_result.ctx.clone(); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = parse_field_list(skip_newlines(__ec.clone()), ctx.clone()); - if has_err(r.err.clone()) { - return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let ctx = r.ctx.clone(); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { - return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let type_children = Rc::new({ - let mut __result = Vec::new(); - for f in r.fields.clone().iter().cloned() { - __result.push(field_to_child_node(&f, &ctx.source_indices.clone())); - } - __result - }); - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: type_children, - connective: Connective::Conj, - params: type_params.clone(), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r2.tokens.clone()), - ctx: ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectEq))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let tokens = skip_newlines(__ec.clone()); - parse_type_body_after_eq( - &tokens, - &ctx, - &name, - &name_span, - &start_span, - &type_params, - ) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: type_params.clone(), - inferred: Some(Rc::new(InferredNode::Resolved { - node: leaf_type_node(&name, &name_span), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: __eu.clone(), - ctx: ctx.clone(), - err: None, - }) - } - } - } - } - } + item: named_dummy.clone(), + tokens: inhabits_result.tokens.clone(), + ctx: inhabits_result.ctx.clone(), + err: inhabits_result.err.clone(), +}) + } +let tokens = inhabits_result.tokens.clone(); +let ctx = inhabits_result.ctx.clone(); +let type_properties = type_inhabits_properties(inhabits_result.type_expr.clone()); +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let r = parse_field_list(skip_newlines(__ec.clone()), ctx.clone()); +if has_err(r.err.clone()) { + return Rc::new(ItemResult { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let ctx = r.ctx.clone(); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { + return Rc::new(ItemResult { + item: named_dummy.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let type_children = Rc::new({ let mut __result = Vec::new(); for f in r.fields.clone().iter().cloned() { __result.push(field_to_child_node(&f, &ctx.source_indices.clone())); } __result }); +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: type_children, + connective: Connective::Conj, + params: type_params.clone(), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: type_properties, + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r2.tokens.clone()), + ctx: ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => match (*eat(&tokens, Rc::new(ExpectedToken::ExpectEq))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let tokens = skip_newlines(__ec.clone()); +parse_type_body_after_eq(&tokens, &ctx, &name, &name_span, &start_span, &type_params, &type_properties) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: type_params.clone(), + inferred: Some(Rc::new(InferredNode::Resolved { + node: leaf_type_node(&name, &name_span), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: type_properties, + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: __eu.clone(), + ctx: ctx.clone(), + err: None, +}) +}, +}, +} +} } -pub fn parse_type_body_after_eq( - tokens: &Rc>>, - ctx: &Rc, - name: &String, - name_span: &Rc, - start_span: &Rc, - type_params: &Rc>>, -) -> Rc { +pub fn parse_type_body_after_eq(tokens: &Rc>>, ctx: &Rc, name: &String, name_span: &Rc, start_span: &Rc, type_params: &Rc>>, type_properties: &Rc>>) -> Rc { { let dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: type_params.clone(), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - if tok_is_ident(tokens.clone().first().cloned()) { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: type_params.clone(), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: type_properties.clone(), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +if tok_is_ident(tokens.clone().first().cloned()) { { let r = expect_ident(&tokens); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + item: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let first_name = r.name.clone(); - let first_name_span = r.span.clone(); - let tokens = skip_newlines(r.tokens.clone()); - if (tok_is_lbrace(tokens.clone().first().cloned()) - || tok_is_pipe(tokens.clone().first().cloned())) - { +let first_name = r.name.clone(); +let first_name_span = r.span.clone(); +let tokens = skip_newlines(r.tokens.clone()); +if (tok_is_lbrace(tokens.clone().first().cloned()) || tok_is_pipe(tokens.clone().first().cloned())) { { - let r = parse_variant_fields( - &tokens, - ctx.clone(), - &first_name, - &first_name_span, - ); - if has_err(r.err.clone()) { + let r = parse_variant_fields(&tokens, ctx.clone(), &first_name, &first_name_span); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + item: dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let first_variant = r.variant.clone(); - let rest = parse_more_variants_acc( - r.tokens.clone(), - r.ctx.clone(), - Rc::new(vec![first_variant]), - ); - if has_err(rest.err.clone()) { +let first_variant = r.variant.clone(); +let rest = parse_more_variants_acc(r.tokens.clone(), r.ctx.clone(), Rc::new(vec![first_variant])); +if has_err(rest.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: rest.tokens.clone(), - ctx: rest.ctx.clone(), - err: rest.err.clone(), - }); + item: dummy.clone(), + tokens: rest.tokens.clone(), + ctx: rest.ctx.clone(), + err: rest.err.clone(), +}) } - let variants = rest.variants.clone(); - let type_children = Rc::new({ - let mut __result = Vec::new(); - for v in variants.iter().cloned() { - __result - .push(variant_to_child_node(&v, &ctx.source_indices.clone())); - } - __result - }); - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: type_children, - connective: Connective::Disj, - params: type_params.clone(), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(rest.tokens.clone()), - ctx: rest.ctx.clone(), - err: None, - }) - } +let variants = rest.variants.clone(); +let type_children = Rc::new({ let mut __result = Vec::new(); for v in variants.iter().cloned() { __result.push(variant_to_child_node(&v, &ctx.source_indices.clone())); } __result }); +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: type_children, + connective: Connective::Disj, + params: type_params.clone(), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: type_properties.clone(), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(rest.tokens.clone()), + ctx: rest.ctx.clone(), + err: None, +}) +} } else { { - let r = finish_type_expr_from_name( - &tokens, - ctx.clone(), - &first_name, - &first_name_span, - ); - if has_err(r.err.clone()) { + let r = finish_type_expr_from_name(&tokens, ctx.clone(), &first_name, &first_name_span); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + item: dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let wr = try_where_clause( - &r.tokens.clone(), - r.ctx.clone(), - &r.type_expr.clone(), - &start_span, - ); - if has_err(wr.err.clone()) { +let wr = try_where_clause(&r.tokens.clone(), r.ctx.clone(), &r.type_expr.clone(), &start_span); +if has_err(wr.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: wr.tokens.clone(), - ctx: wr.ctx.clone(), - err: wr.err.clone(), - }); + item: dummy.clone(), + tokens: wr.tokens.clone(), + ctx: wr.ctx.clone(), + err: wr.err.clone(), +}) } - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: type_params.clone(), - inferred: Some(Rc::new(InferredNode::Resolved { - node: wr.type_expr.clone(), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(wr.tokens.clone()), - ctx: wr.ctx.clone(), - err: None, - }) - } +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: type_params.clone(), + inferred: Some(Rc::new(InferredNode::Resolved { + node: wr.type_expr.clone(), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: type_properties.clone(), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(wr.tokens.clone()), + ctx: wr.ctx.clone(), + err: None, +}) +} } - } +} } else { { let r = parse_type_expr(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let wr = try_where_clause( - &r.tokens.clone(), - r.ctx.clone(), - &r.type_expr.clone(), - &start_span, - ); - if has_err(wr.err.clone()) { + item: dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let wr = try_where_clause(&r.tokens.clone(), r.ctx.clone(), &r.type_expr.clone(), &start_span); +if has_err(wr.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: wr.tokens.clone(), - ctx: wr.ctx.clone(), - err: wr.err.clone(), - }); - } - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: type_params.clone(), - inferred: Some(Rc::new(InferredNode::Resolved { - node: wr.type_expr.clone(), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(wr.tokens.clone()), - ctx: wr.ctx.clone(), - err: None, - }) - } + item: dummy.clone(), + tokens: wr.tokens.clone(), + ctx: wr.ctx.clone(), + err: wr.err.clone(), +}) + } +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: type_params.clone(), + inferred: Some(Rc::new(InferredNode::Resolved { + node: wr.type_expr.clone(), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: type_properties.clone(), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(wr.tokens.clone()), + ctx: wr.ctx.clone(), + err: None, +}) +} } - } +} } -pub fn try_where_clause( - tokens: &Rc>>, - ctx: Rc, - base_te: &Rc, - start_span: &Rc, -) -> Rc { +pub fn try_where_clause(tokens: &Rc>>, ctx: Rc, base_te: &Rc, start_span: &Rc) -> Rc { if tok_is_keyword(tokens.clone().first().cloned(), "where".to_string()) { match (*advance(&tokens)).clone() { - AdvanceResult::AdvanceOk { tokens: rest, .. } => { - let r = parse_predicates(rest.clone(), ctx); - if has_err(r.err.clone()) { - return Rc::new(TypeResult { - type_expr: base_te.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let predicate_node = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: r.predicates.clone(), - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let refined = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![base_te.clone()]), - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: Some(predicate_node), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(TypeResult { - type_expr: refined, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - AdvanceResult::AdvanceEof => Rc::new(TypeResult { - type_expr: base_te.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }), - } + AdvanceResult::AdvanceOk { tokens: rest, .. } => { + let r = parse_predicates(rest.clone(), ctx); +if has_err(r.err.clone()) { + return Rc::new(TypeResult { + type_expr: base_te.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let predicate_node = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: r.predicates.clone(), + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let refined = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![base_te.clone()]), + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: Some(predicate_node), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(TypeResult { + type_expr: refined, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +}, + AdvanceResult::AdvanceEof => Rc::new(TypeResult { + type_expr: base_te.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}), +} } else { Rc::new(TypeResult { - type_expr: base_te.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) + type_expr: base_te.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) } } @@ -3628,1005 +3134,757 @@ pub fn parse_predicates(tokens: Rc>>, ctx: Rc) -> Rc parse_predicates_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_predicates_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_predicates_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { let r = parse_single_predicate(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(PredsResult { - predicates: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - acc = v2_rt::rc_list_push(acc.clone(), r.predicate.clone()); - match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let __tco_0 = skip_newlines(__ec.clone()); - let __tco_1 = r.ctx.clone(); - tokens = __tco_0; - ctx = __tco_1; - continue; - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(PredsResult { - predicates: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } - } - } -} - -pub fn parse_single_predicate( - tokens: &Rc>>, - ctx: &Rc, -) -> Rc { + predicates: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +acc = v2_rt::rc_list_push(acc.clone(), r.predicate.clone()); +match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { { + let __tco_0 = skip_newlines(__ec.clone()); +let __tco_1 = r.ctx.clone(); +tokens = __tco_0; +ctx = __tco_1; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(PredsResult { + predicates: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); }, +} +} +} + +pub fn parse_single_predicate(tokens: &Rc>>, ctx: &Rc) -> Rc { { let zero_span = make_span(0, 0); - let dummy_pred = make_field_init_node( - &"".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitBool { value: false }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { +let dummy_pred = make_field_init_node(&"".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitBool { + value: false, +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone()); +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let pred_name = r.name.clone(); - let tokens = r.tokens.clone(); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLParen))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let tokens = __ec.clone(); - match pred_name.clone().as_str() { - "pattern" => { - let r2 = parse_string_literal_value(&tokens); - if has_err(r2.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r3.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(PredResult { - predicate: make_field_init_node( - &"Pattern".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: r2.value.clone(), - }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - "format" => { - let r2 = expect_ident(&tokens); - if has_err(r2.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r3.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(PredResult { - predicate: make_field_init_node( - &"Format".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: r2.name.clone(), - }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - "brand" => { - let r2 = parse_string_literal_value(&tokens); - if has_err(r2.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r3.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(PredResult { - predicate: make_field_init_node( - &"Brand".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: r2.value.clone(), - }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - "content" => { - let r2 = expect_ident(&tokens); - if has_err(r2.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r3.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(PredResult { - predicate: make_field_init_node( - &"ContentEncoding".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: r2.name.clone(), - }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - "domain" => { - let r2 = expect_ident(&tokens); - if has_err(r2.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r3.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(PredResult { - predicate: make_field_init_node( - &"Domain".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: r2.name.clone(), - }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - "range" => { - let r2 = parse_named_int_args(tokens.clone(), ctx.clone()); - if has_err(r2.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r3.err.clone()) { - return Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - let min_fields = if (r2.min_val.clone() != None) { - Rc::new(vec![make_field_init_node( - &"min".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitInt { - value: r2.min_val.clone().clone().unwrap(), - }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - )]) - } else { - Rc::new(vec![]) - }; - let max_fields = if (r2.max_val.clone() != None) { - Rc::new(vec![make_field_init_node( - &"max".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitInt { - value: r2.max_val.clone().clone().unwrap(), - }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - )]) - } else { - Rc::new(vec![]) - }; - Rc::new(PredResult { - predicate: make_field_init_node( - &"Range".to_string(), - make_expr_node( - Rc::new(ExprData::ExprRecordLit { parent_enum: None }), - v2_rt::concat(min_fields, max_fields), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } - _ => Rc::new(PredResult { - predicate: dummy_pred.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - v2_rt::concat( - v2_rt::concat( - "unknown where predicate `".to_string(), - pred_name.clone(), - ), - "`".to_string(), - ), - token_span(tokens.clone().first().cloned()), - )), - }), + predicate: dummy_pred.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let pred_name = r.name.clone(); +let tokens = r.tokens.clone(); +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLParen))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let tokens = __ec.clone(); +match pred_name.clone().as_str() { + "pattern" => { + let r2 = parse_string_literal_value(&tokens); +if has_err(r2.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r3.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) } - } - EatResult::EatUnchanged { tokens: __eu, .. } => match pred_name.clone().as_str() { - "non_empty" => Rc::new(PredResult { - predicate: make_field_init_node( - &"NonEmpty".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitBool { value: true }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }), - _ => Rc::new(PredResult { - predicate: make_field_init_node( - &pred_name, - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitBool { value: true }), - }), - Rc::new(vec![]), - None, - zero_span.clone(), - ), - zero_span.clone(), - zero_span.clone(), - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }), - }, - } - } -} - -pub fn parse_named_int_args( - tokens: Rc>>, - ctx: Rc, -) -> Rc { - { - let r = parse_single_named_int(tokens, &ctx); - if has_err(r.err.clone()) { - return Rc::new(RangeArgsResult { - min_val: None, - max_val: None, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r2 = parse_single_named_int(skip_newlines(__ec.clone()), &r.ctx.clone()); - if has_err(r2.err.clone()) { - return Rc::new(RangeArgsResult { - min_val: None, - max_val: None, - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); +Rc::new(PredResult { + predicate: make_field_init_node(&"Pattern".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: r2.value.clone(), +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone()), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, + "format" => { + let r2 = expect_ident(&tokens); +if has_err(r2.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r3.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) + } +Rc::new(PredResult { + predicate: make_field_init_node(&"Format".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: r2.name.clone(), +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone()), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, + "brand" => { + let r2 = parse_string_literal_value(&tokens); +if has_err(r2.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r3.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) + } +Rc::new(PredResult { + predicate: make_field_init_node(&"Brand".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: r2.value.clone(), +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone()), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, + "content" => { + let r2 = expect_ident(&tokens); +if has_err(r2.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r3.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) + } +Rc::new(PredResult { + predicate: make_field_init_node(&"ContentEncoding".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: r2.name.clone(), +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone()), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, + "domain" => { + let r2 = expect_ident(&tokens); +if has_err(r2.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r3.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) } - let min_val = if (r.arg_name.clone().as_str() == "min".to_string().as_str()) { - Some(r.arg_value.clone()) +Rc::new(PredResult { + predicate: make_field_init_node(&"Domain".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: r2.name.clone(), +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone()), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, + "range" => { + let r2 = parse_named_int_args(tokens.clone(), ctx.clone()); +if has_err(r2.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r3.err.clone()) { + return Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +let min_fields = if (r2.min_val.clone() != None) { + Rc::new(vec![make_field_init_node(&"min".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitInt { + value: r2.min_val.clone().clone().unwrap(), +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone())]) } else { - if (r2.arg_name.clone().as_str() == "min".to_string().as_str()) { - Some(r2.arg_value.clone()) - } else { - None - } + Rc::new(vec![]) }; - let max_val = if (r.arg_name.clone().as_str() == "max".to_string().as_str()) { - Some(r.arg_value.clone()) +let max_fields = if (r2.max_val.clone() != None) { + Rc::new(vec![make_field_init_node(&"max".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitInt { + value: r2.max_val.clone().clone().unwrap(), +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone())]) } else { - if (r2.arg_name.clone().as_str() == "max".to_string().as_str()) { - Some(r2.arg_value.clone()) - } else { - None - } + Rc::new(vec![]) }; - Rc::new(RangeArgsResult { - min_val: min_val, - max_val: max_val, - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let min_val = if (r.arg_name.clone().as_str() == "min".to_string().as_str()) { - Some(r.arg_value.clone()) +Rc::new(PredResult { + predicate: make_field_init_node(&"Range".to_string(), make_expr_node(Rc::new(ExprData::ExprRecordLit { + parent_enum: None, +}), v2_rt::concat(min_fields, max_fields), None, zero_span.clone()), zero_span.clone(), zero_span.clone()), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +}, + _ => Rc::new(PredResult { + predicate: dummy_pred.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error(v2_rt::concat(v2_rt::concat("unknown where predicate `".to_string(), pred_name.clone()), "`".to_string()), token_span(tokens.clone().first().cloned()))), +}), +} +}, + EatResult::EatUnchanged { tokens: __eu, .. } => match pred_name.clone().as_str() { + "non_empty" => Rc::new(PredResult { + predicate: make_field_init_node(&"NonEmpty".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitBool { + value: true, +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone()), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), + _ => Rc::new(PredResult { + predicate: make_field_init_node(&pred_name, make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitBool { + value: true, +}), +}), Rc::new(vec![]), None, zero_span.clone()), zero_span.clone(), zero_span.clone()), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +}, +} +} +} + +pub fn parse_named_int_args(tokens: Rc>>, ctx: Rc) -> Rc { + { + let r = parse_single_named_int(tokens, &ctx); +if has_err(r.err.clone()) { + return Rc::new(RangeArgsResult { + min_val: None, + max_val: None, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let r2 = parse_single_named_int(skip_newlines(__ec.clone()), &r.ctx.clone()); +if has_err(r2.err.clone()) { + return Rc::new(RangeArgsResult { + min_val: None, + max_val: None, + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let min_val = if (r.arg_name.clone().as_str() == "min".to_string().as_str()) { + Some(r.arg_value.clone()) + } else { + if (r2.arg_name.clone().as_str() == "min".to_string().as_str()) { + Some(r2.arg_value.clone()) } else { None - }; - let max_val = if (r.arg_name.clone().as_str() == "max".to_string().as_str()) { - Some(r.arg_value.clone()) + } + }; +let max_val = if (r.arg_name.clone().as_str() == "max".to_string().as_str()) { + Some(r.arg_value.clone()) + } else { + if (r2.arg_name.clone().as_str() == "max".to_string().as_str()) { + Some(r2.arg_value.clone()) } else { None - }; - Rc::new(RangeArgsResult { - min_val: min_val, - max_val: max_val, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - } - } + } + }; +Rc::new(RangeArgsResult { + min_val: min_val, + max_val: max_val, + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let min_val = if (r.arg_name.clone().as_str() == "min".to_string().as_str()) { + Some(r.arg_value.clone()) + } else { + None + }; +let max_val = if (r.arg_name.clone().as_str() == "max".to_string().as_str()) { + Some(r.arg_value.clone()) + } else { + None + }; +Rc::new(RangeArgsResult { + min_val: min_val, + max_val: max_val, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +}, +} +} } -pub fn parse_single_named_int( - tokens: Rc>>, - ctx: &Rc, -) -> Rc { +pub fn parse_single_named_int(tokens: Rc>>, ctx: &Rc) -> Rc { { let r = expect_ident(&tokens); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(NamedIntResult { - arg_name: "".to_string(), - arg_value: 0, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { + arg_name: "".to_string(), + arg_value: 0, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(NamedIntResult { - arg_name: name.clone(), - arg_value: 0, - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_int_literal_value(&r2.tokens.clone()); - if has_err(r3.err.clone()) { + arg_name: name.clone(), + arg_value: 0, + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_int_literal_value(&r2.tokens.clone()); +if has_err(r3.err.clone()) { return Rc::new(NamedIntResult { - arg_name: name.clone(), - arg_value: 0, - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(NamedIntResult { - arg_name: name.clone(), - arg_value: r3.value.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } + arg_name: name.clone(), + arg_value: 0, + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) + } +Rc::new(NamedIntResult { + arg_name: name.clone(), + arg_value: r3.value.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +} } -pub fn parse_variant_fields( - tokens: &Rc>>, - ctx: Rc, - vname: &String, - vname_span: &Rc, -) -> Rc { +pub fn parse_variant_fields(tokens: &Rc>>, ctx: Rc, vname: &String, vname_span: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = parse_field_list(skip_newlines(__ec.clone()), ctx); - if has_err(r.err.clone()) { - return Rc::new(VariantResult { - variant: make_variant_node( - &vname, - Rc::new(vec![]), - start_span.clone(), - vname_span.clone(), - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { - return Rc::new(VariantResult { - variant: make_variant_node( - &vname, - Rc::new(vec![]), - start_span.clone(), - vname_span.clone(), - ), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - let v = make_variant_node( - &vname, - r.fields.clone(), - start_span.clone(), - vname_span.clone(), - ); - Rc::new(VariantResult { - variant: v, - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let v = make_variant_node( - &vname, - Rc::new(vec![]), - vname_span.clone(), - vname_span.clone(), - ); - Rc::new(VariantResult { - variant: v, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) - } - } - } +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBrace))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let r = parse_field_list(skip_newlines(__ec.clone()), ctx); +if has_err(r.err.clone()) { + return Rc::new(VariantResult { + variant: make_variant_node(&vname, Rc::new(vec![]), start_span.clone(), vname_span.clone()), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { + return Rc::new(VariantResult { + variant: make_variant_node(&vname, Rc::new(vec![]), start_span.clone(), vname_span.clone()), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +let v = make_variant_node(&vname, r.fields.clone(), start_span.clone(), vname_span.clone()); +Rc::new(VariantResult { + variant: v, + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let v = make_variant_node(&vname, Rc::new(vec![]), vname_span.clone(), vname_span.clone()); +Rc::new(VariantResult { + variant: v, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) +}, +} +} } -pub fn parse_more_variants( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_more_variants(tokens: Rc>>, ctx: Rc) -> Rc { parse_more_variants_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_more_variants_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_more_variants_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectPipe))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - tokens = skip_newlines(__ec.clone()); - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { - return Rc::new(VariantsResult { - variants: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = parse_variant_fields( - &r.tokens.clone(), - ctx.clone(), - &r.name.clone(), - &r.span.clone(), - ); - if has_err(r2.err.clone()) { - return Rc::new(VariantsResult { - variants: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - { - let __tco_0 = r2.tokens.clone(); - let __tco_1 = r2.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(acc, r2.variant.clone()); - tokens = __tco_0; - ctx = __tco_1; - acc = __tco_2; - continue; - } - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(VariantsResult { - variants: acc, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } - } - } +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectPipe))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { tokens = skip_newlines(__ec.clone()); +let r = expect_ident(&tokens); +if has_err(r.err.clone()) { + return Rc::new(VariantsResult { + variants: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = parse_variant_fields(&r.tokens.clone(), ctx.clone(), &r.name.clone(), &r.span.clone()); +if has_err(r2.err.clone()) { + return Rc::new(VariantsResult { + variants: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +{ + let __tco_0 = r2.tokens.clone(); +let __tco_1 = r2.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(acc, r2.variant.clone()); +tokens = __tco_0; +ctx = __tco_1; +acc = __tco_2; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(VariantsResult { + variants: acc, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); }, +} +} +} + +pub fn parse_type_expr(tokens: &Rc>>, ctx: &Rc) -> Rc { + { + let tokens = skip_newlines(tokens.clone()); +let tok = tokens.clone().first().cloned(); +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +let span = token_span(tok.clone()); +match sh { + Some(TokenShape::ShLBrace) => { + let r = parse_field_list(skip_newlines(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>())), ctx.clone()); +if has_err(r.err.clone()) { + return Rc::new(TypeResult { + type_expr: leaf_type_node(&"".to_string(), &span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { + return Rc::new(TypeResult { + type_expr: leaf_type_node(&"".to_string(), &span), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +let te = Rc::new(Node { + name: "".to_string(), + span: span.clone(), + ident_span: None, + children: Rc::new({ let mut __result = Vec::new(); for f in r.fields.clone().iter().cloned() { __result.push(field_to_child_node(&f, &ctx.source_indices.clone())); } __result }), + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(TypeResult { + type_expr: te, + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +}, + Some(TokenShape::ShKeyword) => if (tok.clone().unwrap().text.clone().as_str() == "fn".to_string().as_str()) { + parse_callable_type_expr(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &ctx, &span) + } else { + Rc::new(TypeResult { + type_expr: leaf_type_node(&"".to_string(), &span), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("expected type expression".to_string(), span.clone())), +}) + }, + Some(TokenShape::ShIdent) => { + let n = tok.clone().unwrap().text.clone(); +finish_type_expr_from_name(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx.clone(), &n, &span) +}, + _ => Rc::new(TypeResult { + type_expr: leaf_type_node(&"".to_string(), &span), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("expected type expression".to_string(), span.clone())), +}), +} } - -pub fn parse_type_expr(tokens: &Rc>>, ctx: &Rc) -> Rc { - { - let tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let span = token_span(tok.clone()); - match sh { - Some(TokenShape::ShLBrace) => { - let r = parse_field_list( - skip_newlines(Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - )), - ctx.clone(), - ); - if has_err(r.err.clone()) { - return Rc::new(TypeResult { - type_expr: leaf_type_node(&"".to_string(), &span), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { - return Rc::new(TypeResult { - type_expr: leaf_type_node(&"".to_string(), &span), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - let te = Rc::new(Node { - name: "".to_string(), - span: span.clone(), - ident_span: None, - children: Rc::new({ - let mut __result = Vec::new(); - for f in r.fields.clone().iter().cloned() { - __result.push(field_to_child_node(&f, &ctx.source_indices.clone())); - } - __result - }), - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(TypeResult { - type_expr: te, - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - Some(TokenShape::ShKeyword) => { - if (tok.clone().unwrap().text.clone().as_str() == "fn".to_string().as_str()) { - parse_callable_type_expr( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &ctx, - &span, - ) - } else { - Rc::new(TypeResult { - type_expr: leaf_type_node(&"".to_string(), &span), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "expected type expression".to_string(), - span.clone(), - )), - }) - } - } - Some(TokenShape::ShIdent) => { - let n = tok.clone().unwrap().text.clone(); - finish_type_expr_from_name( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx.clone(), - &n, - &span, - ) - } - _ => Rc::new(TypeResult { - type_expr: leaf_type_node(&"".to_string(), &span), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "expected type expression".to_string(), - span.clone(), - )), - }), - } - } } -pub fn parse_callable_type_expr( - tokens: &Rc>>, - ctx: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_callable_type_expr(tokens: &Rc>>, ctx: &Rc, start_span: &Rc) -> Rc { { let dummy_te = leaf_type_node(&"".to_string(), &start_span); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); - if has_err(r.err.clone()) { +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); +if has_err(r.err.clone()) { return Rc::new(TypeResult { - type_expr: dummy_te.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let params_result = if tok_is_rparen(tokens.clone().first().cloned()) { + type_expr: dummy_te.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let params_result = if tok_is_rparen(tokens.clone().first().cloned()) { Rc::new(ParamsResult { - params: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + params: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } else { parse_callable_param_types(tokens.clone(), ctx.clone(), Rc::new(vec![])) }; - if has_err(params_result.err.clone()) { +if has_err(params_result.err.clone()) { return Rc::new(TypeResult { - type_expr: dummy_te.clone(), - tokens: params_result.tokens.clone(), - ctx: params_result.ctx.clone(), - err: params_result.err.clone(), - }); - } - let tokens = skip_newlines(params_result.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r2.err.clone()) { + type_expr: dummy_te.clone(), + tokens: params_result.tokens.clone(), + ctx: params_result.ctx.clone(), + err: params_result.err.clone(), +}) + } +let tokens = skip_newlines(params_result.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r2.err.clone()) { return Rc::new(TypeResult { - type_expr: dummy_te.clone(), - tokens: r2.tokens.clone(), - ctx: params_result.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectArrow)); - if has_err(r3.err.clone()) { + type_expr: dummy_te.clone(), + tokens: r2.tokens.clone(), + ctx: params_result.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectArrow)); +if has_err(r3.err.clone()) { return Rc::new(TypeResult { - type_expr: dummy_te.clone(), - tokens: r3.tokens.clone(), - ctx: params_result.ctx.clone(), - err: r3.err.clone(), - }); - } - let ret = parse_type_expr(&r3.tokens.clone(), ¶ms_result.ctx.clone()); - if has_err(ret.err.clone()) { + type_expr: dummy_te.clone(), + tokens: r3.tokens.clone(), + ctx: params_result.ctx.clone(), + err: r3.err.clone(), +}) + } +let ret = parse_type_expr(&r3.tokens.clone(), ¶ms_result.ctx.clone()); +if has_err(ret.err.clone()) { return Rc::new(TypeResult { - type_expr: dummy_te.clone(), - tokens: ret.tokens.clone(), - ctx: ret.ctx.clone(), - err: ret.err.clone(), - }); - } - let te = Rc::new(Node { - name: "Callable".to_string(), - span: start_span.clone(), - ident_span: Some(start_span.clone()), - children: Rc::new(vec![]), - connective: Connective::Arrow, - params: params_result.params.clone(), - inferred: Some(Rc::new(InferredNode::Resolved { - node: ret.type_expr.clone(), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - maybe_optional( - &ret.tokens.clone(), - ret.ctx.clone(), - &te, - start_span.clone(), - ) - } + type_expr: dummy_te.clone(), + tokens: ret.tokens.clone(), + ctx: ret.ctx.clone(), + err: ret.err.clone(), +}) + } +let te = Rc::new(Node { + name: "Callable".to_string(), + span: start_span.clone(), + ident_span: Some(start_span.clone()), + children: Rc::new(vec![]), + connective: Connective::Arrow, + params: params_result.params.clone(), + inferred: Some(Rc::new(InferredNode::Resolved { + node: ret.type_expr.clone(), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +maybe_optional(&ret.tokens.clone(), ret.ctx.clone(), &te, start_span.clone()) +} } -pub fn parse_callable_param_types( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_callable_param_types(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { let r = parse_type_expr(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ParamsResult { - params: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let param = make_param_node( - &"".to_string(), - r.type_expr.clone(), - None, - r.type_expr.clone().span.clone(), - r.type_expr.clone().span.clone(), - ); - acc = v2_rt::rc_list_push(acc.clone(), param); - match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - tokens = skip_newlines(__ec.clone()); - if tok_is_rparen(tokens.clone().first().cloned()) { - break Rc::new(ParamsResult { - params: acc.clone(), - tokens: tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } else { - { - let __tco_0 = r.ctx.clone(); - ctx = __tco_0; - continue; - } - } - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(ParamsResult { - params: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } - } - } + params: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let param = make_param_node(&"".to_string(), r.type_expr.clone(), None, r.type_expr.clone().span.clone(), r.type_expr.clone().span.clone()); +acc = v2_rt::rc_list_push(acc.clone(), param); +match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { tokens = skip_newlines(__ec.clone()); +if tok_is_rparen(tokens.clone().first().cloned()) { + break Rc::new(ParamsResult { + params: acc.clone(), + tokens: tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); +} else { + { + let __tco_0 = r.ctx.clone(); +ctx = __tco_0; +continue; +} +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(ParamsResult { + params: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); }, +} +} } -pub fn finish_type_expr_from_name( - tokens: &Rc>>, - ctx: Rc, - type_name: &String, - start_span: &Rc, -) -> Rc { +pub fn finish_type_expr_from_name(tokens: &Rc>>, ctx: Rc, type_name: &String, start_span: &Rc) -> Rc { { let dummy_te = leaf_type_node(&type_name, &start_span); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLt))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = parse_type_expr(&__ec, &ctx); - if has_err(r.err.clone()) { - return r.clone(); - } - let first_arg = r.type_expr.clone(); - let type_args = - collect_type_args(r.tokens.clone(), r.ctx.clone(), Rc::new(vec![first_arg])); - if has_err(type_args.err.clone()) { - return Rc::new(TypeResult { - type_expr: dummy_te.clone(), - tokens: type_args.tokens.clone(), - ctx: type_args.ctx.clone(), - err: type_args.err.clone(), - }); - } - let r3 = expect(&type_args.tokens.clone(), &Rc::new(ExpectedToken::ExpectGt)); - if has_err(r3.err.clone()) { - return Rc::new(TypeResult { - type_expr: dummy_te.clone(), - tokens: r3.tokens.clone(), - ctx: type_args.ctx.clone(), - err: r3.err.clone(), - }); - } - let te = Rc::new(Node { - name: type_name.clone(), - span: start_span.clone(), - ident_span: Some(start_span.clone()), - children: type_args.args.clone(), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - maybe_optional( - &r3.tokens.clone(), - type_args.ctx.clone(), - &te, - start_span.clone(), - ) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let te = leaf_type_node(&type_name, &start_span); - maybe_optional(&tokens, ctx, &te, start_span.clone()) - } - } - } +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLt))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let r = parse_type_expr(&__ec, &ctx); +if has_err(r.err.clone()) { + return r.clone() + } +let first_arg = r.type_expr.clone(); +let type_args = collect_type_args(r.tokens.clone(), r.ctx.clone(), Rc::new(vec![first_arg])); +if has_err(type_args.err.clone()) { + return Rc::new(TypeResult { + type_expr: dummy_te.clone(), + tokens: type_args.tokens.clone(), + ctx: type_args.ctx.clone(), + err: type_args.err.clone(), +}) + } +let r3 = expect(&type_args.tokens.clone(), &Rc::new(ExpectedToken::ExpectGt)); +if has_err(r3.err.clone()) { + return Rc::new(TypeResult { + type_expr: dummy_te.clone(), + tokens: r3.tokens.clone(), + ctx: type_args.ctx.clone(), + err: r3.err.clone(), +}) + } +let te = Rc::new(Node { + name: type_name.clone(), + span: start_span.clone(), + ident_span: Some(start_span.clone()), + children: type_args.args.clone(), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +maybe_optional(&r3.tokens.clone(), type_args.ctx.clone(), &te, start_span.clone()) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let te = leaf_type_node(&type_name, &start_span); +maybe_optional(&tokens, ctx, &te, start_span.clone()) +}, +} +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -4636,72 +3894,54 @@ pub struct TypeParamsResult { pub ctx: Rc, } -pub fn parse_optional_type_params( - tokens: &Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_optional_type_params(tokens: &Rc>>, ctx: Rc) -> Rc { match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLt))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let params_result = collect_type_param_names(__ec.clone(), ctx, Rc::new(vec![])); - let r = expect( - ¶ms_result.tokens.clone(), - &Rc::new(ExpectedToken::ExpectGt), - ); - Rc::new(TypeParamsResult { - params: params_result.params.clone(), - tokens: r.tokens.clone(), - ctx: params_result.ctx.clone(), - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(TypeParamsResult { - params: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx, - }), - } + EatResult::EatConsumed { tokens: __ec, .. } => { + let params_result = collect_type_param_names(__ec.clone(), ctx, Rc::new(vec![])); +let r = expect(¶ms_result.tokens.clone(), &Rc::new(ExpectedToken::ExpectGt)); +Rc::new(TypeParamsResult { + params: params_result.params.clone(), + tokens: r.tokens.clone(), + ctx: params_result.ctx.clone(), +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(TypeParamsResult { + params: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx, +}), +} } -pub fn collect_type_param_names( - mut tokens: Rc>>, - mut ctx: Rc, - mut params: Rc>>, -) -> Rc { +pub fn collect_type_param_names(mut tokens: Rc>>, mut ctx: Rc, mut params: Rc>>) -> Rc { loop { if tok_is_ident(tokens.clone().first().cloned()) { let r = expect_ident(&tokens); - let span = r.span.clone(); - let param = make_param_node( - &r.name.clone(), - leaf_type_node(&r.name.clone(), &span), - None, - span.clone(), - span.clone(), - ); - let next_params = v2_rt::rc_list_push(params, param); - match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let __tco_0 = __ec.clone(); - let __tco_1 = next_params; - tokens = __tco_0; - params = __tco_1; - continue; - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(TypeParamsResult { - params: next_params, - tokens: r.tokens.clone(), - ctx: ctx, - }); - } - } - } else { +let span = r.span.clone(); +let param = make_param_node(&r.name.clone(), leaf_type_node(&r.name.clone(), &span), None, span.clone(), span.clone()); +let next_params = v2_rt::rc_list_push(params, param); +match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { { + let __tco_0 = __ec.clone(); +let __tco_1 = next_params; +tokens = __tco_0; +params = __tco_1; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(TypeParamsResult { + params: next_params, + tokens: r.tokens.clone(), + ctx: ctx, +}); }, +} +} else { break Rc::new(TypeParamsResult { - params: params, - tokens: tokens.clone(), - ctx: ctx, - }); - } - } + params: params, + tokens: tokens.clone(), + ctx: ctx, +}); +} +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -4712,1075 +3952,954 @@ pub struct TypeArgsResult { pub err: Option>, } -pub fn collect_type_args( - mut tokens: Rc>>, - mut ctx: Rc, - mut args: Rc>>, -) -> Rc { +pub fn collect_type_args(mut tokens: Rc>>, mut ctx: Rc, mut args: Rc>>) -> Rc { loop { match (*eat(&tokens, Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = parse_type_expr(&__ec, &ctx); - if has_err(r.err.clone()) { - return Rc::new(TypeArgsResult { - args: args.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(args, r.type_expr.clone()); - tokens = __tco_0; - ctx = __tco_1; - args = __tco_2; - continue; - } - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(TypeArgsResult { - args: args.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } - } - } + EatResult::EatConsumed { tokens: __ec, .. } => { let r = parse_type_expr(&__ec, &ctx); +if has_err(r.err.clone()) { + return Rc::new(TypeArgsResult { + args: args.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(args, r.type_expr.clone()); +tokens = __tco_0; +ctx = __tco_1; +args = __tco_2; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(TypeArgsResult { + args: args.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); }, +} +} } -pub fn maybe_optional( - tokens: &Rc>>, - ctx: Rc, - te: &Rc, - start_span: Rc, -) -> Rc { +pub fn maybe_optional(tokens: &Rc>>, ctx: Rc, te: &Rc, start_span: Rc) -> Rc { match (*eat(&tokens, Rc::new(ExpectedToken::ExpectQuestion))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let ote = Rc::new(Node { - name: te.name.clone(), - span: te.span.clone(), - ident_span: te.ident_span.clone(), - children: te.children.clone(), - connective: te.connective.clone(), - params: te.params.clone(), - inferred: te.inferred.clone(), - return_cardinality: Cardinality::CardOptional, - uses: te.uses.clone(), - body: te.body.clone(), - transport: te.transport.clone(), - properties: te.properties.clone(), - type_annotation: te.type_annotation.clone(), - is_self_recursive: te.is_self_recursive.clone(), - has_non_tail_self_call: te.has_non_tail_self_call.clone(), - match_pattern: te.match_pattern.clone(), - expr_data: te.expr_data.clone(), - ident: None, - }); - Rc::new(TypeResult { - type_expr: ote, - tokens: __ec.clone(), - ctx: ctx, - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(TypeResult { - type_expr: te.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }), - } + EatResult::EatConsumed { tokens: __ec, .. } => { + let ote = Rc::new(Node { + name: te.name.clone(), + span: te.span.clone(), + ident_span: te.ident_span.clone(), + children: te.children.clone(), + connective: te.connective.clone(), + params: te.params.clone(), + inferred: te.inferred.clone(), + return_cardinality: Cardinality::CardOptional, + uses: te.uses.clone(), + body: te.body.clone(), + transport: te.transport.clone(), + properties: te.properties.clone(), + type_annotation: te.type_annotation.clone(), + is_self_recursive: te.is_self_recursive.clone(), + has_non_tail_self_call: te.has_non_tail_self_call.clone(), + match_pattern: te.match_pattern.clone(), + expr_data: te.expr_data.clone(), + ident: None, +}); +Rc::new(TypeResult { + type_expr: ote, + tokens: __ec.clone(), + ctx: ctx, + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(TypeResult { + type_expr: te.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}), +} } pub fn parse_field_list(tokens: Rc>>, ctx: Rc) -> Rc { parse_field_list_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_field_list_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_field_list_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - if ((tok_is_rbrace(tok.clone()) || tok_is_rparen(tok.clone())) || tok_is_eof(tok.clone())) { +let tok = tokens.clone().first().cloned(); +if ((tok_is_rbrace(tok.clone()) || tok_is_rparen(tok.clone())) || tok_is_eof(tok.clone())) { break Rc::new(FieldsResult { - fields: acc, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + fields: acc, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { if (tok_is_ident(tok.clone()) || tok_is_keyword_name(tok.clone())) { let r = parse_field(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(FieldsResult { - fields: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - tokens = r.tokens.clone(); - let e = eat(&tokens, Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => tokens.clone(), - }); - { + fields: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +tokens = r.tokens.clone(); +let e = eat(&tokens, Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => tokens.clone(), +}); +{ let __tco_0 = r.ctx.clone(); - let __tco_1 = v2_rt::rc_list_push(acc, r.field.clone()); - ctx = __tco_0; - acc = __tco_1; - continue; - } - } else { +let __tco_1 = v2_rt::rc_list_push(acc, r.field.clone()); +ctx = __tco_0; +acc = __tco_1; +continue; +} +} else { break Rc::new(FieldsResult { - fields: acc, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } - } - } + fields: acc, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} +} +} } pub fn parse_field(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy_field = make_field_node( - &"".to_string(), - leaf_type_node(&"".to_string(), &start_span), - Cardinality::Required, - None, - None, - start_span.clone(), - start_span.clone(), - ); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { +let dummy_field = make_field_node(&"".to_string(), leaf_type_node(&"".to_string(), &start_span), Cardinality::Required, None, None, start_span.clone(), start_span.clone()); +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(FieldResult { - field: dummy_field.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let tokens = r.tokens.clone(); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { + field: dummy_field.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let tokens = r.tokens.clone(); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(FieldResult { - field: dummy_field.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_type_expr(&r2.tokens.clone(), &ctx); - if has_err(r3.err.clone()) { + field: dummy_field.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_type_expr(&r2.tokens.clone(), &ctx); +if has_err(r3.err.clone()) { return Rc::new(FieldResult { - field: dummy_field.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - let wr = try_where_clause( - &r3.tokens.clone(), - r3.ctx.clone(), - &r3.type_expr.clone(), - &start_span, - ); - if has_err(wr.err.clone()) { + field: dummy_field.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let wr = try_where_clause(&r3.tokens.clone(), r3.ctx.clone(), &r3.type_expr.clone(), &start_span); +if has_err(wr.err.clone()) { return Rc::new(FieldResult { - field: dummy_field.clone(), - tokens: wr.tokens.clone(), - ctx: wr.ctx.clone(), - err: wr.err.clone(), - }); - } - let te = wr.type_expr.clone(); - let tokens = wr.tokens.clone(); - let ctx = wr.ctx.clone(); - let from_r = parse_optional_from_key(&tokens, ctx.clone()); - let from_key = from_r.from_key.clone(); - let tokens = from_r.tokens.clone(); - let ctx = from_r.ctx.clone(); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectEq))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r4 = parse_expr(__ec.clone(), ctx.clone()); - if has_err(r4.err.clone()) { - return Rc::new(FieldResult { - field: dummy_field.clone(), - tokens: r4.tokens.clone(), - ctx: r4.ctx.clone(), - err: r4.err.clone(), - }); - } - let f = make_field_node( - &name, - te.clone(), - te.return_cardinality.clone(), - Some(r4.expr.clone()), - from_key, - start_span.clone(), - name_span, - ); - Rc::new(FieldResult { - field: f, - tokens: r4.tokens.clone(), - ctx: r4.ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let f = make_field_node( - &name, - te.clone(), - te.return_cardinality.clone(), - None, - from_key, - start_span.clone(), - name_span, - ); - Rc::new(FieldResult { - field: f, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - } - } + field: dummy_field.clone(), + tokens: wr.tokens.clone(), + ctx: wr.ctx.clone(), + err: wr.err.clone(), +}) + } +let te = wr.type_expr.clone(); +let tokens = wr.tokens.clone(); +let ctx = wr.ctx.clone(); +let from_r = parse_optional_from_key(&tokens, ctx.clone()); +let from_key = from_r.from_key.clone(); +let tokens = from_r.tokens.clone(); +let ctx = from_r.ctx.clone(); +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectEq))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let r4 = parse_expr(__ec.clone(), ctx.clone()); +if has_err(r4.err.clone()) { + return Rc::new(FieldResult { + field: dummy_field.clone(), + tokens: r4.tokens.clone(), + ctx: r4.ctx.clone(), + err: r4.err.clone(), +}) + } +let f = make_field_node(&name, te.clone(), te.return_cardinality.clone(), Some(r4.expr.clone()), from_key, start_span.clone(), name_span); +Rc::new(FieldResult { + field: f, + tokens: r4.tokens.clone(), + ctx: r4.ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let f = make_field_node(&name, te.clone(), te.return_cardinality.clone(), None, from_key, start_span.clone(), name_span); +Rc::new(FieldResult { + field: f, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, +} +} } -pub fn parse_optional_from_key( - tokens: &Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_optional_from_key(tokens: &Rc>>, ctx: Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShIdent) => { - if (tok.clone().unwrap().text.clone().as_str() == "from".to_string().as_str()) { - { - let tok2 = tokens.clone().get(1 as usize).cloned(); - let sh2 = match tok2.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh2 { - Some(TokenShape::ShLitStr) => { - let key = tok2.clone().unwrap().text.clone(); - Rc::new(FromKeyResult { - from_key: Some(key), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(2 as usize) - .collect::>(), - ), - ctx: ctx, - err: None, - }) - } - _ => Rc::new(FromKeyResult { - from_key: None, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }), - } - } - } else { - Rc::new(FromKeyResult { - from_key: None, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) - } - } - _ => Rc::new(FromKeyResult { - from_key: None, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }), - } - } +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShIdent) => if (tok.clone().unwrap().text.clone().as_str() == "from".to_string().as_str()) { + { + let tok2 = tokens.clone().get(1 as usize).cloned(); +let sh2 = match tok2.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh2 { + Some(TokenShape::ShLitStr) => { + let key = tok2.clone().unwrap().text.clone(); +Rc::new(FromKeyResult { + from_key: Some(key), + tokens: Rc::new(tokens.clone().iter().cloned().skip(2 as usize).collect::>()), + ctx: ctx, + err: None, +}) +}, + _ => Rc::new(FromKeyResult { + from_key: None, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}), +} +} + } else { + Rc::new(FromKeyResult { + from_key: None, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) + }, + _ => Rc::new(FromKeyResult { + from_key: None, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}), +} +} } pub fn parse_fn_def(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "fn".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "fn".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - parse_fn_after_kw(&r.tokens.clone(), &ctx, &start_span) - } +parse_fn_after_kw(&r.tokens.clone(), &ctx, &start_span) +} } -pub fn parse_fn_after_kw( - tokens: &Rc>>, - ctx: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_fn_after_kw(tokens: &Rc>>, ctx: &Rc, start_span: &Rc) -> Rc { { let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect_ident(&tokens); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let tokens = r.tokens.clone(); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = parse_params(&tokens, &ctx); - if has_err(r.err.clone()) { + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let tokens = r.tokens.clone(); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = parse_params(&tokens, &ctx); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let params = r.params.clone(); - let tokens = r.tokens.clone(); - let ctx = r.ctx.clone(); - let ret = parse_optional_inferred(&tokens, ctx.clone()); - if has_err(ret.err.clone()) { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let params = r.params.clone(); +let tokens = r.tokens.clone(); +let ctx = r.ctx.clone(); +let ret = parse_optional_inferred(&tokens, ctx.clone()); +if has_err(ret.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: ret.tokens.clone(), - ctx: ret.ctx.clone(), - err: ret.err.clone(), - }); - } - let inferred = ret.inferred.clone(); - let tokens = ret.tokens.clone(); - let ctx = ret.ctx.clone(); - let r = parse_block(&skip_newlines(tokens.clone()), &ctx); - if has_err(r.err.clone()) { + item: named_dummy.clone(), + tokens: ret.tokens.clone(), + ctx: ret.ctx.clone(), + err: ret.err.clone(), +}) + } +let inferred = ret.inferred.clone(); +let tokens = ret.tokens.clone(); +let ctx = ret.ctx.clone(); +let r = parse_block(&skip_newlines(tokens.clone()), &ctx); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let body = r.expr.clone(); - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: params, - inferred: inferred, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: Some(body), - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r.tokens.clone()), - ctx: r.ctx.clone(), - err: None, - }) - } + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let body = r.expr.clone(); +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: params, + inferred: inferred, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: Some(body), + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r.tokens.clone()), + ctx: r.ctx.clone(), + err: None, +}) +} } -pub fn parse_fn_body_from_prefix( - prefix: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_fn_body_from_prefix(prefix: &Rc, start_span: &Rc) -> Rc { { let name = prefix.name.clone(); - let name_span = prefix.name_span.clone(); - let type_params = prefix.type_params.clone(); - let params = prefix.params.clone(); - let inferred = prefix.inferred.clone(); - let ctx = prefix.ctx.clone(); - let all_params = v2_rt::concat(type_params, params); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: all_params.clone(), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = parse_block(&skip_newlines(prefix.tokens.clone()), &ctx); - if has_err(r.err.clone()) { +let name_span = prefix.name_span.clone(); +let type_params = prefix.type_params.clone(); +let params = prefix.params.clone(); +let inferred = prefix.inferred.clone(); +let ctx = prefix.ctx.clone(); +let all_params = v2_rt::concat(type_params, params); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: all_params.clone(), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = parse_block(&skip_newlines(prefix.tokens.clone()), &ctx); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let body = r.expr.clone(); - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: all_params.clone(), - inferred: inferred, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: Some(body), - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r.tokens.clone()), - ctx: r.ctx.clone(), - err: None, - }) - } + item: named_dummy, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let body = r.expr.clone(); +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: all_params.clone(), + inferred: inferred, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: Some(body), + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r.tokens.clone()), + ctx: r.ctx.clone(), + err: None, +}) +} } pub fn parse_func_def(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let kw = tok_keyword_text(tokens.clone().first().cloned()); - let r = if (kw.clone().as_str() == "func".to_string().as_str()) { - expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "func".to_string(), - }), - ) +let dummy = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let kw = tok_keyword_text(tokens.clone().first().cloned()); +let r = if (kw.clone().as_str() == "func".to_string().as_str()) { + expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "func".to_string(), +})) } else { if (kw.clone().as_str() == "pattern".to_string().as_str()) { - expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "pattern".to_string(), - }), - ) + expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "pattern".to_string(), +})) } else { if (kw.clone().as_str() == "interface".to_string().as_str()) { - expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "interface".to_string(), - }), - ) + expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "interface".to_string(), +})) } else { - expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "func".to_string(), - }), - ) + expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "func".to_string(), +})) } } }; - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let has_uses = (kw.clone().as_str() == "func".to_string().as_str()); - let form = Rc::new(ItemForm { - kind: ItemFormKind::OtherForm, - keyword: kw.clone(), - has_type_params: false, - has_params: true, - has_return_type: true, - return_required: false, - has_uses: has_uses, - body_kind: BodyKind::BlockBody, - }); - let prefix = parse_item_prefix(&r.tokens.clone(), &ctx, &form); - if has_err(prefix.err.clone()) { + item: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let has_uses = (kw.clone().as_str() == "func".to_string().as_str()); +let form = Rc::new(ItemForm { + kind: ItemFormKind::OtherForm, + keyword: kw.clone(), + has_type_params: false, + has_params: true, + has_return_type: true, + return_required: false, + has_uses: has_uses, + body_kind: BodyKind::BlockBody, +}); +let prefix = parse_item_prefix(&r.tokens.clone(), &ctx, &form); +if has_err(prefix.err.clone()) { return Rc::new(ItemResult { - item: dummy.clone(), - tokens: prefix.tokens.clone(), - ctx: prefix.ctx.clone(), - err: prefix.err.clone(), - }); + item: dummy.clone(), + tokens: prefix.tokens.clone(), + ctx: prefix.ctx.clone(), + err: prefix.err.clone(), +}) } - parse_block_body_from_prefix(&prefix, &start_span) - } +parse_block_body_from_prefix(&prefix, &start_span) +} } -pub fn parse_block_item_after_kw( - tokens: &Rc>>, - ctx: &Rc, - start_span: &Rc, - form: Rc, -) -> Rc { +pub fn parse_block_item_after_kw(tokens: &Rc>>, ctx: &Rc, start_span: &Rc, form: Rc) -> Rc { { let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect_ident(&tokens); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let tokens = r.tokens.clone(); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = parse_params(&tokens, &ctx); - if has_err(r.err.clone()) { + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let tokens = r.tokens.clone(); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = parse_params(&tokens, &ctx); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let params = r.params.clone(); - let tokens = r.tokens.clone(); - let ctx = r.ctx.clone(); - let ret = parse_optional_inferred(&tokens, ctx.clone()); - if has_err(ret.err.clone()) { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let params = r.params.clone(); +let tokens = r.tokens.clone(); +let ctx = r.ctx.clone(); +let ret = parse_optional_inferred(&tokens, ctx.clone()); +if has_err(ret.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: ret.tokens.clone(), - ctx: ret.ctx.clone(), - err: ret.err.clone(), - }); - } - let inferred = ret.inferred.clone(); - let tokens = ret.tokens.clone(); - let ctx = ret.ctx.clone(); - let uses_r = if form.has_uses.clone() { + item: named_dummy.clone(), + tokens: ret.tokens.clone(), + ctx: ret.ctx.clone(), + err: ret.err.clone(), +}) + } +let inferred = ret.inferred.clone(); +let tokens = ret.tokens.clone(); +let ctx = ret.ctx.clone(); +let uses_r = if form.has_uses.clone() { parse_uses_clause(&skip_newlines(tokens.clone()), ctx.clone()) } else { Rc::new(UsesResult { - uses: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + uses: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) }; - if has_err(uses_r.err.clone()) { +if has_err(uses_r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: uses_r.tokens.clone(), - ctx: uses_r.ctx.clone(), - err: uses_r.err.clone(), - }); - } - let uses = uses_r.uses.clone(); - let tokens = uses_r.tokens.clone(); - let ctx = uses_r.ctx.clone(); - let r = parse_block(&skip_newlines(tokens.clone()), &ctx); - if has_err(r.err.clone()) { + item: named_dummy.clone(), + tokens: uses_r.tokens.clone(), + ctx: uses_r.ctx.clone(), + err: uses_r.err.clone(), +}) + } +let uses = uses_r.uses.clone(); +let tokens = uses_r.tokens.clone(); +let ctx = uses_r.ctx.clone(); +let r = parse_block(&skip_newlines(tokens.clone()), &ctx); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let body = r.expr.clone(); - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: params, - inferred: inferred, - return_cardinality: Cardinality::Required, - uses: uses, - body: Some(body), - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r.tokens.clone()), - ctx: r.ctx.clone(), - err: None, - }) - } + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let body = r.expr.clone(); +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: params, + inferred: inferred, + return_cardinality: Cardinality::Required, + uses: uses, + body: Some(body), + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r.tokens.clone()), + ctx: r.ctx.clone(), + err: None, +}) +} } -pub fn parse_block_body_from_prefix( - prefix: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_block_body_from_prefix(prefix: &Rc, start_span: &Rc) -> Rc { { let name = prefix.name.clone(); - let name_span = prefix.name_span.clone(); - let params = prefix.params.clone(); - let inferred = prefix.inferred.clone(); - let uses = prefix.uses.clone(); - let ctx = prefix.ctx.clone(); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = parse_block(&skip_newlines(prefix.tokens.clone()), &ctx); - if has_err(r.err.clone()) { +let name_span = prefix.name_span.clone(); +let params = prefix.params.clone(); +let inferred = prefix.inferred.clone(); +let uses = prefix.uses.clone(); +let ctx = prefix.ctx.clone(); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = parse_block(&skip_newlines(prefix.tokens.clone()), &ctx); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let body = r.expr.clone(); - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: params, - inferred: inferred, - return_cardinality: Cardinality::Required, - uses: uses, - body: Some(body), - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r.tokens.clone()), - ctx: r.ctx.clone(), - err: None, - }) - } + item: named_dummy, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let body = r.expr.clone(); +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: params, + inferred: inferred, + return_cardinality: Cardinality::Required, + uses: uses, + body: Some(body), + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r.tokens.clone()), + ctx: r.ctx.clone(), + err: None, +}) +} } -pub fn parse_no_body_from_prefix( - prefix: &Rc, - start_span: Rc, -) -> Rc { +pub fn parse_no_body_from_prefix(prefix: &Rc, start_span: Rc) -> Rc { { let item = Rc::new(Node { - name: prefix.name.clone(), - span: start_span, - ident_span: Some(prefix.name_span.clone()), - children: Rc::new(vec![]), - params: prefix.params.clone(), - inferred: prefix.inferred.clone(), - return_cardinality: Cardinality::Required, - uses: prefix.uses.clone(), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: prefix.tokens.clone(), - ctx: prefix.ctx.clone(), - err: None, - }) - } + name: prefix.name.clone(), + span: start_span, + ident_span: Some(prefix.name_span.clone()), + children: Rc::new(vec![]), + params: prefix.params.clone(), + inferred: prefix.inferred.clone(), + return_cardinality: Cardinality::Required, + uses: prefix.uses.clone(), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: prefix.tokens.clone(), + ctx: prefix.ctx.clone(), + err: None, +}) +} } pub fn parse_uses_clause(tokens: &Rc>>, ctx: Rc) -> Rc { { let tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - let is_uses = match tok { - Some(t) => { - (is_ident_shape(t.shape.clone()) - && (t.text.clone().as_str() == "uses".to_string().as_str())) - } - None => false, - }; - if is_uses { +let tok = tokens.clone().first().cloned(); +let is_uses = match tok { + Some(t) => (is_ident_shape(t.shape.clone()) && (t.text.clone().as_str() == "uses".to_string().as_str())), + None => false, +}; +if is_uses { { - let r = parse_uses_list( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx, - ); - if has_err(r.err.clone()) { - return r.clone(); + let r = parse_uses_list(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx); +if has_err(r.err.clone()) { + return r.clone() } - Rc::new(UsesResult { - uses: r.uses.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +Rc::new(UsesResult { + uses: r.uses.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { Rc::new(UsesResult { - uses: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) + uses: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) } - } +} } pub fn parse_uses_list(tokens: Rc>>, ctx: Rc) -> Rc { parse_uses_list_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_uses_list_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_uses_list_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { let r = parse_uses_entry(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(UsesResult { - uses: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - acc = v2_rt::rc_list_push(acc.clone(), r.resource_use.clone()); - match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let __tco_0 = __ec.clone(); - let __tco_1 = r.ctx.clone(); - tokens = __tco_0; - ctx = __tco_1; - continue; - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(UsesResult { - uses: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } - } - } + uses: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +acc = v2_rt::rc_list_push(acc.clone(), r.resource_use.clone()); +match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { { + let __tco_0 = __ec.clone(); +let __tco_1 = r.ctx.clone(); +tokens = __tco_0; +ctx = __tco_1; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(UsesResult { + uses: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); }, +} +} } pub fn parse_uses_entry(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy = make_resource_use_node( - &"".to_string(), - leaf_type_node(&"".to_string(), &start_span), - start_span.clone(), - start_span.clone(), - ); - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { +let dummy = make_resource_use_node(&"".to_string(), leaf_type_node(&"".to_string(), &start_span), start_span.clone(), start_span.clone()); +let r = expect_ident(&tokens); +if has_err(r.err.clone()) { return Rc::new(ResUseResult { - resource_use: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let tokens = r.tokens.clone(); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { - return Rc::new(ResUseResult { - resource_use: dummy.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_type_expr(&r2.tokens.clone(), &ctx); - if has_err(r3.err.clone()) { + resource_use: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let tokens = r.tokens.clone(); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(ResUseResult { - resource_use: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - match (*eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectLParen))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let ar = parse_resource_config_args(__ec.clone(), r3.ctx.clone()); - if has_err(ar.err.clone()) { - return Rc::new(ResUseResult { - resource_use: dummy.clone(), - tokens: ar.tokens.clone(), - ctx: ar.ctx.clone(), - err: ar.err.clone(), - }); - } - let r4 = expect(&ar.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r4.err.clone()) { - return Rc::new(ResUseResult { - resource_use: dummy.clone(), - tokens: r4.tokens.clone(), - ctx: ar.ctx.clone(), - err: r4.err.clone(), - }); - } - let res_node = Rc::new(Node { - name: r3.type_expr.clone().name.clone(), - span: r3.type_expr.clone().span.clone(), - ident_span: r3.type_expr.clone().ident_span.clone(), - children: r3.type_expr.clone().children.clone(), - params: r3.type_expr.clone().params.clone(), - inferred: r3.type_expr.clone().inferred.clone(), - return_cardinality: r3.type_expr.clone().return_cardinality.clone(), - uses: r3.type_expr.clone().uses.clone(), - body: r3.type_expr.clone().body.clone(), - connective: r3.type_expr.clone().connective.clone(), - transport: r3.type_expr.clone().transport.clone(), - properties: ar.fields.clone(), - type_annotation: r3.type_expr.clone().type_annotation.clone(), - is_self_recursive: r3.type_expr.clone().is_self_recursive.clone(), - has_non_tail_self_call: r3.type_expr.clone().has_non_tail_self_call.clone(), - match_pattern: r3.type_expr.clone().match_pattern.clone(), - expr_data: r3.type_expr.clone().expr_data.clone(), - ident: None, - }); - let ru = - make_resource_use_node(&name, res_node, start_span.clone(), r.span.clone()); - Rc::new(ResUseResult { - resource_use: ru, - tokens: r4.tokens.clone(), - ctx: ar.ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let ru = make_resource_use_node( - &name, - r3.type_expr.clone(), - start_span.clone(), - r.span.clone(), - ); - Rc::new(ResUseResult { - resource_use: ru, - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: None, - }) - } + resource_use: dummy.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - } +let r3 = parse_type_expr(&r2.tokens.clone(), &ctx); +if has_err(r3.err.clone()) { + return Rc::new(ResUseResult { + resource_use: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +match (*eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectLParen))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let ar = parse_resource_config_args(__ec.clone(), r3.ctx.clone()); +if has_err(ar.err.clone()) { + return Rc::new(ResUseResult { + resource_use: dummy.clone(), + tokens: ar.tokens.clone(), + ctx: ar.ctx.clone(), + err: ar.err.clone(), +}) + } +let r4 = expect(&ar.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r4.err.clone()) { + return Rc::new(ResUseResult { + resource_use: dummy.clone(), + tokens: r4.tokens.clone(), + ctx: ar.ctx.clone(), + err: r4.err.clone(), +}) + } +let res_node = Rc::new(Node { + name: r3.type_expr.clone().name.clone(), + span: r3.type_expr.clone().span.clone(), + ident_span: r3.type_expr.clone().ident_span.clone(), + children: r3.type_expr.clone().children.clone(), + params: r3.type_expr.clone().params.clone(), + inferred: r3.type_expr.clone().inferred.clone(), + return_cardinality: r3.type_expr.clone().return_cardinality.clone(), + uses: r3.type_expr.clone().uses.clone(), + body: r3.type_expr.clone().body.clone(), + connective: r3.type_expr.clone().connective.clone(), + transport: r3.type_expr.clone().transport.clone(), + properties: ar.fields.clone(), + type_annotation: r3.type_expr.clone().type_annotation.clone(), + is_self_recursive: r3.type_expr.clone().is_self_recursive.clone(), + has_non_tail_self_call: r3.type_expr.clone().has_non_tail_self_call.clone(), + match_pattern: r3.type_expr.clone().match_pattern.clone(), + expr_data: r3.type_expr.clone().expr_data.clone(), + ident: None, +}); +let ru = make_resource_use_node(&name, res_node, start_span.clone(), r.span.clone()); +Rc::new(ResUseResult { + resource_use: ru, + tokens: r4.tokens.clone(), + ctx: ar.ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let ru = make_resource_use_node(&name, r3.type_expr.clone(), start_span.clone(), r.span.clone()); +Rc::new(ResUseResult { + resource_use: ru, + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: None, +}) +}, +} +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -5791,981 +4910,768 @@ pub struct ResConfigResult { pub err: Option>, } -pub fn parse_resource_config_args( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_resource_config_args(tokens: Rc>>, ctx: Rc) -> Rc { parse_resource_config_acc(skip_newlines(tokens), ctx, Rc::new(vec![])) } -pub fn parse_resource_config_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_resource_config_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { if tok_is_rparen(tokens.clone().first().cloned()) { return Rc::new(ResConfigResult { - fields: acc.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); + fields: acc.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } - let zero_span = make_span(0, 0); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { - return Rc::new(ResConfigResult { - fields: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let field_name = r.name.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { +let zero_span = make_span(0, 0); +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(ResConfigResult { - fields: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { + fields: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let field_name = r.name.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(ResConfigResult { - fields: Rc::new(vec![]), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - let fi = make_field_init_node(&field_name, r3.expr.clone(), zero_span, r.span.clone()); - acc = v2_rt::rc_list_push(acc.clone(), fi); - match (*eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let __tco_0 = skip_newlines(__ec.clone()); - let __tco_1 = r3.ctx.clone(); - tokens = __tco_0; - ctx = __tco_1; - continue; - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(ResConfigResult { - fields: acc.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: None, - }); - } + fields: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - } -} - -pub fn parse_optional_inferred( - tokens: &Rc>>, - ctx: Rc, -) -> Rc { +let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); +if has_err(r3.err.clone()) { + return Rc::new(ResConfigResult { + fields: Rc::new(vec![]), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let fi = make_field_init_node(&field_name, r3.expr.clone(), zero_span, r.span.clone()); +acc = v2_rt::rc_list_push(acc.clone(), fi); +match (*eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { { + let __tco_0 = skip_newlines(__ec.clone()); +let __tco_1 = r3.ctx.clone(); +tokens = __tco_0; +ctx = __tco_1; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(ResConfigResult { + fields: acc.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: None, +}); }, +} +} +} + +pub fn parse_optional_inferred(tokens: &Rc>>, ctx: Rc) -> Rc { match (*eat(&tokens, Rc::new(ExpectedToken::ExpectArrow))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = parse_type_expr(&__ec, &ctx); - if has_err(r.err.clone()) { - return Rc::new(OptRetResult { - inferred: None, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - Rc::new(OptRetResult { - inferred: Some(Rc::new(InferredNode::Resolved { - node: r.type_expr.clone(), - })), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(OptRetResult { - inferred: None, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }), - } + EatResult::EatConsumed { tokens: __ec, .. } => { + let r = parse_type_expr(&__ec, &ctx); +if has_err(r.err.clone()) { + return Rc::new(OptRetResult { + inferred: None, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +Rc::new(OptRetResult { + inferred: Some(Rc::new(InferredNode::Resolved { + node: r.type_expr.clone(), +})), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(OptRetResult { + inferred: None, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}), +} } pub fn parse_service_def(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "service".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "service".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - parse_service_after_kw(&r.tokens.clone(), &ctx, &start_span) - } +parse_service_after_kw(&r.tokens.clone(), &ctx, &start_span) +} } -pub fn parse_service_after_kw( - tokens: &Rc>>, - ctx: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_service_after_kw(tokens: &Rc>>, ctx: &Rc, start_span: &Rc) -> Rc { { let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r_ns = expect_name(&tokens); - if has_err(r_ns.err.clone()) { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r_ns = expect_name(&tokens); +if has_err(r_ns.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r_ns.tokens.clone(), - ctx: ctx.clone(), - err: r_ns.err.clone(), - }); - } - let namespace_root = r_ns.name.clone(); - let r = parse_dotted_ident_rest( - r_ns.tokens.clone(), - namespace_root.clone(), - r_ns.span.clone(), - ); - let name = r.name.clone(); - let svc_name_span = r.span.clone(); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(svc_name_span.clone()), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectLBrace)); - if has_err(r.err.clone()) { + item: dummy, + tokens: r_ns.tokens.clone(), + ctx: ctx.clone(), + err: r_ns.err.clone(), +}) + } +let namespace_root = r_ns.name.clone(); +let r = parse_dotted_ident_rest(r_ns.tokens.clone(), namespace_root.clone(), r_ns.span.clone()); +let name = r.name.clone(); +let svc_name_span = r.span.clone(); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(svc_name_span.clone()), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r = parse_service_body(&tokens, ctx.clone()); - if has_err(r.err.clone()) { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r = parse_service_body(&tokens, ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - let ns_prop = make_field_init_node( - &"namespace_root".to_string(), - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: namespace_root.clone(), - }), - }), - Rc::new(vec![]), - None, - start_span.clone(), - ), - start_span.clone(), - no_span(), - ); - let svc_props = match r.config.clone() { - Some(cfg) => service_config_properties( - cfg.endpoint.clone(), - cfg.auth.clone(), - cfg.auth_input.clone(), - cfg.auth_source.clone(), - cfg.rate_limit.clone(), - cfg.retry.clone(), - ), - None => Rc::new(vec![]), - }; - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(svc_name_span.clone()), - children: r.operations.clone(), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: Some(r.transport.clone()), - properties: v2_rt::concat(Rc::new(vec![ns_prop]), svc_props), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r2.tokens.clone()), - ctx: r.ctx.clone(), - err: None, - }) - } + item: named_dummy.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +let ns_prop = make_field_init_node(&"namespace_root".to_string(), make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: namespace_root.clone(), +}), +}), Rc::new(vec![]), None, start_span.clone()), start_span.clone(), no_span()); +let svc_props = match r.config.clone() { + Some(cfg) => service_config_properties(cfg.endpoint.clone(), cfg.auth.clone(), cfg.auth_input.clone(), cfg.auth_source.clone(), cfg.rate_limit.clone(), cfg.retry.clone()), + None => Rc::new(vec![]), +}; +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(svc_name_span.clone()), + children: r.operations.clone(), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: Some(r.transport.clone()), + properties: v2_rt::concat(Rc::new(vec![ns_prop]), svc_props), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r2.tokens.clone()), + ctx: r.ctx.clone(), + err: None, +}) +} } -pub fn parse_service_body( - tokens: &Rc>>, - ctx: Rc, -) -> Rc { - parse_service_entries( - tokens.clone(), - ctx, - None, - local_transport_node(token_span(tokens.clone().first().cloned())), - Rc::new(vec![]), - ) -} - -pub fn parse_service_entries( - mut tokens: Rc>>, - mut ctx: Rc, - mut config: Option>, - mut transport: Rc, - mut operations: Rc>>, -) -> Rc { +pub fn parse_service_body(tokens: &Rc>>, ctx: Rc) -> Rc { + parse_service_entries(tokens.clone(), ctx, None, local_transport_node(token_span(tokens.clone().first().cloned())), Rc::new(vec![])) +} + +pub fn parse_service_entries(mut tokens: Rc>>, mut ctx: Rc, mut config: Option>, mut transport: Rc, mut operations: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - if (tok_is_rbrace(tok.clone()) || tok_is_eof(tok.clone())) { +let tok = tokens.clone().first().cloned(); +if (tok_is_rbrace(tok.clone()) || tok_is_eof(tok.clone())) { break Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let span = token_span(tok.clone()); - match sh { - Some(TokenShape::ShIdent) => { - let id = tok.clone().unwrap().text.clone(); - if (id.clone().as_str() == "config".to_string().as_str()) { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { - return Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = parse_service_config_block( - skip_newlines(r.tokens.clone()), - ctx.clone(), - ); - if has_err(r2.err.clone()) { - return Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - tokens = skip_newlines(r2.tokens.clone()); - let r3 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r3.err.clone()) { - return Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - { - let __tco_0 = r3.tokens.clone(); - let __tco_1 = r2.ctx.clone(); - let __tco_2 = Some(r2.config.clone()); - tokens = __tco_0; - ctx = __tco_1; - config = __tco_2; - continue; - } - } else { - if (id.clone().as_str() == "transport".to_string().as_str()) { - let r = parse_transport_binding( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &ctx, - ); - if has_err(r.err.clone()) { - return Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = r.transport.clone(); - tokens = __tco_0; - ctx = __tco_1; - transport = __tco_2; - continue; - } - } else { - break Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "expected config, transport, or operation in service block" - .to_string(), - span, - )), - }); - } - } - } - Some(TokenShape::ShKeyword) => { - let kw_text = tok.clone().unwrap().text.clone(); - if (kw_text.as_str() == "operation".to_string().as_str()) { - let r = parse_operation_def(&tokens, &ctx); - if has_err(r.err.clone()) { - return Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(operations, r.operation.clone()); - tokens = __tco_0; - ctx = __tco_1; - operations = __tco_2; - continue; - } - } else { - break Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "expected config, transport, or operation in service block" - .to_string(), - span, - )), - }); + Some(t) => Some(t.shape.clone()), + None => None, +}; +let span = token_span(tok.clone()); +match sh { + Some(TokenShape::ShIdent) => { let id = tok.clone().unwrap().text.clone(); +if (id.clone().as_str() == "config".to_string().as_str()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { + return Rc::new(ServiceBodyResult { + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = parse_service_config_block(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { + return Rc::new(ServiceBodyResult { + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +tokens = skip_newlines(r2.tokens.clone()); +let r3 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { + return Rc::new(ServiceBodyResult { + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +{ + let __tco_0 = r3.tokens.clone(); +let __tco_1 = r2.ctx.clone(); +let __tco_2 = Some(r2.config.clone()); +tokens = __tco_0; +ctx = __tco_1; +config = __tco_2; +continue; +} +} else { + if (id.clone().as_str() == "transport".to_string().as_str()) { + let r = parse_transport_binding(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &ctx); +if has_err(r.err.clone()) { + return Rc::new(ServiceBodyResult { + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - } - _ => { +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = r.transport.clone(); +tokens = __tco_0; +ctx = __tco_1; +transport = __tco_2; +continue; +} +} else { break Rc::new(ServiceBodyResult { - config: config.clone(), - transport: transport.clone(), - operations: operations.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "expected config, transport, or operation in service block".to_string(), - span, - )), - }); - } - } - } - } + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("expected config, transport, or operation in service block".to_string(), span)), +}); +} +} }, + Some(TokenShape::ShKeyword) => { let kw_text = tok.clone().unwrap().text.clone(); +if (kw_text.as_str() == "operation".to_string().as_str()) { + let r = parse_operation_def(&tokens, &ctx); +if has_err(r.err.clone()) { + return Rc::new(ServiceBodyResult { + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(operations, r.operation.clone()); +tokens = __tco_0; +ctx = __tco_1; +operations = __tco_2; +continue; +} +} else { + break Rc::new(ServiceBodyResult { + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("expected config, transport, or operation in service block".to_string(), span)), +}); +} }, + _ => { break Rc::new(ServiceBodyResult { + config: config.clone(), + transport: transport.clone(), + operations: operations.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("expected config, transport, or operation in service block".to_string(), span)), +}); }, +} +} +} } -pub fn parse_service_config_block( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_service_config_block(tokens: Rc>>, ctx: Rc) -> Rc { parse_config_fields(tokens, ctx, None, None, None, None, None, None) } -pub fn parse_config_fields( - mut tokens: Rc>>, - mut ctx: Rc, - mut endpoint: Option>, - mut auth: Option>, - mut auth_input: Option>, - mut auth_source: Option>, - mut rate_limit: Option>, - mut retry: Option>, -) -> Rc { +pub fn parse_config_fields(mut tokens: Rc>>, mut ctx: Rc, mut endpoint: Option>, mut auth: Option>, mut auth_input: Option>, mut auth_source: Option>, mut rate_limit: Option>, mut retry: Option>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { let cfg = Rc::new(ServiceConfig { - endpoint: match endpoint { - Some(e) => e.clone(), - None => make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: "".to_string(), - }), - }), - Rc::new(vec![]), - None, - make_span(0, 0), - ), - }, - auth: auth, - auth_input: auth_input, - auth_source: auth_source, - rate_limit: rate_limit, - retry: retry, - }); - break Rc::new(ConfigResult { - config: cfg, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + endpoint: match endpoint { + Some(e) => e.clone(), + None => make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: "".to_string(), +}), +}), Rc::new(vec![]), None, make_span(0, 0)), +}, + auth: auth, + auth_input: auth_input, + auth_source: auth_source, + rate_limit: rate_limit, + retry: retry, +}); +break Rc::new(ConfigResult { + config: cfg, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let dummy_cfg = Rc::new(ServiceConfig { - endpoint: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: "".to_string(), - }), - }), - Rc::new(vec![]), - None, - make_span(0, 0), - ), - auth: None, - auth_input: None, - auth_source: None, - rate_limit: None, - retry: None, - }); - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { + endpoint: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: "".to_string(), +}), +}), Rc::new(vec![]), None, make_span(0, 0)), + auth: None, + auth_input: None, + auth_source: None, + rate_limit: None, + retry: None, +}); +let r = expect_ident(&tokens); +if has_err(r.err.clone()) { return Rc::new(ConfigResult { - config: dummy_cfg.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + config: dummy_cfg.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let fname = r.name.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { +let fname = r.name.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(ConfigResult { - config: dummy_cfg.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); + config: dummy_cfg.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { +let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); +if has_err(r3.err.clone()) { return Rc::new(ConfigResult { - config: dummy_cfg.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - tokens = r3.tokens.clone(); - ctx = r3.ctx.clone(); - let e = eat(&tokens, Rc::new(ExpectedToken::ExpectComma)); - tokens = match (*e.clone()).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => tokens.clone(), - }; - match fname.as_str() { - "endpoint" => { - let __tco_0 = Some(r3.expr.clone()); - endpoint = __tco_0; - continue; - } - "auth" => { - let __tco_0 = Some(r3.expr.clone()); - auth = __tco_0; - continue; - } - "auth_input" => { - let __tco_0 = Some(r3.expr.clone()); - auth_input = __tco_0; - continue; - } - "auth_source" => { - let __tco_0 = Some(r3.expr.clone()); - auth_source = __tco_0; - continue; - } - "rate_limit" => { - let __tco_0 = Some(r3.expr.clone()); - rate_limit = __tco_0; - continue; - } - "retry" => { - let __tco_0 = Some(r3.expr.clone()); - retry = __tco_0; - continue; - } - _ => { - continue; - } - } - } - } + config: dummy_cfg.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +tokens = r3.tokens.clone(); +ctx = r3.ctx.clone(); +let e = eat(&tokens, Rc::new(ExpectedToken::ExpectComma)); +tokens = match (*e.clone()).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => tokens.clone(), +}; +match fname.as_str() { + "endpoint" => { { + let __tco_0 = Some(r3.expr.clone()); +endpoint = __tco_0; +continue; +} }, + "auth" => { { + let __tco_0 = Some(r3.expr.clone()); +auth = __tco_0; +continue; +} }, + "auth_input" => { { + let __tco_0 = Some(r3.expr.clone()); +auth_input = __tco_0; +continue; +} }, + "auth_source" => { { + let __tco_0 = Some(r3.expr.clone()); +auth_source = __tco_0; +continue; +} }, + "rate_limit" => { { + let __tco_0 = Some(r3.expr.clone()); +rate_limit = __tco_0; +continue; +} }, + "retry" => { { + let __tco_0 = Some(r3.expr.clone()); +retry = __tco_0; +continue; +} }, + _ => { { + continue; +} }, +} +} +} } -pub fn parse_transport_binding( - tokens: &Rc>>, - ctx: &Rc, -) -> Rc { +pub fn parse_transport_binding(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy = local_transport_node(span); - let tok = tokens.clone().first().cloned(); - let tok_text = match tok.clone() { - Some(t) => t.text.clone(), - None => "".to_string(), - }; - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShIdent) => { - if (tok_text.clone().as_str() == "rest".to_string().as_str()) { +let dummy = local_transport_node(span); +let tok = tokens.clone().first().cloned(); +let tok_text = match tok.clone() { + Some(t) => t.text.clone(), + None => "".to_string(), +}; +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShIdent) => if (tok_text.clone().as_str() == "rest".to_string().as_str()) { + { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { + return Rc::new(TransportResult { + transport: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = parse_rest_binding_body(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { + return Rc::new(TransportResult { + transport: r2.transport.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { + return Rc::new(TransportResult { + transport: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +Rc::new(TransportResult { + transport: r2.transport.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +} + } else { + if (tok_text.clone().as_str() == "shell".to_string().as_str()) { + { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { + return Rc::new(TransportResult { + transport: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = parse_shell_binding_body(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { + return Rc::new(TransportResult { + transport: r2.transport.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { + return Rc::new(TransportResult { + transport: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +Rc::new(TransportResult { + transport: r2.transport.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +} + } else { + if (tok_text.clone().as_str() == "file".to_string().as_str()) { { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + transport: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let r2 = - parse_rest_binding_body(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r2.err.clone()) { +let r2 = parse_file_binding_body(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { return Rc::new(TransportResult { - transport: r2.transport.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); + transport: r2.transport.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); + transport: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) } - Rc::new(TransportResult { - transport: r2.transport.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } +Rc::new(TransportResult { + transport: r2.transport.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +} } else { - if (tok_text.clone().as_str() == "shell".to_string().as_str()) { - { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { - return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = parse_shell_binding_body( - skip_newlines(r.tokens.clone()), - ctx.clone(), - ); - if has_err(r2.err.clone()) { - return Rc::new(TransportResult { - transport: r2.transport.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { - return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(TransportResult { - transport: r2.transport.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } - } else { - if (tok_text.clone().as_str() == "file".to_string().as_str()) { - { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { - return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = parse_file_binding_body( - skip_newlines(r.tokens.clone()), - ctx.clone(), - ); - if has_err(r2.err.clone()) { - return Rc::new(TransportResult { - transport: r2.transport.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { - return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(TransportResult { - transport: r2.transport.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } - } else { - Rc::new(TransportResult { - transport: dummy.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - } + Rc::new(TransportResult { + transport: dummy.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } } - _ => Rc::new(TransportResult { - transport: dummy.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }), - } - } + }, + _ => Rc::new(TransportResult { + transport: dummy.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +} +} +} + +pub fn parse_rest_binding_body(tokens: Rc>>, ctx: Rc) -> Rc { + parse_rest_fields(tokens, ctx, None, None, None, None, None, None, Rc::new(vec![])) } -pub fn parse_rest_binding_body( - tokens: Rc>>, - ctx: Rc, -) -> Rc { - parse_rest_fields( - tokens, - ctx, - None, - None, - None, - None, - None, - None, - Rc::new(vec![]), - ) -} - -pub fn parse_rest_fields( - mut tokens: Rc>>, - mut ctx: Rc, - mut base_url: Option>, - mut method: Option>, - mut path_template: Option>, - mut query: Option>, - mut request_body: Option>, - mut response_format: Option>, - mut headers: Rc>>, -) -> Rc { +pub fn parse_rest_fields(mut tokens: Rc>>, mut ctx: Rc, mut base_url: Option>, mut method: Option>, mut path_template: Option>, mut query: Option>, mut request_body: Option>, mut response_format: Option>, mut headers: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let span = token_span(tokens.clone().first().cloned()); - let dummy = local_transport_node(span.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +let span = token_span(tokens.clone().first().cloned()); +let dummy = local_transport_node(span.clone()); +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { let bu = match base_url { - Some(e) => e.clone(), - None => make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: "".to_string(), - }), - }), - Rc::new(vec![]), - None, - make_span(0, 0), - ), - }; - break Rc::new(TransportResult { - transport: rest_transport_node( - bu, - Rc::new(vec![]), - headers, - method, - path_template, - query, - request_body, - response_format, - span.clone(), - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + Some(e) => e.clone(), + None => make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: "".to_string(), +}), +}), Rc::new(vec![]), None, make_span(0, 0)), +}; +break Rc::new(TransportResult { + transport: rest_transport_node(bu, Rc::new(vec![]), headers, method, path_template, query, request_body, response_format, span.clone()), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let r = expect_ident(&tokens); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + transport: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let fname = r.name.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { +let fname = r.name.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); + transport: dummy.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { +let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); +if has_err(r3.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = match (*e.clone()).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r3.tokens.clone(), - }; - ctx = r3.ctx.clone(); - if (fname.clone().as_str() == transport_url_key().as_str()) { + transport: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = match (*e.clone()).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r3.tokens.clone(), +}; +ctx = r3.ctx.clone(); +if (fname.clone().as_str() == transport_url_key().as_str()) { { let __tco_0 = Some(r3.expr.clone()); - base_url = __tco_0; - continue; - } - } else { +base_url = __tco_0; +continue; +} +} else { if (fname.clone().as_str() == transport_method_key().as_str()) { { let __tco_0 = Some(r3.expr.clone()); - method = __tco_0; - continue; - } - } else { +method = __tco_0; +continue; +} +} else { if (fname.clone().as_str() == transport_path_template_key().as_str()) { { let __tco_0 = Some(r3.expr.clone()); - path_template = __tco_0; - continue; - } - } else { +path_template = __tco_0; +continue; +} +} else { if (fname.clone().as_str() == transport_query_key().as_str()) { { let __tco_0 = Some(r3.expr.clone()); - query = __tco_0; - continue; - } - } else { +query = __tco_0; +continue; +} +} else { if (fname.clone().as_str() == transport_body_key().as_str()) { { let __tco_0 = Some(r3.expr.clone()); - request_body = __tco_0; - continue; - } - } else { - if (fname.clone().as_str() - == transport_response_format_key().as_str()) - { +request_body = __tco_0; +continue; +} +} else { + if (fname.clone().as_str() == transport_response_format_key().as_str()) { { let __tco_0 = Some(r3.expr.clone()); - response_format = __tco_0; - continue; - } - } else { - if (fname.clone().as_str() == transport_headers_key().as_str()) - { +response_format = __tco_0; +continue; +} +} else { + if (fname.clone().as_str() == transport_headers_key().as_str()) { let h = match (*r3.expr.clone().expr_data.clone()).clone() { ExprData::ExprRecordLit { .. } => r3.expr.clone().children.clone(), _ => return Rc::new(TransportResult { @@ -6778,1048 +5684,812 @@ pub fn parse_rest_fields( }), "".to_string())), }), }; - { +{ let __tco_0 = h; - headers = __tco_0; - continue; - } - } else { +headers = __tco_0; +continue; +} +} else { { continue; - } - } - } - } - } - } - } - } - } - } +} +} +} +} +} +} +} +} +} +} } -pub fn parse_shell_binding_body( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_shell_binding_body(tokens: Rc>>, ctx: Rc) -> Rc { parse_shell_fields(tokens, ctx, Rc::new(vec![]), None) } -pub fn parse_shell_fields( - mut tokens: Rc>>, - mut ctx: Rc, - mut argv: Rc>>, - mut stdin: Option>, -) -> Rc { +pub fn parse_shell_fields(mut tokens: Rc>>, mut ctx: Rc, mut argv: Rc>>, mut stdin: Option>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let span = token_span(tokens.clone().first().cloned()); - let dummy = local_transport_node(span.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +let span = token_span(tokens.clone().first().cloned()); +let dummy = local_transport_node(span.clone()); +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(TransportResult { - transport: shell_transport_node(argv, Rc::new(vec![]), stdin, &span), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + transport: shell_transport_node(argv, Rc::new(vec![]), stdin, &span), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let r = expect_ident(&tokens); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + transport: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let fname = r.name.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { +let fname = r.name.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); + transport: dummy.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - if (fname.clone().as_str() == "argv".to_string().as_str()) { +if (fname.clone().as_str() == "argv".to_string().as_str()) { let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectLBracket)); - if has_err(r3.err.clone()) { +if has_err(r3.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); + transport: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) } - let r4 = parse_expr_list_until( - r3.tokens.clone(), - ctx.clone(), - Rc::new(ExpectedToken::ExpectRBracket), - ); - if has_err(r4.err.clone()) { +let r4 = parse_expr_list_until(r3.tokens.clone(), ctx.clone(), Rc::new(ExpectedToken::ExpectRBracket)); +if has_err(r4.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r4.tokens.clone(), - ctx: r4.ctx.clone(), - err: r4.err.clone(), - }); + transport: dummy.clone(), + tokens: r4.tokens.clone(), + ctx: r4.ctx.clone(), + err: r4.err.clone(), +}) } - let r5 = expect(&r4.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBracket)); - if has_err(r5.err.clone()) { +let r5 = expect(&r4.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBracket)); +if has_err(r5.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r5.tokens.clone(), - ctx: r4.ctx.clone(), - err: r5.err.clone(), - }); - } - let e = eat(&r5.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r5.tokens.clone(), - }; - { + transport: dummy.clone(), + tokens: r5.tokens.clone(), + ctx: r4.ctx.clone(), + err: r5.err.clone(), +}) + } +let e = eat(&r5.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r5.tokens.clone(), +}; +{ let __tco_0 = r4.ctx.clone(); - let __tco_1 = r4.exprs.clone(); - ctx = __tco_0; - argv = __tco_1; - continue; - } - } else { +let __tco_1 = r4.exprs.clone(); +ctx = __tco_0; +argv = __tco_1; +continue; +} +} else { if (fname.clone().as_str() == transport_stdin_key().as_str()) { let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { +if has_err(r3.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); + transport: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) } - let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r3.tokens.clone(), - }; - { +let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r3.tokens.clone(), +}; +{ let __tco_0 = r3.ctx.clone(); - let __tco_1 = Some(r3.expr.clone()); - ctx = __tco_0; - stdin = __tco_1; - continue; - } - } else { +let __tco_1 = Some(r3.expr.clone()); +ctx = __tco_0; +stdin = __tco_1; +continue; +} +} else { let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { +if has_err(r3.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); + transport: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) } - let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r3.tokens.clone(), - }; - { +let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r3.tokens.clone(), +}; +{ let __tco_0 = r3.ctx.clone(); - ctx = __tco_0; - continue; - } - } - } - } - } +ctx = __tco_0; +continue; +} +} +} +} +} } -pub fn parse_file_binding_body( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_file_binding_body(tokens: Rc>>, ctx: Rc) -> Rc { parse_file_fields(tokens, ctx, None) } -pub fn parse_file_fields( - mut tokens: Rc>>, - mut ctx: Rc, - mut base_path: Option>, -) -> Rc { +pub fn parse_file_fields(mut tokens: Rc>>, mut ctx: Rc, mut base_path: Option>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let span = token_span(tokens.clone().first().cloned()); - let dummy = local_transport_node(span.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +let span = token_span(tokens.clone().first().cloned()); +let dummy = local_transport_node(span.clone()); +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { let bp = match base_path { - Some(e) => e.clone(), - None => make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: "".to_string(), - }), - }), - Rc::new(vec![]), - None, - make_span(0, 0), - ), - }; - break Rc::new(TransportResult { - transport: file_transport_node(bp, span.clone()), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + Some(e) => e.clone(), + None => make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: "".to_string(), +}), +}), Rc::new(vec![]), None, make_span(0, 0)), +}; +break Rc::new(TransportResult { + transport: file_transport_node(bp, span.clone()), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let r = expect_ident(&tokens); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + transport: dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let fname = r.name.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { +let fname = r.name.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); + transport: dummy.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { +let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); +if has_err(r3.err.clone()) { return Rc::new(TransportResult { - transport: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = match (*e.clone()).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r3.tokens.clone(), - }; - if ((fname.clone().as_str() == "path".to_string().as_str()) - || (fname.clone().as_str() == transport_path_key().as_str())) - { + transport: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = match (*e.clone()).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r3.tokens.clone(), +}; +if ((fname.clone().as_str() == "path".to_string().as_str()) || (fname.clone().as_str() == transport_path_key().as_str())) { { let __tco_0 = r3.ctx.clone(); - let __tco_1 = Some(r3.expr.clone()); - ctx = __tco_0; - base_path = __tco_1; - continue; - } - } else { +let __tco_1 = Some(r3.expr.clone()); +ctx = __tco_0; +base_path = __tco_1; +continue; +} +} else { { let __tco_0 = r3.ctx.clone(); - ctx = __tco_0; - continue; - } - } - } - } +ctx = __tco_0; +continue; +} +} +} +} } pub fn parse_operation_def(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy_op = make_operation_node( - "".to_string(), - None, - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - None, - &start_span, - &ctx.source_indices.clone(), - ); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "operation".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy_op = make_operation_node("".to_string(), None, Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), None, &start_span, &ctx.source_indices.clone()); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "operation".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = expect_ident(&r.tokens.clone()); - if has_err(r.err.clone()) { + operation: dummy_op.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = expect_ident(&r.tokens.clone()); +if has_err(r.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let tokens = skip_newlines(r.tokens.clone()); - if tok_is_lbrace(tokens.clone().first().cloned()) { + operation: dummy_op.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let tokens = skip_newlines(r.tokens.clone()); +if tok_is_lbrace(tokens.clone().first().cloned()) { parse_operation_v1_body(&tokens, &ctx, name, name_span, &start_span) } else { parse_operation_v2_inline(&tokens, &ctx, name, name_span, &start_span) } - } +} } -pub fn parse_operation_v2_inline( - tokens: &Rc>>, - ctx: &Rc, - name: String, - name_span: Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_operation_v2_inline(tokens: &Rc>>, ctx: &Rc, name: String, name_span: Rc, start_span: &Rc) -> Rc { { - let dummy_op = make_operation_node( - "".to_string(), - None, - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - None, - &start_span, - &ctx.source_indices.clone(), - ); - let mods_r = parse_operation_modifiers(tokens.clone(), ctx.clone()); - let modifiers = mods_r.modifiers.clone(); - let mod_props = modifiers_to_props(modifiers, start_span.clone()); - let tokens = mods_r.tokens.clone(); - let ctx = mods_r.ctx.clone(); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); - if has_err(r.err.clone()) { + let dummy_op = make_operation_node("".to_string(), None, Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), None, &start_span, &ctx.source_indices.clone()); +let mods_r = parse_operation_modifiers(tokens.clone(), ctx.clone()); +let modifiers = mods_r.modifiers.clone(); +let mod_props = modifiers_to_props(modifiers, start_span.clone()); +let tokens = mods_r.tokens.clone(); +let ctx = mods_r.ctx.clone(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); +if has_err(r.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r.err.clone()) { + operation: dummy_op.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let inputs = r.fields.clone(); - let r = expect( - &skip_newlines(r.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRParen), - ); - if has_err(r.err.clone()) { + operation: dummy_op.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let inputs = r.fields.clone(); +let r = expect(&skip_newlines(r.tokens.clone()), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = r.tokens.clone(); - let ret = parse_optional_inferred(&tokens, ctx.clone()); - if has_err(ret.err.clone()) { + operation: dummy_op.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = r.tokens.clone(); +let ret = parse_optional_inferred(&tokens, ctx.clone()); +if has_err(ret.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: ret.tokens.clone(), - ctx: ret.ctx.clone(), - err: ret.err.clone(), - }); - } - let tokens = ret.tokens.clone(); - let ctx = ret.ctx.clone(); - let outputs = match ret.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - node_inferred_to_outputs(&rt, ctx.source_indices.clone()) - } - _ => Rc::new(vec![]), - }; - let tokens = skip_newlines(tokens.clone()); - let resp_r = parse_optional_response_block(&tokens, &ctx); - if has_err(resp_r.err.clone()) { + operation: dummy_op.clone(), + tokens: ret.tokens.clone(), + ctx: ret.ctx.clone(), + err: ret.err.clone(), +}) + } +let tokens = ret.tokens.clone(); +let ctx = ret.ctx.clone(); +let outputs = match ret.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => node_inferred_to_outputs(&rt, ctx.source_indices.clone()), + _ => Rc::new(vec![]), +}; +let tokens = skip_newlines(tokens.clone()); +let resp_r = parse_optional_response_block(&tokens, &ctx); +if has_err(resp_r.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: resp_r.tokens.clone(), - ctx: resp_r.ctx.clone(), - err: resp_r.err.clone(), - }); - } - let tokens = skip_newlines(resp_r.tokens.clone()); - let ctx = resp_r.ctx.clone(); - let mock_r = parse_optional_mock_response_block(&tokens, &ctx); - if has_err(mock_r.err.clone()) { + operation: dummy_op.clone(), + tokens: resp_r.tokens.clone(), + ctx: resp_r.ctx.clone(), + err: resp_r.err.clone(), +}) + } +let tokens = skip_newlines(resp_r.tokens.clone()); +let ctx = resp_r.ctx.clone(); +let mock_r = parse_optional_mock_response_block(&tokens, &ctx); +if has_err(mock_r.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: mock_r.tokens.clone(), - ctx: mock_r.ctx.clone(), - err: mock_r.err.clone(), - }); - } - let tokens = skip_newlines(mock_r.tokens.clone()); - let ctx = mock_r.ctx.clone(); - let op = make_operation_node( - name, - Some(name_span), - inputs, - outputs, - resp_r.responses.clone(), - mock_r.mocks.clone(), - Rc::new(vec![]), - mod_props, - None, - &start_span, - &ctx.source_indices.clone(), - ); - Rc::new(OpResult { - operation: op, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } + operation: dummy_op.clone(), + tokens: mock_r.tokens.clone(), + ctx: mock_r.ctx.clone(), + err: mock_r.err.clone(), +}) + } +let tokens = skip_newlines(mock_r.tokens.clone()); +let ctx = mock_r.ctx.clone(); +let op = make_operation_node(name, Some(name_span), inputs, outputs, resp_r.responses.clone(), mock_r.mocks.clone(), Rc::new(vec![]), mod_props, None, &start_span, &ctx.source_indices.clone()); +Rc::new(OpResult { + operation: op, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +} } -pub fn parse_operation_v1_body( - tokens: &Rc>>, - ctx: &Rc, - name: String, - name_span: Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_operation_v1_body(tokens: &Rc>>, ctx: &Rc, name: String, name_span: Rc, start_span: &Rc) -> Rc { { - let dummy_op = make_operation_node( - "".to_string(), - None, - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - None, - &start_span, - &ctx.source_indices.clone(), - ); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBrace)); - if has_err(r.err.clone()) { + let dummy_op = make_operation_node("".to_string(), None, Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), None, &start_span, &ctx.source_indices.clone()); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = parse_op_body_entries( - tokens.clone(), - ctx.clone(), - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - None, - Rc::new(vec![]), - Rc::new(vec![]), - Rc::new(vec![]), - ); - if has_err(r2.err.clone()) { + operation: dummy_op.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r2 = parse_op_body_entries(tokens.clone(), ctx.clone(), Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![]), None, Rc::new(vec![]), Rc::new(vec![]), Rc::new(vec![])); +if has_err(r2.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { + operation: dummy_op.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { return Rc::new(OpResult { - operation: dummy_op.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - let op = make_operation_node( - name, - Some(name_span), - r2.inputs.clone(), - r2.outputs.clone(), - r2.response_props.clone(), - r2.mock_props.clone(), - r2.exit_props.clone(), - r2.modifier_props.clone(), - r2.transport.clone(), - &start_span, - &ctx.source_indices.clone(), - ); - Rc::new(OpResult { - operation: op, - tokens: skip_newlines(r3.tokens.clone()), - ctx: r2.ctx.clone(), - err: None, - }) - } + operation: dummy_op.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +let op = make_operation_node(name, Some(name_span), r2.inputs.clone(), r2.outputs.clone(), r2.response_props.clone(), r2.mock_props.clone(), r2.exit_props.clone(), r2.modifier_props.clone(), r2.transport.clone(), &start_span, &ctx.source_indices.clone()); +Rc::new(OpResult { + operation: op, + tokens: skip_newlines(r3.tokens.clone()), + ctx: r2.ctx.clone(), + err: None, +}) +} } -pub fn parse_op_body_entries( - mut tokens: Rc>>, - mut ctx: Rc, - mut inputs: Rc>>, - mut outputs: Rc>>, - mut modifier_props: Rc>>, - mut transport: Option>, - mut exit_props: Rc>>, - mut response_props: Rc>>, - mut mock_props: Rc>>, -) -> Rc { +pub fn parse_op_body_entries(mut tokens: Rc>>, mut ctx: Rc, mut inputs: Rc>>, mut outputs: Rc>>, mut modifier_props: Rc>>, mut transport: Option>, mut exit_props: Rc>>, mut response_props: Rc>>, mut mock_props: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - let span = token_span(tok.clone()); - let mk_result = Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - if (tok_is_rbrace(tok.clone()) || tok_is_eof(tok.clone())) { +let tok = tokens.clone().first().cloned(); +let span = token_span(tok.clone()); +let mk_result = Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +if (tok_is_rbrace(tok.clone()) || tok_is_eof(tok.clone())) { break mk_result; - } else { +} else { let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShKeyword) => { - let kw_text = tok.clone().unwrap().text.clone(); - if (kw_text.clone().as_str() == "input".to_string().as_str()) { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r2.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - { - let __tco_0 = r3.tokens.clone(); - let __tco_1 = r2.ctx.clone(); - let __tco_2 = r2.fields.clone(); - tokens = __tco_0; - ctx = __tco_1; - inputs = __tco_2; - continue; - } - } else { - if (kw_text.clone().as_str() == "output".to_string().as_str()) { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r2.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - { - let __tco_0 = r3.tokens.clone(); - let __tco_1 = r2.ctx.clone(); - let __tco_2 = r2.fields.clone(); - tokens = __tco_0; - ctx = __tco_1; - outputs = __tco_2; - continue; - } - } else { - if (kw_text.clone().as_str() == "idempotent".to_string().as_str()) { - let prop = modifier_to_prop("idempotent".to_string(), &span); - { - let __tco_0 = Rc::new( - tokens.iter().cloned().skip(1 as usize).collect::>(), - ); - let __tco_1 = v2_rt::rc_list_push(modifier_props, prop); - tokens = __tco_0; - modifier_props = __tco_1; - continue; - } - } else { - if (kw_text.clone().as_str() == "readonly".to_string().as_str()) { - let prop = modifier_to_prop("readonly".to_string(), &span); - { - let __tco_0 = Rc::new( - tokens - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = v2_rt::rc_list_push(modifier_props, prop); - tokens = __tco_0; - modifier_props = __tco_1; - continue; - } - } else { - if (kw_text.clone().as_str() == "hermetic".to_string().as_str()) - { - let prop = modifier_to_prop("hermetic".to_string(), &span); - { - let __tco_0 = Rc::new( - tokens - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = v2_rt::rc_list_push(modifier_props, prop); - tokens = __tco_0; - modifier_props = __tco_1; - continue; - } - } else { - break mk_result; - } - } - } - } + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShKeyword) => { let kw_text = tok.clone().unwrap().text.clone(); +if (kw_text.clone().as_str() == "input".to_string().as_str()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +{ + let __tco_0 = r3.tokens.clone(); +let __tco_1 = r2.ctx.clone(); +let __tco_2 = r2.fields.clone(); +tokens = __tco_0; +ctx = __tco_1; +inputs = __tco_2; +continue; +} +} else { + if (kw_text.clone().as_str() == "output".to_string().as_str()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - } - Some(TokenShape::ShIdent) => { - let id = tok.clone().unwrap().text.clone(); - if (id.clone().as_str() == "transport".to_string().as_str()) { - let r = parse_transport_binding( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &ctx, - ); - if has_err(r.err.clone()) { +let r2 = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +{ + let __tco_0 = r3.tokens.clone(); +let __tco_1 = r2.ctx.clone(); +let __tco_2 = r2.fields.clone(); +tokens = __tco_0; +ctx = __tco_1; +outputs = __tco_2; +continue; +} +} else { + if (kw_text.clone().as_str() == "idempotent".to_string().as_str()) { + let prop = modifier_to_prop("idempotent".to_string(), &span); +{ + let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(modifier_props, prop); +tokens = __tco_0; +modifier_props = __tco_1; +continue; +} +} else { + if (kw_text.clone().as_str() == "readonly".to_string().as_str()) { + let prop = modifier_to_prop("readonly".to_string(), &span); +{ + let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(modifier_props, prop); +tokens = __tco_0; +modifier_props = __tco_1; +continue; +} +} else { + if (kw_text.clone().as_str() == "hermetic".to_string().as_str()) { + let prop = modifier_to_prop("hermetic".to_string(), &span); +{ + let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(modifier_props, prop); +tokens = __tco_0; +modifier_props = __tco_1; +continue; +} +} else { + break mk_result; +} +} +} +} +} }, + Some(TokenShape::ShIdent) => { let id = tok.clone().unwrap().text.clone(); +if (id.clone().as_str() == "transport".to_string().as_str()) { + let r = parse_transport_binding(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &ctx); +if has_err(r.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = Some(r.transport.clone()); +tokens = __tco_0; +ctx = __tco_1; +transport = __tco_2; +continue; +} +} else { + if (id.clone().as_str() == "exit".to_string().as_str()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = parse_exit_entries(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +{ + let __tco_0 = r3.tokens.clone(); +let __tco_1 = r2.ctx.clone(); +let __tco_2 = r2.entries.clone(); +tokens = __tco_0; +ctx = __tco_1; +exit_props = __tco_2; +continue; +} +} else { + if (id.clone().as_str() == "response".to_string().as_str()) { + let r = parse_optional_response_block(&tokens, &ctx); +if has_err(r.err.clone()) { return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - { +{ let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = Some(r.transport.clone()); - tokens = __tco_0; - ctx = __tco_1; - transport = __tco_2; - continue; - } - } else { - if (id.clone().as_str() == "exit".to_string().as_str()) { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = - parse_exit_entries(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r2.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { +let __tco_1 = r.ctx.clone(); +let __tco_2 = r.responses.clone(); +tokens = __tco_0; +ctx = __tco_1; +response_props = __tco_2; +continue; +} +} else { + if (id.clone().as_str() == "mock_response".to_string().as_str()) { + let r = parse_optional_mock_response_block(&tokens, &ctx); +if has_err(r.err.clone()) { return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - { - let __tco_0 = r3.tokens.clone(); - let __tco_1 = r2.ctx.clone(); - let __tco_2 = r2.entries.clone(); - tokens = __tco_0; - ctx = __tco_1; - exit_props = __tco_2; - continue; + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - } else { - if (id.clone().as_str() == "response".to_string().as_str()) { - let r = parse_optional_response_block(&tokens, &ctx); - if has_err(r.err.clone()) { +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = r.mocks.clone(); +tokens = __tco_0; +ctx = __tco_1; +mock_props = __tco_2; +continue; +} +} else { + if peek_is_colon_after_ident(tokens.clone()) { + let r = expect_ident(&tokens); +if has_err(r.err.clone()) { return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = r.responses.clone(); - tokens = __tco_0; - ctx = __tco_1; - response_props = __tco_2; - continue; +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - } else { - if (id.clone().as_str() == "mock_response".to_string().as_str()) { - let r = parse_optional_mock_response_block(&tokens, &ctx); - if has_err(r.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = r.mocks.clone(); - tokens = __tco_0; - ctx = __tco_1; - mock_props = __tco_2; - continue; - } - } else { - if peek_is_colon_after_ident(tokens.clone()) { - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = expect( - &r.tokens.clone(), - &Rc::new(ExpectedToken::ExpectColon), - ); - if has_err(r2.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { - return Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - { - let __tco_0 = skip_newlines(r3.tokens.clone()); - let __tco_1 = r3.ctx.clone(); - tokens = __tco_0; - ctx = __tco_1; - continue; - } - } else { - break Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - format!( - "unexpected '{}' in operation body", - id.clone() - ), - span, - )), - }); - } +let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); +if has_err(r3.err.clone()) { + return Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) } - } - } - } - } - _ => { - break Rc::new(OpBodyResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - modifier_props: modifier_props.clone(), - transport: transport.clone(), - exit_props: exit_props.clone(), - response_props: response_props.clone(), - mock_props: mock_props.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "unexpected token in operation body".to_string(), - span, - )), - }); - } - } - } - } +{ + let __tco_0 = skip_newlines(r3.tokens.clone()); +let __tco_1 = r3.ctx.clone(); +tokens = __tco_0; +ctx = __tco_1; +continue; +} +} else { + break Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error(format!("unexpected '{}' in operation body", id.clone()), span)), +}); +} +} +} +} +} }, + _ => { break Rc::new(OpBodyResult { + inputs: inputs.clone(), + outputs: outputs.clone(), + modifier_props: modifier_props.clone(), + transport: transport.clone(), + exit_props: exit_props.clone(), + response_props: response_props.clone(), + mock_props: mock_props.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("unexpected token in operation body".to_string(), span)), +}); }, +} +} +} } pub fn modifier_to_prop(name: String, span: &Rc) -> Rc { - make_field_init_node( - &name, - make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitBool { value: true }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - span.clone(), - span.clone(), - ) -} - -pub fn modifiers_to_props( - modifiers: Rc>, - span: Rc, -) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for m in modifiers.iter().cloned() { - __result.push(match m.clone() { - OperationModifier::Idempotent => modifier_to_prop("idempotent".to_string(), &span), - OperationModifier::Readonly => modifier_to_prop("readonly".to_string(), &span), - OperationModifier::Hermetic => modifier_to_prop("hermetic".to_string(), &span), - }); - } - __result - }) + make_field_init_node(&name, make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitBool { + value: true, +}), +}), Rc::new(vec![]), None, span.clone()), span.clone(), span.clone()) } -pub fn status_expr_to_str( - expr: &Rc, - source_indices: Rc>>, -) -> String { +pub fn modifiers_to_props(modifiers: Rc>, span: Rc) -> Rc>> { + Rc::new({ let mut __result = Vec::new(); for m in modifiers.iter().cloned() { __result.push(match m.clone() { + OperationModifier::Idempotent => modifier_to_prop("idempotent".to_string(), &span), + OperationModifier::Readonly => modifier_to_prop("readonly".to_string(), &span), + OperationModifier::Hermetic => modifier_to_prop("hermetic".to_string(), &span), +}); } __result }) +} + +pub fn status_expr_to_str(expr: &Rc, source_indices: Rc>>) -> String { match (*expr.expr_data.clone()).clone() { - ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { - LiteralValue::LitInt { value: n, .. } => int_to_string(n.clone()), - LiteralValue::LitStr { value: s, .. } => s.clone(), - _ => "_".to_string(), - }, - ExprData::ExprVar { .. } => expr_var_name_at(expr.clone(), source_indices), - _ => "_".to_string(), - } + ExprData::ExprLiteral { value: v, .. } => match (*v.clone()).clone() { + LiteralValue::LitInt { value: n, .. } => int_to_string(n.clone()), + LiteralValue::LitStr { value: s, .. } => s.clone(), + _ => "_".to_string(), +}, + ExprData::ExprVar { .. } => expr_var_name_at(expr.clone(), source_indices), + _ => "_".to_string(), +} } pub fn int_to_string(value: i64) -> String { @@ -7828,8 +6498,8 @@ pub fn int_to_string(value: i64) -> String { } else { { let digits = int_to_string_acc(value.clone(), Rc::new(vec![])); - digits.join(&"".to_string()) - } +digits.join(&"".to_string()) +} } } @@ -7837,2828 +6507,2195 @@ pub fn int_to_string_acc(mut value: i64, mut acc: Rc>) -> Rc>(), - ) - .iter() - .cloned() - { - if (p.0.clone() == digit.clone()) { - __result.push(p); - } - } - __result - }) - .first() - .cloned() - { - Some(p) => p.1.clone(), - None => "?".to_string(), - }; - { +let digit = (value.clone() - (rest.clone() * 10)); +let digit_chars = Rc::new(vec!["0".to_string(), "1".to_string(), "2".to_string(), "3".to_string(), "4".to_string(), "5".to_string(), "6".to_string(), "7".to_string(), "8".to_string(), "9".to_string()]); +let ch = match Rc::new({ let mut __result = Vec::new(); for p in Rc::new(digit_chars.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (p.0.clone() == digit.clone()) { __result.push(p); } } __result }).first().cloned() { + Some(p) => p.1.clone(), + None => "?".to_string(), +}; +{ let __tco_0 = rest.clone(); - let __tco_1 = v2_rt::concat(Rc::new(vec![ch]), acc); - value = __tco_0; - acc = __tco_1; - continue; - } - } - } +let __tco_1 = v2_rt::concat(Rc::new(vec![ch]), acc); +value = __tco_0; +acc = __tco_1; +continue; +} +} +} } pub fn first_child_or_self(n: Rc) -> Rc { match n.children.clone().first().cloned() { - Some(ch) => ch.clone(), - None => n.clone(), - } + Some(ch) => ch.clone(), + None => n.clone(), +} } pub fn last_child_or_self(n: Rc) -> Rc { match n.children.clone().last().cloned() { - Some(ch) => ch.clone(), - None => n.clone(), - } + Some(ch) => ch.clone(), + None => n.clone(), +} } -pub fn node_to_name_str( - n: &Rc, - source_indices: &Rc>>, -) -> String { +pub fn node_to_name_str(n: &Rc, source_indices: &Rc>>) -> String { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); - let effective_n = if is_optional.clone() { - with_required_cardinality(&n) - } else { - n.clone() - }; - let opt_prefix = if is_optional.clone() { - "Optional_".to_string() - } else { - "".to_string() - }; - let effective_name = authored_name_at(source_indices.clone(), &effective_n); - let is_keyed_container = (is_container_type(effective_name.clone()) - && ((effective_n.children.clone().len() as i64) == 2)); - if is_keyed_container { - match effective_n.children.clone().last().cloned() { - Some(ch) => v2_rt::concat( - v2_rt::concat( - v2_rt::concat(opt_prefix, effective_name.clone()), - "_".to_string(), - ), - node_to_name_str(&ch, &source_indices), - ), - None => v2_rt::concat(opt_prefix, effective_name.clone()), - } - } else { - if (effective_n.type_annotation.clone() != None) { - match effective_n.children.clone().first().cloned() { - Some(ch) => v2_rt::concat(opt_prefix, node_to_name_str(&ch, &source_indices)), - None => v2_rt::concat(opt_prefix, effective_name.clone()), - } + { + let is_optional = (n.return_cardinality.clone() == Cardinality::CardOptional); +let effective_n = if is_optional.clone() { + with_required_cardinality(&n) + } else { + n.clone() + }; +let opt_prefix = if is_optional.clone() { + "Optional_".to_string() + } else { + "".to_string() + }; +let effective_name = authored_name_at(source_indices.clone(), &effective_n); +let is_keyed_container = (is_container_type(effective_name.clone()) && ((effective_n.children.clone().len() as i64) == 2)); +if is_keyed_container { + match effective_n.children.clone().last().cloned() { + Some(ch) => v2_rt::concat(v2_rt::concat(v2_rt::concat(opt_prefix, effective_name.clone()), "_".to_string()), node_to_name_str(&ch, &source_indices)), + None => v2_rt::concat(opt_prefix, effective_name.clone()), +} } else { - if is_container_type(effective_name.clone()) { + if (effective_n.type_annotation.clone() != None) { match effective_n.children.clone().first().cloned() { - Some(ch) => v2_rt::concat( - v2_rt::concat(opt_prefix, "List_".to_string()), - node_to_name_str(&ch, &source_indices), - ), - None => v2_rt::concat(opt_prefix, effective_name.clone()), - } + Some(ch) => v2_rt::concat(opt_prefix, node_to_name_str(&ch, &source_indices)), + None => v2_rt::concat(opt_prefix, effective_name.clone()), +} } else { - if (effective_n.ident_span.clone() == None) { - { - let is_conj = (effective_n.connective.clone() == Connective::Conj); - let is_disj = (effective_n.connective.clone() == Connective::Disj); - if is_conj { - v2_rt::concat(opt_prefix, "Record".to_string()) - } else { - if is_disj { - v2_rt::concat(opt_prefix, "Union".to_string()) + if is_container_type(effective_name.clone()) { + match effective_n.children.clone().first().cloned() { + Some(ch) => v2_rt::concat(v2_rt::concat(opt_prefix, "List_".to_string()), node_to_name_str(&ch, &source_indices)), + None => v2_rt::concat(opt_prefix, effective_name.clone()), +} + } else { + if (effective_n.ident_span.clone() == None) { + { + let is_conj = (effective_n.connective.clone() == Connective::Conj); +let is_disj = (effective_n.connective.clone() == Connective::Disj); +if is_conj { + v2_rt::concat(opt_prefix, "Record".to_string()) } else { - v2_rt::concat(opt_prefix, effective_name.clone()) + if is_disj { + v2_rt::concat(opt_prefix, "Union".to_string()) + } else { + v2_rt::concat(opt_prefix, effective_name.clone()) + } } - } +} + } else { + v2_rt::concat(opt_prefix, effective_name.clone()) } - } else { - v2_rt::concat(opt_prefix, effective_name.clone()) } } } - } +} }) } -pub fn parse_exit_entries( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_exit_entries(tokens: Rc>>, ctx: Rc) -> Rc { parse_exit_entries_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_exit_entries_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_exit_entries_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(ExitEntriesResult { - entries: acc, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + entries: acc, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let r = parse_status_pattern(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExitEntriesResult { - entries: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let code = r.expr.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectFatArrow)); - if has_err(r2.err.clone()) { + entries: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let code = r.expr.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectFatArrow)); +if has_err(r2.err.clone()) { return Rc::new(ExitEntriesResult { - entries: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_type_expr(&r2.tokens.clone(), &r.ctx.clone()); - if has_err(r3.err.clone()) { + entries: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_type_expr(&r2.tokens.clone(), &r.ctx.clone()); +if has_err(r3.err.clone()) { return Rc::new(ExitEntriesResult { - entries: Rc::new(vec![]), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - let desc_tok = r3.tokens.clone().first().cloned(); - let desc_sh = match desc_tok { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let desc_tokens = match desc_sh { - Some(TokenShape::ShLitStr) => Rc::new( - r3.tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - _ => r3.tokens.clone(), - }; - let code_str = status_expr_to_str(&code, ctx.source_indices.clone()); - let type_name = node_to_name_str(&r3.type_expr.clone(), &ctx.source_indices.clone()); - let prop_name = v2_rt::concat("exit_".to_string(), code_str); - let entry = make_field_init_node( - &prop_name, - make_named_expr_node( - &type_name, - Rc::new(ExprData::ExprVar { binding_kind: None }), - Rc::new(vec![]), - None, - r3.type_expr.clone().span.clone(), - r3.type_expr.clone().span.clone(), - ), - r3.type_expr.clone().span.clone(), - no_span(), - ); - let e = eat(&desc_tokens, Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => desc_tokens.clone(), - }); - { + entries: Rc::new(vec![]), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let desc_tok = r3.tokens.clone().first().cloned(); +let desc_sh = match desc_tok { + Some(t) => Some(t.shape.clone()), + None => None, +}; +let desc_tokens = match desc_sh { + Some(TokenShape::ShLitStr) => Rc::new(r3.tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + _ => r3.tokens.clone(), +}; +let code_str = status_expr_to_str(&code, ctx.source_indices.clone()); +let type_name = node_to_name_str(&r3.type_expr.clone(), &ctx.source_indices.clone()); +let prop_name = v2_rt::concat("exit_".to_string(), code_str); +let entry = make_field_init_node(&prop_name, make_named_expr_node(&type_name, Rc::new(ExprData::ExprVar { + binding_kind: None, +}), Rc::new(vec![]), None, r3.type_expr.clone().span.clone(), r3.type_expr.clone().span.clone()), r3.type_expr.clone().span.clone(), no_span()); +let e = eat(&desc_tokens, Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => desc_tokens.clone(), +}); +{ let __tco_0 = r3.ctx.clone(); - let __tco_1 = v2_rt::rc_list_push(acc, entry); - ctx = __tco_0; - acc = __tco_1; - continue; - } - } - } +let __tco_1 = v2_rt::rc_list_push(acc, entry); +ctx = __tco_0; +acc = __tco_1; +continue; +} +} +} } -pub fn parse_operation_modifiers( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_operation_modifiers(tokens: Rc>>, ctx: Rc) -> Rc { parse_operation_modifiers_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_operation_modifiers_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>, -) -> Rc { +pub fn parse_operation_modifiers_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>) -> Rc { loop { let kw = tok_keyword_text(tokens.clone().first().cloned()); - if (kw.clone().as_str() == "idempotent".to_string().as_str()) { +if (kw.clone().as_str() == "idempotent".to_string().as_str()) { { let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); - let __tco_1 = v2_rt::rc_list_push(acc, OperationModifier::Idempotent); - tokens = __tco_0; - acc = __tco_1; - continue; - } - } else { +let __tco_1 = v2_rt::rc_list_push(acc, OperationModifier::Idempotent); +tokens = __tco_0; +acc = __tco_1; +continue; +} +} else { if (kw.clone().as_str() == "readonly".to_string().as_str()) { { - let __tco_0 = - Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); - let __tco_1 = v2_rt::rc_list_push(acc, OperationModifier::Readonly); - tokens = __tco_0; - acc = __tco_1; - continue; - } - } else { + let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(acc, OperationModifier::Readonly); +tokens = __tco_0; +acc = __tco_1; +continue; +} +} else { if (kw.clone().as_str() == "hermetic".to_string().as_str()) { { - let __tco_0 = - Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); - let __tco_1 = v2_rt::rc_list_push(acc, OperationModifier::Hermetic); - tokens = __tco_0; - acc = __tco_1; - continue; - } - } else { + let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(acc, OperationModifier::Hermetic); +tokens = __tco_0; +acc = __tco_1; +continue; +} +} else { break Rc::new(ModsResult { - modifiers: acc, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } - } - } - } + modifiers: acc, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} +} +} +} } pub fn parse_status_pattern(tokens: &Rc>>, ctx: &Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let span = token_span(tok.clone()); - match sh { - Some(TokenShape::ShLitInt) => { - let n_opt = v2_rt::parse_int(tok.clone().unwrap().text.clone()); - let n = match n_opt { - Some(v) => v.clone(), - None => { - return Rc::new(ExprResult { - expr: make_expr_error_node( - ExprErrorKind::InternalExprError, - &v2_rt::concat( - v2_rt::concat( - "internal: ShLitInt token text not parseable as int: '" - .to_string(), - tok.clone().unwrap().text.clone(), - ), - "'".to_string(), - ), - &span, - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - }; - let next_tok = tokens.clone().get(1 as usize).cloned(); - match next_tok { - Some(t) => { - if (is_ident_shape(t.shape.clone()) - && (t.text.clone().as_str() == "xx".to_string().as_str())) - { - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: format!("{}xx", n), - }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(2 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } else { - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitInt { value: n }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } - } - None => Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitInt { value: n }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }), - } - } - Some(TokenShape::ShIdent) => { - let id = tok.clone().unwrap().text.clone(); +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +let span = token_span(tok.clone()); +match sh { + Some(TokenShape::ShLitInt) => { + let n_opt = v2_rt::parse_int(tok.clone().unwrap().text.clone()); +let n = match n_opt { + Some(v) => v.clone(), + None => return Rc::new(ExprResult { + expr: make_expr_error_node(ExprErrorKind::InternalExprError, &v2_rt::concat(v2_rt::concat("internal: ShLitInt token text not parseable as int: '".to_string(), tok.clone().unwrap().text.clone()), "'".to_string()), &span), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +}; +let next_tok = tokens.clone().get(1 as usize).cloned(); +match next_tok { + Some(t) => if (is_ident_shape(t.shape.clone()) && (t.text.clone().as_str() == "xx".to_string().as_str())) { Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { value: id }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } - _ => Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { - value: "_".to_string(), - }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }), - } - } + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: format!("{}xx", n), +}), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(2 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) + } else { + Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitInt { + value: n, +}), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) + }, + None => Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitInt { + value: n, +}), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}), +} +}, + Some(TokenShape::ShIdent) => { + let id = tok.clone().unwrap().text.clone(); +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: id, +}), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) +}, + _ => Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: "_".to_string(), +}), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}), +} +} } -pub fn parse_optional_response_block( - tokens: &Rc>>, - ctx: &Rc, -) -> Rc { +pub fn parse_optional_response_block(tokens: &Rc>>, ctx: &Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let is_response = match tok { - Some(t) => { - (is_ident_shape(t.shape.clone()) - && (t.text.clone().as_str() == "response".to_string().as_str())) - } - None => false, - }; - if is_response { +let is_response = match tok { + Some(t) => (is_ident_shape(t.shape.clone()) && (t.text.clone().as_str() == "response".to_string().as_str())), + None => false, +}; +if is_response { { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(ResponsesResult { - responses: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + responses: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let r2 = parse_response_entries(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r2.err.clone()) { +let r2 = parse_response_entries(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { return Rc::new(ResponsesResult { - responses: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { + responses: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { return Rc::new(ResponsesResult { - responses: Rc::new(vec![]), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(ResponsesResult { - responses: r2.entries.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } + responses: Rc::new(vec![]), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +Rc::new(ResponsesResult { + responses: r2.entries.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +} } else { Rc::new(ResponsesResult { - responses: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + responses: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } - } +} } -pub fn parse_response_entries( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_response_entries(tokens: Rc>>, ctx: Rc) -> Rc { parse_response_entries_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_response_entries_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_response_entries_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(RespEntriesResult { - entries: acc, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + entries: acc, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let r = parse_status_pattern(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(RespEntriesResult { - entries: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let status = r.expr.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectFatArrow)); - if has_err(r2.err.clone()) { + entries: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let status = r.expr.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectFatArrow)); +if has_err(r2.err.clone()) { return Rc::new(RespEntriesResult { - entries: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_type_expr(&r2.tokens.clone(), &r.ctx.clone()); - if has_err(r3.err.clone()) { + entries: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_type_expr(&r2.tokens.clone(), &r.ctx.clone()); +if has_err(r3.err.clone()) { return Rc::new(RespEntriesResult { - entries: Rc::new(vec![]), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - let status_str = status_expr_to_str(&status, ctx.source_indices.clone()); - let type_name = node_to_name_str(&r3.type_expr.clone(), &ctx.source_indices.clone()); - let prop_name = v2_rt::concat("response_".to_string(), status_str); - let entry = make_field_init_node( - &prop_name, - make_named_expr_node( - &type_name, - Rc::new(ExprData::ExprVar { binding_kind: None }), - Rc::new(vec![]), - None, - r3.type_expr.clone().span.clone(), - r3.type_expr.clone().span.clone(), - ), - r3.type_expr.clone().span.clone(), - no_span(), - ); - let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r3.tokens.clone(), - }); - { + entries: Rc::new(vec![]), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let status_str = status_expr_to_str(&status, ctx.source_indices.clone()); +let type_name = node_to_name_str(&r3.type_expr.clone(), &ctx.source_indices.clone()); +let prop_name = v2_rt::concat("response_".to_string(), status_str); +let entry = make_field_init_node(&prop_name, make_named_expr_node(&type_name, Rc::new(ExprData::ExprVar { + binding_kind: None, +}), Rc::new(vec![]), None, r3.type_expr.clone().span.clone(), r3.type_expr.clone().span.clone()), r3.type_expr.clone().span.clone(), no_span()); +let e = eat(&r3.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r3.tokens.clone(), +}); +{ let __tco_0 = r3.ctx.clone(); - let __tco_1 = v2_rt::rc_list_push(acc, entry); - ctx = __tco_0; - acc = __tco_1; - continue; - } - } - } +let __tco_1 = v2_rt::rc_list_push(acc, entry); +ctx = __tco_0; +acc = __tco_1; +continue; +} +} +} } -pub fn parse_optional_mock_response_block( - tokens: &Rc>>, - ctx: &Rc, -) -> Rc { +pub fn parse_optional_mock_response_block(tokens: &Rc>>, ctx: &Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let is_mock = match tok { - Some(t) => { - (is_ident_shape(t.shape.clone()) - && (t.text.clone().as_str() == "mock_response".to_string().as_str())) - } - None => false, - }; - if is_mock { +let is_mock = match tok { + Some(t) => (is_ident_shape(t.shape.clone()) && (t.text.clone().as_str() == "mock_response".to_string().as_str())), + None => false, +}; +if is_mock { { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(MocksResult { - mocks: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + mocks: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let r2 = parse_mock_response_entries(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r2.err.clone()) { +let r2 = parse_mock_response_entries(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { return Rc::new(MocksResult { - mocks: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { + mocks: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { return Rc::new(MocksResult { - mocks: Rc::new(vec![]), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - Rc::new(MocksResult { - mocks: r2.entries.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } + mocks: Rc::new(vec![]), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +Rc::new(MocksResult { + mocks: r2.entries.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +} } else { Rc::new(MocksResult { - mocks: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + mocks: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } - } +} } -pub fn parse_mock_response_entries( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_mock_response_entries(tokens: Rc>>, ctx: Rc) -> Rc { parse_mock_response_entries_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_mock_response_entries_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_mock_response_entries_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(MockEntriesResult { - entries: acc, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + entries: acc, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let r = parse_status_pattern(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(MockEntriesResult { - entries: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let status = r.expr.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectFatArrow)); - if has_err(r2.err.clone()) { + entries: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let status = r.expr.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectFatArrow)); +if has_err(r2.err.clone()) { return Rc::new(MockEntriesResult { - entries: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_expr(r2.tokens.clone(), r.ctx.clone()); - if has_err(r3.err.clone()) { + entries: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_expr(r2.tokens.clone(), r.ctx.clone()); +if has_err(r3.err.clone()) { return Rc::new(MockEntriesResult { - entries: Rc::new(vec![]), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - let body = r3.expr.clone(); - let desc_tok = r3.tokens.clone().first().cloned(); - let desc_sh = match desc_tok { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let desc_tokens = match desc_sh { - Some(TokenShape::ShLitStr) => Rc::new( - r3.tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - _ => r3.tokens.clone(), - }; - let status_str = status_expr_to_str(&status, ctx.source_indices.clone()); - let prop_name = v2_rt::concat("mock_".to_string(), status_str); - let entry = make_field_init_node(&prop_name, body, make_span(0, 0), make_span(0, 0)); - let e = eat(&desc_tokens, Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => desc_tokens.clone(), - }); - { + entries: Rc::new(vec![]), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let body = r3.expr.clone(); +let desc_tok = r3.tokens.clone().first().cloned(); +let desc_sh = match desc_tok { + Some(t) => Some(t.shape.clone()), + None => None, +}; +let desc_tokens = match desc_sh { + Some(TokenShape::ShLitStr) => Rc::new(r3.tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + _ => r3.tokens.clone(), +}; +let status_str = status_expr_to_str(&status, ctx.source_indices.clone()); +let prop_name = v2_rt::concat("mock_".to_string(), status_str); +let entry = make_field_init_node(&prop_name, body, make_span(0, 0), make_span(0, 0)); +let e = eat(&desc_tokens, Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => desc_tokens.clone(), +}); +{ let __tco_0 = r3.ctx.clone(); - let __tco_1 = v2_rt::rc_list_push(acc, entry); - ctx = __tco_0; - acc = __tco_1; - continue; - } - } - } +let __tco_1 = v2_rt::rc_list_push(acc, entry); +ctx = __tco_0; +acc = __tco_1; +continue; +} +} +} } pub fn parse_resource_def(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "resource".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "resource".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - parse_resource_after_kw(r.tokens.clone(), &ctx, &start_span) - } +parse_resource_after_kw(r.tokens.clone(), &ctx, &start_span) +} } -pub fn parse_resource_after_kw( - tokens: Rc>>, - ctx: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_resource_after_kw(tokens: Rc>>, ctx: &Rc, start_span: &Rc) -> Rc { { let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect_ident(&tokens); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectLBrace)); - if has_err(r.err.clone()) { + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_resource_entries( - skip_newlines(r.tokens.clone()), - ctx.clone(), - Rc::new(vec![]), - Rc::new(vec![]), - ); - if has_err(r.err.clone()) { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_resource_entries(skip_newlines(r.tokens.clone()), ctx.clone(), Rc::new(vec![]), Rc::new(vec![])); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = expect( - &skip_newlines(r.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r2.err.clone()) { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = expect(&skip_newlines(r.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: r.capabilities.clone(), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: r.properties.clone(), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r2.tokens.clone()), - ctx: r.ctx.clone(), - err: None, - }) - } + item: named_dummy.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: r.capabilities.clone(), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: r.properties.clone(), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r2.tokens.clone()), + ctx: r.ctx.clone(), + err: None, +}) +} } -pub fn parse_resource_entries( - mut tokens: Rc>>, - mut ctx: Rc, - mut properties: Rc>>, - mut capabilities: Rc>>, -) -> Rc { +pub fn parse_resource_entries(mut tokens: Rc>>, mut ctx: Rc, mut properties: Rc>>, mut capabilities: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - let span = token_span(tok.clone()); - if (tok_is_rbrace(tok.clone()) || tok_is_eof(tok.clone())) { +let tok = tokens.clone().first().cloned(); +let span = token_span(tok.clone()); +if (tok_is_rbrace(tok.clone()) || tok_is_eof(tok.clone())) { break Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShKeyword) => { - let kw_text = tok_keyword_text(tok.clone()); - if (kw_text.clone().as_str() == "capability".to_string().as_str()) { - let r = parse_capability(&tokens, &ctx); - if has_err(r.err.clone()) { - return Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(capabilities, r.capability.clone()); - tokens = __tco_0; - ctx = __tco_1; - capabilities = __tco_2; - continue; - } - } else { - if (kw_text.clone().as_str() == "acquire".to_string().as_str()) { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { - return Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = skip_until_rbrace(&skip_newlines(r.tokens.clone())); - let r3 = - expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r3.err.clone()) { - return Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); - } - { - let __tco_0 = skip_newlines(r3.tokens.clone()); - tokens = __tco_0; - continue; - } - } else { - if (kw_text.clone().as_str() == "release".to_string().as_str()) { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { - return Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = skip_until_rbrace(&skip_newlines(r.tokens.clone())); - let r3 = expect( - &r2.tokens.clone(), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { - return Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: r3.tokens.clone(), - ctx: ctx.clone(), - err: r3.err.clone(), - }); - } - { - let __tco_0 = skip_newlines(r3.tokens.clone()); - tokens = __tco_0; - continue; - } - } else { - break Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "unexpected keyword in resource block".to_string(), - span, - )), - }); - } - } + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShKeyword) => { let kw_text = tok_keyword_text(tok.clone()); +if (kw_text.clone().as_str() == "capability".to_string().as_str()) { + let r = parse_capability(&tokens, &ctx); +if has_err(r.err.clone()) { + return Rc::new(ResPropResult { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(capabilities, r.capability.clone()); +tokens = __tco_0; +ctx = __tco_1; +capabilities = __tco_2; +continue; +} +} else { + if (kw_text.clone().as_str() == "acquire".to_string().as_str()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { + return Rc::new(ResPropResult { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - } - Some(TokenShape::ShIdent) => { - if peek_is_colon_after_ident(tokens.clone()) { - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { - return Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let fname = r.name.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { +let r2 = skip_until_rbrace(&skip_newlines(r.tokens.clone())); +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { + return Rc::new(ResPropResult { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) + } +{ + let __tco_0 = skip_newlines(r3.tokens.clone()); +tokens = __tco_0; +continue; +} +} else { + if (kw_text.clone().as_str() == "release".to_string().as_str()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { +let r2 = skip_until_rbrace(&skip_newlines(r.tokens.clone())); +let r3 = expect(&r2.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { return Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: r3.tokens.clone(), + ctx: ctx.clone(), + err: r3.err.clone(), +}) } - let fi = make_field_init_node( - &fname, - r3.expr.clone(), - make_span(0, 0), - r.span.clone(), - ); - { +{ let __tco_0 = skip_newlines(r3.tokens.clone()); - let __tco_1 = r3.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(properties, fi); - tokens = __tco_0; - ctx = __tco_1; - properties = __tco_2; - continue; - } - } else { +tokens = __tco_0; +continue; +} +} else { break Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "unexpected token in resource block".to_string(), - span, - )), - }); - } - } - _ => { - break Rc::new(ResPropResult { - properties: properties.clone(), - capabilities: capabilities.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - "expected capability, acquire, release, or property in resource block" - .to_string(), - span, - )), - }); - } - } - } - } + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("unexpected keyword in resource block".to_string(), span)), +}); +} +} +} }, + Some(TokenShape::ShIdent) => { if peek_is_colon_after_ident(tokens.clone()) { + let r = expect_ident(&tokens); +if has_err(r.err.clone()) { + return Rc::new(ResPropResult { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let fname = r.name.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { + return Rc::new(ResPropResult { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); +if has_err(r3.err.clone()) { + return Rc::new(ResPropResult { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let fi = make_field_init_node(&fname, r3.expr.clone(), make_span(0, 0), r.span.clone()); +{ + let __tco_0 = skip_newlines(r3.tokens.clone()); +let __tco_1 = r3.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(properties, fi); +tokens = __tco_0; +ctx = __tco_1; +properties = __tco_2; +continue; +} +} else { + break Rc::new(ResPropResult { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("unexpected token in resource block".to_string(), span)), +}); +} }, + _ => { break Rc::new(ResPropResult { + properties: properties.clone(), + capabilities: capabilities.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error("expected capability, acquire, release, or property in resource block".to_string(), span)), +}); }, +} +} +} } pub fn skip_until_rbrace(tokens: &Rc>>) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - if (tok_is_rbrace(tok.clone()) || tok_is_eof(tok.clone())) { - Rc::new(UnitResult { - tokens: tokens.clone(), - err: None, - }) - } else { - { - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShLBrace) => { - let inner = skip_until_rbrace(&Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - )); - let r = - expect(&inner.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r.err.clone()) { + { + let tokens = skip_newlines(tokens.clone()); +let tok = tokens.clone().first().cloned(); +if (tok_is_rbrace(tok.clone()) || tok_is_eof(tok.clone())) { + Rc::new(UnitResult { + tokens: tokens.clone(), + err: None, +}) + } else { + { + let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShLBrace) => { + let inner = skip_until_rbrace(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>())); +let r = expect(&inner.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r.err.clone()) { return Rc::new(UnitResult { - tokens: r.tokens.clone(), - err: r.err.clone(), - }); + tokens: r.tokens.clone(), + err: r.err.clone(), +}) } - skip_until_rbrace(&r.tokens.clone()) - } - _ => skip_until_rbrace(&Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - )), - } +skip_until_rbrace(&r.tokens.clone()) +}, + _ => skip_until_rbrace(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>())), +} +} } - } +} }) } pub fn parse_capability(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy_cap = make_capability_node( - "".to_string(), - None, - Rc::new(vec![]), - Rc::new(vec![]), - &start_span, - &ctx.source_indices.clone(), - ); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "capability".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy_cap = make_capability_node("".to_string(), None, Rc::new(vec![]), Rc::new(vec![]), &start_span, &ctx.source_indices.clone()); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "capability".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = expect_ident(&r.tokens.clone()); - if has_err(r.err.clone()) { + capability: dummy_cap.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = expect_ident(&r.tokens.clone()); +if has_err(r.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let tokens = r.tokens.clone(); - if tok_is_lbrace(tokens.clone().first().cloned()) { + capability: dummy_cap.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let tokens = r.tokens.clone(); +if tok_is_lbrace(tokens.clone().first().cloned()) { { let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBrace)); - if has_err(r2.err.clone()) { +if has_err(r2.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); + capability: dummy_cap.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - let io = parse_input_output_blocks(skip_newlines(r2.tokens.clone()), ctx.clone()); - if has_err(io.err.clone()) { +let io = parse_input_output_blocks(skip_newlines(r2.tokens.clone()), ctx.clone()); +if has_err(io.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: io.tokens.clone(), - ctx: io.ctx.clone(), - err: io.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(io.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { + capability: dummy_cap.clone(), + tokens: io.tokens.clone(), + ctx: io.ctx.clone(), + err: io.err.clone(), +}) + } +let r3 = expect(&skip_newlines(io.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: r3.tokens.clone(), - ctx: io.ctx.clone(), - err: r3.err.clone(), - }); - } - let cap = make_capability_node( - name, - Some(name_span), - io.inputs.clone(), - io.outputs.clone(), - &start_span, - &ctx.source_indices.clone(), - ); - Rc::new(CapResult { - capability: cap, - tokens: skip_newlines(r3.tokens.clone()), - ctx: io.ctx.clone(), - err: None, - }) - } + capability: dummy_cap.clone(), + tokens: r3.tokens.clone(), + ctx: io.ctx.clone(), + err: r3.err.clone(), +}) + } +let cap = make_capability_node(name, Some(name_span), io.inputs.clone(), io.outputs.clone(), &start_span, &ctx.source_indices.clone()); +Rc::new(CapResult { + capability: cap, + tokens: skip_newlines(r3.tokens.clone()), + ctx: io.ctx.clone(), + err: None, +}) +} } else { if tok_is_lparen(tokens.clone().first().cloned()) { { let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); - if has_err(r2.err.clone()) { +if has_err(r2.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); + capability: dummy_cap.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) } - let r3 = parse_field_list(skip_newlines(r2.tokens.clone()), ctx.clone()); - if has_err(r3.err.clone()) { +let r3 = parse_field_list(skip_newlines(r2.tokens.clone()), ctx.clone()); +if has_err(r3.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); + capability: dummy_cap.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) } - let inputs = r3.fields.clone(); - let r4 = expect( - &skip_newlines(r3.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRParen), - ); - if has_err(r4.err.clone()) { +let inputs = r3.fields.clone(); +let r4 = expect(&skip_newlines(r3.tokens.clone()), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r4.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: r4.tokens.clone(), - ctx: r3.ctx.clone(), - err: r4.err.clone(), - }); + capability: dummy_cap.clone(), + tokens: r4.tokens.clone(), + ctx: r3.ctx.clone(), + err: r4.err.clone(), +}) } - let ret = parse_optional_inferred(&r4.tokens.clone(), r3.ctx.clone()); - if has_err(ret.err.clone()) { +let ret = parse_optional_inferred(&r4.tokens.clone(), r3.ctx.clone()); +if has_err(ret.err.clone()) { return Rc::new(CapResult { - capability: dummy_cap.clone(), - tokens: ret.tokens.clone(), - ctx: ret.ctx.clone(), - err: ret.err.clone(), - }); + capability: dummy_cap.clone(), + tokens: ret.tokens.clone(), + ctx: ret.ctx.clone(), + err: ret.err.clone(), +}) } - let outputs = match ret.inferred.clone().as_deref().cloned() { - Some(InferredNode::Resolved { node: rt, .. }) => { - node_inferred_to_outputs(&rt, ret.ctx.clone().source_indices.clone()) - } - _ => Rc::new(vec![]), - }; - let cap = make_capability_node( - name, - Some(name_span), - inputs, - outputs, - &start_span, - &ctx.source_indices.clone(), - ); - Rc::new(CapResult { - capability: cap, - tokens: skip_newlines(ret.tokens.clone()), - ctx: ret.ctx.clone(), - err: None, - }) - } +let outputs = match ret.inferred.clone().as_deref().cloned() { + Some(InferredNode::Resolved { node: rt, .. }) => node_inferred_to_outputs(&rt, ret.ctx.clone().source_indices.clone()), + _ => Rc::new(vec![]), +}; +let cap = make_capability_node(name, Some(name_span), inputs, outputs, &start_span, &ctx.source_indices.clone()); +Rc::new(CapResult { + capability: cap, + tokens: skip_newlines(ret.tokens.clone()), + ctx: ret.ctx.clone(), + err: None, +}) +} } else { { - let cap = make_capability_node( - name, - Some(name_span), - Rc::new(vec![]), - Rc::new(vec![]), - &start_span, - &ctx.source_indices.clone(), - ); - Rc::new(CapResult { - capability: cap, - tokens: skip_newlines(tokens.clone()), - ctx: ctx.clone(), - err: None, - }) - } + let cap = make_capability_node(name, Some(name_span), Rc::new(vec![]), Rc::new(vec![]), &start_span, &ctx.source_indices.clone()); +Rc::new(CapResult { + capability: cap, + tokens: skip_newlines(tokens.clone()), + ctx: ctx.clone(), + err: None, +}) +} } } - } +} } -pub fn parse_input_output_blocks( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_input_output_blocks(tokens: Rc>>, ctx: Rc) -> Rc { parse_io_blocks_acc(tokens, ctx, Rc::new(vec![]), Rc::new(vec![])) } -pub fn parse_io_blocks_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut inputs: Rc>>, - mut outputs: Rc>>, -) -> Rc { +pub fn parse_io_blocks_acc(mut tokens: Rc>>, mut ctx: Rc, mut inputs: Rc>>, mut outputs: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(IOResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + inputs: inputs.clone(), + outputs: outputs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let kw = tok_keyword_text(tokens.clone().first().cloned()); - if (kw.clone().as_str() == "input".to_string().as_str()) { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { +if (kw.clone().as_str() == "input".to_string().as_str()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(IOResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + inputs: inputs.clone(), + outputs: outputs.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let r2 = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r2.err.clone()) { +let r2 = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { return Rc::new(IOResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { + inputs: inputs.clone(), + outputs: outputs.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { return Rc::new(IOResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); - } - { + inputs: inputs.clone(), + outputs: outputs.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) + } +{ let __tco_0 = r3.tokens.clone(); - let __tco_1 = r2.ctx.clone(); - let __tco_2 = r2.fields.clone(); - tokens = __tco_0; - ctx = __tco_1; - inputs = __tco_2; - continue; - } - } else { +let __tco_1 = r2.ctx.clone(); +let __tco_2 = r2.fields.clone(); +tokens = __tco_0; +ctx = __tco_1; +inputs = __tco_2; +continue; +} +} else { if (kw.clone().as_str() == "output".to_string().as_str()) { - let r = expect( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { + let r = expect(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(IOResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + inputs: inputs.clone(), + outputs: outputs.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let r2 = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r2.err.clone()) { +let r2 = parse_field_list(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r2.err.clone()) { return Rc::new(IOResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); + inputs: inputs.clone(), + outputs: outputs.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) } - let r3 = expect( - &skip_newlines(r2.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r3.err.clone()) { +let r3 = expect(&skip_newlines(r2.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r3.err.clone()) { return Rc::new(IOResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - tokens: r3.tokens.clone(), - ctx: r2.ctx.clone(), - err: r3.err.clone(), - }); + inputs: inputs.clone(), + outputs: outputs.clone(), + tokens: r3.tokens.clone(), + ctx: r2.ctx.clone(), + err: r3.err.clone(), +}) } - { +{ let __tco_0 = r3.tokens.clone(); - let __tco_1 = r2.ctx.clone(); - let __tco_2 = r2.fields.clone(); - tokens = __tco_0; - ctx = __tco_1; - outputs = __tco_2; - continue; - } - } else { +let __tco_1 = r2.ctx.clone(); +let __tco_2 = r2.fields.clone(); +tokens = __tco_0; +ctx = __tco_1; +outputs = __tco_2; +continue; +} +} else { break Rc::new(IOResult { - inputs: inputs.clone(), - outputs: outputs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } - } - } - } + inputs: inputs.clone(), + outputs: outputs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} +} +} +} } pub fn parse_data_def(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "data".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy = Rc::new(Node { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "data".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - parse_data_after_kw(r.tokens.clone(), &ctx, &start_span) - } +parse_data_after_kw(r.tokens.clone(), &ctx, &start_span) +} } -pub fn parse_data_after_kw( - tokens: Rc>>, - ctx: &Rc, - start_span: &Rc, -) -> Rc { +pub fn parse_data_after_kw(tokens: Rc>>, ctx: &Rc, start_span: &Rc) -> Rc { { let dummy = Rc::new(Node { - name: "".to_string(), - span: start_span.clone(), - ident_span: None, - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect_ident(&tokens); - if has_err(r.err.clone()) { - return Rc::new(ItemResult { - item: dummy, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let named_dummy = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r.err.clone()) { + name: "".to_string(), + span: start_span.clone(), + ident_span: None, + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect_ident(&tokens); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_type_expr(&r.tokens.clone(), &ctx); - if has_err(r.err.clone()) { + item: dummy, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let named_dummy = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let te = r.type_expr.clone(); - let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); - if has_err(r.err.clone()) { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_type_expr(&r.tokens.clone(), &ctx); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_expr(r.tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let te = r.type_expr.clone(); +let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); +if has_err(r.err.clone()) { return Rc::new(ItemResult { - item: named_dummy.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let item = Rc::new(Node { - name: name.clone(), - span: start_span.clone(), - ident_span: Some(name_span.clone()), - children: Rc::new(vec![]), - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: Some(r.expr.clone()), - connective: Connective::NoConnective, - transport: None, - properties: Rc::new(vec![]), - type_annotation: Some(te), - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - Rc::new(ItemResult { - item: item, - tokens: skip_newlines(r.tokens.clone()), - ctx: r.ctx.clone(), - err: None, - }) - } +let r = parse_expr(r.tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { + return Rc::new(ItemResult { + item: named_dummy.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let item = Rc::new(Node { + name: name.clone(), + span: start_span.clone(), + ident_span: Some(name_span.clone()), + children: Rc::new(vec![]), + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: Some(r.expr.clone()), + connective: Connective::NoConnective, + transport: None, + properties: Rc::new(vec![]), + type_annotation: Some(te), + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +Rc::new(ItemResult { + item: item, + tokens: skip_newlines(r.tokens.clone()), + ctx: r.ctx.clone(), + err: None, +}) +} } pub fn parse_params(tokens: &Rc>>, ctx: &Rc) -> Rc { { let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ParamsResult { - params: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + params: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let tokens = skip_newlines(r.tokens.clone()); - if tok_is_rparen(tokens.clone().first().cloned()) { +let tokens = skip_newlines(r.tokens.clone()); +if tok_is_rparen(tokens.clone().first().cloned()) { Rc::new(ParamsResult { - params: Rc::new(vec![]), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) + params: Rc::new(vec![]), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) } else { { let r = parse_param_list(tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { - return r.clone(); +if has_err(r.err.clone()) { + return r.clone() } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r2.err.clone()) { +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r2.err.clone()) { return Rc::new(ParamsResult { - params: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); + params: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) } - Rc::new(ParamsResult { - params: r.params.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +Rc::new(ParamsResult { + params: r.params.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } - } +} } pub fn parse_param_list(tokens: Rc>>, ctx: Rc) -> Rc { parse_param_list_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_param_list_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_param_list_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { let r = parse_param(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ParamsResult { - params: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - acc = v2_rt::rc_list_push(acc.clone(), r.param.clone()); - match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - tokens = skip_newlines(__ec.clone()); - if tok_is_rparen(tokens.clone().first().cloned()) { - break Rc::new(ParamsResult { - params: acc.clone(), - tokens: tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } else { - { - let __tco_0 = r.ctx.clone(); - ctx = __tco_0; - continue; - } - } - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(ParamsResult { - params: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } - } - } + params: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +acc = v2_rt::rc_list_push(acc.clone(), r.param.clone()); +match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { tokens = skip_newlines(__ec.clone()); +if tok_is_rparen(tokens.clone().first().cloned()) { + break Rc::new(ParamsResult { + params: acc.clone(), + tokens: tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); +} else { + { + let __tco_0 = r.ctx.clone(); +ctx = __tco_0; +continue; +} +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(ParamsResult { + params: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); }, +} +} } pub fn parse_param(tokens: &Rc>>, ctx: &Rc) -> Rc { { let start_span = token_span(tokens.clone().first().cloned()); - let dummy_param = make_param_node( - &"".to_string(), - leaf_type_node(&"".to_string(), &start_span), - None, - start_span.clone(), - start_span.clone(), - ); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { +let dummy_param = make_param_node(&"".to_string(), leaf_type_node(&"".to_string(), &start_span), None, start_span.clone(), start_span.clone()); +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(ParamResult { - param: dummy_param.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); - if has_err(r2.err.clone()) { + param: dummy_param.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectColon)); +if has_err(r2.err.clone()) { return Rc::new(ParamResult { - param: dummy_param.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_type_expr(&r2.tokens.clone(), &ctx); - if has_err(r3.err.clone()) { + param: dummy_param.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_type_expr(&r2.tokens.clone(), &ctx); +if has_err(r3.err.clone()) { return Rc::new(ParamResult { - param: dummy_param.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: r3.err.clone(), - }); - } - let wr = try_where_clause( - &r3.tokens.clone(), - r3.ctx.clone(), - &r3.type_expr.clone(), - &start_span, - ); - if has_err(wr.err.clone()) { + param: dummy_param.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: r3.err.clone(), +}) + } +let wr = try_where_clause(&r3.tokens.clone(), r3.ctx.clone(), &r3.type_expr.clone(), &start_span); +if has_err(wr.err.clone()) { return Rc::new(ParamResult { - param: dummy_param.clone(), - tokens: wr.tokens.clone(), - ctx: wr.ctx.clone(), - err: wr.err.clone(), - }); - } - let type_expr = wr.type_expr.clone(); - let tokens = wr.tokens.clone(); - let ctx = wr.ctx.clone(); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectEq))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r4 = parse_expr(__ec.clone(), ctx.clone()); - if has_err(r4.err.clone()) { - return Rc::new(ParamResult { - param: dummy_param.clone(), - tokens: r4.tokens.clone(), - ctx: r4.ctx.clone(), - err: r4.err.clone(), - }); - } - let p = make_param_node( - &name, - type_expr, - Some(r4.expr.clone()), - start_span.clone(), - name_span, - ); - Rc::new(ParamResult { - param: p, - tokens: r4.tokens.clone(), - ctx: r4.ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let p = make_param_node(&name, type_expr, None, start_span.clone(), name_span); - Rc::new(ParamResult { - param: p, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - } - } + param: dummy_param.clone(), + tokens: wr.tokens.clone(), + ctx: wr.ctx.clone(), + err: wr.err.clone(), +}) + } +let type_expr = wr.type_expr.clone(); +let tokens = wr.tokens.clone(); +let ctx = wr.ctx.clone(); +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectEq))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { + let r4 = parse_expr(__ec.clone(), ctx.clone()); +if has_err(r4.err.clone()) { + return Rc::new(ParamResult { + param: dummy_param.clone(), + tokens: r4.tokens.clone(), + ctx: r4.ctx.clone(), + err: r4.err.clone(), +}) + } +let p = make_param_node(&name, type_expr, Some(r4.expr.clone()), start_span.clone(), name_span); +Rc::new(ParamResult { + param: p, + tokens: r4.tokens.clone(), + ctx: r4.ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => { + let p = make_param_node(&name, type_expr, None, start_span.clone(), name_span); +Rc::new(ParamResult { + param: p, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +}, +} +} } pub fn parse_block(tokens: &Rc>>, ctx: &Rc) -> Rc { { let dummy_expr = parse_recovery_placeholder(); - let block_span = token_span(tokens.clone().first().cloned()); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBrace)); - if has_err(r.err.clone()) { +let block_span = token_span(tokens.clone().first().cloned()); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r = parse_stmts(tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r = parse_stmts(tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let stmts = r.stmts.clone(); - let tokens = skip_newlines(r.tokens.clone()); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let stmts = r.stmts.clone(); +let tokens = skip_newlines(r.tokens.clone()); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - if ((stmts.clone().len() as i64) == 1) { +if ((stmts.clone().len() as i64) == 1) { Rc::new(ExprResult { - expr: stmts.clone().first().cloned().clone().unwrap(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + expr: stmts.clone().first().cloned().clone().unwrap(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } else { Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprBlock), - stmts.clone(), - None, - block_span, - ), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + expr: make_expr_node(Rc::new(ExprData::ExprBlock), stmts.clone(), None, block_span), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } - } +} } pub fn parse_stmts(tokens: Rc>>, ctx: Rc) -> Rc { parse_stmts_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_stmts_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_stmts_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(StmtsResult { - stmts: acc.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + stmts: acc.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { let r = parse_stmt(&tokens, ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(StmtsResult { - stmts: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + stmts: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - { +{ let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(acc, r.expr.clone()); - tokens = __tco_0; - ctx = __tco_1; - acc = __tco_2; - continue; - } - } - } +let __tco_1 = r.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(acc, r.expr.clone()); +tokens = __tco_0; +ctx = __tco_1; +acc = __tco_2; +continue; +} +} +} } pub fn parse_stmt(tokens: &Rc>>, ctx: Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShKeyword) => { - let kw_text = tok_keyword_text(tok.clone()); - if (kw_text.clone().as_str() == "let".to_string().as_str()) { - parse_let(&tokens, &ctx) +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShKeyword) => { + let kw_text = tok_keyword_text(tok.clone()); +if (kw_text.clone().as_str() == "let".to_string().as_str()) { + parse_let(&tokens, &ctx) + } else { + if (kw_text.clone().as_str() == "return".to_string().as_str()) { + parse_return(&tokens, &ctx) } else { - if (kw_text.clone().as_str() == "return".to_string().as_str()) { - parse_return(&tokens, &ctx) + if peek_is_eq_after_ident(tokens.clone()) { + parse_bare_assignment(&tokens, &ctx) } else { - if peek_is_eq_after_ident(tokens.clone()) { - parse_bare_assignment(&tokens, &ctx) - } else { - parse_expr(tokens.clone(), ctx) - } + parse_expr(tokens.clone(), ctx) } } } - Some(TokenShape::ShIdent) => { - if (peek_text_is(tokens.clone(), "node".to_string()) && peek_is_node_decl(&tokens)) - { - parse_node_decl(&tokens, &ctx) +}, + Some(TokenShape::ShIdent) => if (peek_text_is(tokens.clone(), "node".to_string()) && peek_is_node_decl(&tokens)) { + parse_node_decl(&tokens, &ctx) + } else { + if peek_is_eq_after_ident(tokens.clone()) { + parse_bare_assignment(&tokens, &ctx) + } else { + if is_constraint_bracket_after_ident(&tokens) { + parse_constrained_assignment(&tokens, &ctx) } else { - if peek_is_eq_after_ident(tokens.clone()) { - parse_bare_assignment(&tokens, &ctx) - } else { - if is_constraint_bracket_after_ident(&tokens) { - parse_constrained_assignment(&tokens, &ctx) - } else { - parse_expr(tokens.clone(), ctx) - } - } + parse_expr(tokens.clone(), ctx) } } - _ => parse_expr(tokens.clone(), ctx), - } - } + }, + _ => parse_expr(tokens.clone(), ctx), +} +} } pub fn peek_is_eq_after_ident(tokens: Rc>>) -> bool { match tokens.get(1 as usize).cloned() { - Some(t) => is_eq_shape(t.shape.clone()), - None => false, - } + Some(t) => is_eq_shape(t.shape.clone()), + None => false, +} } pub fn peek_is_node_decl(tokens: &Rc>>) -> bool { { let t1 = tokens.clone().get(1 as usize).cloned(); - let t2 = tokens.clone().get(2 as usize).cloned(); - let name_ok = match t1 { - Some(t) => (is_ident_shape(t.shape.clone()) || is_name_keyword(&t)), - None => false, - }; - let decl_ok = match t2 { - Some(t) => { - ((is_colon_shape(t.shape.clone()) || is_lbracket_shape(t.shape.clone())) - || is_eq_shape(t.shape.clone())) - } - None => false, - }; - (name_ok && decl_ok) - } +let t2 = tokens.clone().get(2 as usize).cloned(); +let name_ok = match t1 { + Some(t) => (is_ident_shape(t.shape.clone()) || is_name_keyword(&t)), + None => false, +}; +let decl_ok = match t2 { + Some(t) => ((is_colon_shape(t.shape.clone()) || is_lbracket_shape(t.shape.clone())) || is_eq_shape(t.shape.clone())), + None => false, +}; +(name_ok && decl_ok) +} } pub fn is_constraint_bracket_after_ident(tokens: &Rc>>) -> bool { match tokens.clone().get(1 as usize).cloned() { - Some(t) => { - (is_lbracket_shape(t.shape.clone()) - && is_constraint_bracket(Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ))) - } - None => false, - } + Some(t) => (is_lbracket_shape(t.shape.clone()) && is_constraint_bracket(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()))), + None => false, +} } -pub fn parse_constrained_assignment( - tokens: &Rc>>, - ctx: &Rc, -) -> Rc { +pub fn parse_constrained_assignment(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let cr = try_constraint_annotations(&r.tokens.clone(), ctx.clone()); - if has_err(cr.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let cr = try_constraint_annotations(&r.tokens.clone(), ctx.clone()); +if has_err(cr.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: cr.tokens.clone(), - ctx: cr.ctx.clone(), - err: cr.err.clone(), - }); - } - let r2 = expect(&cr.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); - if has_err(r2.err.clone()) { + expr: dummy_expr.clone(), + tokens: cr.tokens.clone(), + ctx: cr.ctx.clone(), + err: cr.err.clone(), +}) + } +let r2 = expect(&cr.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: cr.ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_expr(r2.tokens.clone(), cr.ctx.clone()); - if has_err(r3.err.clone()) { - return r3.clone(); - } - let node = make_named_expr_node( - &name, - Rc::new(ExprData::ExprLet), - Rc::new(vec![r3.expr.clone()]), - None, - span, - name_span, - ); - let node = Rc::new(Node { - name: node.name.clone(), - span: node.span.clone(), - ident_span: node.ident_span.clone(), - children: node.children.clone(), - params: node.params.clone(), - inferred: node.inferred.clone(), - return_cardinality: node.return_cardinality.clone(), - uses: node.uses.clone(), - body: node.body.clone(), - connective: node.connective.clone(), - transport: node.transport.clone(), - properties: cr.constraints.clone(), - type_annotation: node.type_annotation.clone(), - is_self_recursive: node.is_self_recursive.clone(), - has_non_tail_self_call: node.has_non_tail_self_call.clone(), - match_pattern: node.match_pattern.clone(), - expr_data: node.expr_data.clone(), - ident: None, - }); - Rc::new(ExprResult { - expr: node.clone(), - tokens: r3.tokens.clone(), - ctx: r3.ctx.clone(), - err: None, - }) - } + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: cr.ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_expr(r2.tokens.clone(), cr.ctx.clone()); +if has_err(r3.err.clone()) { + return r3.clone() + } +let node = make_named_expr_node(&name, Rc::new(ExprData::ExprLet), Rc::new(vec![r3.expr.clone()]), None, span, name_span); +let node = Rc::new(Node { + name: node.name.clone(), + span: node.span.clone(), + ident_span: node.ident_span.clone(), + children: node.children.clone(), + params: node.params.clone(), + inferred: node.inferred.clone(), + return_cardinality: node.return_cardinality.clone(), + uses: node.uses.clone(), + body: node.body.clone(), + connective: node.connective.clone(), + transport: node.transport.clone(), + properties: cr.constraints.clone(), + type_annotation: node.type_annotation.clone(), + is_self_recursive: node.is_self_recursive.clone(), + has_non_tail_self_call: node.has_non_tail_self_call.clone(), + match_pattern: node.match_pattern.clone(), + expr_data: node.expr_data.clone(), + ident: None, +}); +Rc::new(ExprResult { + expr: node.clone(), + tokens: r3.tokens.clone(), + ctx: r3.ctx.clone(), + err: None, +}) +} } pub fn peek_text_is(tokens: Rc>>, expected: String) -> bool { match tokens.first().cloned() { - Some(t) => { - (is_ident_shape(t.shape.clone()) && (t.text.clone().as_str() == expected.as_str())) - } - None => false, - } + Some(t) => (is_ident_shape(t.shape.clone()) && (t.text.clone().as_str() == expected.as_str())), + None => false, +} } pub fn parse_node_decl(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let tokens = Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let tokens = Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()); +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let cr = try_constraint_annotations(&r.tokens.clone(), ctx.clone()); - if has_err(cr.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let cr = try_constraint_annotations(&r.tokens.clone(), ctx.clone()); +if has_err(cr.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: cr.tokens.clone(), - ctx: cr.ctx.clone(), - err: cr.err.clone(), - }); - } - let e_colon = eat(&cr.tokens.clone(), Rc::new(ExpectedToken::ExpectColon)); - let tokens = match (*e_colon.clone()).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => { - let r2 = expect(&cr.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); - if has_err(r2.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: cr.ctx.clone(), - err: r2.err.clone(), - }); - } - r2.tokens.clone() - } - }; - let r3 = parse_expr(tokens.clone(), cr.ctx.clone()); - if has_err(r3.err.clone()) { - return r3.clone(); + expr: dummy_expr.clone(), + tokens: cr.tokens.clone(), + ctx: cr.ctx.clone(), + err: cr.err.clone(), +}) + } +let e_colon = eat(&cr.tokens.clone(), Rc::new(ExpectedToken::ExpectColon)); +let tokens = match (*e_colon.clone()).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => { + let r2 = expect(&cr.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); +if has_err(r2.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: cr.ctx.clone(), + err: r2.err.clone(), +}) + } +r2.tokens.clone() +}, +}; +let r3 = parse_expr(tokens.clone(), cr.ctx.clone()); +if has_err(r3.err.clone()) { + return r3.clone() } - let ret = parse_optional_inferred(&r3.tokens.clone(), r3.ctx.clone()); - if has_err(ret.err.clone()) { +let ret = parse_optional_inferred(&r3.tokens.clone(), r3.ctx.clone()); +if has_err(ret.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: ret.tokens.clone(), - ctx: ret.ctx.clone(), - err: ret.err.clone(), - }); - } - let type_ann = match (*e_colon.clone()).clone() { - EatResult::EatConsumed { .. } => Some(r3.expr.clone()), - EatResult::EatUnchanged { .. } => None, - }; - let node = Rc::new(Node { - name: name, - span: span, - ident_span: Some(name_span), - children: Rc::new(vec![r3.expr.clone()]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: ret.inferred.clone(), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: cr.constraints.clone(), - type_annotation: type_ann, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::ExprLet), - ident: None, - }); - Rc::new(ExprResult { - expr: node, - tokens: ret.tokens.clone(), - ctx: ret.ctx.clone(), - err: None, - }) - } + expr: dummy_expr.clone(), + tokens: ret.tokens.clone(), + ctx: ret.ctx.clone(), + err: ret.err.clone(), +}) + } +let type_ann = match (*e_colon.clone()).clone() { + EatResult::EatConsumed { .. } => Some(r3.expr.clone()), + EatResult::EatUnchanged { .. } => None, +}; +let node = Rc::new(Node { + name: name, + span: span, + ident_span: Some(name_span), + children: Rc::new(vec![r3.expr.clone()]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: ret.inferred.clone(), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: cr.constraints.clone(), + type_annotation: type_ann, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::ExprLet), + ident: None, +}); +Rc::new(ExprResult { + expr: node, + tokens: ret.tokens.clone(), + ctx: ret.ctx.clone(), + err: None, +}) +} } -pub fn parse_bare_assignment( - tokens: &Rc>>, - ctx: &Rc, -) -> Rc { +pub fn parse_bare_assignment(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); - if has_err(r2.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); - if has_err(r3.err.clone()) { - return r3.clone(); - } - let cr = try_constraint_annotations(&r3.tokens.clone(), r3.ctx.clone()); - if has_err(cr.err.clone()) { + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let r3 = parse_expr(r2.tokens.clone(), ctx.clone()); +if has_err(r3.err.clone()) { + return r3.clone() + } +let cr = try_constraint_annotations(&r3.tokens.clone(), r3.ctx.clone()); +if has_err(cr.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: cr.tokens.clone(), - ctx: cr.ctx.clone(), - err: cr.err.clone(), - }); - } - let node = make_named_expr_node( - &name, - Rc::new(ExprData::ExprLet), - Rc::new(vec![r3.expr.clone()]), - None, - span, - name_span, - ); - if ((cr.constraints.clone().len() as i64) > 0) { + expr: dummy_expr.clone(), + tokens: cr.tokens.clone(), + ctx: cr.ctx.clone(), + err: cr.err.clone(), +}) + } +let node = make_named_expr_node(&name, Rc::new(ExprData::ExprLet), Rc::new(vec![r3.expr.clone()]), None, span, name_span); +if ((cr.constraints.clone().len() as i64) > 0) { { let node = Rc::new(Node { - name: node.name.clone(), - span: node.span.clone(), - ident_span: node.ident_span.clone(), - children: node.children.clone(), - params: node.params.clone(), - inferred: node.inferred.clone(), - return_cardinality: node.return_cardinality.clone(), - uses: node.uses.clone(), - body: node.body.clone(), - connective: node.connective.clone(), - transport: node.transport.clone(), - properties: cr.constraints.clone(), - type_annotation: node.type_annotation.clone(), - is_self_recursive: node.is_self_recursive.clone(), - has_non_tail_self_call: node.has_non_tail_self_call.clone(), - match_pattern: node.match_pattern.clone(), - expr_data: node.expr_data.clone(), - ident: None, - }); - Rc::new(ExprResult { - expr: node.clone(), - tokens: cr.tokens.clone(), - ctx: cr.ctx.clone(), - err: None, - }) - } + name: node.name.clone(), + span: node.span.clone(), + ident_span: node.ident_span.clone(), + children: node.children.clone(), + params: node.params.clone(), + inferred: node.inferred.clone(), + return_cardinality: node.return_cardinality.clone(), + uses: node.uses.clone(), + body: node.body.clone(), + connective: node.connective.clone(), + transport: node.transport.clone(), + properties: cr.constraints.clone(), + type_annotation: node.type_annotation.clone(), + is_self_recursive: node.is_self_recursive.clone(), + has_non_tail_self_call: node.has_non_tail_self_call.clone(), + match_pattern: node.match_pattern.clone(), + expr_data: node.expr_data.clone(), + ident: None, +}); +Rc::new(ExprResult { + expr: node.clone(), + tokens: cr.tokens.clone(), + ctx: cr.ctx.clone(), + err: None, +}) +} } else { Rc::new(ExprResult { - expr: node.clone(), - tokens: cr.tokens.clone(), - ctx: cr.ctx.clone(), - err: None, - }) + expr: node.clone(), + tokens: cr.tokens.clone(), + ctx: cr.ctx.clone(), + err: None, +}) } - } +} } pub fn parse_expr(tokens: Rc>>, ctx: Rc) -> Rc { parse_expr_bp(tokens, ctx, 0) } -pub fn parse_expr_bp( - tokens: Rc>>, - ctx: Rc, - min_bp: i64, -) -> Rc { +pub fn parse_expr_bp(tokens: Rc>>, ctx: Rc, min_bp: i64) -> Rc { { let r = parse_prefix(&tokens, ctx); - if has_err(r.err.clone()) { - return r.clone(); +if has_err(r.err.clone()) { + return r.clone() } - let lhs = r.expr.clone(); - parse_expr_loop(r.tokens.clone(), r.ctx.clone(), lhs, min_bp) - } +let lhs = r.expr.clone(); +parse_expr_loop(r.tokens.clone(), r.ctx.clone(), lhs, min_bp) +} } -pub fn parse_expr_loop( - mut tokens: Rc>>, - mut ctx: Rc, - mut lhs: Rc, - mut min_bp: i64, -) -> Rc { +pub fn parse_expr_loop(mut tokens: Rc>>, mut ctx: Rc, mut lhs: Rc, mut min_bp: i64) -> Rc { loop { if tok_is_eof(tokens.clone().first().cloned()) { break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + expr: lhs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let loop_span = token_span(tokens.clone().first().cloned()); - tokens = skip_continuation_newlines(&tokens); - let post = try_postfix(&tokens, &ctx, &lhs, min_bp.clone()); - if has_err(post.err.clone()) { +tokens = skip_continuation_newlines(&tokens); +let post = try_postfix(&tokens, &ctx, &lhs, min_bp.clone()); +if has_err(post.err.clone()) { break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: post.tokens.clone(), - ctx: post.ctx.clone(), - err: post.err.clone(), - }); - } else { + expr: lhs.clone(), + tokens: post.tokens.clone(), + ctx: post.ctx.clone(), + err: post.err.clone(), +}); +} else { if post.changed.clone() { { let __tco_0 = post.tokens.clone(); - let __tco_1 = post.ctx.clone(); - let __tco_2 = post.expr.clone(); - tokens = __tco_0; - ctx = __tco_1; - lhs = __tco_2; - continue; - } - } else { +let __tco_1 = post.ctx.clone(); +let __tco_2 = post.expr.clone(); +tokens = __tco_0; +ctx = __tco_1; +lhs = __tco_2; +continue; +} +} else { let bp = infix_bp(tokens.clone()); - match bp { - Some(bps) => { - if (bps.left.clone() < min_bp.clone()) { - break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { - match (*advance(&tokens)).clone() { - AdvanceResult::AdvanceOk { - token: op_tok, - tokens: rest, - .. - } => { - let op_shape = op_tok.shape.clone(); - if is_dot_shape(op_shape.clone()) { - let r = expect_name(&rest); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: lhs.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let new_lhs = make_named_expr_node( - &r.name.clone(), - Rc::new(ExprData::ExprFieldAccess { - summary: None, - }), - Rc::new(vec![lhs.clone()]), - None, - loop_span, - r.span.clone(), - ); - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = new_lhs; - tokens = __tco_0; - lhs = __tco_1; - continue; - } - } else { - if is_pipe_arrow_shape(op_shape.clone()) { - let r = parse_pipe_rhs( - &rest, - &ctx, - lhs.clone(), - loop_span, - ); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = r.expr.clone(); - tokens = __tco_0; - ctx = __tco_1; - lhs = __tco_2; - continue; - } - } else { - tokens = skip_newlines(rest.clone()); - let r = parse_expr_bp( - tokens.clone(), - ctx.clone(), - bps.right.clone(), - ); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let binop_opt = find_operator_binop( - dag_syntax_spec().operators.clone(), - op_tok.text.clone(), - ); - match binop_opt { - Some(binop) => { - let new_lhs = make_expr_node( - Rc::new(ExprData::ExprBinOp { - op: binop.clone(), - algebra_field: None, - }), - Rc::new(vec![ - lhs.clone(), - r.expr.clone(), - ]), - None, - loop_span, - ); - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = new_lhs; - tokens = __tco_0; - ctx = __tco_1; - lhs = __tco_2; - continue; - } - } - None => { - break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: Some(parse_error( - v2_rt::concat( - "unknown binary operator: " - .to_string(), - op_tok.text.clone(), - ), - loop_span, - )), - }); - } - } - } - } - } - AdvanceResult::AdvanceEof => { - break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } - } +match bp { + Some(bps) => { if (bps.left.clone() < min_bp.clone()) { + break Rc::new(ExprResult { + expr: lhs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { + match (*advance(&tokens)).clone() { + AdvanceResult::AdvanceOk { token: op_tok, tokens: rest, .. } => { let op_shape = op_tok.shape.clone(); +if is_dot_shape(op_shape.clone()) { + let r = expect_name(&rest); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: lhs.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - } - None => { - break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } - } - } - } - } - } +let new_lhs = make_named_expr_node(&r.name.clone(), Rc::new(ExprData::ExprFieldAccess { + summary: None, +}), Rc::new(vec![lhs.clone()]), None, loop_span, r.span.clone()); +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = new_lhs; +tokens = __tco_0; +lhs = __tco_1; +continue; +} +} else { + if is_pipe_arrow_shape(op_shape.clone()) { + let r = parse_pipe_rhs(&rest, &ctx, lhs.clone(), loop_span); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = r.expr.clone(); +tokens = __tco_0; +ctx = __tco_1; +lhs = __tco_2; +continue; +} +} else { + tokens = skip_newlines(rest.clone()); +let r = parse_expr_bp(tokens.clone(), ctx.clone(), bps.right.clone()); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let binop_opt = find_operator_binop(dag_syntax_spec().operators.clone(), op_tok.text.clone()); +match binop_opt { + Some(binop) => { let new_lhs = make_expr_node(Rc::new(ExprData::ExprBinOp { + op: binop.clone(), + algebra_field: None, +}), Rc::new(vec![lhs.clone(), r.expr.clone()]), None, loop_span); +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = new_lhs; +tokens = __tco_0; +ctx = __tco_1; +lhs = __tco_2; +continue; +} }, + None => { break Rc::new(ExprResult { + expr: lhs.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: Some(parse_error(v2_rt::concat("unknown binary operator: ".to_string(), op_tok.text.clone()), loop_span)), +}); }, +} +} +} }, + AdvanceResult::AdvanceEof => { break Rc::new(ExprResult { + expr: lhs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); }, +} +} }, + None => { break Rc::new(ExprResult { + expr: lhs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); }, +} +} +} +} +} } pub fn find_operator_bp(ops: Rc>>, symbol: String) -> Option { { - let matching = Rc::new({ - let mut __result = Vec::new(); - for op in ops.iter().cloned() { - if (op.symbol.clone().as_str() == symbol.clone().as_str()) { - __result.push(op); - } - } - __result - }); - if ((matching.clone().len() as i64) > 0) { + let matching = Rc::new({ let mut __result = Vec::new(); for op in ops.iter().cloned() { if (op.symbol.clone().as_str() == symbol.clone().as_str()) { __result.push(op); } } __result }); +if ((matching.clone().len() as i64) > 0) { { let op = matching.clone().first().cloned().clone().unwrap(); - Some(BindingPower { - left: op.left_bp.clone(), - right: op.right_bp.clone(), - }) - } +Some(BindingPower { + left: op.left_bp.clone(), + right: op.right_bp.clone(), +}) +} } else { None } - } +} } pub fn infix_bp(tokens: Rc>>) -> Option { match tokens.first().cloned() { - Some(t) => find_operator_bp(dag_syntax_spec().operators.clone(), t.text.clone()), - None => None, - } + Some(t) => find_operator_bp(dag_syntax_spec().operators.clone(), t.text.clone()), + None => None, +} } pub fn find_operator_binop(ops: Rc>>, symbol: String) -> Option { { - let matching = Rc::new({ - let mut __result = Vec::new(); - for op in ops.iter().cloned() { - if (op.symbol.clone().as_str() == symbol.clone().as_str()) { - __result.push(op); - } - } - __result - }); - if ((matching.clone().len() as i64) > 0) { - matching - .clone() - .first() - .cloned() - .clone() - .unwrap() - .binop - .clone() + let matching = Rc::new({ let mut __result = Vec::new(); for op in ops.iter().cloned() { if (op.symbol.clone().as_str() == symbol.clone().as_str()) { __result.push(op); } } __result }); +if ((matching.clone().len() as i64) > 0) { + matching.clone().first().cloned().clone().unwrap().binop.clone() } else { None } - } +} } -pub fn parse_pipe_rhs( - tokens: &Rc>>, - ctx: &Rc, - receiver: Rc, - span: Rc, -) -> Rc { +pub fn parse_pipe_rhs(tokens: &Rc>>, ctx: &Rc, receiver: Rc, span: Rc) -> Rc { { let dummy_expr = parse_recovery_placeholder(); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let method = r.name.clone(); - let tokens = skip_newlines(r.tokens.clone()); - if tok_is_lparen(tokens.clone().first().cloned()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let method = r.name.clone(); +let tokens = skip_newlines(r.tokens.clone()); +if tok_is_lparen(tokens.clone().first().cloned()) { { let r2 = parse_call_args(&tokens, &ctx); - if has_err(r2.err.clone()) { +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - Rc::new(ExprResult { - expr: make_named_expr_node( - &method, - Rc::new(ExprData::ExprMethodCall { - method_semantics: None, - }), - v2_rt::concat( - Rc::new(vec![receiver]), - Rc::new({ - let mut __result = Vec::new(); - for na in r2.args.clone().iter().cloned() { - __result.push(make_arg_node( - arg_name_at(na.clone(), ctx.source_indices.clone()), - arg_value(&na), - na.span.clone(), - node_name_span(&na), - )); - } - __result - }), - ), - None, - span, - r.span.clone(), - ), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +Rc::new(ExprResult { + expr: make_named_expr_node(&method, Rc::new(ExprData::ExprMethodCall { + method_semantics: None, +}), v2_rt::concat(Rc::new(vec![receiver]), Rc::new({ let mut __result = Vec::new(); for na in r2.args.clone().iter().cloned() { __result.push(make_arg_node(arg_name_at(na.clone(), ctx.source_indices.clone()), arg_value(&na), na.span.clone(), node_name_span(&na))); } __result })), None, span, r.span.clone()), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +} } else { Rc::new(ExprResult { - expr: make_named_expr_node( - &method, - Rc::new(ExprData::ExprMethodCall { - method_semantics: None, - }), - Rc::new(vec![receiver]), - None, - span, - r.span.clone(), - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + expr: make_named_expr_node(&method, Rc::new(ExprData::ExprMethodCall { + method_semantics: None, +}), Rc::new(vec![receiver]), None, span, r.span.clone()), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } - } +} } pub fn parse_prefix(tokens: &Rc>>, ctx: Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let span = token_span(tok.clone()); - match sh { - Some(TokenShape::ShBang) => { - let r = parse_expr_bp( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx, - 12, - ); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprUnaryOp { - op: UnaryOpKind::Not, - }), - Rc::new(vec![r.expr.clone()]), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - Some(TokenShape::ShMinus) => { - let r = parse_expr_bp( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx, - 12, - ); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprUnaryOp { - op: UnaryOpKind::Neg, - }), - Rc::new(vec![r.expr.clone()]), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - _ => parse_primary(&tokens, &ctx), - } - } +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +let span = token_span(tok.clone()); +match sh { + Some(TokenShape::ShBang) => { + let r = parse_expr_bp(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx, 12); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprUnaryOp { + op: UnaryOpKind::Not, +}), Rc::new(vec![r.expr.clone()]), None, span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +}, + Some(TokenShape::ShMinus) => { + let r = parse_expr_bp(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx, 12); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprUnaryOp { + op: UnaryOpKind::Neg, +}), Rc::new(vec![r.expr.clone()]), None, span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +}, + _ => parse_primary(&tokens, &ctx), +} +} } pub fn parse_primary(tokens: &Rc>>, ctx: &Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let span = token_span(tok.clone()); - match sh.clone() { - Some(TokenShape::ShKeyword) => { - let kw_text = tok.clone().unwrap().text.clone(); - let lit_val = - v2_rt::lookup(&dag_syntax_spec().keyword_literals.clone(), kw_text.clone()); - match lit_val { - Some(lv) => Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { value: lv.clone() }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }), - None => { - if (kw_text.clone().as_str() == "match".to_string().as_str()) { - parse_match(&tokens, &ctx) +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +let span = token_span(tok.clone()); +match sh.clone() { + Some(TokenShape::ShKeyword) => { + let kw_text = tok.clone().unwrap().text.clone(); +let lit_val = v2_rt::lookup(&dag_syntax_spec().keyword_literals.clone(), kw_text.clone()); +match lit_val { + Some(lv) => Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: lv.clone(), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}), + None => if (kw_text.clone().as_str() == "match".to_string().as_str()) { + parse_match(&tokens, &ctx) + } else { + if (kw_text.clone().as_str() == "if".to_string().as_str()) { + parse_if(&tokens, &ctx) + } else { + if (kw_text.clone().as_str() == "for".to_string().as_str()) { + parse_for(&tokens, &ctx) + } else { + if (kw_text.clone().as_str() == "let".to_string().as_str()) { + parse_let(&tokens, &ctx) } else { - if (kw_text.clone().as_str() == "if".to_string().as_str()) { - parse_if(&tokens, &ctx) + if (kw_text.clone().as_str() == "return".to_string().as_str()) { + parse_return(&tokens, &ctx) } else { - if (kw_text.clone().as_str() == "for".to_string().as_str()) { - parse_for(&tokens, &ctx) + if (kw_text.clone().as_str() == "fn".to_string().as_str()) { + parse_fn_lambda(&tokens, &ctx) } else { - if (kw_text.clone().as_str() == "let".to_string().as_str()) { - parse_let(&tokens, &ctx) - } else { - if (kw_text.clone().as_str() - == "return".to_string().as_str()) - { - parse_return(&tokens, &ctx) - } else { - if (kw_text.clone().as_str() - == "fn".to_string().as_str()) - { - parse_fn_lambda(&tokens, &ctx) - } else { - { - let kw_name = tok_keyword_to_name(tok.clone()); - match kw_name { + { + let kw_name = tok_keyword_to_name(tok.clone()); +match kw_name { Some(n) => parse_ident_expr(&tokens, ctx.clone(), &n), None => Rc::new(ExprResult { expr: parse_recovery_expr(span.clone(), format!("expected expression, found keyword '{}'", kw_text.clone())), @@ -10667,519 +8704,389 @@ pub fn parse_primary(tokens: &Rc>>, ctx: &Rc) -> Rc< err: Some(parse_error(format!("expected expression, found keyword '{}'", kw_text.clone()), span.clone())), }), } - } - } - } - } +} } } } } } - } - Some(TokenShape::ShLitInt) => { - let n_opt = v2_rt::parse_int(tok.clone().unwrap().text.clone()); - let n = match n_opt { - Some(v) => v.clone(), - None => { - return Rc::new(ExprResult { - expr: make_expr_error_node( - ExprErrorKind::InternalExprError, - &v2_rt::concat( - v2_rt::concat( - "internal: ShLitInt token text not parseable as int: '" - .to_string(), - tok.clone().unwrap().text.clone(), - ), - "'".to_string(), - ), - &span, - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - }; - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitInt { value: n.clone() }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } - Some(TokenShape::ShLitFloat) => { - let f = tok.clone().unwrap().text.clone(); - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitFloat { value: f }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } - Some(TokenShape::ShLitStr) => { - let s = tok.clone().unwrap().text.clone(); - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { value: s }), - }), - Rc::new(vec![]), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } - Some(TokenShape::ShStrBegin) => parse_string_interp(&tokens, ctx.clone()), - Some(TokenShape::ShIdent) => { - let n = tok.clone().unwrap().text.clone(); - parse_ident_expr(&tokens, ctx.clone(), &n) - } - Some(TokenShape::ShLParen) => parse_paren_expr(&tokens, &ctx), - Some(TokenShape::ShLBracket) => parse_list_literal(&tokens, &ctx), - Some(TokenShape::ShLBrace) => parse_brace_expr(&tokens, ctx.clone()), - _ => { - let tag = match sh.clone() { - Some(shape) => shape_display_name(shape.clone()), - None => "EOF".to_string(), - }; - Rc::new(ExprResult { - expr: parse_recovery_expr( - span.clone(), - format!("expected expression, found {}", tag.clone()), - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - format!("expected expression, found {}", tag.clone()), - span.clone(), - )), - }) - } - } - } + }, +} +}, + Some(TokenShape::ShLitInt) => { + let n_opt = v2_rt::parse_int(tok.clone().unwrap().text.clone()); +let n = match n_opt { + Some(v) => v.clone(), + None => return Rc::new(ExprResult { + expr: make_expr_error_node(ExprErrorKind::InternalExprError, &v2_rt::concat(v2_rt::concat("internal: ShLitInt token text not parseable as int: '".to_string(), tok.clone().unwrap().text.clone()), "'".to_string()), &span), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +}; +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitInt { + value: n.clone(), +}), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) +}, + Some(TokenShape::ShLitFloat) => { + let f = tok.clone().unwrap().text.clone(); +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitFloat { + value: f, +}), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) +}, + Some(TokenShape::ShLitStr) => { + let s = tok.clone().unwrap().text.clone(); +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: s, +}), +}), Rc::new(vec![]), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) +}, + Some(TokenShape::ShStrBegin) => parse_string_interp(&tokens, ctx.clone()), + Some(TokenShape::ShIdent) => { + let n = tok.clone().unwrap().text.clone(); +parse_ident_expr(&tokens, ctx.clone(), &n) +}, + Some(TokenShape::ShLParen) => parse_paren_expr(&tokens, &ctx), + Some(TokenShape::ShLBracket) => parse_list_literal(&tokens, &ctx), + Some(TokenShape::ShLBrace) => parse_brace_expr(&tokens, ctx.clone()), + _ => { + let tag = match sh.clone() { + Some(shape) => shape_display_name(shape.clone()), + None => "EOF".to_string(), +}; +Rc::new(ExprResult { + expr: parse_recovery_expr(span.clone(), format!("expected expression, found {}", tag.clone())), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error(format!("expected expression, found {}", tag.clone()), span.clone())), +}) +}, +} +} } pub fn parse_lambda_body(tokens: &Rc>>, ctx: Rc) -> Rc { { let tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - let is_block = (tok_is_keyword(tok.clone(), "let".to_string()) - || tok_is_keyword(tok.clone(), "return".to_string())); - if is_block { +let tok = tokens.clone().first().cloned(); +let is_block = (tok_is_keyword(tok.clone(), "let".to_string()) || tok_is_keyword(tok.clone(), "return".to_string())); +if is_block { { let r = parse_lambda_stmts(tokens.clone(), ctx, Rc::new(vec![])); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: parse_recovery_placeholder(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let span = token_span(tokens.clone().first().cloned()); - if ((r.stmts.clone().len() as i64) == 1) { + expr: parse_recovery_placeholder(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let span = token_span(tokens.clone().first().cloned()); +if ((r.stmts.clone().len() as i64) == 1) { Rc::new(ExprResult { - expr: r.stmts.clone().first().cloned().clone().unwrap(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) + expr: r.stmts.clone().first().cloned().clone().unwrap(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) } else { Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprBlock), - r.stmts.clone(), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) + expr: make_expr_node(Rc::new(ExprData::ExprBlock), r.stmts.clone(), None, span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) } - } +} } else { parse_expr(tokens.clone(), ctx) } - } +} } -pub fn parse_lambda_stmts( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_lambda_stmts(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - if ((tok_is_rparen(tok.clone()) || tok_is_rbrace(tok.clone())) || tok_is_eof(tok.clone())) { +let tok = tokens.clone().first().cloned(); +if ((tok_is_rparen(tok.clone()) || tok_is_rbrace(tok.clone())) || tok_is_eof(tok.clone())) { break Rc::new(StmtsResult { - stmts: acc.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + stmts: acc.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { let r = parse_stmt(&tokens, ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(StmtsResult { - stmts: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + stmts: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - { +{ let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(acc, r.expr.clone()); - tokens = __tco_0; - ctx = __tco_1; - acc = __tco_2; - continue; - } - } - } +let __tco_1 = r.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(acc, r.expr.clone()); +tokens = __tco_0; +ctx = __tco_1; +acc = __tco_2; +continue; +} +} +} } -pub fn parse_ident_expr( - tokens: &Rc>>, - ctx: Rc, - name: &String, -) -> Rc { +pub fn parse_ident_expr(tokens: &Rc>>, ctx: Rc, name: &String) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let tokens = Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - if tok_is_fat_arrow(tokens.clone().first().cloned()) { +let tokens = Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()); +if tok_is_fat_arrow(tokens.clone().first().cloned()) { { - let r = parse_lambda_body( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx, - ); - if has_err(r.err.clone()) { - return r.clone(); + let r = parse_lambda_body(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx); +if has_err(r.err.clone()) { + return r.clone() } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLambda), - v2_rt::concat( - Rc::new(vec![r.expr.clone()]), - Rc::new(vec![parsed_name_leaf(name.clone(), span.clone())]), - ), - None, - span.clone(), - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLambda), v2_rt::concat(Rc::new(vec![r.expr.clone()]), Rc::new(vec![parsed_name_leaf(name.clone(), span.clone())])), None, span.clone()), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { - if (is_uppercase_start(name.clone()) && tok_is_lbrace(tokens.clone().first().cloned())) - { + if (is_uppercase_start(name.clone()) && tok_is_lbrace(tokens.clone().first().cloned())) { parse_record_literal(&tokens, &ctx, name.clone(), &span) } else { Rc::new(ExprResult { - expr: make_named_expr_node( - &name, - Rc::new(ExprData::ExprVar { binding_kind: None }), - Rc::new(vec![]), - None, - span.clone(), - span.clone(), - ), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) + expr: make_named_expr_node(&name, Rc::new(ExprData::ExprVar { + binding_kind: None, +}), Rc::new(vec![]), None, span.clone(), span.clone()), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) } } - } +} } pub fn is_uppercase_start(name: String) -> bool { { let ch = v2_rt::char_at(&name, 0); - ((ch.clone() >= "A".to_string()) && (ch.clone() <= "Z".to_string())) - } +((ch.clone() >= "A".to_string()) && (ch.clone() <= "Z".to_string())) +} } -pub fn try_postfix( - tokens: &Rc>>, - ctx: &Rc, - lhs: &Rc, - min_bp: i64, -) -> Rc { +pub fn try_postfix(tokens: &Rc>>, ctx: &Rc, lhs: &Rc, min_bp: i64) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let span = token_span(tok.clone()); - match sh { - Some(TokenShape::ShLParen) => { - if (14 < min_bp) { - Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } else { - { - let r = parse_call_args(&tokens, &ctx); - if has_err(r.err.clone()) { - return Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let call_expr = - make_call_expr(&lhs, r.args.clone(), span, ctx.source_indices.clone()); - Rc::new(PostfixResult { - expr: call_expr, - changed: true, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +let span = token_span(tok.clone()); +match sh { + Some(TokenShape::ShLParen) => if (14 < min_bp) { + Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) + } else { + { + let r = parse_call_args(&tokens, &ctx); +if has_err(r.err.clone()) { + return Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let call_expr = make_call_expr(&lhs, r.args.clone(), span, ctx.source_indices.clone()); +Rc::new(PostfixResult { + expr: call_expr, + changed: true, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} + }, + Some(TokenShape::ShIdent) => if (tok.clone().unwrap().text.clone().as_str() == "as".to_string().as_str()) { + if (13 < min_bp) { + Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) + } else { + { + let r = parse_type_expr(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &ctx); +if has_err(r.err.clone()) { + return Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - } +Rc::new(PostfixResult { + expr: make_expr_node(Rc::new(ExprData::ExprCast), Rc::new(vec![lhs.clone(), r.type_expr.clone()]), None, span), + changed: true, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } - Some(TokenShape::ShIdent) => { - if (tok.clone().unwrap().text.clone().as_str() == "as".to_string().as_str()) { - if (13 < min_bp) { - Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } else { - { - let r = parse_type_expr( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &ctx, - ); - if has_err(r.err.clone()) { - return Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - Rc::new(PostfixResult { - expr: make_expr_node( - Rc::new(ExprData::ExprCast), - Rc::new(vec![lhs.clone(), r.type_expr.clone()]), - None, - span, - ), - changed: true, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + } else { + Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) + }, + Some(TokenShape::ShLBracket) => if (14 < min_bp) { + Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) + } else { + if is_constraint_bracket(tokens.clone()) { + Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) + } else { + { + let r = parse_index_or_slice(&tokens, &ctx, lhs.clone(), span); +if has_err(r.err.clone()) { + return Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - } else { - Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } +Rc::new(PostfixResult { + expr: r.expr.clone(), + changed: true, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } - Some(TokenShape::ShLBracket) => { - if (14 < min_bp) { - Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } else { - if is_constraint_bracket(tokens.clone()) { - Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } else { - { - let r = parse_index_or_slice(&tokens, &ctx, lhs.clone(), span); - if has_err(r.err.clone()) { - return Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - Rc::new(PostfixResult { - expr: r.expr.clone(), - changed: true, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) + }, + Some(TokenShape::ShLBrace) => match (*lhs.expr_data.clone()).clone() { + ExprData::ExprVar { .. } => { + let n = expr_var_name_at(lhs.clone(), ctx.source_indices.clone()); +if (is_uppercase_start(n.clone()) && (14 <= min_bp)) { + Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) + } else { + if is_uppercase_start(n.clone()) { + { + let r = parse_record_literal(&tokens, &ctx, n.clone(), &lhs.span.clone()); +if has_err(r.err.clone()) { + return Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - } +Rc::new(PostfixResult { + expr: r.expr.clone(), + changed: true, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} + } else { + Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } } - Some(TokenShape::ShLBrace) => match (*lhs.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => { - let n = expr_var_name_at(lhs.clone(), ctx.source_indices.clone()); - if (is_uppercase_start(n.clone()) && (14 <= min_bp)) { - Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } else { - if is_uppercase_start(n.clone()) { - { - let r = parse_record_literal( - &tokens, - &ctx, - n.clone(), - &lhs.span.clone(), - ); - if has_err(r.err.clone()) { - return Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - Rc::new(PostfixResult { - expr: r.expr.clone(), - changed: true, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - } else { - Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } - } - } - _ => Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }), - }, - _ => Rc::new(PostfixResult { - expr: lhs.clone(), - changed: false, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }), - } - } +}, + _ => Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +}, + _ => Rc::new(PostfixResult { + expr: lhs.clone(), + changed: false, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +} +} } pub fn is_constraint_bracket(tokens: Rc>>) -> bool { match tokens.get(1 as usize).cloned() { - Some(t) => { - if is_ident_shape(t.shape.clone()) { - ((t.text.clone().as_str() == "after".to_string().as_str()) - || (t.text.clone().as_str() == "when".to_string().as_str())) - } else { - false - } - } - None => false, - } + Some(t) => if is_ident_shape(t.shape.clone()) { + ((t.text.clone().as_str() == "after".to_string().as_str()) || (t.text.clone().as_str() == "when".to_string().as_str())) + } else { + false + }, + None => false, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -11190,2964 +9097,2240 @@ pub struct ConstraintsResult { pub err: Option>, } -pub fn parse_constraint_annotations( - tokens: &Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_constraint_annotations(tokens: &Rc>>, ctx: Rc) -> Rc { match (*eat(&tokens, Rc::new(ExpectedToken::ExpectLBracket))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r = parse_constraint_list(__ec.clone(), ctx, Rc::new(vec![])); - if has_err(r.err.clone()) { - return r.clone(); - } - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBracket)); - if has_err(r2.err.clone()) { - return Rc::new(ConstraintsResult { - constraints: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - Rc::new(ConstraintsResult { - constraints: r.constraints.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } - EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(ConstraintsResult { - constraints: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }), - } + EatResult::EatConsumed { tokens: __ec, .. } => { + let r = parse_constraint_list(__ec.clone(), ctx, Rc::new(vec![])); +if has_err(r.err.clone()) { + return r.clone() + } +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBracket)); +if has_err(r2.err.clone()) { + return Rc::new(ConstraintsResult { + constraints: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +Rc::new(ConstraintsResult { + constraints: r.constraints.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +}, + EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(ConstraintsResult { + constraints: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}), +} } -pub fn parse_constraint_list( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_constraint_list(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let tok = tokens.clone().first().cloned(); - let is_constraint_kw = match tok.clone() { - Some(t) => { - (is_ident_shape(t.shape.clone()) - && ((t.text.clone().as_str() == "after".to_string().as_str()) - || (t.text.clone().as_str() == "when".to_string().as_str()))) - } - None => false, - }; - if !is_constraint_kw { - return Rc::new(ConstraintsResult { - constraints: acc.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } - let kw_name = tok.clone().unwrap().text.clone(); - let r = parse_expr( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx.clone(), - ); - if has_err(r.err.clone()) { +let tok = tokens.clone().first().cloned(); +let is_constraint_kw = match tok.clone() { + Some(t) => (is_ident_shape(t.shape.clone()) && ((t.text.clone().as_str() == "after".to_string().as_str()) || (t.text.clone().as_str() == "when".to_string().as_str()))), + None => false, +}; +if !is_constraint_kw { return Rc::new(ConstraintsResult { - constraints: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let fi = make_field_init_node(&kw_name, r.expr.clone(), make_span(0, 0), make_span(0, 0)); - acc = v2_rt::rc_list_push(acc.clone(), fi); - match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let __tco_0 = __ec.clone(); - let __tco_1 = r.ctx.clone(); - tokens = __tco_0; - ctx = __tco_1; - continue; - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(ConstraintsResult { - constraints: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } + constraints: acc.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } - } -} - -pub fn try_constraint_annotations( - tokens: &Rc>>, - ctx: Rc, -) -> Rc { +let kw_name = tok.clone().unwrap().text.clone(); +let r = parse_expr(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx.clone()); +if has_err(r.err.clone()) { + return Rc::new(ConstraintsResult { + constraints: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let fi = make_field_init_node(&kw_name, r.expr.clone(), make_span(0, 0), make_span(0, 0)); +acc = v2_rt::rc_list_push(acc.clone(), fi); +match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { { + let __tco_0 = __ec.clone(); +let __tco_1 = r.ctx.clone(); +tokens = __tco_0; +ctx = __tco_1; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(ConstraintsResult { + constraints: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); }, +} +} +} + +pub fn try_constraint_annotations(tokens: &Rc>>, ctx: Rc) -> Rc { if is_constraint_bracket(tokens.clone()) { parse_constraint_annotations(&tokens, ctx) } else { Rc::new(ConstraintsResult { - constraints: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) + constraints: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) } } -pub fn make_call_expr( - lhs: &Rc, - args: Rc>>, - span: Rc, - source_indices: Rc>>, -) -> Rc { +pub fn make_call_expr(lhs: &Rc, args: Rc>>, span: Rc, source_indices: Rc>>) -> Rc { match (*lhs.expr_data.clone()).clone() { - ExprData::ExprVar { .. } => make_named_expr_node( - &expr_var_name_at(lhs.clone(), source_indices), - Rc::new(ExprData::ExprCall { - call_semantics: None, - descent_evidence: None, - }), - args, - None, - lhs.span.clone(), - node_name_span(&lhs), - ), - ExprData::ExprFieldAccess { .. } => make_named_expr_node( - &field_access_field_at(lhs.clone(), source_indices), - Rc::new(ExprData::ExprMethodCall { - method_semantics: None, - }), - v2_rt::concat( - Rc::new(vec![lhs.children.clone().first().cloned().clone().unwrap()]), - args, - ), - None, - lhs.span.clone(), - node_name_span(&lhs), - ), - _ => make_named_expr_node( - &"".to_string(), - Rc::new(ExprData::ExprCall { - call_semantics: None, - descent_evidence: None, - }), - args, - None, - lhs.span.clone(), - no_span(), - ), - } + ExprData::ExprVar { .. } => make_named_expr_node(&expr_var_name_at(lhs.clone(), source_indices), Rc::new(ExprData::ExprCall { + call_semantics: None, + descent_evidence: None, +}), args, None, lhs.span.clone(), node_name_span(&lhs)), + ExprData::ExprFieldAccess { .. } => make_named_expr_node(&field_access_field_at(lhs.clone(), source_indices), Rc::new(ExprData::ExprMethodCall { + method_semantics: None, +}), v2_rt::concat(Rc::new(vec![lhs.children.clone().first().cloned().clone().unwrap()]), args), None, lhs.span.clone(), node_name_span(&lhs)), + _ => make_named_expr_node(&"".to_string(), Rc::new(ExprData::ExprCall { + call_semantics: None, + descent_evidence: None, +}), args, None, lhs.span.clone(), no_span()), +} } -pub fn parse_index_or_slice( - tokens: &Rc>>, - ctx: &Rc, - base: Rc, - span: Rc, -) -> Rc { +pub fn parse_index_or_slice(tokens: &Rc>>, ctx: &Rc, base: Rc, span: Rc) -> Rc { { let dummy_expr = parse_recovery_placeholder(); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBracket)); - if has_err(r.err.clone()) { +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBracket)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_expr(r.tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_expr(r.tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let first_expr = r.expr.clone(); - let tokens = r.tokens.clone(); - let ctx = r.ctx.clone(); - if tok_is_dot_dot(tokens.clone().first().cloned()) { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let first_expr = r.expr.clone(); +let tokens = r.tokens.clone(); +let ctx = r.ctx.clone(); +if tok_is_dot_dot(tokens.clone().first().cloned()) { { - let r = parse_expr( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx.clone(), - ); - if has_err(r.err.clone()) { + let r = parse_expr(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let end_expr = r.expr.clone(); - let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBracket)); - if has_err(r.err.clone()) { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let end_expr = r.expr.clone(); +let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectRBracket)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprSlice), - Rc::new(vec![base, first_expr, end_expr]), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprSlice), Rc::new(vec![base, first_expr, end_expr]), None, span), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +} } else { { let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBracket)); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprIndex), - Rc::new(vec![base, first_expr]), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprIndex), Rc::new(vec![base, first_expr]), None, span), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +} } - } +} } pub fn parse_call_args(tokens: &Rc>>, ctx: &Rc) -> Rc { { let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ArgsResult { - args: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + args: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let tokens = skip_newlines(r.tokens.clone()); - if tok_is_rparen(tokens.clone().first().cloned()) { +let tokens = skip_newlines(r.tokens.clone()); +if tok_is_rparen(tokens.clone().first().cloned()) { Rc::new(ArgsResult { - args: Rc::new(vec![]), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) + args: Rc::new(vec![]), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) } else { { let r = parse_arg_list(tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { - return r.clone(); +if has_err(r.err.clone()) { + return r.clone() } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r2.err.clone()) { +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r2.err.clone()) { return Rc::new(ArgsResult { - args: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); + args: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) } - Rc::new(ArgsResult { - args: r.args.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +Rc::new(ArgsResult { + args: r.args.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } - } +} } pub fn parse_arg_list(tokens: Rc>>, ctx: Rc) -> Rc { parse_arg_list_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_arg_list_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_arg_list_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let r = parse_single_arg(&tokens, ctx); - if has_err(r.err.clone()) { +let r = parse_single_arg(&tokens, ctx); +if has_err(r.err.clone()) { return Rc::new(ArgsResult { - args: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - acc = v2_rt::rc_list_push(acc.clone(), r.arg.clone()); - match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - tokens = skip_newlines(__ec.clone()); - if tok_is_rparen(tokens.clone().first().cloned()) { - break Rc::new(ArgsResult { - args: acc.clone(), - tokens: tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } else { - { - let __tco_0 = r.ctx.clone(); - ctx = __tco_0; - continue; - } - } - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(ArgsResult { - args: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }); - } - } - } + args: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +acc = v2_rt::rc_list_push(acc.clone(), r.arg.clone()); +match (*eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { tokens = skip_newlines(__ec.clone()); +if tok_is_rparen(tokens.clone().first().cloned()) { + break Rc::new(ArgsResult { + args: acc.clone(), + tokens: tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); +} else { + { + let __tco_0 = r.ctx.clone(); +ctx = __tco_0; +continue; +} +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(ArgsResult { + args: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}); }, +} +} } pub fn parse_single_arg(tokens: &Rc>>, ctx: Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_arg = make_arg_node( - None, - parse_recovery_placeholder(), - span.clone(), - span.clone(), - ); - let tok = tokens.clone().first().cloned(); - let is_name_token = (tok_is_ident(tok.clone()) || tok_is_keyword_name(tok.clone())); - if is_name_token { +let dummy_arg = make_arg_node(None, parse_recovery_placeholder(), span.clone(), span.clone()); +let tok = tokens.clone().first().cloned(); +let is_name_token = (tok_is_ident(tok.clone()) || tok_is_keyword_name(tok.clone())); +if is_name_token { { let name_r = expect_name(&tokens); - if has_err(name_r.err.clone()) { +if has_err(name_r.err.clone()) { { let r = parse_expr(tokens.clone(), ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ArgResult { - arg: dummy_arg, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + arg: dummy_arg, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let arg = make_arg_node(None, r.expr.clone(), span.clone(), span.clone()); - Rc::new(ArgResult { - arg: arg, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let arg = make_arg_node(None, r.expr.clone(), span.clone(), span.clone()); +Rc::new(ArgResult { + arg: arg, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { if tok_is_colon(name_r.tokens.clone().first().cloned()) { { - let r = parse_expr( - Rc::new( - name_r - .tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx, - ); - if has_err(r.err.clone()) { + let r = parse_expr(Rc::new(name_r.tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx); +if has_err(r.err.clone()) { return Rc::new(ArgResult { - arg: dummy_arg, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + arg: dummy_arg, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let arg = make_arg_node( - Some(name_r.name.clone()), - r.expr.clone(), - span.clone(), - name_r.span.clone(), - ); - Rc::new(ArgResult { - arg: arg, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let arg = make_arg_node(Some(name_r.name.clone()), r.expr.clone(), span.clone(), name_r.span.clone()); +Rc::new(ArgResult { + arg: arg, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { { let r = parse_expr(tokens.clone(), ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ArgResult { - arg: dummy_arg, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + arg: dummy_arg, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let arg = - make_arg_node(None, r.expr.clone(), span.clone(), span.clone()); - Rc::new(ArgResult { - arg: arg, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let arg = make_arg_node(None, r.expr.clone(), span.clone(), span.clone()); +Rc::new(ArgResult { + arg: arg, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } } - } +} } else { { let r = parse_expr(tokens.clone(), ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ArgResult { - arg: dummy_arg, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + arg: dummy_arg, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let arg = make_arg_node(None, r.expr.clone(), span.clone(), span.clone()); - Rc::new(ArgResult { - arg: arg, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let arg = make_arg_node(None, r.expr.clone(), span.clone(), span.clone()); +Rc::new(ArgResult { + arg: arg, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } - } +} } pub fn parse_match(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "match".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "match".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_expr_no_brace(r.tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { - return r.clone(); - } - let scrutinee = r.expr.clone(); - let r = expect( - &skip_newlines(r.tokens.clone()), - &Rc::new(ExpectedToken::ExpectLBrace), - ); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_expr_no_brace(r.tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { + return r.clone() + } +let scrutinee = r.expr.clone(); +let r = expect(&skip_newlines(r.tokens.clone()), &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_match_arms(skip_newlines(r.tokens.clone()), ctx.clone()); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_match_arms(skip_newlines(r.tokens.clone()), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let arms = r.arms.clone(); - let r = expect( - &skip_newlines(r.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let arms = r.arms.clone(); +let r = expect(&skip_newlines(r.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprMatch), - v2_rt::concat(Rc::new(vec![scrutinee]), arms), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprMatch), v2_rt::concat(Rc::new(vec![scrutinee]), arms), None, span), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +} } pub fn parse_expr_no_brace(tokens: Rc>>, ctx: Rc) -> Rc { parse_expr_bp_no_brace(tokens, ctx, 0) } -pub fn parse_expr_bp_no_brace( - tokens: Rc>>, - ctx: Rc, - min_bp: i64, -) -> Rc { +pub fn parse_expr_bp_no_brace(tokens: Rc>>, ctx: Rc, min_bp: i64) -> Rc { { let r = parse_prefix(&tokens, ctx); - if has_err(r.err.clone()) { - return r.clone(); +if has_err(r.err.clone()) { + return r.clone() } - let lhs = r.expr.clone(); - parse_expr_loop_no_brace(r.tokens.clone(), r.ctx.clone(), lhs, min_bp) - } +let lhs = r.expr.clone(); +parse_expr_loop_no_brace(r.tokens.clone(), r.ctx.clone(), lhs, min_bp) +} } -pub fn parse_expr_loop_no_brace( - mut tokens: Rc>>, - mut ctx: Rc, - mut lhs: Rc, - mut min_bp: i64, -) -> Rc { +pub fn parse_expr_loop_no_brace(mut tokens: Rc>>, mut ctx: Rc, mut lhs: Rc, mut min_bp: i64) -> Rc { loop { let tok = tokens.clone().first().cloned(); - if (tok_is_eof(tok.clone()) || tok_is_lbrace(tok.clone())) { +if (tok_is_eof(tok.clone()) || tok_is_lbrace(tok.clone())) { break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + expr: lhs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let loop_span = token_span(tok.clone()); - tokens = skip_continuation_newlines(&tokens); - if (tok_is_lparen(tokens.clone().first().cloned()) && (14 >= min_bp.clone())) { +tokens = skip_continuation_newlines(&tokens); +if (tok_is_lparen(tokens.clone().first().cloned()) && (14 >= min_bp.clone())) { let r = parse_call_args(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: lhs.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let span = token_span(tokens.clone().first().cloned()); - let new_lhs = - make_call_expr(&lhs, r.args.clone(), span, ctx.source_indices.clone()); - { + expr: lhs.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let span = token_span(tokens.clone().first().cloned()); +let new_lhs = make_call_expr(&lhs, r.args.clone(), span, ctx.source_indices.clone()); +{ let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = new_lhs; - tokens = __tco_0; - ctx = __tco_1; - lhs = __tco_2; - continue; - } - } else { +let __tco_1 = r.ctx.clone(); +let __tco_2 = new_lhs; +tokens = __tco_0; +ctx = __tco_1; +lhs = __tco_2; +continue; +} +} else { if (tok_is_lbracket(tokens.clone().first().cloned()) && (14 >= min_bp.clone())) { let span = token_span(tokens.clone().first().cloned()); - let r = parse_index_or_slice(&tokens, &ctx, lhs.clone(), span); - if has_err(r.err.clone()) { +let r = parse_index_or_slice(&tokens, &ctx, lhs.clone(), span); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - { +{ let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = r.expr.clone(); - tokens = __tco_0; - ctx = __tco_1; - lhs = __tco_2; - continue; - } - } else { +let __tco_1 = r.ctx.clone(); +let __tco_2 = r.expr.clone(); +tokens = __tco_0; +ctx = __tco_1; +lhs = __tco_2; +continue; +} +} else { let bp = infix_bp(tokens.clone()); - match bp { - Some(bps) => { - if (bps.left.clone() < min_bp.clone()) { - break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { - match (*advance(&tokens)).clone() { - AdvanceResult::AdvanceOk { - token: op_tok, - tokens: rest, - .. - } => { - let op_shape = op_tok.shape.clone(); - if is_dot_shape(op_shape.clone()) { - let r = expect_name(&rest); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: lhs.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let new_lhs = make_named_expr_node( - &r.name.clone(), - Rc::new(ExprData::ExprFieldAccess { - summary: None, - }), - Rc::new(vec![lhs.clone()]), - None, - loop_span, - r.span.clone(), - ); - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = new_lhs; - tokens = __tco_0; - lhs = __tco_1; - continue; - } - } else { - if is_pipe_arrow_shape(op_shape.clone()) { - let r = parse_pipe_rhs( - &rest, - &ctx, - lhs.clone(), - loop_span, - ); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = r.expr.clone(); - tokens = __tco_0; - ctx = __tco_1; - lhs = __tco_2; - continue; - } - } else { - tokens = skip_newlines(rest.clone()); - let r = parse_expr_bp_no_brace( - tokens.clone(), - ctx.clone(), - bps.right.clone(), - ); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let binop_opt = find_operator_binop( - dag_syntax_spec().operators.clone(), - op_tok.text.clone(), - ); - match binop_opt { - Some(binop) => { - let new_lhs = make_expr_node( - Rc::new(ExprData::ExprBinOp { - op: binop.clone(), - algebra_field: None, - }), - Rc::new(vec![ - lhs.clone(), - r.expr.clone(), - ]), - None, - loop_span, - ); - { - let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = new_lhs; - tokens = __tco_0; - ctx = __tco_1; - lhs = __tco_2; - continue; - } - } - None => { - break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: Some(parse_error( - v2_rt::concat( - "unknown binary operator: " - .to_string(), - op_tok.text.clone(), - ), - loop_span, - )), - }); - } - } - } - } - } - AdvanceResult::AdvanceEof => { - break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } - } +match bp { + Some(bps) => { if (bps.left.clone() < min_bp.clone()) { + break Rc::new(ExprResult { + expr: lhs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { + match (*advance(&tokens)).clone() { + AdvanceResult::AdvanceOk { token: op_tok, tokens: rest, .. } => { let op_shape = op_tok.shape.clone(); +if is_dot_shape(op_shape.clone()) { + let r = expect_name(&rest); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: lhs.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - } - None => { - break Rc::new(ExprResult { - expr: lhs.clone(), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } - } - } - } - } - } +let new_lhs = make_named_expr_node(&r.name.clone(), Rc::new(ExprData::ExprFieldAccess { + summary: None, +}), Rc::new(vec![lhs.clone()]), None, loop_span, r.span.clone()); +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = new_lhs; +tokens = __tco_0; +lhs = __tco_1; +continue; +} +} else { + if is_pipe_arrow_shape(op_shape.clone()) { + let r = parse_pipe_rhs(&rest, &ctx, lhs.clone(), loop_span); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = r.expr.clone(); +tokens = __tco_0; +ctx = __tco_1; +lhs = __tco_2; +continue; +} +} else { + tokens = skip_newlines(rest.clone()); +let r = parse_expr_bp_no_brace(tokens.clone(), ctx.clone(), bps.right.clone()); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let binop_opt = find_operator_binop(dag_syntax_spec().operators.clone(), op_tok.text.clone()); +match binop_opt { + Some(binop) => { let new_lhs = make_expr_node(Rc::new(ExprData::ExprBinOp { + op: binop.clone(), + algebra_field: None, +}), Rc::new(vec![lhs.clone(), r.expr.clone()]), None, loop_span); +{ + let __tco_0 = r.tokens.clone(); +let __tco_1 = r.ctx.clone(); +let __tco_2 = new_lhs; +tokens = __tco_0; +ctx = __tco_1; +lhs = __tco_2; +continue; +} }, + None => { break Rc::new(ExprResult { + expr: lhs.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: Some(parse_error(v2_rt::concat("unknown binary operator: ".to_string(), op_tok.text.clone()), loop_span)), +}); }, +} +} +} }, + AdvanceResult::AdvanceEof => { break Rc::new(ExprResult { + expr: lhs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); }, +} +} }, + None => { break Rc::new(ExprResult { + expr: lhs.clone(), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); }, +} +} +} +} +} } pub fn parse_match_arms(tokens: Rc>>, ctx: Rc) -> Rc { parse_match_arms_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_match_arms_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_match_arms_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(ArmsResult { - arms: acc.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + arms: acc.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { let r = parse_match_arm(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ArmsResult { - arms: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let e = eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r.tokens.clone(), - }); - { + arms: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let e = eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r.tokens.clone(), +}); +{ let __tco_0 = r.ctx.clone(); - let __tco_1 = v2_rt::rc_list_push(acc, r.arm.clone()); - ctx = __tco_0; - acc = __tco_1; - continue; - } - } - } +let __tco_1 = v2_rt::rc_list_push(acc, r.arm.clone()); +ctx = __tco_0; +acc = __tco_1; +continue; +} +} +} } pub fn parse_match_arm(tokens: &Rc>>, ctx: &Rc) -> Rc { { let arm_span = token_span(tokens.clone().first().cloned()); - let dummy_arm = make_arm_node( - Rc::new(MatchPattern::Wildcard), - None, - parse_recovery_placeholder(), - make_span(0, 0), - ); - let r = parse_pattern(&tokens, &ctx); - if has_err(r.err.clone()) { +let dummy_arm = make_arm_node(Rc::new(MatchPattern::Wildcard), None, parse_recovery_placeholder(), make_span(0, 0)); +let r = parse_pattern(&tokens, &ctx); +if has_err(r.err.clone()) { return Rc::new(ArmResult { - arm: dummy_arm.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let pat = r.pattern.clone(); - let tokens = r.tokens.clone(); - let ctx = r.ctx.clone(); - let guard_r = parse_optional_guard(&tokens, ctx.clone()); - if has_err(guard_r.err.clone()) { + arm: dummy_arm.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let pat = r.pattern.clone(); +let tokens = r.tokens.clone(); +let ctx = r.ctx.clone(); +let guard_r = parse_optional_guard(&tokens, ctx.clone()); +if has_err(guard_r.err.clone()) { return Rc::new(ArmResult { - arm: dummy_arm.clone(), - tokens: guard_r.tokens.clone(), - ctx: guard_r.ctx.clone(), - err: guard_r.err.clone(), - }); - } - let guard = guard_r.guard.clone(); - let tokens = guard_r.tokens.clone(); - let ctx = guard_r.ctx.clone(); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectFatArrow)); - if has_err(r.err.clone()) { + arm: dummy_arm.clone(), + tokens: guard_r.tokens.clone(), + ctx: guard_r.ctx.clone(), + err: guard_r.err.clone(), +}) + } +let guard = guard_r.guard.clone(); +let tokens = guard_r.tokens.clone(); +let ctx = guard_r.ctx.clone(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectFatArrow)); +if has_err(r.err.clone()) { return Rc::new(ArmResult { - arm: dummy_arm.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r = if tok_is_lbrace(tokens.clone().first().cloned()) { + arm: dummy_arm.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r = if tok_is_lbrace(tokens.clone().first().cloned()) { parse_block(&tokens, &ctx) } else { parse_match_arm_body(&tokens, ctx.clone()) }; - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ArmResult { - arm: dummy_arm.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let arm = make_arm_node(pat, guard, r.expr.clone(), arm_span); - Rc::new(ArmResult { - arm: arm, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + arm: dummy_arm.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let arm = make_arm_node(pat, guard, r.expr.clone(), arm_span); +Rc::new(ArmResult { + arm: arm, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } pub fn parse_match_arm_body(tokens: &Rc>>, ctx: Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let is_block = (tok_is_keyword(tok.clone(), "let".to_string()) - || tok_is_keyword(tok.clone(), "return".to_string())); - if is_block { +let is_block = (tok_is_keyword(tok.clone(), "let".to_string()) || tok_is_keyword(tok.clone(), "return".to_string())); +if is_block { { let r = parse_match_arm_stmts(tokens.clone(), ctx, Rc::new(vec![])); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: parse_recovery_placeholder(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let span = token_span(tokens.clone().first().cloned()); - if ((r.stmts.clone().len() as i64) == 1) { + expr: parse_recovery_placeholder(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let span = token_span(tokens.clone().first().cloned()); +if ((r.stmts.clone().len() as i64) == 1) { Rc::new(ExprResult { - expr: r.stmts.clone().first().cloned().clone().unwrap(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) + expr: r.stmts.clone().first().cloned().clone().unwrap(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) } else { Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprBlock), - r.stmts.clone(), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) + expr: make_expr_node(Rc::new(ExprData::ExprBlock), r.stmts.clone(), None, span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) } - } +} } else { parse_expr(tokens.clone(), ctx) } - } +} } -pub fn parse_match_arm_stmts( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_match_arm_stmts(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(StmtsResult { - stmts: acc.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + stmts: acc.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { if looks_like_arm_start(&tokens) { break Rc::new(StmtsResult { - stmts: acc.clone(), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + stmts: acc.clone(), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { let r = parse_stmt(&tokens, ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(StmtsResult { - stmts: acc.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + stmts: acc.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - { +{ let __tco_0 = r.tokens.clone(); - let __tco_1 = r.ctx.clone(); - let __tco_2 = v2_rt::rc_list_push(acc, r.expr.clone()); - tokens = __tco_0; - ctx = __tco_1; - acc = __tco_2; - continue; - } - } - } - } +let __tco_1 = r.ctx.clone(); +let __tco_2 = v2_rt::rc_list_push(acc, r.expr.clone()); +tokens = __tco_0; +ctx = __tco_1; +acc = __tco_2; +continue; +} +} +} +} } pub fn looks_like_arm_start(tokens: &Rc>>) -> bool { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShIdent) => { - let n = tok.clone().unwrap().text.clone(); - if (n.clone().as_str() == "_".to_string().as_str()) { - peek_is_fat_arrow_at(tokens.clone(), 1) - } else { - if is_uppercase_start(n.clone()) { - if peek_is_fat_arrow_at(tokens.clone(), 1) { - true +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShIdent) => { + let n = tok.clone().unwrap().text.clone(); +if (n.clone().as_str() == "_".to_string().as_str()) { + peek_is_fat_arrow_at(tokens.clone(), 1) + } else { + if is_uppercase_start(n.clone()) { + if peek_is_fat_arrow_at(tokens.clone(), 1) { + true + } else { + if peek_is_expected_at(tokens.clone(), 1, Rc::new(ExpectedToken::ExpectLBrace)) { + scan_for_fat_arrow_after_braces(Rc::new(tokens.clone().iter().cloned().skip(2 as usize).collect::>()), 1) } else { - if peek_is_expected_at( - tokens.clone(), - 1, - Rc::new(ExpectedToken::ExpectLBrace), - ) { - scan_for_fat_arrow_after_braces( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(2 as usize) - .collect::>(), - ), - 1, - ) - } else { - false - } + false } - } else { - false } + } else { + false } } - _ => false, - } - } +}, + _ => false, +} +} } pub fn peek_is_fat_arrow_at(tokens: Rc>>, offset: i64) -> bool { match tokens.get(offset as usize).cloned() { - Some(t) => is_fat_arrow_shape(t.shape.clone()), - None => false, - } + Some(t) => is_fat_arrow_shape(t.shape.clone()), + None => false, +} } -pub fn peek_is_expected_at( - tokens: Rc>>, - offset: i64, - expected: Rc, -) -> bool { +pub fn peek_is_expected_at(tokens: Rc>>, offset: i64, expected: Rc) -> bool { match tokens.get(offset as usize).cloned() { - Some(t) => token_matches_expected(&t, expected), - None => false, - } + Some(t) => token_matches_expected(&t, expected), + None => false, +} } pub fn scan_for_fat_arrow_after_braces(mut remaining: Rc>>, mut depth: i64) -> bool { loop { if (depth.clone() <= 0) { match remaining.clone().first().cloned() { - Some(t) => { - break is_fat_arrow_shape(t.shape.clone()); - } - None => { - break false; - } - } - } else { + Some(t) => { break is_fat_arrow_shape(t.shape.clone()); }, + None => { break false; }, +} +} else { match remaining.clone().first().cloned() { - Some(t) => { - if is_lbrace_shape(t.shape.clone()) { - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = (depth + 1); - remaining = __tco_0; - depth = __tco_1; - continue; - } - } else { - if is_rbrace_shape(t.shape.clone()) { - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - let __tco_1 = (depth - 1); - remaining = __tco_0; - depth = __tco_1; - continue; - } - } else { - { - let __tco_0 = Rc::new( - remaining - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - remaining = __tco_0; - continue; - } - } - } - } - None => { - break false; - } - } - } - } + Some(t) => { if is_lbrace_shape(t.shape.clone()) { + { + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = (depth + 1); +remaining = __tco_0; +depth = __tco_1; +continue; +} +} else { + if is_rbrace_shape(t.shape.clone()) { + { + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = (depth - 1); +remaining = __tco_0; +depth = __tco_1; +continue; +} +} else { + { + let __tco_0 = Rc::new(remaining.iter().cloned().skip(1 as usize).collect::>()); +remaining = __tco_0; +continue; +} +} +} }, + None => { break false; }, +} +} +} } pub fn parse_optional_guard(tokens: &Rc>>, ctx: Rc) -> Rc { if tok_is_keyword(tokens.clone().first().cloned(), "if".to_string()) { { - let r = parse_expr( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx, - ); - if has_err(r.err.clone()) { + let r = parse_expr(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx); +if has_err(r.err.clone()) { return Rc::new(GuardResult { - guard: None, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - Rc::new(GuardResult { - guard: Some(r.expr.clone()), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + guard: None, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +Rc::new(GuardResult { + guard: Some(r.expr.clone()), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { Rc::new(GuardResult { - guard: None, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) + guard: None, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) } } pub fn parse_pattern(tokens: &Rc>>, ctx: &Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - let span = token_span(tok.clone()); - match sh { - Some(TokenShape::ShIdent) => { - let n = tok.clone().unwrap().text.clone(); - if (n.clone().as_str() == "_".to_string().as_str()) { - Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Wildcard), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } else { - if is_uppercase_start(n.clone()) { - parse_variant_pattern( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx.clone(), - n.clone(), - ) - } else { - Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Bind { name: n.clone() }), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } - } - } - Some(TokenShape::ShKeyword) => { - let kw_text = tok.clone().unwrap().text.clone(); - let lit_val = v2_rt::lookup(&dag_syntax_spec().keyword_literals.clone(), kw_text); - match lit_val { - Some(lv) => Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::LitPattern { value: lv.clone() }), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }), - None => Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Wildcard), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }), - } - } - Some(TokenShape::ShLitInt) => { - let n_opt = v2_rt::parse_int(tok.clone().unwrap().text.clone()); - let n = match n_opt { - Some(v) => v.clone(), - None => { - return Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Wildcard), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: Some(parse_error( - v2_rt::concat( - v2_rt::concat( - "internal: ShLitInt token text not parseable as int: '" - .to_string(), - tok.clone().unwrap().text.clone(), - ), - "'".to_string(), - ), - span, - )), - }) - } - }; - Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::LitPattern { - value: Rc::new(LiteralValue::LitInt { value: n.clone() }), - }), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } - Some(TokenShape::ShLitStr) => { - let s = tok.clone().unwrap().text.clone(); +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +let span = token_span(tok.clone()); +match sh { + Some(TokenShape::ShIdent) => { + let n = tok.clone().unwrap().text.clone(); +if (n.clone().as_str() == "_".to_string().as_str()) { Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::LitPattern { - value: Rc::new(LiteralValue::LitStr { value: s }), - }), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) - } - _ => Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Wildcard), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }), - } - } + pattern: Rc::new(MatchPattern::Wildcard), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) + } else { + if is_uppercase_start(n.clone()) { + parse_variant_pattern(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx.clone(), n.clone()) + } else { + Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::Bind { + name: n.clone(), +}), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) + } + } +}, + Some(TokenShape::ShKeyword) => { + let kw_text = tok.clone().unwrap().text.clone(); +let lit_val = v2_rt::lookup(&dag_syntax_spec().keyword_literals.clone(), kw_text); +match lit_val { + Some(lv) => Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::LitPattern { + value: lv.clone(), +}), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}), + None => Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::Wildcard), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +} +}, + Some(TokenShape::ShLitInt) => { + let n_opt = v2_rt::parse_int(tok.clone().unwrap().text.clone()); +let n = match n_opt { + Some(v) => v.clone(), + None => return Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::Wildcard), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: Some(parse_error(v2_rt::concat(v2_rt::concat("internal: ShLitInt token text not parseable as int: '".to_string(), tok.clone().unwrap().text.clone()), "'".to_string()), span)), +}), +}; +Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::LitPattern { + value: Rc::new(LiteralValue::LitInt { + value: n.clone(), +}), +}), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) +}, + Some(TokenShape::ShLitStr) => { + let s = tok.clone().unwrap().text.clone(); +Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::LitPattern { + value: Rc::new(LiteralValue::LitStr { + value: s, +}), +}), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) +}, + _ => Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::Wildcard), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +} +} } -pub fn parse_variant_pattern( - tokens: &Rc>>, - ctx: Rc, - name: String, -) -> Rc { +pub fn parse_variant_pattern(tokens: &Rc>>, ctx: Rc, name: String) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - if tok_is_lbrace(tokens.clone().first().cloned()) { +if tok_is_lbrace(tokens.clone().first().cloned()) { { - let r = parse_variant_bindings_brace( - skip_newlines(Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - )), - ctx, - ); - if has_err(r.err.clone()) { + let r = parse_variant_bindings_brace(skip_newlines(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>())), ctx); +if has_err(r.err.clone()) { return Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Wildcard), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = expect( - &skip_newlines(r.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBrace), - ); - if has_err(r2.err.clone()) { + pattern: Rc::new(MatchPattern::Wildcard), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = expect(&skip_newlines(r.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { return Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Wildcard), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::VariantPattern { - name: name, - parent_enum: None, - field_bindings: r.field_bindings.clone(), - }), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + pattern: Rc::new(MatchPattern::Wildcard), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::VariantPattern { + name: name, + parent_enum: None, + field_bindings: r.field_bindings.clone(), +}), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { if tok_is_lparen(tokens.clone().first().cloned()) { { - let r = parse_pattern( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - &ctx, - ); - if has_err(r.err.clone()) { + let r = parse_pattern(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), &ctx); +if has_err(r.err.clone()) { return Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Wildcard), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + pattern: Rc::new(MatchPattern::Wildcard), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r2.err.clone()) { +let r2 = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r2.err.clone()) { return Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::Wildcard), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); + pattern: Rc::new(MatchPattern::Wildcard), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) } - let fb = make_field_binding_node( - &"0".to_string(), - r.pattern.clone(), - span.clone(), - span.clone(), - ); - Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::VariantPattern { - name: name, - parent_enum: None, - field_bindings: Rc::new(vec![fb]), - }), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let fb = make_field_binding_node(&"0".to_string(), r.pattern.clone(), span.clone(), span.clone()); +Rc::new(PatternResult { + pattern: Rc::new(MatchPattern::VariantPattern { + name: name, + parent_enum: None, + field_bindings: Rc::new(vec![fb]), +}), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { Rc::new(PatternResult { - pattern: Rc::new(MatchPattern::VariantPattern { - name: name, - parent_enum: None, - field_bindings: Rc::new(vec![]), - }), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }) + pattern: Rc::new(MatchPattern::VariantPattern { + name: name, + parent_enum: None, + field_bindings: Rc::new(vec![]), +}), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}) } } - } +} } -pub fn parse_variant_bindings_brace( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_variant_bindings_brace(tokens: Rc>>, ctx: Rc) -> Rc { parse_variant_bindings_brace_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_variant_bindings_brace_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_variant_bindings_brace_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(BindingsResult { - field_bindings: acc, - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } else { + field_bindings: acc, + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); +} else { let bind_span = token_span(tokens.clone().first().cloned()); - let r = expect_name(&tokens); - if has_err(r.err.clone()) { +let r = expect_name(&tokens); +if has_err(r.err.clone()) { return Rc::new(BindingsResult { - field_bindings: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let field_name = r.name.clone(); - let field_name_span = r.span.clone(); - tokens = r.tokens.clone(); - match (*eat(&tokens, Rc::new(ExpectedToken::ExpectColon))).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { - let r2 = parse_pattern(&__ec, &ctx); - if has_err(r2.err.clone()) { - return Rc::new(BindingsResult { - field_bindings: Rc::new(vec![]), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); - } - let e2 = eat(&r2.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e2).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r2.tokens.clone(), - }); - let fb = make_field_binding_node( - &field_name, - r2.pattern.clone(), - bind_span, - field_name_span, - ); - { - let __tco_0 = r2.ctx.clone(); - let __tco_1 = v2_rt::rc_list_push(acc, fb); - ctx = __tco_0; - acc = __tco_1; - continue; - } - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - let e2 = eat(&tokens, Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e2).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => tokens.clone(), - }); - let fb = make_field_binding_node( - &field_name, - Rc::new(MatchPattern::Bind { - name: field_name.clone(), - }), - bind_span, - field_name_span, - ); - { - let __tco_0 = v2_rt::rc_list_push(acc, fb); - acc = __tco_0; - continue; - } - } - } - } - } + field_bindings: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let field_name = r.name.clone(); +let field_name_span = r.span.clone(); +tokens = r.tokens.clone(); +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectColon))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { let r2 = parse_pattern(&__ec, &ctx); +if has_err(r2.err.clone()) { + return Rc::new(BindingsResult { + field_bindings: Rc::new(vec![]), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) + } +let e2 = eat(&r2.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e2).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r2.tokens.clone(), +}); +let fb = make_field_binding_node(&field_name, r2.pattern.clone(), bind_span, field_name_span); +{ + let __tco_0 = r2.ctx.clone(); +let __tco_1 = v2_rt::rc_list_push(acc, fb); +ctx = __tco_0; +acc = __tco_1; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { let e2 = eat(&tokens, Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e2).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => tokens.clone(), +}); +let fb = make_field_binding_node(&field_name, Rc::new(MatchPattern::Bind { + name: field_name.clone(), +}), bind_span, field_name_span); +{ + let __tco_0 = v2_rt::rc_list_push(acc, fb); +acc = __tco_0; +continue; +} }, +} +} +} } pub fn parse_if(tokens: &Rc>>, ctx: &Rc) -> Rc { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { - let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "if".to_string(), - }), - ); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_expr_no_brace(r.tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let condition = r.expr.clone(); - let r = parse_block(&skip_newlines(r.tokens.clone()), &r.ctx.clone()); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let then_branch = r.expr.clone(); - let tokens = skip_newlines(r.tokens.clone()); - let ctx = r.ctx.clone(); - match (*eat( - &tokens, - Rc::new(ExpectedToken::ExpectKeyword { - text: "else".to_string(), - }), - )) - .clone() { - EatResult::EatConsumed { tokens: __ec, .. } => { + let span = token_span(tokens.clone().first().cloned()); +let dummy_expr = parse_recovery_placeholder(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "if".to_string(), +})); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_expr_no_brace(r.tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let condition = r.expr.clone(); +let r = parse_block(&skip_newlines(r.tokens.clone()), &r.ctx.clone()); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let then_branch = r.expr.clone(); +let tokens = skip_newlines(r.tokens.clone()); +let ctx = r.ctx.clone(); +match (*eat(&tokens, Rc::new(ExpectedToken::ExpectKeyword { + text: "else".to_string(), +}))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { let tokens = skip_newlines(__ec.clone()); - if tok_is_keyword(tokens.clone().first().cloned(), "if".to_string()) { +if tok_is_keyword(tokens.clone().first().cloned(), "if".to_string()) { { let r2 = parse_if(&tokens, &ctx); - if has_err(r2.err.clone()) { +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: r2.expr.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); + expr: r2.expr.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprIf), - Rc::new(vec![condition, then_branch, r2.expr.clone()]), - None, - span, - ), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprIf), Rc::new(vec![condition, then_branch, r2.expr.clone()]), None, span), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +} } else { { let r2 = parse_block(&tokens, &ctx); - if has_err(r2.err.clone()) { +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: r2.expr.clone(), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: r2.err.clone(), - }); + expr: r2.expr.clone(), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: r2.err.clone(), +}) } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprIf), - Rc::new(vec![condition, then_branch, r2.expr.clone()]), - None, - span, - ), - tokens: r2.tokens.clone(), - ctx: r2.ctx.clone(), - err: None, - }) - } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprIf), Rc::new(vec![condition, then_branch, r2.expr.clone()]), None, span), + tokens: r2.tokens.clone(), + ctx: r2.ctx.clone(), + err: None, +}) +} } - } - EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprIf), - Rc::new(vec![condition, then_branch]), - None, - span, - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }), - } +}, + EatResult::EatUnchanged { tokens: __eu, .. } => Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprIf), Rc::new(vec![condition, then_branch]), None, span), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}), +} +} }) } pub fn parse_let(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "let".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "let".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = expect_name(&r.tokens.clone()); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = expect_name(&r.tokens.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let name = r.name.clone(); - let name_span = r.span.clone(); - let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let name = r.name.clone(); +let name_span = r.span.clone(); +let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectEq)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_expr(r.tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { - return r.clone(); - } - Rc::new(ExprResult { - expr: make_named_expr_node( - &name, - Rc::new(ExprData::ExprLet), - Rc::new(vec![r.expr.clone()]), - None, - span, - name_span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_expr(r.tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { + return r.clone() + } +Rc::new(ExprResult { + expr: make_named_expr_node(&name, Rc::new(ExprData::ExprLet), Rc::new(vec![r.expr.clone()]), None, span, name_span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } pub fn parse_return(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "return".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "return".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr, - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_expr(r.tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { - return r.clone(); - } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprReturn), - Rc::new(vec![r.expr.clone()]), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + expr: dummy_expr, + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_expr(r.tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { + return r.clone() + } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprReturn), Rc::new(vec![r.expr.clone()]), None, span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } pub fn parse_for(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "for".to_string(), - }), - ); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "for".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = expect_name(&r.tokens.clone()); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = expect_name(&r.tokens.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let var_name = r.name.clone(); - let var_name_span = r.span.clone(); - let r = expect( - &r.tokens.clone(), - &Rc::new(ExpectedToken::ExpectKeyword { - text: "in".to_string(), - }), - ); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let var_name = r.name.clone(); +let var_name_span = r.span.clone(); +let r = expect(&r.tokens.clone(), &Rc::new(ExpectedToken::ExpectKeyword { + text: "in".to_string(), +})); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_expr_no_brace(r.tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_expr_no_brace(r.tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let collection = r.expr.clone(); - let r = parse_block(&skip_newlines(r.tokens.clone()), &r.ctx.clone()); - if has_err(r.err.clone()) { + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let collection = r.expr.clone(); +let r = parse_block(&skip_newlines(r.tokens.clone()), &r.ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let body = r.expr.clone(); - let for_expr = make_named_expr_node( - &var_name, - Rc::new(ExprData::ExprForEach), - Rc::new(vec![collection, body]), - None, - span, - var_name_span, - ); - Rc::new(ExprResult { - expr: for_expr, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let body = r.expr.clone(); +let for_expr = make_named_expr_node(&var_name, Rc::new(ExprData::ExprForEach), Rc::new(vec![collection, body]), None, span, var_name_span); +Rc::new(ExprResult { + expr: for_expr, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } -pub fn parse_record_literal( - tokens: &Rc>>, - ctx: &Rc, - name: String, - span: &Rc, -) -> Rc { +pub fn parse_record_literal(tokens: &Rc>>, ctx: &Rc, name: String, span: &Rc) -> Rc { { let dummy_expr = parse_recovery_placeholder(); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBrace)); - if has_err(r.err.clone()) { +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBrace)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r = parse_field_init_list(tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r = parse_field_init_list(tokens.clone(), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - Rc::new(ExprResult { - expr: make_named_expr_node( - &name, - Rc::new(ExprData::ExprRecordLit { parent_enum: None }), - r.fields.clone(), - None, - span.clone(), - span.clone(), - ), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +Rc::new(ExprResult { + expr: make_named_expr_node(&name, Rc::new(ExprData::ExprRecordLit { + parent_enum: None, +}), r.fields.clone(), None, span.clone(), span.clone()), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } -pub fn parse_field_init_list( - tokens: Rc>>, - ctx: Rc, -) -> Rc { +pub fn parse_field_init_list(tokens: Rc>>, ctx: Rc) -> Rc { parse_field_init_list_acc(tokens, ctx, Rc::new(vec![])) } -pub fn parse_field_init_list_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_field_init_list_acc(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if (tok_is_rbrace(tokens.clone().first().cloned()) - || tok_is_eof(tokens.clone().first().cloned())) - { +if (tok_is_rbrace(tokens.clone().first().cloned()) || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(FieldInitsResult { - fields: acc, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + fields: acc, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { let r = parse_field_init(&tokens, &ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(FieldInitsResult { - fields: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let e = eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r.tokens.clone(), - }); - { + fields: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let e = eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r.tokens.clone(), +}); +{ let __tco_0 = r.ctx.clone(); - let __tco_1 = v2_rt::rc_list_push(acc, r.field.clone()); - ctx = __tco_0; - acc = __tco_1; - continue; - } - } - } +let __tco_1 = v2_rt::rc_list_push(acc, r.field.clone()); +ctx = __tco_0; +acc = __tco_1; +continue; +} +} +} } -pub fn parse_field_init( - tokens: &Rc>>, - ctx: &Rc, -) -> Rc { +pub fn parse_field_init(tokens: &Rc>>, ctx: &Rc) -> Rc { { let zero_span = make_span(0, 0); - let span = token_span(tokens.clone().first().cloned()); - let dummy_fi = make_field_init_node( - &"".to_string(), - parse_recovery_placeholder(), - zero_span.clone(), - zero_span.clone(), - ); - let tok = tokens.clone().first().cloned(); - if (tok_is_ident(tok.clone()) || tok_is_keyword_name(tok.clone())) { +let span = token_span(tokens.clone().first().cloned()); +let dummy_fi = make_field_init_node(&"".to_string(), parse_recovery_placeholder(), zero_span.clone(), zero_span.clone()); +let tok = tokens.clone().first().cloned(); +if (tok_is_ident(tok.clone()) || tok_is_keyword_name(tok.clone())) { { let name_r = expect_name(&tokens); - if has_err(name_r.err.clone()) { +if has_err(name_r.err.clone()) { return Rc::new(FieldInitResult { - field: dummy_fi.clone(), - tokens: name_r.tokens.clone(), - ctx: ctx.clone(), - err: name_r.err.clone(), - }); + field: dummy_fi.clone(), + tokens: name_r.tokens.clone(), + ctx: ctx.clone(), + err: name_r.err.clone(), +}) } - let n = name_r.name.clone(); - if tok_is_colon(name_r.tokens.clone().first().cloned()) { +let n = name_r.name.clone(); +if tok_is_colon(name_r.tokens.clone().first().cloned()) { { - let r = parse_expr( - Rc::new( - name_r - .tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx.clone(), - ); - if has_err(r.err.clone()) { + let r = parse_expr(Rc::new(name_r.tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(FieldInitResult { - field: dummy_fi.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + field: dummy_fi.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let fi = make_field_init_node( - &n, - r.expr.clone(), - span.clone(), - name_r.span.clone(), - ); - Rc::new(FieldInitResult { - field: fi, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let fi = make_field_init_node(&n, r.expr.clone(), span.clone(), name_r.span.clone()); +Rc::new(FieldInitResult { + field: fi, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { { - let fi = make_field_init_node( - &n, - make_named_expr_node( - &n, - Rc::new(ExprData::ExprVar { binding_kind: None }), - Rc::new(vec![]), - None, - span.clone(), - name_r.span.clone(), - ), - span.clone(), - name_r.span.clone(), - ); - Rc::new(FieldInitResult { - field: fi, - tokens: name_r.tokens.clone(), - ctx: ctx.clone(), - err: None, - }) - } + let fi = make_field_init_node(&n, make_named_expr_node(&n, Rc::new(ExprData::ExprVar { + binding_kind: None, +}), Rc::new(vec![]), None, span.clone(), name_r.span.clone()), span.clone(), name_r.span.clone()); +Rc::new(FieldInitResult { + field: fi, + tokens: name_r.tokens.clone(), + ctx: ctx.clone(), + err: None, +}) +} } - } +} } else { if (tok_is_lit_str(tok.clone()) && peek_is_colon_after_ident(tokens.clone())) { { let str_name = match tok.clone() { - Some(t) => t.text.clone(), - None => "_".to_string(), - }; - let r = parse_expr( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(2 as usize) - .collect::>(), - ), - ctx.clone(), - ); - if has_err(r.err.clone()) { + Some(t) => t.text.clone(), + None => "_".to_string(), +}; +let r = parse_expr(Rc::new(tokens.clone().iter().cloned().skip(2 as usize).collect::>()), ctx.clone()); +if has_err(r.err.clone()) { return Rc::new(FieldInitResult { - field: dummy_fi.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + field: dummy_fi.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let fi = - make_field_init_node(&str_name, r.expr.clone(), span.clone(), no_span()); - Rc::new(FieldInitResult { - field: fi, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let fi = make_field_init_node(&str_name, r.expr.clone(), span.clone(), no_span()); +Rc::new(FieldInitResult { + field: fi, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { { let r = parse_expr(tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(FieldInitResult { - field: dummy_fi.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + field: dummy_fi.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let fi = make_field_init_node( - &"_".to_string(), - r.expr.clone(), - span.clone(), - no_span(), - ); - Rc::new(FieldInitResult { - field: fi, - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let fi = make_field_init_node(&"_".to_string(), r.expr.clone(), span.clone(), no_span()); +Rc::new(FieldInitResult { + field: fi, + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } } - } +} } pub fn parse_list_literal(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBracket)); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLBracket)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); - } - let r = parse_expr_list_until( - skip_newlines(r.tokens.clone()), - ctx.clone(), - Rc::new(ExpectedToken::ExpectRBracket), - ); - if has_err(r.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) + } +let r = parse_expr_list_until(skip_newlines(r.tokens.clone()), ctx.clone(), Rc::new(ExpectedToken::ExpectRBracket)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let r2 = expect( - &skip_newlines(r.tokens.clone()), - &Rc::new(ExpectedToken::ExpectRBracket), - ); - if has_err(r2.err.clone()) { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let r2 = expect(&skip_newlines(r.tokens.clone()), &Rc::new(ExpectedToken::ExpectRBracket)); +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - Rc::new(ExprResult { - expr: make_expr_node(Rc::new(ExprData::ExprListLit), r.exprs.clone(), None, span), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprListLit), r.exprs.clone(), None, span), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } -pub fn parse_expr_list_until( - tokens: Rc>>, - ctx: Rc, - end_expected: Rc, -) -> Rc { +pub fn parse_expr_list_until(tokens: Rc>>, ctx: Rc, end_expected: Rc) -> Rc { parse_expr_list_until_acc(tokens, ctx, end_expected, Rc::new(vec![])) } -pub fn parse_expr_list_until_acc( - mut tokens: Rc>>, - mut ctx: Rc, - mut end_expected: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn parse_expr_list_until_acc(mut tokens: Rc>>, mut ctx: Rc, mut end_expected: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - let at_end_tag = match tokens.clone().first().cloned() { - Some(t) => token_matches_expected(&t, end_expected.clone()), - None => false, - }; - if (at_end_tag || tok_is_eof(tokens.clone().first().cloned())) { +let at_end_tag = match tokens.clone().first().cloned() { + Some(t) => token_matches_expected(&t, end_expected.clone()), + None => false, +}; +if (at_end_tag || tok_is_eof(tokens.clone().first().cloned())) { break Rc::new(ExprsResult { - exprs: acc, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + exprs: acc, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { let r = parse_expr(tokens.clone(), ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExprsResult { - exprs: Rc::new(vec![]), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let e = eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); - tokens = skip_newlines(match (*e).clone() { - EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), - EatResult::EatUnchanged { .. } => r.tokens.clone(), - }); - { + exprs: Rc::new(vec![]), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let e = eat(&r.tokens.clone(), Rc::new(ExpectedToken::ExpectComma)); +tokens = skip_newlines(match (*e).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => __ec.clone(), + EatResult::EatUnchanged { .. } => r.tokens.clone(), +}); +{ let __tco_0 = r.ctx.clone(); - let __tco_1 = v2_rt::rc_list_push(acc, r.expr.clone()); - ctx = __tco_0; - acc = __tco_1; - continue; - } - } - } +let __tco_1 = v2_rt::rc_list_push(acc, r.expr.clone()); +ctx = __tco_0; +acc = __tco_1; +continue; +} +} +} } pub fn parse_paren_expr(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); - if has_err(r.err.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let r = expect(&tokens, &Rc::new(ExpectedToken::ExpectLParen)); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: ctx.clone(), - err: r.err.clone(), - }); + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: ctx.clone(), + err: r.err.clone(), +}) } - let tokens = skip_newlines(r.tokens.clone()); - if tok_is_rparen(tokens.clone().first().cloned()) { +let tokens = skip_newlines(r.tokens.clone()); +if tok_is_rparen(tokens.clone().first().cloned()) { Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprRecordLit { parent_enum: None }), - Rc::new(vec![]), - None, - span, - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }) + expr: make_expr_node(Rc::new(ExprData::ExprRecordLit { + parent_enum: None, +}), Rc::new(vec![]), None, span), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}) } else { { let lambda_r = try_lambda_params(&tokens, &ctx); - if lambda_r.is_lambda.clone() { +if lambda_r.is_lambda.clone() { { let r = parse_lambda_body(&lambda_r.tokens.clone(), lambda_r.ctx.clone()); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLambda), - v2_rt::concat( - Rc::new(vec![r.expr.clone()]), - Rc::new({ - let mut __result = Vec::new(); - for p in lambda_r.params.clone().iter().cloned() { - __result.push(parsed_name_leaf( - p.name.clone(), - p.span.clone(), - )); - } - __result - }), - ), - None, - span, - ), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLambda), v2_rt::concat(Rc::new(vec![r.expr.clone()]), Rc::new({ let mut __result = Vec::new(); for p in lambda_r.params.clone().iter().cloned() { __result.push(parsed_name_leaf(p.name.clone(), p.span.clone())); } __result })), None, span), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { { let r = parse_expr(lambda_r.tokens.clone(), lambda_r.ctx.clone()); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + expr: r.expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRParen)); - if has_err(r2.err.clone()) { +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) } - Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +Rc::new(ExprResult { + expr: r.expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } - } +} } - } +} } pub fn parse_fn_lambda(tokens: &Rc>>, ctx: &Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy = parse_recovery_placeholder(); - let r1 = expect( - &tokens, - &Rc::new(ExpectedToken::ExpectKeyword { - text: "fn".to_string(), - }), - ); - if has_err(r1.err.clone()) { +let dummy = parse_recovery_placeholder(); +let r1 = expect(&tokens, &Rc::new(ExpectedToken::ExpectKeyword { + text: "fn".to_string(), +})); +if has_err(r1.err.clone()) { return Rc::new(ExprResult { - expr: dummy.clone(), - tokens: r1.tokens.clone(), - ctx: ctx.clone(), - err: r1.err.clone(), - }); - } - let r2 = expect(&r1.tokens.clone(), &Rc::new(ExpectedToken::ExpectLParen)); - if has_err(r2.err.clone()) { + expr: dummy.clone(), + tokens: r1.tokens.clone(), + ctx: ctx.clone(), + err: r1.err.clone(), +}) + } +let r2 = expect(&r1.tokens.clone(), &Rc::new(ExpectedToken::ExpectLParen)); +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy.clone(), - tokens: r2.tokens.clone(), - ctx: ctx.clone(), - err: r2.err.clone(), - }); - } - let params_r = collect_fn_lambda_params(r2.tokens.clone(), ctx.clone(), Rc::new(vec![])); - let r3 = expect( - ¶ms_r.tokens.clone(), - &Rc::new(ExpectedToken::ExpectRParen), - ); - if has_err(r3.err.clone()) { + expr: dummy.clone(), + tokens: r2.tokens.clone(), + ctx: ctx.clone(), + err: r2.err.clone(), +}) + } +let params_r = collect_fn_lambda_params(r2.tokens.clone(), ctx.clone(), Rc::new(vec![])); +let r3 = expect(¶ms_r.tokens.clone(), &Rc::new(ExpectedToken::ExpectRParen)); +if has_err(r3.err.clone()) { return Rc::new(ExprResult { - expr: dummy.clone(), - tokens: r3.tokens.clone(), - ctx: params_r.ctx.clone(), - err: r3.err.clone(), - }); - } - let tokens = skip_newlines(r3.tokens.clone()); - let body_r = parse_brace_expr(&tokens, params_r.ctx.clone()); - if has_err(body_r.err.clone()) { - return body_r.clone(); - } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprLambda), - v2_rt::concat( - Rc::new(vec![body_r.expr.clone()]), - Rc::new({ - let mut __result = Vec::new(); - for p in params_r.params.clone().iter().cloned() { - __result.push(parsed_name_leaf(p.name.clone(), p.span.clone())); - } - __result - }), - ), - None, - span, - ), - tokens: body_r.tokens.clone(), - ctx: body_r.ctx.clone(), - err: None, - }) - } + expr: dummy.clone(), + tokens: r3.tokens.clone(), + ctx: params_r.ctx.clone(), + err: r3.err.clone(), +}) + } +let tokens = skip_newlines(r3.tokens.clone()); +let body_r = parse_brace_expr(&tokens, params_r.ctx.clone()); +if has_err(body_r.err.clone()) { + return body_r.clone() + } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprLambda), v2_rt::concat(Rc::new(vec![body_r.expr.clone()]), Rc::new({ let mut __result = Vec::new(); for p in params_r.params.clone().iter().cloned() { __result.push(parsed_name_leaf(p.name.clone(), p.span.clone())); } __result })), None, span), + tokens: body_r.tokens.clone(), + ctx: body_r.ctx.clone(), + err: None, +}) +} } -pub fn collect_fn_lambda_params( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn collect_fn_lambda_params(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { tokens = skip_newlines(tokens.clone()); - if tok_is_rparen(tokens.clone().first().cloned()) { +if tok_is_rparen(tokens.clone().first().cloned()) { break Rc::new(IdentCollectResult { - success: true, - params: acc, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } else { + success: true, + params: acc, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} else { let name_r = expect_ident(&tokens); - if has_err(name_r.err.clone()) { +if has_err(name_r.err.clone()) { break Rc::new(IdentCollectResult { - success: false, - params: acc, - tokens: name_r.tokens.clone(), - ctx: ctx, - err: name_r.err.clone(), - }); - } else { + success: false, + params: acc, + tokens: name_r.tokens.clone(), + ctx: ctx, + err: name_r.err.clone(), +}); +} else { tokens = skip_newlines(name_r.tokens.clone()); - if tok_is_comma(tokens.clone().first().cloned()) { +if tok_is_comma(tokens.clone().first().cloned()) { { - let __tco_0 = - Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); - let __tco_1 = v2_rt::rc_list_push( - acc, - Rc::new(ParserParam { - name: name_r.name.clone(), - span: name_r.span.clone(), - }), - ); - tokens = __tco_0; - acc = __tco_1; - continue; - } - } else { + let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = v2_rt::rc_list_push(acc, Rc::new(ParserParam { + name: name_r.name.clone(), + span: name_r.span.clone(), +})); +tokens = __tco_0; +acc = __tco_1; +continue; +} +} else { break Rc::new(IdentCollectResult { - success: true, - params: v2_rt::rc_list_push( - acc, - Rc::new(ParserParam { - name: name_r.name.clone(), - span: name_r.span.clone(), - }), - ), - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } - } - } - } + success: true, + params: v2_rt::rc_list_push(acc, Rc::new(ParserParam { + name: name_r.name.clone(), + span: name_r.span.clone(), +})), + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} +} +} +} } -pub fn try_lambda_params( - tokens: &Rc>>, - ctx: &Rc, -) -> Rc { +pub fn try_lambda_params(tokens: &Rc>>, ctx: &Rc) -> Rc { { let r = collect_lambda_idents(tokens.clone(), ctx.clone(), Rc::new(vec![])); - if (r.success.clone() && ((r.params.clone().len() as i64) >= 2)) { +if (r.success.clone() && ((r.params.clone().len() as i64) >= 2)) { if tok_is_rparen(r.tokens.clone().first().cloned()) { { - let after_rparen = Rc::new( - r.tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ); - if tok_is_fat_arrow(after_rparen.clone().first().cloned()) { + let after_rparen = Rc::new(r.tokens.clone().iter().cloned().skip(1 as usize).collect::>()); +if tok_is_fat_arrow(after_rparen.clone().first().cloned()) { Rc::new(LambdaCheckResult { - is_lambda: true, - params: r.params.clone(), - tokens: Rc::new( - after_rparen - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: r.ctx.clone(), - err: None, - }) + is_lambda: true, + params: r.params.clone(), + tokens: Rc::new(after_rparen.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: r.ctx.clone(), + err: None, +}) } else { Rc::new(LambdaCheckResult { - is_lambda: false, - params: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + is_lambda: false, + params: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } - } +} } else { Rc::new(LambdaCheckResult { - is_lambda: false, - params: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + is_lambda: false, + params: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } } else { Rc::new(LambdaCheckResult { - is_lambda: false, - params: Rc::new(vec![]), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }) + is_lambda: false, + params: Rc::new(vec![]), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}) } - } +} } -pub fn collect_lambda_idents( - mut tokens: Rc>>, - mut ctx: Rc, - mut acc: Rc>>, -) -> Rc { +pub fn collect_lambda_idents(mut tokens: Rc>>, mut ctx: Rc, mut acc: Rc>>) -> Rc { loop { if tok_is_ident(tokens.clone().first().cloned()) { let tok = tokens.clone().first().cloned(); - let param = Rc::new(ParserParam { - name: tok.clone().unwrap().text.clone(), - span: tok.clone().unwrap().span.clone(), - }); - let new_acc = v2_rt::rc_list_push(acc, param); - match (*eat( - &Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - Rc::new(ExpectedToken::ExpectComma), - )) - .clone() - { - EatResult::EatConsumed { tokens: __ec, .. } => { - let __tco_0 = __ec.clone(); - let __tco_1 = new_acc; - tokens = __tco_0; - acc = __tco_1; - continue; - } - EatResult::EatUnchanged { tokens: __eu, .. } => { - break Rc::new(IdentCollectResult { - success: true, - params: new_acc, - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx, - err: None, - }); - } - } - } else { +let param = Rc::new(ParserParam { + name: tok.clone().unwrap().text.clone(), + span: tok.clone().unwrap().span.clone(), +}); +let new_acc = v2_rt::rc_list_push(acc, param); +match (*eat(&Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), Rc::new(ExpectedToken::ExpectComma))).clone() { + EatResult::EatConsumed { tokens: __ec, .. } => { { + let __tco_0 = __ec.clone(); +let __tco_1 = new_acc; +tokens = __tco_0; +acc = __tco_1; +continue; +} }, + EatResult::EatUnchanged { tokens: __eu, .. } => { break Rc::new(IdentCollectResult { + success: true, + params: new_acc, + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx, + err: None, +}); }, +} +} else { break Rc::new(IdentCollectResult { - success: false, - params: acc, - tokens: tokens.clone(), - ctx: ctx, - err: None, - }); - } - } + success: false, + params: acc, + tokens: tokens.clone(), + ctx: ctx, + err: None, +}); +} +} } pub fn parse_string_interp(tokens: &Rc>>, ctx: Rc) -> Rc { { let tok = tokens.clone().first().cloned(); - let span = token_span(tok.clone()); - let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShStrBegin) => { - let prefix = tok.clone().unwrap().text.clone(); - let parts_init = if (v2_rt::string_length(&prefix) > 0) { - Rc::new(vec![Rc::new(StringPart::Text { - value: prefix.clone(), - })]) - } else { - Rc::new(vec![]) - }; - parse_interp_parts( - Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx, - parts_init, - span.clone(), - ) - } - _ => Rc::new(ExprResult { - expr: parse_recovery_expr( - span.clone(), - "expected string interpolation".to_string(), - ), - tokens: tokens.clone(), - ctx: ctx, - err: Some(parse_error( - "expected string interpolation".to_string(), - span.clone(), - )), - }), - } - } +let span = token_span(tok.clone()); +let sh = match tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShStrBegin) => { + let prefix = tok.clone().unwrap().text.clone(); +let parts_init = if (v2_rt::string_length(&prefix) > 0) { + Rc::new(vec![Rc::new(StringPart::Text { + value: prefix.clone(), +})]) + } else { + Rc::new(vec![]) + }; +parse_interp_parts(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), ctx, parts_init, span.clone()) +}, + _ => Rc::new(ExprResult { + expr: parse_recovery_expr(span.clone(), "expected string interpolation".to_string()), + tokens: tokens.clone(), + ctx: ctx, + err: Some(parse_error("expected string interpolation".to_string(), span.clone())), +}), +} +} } -pub fn parse_interp_parts( - mut tokens: Rc>>, - mut ctx: Rc, - mut parts: Rc>>, - mut span: Rc, -) -> Rc { +pub fn parse_interp_parts(mut tokens: Rc>>, mut ctx: Rc, mut parts: Rc>>, mut span: Rc) -> Rc { loop { let r = parse_expr(tokens.clone(), ctx.clone()); - if has_err(r.err.clone()) { - return r.clone(); - } - let new_parts = v2_rt::rc_list_push( - parts, - Rc::new(StringPart::Interpolation { - expr: r.expr.clone(), - }), - ); - tokens = r.tokens.clone(); - ctx = r.ctx.clone(); - let interp_tok = tokens.clone().first().cloned(); - let interp_sh = match interp_tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, +if has_err(r.err.clone()) { + return r.clone() + } +let new_parts = v2_rt::rc_list_push(parts, Rc::new(StringPart::Interpolation { + expr: r.expr.clone(), +})); +tokens = r.tokens.clone(); +ctx = r.ctx.clone(); +let interp_tok = tokens.clone().first().cloned(); +let interp_sh = match interp_tok.clone() { + Some(t) => Some(t.shape.clone()), + None => None, +}; +match interp_sh { + Some(TokenShape::ShStrMid) => { let mid = interp_tok.clone().unwrap().text.clone(); +let mid_parts = if (v2_rt::string_length(&mid) > 0) { + v2_rt::rc_list_push(new_parts, Rc::new(StringPart::Text { + value: mid.clone(), +})) + } else { + new_parts }; - match interp_sh { - Some(TokenShape::ShStrMid) => { - let mid = interp_tok.clone().unwrap().text.clone(); - let mid_parts = if (v2_rt::string_length(&mid) > 0) { - v2_rt::rc_list_push(new_parts, Rc::new(StringPart::Text { value: mid.clone() })) - } else { - new_parts - }; - { - let __tco_0 = - Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); - let __tco_1 = mid_parts; - tokens = __tco_0; - parts = __tco_1; - continue; - } - } - Some(TokenShape::ShStrEnd) => { - let suffix = interp_tok.clone().unwrap().text.clone(); - let final_parts = if (v2_rt::string_length(&suffix) > 0) { - v2_rt::rc_list_push( - new_parts, - Rc::new(StringPart::Text { - value: suffix.clone(), - }), - ) - } else { - new_parts - }; - break Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprStringInterp), - Rc::new({ - let mut __result = Vec::new(); - for p in final_parts.iter().cloned() { - __result.push(match (*p.clone()).clone() { - StringPart::Text { value: v, .. } => { - make_text_part_node(v.clone(), span.clone()) - } - StringPart::Interpolation { expr: e, .. } => { - make_interp_part_node(e.clone(), span.clone()) - } - }); - } - __result - }), - None, - span.clone(), - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx.clone(), - err: None, - }); - } - _ => { - break Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprStringInterp), - Rc::new({ - let mut __result = Vec::new(); - for p in new_parts.iter().cloned() { - __result.push(match (*p.clone()).clone() { - StringPart::Text { value: v, .. } => { - make_text_part_node(v.clone(), span.clone()) - } - StringPart::Interpolation { expr: e, .. } => { - make_interp_part_node(e.clone(), span.clone()) - } - }); - } - __result - }), - None, - span.clone(), - ), - tokens: tokens.clone(), - ctx: ctx.clone(), - err: None, - }); - } - } - } +{ + let __tco_0 = Rc::new(tokens.iter().cloned().skip(1 as usize).collect::>()); +let __tco_1 = mid_parts; +tokens = __tco_0; +parts = __tco_1; +continue; +} }, + Some(TokenShape::ShStrEnd) => { let suffix = interp_tok.clone().unwrap().text.clone(); +let final_parts = if (v2_rt::string_length(&suffix) > 0) { + v2_rt::rc_list_push(new_parts, Rc::new(StringPart::Text { + value: suffix.clone(), +})) + } else { + new_parts + }; +break Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprStringInterp), Rc::new({ let mut __result = Vec::new(); for p in final_parts.iter().cloned() { __result.push(match (*p.clone()).clone() { + StringPart::Text { value: v, .. } => make_text_part_node(v.clone(), span.clone()), + StringPart::Interpolation { expr: e, .. } => make_interp_part_node(e.clone(), span.clone()), +}); } __result }), None, span.clone()), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx.clone(), + err: None, +}); }, + _ => { break Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprStringInterp), Rc::new({ let mut __result = Vec::new(); for p in new_parts.iter().cloned() { __result.push(match (*p.clone()).clone() { + StringPart::Text { value: v, .. } => make_text_part_node(v.clone(), span.clone()), + StringPart::Interpolation { expr: e, .. } => make_interp_part_node(e.clone(), span.clone()), +}); } __result }), None, span.clone()), + tokens: tokens.clone(), + ctx: ctx.clone(), + err: None, +}); }, +} +} } pub fn parse_brace_expr(tokens: &Rc>>, ctx: Rc) -> Rc { { let span = token_span(tokens.clone().first().cloned()); - let dummy_expr = parse_recovery_placeholder(); - let tokens = skip_newlines(Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - )); - let tok = tokens.clone().first().cloned(); - if tok_is_rbrace(tok.clone()) { +let dummy_expr = parse_recovery_placeholder(); +let tokens = skip_newlines(Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>())); +let tok = tokens.clone().first().cloned(); +if tok_is_rbrace(tok.clone()) { Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprRecordLit { parent_enum: None }), - Rc::new(vec![]), - None, - span, - ), - tokens: Rc::new( - tokens - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ), - ctx: ctx, - err: None, - }) + expr: make_expr_node(Rc::new(ExprData::ExprRecordLit { + parent_enum: None, +}), Rc::new(vec![]), None, span), + tokens: Rc::new(tokens.clone().iter().cloned().skip(1 as usize).collect::>()), + ctx: ctx, + err: None, +}) } else { { let sh = match tok.clone() { - Some(t) => Some(t.shape.clone()), - None => None, - }; - match sh { - Some(TokenShape::ShKeyword) => { - let brace_kw = tok_keyword_text(tok.clone()); - if ((brace_kw.clone().as_str() == "let".to_string().as_str()) - || (brace_kw.clone().as_str() == "return".to_string().as_str())) + Some(t) => Some(t.shape.clone()), + None => None, +}; +match sh { + Some(TokenShape::ShKeyword) => { + let brace_kw = tok_keyword_text(tok.clone()); +if ((brace_kw.clone().as_str() == "let".to_string().as_str()) || (brace_kw.clone().as_str() == "return".to_string().as_str())) { { + let r = parse_stmts(tokens.clone(), ctx); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +if ((r.stmts.clone().len() as i64) == 1) { + Rc::new(ExprResult { + expr: r.stmts.clone().first().cloned().clone().unwrap(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) + } else { + Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprBlock), r.stmts.clone(), None, span), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) + } +} + } else { + if (tok_is_keyword_name(tok.clone()) && peek_is_colon_after_ident(tokens.clone())) { { - let r = parse_stmts(tokens.clone(), ctx); - if has_err(r.err.clone()) { + let r = parse_field_init_list(tokens.clone(), ctx); +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - if ((r.stmts.clone().len() as i64) == 1) { - Rc::new(ExprResult { - expr: r.stmts.clone().first().cloned().clone().unwrap(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } else { - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprBlock), - r.stmts.clone(), - None, - span, - ), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) } - } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprRecordLit { + parent_enum: None, +}), r.fields.clone(), None, span), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { - if (tok_is_keyword_name(tok.clone()) - && peek_is_colon_after_ident(tokens.clone())) { - { - let r = parse_field_init_list(tokens.clone(), ctx); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprRecordLit { parent_enum: None }), - r.fields.clone(), - None, - span, - ), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) + let r = parse_expr(tokens.clone(), ctx); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - } else { - { - let r = parse_expr(tokens.clone(), ctx); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - Rc::new(ExprResult { - expr: r.expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) } - } +Rc::new(ExprResult { + expr: r.expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } } - _ => { - let ident_or_keyword = - (tok_is_ident(tok.clone()) || tok_is_keyword_name(tok.clone())); - if (ident_or_keyword && peek_is_colon_after_ident(tokens.clone())) { +}, + _ => { + let ident_or_keyword = (tok_is_ident(tok.clone()) || tok_is_keyword_name(tok.clone())); +if (ident_or_keyword && peek_is_colon_after_ident(tokens.clone())) { + { + let r = parse_field_init_list(tokens.clone(), ctx); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) + } +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) + } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprRecordLit { + parent_enum: None, +}), r.fields.clone(), None, span), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} + } else { + if (tok_is_lit_str(tok.clone()) && peek_is_colon_after_ident(tokens.clone())) { { let r = parse_field_init_list(tokens.clone(), ctx); - if has_err(r.err.clone()) { +if has_err(r.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprRecordLit { parent_enum: None }), - r.fields.clone(), - None, - span, - ), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprRecordLit { + parent_enum: None, +}), r.fields.clone(), None, span), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) +} } else { - if (tok_is_lit_str(tok.clone()) - && peek_is_colon_after_ident(tokens.clone())) { - { - let r = parse_field_init_list(tokens.clone(), ctx); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprRecordLit { parent_enum: None }), - r.fields.clone(), - None, - span, - ), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) + let r = parse_stmts(tokens.clone(), ctx); +if has_err(r.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r.tokens.clone(), + ctx: r.ctx.clone(), + err: r.err.clone(), +}) } - } else { - { - let r = parse_stmts(tokens.clone(), ctx); - if has_err(r.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r.tokens.clone(), - ctx: r.ctx.clone(), - err: r.err.clone(), - }); - } - let tokens = skip_newlines(r.tokens.clone()); - let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); - if has_err(r2.err.clone()) { - return Rc::new(ExprResult { - expr: dummy_expr.clone(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: r2.err.clone(), - }); - } - if ((r.stmts.clone().len() as i64) == 1) { - Rc::new(ExprResult { - expr: r.stmts.clone().first().cloned().clone().unwrap(), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } else { - Rc::new(ExprResult { - expr: make_expr_node( - Rc::new(ExprData::ExprBlock), - r.stmts.clone(), - None, - span, - ), - tokens: r2.tokens.clone(), - ctx: r.ctx.clone(), - err: None, - }) - } +let tokens = skip_newlines(r.tokens.clone()); +let r2 = expect(&tokens, &Rc::new(ExpectedToken::ExpectRBrace)); +if has_err(r2.err.clone()) { + return Rc::new(ExprResult { + expr: dummy_expr.clone(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: r2.err.clone(), +}) } - } +if ((r.stmts.clone().len() as i64) == 1) { + Rc::new(ExprResult { + expr: r.stmts.clone().first().cloned().clone().unwrap(), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) + } else { + Rc::new(ExprResult { + expr: make_expr_node(Rc::new(ExprData::ExprBlock), r.stmts.clone(), None, span), + tokens: r2.tokens.clone(), + ctx: r.ctx.clone(), + err: None, +}) + } +} } } - } - } +}, +} +} } - } +} } pub fn peek_is_colon_after_ident(tokens: Rc>>) -> bool { match tokens.get(1 as usize).cloned() { - Some(t) => is_colon_shape(t.shape.clone()), - None => false, - } + Some(t) => is_colon_shape(t.shape.clone()), + None => false, +} } diff --git a/src/v2/stage0/src/v2_compiler_resolve.rs b/src/v2/stage0/src/v2_compiler_resolve.rs index be03f94ffd6..6544945bd40 100644 --- a/src/v2/stage0/src/v2_compiler_resolve.rs +++ b/src/v2/stage0/src/v2_compiler_resolve.rs @@ -1,21 +1,15 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.resolve -pub use crate::std_types::kernel_type_set; -use crate::v2_rt; -use crate::v2_std_core::CompilerDiagnostic::{ - CircularDependency, DuplicateModule, MissingExport, UnresolvedImport, -}; -use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; -pub use crate::v2_std_core::{ - authored_name_at, import_is_all, import_node, import_specific_names_at, make_error_node, - module_imports, module_items, module_node, no_span, CompilerDiagnostic, Connective, ErrorNode, - NewlineIndex, Node, -}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{kernel_type_set}; +pub use crate::v2_std_core::{Node, Connective, ErrorNode, make_error_node, no_span, module_node, import_node, import_is_all, import_specific_names_at, module_imports, module_items, NewlineIndex, authored_name_at, CompilerDiagnostic}; +use crate::v2_std_core::Connective::{Conj, Disj, NoConnective}; +use crate::v2_std_core::CompilerDiagnostic::{UnresolvedImport, MissingExport, DuplicateModule, CircularDependency}; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct ModuleGraph { @@ -52,130 +46,56 @@ pub struct ResolveAccum { pub fn map_has(m: Rc>, key: String) -> bool { match v2_rt::map_get(&m, key) { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } -pub fn resolve_modules( - modules: &Rc>>, - source_indices: &Rc>>, -) -> Rc { +pub fn resolve_modules(modules: &Rc>>, source_indices: &Rc>>) -> Rc { { let dup_diags = check_duplicate_modules(modules.clone(), source_indices.clone()); - let module_index = modules.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>(), - |acc: Rc>>, m: Rc| { - v2_rt::rc_map_insert(acc, authored_name_at(source_indices.clone(), &m), m.clone()) - }, - ); - let export_sets = modules.clone().iter().cloned().fold( - v2_rt::rc_empty_map::>>(), - |acc: Rc>>>, m: Rc| { - let exported = get_exported_names(&m, source_indices.clone()); - let exported_set = exported.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |inner_acc: Rc>, name: String| { - v2_rt::rc_map_insert(inner_acc, name.clone(), true) - }, - ); - v2_rt::rc_map_insert( - acc, - authored_name_at(source_indices.clone(), &m), - exported_set.clone(), - ) - }, - ); - let resolve_accum = modules.clone().iter().cloned().fold( - Rc::new(ResolveAccum { - imports_by_name: v2_rt::rc_empty_map::>>>(), - diagnostics: Rc::new(vec![]), - }), - |acc: Rc, m: Rc| { - let acc = Rc::try_unwrap(acc).unwrap_or_else(|rc| (*rc).clone()); - { - let result = resolve_module_imports( - &m, - module_index.clone(), - export_sets.clone(), - source_indices.clone(), - ); - Rc::new(ResolveAccum { - imports_by_name: v2_rt::rc_map_insert( - acc.imports_by_name, - authored_name_at(source_indices.clone(), &m), - result.resolved_imports.clone(), - ), - diagnostics: v2_rt::concat(acc.diagnostics, result.diagnostics.clone()), - }) - } - }, - ); - let imports_by_name = resolve_accum.imports_by_name.clone(); - let import_diags = resolve_accum.diagnostics.clone(); - let topo_result = topological_sort(&modules, source_indices.clone()); - let topo_diags = match topo_result.cycle_error.clone() { - Some(diag) => Rc::new(vec![diag.clone()]), - None => Rc::new(vec![]), - }; - let sorted_names = topo_result.sorted.clone(); - let sorted_order_map = Rc::new( - sorted_names - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, pair: (i64, String)| { - v2_rt::rc_map_insert(acc, pair.1.clone(), pair.0.clone()) - }, - ); - let acyclic_resolved = Rc::new({ - let mut __result = Vec::new(); - for m in modules.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get( - &sorted_order_map, - authored_name_at(source_indices.clone(), &m), - ) { - Some(order) => match v2_rt::map_get( - &imports_by_name, - authored_name_at(source_indices.clone(), &m), - ) { - Some(imps) => Rc::new(vec![Rc::new(ResolvedModule { - module: m.clone(), - resolved_imports: imps.clone(), - dep_order: order.clone(), - })]), - None => Rc::new(vec![]), - }, - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }); - let sorted_resolved = Rc::new({ - let mut __sorted: Vec<_> = acyclic_resolved.iter().cloned().collect(); - __sorted.sort_by(|a: &Rc, b: &Rc| { - let __ka = (|m: Rc| m.dep_order.clone())(a.clone()); - let __kb = (|m: Rc| m.dep_order.clone())(b.clone()); - __ka.partial_cmp(&__kb).unwrap_or(std::cmp::Ordering::Equal) - }); - __sorted - }); - Rc::new(ModuleGraph { - modules: sorted_resolved, - diagnostics: v2_rt::concat(v2_rt::concat(dup_diags, import_diags), topo_diags), - }) - } +let module_index = modules.clone().iter().cloned().fold(v2_rt::rc_empty_map::>(), |acc: Rc>>, m: Rc| v2_rt::rc_map_insert(acc, authored_name_at(source_indices.clone(), &m), m.clone())); +let export_sets = modules.clone().iter().cloned().fold(v2_rt::rc_empty_map::>>(), |acc: Rc>>>, m: Rc| { + let exported = get_exported_names(&m, source_indices.clone()); +let exported_set = exported.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |inner_acc: Rc>, name: String| v2_rt::rc_map_insert(inner_acc, name.clone(), true)); +v2_rt::rc_map_insert(acc, authored_name_at(source_indices.clone(), &m), exported_set.clone()) +}); +let resolve_accum = modules.clone().iter().cloned().fold(Rc::new(ResolveAccum { + imports_by_name: v2_rt::rc_empty_map::>>>(), + diagnostics: Rc::new(vec![]), +}), |acc: Rc, m: Rc| { let acc = Rc::try_unwrap(acc).unwrap_or_else(|rc| (*rc).clone()); { + let result = resolve_module_imports(&m, module_index.clone(), export_sets.clone(), source_indices.clone()); +Rc::new(ResolveAccum { + imports_by_name: v2_rt::rc_map_insert(acc.imports_by_name, authored_name_at(source_indices.clone(), &m), result.resolved_imports.clone()), + diagnostics: v2_rt::concat(acc.diagnostics, result.diagnostics.clone()), +}) +} }); +let imports_by_name = resolve_accum.imports_by_name.clone(); +let import_diags = resolve_accum.diagnostics.clone(); +let topo_result = topological_sort(&modules, source_indices.clone()); +let topo_diags = match topo_result.cycle_error.clone() { + Some(diag) => Rc::new(vec![diag.clone()]), + None => Rc::new(vec![]), +}; +let sorted_names = topo_result.sorted.clone(); +let sorted_order_map = Rc::new(sorted_names.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, pair: (i64, String)| v2_rt::rc_map_insert(acc, pair.1.clone(), pair.0.clone())); +let acyclic_resolved = Rc::new({ let mut __result = Vec::new(); for m in modules.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&sorted_order_map, authored_name_at(source_indices.clone(), &m)) { + Some(order) => match v2_rt::map_get(&imports_by_name, authored_name_at(source_indices.clone(), &m)) { + Some(imps) => Rc::new(vec![Rc::new(ResolvedModule { + module: m.clone(), + resolved_imports: imps.clone(), + dep_order: order.clone(), +})]), + None => Rc::new(vec![]), +}, + None => Rc::new(vec![]), +}).iter().cloned()); } __result }); +let sorted_resolved = Rc::new({ let mut __sorted: Vec<_> = acyclic_resolved.iter().cloned().collect(); __sorted.sort_by(|a: &Rc, b: &Rc| { let __ka = (|m: Rc| m.dep_order.clone())(a.clone()); let __kb = (|m: Rc| m.dep_order.clone())(b.clone()); __ka.partial_cmp(&__kb).unwrap_or(std::cmp::Ordering::Equal) }); __sorted }); +Rc::new(ModuleGraph { + modules: sorted_resolved, + diagnostics: v2_rt::concat(v2_rt::concat(dup_diags, import_diags), topo_diags), +}) +} } pub fn find_module(module_index: Rc>>, path: String) -> Option> { @@ -188,58 +108,16 @@ pub struct ModuleResolveResult { pub diagnostics: Rc>>, } -pub fn resolve_module_imports( - module: &Rc, - module_index: Rc>>, - export_sets: Rc>>>, - source_indices: Rc>>, -) -> Rc { +pub fn resolve_module_imports(module: &Rc, module_index: Rc>>, export_sets: Rc>>>, source_indices: Rc>>) -> Rc { { - let results = Rc::new({ - let mut __result = Vec::new(); - for imp in module_imports(module.clone()).iter().cloned() { - __result.push(resolve_import( - &imp, - module_index.clone(), - &authored_name_at(source_indices.clone(), &module), - export_sets.clone(), - &source_indices, - )); - } - __result - }); - let resolved = Rc::new({ - let mut __result = Vec::new(); - for r in Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - if ((r.resolved.clone().target_module.clone() != None) - && ((r.diagnostics.clone().len() as i64) == 0)) - { - __result.push(r); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(r.resolved.clone()); - } - __result - }); - let diags = Rc::new({ - let mut __result = Vec::new(); - for r in results.clone().iter().cloned() { - __result.extend((*r.diagnostics.clone()).iter().cloned()); - } - __result - }); - Rc::new(ModuleResolveResult { - resolved_imports: resolved, - diagnostics: diags, - }) - } + let results = Rc::new({ let mut __result = Vec::new(); for imp in module_imports(module.clone()).iter().cloned() { __result.push(resolve_import(&imp, module_index.clone(), &authored_name_at(source_indices.clone(), &module), export_sets.clone(), &source_indices)); } __result }); +let resolved = Rc::new({ let mut __result = Vec::new(); for r in Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { if ((r.resolved.clone().target_module.clone() != None) && ((r.diagnostics.clone().len() as i64) == 0)) { __result.push(r); } } __result }).iter().cloned() { __result.push(r.resolved.clone()); } __result }); +let diags = Rc::new({ let mut __result = Vec::new(); for r in results.clone().iter().cloned() { __result.extend((*r.diagnostics.clone()).iter().cloned()); } __result }); +Rc::new(ModuleResolveResult { + resolved_imports: resolved, + diagnostics: diags, +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -248,165 +126,82 @@ pub struct ImportResolveResult { pub diagnostics: Rc>>, } -pub fn resolve_import( - import: &Rc, - module_index: Rc>>, - importing_module: &String, - export_sets: Rc>>>, - source_indices: &Rc>>, -) -> Rc { +pub fn resolve_import(import: &Rc, module_index: Rc>>, importing_module: &String, export_sets: Rc>>>, source_indices: &Rc>>) -> Rc { { let import_path = authored_name_at(source_indices.clone(), &import); - let target = find_module(module_index, import_path.clone()); - match target { - None => { - let diag = make_error_node( - Rc::new(CompilerDiagnostic::UnresolvedImport { - module_path: import_path.clone(), - importing_module: importing_module.clone(), - span: import.span.clone(), - }), - importing_module.clone(), - ); - Rc::new(ImportResolveResult { - resolved: Rc::new(ResolvedImport { - module_path: import_path.clone(), - is_all: import_is_all(import.clone()), - specific_names: import_specific_names_at( - import.clone(), - source_indices.clone(), - ), - target_module: None, - }), - diagnostics: Rc::new(vec![diag]), - }) - } - Some(target_mod) => { - let exported_set = match v2_rt::map_get(&export_sets, import_path.clone()) { - Some(set) => set.clone(), - None => v2_rt::rc_empty_map::(), - }; - let name_diags = if import_is_all(import.clone()) { - Rc::new(vec![]) - } else { - Rc::new({ - let mut __result = Vec::new(); - for child in Rc::new({ - let mut __result = Vec::new(); - for child in import.children.clone().iter().cloned() { - if (v2_rt::map_has( - &exported_set, - authored_name_at(source_indices.clone(), &child), - ) == false) - { - __result.push(child); - } - } - __result - }) - .iter() - .cloned() - { - __result.push(make_error_node( - Rc::new(CompilerDiagnostic::MissingExport { - name: authored_name_at(source_indices.clone(), &child), - module_path: import_path.clone(), - importing_module: importing_module.clone(), - span: child.span.clone(), - }), - importing_module.clone(), - )); - } - __result - }) - }; - Rc::new(ImportResolveResult { - resolved: Rc::new(ResolvedImport { - module_path: import_path.clone(), - is_all: import_is_all(import.clone()), - specific_names: import_specific_names_at( - import.clone(), - source_indices.clone(), - ), - target_module: Some(target_mod.clone()), - }), - diagnostics: name_diags, - }) - } - } - } +let target = find_module(module_index, import_path.clone()); +match target { + None => { + let diag = make_error_node(Rc::new(CompilerDiagnostic::UnresolvedImport { + module_path: import_path.clone(), + importing_module: importing_module.clone(), + span: import.span.clone(), +}), importing_module.clone()); +Rc::new(ImportResolveResult { + resolved: Rc::new(ResolvedImport { + module_path: import_path.clone(), + is_all: import_is_all(import.clone()), + specific_names: import_specific_names_at(import.clone(), source_indices.clone()), + target_module: None, +}), + diagnostics: Rc::new(vec![diag]), +}) +}, + Some(target_mod) => { + let exported_set = match v2_rt::map_get(&export_sets, import_path.clone()) { + Some(set) => set.clone(), + None => v2_rt::rc_empty_map::(), +}; +let name_diags = if import_is_all(import.clone()) { + Rc::new(vec![]) + } else { + Rc::new({ let mut __result = Vec::new(); for child in Rc::new({ let mut __result = Vec::new(); for child in import.children.clone().iter().cloned() { if (v2_rt::map_has(&exported_set, authored_name_at(source_indices.clone(), &child)) == false) { __result.push(child); } } __result }).iter().cloned() { __result.push(make_error_node(Rc::new(CompilerDiagnostic::MissingExport { + name: authored_name_at(source_indices.clone(), &child), + module_path: import_path.clone(), + importing_module: importing_module.clone(), + span: child.span.clone(), +}), importing_module.clone())); } __result }) + }; +Rc::new(ImportResolveResult { + resolved: Rc::new(ResolvedImport { + module_path: import_path.clone(), + is_all: import_is_all(import.clone()), + specific_names: import_specific_names_at(import.clone(), source_indices.clone()), + target_module: Some(target_mod.clone()), +}), + diagnostics: name_diags, +}) +}, +} +} } -pub fn get_exported_names( - module: &Rc, - source_indices: Rc>>, -) -> Rc> { +pub fn get_exported_names(module: &Rc, source_indices: Rc>>) -> Rc> { { - let item_names = Rc::new({ - let mut __result = Vec::new(); - for item in module_items(module.clone()).iter().cloned() { - __result.push(get_item_name(item.clone(), source_indices.clone())); - } - __result - }); - let variant_names = Rc::new({ - let mut __result = Vec::new(); - for item in module_items(module.clone()).iter().cloned() { - __result.extend( - (*get_variant_names(&item, source_indices.clone())) - .iter() - .cloned(), - ); - } - __result - }); - let imported_names = Rc::new({ - let mut __result = Vec::new(); - for imp in module_imports(module.clone()).iter().cloned() { - __result.extend( - (*if import_is_all(imp.clone()) { - Rc::new(vec![]) - } else { - import_specific_names_at(imp.clone(), source_indices.clone()) - }) - .iter() - .cloned(), - ); - } - __result - }); - v2_rt::concat( - v2_rt::concat(v2_rt::concat(item_names, variant_names), imported_names), - Rc::new(v2_rt::map_keys(&kernel_type_set())), - ) - } + let item_names = Rc::new({ let mut __result = Vec::new(); for item in module_items(module.clone()).iter().cloned() { __result.push(get_item_name(item.clone(), source_indices.clone())); } __result }); +let variant_names = Rc::new({ let mut __result = Vec::new(); for item in module_items(module.clone()).iter().cloned() { __result.extend((*get_variant_names(&item, source_indices.clone())).iter().cloned()); } __result }); +let imported_names = Rc::new({ let mut __result = Vec::new(); for imp in module_imports(module.clone()).iter().cloned() { __result.extend((*if import_is_all(imp.clone()) { + Rc::new(vec![]) + } else { + import_specific_names_at(imp.clone(), source_indices.clone()) + }).iter().cloned()); } __result }); +v2_rt::concat(v2_rt::concat(v2_rt::concat(item_names, variant_names), imported_names), Rc::new(v2_rt::map_keys(&kernel_type_set()))) +} } -pub fn get_item_name( - item: Rc, - source_indices: Rc>>, -) -> String { +pub fn get_item_name(item: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &item) } -pub fn get_variant_names( - item: &Rc, - source_indices: Rc>>, -) -> Rc> { +pub fn get_variant_names(item: &Rc, source_indices: Rc>>) -> Rc> { { let is_coproduct = (item.connective.clone() == Connective::Disj); - if is_coproduct { - Rc::new({ - let mut __result = Vec::new(); - for c in item.children.clone().iter().cloned() { - __result.push(authored_name_at(source_indices.clone(), &c)); - } - __result - }) +if is_coproduct { + Rc::new({ let mut __result = Vec::new(); for c in item.children.clone().iter().cloned() { __result.push(authored_name_at(source_indices.clone(), &c)); } __result }) } else { Rc::new(vec![]) } - } +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -415,47 +210,31 @@ pub struct DuplicateCheckState { pub diagnostics: Rc>>, } -pub fn check_duplicate_modules( - modules: Rc>>, - source_indices: Rc>>, -) -> Rc>> { +pub fn check_duplicate_modules(modules: Rc>>, source_indices: Rc>>) -> Rc>> { { - let result = modules.iter().cloned().fold( - Rc::new(DuplicateCheckState { - seen_names: v2_rt::rc_empty_map::(), - diagnostics: Rc::new(vec![]), - }), - |state: Rc, m: Rc| { - let m_name = authored_name_at(source_indices.clone(), &m); - let is_dup = v2_rt::map_has(&state.seen_names.clone(), m_name.clone()); - if is_dup.clone() { - Rc::new(DuplicateCheckState { - seen_names: state.seen_names.clone(), - diagnostics: v2_rt::concat( - state.diagnostics.clone(), - Rc::new(vec![make_error_node( - Rc::new(CompilerDiagnostic::DuplicateModule { - name: m_name.clone(), - span: m.span.clone(), - }), - m_name.clone(), - )]), - ), - }) - } else { - Rc::new(DuplicateCheckState { - seen_names: v2_rt::rc_map_insert( - state.seen_names.clone(), - m_name.clone(), - true, - ), - diagnostics: state.diagnostics.clone(), - }) - } - }, - ); - result.diagnostics.clone() - } + let result = modules.iter().cloned().fold(Rc::new(DuplicateCheckState { + seen_names: v2_rt::rc_empty_map::(), + diagnostics: Rc::new(vec![]), +}), |state: Rc, m: Rc| { + let m_name = authored_name_at(source_indices.clone(), &m); +let is_dup = v2_rt::map_has(&state.seen_names.clone(), m_name.clone()); +if is_dup.clone() { + Rc::new(DuplicateCheckState { + seen_names: state.seen_names.clone(), + diagnostics: v2_rt::concat(state.diagnostics.clone(), Rc::new(vec![make_error_node(Rc::new(CompilerDiagnostic::DuplicateModule { + name: m_name.clone(), + span: m.span.clone(), +}), m_name.clone())])), +}) + } else { + Rc::new(DuplicateCheckState { + seen_names: v2_rt::rc_map_insert(state.seen_names.clone(), m_name.clone(), true), + diagnostics: state.diagnostics.clone(), +}) + } +}); +result.diagnostics.clone() +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -464,22 +243,14 @@ pub struct TopoResult { pub cycle_error: Option>, } -pub fn adjacency_add_edge( - adjacency: &Rc>>>, - from_module: &String, - to_module: String, -) -> Rc>>> { +pub fn adjacency_add_edge(adjacency: &Rc>>>, from_module: &String, to_module: String) -> Rc>>> { { let existing = match v2_rt::map_get(&adjacency, from_module.clone()) { - Some(lst) => lst.clone(), - None => Rc::new(vec![]), - }; - v2_rt::rc_map_insert( - adjacency.clone(), - from_module.clone(), - v2_rt::rc_list_push(existing, to_module), - ) - } + Some(lst) => lst.clone(), + None => Rc::new(vec![]), +}; +v2_rt::rc_map_insert(adjacency.clone(), from_module.clone(), v2_rt::rc_list_push(existing, to_module)) +} } pub fn topo_sort_key(name: String) -> String { @@ -490,201 +261,67 @@ pub fn topo_sort_key(name: String) -> String { } } -pub fn topological_sort( - modules: &Rc>>, - source_indices: Rc>>, -) -> Rc { +pub fn topological_sort(modules: &Rc>>, source_indices: Rc>>) -> Rc { { - let module_names = Rc::new({ - let mut __result = Vec::new(); - for m in modules.clone().iter().cloned() { - __result.push(authored_name_at(source_indices.clone(), &m)); - } - __result - }); - let has_std_types = { - let mut __found = false; - for name in module_names.clone().iter().cloned() { - if (name.clone().as_str() == "std.types".to_string().as_str()) { - __found = true; - break; - } - } - __found - }; - let explicit_edges = Rc::new({ - let mut __result = Vec::new(); - for m in modules.clone().iter().cloned() { - __result.extend( - (*Rc::new({ - let mut __result = Vec::new(); - for imp in module_imports(m.clone()).iter().cloned() { - __result.push(Rc::new(DepEdge { - from_module: authored_name_at(source_indices.clone(), &imp), - to_module: authored_name_at(source_indices.clone(), &m), - })); - } - __result - })) - .iter() - .cloned(), - ); - } - __result - }); - let implicit_std_types_edges = if has_std_types.clone() { - Rc::new({ - let mut __result = Vec::new(); - for m in modules.clone().iter().cloned() { - __result.extend( - (*{ - let m_name = authored_name_at(source_indices.clone(), &m); - let imports_std_types = { - let mut __found = false; - for imp in module_imports(m.clone()).iter().cloned() { - if (authored_name_at(source_indices.clone(), &imp).as_str() - == "std.types".to_string().as_str()) - { - __found = true; - break; - } - } - __found - }; - if ((((m_name.clone().as_str() != "std.types".to_string().as_str()) - && (m_name.clone().as_str() - != "std.algebra".to_string().as_str())) - && (m_name.clone().as_str() - != "std.error_primitives".to_string().as_str())) - && (imports_std_types.clone() == false)) - { - Rc::new(vec![Rc::new(DepEdge { - from_module: "std.types".to_string(), - to_module: m_name.clone(), - })]) - } else { - Rc::new(vec![]) - } - }) - .iter() - .cloned(), - ); + let module_names = Rc::new({ let mut __result = Vec::new(); for m in modules.clone().iter().cloned() { __result.push(authored_name_at(source_indices.clone(), &m)); } __result }); +let has_std_types = { let mut __found = false; for name in module_names.clone().iter().cloned() { if (name.clone().as_str() == "std.types".to_string().as_str()) { __found = true; break; } } __found }; +let explicit_edges = Rc::new({ let mut __result = Vec::new(); for m in modules.clone().iter().cloned() { __result.extend((*Rc::new({ let mut __result = Vec::new(); for imp in module_imports(m.clone()).iter().cloned() { __result.push(Rc::new(DepEdge { + from_module: authored_name_at(source_indices.clone(), &imp), + to_module: authored_name_at(source_indices.clone(), &m), +})); } __result })).iter().cloned()); } __result }); +let implicit_std_types_edges = if has_std_types.clone() { + Rc::new({ let mut __result = Vec::new(); for m in modules.clone().iter().cloned() { __result.extend((*{ + let m_name = authored_name_at(source_indices.clone(), &m); +let imports_std_types = { let mut __found = false; for imp in module_imports(m.clone()).iter().cloned() { if (authored_name_at(source_indices.clone(), &imp).as_str() == "std.types".to_string().as_str()) { __found = true; break; } } __found }; +if ((((m_name.clone().as_str() != "std.types".to_string().as_str()) && (m_name.clone().as_str() != "std.algebra".to_string().as_str())) && (m_name.clone().as_str() != "std.error_primitives".to_string().as_str())) && (imports_std_types.clone() == false)) { + Rc::new(vec![Rc::new(DepEdge { + from_module: "std.types".to_string(), + to_module: m_name.clone(), +})]) + } else { + Rc::new(vec![]) } - __result - }) +}).iter().cloned()); } __result }) } else { Rc::new(vec![]) }; - let adjacency = v2_rt::concat(explicit_edges, implicit_std_types_edges) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::>>(), - |acc: Rc>>>, edge: Rc| { - adjacency_add_edge(&acc, &edge.from_module.clone(), edge.to_module.clone()) - }, - ); - let in_degree_map = modules.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, m: Rc| { - let m_name = authored_name_at(source_indices.clone(), &m); - let imports_std_types = { - let mut __found = false; - for imp in module_imports(m.clone()).iter().cloned() { - if (authored_name_at(source_indices.clone(), &imp).as_str() - == "std.types".to_string().as_str()) - { - __found = true; - break; - } - } - __found - }; - let implicit_std_types_in_degree = if ((((has_std_types.clone() - && (m_name.clone().as_str() != "std.types".to_string().as_str())) - && (m_name.clone().as_str() != "std.algebra".to_string().as_str())) - && (m_name.clone().as_str() != "std.error_primitives".to_string().as_str())) - && (imports_std_types.clone() == false)) - { - 1 - } else { - 0 - }; - v2_rt::rc_map_insert( - acc, - m_name.clone(), - ((module_imports(m.clone()).len() as i64) - + implicit_std_types_in_degree.clone()), - ) - }, - ); - let initial_queue = Rc::new({ - let mut __sorted: Vec<_> = Rc::new({ - let mut __result = Vec::new(); - for name in module_names.clone().iter().cloned() { - if match v2_rt::map_get(&in_degree_map, name.clone()) { - Some(0) => true, - _ => false, - } { - __result.push(name); - } - } - __result - }) - .iter() - .cloned() - .collect(); - __sorted.sort_by(|a: &String, b: &String| { - let __ka = (|name: String| topo_sort_key(name.clone()))(a.clone()); - let __kb = (|name: String| topo_sort_key(name.clone()))(b.clone()); - __ka.partial_cmp(&__kb).unwrap_or(std::cmp::Ordering::Equal) - }); - __sorted - }); - let module_count = (modules.clone().len() as i64); - let result = kahn_drain( - initial_queue, - Rc::new(vec![]), - in_degree_map.clone(), - adjacency, - module_count.clone(), - ); - if ((result.sorted.clone().len() as i64) == module_count.clone()) { +let adjacency = v2_rt::concat(explicit_edges, implicit_std_types_edges).iter().cloned().fold(v2_rt::rc_empty_map::>>(), |acc: Rc>>>, edge: Rc| adjacency_add_edge(&acc, &edge.from_module.clone(), edge.to_module.clone())); +let in_degree_map = modules.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, m: Rc| { + let m_name = authored_name_at(source_indices.clone(), &m); +let imports_std_types = { let mut __found = false; for imp in module_imports(m.clone()).iter().cloned() { if (authored_name_at(source_indices.clone(), &imp).as_str() == "std.types".to_string().as_str()) { __found = true; break; } } __found }; +let implicit_std_types_in_degree = if ((((has_std_types.clone() && (m_name.clone().as_str() != "std.types".to_string().as_str())) && (m_name.clone().as_str() != "std.algebra".to_string().as_str())) && (m_name.clone().as_str() != "std.error_primitives".to_string().as_str())) && (imports_std_types.clone() == false)) { + 1 + } else { + 0 + }; +v2_rt::rc_map_insert(acc, m_name.clone(), ((module_imports(m.clone()).len() as i64) + implicit_std_types_in_degree.clone())) +}); +let initial_queue = Rc::new({ let mut __sorted: Vec<_> = Rc::new({ let mut __result = Vec::new(); for name in module_names.clone().iter().cloned() { if match v2_rt::map_get(&in_degree_map, name.clone()) { + Some(0) => true, + _ => false, +} { __result.push(name); } } __result }).iter().cloned().collect(); __sorted.sort_by(|a: &String, b: &String| { let __ka = (|name: String| topo_sort_key(name.clone()))(a.clone()); let __kb = (|name: String| topo_sort_key(name.clone()))(b.clone()); __ka.partial_cmp(&__kb).unwrap_or(std::cmp::Ordering::Equal) }); __sorted }); +let module_count = (modules.clone().len() as i64); +let result = kahn_drain(initial_queue, Rc::new(vec![]), in_degree_map.clone(), adjacency, module_count.clone()); +if ((result.sorted.clone().len() as i64) == module_count.clone()) { Rc::new(TopoResult { - sorted: result.sorted.clone(), - cycle_error: None, - }) + sorted: result.sorted.clone(), + cycle_error: None, +}) } else { { - let sorted_set = result.sorted.clone().iter().cloned().fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let cycle_members = Rc::new({ - let mut __result = Vec::new(); - for name in module_names.clone().iter().cloned() { - if (v2_rt::map_has(&sorted_set, name.clone()) == false) { - __result.push(name); - } - } - __result - }); - let cycle_desc = cycle_members.clone().join(&" -> ".to_string()); - Rc::new(TopoResult { - sorted: result.sorted.clone(), - cycle_error: Some(make_error_node( - Rc::new(CompilerDiagnostic::CircularDependency { - modules: cycle_members.clone(), - span: no_span(), - }), - "".to_string(), - )), - }) - } + let sorted_set = result.sorted.clone().iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let cycle_members = Rc::new({ let mut __result = Vec::new(); for name in module_names.clone().iter().cloned() { if (v2_rt::map_has(&sorted_set, name.clone()) == false) { __result.push(name); } } __result }); +let cycle_desc = cycle_members.clone().join(&" -> ".to_string()); +Rc::new(TopoResult { + sorted: result.sorted.clone(), + cycle_error: Some(make_error_node(Rc::new(CompilerDiagnostic::CircularDependency { + modules: cycle_members.clone(), + span: no_span(), +}), "".to_string())), +}) +} } - } +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -693,112 +330,53 @@ pub struct KahnDrainState { pub in_degree_map: Rc>, } -pub fn kahn_drain( - mut queue: Rc>, - mut sorted: Rc>, - mut in_degree_map: Rc>, - mut adjacency: Rc>>>, - mut fuel: i64, -) -> Rc { +pub fn kahn_drain(mut queue: Rc>, mut sorted: Rc>, mut in_degree_map: Rc>, mut adjacency: Rc>>>, mut fuel: i64) -> Rc { loop { if ((queue.clone().len() as i64) == 0) { return Rc::new(KahnDrainState { - sorted: sorted.clone(), - in_degree_map: in_degree_map.clone(), - }); + sorted: sorted.clone(), + in_degree_map: in_degree_map.clone(), +}) } - let batch_result = queue.clone().iter().cloned().fold( - Rc::new(KahnDrainState { - sorted: sorted.clone(), - in_degree_map: in_degree_map.clone(), - }), - |state: Rc, node: String| { - let state = Rc::try_unwrap(state).unwrap_or_else(|rc| (*rc).clone()); - { - let new_sorted = v2_rt::rc_list_push(state.sorted, node.clone()); - let neighbors = match v2_rt::map_get(&adjacency, node.clone()) { - Some(ns) => ns.clone(), - None => Rc::new(vec![]), - }; - let new_degrees = neighbors.clone().iter().cloned().fold( - state.in_degree_map, - |deg_map: Rc>, neighbor: String| { - let current = match v2_rt::map_get(°_map, neighbor.clone()) { - Some(d) => d.clone(), - None => 0, - }; - v2_rt::rc_map_insert( - deg_map.clone(), - neighbor.clone(), - (current.clone() - 1), - ) - }, - ); - Rc::new(KahnDrainState { - sorted: new_sorted.clone(), - in_degree_map: new_degrees.clone(), - }) - } - }, - ); - let new_zero_set = Rc::new({ - let mut __result = Vec::new(); - for neighbor in Rc::new({ - let mut __result = Vec::new(); - for node in queue.clone().iter().cloned() { - __result.extend( - (*match v2_rt::map_get(&adjacency, node.clone()) { - Some(ns) => ns.clone(), - None => Rc::new(vec![]), - }) - .iter() - .cloned(), - ); - } - __result - }) - .iter() - .cloned() - { - if match v2_rt::map_get(&batch_result.in_degree_map.clone(), neighbor.clone()) { - Some(0) => true, - _ => false, - } { - __result.push(neighbor); - } - } - __result - }) - .iter() - .cloned() - .fold( - v2_rt::rc_empty_map::(), - |acc: Rc>, name: String| { - v2_rt::rc_map_insert(acc, name.clone(), true) - }, - ); - let new_zero = Rc::new({ - let mut __sorted: Vec<_> = Rc::new(v2_rt::map_keys(&new_zero_set)) - .iter() - .cloned() - .collect(); - __sorted.sort_by(|a: &String, b: &String| { - let __ka = (|name: String| name.clone())(a.clone()); - let __kb = (|name: String| name.clone())(b.clone()); - __ka.partial_cmp(&__kb).unwrap_or(std::cmp::Ordering::Equal) - }); - __sorted - }); - { +let batch_result = queue.clone().iter().cloned().fold(Rc::new(KahnDrainState { + sorted: sorted.clone(), + in_degree_map: in_degree_map.clone(), +}), |state: Rc, node: String| { let state = Rc::try_unwrap(state).unwrap_or_else(|rc| (*rc).clone()); { + let new_sorted = v2_rt::rc_list_push(state.sorted, node.clone()); +let neighbors = match v2_rt::map_get(&adjacency, node.clone()) { + Some(ns) => ns.clone(), + None => Rc::new(vec![]), +}; +let new_degrees = neighbors.clone().iter().cloned().fold(state.in_degree_map, |deg_map: Rc>, neighbor: String| { + let current = match v2_rt::map_get(°_map, neighbor.clone()) { + Some(d) => d.clone(), + None => 0, +}; +v2_rt::rc_map_insert(deg_map.clone(), neighbor.clone(), (current.clone() - 1)) +}); +Rc::new(KahnDrainState { + sorted: new_sorted.clone(), + in_degree_map: new_degrees.clone(), +}) +} }); +let new_zero_set = Rc::new({ let mut __result = Vec::new(); for neighbor in Rc::new({ let mut __result = Vec::new(); for node in queue.clone().iter().cloned() { __result.extend((*match v2_rt::map_get(&adjacency, node.clone()) { + Some(ns) => ns.clone(), + None => Rc::new(vec![]), +}).iter().cloned()); } __result }).iter().cloned() { if match v2_rt::map_get(&batch_result.in_degree_map.clone(), neighbor.clone()) { + Some(0) => true, + _ => false, +} { __result.push(neighbor); } } __result }).iter().cloned().fold(v2_rt::rc_empty_map::(), |acc: Rc>, name: String| v2_rt::rc_map_insert(acc, name.clone(), true)); +let new_zero = Rc::new({ let mut __sorted: Vec<_> = Rc::new(v2_rt::map_keys(&new_zero_set)).iter().cloned().collect(); __sorted.sort_by(|a: &String, b: &String| { let __ka = (|name: String| name.clone())(a.clone()); let __kb = (|name: String| name.clone())(b.clone()); __ka.partial_cmp(&__kb).unwrap_or(std::cmp::Ordering::Equal) }); __sorted }); +{ let __tco_0 = new_zero; - let __tco_1 = batch_result.sorted.clone(); - let __tco_2 = batch_result.in_degree_map.clone(); - let __tco_3 = (fuel - 1); - queue = __tco_0; - sorted = __tco_1; - in_degree_map = __tco_2; - fuel = __tco_3; - continue; - } - } +let __tco_1 = batch_result.sorted.clone(); +let __tco_2 = batch_result.in_degree_map.clone(); +let __tco_3 = (fuel - 1); +queue = __tco_0; +sorted = __tco_1; +in_degree_map = __tco_2; +fuel = __tco_3; +continue; +} +} } diff --git a/src/v2/stage0/src/v2_compiler_runtime_rust.rs b/src/v2/stage0/src/v2_compiler_runtime_rust.rs index 5c7fbc9d8fd..7b659e92b96 100644 --- a/src/v2/stage0/src/v2_compiler_runtime_rust.rs +++ b/src/v2/stage0/src/v2_compiler_runtime_rust.rs @@ -1,26 +1,14 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.runtime_rust -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; pub fn rt_header() -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "//! Runtime shims for v2 compiler intrinsic operations.\n".to_string(), - "//! Generated by the v2 compiler -- do not edit.\n\n".to_string(), - ), - "#![allow(unused_variables, dead_code)]\n\n".to_string(), - ), - "use std::collections::HashMap;\n".to_string(), - ), - "use std::rc::Rc;\n\n".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("//! Runtime shims for v2 compiler intrinsic operations.\n".to_string(), "//! Generated by the v2 compiler -- do not edit.\n\n".to_string()), "#![allow(unused_variables, dead_code)]\n\n".to_string()), "use std::collections::HashMap;\n".to_string()), "use std::rc::Rc;\n\n".to_string()) } pub fn rt_concat_trait() -> String { @@ -40,23 +28,7 @@ pub fn rt_scanner_ops() -> String { } pub fn rt_unicode_ops() -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "pub fn code_point(c: String) -> i64 {\n".to_string(), - " c.chars().next().map(|ch| ch as i64).unwrap_or(0)\n".to_string(), - ), - "}\n\n".to_string(), - ), - "pub fn from_code_point(cp: i64) -> String {\n".to_string(), - ), - " char::from_u32(cp as u32).map(|c| c.to_string()).unwrap_or_default()\n" - .to_string(), - ), - "}\n\n".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("pub fn code_point(c: String) -> i64 {\n".to_string(), " c.chars().next().map(|ch| ch as i64).unwrap_or(0)\n".to_string()), "}\n\n".to_string()), "pub fn from_code_point(cp: i64) -> String {\n".to_string()), " char::from_u32(cp as u32).map(|c| c.to_string()).unwrap_or_default()\n".to_string()), "}\n\n".to_string()) } pub fn rt_rc_container_ops() -> String { @@ -64,53 +36,9 @@ pub fn rt_rc_container_ops() -> String { } pub fn rt_filesystem() -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - "#[derive(Debug, Clone)]\n".to_string(), - "pub struct FilesystemReadResult {\n".to_string(), - ), - " pub content: String,\n".to_string(), - ), - "}\n\n".to_string(), - ), - "pub fn filesystem_read(path: String) -> FilesystemReadResult {\n" - .to_string(), - ), - " let content = std::fs::read_to_string(&path)\n".to_string(), - ), - " .unwrap_or_else(|e| panic!(\"failed to read {}: {}\", path, e));\n" - .to_string(), - ), - " FilesystemReadResult { content }\n".to_string(), - ), - "}\n".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("#[derive(Debug, Clone)]\n".to_string(), "pub struct FilesystemReadResult {\n".to_string()), " pub content: String,\n".to_string()), "}\n\n".to_string()), "pub fn filesystem_read(path: String) -> FilesystemReadResult {\n".to_string()), " let content = std::fs::read_to_string(&path)\n".to_string()), " .unwrap_or_else(|e| panic!(\"failed to read {}: {}\", path, e));\n".to_string()), " FilesystemReadResult { content }\n".to_string()), "}\n".to_string()) } pub fn rust_runtime_source() -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(rt_header(), rt_concat_trait()), - rt_string_ops(), - ), - rt_collection_ops(), - ), - rt_rc_container_ops(), - ), - rt_scanner_ops(), - ), - rt_unicode_ops(), - ), - rt_filesystem(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(rt_header(), rt_concat_trait()), rt_string_ops()), rt_collection_ops()), rt_rc_container_ops()), rt_scanner_ops()), rt_unicode_ops()), rt_filesystem()) } diff --git a/src/v2/stage0/src/v2_compiler_tokenize.rs b/src/v2/stage0/src/v2_compiler_tokenize.rs index 843451120d1..74bb7d656f5 100644 --- a/src/v2/stage0/src/v2_compiler_tokenize.rs +++ b/src/v2/stage0/src/v2_compiler_tokenize.rs @@ -1,28 +1,22 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.tokenize -use self::StringScanResult::*; -pub use crate::extdeps_languages_dag_syntax::dag_keyword_set; -pub use crate::std_types::SourceSpan; -use crate::v2_rt; -use crate::v2_std_core::TokenShape::{ - ShAnd, ShArrow, ShBang, ShColon, ShComma, ShDot, ShDotDot, ShEof, ShEq, ShEqEq, ShFatArrow, - ShGe, ShGt, ShIdent, ShKeyword, ShLBrace, ShLBracket, ShLParen, ShLe, ShLitFloat, ShLitInt, - ShLitStr, ShLt, ShMinus, ShNe, ShNewline, ShNullCoalesce, ShOr, ShPercent, ShPipe, ShPipeArrow, - ShPlus, ShQuestion, ShRBrace, ShRBracket, ShRParen, ShSlash, ShStar, ShStrBegin, ShStrEnd, - ShStrMid, ShUnknown, -}; -pub use crate::v2_std_core::{make_file_span, Token, TokenShape}; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{SourceSpan}; +pub use crate::v2_std_core::{make_file_span, Token, TokenShape}; +use crate::v2_std_core::TokenShape::{ShKeyword, ShLBrace, ShRBrace, ShLParen, ShRParen, ShLBracket, ShRBracket, ShLt, ShGt, ShLe, ShGe, ShFatArrow, ShArrow, ShColon, ShComma, ShDot, ShDotDot, ShEq, ShEqEq, ShNe, ShPlus, ShMinus, ShStar, ShSlash, ShPercent, ShBang, ShAnd, ShOr, ShQuestion, ShNullCoalesce, ShPipe, ShPipeArrow, ShLitStr, ShLitInt, ShLitFloat, ShIdent, ShStrBegin, ShStrMid, ShStrEnd, ShNewline, ShEof, ShUnknown}; +pub use crate::extdeps_languages_dag_syntax::{dag_keyword_set}; +use self::StringScanResult::*; pub fn is_keyword_text(text: String) -> bool { match v2_rt::lookup(&dag_keyword_set(), text) { - Some(_) => true, - None => false, - } + Some(_) => true, + None => false, +} } pub fn single_punct() -> Rc> { @@ -75,10 +69,10 @@ pub struct SourceRef { pub fn make_token(text: String, span: Rc, shape: TokenShape) -> Rc { Rc::new(Token { - text: text, - span: span, - shape: shape, - }) + text: text, + span: span, + shape: shape, +}) } pub fn source_char(source: Rc, pos: i64) -> String { @@ -93,520 +87,316 @@ pub fn source_substring(source: Rc, start: i64, end: i64) -> String { v2_rt::chars_to_string(&source.source_chars.clone(), start, end) } -pub fn source_scan_while( - mut source: Rc, - mut start: i64, - mut pred: impl Fn(String) -> bool + Clone, -) -> i64 { +pub fn source_scan_while(mut source: Rc, mut start: i64, mut pred: impl Fn(String) -> bool + Clone) -> i64 { loop { if (start.clone() >= source_len(source.clone())) { break source_len(source.clone()); - } else { - if pred(v2_rt::from_code_point( - source.source_chars.clone()[(start.clone()) as usize].clone(), - )) { +} else { + if pred(v2_rt::from_code_point(source.source_chars.clone()[(start.clone()) as usize].clone())) { { let __tco_0 = (start + 1); - start = __tco_0; - continue; - } - } else { +start = __tco_0; +continue; +} +} else { break start.clone(); - } - } - } +} +} +} } pub fn source_skip_ws(mut source: Rc, mut start: i64) -> i64 { loop { if (start.clone() >= source_len(source.clone())) { break start.clone(); - } else { +} else { let ch = source.source_chars.clone()[(start.clone()) as usize].clone(); - if ((ch.clone() == v2_rt::code_point(" ".to_string())) - || (ch.clone() == v2_rt::code_point("\t".to_string()))) - { +if ((ch.clone() == v2_rt::code_point(" ".to_string())) || (ch.clone() == v2_rt::code_point("\t".to_string()))) { { let __tco_0 = (start + 1); - start = __tco_0; - continue; - } - } else { +start = __tco_0; +continue; +} +} else { break start.clone(); - } - } - } +} +} +} } pub fn source_scan_to_eol(mut source: Rc, mut start: i64) -> i64 { loop { if (start.clone() >= source_len(source.clone())) { break source_len(source.clone()); - } else { - if (source.source_chars.clone()[(start.clone()) as usize].clone() - == v2_rt::code_point("\n".to_string())) - { +} else { + if (source.source_chars.clone()[(start.clone()) as usize].clone() == v2_rt::code_point("\n".to_string())) { break start.clone(); - } else { +} else { { let __tco_0 = (start + 1); - start = __tco_0; - continue; - } - } - } - } +start = __tco_0; +continue; +} +} +} +} } pub fn tokenize(source: &String, file: String) -> Rc>> { { let c = Rc::new(source.clone().chars().map(|c| c as i64).collect::>()); - let src = Rc::new(SourceRef { - file: file, - text: source.clone(), - source_chars: c, - }); - let initial = Rc::new(TokPos { - pos: 0, - interp_depth: Rc::new(vec![]), - }); - let final_state = tokenize_loop( - src.clone(), - Rc::new(vec![]), - initial, - (source_len(src.clone()) + 1), - ); - let eof_span = make_file_span( - src.file.clone(), - final_state.pos.clone(), - final_state.pos.clone(), - ); - v2_rt::rc_list_push( - final_state.tokens.clone(), - make_token("".to_string(), eof_span, TokenShape::ShEof), - ) - } +let src = Rc::new(SourceRef { + file: file, + text: source.clone(), + source_chars: c, +}); +let initial = Rc::new(TokPos { + pos: 0, + interp_depth: Rc::new(vec![]), +}); +let final_state = tokenize_loop(src.clone(), Rc::new(vec![]), initial, (source_len(src.clone()) + 1)); +let eof_span = make_file_span(src.file.clone(), final_state.pos.clone(), final_state.pos.clone()); +v2_rt::rc_list_push(final_state.tokens.clone(), make_token("".to_string(), eof_span, TokenShape::ShEof)) +} } pub fn scan_next_token(source: &Rc, pos: &Rc) -> Rc { { let ch = source_char(source.clone(), pos.pos.clone()); - if (ch.clone().as_str() == "\n".to_string().as_str()) { +if (ch.clone().as_str() == "\n".to_string().as_str()) { return Rc::new(ScanResult { - pos: (pos.pos.clone() + 1), - token: make_token( - "\n".to_string(), - make_file_span(source.file.clone(), pos.pos.clone(), (pos.pos.clone() + 1)), - TokenShape::ShNewline, - ), - interp_depth: pos.interp_depth.clone(), - }); + pos: (pos.pos.clone() + 1), + token: make_token("\n".to_string(), make_file_span(source.file.clone(), pos.pos.clone(), (pos.pos.clone() + 1)), TokenShape::ShNewline), + interp_depth: pos.interp_depth.clone(), +}) } - if ((ch.clone().as_str() == "}".to_string().as_str()) - && ((pos.interp_depth.clone().len() as i64) > 0)) - { +if ((ch.clone().as_str() == "}".to_string().as_str()) && ((pos.interp_depth.clone().len() as i64) > 0)) { { let top = pos.interp_depth.clone().last().cloned().clone().unwrap(); - if (top.clone() == 0) { +if (top.clone() == 0) { { let popped = drop_last(&pos.interp_depth.clone()); - let cont_pos = Rc::new(TokPos { - pos: (pos.pos.clone() + 1), - interp_depth: popped, - }); - return scan_str_cont(&source, &cont_pos, pos.pos.clone()); - } +let cont_pos = Rc::new(TokPos { + pos: (pos.pos.clone() + 1), + interp_depth: popped, +}); +return scan_str_cont(&source, &cont_pos, pos.pos.clone()) +} } else { return Rc::new(ScanResult { - pos: (pos.pos.clone() + 1), - token: make_token( - "}".to_string(), - make_file_span( - source.file.clone(), - pos.pos.clone(), - (pos.pos.clone() + 1), - ), - TokenShape::ShRBrace, - ), - interp_depth: replace_last(pos.interp_depth.clone(), (top.clone() - 1)), - }); + pos: (pos.pos.clone() + 1), + token: make_token("}".to_string(), make_file_span(source.file.clone(), pos.pos.clone(), (pos.pos.clone() + 1)), TokenShape::ShRBrace), + interp_depth: replace_last(pos.interp_depth.clone(), (top.clone() - 1)), +}) } - } +} } - scan_token(&source, &pos, &ch) - } +scan_token(&source, &pos, &ch) +} } -pub fn tokenize_loop( - mut source: Rc, - mut tokens: Rc>>, - mut pos: Rc, - mut fuel: i64, -) -> Rc { +pub fn tokenize_loop(mut source: Rc, mut tokens: Rc>>, mut pos: Rc, mut fuel: i64) -> Rc { loop { let s = skip_spaces_and_comments(source.clone(), pos, fuel.clone()); - if (s.pos.clone() >= source_len(source.clone())) { +if (s.pos.clone() >= source_len(source.clone())) { return Rc::new(TokenizerState { - pos: s.pos.clone(), - tokens: tokens.clone(), - interp_depth: s.interp_depth.clone(), - }); + pos: s.pos.clone(), + tokens: tokens.clone(), + interp_depth: s.interp_depth.clone(), +}) } - let result = scan_next_token(&source, &s); - { +let result = scan_next_token(&source, &s); +{ let __tco_0 = v2_rt::rc_list_push(tokens, result.token.clone()); - let __tco_1 = Rc::new(TokPos { - pos: result.pos.clone(), - interp_depth: result.interp_depth.clone(), - }); - let __tco_2 = (fuel - 1); - tokens = __tco_0; - pos = __tco_1; - fuel = __tco_2; - continue; - } - } +let __tco_1 = Rc::new(TokPos { + pos: result.pos.clone(), + interp_depth: result.interp_depth.clone(), +}); +let __tco_2 = (fuel - 1); +tokens = __tco_0; +pos = __tco_1; +fuel = __tco_2; +continue; +} +} } pub fn scan_token(source: &Rc, pos: &Rc, ch: &String) -> Rc { { if (ch.clone().as_str() == "\"".to_string().as_str()) { - return scan_string(&source, &pos); + return scan_string(&source, &pos) } - if is_digit(ch.clone()) { - return scan_number(&source, &pos); +if is_digit(ch.clone()) { + return scan_number(&source, &pos) } - if is_ident_start(&ch) { - return scan_ident(&source, &pos); +if is_ident_start(&ch) { + return scan_ident(&source, &pos) } - let next_ch = if ((pos.pos.clone() + 1) < source_len(source.clone())) { +let next_ch = if ((pos.pos.clone() + 1) < source_len(source.clone())) { source_char(source.clone(), (pos.pos.clone() + 1)) } else { "".to_string() }; - if ((ch.clone().as_str() == "=".to_string().as_str()) - && (next_ch.clone().as_str() == ">".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShFatArrow, - "=>".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "=".to_string().as_str()) && (next_ch.clone().as_str() == ">".to_string().as_str())) { + return emit(&pos, TokenShape::ShFatArrow, "=>".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == "-".to_string().as_str()) - && (next_ch.clone().as_str() == ">".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShArrow, - "->".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "-".to_string().as_str()) && (next_ch.clone().as_str() == ">".to_string().as_str())) { + return emit(&pos, TokenShape::ShArrow, "->".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == "=".to_string().as_str()) - && (next_ch.clone().as_str() == "=".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShEqEq, - "==".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "=".to_string().as_str()) && (next_ch.clone().as_str() == "=".to_string().as_str())) { + return emit(&pos, TokenShape::ShEqEq, "==".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == "!".to_string().as_str()) - && (next_ch.clone().as_str() == "=".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShNe, - "!=".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "!".to_string().as_str()) && (next_ch.clone().as_str() == "=".to_string().as_str())) { + return emit(&pos, TokenShape::ShNe, "!=".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == "<".to_string().as_str()) - && (next_ch.clone().as_str() == "=".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShLe, - "<=".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "<".to_string().as_str()) && (next_ch.clone().as_str() == "=".to_string().as_str())) { + return emit(&pos, TokenShape::ShLe, "<=".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == ">".to_string().as_str()) - && (next_ch.clone().as_str() == "=".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShGe, - ">=".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == ">".to_string().as_str()) && (next_ch.clone().as_str() == "=".to_string().as_str())) { + return emit(&pos, TokenShape::ShGe, ">=".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == "&".to_string().as_str()) - && (next_ch.clone().as_str() == "&".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShAnd, - "&&".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "&".to_string().as_str()) && (next_ch.clone().as_str() == "&".to_string().as_str())) { + return emit(&pos, TokenShape::ShAnd, "&&".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == "|".to_string().as_str()) - && (next_ch.clone().as_str() == "|".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShOr, - "||".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "|".to_string().as_str()) && (next_ch.clone().as_str() == "|".to_string().as_str())) { + return emit(&pos, TokenShape::ShOr, "||".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == "|".to_string().as_str()) - && (next_ch.clone().as_str() == ">".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShPipeArrow, - "|>".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "|".to_string().as_str()) && (next_ch.clone().as_str() == ">".to_string().as_str())) { + return emit(&pos, TokenShape::ShPipeArrow, "|>".to_string(), 2, source.file.clone()) } - if (ch.clone().as_str() == "|".to_string().as_str()) { - return emit( - &pos, - TokenShape::ShPipe, - "|".to_string(), - 1, - source.file.clone(), - ); +if (ch.clone().as_str() == "|".to_string().as_str()) { + return emit(&pos, TokenShape::ShPipe, "|".to_string(), 1, source.file.clone()) } - if ((ch.clone().as_str() == "?".to_string().as_str()) - && (next_ch.clone().as_str() == "?".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShNullCoalesce, - "??".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == "?".to_string().as_str()) && (next_ch.clone().as_str() == "?".to_string().as_str())) { + return emit(&pos, TokenShape::ShNullCoalesce, "??".to_string(), 2, source.file.clone()) } - if ((ch.clone().as_str() == ".".to_string().as_str()) - && (next_ch.clone().as_str() == ".".to_string().as_str())) - { - return emit( - &pos, - TokenShape::ShDotDot, - "..".to_string(), - 2, - source.file.clone(), - ); +if ((ch.clone().as_str() == ".".to_string().as_str()) && (next_ch.clone().as_str() == ".".to_string().as_str())) { + return emit(&pos, TokenShape::ShDotDot, "..".to_string(), 2, source.file.clone()) } - if (ch.clone().as_str() == "=".to_string().as_str()) { - return emit( - &pos, - TokenShape::ShEq, - "=".to_string(), - 1, - source.file.clone(), - ); +if (ch.clone().as_str() == "=".to_string().as_str()) { + return emit(&pos, TokenShape::ShEq, "=".to_string(), 1, source.file.clone()) } - if (ch.clone().as_str() == "<".to_string().as_str()) { - return emit( - &pos, - TokenShape::ShLt, - "<".to_string(), - 1, - source.file.clone(), - ); +if (ch.clone().as_str() == "<".to_string().as_str()) { + return emit(&pos, TokenShape::ShLt, "<".to_string(), 1, source.file.clone()) } - if (ch.clone().as_str() == ">".to_string().as_str()) { - return emit( - &pos, - TokenShape::ShGt, - ">".to_string(), - 1, - source.file.clone(), - ); +if (ch.clone().as_str() == ">".to_string().as_str()) { + return emit(&pos, TokenShape::ShGt, ">".to_string(), 1, source.file.clone()) } - if (ch.clone().as_str() == "-".to_string().as_str()) { - return emit( - &pos, - TokenShape::ShMinus, - "-".to_string(), - 1, - source.file.clone(), - ); +if (ch.clone().as_str() == "-".to_string().as_str()) { + return emit(&pos, TokenShape::ShMinus, "-".to_string(), 1, source.file.clone()) } - if (ch.clone().as_str() == "!".to_string().as_str()) { - return emit( - &pos, - TokenShape::ShBang, - "!".to_string(), - 1, - source.file.clone(), - ); +if (ch.clone().as_str() == "!".to_string().as_str()) { + return emit(&pos, TokenShape::ShBang, "!".to_string(), 1, source.file.clone()) } - if (ch.clone().as_str() == "?".to_string().as_str()) { - return emit( - &pos, - TokenShape::ShQuestion, - "?".to_string(), - 1, - source.file.clone(), - ); +if (ch.clone().as_str() == "?".to_string().as_str()) { + return emit(&pos, TokenShape::ShQuestion, "?".to_string(), 1, source.file.clone()) } - if (ch.clone().as_str() == "{".to_string().as_str()) { +if (ch.clone().as_str() == "{".to_string().as_str()) { { let new_depth = if ((pos.interp_depth.clone().len() as i64) > 0) { - replace_last( - pos.interp_depth.clone(), - (pos.interp_depth.clone().last().cloned().clone().unwrap() + 1), - ) + replace_last(pos.interp_depth.clone(), (pos.interp_depth.clone().last().cloned().clone().unwrap() + 1)) } else { pos.interp_depth.clone() }; - let tok = make_token( - "{".to_string(), - make_file_span(source.file.clone(), pos.pos.clone(), (pos.pos.clone() + 1)), - TokenShape::ShLBrace, - ); - return Rc::new(ScanResult { - pos: (pos.pos.clone() + 1), - token: tok.clone(), - interp_depth: new_depth, - }); - } +let tok = make_token("{".to_string(), make_file_span(source.file.clone(), pos.pos.clone(), (pos.pos.clone() + 1)), TokenShape::ShLBrace); +return Rc::new(ScanResult { + pos: (pos.pos.clone() + 1), + token: tok.clone(), + interp_depth: new_depth, +}) +} } - if (ch.clone().as_str() == "}".to_string().as_str()) { +if (ch.clone().as_str() == "}".to_string().as_str()) { { - let tok = make_token( - "}".to_string(), - make_file_span(source.file.clone(), pos.pos.clone(), (pos.pos.clone() + 1)), - TokenShape::ShRBrace, - ); - return Rc::new(ScanResult { - pos: (pos.pos.clone() + 1), - token: tok.clone(), - interp_depth: pos.interp_depth.clone(), - }); - } - } - match v2_rt::lookup(&single_punct(), ch.clone()) { - Some(sh) => emit(&pos, sh.clone(), ch.clone(), 1, source.file.clone()), - None => emit( - &pos, - TokenShape::ShUnknown, - ch.clone(), - 1, - source.file.clone(), - ), + let tok = make_token("}".to_string(), make_file_span(source.file.clone(), pos.pos.clone(), (pos.pos.clone() + 1)), TokenShape::ShRBrace); +return Rc::new(ScanResult { + pos: (pos.pos.clone() + 1), + token: tok.clone(), + interp_depth: pos.interp_depth.clone(), +}) +} } - } +match v2_rt::lookup(&single_punct(), ch.clone()) { + Some(sh) => emit(&pos, sh.clone(), ch.clone(), 1, source.file.clone()), + None => emit(&pos, TokenShape::ShUnknown, ch.clone(), 1, source.file.clone()), +} +} } -pub fn emit( - pos: &Rc, - shape: TokenShape, - text: String, - len: i64, - file: String, -) -> Rc { +pub fn emit(pos: &Rc, shape: TokenShape, text: String, len: i64, file: String) -> Rc { { - let token = make_token( - text, - make_file_span(file, pos.pos.clone(), (pos.pos.clone() + len.clone())), - shape, - ); - Rc::new(ScanResult { - pos: (pos.pos.clone() + len.clone()), - token: token, - interp_depth: pos.interp_depth.clone(), - }) - } + let token = make_token(text, make_file_span(file, pos.pos.clone(), (pos.pos.clone() + len.clone())), shape); +Rc::new(ScanResult { + pos: (pos.pos.clone() + len.clone()), + token: token, + interp_depth: pos.interp_depth.clone(), +}) +} } pub fn scan_ident(source: &Rc, pos: &Rc) -> Rc { { let end = source_scan_while(source.clone(), pos.pos.clone(), is_ident_char); - let text = source_substring(source.clone(), pos.pos.clone(), end.clone()); - let shape = if is_keyword_text(text.clone()) { +let text = source_substring(source.clone(), pos.pos.clone(), end.clone()); +let shape = if is_keyword_text(text.clone()) { TokenShape::ShKeyword } else { TokenShape::ShIdent }; - let token = make_token( - text.clone(), - make_file_span(source.file.clone(), pos.pos.clone(), end.clone()), - shape, - ); - Rc::new(ScanResult { - pos: end.clone(), - token: token, - interp_depth: pos.interp_depth.clone(), - }) - } +let token = make_token(text.clone(), make_file_span(source.file.clone(), pos.pos.clone(), end.clone()), shape); +Rc::new(ScanResult { + pos: end.clone(), + token: token, + interp_depth: pos.interp_depth.clone(), +}) +} } pub fn scan_number(source: &Rc, pos: &Rc) -> Rc { { let int_end = source_scan_while(source.clone(), pos.pos.clone(), is_digit); - if ((((int_end.clone() + 1) < source_len(source.clone())) - && (source_char(source.clone(), int_end.clone()).as_str() == ".".to_string().as_str())) - && is_digit(source_char(source.clone(), (int_end.clone() + 1)))) - { +if ((((int_end.clone() + 1) < source_len(source.clone())) && (source_char(source.clone(), int_end.clone()).as_str() == ".".to_string().as_str())) && is_digit(source_char(source.clone(), (int_end.clone() + 1)))) { { let frac_end = source_scan_while(source.clone(), (int_end.clone() + 1), is_digit); - let text = source_substring(source.clone(), pos.pos.clone(), frac_end.clone()); - let token = make_token( - text.clone(), - make_file_span(source.file.clone(), pos.pos.clone(), frac_end.clone()), - TokenShape::ShLitFloat, - ); - return Rc::new(ScanResult { - pos: frac_end.clone(), - token: token.clone(), - interp_depth: pos.interp_depth.clone(), - }); - } - } - let text = source_substring(source.clone(), pos.pos.clone(), int_end.clone()); - let parsed = v2_rt::parse_int(text.clone()); - let shape = match parsed { - Some(_) => TokenShape::ShLitInt, - None => TokenShape::ShUnknown, - }; - let token = make_token( - text.clone(), - make_file_span(source.file.clone(), pos.pos.clone(), int_end.clone()), - shape, - ); - Rc::new(ScanResult { - pos: int_end.clone(), - token: token.clone(), - interp_depth: pos.interp_depth.clone(), - }) - } +let text = source_substring(source.clone(), pos.pos.clone(), frac_end.clone()); +let token = make_token(text.clone(), make_file_span(source.file.clone(), pos.pos.clone(), frac_end.clone()), TokenShape::ShLitFloat); +return Rc::new(ScanResult { + pos: frac_end.clone(), + token: token.clone(), + interp_depth: pos.interp_depth.clone(), +}) +} + } +let text = source_substring(source.clone(), pos.pos.clone(), int_end.clone()); +let parsed = v2_rt::parse_int(text.clone()); +let shape = match parsed { + Some(_) => TokenShape::ShLitInt, + None => TokenShape::ShUnknown, +}; +let token = make_token(text.clone(), make_file_span(source.file.clone(), pos.pos.clone(), int_end.clone()), shape); +Rc::new(ScanResult { + pos: int_end.clone(), + token: token.clone(), + interp_depth: pos.interp_depth.clone(), +}) +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum StringScanResult { - ClosedString { content: String, end_pos: i64 }, - InterpolationStart { content: String, end_pos: i64 }, - UnterminatedString { content: String, end_pos: i64 }, + ClosedString { + content: String, + end_pos: i64, + }, + InterpolationStart { + content: String, + end_pos: i64, + }, + UnterminatedString { + content: String, + end_pos: i64, + }, } impl StringScanResult { pub fn content(&self) -> String { @@ -628,179 +418,135 @@ impl StringScanResult { pub fn scan_string(source: &Rc, pos: &Rc) -> Rc { { let span_start = pos.pos.clone(); - let body_start = (pos.pos.clone() + 1); - let result = scan_string_body(source.clone(), body_start, Rc::new(vec![])); - match (*result).clone() { - StringScanResult::ClosedString { - content, end_pos, .. - } => { - let processed = process_escapes(content.clone()); - let token = make_token( - processed, - make_file_span(source.file.clone(), span_start, (end_pos.clone() + 1)), - TokenShape::ShLitStr, - ); - Rc::new(ScanResult { - pos: (end_pos.clone() + 1), - token: token, - interp_depth: pos.interp_depth.clone(), - }) - } - StringScanResult::InterpolationStart { - content, end_pos, .. - } => { - let processed = process_escapes(content.clone()); - let token = make_token( - processed, - make_file_span(source.file.clone(), span_start, (end_pos.clone() + 1)), - TokenShape::ShStrBegin, - ); - Rc::new(ScanResult { - pos: (end_pos.clone() + 1), - token: token, - interp_depth: Rc::new(v2_rt::append(pos.interp_depth.clone(), 0)), - }) - } - StringScanResult::UnterminatedString { - content, end_pos, .. - } => { - let processed = process_escapes(content.clone()); - let token = make_token( - processed, - make_file_span(source.file.clone(), span_start, end_pos.clone()), - TokenShape::ShUnknown, - ); - Rc::new(ScanResult { - pos: end_pos.clone(), - token: token, - interp_depth: pos.interp_depth.clone(), - }) - } - } - } +let body_start = (pos.pos.clone() + 1); +let result = scan_string_body(source.clone(), body_start, Rc::new(vec![])); +match (*result).clone() { + StringScanResult::ClosedString { content, end_pos, .. } => { + let processed = process_escapes(content.clone()); +let token = make_token(processed, make_file_span(source.file.clone(), span_start, (end_pos.clone() + 1)), TokenShape::ShLitStr); +Rc::new(ScanResult { + pos: (end_pos.clone() + 1), + token: token, + interp_depth: pos.interp_depth.clone(), +}) +}, + StringScanResult::InterpolationStart { content, end_pos, .. } => { + let processed = process_escapes(content.clone()); +let token = make_token(processed, make_file_span(source.file.clone(), span_start, (end_pos.clone() + 1)), TokenShape::ShStrBegin); +Rc::new(ScanResult { + pos: (end_pos.clone() + 1), + token: token, + interp_depth: Rc::new(v2_rt::append(pos.interp_depth.clone(), 0)), +}) +}, + StringScanResult::UnterminatedString { content, end_pos, .. } => { + let processed = process_escapes(content.clone()); +let token = make_token(processed, make_file_span(source.file.clone(), span_start, end_pos.clone()), TokenShape::ShUnknown); +Rc::new(ScanResult { + pos: end_pos.clone(), + token: token, + interp_depth: pos.interp_depth.clone(), +}) +}, +} +} } pub fn scan_str_cont(source: &Rc, pos: &Rc, span_start: i64) -> Rc { { let result = scan_string_body(source.clone(), pos.pos.clone(), Rc::new(vec![])); - match (*result).clone() { - StringScanResult::ClosedString { - content, end_pos, .. - } => { - let processed = process_escapes(content.clone()); - let token = make_token( - processed, - make_file_span(source.file.clone(), span_start, (end_pos.clone() + 1)), - TokenShape::ShStrEnd, - ); - Rc::new(ScanResult { - pos: (end_pos.clone() + 1), - token: token, - interp_depth: pos.interp_depth.clone(), - }) - } - StringScanResult::InterpolationStart { - content, end_pos, .. - } => { - let processed = process_escapes(content.clone()); - let token = make_token( - processed, - make_file_span(source.file.clone(), span_start, (end_pos.clone() + 1)), - TokenShape::ShStrMid, - ); - Rc::new(ScanResult { - pos: (end_pos.clone() + 1), - token: token, - interp_depth: Rc::new(v2_rt::append(pos.interp_depth.clone(), 0)), - }) - } - StringScanResult::UnterminatedString { - content, end_pos, .. - } => { - let processed = process_escapes(content.clone()); - let token = make_token( - processed, - make_file_span(source.file.clone(), span_start, end_pos.clone()), - TokenShape::ShUnknown, - ); - Rc::new(ScanResult { - pos: end_pos.clone(), - token: token, - interp_depth: pos.interp_depth.clone(), - }) - } - } - } -} - -pub fn scan_string_body( - mut source: Rc, - mut pos: i64, - mut acc: Rc>, -) -> Rc { +match (*result).clone() { + StringScanResult::ClosedString { content, end_pos, .. } => { + let processed = process_escapes(content.clone()); +let token = make_token(processed, make_file_span(source.file.clone(), span_start, (end_pos.clone() + 1)), TokenShape::ShStrEnd); +Rc::new(ScanResult { + pos: (end_pos.clone() + 1), + token: token, + interp_depth: pos.interp_depth.clone(), +}) +}, + StringScanResult::InterpolationStart { content, end_pos, .. } => { + let processed = process_escapes(content.clone()); +let token = make_token(processed, make_file_span(source.file.clone(), span_start, (end_pos.clone() + 1)), TokenShape::ShStrMid); +Rc::new(ScanResult { + pos: (end_pos.clone() + 1), + token: token, + interp_depth: Rc::new(v2_rt::append(pos.interp_depth.clone(), 0)), +}) +}, + StringScanResult::UnterminatedString { content, end_pos, .. } => { + let processed = process_escapes(content.clone()); +let token = make_token(processed, make_file_span(source.file.clone(), span_start, end_pos.clone()), TokenShape::ShUnknown); +Rc::new(ScanResult { + pos: end_pos.clone(), + token: token, + interp_depth: pos.interp_depth.clone(), +}) +}, +} +} +} + +pub fn scan_string_body(mut source: Rc, mut pos: i64, mut acc: Rc>) -> Rc { loop { if (pos.clone() >= source_len(source.clone())) { break Rc::new(StringScanResult::UnterminatedString { - content: acc.join(&"".to_string()), - end_pos: pos.clone(), - }); - } else { + content: acc.join(&"".to_string()), + end_pos: pos.clone(), +}); +} else { let ch = source_char(source.clone(), pos.clone()); - if (ch.clone().as_str() == "\"".to_string().as_str()) { +if (ch.clone().as_str() == "\"".to_string().as_str()) { break Rc::new(StringScanResult::ClosedString { - content: acc.join(&"".to_string()), - end_pos: pos.clone(), - }); - } else { + content: acc.join(&"".to_string()), + end_pos: pos.clone(), +}); +} else { if (ch.clone().as_str() == "\\".to_string().as_str()) { if ((pos.clone() + 1) < source_len(source.clone())) { let escaped = source_char(source.clone(), (pos.clone() + 1)); - { +{ let __tco_0 = (pos + 2); - let __tco_1 = v2_rt::rc_list_push( - v2_rt::rc_list_push(acc, "\\".to_string()), - escaped, - ); - pos = __tco_0; - acc = __tco_1; - continue; - } - } else { +let __tco_1 = v2_rt::rc_list_push(v2_rt::rc_list_push(acc, "\\".to_string()), escaped); +pos = __tco_0; +acc = __tco_1; +continue; +} +} else { break Rc::new(StringScanResult::UnterminatedString { - content: v2_rt::rc_list_push(acc, "\\".to_string()) - .join(&"".to_string()), - end_pos: (pos.clone() + 1), - }); - } - } else { + content: v2_rt::rc_list_push(acc, "\\".to_string()).join(&"".to_string()), + end_pos: (pos.clone() + 1), +}); +} +} else { if (ch.clone().as_str() == "{".to_string().as_str()) { if should_start_interpolation(&source, pos.clone()) { break Rc::new(StringScanResult::InterpolationStart { - content: acc.join(&"".to_string()), - end_pos: pos.clone(), - }); - } else { + content: acc.join(&"".to_string()), + end_pos: pos.clone(), +}); +} else { { let __tco_0 = (pos + 1); - let __tco_1 = v2_rt::rc_list_push(acc, "{".to_string()); - pos = __tco_0; - acc = __tco_1; - continue; - } - } - } else { +let __tco_1 = v2_rt::rc_list_push(acc, "{".to_string()); +pos = __tco_0; +acc = __tco_1; +continue; +} +} +} else { { let __tco_0 = (pos + 1); - let __tco_1 = v2_rt::rc_list_push(acc, ch.clone()); - pos = __tco_0; - acc = __tco_1; - continue; - } - } - } - } - } - } +let __tco_1 = v2_rt::rc_list_push(acc, ch.clone()); +pos = __tco_0; +acc = __tco_1; +continue; +} +} +} +} +} +} } pub fn should_start_interpolation(source: &Rc, pos: i64) -> bool { @@ -809,10 +555,8 @@ pub fn should_start_interpolation(source: &Rc, pos: i64) -> bool { } else { { let next = source_char(source.clone(), (pos.clone() + 1)); - (((is_ident_start(&next) || (next.clone().as_str() == "(".to_string().as_str())) - || (next.clone().as_str() == "!".to_string().as_str())) - || (next.clone().as_str() == "-".to_string().as_str())) - } +(((is_ident_start(&next) || (next.clone().as_str() == "(".to_string().as_str())) || (next.clone().as_str() == "!".to_string().as_str())) || (next.clone().as_str() == "-".to_string().as_str())) +} } } @@ -824,13 +568,11 @@ pub fn process_escapes_loop(mut source: String, mut pos: i64, mut acc: Rc= v2_rt::string_length(&source)) { break acc.join(&"".to_string()); - } else { +} else { let ch = v2_rt::char_at(&source, pos.clone()); - if ((ch.clone().as_str() == "\\".to_string().as_str()) - && ((pos.clone() + 1) < v2_rt::string_length(&source))) - { +if ((ch.clone().as_str() == "\\".to_string().as_str()) && ((pos.clone() + 1) < v2_rt::string_length(&source))) { let next = v2_rt::char_at(&source, (pos.clone() + 1)); - let resolved = if (next.clone().as_str() == "\"".to_string().as_str()) { +let resolved = if (next.clone().as_str() == "\"".to_string().as_str()) { "\"".to_string() } else { if (next.clone().as_str() == "\\".to_string().as_str()) { @@ -855,85 +597,61 @@ pub fn process_escapes_loop(mut source: String, mut pos: i64, mut acc: Rc>) -> Rc> { { let len = (stack.clone().len() as i64); - Rc::new( - stack - .clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold(Rc::new(vec![]), |result: Rc>, pair: (i64, i64)| { - if (pair.0.clone() < (len.clone() - 1)) { - Rc::new(v2_rt::append(result.clone(), pair.1.clone())) - } else { - result.clone() - } +Rc::new(stack.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(Rc::new(vec![]), |result: Rc>, pair: (i64, i64)| if (pair.0.clone() < (len.clone() - 1)) { + Rc::new(v2_rt::append(result.clone(), pair.1.clone())) + } else { + result.clone() }) - } +} } pub fn replace_last(stack: Rc>, value: i64) -> Rc> { { let prefix = drop_last(&stack); - Rc::new(v2_rt::append(prefix, value)) - } +Rc::new(v2_rt::append(prefix, value)) +} } -pub fn skip_spaces_and_comments( - mut source: Rc, - mut pos: Rc, - mut fuel: i64, -) -> Rc { +pub fn skip_spaces_and_comments(mut source: Rc, mut pos: Rc, mut fuel: i64) -> Rc { loop { let p = source_skip_ws(source.clone(), pos.pos.clone()); - if ((((p.clone() + 1) < source_len(source.clone())) - && (source_char(source.clone(), p.clone()).as_str() == "/".to_string().as_str())) - && (source_char(source.clone(), (p.clone() + 1)).as_str() == "/".to_string().as_str())) - { +if ((((p.clone() + 1) < source_len(source.clone())) && (source_char(source.clone(), p.clone()).as_str() == "/".to_string().as_str())) && (source_char(source.clone(), (p.clone() + 1)).as_str() == "/".to_string().as_str())) { { let eol = source_scan_to_eol(source.clone(), p.clone()); - return skip_spaces_and_comments( - source.clone(), - Rc::new(TokPos { - pos: eol, - interp_depth: pos.interp_depth.clone(), - }), - (fuel - 1), - ); - } +return skip_spaces_and_comments(source.clone(), Rc::new(TokPos { + pos: eol, + interp_depth: pos.interp_depth.clone(), +}), (fuel - 1)) +} } - break Rc::new(TokPos { - pos: p.clone(), - interp_depth: pos.interp_depth.clone(), - }); - } +break Rc::new(TokPos { + pos: p.clone(), + interp_depth: pos.interp_depth.clone(), +}); +} } pub fn is_digit(ch: String) -> bool { @@ -941,9 +659,7 @@ pub fn is_digit(ch: String) -> bool { } pub fn is_ident_start(ch: &String) -> bool { - ((((ch.clone() >= "a".to_string()) && (ch.clone() <= "z".to_string())) - || ((ch.clone() >= "A".to_string()) && (ch.clone() <= "Z".to_string()))) - || (ch.clone().as_str() == "_".to_string().as_str())) + ((((ch.clone() >= "a".to_string()) && (ch.clone() <= "z".to_string())) || ((ch.clone() >= "A".to_string()) && (ch.clone() <= "Z".to_string()))) || (ch.clone().as_str() == "_".to_string().as_str())) } pub fn is_ident_char(ch: String) -> bool { diff --git a/src/v2/stage0/src/v2_compiler_trace.rs b/src/v2/stage0/src/v2_compiler_trace.rs index 33e848a24bd..5fe94ef6c4b 100644 --- a/src/v2/stage0/src/v2_compiler_trace.rs +++ b/src/v2/stage0/src/v2_compiler_trace.rs @@ -1,14 +1,14 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.compiler.trace -use self::TraceEvent::*; -use self::TraceFilter::*; -use crate::v2_rt; -pub use crate::v2_std_core::SourceSpan; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; use std::collections::HashMap; use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::v2_std_core::{SourceSpan}; +use self::TraceEvent::*; +use self::TraceFilter::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct SpanMapping { @@ -67,193 +67,103 @@ pub struct Trace { pub fn empty_trace() -> Rc { Rc::new(Trace { - events: Rc::new(vec![]), - stack: Rc::new(vec![]), - }) + events: Rc::new(vec![]), + stack: Rc::new(vec![]), +}) } pub fn trace_push_event(trace: &Rc, event: Rc) -> Rc { Rc::new(Trace { - events: v2_rt::rc_list_push(trace.events.clone(), event), - stack: trace.stack.clone(), - }) + events: v2_rt::rc_list_push(trace.events.clone(), event), + stack: trace.stack.clone(), +}) } pub fn trace_push_frame(trace: &Rc, frame: Rc) -> Rc { Rc::new(Trace { - events: trace.events.clone(), - stack: v2_rt::rc_list_push(trace.stack.clone(), frame), - }) + events: trace.events.clone(), + stack: v2_rt::rc_list_push(trace.stack.clone(), frame), +}) } pub fn trace_pop_frame(trace: &Rc) -> Rc { { let n = (trace.stack.clone().len() as i64); - if (n.clone() <= 1) { +if (n.clone() <= 1) { Rc::new(Trace { - events: trace.events.clone(), - stack: Rc::new(vec![]), - }) + events: trace.events.clone(), + stack: Rc::new(vec![]), +}) } else { Rc::new(Trace { - events: trace.events.clone(), - stack: Rc::new( - trace - .stack - .clone() - .iter() - .cloned() - .take((n.clone() - 1) as usize) - .collect::>(), - ), - }) + events: trace.events.clone(), + stack: Rc::new(trace.stack.clone().iter().cloned().take((n.clone() - 1) as usize).collect::>()), +}) } - } +} } pub fn event_span(event: Rc) -> Rc { match (*event).clone() { - TraceEvent::TraceEnter { span: s, .. } => s.clone(), - TraceEvent::TraceExit { span: s, .. } => s.clone(), - TraceEvent::TraceError { span: s, .. } => s.clone(), - } + TraceEvent::TraceEnter { span: s, .. } => s.clone(), + TraceEvent::TraceExit { span: s, .. } => s.clone(), + TraceEvent::TraceError { span: s, .. } => s.clone(), +} } pub fn event_node_id(event: Rc) -> String { match (*event).clone() { - TraceEvent::TraceEnter { node_id: id, .. } => id.clone(), - TraceEvent::TraceExit { node_id: id, .. } => id.clone(), - TraceEvent::TraceError { node_id: id, .. } => id.clone(), - } + TraceEvent::TraceEnter { node_id: id, .. } => id.clone(), + TraceEvent::TraceExit { node_id: id, .. } => id.clone(), + TraceEvent::TraceError { node_id: id, .. } => id.clone(), +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum TraceFilter { - FilterByFunc { func_name: String }, - FilterBySpan { start: i64, end: i64 }, + FilterByFunc { + func_name: String, + }, + FilterBySpan { + start: i64, + end: i64, + }, FilterErrors, } pub fn event_matches_span(event: Rc, filter_start: i64, filter_end: i64) -> bool { { let sp = event_span(event); - ((sp.start.clone() >= filter_start) && (sp.start.clone() < filter_end)) - } +((sp.start.clone() >= filter_start) && (sp.start.clone() < filter_end)) +} } pub fn replay_trace(trace: Rc, filter: Rc) -> Rc>> { match (*filter).clone() { - TraceFilter::FilterByFunc { - func_name: name, .. - } => Rc::new({ - let mut __result = Vec::new(); - for e in trace.events.clone().iter().cloned() { - if (event_node_id(e.clone()).as_str() == name.clone().as_str()) { - __result.push(e); - } - } - __result - }), - TraceFilter::FilterBySpan { - start: s, end: e, .. - } => Rc::new({ - let mut __result = Vec::new(); - for ev in trace.events.clone().iter().cloned() { - if event_matches_span(ev.clone(), s.clone(), e.clone()) { - __result.push(ev); - } - } - __result - }), - TraceFilter::FilterErrors => Rc::new({ - let mut __result = Vec::new(); - for e in trace.events.clone().iter().cloned() { - if match (*e.clone()).clone() { - TraceEvent::TraceError { .. } => true, - _ => false, - } { - __result.push(e); - } - } - __result - }), - } + TraceFilter::FilterByFunc { func_name: name, .. } => Rc::new({ let mut __result = Vec::new(); for e in trace.events.clone().iter().cloned() { if (event_node_id(e.clone()).as_str() == name.clone().as_str()) { __result.push(e); } } __result }), + TraceFilter::FilterBySpan { start: s, end: e, .. } => Rc::new({ let mut __result = Vec::new(); for ev in trace.events.clone().iter().cloned() { if event_matches_span(ev.clone(), s.clone(), e.clone()) { __result.push(ev); } } __result }), + TraceFilter::FilterErrors => Rc::new({ let mut __result = Vec::new(); for e in trace.events.clone().iter().cloned() { if match (*e.clone()).clone() { + TraceEvent::TraceError { .. } => true, + _ => false, +} { __result.push(e); } } __result }), +} } pub fn format_span(sp: &Rc) -> String { - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("[".to_string(), (sp.start.clone()).to_string()), - "..".to_string(), - ), - (sp.end.clone()).to_string(), - ), - ")".to_string(), - ) + v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("[".to_string(), (sp.start.clone()).to_string()), "..".to_string()), (sp.end.clone()).to_string()), ")".to_string()) } pub fn format_trace_event(event: Rc) -> String { match (*event).clone() { - TraceEvent::TraceEnter { - node_id: id, - span: sp, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat("> ".to_string(), id.clone()), - " at ".to_string(), - ), - format_span(&sp), - ), - TraceEvent::TraceExit { - node_id: id, - span: sp, - output: out, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("< ".to_string(), id.clone()), - " at ".to_string(), - ), - format_span(&sp), - ), - ": ".to_string(), - ), - out.clone(), - ), - TraceEvent::TraceError { - node_id: id, - span: sp, - message: msg, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("! ".to_string(), id.clone()), - " at ".to_string(), - ), - format_span(&sp), - ), - ": ".to_string(), - ), - msg.clone(), - ), - } + TraceEvent::TraceEnter { node_id: id, span: sp, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat("> ".to_string(), id.clone()), " at ".to_string()), format_span(&sp)), + TraceEvent::TraceExit { node_id: id, span: sp, output: out, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("< ".to_string(), id.clone()), " at ".to_string()), format_span(&sp)), ": ".to_string()), out.clone()), + TraceEvent::TraceError { node_id: id, span: sp, message: msg, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("! ".to_string(), id.clone()), " at ".to_string()), format_span(&sp)), ": ".to_string()), msg.clone()), +} } pub fn format_trace(trace: Rc) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for e in trace.events.clone().iter().cloned() { - __result.push(format_trace_event(e.clone())); - } - __result - }) + Rc::new({ let mut __result = Vec::new(); for e in trace.events.clone().iter().cloned() { __result.push(format_trace_event(e.clone())); } __result }) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -264,17 +174,13 @@ pub struct ReproCase { pub trace: Option>, } -pub fn capture_repro( - func_name: String, - inputs: Rc>, - trace: Rc, -) -> Rc { +pub fn capture_repro(func_name: String, inputs: Rc>, trace: Rc) -> Rc { Rc::new(ReproCase { - func_name: func_name, - inputs: inputs, - expected_output: None, - trace: Some(trace), - }) + func_name: func_name, + inputs: inputs, + expected_output: None, + trace: Some(trace), +}) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -284,16 +190,5 @@ pub struct SourceMap { } pub fn remap_location(source_map: Rc, generated_line: i64) -> Option> { - Rc::new({ - let mut __result = Vec::new(); - for m in source_map.mappings.clone().iter().cloned() { - if (m.generated_line.clone() <= generated_line.clone()) { - __result.push(m); - } - } - __result - }) - .last() - .cloned() - .map(|m| m.source_span.clone()) + Rc::new({ let mut __result = Vec::new(); for m in source_map.mappings.clone().iter().cloned() { if (m.generated_line.clone() <= generated_line.clone()) { __result.push(m); } } __result }).last().cloned().map(|m| m.source_span.clone()) } diff --git a/src/v2/stage0/src/v2_rt.rs b/src/v2/stage0/src/v2_rt.rs index ffaae8d00d3..8e6da305b01 100644 --- a/src/v2/stage0/src/v2_rt.rs +++ b/src/v2/stage0/src/v2_rt.rs @@ -11,84 +11,52 @@ pub trait V2Concat { } impl V2Concat for String { - fn v2_concat(mut self, other: String) -> String { - self.push_str(&other); - self - } + fn v2_concat(mut self, other: String) -> String { self.push_str(&other); self } } impl V2Concat for Vec { - fn v2_concat(mut self, other: Vec) -> Vec { - self.extend(other); - self - } + fn v2_concat(mut self, other: Vec) -> Vec { self.extend(other); self } } -pub fn concat(a: T, b: T) -> T { - a.v2_concat(b) -} +pub fn concat(a: T, b: T) -> T { a.v2_concat(b) } pub fn char_at(s: &str, pos: i64) -> String { let pos = pos.max(0) as usize; if s.is_ascii() { let bytes = s.as_bytes(); - if pos >= bytes.len() { - return String::new(); - } + if pos >= bytes.len() { return String::new(); } return String::from(bytes[pos] as char); } - s.chars() - .nth(pos) - .map(|ch| ch.to_string()) - .unwrap_or_default() + s.chars().nth(pos).map(|ch| ch.to_string()).unwrap_or_default() } pub fn string_length(s: &str) -> i64 { - if s.is_ascii() { - s.len() as i64 - } else { - s.chars().count() as i64 - } + if s.is_ascii() { s.len() as i64 } else { s.chars().count() as i64 } } pub fn substring(s: &str, start: i64, end: i64) -> String { let start = start.max(0) as usize; let end = end.max(0) as usize; - if end <= start { - return String::new(); - } + if end <= start { return String::new(); } if s.is_ascii() { let len = s.len(); - if start >= len { - return String::new(); - } + if start >= len { return String::new(); } return s[start..end.min(len)].to_string(); } - s.chars() - .skip(start) - .take(end.saturating_sub(start)) - .collect() + s.chars().skip(start).take(end.saturating_sub(start)).collect() } pub fn string_contains(s: &str, sub: String) -> bool { s.contains(&*sub) } -pub fn contains(s: String, sub: String) -> bool { - string_contains(&s, sub) -} +pub fn contains(s: String, sub: String) -> bool { string_contains(&s, sub) } -pub fn count(items: Rc>) -> i64 { - items.len() as i64 -} +pub fn count(items: Rc>) -> i64 { items.len() as i64 } -pub fn str_eq(a: String, b: String) -> bool { - a == b -} +pub fn str_eq(a: String, b: String) -> bool { a == b } -pub fn to_string(value: i64) -> String { - value.to_string() -} +pub fn to_string(value: i64) -> String { value.to_string() } pub fn clamp(val: i64, min_val: i64, max_val: i64) -> i64 { val.clamp(min_val, max_val) @@ -100,58 +68,31 @@ pub fn lookup(table: &HashMap, key: String) -> Option { pub fn index_by String>(list: Vec, key_fn: F) -> HashMap { let mut map = HashMap::new(); - for item in list { - let key = key_fn(&item); - map.insert(key, item); - } + for item in list { let key = key_fn(&item); map.insert(key, item); } map } -pub fn empty_map() -> HashMap { - HashMap::new() -} +pub fn empty_map() -> HashMap { HashMap::new() } -pub fn map_insert( - mut map: HashMap, - key: K, - value: V, -) -> HashMap { - map.insert(key, value); - map +pub fn map_insert(mut map: HashMap, key: K, value: V) -> HashMap { + map.insert(key, value); map } -pub fn map_merge( - mut base: HashMap, - overlay: HashMap, -) -> HashMap { - base.extend(overlay); - base +pub fn map_merge(mut base: HashMap, overlay: HashMap) -> HashMap { + base.extend(overlay); base } -pub fn map_get( - m: &HashMap, - key: K, -) -> Option { +pub fn map_get(m: &HashMap, key: K) -> Option { m.get(&key).cloned() } -pub fn map_keys(m: &HashMap) -> Vec { - m.keys().cloned().collect() -} +pub fn map_keys(m: &HashMap) -> Vec { m.keys().cloned().collect() } -pub fn map_values(m: &HashMap) -> Vec { - m.values().cloned().collect() -} +pub fn map_values(m: &HashMap) -> Vec { m.values().cloned().collect() } -pub fn list_concat(mut a: Vec, b: Vec) -> Vec { - a.extend(b); - a -} +pub fn list_concat(mut a: Vec, b: Vec) -> Vec { a.extend(b); a } -pub fn list_push(mut list: Vec, item: T) -> Vec { - list.push(item); - list -} +pub fn list_push(mut list: Vec, item: T) -> Vec { list.push(item); list } pub fn append(list: Rc>, item: T) -> Vec { let mut v = (*list).clone(); @@ -169,9 +110,7 @@ pub fn chars_to_string(chars: &Rc>, start: i64, end: i64) -> String { .collect() } -pub fn parse_int(s: String) -> Option { - s.parse::().ok() -} +pub fn parse_int(s: String) -> Option { s.parse::().ok() } pub fn map_contains_key(m: &HashMap, key: K) -> bool { m.contains_key(&key) @@ -182,9 +121,7 @@ pub fn map_has(m: &HashMap, key: K) } pub fn reverse(list: Rc>) -> Rc> { - let mut v = (*list).clone(); - v.reverse(); - Rc::new(v) + let mut v = (*list).clone(); v.reverse(); Rc::new(v) } pub fn replace(s: String, from: String, to: String) -> String { @@ -209,20 +146,13 @@ pub fn rc_list_concat(a: Rc>, b: Rc>) -> Rc> { result } -pub fn rc_map_insert( - map: Rc>, - key: K, - value: V, -) -> Rc> { +pub fn rc_map_insert(map: Rc>, key: K, value: V) -> Rc> { let mut m = map; Rc::make_mut(&mut m).insert(key, value); m } -pub fn rc_map_merge( - base: Rc>, - overlay: Rc>, -) -> Rc> { +pub fn rc_map_merge(base: Rc>, overlay: Rc>) -> Rc> { let mut result = base; let inner = Rc::make_mut(&mut result); for (k, v) in overlay.iter() { @@ -231,21 +161,14 @@ pub fn rc_map_merge( result } -pub fn rc_index_by String>( - list: Rc>, - key_fn: F, -) -> Rc> { +pub fn rc_index_by String>(list: Rc>, key_fn: F) -> Rc> { Rc::new(list.iter().map(|v| (key_fn(v), v.clone())).collect()) } -pub fn rc_empty_map() -> Rc> { - Rc::new(HashMap::new()) -} +pub fn rc_empty_map() -> Rc> { Rc::new(HashMap::new()) } impl V2Concat for Rc> { - fn v2_concat(self, other: Rc>) -> Rc> { - rc_list_concat(self, other) - } + fn v2_concat(self, other: Rc>) -> Rc> { rc_list_concat(self, other) } } pub fn scan_while(s: &str, start: i64, pred: impl Fn(String) -> bool) -> i64 { @@ -253,20 +176,14 @@ pub fn scan_while(s: &str, start: i64, pred: impl Fn(String) -> bool) -> i64 { if s.is_ascii() { let bytes = s.as_bytes(); let mut pos = start.min(bytes.len()); - while pos < bytes.len() && pred(String::from(bytes[pos] as char)) { - pos += 1; - } + while pos < bytes.len() && pred(String::from(bytes[pos] as char)) { pos += 1; } return pos as i64; } let char_len = s.chars().count(); let start = start.min(char_len); let mut pos = start; for ch in s.chars().skip(start) { - if pred(ch.to_string()) { - pos += 1; - } else { - break; - } + if pred(ch.to_string()) { pos += 1; } else { break; } } pos as i64 } @@ -276,20 +193,14 @@ pub fn skip_horizontal_ws(s: &str, start: i64) -> i64 { if s.is_ascii() { let bytes = s.as_bytes(); let mut pos = start.min(bytes.len()); - while pos < bytes.len() && (bytes[pos] == b' ' || bytes[pos] == b'\t') { - pos += 1; - } + while pos < bytes.len() && (bytes[pos] == b' ' || bytes[pos] == b'\t') { pos += 1; } return pos as i64; } let char_len = s.chars().count(); let start = start.min(char_len); let mut pos = start; for ch in s.chars().skip(start) { - if ch == ' ' || ch == '\t' { - pos += 1; - } else { - break; - } + if ch == ' ' || ch == '\t' { pos += 1; } else { break; } } pos as i64 } @@ -299,20 +210,14 @@ pub fn scan_to_eol(s: &str, start: i64) -> i64 { if s.is_ascii() { let bytes = s.as_bytes(); let start = start.min(bytes.len()); - for i in start..bytes.len() { - if bytes[i] == b'\n' { - return i as i64; - } - } + for i in start..bytes.len() { if bytes[i] == b'\n' { return i as i64; } } return bytes.len() as i64; } let char_len = s.chars().count(); let start = start.min(char_len); let mut pos = start; for ch in s.chars().skip(start) { - if ch == '\n' { - return pos as i64; - } + if ch == '\n' { return pos as i64; } pos += 1; } pos as i64 @@ -324,13 +229,9 @@ pub fn scan_string_end(s: &str, start: i64) -> i64 { let bytes = s.as_bytes(); let mut pos = start.min(bytes.len()); while pos < bytes.len() { - if bytes[pos] == b'\\' { - pos += 2; - } else if bytes[pos] == b'\"' { - return (pos + 1) as i64; - } else { - pos += 1; - } + if bytes[pos] == b'\\' { pos += 2; } + else if bytes[pos] == b'\"' { return (pos + 1) as i64; } + else { pos += 1; } } return bytes.len() as i64; } @@ -359,9 +260,7 @@ pub fn code_point(c: String) -> i64 { } pub fn from_code_point(cp: i64) -> String { - char::from_u32(cp as u32) - .map(|c| c.to_string()) - .unwrap_or_default() + char::from_u32(cp as u32).map(|c| c.to_string()).unwrap_or_default() } #[derive(Debug, Clone)] @@ -370,7 +269,7 @@ pub struct FilesystemReadResult { } pub fn filesystem_read(path: String) -> FilesystemReadResult { - let content = - std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("failed to read {}: {}", path, e)); + let content = std::fs::read_to_string(&path) + .unwrap_or_else(|e| panic!("failed to read {}: {}", path, e)); FilesystemReadResult { content } } diff --git a/src/v2/stage0/src/v2_std_core.rs b/src/v2/stage0/src/v2_std_core.rs index 800cac37ccc..edbf24b96d4 100644 --- a/src/v2/stage0/src/v2_std_core.rs +++ b/src/v2/stage0/src/v2_std_core.rs @@ -1,46 +1,39 @@ // Generated by v2 compiler -- do not edit. // Source module: v2.std.core -use self::CallSemantics::*; -use self::Cardinality::*; -use self::CompilerDiagnostic::*; +use std::collections::HashMap; +use std::rc::Rc; +use crate::v2_rt; +use crate::NonEmptyVec; +use crate::NonEmptyBTreeSet; +pub use crate::std_types::{FilePath, NonEmptyStr, SourceSpan, kernel_type_set, is_kernel_type, container_type_arity, is_container_type, container_expected_arity}; +pub use crate::std_syntax::{BinOp, LiteralValue, AlgebraFieldKind}; +use crate::std_syntax::BinOp::{Add, Sub, Mul, Div, Mod, Eq, Ne, Lt, Gt, Le, Ge, And, Or, NullCoalesce}; +use crate::std_syntax::LiteralValue::{LitStr, LitInt, LitFloat, LitBool, LitNull}; +use crate::std_syntax::AlgebraFieldKind::{AlgAdd, AlgMul, AlgReciprocal, AlgQuotient, AlgRemainder, AlgCompare, AlgMeet, AlgJoin}; +pub use crate::std_algebra::{CollectionSizeEffect, CostShape, AlgebraFieldTemplate}; +use crate::std_algebra::CollectionSizeEffect::*; +use crate::std_algebra::CostShape::*; +pub use crate::std_induction::{SubValueRelation}; +use crate::std_induction::SubValueRelation::*; +use self::TokenShape::*; use self::Connective::*; -use self::ExprData::*; -use self::ExprErrorKind::*; +use self::Cardinality::*; use self::FieldAccessStyle::*; use self::FieldValueShape::*; -use self::FunctionSizeEffect::*; use self::InferredNode::*; -use self::MatchPattern::*; +use self::VarBindingKind::*; +use self::CallSemantics::*; use self::MethodSemantics::*; -use self::NodeFieldRole::*; -use self::OperationModifier::*; -use self::StringPart::*; -use self::TokenShape::*; +use self::ExprErrorKind::*; +use self::ExprData::*; +use self::MatchPattern::*; use self::UnaryOpKind::*; -use self::VarBindingKind::*; -use crate::std_algebra::CollectionSizeEffect::*; -use crate::std_algebra::CostShape::*; -pub use crate::std_algebra::{AlgebraFieldTemplate, CollectionSizeEffect, CostShape}; -pub use crate::std_induction::SubValueRelation; -use crate::std_induction::SubValueRelation::*; -use crate::std_syntax::AlgebraFieldKind::{ - AlgAdd, AlgCompare, AlgJoin, AlgMeet, AlgMul, AlgQuotient, AlgReciprocal, AlgRemainder, -}; -use crate::std_syntax::BinOp::{ - Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, NullCoalesce, Or, Sub, -}; -use crate::std_syntax::LiteralValue::{LitBool, LitFloat, LitInt, LitNull, LitStr}; -pub use crate::std_syntax::{AlgebraFieldKind, BinOp, LiteralValue}; -pub use crate::std_types::{ - container_expected_arity, container_type_arity, is_container_type, is_kernel_type, - kernel_type_set, FilePath, NonEmptyStr, SourceSpan, -}; -use crate::v2_rt; -use crate::NonEmptyBTreeSet; -use crate::NonEmptyVec; -use std::collections::HashMap; -use std::rc::Rc; +use self::StringPart::*; +use self::OperationModifier::*; +use self::CompilerDiagnostic::*; +use self::NodeFieldRole::*; +use self::FunctionSizeEffect::*; #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct Token { @@ -152,18 +145,18 @@ pub enum InferredNode { pub fn inferred_to_node(inferred: Rc) -> Option> { match (*inferred).clone() { - InferredNode::Resolved { node: n, .. } => Some(n.clone()), - InferredNode::CompilerError { .. } => None, - InferredNode::TypeVariable { .. } => None, - } + InferredNode::Resolved { node: n, .. } => Some(n.clone()), + InferredNode::CompilerError { .. } => None, + InferredNode::TypeVariable { .. } => None, +} } pub fn is_compiler_error(inferred: Rc) -> bool { match (*inferred).clone() { - InferredNode::Resolved { .. } => false, - InferredNode::CompilerError { .. } => true, - InferredNode::TypeVariable { .. } => false, - } + InferredNode::Resolved { .. } => false, + InferredNode::CompilerError { .. } => true, + InferredNode::TypeVariable { .. } => false, +} } pub fn has_inferred(n: Rc) -> bool { @@ -175,7 +168,9 @@ pub fn has_inferred(n: Rc) -> bool { pub enum VarBindingKind { LocalValueBinding, FunctionValueBinding, - VariantValueBinding { parent_enum: String }, + VariantValueBinding { + parent_enum: String, + }, MatchBoundBinding, } impl VarBindingKind { @@ -183,9 +178,7 @@ impl VarBindingKind { match self { VarBindingKind::LocalValueBinding => panic!("no parent_enum on unit variant"), VarBindingKind::FunctionValueBinding => panic!("no parent_enum on unit variant"), - VarBindingKind::VariantValueBinding { - parent_enum: __val, .. - } => __val.clone(), + VarBindingKind::VariantValueBinding { parent_enum: __val, .. } => __val.clone(), VarBindingKind::MatchBoundBinding => panic!("no parent_enum on unit variant"), } } @@ -298,8 +291,12 @@ pub enum UnaryOpKind { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(tag = "_variant")] pub enum StringPart { - Text { value: String }, - Interpolation { expr: Rc }, + Text { + value: String, + }, + Interpolation { + expr: Rc, + }, } #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] @@ -440,208 +437,44 @@ pub struct ErrorDAG { pub fn diagnostic_to_span(d: Rc) -> Rc { match (*d).clone() { - CompilerDiagnostic::UnresolvedImport { span: s, .. } => s.clone(), - CompilerDiagnostic::MissingExport { span: s, .. } => s.clone(), - CompilerDiagnostic::UnresolvedType { span: s, .. } => s.clone(), - CompilerDiagnostic::TypeMismatch { span: s, .. } => s.clone(), - CompilerDiagnostic::ArityMismatch { span: s, .. } => s.clone(), - CompilerDiagnostic::VariantNotFound { span: s, .. } => s.clone(), - CompilerDiagnostic::FieldNotFound { span: s, .. } => s.clone(), - CompilerDiagnostic::NonExhaustiveMatch { span: s, .. } => s.clone(), - CompilerDiagnostic::CircularDependency { span: s, .. } => s.clone(), - CompilerDiagnostic::DuplicateModule { span: s, .. } => s.clone(), - CompilerDiagnostic::MissingAnnotation { span: s, .. } => s.clone(), - CompilerDiagnostic::ParseError { span: s, .. } => s.clone(), - CompilerDiagnostic::InternalError { span: s, .. } => s.clone(), - CompilerDiagnostic::ComplexityUnknown { span: s, .. } => s.clone(), - CompilerDiagnostic::OwnershipViolation { span: s, .. } => s.clone(), - CompilerDiagnostic::VariantCollision { span: s, .. } => s.clone(), - } + CompilerDiagnostic::UnresolvedImport { span: s, .. } => s.clone(), + CompilerDiagnostic::MissingExport { span: s, .. } => s.clone(), + CompilerDiagnostic::UnresolvedType { span: s, .. } => s.clone(), + CompilerDiagnostic::TypeMismatch { span: s, .. } => s.clone(), + CompilerDiagnostic::ArityMismatch { span: s, .. } => s.clone(), + CompilerDiagnostic::VariantNotFound { span: s, .. } => s.clone(), + CompilerDiagnostic::FieldNotFound { span: s, .. } => s.clone(), + CompilerDiagnostic::NonExhaustiveMatch { span: s, .. } => s.clone(), + CompilerDiagnostic::CircularDependency { span: s, .. } => s.clone(), + CompilerDiagnostic::DuplicateModule { span: s, .. } => s.clone(), + CompilerDiagnostic::MissingAnnotation { span: s, .. } => s.clone(), + CompilerDiagnostic::ParseError { span: s, .. } => s.clone(), + CompilerDiagnostic::InternalError { span: s, .. } => s.clone(), + CompilerDiagnostic::ComplexityUnknown { span: s, .. } => s.clone(), + CompilerDiagnostic::OwnershipViolation { span: s, .. } => s.clone(), + CompilerDiagnostic::VariantCollision { span: s, .. } => s.clone(), +} } pub fn diagnostic_to_message(d: Rc) -> String { match (*d).clone() { - CompilerDiagnostic::UnresolvedImport { - module_path: m, - importing_module: i, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("unresolved import: module '".to_string(), m.clone()), - "' not found (imported by '".to_string(), - ), - i.clone(), - ), - "')".to_string(), - ), - CompilerDiagnostic::MissingExport { - name: n, - module_path: m, - importing_module: i, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("name '".to_string(), n.clone()), - "' not found in module '".to_string(), - ), - m.clone(), - ), - "' (imported by '".to_string(), - ), - i.clone(), - ), - "')".to_string(), - ), - CompilerDiagnostic::UnresolvedType { name: n, .. } => v2_rt::concat( - v2_rt::concat("unresolved type '".to_string(), n.clone()), - "'".to_string(), - ), - CompilerDiagnostic::TypeMismatch { - expected: e, - got: g, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("type mismatch: expected '".to_string(), e.clone()), - "', got '".to_string(), - ), - g.clone(), - ), - "'".to_string(), - ), - CompilerDiagnostic::ArityMismatch { - name: n, - expected: e, - got: g, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("type ".to_string(), n.clone()), - " expects ".to_string(), - ), - (e.clone()).to_string(), - ), - " type arguments, got ".to_string(), - ), - (g.clone()).to_string(), - ), - CompilerDiagnostic::VariantNotFound { - variant: v, - type_name: t, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("variant '".to_string(), v.clone()), - "' not found in type '".to_string(), - ), - t.clone(), - ), - "'".to_string(), - ), - CompilerDiagnostic::FieldNotFound { - field: f, - type_name: t, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("field '".to_string(), f.clone()), - "' not found in type '".to_string(), - ), - t.clone(), - ), - "'".to_string(), - ), - CompilerDiagnostic::NonExhaustiveMatch { missing: ms, .. } => v2_rt::concat( - "non-exhaustive match: missing variant(s) ".to_string(), - ms.clone().join(&", ".to_string()), - ), - CompilerDiagnostic::CircularDependency { modules: ms, .. } => v2_rt::concat( - "circular dependency detected: ".to_string(), - ms.clone().join(&" -> ".to_string()), - ), - CompilerDiagnostic::DuplicateModule { name: n, .. } => v2_rt::concat( - v2_rt::concat("duplicate module declaration: '".to_string(), n.clone()), - "'".to_string(), - ), - CompilerDiagnostic::MissingAnnotation { - fn_name: f, - what: w, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("function '".to_string(), f.clone()), - "' requires ".to_string(), - ), - w.clone(), - ), - " annotation".to_string(), - ), - CompilerDiagnostic::ParseError { message: m, .. } => m.clone(), - CompilerDiagnostic::InternalError { message: m, .. } => m.clone(), - CompilerDiagnostic::ComplexityUnknown { - func_name: f, - reason: r, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat("complexity: ".to_string(), f.clone()), - ": ".to_string(), - ), - r.clone(), - ), - CompilerDiagnostic::OwnershipViolation { - binding: b, - fn_name: f, - consumers: c, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("ownership: binding '".to_string(), b.clone()), - "' in '".to_string(), - ), - f.clone(), - ), - "' has ".to_string(), - ), - (c.clone()).to_string(), - ), - " consumers".to_string(), - ), - CompilerDiagnostic::VariantCollision { - variant: v, - enum1: e1, - enum2: e2, - .. - } => v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat("variant '".to_string(), v.clone()), - "' appears in both '".to_string(), - ), - e1.clone(), - ), - "' and '".to_string(), - ), - e2.clone(), - ), - "'".to_string(), - ), - } + CompilerDiagnostic::UnresolvedImport { module_path: m, importing_module: i, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("unresolved import: module '".to_string(), m.clone()), "' not found (imported by '".to_string()), i.clone()), "')".to_string()), + CompilerDiagnostic::MissingExport { name: n, module_path: m, importing_module: i, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("name '".to_string(), n.clone()), "' not found in module '".to_string()), m.clone()), "' (imported by '".to_string()), i.clone()), "')".to_string()), + CompilerDiagnostic::UnresolvedType { name: n, .. } => v2_rt::concat(v2_rt::concat("unresolved type '".to_string(), n.clone()), "'".to_string()), + CompilerDiagnostic::TypeMismatch { expected: e, got: g, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("type mismatch: expected '".to_string(), e.clone()), "', got '".to_string()), g.clone()), "'".to_string()), + CompilerDiagnostic::ArityMismatch { name: n, expected: e, got: g, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("type ".to_string(), n.clone()), " expects ".to_string()), (e.clone()).to_string()), " type arguments, got ".to_string()), (g.clone()).to_string()), + CompilerDiagnostic::VariantNotFound { variant: v, type_name: t, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("variant '".to_string(), v.clone()), "' not found in type '".to_string()), t.clone()), "'".to_string()), + CompilerDiagnostic::FieldNotFound { field: f, type_name: t, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("field '".to_string(), f.clone()), "' not found in type '".to_string()), t.clone()), "'".to_string()), + CompilerDiagnostic::NonExhaustiveMatch { missing: ms, .. } => v2_rt::concat("non-exhaustive match: missing variant(s) ".to_string(), ms.clone().join(&", ".to_string())), + CompilerDiagnostic::CircularDependency { modules: ms, .. } => v2_rt::concat("circular dependency detected: ".to_string(), ms.clone().join(&" -> ".to_string())), + CompilerDiagnostic::DuplicateModule { name: n, .. } => v2_rt::concat(v2_rt::concat("duplicate module declaration: '".to_string(), n.clone()), "'".to_string()), + CompilerDiagnostic::MissingAnnotation { fn_name: f, what: w, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("function '".to_string(), f.clone()), "' requires ".to_string()), w.clone()), " annotation".to_string()), + CompilerDiagnostic::ParseError { message: m, .. } => m.clone(), + CompilerDiagnostic::InternalError { message: m, .. } => m.clone(), + CompilerDiagnostic::ComplexityUnknown { func_name: f, reason: r, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat("complexity: ".to_string(), f.clone()), ": ".to_string()), r.clone()), + CompilerDiagnostic::OwnershipViolation { binding: b, fn_name: f, consumers: c, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("ownership: binding '".to_string(), b.clone()), "' in '".to_string()), f.clone()), "' has ".to_string()), (c.clone()).to_string()), " consumers".to_string()), + CompilerDiagnostic::VariantCollision { variant: v, enum1: e1, enum2: e2, .. } => v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat("variant '".to_string(), v.clone()), "' appears in both '".to_string()), e1.clone()), "' and '".to_string()), e2.clone()), "'".to_string()), +} } pub fn is_error_diagnostic(d: Rc) -> bool { @@ -650,16 +483,16 @@ pub fn is_error_diagnostic(d: Rc) -> bool { pub fn is_interpreter_blocking_diagnostic(d: Rc) -> bool { match (*d).clone() { - CompilerDiagnostic::ComplexityUnknown { .. } => false, - _ => true, - } + CompilerDiagnostic::ComplexityUnknown { .. } => false, + _ => true, +} } pub fn make_error_node(diagnostic: Rc, module_name: String) -> Rc { Rc::new(ErrorNode { - diagnostic: diagnostic, - module_name: module_name, - }) + diagnostic: diagnostic, + module_name: module_name, +}) } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -669,8 +502,7 @@ pub struct DeclaredFuncSig { pub inferred: Option>, pub is_async: bool, pub output_provenance: Rc>>>>, - pub variant_provenance: - Rc>>>>>>, + pub variant_provenance: Rc>>>>>>, } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -710,464 +542,359 @@ pub fn default_ident_span(name: String, span: Rc) -> Option) -> Rc { match n.ident_span.clone() { - Some(s) => s.clone(), - None => n.span.clone(), - } + Some(s) => s.clone(), + None => n.span.clone(), } - -pub fn make_expr_node( - expr_data: Rc, - children: Rc>>, - inferred: Option>, - span: Rc, -) -> Rc { - Rc::new(Node { - name: "".to_string(), - span: span, - ident_span: None, - children: children, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: inferred, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: expr_data, - ident: None, - }) } -pub fn make_named_expr_node( - name: &String, - expr_data: Rc, - children: Rc>>, - inferred: Option>, - span: Rc, - name_span: Rc, -) -> Rc { +pub fn make_expr_node(expr_data: Rc, children: Rc>>, inferred: Option>, span: Rc) -> Rc { Rc::new(Node { - name: name.clone(), - span: span, - ident_span: default_ident_span(name.clone(), name_span), - children: children, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: inferred, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: expr_data, - ident: None, - }) -} - -pub fn make_expr_error_node( - kind: ExprErrorKind, - message: &String, - span: &Rc, -) -> Rc { + name: "".to_string(), + span: span, + ident_span: None, + children: children, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: inferred, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: expr_data, + ident: None, +}) +} + +pub fn make_named_expr_node(name: &String, expr_data: Rc, children: Rc>>, inferred: Option>, span: Rc, name_span: Rc) -> Rc { Rc::new(Node { - name: "".to_string(), - span: span.clone(), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::CompilerError { - message: message.clone(), - span: span.clone(), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::ExprError { - kind: kind, - message: message.clone(), - }), - ident: None, - }) -} - -pub fn make_arg_node( - name: Option, - value: Rc, - span: Rc, - name_span: Rc, -) -> Rc { + name: name.clone(), + span: span, + ident_span: default_ident_span(name.clone(), name_span), + children: children, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: inferred, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: expr_data, + ident: None, +}) +} + +pub fn make_expr_error_node(kind: ExprErrorKind, message: &String, span: &Rc) -> Rc { + Rc::new(Node { + name: "".to_string(), + span: span.clone(), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::CompilerError { + message: message.clone(), + span: span.clone(), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::ExprError { + kind: kind, + message: message.clone(), +}), + ident: None, +}) +} + +pub fn make_arg_node(name: Option, value: Rc, span: Rc, name_span: Rc) -> Rc { { let arg_name = match name { - Some(n) => n.clone(), - None => "".to_string(), - }; - Rc::new(Node { - name: arg_name.clone(), - span: span, - ident_span: default_ident_span(arg_name.clone(), name_span), - children: Rc::new(vec![value]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } -} - -pub fn make_arm_node( - pattern: Rc, - guard: Option>, - body: Rc, - span: Rc, -) -> Rc { + Some(n) => n.clone(), + None => "".to_string(), +}; +Rc::new(Node { + name: arg_name.clone(), + span: span, + ident_span: default_ident_span(arg_name.clone(), name_span), + children: Rc::new(vec![value]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} +} + +pub fn make_arm_node(pattern: Rc, guard: Option>, body: Rc, span: Rc) -> Rc { { let children = match guard { - Some(g) => Rc::new(vec![g.clone(), body]), - None => Rc::new(vec![body]), - }; - Rc::new(Node { - name: "".to_string(), - span: span, - ident_span: None, - children: children, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: Some(pattern), - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } -} - -pub fn make_resource_use_node( - name: &String, - resource: Rc, - span: Rc, - name_span: Rc, -) -> Rc { + Some(g) => Rc::new(vec![g.clone(), body]), + None => Rc::new(vec![body]), +}; +Rc::new(Node { + name: "".to_string(), + span: span, + ident_span: None, + children: children, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: Some(pattern), + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} +} + +pub fn make_resource_use_node(name: &String, resource: Rc, span: Rc, name_span: Rc) -> Rc { Rc::new(Node { - name: name.clone(), - span: span, - ident_span: default_ident_span(name.clone(), name_span), - children: Rc::new(vec![resource]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) -} - -pub fn resource_use_name_at( - n: Rc, - source_indices: Rc>>, -) -> String { + name: name.clone(), + span: span, + ident_span: default_ident_span(name.clone(), name_span), + children: Rc::new(vec![resource]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} + +pub fn resource_use_name_at(n: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &n) } pub fn resource_use_resource(n: &Rc) -> Rc { match n.children.clone().first().cloned() { - Some(v) => v.clone(), - None => make_expr_error_node( - ExprErrorKind::InternalExprError, - &"malformed resource-use: missing resource".to_string(), - &n.span.clone(), - ), - } + Some(v) => v.clone(), + None => make_expr_error_node(ExprErrorKind::InternalExprError, &"malformed resource-use: missing resource".to_string(), &n.span.clone()), } - -pub fn make_field_init_node( - name: &String, - value: Rc, - span: Rc, - name_span: Rc, -) -> Rc { - Rc::new(Node { - name: name.clone(), - span: span, - ident_span: default_ident_span(name.clone(), name_span), - children: Rc::new(vec![value]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) } -pub fn make_field_binding_node( - field_name: &String, - binding: Rc, - span: Rc, - name_span: Rc, -) -> Rc { +pub fn make_field_init_node(name: &String, value: Rc, span: Rc, name_span: Rc) -> Rc { Rc::new(Node { - name: field_name.clone(), - span: span, - ident_span: default_ident_span(field_name.clone(), name_span), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: Some(binding), - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) -} - -pub fn field_binding_name_at( - n: Rc, - source_indices: Rc>>, -) -> String { + name: name.clone(), + span: span, + ident_span: default_ident_span(name.clone(), name_span), + children: Rc::new(vec![value]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} + +pub fn make_field_binding_node(field_name: &String, binding: Rc, span: Rc, name_span: Rc) -> Rc { + Rc::new(Node { + name: field_name.clone(), + span: span, + ident_span: default_ident_span(field_name.clone(), name_span), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: Some(binding), + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} + +pub fn field_binding_name_at(n: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &n) } pub fn field_binding_pattern(n: Rc) -> Rc { match n.match_pattern.clone() { - Some(p) => p.clone(), - None => Rc::new(MatchPattern::Wildcard), - } + Some(p) => p.clone(), + None => Rc::new(MatchPattern::Wildcard), +} } pub fn make_text_part_node(text: String, span: Rc) -> Rc { Rc::new(Node { - name: "".to_string(), - span: span, - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::ExprLiteral { - value: Rc::new(LiteralValue::LitStr { value: text }), - }), - ident: None, - }) + name: "".to_string(), + span: span, + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::ExprLiteral { + value: Rc::new(LiteralValue::LitStr { + value: text, +}), +}), + ident: None, +}) } pub fn make_interp_part_node(expr: Rc, span: Rc) -> Rc { Rc::new(Node { - name: "".to_string(), - span: span, - ident_span: None, - children: Rc::new(vec![expr]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) -} - -pub fn make_param_node( - name: &String, - type_expr: Rc, - default_value: Option>, - span: Rc, - name_span: Rc, -) -> Rc { + name: "".to_string(), + span: span, + ident_span: None, + children: Rc::new(vec![expr]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} + +pub fn make_param_node(name: &String, type_expr: Rc, default_value: Option>, span: Rc, name_span: Rc) -> Rc { { let children = match default_value { - Some(dv) => Rc::new(vec![type_expr, dv.clone()]), - None => Rc::new(vec![type_expr]), - }; - Rc::new(Node { - name: name.clone(), - span: span, - ident_span: default_ident_span(name.clone(), name_span), - children: children, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } -} - -pub fn param_node_name_at( - n: Rc, - source_indices: Rc>>, -) -> String { + Some(dv) => Rc::new(vec![type_expr, dv.clone()]), + None => Rc::new(vec![type_expr]), +}; +Rc::new(Node { + name: name.clone(), + span: span, + ident_span: default_ident_span(name.clone(), name_span), + children: children, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} +} + +pub fn param_node_name_at(n: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &n) } -pub fn generic_param_name_at( - n: Rc, - source_indices: Rc>>, -) -> String { +pub fn generic_param_name_at(n: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &n) } -pub fn authored_name_at( - source_indices: Rc>>, - node: &Rc, -) -> String { +pub fn authored_name_at(source_indices: Rc>>, node: &Rc) -> String { match node.ident_span.clone() { - Some(span) => match v2_rt::map_get(&source_indices, span.file.clone()) { - Some(index) => { - let text = source_text_at(index.clone(), &span); - if (text.clone().as_str() == "".to_string().as_str()) { - "".to_string() - } else { - text.clone() - } - } - None => { - if ((v2_rt::string_length(&span.file.clone()) > 8) - && (v2_rt::substring(&span.file.clone(), 0, 8).as_str() - == " "".to_string(), - } + Some(span) => match v2_rt::map_get(&source_indices, span.file.clone()) { + Some(index) => { + let text = source_text_at(index.clone(), &span); +if (text.clone().as_str() == "".to_string().as_str()) { + "".to_string() + } else { + text.clone() + } +}, + None => if ((v2_rt::string_length(&span.file.clone()) > 8) && (v2_rt::substring(&span.file.clone(), 0, 8).as_str() == " "".to_string(), +} } -pub fn find_child_named( - n: Rc, - name: String, - source_indices: Rc>>, -) -> Option> { - match Rc::new({ - let mut __result = Vec::new(); - for c in n.children.clone().iter().cloned() { - if (authored_name_at(source_indices.clone(), &c).as_str() == name.clone().as_str()) { - __result.push(c); - } - } - __result - }) - .first() - .cloned() - { - Some(ch) => Some(ch.clone()), - None => None, - } +pub fn find_child_named(n: Rc, name: String, source_indices: Rc>>) -> Option> { + match Rc::new({ let mut __result = Vec::new(); for c in n.children.clone().iter().cloned() { if (authored_name_at(source_indices.clone(), &c).as_str() == name.clone().as_str()) { __result.push(c); } } __result }).first().cloned() { + Some(ch) => Some(ch.clone()), + None => None, +} } -pub fn has_child_named( - n: Rc, - name: String, - source_indices: Rc>>, -) -> bool { - { - let mut __found = false; - for c in n.children.clone().iter().cloned() { - if (authored_name_at(source_indices.clone(), &c).as_str() == name.clone().as_str()) { - __found = true; - break; - } - } - __found - } +pub fn has_child_named(n: Rc, name: String, source_indices: Rc>>) -> bool { + { let mut __found = false; for c in n.children.clone().iter().cloned() { if (authored_name_at(source_indices.clone(), &c).as_str() == name.clone().as_str()) { __found = true; break; } } __found } } pub fn param_node_type_expr(n: &Rc) -> Rc { match n.children.clone().first().cloned() { - Some(v) => v.clone(), - None => make_expr_error_node( - ExprErrorKind::InternalExprError, - &"malformed param: missing type_expr".to_string(), - &n.span.clone(), - ), - } + Some(v) => v.clone(), + None => make_expr_error_node(ExprErrorKind::InternalExprError, &"malformed param: missing type_expr".to_string(), &n.span.clone()), +} } pub fn param_node_default_value(n: &Rc) -> Option> { @@ -1182,82 +909,67 @@ pub fn param_node_span(n: Rc) -> Rc { n.span.clone() } -pub fn make_field_node( - name: &String, - type_expr: Rc, - cardinality: Cardinality, - default_value: Option>, - from_key: Option, - span: Rc, - name_span: Rc, -) -> Rc { +pub fn make_field_node(name: &String, type_expr: Rc, cardinality: Cardinality, default_value: Option>, from_key: Option, span: Rc, name_span: Rc) -> Rc { { let children = match default_value { - Some(dv) => Rc::new(vec![type_expr, dv.clone()]), - None => Rc::new(vec![type_expr]), - }; - let props = match from_key { - Some(fk) => Rc::new(vec![Rc::new(Node { - name: fk.clone(), - span: make_span(0, 0), - ident_span: default_ident_span(fk.clone(), make_span(0, 0)), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - })]), - None => Rc::new(vec![]), - }; - Rc::new(Node { - name: name.clone(), - span: span, - ident_span: default_ident_span(name.clone(), name_span), - children: children, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: cardinality, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: props, - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } -} - -pub fn field_node_name_at( - n: Rc, - source_indices: Rc>>, -) -> String { + Some(dv) => Rc::new(vec![type_expr, dv.clone()]), + None => Rc::new(vec![type_expr]), +}; +let props = match from_key { + Some(fk) => Rc::new(vec![Rc::new(Node { + name: fk.clone(), + span: make_span(0, 0), + ident_span: default_ident_span(fk.clone(), make_span(0, 0)), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})]), + None => Rc::new(vec![]), +}; +Rc::new(Node { + name: name.clone(), + span: span, + ident_span: default_ident_span(name.clone(), name_span), + children: children, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: cardinality, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: props, + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} +} + +pub fn field_node_name_at(n: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &n) } pub fn field_node_type_expr(n: &Rc) -> Rc { match n.children.clone().first().cloned() { - Some(v) => v.clone(), - None => make_expr_error_node( - ExprErrorKind::InternalExprError, - &"malformed field: missing type_expr".to_string(), - &n.span.clone(), - ), - } + Some(v) => v.clone(), + None => make_expr_error_node(ExprErrorKind::InternalExprError, &"malformed field: missing type_expr".to_string(), &n.span.clone()), +} } pub fn field_node_cardinality(n: Rc) -> Cardinality { @@ -1272,52 +984,41 @@ pub fn field_node_default_value(n: &Rc) -> Option> { } } -pub fn field_node_from_key( - n: Rc, - source_indices: Rc>>, -) -> Option { +pub fn field_node_from_key(n: Rc, source_indices: Rc>>) -> Option { match n.properties.clone().first().cloned() { - Some(p) => Some(authored_name_at(source_indices, &p)), - None => None, - } + Some(p) => Some(authored_name_at(source_indices, &p)), + None => None, +} } pub fn field_node_span(n: Rc) -> Rc { n.span.clone() } -pub fn make_variant_node( - name: &String, - fields: Rc>>, - span: Rc, - name_span: Rc, -) -> Rc { +pub fn make_variant_node(name: &String, fields: Rc>>, span: Rc, name_span: Rc) -> Rc { Rc::new(Node { - name: name.clone(), - span: span, - ident_span: default_ident_span(name.clone(), name_span), - children: fields, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) -} - -pub fn variant_node_name_at( - n: Rc, - source_indices: Rc>>, -) -> String { + name: name.clone(), + span: span, + ident_span: default_ident_span(name.clone(), name_span), + children: fields, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} + +pub fn variant_node_name_at(n: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &n) } @@ -1358,49 +1059,7 @@ pub fn wrapper_child_roles() -> Rc>>>> { } pub fn is_child_accessor_in_model(name: String) -> bool { - ({ - let mut __found = false; - for roles in Rc::new(v2_rt::map_values(&expr_child_roles())) - .iter() - .cloned() - { - if { - let mut __found = false; - for r in roles.clone().iter().cloned() { - if (r.accessor.clone().as_str() == name.clone().as_str()) { - __found = true; - break; - } - } - __found - } { - __found = true; - break; - } - } - __found - } || { - let mut __found = false; - for roles in Rc::new(v2_rt::map_values(&wrapper_child_roles())) - .iter() - .cloned() - { - if { - let mut __found = false; - for r in roles.clone().iter().cloned() { - if (r.accessor.clone().as_str() == name.clone().as_str()) { - __found = true; - break; - } - } - __found - } { - __found = true; - break; - } - } - __found - }) + ({ let mut __found = false; for roles in Rc::new(v2_rt::map_values(&expr_child_roles())).iter().cloned() { if { let mut __found = false; for r in roles.clone().iter().cloned() { if (r.accessor.clone().as_str() == name.clone().as_str()) { __found = true; break; } } __found } { __found = true; break; } } __found } || { let mut __found = false; for roles in Rc::new(v2_rt::map_values(&wrapper_child_roles())).iter().cloned() { if { let mut __found = false; for r in roles.clone().iter().cloned() { if (r.accessor.clone().as_str() == name.clone().as_str()) { __found = true; break; } } __found } { __found = true; break; } } __found }) } pub fn child_roles_for_variant(variant_name: String) -> Option>>> { @@ -1432,17 +1091,17 @@ pub fn node_field_roles() -> Rc> { pub fn is_children_list_field(field_name: String) -> bool { match v2_rt::lookup(&node_field_roles(), field_name) { - Some(NodeFieldRole::ChildrenListField) => true, - _ => false, - } + Some(NodeFieldRole::ChildrenListField) => true, + _ => false, +} } pub fn is_sub_value_field(field_name: String) -> bool { match v2_rt::lookup(&node_field_roles(), field_name) { - Some(NodeFieldRole::SubValueField) => true, - Some(NodeFieldRole::ChildrenListField) => true, - _ => false, - } + Some(NodeFieldRole::SubValueField) => true, + Some(NodeFieldRole::ChildrenListField) => true, + _ => false, +} } #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] @@ -1450,111 +1109,91 @@ pub fn is_sub_value_field(field_name: String) -> bool { pub enum FunctionSizeEffect { TreeSizePreserving, TreeSizeReducing, - PropertyContraction { domain_size: i64 }, + PropertyContraction { + domain_size: i64, + }, } impl FunctionSizeEffect { pub fn domain_size(&self) -> i64 { match self { FunctionSizeEffect::TreeSizePreserving => panic!("no domain_size on unit variant"), FunctionSizeEffect::TreeSizeReducing => panic!("no domain_size on unit variant"), - FunctionSizeEffect::PropertyContraction { - domain_size: __val, .. - } => __val.clone(), + FunctionSizeEffect::PropertyContraction { domain_size: __val, .. } => __val.clone(), } } } pub fn function_size_effects() -> Rc>> { thread_local! { - static CACHED: Rc>> = { - let mut __m = HashMap::new(); - __m.insert("with_required_cardinality".to_string(), Rc::new(FunctionSizeEffect::PropertyContraction { - domain_size: 2, - })); - __m.insert("resolved_type".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); - __m.insert("param_node_type_expr".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); - __m.insert("field_binding_pattern".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); - __m.insert("wrapper_inner_arg".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); - __m.insert("extractor_inner_arg".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); - __m.insert("child_type_node".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); - Rc::new(__m) - }; - } + static CACHED: Rc>> = { + let mut __m = HashMap::new(); + __m.insert("with_required_cardinality".to_string(), Rc::new(FunctionSizeEffect::PropertyContraction { + domain_size: 2, +})); + __m.insert("resolved_type".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); + __m.insert("param_node_type_expr".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); + __m.insert("field_binding_pattern".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); + __m.insert("wrapper_inner_arg".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); + __m.insert("extractor_inner_arg".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); + __m.insert("child_type_node".to_string(), Rc::new(FunctionSizeEffect::TreeSizeReducing)); + Rc::new(__m) + }; + } CACHED.with(|c| c.clone()) } pub fn is_tree_size_preserving(func_name: String) -> bool { - match v2_rt::lookup(&function_size_effects(), func_name) - .as_deref() - .cloned() - { - Some(FunctionSizeEffect::TreeSizePreserving) => true, - Some(FunctionSizeEffect::PropertyContraction { .. }) => true, - _ => false, - } + match v2_rt::lookup(&function_size_effects(), func_name).as_deref().cloned() { + Some(FunctionSizeEffect::TreeSizePreserving) => true, + Some(FunctionSizeEffect::PropertyContraction { .. }) => true, + _ => false, +} } pub fn is_tree_size_reducing(func_name: String) -> bool { - match v2_rt::lookup(&function_size_effects(), func_name) - .as_deref() - .cloned() - { - Some(FunctionSizeEffect::TreeSizeReducing) => true, - _ => false, - } + match v2_rt::lookup(&function_size_effects(), func_name).as_deref().cloned() { + Some(FunctionSizeEffect::TreeSizeReducing) => true, + _ => false, +} } pub fn is_property_contraction(func_name: String) -> bool { - match v2_rt::lookup(&function_size_effects(), func_name) - .as_deref() - .cloned() - { - Some(FunctionSizeEffect::PropertyContraction { .. }) => true, - _ => false, - } + match v2_rt::lookup(&function_size_effects(), func_name).as_deref().cloned() { + Some(FunctionSizeEffect::PropertyContraction { .. }) => true, + _ => false, +} } pub fn expr_child_at(texpr: &Rc, index: i64, role: String) -> Rc { match texpr.children.clone().get(index as usize).cloned() { - Some(v) => v.clone(), - None => make_expr_error_node( - ExprErrorKind::InternalExprError, - &v2_rt::concat("malformed node: missing ".to_string(), role), - &texpr.span.clone(), - ), - } + Some(v) => v.clone(), + None => make_expr_error_node(ExprErrorKind::InternalExprError, &v2_rt::concat("malformed node: missing ".to_string(), role), &texpr.span.clone()), +} } -pub fn arg_name_at( - n: Rc, - source_indices: Rc>>, -) -> Option { +pub fn arg_name_at(n: Rc, source_indices: Rc>>) -> Option { { let name = authored_name_at(source_indices, &n); - if (name.clone().as_str() == "".to_string().as_str()) { +if (name.clone().as_str() == "".to_string().as_str()) { None } else { Some(name.clone()) } - } +} } pub fn arg_value(n: &Rc) -> Rc { match n.children.clone().first().cloned() { - Some(v) => v.clone(), - None => make_expr_error_node( - ExprErrorKind::InternalExprError, - &"malformed arg: missing value".to_string(), - &n.span.clone(), - ), - } + Some(v) => v.clone(), + None => make_expr_error_node(ExprErrorKind::InternalExprError, &"malformed arg: missing value".to_string(), &n.span.clone()), +} } pub fn arm_pattern(n: Rc) -> Rc { match n.match_pattern.clone() { - Some(p) => p.clone(), - None => Rc::new(MatchPattern::Wildcard), - } + Some(p) => p.clone(), + None => Rc::new(MatchPattern::Wildcard), +} } pub fn arm_guard(n: &Rc) -> Option> { @@ -1567,31 +1206,20 @@ pub fn arm_guard(n: &Rc) -> Option> { pub fn arm_body(n: &Rc) -> Rc { match n.children.clone().last().cloned() { - Some(v) => v.clone(), - None => make_expr_error_node( - ExprErrorKind::InternalExprError, - &"malformed arm: missing body".to_string(), - &n.span.clone(), - ), - } + Some(v) => v.clone(), + None => make_expr_error_node(ExprErrorKind::InternalExprError, &"malformed arm: missing body".to_string(), &n.span.clone()), +} } -pub fn field_init_node_name_at( - n: Rc, - source_indices: Rc>>, -) -> String { +pub fn field_init_node_name_at(n: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &n) } pub fn field_init_node_value(n: &Rc) -> Rc { match n.children.clone().first().cloned() { - Some(v) => v.clone(), - None => make_expr_error_node( - ExprErrorKind::InternalExprError, - &"malformed field-init: missing value".to_string(), - &n.span.clone(), - ), - } + Some(v) => v.clone(), + None => make_expr_error_node(ExprErrorKind::InternalExprError, &"malformed field-init: missing value".to_string(), &n.span.clone()), +} } pub fn if_condition(texpr: Rc) -> Rc { @@ -1611,15 +1239,7 @@ pub fn match_scrutinee(texpr: Rc) -> Rc { } pub fn match_arm_nodes(texpr: Rc) -> Rc>> { - Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) + Rc::new(texpr.children.clone().iter().cloned().skip(1 as usize).collect::>()) } pub fn binop_left(texpr: Rc) -> Rc { @@ -1634,10 +1254,7 @@ pub fn unaryop_operand(texpr: Rc) -> Rc { expr_child_at(&texpr, 0, "unaryop operand".to_string()) } -pub fn expr_var_name_at( - texpr: Rc, - source_indices: Rc>>, -) -> String { +pub fn expr_var_name_at(texpr: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &texpr) } @@ -1645,35 +1262,26 @@ pub fn field_access_base(texpr: Rc) -> Rc { expr_child_at(&texpr, 0, "field access base".to_string()) } -pub fn field_access_field_at( - texpr: Rc, - source_indices: Rc>>, -) -> String { +pub fn field_access_field_at(texpr: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &texpr) } pub fn expr_field_access_summary(texpr: Rc) -> Option> { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprFieldAccess { summary: s, .. } => s.clone(), - _ => None, - } + ExprData::ExprFieldAccess { summary: s, .. } => s.clone(), + _ => None, +} } -pub fn expr_call_func_at( - texpr: Rc, - source_indices: Rc>>, -) -> String { +pub fn expr_call_func_at(texpr: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &texpr) } pub fn expr_call_descent_evidence(texpr: Rc) -> Option>>> { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprCall { - descent_evidence: de, - .. - } => de.clone(), - _ => None, - } + ExprData::ExprCall { descent_evidence: de, .. } => de.clone(), + _ => None, +} } pub fn method_receiver(texpr: Rc) -> Rc { @@ -1681,60 +1289,26 @@ pub fn method_receiver(texpr: Rc) -> Rc { } pub fn method_arg_nodes(texpr: Rc) -> Rc>> { - Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) -} - -pub fn expr_method_name_at( - texpr: Rc, - source_indices: Rc>>, -) -> String { + Rc::new(texpr.children.clone().iter().cloned().skip(1 as usize).collect::>()) +} + +pub fn expr_method_name_at(texpr: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &texpr) } pub fn expr_method_call_semantics(texpr: Rc) -> Option> { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprMethodCall { - method_semantics: ms, - .. - } => ms.clone(), - _ => None, - } + ExprData::ExprMethodCall { method_semantics: ms, .. } => ms.clone(), + _ => None, +} } pub fn lambda_body(texpr: Rc) -> Rc { expr_child_at(&texpr, 0, "lambda body".to_string()) } -pub fn lambda_param_names_at( - texpr: Rc, - source_indices: Rc>>, -) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for n in Rc::new( - texpr - .children - .clone() - .iter() - .cloned() - .skip(1 as usize) - .collect::>(), - ) - .iter() - .cloned() - { - __result.push(authored_name_at(source_indices.clone(), &n)); - } - __result - }) +pub fn lambda_param_names_at(texpr: Rc, source_indices: Rc>>) -> Rc> { + Rc::new({ let mut __result = Vec::new(); for n in Rc::new(texpr.children.clone().iter().cloned().skip(1 as usize).collect::>()).iter().cloned() { __result.push(authored_name_at(source_indices.clone(), &n)); } __result }) } pub fn let_value(texpr: Rc) -> Rc { @@ -1745,10 +1319,7 @@ pub fn let_body(texpr: Rc) -> Option> { texpr.children.clone().get(1 as usize).cloned() } -pub fn let_binding_name_at( - texpr: Rc, - source_indices: Rc>>, -) -> String { +pub fn let_binding_name_at(texpr: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &texpr) } @@ -1768,10 +1339,7 @@ pub fn foreach_body(texpr: Rc) -> Rc { expr_child_at(&texpr, 1, "foreach body".to_string()) } -pub fn foreach_variable_at( - texpr: Rc, - source_indices: Rc>>, -) -> String { +pub fn foreach_variable_at(texpr: Rc, source_indices: Rc>>) -> String { authored_name_at(source_indices, &texpr) } @@ -1803,18 +1371,15 @@ pub fn block_stmts(texpr: Rc) -> Rc>> { texpr.children.clone() } -pub fn record_lit_type_name_at( - texpr: Rc, - source_indices: Rc>>, -) -> Option { +pub fn record_lit_type_name_at(texpr: Rc, source_indices: Rc>>) -> Option { { let name = authored_name_at(source_indices, &texpr); - if (name.clone().as_str() == "".to_string().as_str()) { +if (name.clone().as_str() == "".to_string().as_str()) { None } else { Some(name.clone()) } - } +} } pub fn transport_url_key() -> String { @@ -1925,245 +1490,138 @@ pub fn transport_headers_key() -> String { CACHED.with(|c| c.clone()) } -pub fn make_transport_node( - properties: Rc>>, - children: Rc>>, - body: Option>, - span: Rc, -) -> Rc { +pub fn make_transport_node(properties: Rc>>, children: Rc>>, body: Option>, span: Rc) -> Rc { Rc::new(Node { - name: "".to_string(), - span: span, - ident_span: None, - children: children, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: body, - transport: None, - properties: properties, - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: "".to_string(), + span: span, + ident_span: None, + children: children, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: body, + transport: None, + properties: properties, + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn local_transport_node(span: Rc) -> Rc { make_transport_node(Rc::new(vec![]), Rc::new(vec![]), None, span) } -pub fn rest_transport_node( - base_url: Rc, - auth_props: Rc>>, - headers: Rc>>, - method: Option>, - path: Option>, - query: Option>, - request_body: Option>, - response_format: Option>, - span: Rc, -) -> Rc { +pub fn rest_transport_node(base_url: Rc, auth_props: Rc>>, headers: Rc>>, method: Option>, path: Option>, query: Option>, request_body: Option>, response_format: Option>, span: Rc) -> Rc { { let zero_span = make_span(0, 0); - let url_field = make_field_init_node( - &transport_url_key(), - base_url, - zero_span.clone(), - zero_span.clone(), - ); - let method_props = match method { - Some(m) => Rc::new(vec![make_field_init_node( - &transport_method_key(), - m.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let path_props = match path { - Some(p) => Rc::new(vec![make_field_init_node( - &transport_path_template_key(), - p.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let query_props = match query { - Some(q) => Rc::new(vec![make_field_init_node( - &transport_query_key(), - q.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let body_props = match request_body { - Some(b) => Rc::new(vec![make_field_init_node( - &transport_body_key(), - b.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let rf_props = match response_format { - Some(rf) => Rc::new(vec![make_field_init_node( - &transport_response_format_key(), - rf.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let props = v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(Rc::new(vec![url_field]), method_props), - path_props, - ), - query_props, - ), - body_props, - ), - rf_props, - ), - auth_props, - ), - headers, - ); - make_transport_node(props, Rc::new(vec![]), None, span) - } +let url_field = make_field_init_node(&transport_url_key(), base_url, zero_span.clone(), zero_span.clone()); +let method_props = match method { + Some(m) => Rc::new(vec![make_field_init_node(&transport_method_key(), m.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let path_props = match path { + Some(p) => Rc::new(vec![make_field_init_node(&transport_path_template_key(), p.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let query_props = match query { + Some(q) => Rc::new(vec![make_field_init_node(&transport_query_key(), q.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let body_props = match request_body { + Some(b) => Rc::new(vec![make_field_init_node(&transport_body_key(), b.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let rf_props = match response_format { + Some(rf) => Rc::new(vec![make_field_init_node(&transport_response_format_key(), rf.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let props = v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(Rc::new(vec![url_field]), method_props), path_props), query_props), body_props), rf_props), auth_props), headers); +make_transport_node(props, Rc::new(vec![]), None, span) +} } -pub fn shell_transport_node( - argv: Rc>>, - env: Rc>>, - stdin: Option>, - span: &Rc, -) -> Rc { +pub fn shell_transport_node(argv: Rc>>, env: Rc>>, stdin: Option>, span: &Rc) -> Rc { { let shell_marker = Rc::new(Node { - name: "".to_string(), - span: span.clone(), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }); - let zero_span = make_span(0, 0); - let stdin_props = match stdin { - Some(s) => Rc::new(vec![make_field_init_node( - &transport_stdin_key(), - s.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let all_props = v2_rt::concat(env, stdin_props); - Rc::new(Node { - name: "".to_string(), - span: span.clone(), - ident_span: None, - children: argv, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: Some(shell_marker), - transport: None, - properties: all_props, - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } + name: "".to_string(), + span: span.clone(), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}); +let zero_span = make_span(0, 0); +let stdin_props = match stdin { + Some(s) => Rc::new(vec![make_field_init_node(&transport_stdin_key(), s.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let all_props = v2_rt::concat(env, stdin_props); +Rc::new(Node { + name: "".to_string(), + span: span.clone(), + ident_span: None, + children: argv, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: Some(shell_marker), + transport: None, + properties: all_props, + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} } pub fn file_transport_node(base_path: Rc, span: Rc) -> Rc { { - let path_field = make_field_init_node( - &transport_path_key(), - base_path, - make_span(0, 0), - make_span(0, 0), - ); - make_transport_node(Rc::new(vec![path_field]), Rc::new(vec![]), None, span) - } + let path_field = make_field_init_node(&transport_path_key(), base_path, make_span(0, 0), make_span(0, 0)); +make_transport_node(Rc::new(vec![path_field]), Rc::new(vec![]), None, span) +} } -pub fn find_property( - props: Rc>>, - prop_name: String, - source_indices: Rc>>, -) -> Option> { - match Rc::new({ - let mut __result = Vec::new(); - for p in props.iter().cloned() { - if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() - == prop_name.clone().as_str()) - { - __result.push(p); - } - } - __result - }) - .first() - .cloned() - { - Some(fi) => Some(field_init_node_value(&fi)), - None => None, - } +pub fn find_property(props: Rc>>, prop_name: String, source_indices: Rc>>) -> Option> { + match Rc::new({ let mut __result = Vec::new(); for p in props.iter().cloned() { if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() == prop_name.clone().as_str()) { __result.push(p); } } __result }).first().cloned() { + Some(fi) => Some(field_init_node_value(&fi)), + None => None, +} } -pub fn find_property_string( - props: Rc>>, - prop_name: String, - source_indices: Rc>>, -) -> Option { +pub fn find_property_string(props: Rc>>, prop_name: String, source_indices: Rc>>) -> Option { match find_property(props, prop_name, source_indices) { - Some(n) => match (*n.expr_data.clone()).clone() { - ExprData::ExprLiteral { ref value, .. } => { - let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { - unreachable!() - }; - Some(s.clone()) - } - _ => None, - }, - None => None, - } + Some(n) => match (*n.expr_data.clone()).clone() { + ExprData::ExprLiteral { ref value, .. } => { let LiteralValue::LitStr { value: s, .. } = value.as_ref() else { unreachable!() }; Some(s.clone()) }, + _ => None, +}, + None => None, +} } -pub fn transport_base_path( - t: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn transport_base_path(t: Rc, source_indices: Rc>>) -> Option> { find_property(t.properties.clone(), transport_path_key(), source_indices) } @@ -2171,10 +1629,7 @@ pub fn transport_has_argv(t: Rc) -> bool { ((t.children.clone().len() as i64) > 0) } -pub fn is_rest_transport( - t: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_rest_transport(t: Rc, source_indices: Rc>>) -> bool { (transport_base_url(t, source_indices) != None) } @@ -2182,28 +1637,18 @@ pub fn is_shell_transport(t: Rc) -> bool { (t.body.clone() != None) } -pub fn is_file_transport( - t: Rc, - source_indices: Rc>>, -) -> bool { +pub fn is_file_transport(t: Rc, source_indices: Rc>>) -> bool { (transport_base_path(t, source_indices) != None) } -pub fn is_local_transport( - t: &Rc, - source_indices: &Rc>>, -) -> bool { - ((!is_rest_transport(t.clone(), source_indices.clone()) && !is_shell_transport(t.clone())) - && !is_file_transport(t.clone(), source_indices.clone())) +pub fn is_local_transport(t: &Rc, source_indices: &Rc>>) -> bool { + ((!is_rest_transport(t.clone(), source_indices.clone()) && !is_shell_transport(t.clone())) && !is_file_transport(t.clone(), source_indices.clone())) } -pub fn field_init_operation_modifier( - field_init: Rc, - source_indices: Rc>>, -) -> Option { +pub fn field_init_operation_modifier(field_init: Rc, source_indices: Rc>>) -> Option { { let fi_name = field_init_node_name_at(field_init, source_indices); - if (fi_name.clone().as_str() == "idempotent".to_string().as_str()) { +if (fi_name.clone().as_str() == "idempotent".to_string().as_str()) { Some(OperationModifier::Idempotent) } else { if (fi_name.clone().as_str() == "readonly".to_string().as_str()) { @@ -2216,700 +1661,304 @@ pub fn field_init_operation_modifier( } } } - } +} } pub fn operation_modifier_name(modifier: OperationModifier) -> String { match modifier { - OperationModifier::Idempotent => "idempotent".to_string(), - OperationModifier::Readonly => "readonly".to_string(), - OperationModifier::Hermetic => "hermetic".to_string(), - } + OperationModifier::Idempotent => "idempotent".to_string(), + OperationModifier::Readonly => "readonly".to_string(), + OperationModifier::Hermetic => "hermetic".to_string(), +} } -pub fn transport_base_url( - t: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn transport_base_url(t: Rc, source_indices: Rc>>) -> Option> { find_property(t.properties.clone(), transport_url_key(), source_indices) } -pub fn transport_auth_token( - t: Rc, - source_indices: Rc>>, -) -> Option> { - find_property( - t.properties.clone(), - transport_auth_token_key(), - source_indices, - ) -} - -pub fn transport_auth_header_name( - t: Rc, - source_indices: Rc>>, -) -> Option { - find_property_string( - t.properties.clone(), - transport_auth_header_key(), - source_indices, - ) -} - -pub fn transport_has_auth( - t: Rc, - source_indices: Rc>>, -) -> bool { - match find_property( - t.properties.clone(), - transport_auth_token_key(), - source_indices, - ) { - Some(_) => true, - None => false, - } +pub fn transport_auth_token(t: Rc, source_indices: Rc>>) -> Option> { + find_property(t.properties.clone(), transport_auth_token_key(), source_indices) +} + +pub fn transport_auth_header_name(t: Rc, source_indices: Rc>>) -> Option { + find_property_string(t.properties.clone(), transport_auth_header_key(), source_indices) +} + +pub fn transport_has_auth(t: Rc, source_indices: Rc>>) -> bool { + match find_property(t.properties.clone(), transport_auth_token_key(), source_indices) { + Some(_) => true, + None => false, +} } -pub fn transport_method( - t: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn transport_method(t: Rc, source_indices: Rc>>) -> Option> { find_property(t.properties.clone(), transport_method_key(), source_indices) } -pub fn transport_path_template( - t: Rc, - source_indices: Rc>>, -) -> Option> { - find_property( - t.properties.clone(), - transport_path_template_key(), - source_indices, - ) +pub fn transport_path_template(t: Rc, source_indices: Rc>>) -> Option> { + find_property(t.properties.clone(), transport_path_template_key(), source_indices) } -pub fn transport_query( - t: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn transport_query(t: Rc, source_indices: Rc>>) -> Option> { find_property(t.properties.clone(), transport_query_key(), source_indices) } -pub fn transport_request_body( - t: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn transport_request_body(t: Rc, source_indices: Rc>>) -> Option> { find_property(t.properties.clone(), transport_body_key(), source_indices) } -pub fn transport_stdin( - t: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn transport_stdin(t: Rc, source_indices: Rc>>) -> Option> { find_property(t.properties.clone(), transport_stdin_key(), source_indices) } -pub fn transport_response_format( - t: Rc, - source_indices: Rc>>, -) -> Option> { - find_property( - t.properties.clone(), - transport_response_format_key(), - source_indices, - ) +pub fn transport_response_format(t: Rc, source_indices: Rc>>) -> Option> { + find_property(t.properties.clone(), transport_response_format_key(), source_indices) } pub fn is_config_reserved_key(name: &String) -> bool { - ((((((((((((name.clone().as_str() == transport_url_key().as_str()) - || (name.clone().as_str() == transport_path_key().as_str())) - || (name.clone().as_str() == transport_auth_scheme_key().as_str())) - || (name.clone().as_str() == transport_auth_header_key().as_str())) - || (name.clone().as_str() == transport_auth_token_key().as_str())) - || (name.clone().as_str() == transport_method_key().as_str())) - || (name.clone().as_str() == transport_path_template_key().as_str())) - || (name.clone().as_str() == transport_query_key().as_str())) - || (name.clone().as_str() == transport_body_key().as_str())) - || (name.clone().as_str() == transport_stdin_key().as_str())) - || (name.clone().as_str() == transport_response_format_key().as_str())) - || (name.clone().as_str() == transport_headers_key().as_str())) -} - -pub fn transport_headers( - t: Rc, - source_indices: Rc>>, -) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for p in t.properties.clone().iter().cloned() { - if !is_config_reserved_key(&field_init_node_name_at(p.clone(), source_indices.clone())) - { - __result.push(p); - } - } - __result - }) + ((((((((((((name.clone().as_str() == transport_url_key().as_str()) || (name.clone().as_str() == transport_path_key().as_str())) || (name.clone().as_str() == transport_auth_scheme_key().as_str())) || (name.clone().as_str() == transport_auth_header_key().as_str())) || (name.clone().as_str() == transport_auth_token_key().as_str())) || (name.clone().as_str() == transport_method_key().as_str())) || (name.clone().as_str() == transport_path_template_key().as_str())) || (name.clone().as_str() == transport_query_key().as_str())) || (name.clone().as_str() == transport_body_key().as_str())) || (name.clone().as_str() == transport_stdin_key().as_str())) || (name.clone().as_str() == transport_response_format_key().as_str())) || (name.clone().as_str() == transport_headers_key().as_str())) } -pub fn transport_env( - t: Rc, - source_indices: Rc>>, -) -> Rc>> { - Rc::new({ - let mut __result = Vec::new(); - for p in t.properties.clone().iter().cloned() { - if !is_config_reserved_key(&field_init_node_name_at(p.clone(), source_indices.clone())) - { - __result.push(p); - } - } - __result - }) +pub fn transport_headers(t: Rc, source_indices: Rc>>) -> Rc>> { + Rc::new({ let mut __result = Vec::new(); for p in t.properties.clone().iter().cloned() { if !is_config_reserved_key(&field_init_node_name_at(p.clone(), source_indices.clone())) { __result.push(p); } } __result }) } -pub fn map_children(node: &Rc, transform: impl Fn(Rc) -> Rc + Clone) -> Rc { - Rc::new(Node { - name: node.name.clone(), - ident: node.ident.clone(), - span: node.span.clone(), - ident_span: node.ident_span.clone(), - children: Rc::new({ - let mut __result = Vec::new(); - for child in node.children.clone().iter().cloned() { - __result.push(transform(child.clone())); - } - __result - }), - connective: node.connective.clone(), - params: node.params.clone(), - inferred: node.inferred.clone(), - return_cardinality: node.return_cardinality.clone(), - uses: node.uses.clone(), - body: node.body.clone(), - transport: node.transport.clone(), - properties: node.properties.clone(), - type_annotation: node.type_annotation.clone(), - is_self_recursive: node.is_self_recursive.clone(), - has_non_tail_self_call: node.has_non_tail_self_call.clone(), - match_pattern: node.match_pattern.clone(), - expr_data: node.expr_data.clone(), - }) +pub fn transport_env(t: Rc, source_indices: Rc>>) -> Rc>> { + Rc::new({ let mut __result = Vec::new(); for p in t.properties.clone().iter().cloned() { if !is_config_reserved_key(&field_init_node_name_at(p.clone(), source_indices.clone())) { __result.push(p); } } __result }) } -pub fn expr_has_self_call( - texpr: &Rc, - fn_name: &String, - source_indices: &Rc>>, -) -> bool { +pub fn map_children(node: &Rc, transform: impl Fn(Rc) -> Rc + Clone) -> Rc { + Rc::new(Node { + name: node.name.clone(), + ident: node.ident.clone(), + span: node.span.clone(), + ident_span: node.ident_span.clone(), + children: Rc::new({ let mut __result = Vec::new(); for child in node.children.clone().iter().cloned() { __result.push(transform(child.clone())); } __result }), + connective: node.connective.clone(), + params: node.params.clone(), + inferred: node.inferred.clone(), + return_cardinality: node.return_cardinality.clone(), + uses: node.uses.clone(), + body: node.body.clone(), + transport: node.transport.clone(), + properties: node.properties.clone(), + type_annotation: node.type_annotation.clone(), + is_self_recursive: node.is_self_recursive.clone(), + has_non_tail_self_call: node.has_non_tail_self_call.clone(), + match_pattern: node.match_pattern.clone(), + expr_data: node.expr_data.clone(), +}) +} + +pub fn expr_has_self_call(texpr: &Rc, fn_name: &String, source_indices: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - if (expr_call_func_at(texpr.clone(), source_indices.clone()).as_str() - == fn_name.clone().as_str()) - { - true - } else { - { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_self_call(&child, &fn_name, &source_indices) { - __found = true; - break; - } - } - __found - } - } - } - _ => { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_self_call(&child, &fn_name, &source_indices) { - __found = true; - break; - } - } - __found - } - } + ExprData::ExprCall { .. } => if (expr_call_func_at(texpr.clone(), source_indices.clone()).as_str() == fn_name.clone().as_str()) { + true + } else { + { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_self_call(&child, &fn_name, &source_indices) { __found = true; break; } } __found } + }, + _ => { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_self_call(&child, &fn_name, &source_indices) { __found = true; break; } } __found }, +} }) } -pub fn expr_has_non_tail_self_call( - texpr: &Rc, - fn_name: &String, - in_tail: bool, - source_indices: &Rc>>, -) -> bool { +pub fn expr_has_non_tail_self_call(texpr: &Rc, fn_name: &String, in_tail: bool, source_indices: &Rc>>) -> bool { stacker::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { match (*texpr.expr_data.clone()).clone() { - ExprData::ExprCall { .. } => { - if (expr_call_func_at(texpr.clone(), source_indices.clone()).as_str() - == fn_name.clone().as_str()) - { - if (in_tail.clone() == false) { - true - } else { - { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_non_tail_self_call( - &child, - &fn_name, - false, - &source_indices, - ) { - __found = true; - break; - } - } - __found - } - } - } else { - { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) - { - __found = true; - break; - } - } - __found - } - } - } - ExprData::ExprError { .. } => false, - ExprData::ExprVar { .. } => false, - ExprData::ExprLiteral { .. } => false, - ExprData::ExprFieldAccess { .. } => { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) { - __found = true; - break; - } - } - __found - } - ExprData::ExprMethodCall { .. } => { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) { - __found = true; - break; - } - } - __found - } - ExprData::ExprIf => { - let cond_bad = expr_has_non_tail_self_call( - &if_condition(texpr.clone()), - &fn_name, - false, - &source_indices, - ); - let then_bad = expr_has_non_tail_self_call( - &if_then_branch(texpr.clone()), - &fn_name, - in_tail.clone(), - &source_indices, - ); - let else_bad = match if_else_branch(texpr.clone()) { - Some(e) => { - expr_has_non_tail_self_call(&e, &fn_name, in_tail.clone(), &source_indices) - } - None => false, - }; - ((cond_bad || then_bad) || else_bad) - } - ExprData::ExprMatch => { - let scrut_bad = expr_has_non_tail_self_call( - &match_scrutinee(texpr.clone()), - &fn_name, - false, - &source_indices, - ); - let arms_bad = { - let mut __found = false; - for arm_node in match_arm_nodes(texpr.clone()).iter().cloned() { - if expr_has_non_tail_self_call( - &arm_body(&arm_node), - &fn_name, - in_tail.clone(), - &source_indices, - ) { - __found = true; - break; - } - } - __found - }; - (scrut_bad || arms_bad) - } - ExprData::ExprLet => { - let val_bad = expr_has_non_tail_self_call( - &let_value(texpr.clone()), - &fn_name, - false, - &source_indices, - ); - let body_bad = match let_body(texpr.clone()) { - Some(b) => { - expr_has_non_tail_self_call(&b, &fn_name, in_tail.clone(), &source_indices) - } - None => false, - }; - (val_bad || body_bad) - } - ExprData::ExprBlock => { - let ss = texpr.children.clone(); - let ss_count = (ss.clone().len() as i64); - if (ss_count.clone() == 0) { - false - } else { - { - let init_bad = { - let mut __found = false; - for p in Rc::new({ - let mut __result = Vec::new(); - for p in Rc::new( - ss.clone() - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - { - if (p.0.clone() < (ss_count.clone() - 1)) { - __result.push(p); - } - } - __result - }) - .iter() - .cloned() - { - if expr_has_non_tail_self_call( - &p.1.clone(), - &fn_name, - false, - &source_indices, - ) { - __found = true; - break; - } - } - __found - }; - let last_bad = match ss.clone().last().cloned() { - Some(last_expr) => expr_has_non_tail_self_call( - &last_expr, - &fn_name, - in_tail.clone(), - &source_indices, - ), - None => false, - }; - (init_bad || last_bad) - } - } - } - ExprData::ExprReturn => { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_non_tail_self_call(&child, &fn_name, true, &source_indices) { - __found = true; - break; - } - } - __found - } - ExprData::NoExprData => { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_non_tail_self_call( - &child, - &fn_name, - in_tail.clone(), - &source_indices, - ) { - __found = true; - break; - } - } - __found + ExprData::ExprCall { .. } => if (expr_call_func_at(texpr.clone(), source_indices.clone()).as_str() == fn_name.clone().as_str()) { + if (in_tail.clone() == false) { + true + } else { + { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) { __found = true; break; } } __found } } - _ => { - let mut __found = false; - for child in texpr.children.clone().iter().cloned() { - if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) { - __found = true; - break; - } - } - __found + } else { + { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) { __found = true; break; } } __found } + }, + ExprData::ExprError { .. } => false, + ExprData::ExprVar { .. } => false, + ExprData::ExprLiteral { .. } => false, + ExprData::ExprFieldAccess { .. } => { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) { __found = true; break; } } __found }, + ExprData::ExprMethodCall { .. } => { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) { __found = true; break; } } __found }, + ExprData::ExprIf => { + let cond_bad = expr_has_non_tail_self_call(&if_condition(texpr.clone()), &fn_name, false, &source_indices); +let then_bad = expr_has_non_tail_self_call(&if_then_branch(texpr.clone()), &fn_name, in_tail.clone(), &source_indices); +let else_bad = match if_else_branch(texpr.clone()) { + Some(e) => expr_has_non_tail_self_call(&e, &fn_name, in_tail.clone(), &source_indices), + None => false, +}; +((cond_bad || then_bad) || else_bad) +}, + ExprData::ExprMatch => { + let scrut_bad = expr_has_non_tail_self_call(&match_scrutinee(texpr.clone()), &fn_name, false, &source_indices); +let arms_bad = { let mut __found = false; for arm_node in match_arm_nodes(texpr.clone()).iter().cloned() { if expr_has_non_tail_self_call(&arm_body(&arm_node), &fn_name, in_tail.clone(), &source_indices) { __found = true; break; } } __found }; +(scrut_bad || arms_bad) +}, + ExprData::ExprLet => { + let val_bad = expr_has_non_tail_self_call(&let_value(texpr.clone()), &fn_name, false, &source_indices); +let body_bad = match let_body(texpr.clone()) { + Some(b) => expr_has_non_tail_self_call(&b, &fn_name, in_tail.clone(), &source_indices), + None => false, +}; +(val_bad || body_bad) +}, + ExprData::ExprBlock => { + let ss = texpr.children.clone(); +let ss_count = (ss.clone().len() as i64); +if (ss_count.clone() == 0) { + false + } else { + { + let init_bad = { let mut __found = false; for p in Rc::new({ let mut __result = Vec::new(); for p in Rc::new(ss.clone().iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned() { if (p.0.clone() < (ss_count.clone() - 1)) { __result.push(p); } } __result }).iter().cloned() { if expr_has_non_tail_self_call(&p.1.clone(), &fn_name, false, &source_indices) { __found = true; break; } } __found }; +let last_bad = match ss.clone().last().cloned() { + Some(last_expr) => expr_has_non_tail_self_call(&last_expr, &fn_name, in_tail.clone(), &source_indices), + None => false, +}; +(init_bad || last_bad) +} } - } +}, + ExprData::ExprReturn => { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_non_tail_self_call(&child, &fn_name, true, &source_indices) { __found = true; break; } } __found }, + ExprData::NoExprData => { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_non_tail_self_call(&child, &fn_name, in_tail.clone(), &source_indices) { __found = true; break; } } __found }, + _ => { let mut __found = false; for child in texpr.children.clone().iter().cloned() { if expr_has_non_tail_self_call(&child, &fn_name, false, &source_indices) { __found = true; break; } } __found }, +} }) } -pub fn service_config_properties( - endpoint: Rc, - auth: Option>, - auth_input: Option>, - auth_source: Option>, - rate_limit: Option>, - retry: Option>, -) -> Rc>> { +pub fn service_config_properties(endpoint: Rc, auth: Option>, auth_input: Option>, auth_source: Option>, rate_limit: Option>, retry: Option>) -> Rc>> { { let zero_span = make_span(0, 0); - let ep_prop = Rc::new(vec![make_field_init_node( - &"svc_endpoint".to_string(), - endpoint, - zero_span.clone(), - zero_span.clone(), - )]); - let auth_prop = match auth { - Some(a) => Rc::new(vec![make_field_init_node( - &"svc_auth".to_string(), - a.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let auth_input_prop = match auth_input { - Some(ai) => Rc::new(vec![make_field_init_node( - &"svc_auth_input".to_string(), - ai.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let auth_source_prop = match auth_source { - Some(src) => Rc::new(vec![make_field_init_node( - &"svc_auth_source".to_string(), - src.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let rate_prop = match rate_limit { - Some(r) => Rc::new(vec![make_field_init_node( - &"svc_rate_limit".to_string(), - r.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - let retry_prop = match retry { - Some(r) => Rc::new(vec![make_field_init_node( - &"svc_retry".to_string(), - r.clone(), - zero_span.clone(), - zero_span.clone(), - )]), - None => Rc::new(vec![]), - }; - v2_rt::concat( - v2_rt::concat( - v2_rt::concat( - v2_rt::concat(v2_rt::concat(ep_prop, auth_prop), auth_input_prop), - auth_source_prop, - ), - rate_prop, - ), - retry_prop, - ) - } +let ep_prop = Rc::new(vec![make_field_init_node(&"svc_endpoint".to_string(), endpoint, zero_span.clone(), zero_span.clone())]); +let auth_prop = match auth { + Some(a) => Rc::new(vec![make_field_init_node(&"svc_auth".to_string(), a.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let auth_input_prop = match auth_input { + Some(ai) => Rc::new(vec![make_field_init_node(&"svc_auth_input".to_string(), ai.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let auth_source_prop = match auth_source { + Some(src) => Rc::new(vec![make_field_init_node(&"svc_auth_source".to_string(), src.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let rate_prop = match rate_limit { + Some(r) => Rc::new(vec![make_field_init_node(&"svc_rate_limit".to_string(), r.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +let retry_prop = match retry { + Some(r) => Rc::new(vec![make_field_init_node(&"svc_retry".to_string(), r.clone(), zero_span.clone(), zero_span.clone())]), + None => Rc::new(vec![]), +}; +v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(v2_rt::concat(ep_prop, auth_prop), auth_input_prop), auth_source_prop), rate_prop), retry_prop) +} } -pub fn has_service_config( - n: Rc, - source_indices: Rc>>, -) -> bool { - { - let mut __found = false; - for p in n.properties.clone().iter().cloned() { - if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() - == "svc_endpoint".to_string().as_str()) - { - __found = true; - break; - } - } - __found - } +pub fn has_service_config(n: Rc, source_indices: Rc>>) -> bool { + { let mut __found = false; for p in n.properties.clone().iter().cloned() { if (field_init_node_name_at(p.clone(), source_indices.clone()).as_str() == "svc_endpoint".to_string().as_str()) { __found = true; break; } } __found } } -pub fn service_config_endpoint( - n: Rc, - source_indices: Rc>>, -) -> Option> { - find_property( - n.properties.clone(), - "svc_endpoint".to_string(), - source_indices, - ) +pub fn service_config_endpoint(n: Rc, source_indices: Rc>>) -> Option> { + find_property(n.properties.clone(), "svc_endpoint".to_string(), source_indices) } -pub fn service_config_auth( - n: Rc, - source_indices: Rc>>, -) -> Option> { +pub fn service_config_auth(n: Rc, source_indices: Rc>>) -> Option> { find_property(n.properties.clone(), "svc_auth".to_string(), source_indices) } -pub fn service_config_rate_limit( - n: Rc, - source_indices: Rc>>, -) -> Option> { - find_property( - n.properties.clone(), - "svc_rate_limit".to_string(), - source_indices, - ) -} - -pub fn service_config_retry( - n: Rc, - source_indices: Rc>>, -) -> Option> { - find_property( - n.properties.clone(), - "svc_retry".to_string(), - source_indices, - ) -} - -pub fn service_config_auth_input( - n: Rc, - source_indices: Rc>>, -) -> Option> { - find_property( - n.properties.clone(), - "svc_auth_input".to_string(), - source_indices, - ) -} - -pub fn service_config_auth_source( - n: Rc, - source_indices: Rc>>, -) -> Option> { - find_property( - n.properties.clone(), - "svc_auth_source".to_string(), - source_indices, - ) -} - -pub fn module_node( - name: &String, - imports: Rc>>, - items: Rc>>, - span: &Rc, -) -> Rc { - Rc::new(Node { - name: name.clone(), - span: span.clone(), - ident_span: default_ident_span(name.clone(), span.clone()), - children: items, - connective: Connective::NoConnective, - params: imports, - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) +pub fn service_config_rate_limit(n: Rc, source_indices: Rc>>) -> Option> { + find_property(n.properties.clone(), "svc_rate_limit".to_string(), source_indices) +} + +pub fn service_config_retry(n: Rc, source_indices: Rc>>) -> Option> { + find_property(n.properties.clone(), "svc_retry".to_string(), source_indices) +} + +pub fn service_config_auth_input(n: Rc, source_indices: Rc>>) -> Option> { + find_property(n.properties.clone(), "svc_auth_input".to_string(), source_indices) +} + +pub fn service_config_auth_source(n: Rc, source_indices: Rc>>) -> Option> { + find_property(n.properties.clone(), "svc_auth_source".to_string(), source_indices) } -pub fn import_node( - module_path: String, - is_all: bool, - specific_names: Rc>>, - span: &Rc, - name_span: Rc, -) -> Rc { +pub fn module_node(name: &String, imports: Rc>>, items: Rc>>, span: &Rc) -> Rc { + Rc::new(Node { + name: name.clone(), + span: span.clone(), + ident_span: default_ident_span(name.clone(), span.clone()), + children: items, + connective: Connective::NoConnective, + params: imports, + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} + +pub fn import_node(module_path: String, is_all: bool, specific_names: Rc>>, span: &Rc, name_span: Rc) -> Rc { { let wildcard_marker = if is_all { Some(Rc::new(Node { - name: "".to_string(), - span: span.clone(), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - })) + name: "".to_string(), + span: span.clone(), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +})) } else { None }; - Rc::new(Node { - name: module_path, - span: span.clone(), - ident_span: Some(name_span), - children: specific_names, - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: wildcard_marker, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - } +Rc::new(Node { + name: module_path, + span: span.clone(), + ident_span: Some(name_span), + children: specific_names, + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: wildcard_marker, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) +} } pub fn import_is_all(n: Rc) -> bool { (n.body.clone() != None) } -pub fn import_specific_names_at( - n: Rc, - source_indices: Rc>>, -) -> Rc> { - Rc::new({ - let mut __result = Vec::new(); - for c in n.children.clone().iter().cloned() { - __result.push(authored_name_at(source_indices.clone(), &c)); - } - __result - }) +pub fn import_specific_names_at(n: Rc, source_indices: Rc>>) -> Rc> { + Rc::new({ let mut __result = Vec::new(); for c in n.children.clone().iter().cloned() { __result.push(authored_name_at(source_indices.clone(), &c)); } __result }) } pub fn module_imports(n: Rc) -> Rc>> { @@ -2922,203 +1971,200 @@ pub fn module_items(n: Rc) -> Rc>> { pub fn leaf_node_with_span(name: &String, span: &Rc) -> Rc { Rc::new(Node { - name: name.clone(), - span: span.clone(), - ident_span: default_ident_span(name.clone(), span.clone()), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) + name: name.clone(), + span: span.clone(), + ident_span: default_ident_span(name.clone(), span.clone()), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) } pub fn kernel_span(name: &String) -> Rc { Rc::new(SourceSpan { - file: v2_rt::concat( - v2_rt::concat("".to_string(), - ), - start: 0, - end: v2_rt::string_length(&name), - }) + file: v2_rt::concat(v2_rt::concat("".to_string()), + start: 0, + end: v2_rt::string_length(&name), +}) } pub fn unit_type() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(Node { - name: "Unit".to_string(), - span: kernel_span(&"Unit".to_string()), - ident_span: Some(kernel_span(&"Unit".to_string())), - children: Rc::new(vec![]), - connective: Connective::Conj, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - }; - } + static CACHED: Rc = { + Rc::new(Node { + name: "Unit".to_string(), + span: kernel_span(&"Unit".to_string()), + ident_span: Some(kernel_span(&"Unit".to_string())), + children: Rc::new(vec![]), + connective: Connective::Conj, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) + }; + } CACHED.with(|c| c.clone()) } pub fn bool_type() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(Node { - name: "Bool".to_string(), - span: kernel_span(&"Bool".to_string()), - ident_span: Some(kernel_span(&"Bool".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - }; - } + static CACHED: Rc = { + Rc::new(Node { + name: "Bool".to_string(), + span: kernel_span(&"Bool".to_string()), + ident_span: Some(kernel_span(&"Bool".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) + }; + } CACHED.with(|c| c.clone()) } pub fn string_type() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(Node { - name: "String".to_string(), - span: kernel_span(&"String".to_string()), - ident_span: Some(kernel_span(&"String".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - }; - } + static CACHED: Rc = { + Rc::new(Node { + name: "String".to_string(), + span: kernel_span(&"String".to_string()), + ident_span: Some(kernel_span(&"String".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) + }; + } CACHED.with(|c| c.clone()) } pub fn int_type() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(Node { - name: "Int".to_string(), - span: kernel_span(&"Int".to_string()), - ident_span: Some(kernel_span(&"Int".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - }; - } + static CACHED: Rc = { + Rc::new(Node { + name: "Int".to_string(), + span: kernel_span(&"Int".to_string()), + ident_span: Some(kernel_span(&"Int".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) + }; + } CACHED.with(|c| c.clone()) } pub fn float_type() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(Node { - name: "Float".to_string(), - span: kernel_span(&"Float".to_string()), - ident_span: Some(kernel_span(&"Float".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - }; - } + static CACHED: Rc = { + Rc::new(Node { + name: "Float".to_string(), + span: kernel_span(&"Float".to_string()), + ident_span: Some(kernel_span(&"Float".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) + }; + } CACHED.with(|c| c.clone()) } pub fn none_type() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(Node { - name: "None".to_string(), - span: kernel_span(&"None".to_string()), - ident_span: Some(kernel_span(&"None".to_string())), - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: None, - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::NoExprData), - ident: None, - }) - }; - } + static CACHED: Rc = { + Rc::new(Node { + name: "None".to_string(), + span: kernel_span(&"None".to_string()), + ident_span: Some(kernel_span(&"None".to_string())), + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: None, + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::NoExprData), + ident: None, +}) + }; + } CACHED.with(|c| c.clone()) } @@ -3133,52 +2179,52 @@ pub fn tuple_type_name() -> String { pub fn error_type() -> Rc { thread_local! { - static CACHED: Rc = { - Rc::new(Node { - name: "".to_string(), - span: make_span(0, 0), - ident_span: None, - children: Rc::new(vec![]), - connective: Connective::NoConnective, - params: Rc::new(vec![]), - inferred: Some(Rc::new(InferredNode::CompilerError { - message: "unresolved type".to_string(), - span: make_span(0, 0), - })), - return_cardinality: Cardinality::Required, - uses: Rc::new(vec![]), - body: None, - transport: None, - properties: Rc::new(vec![]), - type_annotation: None, - is_self_recursive: false, - has_non_tail_self_call: false, - match_pattern: None, - expr_data: Rc::new(ExprData::ExprError { - kind: ExprErrorKind::SemanticExprError, - message: "unresolved type".to_string(), - }), - ident: None, - }) - }; - } + static CACHED: Rc = { + Rc::new(Node { + name: "".to_string(), + span: make_span(0, 0), + ident_span: None, + children: Rc::new(vec![]), + connective: Connective::NoConnective, + params: Rc::new(vec![]), + inferred: Some(Rc::new(InferredNode::CompilerError { + message: "unresolved type".to_string(), + span: make_span(0, 0), +})), + return_cardinality: Cardinality::Required, + uses: Rc::new(vec![]), + body: None, + transport: None, + properties: Rc::new(vec![]), + type_annotation: None, + is_self_recursive: false, + has_non_tail_self_call: false, + match_pattern: None, + expr_data: Rc::new(ExprData::ExprError { + kind: ExprErrorKind::SemanticExprError, + message: "unresolved type".to_string(), +}), + ident: None, +}) + }; + } CACHED.with(|c| c.clone()) } pub fn make_span(start: i64, end: i64) -> Rc { Rc::new(SourceSpan { - file: "".to_string(), - start: start, - end: end, - }) + file: "".to_string(), + start: start, + end: end, +}) } pub fn make_file_span(file: String, start: i64, end: i64) -> Rc { Rc::new(SourceSpan { - file: file, - start: start, - end: end, - }) + file: file, + start: start, + end: end, +}) } pub fn no_span() -> Rc { @@ -3201,29 +2247,17 @@ pub struct NewlineIndex { pub fn build_newline_index(file: String, source: &String) -> Rc { { let char_codes = Rc::new(source.clone().chars().map(|c| c as i64).collect::>()); - let offsets = Rc::new( - char_codes - .iter() - .cloned() - .enumerate() - .map(|(i, v)| (i as i64, v)) - .collect::>(), - ) - .iter() - .cloned() - .fold(Rc::new(vec![]), |acc: _, pair: (i64, i64)| { - if (pair.1.clone() == 10) { - v2_rt::rc_list_push(acc.clone(), pair.0.clone()) - } else { - acc.clone() - } +let offsets = Rc::new(char_codes.iter().cloned().enumerate().map(|(i, v)| (i as i64, v)).collect::>()).iter().cloned().fold(Rc::new(vec![]), |acc: _, pair: (i64, i64)| if (pair.1.clone() == 10) { + v2_rt::rc_list_push(acc.clone(), pair.0.clone()) + } else { + acc.clone() }); - Rc::new(NewlineIndex { - file: file, - offsets: offsets, - source: source.clone(), - }) - } +Rc::new(NewlineIndex { + file: file, + offsets: offsets, + source: source.clone(), +}) +} } pub fn byte_to_line_col(index: &Rc, offset: i64) -> LineCol { @@ -3233,65 +2267,40 @@ pub fn byte_to_line_col(index: &Rc, offset: i64) -> LineCol { } else { offset.clone() }; - let line = ((Rc::new({ - let mut __result = Vec::new(); - for o in index.offsets.clone().iter().cloned() { - if (o.clone() < clamped.clone()) { - __result.push(o); - } - } - __result - }) - .len() as i64) - + 1); - let line_start = if (line.clone() <= 1) { +let line = ((Rc::new({ let mut __result = Vec::new(); for o in index.offsets.clone().iter().cloned() { if (o.clone() < clamped.clone()) { __result.push(o); } } __result }).len() as i64) + 1); +let line_start = if (line.clone() <= 1) { 0 } else { - match index - .offsets - .clone() - .get((line.clone() - 2) as usize) - .cloned() - { - Some(o) => (o.clone() + 1), - None => 0, - } + match index.offsets.clone().get((line.clone() - 2) as usize).cloned() { + Some(o) => (o.clone() + 1), + None => 0, +} }; - let col = ((clamped.clone() - line_start) + 1); - LineCol { - line: line.clone(), - col: col, - } - } +let col = ((clamped.clone() - line_start) + 1); +LineCol { + line: line.clone(), + col: col, +} +} } pub fn source_line_at(index: &Rc, line: i64) -> String { { let src_len = v2_rt::string_length(&index.source.clone()); - let line_start = if (line.clone() <= 1) { +let line_start = if (line.clone() <= 1) { 0 } else { - match index - .offsets - .clone() - .get((line.clone() - 2) as usize) - .cloned() - { - Some(o) => (o.clone() + 1), - None => src_len.clone(), - } - }; - let line_end = match index - .offsets - .clone() - .get((line.clone() - 1) as usize) - .cloned() - { - Some(o) => o.clone(), - None => src_len.clone(), + match index.offsets.clone().get((line.clone() - 2) as usize).cloned() { + Some(o) => (o.clone() + 1), + None => src_len.clone(), +} }; - v2_rt::substring(&index.source.clone(), line_start, line_end) - } +let line_end = match index.offsets.clone().get((line.clone() - 1) as usize).cloned() { + Some(o) => o.clone(), + None => src_len.clone(), +}; +v2_rt::substring(&index.source.clone(), line_start, line_end) +} } pub fn source_text_at(index: Rc, span: &Rc) -> String { @@ -3313,135 +2322,119 @@ pub struct InternResult { pub fn empty_intern_table() -> Rc { Rc::new(InternTable { - strings: Rc::new(vec!["".to_string()]), - index: v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), "".to_string(), 0), - next_id: 1, - }) + strings: Rc::new(vec!["".to_string()]), + index: v2_rt::rc_map_insert(v2_rt::rc_empty_map::(), "".to_string(), 0), + next_id: 1, +}) } pub fn intern(table: &Rc, s: &String) -> Rc { match v2_rt::map_get(&table.index.clone(), s.clone()) { - Some(id) => Rc::new(InternResult { - table: table.clone(), - id: id.clone(), - }), - None => { - let id = table.next_id.clone(); - Rc::new(InternResult { - table: Rc::new(InternTable { - strings: v2_rt::rc_list_push(table.strings.clone(), s.clone()), - index: v2_rt::rc_map_insert(table.index.clone(), s.clone(), id.clone()), - next_id: (id.clone() + 1), - }), - id: id.clone(), - }) - } - } + Some(id) => Rc::new(InternResult { + table: table.clone(), + id: id.clone(), +}), + None => { + let id = table.next_id.clone(); +Rc::new(InternResult { + table: Rc::new(InternTable { + strings: v2_rt::rc_list_push(table.strings.clone(), s.clone()), + index: v2_rt::rc_map_insert(table.index.clone(), s.clone(), id.clone()), + next_id: (id.clone() + 1), +}), + id: id.clone(), +}) +}, +} } pub fn intern_str(table: Rc, id: i64) -> String { match table.strings.clone().get(id as usize).cloned() { - Some(s) => s.clone(), - None => "".to_string(), - } + Some(s) => s.clone(), + None => "".to_string(), +} } pub fn intern_find(table: Rc, s: String) -> Option { match v2_rt::map_get(&table.index.clone(), s) { - Some(id) => Some(id.clone()), - None => None, - } + Some(id) => Some(id.clone()), + None => None, +} } pub fn intern_find_or_empty(table: Rc, s: String) -> i64 { match v2_rt::map_get(&table.index.clone(), s) { - Some(id) => id.clone(), - None => 0, - } + Some(id) => id.clone(), + None => 0, +} } pub fn merge_intern_tables(tables: Rc>>) -> Rc { - tables.iter().cloned().fold( - empty_intern_table(), - |merged: Rc, t: Rc| { - t.strings - .clone() - .iter() - .cloned() - .fold(merged, |m: Rc, s: String| { - if (s.clone().as_str() == "".to_string().as_str()) { - m.clone() - } else { - intern(&m, &s).table.clone() - } - }) - }, - ) + tables.iter().cloned().fold(empty_intern_table(), |merged: Rc, t: Rc| t.strings.clone().iter().cloned().fold(merged, |m: Rc, s: String| if (s.clone().as_str() == "".to_string().as_str()) { + m.clone() + } else { + intern(&m, &s).table.clone() + })) } pub fn is_internable_token(shape: TokenShape) -> bool { match shape { - TokenShape::ShIdent => true, - TokenShape::ShKeyword => true, - _ => false, - } + TokenShape::ShIdent => true, + TokenShape::ShKeyword => true, + _ => false, +} } pub fn pre_intern_tokens(tokens: Rc>>, table: Rc) -> Rc { - tokens - .iter() - .cloned() - .fold(table, |t: Rc, tok: Rc| { - if is_internable_token(tok.shape.clone()) { - intern(&t, &tok.text.clone()).table.clone() - } else { - t.clone() - } - }) + tokens.iter().cloned().fold(table, |t: Rc, tok: Rc| if is_internable_token(tok.shape.clone()) { + intern(&t, &tok.text.clone()).table.clone() + } else { + t.clone() + }) } pub fn with_optional_cardinality(n: &Rc) -> Rc { Rc::new(Node { - name: n.name.clone(), - ident: n.ident.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: n.children.clone(), - connective: n.connective.clone(), - params: n.params.clone(), - inferred: n.inferred.clone(), - return_cardinality: Cardinality::CardOptional, - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: n.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: n.is_self_recursive.clone(), - has_non_tail_self_call: n.has_non_tail_self_call.clone(), - match_pattern: n.match_pattern.clone(), - expr_data: n.expr_data.clone(), - }) + name: n.name.clone(), + ident: n.ident.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: n.children.clone(), + connective: n.connective.clone(), + params: n.params.clone(), + inferred: n.inferred.clone(), + return_cardinality: Cardinality::CardOptional, + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: n.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: n.is_self_recursive.clone(), + has_non_tail_self_call: n.has_non_tail_self_call.clone(), + match_pattern: n.match_pattern.clone(), + expr_data: n.expr_data.clone(), +}) } pub fn with_required_cardinality(n: &Rc) -> Rc { Rc::new(Node { - name: n.name.clone(), - ident: n.ident.clone(), - span: n.span.clone(), - ident_span: n.ident_span.clone(), - children: n.children.clone(), - connective: n.connective.clone(), - params: n.params.clone(), - inferred: n.inferred.clone(), - return_cardinality: Cardinality::Required, - uses: n.uses.clone(), - body: n.body.clone(), - transport: n.transport.clone(), - properties: n.properties.clone(), - type_annotation: n.type_annotation.clone(), - is_self_recursive: n.is_self_recursive.clone(), - has_non_tail_self_call: n.has_non_tail_self_call.clone(), - match_pattern: n.match_pattern.clone(), - expr_data: n.expr_data.clone(), - }) + name: n.name.clone(), + ident: n.ident.clone(), + span: n.span.clone(), + ident_span: n.ident_span.clone(), + children: n.children.clone(), + connective: n.connective.clone(), + params: n.params.clone(), + inferred: n.inferred.clone(), + return_cardinality: Cardinality::Required, + uses: n.uses.clone(), + body: n.body.clone(), + transport: n.transport.clone(), + properties: n.properties.clone(), + type_annotation: n.type_annotation.clone(), + is_self_recursive: n.is_self_recursive.clone(), + has_non_tail_self_call: n.has_non_tail_self_call.clone(), + match_pattern: n.match_pattern.clone(), + expr_data: n.expr_data.clone(), +}) } From 99a56b7b5f8fa2ada39abbe15091a1889f6bb12e Mon Sep 17 00:00:00 2001 From: Brian Searls Date: Sun, 10 May 2026 01:45:18 +0000 Subject: [PATCH 5/8] Fix v2 inhabits parse precedence after main merge --- src/v2/02_parse.dag | 10 +- src/v2/stage0/src/v2_compiler_emit.rs | 4 +- src/v2/stage0/src/v2_compiler_emit_rust.rs | 92 +++++-------------- src/v2/stage0/src/v2_compiler_infer.rs | 41 ++++----- src/v2/stage0/src/v2_compiler_infer_cycle.rs | 13 ++- .../stage0/src/v2_compiler_infer_emit_info.rs | 4 +- src/v2/stage0/src/v2_compiler_ownership.rs | 23 ++--- src/v2/stage0/src/v2_compiler_parse.rs | 27 ++++-- src/v2/stage0/src/v2_rt.rs | 5 +- src/v2/tests/src/parse.rs | 21 +++++ src/v2/tests/src/pipeline.rs | 8 +- 11 files changed, 124 insertions(+), 124 deletions(-) diff --git a/src/v2/02_parse.dag b/src/v2/02_parse.dag index 62c2569f97c..d85ec790176 100644 --- a/src/v2/02_parse.dag +++ b/src/v2/02_parse.dag @@ -403,11 +403,19 @@ fn type_body_tokens_after_modifiers(tokens: List) -> List { fn parse_optional_type_inhabits_clause(tokens: List, ctx: ParseContext) -> TypeInhabitsResult { if tok_is_ident_text(tok: tokens |> first, text: "inhabits") { let r = parse_type_expr(tokens: tokens |> skip(1), ctx: ctx) - TypeInhabitsResult { type_expr: Some { value: r.type_expr }, tokens: skip_newlines(tokens: r.tokens), ctx: r.ctx, err: r.err } + let after_type = skip_newlines(tokens: r.tokens) + if has_err(err: r.err) || type_inhabits_clause_follow(tokens: after_type) { + TypeInhabitsResult { type_expr: Some { value: r.type_expr }, tokens: after_type, ctx: r.ctx, err: r.err } + } else { + TypeInhabitsResult { type_expr: none, tokens: tokens, ctx: ctx, err: none } + } } else { TypeInhabitsResult { type_expr: none, tokens: tokens, ctx: ctx, err: none } } } +fn type_inhabits_clause_follow(tokens: List) -> Bool { + tok_is_eq(tok: tokens |> first) || tok_is_lbrace(tok: tokens |> first) || tok_is_eof(tok: tokens |> first) +} fn type_inhabits_properties(type_expr: Node?) -> List { match type_expr { Some { value: t } => [make_field_init_node(name: "inhabits", value: t, span: t.span, name_span: no_span())] diff --git a/src/v2/stage0/src/v2_compiler_emit.rs b/src/v2/stage0/src/v2_compiler_emit.rs index f9947ae4784..2d7e1f824b9 100644 --- a/src/v2/stage0/src/v2_compiler_emit.rs +++ b/src/v2/stage0/src/v2_compiler_emit.rs @@ -49,7 +49,9 @@ pub use crate::v2_compiler_languages::{ TcoSyntax, TestConventions, TestNameStyle, VariantPatternSyntax, VisibilitySpec, }; use crate::v2_rt; -use crate::v2_rt::{rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains}; +use crate::v2_rt::{ + rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains, +}; use crate::v2_std_core::AlgebraFieldKind::*; use crate::v2_std_core::BinOp::NullCoalesce; use crate::v2_std_core::Cardinality::CardOptional; diff --git a/src/v2/stage0/src/v2_compiler_emit_rust.rs b/src/v2/stage0/src/v2_compiler_emit_rust.rs index d1af510e182..a225f3d6956 100644 --- a/src/v2/stage0/src/v2_compiler_emit_rust.rs +++ b/src/v2/stage0/src/v2_compiler_emit_rust.rs @@ -67,7 +67,9 @@ pub use crate::v2_compiler_ownership::{ }; pub use crate::v2_compiler_runtime_rust::rust_runtime_source; use crate::v2_rt; -use crate::v2_rt::{rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains}; +use crate::v2_rt::{ + rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains, +}; use crate::v2_std_core::AlgebraFieldKind::*; use crate::v2_std_core::BinOp::*; use crate::v2_std_core::CallSemantics::{LookupCallSemantics, PlainCallSemantics}; @@ -1581,8 +1583,7 @@ pub fn build_ownership_results(modules: &Rc>>) -> Rc>, - m: Rc| { + |acc: Rc>, m: Rc| { Rc::new({ let mut __result = Vec::new(); for item in m.items.clone().iter().cloned() { @@ -1596,10 +1597,7 @@ pub fn build_ownership_results(modules: &Rc>>) -> Rc, - >, - item: Rc| { + |inner: Rc>, item: Rc| { set_union( inner, collect_callable_refs( @@ -1632,12 +1630,7 @@ pub fn build_ownership_results(modules: &Rc>>) -> Rc, - >, - p: Rc| { + |acc: Rc>, p: Rc| { set_insert( acc, param_node_name_at( @@ -4838,17 +4831,8 @@ pub fn emit_variant_pattern( ), None => name.clone(), }; - let is_fielded = - match v2_rt::map_get(&emit_info.fielded_variants.clone(), fielded_key) { - Some(true) => true, - _ => match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - qualified.clone(), - ) { - Some(true) => true, - _ => false, - }, - }; + let is_fielded = set_contains(emit_info.fielded_variants.clone(), fielded_key) + || set_contains(emit_info.fielded_variants.clone(), qualified.clone()); if is_fielded { v2_rt::concat(qualified.clone(), " { .. }".to_string()) } else { @@ -4878,19 +4862,12 @@ pub fn emit_variant_pattern( ), None => name.clone(), }; - let is_fielded2 = match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - fielded_key2, - ) { - Some(true) => true, - _ => match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - qualified.clone(), - ) { - Some(true) => true, - _ => false, - }, - }; + let is_fielded2 = + set_contains(emit_info.fielded_variants.clone(), fielded_key2) + || set_contains( + emit_info.fielded_variants.clone(), + qualified.clone(), + ); if is_fielded2 { v2_rt::concat(qualified.clone(), " { .. }".to_string()) } else { @@ -5271,17 +5248,8 @@ pub fn emit_variant_pattern_rc_aware( ), None => name.clone(), }; - let is_fielded = - match v2_rt::map_get(&emit_info.fielded_variants.clone(), fielded_key) { - Some(true) => true, - _ => match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - qualified.clone(), - ) { - Some(true) => true, - _ => false, - }, - }; + let is_fielded = set_contains(emit_info.fielded_variants.clone(), fielded_key) + || set_contains(emit_info.fielded_variants.clone(), qualified.clone()); if is_fielded { v2_rt::concat(qualified.clone(), " { .. }".to_string()) } else { @@ -5311,19 +5279,12 @@ pub fn emit_variant_pattern_rc_aware( ), None => name.clone(), }; - let is_fielded2 = match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - fielded_key2, - ) { - Some(true) => true, - _ => match v2_rt::map_get( - &emit_info.fielded_variants.clone(), - qualified.clone(), - ) { - Some(true) => true, - _ => false, - }, - }; + let is_fielded2 = + set_contains(emit_info.fielded_variants.clone(), fielded_key2) + || set_contains( + emit_info.fielded_variants.clone(), + qualified.clone(), + ); if is_fielded2 { v2_rt::concat(qualified.clone(), " { .. }".to_string()) } else { @@ -8232,10 +8193,9 @@ pub fn emit_rust_fold_method_call( ownership_index: emit_info.ownership_index.clone(), movable: emit_info.movable.clone(), variant_to_enum: emit_info.variant_to_enum.clone(), - owned_bindings: v2_rt::rc_map_insert( + owned_bindings: set_insert( emit_info.owned_bindings.clone(), acc_name.clone(), - true, ), read_only_params_index: emit_info.read_only_params_index.clone(), read_only_params: emit_info.read_only_params.clone(), @@ -8260,11 +8220,7 @@ pub fn emit_rust_fold_method_call( fielded_variants: emit_info.fielded_variants.clone(), shared_types: emit_info.shared_types.clone(), ownership_index: emit_info.ownership_index.clone(), - movable: v2_rt::rc_map_insert( - emit_info.movable.clone(), - acc_name.clone(), - true, - ), + movable: set_insert(emit_info.movable.clone(), acc_name.clone()), variant_to_enum: emit_info.variant_to_enum.clone(), owned_bindings: emit_info.owned_bindings.clone(), read_only_params_index: emit_info.read_only_params_index.clone(), diff --git a/src/v2/stage0/src/v2_compiler_infer.rs b/src/v2/stage0/src/v2_compiler_infer.rs index 61e8604ae52..f3882a7d5bf 100644 --- a/src/v2/stage0/src/v2_compiler_infer.rs +++ b/src/v2/stage0/src/v2_compiler_infer.rs @@ -83,7 +83,9 @@ pub use crate::v2_compiler_infer_types::{ }; pub use crate::v2_compiler_resolve::{ModuleGraph, ResolvedImport, ResolvedModule}; use crate::v2_rt; -use crate::v2_rt::{rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains}; +use crate::v2_rt::{ + rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains, +}; use crate::v2_std_core::BinOp::{ Add, And, Div, Eq, Ge, Gt, Le, Lt, Mod, Mul, Ne, NullCoalesce, Or, Sub, }; @@ -10235,8 +10237,9 @@ pub fn build_type_env( ); let cross_type_set_str = cross_type_all_names.clone().iter().cloned().fold( empty_set(), - |acc: Rc>, - name: String| set_insert(acc, name.clone()), + |acc: Rc>, name: String| { + set_insert(acc, name.clone()) + }, ); let cross_type_set = cross_type_all_names.clone().iter().cloned().fold( v2_rt::rc_empty_map::(), @@ -10695,8 +10698,9 @@ pub fn build_type_env_unresolved( ); let cross_type_set_str = cross_type_all_names.clone().iter().cloned().fold( empty_set(), - |acc: Rc>, - name: String| set_insert(acc, name.clone()), + |acc: Rc>, name: String| { + set_insert(acc, name.clone()) + }, ); let cross_type_set = cross_type_all_names.clone().iter().cloned().fold( v2_rt::rc_empty_map::(), @@ -11347,8 +11351,9 @@ pub fn topo_resolve_types( } let remaining_set = remaining.clone().iter().cloned().fold( empty_set(), - |acc: Rc>, - name: String| set_insert(acc, name.clone()), + |acc: Rc>, name: String| { + set_insert(acc, name.clone()) + }, ); let ready = Rc::new({ let mut __result = Vec::new(); @@ -11566,16 +11571,12 @@ pub fn build_fielded_variants( { let result = modules.iter().cloned().fold( empty_set(), - |acc: Rc>, - m: Rc| { + |acc: Rc>, m: Rc| { let items = m.items.clone(); let si = m.type_env.clone().source_indices.clone(); items.clone().iter().cloned().fold( acc, - |inner: Rc< - std::collections::BTreeSet, - >, - item: Rc| { + |inner: Rc>, item: Rc| { let is_enum = match v2_rt::map_get( &type_summaries, authored_name_at(si.clone(), &item), @@ -11592,11 +11593,7 @@ pub fn build_fielded_variants( let variants = item.children.clone(); variants.clone().iter().cloned().fold( inner.clone(), - |vacc: Rc< - std::collections::BTreeSet< - String, - >, - >, + |vacc: Rc>, variant: Rc| { let has_fields = ((variant.children.clone().len() as i64) > 0); @@ -11650,8 +11647,7 @@ pub fn build_emit_graph_info(modules: &Rc>>) -> Rc>, - m: Rc| { + |acc: Rc>, m: Rc| { Rc::new(v2_rt::map_keys( &m.type_env.clone().recursive_type_set.clone(), )) @@ -11659,10 +11655,7 @@ pub fn build_emit_graph_info(modules: &Rc>>) -> Rc, - >, - ident: i64| { + |inner: Rc>, ident: i64| { set_insert( inner, intern_str(m.type_env.clone().intern_table.clone(), ident.clone()), diff --git a/src/v2/stage0/src/v2_compiler_infer_cycle.rs b/src/v2/stage0/src/v2_compiler_infer_cycle.rs index 2c3d0766028..ef66a78b013 100644 --- a/src/v2/stage0/src/v2_compiler_infer_cycle.rs +++ b/src/v2/stage0/src/v2_compiler_infer_cycle.rs @@ -3,7 +3,9 @@ pub use crate::v2_compiler_infer_env::TypeBinding; use crate::v2_rt; -use crate::v2_rt::{rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains}; +use crate::v2_rt::{ + rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains, +}; use crate::NonEmptyBTreeSet; use crate::NonEmptyVec; use std::collections::HashMap; @@ -235,8 +237,7 @@ pub fn detect_type_cycles_kahn( }); let name_set = all_names.clone().iter().cloned().fold( empty_set(), - |acc: Rc>, - n: String| set_insert(acc, n.clone()), + |acc: Rc>, n: String| set_insert(acc, n.clone()), ); let local_deps = compute_in_graph_deps(all_names.clone(), deps_map.clone(), name_set); let self_refs = Rc::new({ @@ -263,13 +264,11 @@ pub fn detect_type_cycles_kahn( let cycle_members = kahn_remove_loop(&all_names, &local_deps); let sr_set = self_refs.iter().cloned().fold( empty_set(), - |acc: Rc>, - n: String| set_insert(acc, n.clone()), + |acc: Rc>, n: String| set_insert(acc, n.clone()), ); let cm_set = cycle_members.iter().cloned().fold( sr_set, - |acc: Rc>, - n: String| set_insert(acc, n.clone()), + |acc: Rc>, n: String| set_insert(acc, n.clone()), ); let result = Rc::new({ let mut __result = Vec::new(); diff --git a/src/v2/stage0/src/v2_compiler_infer_emit_info.rs b/src/v2/stage0/src/v2_compiler_infer_emit_info.rs index 6d5d4689d73..a7a0e40aaaa 100644 --- a/src/v2/stage0/src/v2_compiler_infer_emit_info.rs +++ b/src/v2/stage0/src/v2_compiler_infer_emit_info.rs @@ -6,7 +6,9 @@ pub use crate::v2_compiler_infer_types::{ child_type_node, emit_map_has, node_type_equals, normalize_access_type_node, }; use crate::v2_rt; -use crate::v2_rt::{rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains}; +use crate::v2_rt::{ + rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains, +}; use crate::v2_std_core::Cardinality::CardOptional; use crate::v2_std_core::Connective::{Arrow, Conj, NoConnective}; use crate::v2_std_core::FieldAccessStyle::{EnumAccessor, StoredField, TupleFirst, TupleSecond}; diff --git a/src/v2/stage0/src/v2_compiler_ownership.rs b/src/v2/stage0/src/v2_compiler_ownership.rs index 1f560972410..921f510b79a 100644 --- a/src/v2/stage0/src/v2_compiler_ownership.rs +++ b/src/v2/stage0/src/v2_compiler_ownership.rs @@ -5,7 +5,9 @@ use self::EdgeKind::*; use self::OwnershipDecision::*; pub use crate::v2_compiler_emit::to_string; use crate::v2_rt; -use crate::v2_rt::{rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains}; +use crate::v2_rt::{ + rc_empty_set as empty_set, rc_set_insert as set_insert, rc_set_union as set_union, set_contains, +}; use crate::v2_std_core::Cardinality::Required; use crate::v2_std_core::ExprData::{ ExprBlock, ExprCall, ExprError, ExprFieldAccess, ExprForEach, ExprIf, ExprLambda, ExprLet, @@ -711,8 +713,9 @@ pub fn build_movable_set(proof: Rc) -> Rc>, - usage: Rc| set_insert(acc, usage.name.clone()), + |acc: Rc>, usage: Rc| { + set_insert(acc, usage.name.clone()) + }, ) } @@ -754,8 +757,9 @@ pub fn build_read_only_params( .cloned() .fold( empty_set(), - |acc: Rc>, - usage: Rc| set_insert(acc, usage.name.clone()), + |acc: Rc>, usage: Rc| { + set_insert(acc, usage.name.clone()) + }, ) } @@ -780,8 +784,7 @@ pub fn collect_callable_refs( } ExprData::ExprCall { .. } => texpr.children.clone().iter().cloned().fold( empty_set(), - |acc: Rc>, - a: Rc| { + |acc: Rc>, a: Rc| { set_union(acc, collect_callable_refs(&arg_value(&a), &si)) }, ), @@ -821,8 +824,7 @@ pub fn collect_callable_refs( } ExprData::ExprBlock => texpr.children.clone().iter().cloned().fold( empty_set(), - |acc: Rc>, - child: Rc| { + |acc: Rc>, child: Rc| { set_union(acc, collect_callable_refs(&child, &si)) }, ), @@ -840,8 +842,7 @@ pub fn collect_callable_refs( } ExprData::ExprRecordLit { .. } => texpr.children.clone().iter().cloned().fold( empty_set(), - |acc: Rc>, - field: Rc| { + |acc: Rc>, field: Rc| { set_union(acc, collect_callable_refs(&arg_value(&field), &si)) }, ), diff --git a/src/v2/stage0/src/v2_compiler_parse.rs b/src/v2/stage0/src/v2_compiler_parse.rs index 2277e2ee08f..4624a1e20bf 100644 --- a/src/v2/stage0/src/v2_compiler_parse.rs +++ b/src/v2/stage0/src/v2_compiler_parse.rs @@ -1218,12 +1218,22 @@ pub fn parse_optional_type_inhabits_clause( ), &ctx, ); - Rc::new(TypeInhabitsResult { - type_expr: Some(r.type_expr.clone()), - tokens: skip_newlines(r.tokens.clone()), - ctx: r.ctx.clone(), - err: r.err.clone(), - }) + let after_type = skip_newlines(r.tokens.clone()); + if (has_err(r.err.clone()) || type_inhabits_clause_follow(after_type.clone())) { + Rc::new(TypeInhabitsResult { + type_expr: Some(r.type_expr.clone()), + tokens: after_type, + ctx: r.ctx.clone(), + err: r.err.clone(), + }) + } else { + Rc::new(TypeInhabitsResult { + type_expr: None, + tokens: tokens.clone(), + ctx: ctx, + err: None, + }) + } } } else { Rc::new(TypeInhabitsResult { @@ -1235,6 +1245,11 @@ pub fn parse_optional_type_inhabits_clause( } } +pub fn type_inhabits_clause_follow(tokens: Rc>>) -> bool { + ((tok_is_eq(tokens.clone().first().cloned()) || tok_is_lbrace(tokens.clone().first().cloned())) + || tok_is_eof(tokens.clone().first().cloned())) +} + pub fn type_inhabits_properties(type_expr: Option>) -> Rc>> { match type_expr { Some(t) => Rc::new(vec![make_field_init_node( diff --git a/src/v2/stage0/src/v2_rt.rs b/src/v2/stage0/src/v2_rt.rs index 17e5a574e27..42846e62203 100644 --- a/src/v2/stage0/src/v2_rt.rs +++ b/src/v2/stage0/src/v2_rt.rs @@ -252,7 +252,10 @@ pub fn rc_set_insert(set: Rc>, value: T) -> Rc(left: Rc>, right: Rc>) -> Rc> { +pub fn rc_set_union( + left: Rc>, + right: Rc>, +) -> Rc> { let mut result = left; Rc::make_mut(&mut result).extend(right.iter().cloned()); result diff --git a/src/v2/tests/src/parse.rs b/src/v2/tests/src/parse.rs index 205bc5befd0..c132d079690 100644 --- a/src/v2/tests/src/parse.rs +++ b/src/v2/tests/src/parse.rs @@ -723,6 +723,27 @@ fn shared_std_types_accepts_type_inhabits_clause() { assert_eq!(inhabits_expr.name, "BooleanAlgebra"); } +#[test] +fn type_body_keeps_inhabits_as_identifier() { + let source = "module test\ntype X = inhabits | Other\n"; + let result = parse_source(source); + assert!( + result.error.is_none(), + "inhabits should remain a valid type-body identifier: {:?}", + result.error + ); + let module = result.module.clone().expect("module"); + let type_item = module.children[0].clone(); + assert!( + type_item + .properties + .iter() + .all(|property| property.name != "inhabits"), + "identifier-form type body must not become an inhabits property" + ); + assert_eq!(type_item.children[0].name, "inhabits"); +} + // ── keyword-as-name regression (dag_non_name_keywords authority) ─────── /// Keywords that ARE valid as field/type names should parse. diff --git a/src/v2/tests/src/pipeline.rs b/src/v2/tests/src/pipeline.rs index 943ebf594a0..f11f4633334 100644 --- a/src/v2/tests/src/pipeline.rs +++ b/src/v2/tests/src/pipeline.rs @@ -4505,7 +4505,7 @@ fn type_rendering_bare_list_not_map() { use v2_compiler::v2_compiler_emit::render_node_type; let list_node = test_leaf_node("List"); - let shared_types = Rc::new(HashMap::from([("List".to_string(), true)])); + let shared_types = Rc::new(std::collections::BTreeSet::from(["List".to_string()])); let rendered = render_node_type( &list_node, @@ -4531,7 +4531,7 @@ fn type_rendering_bare_map_stays_hashmap() { use v2_compiler::v2_compiler_emit::render_node_type; let map_node = test_leaf_node("Map"); - let shared_types = Rc::new(HashMap::from([("Map".to_string(), true)])); + let shared_types = Rc::new(std::collections::BTreeSet::from(["Map".to_string()])); let rendered = render_node_type( &map_node, @@ -4562,7 +4562,7 @@ fn type_rendering_named_conj_with_container_template() { })), ..(*test_leaf_node("")).clone() }); - let shared_types = Rc::new(HashMap::from([("FreeMonoid".to_string(), true)])); + let shared_types = Rc::new(std::collections::BTreeSet::from(["FreeMonoid".to_string()])); let rendered = render_node_type( &free_monoid_conj, @@ -10001,7 +10001,7 @@ fn count_ownership_violations( for proof in result.ownership.iter() { let movable = build_movable_set(proof.clone()); - for (name, _) in movable.iter() { + for name in movable.iter() { // The proof says this binding should move. // Check if the emitted code clones it instead. let clone_pattern = format!("{}.clone()", name); From 80628cc2bdfbf25c625fc5dde0a2cf9c9c0165fe Mon Sep 17 00:00:00 2001 From: Brian Searls Date: Sun, 10 May 2026 01:51:19 +0000 Subject: [PATCH 6/8] Refresh v3 bootstrap snapshots --- src/v3/compiler/src/bootstrap_generated.rs | 14 +++++++------- .../bootstrap_generated_without_parse_surface.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/v3/compiler/src/bootstrap_generated.rs b/src/v3/compiler/src/bootstrap_generated.rs index b96b8bae617..f70053e59be 100644 --- a/src/v3/compiler/src/bootstrap_generated.rs +++ b/src/v3/compiler/src/bootstrap_generated.rs @@ -26951,7 +26951,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4492, 4530), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4498, 4536), }); declarations.push(Declaration { id: DeclarationId(890), @@ -26970,7 +26970,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 5494, 5541), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 5500, 5547), }); declarations.push(Declaration { id: DeclarationId(891), @@ -27003,9 +27003,9 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6184, 6294), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6190, 6300), }); - declarations.push(Declaration { id: DeclarationId(892), name: Some("bridge_ledger".to_string()), connective: TypeConnective::Instantiation { template: DeclarationId(665), arguments: vec![TemplateArgument { parameter: DeclarationId(666), value: DeclarationId(891) }] }, type_params: vec![], phantom_params: Vec::new(), meta_tag: Some(DeclarationId(2032)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_source_span_file_participation_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R3".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("ROADMAP.md#lens-fold-file-path-semantics".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_mark_bootstrap_secret_nominal_opacity_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("PR #937".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_dispatch_pr1183_slice_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("src/v3/compiler/tests/integration/canonical_lens_bridge_ratchet_test.rs".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_patching_residual".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Runtime".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("docs/briefs/r2-pb-canonical-lens-bridge-disposition.md".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_include_str_side_channels_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("pipeline_authority".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("src/v3/compiler/tests/integration/l1_5_fixed_point_test.rs".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_exact_string_patching_residual_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Tier-2".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("dsl/std/types.dag Bool inhabits BooleanAlgebra + src/v3/compiler/tests/integration/bridge_lower_helpers_patch_zero_residual_test.rs".to_string())))])])), refinement: None, nominal_opacity: None, span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6758, 8044) }); + declarations.push(Declaration { id: DeclarationId(892), name: Some("bridge_ledger".to_string()), connective: TypeConnective::Instantiation { template: DeclarationId(665), arguments: vec![TemplateArgument { parameter: DeclarationId(666), value: DeclarationId(891) }] }, type_params: vec![], phantom_params: Vec::new(), meta_tag: Some(DeclarationId(2032)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_source_span_file_participation_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R3".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2031), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("ROADMAP.md#lens-fold-file-path-semantics".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_mark_bootstrap_secret_nominal_opacity_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("PR #937".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_dispatch_pr1183_slice_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("src/v3/compiler/tests/integration/canonical_lens_bridge_ratchet_test.rs".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_patching_residual".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Runtime".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("docs/briefs/r3-pb-bridge-canonical-lens-name-dispatch-closure.md".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_include_str_side_channels_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("pipeline_authority".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("src/v3/compiler/tests/integration/l1_5_fixed_point_test.rs".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_exact_string_patching_residual_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Tier-2".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2030), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("dsl/std/types.dag Bool inhabits BooleanAlgebra + src/v3/compiler/tests/integration/bridge_lower_helpers_patch_zero_residual_test.rs".to_string())))])])), refinement: None, nominal_opacity: None, span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6764, 8063) }); declarations.push(Declaration { id: DeclarationId(893), name: Some("CleanEmissionContract".to_string()), @@ -67676,7 +67676,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4514, 4521), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4520, 4527), }); declarations.push(Declaration { id: DeclarationId(2031), @@ -67690,7 +67690,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4526, 4530), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 4532, 4536), }); declarations.push(Declaration { id: DeclarationId(2032), @@ -67710,7 +67710,7 @@ fn bootstrapped_fixture_dag_declarations() -> Vec { value_body: None, refinement: None, nominal_opacity: None, - span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6778, 6799), + span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6784, 6805), }); declarations.push(Declaration { id: DeclarationId(2033), diff --git a/src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs b/src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs index 2002ce8f3e2..113312e5f38 100644 --- a/src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs +++ b/src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs @@ -26951,7 +26951,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec Vec Vec + src/v3/compiler/tests/integration/bridge_lower_helpers_patch_zero_residual_test.rs".to_string())))])])), refinement: None, nominal_opacity: None, span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6758, 8044) }); + declarations.push(Declaration { id: DeclarationId(892), name: Some("bridge_ledger".to_string()), connective: TypeConnective::Instantiation { template: DeclarationId(665), arguments: vec![TemplateArgument { parameter: DeclarationId(666), value: DeclarationId(891) }] }, type_params: vec![], phantom_params: Vec::new(), meta_tag: Some(DeclarationId(2017)), specialization_parent: None, inhabits: None, value_body: Some(ValueBody::List(vec![FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_source_span_file_participation_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R3".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2016), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("ROADMAP.md#lens-fold-file-path-semantics".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_mark_bootstrap_secret_nominal_opacity_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2015), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("PR #937".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_dispatch_pr1183_slice_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("R2-Substrate".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2015), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("src/v3/compiler/tests/integration/canonical_lens_bridge_ratchet_test.rs".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_canonical_lens_name_patching_residual".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Runtime".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2015), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("docs/briefs/r3-pb-bridge-canonical-lens-name-dispatch-closure.md".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_include_str_side_channels_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("pipeline_authority".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2015), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("src/v3/compiler/tests/integration/l1_5_fixed_point_test.rs".to_string())))]), FieldValue::Record(vec![("name".to_string(), FieldValue::Literal(LiteralBits::String("bridge_exact_string_patching_residual_retired".to_string()))), ("owner".to_string(), FieldValue::Literal(LiteralBits::String("PB-Tier-2".to_string()))), ("status".to_string(), FieldValue::Variant { constructor: DeclarationId(2015), payload: vec![] }), ("authority".to_string(), FieldValue::Literal(LiteralBits::String("dsl/std/types.dag Bool inhabits BooleanAlgebra + src/v3/compiler/tests/integration/bridge_lower_helpers_patch_zero_residual_test.rs".to_string())))])])), refinement: None, nominal_opacity: None, span: SourceSpan::new("src/v3/std/bridge_ledger.dag", 6764, 8063) }); declarations.push(Declaration { id: DeclarationId(893), name: Some("CleanEmissionContract".to_string()), @@ -64969,7 +64969,7 @@ fn bootstrapped_fixture_without_parse_surface_dag_declarations() -> Vec Vec Vec Date: Sun, 10 May 2026 01:55:43 +0000 Subject: [PATCH 7/8] Use R3 status taxonomy for bridge retirements --- docs/r3-program-plan.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/r3-program-plan.md b/docs/r3-program-plan.md index 344e304abfd..acd2cc4f7a3 100644 --- a/docs/r3-program-plan.md +++ b/docs/r3-program-plan.md @@ -257,8 +257,8 @@ This principle is NOT a separate lane; it's a per-lane gate-shape requirement ap | 31 | `bridge_source_span_file_participation_retired` | state-check | T-Bridge-Retirement | DECLARED | typed-identity-surface authority | | 32 | `bridge_mark_bootstrap_secret_nominal_opacity_retired` | state-check | T-Bridge-Retirement | **PASSING** | `dsl/std/types.dag` `type Secret nominal_opaque = String` + `src/v3/std/bridge_ledger.dag` row `Retired` + unit ratchet `dag.rs::bridge_mark_bootstrap_secret_nominal_opacity_retired` (bootstrap snapshots carry `Declaration.nominal_opacity` on `Secret`); historical name-keyed bootstrap bridge removed (#1272 / #937 lineage) | | 33 | `bridge_canonical_lens_name_dispatch_retired` | state-check | T-Bridge-Retirement | DECLARED | DeclarationRef/typed identity | -| 34 | `bridge_include_str_side_channels_retired` | state-check | T-Bridge-Retirement | RETIRED | pipeline-authority source-text side channel retired; stage order reads structural `PipelineStageBinding` | -| 35 | `bridge_exact_string_patching_residual_retired` | state-check | T-Bridge-Retirement | RETIRED | exact-string scaffolds retired; Bool-inhabits is source-authored and lower-helper patch remains zero-ratcheted | +| 34 | `bridge_include_str_side_channels_retired` | state-check | T-Bridge-Retirement | PASSING | pipeline-authority source-text side channel retired; stage order reads structural `PipelineStageBinding` | +| 35 | `bridge_exact_string_patching_residual_retired` | state-check | T-Bridge-Retirement | PASSING | exact-string scaffolds retired; Bool-inhabits is source-authored and lower-helper patch remains zero-ratcheted | | 36 | `bridge_retirement_ledger_zero` | ledger-count | T-Bridge-Retirement | DECLARED | unified ledger reports 0 | | 37 | `cost_lens_reads_target_realization` | structural-fold | T-CostLens-Composition | **INTEGRATION_RECEIPT (partial — ε-slice)** — PR #2181 ε path: `lens_cost_target_realization_test.rs` proves (i) **TypeRealization** slice: Rust-side `symbolic_cost_of` on a tiny program × `rust_int` row `cost` composed via `Semiring` `sequential`; (ii) **CallableRealization** slice: bootstrap `rust_is_empty_callable` row `cost` readable as a lowered structural field (same row-shape discipline as (i), **without** a second `sequential` composition pin in that subtest). **Not** full emit-time / `LanguageSpec`-indexed cost-lens consumer (that closure remains with gates **#40** / **#70** / follow-on slices per program plan). Historical gate id; lens output stays abstract `SymbolicCost`. | ε-slice receipt; emit-time fold follow-on | | 38 | `coercion_cost_equals_complexity_by_construction` | structural-fold | T-CostLens-Composition | **SATISFIED-BY-CONSTRUCTION** (α-narrow PR #2171; `Semiring` `sequential`/`iterate` at `src/v3/std/algebra.dag:181-188` is sole composition authority — no parallel "complexity-vs-cost" reconciliation surface exists) | thesis unification holds structurally | From 66ae519b2bdf96737256f8bc68053740ede253c5 Mon Sep 17 00:00:00 2001 From: Brian Searls Date: Sat, 9 May 2026 22:04:48 -0400 Subject: [PATCH 8/8] WIP: R3 gate #35: bridge exact string patching residual retired --- src/v3/compiler/tests/integration/parse_corpus_manifest.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/v3/compiler/tests/integration/parse_corpus_manifest.txt b/src/v3/compiler/tests/integration/parse_corpus_manifest.txt index 3a1ef168128..4efb7d4aec9 100644 --- a/src/v3/compiler/tests/integration/parse_corpus_manifest.txt +++ b/src/v3/compiler/tests/integration/parse_corpus_manifest.txt @@ -11,7 +11,7 @@ dsl/std/magnitude.dag 2 560 d1579da2ea458db8 dsl/std/nat.dag 4 1895 9c5eb0ac8d25a015 dsl/std/rational.dag 4 2379 3c3b86f7e18caf82 dsl/std/string_type.dag 4 1910 119741c6fb9de2e3 -dsl/std/types.dag 111 198793 3a2f47d17a81426d +dsl/std/types.dag 111 199485 45ad73daf932d379 src/v3/compiler/operators.dag 5 47160 b75a91c65bf8a242 src/v3/compiler/parse_tables.dag 43 92946 f6a6c0d08e3081bb src/v3/compiler/pipeline.dag 26 47032 a13b41aa379fd167 @@ -32,7 +32,7 @@ src/v3/std/anthropic_schema.dag 14 69934 58a973240ec25777 src/v3/std/approximate_field.dag 11 16864 ccbe4826dc31c636 src/v3/std/bin_shim.dag 4 2544 9ac96f1b3feafe47 src/v3/std/bootstrap_authority.dag 4 70609 e228bb8bb2449ece -src/v3/std/bridge_ledger.dag 7 31728 e199a822d969d067 +src/v3/std/bridge_ledger.dag 7 31845 e4b7260339078102 src/v3/std/clean_emission.dag 15 23867 e7bc1e6145f4781e src/v3/std/computation.dag 19 37870 25c5a33ef4d8735a src/v3/std/computation_model.dag 14 22953 20e458fe097d175a