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" {...@@ -7048,8 +7048,10 @@ test "foo" {
7048 <li>All variables are {#syntax#}comptime{#endsyntax#} variables.</li>7048 <li>All variables are {#syntax#}comptime{#endsyntax#} variables.</li>
7049 <li>All {#syntax#}if{#endsyntax#}, {#syntax#}while{#endsyntax#}, {#syntax#}for{#endsyntax#}, and {#syntax#}switch{#endsyntax#}7049 <li>All {#syntax#}if{#endsyntax#}, {#syntax#}while{#endsyntax#}, {#syntax#}for{#endsyntax#}, and {#syntax#}switch{#endsyntax#}
7050 expressions are evaluated at compile-time, or emit a compile error if this is not possible.</li>7050 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 a7051 <li>All {#syntax#}return{#endsyntax#} and {#syntax#}try{#endsyntax#} expressions are invalid (unless the function itself is called at compile-time).</li>
7052 compile error if the function tries to do something that has global run-time side effects.</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>
7053 </ul>7055 </ul>
7054 <p>7056 <p>
7055 This means that a programmer can create a function which is called both at compile-time and run-time, with7057 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" {...@@ -7071,9 +7073,7 @@ test "fibonacci" {
7071 try expect(fibonacci(7) == 13);7073 try expect(fibonacci(7) == 13);
70727074
7073 // test fibonacci at compile-time7075 // test fibonacci at compile-time
7074 comptime {7076 try comptime expect(fibonacci(7) == 13);
7075 try expect(fibonacci(7) == 13);
7076 }
7077}7077}
7078 {#code_end#}7078 {#code_end#}
7079 <p>7079 <p>
...@@ -7088,9 +7088,7 @@ fn fibonacci(index: u32) u32 {...@@ -7088,9 +7088,7 @@ fn fibonacci(index: u32) u32 {
7088}7088}
70897089
7090test "fibonacci" {7090test "fibonacci" {
7091 comptime {7091 try comptime expect(fibonacci(7) == 13);
7092 try expect(fibonacci(7) == 13);
7093 }
7094}7092}
7095 {#code_end#}7093 {#code_end#}
7096 <p>7094 <p>
...@@ -7111,9 +7109,7 @@ fn fibonacci(index: i32) i32 {...@@ -7111,9 +7109,7 @@ fn fibonacci(index: i32) i32 {
7111}7109}
71127110
7113test "fibonacci" {7111test "fibonacci" {
7114 comptime {7112 try comptime assert(fibonacci(7) == 13);
7115 try assert(fibonacci(7) == 13);
7116 }
7117}7113}
7118 {#code_end#}7114 {#code_end#}
7119 <p>7115 <p>
...@@ -7143,9 +7139,7 @@ fn fibonacci(index: i32) i32 {...@@ -7143,9 +7139,7 @@ fn fibonacci(index: i32) i32 {
7143}7139}
71447140
7145test "fibonacci" {7141test "fibonacci" {
7146 comptime {7142 try comptime assert(fibonacci(7) == 99999);
7147 try assert(fibonacci(7) == 99999);
7148 }
7149}7143}
7150 {#code_end#}7144 {#code_end#}
71517145