microsoft / microsoft/STL

<exception>: Consider changing exception_ptr to have the size of a single pointer

Open
#751 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance vNext
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Hi!

I'm wondering if it's not too late to request an ABI breaking change to shrink the size of the STL's std::exception_ptr class type down to match that of a single pointer. Currently, it uses a std::shared_ptr to manage the lifetime of the stored exception object, and this naturally requires two pointer-sized variables for the std::shared_ptr's state. By changing the internal representation of std::exception_ptr over to an intrusive reference-counted pointer implementation, it would be possible to make sizeof(std::exception_ptr) == sizeof(void*).

The reason this would be valuable is it makes implementing both P1028 and P0709 much easier, in particular type-erasing a std::exception_ptr object and storing it in a std::system_code, which uses a single std::intptr_t for state. Both of these proposals, while well received, are still a long way off and may never land in their present form. However, there is an open source implementation and other libraries using the same technique (the company I work has its own implementation of P1028 used for exceptionless futures/promises and senders/receivers). With std::exception_ptr being larger than std::uintptr_t as it currently is in the Microsoft STL, the only way to do this type-erasure is to allocate additional memory, which would be nice to avoid inside of error handling code paths.

Both libc++ and libstdc++ appear to use the intrusive-reference counting approach for std::exception_ptr and have sizeof(std::exception_ptr) == sizeof(void*), so you would also be hitting parity with these libraries if the change were to be done.

vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the vNext note and issue #169, then compare the exception_ptr representation described here with the approaches used by libc++ and libstdc++. Done means evaluating the ABI-breaking size change for vNext; the issue states that pull requests cannot be accepted until that branch is available.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.