Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline subs #23

rurban opened this issue Sep 11, 2015 · 0 comments

inline subs #23

rurban opened this issue Sep 11, 2015 · 0 comments


Copy link

@rurban rurban commented Sep 11, 2015

perl-5.003_02 added an incomplete op_const_sv to check an optree for a single const or pad, and to mark it as CvCONST then. 760ac83
Nothing much changed since then.

This is

  1. wrong. only const pad values may be used like this. sideeffects changing the lexical are not safe. 5.22 started warning about this condition.
  2. not enough. proper constant folding should be done to check if the body may be inlinable.

Splice a OP* into the caller if inlinable, not just a CONSTSUB via the const_sv logic.
With some heuristic/cost calculation when it makes sense.

we can also use the new :const and :pure attributes to mark functions as inlinable.
:const to bypass the constant folding check, :pure to mark the closed over lexicals as not being changed by sideeffects.

Note: inlined subs and methods are a huge performance win in most dynamic languages. esp. with the slow perl function calls, it might be a big win.

Analyze the body and check if a enter/leave is needed, and if the args can be hardcoded into the inlined body (optim_args). this can be done by ref (with consts and with $_[]) or by value via copies of the sv/pad.
otherwise use a simple push @_ , args oplist instead of the pushmark args gv entersub sequence.

The inlined body needs to be copied, as the nextstate and args needs to be changed. We can do this on the fly, or 2nd or more generally add a new op_clone_oplist() API, which just clones the ops, not the data.

See the branch feature/CM-707-cperl-inline-subs, now feature/gh311-opclone

@rurban rurban self-assigned this Sep 11, 2015
@rurban rurban added the enhancement label Sep 11, 2015
@rurban rurban added this to the v5.24.0 milestone Sep 13, 2015
@rurban rurban modified the milestones: v5.24.1, v5.24.0 May 10, 2016
@rurban rurban modified the milestones: v5.26.0, v5.24.1 Oct 11, 2016
@rurban rurban added the in progress label Dec 1, 2016
@rurban rurban removed this from the v5.26.0c milestone Mar 2, 2017
@rurban rurban added this to the v5.26.0c milestone Mar 30, 2017
@rurban rurban removed the in progress label Mar 30, 2017
@rurban rurban removed this from the v5.26.0c milestone Apr 29, 2017
@rurban rurban added this to In progress in cperl Dec 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
In progress
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.