develooper Front page | perl.perl5.changes | Postings from September 2021

[Perl/perl5] 0a639b: Tests for existing for loop optrees.

From:
Nicholas Clark via perl5-changes
Date:
September 16, 2021 15:03
Subject:
[Perl/perl5] 0a639b: Tests for existing for loop optrees.
Message ID:
Perl/perl5/push/refs/heads/smoke-me/nicholas/pp_iter/390937-e091bd@github.com
  Branch: refs/heads/smoke-me/nicholas/pp_iter
  Home:   https://github.com/Perl/perl5
  Commit: 0a639b7ecea42cc118271f8fc5cb30d5de0d33b1
      https://github.com/Perl/perl5/commit/0a639b7ecea42cc118271f8fc5cb30d5de0d33b1
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M MANIFEST
    A ext/B/t/optree_for.t

  Log Message:
  -----------
  Tests for existing for loop optrees.


  Commit: 703d63644a69cfd94b97262a32e00d50beff256f
      https://github.com/Perl/perl5/commit/703d63644a69cfd94b97262a32e00d50beff256f
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  Re-indent the case statement in pp_iter, ready for the next commit.

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.


  Commit: 32e5b070cff72cbc3de87224a71ac02a75f19f92
      https://github.com/Perl/perl5/commit/32e5b070cff72cbc3de87224a71ac02a75f19f92
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  Iterate for loops $n-at-a-time in PP_ITER.

This commit provides the runtime changes needed to iterate for loops over
two or more variables.


  Commit: f34fc6e228f13083004db940f90a4503c2f76d61
      https://github.com/Perl/perl5/commit/f34fc6e228f13083004db940f90a4503c2f76d61
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M op.c
    M pod/perldiag.pod

  Log Message:
  -----------
  Generate the optree for n-at-a-time for loops.

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.


  Commit: 7581ddc1ab7e3fb10f0125d29035505a53644a7a
      https://github.com/Perl/perl5/commit/7581ddc1ab7e3fb10f0125d29035505a53644a7a
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M perly.act
    M perly.h
    M perly.tab
    M perly.y
    M toke.c

  Log Message:
  -----------
  Implement n-at-a-time for loops.

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).


  Commit: dfb1028a405c3ac7b8e6ec9183bbc7018c99a714
      https://github.com/Perl/perl5/commit/dfb1028a405c3ac7b8e6ec9183bbc7018c99a714
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M MANIFEST
    M pod/perlsyn.pod
    A t/op/for-many.t

  Log Message:
  -----------
  Regression tests and documentation for n-at-a-time for.


  Commit: 96b1f0827f04d6ac9988b7befb2718f44a7b065b
      https://github.com/Perl/perl5/commit/96b1f0827f04d6ac9988b7befb2718f44a7b065b
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M ext/B/B/Concise.pm
    M ext/B/t/optree_for.t

  Log Message:
  -----------
  B::Concise now handles n-at-a-time for.


  Commit: e34be51867599eaf8f6cb2e116c49b80e5045759
      https://github.com/Perl/perl5/commit/e34be51867599eaf8f6cb2e116c49b80e5045759
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M lib/B/Deparse.pm
    M lib/B/Deparse.t

  Log Message:
  -----------
  B::Deparse now handles n-at-a-time for.


  Commit: 9470467875368772f5ab9813eee9f4d114e58bda
      https://github.com/Perl/perl5/commit/9470467875368772f5ab9813eee9f4d114e58bda
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  Move reading CxTYPE(cx) out of the loop, to be clear that it doesn't 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.


  Commit: d4bf06ce40facef8cbd88cd3d2daff58380eba9f
      https://github.com/Perl/perl5/commit/d4bf06ce40facef8cbd88cd3d2daff58380eba9f
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M lib/warnings.pm
    M regen/warnings.pl
    M warnings.h

  Log Message:
  -----------
  Add a new warning experimental::for_list.


  Commit: 399bab0d9cdb868455da0530a65af7aca033f3eb
      https://github.com/Perl/perl5/commit/399bab0d9cdb868455da0530a65af7aca033f3eb
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M lib/B/Deparse.t
    M pod/perldiag.pod
    M pod/perlsyn.pod
    M t/op/for-many.t
    M toke.c

  Log Message:
  -----------
  n-at-a-time for loops now warn by default (as 'experimental::for_list').


  Commit: 8d0e7db68a5bbe26a4272a49a03c143071500457
      https://github.com/Perl/perl5/commit/8d0e7db68a5bbe26a4272a49a03c143071500457
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M pod/perldelta.pod

  Log Message:
  -----------
  perldelta for n-at-a-time for loops.


  Commit: f0bb56888db0e8439e691603d9f059db7f036dbf
      https://github.com/Perl/perl5/commit/f0bb56888db0e8439e691603d9f059db7f036dbf
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M pp_hot.c

  Log Message:
  -----------
  Note why this if block in pp_iter is empty


  Commit: a4fa3f95d8214685a80ac003603770bc7d037aa2
      https://github.com/Perl/perl5/commit/a4fa3f95d8214685a80ac003603770bc7d037aa2
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M t/op/for-many.t

  Log Message:
  -----------
  Test next, continue and redo with n-at-a-time for loops


  Commit: e091bd9753c25e84cbd20be75022003dca01aea2
      https://github.com/Perl/perl5/commit/e091bd9753c25e84cbd20be75022003dca01aea2
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-09-16 (Thu, 16 Sep 2021)

  Changed paths:
    M perly.act
    M perly.h
    M perly.tab
    M perly.y
    M t/op/for-many.t

  Log Message:
  -----------
  for my ($foo,,, $bar) { ... } should parse as ($foo, $bar)

Multiple commas between the lexicals in the list shouldn't change the
parsing.


Compare: https://github.com/Perl/perl5/compare/390937f47969...e091bd9753c2



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About