Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #87615

Merged
merged 25 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3e82dca
Optimize fmt::PadAdapter::wrap
phlopsi Jul 11, 2021
b8eb1f1
Fix assert in diy_float
frogtd Jul 27, 2021
cd6c0e4
Fix typo in rustc_driver::version
bjorn3 Jul 28, 2021
9829efb
Range PatKind implies discr should be read
roxelo Jul 28, 2021
d380ed1
fix nit
roxelo Jul 28, 2021
cf5e48d
min_type_alias_impl_trait is going to be removed in 1.56
spastorino Jul 28, 2021
d4a60ab
Update the examples in `String` and `VecDeque::retain`
cuviper Jul 28, 2021
2f6662d
Use strip_prefix
bjorn3 Jul 29, 2021
8307072
Remove redundant option around compression caches
tmiasko Jul 27, 2021
0ce8001
Flatten compression caches into symbol mangler
tmiasko Jul 29, 2021
0eabbf8
Implement `Printer` for `&mut SymbolMangler`
tmiasko Jul 29, 2021
cf0f502
Add missing links for core::char types
GuillaumeGomez Jul 29, 2021
ce1bd70
fs File get_path procfs usage for netbsd same as linux.
devnexen Jul 29, 2021
3fda708
Add regression test
wesleywiser Jul 28, 2021
286cdc8
[backtraces]: look for the `begin` symbol only after seeing `end`
wesleywiser Jul 29, 2021
c25b979
Rollup merge of #87052 - phlopsi:patch-1, r=jyn514
JohnTitor Jul 30, 2021
fd79e77
Rollup merge of #87522 - frogtd:patch-1, r=yaahc
JohnTitor Jul 30, 2021
7e4b173
Rollup merge of #87553 - bjorn3:fix_hotplug_codegen_version, r=wesley…
JohnTitor Jul 30, 2021
aaef1a1
Rollup merge of #87554 - sexxi-goose:fix-issue-87426, r=nikomatsakis
JohnTitor Jul 30, 2021
55ce7ed
Rollup merge of #87564 - spastorino:adjust-min-tait-removed-version, …
JohnTitor Jul 30, 2021
3bc6c28
Rollup merge of #87574 - cuviper:retain-examples, r=joshtriplett
JohnTitor Jul 30, 2021
1757d6b
Rollup merge of #87583 - tmiasko:compression-cache, r=wesleywiser
JohnTitor Jul 30, 2021
6e61383
Rollup merge of #87585 - GuillaumeGomez:char-types-doc, r=joshtriplett
JohnTitor Jul 30, 2021
0180d4c
Rollup merge of #87594 - devnexen:netbsd_fs_getfiledescriptor_path, r…
JohnTitor Jul 30, 2021
84e1882
Rollup merge of #87602 - wesleywiser:partially_fix_short_backtraces_w…
JohnTitor Jul 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,7 @@ pub fn version(binary: &str, matches: &getopts::Matches) {
println!("release: {}", unw(util::release_str()));

let debug_flags = matches.opt_strs("Z");
let backend_name = debug_flags.iter().find_map(|x| {
if x.starts_with("codegen-backend=") {
Some(&x["codegen-backends=".len()..])
} else {
None
}
});
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
get_codegen_backend(&None, backend_name).print_version();
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ declare_features! (
Some("the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done")),

/// Allows the use of type alias impl trait in function return positions
(removed, min_type_alias_impl_trait, "1.55.0", Some(63063), None,
(removed, min_type_alias_impl_trait, "1.56.0", Some(63063), None,
Some("removed in favor of full type_alias_impl_trait")),

// -------------------------------------------------------------------------
Expand Down
77 changes: 32 additions & 45 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ pub(super) fn mangle(
let substs = tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), instance.substs);

let prefix = "_R";
let mut cx = SymbolMangler {
let mut cx = &mut SymbolMangler {
tcx,
compress: Some(Box::new(CompressionCaches {
start_offset: prefix.len(),

paths: FxHashMap::default(),
types: FxHashMap::default(),
consts: FxHashMap::default(),
})),
start_offset: prefix.len(),
paths: FxHashMap::default(),
types: FxHashMap::default(),
consts: FxHashMap::default(),
binders: vec![],
out: String::from(prefix),
};
Expand All @@ -52,17 +49,7 @@ pub(super) fn mangle(
if let Some(instantiating_crate) = instantiating_crate {
cx = cx.print_def_path(instantiating_crate.as_def_id(), &[]).unwrap();
}
cx.out
}

struct CompressionCaches<'tcx> {
// The length of the prefix in `out` (e.g. 2 for `_R`).
start_offset: usize,

// The values are start positions in `out`, in bytes.
paths: FxHashMap<(DefId, &'tcx [GenericArg<'tcx>]), usize>,
types: FxHashMap<Ty<'tcx>, usize>,
consts: FxHashMap<&'tcx ty::Const<'tcx>, usize>,
std::mem::take(&mut cx.out)
}

