pub struct SubshellSnapshot {Show 15 fields
pub paramtab: HashMap<String, Param>,
pub paramtab_hashed_storage: HashMap<String, IndexMap<String, String>>,
pub positional_params: Vec<String>,
pub env_vars: HashMap<String, String>,
pub cwd: Option<PathBuf>,
pub umask: u32,
pub traps: HashMap<String, String>,
pub opts: HashMap<String, bool>,
pub aliases: Vec<(String, String)>,
pub shfuncs: HashMap<String, Box<shfunc>>,
pub functions_compiled: HashMap<String, Chunk>,
pub function_source: HashMap<String, String>,
pub modules: HashMap<String, i32>,
pub thingytab: HashMap<String, Thingy>,
pub keymapnamtab: HashMap<String, KeymapName>,
}Expand description
Snapshot of subshell-isolated state. Captured at ( entry, restored at
) exit. zsh subshell semantics: assignments inside (…) don’t leak to
the outer scope — and that includes export. zsh forks a child for the
subshell so the child’s env::set_var dies with the child; without a fork
(zshrs runs subshells in-process for perf), we snapshot+restore the OS
env table around the subshell. Otherwise (export y=v) would leak y
to the parent shell, breaking every script that uses a subshell to
scope an env override.
Snapshot of mutable executor state across a subshell
boundary.
Port of the entersubsh() save/restore Src/exec.c does at
line 1084 — captures everything that must be replaced when a
(...) group fires.
Fields§
§paramtab: HashMap<String, Param>Snapshot of paramtab (the C-canonical parameter store) at
subshell entry. Step 1 of the unification mirrors writes to
paramtab, so subshell-scoped assignments now show up there
too — without this snapshot, restoring only variables /
arrays / assoc_arrays leaks the subshell’s writes to the
parent via paramtab (e.g. x=outer; (x=inner); echo $x returned
inner because paramsubst reads through paramtab).
paramtab_hashed_storage: HashMap<String, IndexMap<String, String>>paramtab_hashed_storage field.
positional_params: Vec<String>positional_params field.
env_vars: HashMap<String, String>env_vars field.
cwd: Option<PathBuf>Process working directory at subshell entry. cd inside the
subshell shouldn’t leak to the parent; we restore on End.
umask: u32File-creation mask at subshell entry. zsh forks for (...) so
umask set inside dies with the child; we run subshells in
process so we must restore the mask on End. Otherwise
umask 022; (umask 077); umask shows 077 in the parent.
traps: HashMap<String, String>Parent’s traps at subshell entry. zsh’s (trap "echo X" EXIT; true) runs the trap when the subshell exits — BEFORE the parent
continues. Without this snapshot, the trap inherited from parent
would fire, OR a trap set inside the subshell would leak to the
parent’s process exit. Restored on subshell_end after the
subshell’s own EXIT trap (if any) has fired. Stores a snapshot
of crate::ported::builtin::traps_table() (canonical).
opts: HashMap<String, bool>Parent’s shell options at subshell entry. (set -e) /
(setopt extendedglob) mustn’t leak; zsh forks the subshell
so child options die with the child. We run in-process, so we
must restore the option store on subshell_end.
aliases: Vec<(String, String)>Parent’s alias entries at subshell entry. zsh forks for
(...) so (alias x=y) inside a subshell dies with the
child and doesn’t leak to the parent. zshrs runs subshells
in-process, so we must restore the alias table on
subshell_end. Bug #209 in docs/BUGS.md. Stored as a flat
Vec<(name, text)> snapshot — the underlying alias_table holds
an IndexMap<String, alias> but alias carries hashnode
metadata we don’t need to round-trip; only name + text are
observable via alias NAME lookup.
shfuncs: HashMap<String, Box<shfunc>>Parent’s shell-function table at subshell entry. C zsh’s
entersubsh (Src/exec.c) forks before running the
subshell body so (f() { ... }) defining a function dies
with the child and never leaks to the parent. zshrs runs
subshells in-process, so we must clone shfunctab on entry
and restore on exit. Bug #208 in docs/BUGS.md. Stored as
the full HashMap<String, Box<shfunc>> clone — shfunc is
Clone and the table snapshot is bounded by the user’s
declared function set.
functions_compiled: HashMap<String, Chunk>Parent’s compiled-function chunks at subshell entry. Companion
to shfuncs above — ShellExecutor.functions_compiled is the
runtime dispatch table that Op::CallFunction reads through;
without restoring it, a subshell (g() { override; }) leaves
the override bytecode chunk in place so the parent’s
g call still runs the override after subshell_end
restored shfunctab. Bug #208 in docs/BUGS.md.
function_source: HashMap<String, String>Parent’s function source map at subshell entry. Companion to
functions_compiled so typeset -f / whence show the
parent’s source after subshell exit, not the subshell’s
overridden body. Bug #208 in docs/BUGS.md.
modules: HashMap<String, i32>Parent’s modulestab modules map at subshell entry. zsh forks
for (...) so a (zmodload zsh/X) inside the subshell sets
MOD_INIT_B on the child’s modulestab; when the child exits the
flag dies with it and the parent’s modulestab is untouched.
zshrs runs subshells in-process, so a subshell zmodload
would otherwise flip the parent’s ${modules[zsh/X]} from
unset to “loaded”. Snapshot here and restore on subshell_end.
Bug #210 in docs/BUGS.md. Stored as (name → flags)
since module struct doesn’t derive Clone (LinkList/
Linkedmod) — and the only thing zmodload mutates that
affects introspection is the flags bitmask (MOD_INIT_B
for loaded, MOD_UNLOAD for unloaded).
thingytab: HashMap<String, Thingy>Parent’s THINGYTAB (ZLE widget registry) at subshell entry.
zsh forks for (...) so zle -N w f / zle -D w inside the
subshell flip widget bindings only in the child; when the
child exits the parent’s widget table is untouched. zshrs runs
subshells in-process so a subshell’s zle -D w would
otherwise unbind the parent’s widget. Bug #453 in docs/BUGS.md.
keymapnamtab: HashMap<String, KeymapName>Parent’s KEYMAPNAMTAB (named keymap registry) at subshell
entry. Same fork-copy semantics as THINGYTAB — a subshell’s
bindkey -N km / bindkey -D km mutates only the child’s
keymap registry in C zsh. Bug #454 in docs/BUGS.md.
Auto Trait Implementations§
impl Freeze for SubshellSnapshot
impl RefUnwindSafe for SubshellSnapshot
impl Send for SubshellSnapshot
impl Sync for SubshellSnapshot
impl Unpin for SubshellSnapshot
impl UnsafeUnpin for SubshellSnapshot
impl UnwindSafe for SubshellSnapshot
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more