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
[PATCH] Support B::Generate and B::C #10591
Comments
From @jimc---------- Forwarded message ----------
attached is a patch adding fold-constant tests;
d: runs LINKLIST()
can you suggest perl statements that trigger these particular cases ?
|
From @jimc0001-add-constant-expression-folding-tests.patchFrom f08de5533fad89b1364b4b53884c08ce219cf25f Mon Sep 17 00:00:00 2001
From: Jim Cromie <jim.cromie@gmail.com>
Date: Sun, 29 Aug 2010 15:43:49 -0600
Subject: [PATCH 1/2] add constant expression folding tests
test addition, string catenation,
constant args to lc*, uc* and conditionals with gt, lt, ge, le, cmp
also 2 mixed string-cat . arithmetic constant tests,
1st with () to force precendence, 2nd TODO without ()
---
ext/B/t/optree_constants.t | 178 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 177 insertions(+), 1 deletions(-)
diff --git a/ext/B/t/optree_constants.t b/ext/B/t/optree_constants.t
index 47afea4..4f1f727 100644
--- a/ext/B/t/optree_constants.t
+++ b/ext/B/t/optree_constants.t
@@ -13,7 +13,7 @@ BEGIN {
use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
use Config;
-my $tests = 30;
+my $tests = 36;
plan tests => $tests;
SKIP: {
skip "no perlio in this build", $tests unless $Config::Config{useperlio};
@@ -243,6 +243,182 @@ checkOptree ( name => 'call many in a print statement',
strip_open_hints => 1,
expect => $expect, expect_nt => $expect_nt);
+# test constant expression folding
+
+checkOptree ( name => 'arithmetic constant folding in print',
+ code => 'print 1+2+3',
+ strip_open_hints => 1,
+ expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
+# 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->5
+# 1 <;> nextstate(main 937 (eval 53):1) v ->2
+# 4 <@> print sK ->5
+# 2 <0> pushmark s ->3
+# 3 <$> const[IV 6] s ->4
+EOT_EOT
+# 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->5
+# 1 <;> nextstate(main 937 (eval 53):1) v ->2
+# 4 <@> print sK ->5
+# 2 <0> pushmark s ->3
+# 3 <$> const(IV 6) s ->4
+EONT_EONT
+
+checkOptree ( name => 'string constant folding in print',
+ code => 'print "foo"."bar"',
+ strip_open_hints => 1,
+ expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
+# 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->5
+# 1 <;> nextstate(main 942 (eval 55):1) v ->2
+# 4 <@> print sK ->5
+# 2 <0> pushmark s ->3
+# 3 <$> const[PV "foobar"] s ->4
+EOT_EOT
+# 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->5
+# 1 <;> nextstate(main 942 (eval 55):1) v ->2
+# 4 <@> print sK ->5
+# 2 <0> pushmark s ->3
+# 3 <$> const(PV "foobar") s ->4
+EONT_EONT
+
+checkOptree ( name => 'boolean or folding',
+ code => 'print "foobar" if 1 or 0',
+ strip_open_hints => 1,
+ expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
+# 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->5
+# 1 <;> nextstate(main 942 (eval 55):1) v ->2
+# 4 <@> print sK ->5
+# 2 <0> pushmark s ->3
+# 3 <$> const[PV "foobar"] s ->4
+EOT_EOT
+# 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->5
+# 1 <;> nextstate(main 942 (eval 55):1) v ->2
+# 4 <@> print sK ->5
+# 2 <0> pushmark s ->3
+# 3 <$> const(PV "foobar") s ->4
+EONT_EONT
+
+checkOptree ( name => 'lc*,uc*,gt,lt,ge,le,cmp',
+ code => sub {
+ $s = uc('foo.').ucfirst('bar.').lc('LOW.').lcfirst('LOW');
+ print "lt-a-b" if "a" lt "b";
+ print "gt-b-a" if "b" gt "a";
+ print "le-a-b" if "a" le "b";
+ print "ge-b-a" if "b" ge "a";
+ print "cmp-b-a" if "b" cmp "a";
+ },
+ strip_open_hints => 1,
+ expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
+# p <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->p
+# 1 <;> nextstate(main 776 optree_constants.t:307) v:{ ->2
+# 4 <2> sassign vKS/2 ->5
+# 2 <$> const[PV "FOO.Bar.low.lOW"] s ->3
+# - <1> ex-rv2sv sKRM*/1 ->4
+# 3 <$> gvsv[*s] s ->4
+# 5 <;> nextstate(main 776 optree_constants.t:308) v:{ ->6
+# 8 <@> print vK ->9
+# 6 <0> pushmark s ->7
+# 7 <$> const[PV "lt-a-b"] s ->8
+# 9 <;> nextstate(main 776 optree_constants.t:309) v:{ ->a
+# c <@> print vK ->d
+# a <0> pushmark s ->b
+# b <$> const[PV "gt-b-a"] s ->c
+# d <;> nextstate(main 776 optree_constants.t:310) v:{ ->e
+# g <@> print vK ->h
+# e <0> pushmark s ->f
+# f <$> const[PV "le-a-b"] s ->g
+# h <;> nextstate(main 776 optree_constants.t:311) v:{ ->i
+# k <@> print vK ->l
+# i <0> pushmark s ->j
+# j <$> const[PV "ge-b-a"] s ->k
+# l <;> nextstate(main 776 optree_constants.t:312) v:{ ->m
+# o <@> print sK ->p
+# m <0> pushmark s ->n
+# n <$> const[PV "cmp-b-a"] s ->o
+EOT_EOT
+# p <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->p
+# 1 <;> nextstate(main 776 optree_constants.t:307) v:{ ->2
+# 4 <2> sassign vKS/2 ->5
+# 2 <$> const(PV "FOO.Bar.low.lOW") s ->3
+# - <1> ex-rv2sv sKRM*/1 ->4
+# 3 <$> gvsv(*s) s ->4
+# 5 <;> nextstate(main 776 optree_constants.t:308) v:{ ->6
+# 8 <@> print vK ->9
+# 6 <0> pushmark s ->7
+# 7 <$> const(PV "lt-a-b") s ->8
+# 9 <;> nextstate(main 776 optree_constants.t:309) v:{ ->a
+# c <@> print vK ->d
+# a <0> pushmark s ->b
+# b <$> const(PV "gt-b-a") s ->c
+# d <;> nextstate(main 776 optree_constants.t:310) v:{ ->e
+# g <@> print vK ->h
+# e <0> pushmark s ->f
+# f <$> const(PV "le-a-b") s ->g
+# h <;> nextstate(main 776 optree_constants.t:311) v:{ ->i
+# k <@> print vK ->l
+# i <0> pushmark s ->j
+# j <$> const(PV "ge-b-a") s ->k
+# l <;> nextstate(main 776 optree_constants.t:312) v:{ ->m
+# o <@> print sK ->p
+# m <0> pushmark s ->n
+# n <$> const(PV "cmp-b-a") s ->o
+EONT_EONT
+
+checkOptree ( name => 'mixed constant folding, with explicit precendence',
+ code => '$i=1; print "foo"."bar".(2+3+$i)',
+ strip_open_hints => 1,
+ expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
+# d <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->d
+# 1 <;> nextstate(main 955 (eval 60):1) v:{ ->2
+# 4 <2> sassign vKS/2 ->5
+# 2 <$> const[IV 1] s ->3
+# - <1> ex-rv2sv sKRM*/1 ->4
+# 3 <$> gvsv[*i] s ->4
+# 5 <;> nextstate(main 955 (eval 60):1) v:{ ->6
+# c <@> print sK ->d
+# 6 <0> pushmark s ->7
+# b <2> concat[t4] sK/2 ->c
+# 7 <$> const[PV "foobar"] s ->8
+# a <2> add[t3] sKP/2 ->b
+# 8 <$> const[IV 5] s ->9
+# - <1> ex-rv2sv sK/1 ->a
+# 9 <$> gvsv[*i] s ->a
+EOT_EOT
+# d <1> leavesub[1 ref] K/REFC,1 ->(end)
+# - <@> lineseq KP ->d
+# 1 <;> nextstate(main 955 (eval 60):1) v:{ ->2
+# 4 <2> sassign vKS/2 ->5
+# 2 <$> const(IV 1) s ->3
+# - <1> ex-rv2sv sKRM*/1 ->4
+# 3 <$> gvsv(*i) s ->4
+# 5 <;> nextstate(main 955 (eval 60):1) v:{ ->6
+# c <@> print sK ->d
+# 6 <0> pushmark s ->7
+# b <2> concat[t4] sK/2 ->c
+# 7 <$> const(PV "foobar") s ->8
+# a <2> add[t3] sKP/2 ->b
+# 8 <$> const(IV 5) s ->9
+# - <1> ex-rv2sv sK/1 ->a
+# 9 <$> gvsv(*i) s ->a
+EONT_EONT
+
+checkOptree ( name => 'mixed constant folding',
+ code => '$i=1; print "foo"."bar". 2+3+$i',
+ todo => 1,
+ strip_open_hints => 1,
+ expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
+string folding breaks when arithmetic folding is also done
+EOT_EOT
+string folding breaks when arithmetic folding is also done
+EONT_EONT
+
} #skip
__END__
--
1.7.2.2
|
From @jimc0002-add-Ilib-Iext-B-to-runperl-calls.patchFrom b6759ecfee39701442dff777bab4e2467ef6dc31 Mon Sep 17 00:00:00 2001
From: Jim Cromie <jim.cromie@gmail.com>
Date: Sun, 29 Aug 2010 16:40:34 -0600
Subject: [PATCH 2/2] add -Ilib -Iext/B to runperl calls
adding these to @INC lets tests find O.pm when run bare,
ie not inside make test. Without it, some of these tests
fail, despite having the -Iargs passed in.
for t in ext/B/t/*.t; do
echo $t; ./perl -Ilib -I ext/B -I ext/B/t/ $t
done
---
ext/B/t/OptreeCheck.pm | 3 ++-
ext/B/t/concise.t | 20 +++++++++++++-------
ext/B/t/showlex.t | 2 +-
3 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/ext/B/t/OptreeCheck.pm b/ext/B/t/OptreeCheck.pm
index ce2482d..b0f3d53 100644
--- a/ext/B/t/OptreeCheck.pm
+++ b/ext/B/t/OptreeCheck.pm
@@ -511,7 +511,8 @@ sub getRendering {
if ($tc->{prog}) {
- $rendering = runperl( switches => ['-w',join(',',"-MO=Concise",@opts)],
+ $rendering = runperl( switches => ['-w', '-Ilib', '-Iext/B',
+ join(',',"-MO=Concise",@opts)],
prog => $tc->{prog}, stderr => 1,
); # verbose => 1);
} else {
diff --git a/ext/B/t/concise.t b/ext/B/t/concise.t
index 3eb22ce..eecf500 100644
--- a/ext/B/t/concise.t
+++ b/ext/B/t/concise.t
@@ -14,7 +14,7 @@ plan tests => 157;
require_ok("B::Concise");
-$out = runperl(switches => ["-MO=Concise"], prog => '$a', stderr => 1);
+$out = runperl(switches => ["-Iext/B", "-MO=Concise"], prog => '$a', stderr => 1);
# If either of the next two tests fail, it probably means you need to
# fix the section labeled 'fragile kludge' in Concise.pm
@@ -366,14 +366,16 @@ SKIP: {
# re-vivified later, but not in time for this (BEGIN/CHECK)-time
# rendering.
-$out = runperl ( switches => ["-MO=Concise,Config::AUTOLOAD"],
+$out = runperl ( switches => ["-Ilib", "-Iext/B",
+ "-MO=Concise,Config::AUTOLOAD"],
prog => 'use Config; BEGIN { $Config{awk} }',
stderr => 1 );
like($out, qr/Config::AUTOLOAD exists in stash, but has no START/,
"coderef properly undefined");
-$out = runperl ( switches => ["-MO=Concise,Config::AUTOLOAD"],
+$out = runperl ( switches => ["-Ilib", "-Iext/B",
+ "-MO=Concise,Config::AUTOLOAD"],
prog => 'use Config; CHECK { $Config{awk} }',
stderr => 1 );
@@ -383,7 +385,8 @@ like($out, qr/Config::AUTOLOAD exists in stash, but has no START/,
# test -stash and -src rendering
# todo: stderr=1 puts '-e syntax OK' into $out,
# conceivably fouling one of the lines that are tested
-$out = runperl ( switches => ["-MO=Concise,-stash=B::Concise,-src"],
+$out = runperl ( switches => ["-Ilib", "-Iext/B",
+ "-MO=Concise,-stash=B::Concise,-src"],
prog => '-e 1', stderr => 1 );
like($out, qr/FUNC: \*B::Concise::concise_cv_obj/,
@@ -401,13 +404,15 @@ like($out, qr/PAD_FAKELEX_MULTI is a constant sub, optimized to a IV/,
like($out, qr/\# 4\d\d: \s+ \$l->concise\(\$level\);/,
"src-line rendering works");
-$out = runperl ( switches => ["-MO=Concise,-stash=ExtUtils::Mksymlists,-src,-exec"],
+$out = runperl ( switches => ["-Ilib", "-Iext/B",
+ "-MO=Concise,-stash=ExtUtils::Mksymlists,-src,-exec"],
prog => '-e 1', stderr => 1 );
like($out, qr/FUNC: \*ExtUtils::Mksymlists::_write_vms/,
"stash rendering loads package as needed");
-$out = runperl ( switches => ["-MO=Concise,-stash=Data::Dumper,-src,-exec"],
+$out = runperl ( switches => ["-Ilib", "-Iext/B",
+ "-MO=Concise,-stash=Data::Dumper,-src,-exec"],
prog => '-e 1', stderr => 1 );
like($out, qr/FUNC: \*Data::Dumper::format_refaddr/,
@@ -416,7 +421,8 @@ like($out, qr/FUNC: \*Data::Dumper::format_refaddr/,
my $prog = q{package FOO; sub bar { print "bar" } package main; FOO::bar(); };
# this would fail if %INC used for -stash test
-$out = runperl ( switches => ["-MO=Concise,-src,-stash=FOO,-main"],
+$out = runperl ( switches => ["-Ilib", "-Iext/B",
+ "-MO=Concise,-src,-stash=FOO,-main"],
prog => $prog, stderr => 1 );
like($out, qr/FUNC: \*FOO::bar/,
diff --git a/ext/B/t/showlex.t b/ext/B/t/showlex.t
index 257b9c9..c10b712 100644
--- a/ext/B/t/showlex.t
+++ b/ext/B/t/showlex.t
@@ -51,7 +51,7 @@ sub padrep {
for $newlex ('', '-newlex') {
- $out = runperl ( switches => ["-MO=Showlex,$newlex"],
+ $out = runperl ( switches => ["-Ilib", "-Iext/B", "-MO=Showlex,$newlex"],
prog => 'my ($a,$b)', stderr => 1 );
$na = padrep('$a',$newlex);
$nb = padrep('$b',$newlex);
--
1.7.2.2
|
From @rurbanJim Cromie (via RT) schrieb:
I already posted a similar example with and without. From worse to better, so you see how bad the optimiser really is. Do almost nothing, slow: ($n is not detected as constant) $ perl -MO=Terse -e '$n=1127;$result=($n%1000)+167772160;' Use at least intops: $ perl -MO=Terse -Minteger -e '$n=1127;$result=($n%1000)+167772160;' Do some simple minor folding: $ perl -MO=Terse -e '$result=(1127%1000)+167772160;' And finally constant fold with symbols: $ perl -MO=Terse -Minteger -e 'use constant n=>1127; |
The RT System itself - Status changed from 'new' to 'open' |
From @jimcOn Tue, Aug 31, 2010 at 3:50 PM, Reini Urban via RT <
yes - I see that now, Ive tested fold-constants wrt Nicks a-e comments, And my "system" tests work fine as a test of internal behavior. So, to doublecheck, you still want embed with XM rather than A, correct ?
Im not sure I agree - a few failures wouldnt slow down somebody I wonder whats needed to catch and optimize
|
From @doyI'm not really sure what's going on here, because there seems to be some -doy |
From @rurbanOn Thu, Jul 5, 2012 at 2:34 AM, Jesse Luehrs via RT
Two things are missing: Nick's argumentations against it was Nick also said that he tries to stay away from things he does not understand. 2. [RT #81332] Nick moved XSLoader::load B into the BEGIN block, thus |
From @nwc10On Sun, Jul 08, 2012 at 10:42:25AM -0500, Reini Urban wrote:
Yes. I have asked questions which *remain* unanswered. I shall restate them, I remain of the strong opinion that the changes requested have not been
No, I understand it well enough to see that it's actually complex enough that http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2010-08/msg00920.html You patch has no tests. For the documentation for fold_constants I see: And I should now note that it no longer does all of the above. It now only runs LINKLIST() and folds constants. Is that the behaviour that B::Generate requires? Or does it require the
There was common agreement - that it was a bug. Do you have any URLs to To restate - the "optimisation", present until 5.6.0, was that the peephole http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2010-08/msg01025.html $ /export/home/nwc10/Reference/5.005_03/bin/perl5.00503 -e 'my $a = "AB"; my $int = 0x7FFFFFFF + length $a + 0x7FFFFFFF; warn $int' Similarly the return result of time is an integer, so it was assumed to be $ /export/home/nwc10/Reference/5.005_03/bin/perl5.00503 -le 'print time; print time * 1000' whereas the expected answer would be something like this: $ perl -le 'print time; print time * 1000' which 5.6.0 and later on a 32 bit system give. Because they don't have If I understood you correctly at the time (sorry, can't find the message), $ perl -le 'print 4294967297 * 4294967295' because the former is an integer expression, whereas the latter is a floating As I stated back then: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2010-08/msg01020.html I don't agree. I don't think that it's safe. I can't *prove* that it's safe, An optimisation is only an optimisation if it is both a) correct than what it replaces. Moreover, buggy optimisations cost far far more people time than they save. I'm not convinced that it's possible to prove that this is a safe a) signed integer overflow is undefined behaviour
No, as I stated at the time, it needed unit tests. Jim provided tests that What is needed are tests that calling the function fold_constants() at the C (Or, as above - whatever it is that "fold constants" is supposed to do, The current tests do not verify that the function behaves. It would be
No, that it is should not be called at runtime. More specifically, that it PL_warnhook = oldwarnhook; which would put the interpreter in an inconsistent state if the function To restate a previous message on *exactly* this subject: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2009-07/msg01272.html Given this: To call these functions properly, the interpreter state must be "compile time". Furthermore, the reason that I find the entire subject of B::Generate http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2010-08/msg00988.html So I commented out the assertion, and rebuilt perl. I've added runloop tracing: So, specifically, because B::Generate has no DESTROY method, and because of 1: Any ops that B::Generate creates will (by default) *leak* plus 3: It provides *no abstraction* from the C level manipulations hence I continue to assert that the approach it takes can't work.
People should not be changing things that they don't understand. Hence *no-one* should be changing the code unless they understand it. I have asked for clarification on areas that I know I don't understand. Nicholas Clark |
From @doyOn Tue, Jul 10, 2012 at 05:04:10PM +0100, Nicholas Clark wrote:
On a related note, I would very much like to see #11606 be finished at some -doy |
From @rjbs* Nicholas Clark <nick@ccl4.org> [2012-07-10T12:04:10]
Alternately, "I made some changes and it did what I wanted! I have no idea That's actually often going to be a lot better than "I didn't know why it Also, better than, "I didn't know why it worked, and neither did the guy who -- |
Migrated from rt.perl.org#77536 (status was 'open')
Searchable as RT77536$
The text was updated successfully, but these errors were encountered: