Skip to content

Commit a73533c

Browse files
committed
docs: add inlineDemo tracing example (leaf helper, two sites) (#232)
A small leaf helper square(x) called from two sites with storage-read args. At O2/O3 both sites inline into the caller -> two virtual activations in the tracer (the inline showcase, as sum/factorial were for tailcall). Args are non-constant (storage reads) so L1 fold can't collapse the inlined bodies. Verified against bugc: correct result (3^2 + 4^2 = 25) at O0-O3; zero inline marks at O0/O1, both sites inlined at O2 (108 -> 50 runtime instrs) and O3. Prose + TraceExample wiring to follow (writer/docs).
1 parent 36a5992 commit a73533c

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎packages/web/docs/core-schemas/programs/tracing-examples.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,27 @@ create {
138138
code {
139139
result = fact(5, 1);
140140
}`;
141+
142+
export const inlineDemo = `name InlineDemo;
143+
144+
define {
145+
function square(x: uint256) -> uint256 {
146+
return x * x;
147+
};
148+
}
149+
150+
storage {
151+
[0] a: uint256;
152+
[1] b: uint256;
153+
[2] sumOfSquares: uint256;
154+
}
155+
156+
create {
157+
a = 3;
158+
b = 4;
159+
sumOfSquares = 0;
160+
}
161+
162+
code {
163+
sumOfSquares = square(a) + square(b);
164+
}`;

0 commit comments

Comments
 (0)