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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 10 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 13 additions & 26 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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 {

0 commit comments

Comments
 (0)