Refactor: introduce 2 associated functions to PipelineData (#16233)

# Description
As title: this pr is try to introduce 2 functions to `PipelineData`:
1. PipelineData::list_stream --> create a PipelineData::ListStream
2. PipelineData::byte_stream -> create a PipelineData::ByteStream
And use these functions everywhere.

### Reason behind this change
I tried to implement `pipefail` feature, but this would required to
change `PipelineData` from enum to struct. So use these functions can
reduce diff if I finally change to struct. [Discord message
here](https://discord.com/channels/601130461678272522/615962413203718156/1396999539000479784)
is my plan.

# User-Facing Changes
NaN

# Tests + Formatting
NaN

# After Submitting
NaN
This commit is contained in:
Wind
2025-08-02 09:30:30 +08:00
committed by GitHub
parent ee5b5bd39e
commit eb8d2d3206
126 changed files with 299 additions and 304 deletions

View File

@ -37,7 +37,7 @@ fn eval_fn(debug: bool) -> EvalBlockWithEarlyReturnFn {
/// let mut closure = ClosureEval::new(engine_state, stack, closure);
/// let iter = Vec::<Value>::new()
/// .into_iter()
/// .map(move |value| closure.add_arg(value).run_with_input(PipelineData::Empty));
/// .map(move |value| closure.add_arg(value).run_with_input(PipelineData::empty()));
/// ```
///
/// Many closures follow a simple, common scheme where the pipeline input and the first argument are the same value.
@ -175,7 +175,7 @@ impl ClosureEval {
/// # let value = unimplemented!();
/// let result = ClosureEvalOnce::new(engine_state, stack, closure)
/// .add_arg(value)
/// .run_with_input(PipelineData::Empty);
/// .run_with_input(PipelineData::empty());
/// ```
///
/// Many closures follow a simple, common scheme where the pipeline input and the first argument are the same value.

View File

@ -412,7 +412,7 @@ fn get_command_documentation(
))],
parser_info: HashMap::new(),
},
PipelineData::Value(Value::list(vals, span), None),
PipelineData::value(Value::list(vals, span), None),
) {
if let Ok((str, ..)) = result.collect_string_strict(span) {
let _ = writeln!(long_desc, "\n{help_section_name}Input/output types{RESET}:");
@ -487,7 +487,7 @@ fn get_command_documentation(
engine_state,
stack,
&(&table_call).into(),
PipelineData::Value(result.clone(), None),
PipelineData::value(result.clone(), None),
)
.ok()
});
@ -532,7 +532,7 @@ fn update_ansi_from_config(
arguments: vec![argument],
parser_info: HashMap::new(),
},
PipelineData::Empty,
PipelineData::empty(),
) {
if let Ok((str, ..)) = result.collect_string_strict(span) {
*ansi_code = str;

View File

@ -294,7 +294,7 @@ pub fn eval_block_with_early_return<D: DebugContext>(
input: PipelineData,
) -> Result<PipelineData, ShellError> {
match eval_block::<D>(engine_state, stack, block, input) {
Err(ShellError::Return { span: _, value }) => Ok(PipelineData::Value(*value, None)),
Err(ShellError::Return { span: _, value }) => Ok(PipelineData::value(*value, None)),
x => x,
}
}

View File

@ -48,7 +48,7 @@ pub fn eval_ir_block<D: DebugContext>(
// the heap allocation here by reusing buffers - our allocator is fast enough
let mut registers = Vec::with_capacity(ir_block.register_count as usize);
for _ in 0..ir_block.register_count {
registers.push(PipelineData::Empty);
registers.push(PipelineData::empty());
}
// Initialize file storage.
@ -133,15 +133,15 @@ impl<'a> EvalContext<'a> {
// log::trace!("<- {reg_id}");
std::mem::replace(
&mut self.registers[reg_id.get() as usize],
PipelineData::Empty,
PipelineData::empty(),
)
}
/// Clone data from a register. Must be collected first.
fn clone_reg(&mut self, reg_id: RegId, error_span: Span) -> Result<PipelineData, ShellError> {
match &self.registers[reg_id.get() as usize] {
PipelineData::Empty => Ok(PipelineData::Empty),
PipelineData::Value(val, meta) => Ok(PipelineData::Value(val.clone(), meta.clone())),
PipelineData::Empty => Ok(PipelineData::empty()),
PipelineData::Value(val, meta) => Ok(PipelineData::value(val.clone(), meta.clone())),
_ => Err(ShellError::IrEvalError {
msg: "Must collect to value before using instruction that clones from a register"
.into(),
@ -269,7 +269,7 @@ fn prepare_error_handler(
);
} else {
// Set the register to empty
ctx.put_reg(reg_id, PipelineData::Empty);
ctx.put_reg(reg_id, PipelineData::empty());
}
}
}
@ -838,7 +838,7 @@ fn load_literal(
span: Span,
) -> Result<InstructionResult, ShellError> {
let value = literal_value(ctx, lit, span)?;
ctx.put_reg(dst, PipelineData::Value(value, None));
ctx.put_reg(dst, PipelineData::value(value, None));
Ok(InstructionResult::Continue)
}
@ -993,7 +993,7 @@ fn binary_op(
}
};
ctx.put_reg(lhs_dst, PipelineData::Value(result, None));
ctx.put_reg(lhs_dst, PipelineData::value(result, None));
Ok(InstructionResult::Continue)
}
@ -1466,7 +1466,7 @@ fn collect(data: PipelineData, fallback_span: Span) -> Result<PipelineData, Shel
other => other,
};
let value = data.into_value(span)?;
Ok(PipelineData::Value(value, metadata))
Ok(PipelineData::value(value, metadata))
}
/// Helper for drain behavior.
@ -1584,7 +1584,7 @@ fn eval_iterate(
ctx.put_reg(stream, data); // put the stream back so it can be iterated on again
Ok(InstructionResult::Continue)
} else {
ctx.put_reg(dst, PipelineData::Empty);
ctx.put_reg(dst, PipelineData::empty());
Ok(InstructionResult::Branch(end_index))
}
} else {
@ -1594,7 +1594,7 @@ fn eval_iterate(
let span = data.span().unwrap_or(Span::unknown());
ctx.put_reg(
stream,
PipelineData::ListStream(
PipelineData::list_stream(
ListStream::new(data.into_iter(), span, Signals::EMPTY),
metadata,
),