Skip to content

Attribute based ABI opt-in #39

Description

@SidneyCogdill

P2785R4 adds new rules when reloc should not call relocate ctor to solve the ABI issue. However, this significantly complicates the design and hurts teachability, causing it to suffer from the same "std::move doesn't move" issue. Furthermore, the early destruction use-case is no longer reliably usable:

auto read_and_update() {
    std::lock_guard l{m_mtx};
    auto num = m_res.load();
    reloc l; // Early dropping the lock guard without requiring std::unique_lock.
    very_slow_update(num); // Assuming this a blocking call that takes a long time...
}

In the above case, if it's decided that reloc can be silently deferred to later stage, it can introduce a silent performance regression without the users knowing, which in turn causes the ecosystem to simply not trust the effectiveness of discard semantic, resulting in a mechanism that looks good on paper but gains none of real adoption.

I suggest that reloc mandates the operand to be an owned parameter, or is ill-formed (emits a compile time error). And use a new attribute to explicitly opt into the new ABI behavior:

void f2(std::unique_ptr<int> p);

auto f1(std::unique_ptr<int> [[owned]] p) {
    f2(reloc p);
}

Which forces p to be an owned parameter and callee-destroyed. This makes the ABI breakage strictly opt-in without hurting the explicitness of reloc operator.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions