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
4 changes: 4 additions & 0 deletions packages/bugc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ support. Changes to the specification itself are tracked in the root
`struct Outer { x: uint8; inner: Inner; y: uint16; }`, `y` is now in
slot 3 of an `Outer`, after `inner` in slots 1 and 2. Before, `y` was
in slot 2 ([#377]).
- The `advanced/token-registry.bug` example is no longer marked work
in progress. It compiles, and runs the same, at every optimization
level ([#395]).

### Fixed

Expand Down Expand Up @@ -572,3 +575,4 @@ First publication.
[#384]: https://github.com/ethdebug/format/pull/384
[#388]: https://github.com/ethdebug/format/pull/388
[#391]: https://github.com/ethdebug/format/pull/391
[#395]: https://github.com/ethdebug/format/pull/395
1 change: 0 additions & 1 deletion packages/bugc/examples/advanced/token-registry.bug
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @wip
name TokenRegistry;

// This example demonstrates:
Expand Down
4 changes: 4 additions & 0 deletions packages/bugc/src/ir/utils/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { Type } from "../spec/type.js";
* `string` is its text, in UTF-8, and `bytes` (from a hex literal too
* long for a word) are the bytes the "0x…" hex names. Code generation
* stores these bytes, and constant folding hashes them.
*
* The encoding follows the constant's TYPE, so a fold of a string
* constant across `as bytes` must re-encode its value ("0x" + hex of
* the UTF-8), not only retype it.
*/
export function constantBytes(value: string, type: Type): Uint8Array {
const isString =
Expand Down
2 changes: 2 additions & 0 deletions packages/bugc/src/optimizer/steps/constant-folding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ export class ConstantFoldingStep extends BaseOptimizationStep {
constants: Map<string, bigint | boolean | string>,
): Ir.Instruction.Const | undefined {
const value = this.getConstantValue(inst.value, constants);
// A string constant's bytes follow its type (see constantBytes):
// to fold one across `as bytes`, re-encode its value as "0x" + hex
if (typeof value !== "bigint") return undefined;

const steps = Ir.Utils.castSteps(inst.value.type, inst.targetType);
Expand Down
5 changes: 3 additions & 2 deletions packages/bugc/test/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ describe("Example Files", async () => {
expect(identifiers).toEqual(storageNames);
}
// A program lists its locals at every instruction, so a long
// one takes a while to validate
// one takes a while to validate (advanced/token-registry.bug
// takes over 10 seconds on CI)
},
10_000,
30_000,
);
}
}
Expand Down
Loading