Skip to content

Commit 5e17a2a

Browse files
committed
Auto merge of rust-lang#139417 - matthiaskrgr:rollup-ktf1d6s, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#136877 (Fix missing const for inherent pointer `replace` methods) - rust-lang#138797 (Fix `ProvenVia` for global where clauses) - rust-lang#139121 (Rename internal module from `statik` to `no_threads`) - rust-lang#139319 (StableMIR: Prepare for refactoring) - rust-lang#139404 (Small smir cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0c478fd + 91377bd commit 5e17a2a

File tree

37 files changed

+378
-338
lines changed

37 files changed

+378
-338
lines changed

Cargo.lock

+2-3
Original file line numberDiff line numberDiff line change
@@ -4432,7 +4432,7 @@ dependencies = [
44324432
"rustc_span",
44334433
"rustc_target",
44344434
"scoped-tls",
4435-
"stable_mir",
4435+
"serde",
44364436
"tracing",
44374437
]
44384438

@@ -4990,8 +4990,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
49904990
name = "stable_mir"
49914991
version = "0.1.0-preview"
49924992
dependencies = [
4993-
"scoped-tls",
4994-
"serde",
4993+
"rustc_smir",
49954994
]
49964995

49974996
[[package]]

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,6 @@ where
13011301
.filter(|c| matches!(c.source, CandidateSource::ParamEnv(_)))
13021302
.map(|c| c.result)
13031303
.collect();
1304-
13051304
return if let Some(response) = self.try_merge_responses(&where_bounds) {
13061305
Ok((response, Some(TraitGoalProvenVia::ParamEnv)))
13071306
} else {
@@ -1322,9 +1321,18 @@ where
13221321
};
13231322
}
13241323

1324+
// If there are *only* global where bounds, then make sure to return that this
1325+
// is still reported as being proven-via the param-env so that rigid projections
1326+
// operate correctly.
1327+
let proven_via =
1328+
if candidates.iter().all(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1329+
TraitGoalProvenVia::ParamEnv
1330+
} else {
1331+
TraitGoalProvenVia::Misc
1332+
};
13251333
let all_candidates: Vec<_> = candidates.into_iter().map(|c| c.result).collect();
13261334
if let Some(response) = self.try_merge_responses(&all_candidates) {
1327-
Ok((response, Some(TraitGoalProvenVia::Misc)))
1335+
Ok((response, Some(proven_via)))
13281336
} else {
13291337
self.flounder(&all_candidates).map(|r| (r, None))
13301338
}

compiler/rustc_smir/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ rustc_session = { path = "../rustc_session" }
1414
rustc_span = { path = "../rustc_span" }
1515
rustc_target = { path = "../rustc_target" }
1616
scoped-tls = "1.0"
17-
stable_mir = {path = "../stable_mir" }
17+
serde = { version = "1.0.125", features = [ "derive" ] }
1818
tracing = "0.1"
1919
# tidy-alphabetical-end

compiler/rustc_smir/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ pub mod rustc_internal;
2222

2323
// Make this module private for now since external users should not call these directly.
2424
mod rustc_smir;
25+
26+
pub mod stable_mir;

compiler/rustc_smir/src/rustc_internal/internal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use stable_mir::{CrateItem, CrateNum, DefId};
2121

2222
use super::RustcInternal;
2323
use crate::rustc_smir::Tables;
24+
use crate::stable_mir;
2425

