Skip to content

Commit

Permalink
Auto merge of rust-lang#118023 - matthiaskrgr:rollup-i9skwic, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#117338 (Remove asmjs)
 - rust-lang#117549 (Use `copied` instead of manual `map`)
 - rust-lang#117745 (Emit smir)
 - rust-lang#117964 (When using existing fn as module, don't claim it doesn't exist)
 - rust-lang#118006 (clarify `fn discriminant` guarantees: only free lifetimes may get erased)
 - rust-lang#118016 (Add stable mir members to triagebot config)
 - rust-lang#118022 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 17, 2023
2 parents 2831701 8acb27c commit 82b804c
Show file tree
Hide file tree
Showing 92 changed files with 644 additions and 304 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3815,6 3815,7 @@ dependencies = [
"rustc_query_system",
"rustc_resolve",
"rustc_session",
"rustc_smir",
"rustc_span",
"rustc_symbol_mangling",
"rustc_target",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 42,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
// Merge attributes into the inner expression.
if !e.attrs.is_empty() {
let old_attrs =
self.attrs.get(&ex.hir_id.local_id).map(|la| *la).unwrap_or(&[]);
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]);
self.attrs.insert(
ex.hir_id.local_id,
&*self.arena.alloc_from_iter(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 499,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
/// resolver (if any).
fn orig_opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
self.resolver.node_id_to_def_id.get(&node).map(|local_def_id| *local_def_id)
self.resolver.node_id_to_def_id.get(&node).copied()
}

/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
Expand Down Expand Up @@ -542,7 542,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.generics_def_id_map
.iter()
.rev()
.find_map(|map| map.get(&local_def_id).map(|local_def_id| *local_def_id))
.find_map(|map| map.get(&local_def_id).copied())
.unwrap_or(local_def_id)
}

Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,11 990,7 @@ unsafe fn embed_bitcode(
// reason (see issue #90326 for historical background).
let is_aix = target_is_aix(cgcx);
let is_apple = target_is_apple(cgcx);
if is_apple
|| is_aix
|| cgcx.opts.target_triple.triple().starts_with("wasm")
|| cgcx.opts.target_triple.triple().starts_with("asmjs")
{
if is_apple || is_aix || cgcx.opts.target_triple.triple().starts_with("wasm") {
// We don't need custom section flags, create LLVM globals.
let llconst = common::bytes_in_context(llcx, bitcode);
let llglobal = llvm::LLVMAddGlobal(
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,9 2243,9 @@ fn linker_with_args<'a>(
// ------------ Late order-dependent options ------------

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

Ok(cmd.take_cmd())
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_driver_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 43,7 @@ rustc_privacy = { path = "../rustc_privacy" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_resolve = { path = "../rustc_resolve" }
rustc_session = { path = "../rustc_session" }
rustc_smir ={ path = "../rustc_smir" }
rustc_span = { path = "../rustc_span" }
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
rustc_target = { path = "../rustc_target" }
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_driver_impl/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 9,7 @@ use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
use rustc_middle::ty::{self, TyCtxt};
use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
use rustc_session::Session;
use rustc_smir::rustc_internal::pretty::write_smir_pretty;
use rustc_span::symbol::Ident;
use rustc_span::FileName;

Expand Down Expand Up @@ -325,6 326,11 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
write_mir_graphviz(ex.tcx(), None, &mut out).unwrap();
String::from_utf8(out).unwrap()
}
StableMir => {
let mut out = Vec::new();
write_smir_pretty(ex.tcx(), &mut out).unwrap();
String::from_utf8(out).unwrap()
}
ThirTree => {
let tcx = ex.tcx();
let mut out = String::new();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 860,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
self.suggest_boxing_for_return_impl_trait(
err,
ret_sp,
prior_arms.iter().chain(std::iter::once(&arm_span)).map(|s| *s),
prior_arms.iter().chain(std::iter::once(&arm_span)).copied(),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 703,7 @@ pub trait LintContext {
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");
},
BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => {
let possibilities: Vec<Symbol> = sess.parse_sess.check_config.expecteds.keys().map(|s| *s).collect();
let possibilities: Vec<Symbol> = sess.parse_sess.check_config.expecteds.keys().copied().collect();

// Suggest the most probable if we found one
if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 1337,7 @@ pub fn write_allocations<'tcx>(
fn alloc_ids_from_alloc(
alloc: ConstAllocation<'_>,
) -> impl DoubleEndedIterator<Item = AllocId> '_ {
alloc.inner().provenance().ptrs().values().map(|id| *id)
alloc.inner().provenance().ptrs().values().copied()
}

fn alloc_ids_from_const_val(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> '_ {
Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 2028,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
},
)
});
(format!("use of undeclared crate or module `{ident}`"), suggestion)
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
ident,
ScopeSet::All(ValueNS),
parent_scope,
None,
false,
ignore_binding,
) {
let descr = binding.res().descr();
(format!("{descr} `{ident}` is not a crate or module"), suggestion)
} else {
(format!("use of undeclared crate or module `{ident}`"), suggestion)
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2926,12 2926,13 @@ fn parse_pretty(handler: &EarlyErrorHandler, unstable_opts: &UnstableOptions) ->
"thir-tree" => ThirTree,
"thir-flat" => ThirFlat,
"mir" => Mir,
"stable-mir" => StableMir,
"mir-cfg" => MirCFG,
name => handler.early_error(format!(
"argument to `unpretty` must be one of `normal`, `identified`, \
`expanded`, `expanded,identified`, `expanded,hygiene`, \
`ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \
`hir,typed`, `hir-tree`, `thir-tree`, `thir-flat`, `mir` or \
`hir,typed`, `hir-tree`, `thir-tree`, `thir-flat`, `mir`, `stable-mir`, or \
`mir-cfg`; got {name}"
)),
};
Expand Down Expand Up @@ -3106,6 3107,8 @@ pub enum PpMode {
Mir,
/// `-Zunpretty=mir-cfg`
MirCFG,
/// `-Zunpretty=stable-mir`
StableMir,
}

impl PpMode {
Expand All @@ -3122,21 3125,22 @@ impl PpMode {
| ThirTree
| ThirFlat
| Mir
| MirCFG => true,
| MirCFG
| StableMir => true,
}
}
pub fn needs_hir(&self) -> bool {
use PpMode::*;
match *self {
Source(_) | AstTree | AstTreeExpanded => false,

Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG => true,
Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG | StableMir => true,
}
}

pub fn needs_analysis(&self) -> bool {
use PpMode::*;
matches!(*self, Hir(PpHirMode::Typed) | Mir | MirCFG | ThirTree | ThirFlat)
matches!(*self, Hir(PpHirMode::Typed) | Mir | StableMir | MirCFG | ThirTree | ThirFlat)
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,7 @@ use std::hash::Hash;
use std::ops::Index;

mod internal;
pub mod pretty;

pub fn stable<'tcx, S: Stable<'tcx>>(item: S) -> S::T {
with_tables(|tables| item.stable(tables))
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_smir/src/rustc_internal/pretty.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,20 @@
use std::io;

use super::run;
use rustc_middle::ty::TyCtxt;

pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io::Result<()> {
writeln!(
w,
"// WARNING: This is highly experimental output it's intended for stable-mir developers only."
)?;
writeln!(
w,
"// If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir."
)?;
let _ = run(tcx, || {
let items = stable_mir::all_local_items();
let _ = items.iter().map(|item| -> io::Result<()> { item.dump(w) }).collect::<Vec<_>>();
});
Ok(())
}
7 changes: 6 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,7 @@
//!
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.

use crate::rustc_internal::{IndexMap, RustcInternal};
use crate::rustc_internal::{internal, IndexMap, RustcInternal};
use crate::rustc_smir::stable_mir::ty::{BoundRegion, Region};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
Expand Down Expand Up @@ -105,6 105,10 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tables.tcx.type_of(item.internal(&mut *tables)).instantiate_identity().stable(&mut *tables)
}

fn const_literal(&self, cnst: &stable_mir::ty::Const) -> String {
internal(cnst).to_string()
}

fn span_of_an_item(&self, def_id: stable_mir::DefId) -> Span {
let mut tables = self.0.borrow_mut();
tables.tcx.def_span(tables[def_id]).stable(&mut *tables)
Expand Down Expand Up @@ -404,6 408,7 @@ impl<'tcx> Stable<'tcx> for mir::Body<'tcx> {
.map(|decl| stable_mir::mir::LocalDecl {
ty: decl.ty.stable(tables),
span: decl.source_info.span.stable(tables),
mutability: decl.mutability.stable(tables),
})
.collect(),
self.arg_count,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/abi/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 836,6 @@ impl<'a, Ty> FnAbi<'a, Ty> {
wasm::compute_c_abi_info(cx, self)
}
}
"asmjs" => wasm::compute_c_abi_info(cx, self),
"bpf" => bpf::compute_abi_info(self),
arch => {
return Err(AdjustForForeignAbiError::Unsupported {
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 1609,6 @@ supported_targets! {
("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc),
("thumbv7a-uwp-windows-msvc", thumbv7a_uwp_windows_msvc),

("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
("wasm32-unknown-emscripten", wasm32_unknown_emscripten),
("wasm32-unknown-unknown", wasm32_unknown_unknown),
("wasm32-wasi", wasm32_wasi),
Expand Down Expand Up @@ -2244,10 2243,6 @@ impl TargetOptions {
add_link_args(&mut self.pre_link_args, flavor, args);
}

fn add_post_link_args(&mut self, flavor: LinkerFlavor, args: &[&'static str]) {
add_link_args(&mut self.post_link_args, flavor, args);
}

fn update_from_cli(&mut self) {
self.linker_flavor = LinkerFlavor::from_cli_json(
self.linker_flavor_json,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ty_utils/src/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 43,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
trait_fn_def_id,
)
})
.map(|def_id| *def_id),
.copied(),
),
)
}
Expand All @@ -69,7 69,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
impl_fn_def_id,
)
})
.map(|def_id| *def_id)
.copied()
})),
)
}
Expand Down
14 changes: 12 additions & 2 deletions compiler/stable_mir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 19,9 @@

use crate::mir::mono::InstanceDef;
use crate::mir::Body;
use std::cell::Cell;
use std::fmt;
use std::fmt::Debug;
use std::{cell::Cell, io};

use self::ty::{
GenericPredicates, Generics, ImplDef, ImplTrait, IndexedVal, LineInfo, Span, TraitDecl,
Expand All @@ -36,10 36,12 @@ pub mod mir;
pub mod ty;
pub mod visitor;

use crate::mir::pretty::function_name;
use crate::mir::Mutability;
use crate::ty::{AdtDef, AdtKind, ClosureDef, ClosureKind};
pub use error::*;
use mir::mono::Instance;
use ty::{FnDef, GenericArgs};
use ty::{Const, FnDef, GenericArgs};

/// Use String for now but we should replace it.
pub type Symbol = String;
Expand Down Expand Up @@ -137,6 139,11 @@ impl CrateItem {
pub fn ty(&self) -> Ty {
with(|cx| cx.def_ty(self.0))
}

pub fn dump<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
writeln!(w, "{}", function_name(*self))?;
self.body().dump(w)
}
}

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

/// Returns literal value of a const as a string.
fn const_literal(&self, cnst: &Const) -> String;

/// `Span` of an item
fn span_of_an_item(&self, def_id: DefId) -> Span;

