Skip to content

Commit

Permalink
Auto merge of #61716 - Centril:rollup-nxwf5ol, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 10, 2019
2 parents 1cbd8a4 + f90d348 commit a73ecb3
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 126 deletions.
43 changes: 16 additions & 27 deletions src/libcore/intrinsics.rs
Expand Up @@ -1326,30 +1326,10 @@ extern "rust-intrinsic" {
pub fn nontemporal_store<T>(ptr: *mut T, val: T);
}

mod real_intrinsics {
extern "rust-intrinsic" {
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
/// and destination must *not* overlap.
/// For the full docs, see the stabilized wrapper [`copy_nonoverlapping`].
///
/// [`copy_nonoverlapping`]: ../../std/ptr/fn.copy_nonoverlapping.html
pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);

/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
/// and destination may overlap.
/// For the full docs, see the stabilized wrapper [`copy`].
///
/// [`copy`]: ../../std/ptr/fn.copy.html
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);

/// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
/// `val`.
/// For the full docs, see the stabilized wrapper [`write_bytes`].
///
/// [`write_bytes`]: ../../std/ptr/fn.write_bytes.html
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
}
}
// Some functions are defined here because they accidentally got made
// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
// (`transmute` also falls into this category, but it cannot be wrapped due to the
// check that `T` and `U` have the same size.)

/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
/// and destination must *not* overlap.
Expand Down Expand Up @@ -1437,7 +1417,10 @@ mod real_intrinsics {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
real_intrinsics::copy_nonoverlapping(src, dst, count);
extern "rust-intrinsic" {
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
}
copy_nonoverlapping(src, dst, count);
}

/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
Expand Down Expand Up @@ -1494,7 +1477,10 @@ pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
real_intrinsics::copy(src, dst, count)
extern "rust-intrinsic" {
fn copy<T>(src: *const T, dst: *mut T, count: usize);
}
copy(src, dst, count)
}

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

