Repository navigation
Custard: discard unused droppable results before local liveness analysis - #4761
Merged
gebner merged 1 commit intoOct 22, 2026
Merged
Conversation
Discard unused initializer and sequence results before simplifying and floating nested lets. Eliminate droppable computations while retaining comment text and observable effects, and preserve named unused lets for the KaRaMeL backends. Extend PulseComment to cover discarded read chains, compound initializers, and effectful results. Register OCaml extraction coverage alongside the native C/C++ regression. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df4f3106-a781-4948-adcd-041ba6fb08fc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Discard unused initializer and sequence results before simplifying and floating nested lets. Eliminate droppable computations while retaining comment text and observable effects, and preserve named unused lets for the KaRaMeL backends.
Extend PulseComment to cover discarded read chains, compound initializers, and effectful results. Register OCaml extraction coverage alongside the native C/C++ regression.
Summary
Fix dead-local elimination in Custard when an expression's result is unused.
Discarding the result must happen before simplifying and floating the
expression's nested lets, so bindings used only to compute that result can
also be eliminated.
This surfaced during EverParse direct-to-C extraction: generated validators
contained unused intermediate locals and failed to compile with
-Werror=unused-variable.Problem
Two related cases left dead bindings in the generated C:
Discarded commented expressions. The C printer already omits a
droppable operand when printing a discarded
Commentedexpression, whileretaining the comment text. However, simplification had counted uses in
that operand and retained the bindings producing it. For example:
Once the commented value disappeared,
middlewas left unused.Discarded compound initializers. An initializer containing nested lets
was simplified before the enclosing binding was recognized as unused.
Floating those lets out could leave intermediates whose only consumer was
the initializer's discarded result. An effectful call must still execute,
but its unused return value need not be bound to a local.
This is over-retention of dead values, not deletion of live computations.
Implementation
In
src/custard/FStarC.Custard.Simplify.fst:discard_value, which propagates discarded-result handling throughthe result positions of nested lets and sequences.
droppable operand, retain the comment node and replace only its operand
with unit.
used, and discard an unused initializer's result before simplifying and
floating its lets.
The transformation uses the existing
is_droppablepredicate. Observableeffects are retained, and the existing treatment of programmer-named unused
lets for the
KrmlCandKrmlRustbackends is preserved.There are no new options, attributes, or CUI-format changes, and the fix does
not depend on the separate EverParse-related Custard feature branches.
Regression coverage
Extend
tests/custard/pulse/PulseComment.fstwith:effectful call must remain.
The program checks that both effectful calls execute. The Makefile also
checks that the new comment strings survive and registers
PulseCommentfor OCaml extraction/type-checking alongside its existing native C test.
Focused validation
with unused
middle,n, and__anf0locals.PulseCommentcompiles as C11 and C++17 with warnings treatedas errors, and its C executable succeeds.
PulseCommentsucceed.DeadReadandCDeadLetC/C++ compilation and execution succeed.PulseCommentEndandPulseCommentDynrejection checks succeed.