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

Weed out needless PERL_UNUSED_ARG #14420

Open
p5pRT opened this issue Jan 17, 2015 · 13 comments
Open

Weed out needless PERL_UNUSED_ARG #14420

p5pRT opened this issue Jan 17, 2015 · 13 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 17, 2015

Migrated from rt.perl.org#123616 (status was 'open')

Searchable as RT123616$

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2015

From jasmine.ngan@outlook.com

Hi there,

This is my first time contributing a patch so I'm looking for a little guidance. As suggested by the subject and with assistance from Hugo at the London Perl Hackday, I've weeded out some obvious PERL_UNUSED_ARG statements inside static functions as requested in the Perl 5 todo.pod file.

The remaining PERL_UNUSED_ARG statements appear to be for variables that are (1) contained in non-static functions, (2) conditionally used depending on pre-processor macros or (3) placeholders so that the static function prototypes match particular function pointers.

I'm not sure if this task is completed yet so I haven't removed the item from todo.pm yet. Let me know what you think. Thanks!

Kind regards,
Jasmine Ngan

 

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2015

From jasmine.ngan@outlook.com

0001-Removed-PERL_UNUSED_ARG-in-S_grok_bslash_x.patch
From f4e4e2e0a53f02a32e7cc0d98c62910e979a8a76 Mon Sep 17 00:00:00 2001
From: Jasmine Ngan <jasmine.ngan@outlook.com>
Date: Sat, 17 Jan 2015 14:26:02 +0000
Subject: [PATCH 1/3] Removed PERL_UNUSED_ARG() in S_grok_bslash_x()

output_warning is actually used.
---
 dquote_static.c |    2 --
 1 file changed, 2 deletions(-)

diff --git a/dquote_static.c b/dquote_static.c
index 16227c1..076e6c2 100644
--- a/dquote_static.c
+++ b/dquote_static.c
@@ -218,8 +218,6 @@ S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
 
     PERL_ARGS_ASSERT_GROK_BSLASH_X;
 
-    PERL_UNUSED_ARG(output_warning);
-
     assert(**s == 'x');
     (*s)++;
 
-- 
1.7.10.4

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2015

From jasmine.ngan@outlook.com

0002-Changed-PERL_UNUSED_VAR-to-PERL_UNUSED_ARG-for-items.patch
From f80dd918e4d16399482fc7fbefdc357271c6854e Mon Sep 17 00:00:00 2001
From: Jasmine Ngan <jasmine.ngan@outlook.com>
Date: Sat, 17 Jan 2015 15:04:03 +0000
Subject: [PATCH 2/3] Changed PERL_UNUSED_VAR to PERL_UNUSED_ARG for items

items is not a function argument but a local variable.
---
 perl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/perl.c b/perl.c
index bb4a342..3f32d6e 100644
--- a/perl.c
+++ b/perl.c
@@ -1768,7 +1768,7 @@ S_Internals_V(pTHX_ CV *cv)
 #  endif	       
 	;
     PERL_UNUSED_ARG(cv);
-    PERL_UNUSED_ARG(items);
+    PERL_UNUSED_VAR(items);
 
     EXTEND(SP, entries);
 
-- 
1.7.10.4

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2015

From jasmine.ngan@outlook.com

0003-Added-myself-to-AUTHORS.patch
From bf3ec1f50e0d089e80dae92aa6fbee774cd91cc6 Mon Sep 17 00:00:00 2001
From: Jasmine Ngan <jasmine.ngan@outlook.com>
Date: Sat, 17 Jan 2015 16:02:44 +0000
Subject: [PATCH 3/3] Added myself to AUTHORS

---
 AUTHORS |    1 +
 1 file changed, 1 insertion(+)

diff --git a/AUTHORS b/AUTHORS
index 7f2b8f0..61a9dfc 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -534,6 +534,7 @@ Jared Rhine			<jared@organic.com>
 Jari Aalto			<jari.aalto@poboxes.com>
 Jarkko Hietaniemi		<jhi@iki.fi>
 Jasmine Ahuja			<jasmine.ahuja11@gmail.com>
+Jasmine Ngan			<jasmine.ngan@outlook.com>
 Jason A. Smith			<smithj4@rpi.edu>
 Jason E. Stewart		<jason@openinformatics.com>
 Jason Hord			<pravus@cpan.org>
-- 
1.7.10.4

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2015

From @bulk88

On Sat Jan 17 09​:00​:57 2015, jasmine.ngan@​outlook.com wrote​:

Hi there,

This is my first time contributing a patch so I'm looking for a little
guidance. As suggested by the subject and with assistance from Hugo at
the London Perl Hackday, I've weeded out some obvious PERL_UNUSED_ARG
statements inside static functions as requested in the Perl 5 todo.pod
file.

The remaining PERL_UNUSED_ARG statements appear to be for variables
that are (1) contained in non-static functions, (2) conditionally used
depending on pre-processor macros or (3) placeholders so that the
static function prototypes match particular function pointers.

Reading about dquote_static.c and grok_bslash_x brings up a couple questions how its implementation.

grok_bslash_x is 0x133 bytes of VC 2003 -O1 32 bit machine code. It is declared as PERL_STATIC_INLINE in dquote_static.c and in "EMiR" embed.fnc. Something that fat in machine code and pagefuls of C code should be inlined in exactly one scenario, it has only 1 caller, and it is unconditionally (basically not in a "if" branch) executed in that caller. VC optimizer refused to inline grok_bslash_x and instead it is called from 3 callers in VC machine code and in Perl C source code, S_regatom, S_regclass, and S_scan_const.

The inline came from http​://perl5.git.perl.org/perl.git/commitdiff/a04812933fd16241c831d020a4c64870d7ca8624 by khw from 5.17.1.