2526
impl RustcInternal for CrateItem {
2627
type T<'tcx> = rustc_span::def_id::DefId;

compiler/rustc_smir/src/rustc_internal/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use stable_mir::ty::IndexedVal;
2222

2323
use crate::rustc_smir::context::TablesWrapper;
2424
use crate::rustc_smir::{Stable, Tables};
25+
use crate::stable_mir;
2526

2627
mod internal;
2728
pub mod pretty;

compiler/rustc_smir/src/rustc_internal/pretty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::io;
33
use rustc_middle::ty::TyCtxt;
44

55
use super::run;
6+
use crate::stable_mir;
67

78
pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io::Result<()> {
89
writeln!(

compiler/rustc_smir/src/rustc_smir/alloc.rs

+13-26
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use stable_mir::mir::Mutability;
66
use stable_mir::ty::{Allocation, ProvenanceMap};
77

88
use crate::rustc_smir::{Stable, Tables};
9+
use crate::stable_mir;
910

1011
/// Creates new empty `Allocation` from given `Align`.
1112
fn new_empty_allocation(align: Align) -> Allocation {
@@ -27,7 +28,7 @@ pub(crate) fn new_allocation<'tcx>(
2728
tables: &mut Tables<'tcx>,
2829
) -> Allocation {
2930
try_new_allocation(ty, const_value, tables)
30-
.expect(&format!("Failed to convert: {const_value:?} to {ty:?}"))
31+
.unwrap_or_else(|_| panic!("Failed to convert: {const_value:?} to {ty:?}"))
3132
}
3233

3334
#[allow(rustc::usage_of_qualified_ty)]
@@ -36,39 +37,30 @@ pub(crate) fn try_new_allocation<'tcx>(
3637
const_value: ConstValue<'tcx>,
3738
tables: &mut Tables<'tcx>,
3839
) -> Result<Allocation, Error> {
40+
let layout = tables
41+
.tcx
42+
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
43+
.map_err(|e| e.stable(tables))?;
3944
Ok(match const_value {
4045
ConstValue::Scalar(scalar) => {
4146
let size = scalar.size();
42-
let align = tables
43-
.tcx
44-
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
45-
.map_err(|e| e.stable(tables))?
46-
.align;
47-
let mut allocation =
48-
rustc_middle::mir::interpret::Allocation::new(size, align.abi, AllocInit::Uninit);
47+
let mut allocation = rustc_middle::mir::interpret::Allocation::new(
48+
size,
49+
layout.align.abi,
50+
AllocInit::Uninit,
51+
);
4952
allocation
5053
.write_scalar(&tables.tcx, alloc_range(Size::ZERO, size), scalar)
5154
.map_err(|e| e.stable(tables))?;
5255
allocation.stable(tables)
5356
}
54-
ConstValue::ZeroSized => {
55-
let align = tables
56-
.tcx
57-
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
58-
.map_err(|e| e.stable(tables))?
59-
.align;
60-
new_empty_allocation(align.abi)
61-
}
57+
ConstValue::ZeroSized => new_empty_allocation(layout.align.abi),
6258
ConstValue::Slice { data, meta } => {
6359
let alloc_id = tables.tcx.reserve_and_set_memory_alloc(data);
6460
let ptr = Pointer::new(alloc_id.into(), Size::ZERO);
6561
let scalar_ptr = rustc_middle::mir::interpret::Scalar::from_pointer(ptr, &tables.tcx);
6662
let scalar_meta =
6763
rustc_middle::mir::interpret::Scalar::from_target_usize(meta, &tables.tcx);
68-
let layout = tables
69-
.tcx
70-
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
71-
.map_err(|e| e.stable(tables))?;
7264
let mut allocation = rustc_middle::mir::interpret::Allocation::new(
7365
layout.size,
7466
layout.align.abi,
@@ -92,12 +84,7 @@ pub(crate) fn try_new_allocation<'tcx>(
9284
}
9385
ConstValue::Indirect { alloc_id, offset } => {
9486
let alloc = tables.tcx.global_alloc(alloc_id).unwrap_memory();
95-
let ty_size = tables
96-
.tcx
97-
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
98-
.map_err(|e| e.stable(tables))?
99-
.size;
100-
allocation_filter(&alloc.0, alloc_range(offset, ty_size), tables)
87+
allocation_filter(&alloc.0, alloc_range(offset, layout.size), tables)
10188
}
10289
})
10390
}

compiler/rustc_smir/src/rustc_smir/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::mir::visit::MutVisitor;
1010
use rustc_middle::ty::{self, TyCtxt};
1111

1212
use crate::rustc_smir::{Stable, Tables};
13+
use crate::stable_mir;
1314

1415
/// Builds a monomorphic body for a given instance.
1516
pub(crate) struct BodyBuilder<'tcx> {

compiler/rustc_smir/src/rustc_smir/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use stable_mir::{Crate, CrateDef, CrateItem, CrateNum, DefId, Error, Filename, I
3535
use crate::rustc_internal::RustcInternal;
3636
use crate::rustc_smir::builder::BodyBuilder;
3737
use crate::rustc_smir::{Stable, Tables, alloc, filter_def_ids, new_item_kind, smir_crate};
38+
use crate::stable_mir;
3839

3940
impl<'tcx> Context for TablesWrapper<'tcx> {
4041
fn target_info(&self) -> MachineInfo {

compiler/rustc_smir/src/rustc_smir/convert/abi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use stable_mir::target::MachineSize as Size;
1414
use stable_mir::ty::{Align, IndexedVal, VariantIdx};
1515

1616
use crate::rustc_smir::{Stable, Tables};
17+
use crate::stable_mir;
1718

1819
impl<'tcx> Stable<'tcx> for rustc_abi::VariantIdx {
1920
type T = VariantIdx;

compiler/rustc_smir/src/rustc_smir/convert/error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_middle::mir::interpret::AllocError;
66
use rustc_middle::ty::layout::LayoutError;
77

88
use crate::rustc_smir::{Stable, Tables};
9+
use crate::stable_mir;
910

1011
impl<'tcx> Stable<'tcx> for LayoutError<'tcx> {
1112
type T = stable_mir::Error;

compiler/rustc_smir/src/rustc_smir/convert/mir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use stable_mir::ty::{Allocation, ConstantKind, MirConst};
99
use stable_mir::{Error, opaque};
1010

1111
use crate::rustc_smir::{Stable, Tables, alloc};
12+
use crate::stable_mir;
1213

1314
impl<'tcx> Stable<'tcx> for mir::Body<'tcx> {
1415
type T = stable_mir::mir::Body;

compiler/rustc_smir/src/rustc_smir/convert/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use rustc_abi::FieldIdx;
44

55
use crate::rustc_smir::{Stable, Tables};
6+
use crate::stable_mir;
67

78
mod abi;
89
mod error;

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use stable_mir::ty::{
77
};
88

99
use crate::rustc_smir::{Stable, Tables, alloc};
10+
use crate::stable_mir;
1011

1112
impl<'tcx> Stable<'tcx> for ty::AliasTyKind {
1213
type T = stable_mir::ty::AliasKind;

compiler/rustc_smir/src/rustc_smir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use stable_mir::{CtorKind, ItemKind};
2121
use tracing::debug;
2222

2323
use crate::rustc_internal::IndexMap;
24+
use crate::stable_mir;
2425

2526
mod alloc;
2627
mod builder;

compiler/stable_mir/src/abi.rs renamed to compiler/rustc_smir/src/stable_mir/abi.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use std::num::NonZero;
33
use std::ops::RangeInclusive;
44

55
use serde::Serialize;
6+
use stable_mir::compiler_interface::with;
7+
use stable_mir::mir::FieldIdx;
8+
use stable_mir::target::{MachineInfo, MachineSize as Size};
9+
use stable_mir::ty::{Align, IndexedVal, Ty, VariantIdx};
10+
use stable_mir::{Error, Opaque, error};
611

7-
use crate::compiler_interface::with;
8-
use crate::mir::FieldIdx;
9-
use crate::target::{MachineInfo, MachineSize as Size};
10-
use crate::ty::{Align, IndexedVal, Ty, VariantIdx};
11-
use crate::{Error, Opaque, error};
12+
use crate::stable_mir;
1213

1314
/// A function ABI definition.
1415
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
@@ -149,7 +150,7 @@ pub enum FieldsShape {
149150
Arbitrary {
150151
/// Offsets for the first byte of each field,
151152
/// ordered to match the source definition order.
152-
/// I.e.: It follows the same order as [crate::ty::VariantDef::fields()].
153+
/// I.e.: It follows the same order as [super::ty::VariantDef::fields()].
153154
/// This vector does not go in increasing order.
154155
offsets: Vec<Size>,
155156
},

compiler/stable_mir/src/compiler_interface.rs renamed to compiler/rustc_smir/src/stable_mir/compiler_interface.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
66
use std::cell::Cell;
77

8-
use crate::abi::{FnAbi, Layout, LayoutShape};
9-
use crate::crate_def::Attribute;
10-
use crate::mir::alloc::{AllocId, GlobalAlloc};
11-
use crate::mir::mono::{Instance, InstanceDef, StaticDef};
12-
use crate::mir::{BinOp, Body, Place, UnOp};
13-
use crate::target::MachineInfo;
14-
use crate::ty::{
8+
use stable_mir::abi::{FnAbi, Layout, LayoutShape};
9+
use stable_mir::crate_def::Attribute;
10+
use stable_mir::mir::alloc::{AllocId, GlobalAlloc};
11+
use stable_mir::mir::mono::{Instance, InstanceDef, StaticDef};
12+
use stable_mir::mir::{BinOp, Body, Place, UnOp};
13+
use stable_mir::target::MachineInfo;
14+
use stable_mir::ty::{
1515
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, FieldDef, FnDef, ForeignDef,
1616
ForeignItemKind, ForeignModule, ForeignModuleDef, GenericArgs, GenericPredicates, Generics,
1717
ImplDef, ImplTrait, IntrinsicDef, LineInfo, MirConst, PolyFnSig, RigidTy, Span, TraitDecl,
1818
TraitDef, Ty, TyConst, TyConstId, TyKind, UintTy, VariantDef,
1919
};
20-
use crate::{
20+
use stable_mir::{
2121
AssocItems, Crate, CrateItem, CrateItems, CrateNum, DefId, Error, Filename, ImplTraitDecls,
2222
ItemKind, Symbol, TraitDecls, mir,
2323
};
2424

25+
use crate::stable_mir;
26+
2527
/// This trait defines the interface between stable_mir and the Rust compiler.
2628
/// Do not use this directly.
2729
pub trait Context {

compiler/stable_mir/src/crate_def.rs renamed to compiler/rustc_smir/src/stable_mir/crate_def.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
//! such as, a function, a trait, an enum, and any other definitions.
33
44
use serde::Serialize;
5+
use stable_mir::ty::{GenericArgs, Span, Ty};
6+
use stable_mir::{AssocItems, Crate, Symbol, with};
57

6-
use crate::ty::{GenericArgs, Span, Ty};
7-
use crate::{AssocItems, Crate, Symbol, with};
8+
use crate::stable_mir;
89

910
/// A unique identification number for each item accessible for the current compilation unit.
1011
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize)]

compiler/stable_mir/src/mir/alloc.rs renamed to compiler/rustc_smir/src/stable_mir/mir/alloc.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
use std::io::Read;
44

55
use serde::Serialize;
6+
use stable_mir::mir::mono::{Instance, StaticDef};
7+
use stable_mir::target::{Endian, MachineInfo};
8+
use stable_mir::ty::{Allocation, Binder, ExistentialTraitRef, IndexedVal, Ty};
9+
use stable_mir::{Error, with};
610

7-
use crate::mir::mono::{Instance, StaticDef};
8-
use crate::target::{Endian, MachineInfo};
9-
use crate::ty::{Allocation, Binder, ExistentialTraitRef, IndexedVal, Ty};
10-
use crate::{Error, with};
11+
use crate::stable_mir;
1112

1213
/// An allocation in the SMIR global memory can be either a function pointer,
1314
/// a static, or a "real" allocation with some data in it.

compiler/stable_mir/src/mir/body.rs renamed to compiler/rustc_smir/src/stable_mir/mir/body.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::io;
22

33
use serde::Serialize;
4-
5-
use crate::compiler_interface::with;
6-
use crate::mir::pretty::function_body;
7-
use crate::ty::{
4+
use stable_mir::compiler_interface::with;
5+
use stable_mir::mir::pretty::function_body;
6+
use stable_mir::ty::{
87
AdtDef, ClosureDef, CoroutineClosureDef, CoroutineDef, GenericArgs, MirConst, Movability,
98
Region, RigidTy, Ty, TyConst, TyKind, VariantIdx,
109
};
11-
use crate::{Error, Opaque, Span, Symbol};
10+
use stable_mir::{Error, Opaque, Span, Symbol};
11+
12+
use crate::stable_mir;
1213

1314
/// The SMIR representation of a single function.
1415
#[derive(Clone, Debug, Serialize)]
@@ -565,7 +566,7 @@ pub enum Rvalue {
565566
///
566567
/// **Needs clarification**: Are there weird additional semantics here related to the runtime
567568
/// nature of this operation?
568-
ThreadLocalRef(crate::CrateItem),
569+
ThreadLocalRef(stable_mir::CrateItem),
569570

570571
/// Computes a value as described by the operation.
571572
NullaryOp(NullOp, Ty),

0 commit comments

Comments
 (0)