In perl.git, the branch smoke-me/davem/contextsB3 has been created
<http://perl5.git.perl.org/perl.git/commitdiff/52c36c846381c0fc8402291887ad919545b75a15?hp=0000000000000000000000000000000000000000>
at 52c36c846381c0fc8402291887ad919545b75a15 (commit)
- Log -----------------------------------------------------------------
commit 52c36c846381c0fc8402291887ad919545b75a15
Author: David Mitchell <[email protected]>
Date: Sun Jan 3 19:38:13 2016 +0000
fix -DPERL_GLOBAL_STRUCT_PRIVATE
Perl_leave_adjust_stacks() needed a dVAR
M pp_hot.c
commit 75d76367c89168b8d32b7db60a97987b5560814a
Author: David Mitchell <[email protected]>
Date: Sun Jan 3 17:28:06 2016 +0000
perlfunc: say what block types 'return' recognises
'return' recognises these blocks
sort { ...; return } ...
/(?{ ...; return })/;
but ignores these:
grep { ...; return } ...;
map { ...; return } ...;
M pod/perlfunc.pod
commit 72e012e1108e9a51248dfebd64f9be5c2fca26f5
Author: David Mitchell <[email protected]>
Date: Sun Jan 3 15:23:56 2016 +0000
perlguts: add section on context stack
M pod/perlguts.pod
commit 86fb5514a1113b99916bb57a5acb23a8e6e6329f
Author: David Mitchell <[email protected]>
Date: Sun Jan 3 15:17:40 2016 +0000
fix cx_dup for CXt_LOOP_PLAIN
The context stack duplication code tries to duplicate the loop var
even for CXt_LOOP_PLAIN, which doesn't have a loop var. This didn't
use to matter, since PUSHLOOP_PLAIN() used to set the field to NULL;
for efficiency its now left untouched. So don't try to use it.
Also update the debugging context names since the ordering of the
CXt_LOOP_* has changed recently.
M perl.h
M sv.c
commit 7f46028de21d668edb62859c79844bc07e7871c0
Author: David Mitchell <[email protected]>
Date: Thu Dec 31 10:39:17 2015 +0000
MULTICALL *shouldn't* clear savestack
About 25 commits ago in this branch I added a commit:
MULTICALL should clear scope after each call
To fix RT #116577, which reported that lexicals were only being freed
at the end of the MULTICALL, not after each individual call to the sub.
In that commit, I added a LEAVE_SCOPE() to the end of the MULTICALL()
definition. However, after further thought I realise that's wrong. If a
multicall sub does something like { my $x = $_*2; $x }, then the returned
value would be freed before the XS code which calls MULTICALL() has a
chance to do anything with it (e.g. test for truth, or add it to the return
args or whatever).
So I think popping the save stack should be the responsibility of the
caller of MULTICALL(), rather than of MULTICALL() itself.
M cop.h
M ext/XS-APItest/t/multicall.t
M regexec.c
commit 0adaca3aa4388ce2507bf0a80ae0e168bd215c27
Author: David Mitchell <[email protected]>
Date: Wed Dec 30 15:48:52 2015 +0000
add blk_old_tmpsfloor shortcut
Add
#define blk_old_tmpsfloor cx_u.cx_blk.blku_old_tmpsfloor
to match all the other 'struct block' fields which have similar short cuts
M cop.h
M inline.h
commit 427b37f9c4a5b8398ed72e875ae924e200153b8c
Author: David Mitchell <[email protected]>
Date: Wed Dec 30 15:20:41 2015 +0000
dMULTICALL: remove unused vars
dMULTICALL declares several vars that are used either to maintain
state across multiple calls, or to pass values to PUSHSUB etc, where
those macros expected to obtain some of their args by values being
implicitly passed via local vars. Since PUSHSUB has been replaced by
cx_pushsub() which now has all parameters explicitly passed, there is
no longer any need for those vars. So this commit eliminates them:
newsp
hasargs
There are also a couple vars which are no longer used due to changes to
the implementation over time; these can also be eliminated:
cx multicall_cv
Finally, this branch introduced a new var, saveix_floor; rename it to
multicall_saveix_floor for consistency with other dMULTICALL vars.
Although none of these vars are listed in the documentation, its possible
that some code out there may rely on them in some way, and will need to be
fixed up.
M cop.h
M ext/XS-APItest/APItest.xs
M regexec.c
commit 59472e95fe31e588f96f0f2a23e7ddea4a403fd1
Author: David Mitchell <[email protected]>
Date: Wed Dec 30 14:33:51 2015 +0000
convert CX_{PUSH|POP}{WHEN|GIVEN} to inline fns
Replace CX_PUSHGIVEN() with cx_pushgiven() etc.
M cop.h
M embed.fnc
M embed.h
M inline.h
M pp_ctl.c
M proto.h
commit 40dc0754da3c93f3e5ffc5d0047f68f759567f16
Author: David Mitchell <[email protected]>
Date: Wed Dec 30 14:18:05 2015 +0000
convert CX_PUSHLOOP*/POPLOOP to inline fns
Replace CX_PUSHLOOP_FOR() with cx_pushfloop_for() etc.
M cop.h
M embed.fnc
M embed.h
M inline.h
M pp_ctl.c
M proto.h
commit fa5c5a87ab47b080d49101639541784a40b493ff
Author: David Mitchell <[email protected]>
Date: Wed Dec 30 13:23:47 2015 +0000
convert CX_PUSHEVAL/POPEVAL to inline fns
Replace CX_PUSHEVAL() with cx_pusheval() etc.
No functional changes.
M cop.h
M embed.fnc
M embed.h
M inline.h
M op.h
M perl.c
M pp_ctl.c
M proto.h
commit a1f0090e76d20a1f77050d7d3cae602474e61fdd
Author: David Mitchell <[email protected]>
Date: Wed Dec 30 13:09:36 2015 +0000
convert CX_PUSHFORMAT/POPFORMAT to inline fns
Replace CX_PUSHFORMAT() with cx_pushformat() etc.
No functional changes.
M cop.h
M embed.fnc
M embed.h
M inline.h
M pp_ctl.c
M pp_sys.c
M proto.h
commit 59abad4307ff60635671cd02c86f75749552a08f
Author: David Mitchell <[email protected]>
Date: Wed Dec 30 12:33:48 2015 +0000
convert CX_PUSHSUB/POPSUB to inline fns
Replace CX_PUSHSUB() with cx_pushsub() etc.
No functional changes.
M cop.h
M embed.fnc
M embed.h
M inline.h
M pp.c
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M proto.h
M t/op/args.t
commit 699d1a81dc22e19b37c9c15bfe9f5f839cf11a1e
Author: David Mitchell <[email protected]>
Date: Wed Dec 30 11:46:22 2015 +0000
convert CX_PUSH/POP/TOPBLOCK to inline fns
Replace CX_PUSHBLOCK() with cx_pushblock() etc.
No functional changes.
M cop.h
M embed.fnc
M embed.h
M ext/XS-APItest/APItest.xs
M inline.h
M op.c
M perl.c
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
M proto.h
commit 5f145a238e69381efde8b22de8ab20b96c18efda
Author: David Mitchell <[email protected]>
Date: Tue Dec 29 10:05:29 2015 +0000
add a few grep and map benchmarks
M t/perf/benchmarks
commit 9f262bcb707c2927f0601630afd8d6791fe720cf
Author: David Mitchell <[email protected]>
Date: Sun Dec 27 14:07:02 2015 +0000
offset PL_savestack_max by SS_MAXPUSH
The newer SS_ADD macros expect there to always be SS_MAXPUSH slots
free on the savestack; so they can push multiple items, then only check
once at the end whether stack needs expanding.
This commit makes savestack_grow() set PL_savestack_max to SS_MAXPUSH
short of what has actually been allocated. This makes the tests
to see whether the stack needs growing slightly simpler, i.e.
PL_savestack_ix > PL_savestack_max
rather than
PL_savestack_ix + SS_MAXPUSH > PL_savestack_max
M perl.c
M scope.c
M scope.h
commit 890efe2e100b7d130b5a2e8cda0138aed4096871
Author: David Mitchell <[email protected]>
Date: Sun Dec 27 10:41:41 2015 +0000
add SAVEt_TMPSFLOOR save type and Perl_savetmps()
By making SAVETMPS have its own dedicated save type, it avoids having to
push the address of PL_tmps_floor onto the save stack each time.
By also giving it a dedicated save function, the function can do
the PL_tmpsfloor = PL_tmps_ix step too, making the binary slightly more
compact.
M embed.fnc
M proto.h
M scope.c
M scope.h
M sv.c
commit 4889980ded5d53228dec28a4f490b14dfd6b07d3
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 22:28:59 2015 +0000
rename PUSHBLOCK,PUSHSUB etc to CX_PUSHBLOCK etc
Earlier all the POPFOO macros were renamed to CX_POPFOO to reflect
the changed API (like POPBLOCK no longer decremented cxstack_ix).
Now rename the PUSH ones for consistency.
M cop.h
M op.h
M perl.c
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
M scope.c
commit 740197a51ead22e28dbd1a9b98392b95ac459387
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 22:14:00 2015 +0000
eliminate PUSH/POPBASICBLK macros
These are both NOOPs now, and were introduced within this branch
as a temporary measure while extra stuff needed doing when pushing or
popping a CXt_BOCK (pp_enter/pp_leave).
M cop.h
M pp_ctl.c
commit 49a0aec2d2a2c24a2b102fc284fb9edfafe8657e
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 21:49:28 2015 +0000
pp_enteriter: add comment about setting cxt type
M pp_ctl.c
commit 69a22ff7faffaf5f7a6c2de5f2af723b79ee942a
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 13:48:43 2015 +0000
consolidate common code in PUSHLOOP_FOR,_PLAIN
M cop.h
commit 826aaf67ad748b55bb04ec2d9c96cf9e18f0a845
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 12:45:01 2015 +0000
PUSHEVAL: make n param an SV rather than a string
Rather than doing
cx->blk_eval.old_namesv = (n ? newSVpv(n,0) : NULL);
make the caller responsible for creating and passing in the SV. Since
only only place (pp_require) passes a non-null value, this saves the
other places having to test for nullness.
M cop.h
M pp_ctl.c
commit 6201b7b809f9c104991b079c33ca119d14827c85
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 12:37:30 2015 +0000
PUSHSUB: make retop a parameter
Rather than doing cx->blk_sub.retop = NULL in PUSHSUB, then relying on
the caller to subsequently change it to something more useful, make it an
arg to PUSHSUB.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
commit a15eb6203836dfafe05b5cbeaf07df4af32f0e99
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 12:30:25 2015 +0000
PUSHEVAL: make retop a parameter
Rather than doing cx->blk_eval.retop = NULL in PUSHEVAL, then relying on
the caller to subsequently change it to something more useful, make it an
arg to PUSHEVAL.
M cop.h
M embed.fnc
M embed.h
M op.c
M perl.c
M pp_ctl.c
M proto.h
commit 582b90763d1a70e67099a2583bb31cdfdd668f2f
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 12:07:50 2015 +0000
PUSHFORMAT: don't use implicit args
Make cv and gv explicit parameters of PUSHFORMAT(), rather than just
assuming that there are such vars in scope.
M cop.h
M pp_sys.c
commit 3e52da14cb1ecaa8dcb49a854f34f2d436a25526
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 11:52:33 2015 +0000
PUSHSUB: don't use implicit args
Make cv and hasargs explicit parameters of PUSHSUB(), rather than just
assuming that there are such vars in scope.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
commit 613056b3ab4dbcc50769a0275809afbdb2236c65
Author: David Mitchell <[email protected]>
Date: Sat Dec 26 11:39:30 2015 +0000
PUSHBLOCK: don't use implicit args
Make gimme a parameter of PUSHBLOCK() rather than just assuming that
there's a 'gimme' var in scope.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
commit db78b689453e2ba68b40b5cd04e619d222cad767
Author: David Mitchell <[email protected]>
Date: Fri Dec 25 23:54:23 2015 +0000
move PL_savestack_ix saving into PUSHBLOCK
Currently blku_oldsaveix was being set by the various PUSHFOO macros,
except for PUSHSUB and PUSHEVAL which expected their caller to do it
manually.
Now that all the main context state is stored on the context stack
rather than than some on the save stack too, things are a lot simpler,
and this messy transitional state can now be rationalised, whereby
blku_oldsaveix is now always set by PUSHBLOCK; the exact value being
specified by a new arg to PUSHBLOCK.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
commit 5fab97d8a7060170233b5f0afcc4cdbf16e7bb74
Author: David Mitchell <[email protected]>
Date: Fri Dec 25 23:12:29 2015 +0000
PUSH_MULTICALL: use SAVEOP()
SAVEOP() should be more efficient than SAVEVPTR(PL_op), since it
uses the dedicated SAVEt_OP.
M cop.h
commit 2539e892cad6b4bdf4ce07bc9e9a8afcd91b80e3
Author: David Mitchell <[email protected]>
Date: Fri Dec 25 22:41:21 2015 +0000
eliminate PERL_STACK_OVERFLOW_CHECK
This macro is defined as NOOP on all platforms except for MacOS classic,
where it was added as a hook to allow for OSes that have a small CPU
stack size. Since pp_entersub et al don't actually use the CPU stack,
this hook looks misconceived from the beginning. So remove all
uses of it in the core.
M cop.h
M perl.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
commit 290aa5b4f329f85119898066847aadeef9fb5f54
Author: David Mitchell <[email protected]>
Date: Fri Dec 25 22:28:14 2015 +0000
sort compare subs: don't do unnecessary scope work
The 3 functions S_sortcv(), S_sortcv_stacked(), S_sortcv_xsub(),
which call a comparison function to compare $a and $b, do unnecessary work
with the scope and save stacks.
First, they pop any excess scope stack entries; but there shouldn't
be, since exiting the sort sub should have already pooped any inner
scopes. Indeed, running with an assert that PL_scopestack_ix == oldscopeix
didn't trigger any failures.
Secondly replace the unconditional leave_scope(oldsaveix) with
LEAVE_SCOPE(), which only calls the function if PL_savestack_ix >
oldsaveix.
M pp_sort.c
commit 8e3cb70ca8741a0da804eee50478ac94256676d6
Author: David Mitchell <[email protected]>
Date: Fri Dec 25 22:03:10 2015 +0000
MULTICALL should clear scope after each call
RT #116577
Lexicals etc were only being freed at the end of the MULTICALL, not
after each individual call to the sub.
M cop.h
M ext/XS-APItest/t/multicall.t
M regexec.c
commit a36793757bcfc51aa979d280a636f7ecc5ea38dc
Author: David Mitchell <[email protected]>
Date: Fri Dec 25 12:03:00 2015 +0000
Document CxLVAL()
M cop.h
commit b9df7734ea952c22c0103a854fff7259e785341d
Author: David Mitchell <[email protected]>
Date: Fri Dec 25 11:51:37 2015 +0000
CX_POPFOO(): assert cx is of the right type
At the start of each CX_POPFOO(cx) macro, add an assertion that cx is of
type CXt_FOO.
M cop.h
commit e8d4c93497647f5503b4f5a7bcc96ad03928641e
Author: David Mitchell <[email protected]>
Date: Fri Dec 25 11:07:28 2015 +0000
rename POPFOO() to CX_POPFOO()
Rename all the context-popping macros such as POPBLOCK and POPSUB, by
giving them a CX_ prefix. (Do TOPBLOCK too).
This is principally to deliberately break any existing non-core use of
these non-API macros, as their behaviour has changed in this branch.
In particular, POPBLOCK(cx) no longer decrements the cxt stack pointer
nor sets cx; instead, cx is now expected to already point to the stack
frame which POPBLOCK should process.
At the same time, giving them a CX_ prefix makes it clearer that these
are all part of a family of macros that manipulate the context stack.
The PUSHFOO() macros will be renamed in a later commit.
M cop.h
M ext/XS-APItest/APItest.xs
M op.c
M perl.c
M pp.c
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
M scope.c
M t/op/args.t
commit 73c77135f77c520a4ec9a9d4de41babd36cf606a
Author: David Mitchell <[email protected]>
Date: Thu Dec 24 23:12:37 2015 +0000
pp_redo()): reorder some stuff
It probably doesn't make any difference, but reorder the FREETMPS,
CX_LEAVE_SCOPE and TOPBLOCK so it matches the order we do things when
leaving a scope.
M pp_ctl.c
commit 3fbbae42ce275e6c4190cb3c0f4b43117ece5514
Author: David Mitchell <[email protected]>
Date: Thu Dec 24 22:37:48 2015 +0000
optimise bare 'next'
If a 'next' without a label appears directly in the scope of the current
loop, then skip searching the context stack for a suitable LOOP context.
M pp_ctl.c
M t/perf/benchmarks
commit 9bda2d1b08fbbfae306368336715a3ac853884e4
Author: David Mitchell <[email protected]>
Date: Thu Dec 24 21:48:23 2015 +0000
S_unwind_loop(): remove opname param
This is only used for error messages, and can be derived from
OP_NAME(PL_op); so for efficiency, don't pass it.
M pp_ctl.c
commit 2d6418b3434215e3d5e379ccd07bf8e9299ced04
Author: David Mitchell <[email protected]>
Date: Thu Dec 24 21:33:49 2015 +0000
S_unwind_loop(): return pointer rather than index
return &cxstack[cxix] rather than cxix, since this is what the caller
actually needs.
M pp_ctl.c
commit 1fac61bbf1e54a307f9c471aef77c2afe97cd1a4
Author: David Mitchell <[email protected]>
Date: Thu Dec 24 20:30:15 2015 +0000
factor out common actions in TOPBLOCK and POPBLOCK
M cop.h
commit 9605b68288aee6e4351ab41651d5659479d8f9c3
Author: David Mitchell <[email protected]>
Date: Thu Dec 24 19:44:05 2015 +0000
dounwind(): do a POPBLOCK for final cx frame.
Previously dounwind() relied on the caller to a TOPBLOCK or POPBLOCK
following the call to dounwind(). It's debatable who should be
responsible. Arguably its more efficient for dounwind() not to do a
POPBLOCK, since the caller will probably immediately follow on with
POPFOO; POPBLOCK for the next context frame anyway.
Logically however, dounwind() should do this, and its not possible
for the caller to do so retrospectively, as context frame cxstack_ix + 1
may have been overwritten by the time dounwind returns.
Also, the changes in this branch mean that the old PL_tmps_floor is now
saved in the context struct rather than on the save stack, so code that
does C<dounwind(-1); LEAVE_SCOPE();> will no longer automatically
restore PL_tmps_floor. With thiis commit, it will.
The change to pp_return reflects that we now need to copy any return args
*before* donwind() is called, so that "return $1" will mg_get($1) while
the correct (inner) PL_curpm is still in scope.
M pp_ctl.c
M t/op/sub.t
commit e04dacc4c786241da301af6583de67b5d3421737
Author: David Mitchell <[email protected]>
Date: Mon Dec 21 16:33:57 2015 +0000
pp_break(): don't use TOPBLOCK
It appears to be using TOPBLOCK purely for its effect of resetting
PL_stack_sp. Since the next op will be pp_leavegiven which will do a
POPBLOCK, the other actions of TOPBLOCK are redundant. So just set
PL_stack_sp directly.
M pp_ctl.c
commit dda93a4b97cb7003026e4ba8ab626968301f4c86
Author: David Mitchell <[email protected]>
Date: Mon Dec 21 16:00:59 2015 +0000
tweak POPLOOP and CXt_LOOP_* order
Re-arrange the order of the CXt_LOOP_* to make it easier for compilers
to produce efficient code, and tweak POPLOOP so that the code for
freeing ary and cur is shared (as they occupy the same position in the
union).
M cop.h
commit af209f94a6b984aeeb962930dce3fe68f880314c
Author: David Mitchell <[email protected]>
Date: Mon Dec 21 15:45:57 2015 +0000
fix CxFOREACH
It wasn't detecting CXt_LOOP_LAZYIV as a 'for' loop type. This only
affected 'given' and 'break' (which need to distinguish between being
in a 'given' block and being in a 'for' block).
M cop.h
M t/op/switch.t
commit e08fe866939873177ef3750f54d9e97c53ce0cfd
Author: David Mitchell <[email protected]>
Date: Mon Dec 21 13:32:13 2015 +0000
only set CXp_FOR_DEF with CXp_FOR_GV
C<for (...)> is a special-case of C<for $pkg_var (...)>, so CXp_FOR_DEF
should only be set when CXp_FOR_GV also is. So in pp_enteriter(), only
test for (PL_op->op_private & OPpITER_DEF) in the GV branch and assert
that it's otherwise unset. This is slightly more efficient in the non-GV
branches.
Also add some more commentary to the CXp_FOR_* flag definitions.
M cop.h
M pp_ctl.c
commit 45fb1da9c39bb908c5589ea40fc950bf20c793e3
Author: David Mitchell <[email protected]>
Date: Fri Dec 18 22:09:58 2015 +0000
give POP_SAVEARRAY() macro a cx arg
rather than just assuming that there's a 'cx' var in scope
M cop.h
M pp_ctl.c
commit f3ace0ff73a7abc1430a6dd2373f7192a501a9cf
Author: David Mitchell <[email protected]>
Date: Fri Dec 18 22:07:25 2015 +0000
clarify code comment in pp_goto(()
M pp_ctl.c
commit d7a79f696d793e1f68fc9a5adeeddb94adb187af
Author: David Mitchell <[email protected]>
Date: Fri Dec 18 21:33:10 2015 +0000
APItest.xs: fixup clone_with_stack()
Make the unwinding and freeing of the old interpreter up to date
with the latest handling of PL_scopestack.
M ext/XS-APItest/APItest.xs
commit 8069cfd21e56b4a3eb790ef37d9427d36e51944a
Author: David Mitchell <[email protected]>
Date: Fri Dec 18 20:18:13 2015 +0000
fixup cx_dup()
By visual inspection, tweak bits of the context stack duplicating code
to reflect recent changes in this branch, especially new fields, or
whether fields hold a reference count or not.
Since I don't use Windows, this has largely been done blind.
M sv.c
commit 267b4b8ba08abfd443dde4dcad38149ad69a978e
Author: David Mitchell <[email protected]>
Date: Fri Dec 18 16:36:54 2015 +0000
pp_iter: optimise integer setting in for (1..10) {}
If the target SV is a simple SVt_IV, which it is likely to be,
just update it directly rather than calling sv_setiv()
M pp_hot.c
commit bcf9b6f452f625ddb904468d9d2eb3ae6f2fb507
Author: David Mitchell <[email protected]>
Date: Fri Dec 18 15:09:42 2015 +0000
fix *_ = "" for 0 .. 1;
RT #123994
pp_iter couldn't handle GvSv(gv) being NULL.
In that ticket, Tony Cook suggested two possible fixes. First,
always instantiate the GvSV slot at the start of pp_iter by using
GvSVn rather than GvSV in the CxITERVAR() macro;
Second, test for it being null within the two 'range' branches,
(for(1..9), for('a'..'z')), and if so create it. One advantage of doing
it there is that there's already code for (re)creating the SV if the
reference count is != 1. It also means that the list and array cases
(for(@a), for(1,3,5)) which always put the next iterated SV into the
pad/GvSV slot don't waste time creating and then immediately discarding an
SV if GvSV was NULL.
I went for the second fix.
It also means that's there's no longer any need in pp_enteriter to
initially poulate GvSV is it was null, as this will be detected during
the first pp_iter() anyway.
M pp_ctl.c
M pp_hot.c
M t/op/for.t
commit 93fbcd7e3547489dbef32308303dfe9e76f89ec0
Author: David Mitchell <[email protected]>
Date: Fri Dec 18 12:34:37 2015 +0000
pp_enteriter: use efficient SvREFCNT_inc variant
replace a couple of SvREFCNT_inc() with SvREFCNT_inc_simple_void_NN().
Also add a couple of code comments.
M pp_ctl.c
commit 288ee59518b248eed6b778ff72370c8efc9b0580
Author: David Mitchell <[email protected]>
Date: Thu Dec 17 17:50:52 2015 +0000
provide some basic documentation for Perl_dounwind
M pp_ctl.c
commit 22769fa668afcad83ea047fdad27efe9c656295f
Author: David Mitchell <[email protected]>
Date: Thu Dec 17 17:34:36 2015 +0000
TOPBLOCK: make comment clear its used by goto too
M cop.h
commit 24152d958a429b78060fa72e801b6cc92f3a1794
Author: David Mitchell <[email protected]>
Date: Thu Dec 17 17:30:48 2015 +0000
POPSUB_ARGS: move a code comment to the right line
M cop.h
commit fc2ed1f097a4897ef69417859d1f9732ff593675
Author: David Mitchell <[email protected]>
Date: Thu Dec 17 12:37:17 2015 +0000
pp_ctl.c: s/newsp/oldsp/g
There are various pp_leavefoo() functions that have similar code along the
lines of
SV **newsp;
newsp = PL_stack_base + cx->blk_oldsp;
Rename all these vars to 'oldsp' to reduce the cognitive dissonance.
The name 'newsp' was a hangover from when POPBLOCK used to implicitly
set a var called 'newsp.
M pp_ctl.c
commit 3742e46688a01ebe562b56f246b727df0c73a9ed
Author: David Mitchell <[email protected]>
Date: Thu Dec 17 12:13:09 2015 +0000
replace leave_common() with leave_adjust_stacks()
Make the remaining callers of S_leave_common() use leave_adjust_stacks()
instead, then delete this static function.
This brings the benefits of freeing TEMPS on all scope exists that
has already been introduced on sub exits; uses the optimised code for
creating mortal copies; and finally unifies all the different 'process
return args on scope exit' implementations into single function.
M embed.fnc
M embed.h
M pp_ctl.c
M pp_hot.c
M proto.h
M t/op/do.t
M t/op/grep.t
commit 0dbb1bbd4dfca7fa2dca79ab7f36a5bf01c6a866
Author: David Mitchell <[email protected]>
Date: Wed Dec 16 14:52:22 2015 +0000
make pp_return() use leave_adjust_stacks()
It was using S_leave_common(), but that's shortly to be removed. It also
required adding an extra arg to leave_adjust_stacks() to indicate where to
shift the return args to. This will also be needed for when we replace the
remaining uses of S_leave_common() with leave_adjust_stacks().
M embed.fnc
M embed.h
M pp_ctl.c
M pp_hot.c
M proto.h
commit 74fff70f8b0f6062fd313e9634a80aadb6d00bbd
Author: David Mitchell <[email protected]>
Date: Wed Dec 16 12:30:01 2015 +0000
make pp_leavesublv use S_leavesub_adjust_stacks()
Currently S_leavesub_adjust_stacks() is just used by pp_leavesub.
Rename it to Perl_leave_adjust_stacks(), extend its functionality
slightly, then make pp_leavesublv() use it too.
This means that lvalue sub exit gains the benefit of FREETMPS being done,
and (where mortal copying needs doing) the optimised copying code.
It also means there is now one less version of the "process args on scope
exit" code.
pp_leavesublv() still does a scan of its return args looking for things to
croak() on, but leaves everything else to leave_adjust_stacks().
leave_adjust_stacks() is intended shortly to be used in place of
S_leave_common() too, thus unifying all args-on-scope-exit code.
The changes to leave_adjust_stacks() in this commit (apart from the
renaming and doc changes) are:
* a new arg to indicate what condition to use to decide whether to
pass or copy the arg;
* a new branch to mortalise and ref count bump an arg
M embed.fnc
M embed.h
M pp_ctl.c
M pp_hot.c
M proto.h
commit 56d72c5303391615825ca8c1282204fcae111918
Author: David Mitchell <[email protected]>
Date: Mon Dec 14 12:10:45 2015 +0000
pp_leavesublv(): document PL_sv_undef exception
M pp_ctl.c
commit ffab7e0fa4131be6cba0dab0b85f2997d879ae96
Author: David Mitchell <[email protected]>
Date: Mon Dec 14 11:55:14 2015 +0000
pp_leavesublv(): croak on *all* PADTMPs
pp_leavesublv() generally croaks on returned PADTMPs when called in lvalue
context. However, an exception was made in scalar context if the PADTMP
had set magic. This was to allow for things like
sub :lvalue { $tied{foo} }
and
sub :lvalue { substr($foo,1,2) }
However, it was later found that in places like pp_substr(), when
returning a PVLV, it should return a new mortal rather than upgrading
its pad target to PVLV, because the PVLV holds a reference to $foo which
then gets delayed being freed indefinitely.
Since places like pp_susbtr() no longer return lvalue PADTMPs, there's
no longer any need to make a special exception in pp_leavesublv().
I've added an assertion to the effect that PADTMPs don't have set
container magic, but I've added the assert to pp_leavesub() rather than
pp_leavesublv(), since the former is much likely to be used in many weird
situations and edge cases that would quickly flush out any false
assumptions.
If this assumption is wrong and the exception needs to be re-instated in
pp_leavesublv(), then presumably it needs adding to the ARRAY context
branch too - I'm assuming that its previous absence there was an oversight;
i.e.
sub foo :lvalue { $tied{foo}, substr($foo,1,2) }
foo() = (1,2);
should work too.
M pp_ctl.c
M pp_hot.c
commit 0f6ff17ea8bafca698c3c0c035c806e13ded960a
Author: David Mitchell <[email protected]>
Date: Sun Nov 8 15:16:09 2015 +0000
pp_leavesub(): call FREETMPS and optimise
Currently pp_leavesub() doesn't call FREETMPS. Presumably this is due to
the danger of freeing temps that need to exist beyond the return, such
as the mortal copies we make of return args, or return args that are
already temps.
The down side of this is that temps aren't freed until the next nextstate
is executed following the function call. If the function isn't near a
statement boundary, then it may be a while before temps are freed; e.g.
in f(g()), when g() returns, its temps continue to exist during the call
to f(). For recursive subs it gets worse, although there is a specific
hack already in pp_leavesub() that says in scalar context if CvDEPTH > 1,
then temporarily RC++ the single return value then do a FREETMPS. This
can in theory leak if something dies during the FREETMPS.
This commit provides a more general solution. During the course of
processing (usually mortal copying) the return args, it divides the
current temps stack frame into two halves, with the temps that need
keeping migrating to the bottom half. It then does a FREETMPS equivalent
only of the top half.
This is actually more efficient than it sounds; but in addition, the code
has been heavily optimised: in particular the call to sv_mortalcopy()
has been unrolled and inlined, and within that code common cases (such as
IV, RV) handled directly, and the mortal stack is only checked/extended
once, rather than for every arg.
Also, the arg adjust / freetmps code has been moved out of pp_leavesub()
and into a separate static function.
M pp_hot.c
M t/op/sub.t
M t/perf/benchmarks
commit 755bb9868723d3f1093401a8ddee2df47d343469
Author: David Mitchell <[email protected]>
Date: Fri Dec 4 15:50:54 2015 +0000
move SET_SVANY_FOR_BODYLESS_IV() from sv.c to sv.h
Ditto for SET_SVANY_FOR_BODYLESS_NV.
The IV variant will shortly be needed in pp_hot.c, so make it
available outside sv.c. For now, protect with #ifdef PERL_CORE,
so as little as possible is changed by this commit.
M sv.c
M sv.h
commit 235b1bb89c000f317c2195bcf19dc1561d6cf034
Author: David Mitchell <[email protected]>
Date: Mon Nov 16 14:40:04 2015 +0000
Perl_runops_debug(): do FREETMPS
In runops_debug() wrap the optional printing of next op, arg stack
etc with ENTER/SAVETMPS, FREETMPS/LEAVE - so that temporaries created by
the dump output are promptly freed, and thus don't alter the tmps stack.
(I'm trying to debug some tmps stack corruption, and running with -Dst
made the problem go away).
M dump.c
commit c95210d892924f1e40c754b58f4738fde7e192e0
Author: David Mitchell <[email protected]>
Date: Mon Nov 9 21:11:58 2015 +0000
optimise sv_setsv_flags()
This commit does two things.
First, it streamlines and re-orders some of the initial tests,
such as 'is sstr already freed?'.
Second, it looks for a reasonably common case where both sstr and dstr are
SVt_NULL/SVt_IV. This covers undef, int and refs, where the SV hasn't
previously been used for other things (like strings).
With just SVt_NULL/SVt_IV, we know that the SV won't have a real body, and
won't need one and can be very quick.
The check for SVt_NULL/SVt_IV is a single compare-and-branch, so
has a minimal effect on users of sv_setsv_flags() that have more complex
types.
M sv.c
M t/perf/benchmarks
commit 9dd929f126adc4a1ca865ba7e8448b5123021efe
Author: David Mitchell <[email protected]>
Date: Sun Nov 8 20:08:20 2015 +0000
intrvar.h: document PL_tmps_max
Its name implies that it's the top allocated element; in fact it's top+1.
M intrpvar.h
commit 2b7bf8d5bdce06f73cf7705d4259ed7fb00d4b72
Author: David Mitchell <[email protected]>
Date: Sun Nov 8 15:05:01 2015 +0000
pp_leavesub: reset SP in void context
In void context, pp_leavesub() doesn't bother resetting SP to the
base; either as an efficiency measure, or as an oversight (the other
pp_leavefoo functions do reset).
This is mostly harmless, as being void context, it's likely to immediately
execute pp_nextstate or similar, which will reset the stack anyway.
However with attributes, something like
my @foo :attr = ()
causes attributes::import() to be called in void context, and whatever
dross it leaves on the stack becomes part of the assign, i.e. that assign
becomes the equivalent of:
my (@foo, dross) = ()
which again is fairly harmless, if slightly inefficient.
However, the next commit should make pp_leavesub() call FRETMPS,
which means that 'dross' may now include freed SVs, which will make
pp_aassign choke.
This commit also requires ext/XS-APItest/t/call.t to be fixed.
Some tests in there (added years ago by myself) test the statu quo; that
is, it expects that calling call_sv(G_VOID) will leave return args on the
stack. Now it doesn't.
M ext/XS-APItest/t/call.t
M pp_hot.c
commit 72eb0dc9de2c82d6225233e411cd801afe8b33f1
Author: David Mitchell <[email protected]>
Date: Sun Nov 8 19:19:02 2015 +0000
Perl_free_tmps(): don't test for PL_sv_undef
Each sv being popped off the tmps stack is compared against PL_sv_undef,
and if so, the SvTEMP_off(sv); SvREFCNT_dec_NN(sv); is skipped.
This condition was added by 8aacddc1 back in 2001, as part of a commit
to add support for hash placeholders. Initially it used &PL_sv_undef in
HE value slots to indicate a placeholder. In a later commit, that was
changed to &PL_sv_placeholder, but the test in free_tmps() continued
to test against &PL_sv_undef.
Im not sure what the original intent was, but I strongly suspect that
whatever purpose it may have originally served, it no longer served that
after the switch to PL_sv_placeholder.
On a purely pragmatic note, I can't see any harm in untemping PL_sv_undef;
at worst its ref count will occasionally reach 0, and the special code in
sv_free2() will reset its count to SvREFCNT_IMMORTAL. And no tests
fail....
M scope.c
commit 58df1d69dd3169b854c72a50aea099885d0692c5
Author: David Mitchell <[email protected]>
Date: Wed Oct 28 08:28:56 2015 +0000
restore PL_tmps_floor on exit
A couple of places were expecting dounwind(-1); LEAVE_SCOPE(0);
to restore PL_tmps_floor, since its old value was saved on the savestack.
Since that's now stored in the context struct instead, do
a POPBLOCK(&cxstack[0]).
This problem only showed up on 'make test' rather than 'make
test_harness', since only the former sets PERL_DESTRUCT_LEVEL.
M ext/XS-APItest/APItest.xs
M perl.c
commit 5e5c55e7e4e5763cc3cf7e741c883121de3a4509
Author: David Mitchell <[email protected]>
Date: Wed Oct 21 19:10:34 2015 +0100
extend magic copy test to all scope exit types
Commit v5.15.6-387-g6f48390 forced leavesub to copy returned items
if they were get-magical. Normally rvalue subs are supposed to return a
copy of their return args, but that copy is sometimes skipped if leavesub
thinks the side-effects will never be visible. Tied elements was an
example where the implementation leaked.
However, this applies equally well to other leave types, such as
do { ....}, so test for get magic in those too.
M pp_ctl.c
M t/op/gmagic.t
commit 324d6cdf2edd072629cf4f0ca4f3bf8bca600db2
Author: David Mitchell <[email protected]>
Date: Wed Oct 21 17:54:29 2015 +0100
test that pp_leavesub copies returned PADTMPs.
Although pp_leavesub() has in fact always done this, it was never actually
tested for.
M t/op/sub.t
commit 7bf06417428c35c5681f8ca4f12933a0a3d78bd2
Author: David Mitchell <[email protected]>
Date: Wed Oct 21 13:10:44 2015 +0100
Always copy return values when exiting scope
v5.14.0-642-g3ed94dc fixed certain instances where returning from a sub
incorrectly returned the actual value rather than a copy, e.g.
sub f { delete $foo{bar} }
This was because if the value(s) being returned had SvTEMP set, copying
was skipped. That commit added an extra condition to the skip test,
SvREFCNT(sv) == 1.
However, this applies equally well to other scope exits, for example
do { ...; delete $foo{bar} }
So this commits adds the RC==1 test to S_leave_common() too, which handles
all the non-sub scope exits. As well as adding a test to do.t, it adds an
additional test to sub.t, since the original tests, although they
*detected* a non-copied return, didn't actually demonstrate a case where
it was actually harmful.
Note that S_leave_common() also sometimes skips on PADTMPs as well as
TEMPs, so this commit as a side-effect also makes it copy PADTMPs unless
their RC ==1. But since their RC should in fact almost always be 1 anyway,
in practice it makes no difference.
M pp_ctl.c
M t/op/do.t
M t/op/sub.t
commit 69af269c4b931ad077a714b20636c6ba46d20234
Author: David Mitchell <[email protected]>
Date: Wed Oct 21 12:28:35 2015 +0100
op/sub.t: fix ticket number in comment
Took me a while to track down that non-existent ticket!
M t/op/sub.t
commit 0b30938429f367ca4234f549f5c542d7537f8d6c
Author: David Mitchell <[email protected]>
Date: Wed Oct 21 09:47:21 2015 +0100
make TOPBLOCK(cx) not set cx
i.e. replace
TOPBLOCK(cx);
with
cx = CX_CUR();
TOPBLOCK(cx);
This is part of general trend of separating out the cx/cxstack_ix
setting/manipulation from the save/restore actions
M cop.h
M pp_ctl.c
commit 35d88e3f928140219debd7803b1b2713b2d25124
Author: David Mitchell <[email protected]>
Date: Wed Oct 21 09:41:52 2015 +0100
rename DEBUG_CX() to CX_DEBUG()
For consistency with the new naming convention for context-stack macros.
Also, give it a cx arg rather than using CX_CUR()
M cop.h
M pp_ctl.c
commit f82275bcdad319b204039cab62936581841a6be5
Author: David Mitchell <[email protected]>
Date: Wed Oct 21 09:28:52 2015 +0100
add CX_CUR() macro
This is simply
#define CX_CUR() (&cxstack[cxstack_ix])
M cop.h
M op.c
M perl.c
M pp.c
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
M toke.c
commit 93829347f1857ed53fdfe7e86374a1c48aa0bcac
Author: David Mitchell <[email protected]>
Date: Mon Oct 19 17:21:58 2015 +0100
make POPSUBST re-entrant safe
M cop.h
commit c12cf74ce5f6c3633dd47a203d96935fa2b61758
Author: David Mitchell <[email protected]>
Date: Mon Oct 19 17:14:58 2015 +0100
make POPGIVEN re-entrant safe
M cop.h
commit 8816cc4cba30530667522f9f0e5f3c1902385235
Author: David Mitchell <[email protected]>
Date: Mon Oct 19 17:04:02 2015 +0100
make POPSUB re-entrant safe
M cop.h
commit dd75806efb74fd894bd2273ec4732ba8cf10cc3f
Author: David Mitchell <[email protected]>
Date: Mon Oct 19 16:46:06 2015 +0100
make POPEVAL safe against re-entrancy
M cop.h
commit f53633cf5b189186324c5688ba2eb3130e46e3f8
Author: David Mitchell <[email protected]>
Date: Mon Oct 19 16:12:33 2015 +0100
make POPSUB and POPFORMAT re-entrant safe
In code like
sub DESTROY { exit }
sub f { push @_, bless [] }
f()
While leaving f, POPSUB will attempt to clear @_. This triggers the
destructor, which calls exit, which unwinds the context stack, calling
POPSUB again on thr same context stack entry.
Thus we need to to be careful that POPSUB can be called multiple times
on the same CX stack entry.
The general way of doing this is to NULL or update pointers *before*
calling SvREFCNT_dec() on the old value.
This commit also removes the old CxPOPSUB_DONE mechanism which was a poor
bandaid added at the last minute to 5.22 to try and achieve the basics
of what this commit does comprehensively (hopefully). Also, CxPOPSUB_DONE
was mainly a protection against re-entrantly calling LEAVE_SCOPE(). Since
that's now done before POPSUB rather than in the middle of it, it has
become reentrant-safe by default.
M cop.h
M pp_hot.c
M pp_sys.c
commit 9e9e06813b1aff203861972902880e0e634d7a8a
Author: David Mitchell <[email protected]>
Date: Sat Oct 17 15:22:05 2015 +0100
reorder 'struct block' fields.
On 64-bit builds, there was a 32-bit hole near the beginning. Shuffle this
towards the middle of the struct (just before the blk_u union).
Unfortunately this (moved) hole can't be filled by having an I32 at the
start of each union member, since struct block_eval is already the largest
and has no 32-bit fields.
Still, moving further on than some of the hotter fields can't hurt.
M cop.h
commit ef6315337a8ee83af4fd218a0a3743c51f6fa8be
Author: David Mitchell <[email protected]>
Date: Sat Oct 17 14:52:50 2015 +0100
move and rename cx_old_savestack_ix
Earlier on in this branch I temporarily added cx_old_savestack_ix
as the first element in the context struct. This commit moves it down
32 bits so it now follows type/gimme/u16 in the sbu and blku unions.
This means that type is now back as the first item in the struct.
I've also renamed it blku_oldsaveix to be more in keeping with similar
field names.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M scope.c
commit 3f5a600b8276c2df377709f1ea1311c201efd39a
Author: David Mitchell <[email protected]>
Date: Sat Oct 17 13:24:30 2015 +0100
simplify two conditions in pp_iter:
- if (UNLIKELY(SvMAGICAL(av) || AvREIFY(av))) {
+ if (UNLIKELY(SvRMAGICAL(av))) {
This condition is deciding whether to call av_fetch or cheat and do
sv = AvARRAY(av)[ix].
The magic test is too broad: av_fetch() only handles the specially on
RMG, not all magic.
The AvREIFY condition was originally added by 64138690 in 2001. It was
an attempt to paper over the cracks if function args are deleted, then
iterate over @_, which now contains freed elements. Since pp_iter now
includes a 'freed sv' check itself, there's no need to call into av_fetch
which has a similar check.
This makes a slight functional change - previously if @_ contained a freed
element, av_fetch would silently return NULL; now instead, pp_iter
croaks with "Use of freed value in iteration", the same as it does with
all other cases involving freed elements being iterated over.
M pp_hot.c
M t/run/fresh_perl.t
commit 7dfe2aec7da5022d955a534a51374df793ccc9d1
Author: David Mitchell <[email protected]>
Date: Sat Oct 17 13:15:06 2015 +0100
PUSHLOOP_PLAIN: don't set unused fields
Currently PUSHLOOP_PLAIN sets a whole unch of fields that it isn't going
to ue to NULL or 0, e.g. blk_loop.itersave.
Skip this and leave them wild. Make cx_dump() not try to dump them for
CXt_LOOP_PLAIN
M cop.h
M scope.c
commit ac03321dc0fa2c16a7d099d93fce589f2cd16c8c
Author: David Mitchell <[email protected]>
Date: Sat Oct 17 12:56:15 2015 +0100
Eliminate cx->blk_loop.resetsp
Of all the loop types, only CXt_LOOP_LIST, i.e. for (1,2,3) {},
needs to keep anything on the stack, i.e. for all the others,
cx->blk_loop.resetsp can always equal cx->blk_oldsp.
For CXt_LOOP_LIST, the same value as resetsp is stored as
blk_loop.state_u.stack.basesp.
So we can eliminate the resetsp field. This is good as the loop substruct
is the largest (ITHREADS) or joint largest with eval (non-threaded).
Also, we now don't have to store that value for non-CXt_LOOP_LIST loops.
The downside is we now have to choose between basesp and oldsp in
pp_leaveloop and pp_last, based on CX type.
M cop.h
M pp_ctl.c
M scope.c
commit 546f1246aa5752002e1d6cd21eff1cc3e6749ee7
Author: David Mitchell <[email protected]>
Date: Sat Oct 17 10:53:10 2015 +0100
pp_iter(): optimise stack handling
Make pp_enteriter() do EXTEND(SP,1); then there's no need for pp_iter() to
check for space to push PL_sv_yes/no each time round the loop.
Since the only stack manipulation in pp_iter is now just pushing a boolean
at the end, remove dSP etc and just directly push to PL_stack_sp at the
end.
M pp_ctl.c
M pp_hot.c
commit ea104d4f378926f932c8c5045aaf75625b165c8b
Author: David Mitchell <[email protected]>
Date: Sat Oct 17 00:18:44 2015 +0100
split CXt_LOOP_FOR into CXt_LOOP_LIST,CXt_LOOP_ARY
Create a new context type so that "for (1,2,3)" and "for (@ary)"
are now two separate types.
For the list type, we store the index of the base stack element in the
state union rather than having an array pointer. Currently this is just
the same as blk_resetsp, but this will shortly allow us to eliminate the
resetsp field from the struct block_loop - which is currently the largest
sub-struct within the block union.
Having two separate types also allows the two cases to be handled directly
in the main switch in the hot pp_iter code, rather than having extra
conditionals.
M cop.h
M lib/B/Op_private.pm
M opcode.h
M perl.h
M pp_ctl.c
M pp_hot.c
M regen/op_private
M scope.c
M sv.c
commit ec35a8cfee6da64f0e24d8eab6643f6ba719eab0
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 16:20:47 2015 +0100
benchmarks: add some 'for' array iterating
M t/perf/benchmarks
commit 4169d4e75b7d1e08e2fbbc88065cf078094d149e
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 14:32:26 2015 +0100
stop S_undo_inc_then_croak() doing CX_POP
I added this static function several commits commits ago but in hindsight
I don't like that a cx is passed to it and it does a CX_POP(cx). This is
too much like action at a distance. Instead make the caller save
cx->blk_eval.old_namesv and do the CX_POP itself, then pass namesv as an
arg.
M pp_ctl.c
commit 65a4a0fc33c2a15a25e5e57e7400c9283ead29e4
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 13:31:57 2015 +0100
pp_leaveeval: reset stack in VOID context
$ perl -Dst -e'eval"1"'
Gives:
....
((eval 1):1) leaveeval
=> (FREED)
Change it so that like all the other pp_leavefoo() functions, it does
if (gimme == G_VOID)
PL_stack_sp = newsp;
I can't think of any (non-debugging) perl-level badness the old behaviour
can be shown to demonstrate, but best not to have freed values left
dangling.
This also allows pp_leaveeval() to (like the other pp_leavefoo functions)
avoid doing a dSP with the associated unnecessary PUTBACKs and SPAGAINs.
Finally, the code to detect a false require is moved to earlier in the
function where it's in the same place as the rest of the stack arg
processing code.
M ext/XS-APItest/t/call.t
M pp_ctl.c
commit f393797d403c70ceef0146d247e43a24d0cf4d6f
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 13:07:23 2015 +0100
rename S_doeval() to S_doeval_compile()
This makes it a bit more obvious what niche in the "eval" ecosystem
that it occupies.
M cop.h
M embed.fnc
M embed.h
M pp_ctl.c
M proto.h
M t/op/eval.t
commit 10b5eca435f7d2d02f0195aca64fe0779c0ba3f4
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 12:19:44 2015 +0100
S_doeval(): tidy up comments
Also, replace
if (...) {
...
return;
}
else
B
with
if (...) {
...
return;
}
B
M pp_ctl.c
commit 887b4e1df7e938bd2c2cd742a14526fbe9d3d46e
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 12:00:46 2015 +0100
remove obsolete panic from die_unwind()
It panics if the context it has just popped back to isn't a CXt_EVAL.
Since we have just called dopoptoeval() which can only pop to an eval, and
since we assert that its an eval, this seems such an unlikely "this can
can never happen" that it doesn't really seem worth testing for.
It was added in perl5.000, and may have made slightly more sense then, as
there used to be a POPBLOCK just before it.
M pod/perldiag.pod
M pp_ctl.c
commit cd3a4aba85dfc45640ec394291b9f617acd78fef
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 11:33:43 2015 +0100
pp_return: avoid potential CX stack realloc prob
M pp_ctl.c
commit 4b036c6caf517f695e33dc5165c7d730e5b0d2ee
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 11:25:42 2015 +0100
Perl_die_unwind(): remove unneeded assert
Now that the order of things has changed, PL_curcop will always have just
been restored at this point. So there's no longer any needs to assert that
its the correct value.
M pp_ctl.c
commit 81de3572f835d1629ad5c3c03bd9a450eb47682b
Author: David Mitchell <[email protected]>
Date: Fri Oct 16 00:03:00 2015 +0100
add S_undo_inc_then_croak()
Consolidate into a single static function, code in 3 functions that all
'undo' an added %INC entry on failure, then croak.
M pp_ctl.c
commit cb2096d5648cc52afc6db5b5e67174b5fb8db715
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 22:27:03 2015 +0100
POPEVAL: don't set optype
don't quietly set the local var optype; instead explicitly set it
in the couple of places its actually needed. This allows us to
get rid of a bunch of PERL_UNUSED_VAR(optype);
M cop.h
M pp_ctl.c
commit 7c252daed6e7d6300fad0e9e9882e1e36363cd1d
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 17:46:31 2015 +0100
add CX_POP(cx) macro: glorified cxstack_ix--
but with extra checking goodness on debugging builds.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
commit 9b96883f49f6c97f7e75c1bfb6b1b998171932ef
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 16:59:19 2015 +0100
simplify CHANGE_MULTICALL_FLAGS
But using POPSUB_COMMON(), we achieve commonality. This incurs the extra
overhead of restoring PL_comppad/PL_curpad, which is compensated for by
not having to temporarily protect PL_comppad in the following PUSHSUB.
M cop.h
commit 0da0a35490da8da26fa025b39f7e7ad5a94ebabc
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 16:03:34 2015 +0100
remove redundant croak code in pp_leavesublv
Just before a code path that croaks, it does a POPSUB etc.
Since this will be done by the unwind following the croak anyway, it's
redundant.
M pp_ctl.c
commit 60307578af5420a4aa4632e7485e6e7a334b388d
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 15:50:08 2015 +0100
factor common code into POPSUB_ARGS()
Some code that is common to POPSUB() and pp_coreargs, extract out
into a common macro. (There's some almost identical code in pp_goto,
so add a note there).
This makes pp_coreargs slightly less efficient, since it now tests for
AvREAL(av), when that should never be true. But it's not exactly hot code.
M cop.h
M pp.c
M pp_ctl.c
commit 0ab90e7af01448d3a9bf7ec81601659dd0d4d00f
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 15:39:42 2015 +0100
pp_coreargs: rationalise @_ code
Make the code in pp_coreargs that cleans up @_ more like the code in
POPSUB, so that the two can eventually be extracted out into a common
macro.
M pp.c
commit eb8ac6e534b853ca1630aa326580159dd9fe5dbe
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 14:58:35 2015 +0100
split some common POPSUB code into a macro
POP_MULTICALL duplicates some of the code in POPSUB, so extract it
out into a common macro.
M cop.h
commit d1b83f3bc579686df82d83163306be25b8b01629
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 14:36:59 2015 +0100
make POPSUBST not cxstack_ix--
For consistency with with the new POPBLOCK, make POPSUBST(cx) no longer
set c nor decrement cxstack_ix. This also makes dounwind more consistent.
M cop.h
M pp_ctl.c
commit bcd19b823f240388a4b52cfeee1360c7515849e0
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 14:28:28 2015 +0100
dowinwind(): move common CX_LEAVE_SCOPE() outside
Now the every branch in the switch does CX_LEAVE_SCOPE(cx), hoist it
above the satrt of the switch.
M pp_ctl.c
commit 6cd3087d8e940e44b8fdd0917f9ae0d3c4300d0e
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 14:26:21 2015 +0100
dounwind: CX_LEAVE_SCOPE for CXt_SUBST too
This was the only branch that didn't clear up the context stack as
part of a context stack unwind.
M pp_ctl.c
commit 24ba3eb31660a6ee278f7290810a52c14ea3ea3c
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 14:15:57 2015 +0100
move blku_old_savestack_ix to base of cxt struct
The previous commit moved the "old savestack" field of substitution
contexts into the shared root of the context union. This commit does the
same for all other context types
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
commit e4553b06dd10da01f4c4c7c5206082b6e8fd96c3
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 14:04:09 2015 +0100
move sbu_oldsave into base of CX struct
the context struct is a union of two basic types: the substitution context
and everything else.
This commit moves the sbu_oldsave field from the substitution context
into the base of the context struct, so that the next commit will allow
the same field (and macros) to be used by *all* context types.
M cop.h
M pp_ctl.c
commit 3191127446ba9d4f1eeb75e79dcbc48485205c22
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 13:48:25 2015 +0100
move CX_LEAVE_SCOPE outside the POPFOO's
Currently every POPFOO macro has CX_LEAVE_SCOPE(cx) as its first action.
Since this is common code and not specific to a particular POPFOO type,
remove it from each POPFOO macro and make each caller of POPFOO explicitly
call CX_LEAVE_SCOPE() instead.
This should make no functional difference (but will help if you're
single-stepping the code in a debugger :-)
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
commit 2d2ab7f61dadf7bfafe3f1b55d95c91d8677a919
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 11:47:07 2015 +0100
do PL_tmps_floor save in PUSHBLOCK
Currently every individual PUSHFOO type does
cx->cx_u.cx_blk.blku_old_tmpsfloor = PL_tmps_floor;
PL_tmps_floor = PL_tmps_ix;
Move all these into PUSHBLOCK instead, which usually immediately precedes
the PUSHFOO.
M cop.h
M pp_sort.c
commit 9664c13a95ae79fd9a9903190fbc479ecbecfddc
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 11:34:41 2015 +0100
do PL_tmps_floor restore in POPBLOCK
Currently every individual POPFOO type does
PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor
as its last action.
Move all these into POPBLOCK instead, which always immediately follows
the POPFOO.
M cop.h
M pp_sort.c
commit 7dd5e012b9e1f81411de9bfbe3b0e3beb7ae9223
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 11:16:14 2015 +0100
sort(!) out CXt_NULL and CXp_MULTICALL
A sort BLOCK is done using a CXt_NULL context type. Currently it has
the CXp_MULTICALL flag set. Remove this flag so that CXp_MULTICALL is
only set on CXt_SUB contexts.
Also add code comments in various places explainging that CXt_NULL is
likely to a sort BLOCK, and fix the comments in pp_return which said
a particular code path was only taken by sort BLOCK; it's also taken
be (?{...}) too.
M cop.h
M pp_ctl.c
M pp_sort.c
M sv.c
M t/re/re_tests
commit 130c11ddf264e922d451e83dacd36391bc09fbf1
Author: David Mitchell <[email protected]>
Date: Thu Oct 15 08:52:18 2015 +0100
pp_sort: add missing CX_LEAVE_SCOPE()
The branch that does POPSUB has an implicit CX_LEAVE_SCOPE; the
other branch didn't; do add one for consistency. It's fairly harmless,
as pp_sort shortly afterwards does a LEAVE() anyway.
Also add an assertion to POPBLOCK that the save stack has been popped;
this is how I discovered the sort issue in the first place.
M cop.h
M pp_sort.c
commit bad854117881210713a78ba392105348af9a9767
Author: David Mitchell <[email protected]>
Date: Mon Oct 12 15:33:56 2015 +0100
remove newpm param from POPBLOCK() macro.
Since all core usage of POPBLOCK now immediately restores PL_curpm,
there's no need to copy the old value to a temp var specified by the
caller; just make POPBLOCK itself restore PL_curpm in the same way that
it restores all the other PL_ vars.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
commit 728600ddd43b8d36ad2b46b474dc2b7763725244
Author: David Mitchell <[email protected]>
Date: Mon Oct 12 14:56:35 2015 +0100
reverse the order of POPBLOCK; POPFOO
Currently most pp_leavefoo subs have something along the lines of
POPBLOCK(cx);
POPFOO(cx);
where POPBLOCK does cxstack_ix-- and sets cx to point to the top CX stack
entry. It then restores a bunch of PL_ vars saved in the CX struct.
Then POPFOO does any type-specific restoration, e.g. POPSUB decrements the
ref count of the cv that was just executed.
However, this is logically the wrong order. When we *enter* a scope, we do
PUSHBLOCK;
PUSHFOO;
so undoing the PUSHBLOCK should be the last thing we do. As it happens,
it doesn't really make any difference to the running, which is why we've
never fixed it before.
Reordering it has two advantages.
First, it allows the steps for scope exit to be the exact logical reverse
of scope exit, which makes understanding what's going on and debugging
easier.
It allows us to make the code cleaner.
This commit also removes the cxstack_ix-- and setting cx steps from
POPBLOCK; now we already expect cx to be set (which it usually already is)
and we do the cxstack_ix-- ourselves. This also means we can remove a
whole bunch of cxstack_ix++'s that were added immediately after the
POPBLOCK in order to prevent the context being inadvertently overwritten
before we've finished using it.
So in full,
POPBLOCK(cx);
POPFOO(cx);
is now implemented as:
cx = &cxstack[cxstack_ix];
... other stuff done with cx ...
POPFOO(cx);
POPBLOCK(cx);
cxstack_ix--;
Finally, this commit also tweaks PL_curcop in pp_leaveeval, since
otherwise PL_curcop could temporarily be NULL when debugging code is
called in the presence of 'use re Debug'. It also stops the debugging code
crashing if PL_curcop is still NULL.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
M regcomp.h
commit aff50cee8a5b1184892b856f8fa9e96373a63976
Author: David Mitchell <[email protected]>
Date: Mon Oct 12 12:02:05 2015 +0100
make PL_tmps_floor restore consistent
On scope exit this is done:
PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor;
This is mostly contained within the POPFOO macros; for those,
make it consistently the last entry in the macro. POPEVAL
didn't include this line; move it into the macro and out of the
various places where it's done explicitly.
This will allow us to move it into a revamped POPBLOCK macro shortly.
M cop.h
M pp_ctl.c
commit b4d39accd6d0198eaef1bba2b560af681f5885f3
Author: David Mitchell <[email protected]>
Date: Sun Oct 11 15:58:06 2015 +0100
simplify S_leave_common() and callers
Currently one of the args to S_leave_common() is supposed to be the
current stack pointer; it returns an updated sp. Instead make it get/set
PL_stack_sp directly.
e.g. in the caller, replace
dSP;
SP = S_leave_common(..., SP, ...);
PUTBACK;
with
S_leave_common(..., ...);
and in S_leave_common(), make it initially get PL_stack_sp, and before
returning, update PL_stack_sp.
M embed.fnc
M embed.h
M pp_ctl.c
M proto.h
commit c97df907a4d8a9eac0dd19590ed2782e8157218e
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 23:41:15 2015 +0100
eliminate weird gimme calc in pp_leave()
Some code in pp_leave that's been around in one form or another since
5.000, calculates the value of gimme in a complicated way, rather than
just using the saved value in the current context, like all the other
pp_leave* functions do.
I think this code is redundant; running the test suite with an assert that
the extra calculation doesn't change anything, doesn't produce any failures.
So out it goes.
(In particular. cxstack_ix can never be < 0 here.)
M pp_ctl.c
commit 491a9fbc926cb1481547884592748472a40db6c3
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 23:22:30 2015 +0100
eliminate LEAVESUB() macro
Many years ago, POPSUB was split into two parts, with a final cleanup
being done by the LEAVESUB() macro. After the previous commit, LEAVESUB
now always immediately follows POPSUB, so roll its action into the
last line of POPSUB and eliminate it.
This also allows us to remove the 'sv' parameter from POPSUB(), which
was needed purely to communicate to LEAVESUB() which var to process
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
commit da66c867cbcd6cf7a26daa64688550df524e59ec
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 23:10:23 2015 +0100
make LEAVESUB() always immediately follow POPSUB()
Many years ago, POPSUB was split into two parts, with a final cleanup
being done by the LEAVESUB() macro. This is no longer needed;
shuffle LEAVESUB up a bit in various places so that it always immediately
follows POPSUB. Then the next commit will eliminate it altogether.
M cop.h
M pp_ctl.c
M pp_hot.c
commit 667b370c31d6678a417643a2cc2fd060f8a62815
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 23:01:55 2015 +0100
move CX_LEAVE_SCOPE into POPEVAL
All the other POPFOO types have CX_LEAVE_SCOPE as their first action.
Add it as the first action of POPEVAL too, and remove all the explicit
calls to CX_LEAVE_SCOPE dotted around near POPEVALs.
Note that this causes a slight change in behaviour in dounwind:
the CX_LEAVE_SCOPE is now done as the first action of POPEVAL there
rather than being done afterwards. This is now consistence will all other
uses of POPEVAL.
M cop.h
M pp_ctl.c
commit c5097c105755743de38b654af5aaca79382b4744
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 22:49:46 2015 +0100
add CX_LEAVE_SCOPE(cx) macro
which is shorthand for
LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix)
This is the start of a new breed of macros designed to manipulate the
conetect stack, that have a CX_ prefix, that will eventually superede
the (PUSH/POP)(BLOCK/SUB/ETC) system.
M cop.h
M pp_ctl.c
M pp_hot.c
commit 330fe1a1c3510200799cd5ed8473891fcf1ee6be
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 22:38:54 2015 +0100
call LEAVE_SCOPE() before POPEVAL()
All the other POPFOO() types have
LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
as their first action.
POPEVAL doesn't include this. Instead, each place that does POPEVAL()
currently does a LEAVE_SCOPE() sometime shortly afterwards.
This commit moves all those LEAVE_SCOPE()s to just before each POPEVAL()
to make the behaviour like all the other context types.
This is the logically correct order: process all the savestack items
accumulated during the eval before popping the eval itself.
M pp_ctl.c
commit e954d303a79997427388125cf288305c20a3bd95
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 22:23:19 2015 +0100
POPBLOCK: don't set newsp and gimme
This macro used to set these two vars as a side-effect.
Since we now usually access those values before we call POPBLOCK,
it's wasteful to set them again.
M cop.h
M pp_ctl.c
M pp_sort.c
M pp_sys.c
commit 916a3df2b8f3da41a33e8e4eefb8d9c956f98ec5
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 16:31:28 2015 +0100
move POPBLOCK after arg stack munging
In various places where scope is left (pp_leave, pp_leavesub etc)
the perl argument stack is processed: a combination of shifting return
args down and mortalising or copying them. This is typically done in
S_leave_common() (although pp_leavesub(lv) roll their own).
Normally POPBLOCK() is called just before this, which
a) initialises cx;
b) sets newsp, gimme etc which are needed by S_leave_common()
c) restores a bunch of PL_ vars from the saved values in cx.
Logically, (c) should be the last thing done in the various pp_leave*
functions, as saving the vars is the first thing done in the various
pp_enter* functions.
This commit moves POPBLOCK after S_leave_common() as a first step towards
migrating it towards the end of the various functions.
It shouldn't make any functional difference, as the values of the various
restored vars aren't used by the arg munging code.
M pp_ctl.c
M pp_hot.c
commit 5f13648d256aef3809317b4ba4922099b3a72819
Author: David Mitchell <[email protected]>
Date: Sat Oct 10 15:39:53 2015 +0100
add PUSH/POPBASICBLK macros.
Most contexts types have a pair, e.g. PUSHSUB/POPSUB for CXt_SUB.
Add them for a basic block too, CXt_BLOCK, i.e. pp_enter/pp_leave.
It makes things slightly more regular ahead of future refactoring.
M cop.h
M pp_ctl.c
commit 10149885bfc79a529605a25bb379ad7920a98f5c
Author: David Mitchell <[email protected]>
Date: Mon Oct 5 16:59:05 2015 +0100
pp_leavewhen(): skip POPWHEN()
pp_leavewhen at some point will do an unconditional dounwind()
to pop the WHEN, BLOCK, and any other intermediate contexts, till it
returns to the enclosing FOR or GIVEN context. Thus there is no need to do
an initial POPBLOCK()/POPWHEN(), as this will be done by dounwind.
We just need to grab a couple of values from the top (GIVEN) context
to go arg stack processing correctly.
M pp_ctl.c
commit 59ae5db969a0e83f51cbf9d60db6eeb811e602a9
Author: David Mitchell <[email protected]>
Date: Mon Oct 5 16:23:07 2015 +0100
pp_leavewhen: simply for() handling
when returning control to an enclosing for loop, the next op to execute
(i.e. my_op->op_nextop) will be an OP_UNSTACK, which handles popping stuff
of stacks and doing PERL_ASYNC_CHECK(); so no need to do it here too.
M pp_ctl.c
commit f7d8a3ceecaa35e816f7a96af73bc5d87f6dc56a
Author: David Mitchell <[email protected]>
Date: Mon Oct 5 15:50:18 2015 +0100
rename S_dopoptogiven() to S_dopoptogivenfor()
Since it searches the context stack for the next GIVEN *or* FOR LOOP
context, make the name better express its purpose.
M embed.fnc
M embed.h
M pp_ctl.c
M proto.h
commit 897b827d61e1b950663ea12225d2fb95d58cab62
Author: David Mitchell <[email protected]>
Date: Mon Oct 5 14:48:35 2015 +0100
add loop benchmark tests
M t/perf/benchmarks
commit ebacb9cc827199bf00fbac76561e70afed3467dd
Author: David Mitchell <[email protected]>
Date: Fri Aug 28 16:11:50 2015 +0100
Make remaining context types avoid ENTER/LEAVE
Previous commits have made the 'subbish' context types like SUB, EVAL
use the context stack to save the old values of PL_savestack_ix and
PL_tmps_floor rather than using ENTER/SAVETMPS/LEAVE; extend this
to the remaining contexts types; specifically loops, bare blocks and
given/when.
Note that this means that during context stack unwinding (e.g. in
dounwind()), LEAVE_SCOPE() is called for every context popped, whereas
before it was only done for each subbish context type.
This makes the ordering of the actions in scope unwinding match much more
closely the reverse order in which things were done during scope pushing;
for example entering and leaving a for loop will now do:
PUSHLOOP_FOR();
...
... code within loop which pushes stuff on the savestack
...
LEAVE_SCOPE(); /* pops the stuff from above */
POPLOOP();
The main reason for this commit (apart from increased consistency)
is that its a lot faster.
M cop.h
M pp_ctl.c
M pp_hot.c
commit 77349bb382466edc12bb91bb65b31a6d32725ff0
Author: David Mitchell <[email protected]>
Date: Mon Oct 5 10:57:09 2015 +0100
Consistently call leave_common() before POPFOO
In some places the code does
POPBLOCK(); POPFOO(); leave_common();
while in other places it does
POPBLOCK(); leave_common(); POPFOO();
Make it do the latter consistently. This is because the next commit
will make *all* context types do a LEAVE_SCOPE(), not just the 'subish'
ones as now. This means that any context type that can return args needs
to preserve its args before doing the LEAVE_SCOPE()/POPFOO(), not just the
sub ones.
For example this lexical var is declared within a LOOP_PLAIN:
sub foo {
{
my $x = 1;
$x;
}
}
where the return value of the loop block ($x) is also the return value of
the sub. So let leave_common() make a mortal copy of $x before POPLOOP
frees the lexicals in the inner scope.
Similar comments apply to calling leave_common() before calling
dounwind().
Note that where the LEAVE_SCOPE() is located it not yet consistent;
sometimes it's part of the POPFOO macro, sometimes it's not, and so has to
be done explicitly just before calling POPBAR.
M pp_ctl.c
commit 9f8bca8ff2b3314f3e2322195d1163faf0e4ae38
Author: David Mitchell <[email protected]>
Date: Fri Oct 2 17:28:00 2015 +0100
pp_given: avoid using savestack for old var
Add a new field, defsv_save, to struct block_givwhen, and use this
to save the previous $_ in 'when(expr)' rather than saving it on the save
stack.
Also add POPWHEN and POPGIVEN macros. The former is a no-op for now.
M cop.h
M pp_ctl.c
commit 4cbfcdae20156b21ec7faf04654e4dcffd149607
Author: David Mitchell <[email protected]>
Date: Fri Aug 28 15:37:23 2015 +0100
context: move couple of fields into block struct
A few of the block_foo substructs within the context struct have the
same two fields, old_savestack_ix and old_tmpsfloor. Move these into the
basic block struct so they can be used by all blockish context types.
This is basically a big renaming exercise and should make no functional
difference.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
commit a5dbd1b53861ebe06263fe69b8820d25d0656264
Author: David Mitchell <[email protected]>
Date: Fri Aug 28 08:37:42 2015 +0100
pp_enteriter, POPLOOP: simplify some code
merge some common code from branch arms and tidy up. Shouldn't make
any functional difference.
M cop.h
M pp_ctl.c
commit ddffb624b17445f9b3480e98110b61c8c9675bcb
Author: David Mitchell <[email protected]>
Date: Fri Aug 28 08:21:05 2015 +0100
pp_enteriter: don't create new SV for GvSV slot
Currently in
for $pkg_var (...) {}
pp_enteriter() saves the current SV that's in the GvSV slot, then
replaces it with a newSV(0). Instead, leave it untouched. In the range
cases:
for $pkg_var (1..10) {}
for $pkg_var ('a'..'z') {}
a new SV will be created anyway in the first call to pp_iter(), since each
time round the loop it checks whether the refcount of the iterator vars is
greater than 1 and if so abandons it.
For the list case, e.g.
for $pkg_var (1,3,5) {}
for $pkg_var (@foo) {}
each call to pp_iter updates the GvSV slot to point to the current var,
so sticking a null SV in there initially, and freeing it the end is just
pointless extra work.
The only slight proviso is when the GvSV slot is initially NULL. In this
rare case we still create the SV, as it will be needed for the range
cases.
M pp_ctl.c
M t/op/for.t
commit 8b4ce54e83809b939a5ed81878702d2a604e89fc
Author: David Mitchell <[email protected]>
Date: Thu Aug 27 16:03:42 2015 +0100
add CXp_FOR_PAD, CXp_FOR_GV flags
These indicate that the loop is a for loop, with a lexical or package
iterator variable.
These flags make various tests simpler and more efficient.
This commit also fixes a bug introduced a couple of commits ago;
I was assuming that in POPLOOP, itersave being non-NULL indicated a
'for $lex' or 'for $pkg', but something like
local *x;
for $x (..) {}
leaves the loop with itersave set to NULL. Instead we can use the new
flags to indicate that itersave is valid.
M cop.h
M pp_ctl.c
M t/op/for.t
commit beb0ab3c5e4c0b2a028dd2b33698751859c61b25
Author: David Mitchell <[email protected]>
Date: Thu Aug 27 14:45:13 2015 +0100
pp_enteriter: tidy itervar-setting code
rename itervar to itervarp since it's more like an SV** than an SV*,
and set itersave earlier so that it can be used directly rather than
repeatedly dereffing itervarp.
Shouldn't be any functional change.
M pp_ctl.c
commit d73fdf419d2e0c7e08eecf7465e61ff64932389c
Author: David Mitchell <[email protected]>
Date: Thu Aug 27 13:43:49 2015 +0100
for loops: don't refcount bump orig var
In something like
for $pkg_var (...)
pp_enteriter() bumps the reference count or $pkg_var before making
itersave point to it. POPLOOP later decrements this ref count.
This bump is unnecessary; since we are effectively transferring ownership
(and thus ref count contribution) of the $pkg_var SV from the GvSV slot of
*pkg_var to the itersave slot of the context struct, the overall ref count
of the var should remain unchanged.
So skip the bump and later undo. This should make no functional difference;
it's just more efficient.
M cop.h
M pp_ctl.c
commit 7430556dc3cb0422e24b26005430ad9c72fd64b6
Author: David Mitchell <[email protected]>
Date: Thu Aug 27 13:40:20 2015 +0100
POPLOOP(): no need to mortalise current item
Now that pp_return() protects its return arg(s) against premature freeing
before calling dounwind(), there's no need for POPLOOP to mortalise the
current item.
M cop.h
commit 547c840b3f5fb5bf6a98a80a1595ed5b85d9ccc7
Author: David Mitchell <[email protected]>
Date: Wed Aug 19 12:33:24 2015 +0100
Add itersave field to LOOP context struct
When entering a for loop, rather than saving the original loop variable on
the save stack, save it in the context struct. Quicker and simpler.
Note that as of this commit, entering a for loop no longer saves anything
on the save stack.
M cop.h
M pp_ctl.c
commit fafbacac6ee548bf2cb3b70e1eff8896f6bba96b
Author: David Mitchell <[email protected]>
Date: Thu Aug 27 12:13:58 2015 +0100
POPLOOP: call LEAVE_SCOPE()
in PUSHLOOP, save the current PL_savestack_ix, and in POPLOOP, do
LEAVE_SCOPE(cx->blk_loop.old_savestack_ix);
This is in preparation for shortly not wrapping loops in ENTER/LEAVE.
M cop.h
commit 9bba669fe59b5980a3c9e9e6c6316164d6e82075
Author: David Mitchell <[email protected]>
Date: Thu Aug 27 12:02:27 2015 +0100
pp_return(): reindent following previous commit
whitespace-only change
M pp_ctl.c
commit b3b0b9b63f5594b835606871aeedb528969891fe
Author: David Mitchell <[email protected]>
Date: Tue Aug 25 13:57:55 2015 +0100
pp_return(): handle dounwind() freeing args
Currently only POPSUB (and other sub-like contexts, such as POPEVAL) do a
LEAVE_SCOPE() as well as restoring things from the context struct. This
means that if pp_return() does a dounwind() to pop back to the next
SUB/EVAL/FORMAT context, LEAVE_SCOPE() won't get called, and any return
values aren't prematurely freed, e.g. in the following
sub f {
for (...) {
my $x = 1;
return $x;
}
}
POPLOOP() won't call LEAVE_SCOPE(), so $x doesn't get freed.
The next commit is about to change that: POPLOOP() will indeed call
LEAVE_SCOPE(), (and later commits may make other POPFOO() types do that
too). So in preparation, this commit makes pp_return() preserve any return
args before calling dounwind().
M pp_ctl.c
M t/op/sub.t
M t/op/sub_lval.t
commit 68eb494d75ef6a0f21ab1d6af9897f3b84e5ca15
Author: David Mitchell <[email protected]>
Date: Wed Aug 26 11:34:59 2015 +0100
pp_leaveloop: use SVs_PADTMP|SVs_TEMP
When calling leave_common(), most callers specify the "safe" return SVs
that don't need copying as being those with SVs_PADTMP or SVs_TEMP
set (leaveeval is a correct exception to this this).
pp_leaveloop() specified no flags, meaning that it always copies. This
appears to be just be an oversight rather than being for any good reason.
M pp_ctl.c
commit 3c54a1d62cda5e9f232ef9fe5ff005f8716e4e2c
Author: David Mitchell <[email protected]>
Date: Wed Aug 26 09:53:09 2015 +0100
S_leave_common(): simplify SVs_PADTMP handling
Now that SVs_PADTMP is a simple flag again (at one point its meaning was
inferred from the state of two flags) it no longer needs special handling
in S_leave_common().
M pp_ctl.c
commit 9463870af4e7bcbb1c646c382d86c3d4c7c72b78
Author: David Mitchell <[email protected]>
Date: Sun Jul 19 10:51:38 2015 +0100
for my $x (...): $x is always stale
Remove the code in pp_enteriter that turns $x's staleness off and schedules
on the save stack for it to be turned back on at scope exit.
Since 'for my $x' works by making $x's pad slot temporarily point to
each item in turn, the "real" $x which lives in the pad outside of loop
time can never be accessed by the usual closure tricks (BEGIN, eval,
nested named subs etc) during a loop, so doesn't need to be marked as not
stale.
Skipping this step is one less thing to be pushed onto the save stack
on each for loop entry.
M pp_ctl.c
commit fe239f49cab8f17fd356403f3610574cb066e35e
Author: David Mitchell <[email protected]>
Date: Fri Jul 17 23:22:29 2015 +0100
pp_last: use debugging LEAVE variant
Make the two LEAVEs in pp_last() be instead
LEAVE_with_name("loop2");
LEAVE_with_name("loop1");
which is more self-documenting and will trap mistakes on DEBUGGING builds
M pp_ctl.c
commit ae27e0ef32ea5ffc836db6e4ffd1dfb666622efc
Author: David Mitchell <[email protected]>
Date: Fri Jul 17 22:49:40 2015 +0100
only call leave_common in non-void context
A lot of the pp_leave* functions call S_leave_common() to process
any return args. Since many of these tend to be used in void context
(e.g. plain blocks {; ... }, for loops etc) tst gimme and only call
these function is non-void. For void context the function is mostly
a noop anyway; the only thing we're skipping is TAINT_NOT, which
doesn't matter in void context.
M pp_ctl.c
commit 90161a55878a3c292e76b5da0e78575110511760
Author: David Mitchell <[email protected]>
Date: Fri Jul 17 22:23:51 2015 +0100
CXt_EVAL: save savestack_ix and tmps_floor in CX
In the various places that do PUSHEVAL (eval, require etc), eliminate
ENTER; SAVETMPS
and instead save the old values of PL_savestack_ix and PL_tmps_floor
directly in the eval context frame, similarly to how subs have been
recently changed.
This is faster and cleaner.
M cop.h
M pp_ctl.c
commit 84592b5317226b43938b42b98bc9ec4628b8250f
Author: David Mitchell <[email protected]>
Date: Fri Jul 17 21:51:25 2015 +0100
move SAVETMPS next to PUSHEVAL
In the various places where PUSHEVAL() is used, a SAVETMPS appears
shortly before it. Move each occurrence of SAVETMPS to just after the
SAVETMPS, in preparation shortly for making PUSHEVAL responsible for
saving PL_tmps_floor.
In theory this could make certain temporary items created during
eval/require startup to be freed slightly later. I don't know whether
this is is an issue or not. No tests fail ;-)
M pp_ctl.c
commit 425fd9df66b57e33339b2d20712ca699b00212cb
Author: David Mitchell <[email protected]>
Date: Fri Jul 17 14:44:32 2015 +0100
call_sv(), fold_const(): different CX pop test
Perl_call_sv() and S_fold_constants() both have similar code that:
pushes an EVAL context, does a JMPENV_PUSH() and CALLRUNOPS(), then
optionally pops the EVAL context.
The optionally part depends on whether what's doing the dying
has already popped the context before long-jumping. Currently the decision
on whether to pop is based on whether the scope stack has already been
popped.
This commit changes that to whether the context stack has already been
popped, since shortly we're going to change eval contexts so that the old
savestack_ix is stored in the CX struct rather than on the scope stack.
I ran this code with some asserts that the two conditions were identical,
and nothing failed.
M op.c
M perl.c
commit c98f8d148d708127249bf5024f864b71fd992fcc
Author: David Mitchell <[email protected]>
Date: Thu Jul 16 14:44:06 2015 +0100
CXt_FORMAT: save ss_ix and tmps_floor in CX struct
To match the recent work in this branch on CXt_SUB, make CXt_FORMAT save
PL_savestack_ix and PL_tmps_floor in the context structure rather than
doing ENTER/SAVETMPS. It's more efficient and more consistent.
M cop.h
M pp_sys.c
commit c2053376136b24be5a66056d291b6788be1ede37
Author: David Mitchell <[email protected]>
Date: Mon Jul 13 16:31:20 2015 +0100
pp_entersub(): reduce life of padlist var
only set it when it's needed
M pp_hot.c
commit a035f3aff01b16c7a2e373d5823b6b8d78640c3a
Author: David Mitchell <[email protected]>
Date: Mon Jul 13 16:25:36 2015 +0100
pp_entersub: unroll some CvFLAGS(cv) tests
Do a single bit comparison rather than two conditionals. Slightly faster.
M pp_hot.c
commit 30a73f88d184d92356e706bb47bd37f630c4ebbc
Author: David Mitchell <[email protected]>
Date: Mon Jul 13 16:18:55 2015 +0100
pp_entersub(): reduce scope of gimme
Only calculate the gimme var where its needed.
M pp_hot.c
commit be904e6da3d3e64e887f5b7ccd9c50fbb9098836
Author: David Mitchell <[email protected]>
Date: Mon Jul 13 13:11:01 2015 +0100
pp_entersub(): don't prematurely calc hasargs
Currently at the top of pp_entersub() is:
const bool hasargs = (PL_op->op_flags & OPf_STACKED) != 0;
Defer testing this flag and/or saving it to a local var until
its actually needed. This is a micro-optimisation.
M pp_hot.c
commit 0fae5268f7c26bfe099109448d39013fedcaf92c
Author: David Mitchell <[email protected]>
Date: Mon Jul 13 12:48:17 2015 +0100
revamp pp_entersub()'s CV locating code
The big switch statement at the top of pp_entersub() is intended
to extract the CV from the passed argument, which might be a CV, a GV,
a ref to a CV, etc etc.
In 5.22.0, an optimisation was added to stashes such that if an entry
contained only a CV, then a ref to the CV was stored in the stash, rather
than a GV. This means that in the common case for a plain sub call, sv is
now a ref to a CV rather than a GV. So update the code to:
1) remove the special-casing of GVs;
2) add special casing for the sv being a non-magical, non-overloaded RV
pointing to a CV;
3) add special casing for the sv being a CV (true on method calls);
3) move the rare "sv == &PL_sv_yes" test further down the condition chain;
4) generally rearrange the switch cases so that common things fall though
and uncommon things do a goto;
5) sprinkle more LIKELY() pixie dust.
Part of the intention of special-casing is to avoid doing an indirect
branch by avoiding the switch statement completely.
M pp_hot.c
commit 9bea78dab3e72938fa320fc8d42fc4691f083de2
Author: David Mitchell <[email protected]>
Date: Mon Jul 13 11:48:04 2015 +0100
tweak POPSUB()
re-order things slightly in POPSUB() so that values aren't being
read into local vars before they're needed (so the compiler doesn't
have to write the values back out to the local stack frame if it runs out
of spare registers).
Also, re-order the fields in struct block_sub so that they roughly
correspond with the order in which they are accessed by POPSUB. This is on
the voodoo theory that if the struct straddles a cache line, we may
trigger a prefetch of the second line, so the extra data will be ready for
us when we need it.
M cop.h
commit 83a3e4f924fc35386b0eabd3842394d6b796f778
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 22:13:51 2015 +0100
Eliminate ENTER/LEAVE from sub calls
Every sub call is wrapped in an ENTER/LEAVE pair, which uses the next
free slot on the scope stack to save and then restore the old value of
PL_savestack_ix. Instead, store the old value in a new field in the
context structure, old_savestack_ix. This is quicker and simpler.
Not that we keep the ENTER/LEAVE for XS sub calls, as they don't push a
context frame, and so have nowhere else to remember PL_savestack_ix.
As a side-effect, this commit fixes a TODO test in t/op/sub.t,
which was related to dying while popping a context, then re-popping that
context. For the second pop, the scopestack has since been overwritten
and so too much was getting popped from the savestack. Since we no longer
use the scopestack, it's no longer an issue.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M t/op/sub.t
commit 53f293f883bd2a99aaa1bc1c1c3135defc3d6a54
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 16:43:25 2015 +0100
pp_hot.c: skip unnecessary test
This condition:
!CvROOT(cv) && !CvXSUB(cv)
can be simplified because those two cv fields are actually
the same slot in a union.
M pp_hot.c
commit 65185d8501405b1e1b34e8fc58566de5b0a00148
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 15:37:11 2015 +0100
pp_entersub(): simplify autoload logic
eliminate a label and goto by by just setting cv to null on failure,
and have a single "if (!cv) croak()" test at the end of the loop.
M pp_hot.c
commit 5a60b90b56e221b77ca2122e6123c1f32736420b
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 15:30:38 2015 +0100
pp_entersub(): eliminate a label
replace:
retry:
if (A) die;
if (B) {
...;
goto retry;
}
with
while (B) {
...;
}
if (A) die;
it's functionally equivalent except that the A test is now only
tried after we have been successful at B. This is ok, because
A is testing for an uncloned closure prototype, while B is looking
for a CV stub which needs autoloading,and it doesn't rally matter
which we test for first.
M pp_hot.c
commit c6b71c2e413c4ef87a1cf8651fb19f2e336d3fa9
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 14:42:56 2015 +0100
add old_tmpsfloor field to CXt_SUB context frame
Rather than saving and restoring PL_tmps_floor on subroutine entry/exit
by using SAVETMPS and the save stack, store the old value directly
in the context struct and make PUSHSUB/POPSUB handle the saving and
restoring.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
commit 9be337115250c7fa923a818096535800885531e2
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 14:16:29 2015 +0100
PUSH_MULTICALL: move SAVETMPS later
Move the SAVETMPS to just after the PUSHSUB. This should make no
functional difference, because nothing should have affected the TMPS stack
between the old and the new code positions.
M cop.h
commit 3a362ea026ad20c96b4bdaf49b349fa1d6e7d3e8
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 14:04:59 2015 +0100
pp_dbstate: do SAVETMPS etc in both branches
pp_dbstate() does an XS or non-XS subroutine call to &DB::DB;
move the SAVETMPS from before the (if CvISXSUB(cv)) test to the head of
both branches. This duplication of code is currently a noop, but will
shortly allow us to handle things differently in the two branches.
M pp_ctl.c
commit 2223dd0566979d6b9c92e3384a0048890137e2fc
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 13:58:47 2015 +0100
pp_sort: move SAVETMPS later
Move the SAVETMPS to just after the PUSHSUB. This should make no
functional difference, because nothing should have affected the TMPS stack
between the old and the new code positions.
For the OPf_SPECIAL/ CXt_NULL case, which doesn't do a PUSHSUB,
do another SAVETMPS there too.
M pp_sort.c
commit e25b7d80eecd6bf0d3332c7e6be38b3b1fc6380c
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 13:45:01 2015 +0100
pp_goto: do SAVETMPS etc in XS and non-XS branches
Move a SAVETMPS;SAVEFREESV(cv); from before the "if (CvISXSUB(cv))" test
to the head of both branches. This duplication of code is currently
a NOOP, but will shortly allow us to handle things differently in the two
branches.
M pp_ctl.c
commit 936c75a670ff29db72fe541c6743aa8cd4ac1c43
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 13:32:03 2015 +0100
pp_entersub(): move SAVETMPS next to PUSHSUB
It it intended that eventually PUSHSUB() will do the SAVETMPS itself,
so move the SAVETMPS up so that it's next to the PUSHSUB.
There should be nothing between those two points that use the TEMPS stack,
so this commit should have no functional effect.
M pp_hot.c
commit cf0791b2e02a65178da1ce7c215eb4a634ebc56f
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 13:10:00 2015 +0100
pp_entersub(): remove an unnecessary condition
The code that scans the args list making mortal copies is protected by an
if (LIKELY(hasargs)) {
However, a sub called as "&foo;" (which is how hasargs is determined)
won't have pushed anything on the stack, so the first part of that code
block, "while (svp < SP)", will drop out immediately.
So skip doing the hasargs test.
NB - it's possible in theory for XS code to call call_sv() jn such a way
as to both have !hasargs but with stuff on the stack; in this worst case,
we just waste a bit of time making some mortal copies of those args.
M pp_hot.c
commit 00e01bc88749e79e93c761ffb4b7e0f3ea3e4b90
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 12:43:43 2015 +0100
pp_entersub(): mortal-copy args earlier
Move the code earlier which makes a mortal copy of any PADTMP args.
This should make no functional difference, but will shortly allow
us to move the SAVETMPS earlier too (while still coming after the
mortal copying).
M pp_hot.c
commit 66790aec946c029475f2be43ad063d28e12e0bfd
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 11:49:13 2015 +0100
pp_leavesub: simplify recursion test
Part of pp_leavesub() tests whether we're in recursion by looking
at CvDEPTH(cx->blk_sub.cv). Instead, just directly check
cx->blk_sub.olddepth, which is equivalent (allowing for an offset of 1)
but faster.
M pp_hot.c
commit 4cd1269a646de3a0346d4fcfc9afa316c6c7fadf
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 11:05:55 2015 +0100
clear_defarray(): clear @_ if possible
clear_defarray() is called during sub exit to clean up @_ in the
less common case where @_ has somehow gotten reified.
At the moment it just frees the old @_, then creates a new AV and
sticks it in pad[0].
This commit changes it so that for the reasonably common case of a reified
@_ where it's not magical and only has a reference count of 1, just call
av_clear() on it, rather than freeing and recreating.
Typical code that will benefit from this change is be something like:
sub f { push @_, ...; ... }
which causes the AV to be reified, but not to become otherwise visible.
M pp_hot.c
commit 07089d4c3854d9d0a7136be204752e46da50f656
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 10:52:49 2015 +0100
pp_goto(): use clear_defarray()
In pp_goto(), use the newly-added clear_defarray() function
to the clear the old @_. This ensures that POPSUB() and pp_goto()
do the same thing. Note that clear_defarray() is actually better than
the old pp_goto() code, in that it pre-sizes the newly-created array
to match the size of the array being abandoned.
M pp_ctl.c
commit 926f1bc7d5cb8e391acbdd2fc8084fe379cf8eb9
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 10:40:23 2015 +0100
add Perl_clear_defarray()
This function implements the less commonly used branch in the POPSUB()
macro that clears @_ in place, or abandons it and creates a new array
in pad slot 0 of the function (the common branch is where @_ hasn't been
reified, and so can be clered simply by setting fill to -1).
By moving this out to a separate function we can avoid repeating the same
code everywhere the POPSUB macro is used; but since its only used
in the less frequent cases, the extra overall of a function call doesn't
matter.
It has a currently unused arg, 'abandon', which will be used shortly.
M cop.h
M embed.fnc
M embed.h
M pp_hot.c
M proto.h
commit 9e4c5ecfee752f7195311b8dda6136f7d4a9991e
Author: David Mitchell <[email protected]>
Date: Sat Jul 11 10:06:39 2015 +0100
avoid leaking @_ in goto
pp_goto temporarily bumps the reference count of @_ while doing
LEAVE_SCOPE(), to stop it getting prematurelly freed. If something
dies during the save stack unwinding, it will leak.
Instead, make it mortal.
M pp_ctl.c
M t/op/svleak.t
commit b2ae0dd19891c30088a2c9732bcb8bff74d4ffa2
Author: David Mitchell <[email protected]>
Date: Thu Jul 9 09:22:38 2015 +0100
goto.t: add freeing CV test
This code SEGVed in a cpan/ module while I was messing with pp_goto.
Add it to t/op/goto.t so that it can SEGV there instead.
M t/op/goto.t
commit ca7f18c00066c37c12041c5f750a1b33e040585c
Author: David Mitchell <[email protected]>
Date: Sun Jul 5 10:21:14 2015 +0100
pp_goto: do the DIEing before the POPing
Rearrange the beginning of the 'goto &func' part of pp_goto so that it
does most of its error checks (e.g. "Can't goto subroutine from an eval")
before it starts doing "return-ish" stuff. This makes the code slightly
cleaner, especially as it doesn't have to undo the SvREFCNT_inc(cv) guard
in every die branch.
M pp_ctl.c
commit 56b11f1774c67eaca8e6f045af061f421bfe1db4
Author: David Mitchell <[email protected]>
Date: Sun Jul 5 10:08:25 2015 +0100
eliminate a goto in pp_goto (!)
Replace a C-level goto with a while loop: logically equivalent,
but doesn't use a goto. (I know, I know, this is in pp_goto, but even
so...)
M pp_ctl.c
commit 2247876c6cce26a6ce6b6ce0afaec65aca02477b
Author: David Mitchell <[email protected]>
Date: Fri Jul 3 11:40:01 2015 +0100
pp_goto: a couple of cosmetic changes
had a lable outdented 2, not 4 chars, and move a comment describing
what a branch does from before to after the 'if'.
M pp_ctl.c
commit ccc442de83479ef624d16dc8dc3b7ff5512a0d0a
Author: David Mitchell <[email protected]>
Date: Fri Jul 3 11:14:30 2015 +0100
make POP_SAVEARRAY() safe
POP_SAVEARRAY() frees the current @_ and restores it to the callers value.
As currently defined, it frees the old AV then updates GvAV(PL_defgv). If
the free old the old AV triggers a destructor for example, then in
theory something bad could happen.
I couldn't actually find a simple failure case, but I suspect that
something like
sub f { *_ = bless [], 'Foo' }
where Foo::DESTROY is an XS sub that messes with GvAV(PL_defgv), could do
it.
Anyway to play safe, this commit updates the GvAV() slot and *then* frees
the old AV. This our normal modus operandi in other places anyway.
The equivalent code in pp_goto already does this the safe way. This commit
also updates pp_goto to use the (now equivalent) POP_SAVEARRAY() macro.
M cop.h
M pp_ctl.c
commit 80dfc343bad79521139bd49b8e62666a626300fa
Author: David Mitchell <[email protected]>
Date: Thu Jul 2 10:14:14 2015 +0100
t/perf/benchmarks: add a few sub and goto tests
M t/perf/benchmarks
commit 4a59fd28a33ff3ee27b615b02a9c0495af62f19f
Author: David Mitchell <[email protected]>
Date: Wed Jul 1 20:19:23 2015 +0100
pp_entersub: skip resetting @_
Whenever we leave a sub by whatever means (pp_leavesub, pp_return,
pp_goto, die etc) it is the responsibility of the code that pops
the SUB context to clean up the private @_ of that sub (i.e pad[0])
so that it's empty and not real.
There's some code in pp_entersub that duplicates this check. I believe
this check is unnecessary and so this commit removes it and replaces it
with an assert. It was added by 221373f04 in 1999 to fix the issue
described in
Subject: [ID 19991015.010] [BUG 5.005_62 Assertation failed:
"pp_ctl.c" line 2443]
Message-Id: <[email protected]>
There were two fixes applied for this issue; the other was
0253cb4. I think the second commit actually fixed the issue and the
first fix was a red herring.
If my newly-added assert fails, it implies that something needs fixing in
the context-popping code, rather than in pp_entersub.
In fact the new assert showed up one issue: the special-case handling
of @_ for &CORE::undef in pp_coreargs wasn't emptying the array,
so I added a CLEAR_ARGARRAY().
M pp.c
M pp_hot.c
commit 60a0eec3a19cd9dd727d9bdc3bc14fabc31fb113
Author: David Mitchell <[email protected]>
Date: Wed Jul 1 16:50:53 2015 +0100
improve @_ commentary in pp_goto
Following on from the previous commit which removed cx.argarray,
remove 'argarray' from the comments about @_, and at the same time
generally overhaul those comments; in particular, explaining how
it's a two part process of donating the current @_ to the new sub.
M pp_ctl.c
commit c5a71cde2b929f8077095f400bf5273b9b9248f0
Author: David Mitchell <[email protected]>
Date: Wed Jul 1 13:37:32 2015 +0100
eliminate the argarray field from the CX struct
At the end of a normal sub call there are often 3 AVs of interest
associated with @_; these are:
cx->blk_sub.savearray the caller's @_
GvAV(PL_defgv) the current sub's current @_
cx->blk_sub.argarray the current sub's original @_
Note that those last two can differ: if for example the sub does
local *_ = [];
Each sub's arg array is created and stored in pad slot 0 at the time
the sub is created. When a sub is called, pp_entersub() does
cx->blk_sub.argarray = PL_curpad[0]
The argarray field is used in two main places:
* at subroutine exit, to clear/abandon the sub's original @_;
* in pp_caller, to set @DB::args to the caller(n)'s args.
In the first case, the last few commits have arranged things so that at
that point, PL_curpad always points to the current pad of the sub being
exited from. So we can just use PL_curpad[0] rather than
cx->blk_sub.argarray.
In the second case (which is not performance critical), we can just use
cx->blk_sub.cv
and
cx->blk_sub.olddepth+1
to find the pad of that call frame's CV.
So we can eliminate the argarray field. This saves a write during
a sub call, and potentially reduces the size of the context struct.
It also makes the code marginally less confusing: there are now 3 arrays
pointed to from 3 places, rather than 3 arrays pointed to from 4 places.
The asserts added in the previous commit confirmed that using argarray
is the same as using PL_curpad[0]; They also confirmed that the current
PL_curpad matches the current CV at the current depth. Those latter
asserts are kept for now.
M cop.h
M pp.c
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M sv.c
commit 94f77189bbfcc372d163554c1ab5040503df40fe
Author: David Mitchell <[email protected]>
Date: Wed Jul 1 12:21:06 2015 +0100
assert that it's safe to remove CX.argarray field
This commit adds assertions that demonstrate that the next commit is safe.
See the description of that commit for details.
M cop.h
M pp.c
M pp_ctl.c
commit a02aea2492ed7b34af28280690e8b71c720e5d4a
Author: David Mitchell <[email protected]>
Date: Wed Jul 1 09:57:51 2015 +0100
Unwind save stack in sync with POPEVAL
During normal exit from an eval, both POPEVAL and LEAVE are done,
meaning that the context stack and save stack are unwound in lockstep.
However, during an exception, dounwind() does the POPEVAL but not the
LEAVE, leaving them temporarily out of step.
About a 2 years ago, with v5.19.3-139-g2537512, subs and formats were
changed so that the save stack popping was done in sync in dounwind.
This commit extends that to evals too.
I'm doing this principally so that PL_compad will always be restored at
the correct moment, which will shortly allow me to eliminate the argarray
field from the context struct.
NB: unlike POPSUB and POPFORMAT, I've added the LEAVE_SCOPE to dounwind
rather than directly adding to the POPEVAL macro - this is because the
various places that use POPEVAL typically use it earlier than the
comparable places with POPSUB, which means they aren't ready to pop the
save stack yet.
NNB: The LEAVE_SCOPE can't be extended to all context types in dounwind(),
only to sub-ish types - specifically the types that can be 'return'ed from.
This is because if you 'return' from a sub or eval, pp_return will
unwind all contexts down to the next sub or eval (discarding all the loops
etc that it escaping out of), but the args it is returning shouldn't
be prematurely freed.
M pp_ctl.c
commit 9501913ab04f4c3b2bde3641f001332885cb7bd3
Author: David Mitchell <[email protected]>
Date: Wed Jul 1 07:56:39 2015 +0100
pp_goto: skip restoring PL_comppad
Now that PL_comppad is saved in the context struct rather than on the save
stack, we can better control when and how it is restored. In the case of
pp_goto, there's no need to restore the caller's PL_comppad in the non-XS
case, since we will be immediately setting it to the new function's pad.
AS well as being slightly more efficient, this avoids restoring PL_comppad
too early, where if we subsequently croak we re-process the CXt_SUB block
in dounwind, but this time with the wrong pad.
In particular, by having always PL_curpad[0] == cx.argarray at sub exit
time, we can shortly eliminate the argarray field.
M pp_ctl.c
commit 933888a75bc3057218326f184b949606956556b6
Author: David Mitchell <[email protected]>
Date: Tue Jun 30 08:03:43 2015 +0100
undef *_; goto &f: update cx.argarray
In something like
sub f { goto &g }
normally g's pad[0] is updated to hold the passed-across @_, and the
context block's argarray field is updated to point to g's @_ too.
However in the case of
sub f { undef *_; goto &g }
cx.argarray isn't being updated. This is probably harmless (I couldn't
come up with a test case that fails), but for consistency, update it too.
This is mainly so that over the next few commits, this condition will come
to apply consistently:
cx.argarray == PL_curpad[0]
and so the argarray field can be eliminated.
M pp_ctl.c
commit 7f84d1627ab0984df4d2442917e30aedc12ebcb9
Author: David Mitchell <[email protected]>
Date: Mon Jun 29 12:33:35 2015 +0100
make "for my $lex {}" faster under ITHREADS
Normally at the start of a 'for' iteration (pp_enteriter), we store the
address of the GV or the address of the pad slot of the iteration variable
in the CX struct, so we can quickly access and update it in pp_iter. For
the ITHREADS case however, the pad may change if the thread is cloned, so
instead the address of PL_comppad was stored, and then updated during
cloning. This meant that on each iter, we would have to retrieve the saved
PL_comppad address from the ctx struct, retrieve the targ from the saved
my_op, and do a (perlish) array indexing.
Thuis commit makes this faster by, for the ITHREADS case, storing both
PL_comppad and svp = &PLcurpad[targ]. In pp_iter(), we're fast by directly
accessing *svp; while storing PL_comppad allows us to update both it and
svp during thread cloning.
This requires one extra pointer in the block_loop part of the context
union under threads, but this is already smaller than some other parts of
the union, so has no effect.
Note that the oldcomppad field was formerly part of the itervar_u union,
but is now a separate field within the larger block_loop struct (but only
on threaded builds).
Note also that the tests I've added I retrieved from an old WIP private
branch that contained a forerunner of this commit, so they may not be
entirely relevant to the current form of this commit. But extra tests
can never hurt, so I've included them.
M cop.h
M ext/XS-APItest/t/clone-with-stack.t
M pp_ctl.c
M sv.c
M t/op/for.t
M t/perf/benchmarks
commit fb64c53864adab0b360cc950059aaebba16bf032
Author: David Mitchell <[email protected]>
Date: Mon Jun 29 12:02:18 2015 +0100
eliminate cx->blk_sub.oldcomppad
In the CXt_SUB sub-struct of the context struct, there is a field
called oldcomppad. Despite the "old" in its name, this field actually
stores the value of PL_comppad of the new sub, not of the caller.
It's only use currently is in POPSUB() when abandoning a reified @_, to
locate PL_curpad[0] of the current sub in order to stick a new empty AV
there. This is a relatively rare occurrence, and the pad slot can be
found (slightly less efficiently) from the saved CV and its depth.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M sv.c
commit fc8b689f9d01a1b266523417f2d453ee791b4b8d
Author: David Mitchell <[email protected]>
Date: Mon Jun 29 11:36:27 2015 +0100
document unrolled PUSHSUB/POPSUB
some places in the code do some or all of the same activities as
PUSHSUB() and POPSUB(). Add comments in those places pointing out that
it's a partially unrolled PUSH/POPSUB(). This will also help if someone
greps the code looking for all the places in core that supposedly does
a PUSH/POPSUB.
M cop.h
M pp_ctl.c
commit efb309868585e0bd61811e79eb3b361a3cabdff0
Author: David Mitchell <[email protected]>
Date: Mon Jun 29 11:27:36 2015 +0100
save old PL_comppad in CXt_SUB/FORMAT block
Currently when we call a sub, the old value of PL_comppad is
saved on the save stack using SAVECOMPPAD(). Instead, save it in
a new field in the context struct, called prevcomppad. This is simpler
and more efficient.
Note that there is already a confusingly-named field in the CXt_SUB
context struct called oldcomppad, which holds the value of PL_comppad for
the *current* sub, not for its caller. So the new field had to be called
something else.
One side effect of this is that an existing bug - which causes too much
to be popped off the savestack when dieing while leaving a sub scope - is
now more noticeable, since PL_curpad and SAVEt_CLEARSV are now out of
sync: formerly, the unwinding of the save stack restored PL_curpad in
lockstep. The fix for this will come later in this branch, when the whole
issue of context stack popping order and reentrancy is addressed; for
now, a TODO test has been added.
M cop.h
M pp_ctl.c
M pp_hot.c
M pp_sort.c
M pp_sys.c
M regexec.c
M sv.c
M t/op/sub.t
commit 076ade38f66d518fca4358cc41c3965ef0039472
Author: David Mitchell <[email protected]>
Date: Fri Jun 26 12:17:59 2015 +0100
pp_entersub: remove extraneous SAVETMPS
The branch that handles "no cv, try autoload" does a SAVETMPS.
This serves no purpose, since we will shortly be doing another SAVETMPS
anyway with no intervening ENTER.
M pp_hot.c
commit cf8e87601f1c18787d9bfe0c7431ab9d18397c38
Author: David Mitchell <[email protected]>
Date: Thu Jun 25 16:08:02 2015 +0100
pp_goto: SvREFCNT_dec(oldcv) *after* undef test
pp_goto does a LEAVE, then checks that the new CV hasn't been undefed
by the LEAVE. If it has, it croaks.
Move the decrementing of the old CV's ref count and depth to *after*
this check, since the POPSUB done during the croak unwind will do the
decrement also. Otherwise the old sub will be doubly freed.
M pp_ctl.c
M t/op/goto.t
commit 5bee97624b7d659d5e1c3f5d881eff622ab95975
Author: David Mitchell <[email protected]>
Date: Thu Jun 25 15:18:25 2015 +0100
pp_goto(): reorder LEAVE_SCOPE for consistency
pp_leavesub (via POPSUB()) does a LEAVE_SCOPE before decrementing the CV's
ref count and depth; pp_goto does it after. Reorder it for consistency
with leavesub.
At this point I make no assertion as to which way round is the most
correct.
M pp_ctl.c
commit 032c587a37f0eb9b5aaa2ef39131e9a580cf7ab1
Author: David Mitchell <[email protected]>
Date: Thu Jun 25 15:08:37 2015 +0100
pp_goto: use cx->blk_oldscopesp
POPSUB() does:
LEAVE_SCOPE(PL_scopestack[cx->blk_oldscopesp - 1])
while pp_goto(), which manually does the relevant actions from POPSUB(),
does:
LEAVE_SCOPE(PL_scopestack[PL_scopestack_ix - 1])
For consistency, make pp_goto() use cx->blk_oldscopesp instead. In fact
at that point they should both hold the same value (and I've added an
assert to that effect), since we should have just popped any nested
scopes.
M pp_ctl.c
commit 7f3652cde6519f4f2b005d997bf4b85f639441dc
Author: David Mitchell <[email protected]>
Date: Thu Jun 25 12:05:50 2015 +0100
SvREFCNT_inc(cv) recursive subs
A CXt_SUB context frame owns 1 reference count to the CV being called,
but only if it's the bottom-level call to that CV; recursive calls don't
count.
This commit changes it so that every CXt_SUB frame owns a reference count.
This removes a lot of "if (CvDEPTH(cv) < 2)" type tests from the code and
makes things generally simpler and less bug-prone.
For ordinary (non-recursive) sub calls it will now be slightly faster, as
it no longer has to do the CvDEPTH check on sub entry and exit; for subs
being recursed into, it will probably be slightly slower, as although it
no longer has to the CvDEPTH check on entry and exit, it now has to do a
refcnt ++/-- instead.
This also means that a deeply recursing sub will have a very high ref
count; but there is no new additional danger of overflow, as sv_refcnt is
U32 while xcv_depth is I32: so the latter will still overflow earlier
anyway.
M cop.h
M pp_ctl.c
M pp_sort.c
M sv.c
commit c0d1453a0a57c7bb3b311e49f6b497ed55b68edd
Author: David Mitchell <[email protected]>
Date: Thu Jun 25 10:48:58 2015 +0100
eliminate an SAVEFREESV(cv) from PUSHSUB
When a CXt_SUB context is pushed, the reference count of the CV is
increased (and is effectively owned by that context frame). It is
decremented when the context frame is popped.
There was an issue in that the POPSUB was done before the LEAVE,
which meant that at sub exit, the sub could be freed before stuff that
referred to that sub was done (such as lexicals being cleaned up by
SAVEt_CLEARSV).
This was fixed by perl-5.005_02-2095-gb0d9ce3, which split POPSUB
into POPSUB and LEAVESUB with the latter responsible for the decrement.
So for example code might do POPSUB; LEAVE; LEAVSUB.
However this wasn't sufficient, because a similar thing happened during
die, for example
sub d {die}
my $f;
$f = sub {my $x=1; $f = 0; d};
eval{ $f->() };
since all *all* the CXt_SUB contexts were popped with POPSUB/LEAVSUB
*before* LEAVE was called.
I fixed this with perl-5.8.0-3206-gb36bdec, by adding another increment to
the CV and doing a SAVEFREESV(cv), both in PUSHSUB. This meant that
the save stack would hold at least one reference to the CV while being
unwound.
However, v5.19.3-139-g2537512 then changed things so that POPSUB also
did a LEAVE. This means that now, die unwinds the context stack and the
save stack in lockstep, so my second fix is now redundant. So this commit
undoes it, saving an rc++/-- and SAVEFREE(cv) per sub call.
M cop.h
-----------------------------------------------------------------------
--
Perl5 Master Repository