Repository navigation
A default trait method is lowered as any function's body is: it drops its owned parameters and runs its defers - #3361
Merged
Merged
Conversation
added 2 commits
November 16, 2026 02:42
… its owned parameters and runs its defers; destructors are known before any body is generated
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.
The leak. A default trait method an impl inherits never dropped an owned parameter: a
List[str]argument leaked (debug allocator:leak count=3) and aDroptype's destructor never ran. Its body had a lowering of its own (in codegen until #3359, copied into the MIR phase by it) that created the parameter locals and nothing else: no drop scheduling, noStorageLive, nodeferat return, no D22 fact context, none of the passes an ordinary body gets.Fix: one owner.
lower_fn_with_sigreads what it needs of a declaration into aFnLowerShape(flags, body, parameter records, spans) and callslower_fn_shape; a default method, which has no declaration node, builds the same shape from the trait's parameter records and the impl's copy of the body. The second lowering is gone.The bug this exposed, exact line.
Codegen.gen_modulegenerated default method bodies in pass 1.3 and registered destructors in pass 1.5 (detect_drop_functions). A default body that drops aDroptype built that type's glue (ensure_structural_drop_fn, cached per module) whiledrop_fn_valueswas still empty:__drop_struct_<ty>wasentry: ret void(read withWITH_DUMP_LLIR_PRE=1), and every drop of that type in the program called it. Destructors are now detected before any body is generated.Tests (both fail on the compiler before this, pass after):
behav_default_method_is_an_ordinary_body(destructor of an owned parameter,defer),da_default_method_drops_owned_parameters(debug allocator,leak count=0).Filed, not in this change: #3360 (Sema checks a default body with a smaller copy of the function-body check: an implicit
Oktail there is an ICE).Battery: GREEN (820 s).