Skip to content

[Pitch] OutputSpan #2803

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

[Pitch] OutputSpan #2803

wants to merge 12 commits into from

Conversation

glessard
Copy link
Contributor

@glessard glessard commented Apr 23, 2025

A proposal for a new type to manage and delegate the initialization of memory, along with some new initializers that use it for Array, String and InlineArray.

@glessard glessard changed the title [Pitch] Outputspan [Pitch] OutputSpan Apr 23, 2025
@rjmccall rjmccall added the LSG Contains topics under the domain of the Language Steering Group label Apr 28, 2025

An `OutputSpan` provided by a container represents a mutation of that container, and is therefore an exclusive access.
Like `MutableSpan`, `OutputSpan` relies on two guarantees: (a) that it has exclusive access to the range of memory it represents, and (b) that the memory locations it represents will remain valid for the duration of the access. These guarantee data race safety and temporal safety. `OutputSpan` performs bounds-checking on every access to preserve spatial safety. `OutputSpan` manages the initialization state of the memory in represents on behalf of the memory's owner.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to encourage you to use "lifetime safety" instead of "temporal safety" and "bounds safety" instead of "spatial safety", which are more accessible.


#### <a name="contentsOf"></a>Alternative names for `append()` methods

`OutputSpan` lays the groundwork for new, generalized `Container` protocols that will expand upon and succeed the `Collection` hierarchy while allowing non-copyability and non-escapability to be applied to both containers and elements. We hope to find method and property names that will be applicable types The origin of the `append(contentsOf:)` method we are expanding upon is the `RangeReplaceableCollection` protocol, which always represents copyable and escapable collections and copyable and escapable elements. The definition is as follows: `mutating func append<S: Sequence>(contentsOf newElements: __owned S)`. This support copying elements from the source, while also destroying the source if we happen to own its only copy. This is obviously not sufficient if the elements are non-copyable, or if we only have access to a borrow of the source.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo:

will be applicable  types The origin of the `append(contentsOf:)`


`OutputSpan` lays the groundwork for new, generalized `Container` protocols that will expand upon and succeed the `Collection` hierarchy while allowing non-copyability and non-escapability to be applied to both containers and elements. We hope to find method and property names that will be applicable types The origin of the `append(contentsOf:)` method we are expanding upon is the `RangeReplaceableCollection` protocol, which always represents copyable and escapable collections and copyable and escapable elements. The definition is as follows: `mutating func append<S: Sequence>(contentsOf newElements: __owned S)`. This support copying elements from the source, while also destroying the source if we happen to own its only copy. This is obviously not sufficient if the elements are non-copyable, or if we only have access to a borrow of the source.

When the elements are non-copyable, we must append elements that are removed from the source. Afterwards, there are two possible dispositions of the source: destruction (`consuming`,) where the source can no longer be used, or mutation (`inout`,) where the source has been emptied but is still usable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comma on wrong side of closing parenthesis?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
LSG Contains topics under the domain of the Language Steering Group
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants