Skip to content

Commit

Permalink
Turn a few Vec<T> into Box<[T]> to signal fixed length.
Browse files Browse the repository at this point in the history
  • Loading branch information
01mf02 committed Jan 18, 2024
1 parent 4d9a54a commit ca07652
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions jaq-interpret/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ast>);
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]))
}
}

Expand Down Expand Up @@ -41,12 +41,12 @@ pub(crate) struct Call {
pub id: Id,
pub typ: CallTyp,
pub skip: usize,
pub args: Vec<Bind<Id, Id>>,
pub args: Box<[Bind<Id, Id>]>,
}

impl Owned {
pub(crate) fn new(main: Id, recs: Vec<Ast>) -> Self {
Self(main, recs)
Self(main, recs.into())
}
}

Expand All @@ -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),
Expand Down Expand Up @@ -107,7 +107,7 @@ pub(crate) enum Ast {
Var(usize),
Call(Call),

Native(Native, Vec<Id>),
Native(Native, Box<[Id]>),
}

// we can unfortunately not make a `Box<dyn ... + Clone>`
Expand Down
6 changes: 3 additions & 3 deletions jaq-interpret/src/lir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ fn recurse(typ: CallTyp) -> Filter {
id: RECURSE,
typ,
skip: 0,
args: Vec::new(),
args: Default::default(),
})
}

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])))
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ca07652

Please sign in to comment.