Skip to main content

meta_language/translation/
surface.rs

1//! The surface AST the four frontends produce and the checker consumes.
2//!
3//! Its JSON form is the JavaScript runtime's (`{ "k": "binary", "op": "add", … }`),
4//! so the frontends of both runtimes can be compared node for node.
5
6use serde::{Deserialize, Deserializer, Serialize};
7
8use super::types::Type;
9use super::{Language, Span};
10
11mod externals;
12pub use externals::{External, ExternalParam, SImport, SImportName};
13mod array_item;
14pub use array_item::SArrayItem;
15mod binding_type_annotation;
16pub use binding_type_annotation::SurfaceBindingTypeAnnotation;
17mod raw_metadata;
18pub use raw_metadata::SurfaceRawMetadata;
19mod nodes;
20pub use nodes::SNode;
21pub(crate) mod array_bindings;
22mod record_entry;
23pub use record_entry::SRecordEntry;
24mod record_projection;
25
26#[allow(clippy::trivially_copy_pass_by_ref)] // serde passes fields by reference
27const fn is_false(value: &bool) -> bool {
28    !*value
29}
30
31/// Numeral text: the JavaScript frontends store some pattern numerals as
32/// numbers and others as decimal strings.
33fn numeral<'de, D: Deserializer<'de>>(deserializer: D) -> Result<String, D::Error> {
34    #[derive(Deserialize)]
35    #[serde(untagged)]
36    enum Numeral {
37        Text(String),
38        Number(serde_json::Number),
39    }
40    Ok(match Numeral::deserialize(deserializer)? {
41        Numeral::Text(text) => text,
42        Numeral::Number(number) => number.to_string(),
43    })
44}
45
46/// A surface expression.
47#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
48#[serde(try_from = "array_bindings::SurfaceExpression")]
49pub struct SExpr {
50    #[serde(flatten)]
51    pub node: SNode,
52    #[serde(default, skip_serializing_if = "Option::is_none")]
53    pub span: Option<Span>,
54    /// Grouping is raw source metadata, with absence independent of its value.
55    #[serde(
56        default,
57        skip_serializing_if = "Option::is_none",
58        deserialize_with = "raw_metadata::read_present_surface_raw_metadata"
59    )]
60    pub parenthesized: Option<SurfaceRawMetadata>,
61    /// Set on a Rust block expression (`{ … }`) used as a value.
62    #[serde(default, skip_serializing_if = "is_false")]
63    pub block: bool,
64    /// Set on the match a JavaScript `x.$ === 'tag'` test reads as, so an
65    /// `if` on it can narrow `x`.
66    #[serde(rename = "tagTest", default, skip_serializing_if = "Option::is_none")]
67    pub tag_test: Option<Box<STagTest>>,
68}
69
70/// A JavaScript `x.$ === 'tag'` (or `!==`) test: the tested value, the tag
71/// and the data type that has it.
72#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
73pub struct STagTest {
74    pub object: SExpr,
75    pub tag: String,
76    pub data: SData,
77    pub negated: bool,
78}
79
80impl SExpr {
81    #[must_use]
82    pub const fn new(node: SNode, span: Option<Span>) -> Self {
83        Self {
84            node,
85            span,
86            parenthesized: None,
87            block: false,
88            tag_test: None,
89        }
90    }
91
92    /// A name reference without a span, as the checker builds them.
93    #[must_use]
94    pub fn name(name: &str) -> Self {
95        Self::new(
96            SNode::Name {
97                path: vec![name.to_owned()],
98            },
99            None,
100        )
101    }
102
103    /// The single-segment name this expression refers to, if it is one.
104    #[must_use]
105    pub fn simple_name(&self) -> Option<&str> {
106        match &self.node {
107            SNode::Name { path } if path.len() == 1 => Some(&path[0]),
108            _ => None,
109        }
110    }
111}
112
113#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
114#[serde(rename_all = "camelCase")]
115pub enum UnaryOp {
116    Not,
117    Neg,
118}
119
120/// Surface binary operators: `plus` is JavaScript's overloaded `+`.
121#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
122#[serde(rename_all = "camelCase")]
123pub enum BinaryOp {
124    Add,
125    Sub,
126    Mul,
127    Div,
128    Rem,
129    Eq,
130    Ne,
131    Lt,
132    Le,
133    Gt,
134    Ge,
135    And,
136    Or,
137    Concat,
138    Plus,
139}
140
141impl BinaryOp {
142    /// The operator's name in the checked program's JSON, such as `add`.
143    #[must_use]
144    pub const fn name(self) -> &'static str {
145        match self {
146            Self::Add => "add",
147            Self::Sub => "sub",
148            Self::Mul => "mul",
149            Self::Div => "div",
150            Self::Rem => "rem",
151            Self::Eq => "eq",
152            Self::Ne => "ne",
153            Self::Lt => "lt",
154            Self::Le => "le",
155            Self::Gt => "gt",
156            Self::Ge => "ge",
157            Self::And => "and",
158            Self::Or => "or",
159            Self::Concat => "concat",
160            Self::Plus => "plus",
161        }
162    }
163}
164
165/// Division rounding a source operator asks for.
166#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
167#[serde(rename_all = "camelCase")]
168pub enum Rounding {
169    Trunc,
170    Euclid,
171    Floor,
172}
173
174/// How a value is printed: each source language's own rendering.
175#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
176pub enum ShowStyle {
177    #[serde(rename = "lean")]
178    Lean,
179    #[serde(rename = "rocq")]
180    Rocq,
181    #[serde(rename = "rust")]
182    Rust,
183    #[serde(rename = "js-console")]
184    JsConsole,
185    #[serde(rename = "js-template")]
186    JsTemplate,
187    /// The first of several `console.log` arguments, when it is not a literal string.
188    #[serde(rename = "js-format-first")]
189    JsFormatFirst,
190    /// The argument of a `%d` directive.
191    #[serde(rename = "js-format-number")]
192    JsFormatNumber,
193    /// The argument of a `%i` directive.
194    #[serde(rename = "js-format-integer")]
195    JsFormatInteger,
196}
197
198impl ShowStyle {
199    /// True for the values `console.log` shows: its argument, or those `util.format` reads.
200    #[must_use]
201    pub const fn is_console(self) -> bool {
202        matches!(
203            self,
204            Self::JsConsole | Self::JsFormatFirst | Self::JsFormatNumber | Self::JsFormatInteger
205        )
206    }
207}
208
209/// Conversion semantics: exact, checked (aborts when out of range) or clamped.
210#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
211#[serde(rename_all = "camelCase")]
212pub enum Flavor {
213    Exact,
214    Checked,
215    Clamp,
216}
217
218/// A source prototype definition, preserved until the checker refuses it.
219#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
220#[serde(rename_all = "camelCase")]
221pub struct ConstructorPrototypeDefinition {
222    /// The complete initializer expression.
223    pub value: Box<SExpr>,
224    /// The uncomputed property key's source range.
225    pub span: Span,
226    /// The original property position, including the constructor tag.
227    pub index: usize,
228}
229
230/// An object whose keys keep their insertion order, as JavaScript objects do.
231mod ordered_fields {
232    use std::fmt;
233
234    use serde::de::{MapAccess, Visitor};
235    use serde::ser::SerializeMap;
236    use serde::{Deserializer, Serializer};
237
238    use super::SExpr;
239
240    #[allow(clippy::ptr_arg)]
241    pub fn serialize<S: Serializer>(
242        fields: &Vec<(String, SExpr)>,
243        serializer: S,
244    ) -> Result<S::Ok, S::Error> {
245        let mut map = serializer.serialize_map(Some(fields.len()))?;
246        for (name, value) in fields {
247            map.serialize_entry(name, value)?;
248        }
249        map.end()
250    }
251
252    pub fn deserialize<'de, D: Deserializer<'de>>(
253        deserializer: D,
254    ) -> Result<Vec<(String, SExpr)>, D::Error> {
255        struct Fields;
256        impl<'de> Visitor<'de> for Fields {
257            type Value = Vec<(String, SExpr)>;
258            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
259                formatter.write_str("an object of fields")
260            }
261            fn visit_map<A: MapAccess<'de>>(self, mut map: A) -> Result<Self::Value, A::Error> {
262                let mut fields = Vec::new();
263                while let Some(entry) = map.next_entry()? {
264                    fields.push(entry);
265                }
266                Ok(fields)
267            }
268        }
269        deserializer.deserialize_map(Fields)
270    }
271}
272
273/// One row of a multi-scrutinee surface match.
274#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
275pub struct SRow {
276    pub patterns: Vec<SPattern>,
277    pub body: SExpr,
278    #[serde(default, skip_serializing_if = "Option::is_none")]
279    pub span: Option<Span>,
280}
281
282/// One case of a single-level match.
283#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
284pub struct SCase {
285    pub pattern: SCasePattern,
286    pub body: SExpr,
287    #[serde(default, skip_serializing_if = "Option::is_none")]
288    pub span: Option<Span>,
289}
290
291/// Patterns of a single-level match: one constructor, fields bound to names.
292#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
293#[serde(tag = "k", rename_all = "camelCase", rename_all_fields = "camelCase")]
294pub enum SCasePattern {
295    Wild,
296    Bind {
297        name: String,
298    },
299    NatZero,
300    NatSucc {
301        name: String,
302    },
303    Ctor {
304        path: Vec<String>,
305        binds: Vec<Option<String>>,
306    },
307}
308
309/// A surface pattern.
310#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
311pub struct SPattern {
312    #[serde(flatten)]
313    pub node: SPatternNode,
314    #[serde(default, skip_serializing_if = "Option::is_none")]
315    pub span: Option<Span>,
316}
317
318#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
319#[serde(tag = "k", rename_all = "camelCase", rename_all_fields = "camelCase")]
320pub enum SPatternNode {
321    Wild,
322    /// A lone name: a nullary constructor when the scrutinee type has one, else a binder.
323    BindOrCtor {
324        name: String,
325    },
326    /// A binder, which the JavaScript frontend's generated matches use.
327    Bind {
328        name: String,
329    },
330    Ctor {
331        path: Vec<String>,
332        args: Vec<SPattern>,
333    },
334    NumLit {
335        #[serde(deserialize_with = "numeral")]
336        value: String,
337        #[serde(default, skip_serializing_if = "is_false")]
338        negative: bool,
339    },
340    BoolLit {
341        value: bool,
342        #[serde(default, skip_serializing_if = "is_false")]
343        negative: bool,
344    },
345    StrLit {
346        value: String,
347    },
348    /// Lean's `n + 2`; `add` holds the numeral's decimal digits.
349    NatAdd {
350        inner: Box<SPattern>,
351        add: String,
352    },
353}
354
355#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
356#[serde(rename_all = "camelCase")]
357pub struct SBinder {
358    pub name: String,
359    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
360    pub ty: Option<Type>,
361    /// The Rocq type as written (`N`, `nat`, `Z`), which proof steps consult.
362    #[serde(default, skip_serializing_if = "Option::is_none")]
363    pub rocq_type: Option<String>,
364    #[serde(default, skip_serializing_if = "Option::is_none")]
365    pub span: Option<Span>,
366}
367
368/// A surface proposition.
369#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
370pub struct SProp {
371    #[serde(flatten)]
372    pub node: SPropNode,
373    #[serde(default, skip_serializing_if = "Option::is_none")]
374    pub span: Option<Span>,
375}
376
377#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
378pub struct SComparison {
379    pub left: SExpr,
380    pub right: SExpr,
381    /// JavaScript's `assert.equal`, which compares objects by identity.
382    #[serde(default, skip_serializing_if = "is_false")]
383    pub reference: bool,
384    /// `assert.strictEqual` and its kin compare with `SameValue`
385    /// (`Object.is`): `NaN` equals `NaN`, and `0` differs from `-0`.
386    #[serde(default, rename = "sameValue", skip_serializing_if = "is_false")]
387    pub same_value: bool,
388}
389
390#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
391#[serde(tag = "p", rename_all = "camelCase", rename_all_fields = "camelCase")]
392pub enum SPropNode {
393    Forall {
394        binders: Vec<SBinder>,
395        body: Box<SProp>,
396    },
397    And {
398        left: Box<SProp>,
399        right: Box<SProp>,
400    },
401    Or {
402        left: Box<SProp>,
403        right: Box<SProp>,
404    },
405    Implies {
406        left: Box<SProp>,
407        right: Box<SProp>,
408    },
409    Not {
410        arg: Box<SProp>,
411    },
412    Bool {
413        expr: SExpr,
414    },
415    Eq(SComparison),
416    Ne(SComparison),
417    Lt(SComparison),
418    Le(SComparison),
419    Gt(SComparison),
420    Ge(SComparison),
421}
422
423#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
424pub struct SRule {
425    pub name: String,
426    pub reverse: bool,
427}
428
429/// A proof step: `t` names the tactic family.
430#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
431#[serde(tag = "t", rename_all = "camelCase", rename_all_fields = "camelCase")]
432pub enum SStep {
433    Compute {
434        #[serde(default, skip_serializing_if = "Option::is_none")]
435        tactic: Option<String>,
436    },
437    Arith {
438        #[serde(default, skip_serializing_if = "Option::is_none")]
439        tactic: Option<String>,
440    },
441    Intro {
442        names: Vec<String>,
443    },
444    Unfold {
445        names: Vec<String>,
446        #[serde(default, skip_serializing_if = "Option::is_none")]
447        tactic: Option<String>,
448    },
449    Simp {
450        rules: Vec<SRule>,
451        #[serde(default, skip_serializing_if = "Option::is_none")]
452        only: Option<bool>,
453        #[serde(default, skip_serializing_if = "Option::is_none")]
454        tactic: Option<String>,
455    },
456    Rewrite {
457        rules: Vec<SRule>,
458        #[serde(default, skip_serializing_if = "Option::is_none")]
459        only: Option<bool>,
460        #[serde(default, skip_serializing_if = "Option::is_none")]
461        tactic: Option<String>,
462    },
463    Induction(SSplit),
464    Cases(SSplit),
465}
466
467#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
468pub struct SSplit {
469    pub variable: String,
470    pub cases: Vec<SSplitCase>,
471    /// Rocq names cases by position; Lean by constructor.
472    #[serde(default, skip_serializing_if = "is_false")]
473    pub positional: bool,
474    #[serde(default, skip_serializing_if = "Option::is_none")]
475    pub blocks: Option<usize>,
476}
477
478#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
479pub struct SSplitCase {
480    #[serde(default, skip_serializing_if = "Option::is_none")]
481    pub ctor: Option<String>,
482    #[serde(default, skip_serializing_if = "Option::is_none")]
483    pub index: Option<usize>,
484    pub binds: Vec<Option<String>>,
485    pub steps: Vec<SStep>,
486}
487
488#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
489#[serde(rename_all = "camelCase")]
490pub struct SProof {
491    pub steps: Vec<SStep>,
492    #[serde(default, skip_serializing_if = "Option::is_none")]
493    pub source: Option<String>,
494    pub source_language: Language,
495}
496
497#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
498#[serde(rename_all = "camelCase")]
499pub struct SField {
500    #[serde(default, skip_serializing_if = "Option::is_none")]
501    pub name: Option<String>,
502    #[serde(rename = "type")]
503    pub ty: Type,
504    /// The type as written, on a Rocq constructor field declared as a binder `(x : N)`.
505    #[serde(default, skip_serializing_if = "Option::is_none")]
506    pub rocq_type: Option<String>,
507    #[serde(default, skip_serializing_if = "Option::is_none")]
508    pub span: Option<Span>,
509}
510
511#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
512pub struct SCtor {
513    pub name: String,
514    pub fields: Vec<SField>,
515}
516
517/// The leading `if (n < 0n) throw …` of a JavaScript parameter: a negative
518/// argument aborts with its message, the guards in their order.
519#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
520pub struct Guard {
521    pub message: String,
522    pub order: usize,
523}
524
525#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
526#[serde(rename_all = "camelCase")]
527pub struct SParam {
528    pub name: String,
529    /// An omitted documented parameter passes its actual undefined default.
530    #[serde(default, skip_serializing_if = "is_false")]
531    pub optional: bool,
532    #[serde(default, rename = "default", skip_serializing_if = "Option::is_none")]
533    pub default_value: Option<SExpr>,
534    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
535    pub ty: Option<Type>,
536    #[serde(default, skip_serializing_if = "Option::is_none")]
537    pub span: Option<Span>,
538    /// A JavaScript parameter restricted to the naturals by a leading guard.
539    #[serde(default, skip_serializing_if = "Option::is_none")]
540    pub guard: Option<Guard>,
541    #[serde(default, skip_serializing_if = "Option::is_none")]
542    pub rocq_type: Option<String>,
543}
544
545#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
546pub struct SData {
547    pub name: String,
548    pub ctors: Vec<SCtor>,
549    #[serde(default, skip_serializing_if = "Option::is_none")]
550    pub span: Option<Span>,
551    /// A data type the translator made up, whose name may use the reserved `ml_` prefix.
552    #[serde(default, skip_serializing_if = "is_false")]
553    pub generated: bool,
554    /// Optional actual field-free Rust Clone derivation owned by this datatype.
555    #[serde(
556        default,
557        rename = "sourceUnitCloneDerivation",
558        skip_serializing_if = "Option::is_none"
559    )]
560    pub source_unit_clone_derivation: Option<Box<serde_json::Value>>,
561}
562
563#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
564pub struct SFn {
565    /// Actual complete pure Unit header and body sites under the selected model.
566    #[serde(
567        default,
568        rename = "sourcePureUnit",
569        skip_serializing_if = "Option::is_none"
570    )]
571    pub source_pure_unit: Option<Box<serde_json::Value>>,
572    pub name: String,
573    pub params: Vec<SParam>,
574    #[serde(default, skip_serializing_if = "Option::is_none")]
575    pub ret: Option<Type>,
576    /// Actual inferred return when source annotations omit an absence case.
577    #[serde(
578        default,
579        rename = "semanticRet",
580        skip_serializing_if = "Option::is_none",
581        deserialize_with = "crate::translation::present_type::read_present_type"
582    )]
583    pub semantic_ret: Option<Type>,
584    pub body: SExpr,
585    #[serde(default, skip_serializing_if = "Option::is_none")]
586    pub span: Option<Span>,
587    /// A function the translator made up, such as a lifted loop.
588    #[serde(default, skip_serializing_if = "is_false")]
589    pub generated: bool,
590    /// Optional owned facts from the actually parsed source function header.
591    #[serde(
592        default,
593        rename = "sourceSignature",
594        skip_serializing_if = "Option::is_none"
595    )]
596    pub source_signature: Option<Box<super::source_signatures::SourceSignature>>,
597    /// Optional owned scalar loop state and checked continuation interpretation.
598    #[serde(
599        default,
600        rename = "sourceLoop",
601        skip_serializing_if = "Option::is_none"
602    )]
603    pub source_loop: Option<Box<super::source_loops::SourceLoop>>,
604    /// Owned actual standard primitive paths, imported aliases and body sites.
605    #[serde(
606        default,
607        rename = "sourcePrimitiveOwners",
608        skip_serializing_if = "Option::is_none"
609    )]
610    pub source_primitive_owners: Option<serde_json::Value>,
611    /// Optional owned standard empty-option source interpretation.
612    #[serde(
613        default,
614        rename = "sourceEmptyOption",
615        skip_serializing_if = "Option::is_none"
616    )]
617    pub source_empty_option: Option<Box<serde_json::Value>>,
618    /// Optional actual Rust type spellings with rechecked scoped ownership.
619    #[serde(
620        default,
621        rename = "sourceTypeNamespace",
622        skip_serializing_if = "Option::is_none"
623    )]
624    pub source_type_namespace: Option<Box<serde_json::Value>>,
625    /// Ordered owned local String moves, copies and replacements.
626    #[serde(
627        default,
628        rename = "sourceLocalState",
629        skip_serializing_if = "Option::is_none"
630    )]
631    pub source_local_state: Option<Box<serde_json::Value>>,
632    /// Owned actual const qualification of a closed primitive predicate.
633    #[serde(
634        default,
635        rename = "sourceConstFunction",
636        skip_serializing_if = "Option::is_none"
637    )]
638    pub source_const_function: Option<Box<serde_json::Value>>,
639    /// Ordered original diagnostic-only attributes attached to this const function.
640    #[serde(
641        default,
642        rename = "sourceDiagnosticAttributes",
643        skip_serializing_if = "Option::is_none",
644        deserialize_with = "crate::translation::source_diagnostic_attributes::read_present_surface_facet"
645    )]
646    pub source_diagnostic_attributes: Option<Box<serde_json::Value>>,
647}
648
649#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
650pub struct STheorem {
651    pub name: String,
652    pub binders: Vec<SBinder>,
653    pub prop: SProp,
654    pub proof: SProof,
655    #[serde(default, skip_serializing_if = "Option::is_none")]
656    pub span: Option<Span>,
657}
658
659#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
660pub struct SModule {
661    pub name: String,
662    pub items: Vec<SItem>,
663    #[serde(default, skip_serializing_if = "Option::is_none")]
664    pub span: Option<Span>,
665}
666
667#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
668#[serde(tag = "k", rename_all = "camelCase")]
669pub enum SItem {
670    Data(SData),
671    Fn(SFn),
672    Theorem(STheorem),
673    Module(SModule),
674}
675
676impl SItem {
677    #[must_use]
678    pub fn name(&self) -> &str {
679        match self {
680            Self::Data(item) => &item.name,
681            Self::Fn(item) => &item.name,
682            Self::Theorem(item) => &item.name,
683            Self::Module(item) => &item.name,
684        }
685    }
686
687    #[must_use]
688    pub const fn span(&self) -> Option<Span> {
689        match self {
690            Self::Data(item) => item.span,
691            Self::Fn(item) => item.span,
692            Self::Theorem(item) => item.span,
693            Self::Module(item) => item.span,
694        }
695    }
696}
697
698#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
699#[serde(tag = "k", rename_all = "camelCase", rename_all_fields = "camelCase")]
700pub enum SEffect {
701    Print {
702        expr: SExpr,
703        style: ShowStyle,
704        #[serde(default, skip_serializing_if = "Option::is_none")]
705        span: Option<Span>,
706    },
707    Let {
708        /// Actual ordered owned Unit-call statement site.
709        #[serde(default, skip_serializing_if = "Option::is_none")]
710        source_pure_unit_call: Option<serde_json::Value>,
711        name: String,
712        #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
713        ty: Option<Type>,
714        value: SExpr,
715        #[serde(default, skip_serializing_if = "is_false")]
716        constant: bool,
717        #[serde(default, skip_serializing_if = "Option::is_none")]
718        span: Option<Span>,
719    },
720    Assert {
721        prop: SProp,
722        #[serde(default, skip_serializing_if = "Option::is_none")]
723        span: Option<Span>,
724    },
725}
726
727#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
728pub struct SMain {
729    /// Owned worker context for an independently selected complete runtime.
730    #[serde(
731        default,
732        rename = "sourceRuntimeWorker",
733        skip_serializing_if = "Option::is_none"
734    )]
735    pub source_runtime_worker: Option<serde_json::Value>,
736    pub effects: Vec<SEffect>,
737    #[serde(default, skip_serializing_if = "Option::is_none")]
738    pub span: Option<Span>,
739    /// Every call of an async function is awaited where it is made.
740    #[serde(rename = "sequentialAsync", default, skip_serializing_if = "is_false")]
741    pub sequential_async: bool,
742}
743
744/// A parsed source program.
745#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
746pub struct SProgram {
747    /// Preserve the raw program representation selector without erasing null.
748    #[serde(
749        default,
750        rename = "referenceSemantics",
751        skip_serializing_if = "Option::is_none",
752        deserialize_with = "raw_metadata::read_present_surface_raw_metadata"
753    )]
754    pub reference_semantics: Option<SurfaceRawMetadata>,
755    /// Complete owned source runtime interpretation, separate from its pure core.
756    #[serde(
757        default,
758        rename = "sourceRuntimeShell",
759        skip_serializing_if = "Option::is_none"
760    )]
761    pub source_runtime_shell: Option<serde_json::Value>,
762    /// Independently selected complete pure Unit program interpretation.
763    #[serde(
764        default,
765        rename = "sourcePureUnitCalls",
766        skip_serializing_if = "Option::is_none"
767    )]
768    pub source_pure_unit_calls: Option<serde_json::Value>,
769    pub language: Language,
770    pub items: Vec<SItem>,
771    #[serde(default)]
772    pub main: Option<SMain>,
773    /// Imports of the items of other modules of the crate (self-translation only).
774    #[serde(default, skip_serializing_if = "Vec::is_empty")]
775    pub imports: Vec<SImport>,
776    /// The other items of the module, which the program calls and reads.
777    #[serde(default, skip_serializing_if = "Vec::is_empty")]
778    pub externals: Vec<External>,
779}