Skip to content

Commit 10ee529

Browse files
committed
Auto merge of #119144 - compiler-errors:rollup-uhlhzvn, r=compiler-errors
Rollup of 4 pull requests Successful merges: - #119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - #119094 (Add function ABI and type layout to StableMIR) - #119102 (Add arm-none-eabi and armv7r-none-eabi platform-support documentation.) - #119107 (subtype_predicate: remove unnecessary probe) Failed merges: - #119141 (Add method to get instance instantiation arguments) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f704f3b + 8924fa5 commit 10ee529

File tree

22 files changed

+980
-144
lines changed

22 files changed

+980
-144
lines changed

compiler/rustc_infer/src/infer/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
713713
}
714714

715715
impl<'tcx, T> InferOk<'tcx, T> {
716-
pub fn unit(self) -> InferOk<'tcx, ()> {
717-
InferOk { value: (), obligations: self.obligations }
718-
}
719-
720716
/// Extracts `value`, registering any obligations into `fulfill_cx`.
721717
pub fn into_value_registering_obligations(
722718
self,
@@ -1025,15 +1021,10 @@ impl<'tcx> InferCtxt<'tcx> {
10251021
_ => {}
10261022
}
10271023

1028-
Ok(self.commit_if_ok(|_snapshot| {
1029-
let ty::SubtypePredicate { a_is_expected, a, b } =
1030-
self.instantiate_binder_with_placeholders(predicate);
1031-
1032-
let ok =
1033-
self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b)?;
1024+
let ty::SubtypePredicate { a_is_expected, a, b } =
1025+
self.instantiate_binder_with_placeholders(predicate);
10341026

1035-
Ok(ok.unit())
1036-
}))
1027+
Ok(self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b))
10371028
}
10381029

10391030
pub fn region_outlives_predicate(

compiler/rustc_smir/src/rustc_internal/internal.rs

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use crate::rustc_smir::Tables;
88
use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy};
99
use rustc_span::Symbol;
10+
use stable_mir::abi::Layout;
1011
use stable_mir::mir::alloc::AllocId;
1112
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
1213
use stable_mir::mir::{Mutability, Safety};
@@ -460,6 +461,14 @@ impl<'tcx> RustcInternal<'tcx> for Span {
460461
}
461462
}
462463

464+
impl<'tcx> RustcInternal<'tcx> for Layout {
465+
type T = rustc_target::abi::Layout<'tcx>;
466+
467+
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
468+
tables.layouts[*self]
469+
}
470+
}
471+
463472
impl<'tcx, T> RustcInternal<'tcx> for &T
464473
where
465474
T: RustcInternal<'tcx>,

compiler/rustc_smir/src/rustc_internal/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_middle::ty::TyCtxt;
1212
use rustc_span::def_id::{CrateNum, DefId};
1313
use rustc_span::Span;
1414
use scoped_tls::scoped_thread_local;
15+
use stable_mir::abi::Layout;
1516
use stable_mir::ty::IndexedVal;
1617
use stable_mir::Error;
1718
use std::cell::Cell;
@@ -136,6 +137,10 @@ impl<'tcx> Tables<'tcx> {
136137
pub(crate) fn static_def(&mut self, did: DefId) -> stable_mir::mir::mono::StaticDef {
137138
stable_mir::mir::mono::StaticDef(self.create_def_id(did))
138139
}
140+
141+
pub(crate) fn layout_id(&mut self, layout: rustc_target::abi::Layout<'tcx>) -> Layout {
142+
self.layouts.create_or_fetch(layout)
143+
}
139144
}
140145

141146
pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
@@ -180,6 +185,7 @@ where
180185
types: IndexMap::default(),
181186
instances: IndexMap::default(),
182187
constants: IndexMap::default(),
188+
layouts: IndexMap::default(),
183189
}));
184190
stable_mir::compiler_interface::run(&tables, || init(&tables, f))
185191
}

compiler/rustc_smir/src/rustc_smir/context.rs

+73-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
//! This trait is currently the main interface between the Rust compiler,
44
//! and the `stable_mir` crate.
55
6+
#![allow(rustc::usage_of_qualified_ty)]
7+
8+
use rustc_abi::HasDataLayout;
69
use rustc_middle::ty;
10+
use rustc_middle::ty::layout::{
11+
FnAbiOf, FnAbiOfHelpers, HasParamEnv, HasTyCtxt, LayoutOf, LayoutOfHelpers,
12+
};
713
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
814
use rustc_middle::ty::{
9-
GenericPredicates, Instance, ParamEnv, ScalarInt, TypeVisitableExt, ValTree,
15+
GenericPredicates, Instance, List, ParamEnv, ScalarInt, TyCtxt, TypeVisitableExt, ValTree,
1016
};
1117
use rustc_span::def_id::LOCAL_CRATE;
18+
use stable_mir::abi::{FnAbi, Layout, LayoutShape};
1219
use stable_mir::compiler_interface::Context;
1320
use stable_mir::mir::alloc::GlobalAlloc;
1421
use stable_mir::mir::mono::{InstanceDef, StaticDef};
@@ -280,7 +287,6 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
280287
tables.tcx.mk_ty_from_kind(internal_kind).stable(&mut *tables)
281288
}
282289

283-
#[allow(rustc::usage_of_qualified_ty)]
284290
fn new_box_ty(&self, ty: stable_mir::ty::Ty) -> stable_mir::ty::Ty {
285291
let mut tables = self.0.borrow_mut();
286292
let inner = ty.internal(&mut *tables);
@@ -335,6 +341,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
335341
instance.ty(tables.tcx, ParamEnv::reveal_all()).stable(&mut *tables)
336342
}
337343

344+
fn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error> {
345+
let mut tables = self.0.borrow_mut();
346+
let instance = tables.instances[def];
347+
Ok(tables.fn_abi_of_instance(instance, List::empty())?.stable(&mut *tables))
348+
}
349+
338350
fn instance_def_id(&self, def: InstanceDef) -> stable_mir::DefId {
339351
let mut tables = self.0.borrow_mut();
340352
let def_id = tables.instances[def].def_id();
@@ -473,6 +485,65 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
473485
)
474486
}
475487
}
488+
489+
fn ty_layout(&self, ty: Ty) -> Result<Layout, Error> {
490+
let mut tables = self.0.borrow_mut();
491+
let ty = ty.internal(&mut *tables);
492+
let layout = tables.layout_of(ty)?.layout;
493+
Ok(layout.stable(&mut *tables))
494+
}
495+
496+
fn layout_shape(&self, id: Layout) -> LayoutShape {
497+
let mut tables = self.0.borrow_mut();
498+
id.internal(&mut *tables).0.stable(&mut *tables)
499+
}
476500
}
477501

478502
pub struct TablesWrapper<'tcx>(pub RefCell<Tables<'tcx>>);
503+
504+
/// Implement error handling for extracting function ABI information.
505+
impl<'tcx> FnAbiOfHelpers<'tcx> for Tables<'tcx> {
506+
type FnAbiOfResult = Result<&'tcx rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>>, Error>;
507+
508+
#[inline]
509+
fn handle_fn_abi_err(
510+
&self,
511+
err: ty::layout::FnAbiError<'tcx>,
512+
_span: rustc_span::Span,
513+
fn_abi_request: ty::layout::FnAbiRequest<'tcx>,
514+
) -> Error {
515+
Error::new(format!("Failed to get ABI for `{fn_abi_request:?}`: {err:?}"))
516+
}
517+
}
518+
519+
impl<'tcx> LayoutOfHelpers<'tcx> for Tables<'tcx> {
520+
type LayoutOfResult = Result<ty::layout::TyAndLayout<'tcx>, Error>;
521+
522+
#[inline]
523+
fn handle_layout_err(
524+
&self,
525+
err: ty::layout::LayoutError<'tcx>,
526+
_span: rustc_span::Span,
527+
ty: ty::Ty<'tcx>,
528+
) -> Error {
529+
Error::new(format!("Failed to get layout for `{ty}`: {err}"))
530+
}
531+
}
532+
533+
impl<'tcx> HasParamEnv<'tcx> for Tables<'tcx> {
534+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
535+
ty::ParamEnv::reveal_all()
536+
}
537+
}
538+
539+
impl<'tcx> HasTyCtxt<'tcx> for Tables<'tcx> {
540+
fn tcx(&self) -> TyCtxt<'tcx> {
541+
self.tcx
542+
}
543+
}
544+
545+
impl<'tcx> HasDataLayout for Tables<'tcx> {
546+
fn data_layout(&self) -> &rustc_abi::TargetDataLayout {
547+
self.tcx.data_layout()
548+
}
549+
}

0 commit comments

Comments
 (0)