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 13 pull requests #85949

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3efe017
shrinking the deprecated method span
Rustin170506 May 24, 2021
c180af8
Address comment
Rustin170506 May 24, 2021
027d73d
Restrict Fake Read precision
roxelo May 25, 2021
382338f
Remove feature gate
roxelo May 27, 2021
7fed92b
rustc: Allow safe #[target_feature] on wasm
alexcrichton May 6, 2021
dbff14b
Clarify meaning of MachineApplicable suggestions.
m-ou-se May 31, 2021
a0228d9
Intra doc link-ify a reference to a function
est31 Jun 1, 2021
9283956
skip check_static on rvalue::threadlocalref
csmoe Jun 1, 2021
ba680aa
Add test for forward declared const param defaults
BoxyUwU Jun 1, 2021
f4f76e6
Reland - Report coverage `0` of dead blocks
richkadel May 1, 2021
521d9ab
convert Rvalue::threadlocalref assertion to delay bug
csmoe Jun 1, 2021
3844570
Restore the num_def_ids_untracked public function giving the total nu…
denismerigoux Jun 1, 2021
f353cbf
Generate better debuginfo for directly tagged enums
wesleywiser Apr 26, 2021
b644f06
Resolve EnumTagInfo FIXME
wesleywiser Apr 27, 2021
2a025c1
Remove fallback for containing scopes
wesleywiser Apr 28, 2021
141546c
Generate better debuginfo for niche-layout enums
wesleywiser May 13, 2021
2a9fa20
Add/update tests
wesleywiser May 13, 2021
d650091
Make tidy happy
wesleywiser May 14, 2021
d2d6fa8
Respond to review feedback
wesleywiser May 17, 2021
ef053fd
Change the type name from `_enum<..>` to `enum$<..>`
wesleywiser May 20, 2021
3127419
Respond to review feedback
wesleywiser May 26, 2021
012c323
Implement `Ty::is_enum` using `matches!`
tmiasko Jun 2, 2021
c898681
Add `Ty::is_union` predicate and use it
tmiasko Jun 2, 2021
957e2ef
Address comment
Rustin170506 Jun 2, 2021
11478bd
Validate type of locals used as indices
tmiasko Jun 2, 2021
f7c283c
Stabilize `vecdeque_binary_search`
SOF3 Mar 22, 2021
f51f277
Bumped `vecdeque_binary_search` stabilization version to 1.53.0
SOF3 Mar 22, 2021
f086f1e
Bump vecdeque_binary_search stabilization to 1.54.
m-ou-se Jun 2, 2021
f717992
Stabilize VecDeque::partition_point.
m-ou-se Jun 2, 2021
94c45ef
Update generator tests
wesleywiser Jun 2, 2021
11acbff
Rollup merge of #83362 - SOF3:stab/vecdeque-binary-search, r=m-ou-se
Dylan-DPC Jun 3, 2021
66eaa42
Rollup merge of #84988 - alexcrichton:safe-target-feature-wasm, r=jos…
Dylan-DPC Jun 3, 2021
f818167
Rollup merge of #85292 - wesleywiser:enum_debuginfo, r=michaelwoerister
Dylan-DPC Jun 3, 2021
f946bc5
Rollup merge of #85385 - richkadel:simpler-simplify-with-coverage, r=…
Dylan-DPC Jun 3, 2021
ab0b248
Rollup merge of #85617 - hi-rustin:rustin-patch-fix, r=estebank
Dylan-DPC Jun 3, 2021
0a02bf8
Rollup merge of #85724 - sexxi-goose:rox-fix-issue-85435, r=nikomatsakis
Dylan-DPC Jun 3, 2021
61e0d9a
Rollup merge of #85852 - m-ou-se:machineapplicable-docs, r=nikomatsakis
Dylan-DPC Jun 3, 2021
9f9ce89
Rollup merge of #85877 - est31:intra_doc_links, r=jyn514
Dylan-DPC Jun 3, 2021
6c03416
Rollup merge of #85880 - csmoe:ice-85768, r=oli-obk
Dylan-DPC Jun 3, 2021
6ce6c43
Rollup merge of #85889 - denismerigoux:master, r=petrochenkov
Dylan-DPC Jun 3, 2021
c11e324
Rollup merge of #85896 - BoxyUwU:remove-fixme-fwd-declared-const-defa…
Dylan-DPC Jun 3, 2021
2390917
Rollup merge of #85934 - tmiasko:is-union, r=jackh726
Dylan-DPC Jun 3, 2021
da85cce
Rollup merge of #85935 - tmiasko:validate-indexing, r=jonas-schievink
Dylan-DPC Jun 3, 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
251 changes: 149 additions & 102 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ extern "C" {

pub fn LLVMRustDIBuilderCreateUnionType(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Scope: Option<&'a DIScope>,
Name: *const c_char,
NameLen: size_t,
File: &'a DIFile,
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_ssa/src/coverageinfo/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Expression {
/// only whitespace or comments). According to LLVM Code Coverage Mapping documentation, "A count
/// for a gap area is only used as the line execution count if there are no other regions on a
/// line."
#[derive(Debug)]
pub struct FunctionCoverage<'tcx> {
instance: Instance<'tcx>,
source_hash: u64,
Expand Down Expand Up @@ -113,6 +114,14 @@ impl<'tcx> FunctionCoverage<'tcx> {
expression_id, lhs, op, rhs, region
);
let expression_index = self.expression_index(u32::from(expression_id));
debug_assert!(
expression_index.as_usize() < self.expressions.len(),
"expression_index {} is out of range for expressions.len() = {}
for {:?}",
expression_index.as_usize(),
self.expressions.len(),
self,
);
if let Some(previous_expression) = self.expressions[expression_index].replace(Expression {
lhs,
op,
Expand Down
59 changes: 56 additions & 3 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{self, subst::SubstsRef, Ty, TyCtxt};
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty, TyCtxt};
use rustc_target::abi::{TagEncoding, Variants};

use std::fmt::Write;

Expand Down Expand Up @@ -45,8 +46,12 @@ pub fn push_debuginfo_type_name<'tcx>(
ty::Float(float_ty) => output.push_str(float_ty.name_str()),
ty::Foreign(def_id) => push_item_name(tcx, def_id, qualified, output),
ty::Adt(def, substs) => {
push_item_name(tcx, def.did, qualified, output);
push_type_params(tcx, substs, output, visited);
if def.is_enum() && cpp_like_names {
msvc_enum_fallback(tcx, t, def, substs, output, visited);
} else {
push_item_name(tcx, def.did, qualified, output);
push_type_params(tcx, substs, output, visited);
}
}
ty::Tuple(component_types) => {
if cpp_like_names {
Expand Down Expand Up @@ -233,6 +238,54 @@ pub fn push_debuginfo_type_name<'tcx>(
}
}

/// MSVC names enums differently than other platforms so that the debugging visualization
// format (natvis) is able to understand enums and render the active variant correctly in the
// debugger. For more information, look in `src/etc/natvis/intrinsic.natvis` and
// `EnumMemberDescriptionFactor::create_member_descriptions`.
fn msvc_enum_fallback(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
def: &AdtDef,
substs: SubstsRef<'tcx>,
output: &mut String,
visited: &mut FxHashSet<Ty<'tcx>>,
) {
let layout = tcx.layout_of(tcx.param_env(def.did).and(ty)).expect("layout error");

if let Variants::Multiple {
tag_encoding: TagEncoding::Niche { dataful_variant, .. },
tag,
variants,
..
} = &layout.variants
{
let dataful_variant_layout = &variants[*dataful_variant];

// calculate the range of values for the dataful variant
let dataful_discriminant_range =
&dataful_variant_layout.largest_niche.as_ref().unwrap().scalar.valid_range;

let min = dataful_discriminant_range.start();
let min = tag.value.size(&tcx).truncate(*min);

let max = dataful_discriminant_range.end();
let max = tag.value.size(&tcx).truncate(*max);

output.push_str("enum$<");
push_item_name(tcx, def.did, true, output);
push_type_params(tcx, substs, output, visited);

let dataful_variant_name = def.variants[*dataful_variant].ident.as_str();

output.push_str(&format!(", {}, {}, {}>", min, max, dataful_variant_name));
} else {
output.push_str("enum$<");
push_item_name(tcx, def.did, true, output);
push_type_params(tcx, substs, output, visited);
output.push('>');
}
}

fn push_item_name(tcx: TyCtxt<'tcx>, def_id: DefId, qualified: bool, output: &mut String) {
if qualified {
output.push_str(&tcx.crate_name(def_id.krate).as_str());
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ macro_rules! pluralize {
/// before applying the suggestion.
#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
pub enum Applicability {
/// The suggestion is definitely what the user intended. This suggestion should be
/// The suggestion is definitely what the user intended, or maintains the exact meaning of the code.
/// This suggestion should be automatically applied.
///
/// In case of multiple `MachineApplicable` suggestions (whether as part of
/// the same `multipart_suggestion` or not), all of them should be
/// automatically applied.
MachineApplicable,

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,10 @@ impl CrateMetadata {
self.root.hash
}

fn num_def_ids(&self) -> usize {
self.root.tables.def_keys.size()
}

fn local_def_id(&self, index: DefIndex) -> DefId {
DefId { krate: self.cnum, index }
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ impl CStore {
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
}

/// Only public-facing way to traverse all the definitions in a non-local crate.
/// Critically useful for this third-party project: https://github.com/hacspec/hacspec.
/// See https://github.com/rust-lang/rust/pull/85889 for context.
pub fn num_def_ids_untracked(&self, cnum: CrateNum) -> usize {
self.get_crate_data(cnum).num_def_ids()
}

pub fn item_attrs(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
}
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1837,10 +1837,12 @@ impl<'tcx> TyS<'tcx> {

#[inline]
pub fn is_enum(&self) -> bool {
match self.kind() {
Adt(adt_def, _) => adt_def.is_enum(),
_ => false,
}
matches!(self.kind(), Adt(adt_def, _) if adt_def.is_enum())
}

#[inline]
pub fn is_union(&self) -> bool {
matches!(self.kind(), Adt(adt_def, _) if adt_def.is_union())
}

#[inline]
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_mir/src/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1965,13 +1965,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// no move out from an earlier location) then this is an attempt at initialization
// of the union - we should error in that case.
let tcx = this.infcx.tcx;
if let ty::Adt(def, _) = base.ty(this.body(), tcx).ty.kind() {
if def.is_union() {
if this.move_data.path_map[mpi].iter().any(|moi| {
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
}) {
return;
}
if base.ty(this.body(), tcx).ty.is_union() {
if this.move_data.path_map[mpi].iter().any(|moi| {
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
}) {
return;
}
}

Expand Down
19 changes: 8 additions & 11 deletions compiler/rustc_mir/src/borrow_check/places_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,14 @@ fn place_projection_conflict<'tcx>(
Overlap::EqualOrDisjoint
} else {
let ty = Place::ty_from(pi1_local, pi1_proj_base, body, tcx).ty;
match ty.kind() {
ty::Adt(def, _) if def.is_union() => {
// Different fields of a union, we are basically stuck.
debug!("place_element_conflict: STUCK-UNION");
Overlap::Arbitrary
}
_ => {
// Different fields of a struct (`a.x` vs. `a.y`). Disjoint!
debug!("place_element_conflict: DISJOINT-FIELD");
Overlap::Disjoint
}
if ty.is_union() {
// Different fields of a union, we are basically stuck.
debug!("place_element_conflict: STUCK-UNION");
Overlap::Arbitrary
} else {
// Different fields of a struct (`a.x` vs. `a.y`). Disjoint!
debug!("place_element_conflict: DISJOINT-FIELD");
Overlap::Disjoint
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir/src/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
// Check if we are assigning into a field of a union, if so, lookup the place
// of the union so it is marked as initialized again.
if let Some((place_base, ProjectionElem::Field(_, _))) = place.last_projection() {
if let ty::Adt(def, _) = place_base.ty(self.builder.body, self.builder.tcx).ty.kind() {
if def.is_union() {
place = place_base;
}
if place_base.ty(self.builder.body, self.builder.tcx).ty.is_union() {
place = place_base;
}
}

Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,9 @@ impl Validator<'mir, 'tcx> {
}

fn check_static(&mut self, def_id: DefId, span: Span) {
assert!(
!self.tcx.is_thread_local_static(def_id),
"tls access is checked in `Rvalue::ThreadLocalRef"
);
if self.tcx.is_thread_local_static(def_id) {
self.tcx.sess.delay_span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef");
}
self.check_op_spanned(ops::StaticAccess, span)
}

Expand Down Expand Up @@ -753,12 +752,8 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
| ProjectionElem::Field(..)
| ProjectionElem::Index(_) => {
let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty;
match base_ty.ty_adt_def() {
Some(def) if def.is_union() => {
self.check_op(ops::UnionAccess);
}

_ => {}
if base_ty.is_union() {
self.check_op(ops::UnionAccess);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_mir/src/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
}

let base_ty = base.ty(self.body, self.tcx).ty;
if base_ty.ty_adt_def().map_or(false, |adt| adt.is_union()) {
if base_ty.is_union() {
// If we did not hit a `Deref` yet and the overall place use is an assignment, the
// rules are different.
let assign_to_field = !saw_deref
Expand Down Expand Up @@ -376,6 +376,12 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
/// Checks whether calling `func_did` needs an `unsafe` context or not, i.e. whether
/// the called function has target features the calling function hasn't.
fn check_target_features(&mut self, func_did: DefId) {
// Unsafety isn't required on wasm targets. For more information see
// the corresponding check in typeck/src/collect.rs
if self.tcx.sess.target.options.is_like_wasm {
return;
}

let callee_features = &self.tcx.codegen_fn_attrs(func_did).target_features;
let self_features = &self.tcx.codegen_fn_attrs(self.body_did).target_features;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/const_goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'tcx> MirPass<'tcx> for ConstGoto {
// if we applied optimizations, we potentially have some cfg to cleanup to
// make it easier for further passes
if should_simplify {
simplify_cfg(body);
simplify_cfg(tcx, body);
simplify_locals(body, tcx);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/deduplicate_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'tcx> MirPass<'tcx> for DeduplicateBlocks {
if has_opts_to_apply {
let mut opt_applier = OptApplier { tcx, duplicates };
opt_applier.visit_body(body);
simplify_cfg(body);
simplify_cfg(tcx, body);
}
}
}
Expand Down
15 changes: 3 additions & 12 deletions compiler/rustc_mir/src/transform/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ use rustc_middle::mir::{
traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place, PlaceElem,
Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::TyCtxt;

// Empirical measurements have resulted in some observations:
// - Running on a body with a single block and 500 locals takes barely any time
Expand Down Expand Up @@ -910,17 +910,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {

// Handle the "subtle case" described above by rejecting any `dest` that is or
// projects through a union.
let is_union = |ty: Ty<'_>| {
if let ty::Adt(def, _) = ty.kind() {
if def.is_union() {
return true;
}
}

false
};
let mut place_ty = PlaceTy::from_ty(self.body.local_decls[dest.local].ty);
if is_union(place_ty.ty) {
if place_ty.ty.is_union() {
return;
}
for elem in dest.projection {
Expand All @@ -930,7 +921,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {
}

place_ty = place_ty.projection_ty(self.tcx, elem);
if is_union(place_ty.ty) {
if place_ty.ty.is_union() {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
// Since this optimization adds new basic blocks and invalidates others,
// clean up the cfg to make it nicer for other passes
if should_cleanup {
simplify_cfg(body);
simplify_cfg(tcx, body);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ fn create_generator_drop_shim<'tcx>(

// Make sure we remove dead blocks to remove
// unrelated code from the resume part of the function
simplify::remove_dead_blocks(&mut body);
simplify::remove_dead_blocks(tcx, &mut body);

dump_mir(tcx, None, "generator_drop", &0, &body, |_, _| Ok(()));

Expand Down Expand Up @@ -1137,7 +1137,7 @@ fn create_generator_resume_function<'tcx>(

// Make sure we remove dead blocks to remove
// unrelated code from the drop part of the function
simplify::remove_dead_blocks(body);
simplify::remove_dead_blocks(tcx, body);

dump_mir(tcx, None, "generator_resume", &0, body, |_, _| Ok(()));
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
if inline(tcx, body) {
debug!("running simplify cfg on {:?}", body.source);
CfgSimplifier::new(body).simplify();
remove_dead_blocks(body);
remove_dead_blocks(tcx, body);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/match_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
}

if should_cleanup {
simplify_cfg(body);
simplify_cfg(tcx, body);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
}
}

simplify::remove_dead_blocks(body)
simplify::remove_dead_blocks(tcx, body)
}
}
6 changes: 2 additions & 4 deletions compiler/rustc_mir/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,9 @@ impl<'tcx> Validator<'_, 'tcx> {

ProjectionElem::Field(..) => {
let base_ty = place_base.ty(self.body, self.tcx).ty;
if let Some(def) = base_ty.ty_adt_def() {
if base_ty.is_union() {
// No promotion of union field accesses.
if def.is_union() {
return Err(Unpromotable);
}
return Err(Unpromotable);
}
}
}
Expand Down
Loading