Skip to main content

decl_lang/
ast.rs

1//! AST of the runtime — the shape the tree-sitter CST lowers into
2//! (parse.rs), mirroring the reference implementation's ast.ts.
3use crate::semantics::Value;
4use std::cell::RefCell;
5use std::collections::HashMap;
6use std::rc::Rc;
7
8/// a source range: zero-based rows and columns (UTF-16 units, as the
9/// reference reads them from web-tree-sitter), end exclusive
10#[derive(Debug, Clone, Copy, PartialEq)]
11pub struct Loc {
12    /// the start line
13    pub sl: usize,
14    /// the start column
15    pub sc: usize,
16    /// the end line
17    pub el: usize,
18    /// the end column, exclusive
19    pub ec: usize,
20}
21
22// Every expression node carries its source range in a side table keyed
23// by the node's address (expressions are shared through `Rc`, so the
24// address is the node's identity, as object identity is in the
25// reference); types, members, and declarations carry `loc` inline.
26thread_local! {
27    static EXPR_LOCS: RefCell<HashMap<usize, Loc>> = RefCell::new(HashMap::new());
28}
29fn expr_key(e: &Rc<Expr>) -> usize {
30    Rc::as_ptr(e) as *const u8 as usize
31}
32/// Record an expression's source range.
33pub fn set_expr_loc(e: &Rc<Expr>, loc: Loc) {
34    EXPR_LOCS.with(|t| t.borrow_mut().insert(expr_key(e), loc));
35}
36/// An expression's source range, when recorded.
37pub fn expr_loc(e: &Rc<Expr>) -> Option<Loc> {
38    EXPR_LOCS.with(|t| t.borrow().get(&expr_key(e)).copied())
39}
40
41#[derive(Debug, Clone)]
42/// a type expression (§3; chapter 11)
43pub enum TypeAst {
44    /// a primitive type by name
45    Prim {
46        /// the name
47        name: String,
48        /// the source range
49        loc: Option<Loc>,
50    },
51    /// a literal type
52    Lit {
53        /// the literal
54        v: Value,
55        /// the source range
56        loc: Option<Loc>,
57    },
58    /// a numeric range
59    Range {
60        /// the lower bound
61        lo: Value,
62        /// the upper bound
63        hi: Value,
64        /// whether the upper bound is excluded
65        excl: bool,
66        /// the source range
67        loc: Option<Loc>,
68    },
69    /// a string pattern
70    Pattern {
71        /// the pattern's text
72        re: String,
73        /// the source range
74        loc: Option<Loc>,
75    },
76    /// a record type
77    Record {
78        /// its members
79        members: Vec<MemberAst>,
80        /// whether it is open (`...`)
81        open: bool,
82        /// the source range
83        loc: Option<Loc>,
84    },
85    /// a map type
86    Map {
87        /// the key type
88        key: Box<TypeAst>,
89        /// the value type
90        val: Box<TypeAst>,
91        /// the source range
92        loc: Option<Loc>,
93    },
94    /// an array type
95    Array {
96        /// the element type
97        elem: Box<TypeAst>,
98        /// the lower size bound
99        lo: Option<Value>,
100        /// the upper size bound
101        hi: Option<Value>,
102        /// whether the upper bound is excluded
103        excl: bool,
104        /// the source range
105        loc: Option<Loc>,
106    },
107    /// a union
108    Union {
109        /// its arms
110        arms: Vec<TypeAst>,
111        /// the source range
112        loc: Option<Loc>,
113    },
114    /// an intersection
115    Isect {
116        /// its arms
117        arms: Vec<TypeAst>,
118        /// the source range
119        loc: Option<Loc>,
120    },
121    /// a function type
122    Func {
123        /// the parameter types
124        params: Vec<TypeAst>,
125        /// the return type
126        ret: Box<TypeAst>,
127        /// the source range
128        loc: Option<Loc>,
129    },
130    /// a named type, with its arguments, predicates, and extension
131    Named {
132        /// the name
133        name: String,
134        /// its type arguments
135        args: Vec<TypeAst>,
136        /// its predicates, when refined
137        preds: Option<Vec<Rc<Expr>>>,
138        /// its extension (`{ … }`)
139        ext: Option<Box<TypeAst>>,
140        /// the source range
141        loc: Option<Loc>,
142    },
143}
144impl TypeAst {
145    /// The source range.
146    pub fn loc(&self) -> Option<Loc> {
147        match self {
148            TypeAst::Prim { loc, .. }
149            | TypeAst::Lit { loc, .. }
150            | TypeAst::Range { loc, .. }
151            | TypeAst::Pattern { loc, .. }
152            | TypeAst::Record { loc, .. }
153            | TypeAst::Map { loc, .. }
154            | TypeAst::Array { loc, .. }
155            | TypeAst::Union { loc, .. }
156            | TypeAst::Isect { loc, .. }
157            | TypeAst::Func { loc, .. }
158            | TypeAst::Named { loc, .. } => *loc,
159        }
160    }
161    /// Record the source range.
162    pub fn set_loc(&mut self, l: Loc) {
163        match self {
164            TypeAst::Prim { loc, .. }
165            | TypeAst::Lit { loc, .. }
166            | TypeAst::Range { loc, .. }
167            | TypeAst::Pattern { loc, .. }
168            | TypeAst::Record { loc, .. }
169            | TypeAst::Map { loc, .. }
170            | TypeAst::Array { loc, .. }
171            | TypeAst::Union { loc, .. }
172            | TypeAst::Isect { loc, .. }
173            | TypeAst::Func { loc, .. }
174            | TypeAst::Named { loc, .. } => *loc = Some(l),
175        }
176    }
177}
178
179#[derive(Debug, Clone)]
180/// a member of a record type (§5)
181pub enum MemberAst {
182    /// a value member: required, optional, or defaulted
183    Value {
184        /// the name
185        name: String,
186        /// optional (`?`)
187        opt: bool,
188        /// the type
189        ty: TypeAst,
190        /// the default, for a defaulted member
191        dflt: Option<Rc<Expr>>,
192        /// the annotations (§5.10)
193        annotations: Vec<Annotation>,
194        /// the source range
195        loc: Option<Loc>,
196    },
197    /// `hidden`: `x$ = e` — computed for the schema's own use, never part of the value (D34)
198    Derived {
199        /// the name
200        name: String,
201        /// the annotation, when given
202        ty: Option<TypeAst>,
203        /// the expression
204        expr: Rc<Expr>,
205        /// hidden (`x$ = e`)
206        hidden: bool,
207        /// the annotations (§5.10)
208        annotations: Vec<Annotation>,
209        /// the source range
210        loc: Option<Loc>,
211    },
212    /// a context declaration (`$parent: ref<P>`, §7.3)
213    Context {
214        /// the variable
215        variable: String,
216        /// the declared type
217        ty: TypeAst,
218        /// the annotations (§5.10)
219        annotations: Vec<Annotation>,
220        /// the source range
221        loc: Option<Loc>,
222    },
223    /// an assertion
224    Assert {
225        /// the name
226        name: String,
227        /// the condition
228        cond: Rc<Expr>,
229        /// the `else` tail
230        tail: Option<Tail>,
231        /// the annotations (§5.10)
232        annotations: Vec<Annotation>,
233        /// the source range
234        loc: Option<Loc>,
235    },
236    /// a guarded group of members (`when`)
237    When {
238        /// the condition
239        cond: Rc<Expr>,
240        /// the members
241        body: Vec<MemberAst>,
242        /// the annotations (§5.10)
243        annotations: Vec<Annotation>,
244        /// the source range
245        loc: Option<Loc>,
246    },
247}
248impl MemberAst {
249    /// The source range.
250    pub fn loc(&self) -> Option<Loc> {
251        match self {
252            MemberAst::Value { loc, .. }
253            | MemberAst::Derived { loc, .. }
254            | MemberAst::Context { loc, .. }
255            | MemberAst::Assert { loc, .. }
256            | MemberAst::When { loc, .. } => *loc,
257        }
258    }
259    /// Record the source range.
260    pub fn set_loc(&mut self, l: Loc) {
261        match self {
262            MemberAst::Value { loc, .. }
263            | MemberAst::Derived { loc, .. }
264            | MemberAst::Context { loc, .. }
265            | MemberAst::Assert { loc, .. }
266            | MemberAst::When { loc, .. } => *loc = Some(l),
267        }
268    }
269    /// Attach the annotations (§5.10).
270    pub fn set_annotations(&mut self, a: Vec<Annotation>) {
271        match self {
272            MemberAst::Value { annotations, .. }
273            | MemberAst::Derived { annotations, .. }
274            | MemberAst::Context { annotations, .. }
275            | MemberAst::Assert { annotations, .. }
276            | MemberAst::When { annotations, .. } => *annotations = a,
277        }
278    }
279    /// the annotations (§5.10)
280    pub fn annotations(&self) -> &[Annotation] {
281        match self {
282            MemberAst::Value { annotations, .. }
283            | MemberAst::Derived { annotations, .. }
284            | MemberAst::Context { annotations, .. }
285            | MemberAst::Assert { annotations, .. }
286            | MemberAst::When { annotations, .. } => annotations,
287        }
288    }
289    /// the member's name (`name` in the reference: value, derived, and assert members)
290    pub fn name(&self) -> Option<&str> {
291        match self {
292            MemberAst::Value { name, .. }
293            | MemberAst::Derived { name, .. }
294            | MemberAst::Assert { name, .. } => Some(name),
295            _ => None,
296        }
297    }
298}
299
300#[derive(Debug, Clone)]
301/// a part of a template: text, or an interpolated expression
302pub enum TPart {
303    /// text
304    Text(String),
305    /// an interpolated expression
306    Expr(Rc<Expr>),
307}
308
309#[derive(Debug, Clone)]
310/// an `else` tail: an inline message with a severity, or a diagnostic reference
311pub enum Tail {
312    /// an inline message
313    Inline {
314        /// the severity
315        severity: String,
316        /// the message template
317        template: Vec<TPart>,
318    },
319    /// a diagnostic reference
320    Ref {
321        /// the diagnostic's name
322        name: String,
323        /// its arguments
324        args: Vec<Rc<Expr>>,
325    },
326}
327
328#[derive(Debug, Clone)]
329/// a comprehension clause
330pub struct ForClause {
331    /// the variable
332    pub v: String,
333    /// what it ranges over
334    pub iter: Rc<Expr>,
335    /// the `if` filters
336    pub filters: Vec<Rc<Expr>>,
337}
338
339#[derive(Debug, Clone)]
340/// an arm of a `match`
341pub struct MatchArm {
342    /// the variable
343    pub v: String,
344    /// the type it matches; none for the catch-all
345    pub ty: Option<TypeAst>,
346    /// the body
347    pub body: Rc<Expr>,
348}
349
350#[derive(Debug, Clone)]
351/// an expression (§4)
352pub enum Expr {
353    /// a literal
354    Lit(Value),
355    /// a unit literal
356    UnitLit {
357        /// the number
358        num: f64,
359        /// the unit
360        unit: String,
361    },
362    /// a template string
363    Template(Vec<TPart>),
364    /// a name
365    Name(String),
366    /// a context variable (`$this`, `$parent`, `$root`, `$key`)
367    Ctx(String),
368    /// `$referrers(T, "m")`
369    Referrers {
370        /// the referring type
371        ty: String,
372        /// its member
373        member: String,
374    },
375    /// a record literal
376    Obj(Vec<(String, Rc<Expr>)>),
377    /// a spread entry's operand (§4.2): the value of an object entry keyed `...`
378    Spread(Rc<Expr>),
379    /// an array literal: (spread, item)
380    Arr(Vec<(bool, Rc<Expr>)>),
381    /// an array comprehension
382    Comp {
383        /// the head
384        head: Rc<Expr>,
385        /// the clauses
386        clauses: Vec<ForClause>,
387    },
388    /// a map comprehension
389    MapComp {
390        /// the key
391        key: Rc<Expr>,
392        /// the value
393        val: Rc<Expr>,
394        /// the clauses
395        clauses: Vec<ForClause>,
396    },
397    /// a binary operation
398    Bin {
399        /// the operator
400        op: String,
401        /// the left operand
402        l: Rc<Expr>,
403        /// the right operand
404        r: Rc<Expr>,
405    },
406    /// a unary operation
407    Un {
408        /// the operator
409        op: String,
410        /// the operand
411        x: Rc<Expr>,
412    },
413    /// a parenthesized expression
414    Paren(Rc<Expr>),
415    /// `if … then … else`
416    If {
417        /// the condition
418        c: Rc<Expr>,
419        /// the `then` branch
420        t: Rc<Expr>,
421        /// the `else` branch
422        f: Rc<Expr>,
423    },
424    /// a function literal
425    Lambda {
426        /// the parameters
427        params: Vec<String>,
428        /// the body
429        body: Rc<Expr>,
430    },
431    /// a call
432    Call {
433        /// the function
434        fun: Rc<Expr>,
435        /// the arguments
436        args: Vec<Rc<Expr>>,
437    },
438    /// a member access
439    Member {
440        /// the record
441        x: Rc<Expr>,
442        /// the member
443        name: String,
444        /// `?.`
445        safe: bool,
446    },
447    /// an index or key access
448    Index {
449        /// the array or map
450        x: Rc<Expr>,
451        /// the index or key
452        i: Rc<Expr>,
453    },
454    /// a record update (`with`)
455    With {
456        /// the base
457        base: Rc<Expr>,
458        /// the patch
459        patch: Rc<Expr>,
460    },
461    /// a pattern literal
462    Pattern(String),
463    /// a `match`
464    Match {
465        /// the subject
466        subject: Rc<Expr>,
467        /// the arms
468        arms: Vec<MatchArm>,
469    },
470}
471
472#[derive(Debug, Clone)]
473/// an annotation (§5.10): `@name` or `@name(args)` — metadata only (D4)
474pub struct Annotation {
475    /// the name
476    pub name: String,
477    /// the arguments
478    pub args: Vec<Rc<Expr>>,
479    /// the source range
480    pub loc: Option<Loc>,
481}
482
483#[derive(Debug, Clone)]
484/// a parameter of a function, a type, or a diagnostic
485pub struct Param {
486    /// the name
487    pub name: String,
488    /// the type, when annotated
489    pub ty: Option<TypeAst>,
490}
491
492#[derive(Debug, Clone)]
493/// an imported name, possibly renamed
494pub struct ImportItem {
495    /// the name
496    pub name: String,
497    /// the alias
498    pub alias: Option<String>,
499}
500
501// `ret` is lowered for fidelity with the reference AST; the runtime does
502// not check return annotations (that is the static checker's job)
503#[allow(dead_code)]
504#[derive(Debug, Clone)]
505/// a declaration (§5, §8)
506pub enum DeclBody {
507    /// a type
508    Type {
509        /// the name
510        name: String,
511        /// the type parameters
512        params: Vec<Param>,
513        /// the type
514        ty: TypeAst,
515        /// its `else` tail
516        tail: Option<Tail>,
517    },
518    /// a constant
519    Const {
520        /// the name
521        name: String,
522        /// the annotation, when given
523        ty: Option<TypeAst>,
524        /// the expression
525        expr: Rc<Expr>,
526    },
527    /// a function
528    Func {
529        /// the name
530        name: String,
531        /// the parameters
532        params: Vec<Param>,
533        /// the return type, when annotated
534        ret: Option<TypeAst>,
535        /// the body
536        body: Rc<Expr>,
537    },
538    /// an output root
539    Output {
540        /// the name
541        name: String,
542        /// the type
543        ty: TypeAst,
544        /// the expression
545        expr: Rc<Expr>,
546    },
547    /// an input root
548    Input {
549        /// the name
550        name: String,
551        /// the type
552        ty: TypeAst,
553        /// the fallback, when given
554        fallback: Option<Rc<Expr>>,
555    },
556    /// a diagnostic template
557    Diagnostic {
558        /// the name
559        name: String,
560        /// the parameters
561        params: Vec<Param>,
562        /// the severity
563        severity: String,
564        /// the message template
565        template: Vec<TPart>,
566    },
567    /// a dimension
568    Dimension {
569        /// the name
570        name: String,
571        /// its definition as (dimension, exponent) terms; none for a base dimension
572        terms: Option<Vec<(String, i32)>>,
573    },
574    /// a unit
575    Unit {
576        /// the name
577        name: String,
578        /// its dimension
579        dim: Option<String>,
580        /// its factor against the base unit
581        factor: Option<Rc<Expr>>,
582        /// the base unit it is defined against
583        base: Option<String>,
584    },
585    /// an import
586    Import {
587        /// the module
588        from: String,
589        /// the names imported; none for a namespace import
590        names: Option<Vec<ImportItem>>,
591        /// the namespace, for `import * as ns`
592        ns: Option<String>,
593    },
594    /// a re-export
595    ReExport {
596        /// the module
597        from: String,
598        /// the names
599        names: Vec<ImportItem>,
600    },
601}
602
603#[derive(Debug, Clone)]
604/// a declaration, with whether it is exported and its source range
605pub struct Decl {
606    /// the declaration
607    pub body: DeclBody,
608    /// `export`
609    pub exported: bool,
610    /// the annotations (§5.10)
611    pub annotations: Vec<Annotation>,
612    /// the declaration's source range (Phase 6 foundations); `export` included
613    pub loc: Option<Loc>,
614}
615
616impl Decl {
617    /// The declared name, when the declaration has one.
618    pub fn name(&self) -> Option<&str> {
619        match &self.body {
620            DeclBody::Type { name, .. }
621            | DeclBody::Const { name, .. }
622            | DeclBody::Func { name, .. }
623            | DeclBody::Output { name, .. }
624            | DeclBody::Input { name, .. }
625            | DeclBody::Diagnostic { name, .. }
626            | DeclBody::Dimension { name, .. }
627            | DeclBody::Unit { name, .. } => Some(name),
628            _ => None,
629        }
630    }
631}
632
633/// does an expression mention `$referrers` anywhere? (deferred slots)
634pub fn mentions_referrers(e: &Expr) -> bool {
635    match e {
636        Expr::Referrers { .. } => true,
637        Expr::Lit(_) | Expr::UnitLit { .. } | Expr::Name(_) | Expr::Ctx(_) | Expr::Pattern(_) => {
638            false
639        }
640        Expr::Template(parts) => parts
641            .iter()
642            .any(|p| matches!(p, TPart::Expr(x) if mentions_referrers(x))),
643        Expr::Obj(es) => es.iter().any(|(_, v)| mentions_referrers(v)),
644        Expr::Spread(x) => mentions_referrers(x),
645        Expr::Arr(items) => items.iter().any(|(_, v)| mentions_referrers(v)),
646        Expr::Comp { head, clauses } => {
647            mentions_referrers(head) || clauses.iter().any(clause_mentions)
648        }
649        Expr::MapComp { key, val, clauses } => {
650            mentions_referrers(key)
651                || mentions_referrers(val)
652                || clauses.iter().any(clause_mentions)
653        }
654        Expr::Bin { l, r, .. } => mentions_referrers(l) || mentions_referrers(r),
655        Expr::Un { x, .. } | Expr::Paren(x) => mentions_referrers(x),
656        Expr::If { c, t, f } => {
657            mentions_referrers(c) || mentions_referrers(t) || mentions_referrers(f)
658        }
659        Expr::Lambda { body, .. } => mentions_referrers(body),
660        Expr::Call { fun, args } => {
661            mentions_referrers(fun) || args.iter().any(|a| mentions_referrers(a))
662        }
663        Expr::Member { x, .. } => mentions_referrers(x),
664        Expr::Index { x, i } => mentions_referrers(x) || mentions_referrers(i),
665        Expr::With { base, patch } => mentions_referrers(base) || mentions_referrers(patch),
666        Expr::Match { subject, arms } => {
667            mentions_referrers(subject) || arms.iter().any(|a| mentions_referrers(&a.body))
668        }
669    }
670}
671
672fn clause_mentions(c: &ForClause) -> bool {
673    mentions_referrers(&c.iter) || c.filters.iter().any(|f| mentions_referrers(f))
674}
675
676/// A short name for an expression, for messages.
677pub fn expr_name(e: &Expr) -> String {
678    match e {
679        Expr::Name(n) => n.clone(),
680        Expr::Call { fun, .. } => expr_name(fun),
681        _ => "<predicate>".into(),
682    }
683}
684
685// ---------------- generic AST traversal (the reference walks object values) ----------------
686/// every expression reachable from `e`, in the reference's object-value
687/// order; `into_types` also descends into type ASTs embedded in
688/// expressions (match arm types), as the untyped walks do
689pub(crate) fn walk_expr_tree(e: &Rc<Expr>, into_types: bool, f: &mut dyn FnMut(&Rc<Expr>)) {
690    f(e);
691    let mut go = |x: &Rc<Expr>| walk_expr_tree(x, into_types, f);
692    match &**e {
693        Expr::Lit(_)
694        | Expr::UnitLit { .. }
695        | Expr::Name(_)
696        | Expr::Ctx(_)
697        | Expr::Referrers { .. }
698        | Expr::Pattern(_) => {}
699        Expr::Template(parts) => {
700            for p in parts {
701                if let TPart::Expr(x) = p {
702                    go(x);
703                }
704            }
705        }
706        Expr::Obj(entries) => entries.iter().for_each(|(_, v)| go(v)),
707        Expr::Arr(items) => items.iter().for_each(|(_, v)| go(v)),
708        Expr::Comp { head, clauses } => {
709            go(head);
710            for c in clauses {
711                go(&c.iter);
712                c.filters.iter().for_each(&mut go);
713            }
714        }
715        Expr::MapComp { key, val, clauses } => {
716            go(key);
717            go(val);
718            for c in clauses {
719                go(&c.iter);
720                c.filters.iter().for_each(&mut go);
721            }
722        }
723        Expr::Bin { l, r, .. } => {
724            go(l);
725            go(r);
726        }
727        Expr::Un { x, .. } | Expr::Paren(x) | Expr::Spread(x) => go(x),
728        Expr::If { c, t, f: ff } => {
729            go(c);
730            go(t);
731            go(ff);
732        }
733        Expr::Lambda { body, .. } => go(body),
734        Expr::Call { fun, args } => {
735            go(fun);
736            args.iter().for_each(&mut go);
737        }
738        Expr::Member { x, .. } => go(x),
739        Expr::Index { x, i } => {
740            go(x);
741            go(i);
742        }
743        Expr::With { base, patch } => {
744            go(base);
745            go(patch);
746        }
747        Expr::Match { subject, arms } => {
748            go(subject);
749            for a in arms {
750                if into_types {
751                    if let Some(t) = &a.ty {
752                        walk_type_exprs(t, into_types, f);
753                    }
754                }
755                walk_expr_tree(&a.body, into_types, f);
756            }
757        }
758    }
759}
760/// every expression embedded in a type AST (predicates, member defaults, asserts)
761pub(crate) fn walk_type_exprs(t: &TypeAst, into_types: bool, f: &mut dyn FnMut(&Rc<Expr>)) {
762    match t {
763        TypeAst::Prim { .. }
764        | TypeAst::Lit { .. }
765        | TypeAst::Range { .. }
766        | TypeAst::Pattern { .. } => {}
767        TypeAst::Record { members, .. } => members
768            .iter()
769            .for_each(|m| walk_member_exprs(m, into_types, f)),
770        TypeAst::Map { key, val, .. } => {
771            walk_type_exprs(key, into_types, f);
772            walk_type_exprs(val, into_types, f);
773        }
774        TypeAst::Array { elem, .. } => walk_type_exprs(elem, into_types, f),
775        TypeAst::Union { arms, .. } | TypeAst::Isect { arms, .. } => {
776            arms.iter().for_each(|a| walk_type_exprs(a, into_types, f))
777        }
778        TypeAst::Func { params, ret, .. } => {
779            params
780                .iter()
781                .for_each(|p| walk_type_exprs(p, into_types, f));
782            walk_type_exprs(ret, into_types, f);
783        }
784        TypeAst::Named {
785            args, preds, ext, ..
786        } => {
787            args.iter().for_each(|a| walk_type_exprs(a, into_types, f));
788            if let Some(ps) = preds {
789                ps.iter().for_each(|p| walk_expr_tree(p, into_types, f));
790            }
791            if let Some(x) = ext {
792                walk_type_exprs(x, into_types, f);
793            }
794        }
795    }
796}
797fn walk_member_exprs(m: &MemberAst, into_types: bool, f: &mut dyn FnMut(&Rc<Expr>)) {
798    match m {
799        MemberAst::Value { ty, dflt, .. } => {
800            walk_type_exprs(ty, into_types, f);
801            if let Some(d) = dflt {
802                walk_expr_tree(d, into_types, f);
803            }
804        }
805        MemberAst::Derived { ty, expr, .. } => {
806            if let Some(t) = ty {
807                walk_type_exprs(t, into_types, f);
808            }
809            walk_expr_tree(expr, into_types, f);
810        }
811        MemberAst::Context { ty, .. } => walk_type_exprs(ty, into_types, f),
812        MemberAst::Assert { cond, tail, .. } => {
813            walk_expr_tree(cond, into_types, f);
814            match tail {
815                Some(Tail::Inline { template, .. }) => {
816                    for p in template {
817                        if let TPart::Expr(x) = p {
818                            walk_expr_tree(x, into_types, f);
819                        }
820                    }
821                }
822                Some(Tail::Ref { args, .. }) => {
823                    args.iter().for_each(|a| walk_expr_tree(a, into_types, f))
824                }
825                None => {}
826            }
827        }
828        MemberAst::When { cond, body, .. } => {
829            walk_expr_tree(cond, into_types, f);
830            body.iter()
831                .for_each(|b| walk_member_exprs(b, into_types, f));
832        }
833    }
834}