Skip to content

Tags: google/emboss

Tags

v2026.0604.051943

Toggle v2026.0604.051943's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Drop redundant Known() guard when discriminant is provably Known (#257)

The optimized switch block opens with

    const auto emboss_reserved_switch_discrim = \${discriminant};
    if (!emboss_reserved_switch_discrim.Known()) return false;

The Known() guard is a safety net: if reading the discriminant
failed, Ok() must return false. But fields_in_dependency_order
guarantees the discriminant field is validated earlier in Ok(), and
for a non-conditional, non-virtual field of the current structure
the earlier \`if (has_X().ValueOrDefault() && !X().Ok()) return false;\`
already enforces X().Ok(). Past that point the Maybe<> wrapper around
the field read is provably Known and the extra guard is dead code.

_is_discriminant_provably_known recognizes the safe shape — a
single-segment field_reference to a non-conditional non-virtual field
in the current structure's field list — and removes the guard in
that case. The detection is intentionally narrow; nested paths and
computed discriminants keep the guard.

One line saved per qualifying switch — minor on hosted targets, but
on Thumb-2 and MicroBlaze this removes a load, a compare, and a
conditional return per switch block, plus the constant-pool slot.

v2026.0604.051035

Toggle v2026.0604.051035's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Extend switch matcher: disjunction, conjunction, single-entry demotion (

#256)

PR 241's _get_switch_candidate only matched bare \`discrim == K\`
equalities. Real protocol grammars express the same intent in many
forms; this PR rewrites the matcher to recognize them all.

_extract_switch_arms decomposes an existence_condition into a
(discriminant, [(case_value, residual), ...]) tuple, handling:

  * Bare equality (\`tag == K\`) — one arm, no residual.
  * Disjunction of equalities on a shared discriminant
    (\`tag == A || tag == B || tag == C\`) — one arm per Ki, no
    residual. Common for tagged unions where several values share a
    payload. Combined with the identical-body coalescing already in
    place, this collapses to a single multi-label switch arm.
  * Conjunction with an equality (\`tag == K && other_predicate\`) —
    one arm carrying \`[other_predicate]\` as residual. Useful for
    nested guards like \`if outer_flag && tag == K\`.
  * Mixed shapes inside a disjunction:
    \`(tag == 0 && a) || (tag == 1 && b) || tag == 2\` — three arms
    with respective residuals \`[a]\`, \`[b]\`, \`[]\`.

An arm with a residual emits the has_\${field}()-based check as its
case body (the residual is folded into the existing accessor) — sound
and lets the C++ compiler fold the case-pinned discriminant
comparison via inlining.

A demotion pass measures total arm-entries per group and falls back
to ok_method_test when the count is below 2 — without this, a lone
field like \`if outer && tag == K: xc\` would get wrapped in a one-case
switch whose overhead (temporary, Known() guard, scope braces)
exceeds the dedupe. This also fixes a latent bug introduced when
render-dedup was added: the scoped discriminant render mutated
subexpressions during the grouping pass, so groups that later got
demoted would have left dead \`const auto = ...\` definitions in the
emitted Ok(). The scoped render now happens at emit time, only for
surviving groups.

The benchmark schema gains a DisjunctionConditionals struct
exercising three \`||\` chains (2, 3, 3 labels) and the benchmark TU
gains a runtime test for it. Golden churn: many_conditionals.emb.h
gains the new struct's output; condition.emb.h and virtual_field.emb.h
shrink because several BasicConditional-style structs had a lone xc
field that PR 241 was wrapping in a one-arm switch — demotion brings
them back to the cheaper has_xc() check.

v2026.0604.003906

Toggle v2026.0604.003906's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Render switch discriminant once per group; drop dead inner scope (#253)

* Render switch discriminant once per group; drop dead inner scope

The optimized Ok() switch-block code in _generate_optimized_ok_method_body
was rendering each switch group's discriminant twice: once unscoped at
grouping time to build the SWITCH: key, and again with the active
ExpressionScope at emit time. Render it once with the scope and reuse
the result. The result is stable for equivalent discriminants because
ExpressionScope.add dedupes by inner rendered form, so it still works
as a grouping key.

The ok_method_switch_block template's \${inner_scope_definitions}
placeholder was unused — the inner ExpressionScope it referenced had
nothing added to it. Removed both, which also drops the blank line
each switch block carried in the goldens.

No behavioral change; purely compile-time cleanup. Golden churn
limited to the blank-line removal in four files (one line per existing
switch block).

* Sort switch cases by value; coalesce identical-body cases (#254)

Three composing changes to the optimized Ok() switch generator:

1. Case-label sort. Each switch arm's labels are sorted by the
   underlying integer/enum value before emit. _case_sort_key()
   returns the int for sorting. Sorted cases give older embedded
   GCCs (the ones shipped with microblaze-elf and many bare-metal
   arm-none-eabi toolchains) a better shot at emitting a dense
   jump table rather than an if-ladder.

2. Identical-body coalescing. Cases whose rendered body text is
   identical (same field set in the same order) are merged into a
   single arm with multiple \`case X:\` labels. The C++ compiler
   emits one body for the whole arm — a real text-size win once a
   later PR (disjunction matching) starts producing such pairs.

3. Multi-field per case. When two conditional fields share a
   discriminant + case value (\`if tag == 0: a\` and \`if tag == 0: b\`),
   they're now bundled into the same case arm rather than the second
   falling back to a separate if-statement. Each field's validation
   becomes one line of the case body.

The ok_method_switch_case template becomes ok_method_switch_arm,
taking pre-formatted \${case_labels} and \${case_body} strings.
Single-label single-field arms render identically to the old
template, so golden churn is limited to the f0_copy field in
testdata/many_conditionals.emb folding into case 0 of the
LargeConditionals switch.

v2026.0601.200710

Toggle v2026.0601.200710's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Add clang-format to c++ backend (#262)

* Format generated C++ headers with clang-format

Apply Google-style clang-format to all generated .emb.h output, in
both the bazel codegen path (emboss_codegen_cpp.main) and the
standalone embossc driver.

The clang-format binary path is resolved through the new
compiler/back_end/cpp/clang_format_path module, which is the single
seam to the underlying binary. The upstream version uses the
clang-format PyPI package; downstream forks that cannot use the PyPI
package can replace just clang_format_path.py and its BUILD entry
with a shim returning an alternative path.

* Regenerate build.json for new clang_format_path.py

* Move clang_format import to module top in clang_format_path.py

v2026.0520.190324

Toggle v2026.0520.190324's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Add scripts/regenerate_goldens.py for batch golden regeneration (#251)

* Add scripts/regenerate_goldens.py for batch golden regeneration

Mirrors the cpp_golden_test list in compiler/back_end/cpp/BUILD,
invoking embossc on each input .emb file to regenerate the
corresponding golden header. Makes generator changes (which usually
require regenerating dozens of golden files) a one-command operation
instead of a per-file dance.

Also handles the testdata/imported_genfiles.emb genrule transform
locally and cleans up afterward so the produced file doesn't collide
with the bazel genrule on subsequent builds.

* Note regenerate_goldens.py mirror in BUILD

v2026.0520.190155

Toggle v2026.0520.190155's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Add scripts/regenerate_goldens.py for batch golden regeneration (#251)

* Add scripts/regenerate_goldens.py for batch golden regeneration

Mirrors the cpp_golden_test list in compiler/back_end/cpp/BUILD,
invoking embossc on each input .emb file to regenerate the
corresponding golden header. Makes generator changes (which usually
require regenerating dozens of golden files) a one-command operation
instead of a per-file dance.

Also handles the testdata/imported_genfiles.emb genrule transform
locally and cleans up afterward so the produced file doesn't collide
with the bazel genrule on subsequent builds.

* Note regenerate_goldens.py mirror in BUILD

v2026.0520.152057

Toggle v2026.0520.152057's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Fix BUILD file formatting and action mnemonics (#261)

* Fix BUILD file formatting and action mnemonics

* Fix generated C++ switch statements

v2026.0520.012004

Toggle v2026.0520.012004's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Fix TapPresubmit and Buildifier errors (#260)

v2026.0520.005033

Toggle v2026.0520.005033's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Fix TapPresubmit and Buildifier errors (#255)

v2026.0519.231551

Toggle v2026.0519.231551's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Bump black from 24.8.0 to 26.3.1 in the pip group across 1 directory (#…

…246)

* Bump black from 24.8.0 to 26.3.1 in the pip group across 1 directory

Bumps the pip group with 1 update in the / directory: [black](https://github.com/psf/black).


Updates `black` from 24.8.0 to 26.3.1
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/main/CHANGES.md)
- [Commits](psf/black@24.8.0...26.3.1)

---
updated-dependencies:
- dependency-name: black
  dependency-version: 26.3.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* build: Add missing dependencies for black 26.3.1

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Aaron Webster <webstera@google.com>