Closed Bug 1204166 Opened 9 years ago Closed 6 years ago

Consider making mozilla::Function copyable

Categories

(Core :: MFBT, defect)

defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: botond, Unassigned)

References

Details

Currently, mozilla::Function is movable but noy copyable (because it stores the wrapped callable object by UniquePtr).

We may want to consider making it copyable. If so, we need to decide what semantics we want for copying it.

  - If we store the callable via shared pointer (like nsRefPtr), then 
    multiple copies will point to the same callable. If the callable
    has state that calls to it can modify, this may not be desirable.

  - If we store the callable via an always-copying smart pointer, we
    can incur unnecessary memory allocations and copies in situations
    where, had it not been copyable, we may have been able to just
    move it. Using a copy-on-write smart pointer (do we have one in
    MFBT?) would address this.

Input is welcome.
Depends on: 1198451
This seems like a source of headaches in the future regardless of which of those two semantics are implemented.

With the first, there are the mutability issues you mentioned and that is combined with shared ownership, which sounds like bugs waiting to happen.

With the second, we need to ensure that all state that gets closed over is /also/ copyable, or else we're back to shared ownership of mutable resources. If we only allow copying if all of the closed over state is also copyable, then this is moot. I'm not sure if we can express this constraint very well, though.

Personally, I would prefer leaving mozilla::Function move-only.
mozilla::Function has been removed in bug 1320752, so this bug is moot.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.