authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-27 13:41:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-27 13:41:18-07:00
loge11cd2316bf752d42ab03807f40112e85cd46ab0
treef53e433fdf5e06eae621f36e9dffb4b81844b18e
parentd26018b0f46f14adac17f021782270e13ede5a92

langref: IINAH (Inline Is Not A Hint)

maybe this meme will help spread the information better

1 files changed, 16 insertions(+), 10 deletions(-)

doc/langref.html.in+16-10
......@@ -2934,8 +2934,8 @@ or
29342934 {#header_open|inline fn#}
29352935 <p>
29362936 Adding the {#syntax#}inline{#endsyntax#} keyword to a function definition makes that
2937 function become <em>semantically inlined</em> at the callsite. This is
2938 not a hint to be possibly observed by optimization passes, but has
2937 function become <em>semantically inlined</em> at the callsite. {#link|Inline Is Not A Hint#}
2938 to be possibly observed by optimization passes, but has
29392939 implications on the types and values involved in the function call.
29402940 </p>
29412941 <p>
......@@ -2947,16 +2947,22 @@ or
29472947
29482948 <p>If {#syntax#}inline{#endsyntax#} is removed, the test fails with the compile error
29492949 instead of passing.</p>
2950 <p>It is generally better to let the compiler decide when to inline a
2951 function, except for these scenarios:</p>
2950
2951 {#header_open|Inline Is Not A Hint#}
2952 <p>Use of {#syntax#}inline{#endsyntax#} <em>restricts</em> what the
2953 compiler is allowed to do. <strong>This can harm binary size, compilation speed,
2954 and even runtime performance.</strong> In exchange, these use cases are addressed:</p>
29522955 <ul>
2953 <li>To change how many stack frames are in the call stack, for debugging purposes.</li>
2954 <li>To force comptime-ness of the arguments to propagate to the return value of the function, as in the above example.</li>
2955 <li>Real world performance measurements demand it.</li>
2956 <li>Ability to ensure certain stack frames are in the call stack, for
2957 debugging purposes, or for integrating with {#link|Assembly#}.</li>
2958 <li>Forcing arguments from the callsite that happen to be
2959 {#link|comptime#} to propagate to the return value of the function, as
2960 in the above example.</li>
2961 <li>Working around limitations of compiler backend implementations.</li>
29562962 </ul>
2957 <p>Note that {#syntax#}inline{#endsyntax#} actually <em>restricts</em>
2958 what the compiler is allowed to do. This can harm binary size,
2959 compilation speed, and even runtime performance.</p>
2963 <p>For an alternative to {#syntax#}inline{#endsyntax#} that merely hints to the compiler
2964 that inlining a function may be valuable, use {#link|@branchHint#}.</p>
2965 {#header_close#}
29602966 {#header_close#}
29612967
29622968 {#header_open|Function Reflection#}