@@ -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,20 @@ 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 : 'Unexpected LoadLocal with context lvalue' ,
1607+ loc : lvalue . loc ,
1608+ } ,
1609+ ) ;
16011610 state . referenceAndRecordEffects (
16021611 freezeActions ,
16031612 instrValue . place ,
1604- effect ,
1613+ Effect . Capture ,
16051614 ValueReason . Other ,
16061615 ) ;
16071616 lvalue . effect = Effect . ConditionallyMutate ;
@@ -1932,19 +1941,20 @@ function inferBlock(
19321941 ) ;
19331942}
19341943
1935- function hasContextRefOperand (
1944+ function getContextRefOperand (
19361945 state : InferenceState ,
19371946 instrValue : InstructionValue ,
1938- ) : boolean {
1947+ ) : Array < Place > {
1948+ const result = [ ] ;
19391949 for ( const place of eachInstructionValueOperand ( instrValue ) ) {
19401950 if (
19411951 state . isDefined ( place ) &&
19421952 state . kind ( place ) . kind === ValueKind . Context
19431953 ) {
1944- return true ;
1954+ result . push ( place ) ;
19451955 }
19461956 }
1947- return false ;
1957+ return result ;
19481958}
19491959
19501960export function getFunctionCallSignature (
0 commit comments