Expand Down
1 change: 1 addition & 0 deletions compiler/stable_mir/src/mir.rs
Original file line number Diff line number Diff line change
@@ -1,5 1,6 @@
mod body;
pub mod mono;
pub mod pretty;
pub mod visit;

pub use body::*;
Expand Down
26 changes: 25 additions & 1 deletion compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
@@ -1,7 1,8 @@
use crate::mir::pretty::{function_body, pretty_statement};
use crate::ty::{AdtDef, ClosureDef, Const, CoroutineDef, GenericArgs, Movability, Region, Ty};
use crate::Opaque;
use crate::Span;

use std::io;
/// The SMIR representation of a single function.
#[derive(Clone, Debug)]
pub struct Body {
Expand Down Expand Up @@ -56,6 57,28 @@ impl Body {
pub fn locals(&self) -> &[LocalDecl] {
&self.locals
}

pub fn dump<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
writeln!(w, "{}", function_body(self))?;
self.blocks
.iter()
.enumerate()
.map(|(index, block)| -> io::Result<()> {
writeln!(w, " bb{}: {{", index)?;
let _ = block
.statements
.iter()
.map(|statement| -> io::Result<()> {
writeln!(w, "{}", pretty_statement(&statement.kind))?;
Ok(())
})
.collect::<Vec<_>>();
writeln!(w, " }}").unwrap();
Ok(())
})
.collect::<Result<Vec<_>, _>>()?;
Ok(())
}
}

type LocalDecls = Vec<LocalDecl>;
Expand All @@ -64,6 87,7 @@ type LocalDecls = Vec<LocalDecl>;
pub struct LocalDecl {
pub ty: Ty,
pub span: Span,
pub mutability: Mutability,
}

#[derive(Clone, Debug)]
Expand Down
Loading

0 comments on commit 82b804c

Please sign in to comment.