← Contribution overview

Function exits and return values ยท PR #4591

Support function-scope Drops on normal function exit

Merged

Objective

Add function-scope Drop handling for normal exits.

Cover unit tail expressions and function parameters.

Why it was needed

A function can end with a tail expression of type (). A call to another unit-returning function is one example.

gccrs did not emit local Drop calls after this form, and it did not register droppable parameters.

This PR added both cases to normal function-exit cleanup.

Main changes

  • Emits the current scope’s Drop calls after compiling a unit tail expression.
  • Collects droppable parameters while compiling the parameter list, then registers them after creating the function-body block.
  • This registration order makes body locals drop before parameters on a normal function exit.

Test cases

Later change

At this point, parameters and body locals still shared one Drop-candidate list.

PR #4718 later separated their scopes.

View PR on GitHub ← Contribution overview