// Simple bootstrap implementations of minnum/maxnum for stage0 compilation.
Expand Down
21 changes: 11 additions & 10 deletions src/librustc/hir/lowering.rs
Expand Up @@ -2168,7 +2168,7 @@ impl<'a> LoweringContext<'a> {
itctx: ImplTraitContext<'_>,
explicit_owner: Option<NodeId>,
) -> hir::PathSegment {
let (mut generic_args, infer_types) = if let Some(ref generic_args) = segment.args {
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
let msg = "parenthesized type parameters may only be used with a `Fn` trait";
match **generic_args {
GenericArgs::AngleBracketed(ref data) => {
Expand Down Expand Up @@ -2230,17 +2230,17 @@ impl<'a> LoweringContext<'a> {
.collect();
if expected_lifetimes > 0 && param_mode == ParamMode::Explicit {
let anon_lt_suggestion = vec!["'_"; expected_lifetimes].join(", ");
let no_ty_args = generic_args.args.len() == expected_lifetimes;
let no_non_lt_args = generic_args.args.len() == expected_lifetimes;
let no_bindings = generic_args.bindings.is_empty();
let (incl_angl_brckt, insertion_span, suggestion) = if no_ty_args && no_bindings {
let (incl_angl_brckt, insertion_sp, suggestion) = if no_non_lt_args && no_bindings {
// If there are no (non-implicit) generic args or associated type
// bindings, our suggestion includes the angle brackets.
(true, path_span.shrink_to_hi(), format!("<{}>", anon_lt_suggestion))
} else {
// Otherwise (sorry, this is kind of gross) we need to infer the
// place to splice in the `'_, ` from the generics that do exist.
let first_generic_span = first_generic_span
.expect("already checked that type args or bindings exist");
.expect("already checked that non-lifetime args or bindings exist");
(false, first_generic_span.shrink_to_lo(), format!("{}, ", anon_lt_suggestion))
};
match self.anonymous_lifetime_mode {
Expand All @@ -2263,7 +2263,7 @@ impl<'a> LoweringContext<'a> {
expected_lifetimes,
path_span,
incl_angl_brckt,
insertion_span,
insertion_sp,
suggestion,
);
err.emit();
Expand All @@ -2280,7 +2280,7 @@ impl<'a> LoweringContext<'a> {
expected_lifetimes,
path_span,
incl_angl_brckt,
insertion_span,
insertion_sp,
suggestion,
)
);
Expand All @@ -2305,7 +2305,7 @@ impl<'a> LoweringContext<'a> {
Some(id),
Some(self.lower_res(res)),
generic_args,
infer_types,
infer_args,
)
}

Expand All @@ -2316,9 +2316,10 @@ impl<'a> LoweringContext<'a> {
mut itctx: ImplTraitContext<'_>,
) -> (hir::GenericArgs, bool) {
let &AngleBracketedArgs { ref args, ref constraints, .. } = data;
let has_types = args.iter().any(|arg| match arg {
let has_non_lt_args = args.iter().any(|arg| match arg {
ast::GenericArg::Lifetime(_) => false,
ast::GenericArg::Type(_) => true,
_ => false,
ast::GenericArg::Const(_) => true,
});
(
hir::GenericArgs {
Expand All @@ -2328,7 +2329,7 @@ impl<'a> LoweringContext<'a> {
.collect(),
parenthesized: false,
},
!has_types && param_mode == ParamMode::Optional
!has_non_lt_args && param_mode == ParamMode::Optional
)
}

Expand Down
12 changes: 10 additions & 2 deletions src/librustc/hir/map/definitions.rs
Expand Up @@ -582,9 +582,17 @@ impl DefPathData {
}
}

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

// We define the GlobalMetaDataKind enum with this macro because we want to
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/mod.rs
Expand Up @@ -348,7 +348,7 @@ pub struct PathSegment {
/// This only applies to expression and pattern paths, and
/// out of those only the segments with no type parameters
/// to begin with, e.g., `Vec::new` is `<Vec<..>>::new::<..>`.
pub infer_types: bool,
pub infer_args: bool,
}

impl PathSegment {
Expand All @@ -358,7 +358,7 @@ impl PathSegment {
ident,
hir_id: None,
res: None,
infer_types: true,
infer_args: true,
args: None,
}
}
Expand All @@ -368,13 +368,13 @@ impl PathSegment {
hir_id: Option<HirId>,
res: Option<Res>,
args: GenericArgs,
infer_types: bool,
infer_args: bool,
) -> Self {
PathSegment {
ident,
hir_id,
res,
infer_types,
infer_args,
args: if args.is_empty() {
None
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/print.rs
Expand Up @@ -1196,7 +1196,7 @@ impl<'a> State<'a> {

segment.with_generic_args(|generic_args| {
if !generic_args.args.is_empty() || !generic_args.bindings.is_empty() {
return self.print_generic_args(&generic_args, segment.infer_types, true);
return self.print_generic_args(&generic_args, segment.infer_args, true);
}
Ok(())
})?;
Expand Down Expand Up @@ -1561,7 +1561,7 @@ impl<'a> State<'a> {
if segment.ident.name != kw::PathRoot {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args, segment.infer_types,
self.print_generic_args(generic_args, segment.infer_args,
colons_before_params)
})?;
}
Expand All @@ -1574,7 +1574,7 @@ impl<'a> State<'a> {
if segment.ident.name != kw::PathRoot {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args, segment.infer_types, false)
self.print_generic_args(generic_args, segment.infer_args, false)
})?;
}
Ok(())
Expand Down Expand Up @@ -1602,7 +1602,7 @@ impl<'a> State<'a> {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args,
segment.infer_types,
segment.infer_args,
colons_before_params)
})?;
}
Expand All @@ -1614,7 +1614,7 @@ impl<'a> State<'a> {
self.print_ident(item_segment.ident)?;
item_segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args,
item_segment.infer_types,
item_segment.infer_args,
colons_before_params)
})
}
Expand All @@ -1626,7 +1626,7 @@ impl<'a> State<'a> {
self.print_ident(item_segment.ident)?;
item_segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args,
item_segment.infer_types,
item_segment.infer_args,
colons_before_params)
})
}
Expand All @@ -1635,7 +1635,7 @@ impl<'a> State<'a> {

fn print_generic_args(&mut self,
generic_args: &hir::GenericArgs,
infer_types: bool,
infer_args: bool,
colons_before_params: bool)
-> io::Result<()> {
if generic_args.parenthesized {
Expand Down Expand Up @@ -1681,7 +1681,7 @@ impl<'a> State<'a> {

// FIXME(eddyb): this would leak into error messages (e.g.,
// "non-exhaustive patterns: `Some::<..>(_)` not covered").
if infer_types && false {
if infer_args && false {
start_or_comma(self)?;
self.s.word("..")?;
}
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_interface/util.rs
Expand Up @@ -121,9 +121,13 @@ pub fn create_session(
}

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

#[cfg(target_os = "haiku")]
const STACK_SIZE: usize = 16 * 1024 * 1024;

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

0 comments on commit a73ecb3

Please sign in to comment.