If I didn't have VC's WPO/LTO/LTCG mode turned on, there would be 2 copies of S_grok_bslash_x in the perl binary (VC 6 doesn't have LTCG, too old, so it suffers too), since a normal C linker can't dedup nameless, symbol-less static functions. Here is a symbol list from HPUX HP C blead perl showing that HPUX ld didn't dedup the functions.

name addr length
S_grok_bslash_c 00097224 00000148
S_grok_bslash_c_1 000BFBE0 00000148
S_grok_bslash_o 0009736C 000001CC
S_grok_bslash_o_1 000BFD28 000001CC
S_grok_bslash_x 00097538 00000268
S_grok_bslash_x_1 000BFEF4 00000268

I assume that all 3 S_grok_blash* functions are used in re​::* XS module.

There are 2 things that should have been done.

Either S_grok* becomes Perl_grok*_*p and Xp or stays as S_grok* and becomes X in embed.fnc, so they are exported to re​::* XS SO.

or

dquote_static.c becomes a formal translation unit for core but its functions are not exported in embed.fnc. Then on restricted visibility platforms (IE Win32) it is then #include-ed in re​::* again but this time S_grok_bslash* are PERL_STATIC_INLINE. dquote_static.c and embed.fnc has an

#if PERL_EXT && RESTRICTED_SYM_VIS
iR |bool |grok_bslash_xp |NN char** s|NN UV* uv \
  |NN const char** error_msg \
  |const bool strict \
  |const bool silence_non_portable \
  |const bool utf8
#elif PERL_CORE
pR |bool |grok_bslash_xp |NN char** s|NN UV* uv \
  |NN const char** error_msg \
  |const bool strict \
  |const bool silence_non_portable \
  |const bool utf8
#endif

#if PERL_EXT && RESTRICTED_SYM_VIS
PERL_STATIC_INLINE bool
#elif PERL_CORE
bool
#else
# error What are you doing?
#endif
S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
  const bool strict,
  const bool silence_non_portable,
  const bool UTF)
{

This way core's S_grok_bslash can get WPO optimized (random register calling conventions, removing unused params, merging params, etc) but re​:: XS SO/DLL gets its own machine code copy that also was hopefully WPO-ed.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2015

From @bulk88

On Sat Jan 17 09​:00​:57 2015, jasmine.ngan@​outlook.com wrote​:

Hi there,

This is my first time contributing a patch so I'm looking for a little
guidance. As suggested by the subject and with assistance from Hugo at
the London Perl Hackday, I've weeded out some obvious PERL_UNUSED_ARG
statements inside static functions as requested in the Perl 5 todo.pod
file.

The remaining PERL_UNUSED_ARG statements appear to be for variables
that are (1) contained in non-static functions, (2) conditionally used
depending on pre-processor macros or (3) placeholders so that the
static function prototypes match particular function pointers.

I'm not sure if this task is completed yet so I haven't removed the
item from todo.pm yet. Let me know what you think. Thanks!

Kind regards,
Jasmine Ngan

Im inclined to say https://rt-archive.perl.org/perl5/Ticket/Attachment/1326848/707965/0001-Removed-PERL_UNUSED_ARG-in-S_grok_bslash_x.patch is wrong. output_warning is unused in non-DEBUGGING and DEBUGGING. I removed it as an experiment and both build types compiled, see attached patch.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2015

From @bulk88

0001-WIP-output_warning-doesn-t-seem-to-be-used-in-grok_b.patch
From 2b0705617ed787a039499f8ae7be530982e65302 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Sat, 17 Jan 2015 17:53:18 -0500
Subject: [PATCH] WIP output_warning doesn't seem to be used in grok_bslash_x

not for blead, this patch is an experiment
---
 dquote_static.c |    8 +++-----
 embed.fnc       |    3 +--
 embed.h         |    2 +-
 perl.h          |    4 ++++
 proto.h         |    4 ++--
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/dquote_static.c b/dquote_static.c
index 5fe7f0b..505e83b 100644
--- a/dquote_static.c
+++ b/dquote_static.c
@@ -180,8 +180,8 @@ S_grok_bslash_o(pTHX_ char **s, UV *uv, const char** error_msg,
 }
 
 PERL_STATIC_INLINE bool
-S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
-                      const bool output_warning, const bool strict,
+S_grok_bslash_xp(pTHX_ char **s, UV *uv, const char** error_msg,
+                      const bool strict,
                       const bool silence_non_portable,
                       const bool UTF)
 {
@@ -216,9 +216,7 @@ S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
     STRLEN numbers_len;
     I32 flags = PERL_SCAN_DISALLOW_PREFIX;
 
-    PERL_ARGS_ASSERT_GROK_BSLASH_X;
-
-    PERL_UNUSED_ARG(output_warning);
+    PERL_ARGS_ASSERT_GROK_BSLASH_XP;
 
     assert(**s == 'x');
     (*s)++;
diff --git a/embed.fnc b/embed.fnc
index 1444fd0..0652717 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -799,9 +799,8 @@ EMsR	|bool	|grok_bslash_o	|NN char** s|NN UV* uv           \
 				|const bool strict               \
 				|const bool silence_non_portable \
 				|const bool utf8
-EMiR	|bool	|grok_bslash_x	|NN char** s|NN UV* uv           \
+EMiR	|bool	|grok_bslash_xp	|NN char** s|NN UV* uv           \
 				|NN const char** error_msg       \
-				|const bool output_warning       \
 				|const bool strict               \
 				|const bool silence_non_portable \
 				|const bool utf8
diff --git a/embed.h b/embed.h
index 875de9c..f259a33 100644
--- a/embed.h
+++ b/embed.h
@@ -1037,7 +1037,7 @@
 #define form_short_octal_warning(a,b)	S_form_short_octal_warning(aTHX_ a,b)
 #define grok_bslash_c(a,b)	S_grok_bslash_c(aTHX_ a,b)
 #define grok_bslash_o(a,b,c,d,e,f,g)	S_grok_bslash_o(aTHX_ a,b,c,d,e,f,g)
-#define grok_bslash_x(a,b,c,d,e,f,g)	S_grok_bslash_x(aTHX_ a,b,c,d,e,f,g)
+#define grok_bslash_xp(a,b,c,d,e,f)	S_grok_bslash_xp(aTHX_ a,b,c,d,e,f)
 #define regcurly		S_regcurly
 #  endif
 #  if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_UTF8_C)
diff --git a/perl.h b/perl.h
index 046bbdb..3b1437b 100644
--- a/perl.h
+++ b/perl.h
@@ -6294,6 +6294,10 @@ int flock(int fd, int op);
 /* Output flags: */
 #define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 /* should this merge with above? */
 
+#define grok_bslash_x(s, uv, error_msg, output_warning, strict, silence_non_portable, UTF) \
+    S_grok_bslash_xp(aTHX_ s, uv, error_msg, strict, silence_non_portable, UTF)
+
+
 /* to let user control profiling */
 #ifdef PERL_GPROF_CONTROL
 extern void moncontrol(int);
diff --git a/proto.h b/proto.h
index e09c4d3..0f75eda 100644
--- a/proto.h
+++ b/proto.h
@@ -7354,12 +7354,12 @@ STATIC bool	S_grok_bslash_o(pTHX_ char** s, UV* uv, const char** error_msg, cons
 #define PERL_ARGS_ASSERT_GROK_BSLASH_O	\
 	assert(s); assert(uv); assert(error_msg)
 
-PERL_STATIC_INLINE bool	S_grok_bslash_x(pTHX_ char** s, UV* uv, const char** error_msg, const bool output_warning, const bool strict, const bool silence_non_portable, const bool utf8)
+PERL_STATIC_INLINE bool	S_grok_bslash_xp(pTHX_ char** s, UV* uv, const char** error_msg, const bool strict, const bool silence_non_portable, const bool utf8)
 			__attribute__warn_unused_result__
 			__attribute__nonnull__(pTHX_1)
 			__attribute__nonnull__(pTHX_2)
 			__attribute__nonnull__(pTHX_3);
-#define PERL_ARGS_ASSERT_GROK_BSLASH_X	\
+#define PERL_ARGS_ASSERT_GROK_BSLASH_XP	\
 	assert(s); assert(uv); assert(error_msg)
 
 PERL_STATIC_INLINE I32	S_regcurly(const char *s)
-- 
1.7.9.msysgit.0

@p5pRT
Copy link
Author

p5pRT commented Jan 18, 2015

From @hvds

"bulk88 via RT" <perlbug-followup@​perl.org> wrote​:
:Reading about dquote_static.c and grok_bslash_x brings up a couple questions how its implementation.
[...]

I suggest making a separate ticket for that, I don't think it relates to
the removal of unnecessary/wrong PERL_UNUSED_ARG declarations.

Hugo

@p5pRT
Copy link
Author

p5pRT commented Jan 18, 2015

From @hvds

"bulk88 via RT" <perlbug-followup@​perl.org> wrote​:
:Im inclined to say https://rt-archive.perl.org/perl5/Ticket/Attachment/1326848/707965/0001-Removed-PERL_UNUSED_ARG-in-S_grok_bslash_x.patch is wrong. output_warning is unused in non-DEBUGGING and DEBUGGING. I removed it as an experiment and both build types compiled, see attached patch.

How is that managing to compile line 226, just after the context lines
in the patch​:
  if (strict || ! output_warning) {
?

Hugo

@p5pRT
Copy link
Author

p5pRT commented Jan 18, 2015

From @bulk88

hv@​crypt.org wrote​:

"bulk88 via RT" <perlbug-followup@​perl.org> wrote​:
:Im inclined to say https://rt-archive.perl.org/perl5/Ticket/Attachment/1326848/707965/0001-Removed-PERL_UNUSED_ARG-in-S_grok_bslash_x.patch is wrong. output_warning is unused in non-DEBUGGING and DEBUGGING. I removed it as an experiment and both build types compiled, see attached patch.

How is that managing to compile line 226, just after the context lines
in the patch​:
if (strict || ! output_warning) {
?

Hugo

My patch worked on blead from Jan 6 2015/
735ecbe :(

var output_warning really was unused on that day

PERL_STATIC_INLINE bool
S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
  const bool output_warning, const bool strict,
  const bool silence_non_portable,
  const bool UTF)
{

/* Documentation to be supplied when interface nailed down finally
  * This returns FALSE if there is an error which the caller need not
recover
  * from; , otherwise TRUE. In either case the caller should look at *len
  * On input​:
  * s is the address of a pointer to a NULL terminated string that begins
  * with 'x', and the previous character was a backslash. At exit, *s
  * will be advanced to the byte just after those absorbed by this
  * function. Hence the caller can continue parsing from there. In
  * the case of an error, this routine has generally positioned *s to
  * point just to the right of the first bad spot, so that a message
  * that has a "<--" to mark the spot will be correctly positioned.
  * uv points to a UV that will hold the output value, valid only if the
  * return from the function is TRUE
  * error_msg is a pointer that will be set to an internal buffer
giving an
  * error message upon failure (the return is FALSE). Untouched if
  * function succeeds
  * output_warning says whether to output any warning messages, or suppress
  * them
  * strict is true if anything out of the ordinary should cause this to
  * fail instead of warn or be silent. For example, it requires
  * exactly 2 digits following the \x (when there are no braces).
  * 3 digits could be a mistake, so is forbidden in this mode.
  * silence_non_portable is true if to suppress warnings about the code
  * point returned being too large to fit on all platforms.
  * UTF is true iff the string *s is encoded in UTF-8.
  */
  char* e;
  STRLEN numbers_len;
  I32 flags = PERL_SCAN_DISALLOW_PREFIX;

  PERL_ARGS_ASSERT_GROK_BSLASH_X;

  PERL_UNUSED_ARG(output_warning);

  assert(**s == 'x');
  (*s)++;

  if (strict) {
  flags |= PERL_SCAN_SILENT_ILLDIGIT;
  }

  if (**s != '{') {
  STRLEN len = (strict) ? 3 : 2;

  *uv = grok_hex(*s, &len, &flags, NULL);
  *s += len;
  if (strict && len != 2) {
  if (len < 2) {
  *s += (UTF) ? UTF8SKIP(*s) : 1;
  *error_msg = "Non-hex character";
  }
  else {
  *error_msg = "Use \\x{...} for more than two hex
characters";
  }
  return FALSE;
  }
  return TRUE;
  }

  e = strchr(*s, '}');
  if (!e) {
  (*s)++; /* Move past the '{' */
  while (isXDIGIT(**s)) { /* Position beyond the legal digits */
  (*s)++;
  }
  /* XXX The corresponding message above for \o is just '\\o{'; other
  * messages for other constructs include the '}', so are
inconsistent.
  */
  *error_msg = "Missing right brace on \\x{}";
  return FALSE;
  }

  (*s)++; /* Point to expected first digit (could be first byte of
utf8
  sequence if not a digit) */
  numbers_len = e - *s;
  if (numbers_len == 0) {
  if (strict) {
  (*s)++; /* Move past the } */
  *error_msg = "Number with no digits";
  return FALSE;
  }
  return TRUE;
  }

  flags |= PERL_SCAN_ALLOW_UNDERSCORES;
  if (silence_non_portable) {
  flags |= PERL_SCAN_SILENT_NON_PORTABLE;
  }

  *uv = grok_hex(*s, &numbers_len, &flags, NULL);
  /* Note that if has non-hex, will ignore everything starting with
that up
  * to the '}' */

  if (strict && numbers_len != (STRLEN) (e - *s)) {
  *s += numbers_len;
  *s += (UTF) ? UTF8SKIP(*s) : 1;
  *error_msg = "Non-hex character";
  return FALSE;
  }

  /* Return past the '}' */
  *s = e + 1;

  return TRUE;
}

@p5pRT
Copy link
Author

p5pRT commented Jan 18, 2015

From @hvds

bulk88 <bulk88@​hotmail.com> wrote​:
:hv@​crypt.org wrote​:
:> "bulk88 via RT" <perlbug-followup@​perl.org> wrote​:
:> :Im inclined to say https://rt-archive.perl.org/perl5/Ticket/Attachment/1326848/707965/0001-Removed-PERL_UNUSED_ARG-in-S_grok_bslash_x.patch is wrong. output_warning is unused in non-DEBUGGING and DEBUGGING. I removed it as an experiment and both build types compiled, see attached patch.
:>
:> How is that managing to compile line 226, just after the context lines
:> in the patch​:
:> if (strict || ! output_warning) {
:> ?
:>
:> Hugo
:
:
:My patch worked on blead from Jan 6 2015/
:735ecbe919d740c2d0068de6daf6f2359bbcd3eb :(
:
:var output_warning really was unused on that day

Ah, the reference was newly added by khw in 879eb60 a week ago​:
  Output warning in qr// only once

Hugo

@p5pRT
Copy link
Author

p5pRT commented Feb 24, 2015

From @iabyn

On Sat, Jan 17, 2015 at 09​:00​:57AM -0800, Jasmine Ngan wrote​:

# New Ticket Created by Jasmine Ngan
# Please include the string​: [perl #123616]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=123616 >

Hi there,

This is my first time contributing a patch so I'm looking for a little
guidance. As suggested by the subject and with assistance from Hugo at
the London Perl Hackday, I've weeded out some obvious PERL_UNUSED_ARG
statements inside static functions as requested in the Perl 5 todo.pod
file.

Thanks, all applied as commit d3db151. Sorry for the delay, your ticket
got bogged down with other stuff and got forgotten :-(.

The remaining PERL_UNUSED_ARG statements appear to be for variables that
are (1) contained in non-static functions, (2) conditionally used
depending on pre-processor macros or (3) placeholders so that the
static function prototypes match particular function pointers.

That's probably as much as can be done for now.

I'm not sure if this task is completed yet so I haven't removed the item
from todo.pm yet. Let me know what you think. Thanks!

I think this is more of a continuous task. Perhaps we should just note in
todo.pod the last time it was done and suggest that it gets revisited
every year or so?

--
"Foul and greedy Dwarf - you have eaten the last candle."
  -- "Hordes of the Things", BBC Radio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants