Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #118679

Merged
merged 20 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c7d8c65
docs: clarify explicitly freeing heap allocated memory
0xalpharush Nov 4, 2023
efaf425
Add Variant and a few more APIs to stable_mir
celinval Dec 1, 2023
e19c7cd
Finish implementing `RustcInternal` for `TyKind`
celinval Dec 1, 2023
1720b10
Add FieldDef to StableMIR and methods to get type
celinval Dec 5, 2023
1a7b610
Add riscv32 imafc bare metal target
MabezDev Nov 13, 2023
68ea621
add comment about keeping flags in sync between bootstrap.py and boot…
RalfJung Dec 5, 2023
326fea0
Change ty_with_args to return Ty instead of Result
celinval Dec 5, 2023
6c3879d
Provide context when `?` can't be called because of `Result<_, E>`
estebank Oct 6, 2023
5381796
Point at fewer methods in the chain, only those that change the E type
estebank Oct 7, 2023
98e5317
Detect incorrect `;` in `Option::ok_or_else` and `Result::map_err`
estebank Oct 7, 2023
70fe624
Reduce verbosity of error
estebank Oct 7, 2023
dc0f7a1
docs: remove #110800 from release notes
notriddle Dec 6, 2023
7ff9648
library: fix comment about const assert in win api
klensy Dec 6, 2023
f1e1804
Rollup merge of #116496 - estebank:question-method-chain-context, r=c…
matthiaskrgr Dec 6, 2023
49d6594
Rollup merge of #117563 - 0xalpharush:docs/into-raw, r=workingjubilee
matthiaskrgr Dec 6, 2023
df6bc93
Rollup merge of #117874 - esp-rs:riscv3264imafc-unknown-none-elf, r=d…
matthiaskrgr Dec 6, 2023
67d8999
Rollup merge of #118516 - celinval:smir-variants, r=ouz-a
matthiaskrgr Dec 6, 2023
756bc44
Rollup merge of #118650 - RalfJung:flags-sync, r=clubby789
matthiaskrgr Dec 6, 2023
95efc0d
Rollup merge of #118664 - notriddle:master, r=Mark-Simulacrum
matthiaskrgr Dec 6, 2023
2f71a44
Rollup merge of #118669 - klensy:comment-fix, r=workingjubilee
matthiaskrgr Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Rustdoc
-------

- [Add warning block support in rustdoc](https://github.com/rust-lang/rust/pull/106561/)
- [Accept additional user-defined syntax classes in fenced code blocks](https://github.com/rust-lang/rust/pull/110800/)
- [rustdoc-search: add support for type parameters](https://github.com/rust-lang/rust/pull/112725/)
- [rustdoc: show inner enum and struct in type definition for concrete type](https://github.com/rust-lang/rust/pull/114855/)

Expand Down
213 changes: 199 additions & 14 deletions compiler/rustc_smir/src/rustc_internal/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy};
use rustc_span::Symbol;
use stable_mir::mir::alloc::AllocId;
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
use stable_mir::mir::{Mutability, Safety};
use stable_mir::ty::{
AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
ExistentialTraitRef, FloatTy, GenericArgKind, GenericArgs, IntTy, Region, RigidTy, Span,
TraitRef, Ty, UintTy,
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
DynKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig,
GenericArgKind, GenericArgs, IndexedVal, IntTy, Movability, Region, RigidTy, Span, TermKind,
TraitRef, Ty, UintTy, VariantDef, VariantIdx,
};
use stable_mir::{CrateItem, DefId};

Expand Down Expand Up @@ -84,17 +86,38 @@ impl<'tcx> RustcInternal<'tcx> for RigidTy {
}
RigidTy::Str => rustc_ty::TyKind::Str,
RigidTy::Slice(ty) => rustc_ty::TyKind::Slice(ty.internal(tables)),
RigidTy::RawPtr(..)
| RigidTy::Ref(..)
| RigidTy::Foreign(_)
| RigidTy::FnDef(_, _)
| RigidTy::FnPtr(_)
| RigidTy::Closure(..)
| RigidTy::Coroutine(..)
| RigidTy::CoroutineWitness(..)
| RigidTy::Dynamic(..)
| RigidTy::Tuple(..) => {
todo!()
RigidTy::RawPtr(ty, mutability) => rustc_ty::TyKind::RawPtr(rustc_ty::TypeAndMut {
ty: ty.internal(tables),
mutbl: mutability.internal(tables),
}),
RigidTy::Ref(region, ty, mutability) => rustc_ty::TyKind::Ref(
region.internal(tables),
ty.internal(tables),
mutability.internal(tables),
),
RigidTy::Foreign(def) => rustc_ty::TyKind::Foreign(def.0.internal(tables)),
RigidTy::FnDef(def, args) => {
rustc_ty::TyKind::FnDef(def.0.internal(tables), args.internal(tables))
}
RigidTy::FnPtr(sig) => rustc_ty::TyKind::FnPtr(sig.internal(tables)),
RigidTy::Closure(def, args) => {
rustc_ty::TyKind::Closure(def.0.internal(tables), args.internal(tables))
}
RigidTy::Coroutine(def, args, mov) => rustc_ty::TyKind::Coroutine(
def.0.internal(tables),
args.internal(tables),
mov.internal(tables),
),
RigidTy::CoroutineWitness(def, args) => {
rustc_ty::TyKind::CoroutineWitness(def.0.internal(tables), args.internal(tables))
}
RigidTy::Dynamic(predicate, region, dyn_kind) => rustc_ty::TyKind::Dynamic(
tables.tcx.mk_poly_existential_predicates(&predicate.internal(tables)),
region.internal(tables),
dyn_kind.internal(tables),
),
RigidTy::Tuple(tys) => {
rustc_ty::TyKind::Tuple(tables.tcx.mk_type_list(&tys.internal(tables)))
}
}
}
Expand Down Expand Up @@ -141,6 +164,57 @@ impl<'tcx> RustcInternal<'tcx> for FloatTy {
}
}

impl<'tcx> RustcInternal<'tcx> for Mutability {
type T = rustc_ty::Mutability;

fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
match self {
Mutability::Not => rustc_ty::Mutability::Not,
Mutability::Mut => rustc_ty::Mutability::Mut,
}
}
}

impl<'tcx> RustcInternal<'tcx> for Movability {
type T = rustc_ty::Movability;

fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
match self {
Movability::Static => rustc_ty::Movability::Static,
Movability::Movable => rustc_ty::Movability::Movable,
}
}
}

impl<'tcx> RustcInternal<'tcx> for FnSig {
type T = rustc_ty::FnSig<'tcx>;

fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
rustc_ty::FnSig {
inputs_and_output: tables.tcx.mk_type_list(&self.inputs_and_output.internal(tables)),
c_variadic: self.c_variadic,
unsafety: self.unsafety.internal(tables),
abi: self.abi.internal(tables),
}
}
}

impl<'tcx> RustcInternal<'tcx> for VariantIdx {
type T = rustc_target::abi::VariantIdx;

fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
rustc_target::abi::VariantIdx::from(self.to_index())
}
}

impl<'tcx> RustcInternal<'tcx> for VariantDef {
type T = &'tcx rustc_ty::VariantDef;

fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
self.adt_def.internal(tables).variant(self.idx.internal(tables))
}
}

fn ty_const<'tcx>(constant: &Const, tables: &mut Tables<'tcx>) -> rustc_ty::Const<'tcx> {
match constant.internal(tables) {
rustc_middle::mir::Const::Ty(c) => c,
Expand Down Expand Up @@ -230,6 +304,58 @@ impl<'tcx> RustcInternal<'tcx> for BoundVariableKind {
}
}

impl<'tcx> RustcInternal<'tcx> for DynKind {
type T = rustc_ty::DynKind;

fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
match self {
DynKind::Dyn => rustc_ty::DynKind::Dyn,
DynKind::DynStar => rustc_ty::DynKind::DynStar,
}
}
}

impl<'tcx> RustcInternal<'tcx> for ExistentialPredicate {
type T = rustc_ty::ExistentialPredicate<'tcx>;

fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
match self {
ExistentialPredicate::Trait(trait_ref) => {
rustc_ty::ExistentialPredicate::Trait(trait_ref.internal(tables))
}
ExistentialPredicate::Projection(proj) => {
rustc_ty::ExistentialPredicate::Projection(proj.internal(tables))
}
ExistentialPredicate::AutoTrait(trait_def) => {
rustc_ty::ExistentialPredicate::AutoTrait(trait_def.0.internal(tables))
}
}
}
}

impl<'tcx> RustcInternal<'tcx> for ExistentialProjection {
type T = rustc_ty::ExistentialProjection<'tcx>;

fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
rustc_ty::ExistentialProjection {
def_id: self.def_id.0.internal(tables),
args: self.generic_args.internal(tables),
term: self.term.internal(tables),
}
}
}

impl<'tcx> RustcInternal<'tcx> for TermKind {
type T = rustc_ty::Term<'tcx>;

fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
match self {
TermKind::Type(ty) => ty.internal(tables).into(),
TermKind::Const(const_) => ty_const(const_, tables).into(),
}
}
}

impl<'tcx> RustcInternal<'tcx> for ExistentialTraitRef {
type T = rustc_ty::ExistentialTraitRef<'tcx>;

Expand Down Expand Up @@ -279,6 +405,53 @@ impl<'tcx> RustcInternal<'tcx> for AdtDef {
}
}

impl<'tcx> RustcInternal<'tcx> for Abi {
type T = rustc_target::spec::abi::Abi;

fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
match *self {
Abi::Rust => rustc_target::spec::abi::Abi::Rust,
Abi::C { unwind } => rustc_target::spec::abi::Abi::C { unwind },
Abi::Cdecl { unwind } => rustc_target::spec::abi::Abi::Cdecl { unwind },
Abi::Stdcall { unwind } => rustc_target::spec::abi::Abi::Stdcall { unwind },
Abi::Fastcall { unwind } => rustc_target::spec::abi::Abi::Fastcall { unwind },
Abi::Vectorcall { unwind } => rustc_target::spec::abi::Abi::Vectorcall { unwind },
Abi::Thiscall { unwind } => rustc_target::spec::abi::Abi::Thiscall { unwind },
Abi::Aapcs { unwind } => rustc_target::spec::abi::Abi::Aapcs { unwind },
Abi::Win64 { unwind } => rustc_target::spec::abi::Abi::Win64 { unwind },
Abi::SysV64 { unwind } => rustc_target::spec::abi::Abi::SysV64 { unwind },
Abi::PtxKernel => rustc_target::spec::abi::Abi::PtxKernel,
Abi::Msp430Interrupt => rustc_target::spec::abi::Abi::Msp430Interrupt,
Abi::X86Interrupt => rustc_target::spec::abi::Abi::X86Interrupt,
Abi::AmdGpuKernel => rustc_target::spec::abi::Abi::AmdGpuKernel,
Abi::EfiApi => rustc_target::spec::abi::Abi::EfiApi,
Abi::AvrInterrupt => rustc_target::spec::abi::Abi::AvrInterrupt,
Abi::AvrNonBlockingInterrupt => rustc_target::spec::abi::Abi::AvrNonBlockingInterrupt,
Abi::CCmseNonSecureCall => rustc_target::spec::abi::Abi::CCmseNonSecureCall,
Abi::Wasm => rustc_target::spec::abi::Abi::Wasm,
Abi::System { unwind } => rustc_target::spec::abi::Abi::System { unwind },
Abi::RustIntrinsic => rustc_target::spec::abi::Abi::RustIntrinsic,
Abi::RustCall => rustc_target::spec::abi::Abi::RustCall,
Abi::PlatformIntrinsic => rustc_target::spec::abi::Abi::PlatformIntrinsic,
Abi::Unadjusted => rustc_target::spec::abi::Abi::Unadjusted,
Abi::RustCold => rustc_target::spec::abi::Abi::RustCold,
Abi::RiscvInterruptM => rustc_target::spec::abi::Abi::RiscvInterruptM,
Abi::RiscvInterruptS => rustc_target::spec::abi::Abi::RiscvInterruptS,
}
}
}

impl<'tcx> RustcInternal<'tcx> for Safety {
type T = rustc_hir::Unsafety;

fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
match self {
Safety::Unsafe => rustc_hir::Unsafety::Unsafe,
Safety::Normal => rustc_hir::Unsafety::Normal,
}
}
}

impl<'tcx> RustcInternal<'tcx> for Span {
type T = rustc_span::Span;

Expand All @@ -297,6 +470,7 @@ where
(*self).internal(tables)
}
}

impl<'tcx, T> RustcInternal<'tcx> for Option<T>
where
T: RustcInternal<'tcx>,
Expand All @@ -307,3 +481,14 @@ where
self.as_ref().map(|inner| inner.internal(tables))
}
}

impl<'tcx, T> RustcInternal<'tcx> for Vec<T>
where
T: RustcInternal<'tcx>,
{
type T = Vec<T::T>;

fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
self.iter().map(|e| e.internal(tables)).collect()
}
}
26 changes: 24 additions & 2 deletions compiler/rustc_smir/src/rustc_smir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use stable_mir::mir::alloc::GlobalAlloc;
use stable_mir::mir::mono::{InstanceDef, StaticDef};
use stable_mir::mir::Body;
use stable_mir::ty::{
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FnDef, GenericArgs, LineInfo,
PolyFnSig, RigidTy, Span, TyKind,
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, GenericArgs,
LineInfo, PolyFnSig, RigidTy, Span, TyKind, VariantDef,
};
use stable_mir::{self, Crate, CrateItem, DefId, Error, Filename, ItemKind, Symbol};
use std::cell::RefCell;
Expand Down Expand Up @@ -209,6 +209,21 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
sig.stable(&mut *tables)
}

fn adt_variants_len(&self, def: AdtDef) -> usize {
let mut tables = self.0.borrow_mut();
def.internal(&mut *tables).variants().len()
}

fn variant_name(&self, def: VariantDef) -> Symbol {
let mut tables = self.0.borrow_mut();
def.internal(&mut *tables).name.to_string()
}

fn variant_fields(&self, def: VariantDef) -> Vec<FieldDef> {
let mut tables = self.0.borrow_mut();
def.internal(&mut *tables).fields.iter().map(|f| f.stable(&mut *tables)).collect()
}

fn eval_target_usize(&self, cnst: &Const) -> Result<u64, Error> {
let mut tables = self.0.borrow_mut();
let mir_const = cnst.internal(&mut *tables);
Expand Down Expand Up @@ -240,6 +255,13 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tables.tcx.type_of(item.internal(&mut *tables)).instantiate_identity().stable(&mut *tables)
}

fn def_ty_with_args(&self, item: stable_mir::DefId, args: &GenericArgs) -> stable_mir::ty::Ty {
let mut tables = self.0.borrow_mut();
let args = args.internal(&mut *tables);
let def_ty = tables.tcx.type_of(item.internal(&mut *tables));
def_ty.instantiate(tables.tcx, args).stable(&mut *tables)
}

fn const_literal(&self, cnst: &stable_mir::ty::Const) -> String {
internal(cnst).to_string()
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/rustc_smir/convert/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
mir::AggregateKind::Adt(def_id, var_idx, generic_arg, user_ty_index, field_idx) => {
stable_mir::mir::AggregateKind::Adt(
tables.adt_def(*def_id),
var_idx.index(),
var_idx.stable(tables),
generic_arg.stable(tables),
user_ty_index.map(|idx| idx.index()),
field_idx.map(|idx| idx.index()),
Expand Down
19 changes: 10 additions & 9 deletions compiler/rustc_smir/src/rustc_smir/convert/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Conversion of internal Rust compiler items to stable ones.

use rustc_target::abi::FieldIdx;
use stable_mir::mir::VariantIdx;
use stable_mir::ty::{IndexedVal, VariantIdx};

use crate::rustc_smir::{Stable, Tables};

Expand All @@ -25,17 +25,10 @@ impl<'tcx> Stable<'tcx> for FieldIdx {
}
}

impl<'tcx> Stable<'tcx> for (rustc_target::abi::VariantIdx, FieldIdx) {
type T = (usize, usize);
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
(self.0.as_usize(), self.1.as_usize())
}
}

impl<'tcx> Stable<'tcx> for rustc_target::abi::VariantIdx {
type T = VariantIdx;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
self.as_usize()
VariantIdx::to_val(self.as_usize())
}
}

Expand Down Expand Up @@ -67,6 +60,14 @@ impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind {
}
}

impl<'tcx> Stable<'tcx> for rustc_span::Symbol {
type T = stable_mir::Symbol;

fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
self.to_string()
}
}

impl<'tcx> Stable<'tcx> for rustc_span::Span {
type T = stable_mir::ty::Span;

Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_smir/src/rustc_smir/convert/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ impl<'tcx> Stable<'tcx> for ty::AdtKind {
}
}

impl<'tcx> Stable<'tcx> for ty::FieldDef {
type T = stable_mir::ty::FieldDef;

fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
stable_mir::ty::FieldDef {
def: tables.create_def_id(self.did),
name: self.name.stable(tables),
}
}
}

impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> {
type T = stable_mir::ty::GenericArgs;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
Expand Down
Loading
Loading