Skip to content

Commit 82b804c

Browse files
committed
Auto merge of #118023 - matthiaskrgr:rollup-i9skwic, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #117338 (Remove asmjs) - #117549 (Use `copied` instead of manual `map`) - #117745 (Emit smir) - #117964 (When using existing fn as module, don't claim it doesn't exist) - #118006 (clarify `fn discriminant` guarantees: only free lifetimes may get erased) - #118016 (Add stable mir members to triagebot config) - #118022 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2831701 + 8acb27c commit 82b804c

File tree

92 files changed

+644
-304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+644
-304
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3815,6 +3815,7 @@ dependencies = [
38153815
"rustc_query_system",
38163816
"rustc_resolve",
38173817
"rustc_session",
3818+
"rustc_smir",
38183819
"rustc_span",
38193820
"rustc_symbol_mangling",
38203821
"rustc_target",

compiler/rustc_ast_lowering/src/expr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
4242
}
4343
// Merge attributes into the inner expression.
4444
if !e.attrs.is_empty() {
45-
let old_attrs =
46-
self.attrs.get(&ex.hir_id.local_id).map(|la| *la).unwrap_or(&[]);
45+
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]);
4746
self.attrs.insert(
4847
ex.hir_id.local_id,
4948
&*self.arena.alloc_from_iter(

compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
499499
/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
500500
/// resolver (if any).
501501
fn orig_opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
502-
self.resolver.node_id_to_def_id.get(&node).map(|local_def_id| *local_def_id)
502+
self.resolver.node_id_to_def_id.get(&node).copied()
503503
}
504504

505505
/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
@@ -542,7 +542,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
542542
self.generics_def_id_map
543543
.iter()
544544
.rev()
545-
.find_map(|map| map.get(&local_def_id).map(|local_def_id| *local_def_id))
545+
.find_map(|map| map.get(&local_def_id).copied())
546546
.unwrap_or(local_def_id)
547547
}
548548

compiler/rustc_codegen_llvm/src/back/write.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -990,11 +990,7 @@ unsafe fn embed_bitcode(
990990
// reason (see issue #90326 for historical background).
991991
let is_aix = target_is_aix(cgcx);
992992
let is_apple = target_is_apple(cgcx);
993-
if is_apple
994-
|| is_aix
995-
|| cgcx.opts.target_triple.triple().starts_with("wasm")
996-
|| cgcx.opts.target_triple.triple().starts_with("asmjs")
997-
{
993+
if is_apple || is_aix || cgcx.opts.target_triple.triple().starts_with("wasm") {
998994
// We don't need custom section flags, create LLVM globals.
999995
let llconst = common::bytes_in_context(llcx, bitcode);
1000996
let llglobal = llvm::LLVMAddGlobal(

compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2243,9 +2243,9 @@ fn linker_with_args<'a>(
22432243
// ------------ Late order-dependent options ------------
22442244

22452245
// Doesn't really make sense.
2246-
// FIXME: In practice built-in target specs use this for arbitrary order-independent options,
2247-
// introduce a target spec option for order-independent linker options, migrate built-in specs
2248-
// to it and remove the option.
2246+
// FIXME: In practice built-in target specs use this for arbitrary order-independent options.
2247+
// Introduce a target spec option for order-independent linker options, migrate built-in specs
2248+
// to it and remove the option. Currently the last holdout is wasm32-unknown-emscripten.
22492249
add_post_link_args(cmd, sess, flavor);
22502250

22512251
Ok(cmd.take_cmd())

compiler/rustc_driver_impl/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ rustc_privacy = { path = "../rustc_privacy" }
4343
rustc_query_system = { path = "../rustc_query_system" }
4444
rustc_resolve = { path = "../rustc_resolve" }
4545
rustc_session = { path = "../rustc_session" }
46+
rustc_smir ={ path = "../rustc_smir" }
4647
rustc_span = { path = "../rustc_span" }
4748
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
4849
rustc_target = { path = "../rustc_target" }

compiler/rustc_driver_impl/src/pretty.rs

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
99
use rustc_middle::ty::{self, TyCtxt};
1010
use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
1111
use rustc_session::Session;
12+
use rustc_smir::rustc_internal::pretty::write_smir_pretty;
1213
use rustc_span::symbol::Ident;
1314
use rustc_span::FileName;
1415

@@ -325,6 +326,11 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
325326
write_mir_graphviz(ex.tcx(), None, &mut out).unwrap();
326327
String::from_utf8(out).unwrap()
327328
}
329+
StableMir => {
330+
let mut out = Vec::new();
331+
write_smir_pretty(ex.tcx(), &mut out).unwrap();
332+
String::from_utf8(out).unwrap()
333+
}
328334
ThirTree => {
329335
let tcx = ex.tcx();
330336
let mut out = String::new();

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
860860
self.suggest_boxing_for_return_impl_trait(
861861
err,
862862
ret_sp,
863-
prior_arms.iter().chain(std::iter::once(&arm_span)).map(|s| *s),
863+
prior_arms.iter().chain(std::iter::once(&arm_span)).copied(),
864864
);
865865
}
866866
}

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ pub trait LintContext {
703703
db.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
704704
},
705705
BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => {
706-
let possibilities: Vec<Symbol> = sess.parse_sess.check_config.expecteds.keys().map(|s| *s).collect();
706+
let possibilities: Vec<Symbol> = sess.parse_sess.check_config.expecteds.keys().copied().collect();
707707

708708
// Suggest the most probable if we found one
709709
if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) {

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ pub fn write_allocations<'tcx>(
13371337
fn alloc_ids_from_alloc(
13381338
alloc: ConstAllocation<'_>,
13391339
) -> impl DoubleEndedIterator<Item = AllocId> + '_ {
1340-
alloc.inner().provenance().ptrs().values().map(|id| *id)
1340+
alloc.inner().provenance().ptrs().values().copied()
13411341
}
13421342

13431343
fn alloc_ids_from_const_val(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> + '_ {

compiler/rustc_resolve/src/diagnostics.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20282028
},
20292029
)
20302030
});
2031-
(format!("use of undeclared crate or module `{ident}`"), suggestion)
2031+
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
2032+
ident,
2033+
ScopeSet::All(ValueNS),
2034+
parent_scope,
2035+
None,
2036+
false,
2037+
ignore_binding,
2038+
) {
2039+
let descr = binding.res().descr();
2040+
(format!("{descr} `{ident}` is not a crate or module"), suggestion)
2041+
} else {
2042+
(format!("use of undeclared crate or module `{ident}`"), suggestion)
2043+
}
20322044
}
20332045
}
20342046

