-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add intrinsic for Option::Some(_) offset #109095
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; | |
use rustc_span::{sym, Span}; | ||
use rustc_target::abi::{ | ||
call::{FnAbi, PassMode}, | ||
WrappingRange, | ||
FieldsShape, Variants, WrappingRange, | ||
}; | ||
|
||
fn copy_intrinsic<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( | ||
|
@@ -104,6 +104,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |
bx.const_usize(bx.layout_of(tp_ty).align.abi.bytes()) | ||
} | ||
} | ||
sym::option_some_offset => { | ||
let ty = substs.type_at(0); | ||
let layout = bx.layout_of(ty); | ||
let Variants::Multiple { variants, .. } = layout.layout.variants() else { bug!() }; | ||
let Some(variant) = variants.iter().last() else { bug!() }; | ||
let FieldsShape::Arbitrary { offsets, .. } = &variant.fields else { bug!() }; | ||
bx.const_usize(offsets[0].bytes()) | ||
Comment on lines
+112
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use |
||
} | ||
sym::vtable_size | sym::vtable_align => { | ||
let vtable = args[0].immediate(); | ||
let idx = match name { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement}; | |
use rustc_middle::ty::subst::SubstsRef; | ||
use rustc_middle::ty::{Ty, TyCtxt}; | ||
use rustc_span::symbol::{sym, Symbol}; | ||
use rustc_target::abi::{Abi, Align, Primitive, Size}; | ||
use rustc_target::abi::{Abi, Align, FieldsShape, Primitive, Size, Variants}; | ||
|
||
use super::{ | ||
util::ensure_monomorphic_enough, CheckInAllocMsg, ImmTy, InterpCx, Machine, OpTy, PlaceTy, | ||
|
@@ -106,6 +106,13 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( | |
| ty::Tuple(_) | ||
| ty::Error(_) => ConstValue::from_target_usize(0u64, &tcx), | ||
}, | ||
sym::option_some_offset => { | ||
let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?; | ||
let Variants::Multiple { variants, .. } = layout.layout.variants() else { bug!() }; | ||
let Some(variant) = variants.iter().last() else { bug!() }; | ||
let FieldsShape::Arbitrary { offsets, .. } = &variant.fields else { bug!() }; | ||
ConstValue::from_target_usize(offsets[0].bytes(), &tcx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should avoid duplicating this code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, where to put it then? |
||
} | ||
other => bug!("`{}` is not a zero arg intrinsic", other), | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will ICE on
Option<!>
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, a test for
Option<Never>
would be a good add, regardless of implementation 👍