Skip to content

Split alignment calculation from layout calculation #107742

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

Closed
wants to merge 14 commits into from
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1373,6 +1373,16 @@ rustc_queries! {
remap_env_constness
}

/// Computes the alignment of a type. Note that this implicitly
/// executes in "reveal all" mode, and will normalize the input type.
query align_of(
key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
) -> Result<ty::alignment::AbiAndPrefAlign, ty::layout::LayoutError<'tcx>> {
depth_limit
desc { "computing alignment of `{}`", key.value }
remap_env_constness
}

/// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
///
/// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/alignment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use rustc_target::abi::AbiAndPrefAlign;
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
@@ -560,6 +560,17 @@ impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
}
}

pub trait AlignOf<'tcx>: LayoutOf<'tcx> {
#[inline]
fn align_of(&self, ty: Ty<'tcx>) -> Result<AbiAndPrefAlign, LayoutError<'tcx>> {
let span = self.layout_tcx_at_span();
let tcx = self.tcx().at(span);
tcx.align_of(self.param_env().and(ty))
}
}

impl<'tcx, C: LayoutOf<'tcx>> AlignOf<'tcx> for C {}

impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx>
where
C: HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ pub use self::typeck_results::{
pub mod _match;
pub mod abstract_const;
pub mod adjustment;
pub mod alignment;
pub mod binding;
pub mod cast;
pub mod codec;
Loading