Skip to content

Commit a73ecb3

Browse files
committed
Auto merge of #61716 - Centril:rollup-nxwf5ol, r=Centril
Rollup of 5 pull requests Successful merges: - #59600 (Replaced linear token counting macros with optimized implementation) - #61501 (get rid of real_intrinsics module) - #61570 (Fix issues with const argument inference) - #61683 (Haiku: the maximum stack size is 16 MB) - #61697 (submodules: update clippy from 71be6f6 to c0dbd34) Failed merges: r? @ghost
2 parents 1cbd8a4 + f90d348 commit a73ecb3

17 files changed

+231
-126
lines changed

src/libcore/intrinsics.rs

+16-27
Original file line numberDiff line numberDiff line change
@@ -1326,30 +1326,10 @@ extern "rust-intrinsic" {
13261326
pub fn nontemporal_store<T>(ptr: *mut T, val: T);
13271327
}
13281328

1329-
mod real_intrinsics {
1330-
extern "rust-intrinsic" {
1331-
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1332-
/// and destination must *not* overlap.
1333-
/// For the full docs, see the stabilized wrapper [`copy_nonoverlapping`].
1334-
///
1335-
/// [`copy_nonoverlapping`]: ../../std/ptr/fn.copy_nonoverlapping.html
1336-
pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
1337-
1338-
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1339-
/// and destination may overlap.
1340-
/// For the full docs, see the stabilized wrapper [`copy`].
1341-
///
1342-
/// [`copy`]: ../../std/ptr/fn.copy.html
1343-
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
1344-
1345-
/// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
1346-
/// `val`.
1347-
/// For the full docs, see the stabilized wrapper [`write_bytes`].
1348-
///
1349-
/// [`write_bytes`]: ../../std/ptr/fn.write_bytes.html
1350-
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
1351-
}
1352-
}
1329+
// Some functions are defined here because they accidentally got made
1330+
// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
1331+
// (`transmute` also falls into this category, but it cannot be wrapped due to the
1332+
// check that `T` and `U` have the same size.)
13531333

13541334
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
13551335
/// and destination must *not* overlap.
@@ -1437,7 +1417,10 @@ mod real_intrinsics {
14371417
#[stable(feature = "rust1", since = "1.0.0")]
14381418
#[inline]
14391419
pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
1440-
real_intrinsics::copy_nonoverlapping(src, dst, count);
1420+
extern "rust-intrinsic" {
1421+
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
1422+
}
1423+
copy_nonoverlapping(src, dst, count);
14411424
}
14421425

14431426
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
@@ -1494,7 +1477,10 @@ pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
14941477
#[stable(feature = "rust1", since = "1.0.0")]
14951478
#[inline]
14961479
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
1497-
real_intrinsics::copy(src, dst, count)
1480+
extern "rust-intrinsic" {
1481+
fn copy<T>(src: *const T, dst: *mut T, count: usize);
1482+
}
1483+
copy(src, dst, count)
14981484
}
14991485

15001486
/// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
@@ -1572,7 +1558,10 @@ pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
15721558
#[stable(feature = "rust1", since = "1.0.0")]
15731559
#[inline]
15741560
pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
1575-
real_intrinsics::write_bytes(dst, val, count)
1561+
extern "rust-intrinsic" {
1562+
fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
1563+
}
1564+
write_bytes(dst, val, count)
15761565
}
15771566

15781567
// Simple bootstrap implementations of minnum/maxnum for stage0 compilation.

src/librustc/hir/lowering.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ impl<'a> LoweringContext<'a> {
21682168
itctx: ImplTraitContext<'_>,
21692169
explicit_owner: Option<NodeId>,
21702170
) -> hir::PathSegment {
2171-
let (mut generic_args, infer_types) = if let Some(ref generic_args) = segment.args {
2171+
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
21722172
let msg = "parenthesized type parameters may only be used with a `Fn` trait";
21732173
match **generic_args {
21742174
GenericArgs::AngleBracketed(ref data) => {
@@ -2230,17 +2230,17 @@ impl<'a> LoweringContext<'a> {
22302230
.collect();
22312231
if expected_lifetimes > 0 && param_mode == ParamMode::Explicit {
22322232
let anon_lt_suggestion = vec!["'_"; expected_lifetimes].join(", ");
2233-
let no_ty_args = generic_args.args.len() == expected_lifetimes;
2233+
let no_non_lt_args = generic_args.args.len() == expected_lifetimes;
22342234
let no_bindings = generic_args.bindings.is_empty();
2235-
let (incl_angl_brckt, insertion_span, suggestion) = if no_ty_args && no_bindings {
2235+
let (incl_angl_brckt, insertion_sp, suggestion) = if no_non_lt_args && no_bindings {
22362236
// If there are no (non-implicit) generic args or associated type
22372237
// bindings, our suggestion includes the angle brackets.
22382238
(true, path_span.shrink_to_hi(), format!("<{}>", anon_lt_suggestion))
22392239
} else {
22402240
// Otherwise (sorry, this is kind of gross) we need to infer the
22412241
// place to splice in the `'_, ` from the generics that do exist.
22422242
let first_generic_span = first_generic_span
2243-
.expect("already checked that type args or bindings exist");
2243+
.expect("already checked that non-lifetime args or bindings exist");
22442244
(false, first_generic_span.shrink_to_lo(), format!("{}, ", anon_lt_suggestion))
22452245
};
22462246
match self.anonymous_lifetime_mode {
@@ -2263,7 +2263,7 @@ impl<'a> LoweringContext<'a> {
22632263
expected_lifetimes,
22642264
path_span,
22652265
incl_angl_brckt,
2266-
insertion_span,
2266+
insertion_sp,
22672267
suggestion,
22682268
);
22692269
err.emit();
@@ -2280,7 +2280,7 @@ impl<'a> LoweringContext<'a> {
22802280
expected_lifetimes,
22812281
path_span,
22822282
incl_angl_brckt,
2283-
insertion_span,
2283+
insertion_sp,
22842284
suggestion,
22852285
)
22862286
);
@@ -2305,7 +2305,7 @@ impl<'a> LoweringContext<'a> {
23052305
Some(id),
23062306
Some(self.lower_res(res)),
23072307
generic_args,
2308-
infer_types,
2308+
infer_args,
23092309
)
23102310
}
23112311

@@ -2316,9 +2316,10 @@ impl<'a> LoweringContext<'a> {
23162316
mut itctx: ImplTraitContext<'_>,
23172317
) -> (hir::GenericArgs, bool) {
23182318
let &AngleBracketedArgs { ref args, ref constraints, .. } = data;
2319-
let has_types = args.iter().any(|arg| match arg {
2319+
let has_non_lt_args = args.iter().any(|arg| match arg {
2320+
ast::GenericArg::Lifetime(_) => false,
23202321
ast::GenericArg::Type(_) => true,
2321-
_ => false,
2322+
ast::GenericArg::Const(_) => true,
23222323
});
23232324
(
23242325
hir::GenericArgs {
@@ -2328,7 +2329,7 @@ impl<'a> LoweringContext<'a> {
23282329
.collect(),
23292330
parenthesized: false,
23302331
},
2331-
!has_types && param_mode == ParamMode::Optional
2332+
!has_non_lt_args && param_mode == ParamMode::Optional
23322333
)
23332334
}
23342335

src/librustc/hir/map/definitions.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,17 @@ impl DefPathData {
582582
}
583583
}
584584

585+
/// Evaluates to the number of tokens passed to it.
586+
///
587+
/// Logarithmic counting: every one or two recursive expansions, the number of
588+
/// tokens to count is divided by two, instead of being reduced by one.
589+
/// Therefore, the recursion depth is the binary logarithm of the number of
590+
/// tokens to count, and the expanded tree is likewise very small.
585591
macro_rules! count {
586-
() => (0usize);
587-
( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));
592+
() => (0usize);
593+
($one:tt) => (1usize);
594+
($($pairs:tt $_p:tt)*) => (count!($($pairs)*) << 1usize);
595+
($odd:tt $($rest:tt)*) => (count!($($rest)*) | 1usize);
588596
}
589597

590598
// We define the GlobalMetaDataKind enum with this macro because we want to

src/librustc/hir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ pub struct PathSegment {
348348
/// This only applies to expression and pattern paths, and
349349
/// out of those only the segments with no type parameters
350350
/// to begin with, e.g., `Vec::new` is `<Vec<..>>::new::<..>`.
351-
pub infer_types: bool,
351+
pub infer_args: bool,
352352
}
353353

354354
impl PathSegment {
@@ -358,7 +358,7 @@ impl PathSegment {
358358
ident,
359359
hir_id: None,
360360
res: None,
361-
infer_types: true,
361+
infer_args: true,
362362
args: None,
363363
}
364364
}
@@ -368,13 +368,13 @@ impl PathSegment {
368368
hir_id: Option<HirId>,
369369
res: Option<Res>,
370370
args: GenericArgs,
371-
infer_types: bool,
371+
infer_args: bool,
372372
) -> Self {
373373
PathSegment {
374374
ident,
375375
hir_id,
376376
res,
377-
infer_types,
377+
infer_args,
378378
args: if args.is_empty() {
379379
None
380380
} else {

src/librustc/hir/print.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ impl<'a> State<'a> {
11961196

11971197
segment.with_generic_args(|generic_args| {
11981198
if !generic_args.args.is_empty() || !generic_args.bindings.is_empty() {
1199-
return self.print_generic_args(&generic_args, segment.infer_types, true);
1199+
return self.print_generic_args(&generic_args, segment.infer_args, true);
12001200
}
12011201
Ok(())
12021202
})?;
@@ -1561,7 +1561,7 @@ impl<'a> State<'a> {
15611561
if segment.ident.name != kw::PathRoot {
15621562
self.print_ident(segment.ident)?;
15631563
segment.with_generic_args(|generic_args| {
1564-
self.print_generic_args(generic_args, segment.infer_types,
1564+
self.print_generic_args(generic_args, segment.infer_args,
15651565
colons_before_params)
15661566
})?;
15671567
}
@@ -1574,7 +1574,7 @@ impl<'a> State<'a> {
15741574
if segment.ident.name != kw::PathRoot {
15751575
self.print_ident(segment.ident)?;
15761576
segment.with_generic_args(|generic_args| {
1577-
self.print_generic_args(generic_args, segment.infer_types, false)
1577+
self.print_generic_args(generic_args, segment.infer_args, false)
15781578
})?;
15791579
}
15801580
Ok(())
@@ -1602,7 +1602,7 @@ impl<'a> State<'a> {
16021602
self.print_ident(segment.ident)?;
16031603
segment.with_generic_args(|generic_args| {
16041604
self.print_generic_args(generic_args,
1605-
segment.infer_types,
1605+
segment.infer_args,
16061606
colons_before_params)
16071607
})?;
16081608
}
@@ -1614,7 +1614,7 @@ impl<'a> State<'a> {
16141614
self.print_ident(item_segment.ident)?;
16151615
item_segment.with_generic_args(|generic_args| {
16161616
self.print_generic_args(generic_args,
1617-
item_segment.infer_types,
1617+
item_segment.infer_args,
16181618
colons_before_params)
16191619
})
16201620
}
@@ -1626,7 +1626,7 @@ impl<'a> State<'a> {
16261626
self.print_ident(item_segment.ident)?;
16271627
item_segment.with_generic_args(|generic_args| {
16281628
self.print_generic_args(generic_args,
1629-
item_segment.infer_types,
1629+
item_segment.infer_args,
16301630
colons_before_params)
16311631
})
16321632
}
@@ -1635,7 +1635,7 @@ impl<'a> State<'a> {
16351635

16361636
fn print_generic_args(&mut self,
16371637
generic_args: &hir::GenericArgs,
1638-
infer_types: bool,
1638+
infer_args: bool,
16391639
colons_before_params: bool)
16401640
-> io::Result<()> {
16411641
if generic_args.parenthesized {
@@ -1681,7 +1681,7 @@ impl<'a> State<'a> {
16811681

16821682
// FIXME(eddyb): this would leak into error messages (e.g.,
16831683
// "non-exhaustive patterns: `Some::<..>(_)` not covered").
1684-
if infer_types && false {
1684+
if infer_args && false {
16851685
start_or_comma(self)?;
16861686
self.s.word("..")?;
16871687
}

src/librustc_interface/util.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,13 @@ pub fn create_session(
121121
}
122122

123123
// Temporarily have stack size set to 32MB to deal with various crates with long method
124-
// chains or deep syntax trees.
124+
// chains or deep syntax trees, except when on Haiku.
125125
// FIXME(oli-obk): get https://github.com/rust-lang/rust/pull/55617 the finish line
126-
const STACK_SIZE: usize = 32 * 1024 * 1024; // 32MB
126+
#[cfg(not(target_os = "haiku"))]
127+
const STACK_SIZE: usize = 32 * 1024 * 1024;
128+
129+
#[cfg(target_os = "haiku")]
130+
const STACK_SIZE: usize = 16 * 1024 * 1024;
127131

128132
fn get_stack_size() -> Option<usize> {
129133
// FIXME: Hacks on hacks. If the env is trying to override the stack size

0 commit comments

Comments
 (0)