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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
195 changed files with 688 additions and 601 deletions

View file

@ -12,7 +12,7 @@ impl Command for KeybindingsDefault {
fn signature(&self) -> Signature {
Signature::build(self.name())
.category(Category::Platform)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
}
fn usage(&self) -> &str {

View file

@ -14,7 +14,7 @@ impl Command for KeybindingsList {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::table())])
.switch("modifiers", "list of modifiers", Some('m'))
.switch("keycodes", "list of keycodes", Some('k'))
.switch("modes", "list of edit modes", Some('o'))

View file

@ -361,7 +361,7 @@ fn find_matching_block_end_in_expr(
Expr::Nothing => None,
Expr::Garbage => None,
Expr::Table(hdr, rows) => {
Expr::Table(table) => {
if expr_last == global_cursor_offset {
// cursor is at table end
Some(expr_first)
@ -370,11 +370,11 @@ fn find_matching_block_end_in_expr(
Some(expr_last)
} else {
// cursor is inside table
for inner_expr in hdr {
for inner_expr in table.columns.as_ref() {
find_in_expr_or_continue!(inner_expr);
}
for row in rows {
for inner_expr in row {
for row in table.rows.as_ref() {
for inner_expr in row.as_ref() {
find_in_expr_or_continue!(inner_expr);
}
}

View file

@ -24,7 +24,7 @@ impl Command for ToNu {
.switch("tail", "shows tail rows", Some('t'))
.input_output_types(vec![
(Type::Custom("expression".into()), Type::Any),
(Type::Custom("dataframe".into()), Type::Table(vec![])),
(Type::Custom("dataframe".into()), Type::table()),
])
//.input_output_type(Type::Any, Type::Any)
.category(Category::Custom("dataframe".into()))

View file

@ -30,8 +30,8 @@ impl Command for BitsInto {
(Type::Duration, Type::String),
(Type::String, Type::String),
(Type::Bool, 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) // TODO: supply exhaustive examples
.rest(

View file

@ -15,7 +15,7 @@ impl Command for Fmt {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("fmt")
.input_output_types(vec![(Type::Number, Type::Record(vec![]))])
.input_output_types(vec![(Type::Number, Type::record())])
.category(Category::Conversions)
}

View file

@ -16,7 +16,7 @@ impl Command for RollDown {
fn signature(&self) -> Signature {
Signature::build(self.name())
// TODO: It also operates on List
.input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))])
.input_output_types(vec![(Type::table(), Type::table())])
.named("by", SyntaxShape::Int, "Number of rows to roll", Some('b'))
.category(Category::Filters)
}

View file

@ -16,8 +16,8 @@ impl Command for RollLeft {
fn signature(&self) -> Signature {
Signature::build(self.name())
.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(
"by",

View file

@ -16,8 +16,8 @@ impl Command for RollRight {
fn signature(&self) -> Signature {
Signature::build(self.name())
.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(
"by",

View file

@ -16,7 +16,7 @@ impl Command for RollUp {
fn signature(&self) -> Signature {
Signature::build(self.name())
// TODO: It also operates on List
.input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))])
.input_output_types(vec![(Type::table(), Type::table())])
.named("by", SyntaxShape::Int, "Number of rows to roll", Some('b'))
.category(Category::Filters)
}

View file

@ -11,8 +11,8 @@ impl Command for Rotate {
fn signature(&self) -> Signature {
Signature::build("rotate")
.input_output_types(vec![
(Type::Record(vec![]), Type::Table(vec![])),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::record(), Type::table()),
(Type::table(), Type::table()),
])
.switch("ccw", "rotate counter clockwise", None)
.rest(

View file

@ -12,7 +12,7 @@ impl Command for UpdateCells {
fn signature(&self) -> Signature {
Signature::build("update cells")
.input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))])
.input_output_types(vec![(Type::table(), Type::table())])
.required(
"closure",
SyntaxShape::Closure(Some(vec![SyntaxShape::Any])),

View file

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

View file

@ -46,8 +46,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)
.category(Category::Platform)

View file

@ -17,8 +17,8 @@ impl Command for DecodeHex {
Type::List(Box::new(Type::String)),
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)
.rest(

View file

@ -17,8 +17,8 @@ impl Command for EncodeHex {
Type::List(Box::new(Type::Binary)),
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(

View file

@ -13,8 +13,8 @@ impl Command for FormatPattern {
fn signature(&self) -> Signature {
Signature::build("format pattern")
.input_output_types(vec![
(Type::Table(vec![]), Type::List(Box::new(Type::String))),
(Type::Record(vec![]), Type::Any),
(Type::table(), Type::List(Box::new(Type::String))),
(Type::record(), Type::Any),
])
.required(
"pattern",

View file

@ -18,8 +18,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(

View file

@ -14,8 +14,8 @@ impl Command for SubCommand {
Signature::build("str kebab-case")
.input_output_types(vec![
(Type::String, Type::String),
(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::String)),

View file

@ -14,8 +14,8 @@ impl Command for SubCommand {
Signature::build("str pascal-case")
.input_output_types(vec![
(Type::String, Type::String),
(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::String)),

View file

@ -18,8 +18,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(

View file

@ -18,8 +18,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(

View file

@ -18,8 +18,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(

View file

@ -15,7 +15,7 @@ impl Command for LazyMake {
fn signature(&self) -> Signature {
Signature::build("lazy make")
.input_output_types(vec![(Type::Nothing, Type::Record(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::record())])
.required_named(
"columns",
SyntaxShape::List(Box::new(SyntaxShape::String)),

View file

@ -16,7 +16,7 @@ impl Command for Version {
fn signature(&self) -> Signature {
Signature::build("version")
.input_output_types(vec![(Type::Nothing, Type::Record(vec![]))])
.input_output_types(vec![(Type::Nothing, Type::record())])
.allow_variants_without_examples(true)
.category(Category::Core)
}

View file

@ -13,14 +13,17 @@ impl Command for PluginList {
Signature::build("plugin list")
.input_output_type(
Type::Nothing,
Type::Table(vec![
("name".into(), Type::String),
("is_running".into(), Type::Bool),
("pid".into(), Type::Int),
("filename".into(), Type::String),
("shell".into(), Type::String),
("commands".into(), Type::List(Type::String.into())),
]),
Type::Table(
[
("name".into(), Type::String),
("is_running".into(), Type::Bool),
("pid".into(), Type::Int),
("filename".into(), Type::String),
("shell".into(), Type::String),
("commands".into(), Type::List(Type::String.into())),
]
.into(),
),
)
.category(Category::Plugin)
}

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,

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