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 8 pull requests #108919

Merged
merged 19 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
40185db
Delete old re-exports from rustc_smir
celinval Mar 4, 2023
af664be
rustdoc: include link on all.html location header
notriddle Mar 3, 2023
b66db7e
Create new rustc_smir struct to map future crates
celinval Mar 4, 2023
775bacd
Simplify `sort_by` calls
WaffleLapkin Mar 7, 2023
5eaeb71
Change item collection to be on demand
celinval Mar 7, 2023
a439c02
may not => cannot
compiler-errors Mar 7, 2023
0f4255e
Dedup copy field errors for identical types
compiler-errors Mar 8, 2023
8a99ffc
Suppress copy impl error when post-normalized type references errors
compiler-errors Mar 7, 2023
be60bcb
Rename `MapInPlace` as `FlatMapInPlace`.
nnethercote Mar 8, 2023
204ba32
fix: evaluate with wrong obligation stack
LYF1999 Mar 8, 2023
1d442af
move clippy tests back to their intended directory
pietroalbini Mar 8, 2023
6c91ce2
Rollup merge of #108686 - notriddle:notriddle/jank-all, r=jsha
matthiaskrgr Mar 8, 2023
9b6b7a3
Rollup merge of #108846 - celinval:smir-poc, r=oli-obk
matthiaskrgr Mar 8, 2023
1a9376d
Rollup merge of #108873 - WaffleLapkin:cmp, r=cjgillot
matthiaskrgr Mar 8, 2023
f6b8a9f
Rollup merge of #108883 - compiler-errors:post-norm-copy-err, r=BoxyUwU
matthiaskrgr Mar 8, 2023
031b528
Rollup merge of #108884 - compiler-errors:tweak-illegal-copy-impl-mes…
matthiaskrgr Mar 8, 2023
a95943b
Rollup merge of #108887 - nnethercote:rename-MapInPlace, r=lqd
matthiaskrgr Mar 8, 2023
33c3036
Rollup merge of #108901 - LYF1999:yf/108897, r=lcnr
matthiaskrgr Mar 8, 2023
7732ccc
Rollup merge of #108903 - rust-lang:pa-fix-clippy-tests, r=flip1995
matthiaskrgr Mar 8, 2023
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
10 changes: 2 additions & 8 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4669,15 +4669,9 @@ dependencies = [
name = "rustc_smir"
version = "0.0.0"
dependencies = [
"rustc_borrowck",
"rustc_driver",
"rustc_hir",
"rustc_interface",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_mir_transform",
"rustc_serialize",
"rustc_trait_selection",
"rustc_span",
"tracing",
]

[[package]]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::ptr::P;
use crate::token::{self, Token};
use crate::tokenstream::*;

use rustc_data_structures::map_in_place::MapInPlace;
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::sync::Lrc;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::Ident;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ use smallvec::{Array, SmallVec};
use std::ptr;
use thin_vec::ThinVec;

pub trait MapInPlace<T>: Sized {
fn map_in_place<F>(&mut self, mut f: F)
where
F: FnMut(T) -> T,
{
self.flat_map_in_place(|e| Some(f(e)))
}

pub trait FlatMapInPlace<T>: Sized {
fn flat_map_in_place<F, I>(&mut self, f: F)
where
F: FnMut(T) -> I,
Expand Down Expand Up @@ -66,14 +59,14 @@ macro_rules! flat_map_in_place {
};
}

impl<T> MapInPlace<T> for Vec<T> {
impl<T> FlatMapInPlace<T> for Vec<T> {
flat_map_in_place!();
}

impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> {
impl<T, A: Array<Item = T>> FlatMapInPlace<T> for SmallVec<A> {
flat_map_in_place!();
}

impl<T> MapInPlace<T> for ThinVec<T> {
impl<T> FlatMapInPlace<T> for ThinVec<T> {
flat_map_in_place!();
}
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
pub mod base_n;
pub mod binary_search_util;
pub mod captures;
pub mod flat_map_in_place;
pub mod flock;
pub mod functor;
pub mod fx;
pub mod graph;
pub mod intern;
pub mod jobserver;
pub mod macros;
pub mod map_in_place;
pub mod obligation_forest;
pub mod owning_ref;
pub mod sip128;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rustc_ast::tokenstream::{LazyAttrTokenStream, TokenTree};
use rustc_ast::NodeId;
use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem};
use rustc_attr as attr;
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_feature::{Feature, Features, State as FeatureState};
use rustc_feature::{
ACCEPTED_FEATURES, ACTIVE_FEATURES, REMOVED_FEATURES, STABLE_REMOVED_FEATURES,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_ast::{ForeignItemKind, HasAttrs, HasNodeId};
use rustc_ast::{Inline, ItemKind, MacStmtStyle, MetaItemKind, ModKind};
use rustc_ast::{NestedMetaItem, NodeId, PatKind, StmtKind, TyKind};
use rustc_ast_pretty::pprust;
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::sync::Lrc;
use rustc_errors::PResult;
use rustc_feature::Features;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ hir_analysis_missing_type_params =
.note = because of the default `Self` reference, type parameters must be specified on object types

hir_analysis_copy_impl_on_type_with_dtor =
the trait `Copy` may not be implemented for this type; the type has a destructor
the trait `Copy` cannot be implemented for this type; the type has a destructor
.label = `Copy` not allowed on types with destructors

hir_analysis_multiple_relaxed_default_bounds =
type parameter has more than one relaxed default bound, only one is supported

hir_analysis_copy_impl_on_non_adt =
the trait `Copy` may not be implemented for this type
the trait `Copy` cannot be implemented for this type
.label = type is not a structure or enumeration

hir_analysis_const_impl_for_non_const_trait =
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! up data structures required by type-checking/codegen.

use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{struct_span_err, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -86,15 +87,22 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
tcx.sess,
span,
E0204,
"the trait `Copy` may not be implemented for this type"
"the trait `Copy` cannot be implemented for this type"
);

// We'll try to suggest constraining type parameters to fulfill the requirements of
// their `Copy` implementation.
let mut errors: BTreeMap<_, Vec<_>> = Default::default();
let mut bounds = vec![];

let mut seen_tys = FxHashSet::default();

for (field, ty, reason) in fields {
// Only report an error once per type.
if !seen_tys.insert(ty) {
continue;
}

let field_span = tcx.def_span(field.did);
err.span_label(field_span, "this field does not implement `Copy`");

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ hir_typeck_field_multiply_specified_in_initializer =
.previous_use_label = first use of `{$ident}`

hir_typeck_copy_impl_on_type_with_dtor =
the trait `Copy` may not be implemented for this type; the type has a destructor
the trait `Copy` cannot be implemented for this type; the type has a destructor
.label = `Copy` not allowed on types with destructors

hir_typeck_multiple_relaxed_default_bounds =
type parameter has more than one relaxed default bound, only one is supported

hir_typeck_copy_impl_on_non_adt =
the trait `Copy` may not be implemented for this type
the trait `Copy` cannot be implemented for this type
.label = type is not a structure or enumeration

hir_typeck_trait_object_declared_with_no_traits =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
.collect();

// Sort them by the name so we have a stable result.
names.sort_by(|a, b| a.as_str().partial_cmp(b.as_str()).unwrap());
names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
names
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use rustc_trait_selection::traits::{
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
use super::{CandidateSource, MethodError, NoMatchData};
use rustc_hir::intravisit::Visitor;
use std::cmp::Ordering;
use std::cmp::{self, Ordering};
use std::iter;

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Expand Down Expand Up @@ -2527,7 +2527,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if !candidates.is_empty() {
// Sort from most relevant to least relevant.
candidates.sort_by(|a, b| a.cmp(b).reverse());
candidates.sort_by_key(|&info| cmp::Reverse(info));
candidates.dedup();

let param_type = match rcvr_ty.kind() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_monomorphize/src/partitioning/merging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn merge_codegen_units<'tcx>(
// smallest into each other) we're sure to start off with a deterministic
// order (sorted by name). This'll mean that if two cgus have the same size
// the stable sort below will keep everything nice and deterministic.
codegen_units.sort_by(|a, b| a.name().as_str().partial_cmp(b.name().as_str()).unwrap());
codegen_units.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));

// This map keeps track of what got merged into what.
let mut cgu_contents: FxHashMap<Symbol, Vec<Symbol>> =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_monomorphize/src/partitioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub fn partition<'tcx>(
internalization_candidates: _,
} = post_inlining;

result.sort_by(|a, b| a.name().as_str().partial_cmp(b.name().as_str()).unwrap());
result.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));

result
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn report_suspicious_mismatch_block(
.collect();

// sort by `lo`, so the large block spans in the front
matched_spans.sort_by(|a, b| a.0.lo().cmp(&b.0.lo()));
matched_spans.sort_by_key(|(span, _)| span.lo());

// We use larger block whose identation is well to cover those inner mismatched blocks
// O(N^2) here, but we are on error reporting path, so it is fine
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {

let name = path[path.len() - 1].ident.name;
// Make sure error reporting is deterministic.
names.sort_by(|a, b| a.candidate.as_str().partial_cmp(b.candidate.as_str()).unwrap());
names.sort_by(|a, b| a.candidate.as_str().cmp(b.candidate.as_str()));

match find_best_match_for_name(
&names.iter().map(|suggestion| suggestion.candidate).collect::<Vec<Symbol>>(),
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_session/src/code_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lock;
use rustc_span::Symbol;
use rustc_target::abi::{Align, Size};
use std::cmp::{self, Ordering};
use std::cmp;

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct VariantInfo {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl CodeStats {
// Except for Generators, whose variants are already sorted according to
// their yield points in `variant_info_for_generator`.
if kind != DataTypeKind::Generator {
variants.sort_by(|info1, info2| info2.size.cmp(&info1.size));
variants.sort_by_key(|info| cmp::Reverse(info.size));
}
let info = TypeSizeInfo {
kind,
Expand All @@ -107,13 +107,7 @@ impl CodeStats {

// Primary sort: large-to-small.
// Secondary sort: description (dictionary order)
sorted.sort_by(|info1, info2| {
// (reversing cmp order to get large-to-small ordering)
match info2.overall_size.cmp(&info1.overall_size) {
Ordering::Equal => info1.type_description.cmp(&info2.type_description),
other => other,
}
});
sorted.sort_by_key(|info| (cmp::Reverse(info.overall_size), &info.type_description));

for info in sorted {
let TypeSizeInfo { type_description, overall_size, align, kind, variants, .. } = info;
Expand Down
19 changes: 3 additions & 16 deletions compiler/rustc_smir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,12 @@ version = "0.0.0"
edition = "2021"

[dependencies]
rustc_borrowck = { path = "../rustc_borrowck", optional = true }
rustc_driver = { path = "../rustc_driver", optional = true }
rustc_hir = { path = "../rustc_hir", optional = true }
rustc_interface = { path = "../rustc_interface", optional = true }
rustc_middle = { path = "../rustc_middle", optional = true }
rustc_mir_dataflow = { path = "../rustc_mir_dataflow", optional = true }
rustc_mir_transform = { path = "../rustc_mir_transform", optional = true }
rustc_serialize = { path = "../rustc_serialize", optional = true }
rustc_trait_selection = { path = "../rustc_trait_selection", optional = true }
rustc_span = { path = "../rustc_span", optional = true }
tracing = "0.1"

[features]
default = [
"rustc_borrowck",
"rustc_driver",
"rustc_hir",
"rustc_interface",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_mir_transform",
"rustc_serialize",
"rustc_trait_selection",
"rustc_span",
]
37 changes: 37 additions & 0 deletions compiler/rustc_smir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,40 @@ git subtree pull --prefix=compiler/rustc_smir https://github.com/rust-lang/proje
Note: only ever sync to rustc from the project-stable-mir's `smir` branch. Do not sync with your own forks.

Then open a PR against rustc just like a regular PR.

## Stable MIR Design

The stable-mir will follow a similar approach to proc-macro2. It’s
implementation will eventually be broken down into two main crates:

- `stable_mir`: Public crate, to be published on crates.io, which will contain
the stable data structure as well as proxy APIs to make calls to the
compiler.
- `rustc_smir`: The compiler crate that will translate from internal MIR to
SMIR. This crate will also implement APIs that will be invoked by
stable-mir to query the compiler for more information.

This will help tools to communicate with the rust compiler via stable APIs. Tools will depend on
`stable_mir` crate, which will invoke the compiler using APIs defined in `rustc_smir`. I.e.:

```
┌──────────────────────────────────┐ ┌──────────────────────────────────┐
│ External Tool ┌──────────┐ │ │ ┌──────────┐ Rust Compiler │
│ │ │ │ │ │ │ │
│ │stable_mir| │ │ │rustc_smir│ │
│ │ │ ├──────────►| │ │ │
│ │ │ │◄──────────┤ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ └──────────┘ │ │ └──────────┘ │
└──────────────────────────────────┘ └──────────────────────────────────┘
```

More details can be found here:
https://hackmd.io/XhnYHKKuR6-LChhobvlT-g?view

For now, the code for these two crates are in separate modules of this crate.
The modules have the same name for simplicity. We also have a third module,
`rustc_internal` which will expose APIs and definitions that allow users to
gather information from internal MIR constructs that haven't been exposed in
the `stable_mir` module.
2 changes: 1 addition & 1 deletion compiler/rustc_smir/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2022-06-01"
channel = "nightly-2023-02-28"
components = [ "rustfmt", "rustc-dev" ]
8 changes: 4 additions & 4 deletions compiler/rustc_smir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
test(attr(allow(unused_variables), deny(warnings)))
)]
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

pub mod mir;
pub mod rustc_internal;
pub mod stable_mir;

pub mod very_unstable;
// Make this module private for now since external users should not call these directly.
mod rustc_smir;
10 changes: 0 additions & 10 deletions compiler/rustc_smir/src/mir.rs

This file was deleted.

15 changes: 15 additions & 0 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Module that implements the bridge between Stable MIR and internal compiler MIR.
//!
//! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs
//! until stable MIR is complete.

use crate::stable_mir;
pub use rustc_span::def_id::{CrateNum, DefId};

pub fn item_def_id(item: &stable_mir::CrateItem) -> DefId {
item.0
}

pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
item.id.into()
}
Loading