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 #82790

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f45bdcc
Implement size_hint for BufReader
Xavientois Jan 15, 2021
c3e47d9
Fix implementation to specialize
Xavientois Jan 15, 2021
fa76db3
Use helper trait to follow min_specialization rules
Xavientois Jan 15, 2021
11c49f6
Add missing generic
Xavientois Jan 15, 2021
260a270
Move default to trait definition
Xavientois Jan 15, 2021
5f60a30
Fix incorrect token
Xavientois Jan 15, 2021
eea99f4
Add default keyword for specialization
Xavientois Jan 15, 2021
7e56637
Add back lower_bound as memeber
Xavientois Jan 16, 2021
442de9a
Fix semicolon
Xavientois Jan 16, 2021
1190321
Remove exposing private trait
Xavientois Jan 16, 2021
421b40c
Add dyn for SizeHint cast
Xavientois Jan 16, 2021
265db94
Fix formatting
Xavientois Jan 16, 2021
93870c8
Remove stable annotation
Xavientois Jan 16, 2021
7869371
Remove unnecessary default keyword
Xavientois Jan 16, 2021
c8e0f8a
Use fully qualified syntax to avoid dyn
Xavientois Jan 16, 2021
96255f8
Implement SizeHint trait for BufReader, Emtpy, and Chain
Xavientois Jan 16, 2021
389e638
Add tests for SizeHint implementations
Xavientois Jan 16, 2021
b837f3a
Remove trailing newline
Xavientois Jan 16, 2021
81aba38
Add space for proper indentation
Xavientois Jan 16, 2021
fc9cd4a
Fix formatting on mod
Xavientois Jan 16, 2021
7674ae1
Fix line length format
Xavientois Jan 31, 2021
7b021aa
resolve: Reduce scope of `pub_use_of_private_extern_crate` deprecatio…
petrochenkov Jan 28, 2021
6e52b23
Fix jemalloc usage on OSX
sfackler Feb 28, 2021
0ae7250
Add a regression test for issue-81712
JohnTitor Mar 4, 2021
0559e50
Remove a dead code path
oli-obk Mar 4, 2021
09cbcdc
Add BTreeMap::try_insert and btree_map::OccupiedError.
m-ou-se Mar 4, 2021
f6fe24a
Add HashMap::try_insert and hash_map::OccupiedError.
m-ou-se Mar 4, 2021
69d95e2
Improve Debug implementations of OccupiedError.
m-ou-se Mar 4, 2021
d85d82a
Implement Error for OccupiedError.
m-ou-se Mar 4, 2021
da01455
Ignore file length tidy warning in hash/map.rs.
m-ou-se Mar 4, 2021
63af264
Spread tracing instrumentation into the polymorphization logic
oli-obk Mar 4, 2021
67a61b9
Typo
oli-obk Mar 4, 2021
29f4aa7
Fixes -Zpolymorphize for src/test/ui/const-generics/auxiliary/crayte.rs
oli-obk Mar 4, 2021
1aedb4c
Remove unnecessary bound from HashMap::try_insert.
m-ou-se Mar 4, 2021
eddd4f0
Add tracking issue for map_try_insert.
m-ou-se Mar 4, 2021
eb18746
Add assert_matches!(expr, pat).
m-ou-se Mar 4, 2021
cfce60e
Allow for multiple patterns and a guard in assert_matches.
m-ou-se Mar 4, 2021
0a8e401
Add debug_assert_matches macro.
m-ou-se Mar 4, 2021
5bd1204
Fix assert_matches doc examples.
m-ou-se Mar 4, 2021
48167c4
Moved Context and its impls to a separate file
Nicholas-Baron Feb 14, 2021
6c7d7a6
Moved `print_item` and helpers to a separate file
Nicholas-Baron Feb 14, 2021
14983b9
Moved the `make_item_keywords` function to `context.rs` as it is only…
Nicholas-Baron Feb 14, 2021
fd14e38
Moved `write_shared` to its own file
Nicholas-Baron Feb 14, 2021
afb8220
Corrected imports for render tests and mod files
Nicholas-Baron Feb 14, 2021
f223aff
Don't consume the expression in assert_matches!()'s failure case.
m-ou-se Mar 4, 2021
dbdaa12
Update rustdoc documentation
jyn514 Mar 2, 2021
4b30625
Don't warn for `missing_doc_examples` when item is #[doc(hidden)]
GuillaumeGomez Feb 13, 2021
91095b1
Update missing code example test
GuillaumeGomez Feb 13, 2021
186f139
Move visibility check inside the should_have_doc_example function
GuillaumeGomez Feb 15, 2021
ad30c39
Pass TyCtxt directly instead of DocContext in librustdoc::visit_ast::…
GuillaumeGomez Feb 23, 2021
e428799
No more need for borrow call
GuillaumeGomez Feb 23, 2021
1683cb1
Use cache access levels
GuillaumeGomez Mar 2, 2021
80fcdef
Add tracking issue for assert_matches.
m-ou-se Mar 4, 2021
3f41802
Rollup merge of #76716 - GuillaumeGomez:stop-complains-on-doc-hidden,…
JohnTitor Mar 5, 2021
e65024d
Rollup merge of #80763 - petrochenkov:pubusecrate, r=estebank
JohnTitor Mar 5, 2021
0863a46
Rollup merge of #81136 - Xavientois:io_reader_size_hint, r=cramertj
JohnTitor Mar 5, 2021
8c786c8
Rollup merge of #82088 - Nicholas-Baron:shorten_html_render, r=Guilla…
JohnTitor Mar 5, 2021
a482925
Rollup merge of #82642 - sfackler:jemalloc-zone, r=pnkfelix
JohnTitor Mar 5, 2021
65943f7
Rollup merge of #82690 - jyn514:remove-pass-docs, r=Manishearth
JohnTitor Mar 5, 2021
8aed2a0
Rollup merge of #82752 - JohnTitor:gat-ice-test, r=jackh726
JohnTitor Mar 5, 2021
dcf63d4
Rollup merge of #82764 - m-ou-se:map-try-insert, r=Amanieu
JohnTitor Mar 5, 2021
22de90c
Rollup merge of #82765 - oli-obk:polymorphization_regression, r=david…
JohnTitor Mar 5, 2021
a910b04
Rollup merge of #82770 - m-ou-se:assert-match, r=joshtriplett
JohnTitor Mar 5, 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
14 changes: 14 additions & 0 deletions compiler/rustc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ fn main() {
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
#[used]
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;

// On OSX, jemalloc doesn't directly override malloc/free, but instead
// registers itself with the allocator's zone APIs in a ctor. However,
// the linker doesn't seem to consider ctors as "used" when statically
// linking, so we need to explicitly depend on the function.
#[cfg(target_os = "macos")]
{
extern "C" {
fn _rjem_je_zone_register();
}

#[used]
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register();
}
}

