@@ -6652,28 +6652,46 @@ export class Compiler extends DiagnosticEmitter {
66526652 ) : void {
66536653 // Differs from `performAutoreleases` in that concluding this flow also
66546654 // concludes all its parent flows, for example on a `return`.
6655- var module = this . module ;
66566655 if ( flow . is ( FlowFlags . INLINE_CONTEXT ) ) {
66576656 // Traverse to the top-most flow containing the inlined function's
66586657 // locals as scoped locals and release these instead of all the locals.
6658+ let current = flow ;
66596659 let parent : Flow | null ;
6660- while ( parent = flow . parent ) flow = parent ;
6661- this . performAutoreleases ( flow , stmts , /* finalize */ false ) ;
6660+ while ( parent = current . parent ) current = parent ;
6661+ let scopedLocals = current . scopedLocals ;
6662+ if ( scopedLocals ) {
6663+ for ( let local of scopedLocals . values ( ) ) {
6664+ this . maybeFinishAutorelease ( local , flow , stmts ) ;
6665+ }
6666+ }
66626667 } else {
66636668 for ( let local of flow . parentFunction . localsByIndex ) {
6664- let localIndex = local . index ;
6665- if ( flow . isAnyLocalFlag ( localIndex , LocalFlags . ANY_RETAINED ) ) {
6666- flow . unsetLocalFlag ( localIndex , LocalFlags . ANY_RETAINED ) ;
6667- stmts . push (
6668- this . makeRelease (
6669- module . local_get ( localIndex , local . type . toNativeType ( ) )
6670- )
6671- ) ;
6672- }
6669+ this . maybeFinishAutorelease ( local , flow , stmts ) ;
66736670 }
66746671 }
66756672 }
66766673
6674+ /** Finishes a single autorelease of the specified local. */
6675+ private maybeFinishAutorelease (
6676+ /** Local to finish autoreleasing. */
6677+ local : Local ,
6678+ /** Flow releasing its queued autoreleases. */
6679+ flow : Flow ,
6680+ /** Array of statements to append the releases to. */
6681+ stmts : ExpressionRef [ ]
6682+ ) : void {
6683+ var localIndex = local . index ;
6684+ var module = this . module ;
6685+ if ( ~ localIndex && flow . isAnyLocalFlag ( localIndex , LocalFlags . ANY_RETAINED ) ) {
6686+ flow . unsetLocalFlag ( localIndex , LocalFlags . ANY_RETAINED ) ;
6687+ stmts . push (
6688+ this . makeRelease (
6689+ module . local_get ( localIndex , local . type . toNativeType ( ) )
6690+ )
6691+ ) ;
6692+ }
6693+ }
6694+
66776695 // </reference-counting>
66786696
66796697 /** Creates a direct call to the specified function. */
0 commit comments