Skip to content

Commit 0a136fb

Browse files
committed
Merge ref \'733108b6d4ac\' from rust-lang/rust\n\nPull recent changes from https://github.com/rust-lang/rust via Josh.\n\nUpstream ref: 733108b6d4acaa93fe26ae281ea305aacd6aac4e\nFiltered ref: f3289ac\nUpstream diff: https://github.com/rust-lang/rust/compare/...733108b6d4acaa93fe26ae281ea305aacd6aac4e\n\nThis merge was created using https://github.com/rust-lang/josh-sync.\n
2 parents 3e91a10 + f3289ac commit 0a136fb

File tree

11 files changed

+218
-23
lines changed

11 files changed

+218
-23
lines changed

rustc_public/rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "nightly-2023-06-14"
3+
components = [ "rustfmt", "rustc-dev" ]

rustc_public/src/compiler_interface.rs

Lines changed: 118 additions & 0 deletions
Large diffs are not rendered by default.

rustc_public/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
99
#![allow(rustc::usage_of_ty_tykind)]
1010
#![cfg_attr(not(feature = "rustc-build"), feature(rustc_private))]
11-
#![doc(
12-
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
13-
test(attr(allow(unused_variables), deny(warnings)))
14-
)]
11+
#![doc(test(attr(allow(unused_variables), deny(warnings), allow(internal_features))))]
1512
#![feature(sized_hierarchy)]
1613
//!
1714
//! This crate shall contain all type definitions and APIs that we expect third-party tools to invoke to

