-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Use type inference throughout the project #12975
Conversation
@@ -11,7 +11,7 @@ AlignOperands: true | |||
AlignTrailingComments: false | |||
AllowAllParametersOfDeclarationOnNextLine: false | |||
AllowShortBlocksOnASingleLine: Never | |||
AllowShortFunctionsOnASingleLine: Inline | |||
AllowShortFunctionsOnASingleLine: All |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you load the full diff on GitHub your browser might die. I recommend reviewing it offline.
Curiously there's no difference between Inline
and All
in clang-format 13 (which is what we currently use), but there is a difference in the upcoming 14! This change fixes the upcoming incompatibility ahead of time (and was needed in order to run clang-format 14 on this project).
7f3d9a6
to
8068696
Compare
For internal folks: Install CodeFlow, then run:
|
@@ -207,7 +207,7 @@ LRESULT IslandWindow::_OnSizing(const WPARAM wParam, const LPARAM lParam) | |||
// bad parameters, which we won't have, so no big deal. | |||
LOG_IF_FAILED(GetDpiForMonitor(hmon, MDT_EFFECTIVE_DPI, &dpix, &dpiy)); | |||
|
|||
const long minWidthScaled = minimumWidth * dpix / USER_DEFAULT_SCREEN_DPI; | |||
const LONG minWidthScaled = minimumWidth * dpix / USER_DEFAULT_SCREEN_DPI; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, this one didn't turn into an auto
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the expression evaluates to an UINT
actually, because dpix
is an UINT
.
The old code unsafely casts it to a long
, but I think in practice that's just fine. It's unlikely there to be over 2B pixels wide screens after all. 😅
I'll revert this change to long
to reduce the diff by 1.
@@ -231,12 +231,12 @@ LRESULT IslandWindow::_OnSizing(const WPARAM wParam, const LPARAM lParam) | |||
// If user has dragged anything but the top or bottom border (so e.g. left border, | |||
// top-right corner etc.), then this means that the width has changed. We thus ask to | |||
// adjust this new width so that terminal(s) is/are aligned to their character grid(s). | |||
clientWidth = gsl::narrow_cast<int>(_pfnSnapDimensionCallback(true, gsl::narrow_cast<float>(clientWidth))); | |||
clientWidth = static_cast<decltype(clientWidth)>(_pfnSnapDimensionCallback(true, static_cast<float>(clientWidth))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I'll revert it to use gsl::narrow_cast
, but I'll keep the decltype(clientWidth)
, because that adds something. clientWidth
is a long
and not a int
after all.
@@ -804,8 +804,8 @@ namespace winrt::TerminalApp::implementation | |||
// - <unused> | |||
// Return Value: | |||
// - <none> | |||
void CommandPalette::_filterTextChanged(IInspectable const& /*sender*/, | |||
Windows::UI::Xaml::RoutedEventArgs const& /*args*/) | |||
void CommandPalette::_filterTextChanged(const IInspectable& /*sender*/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future we can enforce this with clang-format 14. Until then I'm fine with fixing the ~770 places where we use non-standard ordering for those. Most of these are in console code actually IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k cool
@@ -283,7 +283,7 @@ void Settings::Validate() | |||
{ | |||
// TODO: FIX | |||
//// Get the font that we're going to use to convert pixels to characters. | |||
//DWORD const dwFontIndexWant = FindCreateFont(_uFontFamily, | |||
// const auto dwFontIndexWant = FindCreateFont(_uFontFamily, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah no, I was merely observing that this refactor also applied to commented out code. There's a few other places too. Kinda neat IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to touch up a couple hundred lines of code because clang-format / Resharper didn't get it. In some places for instance auto const
wasn't replaced with const auto
.
I've used \b(\w+) const (\w+) =
to find code like that and fixed that code by hand, including this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, read all 435 files.
- way to pad your contribution stats 😛
- doesn't look like there's
malicious-shit.exe
hiding in here - Any way to enforce this in the future? Presumably audit mode could catch it (for the subset of projects that's enabled for)
- (I don't care if there's not, just curious)
@msftbot merge this in like 4 hours |
Hello @zadjii-msft! Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:
If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you". |
Marking for automerge cause this touches bloody everything and I'm not gonna force anyone else to sit here and read these, but leaving a window to be overruled. |
🎉 Handy links: |
#4015 requires sweeping changes in order to allow a migration of our buffer
coordinates from
int16_t
toint32_t
. This commit reduces the size offuture commits by using type inference wherever possible, dropping the
need to manually adjust types throughout the project later.
As an added bonus this commit standardizes the alignment of cv qualifiers
to be always left of the type (e.g.
const T&
instead ofT const&
).The migration to type inference with
auto
was mostly doneusing JetBrains Resharper with some manual intervention and the
standardization of cv qualifier alignment using clang-format 14.
References
This is preparation work for #4015.
Validation Steps Performed