struct BinderLevel {
Expand All @@ -81,9 +68,15 @@ struct BinderLevel {

struct SymbolMangler<'tcx> {
tcx: TyCtxt<'tcx>,
compress: Option<Box<CompressionCaches<'tcx>>>,
binders: Vec<BinderLevel>,
out: String,

/// The length of the prefix in `out` (e.g. 2 for `_R`).
start_offset: usize,
/// The values are start positions in `out`, in bytes.
paths: FxHashMap<(DefId, &'tcx [GenericArg<'tcx>]), usize>,
types: FxHashMap<Ty<'tcx>, usize>,
consts: FxHashMap<&'tcx ty::Const<'tcx>, usize>,
}

impl SymbolMangler<'tcx> {
Expand Down Expand Up @@ -160,13 +153,13 @@ impl SymbolMangler<'tcx> {
self.push(ident);
}

fn path_append_ns(
mut self,
print_prefix: impl FnOnce(Self) -> Result<Self, !>,
fn path_append_ns<'a>(
mut self: &'a mut Self,
print_prefix: impl FnOnce(&'a mut Self) -> Result<&'a mut Self, !>,
ns: char,
disambiguator: u64,
name: &str,
) -> Result<Self, !> {
) -> Result<&'a mut Self, !> {
self.push("N");
self.out.push(ns);
self = print_prefix(self)?;
Expand All @@ -175,17 +168,17 @@ impl SymbolMangler<'tcx> {
Ok(self)
}

fn print_backref(mut self, i: usize) -> Result<Self, !> {
fn print_backref(&mut self, i: usize) -> Result<&mut Self, !> {
self.push("B");
self.push_integer_62((i - self.compress.as_ref().unwrap().start_offset) as u64);
self.push_integer_62((i - self.start_offset) as u64);
Ok(self)
}

fn in_binder<T>(
mut self,
fn in_binder<'a, T>(
mut self: &'a mut Self,
value: &ty::Binder<'tcx, T>,
print_value: impl FnOnce(Self, &T) -> Result<Self, !>,
) -> Result<Self, !>
print_value: impl FnOnce(&'a mut Self, &T) -> Result<&'a mut Self, !>,
) -> Result<&'a mut Self, !>
where
T: TypeFoldable<'tcx>,
{
Expand Down Expand Up @@ -218,7 +211,7 @@ impl SymbolMangler<'tcx> {
}
}

impl Printer<'tcx> for SymbolMangler<'tcx> {
impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
type Error = !;

type Path = Self;
Expand All @@ -236,7 +229,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
def_id: DefId,
substs: &'tcx [GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
if let Some(&i) = self.compress.as_ref().and_then(|c| c.paths.get(&(def_id, substs))) {
if let Some(&i) = self.paths.get(&(def_id, substs)) {
return self.print_backref(i);
}
let start = self.out.len();
Expand All @@ -246,9 +239,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
// Only cache paths that do not refer to an enclosing
// binder (which would change depending on context).
if !substs.iter().any(|k| k.has_escaping_bound_vars()) {
if let Some(c) = &mut self.compress {
c.paths.insert((def_id, substs), start);
}
self.paths.insert((def_id, substs), start);
}
Ok(self)
}
Expand Down Expand Up @@ -312,7 +303,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
Ok(self)
}

