Closed Bug 1510682 Opened 6 years ago Closed 4 years ago

clang-format does not keep newlines on ClassOps / ::class_ definitions.

Categories

(Core :: JavaScript Engine, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla73
Tracking Status
firefox73 --- fixed

People

(Reporter: nbp, Assigned: tcampbell)

References

Details

Attachments

(4 files)

clang-format, when seeing structure initialization will attempt to pack all the fields as much as possible whereas we splat them for better readability.

ClassOps, ClassSpec and ::class_ definitions are subject to these modification and make things either be strangely organized, and harder to read.

Here are examples taken from builtin/Array.cpp:

before:
> static const ClassOps ArrayObjectClassOps = {
>     array_addProperty,
>     nullptr, /* delProperty */
>     nullptr, /* enumerate */
>     nullptr, /* resolve */
>     nullptr, /* mayResolve */
>     nullptr, /* finalize */
>     nullptr, /* call */
>     nullptr, /* hasInstance */
>     nullptr, /* construct */
>     nullptr, /* trace */
> };

after:
> static const ClassOps ArrayObjectClassOps = {
>     array_addProperty, nullptr, /* delProperty */
>     nullptr,                    /* enumerate */
>     nullptr,                    /* resolve */
>     nullptr,                    /* mayResolve */
>     nullptr,                    /* finalize */
>     nullptr,                    /* call */
>     nullptr,                    /* hasInstance */
>     nullptr,                    /* construct */
>     nullptr,                    /* trace */
> };

We notice that the lack of comments after array_addProperty make clang-format wrap the next field initialization to the previous line. This might be worked around by adding extra /* addProperty */.

It might also be interesting to test adding these comments as prefix.


before:
> const Class ArrayObject::class_ = {
>     "Array",
>     JSCLASS_HAS_CACHED_PROTO(JSProto_Array) | JSCLASS_DELAY_METADATA_BUILDER,
>     &ArrayObjectClassOps,
>     &ArrayObjectClassSpec
> };

after:
> const Class ArrayObject::class_ = {
>     "Array",
>     JSCLASS_HAS_CACHED_PROTO(JSProto_Array) | JSCLASS_DELAY_METADATA_BUILDER,
>     &ArrayObjectClassOps, &ArrayObjectClassSpec};

In this case, the last 2 fields are folded and the closing brace is put on the same line as the last field.  I do not know what might be a good work-around but it really feels more obscure to read.

Maybe we should just take the habit of adding a comment to each field of a structure initialization.
I'd support adding the /* addProperty */ comment even for non-nullptr entries. For the second issue I don't have any good ideas, but am also not too bothered by the default.
Priority: -- → P3
Assignee: nobody → tcampbell
Status: NEW → ASSIGNED
Pushed by tcampbell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/ef29fb21bdd7
Clang format js/src/builtin/streams. r=jandem
https://hg.mozilla.org/integration/autoland/rev/72f4ca2286aa
Add field comments for uses of JSClassOps. r=jandem
https://hg.mozilla.org/integration/autoland/rev/9a1bd82aed93
Add field comments for uses of js::ClassExtension. r=jandem
https://hg.mozilla.org/integration/autoland/rev/8b5ffa9c5266
Add field comments for uses of js::ObjectOps. r=jandem
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: