Skip to content

Commit

Permalink
Remove lazy records (#12682)
Browse files Browse the repository at this point in the history
# Description
Removes lazy records from the language, following from the reasons
outlined in #12622. Namely, this should make semantics more clear and
will eliminate concerns regarding maintainability.

# User-Facing Changes
- Breaking change: `lazy make` is removed.
- Breaking change: `describe --collect-lazyrecords` flag is removed.
- `sys` and `debug info` now return regular records.

# After Submitting
- Update nushell book if necessary.
- Explore new `sys` and `debug info` APIs to prevent them from taking
too long (e.g., subcommands or taking an optional column/cell-path
argument).
  • Loading branch information
IanManske committed May 3, 2024
1 parent ad6dead commit 847646e
Show file tree
Hide file tree
Showing 32 changed files with 142 additions and 876 deletions.
29 changes: 0 additions & 29 deletions crates/nu-cli/src/completions/variable_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,6 @@ fn nested_suggestions(

output
}
Value::LazyRecord { val, .. } => {
// Add all the columns as completion
for column_name in val.column_names() {
output.push(SemanticSuggestion {
suggestion: Suggestion {
value: column_name.to_string(),
description: None,
style: None,
extra: None,
span: current_span,
append_whitespace: false,
},
kind: Some(kind.clone()),
});
}

output
}
Value::List { vals, .. } => {
for column_name in get_columns(vals.as_slice()) {
output.push(SemanticSuggestion {
Expand Down Expand Up @@ -321,17 +303,6 @@ fn recursive_value(val: &Value, sublevels: &[Vec<u8>]) -> Result<Value, Span> {
Err(span)
}
}
Value::LazyRecord { val, .. } => {
for col in val.column_names() {
if col.as_bytes() == *sublevel {
let val = val.get_column_value(col).map_err(|_| span)?;
return recursive_value(&val, next_sublevels);
}
}

// Current sublevel value not found
Err(span)
}
Value::List { vals, .. } => {
for col in get_columns(vals.as_slice()) {
if col.as_bytes() == *sublevel {
Expand Down
75 changes: 8 additions & 67 deletions crates/nu-cmd-lang/src/core_commands/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl Command for Describe {
"show detailed information about the value",
Some('d'),
)
.switch("collect-lazyrecords", "collect lazy records", Some('l'))
.category(Category::Core)
}

Expand All @@ -44,21 +43,7 @@ impl Command for Describe {
let options = Options {
no_collect: call.has_flag(engine_state, stack, "no-collect")?,
detailed: call.has_flag(engine_state, stack, "detailed")?,
collect_lazyrecords: call.has_flag(engine_state, stack, "collect-lazyrecords")?,
};
if options.collect_lazyrecords {
nu_protocol::report_error_new(
engine_state,
&ShellError::GenericError {
error: "Deprecated flag".into(),
msg: "the `--collect-lazyrecords` flag is deprecated, since lazy records will be removed in 0.94.0"
.into(),
span: Some(call.head),
help: None,
inner: vec![],
},
);
}
run(Some(engine_state), call, input, options)
}

Expand All @@ -71,7 +56,6 @@ impl Command for Describe {
let options = Options {
no_collect: call.has_flag_const(working_set, "no-collect")?,
detailed: call.has_flag_const(working_set, "detailed")?,
collect_lazyrecords: call.has_flag_const(working_set, "collect-lazyrecords")?,
};
run(None, call, input, options)
}
Expand All @@ -89,13 +73,11 @@ impl Command for Describe {
"{shell:'true', uwu:true, features: {bugs:false, multiplatform:true, speed: 10}, fib: [1 1 2 3 5 8], on_save: {|x| print $'Saving ($x)'}, first_commit: 2019-05-10, my_duration: (4min + 20sec)} | describe -d",
result: Some(Value::test_record(record!(
"type" => Value::test_string("record"),
"lazy" => Value::test_bool(false),
"columns" => Value::test_record(record!(
"shell" => Value::test_string("string"),
"uwu" => Value::test_string("bool"),
"features" => Value::test_record(record!(
"type" => Value::test_string("record"),
"lazy" => Value::test_bool(false),
"columns" => Value::test_record(record!(
"bugs" => Value::test_string("bool"),
"multiplatform" => Value::test_string("bool"),
Expand Down Expand Up @@ -168,7 +150,6 @@ impl Command for Describe {
struct Options {
no_collect: bool,
detailed: bool,
collect_lazyrecords: bool,
}

fn run(
Expand Down Expand Up @@ -243,7 +224,7 @@ fn run(
if options.no_collect {
Value::string("any", head)
} else {
describe_value(input.into_value(head), head, engine_state, options)?
describe_value(input.into_value(head), head, engine_state, )
}
},
"metadata" => metadata_to_value(metadata, head),
Expand All @@ -264,7 +245,7 @@ fn run(
if !options.detailed {
Value::string(value.get_type().to_string(), head)
} else {
describe_value(value, head, engine_state, options)?
describe_value(value, head, engine_state)
}
}
};
Expand All @@ -288,9 +269,8 @@ fn describe_value(
value: Value,
head: nu_protocol::Span,
engine_state: Option<&EngineState>,
options: Options,
) -> Result<Value, ShellError> {
Ok(match value {
) -> Value {
match value {
Value::Custom { val, .. } => Value::record(
record!(
"type" => Value::string("custom", head),
Expand Down Expand Up @@ -320,14 +300,12 @@ fn describe_value(
std::mem::take(v),
head,
engine_state,
options,
)?);
));
}

Value::record(
record!(
"type" => Value::string("record", head),
"lazy" => Value::bool(false, head),
"columns" => Value::record(val, head),
),
head,
Expand All @@ -338,11 +316,9 @@ fn describe_value(
"type" => Value::string("list", head),
"length" => Value::int(vals.len() as i64, head),
"values" => Value::list(vals.into_iter().map(|v|
Ok(compact_primitive_description(
describe_value(v, head, engine_state, options)?
))
compact_primitive_description(describe_value(v, head, engine_state))
)
.collect::<Result<Vec<Value>, ShellError>>()?, head),
.collect(), head),
),
head,
),
Expand Down Expand Up @@ -394,42 +370,7 @@ fn describe_value(
),
head,
),
Value::LazyRecord { val, .. } => {
let mut record = Record::new();

record.push("type", Value::string("record", head));
record.push("lazy", Value::bool(true, head));

if options.collect_lazyrecords {
let collected = val.collect()?;
if let Value::Record { val, .. } =
describe_value(collected, head, engine_state, options)?
{
let mut val = Record::clone(&val);

for (_k, v) in val.iter_mut() {
*v = compact_primitive_description(describe_value(
std::mem::take(v),
head,
engine_state,
options,
)?);
}

record.push("length", Value::int(val.len() as i64, head));
record.push("columns", Value::record(val, head));
} else {
let cols = val.column_names();
record.push("length", Value::int(cols.len() as i64, head));
}
} else {
let cols = val.column_names();
record.push("length", Value::int(cols.len() as i64, head));
}

Value::record(record, head)
}
})
}
}

fn metadata_to_value(metadata: Option<Box<PipelineMetadata>>, head: nu_protocol::Span) -> Value {
Expand Down
179 changes: 0 additions & 179 deletions crates/nu-cmd-lang/src/core_commands/lazy_make.rs

This file was deleted.

0 comments on commit 847646e

Please sign in to comment.