fn print_region(mut self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
fn print_region(self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
let i = match *region {
// Erased lifetimes use the index 0, for a
// shorter mangling of `L_`.
Expand Down Expand Up @@ -367,7 +358,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
return Ok(self);
}

if let Some(&i) = self.compress.as_ref().and_then(|c| c.types.get(&ty)) {
if let Some(&i) = self.types.get(&ty) {
return self.print_backref(i);
}
let start = self.out.len();
Expand Down Expand Up @@ -476,9 +467,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
// Only cache types that do not refer to an enclosing
// binder (which would change depending on context).
if !ty.has_escaping_bound_vars() {
if let Some(c) = &mut self.compress {
c.types.insert(ty, start);
}
self.types.insert(ty, start);
}
Ok(self)
}
Expand Down Expand Up @@ -545,7 +534,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
}

fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
if let Some(&i) = self.compress.as_ref().and_then(|c| c.consts.get(&ct)) {
if let Some(&i) = self.consts.get(&ct) {
return self.print_backref(i);
}
let start = self.out.len();
Expand Down Expand Up @@ -583,14 +572,12 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
// Only cache consts that do not refer to an enclosing
// binder (which would change depending on context).
if !ct.has_escaping_bound_vars() {
if let Some(c) = &mut self.compress {
c.consts.insert(ct, start);
}
self.consts.insert(ct, start);
}
Ok(self)
}

fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
self.push("C");
let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
self.push_disambiguator(stable_crate_id.to_u64());
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,21 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
}
}
}
PatKind::Lit(_) => {
// If the PatKind is a Lit then we want
PatKind::Lit(_) | PatKind::Range(..) => {
// If the PatKind is a Lit or a Range then we want
// to borrow discr.
needs_to_be_read = true;
}
_ => {}
PatKind::Or(_)
| PatKind::Box(_)
| PatKind::Slice(..)
| PatKind::Ref(..)
| PatKind::Wild => {
// If the PatKind is Or, Box, Slice or Ref, the decision is made later
// as these patterns contains subpatterns
// If the PatKind is Wild, the decision is made based on the other patterns being
// examined
}
}
}));
}
Expand Down
7 changes: 4 additions & 3 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// assert_eq!(buf, [2, 4]);
/// ```
///
/// The exact order may be useful for tracking external state, like an index.
/// Because the elements are visited exactly once in the original order,
/// external state may be used to decide which elements to keep.
///
/// ```
/// use std::collections::VecDeque;
Expand All @@ -2116,8 +2117,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// buf.extend(1..6);
///
/// let keep = [false, true, true, false, true];
/// let mut i = 0;
/// buf.retain(|_| (keep[i], i += 1).0);
/// let mut iter = keep.iter();
/// buf.retain(|_| *iter.next().unwrap());
/// assert_eq!(buf, [2, 3, 5]);
/// ```
#[stable(feature = "vec_deque_retain", since = "1.4.0")]
Expand Down
7 changes: 4 additions & 3 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,13 +1350,14 @@ impl String {
/// assert_eq!(s, "foobar");
/// ```
///
/// The exact order may be useful for tracking external state, like an index.
/// Because the elements are visited exactly once in the original order,
/// external state may be used to decide which elements to keep.
///
/// ```
/// let mut s = String::from("abcde");
/// let keep = [false, true, true, false, true];
/// let mut i = 0;
/// s.retain(|_| (keep[i], i += 1).0);
/// let mut iter = keep.iter();
/// s.retain(|_| *iter.next().unwrap());
/// assert_eq!(s, "bce");
/// ```
#[inline]
Expand Down
7 changes: 7 additions & 0 deletions library/core/src/char/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use crate::fmt;
use super::from_u32_unchecked;

/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.
///
/// This `struct` is created by the [`decode_utf16`] method on [`char`]. See its
/// documentation for more.
///
/// [`decode_utf16`]: char::decode_utf16
#[stable(feature = "decode_utf16", since = "1.9.0")]
#[derive(Clone, Debug)]
pub struct DecodeUtf16<I>
Expand All @@ -16,6 +21,8 @@ where
}

/// An error that can be returned when decoding UTF-16 code points.
///
/// This `struct` is created when using the [`DecodeUtf16`] type.
#[stable(feature = "decode_utf16", since = "1.9.0")]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct DecodeUtf16Error {
Expand Down
5 changes: 1 addition & 4 deletions library/core/src/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ impl<'buf, 'state> PadAdapter<'buf, 'state> {
slot: &'slot mut Option<Self>,
state: &'state mut PadAdapterState,
) -> fmt::Formatter<'slot> {
fmt.wrap_buf(move |buf| {
*slot = Some(PadAdapter { buf, state });
slot.as_mut().unwrap()
})
fmt.wrap_buf(move |buf| slot.insert(PadAdapter { buf, state }))
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/num/diy_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Fp {
f <<= 1;
e -= 1;
}
debug_assert!(f >= (1 >> 63));
debug_assert!(f >= (1 << 63));
Fp { f, e }
}

Expand Down
9 changes: 7 additions & 2 deletions library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ impl FromInner<c_int> for File {

impl fmt::Debug for File {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
fn get_path(fd: c_int) -> Option<PathBuf> {
let mut p = PathBuf::from("/proc/self/fd");
p.push(&fd.to_string());
Expand Down Expand Up @@ -976,7 +976,12 @@ impl fmt::Debug for File {
Some(PathBuf::from(OsString::from_vec(buf)))
}

#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))]
#[cfg(not(any(
target_os = "linux",
target_os = "macos",
target_os = "vxworks",
target_os = "netbsd"
)))]
fn get_path(_fd: c_int) -> Option<PathBuf> {
// FIXME(#24570): implement this for other Unix platforms
None
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys_common/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
hit = true;
if print_fmt == PrintFmt::Short {
if let Some(sym) = symbol.name().and_then(|s| s.as_str()) {
if sym.contains("__rust_begin_short_backtrace") {
if start && sym.contains("__rust_begin_short_backtrace") {
stop = true;
return;
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/closures/2229_closure_analysis/issue-87426.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run-pass
// edition:2021

pub fn foo() {
let ref_x_ck = 123;
let _y = || match ref_x_ck {
2_000_000..=3_999_999 => { println!("A")}
_ => { println!("B")}
};
}

fn main() {
foo();
}
Loading