From ca07652e7f168b7abdb6823ead83a2e93f4916b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=C3=A4rber?= <01mf02@gmail.com> Date: Thu, 18 Jan 2024 12:35:19 +0100 Subject: [PATCH] Turn a few `Vec` into `Box<[T]>` to signal fixed length. This was inspired by . --- jaq-interpret/src/filter.rs | 12 ++++++------ jaq-interpret/src/lir.rs | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/jaq-interpret/src/filter.rs b/jaq-interpret/src/filter.rs index c1ac8f7ba..b05775999 100644 --- a/jaq-interpret/src/filter.rs +++ b/jaq-interpret/src/filter.rs @@ -9,11 +9,11 @@ use jaq_syn::{MathOp, OrdOp}; /// Function from a value to a stream of value results. #[derive(Debug, Clone)] -pub struct Owned(Id, Vec); +pub struct Owned(Id, Box<[Ast]>); impl Default for Owned { fn default() -> Self { - Self(Id(0), Vec::from([Ast::Id])) + Self(Id(0), Box::new([Ast::Id])) } } @@ -41,12 +41,12 @@ pub(crate) struct Call { pub id: Id, pub typ: CallTyp, pub skip: usize, - pub args: Vec>, + pub args: Box<[Bind]>, } impl Owned { pub(crate) fn new(main: Id, recs: Vec) -> Self { - Self(main, recs) + Self(main, recs.into()) } } @@ -61,7 +61,7 @@ pub(crate) enum Ast { Float(f64), Str(String), Array(Id), - Object(Vec<(Id, Id)>), + Object(Box<[(Id, Id)]>), Try(Id, Id), Neg(Id), @@ -107,7 +107,7 @@ pub(crate) enum Ast { Var(usize), Call(Call), - Native(Native, Vec), + Native(Native, Box<[Id]>), } // we can unfortunately not make a `Box` diff --git a/jaq-interpret/src/lir.rs b/jaq-interpret/src/lir.rs index 60ed9f312..d4ee88afd 100644 --- a/jaq-interpret/src/lir.rs +++ b/jaq-interpret/src/lir.rs @@ -59,7 +59,7 @@ fn recurse(typ: CallTyp) -> Filter { id: RECURSE, typ, skip: 0, - args: Vec::new(), + args: Default::default(), }) } @@ -67,7 +67,7 @@ impl Ctx { /// `{}[]` returns zero values. fn empty(&mut self) -> Filter { // `{}` - let obj = Filter::Object(Vec::new()); + let obj = Filter::Object(Default::default()); // `[]` let path = (path::Part::Range(None, None), path::Opt::Essential); Filter::Path(self.id_of_ast(obj), Path(Vec::from([path]))) @@ -156,7 +156,7 @@ impl Ctx { match call { mir::Call::Arg(a) if args.is_empty() => Filter::Var(a), mir::Call::Arg(_) => panic!("higher-order argument encountered"), - mir::Call::Native(n) => Filter::Native(n, args), + mir::Call::Native(n) => Filter::Native(n, args.into()), mir::Call::Def { id, skip, tail } => { let callable = self.get_callable(id); let args = callable.sig.args.iter().zip(args);