Skip to content

Conversation

@dkcumming
Copy link
Collaborator

@dkcumming dkcumming commented Nov 10, 2025

Some instrinsics do not affect the semantics of the compiled program but are hints to the compiler. In our semantics these intrinsics are NO OPs where the call is ignored and current continuation (<k> cell) moves onto the next term in the sequence.

In particular there are rules implemented for these intrinsics:

  • cold_path
  • prefetch_read_data
  • prefetch_write_data
  • prefetch_read_instruction
  • prefetch_write_instruction

By handling cold_path we also support likely and unlikely which are MonoItemFn that call the cold_path instrinic.

This PR also refactors the intrinsics into their only file intrinsics.md.

closes #802

Copy link
Member

@jberthold jberthold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and good refactoring to split it out of kmir.md!
BTW we also need assert_inhabited BTW, but implementing its idea requires type information that we don't really have. We can make it a NO OP, though (it "is not guaranteed to ever panic").

# Rust Intrinsic Functions in K

```k
// This looks like a circular import but only module KMIR in kmir.md imports KMIR-INTRINSICS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should split out the control flow in kmir.md into its own file at some point (not an urgent matter)

@jberthold
Copy link
Member

Needs test adaptation, checked_arithmetic-fail succeeds now.

@automergerpr-permission-manager automergerpr-permission-manager bot merged commit 8ef12df into master Nov 11, 2025
7 checks passed
@automergerpr-permission-manager automergerpr-permission-manager bot deleted the dc/no-op-intrinsics branch November 11, 2025 02:36
dkcumming added a commit that referenced this pull request Nov 11, 2025
- #826
- #828

Conflict with imports correct manually
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement more of the hint/no-op intrinsics

3 participants