cpanel / perl-compiler

cPanel's custom implementation of B::C
https://cpanel.net
Other
8 stars 3 forks source link

Cannot compile a program using Moose #55

Closed atoomic closed 7 years ago

atoomic commented 7 years ago

This is an acknowledge issue for a while but would be good to be able to understand/fix it in the future.

package Foo::Moose; use Moose; has bar => (is => "rw", isa => "Int");
package main; my $moose = Foo::Moose->new; print "ok" if 32 == $moose->bar(32);

current status with HEAD=39f6dac5ae2666a40c47c3d2c79d2e4ce848efc9 is a SEGV when bootstrapping B, is Moose using B ??

Program received signal SIGSEGV, Segmentation fault.
0x00000000005c6cbc in perl_init_bootstraplink_aaaa () at /root/workspace/bc/t/v5.24.1/C-COMPILED/xtestc/0350.c:409735
409735      magic_list[784].mg_obj = (SV*) GvCV( gv_fetchpv("B::perlstring", 0, SVt_PVCV) );
(gdb) bt
#0  0x00000000005c6cbc in perl_init_bootstraplink_aaaa () at /root/workspace/bc/t/v5.24.1/C-COMPILED/xtestc/0350.c:409735
#1  0x00000000005c9167 in perl_init_bootstraplink () at /root/workspace/bc/t/v5.24.1/C-COMPILED/xtestc/0350.c:409994
#2  0x00000000006006bc in main (argc=1, argv=0x7fffffffdcc8, env=0x7fffffffdcd8) at /root/workspace/bc/t/v5.24.1/C-COMPILED/xtestc/0350.c:444676
atoomic commented 7 years ago

indeed moose is using B::perlstring in multiple places

lib/Moose/Meta/Attribute.pm
936:        my $builder = B::perlstring($self->builder);

lib/Moose/Meta/Method/Delegation.pm
93:    my $method_name = B::perlstring( $self->name );
94:    my $attr_name   = B::perlstring( $self->associated_attribute->name );
atoomic commented 7 years ago

perlstring is another flavor of cstring, if that's the only one use, we can even provide an alternate for it

 void
 cstring(sv)
     SV *    sv
     ALIAS:
     perlstring = 1
     cchar = 2
     PPCODE:
     PUSHs(ix == 2 ? cchar(aTHX_ sv) : cstring(aTHX_ sv, (bool)ix));
atoomic commented 7 years ago

0001-lazy-load-B-at-run-time.txt

idea of lazy loading B at run time in Moose

atoomic commented 7 years ago

note that Moose program works when saving B correctly 7f76bf7e62510d434e2ee2681ce25a7a7607d3f8

This still need some extra love but this is a very good start

atoomic commented 7 years ago

The compilation of a Moose program like this one create a binary of ~12M and runs about 10x times faster once compiled

moose.t

package foo;use Moose;
has "x" => (isa => "Int", is => "rw", required => 1);
has "y" => (isa => "Int", is => "rw", required => 1);
sub clear { my $self = shift; $self->x(0); $self->y(0); }
__PACKAGE__->meta->make_immutable;
package main;
my $f = foo->new( x => 5, y => 6);
print $f->x . "\n";

Uncompiled

> time for i in $(seq 1 100); do perl moose.t >/dev/null; done

real    0m37.759s
user    0m35.838s
sys 0m1.909s

vs Compiled

> time for i in $(seq 1 100); do moose.bin >/dev/null; done

real    0m4.302s
user    0m3.035s
sys 0m1.273s