Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improvements around collections and the use of them #314

Merged
merged 7 commits into from
Aug 15, 2023

Conversation

danakj
Copy link
Collaborator

@danakj danakj commented Aug 13, 2023

Implicit conversions back to primitive integers

A big pain when using std containers with subspace is converting explicitly back to primitive types.

But we really don't want subspace types to convert back to primitive types and fall out of subspace land, like adding a primitive to a subspace numeric should always result in a subspace numeric or a compile error (if the primitive is too big).

Getting this right required some serious heroics though where for every builtin binary operator that takes primitive types, we need to replace that with a function of our own if one of the two parameters is a subspace numeric. Then, either perform the action if it's valid, or delete the function if it's not, to avoid falling back to a conversion into a primitive type.

Slice invalidations

While writing docs we uncovered a bug which was caused by Vec returning a reference to itself for a Slice, but then the Slice shared the Vec's length field, so mutating the Vec also mutated the Slice. So Vec now converts to a Slice by constructing a Slice not just a reference.

Largely this was copied from https://doc.rust-lang.org/stable/std/collections/index.html
but with additional information for Subspace and/or C++ specific things
or adjustments as needed.
@danakj danakj force-pushed the collections branch 2 times, most recently from cf71830 to 909e541 Compare August 13, 2023 22:20
@danakj danakj changed the title Move containers to collections and document it. Improvements around collections and the use of them Aug 14, 2023
@danakj danakj force-pushed the collections branch 6 times, most recently from 2b9b786 to 6517131 Compare August 14, 2023 06:35
To do this, we just need an overload on operator== and operator<=>
that compares between the numeric type and its primitive type, and
whichi is not templated. Then we avoid ambiguous overload errors
due to the compiler being able to convert in both directions.
And more docs for the collections namespace about it all.
This would introduce Slice invalidation, as the Slice shares the same
length field as the Vec. Mutating the length of the Vec then changes the
Slice too. This is only possible when you have a borrow checker to
prevent the mutation.
@danakj
Copy link
Collaborator Author

danakj commented Aug 14, 2023

Beginning docs for #277 in the collections namespace here as well.

@danakj danakj merged commit 7420c22 into chromium:main Aug 15, 2023
7 checks passed
@danakj danakj deleted the collections branch August 15, 2023 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant