Shrink the size of Expr (#12610)

# Description
Continuing from #12568, this PR further reduces the size of `Expr` from
64 to 40 bytes. It also reduces `Expression` from 128 to 96 bytes and
`Type` from 32 to 24 bytes.

This was accomplished by:
- for `Expr` with multiple fields (e.g., `Expr::Thing(A, B, C)`),
merging the fields into new AST struct types and then boxing this struct
(e.g. `Expr::Thing(Box<ABC>)`).
- replacing `Vec<T>` with `Box<[T]>` in multiple places. `Expr`s and
`Expression`s should rarely be mutated, if at all, so this optimization
makes sense.

By reducing the size of these types, I didn't notice a large performance
improvement (at least compared to #12568). But this PR does reduce the
memory usage of nushell. My config is somewhat light so I only noticed a
difference of 1.4MiB (38.9MiB vs 37.5MiB).

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
Ian Manske
2024-04-24 15:46:35 +00:00
committed by GitHub
parent c52884b3c8
commit 9996e4a1f8
195 changed files with 688 additions and 601 deletions

View File

@ -31,8 +31,8 @@ impl Command for BytesAdd {
Type::List(Box::new(Type::Binary)),
Type::List(Box::new(Type::Binary)),
),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.required("data", SyntaxShape::Binary, "The binary to add.")

View File

@ -41,8 +41,8 @@ impl Command for BytesAt {
Type::List(Box::new(Type::Binary)),
Type::List(Box::new(Type::Binary)),
),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.required("range", SyntaxShape::Range, "The range to get bytes.")
.rest(

View File

@ -24,8 +24,8 @@ impl Command for BytesEndsWith {
fn signature(&self) -> Signature {
Signature::build("bytes ends-with")
.input_output_types(vec![(Type::Binary, Type::Bool),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.required("pattern", SyntaxShape::Binary, "The pattern to match.")

View File

@ -28,8 +28,8 @@ impl Command for BytesIndexOf {
(Type::Binary, Type::Any),
// FIXME: this shouldn't be needed, cell paths should work with the two
// above
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.required(

View File

@ -17,8 +17,8 @@ impl Command for BytesLen {
Type::List(Box::new(Type::Binary)),
Type::List(Box::new(Type::Int)),
),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.rest(

View File

@ -26,8 +26,8 @@ impl Command for BytesRemove {
Signature::build("bytes remove")
.input_output_types(vec![
(Type::Binary, Type::Binary),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.required("pattern", SyntaxShape::Binary, "The pattern to find.")
.rest(

View File

@ -26,8 +26,8 @@ impl Command for BytesReplace {
Signature::build("bytes replace")
.input_output_types(vec![
(Type::Binary, Type::Binary),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.required("find", SyntaxShape::Binary, "The pattern to find.")

View File

@ -13,8 +13,8 @@ impl Command for BytesReverse {
Signature::build("bytes reverse")
.input_output_types(vec![
(Type::Binary, Type::Binary),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.rest(

View File

@ -25,8 +25,8 @@ impl Command for BytesStartsWith {
Signature::build("bytes starts-with")
.input_output_types(vec![
(Type::Binary, Type::Bool),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.required("pattern", SyntaxShape::Binary, "The pattern to match.")

View File

@ -19,7 +19,7 @@ impl Command for Histogram {
fn signature(&self) -> Signature {
Signature::build("histogram")
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Table(vec![])),])
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::table()),])
.optional("column-name", SyntaxShape::String, "Column name to calc frequency, no need to provide if input is a list.")
.optional("frequency-column-name", SyntaxShape::String, "Histogram's frequency column, default to be frequency column output.")
.named("percentage-type", SyntaxShape::String, "percentage calculate method, can be 'normalize' or 'relative', in 'normalize', defaults to be 'normalize'", Some('t'))

View File

@ -30,8 +30,8 @@ impl Command for SubCommand {
(Type::Bool, Type::Binary),
(Type::Filesize, Type::Binary),
(Type::Date, Type::Binary),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true) // TODO: supply exhaustive examples
.switch("compact", "output without padding zeros", Some('c'))

View File

@ -16,9 +16,9 @@ impl Command for SubCommand {
(Type::Number, Type::Bool),
(Type::String, Type::Bool),
(Type::Bool, Type::Bool),
(Type::List(Box::new(Type::Any)), Type::Table(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::List(Box::new(Type::Any)), Type::table()),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.rest(

View File

@ -15,10 +15,9 @@ impl Command for IntoCellPath {
(Type::Int, Type::CellPath),
(Type::List(Box::new(Type::Any)), Type::CellPath),
(
Type::List(Box::new(Type::Record(vec![
("value".into(), Type::Any),
("optional".into(), Type::Bool),
]))),
Type::List(Box::new(Type::Record(
[("value".into(), Type::Any), ("optional".into(), Type::Bool)].into(),
))),
Type::CellPath,
),
])

View File

@ -62,8 +62,8 @@ impl Command for SubCommand {
(Type::Int, Type::Date),
(Type::String, Type::Date),
(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Date))),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.named(

View File

@ -17,9 +17,9 @@ impl Command for SubCommand {
(Type::Int, Type::Duration),
(Type::String, Type::Duration),
(Type::Duration, Type::Duration),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
//todo: record<hour,minute,sign> | into duration -> Duration
//(Type::Record(vec![]), Type::Record(vec![])),
//(Type::record(), Type::record()),
])
//.allow_variants_without_examples(true)
.named(
@ -203,9 +203,9 @@ fn string_to_duration(s: &str, span: Span) -> Result<i64, ShellError> {
Type::Duration,
|x| x,
) {
if let Expr::ValueWithUnit(value, unit) = expression.expr {
if let Expr::Int(x) = value.expr {
match unit.item {
if let Expr::ValueWithUnit(value) = expression.expr {
if let Expr::Int(x) = value.expr.expr {
match value.unit.item {
Unit::Nanosecond => return Ok(x),
Unit::Microsecond => return Ok(x * 1000),
Unit::Millisecond => return Ok(x * 1000 * 1000),

View File

@ -18,8 +18,8 @@ impl Command for SubCommand {
(Type::Number, Type::Filesize),
(Type::String, Type::Filesize),
(Type::Filesize, Type::Filesize),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
(
Type::List(Box::new(Type::Int)),
Type::List(Box::new(Type::Filesize)),

View File

@ -16,8 +16,8 @@ impl Command for SubCommand {
(Type::String, Type::Float),
(Type::Bool, Type::Float),
(Type::Float, Type::Float),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Float)),

View File

@ -27,8 +27,8 @@ impl Command for SubCommand {
Type::List(Box::new(Type::String)),
Type::List(Box::new(Type::Glob)),
),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032
.rest(

View File

@ -36,8 +36,8 @@ impl Command for SubCommand {
(Type::Duration, Type::Int),
(Type::Filesize, Type::Int),
(Type::Binary, Type::Int),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
(
Type::List(Box::new(Type::String)),
Type::List(Box::new(Type::Int)),

View File

@ -13,11 +13,11 @@ impl Command for SubCommand {
fn signature(&self) -> Signature {
Signature::build("into record")
.input_output_types(vec![
(Type::Date, Type::Record(vec![])),
(Type::Duration, Type::Record(vec![])),
(Type::List(Box::new(Type::Any)), Type::Record(vec![])),
(Type::Range, Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Date, Type::record()),
(Type::Duration, Type::record()),
(Type::List(Box::new(Type::Any)), Type::record()),
(Type::Range, Type::record()),
(Type::record(), Type::record()),
])
.category(Category::Conversions)
}

View File

@ -40,8 +40,8 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::String)),
),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032
.rest(

View File

@ -15,7 +15,7 @@ impl Command for IntoValue {
fn signature(&self) -> Signature {
Signature::build("into value")
.input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))])
.input_output_types(vec![(Type::table(), Type::table())])
.named(
"columns",
SyntaxShape::Table(vec![]),

View File

@ -24,8 +24,8 @@ impl Command for IntoSqliteDb {
Signature::build("into sqlite")
.category(Category::Conversions)
.input_output_types(vec![
(Type::Table(vec![]), Type::Nothing),
(Type::Record(vec![]), Type::Nothing),
(Type::table(), Type::Nothing),
(Type::record(), Type::Nothing),
])
.allow_variants_without_examples(true)
.required(

View File

@ -11,7 +11,7 @@ impl Command for SubCommand {
fn signature(&self) -> Signature {
Signature::build("date list-timezone")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.category(Category::Date)
}

View File

@ -13,8 +13,8 @@ impl Command for SubCommand {
fn signature(&self) -> Signature {
Signature::build("date to-record")
.input_output_types(vec![
(Type::Date, Type::Record(vec![])),
(Type::String, Type::Record(vec![])),
(Type::Date, Type::record()),
(Type::String, Type::record()),
])
.allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032
.category(Category::Date)

View File

@ -13,8 +13,8 @@ impl Command for SubCommand {
fn signature(&self) -> Signature {
Signature::build("date to-table")
.input_output_types(vec![
(Type::Date, Type::Table(vec![])),
(Type::String, Type::Table(vec![])),
(Type::Date, Type::table()),
(Type::String, Type::table()),
])
.allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032
.category(Category::Date)

View File

@ -16,7 +16,7 @@ impl Command for Ast {
fn signature(&self) -> Signature {
Signature::build("ast")
.input_output_types(vec![(Type::String, Type::Record(vec![]))])
.input_output_types(vec![(Type::String, Type::record())])
.required(
"pipeline",
SyntaxShape::String,

View File

@ -31,7 +31,7 @@ impl Command for DebugInfo {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("debug info")
.input_output_types(vec![(Type::Nothing, Type::Record(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::record())])
.category(Category::Debug)
}

View File

@ -18,7 +18,7 @@ impl Command for Metadata {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("metadata")
.input_output_types(vec![(Type::Any, Type::Record(vec![]))])
.input_output_types(vec![(Type::Any, Type::record())])
.allow_variants_without_examples(true)
.optional(
"expression",

View File

@ -34,7 +34,7 @@ impl Command for DebugProfile {
"How many blocks/closures deep to step into (default 2)",
Some('m'),
)
.input_output_types(vec![(Type::Any, Type::Table(vec![]))])
.input_output_types(vec![(Type::Any, Type::table())])
.category(Category::Debug)
}

View File

@ -20,12 +20,15 @@ impl Command for ViewFiles {
Signature::build("view files")
.input_output_types(vec![(
Type::Nothing,
Type::Table(vec![
("filename".into(), Type::String),
("start".into(), Type::Int),
("end".into(), Type::Int),
("size".into(), Type::Int),
]),
Type::Table(
[
("filename".into(), Type::String),
("start".into(), Type::Int),
("end".into(), Type::Int),
("size".into(), Type::Int),
]
.into(),
),
)])
.category(Category::Debug)
}

View File

@ -15,7 +15,7 @@ impl Command for LoadEnv {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("load-env")
.input_output_types(vec![
(Type::Record(vec![]), Type::Nothing),
(Type::record(), Type::Nothing),
(Type::Nothing, Type::Nothing),
])
.allow_variants_without_examples(true)

View File

@ -33,7 +33,7 @@ impl Command for Du {
fn signature(&self) -> Signature {
Signature::build("du")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true)
.rest(
"path",

View File

@ -45,7 +45,7 @@ impl Command for Ls {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("ls")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
// LsGlobPattern is similar to string, it won't auto-expand
// and we use it to track if the user input is quoted.
.rest("pattern", SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::String]), "The glob pattern to use.")

View File

@ -38,7 +38,7 @@ impl Command for Watch {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("watch")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.required("path", SyntaxShape::Filepath, "The path to watch. Can be a file or directory.")
.required("closure",
SyntaxShape::Closure(Some(vec![SyntaxShape::String, SyntaxShape::String, SyntaxShape::String])),

View File

@ -11,8 +11,8 @@ impl Command for Columns {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Table(vec![]), Type::List(Box::new(Type::String))),
(Type::Record(vec![]), Type::List(Box::new(Type::String))),
(Type::table(), Type::List(Box::new(Type::String))),
(Type::record(), Type::List(Box::new(Type::String))),
])
.category(Category::Filters)
}

View File

@ -13,8 +13,8 @@ impl Command for DropColumn {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.optional(
"columns",

View File

@ -11,7 +11,7 @@ impl Command for Drop {
fn signature(&self) -> Signature {
Signature::build("drop")
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -35,7 +35,7 @@ with 'transpose' first."#
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),
),
(Type::Table(vec![]), Type::List(Box::new(Type::Any))),
(Type::table(), Type::List(Box::new(Type::Any))),
(Type::Any, Type::Any),
])
.required(

View File

@ -18,7 +18,7 @@ impl Command for Enumerate {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("enumerate")
.input_output_types(vec![(Type::Any, Type::Table(vec![]))])
.input_output_types(vec![(Type::Any, Type::table())])
.category(Category::Filters)
}

View File

@ -17,7 +17,7 @@ impl Command for Flatten {
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),
),
(Type::Record(vec![]), Type::Table(vec![])),
(Type::record(), Type::table()),
])
.rest(
"rest",

View File

@ -27,8 +27,8 @@ If multiple cell paths are given, this will produce a list of values."#
Type::List(Box::new(Type::Any)),
Type::Any,
),
(Type::Table(vec![]), Type::Any),
(Type::Record(vec![]), Type::Any),
(Type::table(), Type::Any),
(Type::record(), Type::Any),
])
.required(
"cell_path",

View File

@ -12,11 +12,11 @@ impl Command for Headers {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
// Tables with missing values are List<Any>
Type::List(Box::new(Type::Any)),
Type::Table(vec![]),
Type::table(),
),
])
.category(Category::Filters)

View File

@ -12,8 +12,8 @@ impl Command for Insert {
fn signature(&self) -> Signature {
Signature::build("insert")
.input_output_types(vec![
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::record()),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -12,7 +12,7 @@ impl Command for Items {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![(Type::Record(vec![]), Type::Any)])
.input_output_types(vec![(Type::record(), Type::Any)])
.required(
"closure",
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Any])),

View File

@ -46,7 +46,7 @@ impl Command for Join {
.switch("left", "Left-outer join", Some('l'))
.switch("right", "Right-outer join", Some('r'))
.switch("outer", "Outer join", Some('o'))
.input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))])
.input_output_types(vec![(Type::table(), Type::table())])
.category(Category::Filters)
}

View File

@ -23,8 +23,8 @@ repeating this process with row 1, and so on."#
fn signature(&self) -> nu_protocol::Signature {
Signature::build("merge")
.input_output_types(vec![
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::record()),
(Type::table(), Type::table()),
])
.required(
"value",

View File

@ -21,8 +21,8 @@ impl Command for Move {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("move")
.input_output_types(vec![
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::record()),
(Type::table(), Type::table()),
])
.rest("columns", SyntaxShape::String, "The columns to move.")
.named(

View File

@ -22,7 +22,7 @@ impl Command for ParEach {
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),
),
(Type::Table(vec![]), Type::List(Box::new(Type::Any))),
(Type::table(), Type::List(Box::new(Type::Any))),
(Type::Any, Type::Any),
])
.named(

View File

@ -13,7 +13,7 @@ impl Command for Reduce {
Signature::build("reduce")
.input_output_types(vec![
(Type::List(Box::new(Type::Any)), Type::Any),
(Type::Table(vec![]), Type::Any),
(Type::table(), Type::Any),
(Type::Range, Type::Any),
])
.named(

View File

@ -13,8 +13,8 @@ impl Command for Reject {
fn signature(&self) -> Signature {
Signature::build("reject")
.input_output_types(vec![
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::record()),
(Type::table(), Type::table()),
])
.switch(
"ignore-errors",

View File

@ -13,8 +13,8 @@ impl Command for Rename {
fn signature(&self) -> Signature {
Signature::build("rename")
.input_output_types(vec![
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::record()),
(Type::table(), Type::table()),
])
.named(
"column",

View File

@ -14,8 +14,8 @@ impl Command for Select {
fn signature(&self) -> Signature {
Signature::build("select")
.input_output_types(vec![
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::record()),
(Type::table(), Type::table()),
(Type::List(Box::new(Type::Any)), Type::Any),
])
.switch(

View File

@ -11,7 +11,7 @@ impl Command for Skip {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -12,7 +12,7 @@ impl Command for SkipUntil {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -12,7 +12,7 @@ impl Command for SkipWhile {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -17,7 +17,7 @@ impl Command for Sort {
.input_output_types(vec![(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),
), (Type::Record(vec![]), Type::Record(vec![])),])
), (Type::record(), Type::record()),])
.switch("reverse", "Sort in reverse order", Some('r'))
.switch(
"ignore-case",

View File

@ -15,8 +15,8 @@ impl Command for SortBy {
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),
),
(Type::Record(vec![]), Type::Table(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::table()),
(Type::table(), Type::table()),
])
.rest("columns", SyntaxShape::Any, "The column(s) to sort by.")
.switch("reverse", "Sort in reverse order", Some('r'))

View File

@ -11,7 +11,7 @@ impl Command for SplitBy {
fn signature(&self) -> Signature {
Signature::build("split-by")
.input_output_types(vec![(Type::Record(vec![]), Type::Record(vec![]))])
.input_output_types(vec![(Type::record(), Type::record())])
.optional("splitter", SyntaxShape::Any, "The splitter value to use.")
.category(Category::Filters)
}

View File

@ -11,7 +11,7 @@ impl Command for Take {
fn signature(&self) -> Signature {
Signature::build("take")
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -12,7 +12,7 @@ impl Command for TakeUntil {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -12,7 +12,7 @@ impl Command for TakeWhile {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -20,8 +20,8 @@ impl Command for Transpose {
fn signature(&self) -> Signature {
Signature::build("transpose")
.input_output_types(vec![
(Type::Table(vec![]), Type::Any),
(Type::Record(vec![]), Type::Table(vec![])),
(Type::table(), Type::Any),
(Type::record(), Type::table()),
])
.switch(
"header-row",

View File

@ -12,7 +12,7 @@ impl Command for UniqBy {
fn signature(&self) -> Signature {
Signature::build("uniq-by")
.input_output_types(vec![
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -12,8 +12,8 @@ impl Command for Update {
fn signature(&self) -> Signature {
Signature::build("update")
.input_output_types(vec![
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::record()),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -12,8 +12,8 @@ impl Command for Upsert {
fn signature(&self) -> Signature {
Signature::build("upsert")
.input_output_types(vec![
(Type::Record(vec![]), Type::Record(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::record()),
(Type::table(), Type::table()),
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),

View File

@ -12,8 +12,8 @@ impl Command for Values {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(Type::Record(vec![]), Type::List(Box::new(Type::Any))),
(Type::Table(vec![]), Type::List(Box::new(Type::Any))),
(Type::record(), Type::List(Box::new(Type::Any))),
(Type::table(), Type::List(Box::new(Type::Any))),
])
.category(Category::Filters)
}

View File

@ -26,7 +26,7 @@ not supported."#
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),
),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::table(), Type::table()),
(Type::Range, Type::Any),
])
.required(

View File

@ -15,9 +15,9 @@ impl Command for Wrap {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("wrap")
.input_output_types(vec![
(Type::List(Box::new(Type::Any)), Type::Table(vec![])),
(Type::Range, Type::Table(vec![])),
(Type::Any, Type::Record(vec![])),
(Type::List(Box::new(Type::Any)), Type::table()),
(Type::Range, Type::table()),
(Type::Any, Type::record()),
])
.required("name", SyntaxShape::String, "The name of the column.")
.allow_variants_without_examples(true)

View File

@ -11,7 +11,7 @@ impl Command for FromCsv {
fn signature(&self) -> Signature {
Signature::build("from csv")
.input_output_types(vec![(Type::String, Type::Table(vec![]))])
.input_output_types(vec![(Type::String, Type::table())])
.named(
"separator",
SyntaxShape::String,

View File

@ -14,7 +14,7 @@ impl Command for FromOds {
fn signature(&self) -> Signature {
Signature::build("from ods")
.input_output_types(vec![(Type::String, Type::Table(vec![]))])
.input_output_types(vec![(Type::String, Type::table())])
.allow_variants_without_examples(true)
.named(
"sheets",

View File

@ -13,7 +13,7 @@ impl Command for FromSsv {
fn signature(&self) -> Signature {
Signature::build("from ssv")
.input_output_types(vec![(Type::String, Type::Table(vec![]))])
.input_output_types(vec![(Type::String, Type::table())])
.switch(
"noheaders",
"don't treat the first row as column names",

View File

@ -11,7 +11,7 @@ impl Command for FromToml {
fn signature(&self) -> Signature {
Signature::build("from toml")
.input_output_types(vec![(Type::String, Type::Record(vec![]))])
.input_output_types(vec![(Type::String, Type::record())])
.category(Category::Formats)
}

View File

@ -11,7 +11,7 @@ impl Command for FromTsv {
fn signature(&self) -> Signature {
Signature::build("from tsv")
.input_output_types(vec![(Type::String, Type::Table(vec![]))])
.input_output_types(vec![(Type::String, Type::table())])
.named(
"comment",
SyntaxShape::String,

View File

@ -15,7 +15,7 @@ impl Command for FromXlsx {
fn signature(&self) -> Signature {
Signature::build("from xlsx")
.input_output_types(vec![(Type::Binary, Type::Table(vec![]))])
.input_output_types(vec![(Type::Binary, Type::table())])
.allow_variants_without_examples(true)
.named(
"sheets",

View File

@ -14,7 +14,7 @@ impl Command for FromXml {
fn signature(&self) -> Signature {
Signature::build("from xml")
.input_output_types(vec![(Type::String, Type::Record(vec![]))])
.input_output_types(vec![(Type::String, Type::record())])
.switch("keep-comments", "add comment nodes to result", None)
.switch(
"keep-pi",

View File

@ -13,8 +13,8 @@ impl Command for ToCsv {
fn signature(&self) -> Signature {
Signature::build("to csv")
.input_output_types(vec![
(Type::Record(vec![]), Type::String),
(Type::Table(vec![]), Type::String),
(Type::record(), Type::String),
(Type::table(), Type::String),
])
.named(
"separator",

View File

@ -12,7 +12,7 @@ impl Command for ToToml {
fn signature(&self) -> Signature {
Signature::build("to toml")
.input_output_types(vec![(Type::Record(vec![]), Type::String)])
.input_output_types(vec![(Type::record(), Type::String)])
.category(Category::Formats)
}

View File

@ -13,8 +13,8 @@ impl Command for ToTsv {
fn signature(&self) -> Signature {
Signature::build("to tsv")
.input_output_types(vec![
(Type::Record(vec![]), Type::String),
(Type::Table(vec![]), Type::String),
(Type::record(), Type::String),
(Type::table(), Type::String),
])
.switch(
"noheaders",

View File

@ -18,7 +18,7 @@ impl Command for ToXml {
fn signature(&self) -> Signature {
Signature::build("to xml")
.input_output_types(vec![(Type::Record(vec![]), Type::String)])
.input_output_types(vec![(Type::record(), Type::String)])
.named(
"indent",
SyntaxShape::Int,
@ -300,7 +300,7 @@ impl Job {
if top_level {
return Err(ShellError::CantConvert {
to_type: "XML".into(),
from_type: Type::Record(vec![]).to_string(),
from_type: Type::record().to_string(),
span: entry_span,
help: Some("PIs can not be a root element of document".into()),
});
@ -312,7 +312,7 @@ impl Job {
_ => {
return Err(ShellError::CantConvert {
to_type: "XML".into(),
from_type: Type::Record(vec![]).to_string(),
from_type: Type::record().to_string(),
span: content.span(),
help: Some("PI content expected to be a string".into()),
});
@ -369,7 +369,7 @@ impl Job {
.write_event(Event::Comment(comment_content))
.map_err(|_| ShellError::CantConvert {
to_type: "XML".to_string(),
from_type: Type::Record(vec![]).to_string(),
from_type: Type::record().to_string(),
span: entry_span,
help: Some("Failure writing comment to xml".into()),
})
@ -393,7 +393,7 @@ impl Job {
if !matches!(attrs, Value::Nothing { .. }) {
return Err(ShellError::CantConvert {
to_type: "XML".into(),
from_type: Type::Record(vec![]).to_string(),
from_type: Type::record().to_string(),
span: entry_span,
help: Some("PIs do not have attributes".into()),
});
@ -408,7 +408,7 @@ impl Job {
.write_event(Event::PI(pi_content))
.map_err(|_| ShellError::CantConvert {
to_type: "XML".to_string(),
from_type: Type::Record(vec![]).to_string(),
from_type: Type::record().to_string(),
span: entry_span,
help: Some("Failure writing PI to xml".into()),
})
@ -425,7 +425,7 @@ impl Job {
if tag.starts_with('!') || tag.starts_with('?') {
return Err(ShellError::CantConvert {
to_type: "XML".to_string(),
from_type: Type::Record(vec![]).to_string(),
from_type: Type::record().to_string(),
span: tag_span,
help: Some(format!(
"Incorrect tag name {}, tag name can not start with ! or ?",
@ -448,7 +448,7 @@ impl Job {
.write_event(open_tag_event)
.map_err(|_| ShellError::CantConvert {
to_type: "XML".to_string(),
from_type: Type::Record(vec![]).to_string(),
from_type: Type::record().to_string(),
span: entry_span,
help: Some("Failure writing tag to xml".into()),
})?;
@ -463,7 +463,7 @@ impl Job {
.write_event(close_tag_event)
.map_err(|_| ShellError::CantConvert {
to_type: "XML".to_string(),
from_type: Type::Record(vec![]).to_string(),
from_type: Type::record().to_string(),
span: entry_span,
help: Some("Failure writing tag to xml".into()),
})?;

View File

@ -43,7 +43,7 @@ impl Command for Cal {
"Display the month names instead of integers",
None,
)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true) // TODO: supply exhaustive examples
.category(Category::Generators)
}

View File

@ -50,8 +50,8 @@ where
.category(Category::Hash)
.input_output_types(vec![
(Type::String, Type::Any),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.switch(

View File

@ -29,7 +29,7 @@ impl Command for HelpAliases {
"string to find in alias names and usage",
Some('f'),
)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true)
}

View File

@ -29,7 +29,7 @@ impl Command for HelpCommands {
"string to find in command names, usage, and search terms",
Some('f'),
)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true)
}

View File

@ -15,7 +15,7 @@ impl Command for HelpEscapes {
fn signature(&self) -> Signature {
Signature::build("help escapes")
.category(Category::Core)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true)
}

View File

@ -29,7 +29,7 @@ impl Command for HelpExterns {
"string to find in extern names and usage",
Some('f'),
)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true)
}

View File

@ -35,7 +35,7 @@ are also available in the current scope. Commands/aliases that were imported und
"string to find in module names and usage",
Some('f'),
)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true)
}

View File

@ -15,7 +15,7 @@ impl Command for HelpOperators {
fn signature(&self) -> Signature {
Signature::build("help operators")
.category(Category::Core)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true)
}

View File

@ -23,8 +23,8 @@ impl Command for SubCommand {
(Type::List(Box::new(Type::Number)), Type::Number),
(Type::Number, Type::Number),
(Type::Range, Type::Number),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.category(Category::Math)

View File

@ -20,8 +20,8 @@ impl Command for SubCommand {
(Type::List(Box::new(Type::Filesize)), Type::Filesize),
(Type::List(Box::new(Type::Any)), Type::Any),
(Type::Range, Type::Number),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.category(Category::Math)

View File

@ -17,8 +17,8 @@ impl Command for SubCommand {
(Type::List(Box::new(Type::Duration)), Type::Duration),
(Type::List(Box::new(Type::Filesize)), Type::Filesize),
(Type::Range, Type::Number),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.category(Category::Math)

View File

@ -20,8 +20,8 @@ impl Command for SubCommand {
(Type::List(Box::new(Type::Filesize)), Type::Filesize),
(Type::List(Box::new(Type::Any)), Type::Any),
(Type::Range, Type::Number),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.category(Category::Math)

View File

@ -48,7 +48,7 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Filesize)),
Type::List(Box::new(Type::Filesize)),
),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
])
.allow_variants_without_examples(true)
.category(Category::Math)

View File

@ -17,8 +17,8 @@ impl Command for SubCommand {
.input_output_types(vec![
(Type::List(Box::new(Type::Number)), Type::Number),
(Type::Range, Type::Number),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.category(Category::Math)

View File

@ -14,8 +14,8 @@ impl Command for SubCommand {
Signature::build("math stddev")
.input_output_types(vec![
(Type::List(Box::new(Type::Number)), Type::Number),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
(Type::record(), Type::record()),
])
.switch(
"sample",

View File

@ -19,8 +19,8 @@ impl Command for SubCommand {
(Type::List(Box::new(Type::Duration)), Type::Duration),
(Type::List(Box::new(Type::Filesize)), Type::Filesize),
(Type::Range, Type::Number),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.category(Category::Math)

View File

@ -13,8 +13,8 @@ impl Command for SubCommand {
Signature::build("math variance")
.input_output_types(vec![
(Type::List(Box::new(Type::Number)), Type::Number),
(Type::Table(vec![]), Type::Record(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::record()),
(Type::record(), Type::record()),
])
.switch(
"sample",

View File

@ -14,7 +14,7 @@ impl Command for Panic {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("panic")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
// LsGlobPattern is similar to string, it won't auto-expand
// and we use it to track if the user input is quoted.
.optional("msg", SyntaxShape::String, "The glob pattern to use.")

View File

@ -11,8 +11,8 @@ impl Command for SubCommand {
fn signature(&self) -> Signature {
Signature::build("url build-query")
.input_output_types(vec![
(Type::Record(vec![]), Type::String),
(Type::Table(vec![]), Type::String),
(Type::record(), Type::String),
(Type::table(), Type::String),
])
.category(Category::Network)
}

View File

@ -19,8 +19,8 @@ impl Command for SubCommand {
Type::List(Box::new(Type::String)),
Type::List(Box::new(Type::String)),
),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.rest(

Some files were not shown because too many files have changed in this diff Show More