rustc_driver::set_sigpipe_handler();
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_middle/src/mir/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,6 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

#[inline]
pub fn optimized_mir_or_const_arg_mir(
self,
def: ty::WithOptConstParam<DefId>,
) -> &'tcx Body<'tcx> {
if let Some((did, param_did)) = def.as_const_arg() {
self.mir_for_ctfe_of_const_arg((did, param_did))
} else {
self.optimized_mir(def.did)
}
}

#[inline]
pub fn mir_for_ctfe_opt_const_arg(self, def: ty::WithOptConstParam<DefId>) -> &'tcx Body<'tcx> {
if let Some((did, param_did)) = def.as_const_arg() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ impl<'tcx> Instance<'tcx> {
}

/// Returns a new `Instance` where generic parameters in `instance.substs` are replaced by
/// identify parameters if they are determined to be unused in `instance.def`.
/// identity parameters if they are determined to be unused in `instance.def`.
pub fn polymorphize(self, tcx: TyCtxt<'tcx>) -> Self {
debug!("polymorphize: running polymorphization analysis");
if !tcx.sess.opts.debugging_opts.polymorphize {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,10 @@ impl<'tcx> TyCtxt<'tcx> {
| DefKind::AnonConst => self.mir_for_ctfe_opt_const_arg(def),
// If the caller wants `mir_for_ctfe` of a function they should not be using
// `instance_mir`, so we'll assume const fn also wants the optimized version.
_ => self.optimized_mir_or_const_arg_mir(def),
_ => {
assert_eq!(def.const_param_did, None);
self.optimized_mir(def.did)
}
},
ty::InstanceDef::VtableShim(..)
| ty::InstanceDef::ReifyShim(..)
Expand Down
104 changes: 64 additions & 40 deletions compiler/rustc_mir/src/monomorphize/polymorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ pub fn provide(providers: &mut Providers) {
/// Determine which generic parameters are used by the function/method/closure represented by
/// `def_id`. Returns a bitset where bits representing unused parameters are set (`is_empty`
/// indicates all parameters are used).
#[instrument(skip(tcx))]
fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
debug!("unused_generic_params({:?})", def_id);

if !tcx.sess.opts.debugging_opts.polymorphize {
// If polymorphization disabled, then all parameters are used.
return FiniteBitSet::new_empty();
Expand All @@ -46,7 +45,7 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
}

let generics = tcx.generics_of(def_id);
debug!("unused_generic_params: generics={:?}", generics);
debug!(?generics);

// Exit early when there are no parameters to be unused.
if generics.count() == 0 {
Expand All @@ -57,11 +56,11 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
let context = tcx.hir().body_const_context(def_id.expect_local());
match context {
Some(ConstContext::ConstFn) | None if !tcx.is_mir_available(def_id) => {
debug!("unused_generic_params: (no mir available) def_id={:?}", def_id);
debug!("no mir available");
return FiniteBitSet::new_empty();
}
Some(_) if !tcx.is_ctfe_mir_available(def_id) => {
debug!("unused_generic_params: (no ctfe mir available) def_id={:?}", def_id);
debug!("no ctfe mir available");
return FiniteBitSet::new_empty();
}
_ => {}
Expand All @@ -72,9 +71,9 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
generics.count().try_into().expect("more generic parameters than can fit into a `u32`");
let mut unused_parameters = FiniteBitSet::<u32>::new_empty();
unused_parameters.set_range(0..generics_count);
debug!("unused_generic_params: (start) unused_parameters={:?}", unused_parameters);
debug!(?unused_parameters, "(start)");
mark_used_by_default_parameters(tcx, def_id, generics, &mut unused_parameters);
debug!("unused_generic_params: (after default) unused_parameters={:?}", unused_parameters);
debug!(?unused_parameters, "(after default)");

// Visit MIR and accumululate used generic parameters.
let body = match context {
Expand All @@ -85,10 +84,10 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
};
let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters: &mut unused_parameters };
vis.visit_body(body);
debug!("unused_generic_params: (after visitor) unused_parameters={:?}", unused_parameters);
debug!(?unused_parameters, "(after visitor)");

mark_used_by_predicates(tcx, def_id, &mut unused_parameters);
debug!("unused_generic_params: (end) unused_parameters={:?}", unused_parameters);
debug!(?unused_parameters, "(end)");

// Emit errors for debugging and testing if enabled.
if !unused_parameters.is_empty() {
Expand All @@ -101,24 +100,55 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
/// Some parameters are considered used-by-default, such as non-generic parameters and the dummy
/// generic parameters from closures, this function marks them as used. `leaf_is_closure` should
/// be `true` if the item that `unused_generic_params` was invoked on is a closure.
#[instrument(skip(tcx, def_id, generics, unused_parameters))]
fn mark_used_by_default_parameters<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
generics: &'tcx ty::Generics,
unused_parameters: &mut FiniteBitSet<u32>,
) {
if !tcx.is_trait(def_id) && (tcx.is_closure(def_id) || tcx.type_of(def_id).is_generator()) {
for param in &generics.params {
debug!("mark_used_by_default_parameters: (closure/gen) param={:?}", param);
unused_parameters.clear(param.index);
}
} else {
for param in &generics.params {
debug!("mark_used_by_default_parameters: (other) param={:?}", param);
if let ty::GenericParamDefKind::Lifetime = param.kind {
match tcx.def_kind(def_id) {
DefKind::Closure | DefKind::Generator => {
for param in &generics.params {
debug!(?param, "(closure/gen)");
unused_parameters.clear(param.index);
}
}
DefKind::Mod
| DefKind::Struct
| DefKind::Union
| DefKind::Enum
| DefKind::Variant
| DefKind::Trait
| DefKind::TyAlias
| DefKind::ForeignTy
| DefKind::TraitAlias
| DefKind::AssocTy
| DefKind::TyParam
| DefKind::Fn
| DefKind::Const
| DefKind::ConstParam
| DefKind::Static
| DefKind::Ctor(_, _)
| DefKind::AssocFn
| DefKind::AssocConst
| DefKind::Macro(_)
| DefKind::ExternCrate
| DefKind::Use
| DefKind::ForeignMod
| DefKind::AnonConst
| DefKind::OpaqueTy
| DefKind::Field
| DefKind::LifetimeParam
| DefKind::GlobalAsm
| DefKind::Impl => {
for param in &generics.params {
debug!(?param, "(other)");
if let ty::GenericParamDefKind::Lifetime = param.kind {
unused_parameters.clear(param.index);
}
}
}
}

if let Some(parent) = generics.parent {
Expand All @@ -128,23 +158,20 @@ fn mark_used_by_default_parameters<'tcx>(

/// Search the predicates on used generic parameters for any unused generic parameters, and mark
/// those as used.
#[instrument(skip(tcx, def_id))]
fn mark_used_by_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
unused_parameters: &mut FiniteBitSet<u32>,
) {
let def_id = tcx.closure_base_def_id(def_id);
let predicates = tcx.explicit_predicates_of(def_id);
debug!("mark_used_by_predicates: predicates_of={:?}", predicates);

let mut current_unused_parameters = FiniteBitSet::new_empty();
// Run to a fixed point to support `where T: Trait<U>, U: Trait<V>`, starting with an empty
// bit set so that this is skipped if all parameters are already used.
while current_unused_parameters != *unused_parameters {
debug!(
"mark_used_by_predicates: current_unused_parameters={:?} = unused_parameters={:?}",
current_unused_parameters, unused_parameters
);
debug!(?current_unused_parameters, ?unused_parameters);
current_unused_parameters = *unused_parameters;

for (predicate, _) in predicates.predicates {
Expand All @@ -169,13 +196,13 @@ fn mark_used_by_predicates<'tcx>(

/// Emit errors for the function annotated by `#[rustc_polymorphize_error]`, labelling each generic
/// parameter which was unused.
#[instrument(skip(tcx, generics))]
fn emit_unused_generic_params_error<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
generics: &'tcx ty::Generics,
unused_parameters: &FiniteBitSet<u32>,
) {
debug!("emit_unused_generic_params_error: def_id={:?}", def_id);
let base_def_id = tcx.closure_base_def_id(def_id);
if !tcx
.get_attrs(base_def_id)
Expand All @@ -185,7 +212,6 @@ fn emit_unused_generic_params_error<'tcx>(
return;
}

debug!("emit_unused_generic_params_error: unused_parameters={:?}", unused_parameters);
let fn_span = match tcx.opt_item_name(def_id) {
Some(ident) => ident.span,
_ => tcx.def_span(def_id),
Expand All @@ -197,7 +223,7 @@ fn emit_unused_generic_params_error<'tcx>(
while let Some(generics) = next_generics {
for param in &generics.params {
if unused_parameters.contains(param.index).unwrap_or(false) {
debug!("emit_unused_generic_params_error: param={:?}", param);
debug!(?param);
let def_span = tcx.def_span(param.def_id);
err.span_label(def_span, &format!("generic parameter `{}` is unused", param.name));
}
Expand All @@ -219,33 +245,31 @@ struct MarkUsedGenericParams<'a, 'tcx> {
impl<'a, 'tcx> MarkUsedGenericParams<'a, 'tcx> {
/// Invoke `unused_generic_params` on a body contained within the current item (e.g.
/// a closure, generator or constant).
#[instrument(skip(self, def_id, substs))]
fn visit_child_body(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) {
let unused = self.tcx.unused_generic_params(def_id);
debug!(
"visit_child_body: unused_parameters={:?} unused={:?}",
self.unused_parameters, unused
);
debug!(?self.unused_parameters, ?unused);
for (i, arg) in substs.iter().enumerate() {
let i = i.try_into().unwrap();
if !unused.contains(i).unwrap_or(false) {
arg.visit_with(self);
}
}
debug!("visit_child_body: unused_parameters={:?}", self.unused_parameters);
debug!(?self.unused_parameters);
}
}

impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
#[instrument(skip(self, local))]
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
debug!("visit_local_decl: local_decl={:?}", local_decl);
if local == Local::from_usize(1) {
let def_kind = self.tcx.def_kind(self.def_id);
if matches!(def_kind, DefKind::Closure | DefKind::Generator) {
// Skip visiting the closure/generator that is currently being processed. This only
// happens because the first argument to the closure is a reference to itself and
// that will call `visit_substs`, resulting in each generic parameter captured being
// considered used by default.
debug!("visit_local_decl: skipping closure substs");
debug!("skipping closure substs");
return;
}
}
Expand All @@ -263,15 +287,15 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
}

impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
#[instrument(skip(self))]
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
debug!("visit_const: c={:?}", c);
if !c.has_param_types_or_consts() {
return ControlFlow::CONTINUE;
}

match c.val {
ty::ConstKind::Param(param) => {
debug!("visit_const: param={:?}", param);
debug!(?param);
self.unused_parameters.clear(param.index);
ControlFlow::CONTINUE
}
Expand All @@ -296,15 +320,15 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
}
}

#[instrument(skip(self))]
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
debug!("visit_ty: ty={:?}", ty);
if !ty.has_param_types_or_consts() {
return ControlFlow::CONTINUE;
}

match *ty.kind() {
ty::Closure(def_id, substs) | ty::Generator(def_id, substs, ..) => {
debug!("visit_ty: def_id={:?}", def_id);
debug!(?def_id);
// Avoid cycle errors with generators.
if def_id == self.def_id {
return ControlFlow::CONTINUE;
Expand All @@ -316,7 +340,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
ControlFlow::CONTINUE
}
ty::Param(param) => {
debug!("visit_ty: param={:?}", param);
debug!(?param);
self.unused_parameters.clear(param.index);
ControlFlow::CONTINUE
}
Expand All @@ -333,8 +357,8 @@ struct HasUsedGenericParams<'a> {
impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
type BreakTy = ();

#[instrument(skip(self))]
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
debug!("visit_const: c={:?}", c);
if !c.has_param_types_or_consts() {
return ControlFlow::CONTINUE;
}
Expand All @@ -351,8 +375,8 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
}
}

#[instrument(skip(self))]
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
debug!("visit_ty: ty={:?}", ty);
if !ty.has_param_types_or_consts() {
return ControlFlow::CONTINUE;
}
Expand Down
Loading