rustc_public/src/mir/body.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ pub enum StatementKind {
478478
Assign(Place, Rvalue),
479479
FakeRead(FakeReadCause, Place),
480480
SetDiscriminant { place: Place, variant_index: VariantIdx },
481-
Deinit(Place),
482481
StorageLive(Local),
483482
StorageDead(Local),
484483
Retag(RetagKind, Place),
@@ -642,11 +641,8 @@ impl Rvalue {
642641
.discriminant_ty()
643642
.ok_or_else(|| error!("Expected a `RigidTy` but found: {place_ty:?}"))
644643
}
645-
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => {
646-
Ok(Ty::usize_ty())
647-
}
648-
Rvalue::NullaryOp(NullOp::ContractChecks, _)
649-
| Rvalue::NullaryOp(NullOp::UbChecks, _) => Ok(Ty::bool_ty()),
644+
Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => Ok(Ty::usize_ty()),
645+
Rvalue::NullaryOp(NullOp::RuntimeChecks(_), _) => Ok(Ty::bool_ty()),
650646
Rvalue::Aggregate(ak, ops) => match *ak {
651647
AggregateKind::Array(ty) => Ty::try_new_array(ty, ops.len() as u64),
652648
AggregateKind::Tuple => Ok(Ty::new_tuple(
@@ -836,14 +832,6 @@ pub enum ProjectionElem {
836832
/// Like an explicit cast from an opaque type to a concrete type, but without
837833
/// requiring an intermediate variable.
838834
OpaqueCast(Ty),
839-
840-
/// A `Subtype(T)` projection is applied to any `StatementKind::Assign` where
841-
/// type of lvalue doesn't match the type of rvalue, the primary goal is making subtyping
842-
/// explicit during optimizations and codegen.
843-
///
844-
/// This projection doesn't impact the runtime behavior of the program except for potentially changing
845-
/// some type metadata of the interpreter or codegen backend.
846-
Subtype(Ty),
847835
}
848836

849837
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
@@ -1028,20 +1016,25 @@ pub enum CastKind {
10281016
PtrToPtr,
10291017
FnPtrToPtr,
10301018
Transmute,
1019+
Subtype,
10311020
}
10321021

10331022
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
10341023
pub enum NullOp {
1035-
/// Returns the size of a value of that type.
1036-
SizeOf,
1037-
/// Returns the minimum alignment of a type.
1038-
AlignOf,
10391024
/// Returns the offset of a field.
10401025
OffsetOf(Vec<(VariantIdx, FieldIdx)>),
1026+
/// Codegen conditions for runtime checks.
1027+
RuntimeChecks(RuntimeChecks),
1028+
}
1029+
1030+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
1031+
pub enum RuntimeChecks {
10411032
/// cfg!(ub_checks), but at codegen time
10421033
UbChecks,
10431034
/// cfg!(contract_checks), but at codegen time
10441035
ContractChecks,
1036+
/// cfg!(overflow_checks), but at codegen time
1037+
OverflowChecks,
10451038
}
10461039

10471040
impl Operand {
@@ -1089,7 +1082,7 @@ impl ProjectionElem {
10891082
Self::subslice_ty(ty, *from, *to, *from_end)
10901083
}
10911084
ProjectionElem::Downcast(_) => Ok(ty),
1092-
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Subtype(ty) => Ok(*ty),
1085+
ProjectionElem::OpaqueCast(ty) => Ok(*ty),
10931086
}
10941087
}
10951088

rustc_public/src/mir/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ macro_rules! make_mir_visitor {
183183
}
184184
StatementKind::Coverage(coverage) => visit_opaque(coverage),
185185
StatementKind::Intrinsic(intrisic) => match intrisic {
186+
StatementKind::Intrinsic(intrinsic) => match intrinsic {
186187
NonDivergingIntrinsic::Assume(operand) => {
187188
self.visit_operand(operand, location);
188189
}

rustc_public/src/rustc_internal/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ use rustc_span::def_id::CrateNum;
1212
use scoped_tls::scoped_thread_local;
1313

1414
use crate::Error;
15+
use std::cell::RefCell;
16+
17+
use rustc_middle::ty::TyCtxt;
18+
use rustc_public_bridge::Tables;
19+
use rustc_public_bridge::context::CompilerCtxt;
20+
use rustc_span::def_id::CrateNum;
21+
22+
use crate::Error;
23+
use crate::compiler_interface::{BridgeTys, CompilerInterface, with};
1524
use crate::unstable::{RustcInternal, Stable};
1625

1726
pub mod pretty;
@@ -29,6 +38,7 @@ pub mod pretty;
2938
/// This function will panic if rustc_public has not been properly initialized.
3039
pub fn stable<'tcx, S: Stable<'tcx>>(item: S) -> S::T {
3140
with_container(|tables, cx| item.stable(tables, cx))
41+
with_bridge(|tables, cx| item.stable(tables, cx))
3242
}
3343

3444
/// Convert a stable item into its internal Rust compiler counterpart, if one exists.
@@ -50,6 +60,7 @@ where
5060
// See https://github.com/rust-lang/rust/pull/120128/commits/9aace6723572438a94378451793ca37deb768e72
5161
// for more details.
5262
with_container(|tables, _| item.internal(tables, tcx))
63+
with_bridge(|tables, _| item.internal(tables, tcx))
5364
}
5465

5566
pub fn crate_num(item: &crate::Crate) -> CrateNum {
@@ -81,6 +92,14 @@ pub(crate) fn with_container<R, B: Bridge>(
8192
let container = ptr as *const Container<'_, B>;
8293
let mut tables = unsafe { (*container).tables.borrow_mut() };
8394
let cx = unsafe { (*container).cx.borrow() };
95+
/// Loads the current context and calls a function with it.
96+
/// Do not nest these, as that will ICE.
97+
pub(crate) fn with_bridge<R>(
98+
f: impl for<'tcx> FnOnce(&mut Tables<'tcx, BridgeTys>, &CompilerCtxt<'tcx, BridgeTys>) -> R,
99+
) -> R {
100+
with(|compiler| {
101+
let mut tables = compiler.tables.borrow_mut();
102+
let cx = compiler.cx.borrow();
84103
f(&mut *tables, &*cx)
85104
})
86105
}
@@ -93,6 +112,10 @@ where
93112
let container = Container { tables: RefCell::new(Tables::default()), cx: compiler_cx };
94113

95114
crate::compiler_interface::run(&container, || init(&container, f))
115+
let compiler_interface =
116+
CompilerInterface { tables: RefCell::new(Tables::default()), cx: compiler_cx };
117+
118+
crate::compiler_interface::run(&compiler_interface, || f())
96119
}
97120

98121
/// Instantiate and run the compiler with the provided arguments and callback.

rustc_public/src/ty.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ impl TyKind {
334334
#[inline]
335335
pub fn is_trait(&self) -> bool {
336336
matches!(self, TyKind::RigidTy(RigidTy::Dynamic(_, _, DynKind::Dyn)))
337+
matches!(self, TyKind::RigidTy(RigidTy::Dynamic(_, _)))
337338
}
338339

339340
#[inline]
@@ -473,6 +474,7 @@ impl TyKind {
473474

474475
pub fn trait_principal(&self) -> Option<Binder<ExistentialTraitRef>> {
475476
if let TyKind::RigidTy(RigidTy::Dynamic(predicates, _, _)) = self {
477+
if let TyKind::RigidTy(RigidTy::Dynamic(predicates, _)) = self {
476478
if let Some(Binder { value: ExistentialPredicate::Trait(trait_ref), bound_vars }) =
477479
predicates.first()
478480
{
@@ -563,6 +565,7 @@ pub enum RigidTy {
563565
Coroutine(CoroutineDef, GenericArgs),
564566
CoroutineClosure(CoroutineClosureDef, GenericArgs),
565567
Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind),
568+
Dynamic(Vec<Binder<ExistentialPredicate>>, Region),
566569
Never,
567570
Tuple(Vec<Ty>),
568571
CoroutineWitness(CoroutineWitnessDef, GenericArgs),
@@ -1617,6 +1620,7 @@ pub struct AssocItem {
16171620
/// If this is an item in an impl of a trait then this is the `DefId` of
16181621
/// the associated item on the trait that this implements.
16191622
pub trait_item_def_id: Option<AssocDef>,
1623+
pub container: AssocContainer,
16201624
}
16211625

16221626
#[derive(Clone, PartialEq, Debug, Eq, Serialize)]
@@ -1639,6 +1643,11 @@ pub enum AssocKind {
16391643
pub enum AssocItemContainer {
16401644
Trait,
16411645
Impl,
1646+
pub enum AssocContainer {
1647+
InherentImpl,
1648+
/// The `AssocDef` points to the trait item being implemented.
1649+
TraitImpl(AssocDef),
1650+
Trait,
16421651
}
16431652

16441653
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize)]

rustc_public/src/unstable/convert/internal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::mir::mono::{Instance, MonoItem, StaticDef};
1515
use crate::mir::{BinOp, Mutability, Place, ProjectionElem, RawPtrKind, Safety, UnOp};
1616
use crate::ty::{
1717
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, DynKind,
18+
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind,
1819
ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig,
1920
GenericArgKind, GenericArgs, IntTy, MirConst, Movability, Pattern, Region, RigidTy, Span,
2021
TermKind, TraitRef, Ty, TyConst, UintTy, VariantDef, VariantIdx,
@@ -192,6 +193,9 @@ impl RustcInternal for RigidTy {
192193
tcx.mk_poly_existential_predicates(&predicate.internal(tables, tcx)),
193194
region.internal(tables, tcx),
194195
dyn_kind.internal(tables, tcx),
196+
RigidTy::Dynamic(predicate, region) => rustc_ty::TyKind::Dynamic(
197+
tcx.mk_poly_existential_predicates(&predicate.internal(tables, tcx)),
198+
region.internal(tables, tcx),
195199
),
196200
RigidTy::Tuple(tys) => {
197201
rustc_ty::TyKind::Tuple(tcx.mk_type_list(&tys.internal(tables, tcx)))

rustc_public/src/unstable/convert/stable/mir.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ impl<'tcx> Stable<'tcx> for mir::NullOp<'tcx> {
334334
),
335335
UbChecks => crate::mir::NullOp::UbChecks,
336336
ContractChecks => crate::mir::NullOp::ContractChecks,
337+
use rustc_middle::mir::RuntimeChecks::*;
338+
match self {
339+
OffsetOf(indices) => crate::mir::NullOp::OffsetOf(
340+
indices.iter().map(|idx| idx.stable(tables, cx)).collect(),
341+
),
342+
RuntimeChecks(op) => crate::mir::NullOp::RuntimeChecks(match op {
343+
UbChecks => crate::mir::RuntimeChecks::UbChecks,
344+
ContractChecks => crate::mir::RuntimeChecks::ContractChecks,
345+
OverflowChecks => crate::mir::RuntimeChecks::OverflowChecks,
346+
}),
337347
}
338348
}
339349
}
@@ -357,6 +367,7 @@ impl<'tcx> Stable<'tcx> for mir::CastKind {
357367
PtrToPtr => crate::mir::CastKind::PtrToPtr,
358368
FnPtrToPtr => crate::mir::CastKind::FnPtrToPtr,
359369
Transmute => crate::mir::CastKind::Transmute,
370+
Subtype => crate::mir::CastKind::Subtype,
360371
}
361372
}
362373
}

rustc_public/src/unstable/convert/stable/ty.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,13 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
449449
dyn_kind.stable(tables, cx),
450450
))
451451
}
452+
ty::Dynamic(existential_predicates, region) => TyKind::RigidTy(RigidTy::Dynamic(
453+
existential_predicates
454+
.iter()
455+
.map(|existential_predicate| existential_predicate.stable(tables, cx))
456+
.collect(),
457+
region.stable(tables, cx),
458+
)),
452459
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
453460
tables.closure_def(*def_id),
454461
generic_args.stable(tables, cx),
@@ -467,6 +474,10 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
467474
}
468475
ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables, cx)),
469476
ty::Bound(debruijn_idx, bound_ty) => {
477+
ty::Bound(ty::BoundVarIndexKind::Canonical, _) => {
478+
unreachable!()
479+
}
480+
ty::Bound(ty::BoundVarIndexKind::Bound(debruijn_idx), bound_ty) => {
470481
TyKind::Bound(debruijn_idx.as_usize(), bound_ty.stable(tables, cx))
471482
}
472483
ty::CoroutineWitness(def_id, args) => TyKind::RigidTy(RigidTy::CoroutineWitness(
@@ -495,6 +506,7 @@ impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> {
495506
end: Some(end.stable(tables, cx)),
496507
include_end: true,
497508
},
509+
ty::PatternKind::NotNull => todo!(),
498510
ty::PatternKind::Or(_) => todo!(),
499511
}
500512
}
@@ -663,6 +675,13 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
663675
}
664676
ty::GenericParamDefKind::Const { has_default, synthetic: _ } => {
665677
GenericParamDefKind::Const { has_default: *has_default }
678+
match *self {
679+
ty::GenericParamDefKind::Lifetime => GenericParamDefKind::Lifetime,
680+
ty::GenericParamDefKind::Type { has_default, synthetic } => {
681+
GenericParamDefKind::Type { has_default, synthetic }
682+
}
683+
ty::GenericParamDefKind::Const { has_default } => {
684+
GenericParamDefKind::Const { has_default }
666685
}
667686
}
668687
}
@@ -921,6 +940,7 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
921940
name: early_reg.name.to_string(),
922941
}),
923942
ty::ReBound(db_index, bound_reg) => RegionKind::ReBound(
943+
ty::ReBound(ty::BoundVarIndexKind::Bound(db_index), bound_reg) => RegionKind::ReBound(
924944
db_index.as_u32(),
925945
BoundRegion {
926946
var: bound_reg.var.as_u32(),
@@ -1084,6 +1104,21 @@ impl<'tcx> Stable<'tcx> for ty::AssocItemContainer {
10841104
match self {
10851105
ty::AssocItemContainer::Trait => AssocItemContainer::Trait,
10861106
ty::AssocItemContainer::Impl => AssocItemContainer::Impl,
1107+
impl<'tcx> Stable<'tcx> for ty::AssocContainer {
1108+
type T = crate::ty::AssocContainer;
1109+
1110+
fn stable(
1111+
&self,
1112+
tables: &mut Tables<'_, BridgeTys>,
1113+
_: &CompilerCtxt<'_, BridgeTys>,
1114+
) -> Self::T {
1115+
use crate::ty::AssocContainer;
1116+
match self {
1117+
ty::AssocContainer::Trait => AssocContainer::Trait,
1118+
ty::AssocContainer::InherentImpl => AssocContainer::InherentImpl,
1119+
ty::AssocContainer::TraitImpl(trait_item_id) => {
1120+
AssocContainer::TraitImpl(tables.assoc_def(trait_item_id.unwrap()))
1121+
}
10871122
}
10881123
}
10891124
}

0 commit comments

Comments
 (0)