Skip to main content

harn_parser/
ast.rs

1use harn_lexer::{Span, StringSegment};
2
3/// A node wrapped with source location information.
4#[derive(Debug, Clone, PartialEq)]
5pub struct Spanned<T> {
6    pub node: T,
7    pub span: Span,
8}
9
10impl<T> Spanned<T> {
11    pub fn new(node: T, span: Span) -> Self {
12        Self { node, span }
13    }
14
15    pub fn dummy(node: T) -> Self {
16        Self {
17            node,
18            span: Span::dummy(),
19        }
20    }
21}
22
23/// A spanned AST node — the primary unit throughout the compiler.
24pub type SNode = Spanned<Node>;
25
26/// Helper to wrap a node with a span.
27pub fn spanned(node: Node, span: Span) -> SNode {
28    SNode::new(node, span)
29}
30
31/// If `node` is an `AttributedDecl`, returns `(attrs, inner)`; otherwise
32/// returns an empty attribute slice and the node itself. Use at the top
33/// of any consumer that processes top-level statements so attributes
34/// flow through transparently.
35pub fn peel_attributes(node: &SNode) -> (&[Attribute], &SNode) {
36    match &node.node {
37        Node::AttributedDecl { attributes, inner } => (attributes.as_slice(), inner.as_ref()),
38        _ => (&[], node),
39    }
40}
41
42/// A single argument to an attribute. Positional args have `name = None`;
43/// named args use `name: Some("key")`. Values are restricted to
44/// compile-time metadata expressions by the parser (literal scalars,
45/// identifiers, lists, dicts, and call-shaped sentinels).
46#[derive(Debug, Clone, PartialEq)]
47pub struct AttributeArg {
48    pub name: Option<String>,
49    pub value: SNode,
50    pub span: Span,
51}
52
53/// An attribute attached to a declaration: `@deprecated(since: "0.8")`.
54#[derive(Debug, Clone, PartialEq)]
55pub struct Attribute {
56    pub name: String,
57    pub args: Vec<AttributeArg>,
58    pub span: Span,
59}
60
61impl Attribute {
62    /// Find a named argument by key.
63    pub fn named_arg(&self, key: &str) -> Option<&SNode> {
64        self.args
65            .iter()
66            .find(|a| a.name.as_deref() == Some(key))
67            .map(|a| &a.value)
68    }
69
70    /// First positional argument, if any.
71    pub fn positional(&self, idx: usize) -> Option<&SNode> {
72        self.args
73            .iter()
74            .filter(|a| a.name.is_none())
75            .nth(idx)
76            .map(|a| &a.value)
77    }
78
79    /// Convenience: extract a string-literal arg by name.
80    pub fn string_arg(&self, key: &str) -> Option<String> {
81        match self.named_arg(key).map(|n| &n.node) {
82            Some(Node::StringLiteral(s)) => Some(s.clone()),
83            Some(Node::RawStringLiteral(s)) => Some(s.clone()),
84            _ => None,
85        }
86    }
87}
88
89/// AST nodes for the Harn language.
90#[derive(Debug, Clone, PartialEq)]
91pub enum Node {
92    /// A declaration carrying one or more attributes (`@attr`). The inner
93    /// node is always one of: FnDecl, ToolDecl, Pipeline, StructDecl,
94    /// EnumDecl, TypeDecl, InterfaceDecl, ImplBlock.
95    AttributedDecl {
96        attributes: Vec<Attribute>,
97        inner: Box<SNode>,
98    },
99    Pipeline {
100        name: String,
101        params: Vec<String>,
102        return_type: Option<TypeExpr>,
103        body: Vec<SNode>,
104        extends: Option<String>,
105        is_pub: bool,
106    },
107    LetBinding {
108        pattern: BindingPattern,
109        type_ann: Option<TypeExpr>,
110        value: Box<SNode>,
111    },
112    VarBinding {
113        pattern: BindingPattern,
114        type_ann: Option<TypeExpr>,
115        value: Box<SNode>,
116    },
117    OverrideDecl {
118        name: String,
119        params: Vec<String>,
120        body: Vec<SNode>,
121    },
122    ImportDecl {
123        path: String,
124        /// When true, the wildcard import is a re-export: every public symbol
125        /// from the target module becomes part of this module's public surface.
126        is_pub: bool,
127    },
128    /// Selective import: import { foo, bar } from "module"
129    SelectiveImport {
130        names: Vec<String>,
131        path: String,
132        /// When true, the listed names are re-exported as part of this
133        /// module's public surface.
134        is_pub: bool,
135    },
136    EnumDecl {
137        name: String,
138        type_params: Vec<TypeParam>,
139        variants: Vec<EnumVariant>,
140        is_pub: bool,
141    },
142    StructDecl {
143        name: String,
144        type_params: Vec<TypeParam>,
145        fields: Vec<StructField>,
146        is_pub: bool,
147    },
148    InterfaceDecl {
149        name: String,
150        type_params: Vec<TypeParam>,
151        associated_types: Vec<(String, Option<TypeExpr>)>,
152        methods: Vec<InterfaceMethod>,
153    },
154    /// Impl block: impl TypeName { fn method(self, ...) { ... } ... }
155    ImplBlock {
156        type_name: String,
157        methods: Vec<SNode>,
158    },
159
160    IfElse {
161        condition: Box<SNode>,
162        then_body: Vec<SNode>,
163        else_body: Option<Vec<SNode>>,
164    },
165    ForIn {
166        pattern: BindingPattern,
167        iterable: Box<SNode>,
168        body: Vec<SNode>,
169    },
170    MatchExpr {
171        value: Box<SNode>,
172        arms: Vec<MatchArm>,
173    },
174    WhileLoop {
175        condition: Box<SNode>,
176        body: Vec<SNode>,
177    },
178    Retry {
179        count: Box<SNode>,
180        body: Vec<SNode>,
181    },
182    /// Scoped cost-aware LLM routing block:
183    /// `cost_route { key: value ... body }`.
184    ///
185    /// Options are inherited by nested `llm_call` invocations unless a
186    /// call explicitly overrides the same option.
187    CostRoute {
188        options: Vec<(String, SNode)>,
189        body: Vec<SNode>,
190    },
191    ReturnStmt {
192        value: Option<Box<SNode>>,
193    },
194    TryCatch {
195        body: Vec<SNode>,
196        error_var: Option<String>,
197        error_type: Option<TypeExpr>,
198        catch_body: Vec<SNode>,
199        finally_body: Option<Vec<SNode>>,
200    },
201    /// Try expression: try { body } — returns Result.Ok(value), an existing Result,
202    /// or Result.Err(error).
203    TryExpr {
204        body: Vec<SNode>,
205    },
206    FnDecl {
207        name: String,
208        type_params: Vec<TypeParam>,
209        params: Vec<TypedParam>,
210        return_type: Option<TypeExpr>,
211        where_clauses: Vec<WhereClause>,
212        body: Vec<SNode>,
213        is_pub: bool,
214        is_stream: bool,
215    },
216    ToolDecl {
217        name: String,
218        description: Option<String>,
219        params: Vec<TypedParam>,
220        return_type: Option<TypeExpr>,
221        body: Vec<SNode>,
222        is_pub: bool,
223    },
224    /// Top-level `skill NAME { ... }` declaration.
225    ///
226    /// Skills bundle metadata, tool references, MCP server lists, and
227    /// optional lifecycle hooks into a typed unit. Each body entry is a
228    /// `<field_name> <expression>` pair; the compiler lowers the decl to
229    /// `skill_define(skill_registry(), NAME, { field: expr, ... })` and
230    /// binds the resulting registry dict to `NAME`.
231    SkillDecl {
232        name: String,
233        fields: Vec<(String, SNode)>,
234        is_pub: bool,
235    },
236    /// Top-level `eval_pack NAME_OR_STRING { ... }` declaration.
237    ///
238    /// The compiler lowers fields into `eval_pack_manifest({ ... })` and
239    /// binds the normalized manifest to `binding_name`. Optional executable
240    /// body statements are only run when the declaration itself is executed
241    /// in script/block position; top-level pipeline preloading registers the
242    /// manifest data without running the body.
243    EvalPackDecl {
244        binding_name: String,
245        pack_id: String,
246        fields: Vec<(String, SNode)>,
247        body: Vec<SNode>,
248        summarize: Option<Vec<SNode>>,
249        is_pub: bool,
250    },
251    TypeDecl {
252        name: String,
253        type_params: Vec<TypeParam>,
254        type_expr: TypeExpr,
255    },
256    SpawnExpr {
257        body: Vec<SNode>,
258    },
259    /// Duration literal: 500ms, 5s, 30m, 2h, 1d, 1w
260    DurationLiteral(u64),
261    /// Range expression: `start to end` (inclusive) or `start to end exclusive` (half-open)
262    RangeExpr {
263        start: Box<SNode>,
264        end: Box<SNode>,
265        inclusive: bool,
266    },
267    /// Guard clause: guard condition else { body }
268    GuardStmt {
269        condition: Box<SNode>,
270        else_body: Vec<SNode>,
271    },
272    RequireStmt {
273        condition: Box<SNode>,
274        message: Option<Box<SNode>>,
275    },
276    /// Defer statement: defer { body } — runs body at scope exit.
277    DeferStmt {
278        body: Vec<SNode>,
279    },
280    /// Deadline block: deadline DURATION { body }
281    DeadlineBlock {
282        duration: Box<SNode>,
283        body: Vec<SNode>,
284    },
285    /// Yield expression: yields control to host, optionally with a value.
286    YieldExpr {
287        value: Option<Box<SNode>>,
288    },
289    /// Emit expression: emits one value from a `gen fn` stream.
290    EmitExpr {
291        value: Box<SNode>,
292    },
293    /// Mutex block: mutual exclusion for concurrent access.
294    MutexBlock {
295        body: Vec<SNode>,
296    },
297    /// Break out of a loop.
298    BreakStmt,
299    /// Continue to next loop iteration.
300    ContinueStmt,
301
302    /// First-class HITL primitive expression.
303    ///
304    /// Lexed as a reserved keyword (`request_approval`, `dual_control`,
305    /// `ask_user`, `escalate_to`), parsed at primary-expression position
306    /// as `keyword "(" args ")"`. Each arg is either positional
307    /// (`expr`) or named (`name: expr`).
308    ///
309    /// The compiler lowers this to a call to the matching async stdlib
310    /// builtin in `crates/harn-vm/src/stdlib/hitl.rs`, packaging the
311    /// named arguments into the existing options-dict shape. The
312    /// typechecker assigns each kind its canonical envelope return type.
313    HitlExpr {
314        kind: HitlKind,
315        args: Vec<HitlArg>,
316    },
317
318    Parallel {
319        mode: ParallelMode,
320        /// For Count mode: the count expression. For Each/Settle: the list expression.
321        expr: Box<SNode>,
322        variable: Option<String>,
323        body: Vec<SNode>,
324        /// Optional trailing `with { max_concurrent: N, ... }` option block.
325        /// A vec (rather than a dict) preserves source order for error
326        /// reporting and keeps parsing cheap. Only `max_concurrent` is
327        /// currently honored; unknown keys are rejected by the parser.
328        options: Vec<(String, SNode)>,
329    },
330
331    SelectExpr {
332        cases: Vec<SelectCase>,
333        timeout: Option<(Box<SNode>, Vec<SNode>)>,
334        default_body: Option<Vec<SNode>>,
335    },
336
337    FunctionCall {
338        name: String,
339        type_args: Vec<TypeExpr>,
340        args: Vec<SNode>,
341    },
342    MethodCall {
343        object: Box<SNode>,
344        method: String,
345        args: Vec<SNode>,
346    },
347    /// Optional method call: `obj?.method(args)` — returns nil if obj is nil.
348    OptionalMethodCall {
349        object: Box<SNode>,
350        method: String,
351        args: Vec<SNode>,
352    },
353    PropertyAccess {
354        object: Box<SNode>,
355        property: String,
356    },
357    /// Optional chaining: `obj?.property` — returns nil if obj is nil.
358    OptionalPropertyAccess {
359        object: Box<SNode>,
360        property: String,
361    },
362    SubscriptAccess {
363        object: Box<SNode>,
364        index: Box<SNode>,
365    },
366    /// Optional subscript: `obj?[index]` — returns nil if obj is nil.
367    OptionalSubscriptAccess {
368        object: Box<SNode>,
369        index: Box<SNode>,
370    },
371    SliceAccess {
372        object: Box<SNode>,
373        start: Option<Box<SNode>>,
374        end: Option<Box<SNode>>,
375    },
376    BinaryOp {
377        op: String,
378        left: Box<SNode>,
379        right: Box<SNode>,
380    },
381    UnaryOp {
382        op: String,
383        operand: Box<SNode>,
384    },
385    Ternary {
386        condition: Box<SNode>,
387        true_expr: Box<SNode>,
388        false_expr: Box<SNode>,
389    },
390    Assignment {
391        target: Box<SNode>,
392        value: Box<SNode>,
393        /// None = plain `=`, Some("+") = `+=`, etc.
394        op: Option<String>,
395    },
396    ThrowStmt {
397        value: Box<SNode>,
398    },
399
400    /// Enum variant construction: EnumName.Variant(args)
401    EnumConstruct {
402        enum_name: String,
403        variant: String,
404        args: Vec<SNode>,
405    },
406    /// Struct construction: StructName { field: value, ... }
407    StructConstruct {
408        struct_name: String,
409        fields: Vec<DictEntry>,
410    },
411
412    InterpolatedString(Vec<StringSegment>),
413    StringLiteral(String),
414    /// Raw string literal `r"..."` — no escape processing.
415    RawStringLiteral(String),
416    IntLiteral(i64),
417    FloatLiteral(f64),
418    BoolLiteral(bool),
419    NilLiteral,
420    Identifier(String),
421    ListLiteral(Vec<SNode>),
422    DictLiteral(Vec<DictEntry>),
423    /// Spread expression `...expr` inside list/dict literals.
424    Spread(Box<SNode>),
425    /// Try operator: expr? — unwraps Result.Ok or propagates Result.Err.
426    TryOperator {
427        operand: Box<SNode>,
428    },
429    /// Try-star operator: `try* EXPR` — evaluates EXPR; on throw, runs
430    /// pending finally blocks up to the enclosing catch and rethrows
431    /// the original value. On success, evaluates to EXPR's value.
432    /// Lowered per spec/HARN_SPEC.md as:
433    ///   { let _r = try { EXPR }
434    ///     guard is_ok(_r) else { throw unwrap_err(_r) }
435    ///     unwrap(_r) }
436    TryStar {
437        operand: Box<SNode>,
438    },
439
440    /// Or-pattern in a `match` arm: `"ping" | "pong" -> body`. One or
441    /// more alternative patterns that share a single arm body. Only
442    /// legal inside a `MatchArm.pattern` slot.
443    OrPattern(Vec<SNode>),
444
445    Block(Vec<SNode>),
446    Closure {
447        params: Vec<TypedParam>,
448        body: Vec<SNode>,
449        /// When true, this closure was written as `fn(params) { body }`.
450        /// The formatter preserves this distinction.
451        fn_syntax: bool,
452    },
453}
454
455/// First-class human-in-the-loop primitive.
456///
457/// Each `HitlKind` is a reserved keyword expression with VM-enforced
458/// semantics: the names cannot be shadowed or rebound by user code,
459/// signatures are produced by the VM, and the audit log is recorded
460/// deterministically by the runtime.
461#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
462pub enum HitlKind {
463    /// `request_approval(action: ..., args: ..., quorum: ..., reviewers: ..., ...)`.
464    RequestApproval,
465    /// `dual_control(n: ..., m: ..., action: <closure>, approvers: ...)`.
466    DualControl,
467    /// `ask_user(prompt: ..., schema: ..., timeout: ..., default: ...)`.
468    AskUser,
469    /// `escalate_to(role: ..., reason: ...)`.
470    EscalateTo,
471}
472
473impl HitlKind {
474    /// Keyword surface form (matches the reserved keyword in the lexer
475    /// and the corresponding async builtin name in the VM).
476    pub fn as_keyword(self) -> &'static str {
477        match self {
478            HitlKind::RequestApproval => "request_approval",
479            HitlKind::DualControl => "dual_control",
480            HitlKind::AskUser => "ask_user",
481            HitlKind::EscalateTo => "escalate_to",
482        }
483    }
484}
485
486/// A single argument in a [`Node::HitlExpr`] call. `name` is `Some` when
487/// the caller used named-arg syntax (e.g. `quorum: 2`); positional
488/// arguments leave it as `None` and rely on the kind's parameter order.
489#[derive(Debug, Clone, PartialEq)]
490pub struct HitlArg {
491    pub name: Option<String>,
492    pub value: SNode,
493    pub span: Span,
494}
495
496/// Parallel execution mode.
497#[derive(Debug, Clone, Copy, PartialEq)]
498pub enum ParallelMode {
499    /// `parallel N { i -> ... }` — run N concurrent tasks.
500    Count,
501    /// `parallel each list { item -> ... }` — map over list concurrently.
502    Each,
503    /// `parallel each list { item -> ... } as stream` — emit as each task completes.
504    EachStream,
505    /// `parallel settle list { item -> ... }` — map with error collection.
506    Settle,
507}
508
509#[derive(Debug, Clone, PartialEq)]
510pub struct MatchArm {
511    pub pattern: SNode,
512    /// Optional guard: `pattern if condition -> { body }`.
513    pub guard: Option<Box<SNode>>,
514    pub body: Vec<SNode>,
515}
516
517#[derive(Debug, Clone, PartialEq)]
518pub struct SelectCase {
519    pub variable: String,
520    pub channel: Box<SNode>,
521    pub body: Vec<SNode>,
522}
523
524#[derive(Debug, Clone, PartialEq)]
525pub struct DictEntry {
526    pub key: SNode,
527    pub value: SNode,
528}
529
530/// An enum variant declaration.
531#[derive(Debug, Clone, PartialEq)]
532pub struct EnumVariant {
533    pub name: String,
534    pub fields: Vec<TypedParam>,
535}
536
537/// A struct field declaration.
538#[derive(Debug, Clone, PartialEq)]
539pub struct StructField {
540    pub name: String,
541    pub type_expr: Option<TypeExpr>,
542    pub optional: bool,
543}
544
545/// An interface method signature.
546#[derive(Debug, Clone, PartialEq)]
547pub struct InterfaceMethod {
548    pub name: String,
549    pub type_params: Vec<TypeParam>,
550    pub params: Vec<TypedParam>,
551    pub return_type: Option<TypeExpr>,
552}
553
554/// A type annotation (optional, for runtime checking).
555#[derive(Debug, Clone, PartialEq)]
556pub enum TypeExpr {
557    /// A named type: int, string, float, bool, nil, list, dict, closure,
558    /// or a user-defined type name.
559    Named(String),
560    /// A union type: `string | nil`, `int | float`.
561    Union(Vec<TypeExpr>),
562    /// An intersection type: `{x: int} & {y: int}`. The value must satisfy
563    /// every component simultaneously. Useful for layered context types
564    /// such as `fn use(ctx: BaseCtx & AuthCtx)`.
565    Intersection(Vec<TypeExpr>),
566    /// A dict shape type: `{name: string, age: int, active?: bool}`.
567    Shape(Vec<ShapeField>),
568    /// A list type: `list<int>`.
569    List(Box<TypeExpr>),
570    /// A dict type with key and value types: `dict<string, int>`.
571    DictType(Box<TypeExpr>, Box<TypeExpr>),
572    /// A lazy iterator type: `iter<int>`. Yields values of the inner type
573    /// via the combinator/sink protocol (`VmValue::Iter` at runtime).
574    Iter(Box<TypeExpr>),
575    /// A synchronous generator type: `Generator<int>`. Produced by a regular
576    /// `fn` body containing `yield`.
577    Generator(Box<TypeExpr>),
578    /// An asynchronous stream type: `Stream<int>`. Produced by `gen fn`.
579    Stream(Box<TypeExpr>),
580    /// A generic type application: `Option<int>`, `Result<string, int>`.
581    Applied { name: String, args: Vec<TypeExpr> },
582    /// A function type: `fn(int, string) -> bool`.
583    FnType {
584        params: Vec<TypeExpr>,
585        return_type: Box<TypeExpr>,
586    },
587    /// The bottom type: the type of expressions that never produce a value
588    /// (return, throw, break, continue).
589    Never,
590    /// A string-literal type: `"pass"`, `"fail"`. Assignable to `string`.
591    /// Used in unions to represent enum-like discriminated values.
592    LitString(String),
593    /// An int-literal type: `0`, `1`, `-1`. Assignable to `int`.
594    LitInt(i64),
595}
596
597/// A field in a dict shape type.
598#[derive(Debug, Clone, PartialEq)]
599pub struct ShapeField {
600    pub name: String,
601    pub type_expr: TypeExpr,
602    pub optional: bool,
603}
604
605/// A binding pattern for destructuring in let/var/for-in.
606#[derive(Debug, Clone, PartialEq)]
607pub enum BindingPattern {
608    /// Simple identifier: `let x = ...`
609    Identifier(String),
610    /// Dict destructuring: `let {name, age} = ...`
611    Dict(Vec<DictPatternField>),
612    /// List destructuring: `let [a, b] = ...`
613    List(Vec<ListPatternElement>),
614    /// Pair destructuring for `for (a, b) in iter { ... }`. The iter must
615    /// yield `VmValue::Pair` values. Not valid in let/var bindings.
616    Pair(String, String),
617}
618
619/// `_` is the discard binding name in `let`/`var`/destructuring positions.
620pub fn is_discard_name(name: &str) -> bool {
621    name == "_"
622}
623
624/// A field in a dict destructuring pattern.
625#[derive(Debug, Clone, PartialEq)]
626pub struct DictPatternField {
627    /// The dict key to extract.
628    pub key: String,
629    /// Renamed binding (if different from key), e.g. `{name: alias}`.
630    pub alias: Option<String>,
631    /// True for `...rest` (rest pattern).
632    pub is_rest: bool,
633    /// Default value if the key is missing (nil), e.g. `{name = "default"}`.
634    pub default_value: Option<Box<SNode>>,
635}
636
637/// An element in a list destructuring pattern.
638#[derive(Debug, Clone, PartialEq)]
639pub struct ListPatternElement {
640    /// The variable name to bind.
641    pub name: String,
642    /// True for `...rest` (rest pattern).
643    pub is_rest: bool,
644    /// Default value if the index is out of bounds (nil), e.g. `[a = 0]`.
645    pub default_value: Option<Box<SNode>>,
646}
647
648/// Declared variance of a generic type parameter.
649///
650/// - `Invariant` (default, no marker): the parameter appears in both
651///   input and output positions, or mutable state. `T<A>` and `T<B>`
652///   are unrelated unless `A == B`.
653/// - `Covariant` (`out T`): the parameter appears only in output
654///   positions (produced, not consumed). `T<Sub>` flows into
655///   `T<Super>`.
656/// - `Contravariant` (`in T`): the parameter appears only in input
657///   positions (consumed, not produced). `T<Super>` flows into
658///   `T<Sub>`.
659#[derive(Debug, Clone, Copy, PartialEq, Eq)]
660pub enum Variance {
661    Invariant,
662    Covariant,
663    Contravariant,
664}
665
666/// A generic type parameter on a function or pipeline declaration.
667#[derive(Debug, Clone, PartialEq)]
668pub struct TypeParam {
669    pub name: String,
670    pub variance: Variance,
671}
672
673impl TypeParam {
674    /// Construct an invariant type parameter (the default for
675    /// unannotated `<T>`).
676    pub fn invariant(name: impl Into<String>) -> Self {
677        Self {
678            name: name.into(),
679            variance: Variance::Invariant,
680        }
681    }
682}
683
684/// A where-clause constraint on a generic type parameter.
685#[derive(Debug, Clone, PartialEq)]
686pub struct WhereClause {
687    pub type_name: String,
688    pub bound: String,
689}
690
691/// A parameter with an optional type annotation and optional default value.
692#[derive(Debug, Clone, PartialEq)]
693pub struct TypedParam {
694    pub name: String,
695    pub type_expr: Option<TypeExpr>,
696    pub default_value: Option<Box<SNode>>,
697    /// If true, this is a rest parameter (`...name`) that collects remaining arguments.
698    pub rest: bool,
699}
700
701impl TypedParam {
702    /// Create an untyped parameter.
703    pub fn untyped(name: impl Into<String>) -> Self {
704        Self {
705            name: name.into(),
706            type_expr: None,
707            default_value: None,
708            rest: false,
709        }
710    }
711
712    /// Create a typed parameter.
713    pub fn typed(name: impl Into<String>, type_expr: TypeExpr) -> Self {
714        Self {
715            name: name.into(),
716            type_expr: Some(type_expr),
717            default_value: None,
718            rest: false,
719        }
720    }
721
722    /// Extract just the names from a list of typed params.
723    pub fn names(params: &[TypedParam]) -> Vec<String> {
724        params.iter().map(|p| p.name.clone()).collect()
725    }
726
727    /// Return the index of the first parameter with a default value, or None.
728    pub fn default_start(params: &[TypedParam]) -> Option<usize> {
729        params.iter().position(|p| p.default_value.is_some())
730    }
731}