authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-04-15 01:19:37+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-18 19:57:47-07:00
log07b7c3b31babc0763199fe39db875298d2cc12a6
treed32af40b572f4a621d3d84f83dcfe884c00f1a1e
parent0eebc258809beac9779af48216b01c5c20cbbfea

doc: clarifications to comptime section in langref after #14819


1 files changed, 8 insertions(+), 14 deletions(-)

doc/langref.html.in+8-14
......@@ -7048,8 +7048,10 @@ test "foo" {
70487048 <li>All variables are {#syntax#}comptime{#endsyntax#} variables.</li>
70497049 <li>All {#syntax#}if{#endsyntax#}, {#syntax#}while{#endsyntax#}, {#syntax#}for{#endsyntax#}, and {#syntax#}switch{#endsyntax#}
70507050 expressions are evaluated at compile-time, or emit a compile error if this is not possible.</li>
7051 <li>All function calls cause the compiler to interpret the function at compile-time, emitting a
7052 compile error if the function tries to do something that has global run-time side effects.</li>
7051 <li>All {#syntax#}return{#endsyntax#} and {#syntax#}try{#endsyntax#} expressions are invalid (unless the function itself is called at compile-time).</li>
7052 <li>All code with runtime side effects or depending on runtime values emits a compile error.</li>
7053 <li>All function calls cause the compiler to interpret the function at compile-time, emitting a
7054 compile error if the function tries to do something that has global runtime side effects.</li>
70537055 </ul>
70547056 <p>
70557057 This means that a programmer can create a function which is called both at compile-time and run-time, with
......@@ -7071,9 +7073,7 @@ test "fibonacci" {
70717073 try expect(fibonacci(7) == 13);
70727074
70737075 // test fibonacci at compile-time
7074 comptime {
7075 try expect(fibonacci(7) == 13);
7076 }
7076 try comptime expect(fibonacci(7) == 13);
70777077}
70787078 {#code_end#}
70797079 <p>
......@@ -7088,9 +7088,7 @@ fn fibonacci(index: u32) u32 {
70887088}
70897089
70907090test "fibonacci" {
7091 comptime {
7092 try expect(fibonacci(7) == 13);
7093 }
7091 try comptime expect(fibonacci(7) == 13);
70947092}
70957093 {#code_end#}
70967094 <p>
......@@ -7111,9 +7109,7 @@ fn fibonacci(index: i32) i32 {
71117109}
71127110
71137111test "fibonacci" {
7114 comptime {
7115 try assert(fibonacci(7) == 13);
7116 }
7112 try comptime assert(fibonacci(7) == 13);
71177113}
71187114 {#code_end#}
71197115 <p>
......@@ -7143,9 +7139,7 @@ fn fibonacci(index: i32) i32 {
71437139}
71447140
71457141test "fibonacci" {
7146 comptime {
7147 try assert(fibonacci(7) == 99999);
7148 }
7142 try comptime assert(fibonacci(7) == 99999);
71497143}
71507144 {#code_end#}
71517145