compiler/rustc_session/src/config.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -2926,12 +2926,13 @@ fn parse_pretty(handler: &EarlyErrorHandler, unstable_opts: &UnstableOptions) ->
29262926
"thir-tree" => ThirTree,
29272927
"thir-flat" => ThirFlat,
29282928
"mir" => Mir,
2929+
"stable-mir" => StableMir,
29292930
"mir-cfg" => MirCFG,
29302931
name => handler.early_error(format!(
29312932
"argument to `unpretty` must be one of `normal`, `identified`, \
29322933
`expanded`, `expanded,identified`, `expanded,hygiene`, \
29332934
`ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \
2934-
`hir,typed`, `hir-tree`, `thir-tree`, `thir-flat`, `mir` or \
2935+
`hir,typed`, `hir-tree`, `thir-tree`, `thir-flat`, `mir`, `stable-mir`, or \
29352936
`mir-cfg`; got {name}"
29362937
)),
29372938
};
@@ -3106,6 +3107,8 @@ pub enum PpMode {
31063107
Mir,
31073108
/// `-Zunpretty=mir-cfg`
31083109
MirCFG,
3110+
/// `-Zunpretty=stable-mir`
3111+
StableMir,
31093112
}
31103113

31113114
impl PpMode {
@@ -3122,21 +3125,22 @@ impl PpMode {
31223125
| ThirTree
31233126
| ThirFlat
31243127
| Mir
3125-
| MirCFG => true,
3128+
| MirCFG
3129+
| StableMir => true,
31263130
}
31273131
}
31283132
pub fn needs_hir(&self) -> bool {
31293133
use PpMode::*;
31303134
match *self {
31313135
Source(_) | AstTree | AstTreeExpanded => false,
31323136

3133-
Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG => true,
3137+
Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG | StableMir => true,
31343138
}
31353139
}
31363140

31373141
pub fn needs_analysis(&self) -> bool {
31383142
use PpMode::*;
3139-
matches!(*self, Hir(PpHirMode::Typed) | Mir | MirCFG | ThirTree | ThirFlat)
3143+
matches!(*self, Hir(PpHirMode::Typed) | Mir | StableMir | MirCFG | ThirTree | ThirFlat)
31403144
}
31413145
}
31423146

compiler/rustc_smir/src/rustc_internal/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::hash::Hash;
2121
use std::ops::Index;
2222

2323
mod internal;
24+
pub mod pretty;
2425

2526
pub fn stable<'tcx, S: Stable<'tcx>>(item: S) -> S::T {
2627
with_tables(|tables| item.stable(tables))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::io;
2+
3+
use super::run;
4+
use rustc_middle::ty::TyCtxt;
5+
6+
pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io::Result<()> {
7+
writeln!(
8+
w,
9+
"// WARNING: This is highly experimental output it's intended for stable-mir developers only."
10+
)?;
11+
writeln!(
12+
w,
13+
"// If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir."
14+
)?;
15+
let _ = run(tcx, || {
16+
let items = stable_mir::all_local_items();
17+
let _ = items.iter().map(|item| -> io::Result<()> { item.dump(w) }).collect::<Vec<_>>();
18+
});
19+
Ok(())
20+
}

compiler/rustc_smir/src/rustc_smir/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//!
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10-
use crate::rustc_internal::{IndexMap, RustcInternal};
10+
use crate::rustc_internal::{internal, IndexMap, RustcInternal};
1111
use crate::rustc_smir::stable_mir::ty::{BoundRegion, Region};
1212
use rustc_hir as hir;
1313
use rustc_hir::def::DefKind;
@@ -105,6 +105,10 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
105105
tables.tcx.type_of(item.internal(&mut *tables)).instantiate_identity().stable(&mut *tables)
106106
}
107107

108+
fn const_literal(&self, cnst: &stable_mir::ty::Const) -> String {
109+
internal(cnst).to_string()
110+
}
111+
108112
fn span_of_an_item(&self, def_id: stable_mir::DefId) -> Span {
109113
let mut tables = self.0.borrow_mut();
110114
tables.tcx.def_span(tables[def_id]).stable(&mut *tables)
@@ -404,6 +408,7 @@ impl<'tcx> Stable<'tcx> for mir::Body<'tcx> {
404408
.map(|decl| stable_mir::mir::LocalDecl {
405409
ty: decl.ty.stable(tables),
406410
span: decl.source_info.span.stable(tables),
411+
mutability: decl.mutability.stable(tables),
407412
})
408413
.collect(),
409414
self.arg_count,

compiler/rustc_target/src/abi/call/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,6 @@ impl<'a, Ty> FnAbi<'a, Ty> {
836836
wasm::compute_c_abi_info(cx, self)
837837
}
838838
}
839-
"asmjs" => wasm::compute_c_abi_info(cx, self),
840839
"bpf" => bpf::compute_abi_info(self),
841840
arch => {
842841
return Err(AdjustForForeignAbiError::Unsupported {

compiler/rustc_target/src/spec/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,6 @@ supported_targets! {
16091609
("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc),
16101610
("thumbv7a-uwp-windows-msvc", thumbv7a_uwp_windows_msvc),
16111611

1612-
("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
16131612
("wasm32-unknown-emscripten", wasm32_unknown_emscripten),
16141613
("wasm32-unknown-unknown", wasm32_unknown_unknown),
16151614
("wasm32-wasi", wasm32_wasi),
@@ -2244,10 +2243,6 @@ impl TargetOptions {
22442243
add_link_args(&mut self.pre_link_args, flavor, args);
22452244
}
22462245

2247-
fn add_post_link_args(&mut self, flavor: LinkerFlavor, args: &[&'static str]) {
2248-
add_link_args(&mut self.post_link_args, flavor, args);
2249-
}
2250-
22512246
fn update_from_cli(&mut self) {
22522247
self.linker_flavor = LinkerFlavor::from_cli_json(
22532248
self.linker_flavor_json,

compiler/rustc_ty_utils/src/assoc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
4343
trait_fn_def_id,
4444
)
4545
})
46-
.map(|def_id| *def_id),
46+
.copied(),
4747
),
4848
)
4949
}
@@ -69,7 +69,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
6969
impl_fn_def_id,
7070
)
7171
})
72-
.map(|def_id| *def_id)
72+
.copied()
7373
})),
7474
)
7575
}

compiler/stable_mir/src/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
2020
use crate::mir::mono::InstanceDef;
2121
use crate::mir::Body;
22-
use std::cell::Cell;
2322
use std::fmt;
2423
use std::fmt::Debug;
24+
use std::{cell::Cell, io};
2525

2626
use self::ty::{
2727
GenericPredicates, Generics, ImplDef, ImplTrait, IndexedVal, LineInfo, Span, TraitDecl,
@@ -36,10 +36,12 @@ pub mod mir;
3636
pub mod ty;
3737
pub mod visitor;
3838

39+
use crate::mir::pretty::function_name;
40+
use crate::mir::Mutability;
3941
use crate::ty::{AdtDef, AdtKind, ClosureDef, ClosureKind};
4042
pub use error::*;
4143
use mir::mono::Instance;
42-
use ty::{FnDef, GenericArgs};
44+
use ty::{Const, FnDef, GenericArgs};
4345

4446
/// Use String for now but we should replace it.
4547
pub type Symbol = String;
@@ -137,6 +139,11 @@ impl CrateItem {
137139
pub fn ty(&self) -> Ty {
138140
with(|cx| cx.def_ty(self.0))
139141
}
142+
143+
pub fn dump<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
144+
writeln!(w, "{}", function_name(*self))?;
145+
self.body().dump(w)
146+
}
140147
}
141148

142149
/// Return the function where execution starts if the current
@@ -223,6 +230,9 @@ pub trait Context {
223230
/// Returns the type of given crate item.
224231
fn def_ty(&self, item: DefId) -> Ty;
225232

233+
/// Returns literal value of a const as a string.
234+
fn const_literal(&self, cnst: &Const) -> String;
235+
226236
/// `Span` of an item
227237
fn span_of_an_item(&self, def_id: DefId) -> Span;
228238

compiler/stable_mir/src/mir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod body;
22
pub mod mono;
3+
pub mod pretty;
34
pub mod visit;
45

56
pub use body::*;

compiler/stable_mir/src/mir/body.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use crate::mir::pretty::{function_body, pretty_statement};
12
use crate::ty::{AdtDef, ClosureDef, Const, CoroutineDef, GenericArgs, Movability, Region, Ty};
23
use crate::Opaque;
34
use crate::Span;
4-
5+
use std::io;
56
/// The SMIR representation of a single function.
67
#[derive(Clone, Debug)]
78
pub struct Body {
@@ -56,6 +57,28 @@ impl Body {
5657
pub fn locals(&self) -> &[LocalDecl] {
5758
&self.locals
5859
}
60+
61+
pub fn dump<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
62+
writeln!(w, "{}", function_body(self))?;
63+
self.blocks
64+
.iter()
65+
.enumerate()
66+
.map(|(index, block)| -> io::Result<()> {
67+
writeln!(w, " bb{}: {{", index)?;
68+
let _ = block
69+
.statements
70+
.iter()
71+
.map(|statement| -> io::Result<()> {
72+
writeln!(w, "{}", pretty_statement(&statement.kind))?;
73+
Ok(())
74+
})
75+
.collect::<Vec<_>>();
76+
writeln!(w, " }}").unwrap();
77+
Ok(())
78+
})
79+
.collect::<Result<Vec<_>, _>>()?;
80+
Ok(())
81+
}
5982
}
6083

6184
type LocalDecls = Vec<LocalDecl>;
@@ -64,6 +87,7 @@ type LocalDecls = Vec<LocalDecl>;
6487
pub struct LocalDecl {
6588
pub ty: Ty,
6689
pub span: Span,
90+
pub mutability: Mutability,
6791
}
6892

6993
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)