Remove Signature.vectorizes_over_list entirely (#9777)

# Description
With the current typechecking logic this property has no effect.
It was only used in the example testing, and provided some indication of
this vectorizing property.
With #9742 all commands that previously declared it have explicit list
signatures. If we want to get it back in the future we can reconstruct
it from the signature.

Simplifies the example testing a bit.

# User-Facing Changes
Causes a breaking change for plugins that previously declared it. While
this causes a compile fail, this was already broken by our more
stringent type checking.
This will be a good reminder for plugin authors to update their
signature as well to reflect the more stringent type checking.
This commit is contained in:
Stefan Holderbach 2023-07-26 23:34:43 +02:00 committed by GitHub
parent d9230a76f3
commit b2e191f836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 14 additions and 125 deletions

View File

@ -43,7 +43,6 @@ mod test_examples {
&mut make_engine_state(cmd.clone_box()),
&signature.input_output_types,
signature.operates_on_cell_paths(),
signature.vectorizes_over_list,
),
);
check_example_evaluates_to_expected_output(&example, cwd.as_path(), &mut engine_state);

View File

@ -22,7 +22,6 @@ impl Command for BitsAnd {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.required(
"target",
SyntaxShape::Int,

View File

@ -23,7 +23,6 @@ impl Command for BitsNot {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.switch(
"signed",

View File

@ -22,7 +22,6 @@ impl Command for BitsOr {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.required(
"target",
SyntaxShape::Int,

View File

@ -25,7 +25,6 @@ impl Command for BitsRol {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.required("bits", SyntaxShape::Int, "number of bits to rotate left")
.switch(
"signed",

View File

@ -25,7 +25,6 @@ impl Command for BitsRor {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.required("bits", SyntaxShape::Int, "number of bits to rotate right")
.switch(
"signed",

View File

@ -25,7 +25,6 @@ impl Command for BitsShl {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.required("bits", SyntaxShape::Int, "number of bits to shift left")
.switch(
"signed",

View File

@ -25,7 +25,6 @@ impl Command for BitsShr {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.required("bits", SyntaxShape::Int, "number of bits to shift right")
.switch(
"signed",

View File

@ -22,7 +22,6 @@ impl Command for BitsXor {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.required(
"target",
SyntaxShape::Int,

View File

@ -39,7 +39,6 @@ impl Command for BytesAdd {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.required("data", SyntaxShape::Binary, "the binary to add")
.named(

View File

@ -46,7 +46,6 @@ impl Command for BytesAt {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.required("range", SyntaxShape::Range, "the range to get bytes")
.rest(
"rest",

View File

@ -26,7 +26,6 @@ impl Command for BytesLen {
(Type::Record(vec![]), Type::Record(vec![])),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.rest(
"rest",
SyntaxShape::CellPath,

View File

@ -21,7 +21,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -21,7 +21,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -21,7 +21,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Float)),
),
])
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Float)),
),
])
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Float)),
),
])
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -53,7 +53,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.category(Category::Platform)
}

View File

@ -39,7 +39,6 @@ impl Command for SubCommand {
SyntaxShape::CellPath,
"for a data structure input, add links to all strings at the given cell paths",
)
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.category(Category::Platform)
}

View File

@ -25,7 +25,6 @@ impl Command for DecodeHex {
(Type::Record(vec![]), Type::Record(vec![])),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.rest(
"rest",
SyntaxShape::CellPath,

View File

@ -25,7 +25,6 @@ impl Command for EncodeHex {
(Type::Record(vec![]), Type::Record(vec![])),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.rest(
"rest",
SyntaxShape::CellPath,

View File

@ -12,7 +12,6 @@ pub fn check_example_input_and_output_types_match_command_signature(
engine_state: &mut Box<EngineState>,
signature_input_output_types: &Vec<(Type, Type)>,
signature_operates_on_cell_paths: bool,
signature_vectorizes_over_list: bool,
) -> HashSet<(Type, Type)> {
let mut witnessed_type_transformations = HashSet::<(Type, Type)>::new();
@ -37,40 +36,6 @@ pub fn check_example_input_and_output_types_match_command_signature(
}
});
// The example type checks as vectorization over an input list if both:
// 1. The command is declared to vectorize over list input.
// 2. There exists an entry t -> u in the type map such that the
// example_input_type is a subtype of list<t> and the
// example_output_type is a subtype of list<u>.
let example_matches_signature_via_vectorization_over_list =
signature_vectorizes_over_list
&& match &example_input_type {
Type::List(ex_in_type) => {
match signature_input_output_types.iter().find_map(
|(sig_in_type, sig_out_type)| {
if ex_in_type.is_subtype(sig_in_type) {
Some((sig_in_type, sig_out_type))
} else {
None
}
},
) {
Some((sig_in_type, sig_out_type)) => match &example_output_type {
Type::List(ex_out_type)
if ex_out_type.is_subtype(sig_out_type) =>
{
witnessed_type_transformations
.insert((sig_in_type.clone(), sig_out_type.clone()));
true
}
_ => false,
},
None => false,
}
}
_ => false,
};
// The example type checks as a cell path operation if both:
// 1. The command is declared to operate on cell paths.
// 2. The example_input_type is list or record or table, and the example
@ -80,20 +45,20 @@ pub fn check_example_input_and_output_types_match_command_signature(
// TODO: This is too permissive; it should make use of the signature.input_output_types at least.
&& example_output_type.to_shape() == example_input_type.to_shape();
if !(example_matches_signature
|| example_matches_signature_via_vectorization_over_list
|| example_matches_signature_via_cell_path_operation)
{
if !(example_matches_signature || example_matches_signature_via_cell_path_operation) {
panic!(
"The example `{}` demonstrates a transformation of type {:?} -> {:?}. \
However, this does not match the declared signature: {:?}.{} \
For this command, `vectorizes_over_list` is {} and `operates_on_cell_paths()` is {}.",
For this command `operates_on_cell_paths()` is {}.",
example.example,
example_input_type,
example_output_type,
signature_input_output_types,
if signature_input_output_types.is_empty() { " (Did you forget to declare the input and output types for the command?)" } else { "" },
signature_vectorizes_over_list,
if signature_input_output_types.is_empty() {
" (Did you forget to declare the input and output types for the command?)"
} else {
""
},
signature_operates_on_cell_paths
);
};

View File

@ -43,7 +43,6 @@ mod test_examples {
&mut make_engine_state(cmd.clone_box()),
&signature.input_output_types,
signature.operates_on_cell_paths(),
signature.vectorizes_over_list,
),
);
check_example_evaluates_to_expected_output(&example, cwd.as_path(), &mut engine_state);

View File

@ -54,7 +54,6 @@ impl Command for Fill {
// General case for heterogeneous lists
(Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::String))),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.named(
"width",

View File

@ -46,7 +46,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.rest(
"rest",
SyntaxShape::CellPath,

View File

@ -70,7 +70,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Int)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.named("radix", SyntaxShape::Number, "radix of integer", Some('r'))
.switch("little-endian", "use little-endian byte decoding", None)

View File

@ -46,7 +46,6 @@ mod test_examples {
&mut make_engine_state(cmd.clone_box()),
&signature.input_output_types,
signature.operates_on_cell_paths(),
signature.vectorizes_over_list,
),
);
check_example_evaluates_to_expected_output(&example, cwd.as_path(), &mut engine_state);

View File

@ -19,7 +19,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Number)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.category(Category::Math)
}

View File

@ -19,7 +19,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Number)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.category(Category::Math)
}

View File

@ -19,7 +19,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Number)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.category(Category::Math)
}

View File

@ -29,7 +29,6 @@ impl Command for SubCommand {
),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.category(Category::Math)
}

View File

@ -22,7 +22,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Number)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.named(
"precision",

View File

@ -19,7 +19,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::Number)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.category(Category::Math)
}

View File

@ -24,7 +24,6 @@ impl Command for SubCommand {
(Type::Record(vec![]), Type::Record(vec![])),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.switch(
"all",
"encode all non-alphanumeric chars including `/`, `.`, `:`",

View File

@ -29,7 +29,6 @@ impl Command for DecodeBase64 {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.named(
"character-set",

View File

@ -35,7 +35,6 @@ impl Command for EncodeBase64 {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.named(
"character-set",

View File

@ -20,7 +20,6 @@ impl Command for SubCommand {
(Type::String, Type::List(Box::new(Type::String))),
(Type::List(Box::new(Type::String)), Type::Table(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.required(
"separator",

View File

@ -26,7 +26,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -24,7 +24,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -24,7 +24,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -26,7 +26,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::String)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -26,7 +26,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::String)),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -25,7 +25,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -25,7 +25,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -26,7 +26,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -23,7 +23,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -36,7 +36,6 @@ impl Command for SubCommand {
(Type::Record(vec![]), Type::Record(vec![])),
(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool)))
])
.vectorizes_over_list(true)
.required("string", SyntaxShape::String, "the substring to find")
.rest(
"rest",

View File

@ -35,7 +35,6 @@ impl Command for SubCommand {
(Type::Record(vec![]), Type::Record(vec![])),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.required("string", SyntaxShape::String, "the string to match")
.rest(
"rest",

View File

@ -29,7 +29,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::List(Box::new(Type::String)))),
),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.category(Category::Strings)
}

View File

@ -43,7 +43,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true) // TODO: no test coverage
.allow_variants_without_examples(true)
.required("string", SyntaxShape::String, "the string to find in the input")
.switch(

View File

@ -36,7 +36,6 @@ impl Command for SubCommand {
(Type::Record(vec![]), Type::Record(vec![])),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.switch(
"grapheme-clusters",
"count length using grapheme clusters (all visible chars have length 1)",

View File

@ -44,7 +44,6 @@ impl Command for SubCommand {
Type::List(Box::new(Type::String)),
),
])
.vectorizes_over_list(true)
.required("find", SyntaxShape::String, "the pattern to find")
.required("replace", SyntaxShape::String, "the replacement string")
.rest(

View File

@ -26,7 +26,6 @@ impl Command for SubCommand {
(Type::Record(vec![]), Type::Record(vec![])),
])
.allow_variants_without_examples(true)
.vectorizes_over_list(true)
.rest(
"rest",
SyntaxShape::CellPath,

View File

@ -36,7 +36,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.required("string", SyntaxShape::String, "the string to match")
.rest(

View File

@ -48,7 +48,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.switch(
"grapheme-clusters",

View File

@ -44,7 +44,6 @@ impl Command for SubCommand {
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.vectorizes_over_list(true)
.allow_variants_without_examples(true)
.rest(
"rest",

View File

@ -143,11 +143,6 @@ impl PluginSignature {
self
}
pub fn vectorizes_over_list(mut self, vectorizes_over_list: bool) -> PluginSignature {
self.sig = self.sig.vectorizes_over_list(vectorizes_over_list);
self
}
/// Set the input-output type signature variants of the command
pub fn input_output_types(mut self, input_output_types: Vec<(Type, Type)>) -> PluginSignature {
self.sig = self.sig.input_output_types(input_output_types);

View File

@ -112,7 +112,6 @@ pub struct Signature {
pub required_positional: Vec<PositionalArg>,
pub optional_positional: Vec<PositionalArg>,
pub rest_positional: Option<PositionalArg>,
pub vectorizes_over_list: bool,
pub named: Vec<Flag>,
pub input_output_types: Vec<(Type, Type)>,
pub allow_variants_without_examples: bool,
@ -212,7 +211,6 @@ impl Signature {
required_positional: vec![],
optional_positional: vec![],
rest_positional: None,
vectorizes_over_list: false,
input_output_types: vec![],
allow_variants_without_examples: false,
named: vec![],
@ -464,11 +462,6 @@ impl Signature {
self
}
pub fn vectorizes_over_list(mut self, vectorizes_over_list: bool) -> Signature {
self.vectorizes_over_list = vectorizes_over_list;
self
}
/// Set the input-output type signature variants of the command
pub fn input_output_types(mut self, input_output_types: Vec<(Type, Type)>) -> Signature {
self.input_output_types = input_output_types;