Open Bug 1672378 Opened 4 years ago Updated 5 months ago

Lift extensions to MOZ_TRY and related macros from dom/quota/QuotaCommon.h (QM_TRY_*)

Categories

(Core :: MFBT, task, P3)

task

Tracking

()

People

(Reporter: sg, Assigned: janv)

References

(Depends on 1 open bug, Blocks 2 open bugs)

Details

Attachments

(1 file)

For the quota manager and its clients, several extensions to the mechanism provided by MOZ_TRY and MOZ_TRY_VAR are introduced, including:

  • Split MOZ_TRY_VAR into MOZ_TRY_INSPECT and MOZ_TRY_UNWRAP, so that unwrapping can be avoided where not necessary.
  • Allow variables to be declared by MOZ_TRY_INSPECT and MOZ_TRY_UNWRAP (which allows declaring const references/variables!)
  • Report failures in a customizable way, e.g. via NS_DebugBreak/NS_WARNING.
  • Allow the use in functions not returning an error, but having void return type or, e.g., where a nullptr should be returned to indicate an error.
  • Allow customization of cleanup in case of a failure before returning.
  • Allow asserting on failure.
  • Add MOZ_TRY_RETURN to propagate both the result and a failure (including the customization options and reporting mentioned above).

These extensions could benefit the whole codebase by lifting them to mfbt/Result.h.

The original motivation for providing custom macros was the need to include extended error reporting. There is some challenge to make this general and customizable for the whole codebase, the default might be using NS_DebugBreak/NS_WARNING as mentioned above.

Parts of the macros in dom/quota/QuotaCommon.h might currently be specific to Result<T, nsresult>, but this limitation should be liftable.

I was opposed to using "control-flow-hiding" macros for long time, but after introduction of mozilla::Result and MOZ_TRY I changed my mind.
There's a documentation for QM_TRY* macros, including a comparison of typical usage:
https://searchfox.org/mozilla-central/rev/e1d1f043957191616721b9e8bf811c0aab8a203a/dom/quota/QuotaCommon.h#96

(In reply to Jan Varga [:janv] from comment #2)

I was opposed to using "control-flow-hiding" macros for long time, but after introduction of mozilla::Result and MOZ_TRY I changed my mind.
There's a documentation for QM_TRY* macros, including a comparison of typical usage:
https://searchfox.org/mozilla-central/rev/e1d1f043957191616721b9e8bf811c0aab8a203a/dom/quota/QuotaCommon.h#96

If there's consensus about this among the ones owning the style guide (are there actually owners?), the recommendation to use MOZ_TRY etc. should presumably be added to https://searchfox.org/mozilla-central/rev/e1d1f043957191616721b9e8bf811c0aab8a203a/xpcom/base/nsDebug.h#34-35.

It's worth to note that currently MOZ_TRY_VAR cannot be used at all with a non-default-constructible success type, but QM_TRY_UNWRAP/QM_TRY_INSPECT can. I came across this limitation when trying to use it with Result<std::reference_wrapper<T>, nsresult>.

Summary: Lift extensions to MOZ_TRY and related macros from dom/quota/QuotaCommon.h → Lift extensions to MOZ_TRY and related macros from dom/quota/QuotaCommon.h (QM_TRY_*)
Assignee: simon.giesecke → nobody
Depends on: 1855134
Assignee: nobody → jvarga
Depends on: 1862947
Severity: -- → S3
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: