Add support to intrinsics fallback body
Before this fix, the call to `body()` would crash, since `has_body()` would return true, but we would try to retrieve the body of an intrinsic which is not allowed. Instead, the `Instance::body()` function will now convert an Intrinsic into an Item before retrieving its body.
This commit is contained in:
parent
ea40fa210b
commit
1512d06be9
3 changed files with 149 additions and 34 deletions
|
@ -41,13 +41,22 @@ impl Instance {
|
|||
with(|cx| cx.instance_args(self.def))
|
||||
}
|
||||
|
||||
/// Get the body of an Instance. The body will be eagerly monomorphized.
|
||||
/// Get the body of an Instance.
|
||||
///
|
||||
/// The body will be eagerly monomorphized and all constants will already be evaluated.
|
||||
///
|
||||
/// This method will return the intrinsic fallback body if one was defined.
|
||||
pub fn body(&self) -> Option<Body> {
|
||||
with(|context| context.instance_body(self.def))
|
||||
}
|
||||
|
||||
/// Check whether this instance has a body available.
|
||||
///
|
||||
/// For intrinsics with fallback body, this will return `true`. It is up to the user to decide
|
||||
/// whether to specialize the intrinsic or to use its fallback body.
|
||||
///
|
||||
/// For more information on fallback body, see <https://github.com/rust-lang/rust/issues/93145>.
|
||||
///
|
||||
/// This call is much cheaper than `instance.body().is_some()`, since it doesn't try to build
|
||||
/// the StableMIR body.
|
||||
pub fn has_body(&self) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue