mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 11:47:04 +08:00
Revert "Reduce size of Block to 32 bytes"
This doesn't pull its weight. Block size is not a particularly big
problem,
and this both complicates the code a bit and would arbitrarily cause issues
if a fish script exceeded 65k lines.
This reverts commit edd6533a14
.
This commit is contained in:
parent
ac40807309
commit
94644e88fb
|
@ -35,7 +35,6 @@ use libc::c_int;
|
|||
use printf::sprintf;
|
||||
use std::cell::{Ref, RefCell, RefMut};
|
||||
use std::ffi::{CStr, OsStr};
|
||||
use std::num::NonZeroU16;
|
||||
use std::os::fd::{AsRawFd, OwnedFd, RawFd};
|
||||
use std::os::unix::prelude::OsStrExt;
|
||||
use std::rc::{Rc, Weak};
|
||||
|
@ -76,13 +75,8 @@ pub struct Block {
|
|||
/// Name of the file that created this block
|
||||
pub src_filename: Option<Arc<WString>>,
|
||||
|
||||
/// Line number where this block was created, starting from 1.
|
||||
///
|
||||
/// We count lines from 1, so we can use niche optimization to avoid increasing the size when
|
||||
/// this is wrapped in an `Option`.
|
||||
///
|
||||
/// This will saturate at the 65,535th line of a single fish script. I think that's ok!
|
||||
pub src_lineno: Option<NonZeroU16>,
|
||||
/// Line number where this block was created.
|
||||
pub src_lineno: Option<usize>,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
|
@ -131,7 +125,7 @@ impl Block {
|
|||
.to_owned();
|
||||
|
||||
if let Some(src_lineno) = self.src_lineno {
|
||||
result.push_utfstr(&sprintf!(" (line %d)", src_lineno.get()));
|
||||
result.push_utfstr(&sprintf!(" (line %d)", src_lineno));
|
||||
}
|
||||
if let Some(src_filename) = &self.src_filename {
|
||||
result.push_utfstr(&sprintf!(" (file %ls)", src_filename));
|
||||
|
@ -827,10 +821,7 @@ impl Parser {
|
|||
|
||||
/// Pushes a new block. Returns a pointer to the block, stored in the parser.
|
||||
pub fn push_block(&self, mut block: Block) -> BlockId {
|
||||
// It's extremely unrealistic to assume a fish script will have more than 65,535 lines.
|
||||
block.src_lineno = self
|
||||
.get_lineno()
|
||||
.and_then(|num| NonZeroU16::new(num.try_into().unwrap_or(u16::MAX)));
|
||||
block.src_lineno = self.get_lineno();
|
||||
block.src_filename = self.current_filename();
|
||||
if block.typ() != BlockType::top {
|
||||
let new_scope = block.typ() == BlockType::function_call { shadows: true };
|
||||
|
@ -1212,7 +1203,7 @@ fn append_block_description_to_stack_trace(parser: &Parser, b: &Block, trace: &m
|
|||
if let Some(file) = b.src_filename.as_ref() {
|
||||
trace.push_utfstr(&sprintf!(
|
||||
"\tcalled on line %d of file %ls\n",
|
||||
b.src_lineno.map(|n| n.get()).unwrap_or(0),
|
||||
b.src_lineno.unwrap_or(0),
|
||||
user_presentable_path(file, parser.vars())
|
||||
));
|
||||
} else if parser.libdata().pods.within_fish_init {
|
||||
|
|
Loading…
Reference in New Issue
Block a user