Description
While {i128, u128}
support works greatly on many backends (x86 32 bit and 64 bit versions for example), emscripten and other smaller backends have a shaky support story for i128 integers. Often a backend gets written with support for C/C++ in mind, and those languages don't mandate i128 integer support, so those backends don't implement it. You are getting assertions or worse if presenting the backend with IR that uses i128. While we offer intrinsics for many i128 related operations in the compiler_builtins
crate (offering the i128 operation implementations beyond the limited set of targets that C written comiler-rt supports), a backend still needs to implement sret support and other features. So for these backends, i128 is disabled right now.
Having spotty support for i128 means that even if we stabilize i128, many users of the language will avoid using the native i128 types, and instead adopt crates that do that lowering manually, which in turn leads to fragmentation of the ecosystem and prevents them from having a native i128 experience which includes support for proper literals. This is not what we have a native i128 support for!
Therefore, rustc should implement lowering of i128 that backends which don't have support for i128 can opt into.
One way to expose this feature could be as a member i128_lowering
to the TargetOptions
struct, which is enabled for the targets in question.
cc tracking issue #35118.
cc @alexcrichton @nagisa @sfackler
@scottmcm is doing awesome work on the issue:
- -Z lower_128bit_ops option to lower to compiler_builtins calls in MIR (Add a MIR pass to lower 128-bit operators to lang item calls #46093 , Implement all the 128-bit operator lang items (Rust 45676 part 2) compiler-builtins#210, Update compiler-builtins and use it in the 128-bit lowering MIR test #46290 )
- Addition of a flag in TargetOptions in order to do lowering by default on affected targets (Add an i128_lowering flag in TargetOptions #46486)
- Fix -Z lower_128bit_ops handling of statics (Fix -Z lower_128bit_ops handling of statics #46583)