RFC 1300: Semantics of intrinsic functions

lang (machine | intrinsic)

Summary

Define the general semantics of intrinsic functions. This does not define the semantics of the individual intrinsics, instead defines the semantics around intrinsic functions in general.

Motivation

Intrinsics are currently poorly-specified in terms of how they function. This means they are a cause of ICEs and general confusion. The poor specification of them also means discussion affecting intrinsics gets mired in opinions about what intrinsics should be like and how they should act or be implemented.

Detailed design

Intrinsics are currently implemented by generating the code for the intrinsic at the call site. This allows for intrinsics to be implemented much more efficiently in many cases. For example, transmute is able to evaluate the input expression directly into the storage for the result, removing a potential copy. This is the main idea of intrinsics, a way to generate code that is otherwise inexpressible in Rust.

Keeping this in-place behaviour is desirable, so this RFC proposes that intrinsics should only be usable as functions when called. This is not a change from the current behaviour, as you already cannot use intrinsics as function pointers. Using an intrinsic in any way other than directly calling should be considered an error.

Intrinsics should continue to be defined and declared the same way. The rust-intrinsic and platform-intrinsic ABIs indicate that the function is an intrinsic function.

Drawbacks

Alternatives

Unresolved questions

None.