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] Move non-constant folding parts of fold_constants into a separate functions. #11632
Comments
From gerard@ggoossen.netThis is a bug report for perl from gerard@ggoossen.net, From 763753c0fca75fd509e7c93b8bf8b8911fc93ff4 Mon Sep 17 00:00:00 2001 The non-constant folding parts of fold_constants are moved into embed.fnc | 2 + Inline Patchdiff --git a/embed.fnc b/embed.fnc
index 106c6c7..b7988df 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -406,6 +406,8 @@ p |char* |find_script |NN const char *scriptname|bool dosearch \
|NULLOK const char *const *const search_ext|I32 flags
#if defined(PERL_IN_OP_C)
s |OP* |force_list |NULLOK OP* arg
+i |OP* |op_integerize |NN OP *o
+i |OP* |op_std_init |NN OP *o
: FIXME
s |OP* |fold_constants |NN OP *o
#endif
diff --git a/embed.h b/embed.h
index 4ac70e7..120567f 100644
--- a/embed.h
+++ b/embed.h
@@ -1355,6 +1355,8 @@
#define new_logop(a,b,c,d) S_new_logop(aTHX_ a,b,c,d)
#define no_bareword_allowed(a) S_no_bareword_allowed(aTHX_ a)
#define no_fh_allowed(a) S_no_fh_allowed(aTHX_ a)
+#define op_integerize(a) S_op_integerize(aTHX_ a)
+#define op_std_init(a) S_op_std_init(aTHX_ a)
#define opt_scalarhv(a) S_opt_scalarhv(aTHX_ a)
#define pmtrans(a,b,c) S_pmtrans(aTHX_ a,b,c)
#define process_special_blocks(a,b,c) S_process_special_blocks(aTHX_ a,b,c)
diff --git a/op.c b/op.c
index 1d2b437..c36c325 100644
--- a/op.c
+++ b/op.c
@@ -2894,6 +2894,44 @@ Perl_jmaybe(pTHX_ OP *o)
return o;
}
+PERL_STATIC_INLINE OP *
+S_op_std_init(pTHX_ OP *o)
+{
+ I32 type = o->op_type;
+
+ PERL_ARGS_ASSERT_OP_STD_INIT;
+
+ if (PL_opargs[type] & OA_RETSCALAR)
+ scalar(o);
+ if (PL_opargs[type] & OA_TARGET && !o->op_targ)
+ o->op_targ = pad_alloc(type, SVs_PADTMP);
+
+ return o;
+}
+
+PERL_STATIC_INLINE OP *
+S_op_integerize(pTHX_ OP *o)
+{
+ I32 type = o->op_type;
+
+ PERL_ARGS_ASSERT_OP_INTEGERIZE;
+
+ /* integerize op, unless it happens to be C<-foo>.
+ * XXX should pp_i_negate() do magic string negation instead? */
+ if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
+ && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
+ && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
+ {
+ o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
+ }
+
+ if (type == OP_NEGATE)
+ /* XXX might want a ck_negate() for this */
+ cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
+
+ return o;
+}
+
static OP *
S_fold_constants(pTHX_ register OP *o)
{
@@ -2912,28 +2950,10 @@ S_fold_constants(pTHX_ register OP *o)
PERL_ARGS_ASSERT_FOLD_CONSTANTS;
- if (PL_opargs[type] & OA_RETSCALAR)
- scalar(o);
- if (PL_opargs[type] & OA_TARGET && !o->op_targ)
- o->op_targ = pad_alloc(type, SVs_PADTMP);
-
- /* integerize op, unless it happens to be C<-foo>.
- * XXX should pp_i_negate() do magic string negation instead? */
- if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
- && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
- && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
- {
- o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
- }
-
if (!(PL_opargs[type] & OA_FOLDCONST))
goto nope;
switch (type) {
- case OP_NEGATE:
- /* XXX might want a ck_negate() for this */
- cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
- break;
case OP_UCFIRST:
case OP_LCFIRST:
case OP_UC:
@@ -3111,7 +3131,7 @@ Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
if (o->op_type != (unsigned)type)
return o;
- return fold_constants(o);
+ return fold_constants(op_integerize(op_std_init(o)));
}
/*
@@ -3659,7 +3679,7 @@ Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
if (unop->op_next)
return (OP*)unop;
- return fold_constants((OP *) unop);
+ return fold_constants(op_integerize(op_std_init((OP *) unop)));
}
/*
@@ -3709,7 +3729,7 @@ Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
binop->op_last = binop->op_first->op_sibling;
- return fold_constants((OP *)binop);
+ return fold_constants(op_integerize(op_std_init((OP *)binop)));
}
static int uvcompare(const void *a, const void *b)
@@ -8564,7 +8584,7 @@ Perl_ck_select(pTHX_ OP *o)
o->op_type = OP_SSELECT;
o->op_ppaddr = PL_ppaddr[OP_SSELECT];
o = ck_fun(o);
- return fold_constants(o);
+ return fold_constants(op_integerize(op_std_init(o)));
}
}
o = ck_fun(o);
diff --git a/proto.h b/proto.h
index 4c79414..58fc77e 100644
--- a/proto.h
+++ b/proto.h
@@ -5569,6 +5569,16 @@ STATIC OP* S_no_fh_allowed(pTHX_ OP *o)
#define PERL_ARGS_ASSERT_NO_FH_ALLOWED \
assert(o)
+PERL_STATIC_INLINE OP* S_op_integerize(pTHX_ OP *o)
+ __attribute__nonnull__(pTHX_1);
+#define PERL_ARGS_ASSERT_OP_INTEGERIZE \
+ assert(o)
+
+PERL_STATIC_INLINE OP* S_op_std_init(pTHX_ OP *o)
+ __attribute__nonnull__(pTHX_1);
+#define PERL_ARGS_ASSERT_OP_STD_INIT \
+ assert(o)
+
STATIC OP* S_opt_scalarhv(pTHX_ OP* rep_op)
__attribute__nonnull__(pTHX_1);
#define PERL_ARGS_ASSERT_OPT_SCALARHV \
--
Flags: Site configuration information for perl 5.15.2: Configured by gerard at Sun Sep 4 14:41:00 CEST 2011. Summary of my perl5 (revision 5 version 15 subversion 2) configuration: Locally applied patches: @INC for perl 5.15.2: Environment for perl 5.15.2: |
From @cpansproutOn Sun Sep 04 06:44:43 2011, ggoossen wrote:
Don’t integerization and OP_NEGATE folding both fall under constant |
The RT System itself - Status changed from 'new' to 'open' |
From @hvds"Father Chrysostomos via RT" <perlbug-followup@perl.org> wrote: Isn't (this) integerization to switch op types to integer variants In that case, this seems a perfectly fair example of the ongoing Hugo |
From @cpansproutOn Sun Sep 04 14:36:46 2011, hv wrote:
Is it possible nonetheless to keep OP_NEGATE folding in fold_constants, |
From @hvds"Father Chrysostomos via RT" <perlbug-followup@perl.org> wrote: There are two references to OP_NEGATE in S_op_integerize. The first I don't see anything there that's folding constants. Though if I'm Hugo |
From gerard@ggoossen.netOn Sun, Sep 04, 2011 at 10:50:40PM -0700, Hugo van der Sanden via RT wrote:
You're right about what it is doing, and indeed creating a ck_negate Gerard |
From @cpansproutOn Sun Sep 04 22:50:40 2011, hv wrote:
If S_op_integerize is a static function, it probably doesn’t matter what |
From @cpansproutOn Mon Sep 05 08:21:11 2011, sprout wrote:
And I’ve just applied your patch as 985b9e5. Thank you. |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#98372 (status was 'resolved')
Searchable as RT98372$
The text was updated successfully, but these errors were encountered: