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 10 pull requests #121131

Merged
merged 23 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cd7c161
Add known issue of let binding to format_args doc
Stargateur May 2, 2023
2137487
Add APIs for fetching foreign items including foreign modules, their …
momvart Feb 12, 2024
a261f8e
Move windows_sys.lst to bindings.txt
ChrisDenton Nov 15, 2023
adcbeb7
Add windows_sys readme
ChrisDenton Dec 8, 2023
846315d
Automatically sort windows_sys bindings
ChrisDenton Dec 8, 2023
55f9aed
Move all the heavy lifting from `TyCtxtAt::create_def` into `TyCtxt::…
oli-obk Feb 14, 2024
fa1e35c
Remove unnecessary else block from `thread_local!` expanded code
ShoyuVanilla Feb 14, 2024
2e691a5
Rewrite foreign item kind query using `DefKind`
momvart Feb 14, 2024
01c974f
Do not report overflow errors on ConstArgHasType goals
compiler-errors Feb 14, 2024
9cccf20
Clarified docs on non-atomic oprations on owned/mut refs to atomics
peterjoel Feb 14, 2024
64a9c9c
Reinstate some delayed bugs.
nnethercote Feb 14, 2024
a8d869e
rustdoc: cross-crate re-exports: correctly render late-bound params i…
fmease Feb 13, 2024
e6a21f5
Enforce coroutine-closure layouts are identical
compiler-errors Feb 15, 2024
0238d26
Rollup merge of #111106 - Stargateur:doc/format_args, r=m-ou-se
matthiaskrgr Feb 15, 2024
0977600
Rollup merge of #118749 - ChrisDenton:winsys, r=cuviper
matthiaskrgr Feb 15, 2024
71466ca
Rollup merge of #120982 - momvart:smir-61-foreign_kind, r=oli-obk
matthiaskrgr Feb 15, 2024
f9a0675
Rollup merge of #121022 - fmease:rustdoc-x-crate-late-bound-lt-src-or…
matthiaskrgr Feb 15, 2024
e5186aa
Rollup merge of #121082 - peterjoel:atomic-docs, r=cuviper
matthiaskrgr Feb 15, 2024
f62d981
Rollup merge of #121084 - oli-obk:create_def_forever_red2, r=WaffleLa…
matthiaskrgr Feb 15, 2024
15d9e2c
Rollup merge of #121098 - ShoyuVanilla:thread-local-unnecessary-else,…
matthiaskrgr Feb 15, 2024
888fe70
Rollup merge of #121105 - compiler-errors:no-const-ty-overflow, r=oli…
matthiaskrgr Feb 15, 2024
4899108
Rollup merge of #121116 - nnethercote:fix-121103-121108, r=oli-obk
matthiaskrgr Feb 15, 2024
829b59a
Rollup merge of #121122 - compiler-errors:identical-layouts, r=oli-obk
matthiaskrgr Feb 15, 2024
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: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4588,6 +4588,7 @@ dependencies = [
"rustc_data_structures",
"rustc_hir",
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_target",
"scoped-tls",
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
}
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()),
ExprKind::Err => {
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
}
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),

ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ impl<'tcx> MirPass<'tcx> for Validator {
}
}
}

// Enforce that coroutine-closure layouts are identical.
if let Some(layout) = body.coroutine_layout()
&& let Some(by_move_body) = body.coroutine_by_move_body()
&& let Some(by_move_layout) = by_move_body.coroutine_layout()
{
if layout != by_move_layout {
// If this turns out not to be true, please let compiler-errors know.
// It is possible to support, but requires some changes to the layout
// computation code.
cfg_checker.fail(
Location::START,
format!(
"Coroutine layout differs from by-move coroutine layout:\n\
layout: {layout:#?}\n\
by_move_layout: {by_move_layout:#?}",
),
);
}
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_middle/src/mir/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ rustc_index::newtype_index! {
pub struct CoroutineSavedLocal {}
}

#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
pub struct CoroutineSavedTy<'tcx> {
pub ty: Ty<'tcx>,
/// Source info corresponding to the local in the original MIR body.
Expand All @@ -96,7 +97,8 @@ pub struct CoroutineSavedTy<'tcx> {
}

/// The layout of coroutine state.
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
#[derive(Clone, PartialEq, Eq)]
#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
pub struct CoroutineLayout<'tcx> {
/// The type of every local stored inside the coroutine.
pub field_tys: IndexVec<CoroutineSavedLocal, CoroutineSavedTy<'tcx>>,
Expand Down
30 changes: 17 additions & 13 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,22 @@ impl<'tcx> TyCtxtAt<'tcx> {
name: Symbol,
def_kind: DefKind,
) -> TyCtxtFeed<'tcx, LocalDefId> {
let feed = self.tcx.create_def(parent, name, def_kind);

feed.def_span(self.span);
feed
}
}

impl<'tcx> TyCtxt<'tcx> {
/// `tcx`-dependent operations performed for every created definition.
pub fn create_def(
self,
parent: LocalDefId,
name: Symbol,
def_kind: DefKind,
) -> TyCtxtFeed<'tcx, LocalDefId> {
let data = def_kind.def_path_data(name);
// The following call has the side effect of modifying the tables inside `definitions`.
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
// decode the on-disk cache.
Expand All @@ -1067,18 +1083,6 @@ impl<'tcx> TyCtxtAt<'tcx> {
// This is fine because:
// - those queries are `eval_always` so we won't miss their result changing;
// - this write will have happened before these queries are called.
let def_id = self.tcx.create_def(parent, name, def_kind);

let feed = self.tcx.feed_local_def_id(def_id);
feed.def_span(self.span);
feed
}
}

impl<'tcx> TyCtxt<'tcx> {
/// `tcx`-dependent operations performed for every created definition.
pub fn create_def(self, parent: LocalDefId, name: Symbol, def_kind: DefKind) -> LocalDefId {
let data = def_kind.def_path_data(name);
let def_id = self.untracked.definitions.write().create_def(parent, data);

// This function modifies `self.definitions` using a side-effect.
Expand All @@ -1098,7 +1102,7 @@ impl<'tcx> TyCtxt<'tcx> {
feed.visibility(ty::Visibility::Restricted(parent_mod));
}

def_id
feed
}

pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'tcx {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: LocalDefId) -> ConstQualifs {
let body = &tcx.mir_const(def).borrow();

if body.return_ty().references_error() {
assert!(tcx.dcx().has_errors().is_some(), "mir_const_qualif: MIR had errors");
// It's possible to reach here without an error being emitted (#121103).
tcx.dcx().span_delayed_bug(body.span, "mir_const_qualif: MIR had errors");
return Default::default();
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
);

// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
let def_id = self.tcx.create_def(parent, name, def_kind);
let def_id = self.tcx.create_def(parent, name, def_kind).def_id();

// Create the definition.
if expn_id != ExpnId::root() {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_smir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rustc_abi = { path = "../rustc_abi" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_hir = { path = "../rustc_hir" }
rustc_middle = { path = "../rustc_middle" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
scoped-tls = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ impl<'tcx> Tables<'tcx> {
stable_mir::ty::AdtDef(self.create_def_id(did))
}

pub fn foreign_module_def(&mut self, did: DefId) -> stable_mir::ty::ForeignModuleDef {
stable_mir::ty::ForeignModuleDef(self.create_def_id(did))
}

pub fn foreign_def(&mut self, did: DefId) -> stable_mir::ty::ForeignDef {
stable_mir::ty::ForeignDef(self.create_def_id(did))
}
Expand Down
54 changes: 51 additions & 3 deletions compiler/rustc_smir/src/rustc_smir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use stable_mir::mir::mono::{InstanceDef, StaticDef};
use stable_mir::mir::Body;
use stable_mir::target::{MachineInfo, MachineSize};
use stable_mir::ty::{
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, GenericArgs,
LineInfo, PolyFnSig, RigidTy, Span, Ty, TyKind, VariantDef,
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, ForeignDef,
ForeignItemKind, GenericArgs, LineInfo, PolyFnSig, RigidTy, Span, Ty, TyKind, VariantDef,
};
use stable_mir::{Crate, CrateItem, CrateNum, DefId, Error, Filename, ItemKind, Symbol};
use stable_mir::{Crate, CrateDef, CrateItem, CrateNum, DefId, Error, Filename, ItemKind, Symbol};
use std::cell::RefCell;
use std::iter;

Expand Down Expand Up @@ -67,6 +67,39 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tables.tcx.is_mir_available(def_id)
}

fn foreign_modules(&self, crate_num: CrateNum) -> Vec<stable_mir::ty::ForeignModuleDef> {
let mut tables = self.0.borrow_mut();
let tcx = tables.tcx;
tcx.foreign_modules(crate_num.internal(&mut *tables, tcx))
.keys()
.map(|mod_def_id| tables.foreign_module_def(*mod_def_id))
.collect()
}

fn foreign_module(
&self,
mod_def: stable_mir::ty::ForeignModuleDef,
) -> stable_mir::ty::ForeignModule {
let mut tables = self.0.borrow_mut();
let def_id = tables[mod_def.def_id()];
let mod_def = tables.tcx.foreign_modules(def_id.krate).get(&def_id).unwrap();
mod_def.stable(&mut *tables)
}

fn foreign_items(&self, mod_def: stable_mir::ty::ForeignModuleDef) -> Vec<ForeignDef> {
let mut tables = self.0.borrow_mut();
let def_id = tables[mod_def.def_id()];
tables
.tcx
.foreign_modules(def_id.krate)
.get(&def_id)
.unwrap()
.foreign_items
.iter()
.map(|item_def| tables.foreign_def(*item_def))
.collect()
}

fn all_trait_decls(&self) -> stable_mir::TraitDecls {
let mut tables = self.0.borrow_mut();
tables.tcx.all_traits().map(|trait_def_id| tables.trait_def(trait_def_id)).collect()
Expand Down Expand Up @@ -225,6 +258,21 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tables.tcx.is_foreign_item(tables[item])
}

fn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind {
let mut tables = self.0.borrow_mut();
let def_id = tables[def.def_id()];
let tcx = tables.tcx;
use rustc_hir::def::DefKind;
match tcx.def_kind(def_id) {
DefKind::Fn => ForeignItemKind::Fn(tables.fn_def(def_id)),
DefKind::Static(..) => ForeignItemKind::Static(tables.static_def(def_id)),
DefKind::ForeignTy => ForeignItemKind::Type(
tables.intern_ty(rustc_middle::ty::Ty::new_foreign(tcx, def_id)),
),
def_kind => unreachable!("Unexpected kind for a foreign item: {:?}", def_kind),
}
}

fn adt_kind(&self, def: AdtDef) -> AdtKind {
let mut tables = self.0.borrow_mut();
let tcx = tables.tcx;
Expand Down
80 changes: 50 additions & 30 deletions compiler/rustc_smir/src/rustc_smir/convert/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,41 +202,13 @@ where
impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> {
type T = stable_mir::ty::FnSig;
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_target::spec::abi;
use stable_mir::ty::{Abi, FnSig};
use stable_mir::ty::FnSig;

FnSig {
inputs_and_output: self.inputs_and_output.iter().map(|ty| ty.stable(tables)).collect(),
c_variadic: self.c_variadic,
unsafety: self.unsafety.stable(tables),
abi: match self.abi {
abi::Abi::Rust => Abi::Rust,
abi::Abi::C { unwind } => Abi::C { unwind },
abi::Abi::Cdecl { unwind } => Abi::Cdecl { unwind },
abi::Abi::Stdcall { unwind } => Abi::Stdcall { unwind },
abi::Abi::Fastcall { unwind } => Abi::Fastcall { unwind },
abi::Abi::Vectorcall { unwind } => Abi::Vectorcall { unwind },
abi::Abi::Thiscall { unwind } => Abi::Thiscall { unwind },
abi::Abi::Aapcs { unwind } => Abi::Aapcs { unwind },
abi::Abi::Win64 { unwind } => Abi::Win64 { unwind },
abi::Abi::SysV64 { unwind } => Abi::SysV64 { unwind },
abi::Abi::PtxKernel => Abi::PtxKernel,
abi::Abi::Msp430Interrupt => Abi::Msp430Interrupt,
abi::Abi::X86Interrupt => Abi::X86Interrupt,
abi::Abi::EfiApi => Abi::EfiApi,
abi::Abi::AvrInterrupt => Abi::AvrInterrupt,
abi::Abi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
abi::Abi::CCmseNonSecureCall => Abi::CCmseNonSecureCall,
abi::Abi::Wasm => Abi::Wasm,
abi::Abi::System { unwind } => Abi::System { unwind },
abi::Abi::RustIntrinsic => Abi::RustIntrinsic,
abi::Abi::RustCall => Abi::RustCall,
abi::Abi::PlatformIntrinsic => Abi::PlatformIntrinsic,
abi::Abi::Unadjusted => Abi::Unadjusted,
abi::Abi::RustCold => Abi::RustCold,
abi::Abi::RiscvInterruptM => Abi::RiscvInterruptM,
abi::Abi::RiscvInterruptS => Abi::RiscvInterruptS,
},
abi: self.abi.stable(tables),
}
}
}
Expand Down Expand Up @@ -832,3 +804,51 @@ impl<'tcx> Stable<'tcx> for ty::Movability {
}
}
}

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

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

impl<'tcx> Stable<'tcx> for rustc_session::cstore::ForeignModule {
type T = stable_mir::ty::ForeignModule;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
stable_mir::ty::ForeignModule {
def_id: tables.foreign_module_def(self.def_id),
abi: self.abi.stable(tables),
}
}
}
27 changes: 15 additions & 12 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,21 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
ty::PredicateKind::AliasRelate(..) => {
bug!("AliasRelate is only used by the new solver")
}
// Compute `ConstArgHasType` above the overflow check below.
// This is because this is not ever a useful obligation to report
// as the cause of an overflow.
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
DefineOpaqueTypes::No,
ct.ty(),
ty,
) {
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
Err(_) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
SelectionError::Unimplemented,
)),
}
}

// General case overflow check. Allow `process_trait_obligation`
// and `process_projection_obligation` to handle checking for
Expand Down Expand Up @@ -650,18 +665,6 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
}
}
}
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
DefineOpaqueTypes::No,
ct.ty(),
ty,
) {
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
Err(_) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
SelectionError::Unimplemented,
)),
}
}
},
}
}
Expand Down
Loading
Loading