Multiple-alias syntax for foreach#18925
Conversation
|
On 6/23/21 4:57 AM, Nicholas Clark wrote:
Implement RFC 0001 - /Multiple-alias syntax for foreach/
<https://github.com/Perl/RFCs/blob/master/rfc/rfc0001.md>
[That link is correct but currently GitHub is reporting it as a 404.
Start at https://github.com/Perl/RFCs/ <https://github.com/Perl/RFCs/>
and you'll get links that are 404s. I'll edit the text to remove this
note once GitHub no longer has its knickers in a twist]
No, the listed link is one character shorter than the link which you get
by navigating through the above.
Listed: https://github.com/Perl/RFCs/blob/master/rfc/rfc0001.md
Confirmed: https://github.com/Perl/RFCs/blob/master/rfcs/rfc0001.md
I'm not sure how you generated this email, so I don't know where in p.r.
18925 to go to fix. Can you investigate?
I believe that the RFC process now is "this change is subject to normal
code review and merging" by *someone competent who is not me*.
This is curious. When I go to #18925
I see that I have been requested as a code reviewer. Should I have
received an email making that request? AFAICT I did not receive one.
Note that the p.r. has merge conflicts.
Thank you very much.
Jim Keenan
|
You aren't currently assigned as a reviewer, those are just github's suggestions for who to assign as a reviewer (which it decides itself based on various factors AIUI). |
5fcc04d to
5e9f535
Compare
|
I don't know what triggered GitHub to send you an e-mail about this, because I don't think that it was anything I explicitly asked for. It has suggested you are a potential reviewer, but I didn't take it up on its suggestions. Worse - I goofed, and fixed things, but it seems that it didn't e-mail you an updated version of the comment, so you're replying to things that I already figured out, fixed and edited away. Hateful software.
Yes, I figured that the problem was between keyboard and chair about 4 days ago, and fixed it in Perl/PPCs@6f2c56a Specifically, I was getting confused between links that I had generated in the
(as above) - I didn't know who should be a code reviewer, but wasn't confident that its suggestions were great. Really, it's the grammar changes that I'm least confident about, and would like someone to say "this doesn't obviously add subtle bugs". The conflict is due to other more recent changes to B::Concise in the lines around the |
5e9f535 to
0c36ae8
Compare
wolfsage
left a comment
There was a problem hiding this comment.
The C level changes are a bit beyond me - would be nice to have someone like Dave or Tony review them (if they haven't already).
There are a number of whitespace oddities introduced that make the code hard to comprehend that would be nice if they were fixed up.
Have we done benchmarking to see how this impacts normal for loops?
Also worth doing if you haven't:
- -DDEBUGGING build
- Threaded build
- Look for any new warnings generated by gcc (and maybe clang)
- Maybe a new test.valgrind run but that can be painful
Overall I like the feature though I worry about the 'extra undefs if the list isn't quite the right size'.
I ... don't have a solution I like though so I guess I'm just complaining here.
Good stuff!
|
@nwc10 The last I heard, this was waiting on code review. What's the current status of this branch? What prevents us from merging it? Implementation problems? Lack of tests? Lack of docs? Lack of say-so? |
|
Oh if it's ready-pending-review I should definitely give a look-over. |
| { | ||
| switch (CxTYPE(cx)) { | ||
|
|
||
| case CXt_LOOP_LAZYSV: /* string increment */ |
There was a problem hiding this comment.
This commit doesn't do what it says it does. It adds the block around the switch (which isn't purely a whitespace change), and doesn't actually indent the block.
Later commits add lines indented further, so the HEAD includes:
STRLEN maxlen = 0;
const char *max = SvPV_const(end, maxlen);
bool pad_it = FALSE;
if (DO_UTF8(end) && IN_UNI_8_BIT)
I suspect a git rebase --ignore-whitespace bit you here.
There was a problem hiding this comment.
It did. Fixed in the rebase, and thanks for correctly diagnosing the problem.
0c36ae8 to
390937f
Compare
|
@wolfsage - GitHub still thinks "changes requested" but I can't work out what it's nagging about. I think I've addressed all the specific comments you made (and everyone else's), although I only marked as "resolved" those that I was confident you would agree with. |
|
Pushing a rebase to avoid the conflicts. |
390937f to
e091bd9
Compare
wolfsage
left a comment
There was a problem hiding this comment.
One or two minor doc fixups but seems good to me (I only skimmed the C changes this time)
918c0ee to
36df89b
Compare
|
I think that the "Sanity" test has failed because I pushed a commit onto the branch as-is, and as it's based on blead from before the recent release, "changed modules with unchanged VERSION" vs "the latest tag" differs (and so fails) So a rebase is coming soon, to see if I can get to "All tests successful". It's not easy being green. |
36df89b to
87815a2
Compare
| $ary = $self->deparse($ary, 1); | ||
| } | ||
| if (null $var) { | ||
| my $iter_targ = $kid->first->first->targ; |
There was a problem hiding this comment.
I'm not sure how pedantic we want to be here, but the indentation looks off in Github because Deparse.pm is indented with tabs while the code added here is indented with spaces.
There was a problem hiding this comment.
I'm not sure either.
Usually I try to match the indenting (etc) style of the surrounding code, and I missed that this file had tabs.
Well, ...:
$ git show 8b7aa8e4305788f70f89b55541ae664e8ecb17e0 lib/B/Deparse.pm | perl -pe 's/\t/......../g'
commit 8b7aa8e4305788f70f89b55541ae664e8ecb17e0
Author: Nicholas Clark <nick@ccl4.org>
Date: Mon Apr 26 11:23:33 2021 +0000
B::Deparse now handles n-at-a-time for.
diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm
index 2d33039a80..12f6a63670 100644
--- a/lib/B/Deparse.pm
+++ b/lib/B/Deparse.pm
@@ -52,7 +52,7 @@ use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
MDEREF_SHIFT
);
-$VERSION = '1.58';
+$VERSION = '1.59';
use strict;
our $AUTOLOAD;
use warnings ();
@@ -3954,7 +3954,18 @@ sub loop_common {
........} else {
........ $ary = $self->deparse($ary, 1);
........}
-........if (null $var) {
+ my $iter_targ = $kid->first->first->targ;
+ if ($iter_targ) {
+ # for my ($foo, $bar) () stores the count (less 1) in the targ of
+ # the ITER op.
+ my @vars;
+ my $targ = $enter->targ;
+ while ($iter_targ-- >= 0) {
+ push @vars, $self->padname_sv($targ)->PVX;
+ ++$targ;
+ }
+ $var = 'my (' . join(', ', @vars) . ')';
+ } elsif (null $var) {
$var = $self->pp_padsv($enter, 1, 1);
........} elsif ($var->name eq "rv2gv") {
........ $var = $self->pp_rv2sv($var, 1);
it does and it doesn't. The line above my new block had a tab, but the first line after it did not.
The whole file is a inconsistent. There are parts of it with tabs, and other parts (I guess newer, but I didn't see a good way to check this) that have spaces.
So having discovered that, there doesn't seem to be any "right" answer, so I'm tempted to say that this part can be spaces.
There was a problem hiding this comment.
I thought we converted lines we touched to spaces, from perlhack:
The codebase is a mixture of tabs and spaces for indentation, and we
are moving to spaces only. Converting lines you're patching from 8-wide
tabs to spaces will help this migration.
Add braces and indent a block that will become a `for` loop in the next commit. With the exception of these and merging 3 opening braces onto the `if` or `else` on the previous lines, this commit is purely a whitespace change.
This commit provides the runtime changes needed to iterate for loops over two or more variables.
Perl_newFOROP can now also take an OP_LIST corresponding to two or more lexicals to iterate over n-at-a-time, where those lexicals are all declared in the for statement, and occupy consecutive pad slots.
For example, this now works:
for my ($key, $value) (%hash) { ... }
Only for scalars declared with my as a list in the for loop statement.
As many as you want (unless you want more than 4294967296).
…change. Move some other variable declarations into a tighter scope, and initialise variables at the point of declaration where possible. With the recent changes, the function consists of a 4-way switch inside a loop, where each iteration of the loop will take the same case in the switch. This implies a branch taken on each iteration of the loop, which is less efficient than the alternative structure of taking the branch once and then looping. However, the way the code is structured (particularly how two of the cases share code, by jumping sideways), means that rewriting it to "switch first" structure would not be clearer (and likely would also be hard to get right). Hence it seems better to let a compiler optimiser choose what is best. However, it might not realise that CxTYPE(cx) won't be changed, even as a side effect of any function called by this code. Hence hoist it into a constant variable to make this unequivocal.
Multiple commas between the lexicals in the list shouldn't change the parsing.
87815a2 to
4eb6385
Compare
Implement RFC 0001 - Multiple-alias syntax for foreach
I believe that the RFC process now is "this change is subject to normal code review and merging" by someone competent who is not me.
I guess we ask does it implement what the RFCs specified? in addition to the usual does the code have bugs or other defects? and on balance, does merging this give a net improvement?