This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
6 years agoregen/op_private: remove sassign special-casing
David Mitchell [Tue, 8 Aug 2017 11:19:53 +0000 (12:19 +0100)]
regen/op_private: remove sassign special-casing

Since v5.25.5-46-g1257c08, sassign has been correctly listed in
regen/opcodes as a binary op ('2') rather than as a base op, so there's no
need to special-case it in regen/op_private any more.

This commit makes no functional changes, because since
v5.25.5-46-g1257c08, $args2{sassign} was redundantly getting set to a true
value twice, which was harmless. Now it only gets set once.

6 years agofix parameter name in doc
Zefram [Tue, 8 Aug 2017 10:44:22 +0000 (11:44 +0100)]
fix parameter name in doc

The documentation for wrap_op_checker() had an incorrect parameter name.
This was part of the original version of this documentation in commit
e8570548af49b057631f1011e4b19c8c4a1342dd.

6 years agoRevert "Perl_sv_vcatpvfn_flags: skip IN_LC(LC_NUMERIC)"
David Mitchell [Tue, 8 Aug 2017 08:53:13 +0000 (09:53 +0100)]
Revert "Perl_sv_vcatpvfn_flags: skip IN_LC(LC_NUMERIC)"

This reverts commit c10a72e1914795f6399890aafae13734552645cd.

I thought that if PL_numeric_radix_sv is true, then IN_LC(LC_NUMERIC) must
be true, so no need to test for both. So I replaced the expensive
IN_LC(LC_NUMERIC) test with an assert.

But in http://nntp.perl.org/group/perl.perl5.porters/245455, Karl points
out that  the assert is triggering on HP-UX.

So there's something wrong with my logic something.

So revert.

6 years ago(perl #131646) make the test less fragile
Tony Cook [Tue, 8 Aug 2017 04:45:29 +0000 (14:45 +1000)]
(perl #131646) make the test less fragile

The original pattern "UXp>" with the $_ that causes the failure, 5,
so we end up packing exp(5) or 148.... with U packs:

 - U (148), producing C2 94, with the UTF8 flag set
 - X - back up a byte,
 - p> - write the address of PL_sv_no's PV in big-ending

The final p> will typically overwrite the 94 with a zero on 64-bit
systems, but with the smaller address space of 32-bit systems that
high-byte is more likely to be a valid continuation byte, causing
the comparison to fail.

Instead just pack a zero byte.

6 years agolib/locale.t: TODO some netbsd defective locales
Karl Williamson [Mon, 17 Jul 2017 21:40:42 +0000 (15:40 -0600)]
lib/locale.t: TODO some netbsd defective locales

This is part of [perl #131735]

The ISO 8859-2 locales on netbsd 7.1 tend to have the defect of thinking
an NBSP is a graphic character.  This commit tells lib/locale.t to TODO
these failures, so that they don't fail our smokes.

These are defects in the locale furnished by the vendor, and not a Perl
bug.

6 years agolib/locale.t: Add comments
Karl Williamson [Mon, 7 Aug 2017 16:36:51 +0000 (10:36 -0600)]
lib/locale.t: Add comments

This adds some general comments about the portions of the file that test
locales against what the POSIX standard specifies.

6 years agolib/locale.t: Canonicalize $^O into lowercase
Karl Williamson [Mon, 7 Aug 2017 15:57:25 +0000 (09:57 -0600)]
lib/locale.t: Canonicalize $^O into lowercase

This allows the name to be checked for without needing to worry about
case.  Some patterns used /i, but other things used 'eq'.

6 years agofix index(...) == -1 type optimisations
David Mitchell [Mon, 7 Aug 2017 15:58:11 +0000 (16:58 +0100)]
fix index(...) == -1 type optimisations

RT #131851

It was incorrectly optimising some permutations of comparison op and 0/-1
which shouldn't have been, such as

    0 < index(...);

6 years agoutf8_to_uvchr() EBCDIC fix
Karl Williamson [Sun, 6 Aug 2017 03:47:08 +0000 (21:47 -0600)]
utf8_to_uvchr() EBCDIC fix

This fixes a warning message for EBCDIC.  The native character set is
different than Unicode, and needs special handling.  I earlier tried to
save an #ifdef, but the resulting warning was hard to test right, and
that helped convince me that it would be confusing to anyone trying to
make sense of the message.  So, in goes the #ifdef.

6 years agot/perf/opcount.t typo
David Mitchell [Sat, 5 Aug 2017 18:40:27 +0000 (19:40 +0100)]
t/perf/opcount.t typo

fix typo from my recent commit. Spotted by Jarkko.

6 years agoConsider magic %ENV as tied in hv_pushkv.
Craig A. Berry [Sat, 5 Aug 2017 13:00:32 +0000 (08:00 -0500)]
Consider magic %ENV as tied in hv_pushkv.

For the DYNAMIC_ENV_FETCH case, we don't know the number of keys
until the first iteration triggers a call to prime_env_iter(), so
piggyback on the tied magic case, which already handles extending
the stack for each iteration rather than all at once beforehand.

6 years agoextend index(...) == -1 optimisation
David Mitchell [Sat, 5 Aug 2017 11:12:42 +0000 (12:12 +0100)]
extend index(...) == -1 optimisation

Recently I made it so that in expression like index(...) == -1, the
const and eq ops are optimised away and a BOOL flag is set on the index
op.

This commit expands this to various permutations of relational ops too,
such as

    index(...) >=  0
    index(...) <   0
    index(...) <= -1

6 years agot/op/index.t: automate a block of tests
David Mitchell [Sat, 5 Aug 2017 07:28:22 +0000 (08:28 +0100)]
t/op/index.t: automate a block of tests

A block of tests I added recently tests that (index(...) == -1) style
optimisations don't break things.

Each test was hard-coded. Instead, use some nested loops and eval
to test all the combinations.

This commit does just the same tests as before, but it will allow us to
easily add more tests without lots of duplication.

6 years agomerge Perl_ck_cmp() and Perl_ck_eq()
David Mitchell [Fri, 4 Aug 2017 15:40:15 +0000 (16:40 +0100)]
merge Perl_ck_cmp() and Perl_ck_eq()

I added ck_eq() recently; it's used for the EQ and NE ops, while ck_cmp()
is used for LT, GT, LE, GE.

This commit eliminates the ck_eq() function and makes ck_cmp() handle
EQ/NE too.

This will will make it easier to extend the index() == -1 optimisation
to handle index() >= 0 etc too.

At the moment there should be no functional differences.

6 years agoset SVs_PADTMP flag on PL_sv_zero
David Mitchell [Fri, 4 Aug 2017 14:17:44 +0000 (15:17 +0100)]
set SVs_PADTMP flag on PL_sv_zero

Where an op in scalar but not boolean context returns &PL_sv_zero as a
more efficient way of doing sv_2mortal(newSViv(0)), the returned value
must be mutable. For example

    my @a = ();
    my $r = \ scalar grep $_ == 1, @a;
    $$r += 10;

By setting the SVs_PADTMP flag, this forces pp_srefgen() and similar to
make a mortal copy of &PL_sv_zero.

This kind of defeats the original optimisation, but the copy only kicks
in under certain circumstances, whereas the newSViv(0) approach would
create a new mortal every time.

See RT #78288 for where FC suggested the problem and the solution.

6 years agoPVLV-as-REGEXP: avoid PVX double free
David Mitchell [Fri, 4 Aug 2017 13:28:15 +0000 (14:28 +0100)]
PVLV-as-REGEXP: avoid PVX double free

With v5.27.2-30-gdf6b4bd, I changed the way that PVLVs store a regexp
value (by making the xpv_len field point to a regexp struct). There was a
bug in this, which caused the PVX buffer to be double freed.

Several REGEXP SVs can share a PVX buffer. Only one of them will have a
non-zero xpv_len field, and that SV gets to free the buffer.

After the commit above, the non-zero xpv_len was triggering an extra free.

This was showing up in smokes as failures in re/recompile.t when invoked
with PERL_DESTRUCT_LEVEL=2 (which t/TEST does).

6 years agosv_dump(): display regex LEN and LV-as-RX regexp
David Mitchell [Fri, 4 Aug 2017 13:00:26 +0000 (14:00 +0100)]
sv_dump(): display regex LEN and LV-as-RX regexp

When the len field of a REGEXP isn't usurped, display it (it used to
always be skipped for REGEXPs).

When it's usurped by a PVLV to point to a 'struct regexp', display it as
a pointer.

6 years agoPerl_reg_temp_copy(): rename args.
David Mitchell [Fri, 4 Aug 2017 12:12:55 +0000 (13:12 +0100)]
Perl_reg_temp_copy(): rename args.

This function copies a regexp SV. Rename its args to ssv and dsv to
match a usual convention in other functions such as sv_catsv().

Similarly rename the two local vars holding ReANY(ssv/dsv) to srx, drx.

This is less confusing than having four vars called rx, ret_x, r, ret.

Also update the comments explaining what the function does.

6 years agopod/perltie.pod: mention SCALAR() for boolean keys
David Mitchell [Fri, 4 Aug 2017 10:50:07 +0000 (11:50 +0100)]
pod/perltie.pod: mention SCALAR() for boolean keys

After a recent commit of mine, SCALAR() is now called by 'keys' in boolean
context, e.g.

    if (keys %tied) { ... }

update the docs to reflect this. See the thread

    http://nntp.perl.org/group/perl.perl5.porters/245463

6 years agoSvTRUE(): add code comment
David Mitchell [Fri, 4 Aug 2017 08:48:06 +0000 (09:48 +0100)]
SvTRUE(): add code comment

explain that the '!= 0' is acting as a bool cast (since SvTRUE() is
supposed to return a bool value rather than an int value).

6 years agomake utf8::upgrade() of a REGEXP a NOOP
David Mitchell [Fri, 4 Aug 2017 07:51:49 +0000 (08:51 +0100)]
make utf8::upgrade() of a REGEXP a NOOP

RT #131821

After my recent commit

    v5.27.2-30-gdf6b4bd, "give REGEXP SVs the POK flag again",

    $r = qr/.../; utf8::upgrade($$r);

was setting the utf8 flag on the compiled REGEXP SV, which made no sense,
as the regex was already compiled and individual nodes would remain
non-utf8.

The POK flag was removed from REGEXPs in 5.18.0, but before then it didn't
seem to matter if the utf8 flag got set later, but it does now - it broke
a Tk test.

6 years agofix RX_MATCH_UTF8_on() macro
David Mitchell [Tue, 1 Aug 2017 09:18:47 +0000 (10:18 +0100)]
fix RX_MATCH_UTF8_on() macro

v5.27.2-34-g196a02a reorganised the RX_FOO() macros, mostly redefining
them in terms of the RXp_FOO() macros. A cut-an-paste error screwed up
the definition of RX_MATCH_UTF8_on(), which is isn't used in core.

6 years agoData::Dumper: Prevent XS deparse being used on old perls
Steffen Mueller [Fri, 4 Aug 2017 07:47:01 +0000 (09:47 +0200)]
Data::Dumper: Prevent XS deparse being used on old perls

Aaron's improvement mysteriously breaks on old perls. Instead of
investing hours into investigation of what will likely turn out to be
old perl bugs, we simply don't use XS deparse on ancient perls.  This
simply restores long standing behaviour, so it is no regression to any
released version of Data::Dumper.

Tested, still fails on 5.12 and earlier, works on 5.18, not sure about
intermediaries.

Could somebody who needs old perls to work please step up to
investigate?

Includes necessary version bump.

6 years agoperlop: use <<~FOO construct in example of indented here-docs
Lukas Mai [Thu, 3 Aug 2017 21:39:07 +0000 (23:39 +0200)]
perlop: use <<~FOO construct in example of indented here-docs

6 years agoFilter::Simple: Version bump to align with CPAN release
Steffen Mueller [Thu, 3 Aug 2017 14:29:15 +0000 (16:29 +0200)]
Filter::Simple: Version bump to align with CPAN release

6 years agoSelfLoader: Version bump for CPAN sync
Steffen Mueller [Thu, 3 Aug 2017 14:09:16 +0000 (16:09 +0200)]
SelfLoader: Version bump for CPAN sync

6 years agofix ($lex = index(....)) == -1
David Mitchell [Tue, 1 Aug 2017 07:19:42 +0000 (08:19 +0100)]
fix ($lex = index(....)) == -1

RT #131823

My recent commit v5.27.2-56-g7e8d786 optimised index() == -1 and similar.
It asserted that in such an expression, the index op's OPpTARGET_MY
flag couldn't be set. This was an incorrect assumption, obvious in
hindsight:

    ($lex = index(....)) == -1

gets compiled as

    <@> index[$r:2,3] sKP/TARGMY,2 ->c
       <0> ex-pushmark s ->9
       <0> padsv[$s:1,3] s ->a
       <$> const[PVMG "a"] s ->b
    <$> const[IV -1] s/FOLD ->d

The fix is simple: skip the optimisation if OPpTARGET_MY is present,
rather than assert failing.

6 years agofix SvTRUE() cast (broke xor)
David Mitchell [Mon, 31 Jul 2017 22:32:23 +0000 (23:32 +0100)]
fix SvTRUE() cast (broke xor)

RT #131820

It turns out that the 'xor' operator is almost completely untested in
core. A recent change of mine to the SvTRUE() macros made it sometimes
return an int (SvIVX(sv)) rather than a boolean (SvIVX(sv)!=0), while its
documented to return a boolean.

pp_xor() tests for (SvTRUE(left) != SvTRUE(right)) which subsequently
broke, e.g. (1 xor 5) started returning true rather than false.

Fix SvTRUE() and add some basic xor tests.

6 years agoEU::ParseXS: Version bump and changelog for CPAN release
Steffen Mueller [Mon, 31 Jul 2017 15:46:51 +0000 (17:46 +0200)]
EU::ParseXS: Version bump and changelog for CPAN release

6 years agoAdd SvPVCLEAR fallback definiton to Data::Dumper
Steffen Mueller [Mon, 31 Jul 2017 15:18:20 +0000 (17:18 +0200)]
Add SvPVCLEAR fallback definiton to Data::Dumper

See also: 40c7720facf5e6944805c593ad6a5604ad88c9ce

Also includes changelog entry for DD dev release to CPAN.

6 years ago... And now for something completely different
Chris 'BinGOs' Williams [Mon, 31 Jul 2017 14:15:42 +0000 (15:15 +0100)]
... And now for something completely different

6 years agofix example code in wrap_op_checker() doc
Zefram [Mon, 31 Jul 2017 10:10:16 +0000 (11:10 +0100)]
fix example code in wrap_op_checker() doc

Commit b93e7f0e1e15a1bbbcd9031bc4b66a5c60686eca added some code fragments
to the documentation of this function in order to explain it, but
got part of it wrong, confusing a pointer with the thing it points to.
Correct that, and reformulate the fragments of code into a more coherent
single example.

6 years agoAPItest/t/utf8_warn_base.pl: Fix broken tests
Karl Williamson [Mon, 31 Jul 2017 03:47:17 +0000 (21:47 -0600)]
APItest/t/utf8_warn_base.pl: Fix broken tests

There was a typo in one test, and in the other, the code point is output
as Unicode, not native.

6 years agoAPItest/t/utf8.t: Fix broken test on EBCDIC
Karl Williamson [Mon, 31 Jul 2017 03:45:44 +0000 (21:45 -0600)]
APItest/t/utf8.t: Fix broken test on EBCDIC

Perl-extended UTF-8 begins at a different code point on EBCDIC
platforms.

6 years agoperlsub: don't recommend leaky code for recursive "my" subs
Lukas Mai [Sun, 30 Jul 2017 15:17:13 +0000 (17:17 +0200)]
perlsub: don't recommend leaky code for recursive "my" subs

6 years agomake _GNU-ish function declarations visible on cygwin
Tony Cook [Fri, 28 Jul 2017 05:19:46 +0000 (15:19 +1000)]
make _GNU-ish function declarations visible on cygwin

The lack of this caused several test failures on cygwin64, the one case
I tracked down involved memmem() which is a GNU extension that cygwin
supports.

Since the compiler couldn't see the memmem() prototype it treated it's
return value as int, which was then cast to (char *) preventing any
type-mismatch warning, but since int is 32-bits and (char *) on
cygwin64, the upper 32-bits of the pointer was cleared, resulting in a
crash.

After adding this a test cygwin64 build went from 30 or so test failures
to one.

6 years agofix RX_MATCH_COPY_FREE() on win32
David Mitchell [Thu, 27 Jul 2017 19:17:43 +0000 (20:17 +0100)]
fix RX_MATCH_COPY_FREE() on win32

My recent commit made RX_MATCH_COPY_FREE() a wrapper for
RXp_MATCH_COPY_FREE() but it didn't build on VC 2003.

Spotted by bulk88.

6 years ago[perl #131726] [Win32] perl.h remaps 'strtoll' and 'strtoull' incorrectly
Steve Hay [Thu, 27 Jul 2017 17:13:13 +0000 (18:13 +0100)]
[perl #131726] [Win32] perl.h remaps 'strtoll' and 'strtoull' incorrectly

Fix by Kai-Uwe Eckhardt <kuehro [...] posteo.de> taken from
https://rt.cpan.org/Public/Bug/Display.html?id=121683
as suggested by Sisyphus on perl#131726.

6 years ago[MERGE] various boolean-related optimisations
David Mitchell [Thu, 27 Jul 2017 10:30:50 +0000 (11:30 +0100)]
[MERGE] various boolean-related optimisations

This branch contains about 50 commits, which collectively optimise
various aspects of perl's behaviour when detailing with boolean values
or ops that are called in boolean context.

The main changes are:

* A &PL_sv_zero variable has been added. This is a new per-interpreter
immortal SV, very similar to &PL_sv_no, except that it has a string value
of "0" rather than "". As well as being directly usable in cases where
code might otherwise need to do newSViv(0), it has a more subtle use in
ops that handle boolean context directly. For example in

    sub f {
        ....;
        if (%h) { .... }
    }

the 'if' statement is compiled using OP_AND, so is equivalent to

        %h && do { .... }

If %h is empty, then the result of the boolean expression should be 0
rather than &PL_sv_no, and this value gets returned to the caller, which
may expect a scalar result: and what it expects won't be known until run
time.  So by returning &PL_sv_yes and &PL_sv_zero rather than yes and no,
we increase the number of places where it is safe to return a boolean
value.

A downside of &PL_sv_zero is that if assigned to a variable, that variable
gets int, num and string values rather than just an int value.

* SvTRUE() is now more efficient.

This macro is called in places like pp_and, pp_not etc. It has a long list
of conditions which it goes through to determine the truthiness of an SV,
such as whether it has a string value, and if so whether the length is
zero, or the length is 1 and the string's value is "0". It turns out that
the immortals like &PL_sv_yes fare really badly here: they have to go
through nearly every check to finally determine their value. To get round
this, I have made it very quick to check whether an SV is one of the
immortals, and if so whether it is true. This has been done by ensuring
that PL_sv_undef, PL_sv_no, PL_sv_zero and PL_sv_yes are all contiguous in
memory, so that a quick single address comparison is enough to determine
immortality, and then comparing the address against &PL_sv_yes is enough
to determine whether its true.

In particular in non-multiplicity builds, PL_sv_undef etc have been
replaced with the array PL_sv_immortals[4], with PL_sv_undef #defed to
PL_sv_immortals[0] etc.

Also, the SvOK() macro has been made more efficient by restoring the POK
flag on REGEXP svs and and PVLVs which hold a regex. This removes the two
extra checks that SvOK() had to do each time. This has been done by
changing the way that PVLV's-holding-a-regex are implemented. The downside
of this change is that ReANY() now includes a single conditional. To
ameliorate that, places like pp_match() have been tweaked to only fetch
ReANY() once where possible.

* the OP_KEYS op is now optimised away in void and scalar context.
Since a hash in scalar context was changed so that it no longer returns a
bucket count but instead just a key count, '%h' and 'keys %h' in
void/boolean/scalar context are now very similar. So for 'keys %h', rather
than calling pp_padhv+pp_keys, just call pp_padhv with a OPpPADHV_ISKEYS
flag set. Similarly for pp_rv2hv. As well as skipping an extra op call,
this brings the existing boolean-context optimisations of '%h' to 'keys
%h' too. In particular, 'keys %tied' in boolean context now calls SCALAR()
if available, or FIRSTKEY() otherwise, rather than iterating through the
whole hash.

I have also given OP_RV2HV a targ so that it can return integer values
more efficiently.

* Various integer-returning ops are now flagged when in boolean context,
which means at runtime they can just return &PL_sv_yes/&PL_sv_zero rather
than setting a targ to an integer value, or for ops without targs, having
to create a new integer-valued mortal. As well as being quicker to return
a value, this works well with SvTRUE() which now recognises immortals
quickly. Also for ops like length() and pos(), it doesn't need to convert
between byte and char offsets; the fact that the offset is non-zero is
sufficient.

These ops are:

    OP_AASSIGN
    OP_GREPWHILE
    OP_LENGTH
    OP_PADAV
    OP_POS
    OP_RV2AV
    OP_SUBST

Also, index() doesn't return a boolean value, but for no match it returns
-1. So for code like

    if (index(...) != -1) { ... }

optimise away the OP_CONST and the OP_EQ and flag the index op to return a
boolean value.

* Speed up OP_ITER

OP_ITER is called for every iteration of a for loop or similar. Its job is
iterate the loop variable once, then return &PL_sv_yes or &PL_sv_no
depending on whether it's the last iteration. OP_ITER is always followed
by OP_AND, which examines the truth value on the stack, and returns
op_next or op_other accordingly. Now, pp_iter() just asserts that
PL_op->op_next is an OP_AND, and returns PL_op->op_next->op_next or
PL_op->op_next->op_other directly, skipping the PL_sv_yes/no push/pop and
eliminating the call to pp_and().

As part of these changes, I have moved pp_padav(), pp_padhv() from pp.c
to pp_hot.c, moved some common code into a new function
S_padhv_rv2hv_common(), created a new (non-API) function Perl_hv_pushkv()
which pushes a hash's keys or values or both onto the stack, and reduced
the number of callers of Perl_do_kv() (which was acting as both a pp
function for several ops and as a general-purpose function too).

Of the 360 or so tests in t/perf/benchmarks, the following number of
tests had their COND field changed from 100% to the following ranges:

   36 @  96.55% ..  99.99%
  245 @ 100.00% .. 100.99%
   28 @ 101.00% .. 109.99%
    7 @ 110.00% .. 119.99%
   10 @ 120.00% .. 129.99%
   29 @ 130.00% .. 199.99%
    4 @ 200.00% .. 299.99%
    1 @ 314.29%

so about 10% of tests became marginally slower - usually due to one extra
conditional in an op to test for a private BOOL flag or ReANY(); about 70%
of tests were almost unaffected, while 20% of tests showed improvement,
most with considerable improvement, and a few with spectacular improvement.
(The 314% is for an empty @lexical tested in boolean context).

6 years agot/perf/benchmarks: rename some keys() entries
David Mitchell [Tue, 25 Jul 2017 14:10:53 +0000 (15:10 +0100)]
t/perf/benchmarks: rename some keys() entries

move and rename
    expr::hash::bool_empty_keys
    expr::hash::bool_full_keys
to
    func::keys::lex::bool_cxt_empty
    func::keys::lex::bool_cxt

and add
    func::keys::pkg::bool_cxt_empty
    func::keys::pkg::bool_cxt

since its really testing the keys() function in boolean context rather
than a hash in boolean context.

6 years agomake scalar(keys(%lexical)) less slow.
David Mitchell [Sun, 23 Jul 2017 15:31:38 +0000 (16:31 +0100)]
make scalar(keys(%lexical)) less slow.

A recent commit in this branch made OP_PADHV / OP_RV2HV in void/scalar
context, followed by OP_KEYS, optimise away the OP_KEYS op and set the
OPpPADHV_ISKEYS or OPpRV2HV_ISKEYS flag on the OP_PADHV / OP_RV2HV op.

However, in scalar but non-boolean context with OP_PADHV, this actually
makes it slower, because the OP_KEYS op has a target, while the OP_PADHV
op doesn't, thus it has to create a new mortal each time to return the
integer value.

This commit fixes that by, in the case of scalar padhv, retaining the
OP_KEYS node (although still not keeping it in the execution path), then
at runtime using that op's otherwise unused target.

This only works on PERL_OP_PARENT builds (now the default) as the OP_KEYS
is the parent of the OP_PADHV, so would be hard to find at runtime
otherwise.

This commit also fixes pp_padhv/pp_rv2hv in void context - formerly it
was needlessly pushing a scalar-valued count like scalar context.

6 years agohv_pushkv(): handle keys() and values() too
David Mitchell [Fri, 21 Jul 2017 13:32:57 +0000 (14:32 +0100)]
hv_pushkv(): handle keys() and values() too

The newish function hv_pushkv() currently just pushes all key/value pairs on
the stack. i.e. it does the equivalent of the perl code '() = %h'.
Extend it so that it can handle 'keys %h' and values %h' too.

This is basically moving the remaining list-context functionality out of
do_kv() and into hv_pushkv().

The rationale for this is that hv_pushkv() is a pure HV-related function,
while do_kv() is a pp function for several ops including OP_KEYS/VALUES,
and expects PL_op->op_flags/op_private to be valid.

6 years agot/op/tie.t: add tests for scalar(keys(%tied))
David Mitchell [Thu, 20 Jul 2017 07:58:02 +0000 (08:58 +0100)]
t/op/tie.t: add tests for scalar(keys(%tied))

Test what methods it calls. Currently it calls FIRSTKEY() and then
NEXTKEY() x n, regardless of whether SCALAR() is present, although that
might change. This test codifies the current behaviour for now.

6 years agoS_padhv_rv2hv_common(): reorganise code
David Mitchell [Wed, 19 Jul 2017 16:48:03 +0000 (17:48 +0100)]
S_padhv_rv2hv_common(): reorganise code

There are three main booleans in play here:

    * whether the hash is tied;
    * whether we're in boolean context;
    * whether we're implementing 'keys %h'

Reorganise the if-tree logic for these up to 8 permutations to make the
code simpler. In particular, make it so that all these are done in only
one place:

    * call HvUSEDKEYS();
    * call magic_scalarpack();
    * push an integer return value, either as TARG or mortal

The functionality should be unchanged, except that now 'scalar(%h)',
where %h isn't tied, will return an integer value using the targ if
available rather than always creating a new mortal.

6 years agoS_padhv_rv2hv_common(): unroll hv_scalar() calls
David Mitchell [Wed, 19 Jul 2017 16:06:28 +0000 (17:06 +0100)]
S_padhv_rv2hv_common(): unroll hv_scalar() calls

This function makes a couple of calls to hv_scalar(), which does
one of two things depending on whether hash is tied or not.
Since in S_padhv_rv2hv_common() we've already determined whether the
hash is tied, just include the relevant part(s) of hv_scalar() directly.

The code will be reorganised shortly.

6 years agosimplify keys(%tied_hash) in boolean context.
David Mitchell [Wed, 19 Jul 2017 15:50:14 +0000 (16:50 +0100)]
simplify keys(%tied_hash) in boolean context.

Previously something like

    if (keys %tied_hash) { ... }

would have called FIRSTKEY(), followed by NEXTKEY() x N.

Now, it just calls SCALAR() once if present, and if not, falls
back to calling just FIRSTKEY() once.

i.e. it only needs to determine whether at least one key is present.

The behaviour of of 'keys(%tied) in boolean context now matches that of
'(%tied) in boolean context.

See http://nntp.perl.org/group/perl.perl5.porters/245463.

6 years agoS_pushav(): tail call optimise
David Mitchell [Wed, 19 Jul 2017 13:31:27 +0000 (14:31 +0100)]
S_pushav(): tail call optimise

Make it return PL_op->op_next so that (some of) its callers can be
tail-call optimised, if the compiler supports such a thing.

6 years agopp_padav(): use S_pushav()
David Mitchell [Wed, 19 Jul 2017 13:21:28 +0000 (14:21 +0100)]
pp_padav(): use S_pushav()

The previous commit harmonised the two functions, so its ok to use
S_pushav() now.

6 years agoharmonise S_pushav() and pp_padav()
David Mitchell [Wed, 19 Jul 2017 13:04:36 +0000 (14:04 +0100)]
harmonise S_pushav() and pp_padav()

These two functions contain a similar block of code to push an array
onto the stack. However they have some slight differences, which this
commit removes. This will allow padav() to call S_pushav() in the next
commit.

The two differences are:

1) S_pushav() when pushing elements of a magical array, calls mg_get()
on each element. This is to ensure that e.g. in

    sub f { /..../; @+ }

when the elements of @+ are returned, they are set *before* the current
pattern goes out of scope.

However, since probably v5.11.5-132-gfd69380 and v5.13.0-22-g2d961f6,
the mg_get is no longer required.

2) S_pushav() uses the SvRMAGICAL() test to decide whether its unsafe
to access AvARRAY directly; pp_padav() uses SvMAGICAL(). The latter
seems too severe, so I've changed it to SvRMAGICAL().

6 years agoPerl_hv_pushkv(): unroll hv_iterkeysv()
David Mitchell [Wed, 19 Jul 2017 08:11:33 +0000 (09:11 +0100)]
Perl_hv_pushkv(): unroll hv_iterkeysv()

Do our own mortal stack extending and handling.

6 years agocreate Perl_hv_pushkv() function
David Mitchell [Mon, 17 Jul 2017 16:51:57 +0000 (17:51 +0100)]
create Perl_hv_pushkv() function

...and make pp_padhv(), pp_rv2hv() use it rather than using Perl_do_kv()

Both pp_padhv() and pp_rv2hv() (via S_padhv_rv2hv_common()), outsource to
Perl_do_kv(), the list-context pushing/flattening of a hash onto the
stack.

Perl_do_kv() is a big function that handles all the actions of
keys, values etc. Instead, create a new function which does just the
pushing of a hash onto the stack.

At the same time, split it out into two loops, one for tied, one for
normal: the untied one can skip extending the stack on each iteration,
and use a cheaper HeVAL() instead of calling hv_iterval().

6 years agoGive OP_RV2HV a targ
David Mitchell [Mon, 17 Jul 2017 15:33:38 +0000 (16:33 +0100)]
Give OP_RV2HV a targ

OP_RV2AV already has one; its not clear why OP_RV2HV didn't.
Having one means that in scalar context it can return an int value
without having to create a mortal. Ditto when its doing 'keys %h' via
OPpRV2HV_ISKEYS.

6 years agoadd S_padhv_rv2hv_common() function
David Mitchell [Mon, 17 Jul 2017 14:52:38 +0000 (15:52 +0100)]
add S_padhv_rv2hv_common() function

This STATIC INLINE function extracts out a chunk of common code from
pp_padhv() and pp_rv2hv() (well, from pp_rv2av() actually, since that
handles OP_RV2HV too).

Should be no functional changes, except that now in void context,
'keys %h' doesn't leave any rubbish on the stack.

6 years agomove pp_padav(), pp_padhv() from pp.c to pp_hot.c
David Mitchell [Mon, 17 Jul 2017 12:47:12 +0000 (13:47 +0100)]
move pp_padav(), pp_padhv() from pp.c to pp_hot.c

Just a cut+paste; no code or functional changes.

As well as being hot code, pp_padav() and pp_padhv() also have a lot of
code in common with pp_rv2av() (which also implements pp_rv2hv()). Having
all three functions in the same file will allow the next few commits to
move some of that common code into static inline functions.

6 years agopp_grepwhile: no need to extend the stack
David Mitchell [Sat, 15 Jul 2017 21:26:04 +0000 (22:26 +0100)]
pp_grepwhile: no need to extend the stack

when returning from grep in scalar context, no need to extend the stack by
one when pushing the result count, since the last grep iteration will have
pushed its result which we've just popped.

6 years agochange sv_setsv(sv,NULL) to sv_set_undef(sv)
David Mitchell [Sat, 15 Jul 2017 21:12:41 +0000 (22:12 +0100)]
change sv_setsv(sv,NULL) to sv_set_undef(sv)

There are still a few core occurrences of

    sv_setsv(sv, NULL);

which is equivalent to

    sv_setsv(sv, &PL_sv_undef);

but which can now be done more efficiently with

    sv_set_undef(sv);

6 years agopp_iter(): jump directly to op after OP_AND
David Mitchell [Sat, 15 Jul 2017 12:27:09 +0000 (13:27 +0100)]
pp_iter(): jump directly to op after OP_AND

AN OP_ITER's op_next field always points to an OP_AND node. Rather than
pushing &PL_sv_yes or &PL_sv_no and then passing control to the OP_AND,
make pp_iter() return the OP_AND's op_next or op_other directly, depending
on whether this is the last iteration or not.

For an empty body, this cuts about 20% off the time of an iteration.

It's possible that some weird optree-munging XS module may break this
assumption. For now I've just added asserts that the next op is OP_AND
with an op_ppaddr of Perl_pp_and; if that assertion fails, it may be
necessary to convert pp_iter()s' asserts into conditional statements.

In the longer term it might be worthwhile converting OP_ITER from a
BASEOP into a LOGOP and eliminate the OP_AND from the optree altogether.

Alternatively, perhaps pp_iter could just tail call Perl_op_leavesub
directly after the last iteration?

6 years agooptimise (index() == -1)
David Mitchell [Fri, 14 Jul 2017 16:29:43 +0000 (17:29 +0100)]
optimise (index() == -1)

Unusually, index() and rindex() return -1 on failure.

So it's reasonably common to see code like

    if (index(...) != -1) { ... }

and variants.

For such code, this commit optimises away to OP_EQ and OP_CONST,
and sets a couple of private flags on the index op instead, indicating:

    OPpTRUEBOOL        return a boolean which is a comparison of
                       what the return would have been, against -1

    OPpINDEX_BOOLNEG   negate the boolean result

Its also supports OPpTRUEBOOL in conjunction with the existing
OPpTARGET_MY flag, so for example in

    $lexical = (index(...) == -1)

the padmy, sassign, eq and const ops are all optimised away.

6 years agopp_readline,close,getc: explain NULL stack arg
David Mitchell [Fri, 14 Jul 2017 14:23:29 +0000 (15:23 +0100)]
pp_readline,close,getc: explain NULL stack arg

add code comments to explain why these functions can sometimes be called
with a NULL pointer on the stack.

(feature introduced by v5.15.2-112-g30901a8)

6 years agot/perf/optree.t: reformat a table
David Mitchell [Fri, 14 Jul 2017 13:56:03 +0000 (14:56 +0100)]
t/perf/optree.t: reformat a table

whitespace-only change, plus alphabetically sort the lines of ops being
tested).

6 years agoregen/opcodes: move 'method' entry next to others
David Mitchell [Fri, 14 Jul 2017 13:50:19 +0000 (14:50 +0100)]
regen/opcodes: move 'method' entry next to others

there's a block of method_foo ops, and method was apart from them.

No functional difference and part from auto-allocated op numbers.

6 years agoadd boolean context support to several ops
David Mitchell [Thu, 13 Jul 2017 08:40:49 +0000 (09:40 +0100)]
add boolean context support to several ops

For some ops which return integer values and which have a reasonable
likelihood of being used in a boolean context, set the OPpTRUEBOOL
flag on the op as appropriate, and at runtime return &PL_sv_yes /
&PL_sv_zero rather than an integer value.

This is especially beneficial where the op doesn't have a targ, so has
to create a mortal SV to return the integer value.

Similarly, its a win where it may be expensive to calculate an integer
return value, such as pos() or length() converting between byte and char
offset.

Ops done:

    OP_SUBST
    OP_AASSIGN
    OP_POS
    OP_LENGTH
    OP_GREPWHILE

6 years agoS_check_for_bool_cxt(): avoid OPpTARGET_MY + bool
David Mitchell [Fri, 14 Jul 2017 10:50:16 +0000 (11:50 +0100)]
S_check_for_bool_cxt(): avoid OPpTARGET_MY + bool

Where an op allows the OA_TARGLEX optimisation (which eliminates the
assign op in '$lex = foo' and just sets the targ directly - which may be a
padtmp or $lex - the op doesn't care), disallow setting a boolean context
flag on that op. Because if the op does something like

    if (OPpTRUEBOOL)
        SETs(cond ? &PL_sv_yes : &PL_sv_no)

skipping assigning to TARG, then $lex won't get set.

6 years agopp_length: code tidy and simplify assert
David Mitchell [Fri, 14 Jul 2017 10:27:28 +0000 (11:27 +0100)]
pp_length: code tidy and simplify assert

The STATIC_ASSERT_STMT() is basically checking that shifting the
HINT_BYTES byte left 26 places gives you SVf_UTF8, so just assert that.
There's no need to assert the current values of HINT_BYTES and SVf_UTF8.

Other than that, this commit tides up the code a bit (only whitespace
changes and unnecessary brace removal), and adds/updates some code comments.

6 years agopp_length: only call sv_len_utf8_nomg() if needed
David Mitchell [Fri, 14 Jul 2017 10:18:52 +0000 (11:18 +0100)]
pp_length: only call sv_len_utf8_nomg() if needed

after doing get magic, if the result is SVf_POK and non-utf8,
just use SvCUR(sv).

6 years agopp_length: use TARGi rather rather than sv_setiv()
David Mitchell [Fri, 14 Jul 2017 08:47:58 +0000 (09:47 +0100)]
pp_length: use TARGi rather rather than sv_setiv()

TARGi(i,1) is equivalent to sv_setiv_mg(TARG,i), except that it inlines
some simple common cases.

Also add a couple of test for length on an overloaded utf8 string.
I don't think it was being tested for properly.

6 years agot/perf/optree.t: better diagnostics
David Mitchell [Thu, 13 Jul 2017 13:09:55 +0000 (14:09 +0100)]
t/perf/optree.t: better diagnostics

when it fails to the find the op its looking for, dump the optree.

Also, include the grep tests in parentheses, otherwise the condition
can be interpreted as the whole expression if the condition includes
parentheses;

e.g. condition: ($a==$_)

    becomes grep ($a==$_), 1, 2

so do this instead

    becomes grep (($a==$_), 1, 2)

6 years agooptimise @array in boolean context
David Mitchell [Tue, 11 Jul 2017 12:43:26 +0000 (13:43 +0100)]
optimise @array in boolean context

It's quicker to return (and to test for) &PL_sv_zero or &PL_sv_yes,
than setting a targ to an integer value or, in the vase of padav,
creating a mortal sv and setting it to an integer value.

In fact for padav, even in the scalar but non-boolean case, return
&PL_sv_zero if the value is zero rather than creating and setting a mortal.

6 years agooptimise away OP_KEYS op in scalar/void context
David Mitchell [Mon, 10 Jul 2017 14:48:02 +0000 (15:48 +0100)]
optimise away OP_KEYS op in scalar/void context

In something like

    if (keys %h) { ... }

the 'keys %h' is implemented as the op sequences

    gv[*h] s
    rv2hv lKRM/1
    keys[t2] sK/1
or
    padhv[%h:1,6] lRM
    keys[t2] sK/1

It turns out that (%h) in scalar and void context now behaves very
similarly to (keys %h) (except that it reset the iterator), so in these
cases, convert the two ops

    rv2hv/padhv, keys

into the single op

    rv2hv/padhv

with a private flag indicating that the op is handling the 'keys' action
by itself.

As well as one less op to execute, this brings the boolean-context
optimisation already present in padhv/rv2sv to keys. So

    if (keys %h) { ... }

is no longer slower than

    if (%h) { ... }

6 years agoOP_VALUES: reserve OPpMAYBE_LVSUB bit
David Mitchell [Mon, 10 Jul 2017 12:13:03 +0000 (13:13 +0100)]
OP_VALUES: reserve OPpMAYBE_LVSUB bit

This op doesn't use that bit, but it calls the function Perl_do_kv(),
which is called by several different ops which *do* use that bit.
So ensure no-one in future thinks that bit is spare in OP_VALUES.

6 years agouse OPpAVHVSWITCH_MASK
David Mitchell [Mon, 10 Jul 2017 11:39:25 +0000 (12:39 +0100)]
use OPpAVHVSWITCH_MASK

Use this symbolic constant rather than the literal constant '3'.

6 years agoPerl_do_kv(): add asserts and more code comments
David Mitchell [Mon, 10 Jul 2017 11:34:13 +0000 (12:34 +0100)]
Perl_do_kv(): add asserts and more code comments

This function can be called directly or indirectly by several ops.
Update its code comments to explain this in detail, and assert which
ops can call it. Also remove a redundant comment about
OP_RKEYS/OP_RVALUES; these ops have been removed.
Also, reformat the 'dokv = ' expressions.

Finally, add some code comments to pp_avhvswitch explaining what its for.

Apart from the op_type asserts, there should be no functional changes.

6 years agomake callers of SvTRUE() more efficient
David Mitchell [Sat, 8 Jul 2017 14:47:23 +0000 (15:47 +0100)]
make callers of SvTRUE() more efficient

Where its obvious that the args can't be null, use SvTRUE_NN() instead.
Avoid possible multiple evaluations of the arg by assigning to a local var
first if necessary.

6 years agoadd some SvTRUE() benchmarks
David Mitchell [Sat, 8 Jul 2017 13:17:15 +0000 (14:17 +0100)]
add some SvTRUE() benchmarks

Add a few not (!) expressions which exercise SvTRUE() for various types
of operand.

6 years agoSvTRUE(): inline ROK, outline NOK
David Mitchell [Sat, 8 Jul 2017 10:23:18 +0000 (11:23 +0100)]
SvTRUE(): inline ROK, outline NOK

SvTRUE (and its variants) are wrappers around sv_2bool(), which
attempt to test for the common cases without the overhead of a function
call.

This commit changes the definition of common:

SvROK() becomes common: it's very common to test whether a variable
is undef or a ref;
SvNOK becomes uncommon: these days perl prefers IV values over NV values
in SVs whenever possible, so testing the truth value of an NV is less
common.

6 years agoSvTRUE(): special-case immortals
David Mitchell [Wed, 12 Jul 2017 13:48:34 +0000 (14:48 +0100)]
SvTRUE(): special-case immortals

Immortal SVs like PL_sv_no will often be used as an argument to
SvTRUE(); however it turns out that SvTRUE() is very inefficient at
determining the truth value of such SVs. For example, for PL_sv_yes
it does all the following test-and-branches to decide that it is indeed
true:

    SvOK()
    SvPOK()
    SvANY()
    xpv_cur > 1
    xpv_cur
    sv_u.svu_pv != '0'

After the previous commit it is now much cheaper to  test whether an SV is
one of the four "interpreter" immortals PL_sv_yes, PL_sv_undef, PL_sv_no,
PL_sv_zero.

So this commit adds an extra check at the beginning of SvTRUE(): if it's
an immortal, return whether it's a true immortal (i.e. PL_sv_yes).

SvTRUE_nomg_NN(&PL_sv_yes) now only requires one test-and-branch plus an
address comparison. The other immortals are similarly improved.

Non-immortals now require one extra test-and-branch.

6 years agoMake immortal SVs contiguous
David Mitchell [Wed, 12 Jul 2017 13:07:16 +0000 (14:07 +0100)]
Make immortal SVs contiguous

Ensure that PL_sv_yes, PL_sv_undef, PL_sv_no and PL_sv_zero are allocated
adjacently in memory.

This allows the SvIMMORTAL() test to be more efficient, and will (in the
next commit) allow SvTRUE() to be more efficient.

In MULTIPLICITY builds the constraint is already met by virtue of them
being adjacent items in the interpreter struct. For non-MULTIPLICITY
builds, they were just 4 global vars with no guarantees of where
they would be allocated. For this case, PL_sv_undef are deleted
as global vars and replaced with a new global var PL_sv_immortals[4],
with

    #define PL_sv_yes   (PL_sv_immortals[0])

etc in their place.

6 years agoSvTRUE(): handle get magic more efficiently
David Mitchell [Wed, 5 Jul 2017 16:16:34 +0000 (17:16 +0100)]
SvTRUE(): handle get magic more efficiently

SvTRUE() and SvTRUE_NN() are wrappers around  sv_2bool() which
handle the common cases directly and only fallback  to sv_2bool() for the
hard ones. Those macros were considering get magic as hard and falling
back; instead, just call the get magic and continue.

6 years agorationalise SvTRUE() macro variants
David Mitchell [Wed, 5 Jul 2017 16:09:12 +0000 (17:09 +0100)]
rationalise SvTRUE() macro variants

define the plain, _nomg and _NN variants in terms of each other, e.g.

    #define SvTRUE(sv)  (LIKELY(sv) && SvTRUE_NN(sv))

rather than duplicating common code text.

There should be no functional changes, and the macros should (in theory)
continue to expand to the same text.

6 years agoadd, and use, some RXp_FOO() variants of RX_FOO()
David Mitchell [Fri, 21 Jul 2017 16:07:51 +0000 (17:07 +0100)]
add, and use, some RXp_FOO() variants of RX_FOO()

For various  RX_FOO() macros, add a RXp_FOO() variant, in such a way that
the original macro is now defined in terms of

    #define RX_FOO(rx_sv)  (RXp_FOO(ReANY(rx_sv)))

(This is a pre-existing convention; this commit just makes a larger subset
of the RX_() macros have an RXp_() variant).

Then use those macros in various pp_hot.c and regexec.c functions like
pp_match() and regexec_flags(), which already, or added via this commit,
have this line near the start:

    regexp *prog = ReANY(rx);

This avoids having to do multiple ReANY()'s, which is important as this
macro now includes a conditional in its expression (to cope with
PVLV-as-REGEX)..

6 years agorename RX_HAS_CUTGROUP() to RXp_HAS_CUTGROUP()
David Mitchell [Mon, 24 Jul 2017 13:58:58 +0000 (14:58 +0100)]
rename RX_HAS_CUTGROUP() to RXp_HAS_CUTGROUP()

It takes a private/internal regexp* pointer rather than a public REGEXP
pointer, so rename it to match the other RXp_ macros.

Most RXp_ macros are a variant of an RX_ macro; however, I didn't add an
RX_HAS_CUTGROUP() macro - someone can always add that if needed. (There's
only one use of RXp_HAS_CUTGROUP in core).

6 years agoreformat RX_() macros
David Mitchell [Mon, 24 Jul 2017 13:54:53 +0000 (14:54 +0100)]
reformat RX_() macros

The previous commit caused the formatting of these macros to become
messy. Realign them, replacing tabs with spaces, and split some long
macros over multiple lines.

Whitespace-only change (if you count splitting a macro with \ as
whitespace).

6 years agoRX_FOO(prog) becomes RX_FOO(rx_sv)
David Mitchell [Mon, 24 Jul 2017 13:19:29 +0000 (14:19 +0100)]
RX_FOO(prog) becomes RX_FOO(rx_sv)

There are a family of RX_() macros which take an SV of type REGEXP as an
argument. For historical reasons (regexeps didn't use to be SVs), the name
of the parameter is 'prog', which is also by convention used to name the
actual regexp struct in some places. So e.g. at the top of
re_intuit_start(), you see

    struct regexp *const prog = ReANY(rx);

This is confusing. So for this class of macro, rename the parameter from
'prog' to 'rx_sv'.  This makes it clearer that the arg should be a REGEXP*
rather than an regexp*.

Note that there are some RXp_() macros which do take a regexp* as an arg;
I've left their parameter name as 'prog'.

6 years agogive REGEXP SVs the POK flag again
David Mitchell [Fri, 7 Jul 2017 13:13:32 +0000 (14:13 +0100)]
give REGEXP SVs the POK flag again

Commit v5.17.5-99-g8d919b0 stopped SVt_REGEXP SVs (and PVLVs acting as
regexes) from having the POK and pPOK flags set. This made things like
SvOK() and SvTRUE() slower, because as well as the quick single test for
any I/N/P/R flags, SvOK() also has to test for

    (SvTYPE(sv) == SVt_REGEXP
     || (SvFLAGS(sv) & (SVTYPEMASK|SVp_POK|SVpgv_GP|SVf_FAKE))
 == (SVt_PVLV|SVf_FAKE))

This commit fixes the issue fixed by g8d919b0 in a slightly different way,
which is less invasive and allows the POK flag.

Background:

PVLV are basically PVMGs with a few extra fields. They are intended to
be a superset of all scalar types, so any scalar value can be assigned
to a PVLV SV.

However, once REGEXPs were made into first-class scalar SVs, this
assumption broke - there are a whole bunch of fields in a regex SV body
which can't be copied to to a PVLV. So this broke:

    sub f {
        my $r = qr/abc/; # $r is reference to an SVt_REGEXP
        $_[0] = $$r;
    }

    f($h{foo}); # the hash access is deferred - a temporary PVLV is
                # passed instead

The basic idea behind the g8d919b0 fix was, for an LV-acting-as-regex,
to attach both a PVLV body and a regex body to the SV head. This commit
keeps this basic concept; it just changes how the extra body is attached.

The original fix changed SVt_REGEXP SVs so that sv.sv_u.svu_pv no longer
pointed to the regexp's string representation; instead this pointer was
stored in a union made out of the xpv_len field. Doing this necessitated
not turning the POK flag on for any REGEXP SVs.

This freed up the sv_u to point to the regex body, while the sv_any field
could continue to point to the PVLV body. An ReANY() macro was introduced
that returned the sv_u field rather than the sv_any field.

This commit changes it so that instead, on regexp SVs (and LV-as-regexp
SVs), sv_u always points to the string buffer (so they can have POK set
again), but on specifically LV-as-regex SVs, the xpv_len_u union of the
PVLV body points to the regexp body.

This means that SVt_REGEXP SVs are now completely "normal" again,
and SVt_PVLV SVs are normal except in the one case where they hold a
regex, in which case rather than storing the string buffer's length, the
PVLV body stores a pointer to the regex body.

6 years agosv_2bool_flags(): assume ROK implies SvRV
David Mitchell [Wed, 5 Jul 2017 15:26:51 +0000 (16:26 +0100)]
sv_2bool_flags(): assume ROK implies SvRV

If the SvROK flag is set, the SV must have a valid non-nnull SvRV()
pointer, so don;t bother to check that whether its null.

6 years agoS_check_for_bool_cxt(): special-case OP_AND
David Mitchell [Tue, 4 Jul 2017 11:46:20 +0000 (12:46 +0100)]
S_check_for_bool_cxt(): special-case OP_AND

Re-instate the special-casing, which was removed by v5.25.8-172-gb243b19,
of OP_AND in boolean-context determination.

This is because the special-case allowed things to be more efficient
sometimes, but required returning a false value as sv_2mortal(newSViv(0)))
rather than &PL_sv_no. Now that PL_sv_zero has been added we can use
that instead, cheaply.

This commit adds an extra arg to S_check_for_bool_cxt() to indicate
whether the op supports the special-casing of OP_AND.

6 years agouse the new PL_sv_zero in obvious places
David Mitchell [Tue, 4 Jul 2017 08:45:29 +0000 (09:45 +0100)]
use the new PL_sv_zero in obvious places

In places that do things like mPUSHi(0) or newSViv(0), replace them
with PUSHs(&PL_sv_zero) and &PL_sv_zero, etc.

This avoids the cost of creating and/or mortalising an SV, and/or setting
its value to 0.

This commit causes a subtle change to tainting in various places as a
side-effect. For example, grep in scalar context retunrs 0 if it has no
args.  Formerly the zero value could in theory get tainted:

    @a = ();
    $x = ( ($^X . ""), grep { 1 } @a);

It used to be the case that $x would be tainted; now its not.
In practice this doesn't matter - the zero value was only getting tainted
as a side-effect of tainting's "if anything in the statement uses a
tainted value, taint everything" mechanism, which gives (documented) false
positives. This commit merely removes some such false positives, and
makes the behaviour similar to functions which return &PL_sv_undef/no/yes,
which are also immune to side-effect tainting.

6 years agomake B.pm, Concise.pm support PL_sv_zero
David Mitchell [Sat, 8 Jul 2017 15:27:35 +0000 (16:27 +0100)]
make B.pm, Concise.pm support PL_sv_zero

6 years agodist/threads/: support PL_sv_zero
David Mitchell [Wed, 5 Jul 2017 15:44:38 +0000 (16:44 +0100)]
dist/threads/: support PL_sv_zero

and bump version from 2.16 to 2.17

6 years agoadd PL_sv_zero
David Mitchell [Mon, 3 Jul 2017 16:07:28 +0000 (17:07 +0100)]
add PL_sv_zero

it's like PL_sv_no, except that its string value is "0" rather than "".
It can be used for example where pp function wants to push a zero return
value on the stack. The next commit will start to use it.

Also update the SvIMMORTAL() to be more efficient: it now checks whether
the SV's address is in a range rather than individually checking against
&PL_sv_undef, &PL_sv_no etc.

6 years ago[perl #130410] Import B-Debug 1.25 from CPAN
Dagfinn Ilmari Mannsåker [Thu, 27 Jul 2017 10:06:35 +0000 (11:06 +0100)]
[perl #130410] Import B-Debug 1.25 from CPAN

This marks it as deprecated in core so it can be removed in 5.30.

6 years agoFetch CPAN modules from the metacpan mirror instead of s.c.o
Dagfinn Ilmari Mannsåker [Thu, 27 Jul 2017 09:58:42 +0000 (10:58 +0100)]
Fetch CPAN modules from the metacpan mirror instead of s.c.o

6 years agoUpdate MANIFEST and bump base $VERSION for previous commit
Steve Hay [Tue, 25 Jul 2017 16:21:03 +0000 (17:21 +0100)]
Update MANIFEST and bump base $VERSION for previous commit

6 years agoLimit dotless-INC effect on base.pm with guard:
Aristotle Pagaltzis [Mon, 13 Feb 2017 00:28:14 +0000 (01:28 +0100)]
Limit dotless-INC effect on base.pm with guard:

This introduces a more refined and accurate solution for removing
'.' from @INC while reducing the false positives.

The following explanation is roughly what is avaiable in the code
comments. If you stumble upon this and feel like the commit message
or the comments are not helpful enough, please introduce another
commit that adds more explanation or improve the code comments
(or both).

Using

    if ($INC[-1] eq '.' && %{"$base\::"})

We decide that:

The package already exists   => this an optional load
And: there is a dot at the end of @INC  => we want to hide it
However: we only want to hide it during our *own* require()
(i.e. without affecting nested require()s).

So we add a hook to @INC whose job is to hide the dot, but which
first checks checks the callstack depth, because within nested
require()s the callstack is deeper.

Since CORE::GLOBAL::require makes it unknowable in advance what
the exact relevant callstack depth will be, we have to record it
inside a hook. So we put another hook just for that at the front
of @INC, where it's guaranteed to run -- immediately.

The dot-hiding hook does its job by sitting directly in front of
the dot and removing itself from @INC when reached. This causes
the dot to move up one index in @INC, causing the loop inside
pp_require() to skip it.

Loaded coded may disturb this precise arrangement, but that's OK
because the hook is inert by that time. It is only active during
the top-level require(), when @INC is in our control. The only
possible gotcha is if other hooks already in @INC modify @INC in
some way during that initial require().

Note that this jiggery hookery works just fine recursively: if
a module loaded via base.pm uses base.pm itself, there will be
one pair of hooks in @INC per base::import call frame, but the
pairs from different nestings do not interfere with each other.

(cherry picked from commit 571931bfa1120564fe207965f9ec2ea0f8bbbb8a)

[This is a forward-port, with improved commit message by Sawyer X
<xsawyerx@cpan.org>, of the commit that was cherry-picked into
maint-5.22 and maint-5.24 as commits a93da9a38c and 1afa289000
respectively.]

6 years agoRevert B::Debug removal
Dagfinn Ilmari Mannsåker [Tue, 25 Jul 2017 12:04:37 +0000 (13:04 +0100)]
Revert B::Debug removal

Per perlpolicy, modules need to be deprecated for at least one stable
release before removal.

This reverts commits ecfa068aa0dab432bfdef423766b665be127ef77 and
6be75e63260512c636a5bdc72bbf4981a37bad7d.

6 years agoUpdate case folding and character classification in vms/vms.c.
Craig A. Berry [Tue, 25 Jul 2017 13:57:59 +0000 (08:57 -0500)]
Update case folding and character classification in vms/vms.c.

Karl W. tells me we shouldn't be using functions that depend on
the current locale in Perl core, so replace them with the
relevant macros from handy.h.  Use the Latin-1 variants where
possible as Latin-1 is a very close cousin of DEC-MCS.

Use the ASCII variants for things that need to be upcased (like
logical names) or for comparison with literal ASCII upper case
characters.

N.B.  While filenames can in principle be reported as UTF-8, most
of the current processing is done via incrementing a pointer and
checking one byte at a time.  That logic will have to be rewritten
to accommodate multi-byte characters.

strncasecmp, atoi, and atol have not been changed.  The current
implementations are documented to have ASCII assumptions.  We'll
have to take another look if and when the CRTL ever catches up
with a more recent version of POSIX.

6 years agoperldelta for ecfa068aa0dab432bfdef423766b665be127ef77
James E Keenan [Tue, 25 Jul 2017 11:25:51 +0000 (07:25 -0400)]
perldelta for ecfa068aa0dab432bfdef423766b665be127ef77

6 years agoRemove B::Debug from core distribution.
James E Keenan [Tue, 25 Jul 2017 10:44:52 +0000 (06:44 -0400)]
Remove B::Debug from core distribution.

It continues to exist as a CPAN distribution.

Increment $B::Terse::VERSION due to change in POD.

Remove internal links to B::Debug within two .pod files.

For: RT #130410

6 years ago(perl #131685) improve utf8::* function documentation
Tony Cook [Mon, 24 Jul 2017 01:05:40 +0000 (11:05 +1000)]
(perl #131685) improve utf8::* function documentation

Splits the little cheat sheet I posted as a comment into pieces
and puts them closer to where they belong

- better document why you'd want to use utf8::upgrade()

- similarly for utf8::downgrade()

- try hard to convince people not to use utf8::is_utf8()

- no, utf8::is_utf8() isn't what you want instead of utf8::valid()

- change some examples to use $x instead of the sort reserved $a

6 years agounfortunately sysread() tries to read characters
Tony Cook [Wed, 19 Jul 2017 05:42:18 +0000 (15:42 +1000)]
unfortunately sysread() tries to read characters