Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
rust source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
mrustc (master)
rustc 1.0.0
rustc 1.1.0
rustc 1.10.0
rustc 1.11.0
rustc 1.12.0
rustc 1.13.0
rustc 1.14.0
rustc 1.15.1
rustc 1.16.0
rustc 1.17.0
rustc 1.18.0
rustc 1.19.0
rustc 1.2.0
rustc 1.20.0
rustc 1.21.0
rustc 1.22.0
rustc 1.23.0
rustc 1.24.0
rustc 1.25.0
rustc 1.26.0
rustc 1.27.0
rustc 1.27.1
rustc 1.28.0
rustc 1.29.0
rustc 1.3.0
rustc 1.30.0
rustc 1.31.0
rustc 1.32.0
rustc 1.33.0
rustc 1.34.0
rustc 1.35.0
rustc 1.36.0
rustc 1.37.0
rustc 1.38.0
rustc 1.39.0
rustc 1.4.0
rustc 1.40.0
rustc 1.41.0
rustc 1.42.0
rustc 1.43.0
rustc 1.44.0
rustc 1.45.0
rustc 1.45.2
rustc 1.46.0
rustc 1.47.0
rustc 1.48.0
rustc 1.49.0
rustc 1.5.0
rustc 1.50.0
rustc 1.51.0
rustc 1.52.0
rustc 1.53.0
rustc 1.54.0
rustc 1.55.0
rustc 1.56.0
rustc 1.57.0
rustc 1.58.0
rustc 1.59.0
rustc 1.6.0
rustc 1.60.0
rustc 1.61.0
rustc 1.62.0
rustc 1.63.0
rustc 1.64.0
rustc 1.65.0
rustc 1.66.0
rustc 1.67.0
rustc 1.68.0
rustc 1.69.0
rustc 1.7.0
rustc 1.70.0
rustc 1.71.0
rustc 1.72.0
rustc 1.73.0
rustc 1.74.0
rustc 1.75.0
rustc 1.76.0
rustc 1.77.0
rustc 1.78.0
rustc 1.79.0
rustc 1.8.0
rustc 1.80.0
rustc 1.81.0
rustc 1.82.0
rustc 1.83.0
rustc 1.84.0
rustc 1.85.0
rustc 1.86.0
rustc 1.87.0
rustc 1.88.0
rustc 1.89.0
rustc 1.9.0
rustc beta
rustc nightly
rustc-cg-gcc (master)
x86-64 GCCRS (GCC master)
x86-64 GCCRS (GCCRS master)
x86-64 GCCRS 14.1 (GCC assertions)
x86-64 GCCRS 14.1 (GCC)
x86-64 GCCRS 14.2 (GCC assertions)
x86-64 GCCRS 14.2 (GCC)
x86-64 GCCRS 14.3 (GCC assertions)
x86-64 GCCRS 14.3 (GCC)
x86-64 GCCRS 15.1 (GCC assertions)
x86-64 GCCRS 15.1 (GCC)
x86-64 GCCRS 15.2 (GCC assertions)
x86-64 GCCRS 15.2 (GCC)
Options
Source code
/// The max size of a string we can fit inline pub(crate) const MAX_SIZE: usize = core::mem::size_of::<String>(); /// Used as a discriminant to identify different variants pub(crate) const HEAP_MASK: u8 = LastByte::Heap as u8; /// When our string is stored inline, we represent the length of the string in the last byte, offset /// by `LENGTH_MASK` pub(crate) const LENGTH_MASK: u8 = 0b11000000; #[repr(C)] pub(crate) struct Repr( /// We have a pointer in the representation to properly carry provenance. *const (), /// Then we need two `usize`s (aka WORDs) of data, for the first we just define a `usize`... usize, /// ...but the second we breakup into multiple pieces... u32, u16, u8, /// ...so that the last byte can be a [`LastByte`], which allows the compiler to see a niche /// value. LastByte, ); impl Repr { #[no_mangle] pub fn as_slice(&self) -> &[u8] { // initially has the value of the stack pointer, conditionally becomes the heap pointer let mut pointer = self as *const Self as *const u8; let heap_pointer = self.0 as *const u8; if self.last_byte() >= HEAP_MASK { pointer = heap_pointer; } // initially has the value of the stack length, conditionally becomes the heap length let mut length = core::cmp::min( self.last_byte().wrapping_sub(LENGTH_MASK) as usize, MAX_SIZE, ); let heap_length = self.1; if self.last_byte() >= HEAP_MASK { length = heap_length; } // SAFETY: We know the data is valid, aligned, and part of the same contiguous allocated // chunk. It's also valid for the lifetime of self unsafe { core::slice::from_raw_parts(pointer, length) } } /// Returns the last byte that's on the stack. /// /// The last byte stores the discriminant that indicates whether the string is on the stack or /// on the heap. When the string is on the stack the last byte also stores the length #[inline(always)] const fn last_byte(&self) -> u8 { let last_byte = self.5; last_byte as u8 } } /// [`LastByte`] is an unsigned 8-bit integer data type that has a valid range of `[0, 217]`. /// Excluding `[218, 255]` allows the Rust compiler to use these values as niches. /// /// Specifically the compiler can use a value in this range to encode the `None` variant of /// `Option<LastByte>` allowing: /// `std::mem::size_of::<LastByte> == std::mem::size_of::<Option<LastByte>>()` #[allow(dead_code)] #[derive(Copy, Clone, Debug)] #[repr(u8)] pub(crate) enum LastByte { // single character, ASCII: V0 = 0, V1 = 1, V2 = 2, V3 = 3, V4 = 4, V5 = 5, V6 = 6, V7 = 7, V8 = 8, V9 = 9, V10 = 10, V11 = 11, V12 = 12, V13 = 13, V14 = 14, V15 = 15, V16 = 16, V17 = 17, V18 = 18, V19 = 19, V20 = 20, V21 = 21, V22 = 22, V23 = 23, V24 = 24, V25 = 25, V26 = 26, V27 = 27, V28 = 28, V29 = 29, V30 = 30, V31 = 31, V32 = 32, V33 = 33, V34 = 34, V35 = 35, V36 = 36, V37 = 37, V38 = 38, V39 = 39, V40 = 40, V41 = 41, V42 = 42, V43 = 43, V44 = 44, V45 = 45, V46 = 46, V47 = 47, V48 = 48, V49 = 49, V50 = 50, V51 = 51, V52 = 52, V53 = 53, V54 = 54, V55 = 55, V56 = 56, V57 = 57, V58 = 58, V59 = 59, V60 = 60, V61 = 61, V62 = 62, V63 = 63, V64 = 64, V65 = 65, V66 = 66, V67 = 67, V68 = 68, V69 = 69, V70 = 70, V71 = 71, V72 = 72, V73 = 73, V74 = 74, V75 = 75, V76 = 76, V77 = 77, V78 = 78, V79 = 79, V80 = 80, V81 = 81, V82 = 82, V83 = 83, V84 = 84, V85 = 85, V86 = 86, V87 = 87, V88 = 88, V89 = 89, V90 = 90, V91 = 91, V92 = 92, V93 = 93, V94 = 94, V95 = 95, V96 = 96, V97 = 97, V98 = 98, V99 = 99, V100 = 100, V101 = 101, V102 = 102, V103 = 103, V104 = 104, V105 = 105, V106 = 106, V107 = 107, V108 = 108, V109 = 109, V110 = 110, V111 = 111, V112 = 112, V113 = 113, V114 = 114, V115 = 115, V116 = 116, V117 = 117, V118 = 118, V119 = 119, V120 = 120, V121 = 121, V122 = 122, V123 = 123, V124 = 124, V125 = 125, V126 = 126, V127 = 127, // trailing byte in a multi-byte UTF-8 sequence V128 = 128, V129 = 129, V130 = 130, V131 = 131, V132 = 132, V133 = 133, V134 = 134, V135 = 135, V136 = 136, V137 = 137, V138 = 138, V139 = 139, V140 = 140, V141 = 141, V142 = 142, V143 = 143, V144 = 144, V145 = 145, V146 = 146, V147 = 147, V148 = 148, V149 = 149, V150 = 150, V151 = 151, V152 = 152, V153 = 153, V154 = 154, V155 = 155, V156 = 156, V157 = 157, V158 = 158, V159 = 159, V160 = 160, V161 = 161, V162 = 162, V163 = 163, V164 = 164, V165 = 165, V166 = 166, V167 = 167, V168 = 168, V169 = 169, V170 = 170, V171 = 171, V172 = 172, V173 = 173, V174 = 174, V175 = 175, V176 = 176, V177 = 177, V178 = 178, V179 = 179, V180 = 180, V181 = 181, V182 = 182, V183 = 183, V184 = 184, V185 = 185, V186 = 186, V187 = 187, V188 = 188, V189 = 189, V190 = 190, V191 = 191, // Cannot be last character of a UTF-8 sequence (leading byte of a sequence) // V192 .. V244, // Can never occur in UTF-8 (start for a codepoint > U+10FFFF) // V245 .. 255, // length marker: L0 = 192, L1 = 193, L2 = 194, L3 = 195, L4 = 196, L5 = 197, L6 = 198, L7 = 199, L8 = 200, L9 = 201, L10 = 202, L11 = 203, L12 = 204, L13 = 205, L14 = 206, L15 = 207, L16 = 208, L17 = 209, L18 = 210, L19 = 211, L20 = 212, L21 = 213, L22 = 214, L23 = 215, Heap = 216, Static = 217, }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree