Skip to content

Commit 939844a

Browse files
committed
Auto merge of #148686 - jhpratt:rollup-jlh9fj9, r=jhpratt
Rollup of 16 pull requests Successful merges: - #147534 (Implement SIMD funnel shifts in const-eval/Miri) - #147686 (update isolate_highest_one for NonZero<T>) - #148020 (Show backtrace on allocation failures when possible) - #148204 (Modify contributor email entries in .mailmap) - #148230 (rustdoc: Properly highlight shebang, frontmatter & weak keywords in source code pages and code blocks) - #148279 (rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names) - #148555 (Fix rust-by-example spanish translation) - #148556 (Fix suggestion for returning async closures) - #148585 ([rustdoc] Replace `print` methods with functions to improve code readability) - #148600 (re-use `self.get_all_attrs` result for pass indirectly attribute) - #148612 (Add note for identifier with attempted hygiene violation) - #148613 (Switch hexagon targets to rust-lld) - #148619 (Enable std locking functions on AIX) - #148644 ([bootstrap] Make `--open` option work with `doc src/tools/error_index_generator`) - #148649 (don't completely reset `HeadUsages`) - #148675 (Remove eslint-js from npm dependencies) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bbb6f68 + 896d190 commit 939844a

File tree

47 files changed

+1311
-644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1311
-644
lines changed

.mailmap

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Aaron Todd <[email protected]>
99
Abhishek Chanda <[email protected]> Abhishek Chanda <[email protected]>
1010
Abhijeet Bhagat <[email protected]>
1111
Abroskin Alexander <[email protected]>
12-
Adolfo Ochagavía <[email protected]>
12+
1313
Adrian Heine né Lang <[email protected]>
1414
Adrien Tétar <[email protected]>
1515
@@ -36,6 +36,7 @@ Amanda Stjerna <[email protected]> <[email protected]>
3636
3737
3838
39+
3940
Ana-Maria Mihalache <[email protected]>
4041
Anatoly Ikorsky <[email protected]>
4142
Andre Bogus <[email protected]>
@@ -276,7 +277,8 @@ Irina Popa <[email protected]>
276277
Ivan Ivaschenko <[email protected]>
277278
ivan tkachenko <[email protected]>
278279
J. J. Weber <[email protected]>
279-
280+
281+
280282
281283
Jacob Hoffman-Andrews <[email protected]> <[email protected]>
282284
Jacob Greenfield <[email protected]>
@@ -292,6 +294,8 @@ Jakub Adam Wieczorek <[email protected]>
292294
Jakub Adam Wieczorek <[email protected]> <[email protected]>
293295
Jakub Adam Wieczorek <[email protected]> <[email protected]>
294296
Jakub Adam Wieczorek <[email protected]> <[email protected]>
297+
Jakub Adam Wieczorek <[email protected]> <[email protected]>
298+
Jakub Adam Wieczorek <[email protected]> <[email protected]>
295299
296300
James [Undefined] <[email protected]>
297301
@@ -303,6 +307,7 @@ Jamie Hill-Daniel <[email protected]> <[email protected]>
303307
Jana Dönszelmann <[email protected]>
304308
305309
310+
306311
307312
Jaro Fietz <[email protected]>
308313
Jason Fager <[email protected]>
@@ -313,6 +318,7 @@ Jason Toffaletti <[email protected]> Jason Toffaletti <[email protected]>
313318
Jauhien Piatlicki <[email protected]> Jauhien Piatlicki <[email protected]>
314319
315320
Jeremy Letang <[email protected]>
321+
316322
Jeremy Sorensen <[email protected]>
317323
318324
@@ -336,6 +342,7 @@ John Kåre Alsaker <[email protected]>
336342
John Kåre Alsaker <[email protected]> <[email protected]>
337343
John Talling <[email protected]>
338344
John Van Enk <[email protected]>
345+
339346
Jonas Tepe <[email protected]>
340347
341348
Jonathan Chan Kwan Yin <[email protected]>
@@ -424,7 +431,7 @@ Malo Jaffré <[email protected]>
424431
Manish Goregaokar <[email protected]>
425432
426433
Marcell Pardavi <[email protected]>
427-
Marco Ieni <[email protected]>
434+
428435
Marcus Klaas de Vries <[email protected]>
429436
Margaret Meyerhofer <[email protected]> <mmeyerho@andrew>
430437
@@ -531,6 +538,7 @@ Oliver Scherer <[email protected]> <[email protected]>
531538
532539
533540
Oliver Scherer <[email protected]>
541+
534542
535543
Onur Özkan <[email protected]>
536544
Ömer Sinan Ağacan <[email protected]>
@@ -591,6 +599,7 @@ Rusty Blitzerr <[email protected]>
591599
RustyYato <[email protected]>
592600
Ruud van Asseldonk <[email protected]> Ruud van Asseldonk <[email protected]>
593601
Ryan Leung <[email protected]>
602+
594603
Ryan Scheel <[email protected]>
595604
Ryan Sullivant <[email protected]>
596605
Ryan Wiedemann <[email protected]>
@@ -686,6 +695,8 @@ Weihang Lo <[email protected]>
686695
687696
688697
whitequark <[email protected]>
698+
699+
689700
690701
691702
@@ -695,6 +706,8 @@ Xinye Tao <[email protected]>
695706
Xuefeng Wu <[email protected]> Xuefeng Wu <[email protected]>
696707
Xuefeng Wu <[email protected]> XuefengWu <[email protected]>
697708
York Xiang <[email protected]>
709+
710+
698711
699712
700713
Youngsuk Kim <[email protected]>

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,30 +207,30 @@ pub(crate) fn expand_test_or_bench(
207207
};
208208

209209
let test_fn = if is_bench {
210-
// A simple ident for a lambda
211-
let b = Ident::from_str_and_span("b", attr_sp);
212-
210+
// avoid name collisions by using the function name within the identifier, see bug #148275
211+
let bencher_param =
212+
Ident::from_str_and_span(&format!("__bench_{}", fn_.ident.name), attr_sp);
213213
cx.expr_call(
214214
sp,
215215
cx.expr_path(test_path("StaticBenchFn")),
216216
thin_vec![
217217
// #[coverage(off)]
218-
// |b| self::test::assert_test_result(
218+
// |__bench_fn_name| self::test::assert_test_result(
219219
coverage_off(cx.lambda1(
220220
sp,
221221
cx.expr_call(
222222
sp,
223223
cx.expr_path(test_path("assert_test_result")),
224224
thin_vec![
225-
// super::$test_fn(b)
225+
// super::$test_fn(__bench_fn_name)
226226
cx.expr_call(
227227
ret_ty_sp,
228228
cx.expr_path(cx.path(sp, vec![fn_.ident])),
229-
thin_vec![cx.expr_ident(sp, b)],
229+
thin_vec![cx.expr_ident(sp, bencher_param)],
230230
),
231231
],
232232
),
233-
b,
233+
bencher_param,
234234
)), // )
235235
],
236236
)

compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_abi::{BackendRepr, Endian};
33
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
44
use rustc_apfloat::{Float, Round};
55
use rustc_middle::mir::interpret::{InterpErrorKind, Pointer, UndefinedBehaviorInfo};
6-
use rustc_middle::ty::{FloatTy, SimdAlign};
6+
use rustc_middle::ty::{FloatTy, ScalarInt, SimdAlign};
77
use rustc_middle::{bug, err_ub_format, mir, span_bug, throw_unsup_format, ty};
88
use rustc_span::{Symbol, sym};
99
use tracing::trace;
@@ -744,6 +744,58 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
744744
self.write_scalar(val, &dest)?;
745745
}
746746
}
747+
sym::simd_funnel_shl | sym::simd_funnel_shr => {
748+
let (left, _) = self.project_to_simd(&args[0])?;
749+
let (right, _) = self.project_to_simd(&args[1])?;
750+
let (shift, _) = self.project_to_simd(&args[2])?;
751+
let (dest, _) = self.project_to_simd(&dest)?;
752+
753+
let (len, elem_ty) = args[0].layout.ty.simd_size_and_type(*self.tcx);
754+
let (elem_size, _signed) = elem_ty.int_size_and_signed(*self.tcx);
755+
let elem_size_bits = u128::from(elem_size.bits());
756+
757+
let is_left = intrinsic_name == sym::simd_funnel_shl;
758+
759+
for i in 0..len {
760+
let left =
761+
self.read_scalar(&self.project_index(&left, i)?)?.to_bits(elem_size)?;
762+
let right =
763+
self.read_scalar(&self.project_index(&right, i)?)?.to_bits(elem_size)?;
764+
let shift_bits =
765+
self.read_scalar(&self.project_index(&shift, i)?)?.to_bits(elem_size)?;
766+
767+
if shift_bits >= elem_size_bits {
768+
throw_ub_format!(
769+
"overflowing shift by {shift_bits} in `{intrinsic_name}` in lane {i}"
770+
);
771+
}
772+
let inv_shift_bits = u32::try_from(elem_size_bits - shift_bits).unwrap();
773+
774+
// A funnel shift left by S can be implemented as `(x << S) | y.unbounded_shr(SIZE - S)`.
775+
// The `unbounded_shr` is needed because otherwise if `S = 0`, it would be `x | y`
776+
// when it should be `x`.
777+
//
778+
// This selects the least-significant `SIZE - S` bits of `x`, followed by the `S` most
779+
// significant bits of `y`. As `left` and `right` both occupy the lower `SIZE` bits,
780+
// we can treat the lower `SIZE` bits as an integer of the right width and use
781+
// the same implementation, but on a zero-extended `x` and `y`. This works because
782+
// `x << S` just pushes the `SIZE-S` MSBs out, and `y >> (SIZE - S)` shifts in
783+
// zeros, as it is zero-extended. To the lower `SIZE` bits, this looks just like a
784+
// funnel shift left.
785+
//
786+
// Note that the `unbounded_sh{l,r}`s are needed only in case we are using this on
787+
// `u128xN` and `inv_shift_bits == 128`.
788+
let result_bits = if is_left {
789+
(left << shift_bits) | right.unbounded_shr(inv_shift_bits)
790+
} else {
791+
left.unbounded_shl(inv_shift_bits) | (right >> shift_bits)
792+
};
793+
let (result, _overflow) = ScalarInt::truncate_from_uint(result_bits, elem_size);
794+
795+
let dest = self.project_index(&dest, i)?;
796+
self.write_scalar(result, &dest)?;
797+
}
798+
}
747799

748800
// Unsupported intrinsic: skip the return_to_block below.
749801
_ => return interp_ok(false),

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,21 @@ pub fn suggest_impl_trait<'tcx>(
12631263
infcx.tcx.lang_items().future_output(),
12641264
format_as_assoc,
12651265
),
1266+
(
1267+
infcx.tcx.lang_items().async_fn_trait(),
1268+
infcx.tcx.lang_items().async_fn_once_output(),
1269+
format_as_parenthesized,
1270+
),
1271+
(
1272+
infcx.tcx.lang_items().async_fn_mut_trait(),
1273+
infcx.tcx.lang_items().async_fn_once_output(),
1274+
format_as_parenthesized,
1275+
),
1276+
(
1277+
infcx.tcx.lang_items().async_fn_once_trait(),
1278+
infcx.tcx.lang_items().async_fn_once_output(),
1279+
format_as_parenthesized,
1280+
),
12661281
(
12671282
infcx.tcx.lang_items().fn_trait(),
12681283
infcx.tcx.lang_items().fn_once_output(),

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,9 +1512,8 @@ impl<'tcx> TyCtxt<'tcx> {
15121512
field_shuffle_seed ^= user_seed;
15131513
}
15141514

1515-
if let Some(reprs) =
1516-
find_attr!(self.get_all_attrs(did), AttributeKind::Repr { reprs, .. } => reprs)
1517-
{
1515+
let attributes = self.get_all_attrs(did);
1516+
if let Some(reprs) = find_attr!(attributes, AttributeKind::Repr { reprs, .. } => reprs) {
15181517
for (r, _) in reprs {
15191518
flags.insert(match *r {
15201519
attr::ReprRust => ReprFlags::empty(),
@@ -1574,10 +1573,7 @@ impl<'tcx> TyCtxt<'tcx> {
15741573
}
15751574

15761575
// See `TyAndLayout::pass_indirectly_in_non_rustic_abis` for details.
1577-
if find_attr!(
1578-
self.get_all_attrs(did),
1579-
AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)
1580-
) {
1576+
if find_attr!(attributes, AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)) {
15811577
flags.insert(ReprFlags::PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS);
15821578
}
15831579

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,8 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11251125
}
11261126
}
11271127
}
1128+
1129+
self.suggest_ident_hidden_by_hygiene(err, path, span);
11281130
} else if err_code == E0412 {
11291131
if let Some(correct) = Self::likely_rust_type(path) {
11301132
err.span_suggestion(
@@ -1138,6 +1140,28 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11381140
}
11391141
}
11401142

1143+
fn suggest_ident_hidden_by_hygiene(&self, err: &mut Diag<'_>, path: &[Segment], span: Span) {
1144+
let [segment] = path else { return };
1145+
1146+
let ident = segment.ident;
1147+
let callsite_span = span.source_callsite();
1148+
for rib in self.ribs[ValueNS].iter().rev() {
1149+
for (binding_ident, _) in &rib.bindings {
1150+
if binding_ident.name == ident.name
1151+
&& !binding_ident.span.eq_ctxt(span)
1152+
&& !binding_ident.span.from_expansion()
1153+
&& binding_ident.span.lo() < callsite_span.lo()
1154+
{
1155+
err.span_help(
1156+
binding_ident.span,
1157+
"an identifier with the same name exists, but is not accessible due to macro hygiene",
1158+
);
1159+
return;
1160+
}
1161+
}
1162+
}
1163+
}
1164+
11411165
/// Emit special messages for unresolved `Self` and `self`.
11421166
fn suggest_self_ty(
11431167
&self,

compiler/rustc_target/src/spec/targets/hexagon_unknown_linux_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
88
base.features = "-small-data,+hvx-length128b".into();
99

1010
base.has_rpath = true;
11+
base.linker = Some("rust-lld".into());
1112
base.linker_flavor = LinkerFlavor::Unix(Cc::Yes);
1213

1314
base.c_enum_min_bits = Some(8);

compiler/rustc_target/src/spec/targets/hexagon_unknown_none_elf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) fn target() -> Target {
2727
max_atomic_width: Some(32),
2828
emit_debug_gdb_scripts: false,
2929
c_enum_min_bits: Some(8),
30+
linker: Some("rust-lld".into()),
3031
..Default::default()
3132
},
3233
}

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use derive_where::derive_where;
2323
#[cfg(feature = "nightly")]
2424
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
2525
use rustc_type_ir::data_structures::HashMap;
26-
use tracing::{debug, instrument};
26+
use tracing::{debug, instrument, trace};
2727

2828
mod stack;
2929
use stack::{Stack, StackDepth, StackEntry};
@@ -916,6 +916,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
916916
/// heads from the stack. This may not necessarily mean that we've actually
917917
/// reached a fixpoint for that cycle head, which impacts the way we rebase
918918
/// provisional cache entries.
919+
#[derive_where(Debug; X: Cx)]
919920
enum RebaseReason<X: Cx> {
920921
NoCycleUsages,
921922
Ambiguity(X::AmbiguityInfo),
@@ -950,6 +951,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
950951
/// cache entries to also be ambiguous. This causes some undesirable ambiguity for nested
951952
/// goals whose result doesn't actually depend on this cycle head, but that's acceptable
952953
/// to me.
954+
#[instrument(level = "trace", skip(self, cx))]
953955
fn rebase_provisional_cache_entries(
954956
&mut self,
955957
cx: X,
@@ -969,6 +971,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
969971
let popped_head = if heads.highest_cycle_head_index() == popped_head_index {
970972
heads.remove_highest_cycle_head()
971973
} else {
974+
debug_assert!(heads.highest_cycle_head_index() < popped_head_index);
972975
return true;
973976
};
974977

@@ -1057,6 +1060,8 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
10571060
new_highest_head_index,
10581061
));
10591062

1063+
trace!(?input, ?entry, "rebased provisional cache entry");
1064+
10601065
true
10611066
});
10621067
!entries.is_empty()
@@ -1379,7 +1384,8 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
13791384
}
13801385

13811386
// Clear all provisional cache entries which depend on a previous provisional
1382-
// result of this goal and rerun.
1387+
// result of this goal and rerun. This does not remove goals which accessed this
1388+
// goal without depending on its result.
13831389
self.clear_dependent_provisional_results_for_rerun();
13841390

13851391
debug!(?result, "fixpoint changed provisional results");
@@ -1399,7 +1405,12 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
13991405
// similar to the previous iterations when reevaluating, it's better
14001406
// for caching if the reevaluation also starts out with `false`.
14011407
encountered_overflow: false,
1402-
usages: None,
1408+
// We keep provisional cache entries around if they used this goal
1409+
// without depending on its result.
1410+
//
1411+
// We still need to drop or rebase these cache entries once we've
1412+
// finished evaluating this goal.
1413+
usages: Some(HeadUsages::default()),
14031414
candidate_usages: None,
14041415
});
14051416
}

library/core/src/num/nonzero.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,15 @@ macro_rules! nonzero_integer {
660660
without modifying the original"]
661661
#[inline(always)]
662662
pub const fn isolate_highest_one(self) -> Self {
663-
let n = self.get() & (((1 as $Int) << (<$Int>::BITS - 1)).wrapping_shr(self.leading_zeros()));
664-
665663
// SAFETY:
666664
// `self` is non-zero, so masking to preserve only the most
667665
// significant set bit will result in a non-zero `n`.
668-
unsafe { NonZero::new_unchecked(n) }
666+
// and self.leading_zeros() is always < $INT::BITS since
667+
// at least one of the bits in the number is not zero
668+
unsafe {
669+
let bit = (((1 as $Uint) << (<$Uint>::BITS - 1)).unchecked_shr(self.leading_zeros()));
670+
NonZero::new_unchecked(bit as $Int)
671+
}
669672
}
670673

671674
/// Returns `self` with only the least significant bit set.

0 commit comments

Comments
 (0)