Skip to content

Exclude more rarely-used stuff from Windows headers#8513

Merged
2 commits merged intomicrosoft:mainfrom
skyline75489:chesterliu/dev/win32-leaner-and-meaner
Dec 11, 2020
Merged

Exclude more rarely-used stuff from Windows headers#8513
2 commits merged intomicrosoft:mainfrom
skyline75489:chesterliu/dev/win32-leaner-and-meaner

Conversation

@skyline75489
Copy link
Collaborator

@skyline75489 skyline75489 commented Dec 7, 2020

This PR defines a series of NOSOMETHING macros in PCHs, in order to
prevent windows.h from bringing a lot of rarely used things into the
project.

Theoretically this should make PCH generation and overall complication
faster, but I didn't really benchmark the speed.

Another benefit would be reducing the symbol noises caused by
windows.h.

@github-actions
Copy link

github-actions bot commented Dec 7, 2020

New misspellings found, please review:

  • NOCLIPBOARD
  • NOCOMM
  • NOHELP
  • NOKERNEL
  • NOMB
  • NOMCX
  • NOMSG
  • NOSERVICE
  • NOSOUND
  • NOUSER
To accept these changes, run the following commands
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect/5757ec679b03a4240130c3c53766c91bbc5cd6a7.txt
.github/actions/spell-check/expect/655f007265b351e140d20b3976792523ad689241.txt
.github/actions/spell-check/expect/alphabet.txt
.github/actions/spell-check/expect/expect.txt
.github/actions/spell-check/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"AAAAA Bopomofo CParams CSV GENERATEPROJECTPRIFILE hhhh Horiz IHosted Inlines MAKEINTRESOURCEA mousemode renamer
 Reserialize rgus SGRXY tcon UDK UDKs Unfocus xe xlang "');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
  if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
  next if /^($re)(?:$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect/d2fbcd227cce9851e7640f7734955952a23320dd.txt";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"csv horiz inlines NOCLIPBOARD NOCOMM NOHELP NOKERNEL NOMB NOMCX NOMSG NOSERVICE NOSOUND NOUSER Renamer reserialize udk unfocus "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
git add .github/actions/spell-check/expect || echo '... you want to ensure .github/actions/spell-check/expect/d2fbcd227cce9851e7640f7734955952a23320dd.txt is added to your repository...'
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spell-check/dictionary/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spell-check/dictionary/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spell-check/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spell-check/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The :check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

⚠️ Reviewers

At present, the action that triggered this message will not show its ❌ in this PR unless the branch is within this repository.
Thus, you should make sure that this comment has been addressed before encouraging the merge bot to merge this PR.

@miniksa
Copy link
Member

miniksa commented Dec 7, 2020

Oh goodness. Let's list out what these actually do.

  • NOCLIPBOARD
    • Blocks CF_* clipboard formats
    • Blocks Open/Close/Empty clipboard
  • NOCOMM
    • Modem stuff
  • NOHELP
    • WinHelp and friends (I think this is deprecated)
  • NOKERNEL
    • GetProcAddress and a bunch of process/thread management stuff
  • NOMB
    • MessageBox and friends
  • NOMCX
    • Modem extensions
  • NOMSG
    • Message queuing (Wndproc and such)
  • NOSERVICE
    • Service Controller
  • NOSOUND
    • Open/Close/Start/Stop sound
    • Notably not PlaySound
  • NOUSER
    • Icon, Cursor... System Metrics, System Parameters Info...

Now let's list out if any Terminal/Console project has used them.

  • NOCLIPBOARD
    • Console and Terminal use clipboard routines to access the clipboard.
  • NOCOMM
    • Nothing touches the modem
  • NOHELP
    • WinHelp is dead, nothing should touch it.
  • NOKERNEL
    • Console and I believe Terminal need process/thread management and debug stuff from this.
  • NOMB
    • Nothing should use MessageBox in production except maybe a last chance error, but sometimes people use this for debugging.
  • NOMCX
    • Nothing touches the modem
  • NOMSG
    • We use message queuing all the time.
  • NOSERVICE
    • Console doesn't touch the service controller, but I believe Terminal does now to check about the input service.
  • NOSOUND
    • Only PlaySound is used for a system beep. I don't believe we have any other sounds.
  • NOUSER
    • System metrics and parameters are used all over the place.

Then my feeling on this:

  1. I'd rather we remain relatively consistent with what's in all the namespaces in our projects unless there's a measurable and appreciable improvement in compilation time or debugging ease.
  2. I'd rather not block out anything that we used or have the potential to use even on a semi-regular or debugging basis so there's not another roadblock to debugging a problem that is a bit more obtuse/obscure to understand.
  3. I'm fine with blocking things that we really shouldn't have any reason to do.

So overall... I think I'd be fine with blocking out:

  • NOCOMM
  • NOMCX
  • NOHELP
    and probably
  • NOSOUND

But I think all the rest are going to get us into a future difficult-to-debug pitfall that's not worth it unless you can justify it with some sort of improvement metrics.

@skyline75489
Copy link
Collaborator Author

I actually have the same concern that it will “get us into a future difficult-to-debug pitfall ”. I’ll try to make this PR less aggressive.

@zadjii-msft
Copy link
Member

Hey so I don't think I'm qualified to review this one. It looks fine to me, but I don't really have an opinion or enough background to know what the side effects would be. I'm gonna leave it to @miniksa and @DHowett, they're probably the best suited to reviewing this.

@zadjii-msft zadjii-msft added Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Product-Meta The product is the management of the products. labels Dec 11, 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.

I'm okay with this limited subset since it's stuff we shouldn't be using anyway really, but defer veto rights to @DHowett if he doesn't want to take this at all.

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Sure! Thanks.

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

ghost commented Dec 11, 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.

@ghost ghost merged commit 219ee0c into microsoft:main Dec 11, 2020
@skyline75489 skyline75489 deleted the chesterliu/dev/win32-leaner-and-meaner branch January 25, 2021 02:57
mpela81 pushed a commit to mpela81/terminal that referenced this pull request Jan 28, 2021
This PR defines a series of `NOSOMETHING` macros in PCHs, in order to
prevent `windows.h` from bringing a lot of rarely used things into the
project. 

Theoretically this should make PCH generation and overall complication
faster, but I didn't really benchmark the speed. 

Another benefit would be reducing the symbol noises caused by
`windows.h`.
This pull request was closed.
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. AutoMerge Marked for automatic merge by the bot when requirements are met Product-Meta The product is the management of the products.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants