Branch: refs/heads/davem/xs_refactor3
  Home:   https://github.com/Perl/perl5
  Commit: 9d4453860185300d481447ee3a0835a3d355961b
      
https://github.com/Perl/perl5/commit/9d4453860185300d481447ee3a0835a3d355961b
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_init(): fetch typemap once

The code in generate_init() currently looks up the typemap entry for the
passed type, and if not present, errors out. Almost immediately
afterwards it looks up the value again, this time to use.

This commit makes it do the lookup only once. It also renames the
$typem variable to $typemap for easier reading.

Should be no functional changes.


  Commit: 72f7f8cf5a9901b22acbaf23144ce370dfaa491c
      
https://github.com/Perl/perl5/commit/72f7f8cf5a9901b22acbaf23144ce370dfaa491c
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): rm long else block

Change

    if (...) {
        ...
    }
    else {
        ... long block ...
    }

to

    if (...) {
        ...
        return;
    }
        ... long block ...

The next commit will re-indent the long block.
No functional changes.


  Commit: dd3c4db9a7305b80f824b8a6fdaa850db184e654
      
https://github.com/Perl/perl5/commit/dd3c4db9a7305b80f824b8a6fdaa850db184e654
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): reindent

Re-indent a block of code after previous commit removed a scope.
Whitespace-only.


  Commit: e442a4dcb62bede39c653528f0b87b64f3408eae
      
https://github.com/Perl/perl5/commit/e442a4dcb62bede39c653528f0b87b64f3408eae
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): do indent-depth better

One of the things generate_output() does is optionally wrap a chunk
of code it outputs in a block with an extra variable declaration.

This was handled a bit clumsily by doing the conditional extra indent
at every print statement and doing the '{' and '}' emitting at the start
and end in two different places.

Instead, change all the 'print ...' to 'push @lines, ...'
and consolidate all the 'wrap in a block and further indent' logic at
the end in one place.

Makes the code simpler and easier to comprehend.

There should be no change in functionality, except conceivably a slight
change to how mixed tab-and-space indentation is output for a typemap.
The .c files generated from all the .xs files in bleadperl are currently
unchanged.


  Commit: 31fd7a4c299e1d778aefc966dc2d3eb1590c102d
      
https://github.com/Perl/perl5/commit/31fd7a4c299e1d778aefc966dc2d3eb1590c102d
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): simplify some code

Assign the expression ($use_RETVALSV ? 'SV':'') to a variable rather
than repeatedly using the expression. Makes the code easier to read.

No functional changes.


  Commit: 9a8a91bf72fdccd9a4bf96adfdb0e295ffa694cb
      
https://github.com/Perl/perl5/commit/9a8a91bf72fdccd9a4bf96adfdb0e295ffa694cb
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): remove some local's

The local()s here don't add any functionality because the values
being changed are only used once for the typemap eval and then
discarded. So remove them.

Should be no functional changes.


  Commit: 8aa709f867c08f9e8d8c6cb342008a02766f08eb
      
https://github.com/Perl/perl5/commit/8aa709f867c08f9e8d8c6cb342008a02766f08eb
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): remove dead code

An 'if' branch is never taken. Delete it. The copious code comments also
being deleted by this commit explain how this came to be a dead branch.


  Commit: 9e6358016bbd39e181c3087c6f85b043fc15b614
      
https://github.com/Perl/perl5/commit/9e6358016bbd39e181c3087c6f85b043fc15b614
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): use \b in /RETVALSV/

A couple of places in this function do s/RETVALSV/.../.  These are
attempting to fix up a typemap template that has already being expanded
using $var = 'RETVALSV'.

Change these to s/\bRETVALSV\b/.../ to be more precise. It's extremely
unlikely that the original mistake ever broke anything, but now it's
even less likely to break: it now only breaks if the typemap includes
the word RETVALSV somewhere, rather than a word which includes RETVALSV.


  Commit: b12ac752dbc5afc7c7f3b8d39678086d19a46cfb
      
https://github.com/Perl/perl5/commit/b12ac752dbc5afc7c7f3b8d39678086d19a46cfb
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): use \s* in a pattern

There's a minor optimisation which skips emitting a typemap line if
it expands to 'RETVAL = RETVAL;'. This commit makes the pattern looking
for this use \s* rather than fixed spacing, so it might spot more cases
of this.

This is trivial: even if the redundant code is emitted, any decent
optimising C compiler is going to skip it anyway.


  Commit: 8e780196651241cd4e7ee9401f27f6e00e44248f
      
https://github.com/Perl/perl5/commit/8e780196651241cd4e7ee9401f27f6e00e44248f
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): invert a !~

Change

    if (foo !~ /bar/) {
        do something common
    }

to

    unless (foo =~ /bar/) {
        do something common
    }

to emphasise that we normally do this, unless ...


  Commit: acc48a250441aa9a53f575b327f001fd5f38f84c
      
https://github.com/Perl/perl5/commit/acc48a250441aa9a53f575b327f001fd5f38f84c
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): add $want_newmortal

Replace the $pre_expr var (which says what to add) with a new
$want_newmortal bool var which says what to do rather than just
containing a string which will emit code which does what you want.

A trivial change which doesn't effect functionality but makes the code
slightly easier to follow.


  Commit: 3e2a075f4b5ed27a59b7f0a3c9a6e1e36cb49b1c
      
https://github.com/Perl/perl5/commit/3e2a075f4b5ed27a59b7f0a3c9a6e1e36cb49b1c
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): tweak immortal test

There's a regex which looks at whether an expanded typemap assigns
a value to the var which is guaranteed to be immortal. This allows an
optimisation. (False negatives are safe but slower. False positives are
dangerous.)

Update this pattern to:

- use //x;

- split it into multiple lines for readability;

- change the ^\t to ^\s* to that it's more likely to match a typemap
  with weird spacing;

- include matching a closing ) on a boolSV() call

- include /..$/ anchoring to avoid any strange extra thing at the end of
  the typmap being missed and triggering a false positive (unlikely but
  better safe than sorry);

- recognise PL_sv_zero as another immortal. It's very unlikely that that
  PL_sv_zero actually appears in any typemap in the real world, but we
  might as well add it for completeness.

This patten still isn't perfect: it doesn't parse the body of the boolSV
call, so in theory something like this could trigger a false positive:

    $arg = boolSV(....) == &PL_sv_undef ? "undef" : foo();

But that's fairly unlikely.


  Commit: b75332ba3db0b82102d68badaa18e259611b5e47
      
https://github.com/Perl/perl5/commit/b75332ba3db0b82102d68badaa18e259611b5e47
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): change branch nesting

Change the nesting of a couple of branches. No functional changes.

Change this:

    if (/Foo plus a special case/) {
        do an optimisation involving Foo
    }
    elsif (/Foo/) {
        do Foo
    }
    elsif (...)

to this:

    if (/Foo/) {
        if (/Foo plus a special case/) {
            do an optimisation involving Foo
        }
        else {
            do Foo
        }
    elsif (...)

This means that the major branches are solely for detecting the basic
varieties of typemap, while an optimisation for one of those varieties is
handled within that major branch.

The diff looks bigger than it is - all the blocks of code within each
conditional are unchanged.


  Commit: e76db96e9ac5d1ec4ec1fc17dc2ed6e1cffa46cd
      
https://github.com/Perl/perl5/commit/e76db96e9ac5d1ec4ec1fc17dc2ed6e1cffa46cd
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): change ST(0)= logic

Remove the $do_copy_tmp lex var and add a $ST0_already_assigned_to
lex var.

When deciding whether to emit

    ST(0) = ...

that decision should be based on whether the expanded typemap already
includes such an assignment. (Often it doesn't, because various
optimisations change it to 'RETVALSV = ' etc.)

This commit sets a variable which directly states whether this is true,
instead of relying on indirect state.

This commit should provide no change in functionality, but it makes the
code more robust against future changes, by not having to rely on all
branches knowing to set all the correct indirect variable values.


  Commit: ec7929fa1be6cffe6499b4364cf243e9a272739b
      
https://github.com/Perl/perl5/commit/ec7929fa1be6cffe6499b4364cf243e9a272739b
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-08-22 (Thu, 22 Aug 2024)

  Changed paths:
    M dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

  Log Message:
  -----------
  ParseXS: generate_output(): rename $do_mortal

Rename the lexical var $do_mortal to $do_mortalize to better reflect
that it indicates that 'sv_2mortal()' code should be emitted (as opposed
to, for example creating a new mortal).


Compare: https://github.com/Perl/perl5/compare/9d4453860185%5E...ec7929fa1be6

To unsubscribe from these emails, change your notification settings at 
https://github.com/Perl/perl5/settings/notifications

Reply via email to