Prepare til wrappers for migrating off of SMALL_RECT (#11902)

This commit makes the following changes to `til::point/size/rectangle`
for the following reasons:
* Rename `rectangle` into `rect`
  This will make the naming consistent with a later `small_rect` struct
  as well as the existing Win32 POINT/SIZE/RECT structs.
* Standardizes til wrappers on `int32_t` instead of `ptrdiff_t`
  Provides a consistent behavior between x86 and x64, preventing accidental
  errors on x86, as it's less rigorously tested than x64. Additionally it
  improves interop with MIDL3 which only supports fixed width integer types.
* Standardizes til wrappers on throwing `gsl::narrow_error`
  Makes the behavior of our code more consistent.
* Makes all eligible functions `constexpr`
  Because why not.
* Removes implicit constructors and conversion operators
  This is a complex and controversial topic. My reasons are: You can't Ctrl+F
  for an implicit conversion. This breaks most non-IDE engines, like the one on
  GitHub or those we have internally at MS. This is important for me as these
  implicit conversion operators aren't cost free. Narrowing integers itself,
  as well as the boundary checks that need to be done have a certain,
  fixed overhead each time. Additionally the lack of noexcept prevents
  many advanced compiler optimizations. Removing their use entirely
  drops conhost's code segment size by around ~6.5%.

## References

Preliminary work for #4015.

## PR Checklist
* [x] I work here
* [x] Tests added/passed

## Validation Steps Performed
I'm mostly relying on our unit tests here. Both OpenConsole and WT appear to work fine.
This commit is contained in:
Leonard Hecker
2022-01-13 22:09:29 +01:00
committed by GitHub
parent 1a62f473ad
commit b3fab518f8
81 changed files with 2704 additions and 3651 deletions

View File

@@ -10,7 +10,7 @@
[CmdletBinding()]
Param(
[Parameter(Position=0, ValueFromPipeline=$true)]
[string]$TestPath = "UiaTests.csv"
[string]$TestPath = "$PSScriptRoot/../../tools/TestTableWriter/UiaTests.csv"
)
# 0. Generate a comment telling people to not modify these tests in the .cpp
@@ -24,7 +24,7 @@ $result = "// Copyright (c) Microsoft Corporation.
# 1. Define a few helpful variables to make life easier.
$result += "
// Define a few helpful variables
constexpr til::rectangle bufferSize{ 0, 0, 80, 300 };
constexpr til::rect bufferSize{ 0, 0, 80, 300 };
constexpr short midX{ 40 };
constexpr short midY{ 150 };
constexpr short midPopulatedY{ 75 };
@@ -77,7 +77,7 @@ foreach ($var in $vars)
# i. Contains "segment" --> define point at the beginning of a text segment
if ($segmentHeuristic)
{
$result += "constexpr til::point {0}{{ {1}, {2}.y() }};" -f $var, $var.Substring(0, 8), $var.Substring(9, $var.Length - $var.IndexOf("L") - 1);
$result += "constexpr til::point {0}{{ {1}, {2}.y }};" -f $var, $var.Substring(0, 8), $var.Substring(9, $var.Length - $var.IndexOf("L") - 1);
}
# ii. Contains number --> requires movement
elseif ($movementHeuristic)
@@ -125,7 +125,7 @@ foreach ($var in $vars)
elseif ($leftHeuristic)
{
$standardVar = $var.Split("Left")[0]
$result += "constexpr til::point {0}{{ bufferSize.left(), {1}.y() }};" -f $var, $standardVar;
$result += "constexpr til::point {0}{{ bufferSize.left, {1}.y }};" -f $var, $standardVar;
}
$result += "`n";
}
@@ -182,4 +182,4 @@ foreach ($test in $tests)
}
$result += "};`n`n"
$result > "..\..\src\interactivity\win32\ut_interactivity_win32\GeneratedUiaTextRangeMovementTests.g.cpp";
$result > "$PSScriptRoot/../../src/interactivity/win32/ut_interactivity_win32/GeneratedUiaTextRangeMovementTests.g.cpp";