[zeek/spicy] 5ed871: Add new optimizer pass removing unused struct fields.

0 views
Skip to first unread message

Robin Sommer

unread,
Feb 19, 2026, 4:21:07 AMFeb 19
to spicy-...@zeek.org
Branch: refs/heads/topic/robin/remove-unused-fields
Home: https://github.com/zeek/spicy
Commit: 5ed87192c4263accdc6d165c353f840120485953
https://github.com/zeek/spicy/commit/5ed87192c4263accdc6d165c353f840120485953
Author: Robin Sommer <ro...@corelight.com>
Date: 2026-02-19 (Thu, 19 Feb 2026)

Changed paths:
M hilti/toolchain/CMakeLists.txt
M hilti/toolchain/include/base/util.h
M hilti/toolchain/include/compiler/detail/optimizer/pass-id.h
A hilti/toolchain/src/compiler/optimizer/passes/remove-unused-fields.cc
M tests/Baseline/hilti.cfg.dead-write-shadowed/output
M tests/Baseline/hilti.cfg.local-struct-value/output
M tests/Baseline/hilti.cfg.unreachable-return/output
M tests/Baseline/hilti.optimization.dataflow-unreachable/output
M tests/Baseline/hilti.optimization.unimplemented_hook/log
M tests/Baseline/hilti.optimization.unreachable-code/log
M tests/Baseline/hilti.optimization.unused-init/output
A tests/Baseline/hilti.optimization.unused-struct-fields/output
M tests/Baseline/hilti.optimization.unused_function/log
M tests/Baseline/hilti.types.struct.on-heap/output
M tests/Baseline/spicy.optimization.default-parser-functions/log
M tests/Baseline/spicy.optimization.default-parser-functions/opt.hlt
M tests/Baseline/spicy.optimization.feature_requirements/log
M tests/Baseline/spicy.optimization.unused-functions/log
M tests/Baseline/spicy.optimization.unused-types/log
M tests/Baseline/spicy.optimization.unused-types/opt.hlt
A tests/hilti/optimization/unused-struct-fields.hlt

Log Message:
-----------
Add new optimizer pass removing unused struct fields.

Add optimizer pass that removes struct fields with no productive
accesses. The pass marks unused fields with `&no-emit="optimized"`,
allowing them to remain in the AST through codegen, which then emits
code to render them as `(optimized out)`. Fields with `&always-emit`,
or inside types with `&always-emit`, are never removed.

The new optimization is enabled only in `--no-strict-public-api` mode,
which means by default it's on release builds, but not in debug
builds. (That aligns pretty well with the fact that in debug mode,
Spicy generates accesses to *all* parsed fields through the debug
messages it emits, which means they wouldn't be optimized out
anyways.)


Commit: 8d0b5f077406f0c0738cc42cb0496da559305629
https://github.com/zeek/spicy/commit/8d0b5f077406f0c0738cc42cb0496da559305629
Author: Robin Sommer <ro...@corelight.com>
Date: 2026-02-19 (Thu, 19 Feb 2026)

Changed paths:
M hilti/toolchain/src/compiler/optimizer/passes/peephole.cc
M spicy/toolchain/src/compiler/codegen/parser-builder.cc
M tests/Baseline/spicy.optimization.default-parser-functions/log
M tests/Baseline/spicy.optimization.default-parser-functions/noopt.hlt
M tests/Baseline/spicy.optimization.default-parser-functions/opt.hlt
M tests/Baseline/spicy.rt.debug-trace/.stderr
M tests/Baseline/spicy.types.unit.canonical-ids-with-import/output
M tests/spicy/optimization/error-push-pop.spicy
M tests/spicy/types/unit/attribute-access.spicy
M tests/spicy/types/unit/switch-convert-mixed.spicy

Log Message:
-----------
Parse fields into stack variables first.

So far, when parse a standard unit field, we'd immediately store the
retrieved value into the corresponding struct member. Now, if we parse
a non-mutable value, we instead store it into a local temporary first,
finish the field's processing, and only then move the value over from
the temporary to the struct field. The advantage is better
optimization potential: we have more opportunities to identify the
struct field as not (productively) used, and the C++ compiler can
likewise work on the stack temporary for most of the time. However, we
do this only for non-mutable values, because fields of mutable types
need to reflect incremental updates correctly at all times.


Commit: d28e36fda218426e0f7fa65ee9c7dd2fd4ccb504
https://github.com/zeek/spicy/commit/d28e36fda218426e0f7fa65ee9c7dd2fd4ccb504
Author: Robin Sommer <ro...@corelight.com>
Date: 2026-02-19 (Thu, 19 Feb 2026)

Changed paths:
M hilti/toolchain/include/compiler/detail/cfg.h
M hilti/toolchain/src/compiler/cfg.cc
M hilti/toolchain/src/compiler/optimizer/passes/remove-unused-fields.cc

Log Message:
-----------
Provide two flow-based helpers through the CFG context.

The first provides flow information for a given expression, the second
determines if a given expression might contain side effects. Right
now, both are approximate, as we don't have expression-level dataflow
tracking yet. In the future, these should be able to become more
precise.


Commit: 077e987e28986fb8d96241f0f3f94bd0b80cdfc2
https://github.com/zeek/spicy/commit/077e987e28986fb8d96241f0f3f94bd0b80cdfc2
Author: Robin Sommer <ro...@corelight.com>
Date: 2026-02-19 (Thu, 19 Feb 2026)

Changed paths:
M hilti/toolchain/include/compiler/detail/cfg.h
M hilti/toolchain/src/compiler/cfg.cc
M hilti/toolchain/src/compiler/optimizer/passes/dead-code-static.cc
M hilti/toolchain/src/compiler/optimizer/passes/remove-unused-fields.cc
M hilti/toolchain/src/compiler/optimizer/passes/remove-unused-params.cc
M tests/Baseline/hilti.optimization.dataflow-unreachable/output
M tests/Baseline/hilti.optimization.unimplemented_hook/log
M tests/Baseline/hilti.optimization.unused-struct-fields/output
M tests/Baseline/spicy.optimization.default-parser-functions/log
M tests/Baseline/spicy.optimization.feature_requirements/log
M tests/Baseline/spicy.optimization.unused-functions/log
M tests/Baseline/spicy.optimization.unused-types/log

Log Message:
-----------
Use new helper for side effects elsewhere.


Commit: b57011c34c41dc21253adb1b8c0310ee55a8f0c2
https://github.com/zeek/spicy/commit/b57011c34c41dc21253adb1b8c0310ee55a8f0c2
Author: Robin Sommer <ro...@corelight.com>
Date: 2026-02-19 (Thu, 19 Feb 2026)

Changed paths:
M hilti/toolchain/include/ast/ast-context.h
M hilti/toolchain/src/ast/ast-context.cc
M tests/Baseline/hilti.ast.basic-module/debug.log
M tests/Baseline/hilti.ast.imported-id/output
M tests/Baseline/hilti.ast.types/output
M tests/Baseline/spicy.types.unit.canonical-ids-with-import/output
M tests/Baseline/spicy.types.unit.canonical-ids/output

Log Message:
-----------
Compute AST dependencies always right after resolving.

Before, it was pretty inconsistent when exactly the information would
be available. In particular it wasn't available to post-compilation
hooks, which was unfortunate. With this change, we can now leverage
dependencies on the Zeek side.

Implementation note: We need to make the dependency computation a bit
more robust here now because it can potentially run on a not validated
(and hence invalid) AST. That can happen if the resolver flags any
errors. On the other hand, we can't easily run the validator just
before the dependency computation because that would change some
assumptions on when exactly validation runs, potentially leading to
different results.


Commit: b31a788fc29bff615ac32ddc8dc053e975e00c0b
https://github.com/zeek/spicy/commit/b31a788fc29bff615ac32ddc8dc053e975e00c0b
Author: Robin Sommer <ro...@corelight.com>
Date: 2026-02-19 (Thu, 19 Feb 2026)

Changed paths:
M hilti/toolchain/include/compiler/context.h
M hilti/toolchain/src/compiler/driver.cc
M hilti/toolchain/src/compiler/optimizer/passes/remove-unused-fields.cc
M spicy/toolchain/bin/spicy-driver.cc
M spicy/toolchain/bin/spicy-dump/main.cc

Log Message:
-----------
fixup! Add new options `--[no-]strict-public-api` to toolchain commands.

This changes the internal optional from an optional boolean to an
enum.


Commit: 351c04e2a6de85ebd8df5fb3263336e4716f779a
https://github.com/zeek/spicy/commit/351c04e2a6de85ebd8df5fb3263336e4716f779a
Author: Robin Sommer <ro...@corelight.com>
Date: 2026-02-19 (Thu, 19 Feb 2026)

Changed paths:
M hilti/runtime/include/types/bitfield.h
M hilti/toolchain/include/ast/builder/builder.h
M hilti/toolchain/include/ast/builder/node-factory.h
M hilti/toolchain/include/ast/ctors/tuple.h
M hilti/toolchain/include/ast/declaration.h
M hilti/toolchain/include/ast/expressions/grouping.h
M hilti/toolchain/include/ast/node.h
M hilti/toolchain/include/compiler/detail/cfg.h
M hilti/toolchain/src/compiler/cfg.cc
M hilti/toolchain/src/compiler/optimizer/pass.cc
M hilti/toolchain/src/compiler/optimizer/passes/remove-unused-fields.cc
M spicy/toolchain/bin/spicy-dump/printer-json.cc
M spicy/toolchain/src/compiler/codegen/unit-builder.cc

Log Message:
-----------
Address review feedback.


Compare: https://github.com/zeek/spicy/compare/6b49db4b38d4...351c04e2a6de

To unsubscribe from these emails, change your notification settings at https://github.com/zeek/spicy/settings/notifications
Reply all
Reply to author
Forward
0 new messages