Closed Bug 1365928 Opened 7 years ago Closed 7 years ago

Annotate style struct getters as always returning a non-null pointer

Categories

(Core :: CSS Parsing and Computation, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: jfkthame, Assigned: jfkthame)

Details

Attachments

(2 files)

The nsStyleXXX* getters in nsStyleContext and nsIFrame will never return a null pointer (see comment at the declaration of StyleData() in nsStyleContext.h). If we annotate these methods with the returns_nonnull attribute (supported by gcc/clang), this may enable the compiler to optimize better around call sites.
Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
This appears to affect code-gen in a few places in my build; I haven't analyzed them individually but presumably the optimizer knows what it's doing....
Attachment #8869015 - Flags: review?(mats)
Comment on attachment 8869013 [details] [diff] [review]
patch 1 - Add a MOZ_NONNULL_RETURN annotation to mfbt/Attributes.h

Review of attachment 8869013 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!  What does this enable for your particular use case?  Better codegen for placement new?
Attachment #8869013 - Flags: review?(nfroyd) → review+
Attachment #8869015 - Flags: review?(mats) → review+
(In reply to David Baron :dbaron: ⌚️UTC-7 from comment #4)
> I think this came from bug 1365356 comment 7 and bug 1365356 comment 8.

Indeed. It looks like in some cases, it's enabling the compiler to optimize away calls to StyleDisplayWithOptionalParam(), by recognizing that the pointer being passed must be non-null and therefore the method collapses to simply returning its parameter.
https://hg.mozilla.org/integration/mozilla-inbound/rev/3d3190803408c7605fbb52f8215a757fffedcad5
Bug 1365928 - patch 1 - Add a MOZ_NONNULL_RETURN annotation to mfbt/Attributes.h. r=froydnj

https://hg.mozilla.org/integration/mozilla-inbound/rev/75cd3397298ad5c0f02129a87f465059018a9f63
Bug 1365928 - patch 2 - Annotate style-struct getters with MOZ_NONNULL_RETURN for better optimization. r=mats
https://hg.mozilla.org/mozilla-central/rev/3d3190803408
https://hg.mozilla.org/mozilla-central/rev/75cd3397298a
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: