[Perl/perl5] afe3e6: allow some basic infrastructure to load with -Duse...

2024-01-03 Thread Tony Cook via perl5-changes
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: afe3e67fb0863443a08b1e2f0d9aada21c79a279
  
https://github.com/Perl/perl5/commit/afe3e67fb0863443a08b1e2f0d9aada21c79a279
  Author: Tony Cook 
  Date:   2024-01-04 (Thu, 04 Jan 2024)

  Changed paths:
M TestInit.pm
M regen/embed_lib.pl
M t/test.pl

  Log Message:
  ---
  allow some basic infrastructure to load with -Dusedefaultstrict

The changes to t/test.pl appear to be real bugs.

This allows `make test_harness` to run, but many tests will still
fail under -Dusedefaultstrict

This addresses #21732 but does not fix it.  I'm unsure how
supported that build option is.




[Perl/perl5] 06c1b7: pp_backtick: remove RC_STACK wrapper and use the n...

2024-01-03 Thread Tony Cook via perl5-changes
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 06c1b785f4f2327eaae8427ba0077b1c3675df93
  
https://github.com/Perl/perl5/commit/06c1b785f4f2327eaae8427ba0077b1c3675df93
  Author: Tony Cook 
  Date:   2024-01-04 (Thu, 04 Jan 2024)

  Changed paths:
M pp_sys.c

  Log Message:
  ---
  pp_backtick: remove RC_STACK wrapper and use the new APIs




[Perl/perl5] 04de52: locale.c: Reorder cases in a switch()

2024-01-03 Thread Karl Williamson via perl5-changes
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 04de52e6194b67304326382b470d4d67e23d745d
  
https://github.com/Perl/perl5/commit/04de52e6194b67304326382b470d4d67e23d745d
  Author: Karl Williamson 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M locale.c

  Log Message:
  ---
  locale.c: Reorder cases in a switch()

The CODESET case was kept last because it had by far the largest amount
of code of any of the cases.  But the majority of it has now been
shunted into a separate function.  There are, in contrast,  many LC_TIME
related case statements, and future commits will add significantly to
the amount of code implementing them; therefore they are better placed
last in the switch().


  Commit: 7e388717145102073b9150c433d3af44c55f9275
  
https://github.com/Perl/perl5/commit/7e388717145102073b9150c433d3af44c55f9275
  Author: Karl Williamson 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M locale.c

  Log Message:
  ---
  locale.c: Reorder two more case: statements

This is in preparation for future commits where the new order will make
more sense than the current one.


  Commit: 26d70844c1d44097a570f82ecb7beec39e783153
  
https://github.com/Perl/perl5/commit/26d70844c1d44097a570f82ecb7beec39e783153
  Author: Karl Williamson 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M locale.c

  Log Message:
  ---
  locale.c: Adjust some #if, #else

This removes the need for a FALLTHROUGH comment.


Compare: https://github.com/Perl/perl5/compare/2100da0d758d...26d70844c1d4


[Perl/perl5] 228066: add Concise tests for state var assignment

2024-01-03 Thread iabyn via perl5-changes
  Branch: refs/heads/davem/rc7
  Home:   https://github.com/Perl/perl5
  Commit: 2280665a0c90f669febc20e2dec4ad96f11c9c7e
  
https://github.com/Perl/perl5/commit/2280665a0c90f669febc20e2dec4ad96f11c9c7e
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M ext/B/t/optree_varinit.t

  Log Message:
  ---
  add Concise tests for state var assignment

Add tests for

state $x = 1;
my $y = state $x = 1;

to check what context is allocated to the various ops. At the moment it
is actually wrong in places, and this commit captures that wrongness.
The next commit will fix this, and those diffs to the tests added in this
commit will help make it clear what has changed.


  Commit: 6e575db0bff0341bdab5d7d5cba10f3496a34ea1
  
https://github.com/Perl/perl5/commit/6e575db0bff0341bdab5d7d5cba10f3496a34ea1
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M ext/B/t/optree_varinit.t
M op.c

  Log Message:
  ---
  set context in 'state' expressions

The ops associated with a state variable declaration and initial
assignment weren't getting their context (GIMME) assigned.

Background:

state $x = ...;

gets compiled to something similar to

if (first_time)
$x = ...;
else
$x;

Except that the 'if' is performed by an OP_ONCE logop, which checks and
updates a flag in the pad, and branches to op_next or op_other as
appropriate.

During compilation, the context of the state expression wasn't being
passed on to the children of the OP_ONCE. So the assignment (optimised
into a padsv_store) and the padsv were left as UNKNOWN rather than VOID
or SCALAR as appropriate, as in these two examples:

state $x = 1; # should be void
$y = (state $x = 1);  # should be scalar

This commit fixes that. Note that at the moment it makes no practical
difference, since the padsv/padsv_store ops  don't currently change
their behaviour based on context, but that might change.


  Commit: e498a32a9cb6a9c98e0c44b64241b51abe6435a1
  
https://github.com/Perl/perl5/commit/e498a32a9cb6a9c98e0c44b64241b51abe6435a1
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M gv.c
M op.c
M pp.c

  Log Message:
  ---
  Give OPpTARGET_MY ops real context

Perl has an optimisation whereby an op which returns the RHS of a scalar
assignment to a lexical, and which would normally store its result in
a PADTMP, instead skips the following PADSV and SASSIGN ops and assigns
to the lexical directly, instead of to the PADTMP. For example in

$lex = $a + $b;

the ops (in execution-order) would be changed from

add[t5] sK/2
gvsv[*lex] s
sassign vKS/2
nextstate(main 2 -e:1) v:{

to

add[$lex:1,2] sK/TARGMY,2
nextstate(main 2 -e:1) v:{

However, note that although that the add op is now essentially called in
void context, it is still marked as being in scalar context. This commit
changes it to be be marked as void, i.e.

add[$lex:1,2] vK/TARGMY,2

The main reason for this is to allow for future optimisations in
functions like pp_add(), which will be able to skip pushing the result
onto the stack in in void context. It just so happens that scalar
assignments to lexical vars are typically in void context.

However, since this is a visible change from the perspective of modules
which examine ops or optrees, I'll leave doing any optimisations until
later, in case this commit needs to be reverted.

The main things this commit had to fix up following the change were:
- still call overload methods in scalar context, even though the op is
  now marked as void;
- not issuing "useless use of add in void context" style warnings on
  such ops;
- making pp_push and pp_unshift still set TARG in void context

No matter whether the op's context is marked as scalar or as void, some
parts of perl will misunderstand, and will need to be special-cased
(since the op is really both, depending on your perspective). So this
commit changes the burden of the special-casing code to be in the
non-hot code paths, like during complication or when calling out to an
overload method.


  Commit: eb5569f01a08008eaa45bbc5978da9607199046a
  
https://github.com/Perl/perl5/commit/eb5569f01a08008eaa45bbc5978da9607199046a
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M ext/B/t/optree_varinit.t
M peep.c
M pp_hot.c
M t/perf/opcount.t

  Log Message:
  ---
  OP_PADSV_STORE: only in void context

For the optimisation which converts $lex  = expr into an OP_PADSV_STORE
op, only optimise if the scalar assign is in VOID context.

This allows us to stop pp_padsv_store() from uselessly pushing the
result onto the stack, only to be immediately popped again by the
following nextstate or unstack op. This becomes more important on
PERL_RC_STACK builds, as each push or pop involves manipulating the SV's
reference count.

I'm working on t

[Perl/perl5] 2100da: perlguts: fix ref count in tie() example

2024-01-03 Thread iabyn via perl5-changes
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 2100da0d758d65f39a3c82feb2c8991dbad7a821
  
https://github.com/Perl/perl5/commit/2100da0d758d65f39a3c82feb2c8991dbad7a821
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M pod/perlguts.pod

  Log Message:
  ---
  perlguts: fix ref count in tie() example

Spotted by Marcel Telka.




[Perl/perl5]

2024-01-03 Thread iabyn via perl5-changes
  Branch: refs/heads/davem/rc6
  Home:   https://github.com/Perl/perl5


[Perl/perl5] 6d1334: pp_sort: fix leak in PERL_RC_STACK inline sorting

2024-01-03 Thread iabyn via perl5-changes
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 6d1334c5cd9c5a8150747d54de714d03a6141f38
  
https://github.com/Perl/perl5/commit/6d1334c5cd9c5a8150747d54de714d03a6141f38
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M pp_sort.c

  Log Message:
  ---
  pp_sort: fix leak in PERL_RC_STACK inline sorting

For the optimised case where the src and dst are both the same array,
e.g.
@a = sort { ... } @a;

pp_sort() optimises this. When the code was modified to run under
PERL_RC_STACK, I introduced a leak: all the SVs on the stack after
sorting were then stored in the array and their ref counts incremented,
then the stack pointer was reset *without* decrementing the ref count of
each SV. So every SV in the array by the time pp_sort() returned had a
reference count one too high.

The fix is trivial - don't bump the ref counts when storing them in
the array.


  Commit: 9c4b36214a66fdba52027f881d6619e1f9a0d15a
  
https://github.com/Perl/perl5/commit/9c4b36214a66fdba52027f881d6619e1f9a0d15a
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M op.c
M t/op/svleak.t

  Log Message:
  ---
  fix leak in list const folding under PERL_RC_STACK

S_gen_constant_list() wasn't taking account of the stack possibly being
reference-counted, and so when a list was being constant-folded into an
AV, that AV would leak, such as

while (1) { my $x = eval '\(1..3)'; }


  Commit: 7184c7cb9d22e1849493d74272451de21703d71c
  
https://github.com/Perl/perl5/commit/7184c7cb9d22e1849493d74272451de21703d71c
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M pp_ctl.c
M t/op/svleak.t

  Log Message:
  ---
  fix obscure leak in sort { block } ...

This only leaked on PERL_RC_STACK builds, and only in the relatively
rare code path of a sort block which included a nested scope (such as
a for loop), and which then used 'return' to return the value.


  Commit: 48cac15890ee29400bff9bb1e0c940997f1505b1
  
https://github.com/Perl/perl5/commit/48cac15890ee29400bff9bb1e0c940997f1505b1
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M pp_ctl.c

  Log Message:
  ---
  fix minor leak under use feature 'module_true'

Under PERL_RC_STACK builds, any return value from the module, i.e.
the
1;
or other final statement value, would leak.


  Commit: 6ca3ba049e69f7b8d67362ce4fac7b812a47ee1f
  
https://github.com/Perl/perl5/commit/6ca3ba049e69f7b8d67362ce4fac7b812a47ee1f
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M sv.c

  Log Message:
  ---
  Resurrect immortals before checking for SvTEMP()

sv_clear() and sv_free2() both do, in this order, (simplified):

#ifdef DEBUGGING
if (SvTEMP(sv))
Perl_ck_warner_d(..., Attempt to free temp prematurely",...);
#endif

if (SvIMMORTAL(sv))
SvREFCNT(sv) = SvREFCNT_IMMORTAL

Now, it so happens that under DEBUGGING PERL_RC_STACK builds,

a) immortals such s PL_sv_undef have their refcount set to only 10 to
deliberately trigger the edge case of them being freed more often;

b) PERL_RC_STACK builds increasingly don't bother to increment the
reference counts of immortals when pushing them on the stack - this
saves a bit of time, and just means that once every two billion times on
normal builds the ref count drops to zero and sv_clear() sets it back to
SvREFCNT_IMMORTAL.

The combination of these has suddenly made it much more likely that
an immortal on the stack which has also been mortalised, will be passed
to sv_clear() and thus spuriously output the warning message.

So this commit swaps the order of the checks.

In the SvIMMORTAL() branch, it now also turns off SvTEMP.


  Commit: 7f04cfc05d1d08fcba13a426ea4da76216c707cf
  
https://github.com/Perl/perl5/commit/7f04cfc05d1d08fcba13a426ea4da76216c707cf
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)

  Changed paths:
M embed.fnc
M embed.h
M inline.h
M pod/perlguts.pod
M proto.h

  Log Message:
  ---
  add _IMM variants to the rpp_foo() fns

These new function variants assume that the item being put on the stack
is one of the immortals (PL_sv_undef/yes/no/zero), and so skips
incrementing their reference count. This is for a minor efficiency
saving, rather than being necessary for correct functioning of the code.

This commit also tidies up a few of the related rpp_ functions: in
particular moving asserts out of the PERL_RC_STACK-only code into the
general code: an rpp_foo_NN() function should assert fail on a null SV
regardless of whether perl has been compiled under PERL_RC_STACK or not.


  Commit: b6f2485657db9591ba249dc917047dbd11b373cf
  
https://github.com/Perl/perl5/commit/b6f2485657db9591ba249dc917047dbd11b373cf
  Author: David Mitchell 
  Date:   2024-01-03 (Wed, 03 Jan 2024)