-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Add InterpCx::project_fields
#144890
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
Add InterpCx::project_fields
#144890
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 |
---|---|---|
|
@@ -793,44 +793,45 @@ impl Drop for Guard { | |
/// We also make things panic if this type is ever implicitly dropped. | ||
#[derive(Debug)] | ||
#[must_use] | ||
pub struct InterpResult_<'tcx, T> { | ||
pub struct InterpResult<'tcx, T = ()> { | ||
res: Result<T, InterpErrorInfo<'tcx>>, | ||
guard: Guard, | ||
} | ||
|
||
// Type alias to be able to set a default type argument. | ||
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. :thonk: 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 have 0 ideas xd 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. Hm, somehow I must have thought that you can't have defaults in the generics of a struct 🤦 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. Ralf, stop reading github while on vacation!!! |
||
pub type InterpResult<'tcx, T = ()> = InterpResult_<'tcx, T>; | ||
|
||
impl<'tcx, T> ops::Try for InterpResult_<'tcx, T> { | ||
impl<'tcx, T> ops::Try for InterpResult<'tcx, T> { | ||
type Output = T; | ||
type Residual = InterpResult_<'tcx, convert::Infallible>; | ||
type Residual = InterpResult<'tcx, convert::Infallible>; | ||
|
||
#[inline] | ||
fn from_output(output: Self::Output) -> Self { | ||
InterpResult_::new(Ok(output)) | ||
InterpResult::new(Ok(output)) | ||
} | ||
|
||
#[inline] | ||
fn branch(self) -> ops::ControlFlow<Self::Residual, Self::Output> { | ||
match self.disarm() { | ||
Ok(v) => ops::ControlFlow::Continue(v), | ||
Err(e) => ops::ControlFlow::Break(InterpResult_::new(Err(e))), | ||
Err(e) => ops::ControlFlow::Break(InterpResult::new(Err(e))), | ||
} | ||
} | ||
} | ||
|
||
impl<'tcx, T> ops::FromResidual for InterpResult_<'tcx, T> { | ||
impl<'tcx, T> ops::Residual<T> for InterpResult<'tcx, convert::Infallible> { | ||
type TryType = InterpResult<'tcx, T>; | ||
} | ||
|
||
impl<'tcx, T> ops::FromResidual for InterpResult<'tcx, T> { | ||
#[inline] | ||
#[track_caller] | ||
fn from_residual(residual: InterpResult_<'tcx, convert::Infallible>) -> Self { | ||
fn from_residual(residual: InterpResult<'tcx, convert::Infallible>) -> Self { | ||
match residual.disarm() { | ||
Err(e) => Self::new(Err(e)), | ||
} | ||
} | ||
} | ||
|
||
// Allow `yeet`ing `InterpError` in functions returning `InterpResult_`. | ||
impl<'tcx, T> ops::FromResidual<ops::Yeet<InterpErrorKind<'tcx>>> for InterpResult_<'tcx, T> { | ||
impl<'tcx, T> ops::FromResidual<ops::Yeet<InterpErrorKind<'tcx>>> for InterpResult<'tcx, T> { | ||
#[inline] | ||
fn from_residual(ops::Yeet(e): ops::Yeet<InterpErrorKind<'tcx>>) -> Self { | ||
Self::new(Err(e.into())) | ||
|
@@ -840,7 +841,7 @@ impl<'tcx, T> ops::FromResidual<ops::Yeet<InterpErrorKind<'tcx>>> for InterpResu | |
// Allow `?` on `Result<_, InterpError>` in functions returning `InterpResult_`. | ||
// This is useful e.g. for `option.ok_or_else(|| err_ub!(...))`. | ||
impl<'tcx, T, E: Into<InterpErrorInfo<'tcx>>> ops::FromResidual<Result<convert::Infallible, E>> | ||
for InterpResult_<'tcx, T> | ||
for InterpResult<'tcx, T> | ||
{ | ||
#[inline] | ||
fn from_residual(residual: Result<convert::Infallible, E>) -> Self { | ||
|
@@ -863,7 +864,7 @@ impl<'tcx, T, V: FromIterator<T>> FromIterator<InterpResult<'tcx, T>> for Interp | |
} | ||
} | ||
|
||
impl<'tcx, T> InterpResult_<'tcx, T> { | ||
impl<'tcx, T> InterpResult<'tcx, T> { | ||
#[inline(always)] | ||
fn new(res: Result<T, InterpErrorInfo<'tcx>>) -> Self { | ||
Self { res, guard: Guard } | ||
|
@@ -890,31 +891,31 @@ impl<'tcx, T> InterpResult_<'tcx, T> { | |
|
||
#[inline] | ||
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> InterpResult<'tcx, U> { | ||
InterpResult_::new(self.disarm().map(f)) | ||
InterpResult::new(self.disarm().map(f)) | ||
} | ||
|
||
#[inline] | ||
pub fn map_err_info( | ||
self, | ||
f: impl FnOnce(InterpErrorInfo<'tcx>) -> InterpErrorInfo<'tcx>, | ||
) -> InterpResult<'tcx, T> { | ||
InterpResult_::new(self.disarm().map_err(f)) | ||
InterpResult::new(self.disarm().map_err(f)) | ||
} | ||
|
||
#[inline] | ||
pub fn map_err_kind( | ||
self, | ||
f: impl FnOnce(InterpErrorKind<'tcx>) -> InterpErrorKind<'tcx>, | ||
) -> InterpResult<'tcx, T> { | ||
InterpResult_::new(self.disarm().map_err(|mut e| { | ||
InterpResult::new(self.disarm().map_err(|mut e| { | ||
e.0.kind = f(e.0.kind); | ||
e | ||
})) | ||
} | ||
|
||
#[inline] | ||
pub fn inspect_err_kind(self, f: impl FnOnce(&InterpErrorKind<'tcx>)) -> InterpResult<'tcx, T> { | ||
InterpResult_::new(self.disarm().inspect_err(|e| f(&e.0.kind))) | ||
InterpResult::new(self.disarm().inspect_err(|e| f(&e.0.kind))) | ||
} | ||
|
||
#[inline] | ||
|
@@ -937,7 +938,7 @@ impl<'tcx, T> InterpResult_<'tcx, T> { | |
|
||
#[inline] | ||
pub fn and_then<U>(self, f: impl FnOnce(T) -> InterpResult<'tcx, U>) -> InterpResult<'tcx, U> { | ||
InterpResult_::new(self.disarm().and_then(|t| f(t).disarm())) | ||
InterpResult::new(self.disarm().and_then(|t| f(t).disarm())) | ||
} | ||
|
||
/// Returns success if both `self` and `other` succeed, while ensuring we don't | ||
|
@@ -952,13 +953,13 @@ impl<'tcx, T> InterpResult_<'tcx, T> { | |
// Discard the other error. | ||
drop(other.disarm()); | ||
// Return `self`. | ||
InterpResult_::new(Err(e)) | ||
InterpResult::new(Err(e)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[inline(always)] | ||
pub fn interp_ok<'tcx, T>(x: T) -> InterpResult<'tcx, T> { | ||
InterpResult_::new(Ok(x)) | ||
InterpResult::new(Ok(x)) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
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.
Why did you add some empty lines in the middle of the sentence?
(Not a big deal but not an improvement IMO either 🤷 )
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 I did not notice
// the actual raw ptr
part or that it connects to the next commentThere 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.
In general I find it difficult to read code which looks like
I.e. where the break between logical "blocks" is a comment without a newline.
(this possibly doesn't apply here due to the linked nature of the comments)