Skip to content

Simplify MSYS check in is_terminal on Windows - #164261

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
lhecker:is-terminal-simplification
Oct 24, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
lhecker:is-terminal-simplification

Conversation

@lhecker

@lhecker lhecker commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

The diff is a mess but it's actually a trivial change:

  • Avoid MAX_PATH array init on stack using MaybeUninit
  • Remove from_utf16_lossy and convert all checks to utf16!()

To round it off this PR changes is_msys && is_pty to lambdas, which
lets LLVM short-circuit the is_pty check! It gets fully inlined.

This results in an almost 5x binary size reduction and 5-10x
CPU cost reduction (although it was only 100ns to begin with).

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 13, 2026
@rustbot

rustbot commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from JohnTitor, Mark-Simulacrum

// Lambdas are used to allow the compiler to short-circuit the is_pty check.
let is_msys = || name.starts_with(utf16!("msys-")) || name.starts_with(utf16!("cygwin-"));
let is_pty = || name.array_windows::<4>().any(|part| part == utf16!("-pty"));
is_msys() && is_pty()

@lhecker lhecker Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You can find an assembly comparison here: https://godbolt.org/z/or4szY9Wb

FWIW, I have fuzzed this change locally and could not spot any regressions.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@ChrisDenton

Copy link
Copy Markdown
Member

My hope is we can eventually remove this hack since msys and git bash are moving to the native pseudo console API by default. But it's probably still too early to do that.

@ChrisDenton

Copy link
Copy Markdown
Member

Thanks, I confirmed this does indeed improve codegen and doesn't appear to cause regressions (to the extent of my testing).

r? ChrisDenton
@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 1d49b44 has been approved by ChrisDenton

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 23, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #163743 (std: simplify the miri bypass of the stack overflow detection logic)
 - #164474 (core: implement `char::is_xid_{start|continue}`)
 - #164643 (Const-stabilize `{BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque)::{len, is_empty}`)
 - #164739 (Use cfi_encoding instead of name in abi checking in miri)
 - #162927 (stabilize ptr_cast_slice)
 - #163372 (Restrict `PartialEq` and `PartialOrd` documentation to thin pointers)
 - #164261 (Simplify MSYS check in is_terminal on Windows)
 - #164698 (Remove FCP from libs tracking checklist)
 - #164810 (Don't prioritize issues that require internal features)
@rust-bors
rust-bors Bot merged commit 791b6c1 into rust-lang:main Oct 24, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 24, 2026
Rollup merge of #164261 - lhecker:is-terminal-simplification, r=ChrisDenton

Simplify MSYS check in is_terminal on Windows

The diff is a mess but it's actually a trivial change:
* Avoid `MAX_PATH` array init on stack using `MaybeUninit`
* Remove `from_utf16_lossy` and convert all checks to `utf16!()`

To round it off this PR changes `is_msys && is_pty` to lambdas, which
lets LLVM short-circuit the `is_pty` check! It gets fully inlined.

This results in an almost 5x binary size reduction and 5-10x
CPU cost reduction (although it was only 100ns to begin with).
programskillforverification pushed a commit to programskillforverification/miri that referenced this pull request Oct 24, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#163743 (std: simplify the miri bypass of the stack overflow detection logic)
 - rust-lang/rust#164474 (core: implement `char::is_xid_{start|continue}`)
 - rust-lang/rust#164643 (Const-stabilize `{BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque)::{len, is_empty}`)
 - rust-lang/rust#164739 (Use cfi_encoding instead of name in abi checking in miri)
 - rust-lang/rust#162927 (stabilize ptr_cast_slice)
 - rust-lang/rust#163372 (Restrict `PartialEq` and `PartialOrd` documentation to thin pointers)
 - rust-lang/rust#164261 (Simplify MSYS check in is_terminal on Windows)
 - rust-lang/rust#164698 (Remove FCP from libs tracking checklist)
 - rust-lang/rust#164810 (Don't prioritize issues that require internal features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants