develooper Front page | perl.perl5.porters | Postings from January 2016

Re: reworked context stack system

Thread Previous | Thread Next
Dave Mitchell
January 15, 2016 13:45
Re: reworked context stack system
Message ID:
On Mon, Jan 04, 2016 at 07:25:20PM +0100, Vincent Pit (VPIT) wrote:
> However, I am afraid this might break much more than just what is "likely"
> according to In particular, if I understand your description
> correctly, this :
> has a potential of breaking a lot of things, since destruction timing might
> change.
> That's why I would like to see your branch smoked against CPAN before being
> merged in blead. I believe Andreas has the infrastructure ready for this.

Now that CPAN has been smoked, the failures basically boil down to a
handful of XS modules, most of which I had previously identified as likely
to break (because they do non-API stuff). And I suspect fixing some of
them should be as simple as changing e.g.

    case CXt_LOOP_FOR:
    case CXt_LOOP_ARY:
    case CXt_LOOP_LIST:

to reflect the one changed context type.

> Concerning Scope::Upper, it might be impossible to fix after your changes. I
> don't really care since I don't use it personally and the performance gains
> are nice, but I won't hide that it would make me feel like having written it
> for the community (it was a request) was a complete waste of my time.

The attached proof-of-concept patch which I've been working on for the
last 10 days or so gets through the first 500/1000 tests
(blead/context-branch) in t/22-localize-block.t before crashing. It
clearly needs more work (which I *don't* plan to do), but the fact that
it can pass the first few hundred tests shows that Scope::Upper isn't
in principle unfixable.

Given the results of the CPAN smoke and the proof-of-concept Scope::Upper
fix, has anyone still got any objections to me merging this into blead

For Vincent:

My attached Scope::Upper WIP fix addresses two basic changes. First, that
context pushes don't push the old PL_savestack_ix onto the scope stack
any more, but instead store it as blk_oldsaveix. So saved savestack
indexes need adjusting in the context stack as well as the scope stack.
Second, pushing a context now usually involves pushing *nothing* on the
savestack (not even a SAVETMPS), so you can get a whole series of context
stack frames that all share the same blk_oldsaveix. So it makes it
difficult to trigger a call to leave_scope() and thus to su_pop() at the
right time.

My solution to this was, when adjusting the chain of saved
PL_savestack_ix's, rather than adjusting each by the fixed size/offset,
adjust each so it is greater than the previous, so that leave_scope()
is always triggered when needed, and use extra padding if necessary.
Convert origin into an array of structs holding the original ix and the
When su_pop is called, rather than doing depth--, it assumes multiple
scopes may have been popped in one go (for example dounwind() will call
LEAVE_SCOPE() for every context popped, but not for any intervening
ENTERs). So instead it looks at the current value of PL_savestack_ix,
which points to the destructor currently being processed, then pops back
entries in origin until it finds one where origin[depth].ix +
origin[depth].offset < PL_savestack_ix.

I also did a basic fixup to reflect the fact that the cx->blk_sub.argarray
field no longer exists - but this was just enough to make it compile; I
haven't checked whether all uses of CX_ARGARRAY() are correct,

The Enterprise's efficient long-range scanners detect a temporal vortex
distortion in good time, allowing it to be safely avoided via a minor
course correction.
    -- Things That Never Happen in "Star Trek" #21

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About