Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A solution to fix hidden references in reference chains
- X-seq: zsh-workers 54224
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: A solution to fix hidden references in reference chains
- Date: Tue, 17 Mar 2026 11:51:23 -0700
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PnXp1EDqNbcwrrgm/x65Vv3JLnm5iQvp9P1KHGvcibs=; fh=RngAOd9wlRc8Glv1v2GOfDUnq2FsyrczungEY8JNfXY=; b=b5+LitA4TrNwIIe1l3MDEHUx8+tY9P3+KsnbHP8xomSMaNLsl3GlTssJ6qN8uJqpY1 Al9+0Jgd443j9CXzzFD7DB3yqWRXlgyVgmeK36T+CEn+VOmY9SW11jGHGdQ5SJJX44oU Yrv6iwGMNJZD/P4o0q7kasbDLkZUZ2h9G8WcuYSv8n12in0557vZ4GrQydwnhx+xSG5Y I9xIW+r25uG6vCbamTFROuVJ32W+Be+yTPXDPv7So0/fGv43ohC2rWYmL/kllxID8WI8 SJnTv/Q2Nkq12bkv5saZo7LDxjyfP5CYtDVfmFeibMF3LKbYzdWdYnr523y2pVJyzlx1 4gjw==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1773773496; cv=none; d=google.com; s=arc-20240605; b=EL9YecxWZS7mqOmWxuwpg9rNMrAKHKux9BWEfp93iI+QBT2ZvgWJ9wwg/zvh9KDgCj vShz78xKzu4a9CPHkvSW0c3Hd6Q/0iRFJJlT6GPP6FgBrCct9ool8jARI+aFnejJB7Zw s4GHpQFGCWag0UkKfK1FLPQHyzXDJhj4tVyzkB6Z0YqBXYYJRT41PykZFEzbxCcpheKv ov8GSoj6NOf8k0huoywutmV0E3160rSJUN3+yaZSrqDpArDvf2Q5849wQiDn+qnzhtf0 adPu8gy96rx5KqDA83E81yiaFJA7C4AWJUFtXHu2gSwjMbFf9w5P4phNJ0sjaR7xzfmB s2Ag==
- Archived-at: <https://zsh.org/workers/54224>
- In-reply-to: <CAGdYchv8AsaH4UQHcqvetAOmiYrS3_0uNKf+yn2kXRP3YLbWzw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchu3rxH9MBanWDLTuWcaUNh+g1suQD1bRmC+Pbcj+QJY1A@mail.gmail.com> <CAGdYchvU3=Zzk8q-V36EEf9WDHd6Y9Mjgg=mkKFVRn0BbGuAcA@mail.gmail.com> <CAGdYchuNP=3pfWYRX7iq3wqTf1tzwuUA+txdpPiKrLAcATMLdg@mail.gmail.com> <CAGdYchsVb+dSmS6uHVqORNkFdcmY3f9qKz_J9CrLJYuMN6sf0A@mail.gmail.com> <CAH+w=7Y7WcHh6VYUakX42cUc2ybHNPp=q5ex91UUL1HGc1YjMw@mail.gmail.com> <CAH+w=7aWyqQ3WFD_QgPThZ1TgsccZj1DfJ9Pf7FS5Pqkc3wD9g@mail.gmail.com> <CAGdYchv8AsaH4UQHcqvetAOmiYrS3_0uNKf+yn2kXRP3YLbWzw@mail.gmail.com>
On Mon, Mar 16, 2026 at 6:23 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>>
>> scoperefs is a C array of LinkList pointers. It will always be as
>> large as the greatest locallevel (deepest nested scope) in which a
>> nameref has pointed to a nested parameter
>
> One issue with a list of lists is that it can become expensive to find the list of params of a given scope. In the example below each call to "rec" needs to insert the "r" of the enclosing scope into the list of the current scope. That's cheap as that would be the list at the head of the list of lists. However, the last call to "rec" needs to insert "ref" into the list of the scope of "inner". That's expensive because it's behind the 100 lists corresponding to the 100 scopes of "rec".
So, speed/space tradeoff. I guess the question would be how often we
need to find a named reference 100 scopes away vs. how often we need
100 scoperefs at all, and whether the never-freed 800 bytes (?) is
worth worrying about.
> Another issue with a list of lists arises in case you only want to store non-null/empty lists. Then you need an additional data structure to tell you to which scope each list of params corresponds to.
Yes, you'd need a structure consisting of a node and a level.
> You can "unset" an enclosing parameter and then redefine/reuse it with "typeset -g".
But you can't change a named reference into something else that way.
Even "unset -n" doesn't remove the nameref-ness of the surrounding
scope parameter.
Aside #1: Should this code in bin_unset have changed along with other
parts of array-initializer removal in workers/53776?
if ((pm->node.flags & PM_NAMEREF) &&
(!(pm = resolve_nameref(pm)) || pm->width)) {
/* warning? */
continue;
}
(That is, pm->width now irrelevant here?)
Aside #2, noting here so I don't have to refresh my memory again:
% typeset -n positional=3
This used to produce
zsh: invalid variable name: 3
but as of workers/54064 this is allowed:
% typeset -p positional
typeset -n positional=3
with an intent to fix later to be a reference to $3 (currently
$positional always returns empty). Now it only happens for "up"
namerefs:
% () { typeset -nu wrong=5 }
(anon): invalid name reference: 5
This is a bit more interesting now that we can't nameref to argv[3].
> The example below shows how the "ref" parameter defined in "scope1" can be added to the list of params to reset of "scope2" AND of "scope3".
Note to self: Run some variants of this example after applying workers/54196
> I should probably add some explicit tests for the following cases:
> - Ref added to multiple scope lists
> - Ref added multiple times to the same scope list
> - Ref added to a scope list is now an integer with base=N
Per above, I think this is actually impossible, at least at present?
> - Ref added to a scope list was unset (btw, the code should probably explicitly skip params with PM_UNSET)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author