Skip to content

Commit a0c8ad1

Browse files
committed
fix: use intrinsic where required instead of closure
1 parent d220b0b commit a0c8ad1

8 files changed

Lines changed: 24 additions & 15 deletions

File tree

libs/@local/hashql/mir/src/body/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ pub enum Source<'heap> {
7171
/// A compiler intrinsic function.
7272
///
7373
/// This variant represents MIR generated for built-in operations that have
74-
/// special compiler support or runtime behavior. The [`DefId`] identifies the intrinsic
75-
/// definition.
74+
/// special compiler support or runtime behavior. Intrinsics may define a fallback
75+
/// implementation inside of their body.
7676
///
77-
/// The body of an intrinsic function is typically empty, as the intrinsic
78-
/// operation is handled directly by the compiler or runtime.
77+
/// Intrinsics are never inlined, but are still optimized, except in the case of explicit
78+
/// opt-out.
7979
Intrinsic(Intrinsic),
8080

8181
/// A compiler-synthesized wrapper that makes a non-first-class operation callable as a

libs/@local/hashql/mir/src/builder/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ macro_rules! body {
382382
$crate::body::Source::Ctor($name)
383383
};
384384
(@source intrinsic) => {
385-
$crate::body::Source::Intrinsic($crate::def::DefId::PLACEHOLDER)
385+
$crate::body::Source::Intrinsic($crate::intrinsic::Intrinsic { id: $crate::intrinsic::IntrinsicId::EntityPropertyAccess, optimize: true })
386386
};
387387
(@source [synthetic $name:expr]) => {
388388
$crate::body::Source::Synthetic($name)

libs/@local/hashql/mir/src/intrinsic.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ pub enum IntrinsicId {
99
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1010
pub struct Intrinsic {
1111
pub id: IntrinsicId,
12-
// Hint to any optimization passes that this intrinsic should not be optimized in any way.
12+
// Hint to any optimization passes whether the intrinsic should participate in optimization, or
13+
// should be skipped.
1314
pub optimize: bool,
1415
}
16+
17+
impl Intrinsic {
18+
#[must_use]
19+
pub const fn new(id: IntrinsicId) -> Self {
20+
Self { id, optimize: true }
21+
}
22+
}

libs/@local/hashql/mir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub mod def;
4545
pub mod error;
4646
pub mod intern;
4747
pub mod interpret;
48-
mod intrinsic;
48+
pub mod intrinsic;
4949
mod macros;
5050
pub mod pass;
5151
pub mod pretty;

libs/@local/hashql/mir/src/pass/transform/inline/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::{
2727
context::MirContext,
2828
def::{DefId, DefIdSlice, DefIdVec},
2929
intern::Interner,
30+
intrinsic::{Intrinsic, IntrinsicId},
3031
pass::{
3132
Changed, GlobalTransformPass as _, OwnedGlobalTransformState,
3233
analysis::{CallGraph, CallSite},
@@ -542,7 +543,7 @@ fn analysis_directives_by_source() {
542543

543544
let mut intrinsic_body = closure_body.clone();
544545
intrinsic_body.id = DefId::new(2);
545-
intrinsic_body.source = Source::Closure(HirId::PLACEHOLDER, None);
546+
intrinsic_body.source = Source::Intrinsic(Intrinsic::new(IntrinsicId::EntityPropertyAccess));
546547

547548
// Fix closure_body id to be 0
548549
closure_body.id = DefId::new(0);

libs/@local/hashql/mir/tests/ui/pass/copy_propagation/block_param_effectful.snap

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/mir/tests/ui/pass/dle/projection_locals_preserved.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/mir/tests/ui/pass/dse/graph_read_token_preserved.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)