Skip to content

Conversation

@demerphq
Copy link
Collaborator

@demerphq demerphq commented Sep 1, 2022

This patch sequences cleans up various minor nits in our manually managed header files (eg, *.h in the root of the repo) , and then introduces a whitespace fixup patch to put all our header files into a standardized format, with defines using as consistent formatting as possible, multiline macros definitions having consistently formatted line continuation markers and other things like that. Similarly structs and unions are consistently formatted with the * character from pointer declarations being associated with the name not the type like we would normally for variables, and with the member declarations lined up properly and with comments at consistent positions in the definition. In other words the last patch in this sequence should ONLY make whitespace changes.

I wanted to have this patch so we could start a conversation about whether we should use some kind of tool to enforce a consistent format. (I think we should.) I find the inconsistencies in the formatting makes the header files harder to read, and i think programs are better at it than we are, so at least for header files I thought i would see what people think.

@demerphq demerphq force-pushed the yves/ws_cleanup_headers branch from 5757f66 to 20a53e4 Compare September 1, 2022 12:07
@demerphq demerphq marked this pull request as draft September 1, 2022 12:08
@bram-perl
Copy link

bram-perl commented Sep 1, 2022

I think the first commits can be merged as-is,

For the whitespace cleanup commit, skimming the files:

  • op.h doesn't look good:
    • lines 11-40 are misaligned
    • lines 111-167: comments that continue on the next line are no longer aligned
  • perl.h:
    • lines 5223-5555 5523-5555
    • 5556-5599
    • 5605-5636
    • 5642-5681
    • 5842-5849
  • utfebcdic.h:
    • lines 30-32

Other things I am not fond of:

(Taking a random example)
regexp.h

        struct {
            /* this first element must match u.yes */
            struct regmatch_state   *prev_yes_state;
            U32                     lastparen;
            U32                     lastcloseparen;
            CHECKPOINT              cp;

        }                            branchlike;

The name of the struct is too far to the right (again IMO)

(Update: fix typo in line numbers of perl.h)

@khwilliamson
Copy link
Contributor

khwilliamson commented Sep 1, 2022 via email

@demerphq
Copy link
Collaborator Author

demerphq commented Sep 2, 2022 via email

@demerphq
Copy link
Collaborator Author

demerphq commented Sep 6, 2022

I have pushed a significant revamp of the white space cleanups. This also includes sundry changes to infra that is whitespace sensitive or sensitive to line continuation markers in our header files.

I dont think this is "good enough" to merge yet, but i do think its "good enough" to hear folks comments. One issue for me is lining up things can lead to comments straying past the 80 column boundary. I havent decided the right thing to do there, and some of the choices the code makes may not be ideal.

@demerphq demerphq force-pushed the yves/ws_cleanup_headers branch from e3ab7e2 to 0adc6d4 Compare September 6, 2022 16:41
Copy link

@bram-perl bram-perl left a comment

Choose a reason for hiding this comment

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

Preamble:

  • I reviewed commit-per-commit;
  • Some commits I merely skimmed and didn't fully read
  • I know some of the changes that I left comments on was changed again in a later commit (basically resolving the comment); I still left them in place tho just in case they might be useful for other cases.

next unless / - \d+ $ /x;
s/ ^ \# \s* define \s*//x;
m/ (.*) \ (.*) /x;
m/ (\S+) \s+ (.*) /x;

Choose a reason for hiding this comment

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

commit XS-APItest/t/locale.t - deal with indented values properly

It would be nice to amend the commit message with an example of what failed to parse
and/or what parsed incorrectly..

Also: I think it fixes more then just indented values?
I'm assuming (not verified) that before this commit something like: #define FOO "A B C" would get parsed incorrectly

Copy link
Collaborator Author

@demerphq demerphq Sep 6, 2022

Choose a reason for hiding this comment

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

I updated the commit message. I suspect you are right, but the code in practice doesn't have such things. It was just that if you changed a define from define foo bar into define foo__ bar (assume the underbars are spaces here) the parse code would see the define name as foo__ (that is 2 spaces) and then fail. Such white-space sensitivity is unhelpful. :-) And as you said, had it had a more complex value it would have gotten things worse.

XSUB.h Outdated
Comment on lines 189 to 191

#define dXSTARG SV * const targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \
#define dXSTARG \
SV * const targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \
? PAD_SV(PL_op->op_targ) : sv_newmortal())
Copy link

@bram-perl bram-perl Sep 6, 2022

Choose a reason for hiding this comment

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

commit (3) break multiline define

Not entirely sure of these..
I might be tempted to indent the ternary in this case

i.e. something like:

#define dXSTARG                                                     \
    SV * const targ = ((PL_op->op_private & OPpENTERSUB_HASTARG)    \
        ? PAD_SV(PL_op->op_targ) : sv_newmortal())

(but I suppose it might be out of scope for this comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can try to come up with some heuristics, but there is a mixture of cases, some of which expect things to line up precisely, some which could do with an indent like you suggest. If i can figure out a more or less reliable heuristic to distinguish them I am game, but so far anything i tried like that seemed to help a small handful of cases and make the rest worse. This isn't done by hand obviously. :-)

cop.h Outdated
Comment on lines 512 to 514
? GvAV(gv_fetchfile(CopFILE(c))) : NULL)
# define CopFILEAVx(c) (assert_(CopFILE(c)) \
# define CopFILEAVx(c) \
(assert_(CopFILE(c)) \
GvAV(gv_fetchfile(CopFILE(c))))

Choose a reason for hiding this comment

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

commit (3) break multiline define

I may also have indented in this case but maybe with just one space because the first ( is not yet closed.
So something like:

#  define CopFILEAVx(c)     \
       (assert_(CopFILE(c)) \
        GvAV(gv_fetchfile(CopFILE(c))))

or

#  define CopFILEAVx(c)     \
       (assert_(CopFILE(c)) \
           GvAV(gv_fetchfile(CopFILE(c))))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same comment as to your previous feedback. If I can figure out a way to tell when it is something like this:

#define X (foo
          |bar
          |baz)

from cases where the indent would make sense then I will. In general however i found preserving the existing line up as much as possible has produced the widest range of reasonable results.

cv.h Outdated
Comment on lines 288 to 292
#define CvGvNAME_HEK(sv) \
( \
CvNAMED((CV*)sv) ? \
((XPVCV*)MUTABLE_PTR(SvANY((SV*)sv)))->xcv_gv_u.xcv_hek \
: GvNAME_HEK(CvGV( (SV*) sv)) \
)

Choose a reason for hiding this comment

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

commit (3) break multiline define

Here too I would indent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or collapse the parens entirely maybe. I can try something with this, its a special enough case it shouldnt cause much problems (compared to the previous two points).

@demerphq demerphq force-pushed the yves/ws_cleanup_headers branch 4 times, most recently from 2738c3f to 30c9073 Compare September 6, 2022 22:38
@demerphq
Copy link
Collaborator Author

demerphq commented Sep 7, 2022

I hacked late last night, and i see that the latest push has some broken artifacts. Shoulda packed it in earlier. Just a FYI I know about it and im fixing.

@demerphq demerphq force-pushed the yves/ws_cleanup_headers branch 4 times, most recently from ac3b20a to 01d7ddf Compare September 7, 2022 12:07
@demerphq demerphq force-pushed the yves/ws_cleanup_headers branch 4 times, most recently from 43bddff to bfc761d Compare September 7, 2022 23:05
@demerphq
Copy link
Collaborator Author

demerphq commented Nov 5, 2022

Oh, hrm, that chain of reflow C comments at the end means something is wrong. I will check what it is.

@demerphq demerphq force-pushed the yves/ws_cleanup_headers branch from 0cf63f4 to 25725c6 Compare November 5, 2022 12:19
@demerphq
Copy link
Collaborator Author

demerphq commented Nov 5, 2022

and fixed.

@jkeenan
Copy link
Contributor

jkeenan commented Dec 30, 2022

With the merger of #20442 into blead today, is this pull request still needed? If so, merge conflicts will need to be resolved and the p.r.'s status will have to get out of Draft.

@demerphq
Copy link
Collaborator Author

demerphq commented Dec 31, 2022 via email

@bulk88
Copy link
Contributor

bulk88 commented Jan 11, 2025

I would appreciate the tool. Less thinking/time for everyone, what the "right way" is for the p5p repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants