@@ -5871,8 +5871,8 @@ export class Compiler extends DiagnosticEmitter {
5871
5871
let alreadyRetained = this . skippedAutoreleases . has ( valueExpr ) ;
5872
5872
if ( flow . isAnyLocalFlag ( localIndex , LocalFlags . ANY_RETAINED ) ) {
5873
5873
valueExpr = this . makeReplace (
5874
- module . local_get ( localIndex , type . toNativeType ( ) ) ,
5875
5874
valueExpr ,
5875
+ module . local_get ( localIndex , type . toNativeType ( ) ) ,
5876
5876
alreadyRetained
5877
5877
) ;
5878
5878
if ( tee ) { // local = REPLACE(local, value)
@@ -5927,8 +5927,8 @@ export class Compiler extends DiagnosticEmitter {
5927
5927
let alreadyRetained = this . skippedAutoreleases . has ( valueExpr ) ;
5928
5928
valueExpr = module . global_set ( global . internalName ,
5929
5929
this . makeReplace (
5930
- module . global_get ( global . internalName , nativeType ) , // oldRef
5931
- valueExpr , // newRef
5930
+ valueExpr ,
5931
+ module . global_get ( global . internalName , nativeType ) ,
5932
5932
alreadyRetained
5933
5933
)
5934
5934
) ;
@@ -5979,7 +5979,8 @@ export class Compiler extends DiagnosticEmitter {
5979
5979
var nativeThisType = thisType . toNativeType ( ) ;
5980
5980
5981
5981
if ( fieldType . isManaged && thisType . isManaged ) {
5982
- let tempThis = flow . getTempLocal ( thisType ) ;
5982
+ let tempThis = flow . getTempLocal ( thisType , findUsedLocals ( valueExpr ) ) ;
5983
+ // set before and read after valueExpr executes below ^
5983
5984
let alreadyRetained = this . skippedAutoreleases . has ( valueExpr ) ;
5984
5985
let ret : ExpressionRef ;
5985
5986
if ( tee ) { // ((t1 = this).field = REPLACE(t1.field, t2 = value)), t2
@@ -5990,11 +5991,11 @@ export class Compiler extends DiagnosticEmitter {
5990
5991
module . store ( fieldType . byteSize ,
5991
5992
module . local_tee ( tempThis . index , thisExpr ) ,
5992
5993
this . makeReplace (
5993
- module . load ( fieldType . byteSize , fieldType . is ( TypeFlags . SIGNED ) , // oldRef
5994
+ module . local_tee ( tempValue . index , valueExpr ) ,
5995
+ module . load ( fieldType . byteSize , fieldType . is ( TypeFlags . SIGNED ) ,
5994
5996
module . local_get ( tempThis . index , nativeThisType ) ,
5995
5997
nativeFieldType , field . memoryOffset
5996
5998
) ,
5997
- module . local_tee ( tempValue . index , valueExpr ) , // newRef
5998
5999
alreadyRetained
5999
6000
) ,
6000
6001
nativeFieldType , field . memoryOffset
@@ -6007,11 +6008,11 @@ export class Compiler extends DiagnosticEmitter {
6007
6008
ret = module . store ( fieldType . byteSize ,
6008
6009
module . local_tee ( tempThis . index , thisExpr ) ,
6009
6010
this . makeReplace (
6010
- module . load ( fieldType . byteSize , fieldType . is ( TypeFlags . SIGNED ) , // oldRef
6011
+ valueExpr ,
6012
+ module . load ( fieldType . byteSize , fieldType . is ( TypeFlags . SIGNED ) ,
6011
6013
module . local_get ( tempThis . index , nativeThisType ) ,
6012
6014
nativeFieldType , field . memoryOffset
6013
6015
) ,
6014
- valueExpr , // newRef
6015
6016
alreadyRetained
6016
6017
) ,
6017
6018
nativeFieldType , field . memoryOffset
@@ -6733,10 +6734,10 @@ export class Compiler extends DiagnosticEmitter {
6733
6734
6734
6735
/** Makes a replace, retaining the new expression's value and releasing the old expression's value, in this order. */
6735
6736
makeReplace (
6736
- /** Old value being replaced. */
6737
- oldExpr : ExpressionRef ,
6738
6737
/** New value being assigned. */
6739
6738
newExpr : ExpressionRef ,
6739
+ /** Old value being replaced. */
6740
+ oldExpr : ExpressionRef ,
6740
6741
/** Whether the new value is already retained. */
6741
6742
alreadyRetained : bool = false ,
6742
6743
) : ExpressionRef {
0 commit comments