Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.9k stars 539 forks source link

.pmc logic: keep, delete, deprecate? #5271

Closed p5pRT closed 18 years ago

p5pRT commented 22 years ago

Migrated from rt.perl.org#8860 (status was 'resolved')

Searchable as RT8860$

p5pRT commented 22 years ago

From dcd@tc.fluke.com

Created by dcd@tc.fluke.com

Perl's .pmc files are not documented\, and don't seem to add value to require.

While stracing the perl interpreter today\, I saw it stating .pmc files when I didn't expected.

The 'standard' .pod documentation (the perl* pods mentioned in perldoc perl) don't mention requrire stating .pmc files

I later found some documentation in B​::Bytecode that mentions files with .pmc extension. but that doesn't seem to generate a .pmc file that is compatible with what the perl interpreter is looking for.

$ cat Echo.pm warn "Hello World\n"; $ perl -MO=Bytecode\,-uEcho\,-oEcho.pmc Echo.pm Echo.pm syntax OK dd​:dcd$ perl -e 'require Echo' Number found where operator expected at Echo.pm line 1\, near "linux" syntax error at Echo.pm line 1\, near "linux" Compilation failed in require at -e line 1.

Since that didn't work\, I tried

$ cp Echo.pm Echo2.pmc $ perl -e 'require Echo2' Hello World

If .pmc files are supposed to work in some fasion\, they should be documented.

If they don't add any value\, there should be a configuration option to not use them\, thus avoiding potentially expensive stats when requiring files.

Perl Info ``` Flags: category=docs severity=low Site configuration information for perl v5.7.3: Configured by dcd at Tue Mar 19 12:03:54 PST 2002. Summary of my perl5 (revision 5.0 version 7 subversion 3 patch 15336) configuration: Platform: osname=linux, osvers=2.4.19-pre2, archname=i686-linux uname='linux dd 2.4.19-pre2 #1 mon mar 11 16:36:38 pst 2002 i686 ' config_args='-Dmksymlinks -Dinstallusrbinperl -Uversiononly -Dusedevel -Doptimize=-O3 -g -de -Dcf_email=dcd@tc.fluke.com' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=define Compiler: cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O3 -g', cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='egcs-2.91.66.1 19990314/Linux (egcs-1.1.2 release)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lgdbm -ldbm -ldb -ldl -lm -lc perllibs=-ldl -lm -lc libc=/lib/libc.so.5.4.44, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: DEVEL15328 @INC for perl v5.7.3: /usr/local/lib/perl5/5.7.3/i686-linux /usr/local/lib/perl5/5.7.3 /usr/local/lib/perl5/site_perl/5.7.3/i686-linux /usr/local/lib/perl5/site_perl/5.7.3 /usr/local/lib/perl5/site_perl/5.7.2/i686-linux /usr/local/lib/perl5/site_perl/5.7.2 /usr/local/lib/perl5/site_perl/5.6.1/i686-linux /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl . Environment for perl v5.7.3: HOME=/home/dcd LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/dcd/bin:/sbin:/usr/local/bin:/bin:/usr/bin:/usr/X11/bin:/usr/games:/usr/local/samba:/home/hobbes/tools/scripts:/home/hobbes/tools/linux:/usr0/hobbes/tools/scripts:/usr0/dcd/bin:/apps/general/bin:/usr/public PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 21 years ago

From @cwest

What you want is B​::C.

p5pRT commented 21 years ago

@cwest - Status changed from 'open' to 'resolved'

p5pRT commented 21 years ago

From david.dyck@fluke.com

On Fri\, 9 May 2003 at 15​:47 -0000\, Casey West \perlbug\-followup@​perl\.org wrote​:

What you want is B​::C.

Casey\, I'm not sure why you say I want B​::C. I didn't see B​::C mentioning .pmc files\, so perhaps you are trying to tell me that there is a better way to generate an .pmc file using B​::C

My bug report was that .pmc files don't seem to be documented\, but yet perl stat's and uses .pmc files.

I was thinking that if the code in S_doopen_pmc() in pp_ctl.c is not supposed to work then .pmc files should be removed.

S_doopen_pmc(pTHX_ const char *name\, const char *mode) {   STRLEN namelen = strlen(name);   PerlIO *fp;

  if (namelen > 3 && strEQ(name + namelen - 3\, ".pm")) {   SV *pmcsv = Perl_newSVpvf(aTHX_ "%s%c"\, name\, 'c');   char *pmc = SvPV_nolen(pmcsv);   Stat_t pmstat;   Stat_t pmcstat;   if (PerlLIO_stat(pmc\, &pmcstat) \< 0) {   fp = PerlIO_open(name\, mode);   }

When I looked around a little more I found   $ perlcc -B file # Compiles using the bytecode backend mentioned in perldoc perlcc

I tried some variations on that and was able to get the desired results

dd​:tmp$ perlcc -B Echo.pm -o Echo.pmc /usr/local/bin/perlcc​: Will not create a shared library for bytecode dd​:tmp$ perl -e 'require Echo' Hello World

I think that the bug I reported was based on the instructions in ext/B/NOTES that states   perl -MO=Bytecode\,-m\,-oFoo.pmc Foo.pm

I now see the disclamer in perlcompile.pod :-) B​::Bytecode   Stores the parse tree in a machine-independent format\, suitable for   later reloading through the ByteLoader module. Status​: 5 (some things   work\, some things don't\, some things are untested).

p5pRT commented 21 years ago

From david.dyck@fluke.com

This really isn't resolved\, as perldoc -f require states

  If EXPR is a bareword\, the require assumes a ".pm"   extension and replaces "​::" with "/" in the   filename for you\, to make it easy to load standard   modules. This form of loading of modules does not   risk altering your namespace.

but it doesn't mention .pmc.

If an appropriate file with a .pmc extension exists (and is newer than a similar .pm file\, or no .pm file is found) perl will load the .pmc file.

This behavior is not documented in perldoc -f require.

dd​:tmp$ cat Echo.pm warn "Hello World\n"; dd​:tmp$ cat Echox.pm warn "Goodbye World\n";

dd​:tmp$ perlcc -B Echo.pm -o Echox.pmc /usr/local/bin/perlcc​: Will not create a shared library for bytecode dd​:tmp$ touch Echox.pm dd​:tmp$ perl -le 'require Echox' Goodbye World dd​:tmp$ touch Echox.pmc dd​:tmp$ perl -le 'require Echox' Hello World

Same perl code\, different output\, based on timestamps of .pm and .pmc files!

On Fri\, 9 May 2003 at 15​:47 -0000\, Casey West via RT \<perlbug-followup@​perl...​:

From​: Casey West via RT \perlbug\-followup@&#8203;perl\.org To​: dcd Date​: 9 May 2003 15​:47​:29 -0000 Subject​: [perl #8860] [RESOLVED] .pmc extension not documented in require

According to our records\, your request regarding ".pmc extension not documented in require" has been resolved.

If you have any further questions or concerns on the above subject\, please respond to this message.

For other topics\, please create a new ticket.

Please don't feel obligated to say "Thanks" or "Kudos" or "I want to have your child" or "I owe you a beer" -- if you respond to this message it will reopen the ticket. If you must\, please send email directly to the person who handled your ticket\, and not to the tracking system.

\<URL​: http​://rt.perl.org/rt2/Ticket/Display.html?id=8860 >

p5pRT commented 21 years ago

From @cwest

It was Friday\, May 09\, 2003 when David Dyck took the soap box\, saying​: : : This really isn't resolved\, as : perldoc -f require states : : : If EXPR is a bareword\, the require assumes a ".pm" : extension and replaces "​::" with "/" in the : filename for you\, to make it easy to load standard : modules. This form of loading of modules does not : risk altering your namespace. : : but it doesn't mention .pmc.

Now it does\, see patch below.

  Casey West

-- "DOS addresses only 1 Megabyte of RAM because we cannot imagine any applications needing more." -- Microsoft\, 1980\, on the development of DOS

Inline Patch ```diff --- perl-current.orig/pod/perlfunc.pod Fri May 9 00:58:19 2003 +++ perl-current/pod/perlfunc.pod Fri May 9 16:16:56 2003 @@ -4056,6 +4056,15 @@ eval "require $class"; +Now that you understand how C looks for files in the case of +a bareword argument, there is a little extra functionality going on +behind the scenes. Before C looks for a "F<.pm>" extension, +it will first look for a filename with a "F<.pmc>" extension. A file +with this extension is assumed to be Perl bytecode generated by +L. If this file is found, and it's modification +time is newer than a coinciding "F<.pm>" non-compiled file, it will be +loaded in place of that non-compiled file ending in a "F<.pm>" extension. + You can also insert hooks into the import facility, by putting directly Perl code into the @INC array. There are three forms of hooks: subroutine references, array references and blessed objects. ```
p5pRT commented 21 years ago

From dug@plusthree.com

Casey West wrote​:

Now it does\, see patch below.

I believe L\<B​::ByteCode|B​::ByteCode> should be L\<B​::Bytecode|B​::Bytecode>. BTW\, good work with these patches.

Casey West

-- dug

p5pRT commented 21 years ago

From @cwest

It was Friday\, May 09\, 2003 when Douglas Hunter took the soap box\, saying​: : Casey West wrote​: : : >Now it does\, see patch below. : > : : I believe L\<B​::ByteCode|B​::ByteCode> should be : L\<B​::Bytecode|B​::Bytecode>. BTW\, good work with these patches.

Excellent point (dang mac os)\, thank thanks. :-)

  Casey West

-- Shooting yourself in the foot with MS-Windows The gun blows up in your hand.

Inline Patch ```diff --- perl-current.orig/pod/perlfunc.pod Fri May 9 00:58:19 2003 +++ perl-current/pod/perlfunc.pod Fri May 9 16:58:23 2003 @@ -4056,6 +4056,15 @@ eval "require $class"; +Now that you understand how C looks for files in the case of +a bareword argument, there is a little extra functionality going on +behind the scenes. Before C looks for a "F<.pm>" extension, +it will first look for a filename with a "F<.pmc>" extension. A file +with this extension is assumed to be Perl bytecode generated by +L. If this file is found, and it's modification +time is newer than a coinciding "F<.pm>" non-compiled file, it will be +loaded in place of that non-compiled file ending in a "F<.pm>" extension. + You can also insert hooks into the import facility, by putting directly Perl code into the @INC array. There are three forms of hooks: subroutine references, array references and blessed objects. ```
p5pRT commented 21 years ago

From @rgs

Casey West wrote​:

It was Friday\, May 09\, 2003 when Douglas Hunter took the soap box\, saying​: : Casey West wrote​: : : >Now it does\, see patch below. : > : : I believe L\<B​::ByteCode|B​::ByteCode> should be : L\<B​::Bytecode|B​::Bytecode>. BTW\, good work with these patches.

Excellent point (dang mac os)\, thank thanks. :-)

Thanks thanks thanks\, apppplied\, as #19466\, at least this is going to be documented.

--- perl-current.orig/pod/perlfunc.pod Fri May 9 00​:58​:19 2003 +++ perl-current/pod/perlfunc.pod Fri May 9 16​:58​:23 2003 @​@​ -4056\,6 +4056\,15 @​@​

     eval "require $class";

+Now that you understand how C\ looks for files in the case of +a bareword argument\, there is a little extra functionality going on +behind the scenes. Before C\ looks for a "F\<.pm>" extension\, +it will first look for a filename with a "F\<.pmc>" extension. A file +with this extension is assumed to be Perl bytecode generated by +L\<B​::Bytecode|B​::Bytecode>. If this file is found\, and it's modification +time is newer than a coinciding "F\<.pm>" non-compiled file\, it will be +loaded in place of that non-compiled file ending in a "F\<.pm>" extension.

p5pRT commented 21 years ago

@rgs - Status changed from 'open' to 'resolved'

p5pRT commented 21 years ago

From nick@ing-simmons.net

David Dyck \david\.dyck@&#8203;fluke\.com writes​:

This really isn't resolved\, as perldoc -f require states

          If EXPR is a bareword\, the require assumes a "\.pm"
          extension and replaces "&#8203;::" with "/" in the
          filename for you\, to make it easy to load standard
          modules\.  This form of loading of modules does not
          risk altering your namespace\.

but it doesn't mention .pmc.

IIRC we decided that .pmc logic was going to be deprecated or deleted.

-- Nick Ing-Simmons http​://www.ni-s.u-net.com/

p5pRT commented 21 years ago

From @eserte

Nick Ing-Simmons \nick@&#8203;ing\-simmons\.net writes​:

David Dyck \david\.dyck@&#8203;fluke\.com writes​:

This really isn't resolved\, as perldoc -f require states

          If EXPR is a bareword\, the require assumes a "\.pm"
          extension and replaces "&#8203;::" with "/" in the
          filename for you\, to make it easy to load standard
          modules\.  This form of loading of modules does not
          risk altering your namespace\.

but it doesn't mention .pmc.

IIRC we decided that .pmc logic was going to be deprecated or deleted.

Or maybe better to hide the logic behind #ifdef's.

Regards\,   Slaven

-- Slaven Rezic - slaven@​rezic.de

Tk-AppMaster​: a perl/Tk module launcher designed for handhelds   http​://tk-appmaster.sf.net

p5pRT commented 21 years ago

From @rgs

Slaven Rezic wrote​:

Nick Ing-Simmons \nick@&#8203;ing\-simmons\.net writes​:

IIRC we decided that .pmc logic was going to be deprecated or deleted.

Or maybe better to hide the logic behind #ifdef's.

I'd like to hide it behind a "#ifndef PERL_USE_PMC_FILES". So the functionality is here unless we want to build a perl tailored for compilation speed (CGI applications come to mind.)

Or do we really want to kill .pmc files ? That somehow implies some lack of support for B​::Bytecode. (not untrue.)

p5pRT commented 21 years ago

From enache@rdslink.ro

On Sun\, May 11\, 2003 at 10​:50​:47PM +0200\, Rafael Garcia-Suarez wrote​:

Or do we really want to kill .pmc files ? That somehow implies some lack of support for B​::Bytecode. (not untrue.)

Please don't. I just restarted now to revamp Bytecode after a looong delay (sorry)

- with some success - it passes all of t/base\, and most of t/comp and t/op ( allmost all failures are in tests which play with DATA handle ). I hope I get it right before 5.8.1.

Regards\, Adi

p5pRT commented 21 years ago

From nick.ing-simmons@elixent.com

Rafael Garcia-Suarez \rgarciasuarez@&#8203;free\.fr writes​:

Slaven Rezic wrote​:

Nick Ing-Simmons \nick@&#8203;ing\-simmons\.net writes​:

IIRC we decided that .pmc logic was going to be deprecated or deleted.

Or maybe better to hide the logic behind #ifdef's.

I'd like to hide it behind a "#ifndef PERL_USE_PMC_FILES".

So long as the name of the define and the sense of the #ifn?def make sense.

So the functionality is here unless we want to build a perl tailored for compilation speed (CGI applications come to mind.)

For various devious reasons related to selecting versions of modules I often have lots of things in @​INC - the extra (futile) attempts to open .pmc slows things down even more.

Or do we really want to kill .pmc files ? That somehow implies some lack of support for B​::Bytecode. (not untrue.)

Until bytecode loads faster than or is smaller than the .pm file I fail to see the point in it. It does not even hide much now that Deparse is so good.

-- Nick Ing-Simmons http​://www.ni-s.u-net.com/

p5pRT commented 21 years ago

From sky@nanisky.com

On måndag\, maj 12\, 2003\, at 09​:43 Europe/Stockholm\, Nick Ing-Simmons wrote​:

So long as the name of the define and the sense of the #ifn?def make sense.

So the functionality is here unless we want to build a perl tailored for compilation speed (CGI applications come to mind.)

For various devious reasons related to selecting versions of modules I often have lots of things in @​INC - the extra (futile) attempts to open .pmc slows things down even more.

Or do we really want to kill .pmc files ? That somehow implies some lack of support for B​::Bytecode. (not untrue.)

Until bytecode loads faster than or is smaller than the .pm file I fail to see the point in it. It does not even hide much now that Deparse is so good.

Why hide it?

I say keep it so people are encouraged to work on ByteCode or perhaps remove it and put it on the todo that ByteCodeloader should be implemented as a coderef in INC

Arthur

p5pRT commented 21 years ago

From enache@rdslink.ro

On Mon\, May 12\, 2003 at 10​:36​:40AM +0200\, Arthur Bergman wrote​:

Why hide it?

I say keep it so people are encouraged to work on ByteCode or perhaps remove it and put it on the todo that ByteCodeloader should be implemented as a coderef in INC

I completely hate the ByteLoader design but I already spent a lot of hours on it and I promised to make it work - so I have to do it :)

And about hiding - ByteLoader can nuke Deparse by stripping the syntax tree - see if I make this work again.

Since the .pmc has been there for years without ByteLoader working at all I think it should stay there now that it kinda works again.

OK for #ifndef'ing it out but please don't make this the default.

Regards\, Adi

p5pRT commented 21 years ago

From nick.ing-simmons@elixent.com

Arthur Bergman \sky@&#8203;nanisky\.com writes​:

Why hide it?

I say keep it so people are encouraged to work on ByteCode or perhaps remove it and put it on the todo that ByteCodeloader should be implemented as a coderef in INC

You can take by complaints as a vote for the latter.

-- Nick Ing-Simmons http​://www.ni-s.u-net.com/

p5pRT commented 21 years ago

From @pjscott

In article \20030511225047\.6b713c9b\.rgarciasuarez@&#8203;free\.fr\, rgarciasuarez@​free.fr (Rafael Garcia-Suarez) writes​:

Slaven Rezic wrote​:

Nick Ing-Simmons \nick@&#8203;ing\-simmons\.net writes​:

IIRC we decided that .pmc logic was going to be deprecated or deleted.

Or maybe better to hide the logic behind #ifdef's.

I'd like to hide it behind a "#ifndef PERL_USE_PMC_FILES". So the functionality is here unless we want to build a perl tailored for compilation speed (CGI applications come to mind.)

Or do we really want to kill .pmc files ? That somehow implies some lack of support for B​::Bytecode. (not untrue.)

Well if we keep them with the same name won't they be a bit confusing for people when Perl 6/Parrot comes out with a different idea of what a .pmc file is?

-- Peter Scott

p5pRT commented 21 years ago

From nick.ing-simmons@elixent.com

Peter Scott \Peter@&#8203;PSDT\.com writes​:

In article \20030511225047\.6b713c9b\.rgarciasuarez@&#8203;free\.fr\, rgarciasuarez@​free.fr (Rafael Garcia-Suarez) writes​:

Slaven Rezic wrote​:

Nick Ing-Simmons \nick@&#8203;ing\-simmons\.net writes​:

IIRC we decided that .pmc logic was going to be deprecated or deleted.

Or maybe better to hide the logic behind #ifdef's.

I'd like to hide it behind a "#ifndef PERL_USE_PMC_FILES". So the functionality is here unless we want to build a perl tailored for compilation speed (CGI applications come to mind.)

Or do we really want to kill .pmc files ? That somehow implies some lack of support for B​::Bytecode. (not untrue.)

Well if we keep them with the same name won't they be a bit confusing for people when Perl 6/Parrot comes out with a different idea of what a .pmc file is?

Ah yes that was the other reason I had 'em on my hit list.

-- Nick Ing-Simmons http​://www.ni-s.u-net.com/

p5pRT commented 21 years ago

From sky@nanisky.com

On måndag\, maj 12\, 2003\, at 18​:22 Europe/Stockholm\, Nick Ing-Simmons wrote​:

Well if we keep them with the same name won't they be a bit confusing for people when Perl 6/Parrot comes out with a different idea of what a .pmc file is?

Ah yes that was the other reason I had 'em on my hit list.

Perhaps parrot which came along later is the one that should change?

Arthur

p5pRT commented 18 years ago

From @smpeters

[sky@​nanisky.com - Mon May 12 10​:54​:04 2003]​:

On måndag\, maj 12\, 2003\, at 18​:22 Europe/Stockholm\, Nick Ing-Simmons wrote​:

Well if we keep them with the same name won't they be a bit confusing for people when Perl 6/Parrot comes out with a different idea of what a .pmc file is?

Ah yes that was the other reason I had 'em on my hit list.

Perhaps parrot which came along later is the one that should change?

It appears that Perl 5 .pmc files are being used for various Perl 6 projects. Removing or deprecating them now seems to be a bad thing.

p5pRT commented 18 years ago

@smpeters - Status changed from 'open' to 'resolved'