@@ -857,17 +857,19 @@ function inferBlock(
857857 break ;
858858 }
859859 case 'ArrayExpression' : {
860- const valueKind : AbstractValue = hasContextRefOperand ( state , instrValue )
861- ? {
862- kind : ValueKind . Context ,
863- reason : new Set ( [ ValueReason . Other ] ) ,
864- context : new Set ( ) ,
865- }
866- : {
867- kind : ValueKind . Mutable ,
868- reason : new Set ( [ ValueReason . Other ] ) ,
869- context : new Set ( ) ,
870- } ;
860+ const contextRefOperands = getContextRefOperand ( state , instrValue ) ;
861+ const valueKind : AbstractValue =
862+ contextRefOperands . length > 0
863+ ? {
864+ kind : ValueKind . Context ,
865+ reason : new Set ( [ ValueReason . Other ] ) ,
866+ context : new Set ( contextRefOperands ) ,
867+ }
868+ : {
869+ kind : ValueKind . Mutable ,
870+ reason : new Set ( [ ValueReason . Other ] ) ,
871+ context : new Set ( ) ,
872+ } ;
871873 continuation = {
872874 kind : 'initialize' ,
873875 valueKind,
@@ -918,17 +920,19 @@ function inferBlock(
918920 break ;
919921 }
920922 case 'ObjectExpression' : {
921- const valueKind : AbstractValue = hasContextRefOperand ( state , instrValue )
922- ? {
923- kind : ValueKind . Context ,
924- reason : new Set ( [ ValueReason . Other ] ) ,
925- context : new Set ( ) ,
926- }
927- : {
928- kind : ValueKind . Mutable ,
929- reason : new Set ( [ ValueReason . Other ] ) ,
930- context : new Set ( ) ,
931- } ;
923+ const contextRefOperands = getContextRefOperand ( state , instrValue ) ;
924+ const valueKind : AbstractValue =
925+ contextRefOperands . length > 0
926+ ? {
927+ kind : ValueKind . Context ,
928+ reason : new Set ( [ ValueReason . Other ] ) ,
929+ context : new Set ( contextRefOperands ) ,
930+ }
931+ : {
932+ kind : ValueKind . Mutable ,
933+ reason : new Set ( [ ValueReason . Other ] ) ,
934+ context : new Set ( ) ,
935+ } ;
932936
933937 for ( const property of instrValue . properties ) {
934938 switch ( property . kind ) {
@@ -1593,15 +1597,21 @@ function inferBlock(
15931597 }
15941598 case 'LoadLocal' : {
15951599 const lvalue = instr . lvalue ;
1596- const effect =
1597- state . isDefined ( lvalue ) &&
1598- state . kind ( lvalue ) . kind === ValueKind . Context
1599- ? Effect . ConditionallyMutate
1600- : Effect . Capture ;
1600+ CompilerError . invariant (
1601+ ! (
1602+ state . isDefined ( lvalue ) &&
1603+ state . kind ( lvalue ) . kind === ValueKind . Context
1604+ ) ,
1605+ {
1606+ reason :
1607+ '[InferReferenceEffects] Unexpected LoadLocal with context kind' ,
1608+ loc : lvalue . loc ,
1609+ } ,
1610+ ) ;
16011611 state . referenceAndRecordEffects (
16021612 freezeActions ,
16031613 instrValue . place ,
1604- effect ,
1614+ Effect . Capture ,
16051615 ValueReason . Other ,
16061616 ) ;
16071617 lvalue . effect = Effect . ConditionallyMutate ;
@@ -1932,19 +1942,20 @@ function inferBlock(
19321942 ) ;
19331943}
19341944
1935- function hasContextRefOperand (
1945+ function getContextRefOperand (
19361946 state : InferenceState ,
19371947 instrValue : InstructionValue ,
1938- ) : boolean {
1948+ ) : Array < Place > {
1949+ const result = [ ] ;
19391950 for ( const place of eachInstructionValueOperand ( instrValue ) ) {
19401951 if (
19411952 state . isDefined ( place ) &&
19421953 state . kind ( place ) . kind === ValueKind . Context
19431954 ) {
1944- return true ;
1955+ result . push ( place ) ;
19451956 }
19461957 }
1947- return false ;
1958+ return result ;
19481959}
19491960
19501961export function getFunctionCallSignature (
0 commit comments