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

Replace gsl::at with a new til::at(span) for pre-checked bounds #6925

Merged
merged 6 commits into from
Jul 15, 2020

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented Jul 14, 2020

The recent changes to use gsl::span everywhere added a few bounds checks
along codepaths where we were already checking bounds. Some of them may
be non-obvious to the optimizer, so we can now use til::at to help them
along.

To accomplish this, I've added a new overload of til::at that takes a
span and directly accesses its backing buffer.

We were using std::basic_string_view as a stand-in for std::span so that
we could change over all at once when C++20 dropped with full span
support. That day's not here yet, but as of 54a7fce we're using GSL 3,
whose span is C++20-compliant.

This commit replaces every instance of basic_string_view that was not
referring to an actual string with a span of the appropriate type.

I moved the `const` qualifier into span's `T` because while
`basic_string_view.at()` returns `const T&`, `span.at()` returns `T&`
(without the const). I wanted to maintain the invariant that members of
the span were immutable.

* Mechanical Changes
   * `sv.at(x)` -> `gsl::at(sp, x)`

I had to replace a `std::basic_string<>` with a `std::vector>` in
ConImeInfo, and I chose to replace a manual array walk in
ScreenInfoUiaProviderBase with a ranged-for. Please review those
specifically.

This will almost certainly cause a code size regression in Windows
because I'm blowing out all the PGO counts. Whoops.

Related: #3956, #975.
The recent changes to use gsl::span everywhere added a few bounds checks
along codepaths where we were already checking bounds. Some of them may
be non-obvious to the optimizer, so we can now use til::at to help them
along.

To achieve this, I've added a new overload of til::at that takes a span
and directly accesses its backing buffer.
};

template<class T>
struct is_span : public is_span_oracle<std::remove_cv_t<T>>
Copy link
Member

Choose a reason for hiding this comment

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

Alright well I'll file this PR under the list of "C++ is a made-up witchcraft language"

@zadjii-msft zadjii-msft added the Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. label Jul 15, 2020
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

Yep, thanks. It's funny how much the redundant checks add up. This is almost a perf PR too. :P

@DHowett
Copy link
Member Author

DHowett commented Jul 15, 2020

depends on #6921

@DHowett DHowett changed the base branch from dev/duhowett/spandex to master July 15, 2020 16:41
@DHowett DHowett closed this Jul 15, 2020
@DHowett DHowett reopened this Jul 15, 2020
@DHowett
Copy link
Member Author

DHowett commented Jul 15, 2020

This PR is absolutely horked thanks to its base branch being deleted. Recovering.

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jul 15, 2020
@ghost
Copy link

ghost commented Jul 15, 2020

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@DHowett DHowett closed this Jul 15, 2020
@DHowett DHowett reopened this Jul 15, 2020
@DHowett DHowett closed this Jul 15, 2020
@DHowett DHowett reopened this Jul 15, 2020
@DHowett DHowett removed the AutoMerge Marked for automatic merge by the bot when requirements are met label Jul 15, 2020
@DHowett DHowett merged commit 09471c3 into master Jul 15, 2020
@DHowett DHowett deleted the dev/duhowett/span-dex-2 branch July 15, 2020 17:29
DHowett added a commit that referenced this pull request Aug 5, 2020
- Move to GSL 3.1.0 (GH-6908)
- Replace the color table init code with two const arrays (GH-6913)
- Replace basic_string_view<T> with span<const T> (GH-6921)
- Replace gsl::at with a new til::at(span) for pre-checked bounds (GH-6925)

Related work items: MSFT:27866336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants