Skip to content

Add ability to specify assert() calls in embed.fnc #23529

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

Open
wants to merge 12 commits into
base: blead
Choose a base branch
from

Conversation

khwilliamson
Copy link
Contributor

@khwilliamson khwilliamson commented Aug 2, 2025

This allows the removal of the G flag, and the removal of three customized PERL_ARGS_ASSERT macros. One of these showed the brittleness of the old scheme, as after it was written, code was added to improve the generic versions of these macros, but no one realized to update the custom one. This can no longer happen with this pull request

This commit also improves the error checking of embed.fnc entries; adds comments and white space

  • This set of changes includes a perldelta entry

@khwilliamson
Copy link
Contributor Author

In addition to the requested changes, I added a \b to the matching of assert( in HeaderParser, so that it won't match something just ending in assert

And I added, moved some comments in embed.fnc about this new feature

@leonerd leonerd added the squash-before-merge Author must squash the commits down before merging to blead label Aug 7, 2025
Copy link
Contributor

@leonerd leonerd left a comment

Choose a reason for hiding this comment

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

These changes look good, but it'd be useful to squash the commits down a bit. We don't need all 11 distinct ones.

Maybe one commit to add the new assert ability, one to swap the existing uses of the G flag and custom macros, and one final one to remove support for that G flag.

@bram-perl
Copy link

These changes look good, but it'd be useful to squash the commits down a bit. We don't need all 11 distinct ones.

What I would personally do is merge it with a merge-commit so that it's clear it's one block of related changes.
But that does not appear to be something that is typically done in blead. (But it does happen. Also not sure if the GitHub UI allows it and/or makes it easy or hard.)

@jkeenan
Copy link
Contributor

jkeenan commented Aug 7, 2025

These changes look good, but it'd be useful to squash the commits down a bit. We don't need all 11 distinct ones.

I would appreciate some squashing along the lines suggested by @leonerd because it would reduce slightly the number of commits that need to be traversed in a bisection used to diagnose bugs in the future.

What I would personally do is merge it with a merge-commit so that it's clear it's one block of related changes. But that does not appear to be something that is typically done in blead.

$ git log --format=fuller --date=short --since 2024-08-07 --reverse | grep -c '^commit '
2048
$ git log --format=fuller --date=short --since 2024-08-07 --reverse | grep -c '^Merge: '
14

Fewer than 1% of all commits in the last 365 days -- but almost all of them were the culmination of projects long in development and were performed by major contributors. Even within such merges, however, some squashing can be beneficial.

@bram-perl
Copy link

These changes look good, but it'd be useful to squash the commits down a bit. We don't need all 11 distinct ones.

I would appreciate some squashing along the lines suggested by @leonerd because it would reduce slightly the number of commits that need to be traversed in a bisection used to diagnose bugs in the future.

It would not make any significant different on the number of bisect runs. (It's a binary search: it reduces the search space by half each time. So bisecting 900 commits should take 10 builds. Bisecting 1000 commits should also take 10 builds. (2 ** 10 =1024)).

Having clear, small and obvious commits with clear explanation will make viewing history a whole lot easier. (And it will help when you do end up with the bisect on a small commit rather the one large commit.)

I went through the commits and personally I wouldn't squash any of them. I find all of them split reasonably well.

What I would personally do is merge it with a merge-commit so that it's clear it's one block of related changes. But that does not appear to be something that is typically done in blead.

$ git log --format=fuller --date=short --since 2024-08-07 --reverse | grep -c '^commit '
2048
$ git log --format=fuller --date=short --since 2024-08-07 --reverse | grep -c '^Merge: '
14

Fewer than 1% of all commits in the last 365 days

Because the option is disabled in the GitHub UI. Not because it wouldn't be handy - at least in my opinion.
Just look at the recent history: a lot of commits that start with the exact same prefix. To me that is a sign that a merge-commit would be of use because all these changes are very likely related.

@khwilliamson
Copy link
Contributor Author

I've done a few bisections recently. We're at 40K commits when the bisect kicks in. We don't need an extra step until we reach 65536 commits. That's more than half again as many as we've ever done. That means that trying to conserve commits won't help bisecting.

Anything we can do to save human time helps us. Bite-sized commits are helpful in this regard.

Comment on lines +289 to +283
warn "$func: $arg needs NN or NULLOK\n";
++$unflagged_pointers;

Choose a reason for hiding this comment

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

Commit regen/embed.pl: Improve error checking

This commit needs rechecking;.

Same commit in the previous push: a281942
--> it removed the block on line 259-265:

-                  if (   $args_assert_line
-                        && $arg =~ /\*/
-                        && $arg !~ /\b(NN|NULLOK)\b/ )
-                    {
-                        warn "$func: $arg needs NN or NULLOK\n";
-                        ++$unflagged_pointers;
-                    }
-

In this commit it's kept..

I believe the block on lines 259-265 should be removed because the same check is now done here.

Copy link
Contributor Author

@khwilliamson khwilliamson Aug 8, 2025

Choose a reason for hiding this comment

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

This was a rebase -i error. I'm not sure if it was me or rere. Both possibilities are scary (that I missed it)

Comment on lines +124 to +125
my ($flags, $retval, $plain_func, $args, $assertions ) =
@{$embed}{qw(flags return_type name args assertions)};
Copy link

@bram-perl bram-perl Aug 8, 2025

Choose a reason for hiding this comment

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

Commit embed.fnc: Add ability to customize ARGS_ASSERT macros

Just a side note: this is a value slice of a hash ref, it can also be written using postderef as:

my ($flags, $retval, $plain_func, $args, $assertions ) = $embed->@{qw(flags return_type name args assertions)};

(Not asking for a change; just offering it as hint, feel free to ignore it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These lines at the beginning explain why not:

require 5.004;  # keep this compatible, an old perl is all we may have before
                # we build the new one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(That's not to say that that dictum has been obeyed in all commits; and maybe the number should be changed to more recent.)

Choose a reason for hiding this comment

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

In that case you should update the line:

        push @asserts, $assertions->@* if $assertions;

which you added since that too is using post-deref.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah; I imagine there are others that have crept in.

@khwilliamson
Copy link
Contributor Author

I have now added a perldelta entry

@khwilliamson
Copy link
Contributor Author

@leonerd , Both @bram-perl and I think these commits are a reasonable minimal set. But the series should be added as a merge commit so that they can be considered as a whole, as is our policy in perlgit. I have filed #23547 to either make that easier or to make it harder to do a "Rebase and merge" from GH for series of commits.

@khwilliamson
Copy link
Contributor Author

My rules for what needs to be separate commits, is "Would it ever be better to keep this change if we needed to revert the rest?" And sometimes for indentation changes, "Does this change make another change's difference listing easier enough to grok to be worth it?"

If an argument is a literal string, it's not going to be anything else,
so convert an elsif to an else.
Indent newly formed block from the previous commit
@bram-perl found this example of how it could be broken before this
commit:

    initial  : $arg is "NULLOK NN SV *msg_sv
    after s//: $arg is "NULLOKSV *msg_sv
This commit verifies that only one of the mutually exclusive argument
modifiers, like NN, is present, and that NZ isn't used for a pointer
argument.
This generalizes the previous code to make sure all non-word flags are
sorted after the word ones.  Previously it checked for just '#'

All but '#' not being in column 1 is just for aesthetics.  If '#' were
in column 1 it would be a preprocessor directive that likely would fail
to compile.
This enhances embed.fnc entries to contain arbitrary assert() calls,
which will be added to the corresponding generated ARGS_ASSERT macros.

The next commit will use it.
These existed because they exceeded the rudimentary capabilities of the
generated ARGS_ASSERT macros.  But the previous commit generalized that
capability, so they can change to use that.

This moves the three extant customized macros to use the new facility,
removing the need for overriding things

The customized PERL_ARGS_ASSERT_ISA_LOOKUP was out-of-date, missing an
assertion that got added, without the macro getting updated.  This new
scheme will prevent that from happening in the future.
This prevented an empty PERL_ARGS_ASSERT macro from being generated
here, but those are optional to use, so there is no advantage to
suppressing it.
The purpose of this flag has been removed in the past few commits
You can't allocate a zero length array using this function; this uses
the new assert() functionality in embed.fnc introduced in the previous
few commits to cause the assertion to be placed in
PERL_ARGS_ASSERT_AV_NEW_ALLOC rather than be in the function.

There is no particular need to do this; this is mostly a demonstration
of how it can be done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squash-before-merge Author must squash the commits down before merging to blead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants