Skip to content

Allow declaring a parameter UNUSED - #24674

Merged
khwilliamson merged 7 commits into
Perl:bleadfrom
khwilliamson:unused_decl
Sep 7, 2026
Merged

Allow declaring a parameter UNUSED#24674
khwilliamson merged 7 commits into
Perl:bleadfrom
khwilliamson:unused_decl

Conversation

@khwilliamson

@khwilliamson khwilliamson commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

This allows removing many PERL_UNUSED_ARG statements in the code. (The ones that are conditionally compiled cannot be removed this way.)

One exemplar statement is removed.

  • I don't think this set of changest requires a perldelta entry.

Comment thread doio.c
Comment thread embed.fnc Outdated
@tonycoz

tonycoz commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Commit message:

proto.h: Use STMT_START { ... } STMT_END in ARGS_ASSERTs

This is better practice, and the next commit will add things besides
assert()s to these macros.

The ability to do this became available when we switched to requiring
C99, which allows for code before declarations in a block

I'm not sure how:

This is better practice, and the next commit will add things besides
assert()s to these macros.

and

The ability to do this became available when we switched to requiring
C99, which allows for code before declarations in a block

are connected.

asserts() are also statements in these macros (expression statements), which is why so much older code has the PERL_ASSERT_... after any declarations.

@khwilliamson

Copy link
Copy Markdown
Contributor Author

Commit message:

That was a thinko on my part. The commit message is rewritten

@khwilliamson khwilliamson changed the title Allow declaring a parameter UNUSED in embed.fnc Allow declaring a parameter UNUSED Aug 23, 2026
@khwilliamson

Copy link
Copy Markdown
Contributor Author

This new version wants you to say UNUSED in both embed.fnc and the function definition. If the system recognizes the unused attribute compiler directive, the PERL_UNUSED_ARG is dispensed with completely.

Comment thread perl.h Outdated
Comment on lines +495 to +496
/* When we have the attribute available, skip doing the runtime check
* (though likely it's optimized out */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a check, it's a suppression (by trivially using the name), and the actual suppression happens at compile-time.

It's also not an assertion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PERL_ARGS_ASSERT_UNUSED is still not an assertion even though the name suggests it is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't catch your drift, because it hadn't occurred to me that this name would imply that it was an assertion. I was trying to convey that this macro is designed for use (solely) by the PERL_ARGS_ASSERT macros (which no longer are just assertions, but I don't think we should change their names). PERL_UNUSED_ARG_FOR_ARGS_ASSERT would be a bit better. And this name should never be typed by a person, since it is generated, so a long name shouldn't be a problem except to readers. But better long than confusing. Suggestions welcome!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PERL_UNUSED_ARG_FOR_ARGS_ASSERT is as good as any I can think of right now.

Comment thread perl.h Outdated
@khwilliamson
khwilliamson force-pushed the unused_decl branch 2 times, most recently from ece385b to 1f548d4 Compare August 25, 2026 00:50
The components of this will shortly be more than asserts.  The new name
reflects this
This loop is now changed so that a new array for it to handle can
trivially be added.
This was folding, but not taking into consideration a semicolon and the
continuation character.  (Or maybe the intent was 80 columns, but
because of pagers consuming columns, 78 is a better goal anyway.)

I also find it more legible to have two blanks before the continuation
This is better practice when multiple statements are involved.

For most of its history, the expansion of PERL_ARGS_ASSERT macros was
one or more assert()s, and that worked without the STMT_START, STMT_END
wrappers.  But now more complex expansions are about to be added, so it
seems better to add the wrapping.
This allows removing many PERL_UNUSED_ARG statements in the code.
(The ones that are conditionally compiled should not be removed this way.)

And this commit does the removal of one such statement, to show how it
works.

This is enabled only for core perl and extensions.

To use this capability, the symbol UNUSED is added after the parameter
name in *both* its embed.fnc entry and its definition.

On systems that allow declaring an unused attribute for a parameter, the
code in regen.pl arranges for that to happen in the function's prototype
declaration.  On my gcc, that actually gets ignored, and hence doing it
in the function definition is also required.  It may be that other
compilers or a future change to gcc will note the attribute in the
prototype, so the second usage won't be required.

On systems without this capability, regen/embed.pl arranges for the
PERL_ARGS_ASSERT macro for the function to expand to do a
PERL_UNUSED_ARG() on the unused parameter.
@khwilliamson
khwilliamson merged commit b35a6ea into Perl:blead Sep 7, 2026
33 checks passed
@khwilliamson
khwilliamson deleted the unused_decl branch September 7, 2026 03:20
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

Successfully merging this pull request may close these issues.

2 participants