Skip to content

[NFC] Make SortedVector inherit privately from std::vector - #9171

Merged
kripken merged 5 commits into
WebAssembly:mainfrom
kripken:privvec
Sep 29, 2026
Merged

kripken merged 5 commits into
WebAssembly:mainfrom
kripken:privvec

Conversation

@kripken

@kripken kripken commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

This prohibits referring to a SortedVector using an upcast, as the
upcast might manipulate the contents in a non-sorted way.

@kripken
kripken requested a review from a team as a code owner September 29, 2026 19:57
Comment thread src/support/sorted_vector.h
Comment thread src/support/sorted_vector.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like push_back and resize should not be exposed publicly since they will also break invariants. Maybe make this into a class and have a public block?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed the handling of those two cases, good catch.

I don't feel a class/public block would be clearer, but let me know what you think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In general I'd prefer class for something like this, since it's not a POD type and it does have behavior that we want to hide. I think 'private by default' is the safer option especially since we were already exposing methods that we shouldn't have. But not a big deal to me since this is a small codebase and there's not much chance of misuse.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I see what you're saying. Our convention has been otherwise, so I'd rather not go against it, but I'm open to us deciding some day to change the convention here to the safer approach.

Comment thread src/support/sorted_vector.h Outdated
Comment thread src/support/sorted_vector.h
Comment thread src/support/sorted_vector.h
Comment thread src/support/sorted_vector.h Outdated
@kripken
kripken merged commit 6f8d66d into WebAssembly:main Sep 29, 2026
16 checks passed
@kripken
kripken deleted the privvec branch September 29, 2026 22:17
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.

2 participants