Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/bugc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ support. Changes to the specification itself are tracked in the root
inlined call, or returns one's result, now has its own `invoke` and
`return` contexts, around the inner call's. Before, its `invoke` (or its
`return`) was lost, so the call stack did not balance ([#341]).
- At optimization levels 2 and 3, the jump that leaves an inlined body
for the caller's code no longer has a `transform: ["inline"]` context.
It runs after the inlined function's `return`, so it is not part of the
inlined body. Before, a debugger that reads the transform put that jump
in an inlined body that had already returned, with no function or call
site to name ([#347]).
- A cast from dynamic `bytes` to a fixed-size type now reads the bytes.
`msg.data[0:4] as bytes4` is the first four bytes of calldata; bytes
past the slice's length are zero. Before, the cast gave the slice's
Expand Down Expand Up @@ -262,3 +268,4 @@ First publication.
[#343]: https://github.com/ethdebug/format/pull/343
[#344]: https://github.com/ethdebug/format/pull/344
[#345]: https://github.com/ethdebug/format/pull/345
[#347]: https://github.com/ethdebug/format/pull/347
16 changes: 16 additions & 0 deletions packages/bugc/src/evmgen/inline-bracket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ describe("inlined invoke/return are bracketed on emitted bytecode", () => {
expect(t.both).toBe(0);
});

it("marks only the body inline, from its invoke to its return", async () => {
for (const source of [dblTwoSites, multiInstrBody]) {
const instrs = await runtimeInstructions(source, 2);
// Ops past a return (the jump back to the caller's continuation)
// are the caller's code, not part of the inlined body.
let open = 0;
const outside: number[] = [];
instrs.map(flags).forEach((f, i) => {
if (f.invoke) open += 1;
if (f.inline && open === 0) outside.push(i);
if (f.return) open -= 1;
});
expect(outside).toEqual([]);
}
});

it("preserves runtime behavior at every level", async () => {
for (const level of [0, 1, 2, 3] as const) {
const res = await executeProgram(dblTwoSites, {
Expand Down
15 changes: 3 additions & 12 deletions packages/bugc/src/optimizer/steps/inlining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,9 @@ export class InliningStep extends BaseOptimizationStep {
}
const invokes = [...pendingInvokes, inlineInvoke];
const returns = [inlineReturn, ...pendingReturns];
const returnedJump: Ir.Instruction.Debug = {
...Ir.Utils.addTransform(after, "inline"),
...placement(after),
};
// The jump back to the continuation runs past the callee's return:
// it is the caller's code, with no `inline` transform of its own.
const returnedJump: Ir.Instruction.Debug = { ...after };

const entryBlockId = blockRename.get(callee.entry)!;
const returnBlockIds: string[] = [];
Expand Down Expand Up @@ -717,14 +716,6 @@ function withoutActivationsDebug(
return { ...rest, ...(context ? { context } : {}) };
}

/** A debug's inline sites and origin, which say where it is */
function placement(debug: Ir.Instruction.Debug): Ir.Instruction.Debug {
return {
...(debug.inlineSites ? { inlineSites: debug.inlineSites } : {}),
...(debug.origin ? { origin: debug.origin } : {}),
};
}

/**
* Preserve the call site's `code` range on the entry instruction.
* The instruction already maps to the callee body, so the two source
Expand Down
Loading