From e4db0dde4d27aeee05c190abe3696b2ce34e3814 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 15 Nov 2026 12:57:38 +0000 Subject: [PATCH 1/5] Workaround for aarch64-msvc (cherry picked from commit 748c5ea2835fb9b10e654baa55ac2f9d29bc0666) --- .github/workflows/ci.yml | 11 ++++++++++ src/ci/scripts/aarch64-msvc-workaround.ps1 | 24 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/ci/scripts/aarch64-msvc-workaround.ps1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e45ac01331ac..9b721e4eaffd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -197,6 +197,17 @@ jobs: with: python-version: ${{ matrix.required_python_version }} + # msys2 link.exe conflicts with msvc's link.exe. + # Rather than trying to fight over PATH with msys2 we simply delete it + # thus avoiding the conflict. + - name: Remove link.exe + run: rm $(which link.exe) || true + + - name: Workaroud for \#165953 + if: ${{ contains(matrix.name, 'aarch64-msvc') }} + shell: pwsh -Command $ErrorActionPreference='stop'; $PSNativeCommandUseErrorActionPreference=$true; & '{0}' + run: src\ci\scripts\aarch64-msvc-workaround.ps1 + - name: enable ipv6 on Docker # Don't run on codebuild because systemctl is not available if: ${{ !matrix.codebuild }} diff --git a/src/ci/scripts/aarch64-msvc-workaround.ps1 b/src/ci/scripts/aarch64-msvc-workaround.ps1 new file mode 100644 index 0000000000000..181856767dbb8 --- /dev/null +++ b/src/ci/scripts/aarch64-msvc-workaround.ps1 @@ -0,0 +1,24 @@ +# Workaround for #165953. +# This should be removed once that issue is fixed. +$vcvars_ver=14.44 + +# vswhere.exe is used to find Visual Studio directories. +$vswhere="${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + +# LLVM needs the ATL libraries, so make sure we have them. +$atl_include = &$vswhere -find **\atlbase.h | Split-Path -parent +$atl_lib = "$(Split-Path -parent $atl_include)\lib\arm64" +$env:INCLUDE += ";$atl_include" +$env:LIB += ";$atl_lib" + +# vcvarsall.bat sets up the environment so everything should use the given versions +$vcvarsall=&$vswhere -find **\vcvarsall.bat +cd $(Split-Path -parent $vcvarsall) +# Run vcvarsall first so any errors are printed +cmd /c "vcvarsall.bat arm64 -vcvars_ver=$vcvars_ver" +# Then run it again to capture the environment and export any differences. +$old = cmd /c set +$new = cmd /c "vcvarsall.bat arm64 -vcvars_ver=$vcvars_ver > nul && set" +foreach ($entry in (Compare-Object $new $old).InputObject) { + echo $entry >> $env:GITHUB_ENV +} From 6548f1c938e008184dd388b26ba37114822f822a Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 15 Nov 2026 13:28:57 -0800 Subject: [PATCH 2/5] Revert optimized implementation of `String::retain` This reverts commit 35df304c76838c5281ff911888aa0d9105aa113d, reversing changes made to e081d6616f3be5a96c6b42eecc6410f1a5378b7e. (cherry picked from commit 3ff409501baefc883c16fb185bffadb2e01b2fd0) --- library/alloc/src/string.rs | 78 ++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index d51bfd4ee1cc9..9917f07e68428 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -58,7 +58,7 @@ use core::ops::Add; use core::ops::AddAssign; use core::ops::{self, Range, RangeBounds}; use core::str::pattern::{Pattern, Utf8Pattern}; -use core::{fmt, hash, hint, ptr, slice}; +use core::{fmt, hash, ptr, slice}; #[cfg(not(no_global_oom_handling))] use crate::alloc::Allocator; @@ -1697,57 +1697,53 @@ impl String { where F: FnMut(char) -> bool, { - let len = self.len(); - if len == 0 { - // Explicit check results in better optimization - return; - } - - struct PanicGuard<'a> { + struct SetLenOnDrop<'a> { s: &'a mut String, - write: usize, + idx: usize, + del_bytes: usize, } - impl Drop for PanicGuard<'_> { + impl<'a> Drop for SetLenOnDrop<'a> { fn drop(&mut self) { - debug_assert!(self.write <= self.s.len()); - debug_assert!(str::from_utf8(&self.s.vec[..self.write]).is_ok()); - // SAFETY: Restore the string length to the number of bytes written so far. - unsafe { self.s.vec.set_len(self.write) } + let new_len = self.idx - self.del_bytes; + debug_assert!(new_len <= self.s.len()); + unsafe { self.s.vec.set_len(new_len) }; } } - // Fast path: find the first character that should be removed or return early. - let mut chars = self.char_indices(); - let (mut read, write) = loop { - let Some((idx, ch)) = chars.next() else { return }; - if hint::unlikely(!f(ch)) { - break (idx + ch.len_utf8(), idx); - } - }; - drop(chars); - - // Slow path: at least one character is going to be removed. - let mut g = PanicGuard { s: self, write }; - while read < len { - // SAFETY: `read` is within bound because `read` < `len`, so taking - // a slice with `len` is safe. - let ch = unsafe { g.s.get_unchecked(read..len).chars().next().unwrap_unchecked() }; + let len = self.len(); + let mut guard = SetLenOnDrop { s: self, idx: 0, del_bytes: 0 }; + + while guard.idx < len { + let ch = + // SAFETY: `guard.idx` is positive-or-zero and less that len so the `get_unchecked` + // is in bound. `self` is valid UTF-8 like string and the returned slice starts at + // a unicode code point so the `Chars` always return one character. + unsafe { guard.s.get_unchecked(guard.idx..len).chars().next().unwrap_unchecked() }; let ch_len = ch.len_utf8(); - if f(ch) { - // SAFETY: `read` is on a char boundary, as guaranteed above; `g.write` is - // within bounds because it is always behind `read`. - unsafe { - let ptr = g.s.vec.as_mut_ptr(); - ptr::copy(ptr.add(read), ptr.add(g.write), ch_len); - } - g.write += ch_len; + + if !f(ch) { + guard.del_bytes += ch_len; + } else if guard.del_bytes > 0 { + // SAFETY: `guard.idx` is in bound and `guard.del_bytes` represent the number of + // bytes that are erased from the string so the resulting `guard.idx - + // guard.del_bytes` always represent a valid unicode code point. + // + // `guard.del_bytes` >= `ch.len_utf8()`, so taking a slice with `ch.len_utf8()` len + // is safe. + ch.encode_utf8(unsafe { + crate::slice::from_raw_parts_mut( + guard.s.as_mut_ptr().add(guard.idx - guard.del_bytes), + ch.len_utf8(), + ) + }); } - read += ch_len; + + // Point idx to the next char + guard.idx += ch_len; } - // All bytes processed; commit the final length by dropping the guard. - drop(g); + drop(guard); } /// Inserts a character into this `String` at byte position `idx`. From 53456114bb7f1ce4e80df2e21d46dcf7e50bbb22 Mon Sep 17 00:00:00 2001 From: Khashayar Fereidani Date: Sun, 15 Nov 2026 14:08:25 -0800 Subject: [PATCH 3/5] library: Reapply String::retain safety doc for tidy Co-authored-by: Jubilee Young (cherry picked from commit 08e44b178063028f6561cc57aff8d338a070e908) --- library/alloc/src/string.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 9917f07e68428..4f1cc0821a4bb 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1707,6 +1707,7 @@ impl String { fn drop(&mut self) { let new_len = self.idx - self.del_bytes; debug_assert!(new_len <= self.s.len()); + // SAFETY: Restore the string length to the number of bytes written so far. unsafe { self.s.vec.set_len(new_len) }; } } From 417ab51c4af967f230d3d7fde3d9ab726faff232 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 16 Nov 2026 15:17:49 +0100 Subject: [PATCH 4/5] Update LLVM submodule (cherry picked from commit 137e1af6356139c56d5dea87185c950fc753366c) --- src/llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm-project b/src/llvm-project index 0a5579eb649d3..08ec928a5bd18 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 0a5579eb649d3634a9c30ac873300cc2944fa070 +Subproject commit 08ec928a5bd1866f4008c8ad216166ca685fd380 From 4f83a28bd2b1418db3713afe1a498b7127608167 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 17 Nov 2026 17:09:20 +0100 Subject: [PATCH 5/5] Make test robust to unlucky crate disambiguators (cherry picked from commit 6590e6d3618c593e0014ad83b2df5c9c735a8a69) --- tests/codegen-llvm/checked_ilog.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/codegen-llvm/checked_ilog.rs b/tests/codegen-llvm/checked_ilog.rs index e340a45b6a96d..96c575ea4268f 100644 --- a/tests/codegen-llvm/checked_ilog.rs +++ b/tests/codegen-llvm/checked_ilog.rs @@ -8,13 +8,13 @@ // CHECK-SAME: (i16{{.*}} %val, i16{{.*}} %base) #[no_mangle] pub fn checked_ilog(val: u16, base: u16) -> Option { - // CHECK-NOT: udiv - // CHECK-NOT: mul + // CHECK-NOT: udiv i + // CHECK-NOT: mul i // CHECK: %[[IS_LESS:.+]] = icmp ult i16 %val, %base // CHECK-NEXT: br i1 %[[IS_LESS]], label %[[TRUE:.+]], label %[[FALSE:.+]] // CHECK: [[TRUE]]: - // CHECK-NOT: udiv - // CHECK-NOT: mul + // CHECK-NOT: udiv i + // CHECK-NOT: mul i // CHECK: ret { i32, i32 } val.checked_ilog(base) }