@@ -16,6 +16,7 @@ import {
1616 FunctionEffect ,
1717 GeneratedSource ,
1818 HIRFunction ,
19+ Identifier ,
1920 IdentifierId ,
2021 InstructionKind ,
2122 InstructionValue ,
@@ -857,17 +858,19 @@ function inferBlock(
857858 break ;
858859 }
859860 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- } ;
861+ const contextRefOperands = getContextRefOperand ( state , instrValue ) ;
862+ const valueKind : AbstractValue =
863+ contextRefOperands . length > 0
864+ ? {
865+ kind : ValueKind . Context ,
866+ reason : new Set ( [ ValueReason . Other ] ) ,
867+ context : new Set ( contextRefOperands ) ,
868+ }
869+ : {
870+ kind : ValueKind . Mutable ,
871+ reason : new Set ( [ ValueReason . Other ] ) ,
872+ context : new Set ( ) ,
873+ } ;
871874 continuation = {
872875 kind : 'initialize' ,
873876 valueKind,
@@ -918,17 +921,19 @@ function inferBlock(
918921 break ;
919922 }
920923 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- } ;
924+ const contextRefOperands = getContextRefOperand ( state , instrValue ) ;
925+ const valueKind : AbstractValue =
926+ contextRefOperands . length > 0
927+ ? {
928+ kind : ValueKind . Context ,
929+ reason : new Set ( [ ValueReason . Other ] ) ,
930+ context : new Set ( contextRefOperands ) ,
931+ }
932+ : {
933+ kind : ValueKind . Mutable ,
934+ reason : new Set ( [ ValueReason . Other ] ) ,
935+ context : new Set ( ) ,
936+ } ;
932937
933938 for ( const property of instrValue . properties ) {
934939 switch ( property . kind ) {
@@ -1593,15 +1598,20 @@ function inferBlock(
15931598 }
15941599 case 'LoadLocal' : {
15951600 const lvalue = instr . lvalue ;
1596- const effect =
1597- state . isDefined ( lvalue ) &&
1598- state . kind ( lvalue ) . kind === ValueKind . Context
1599- ? Effect . ConditionallyMutate
1600- : Effect . Capture ;
1601+ CompilerError . invariant (
1602+ ! (
1603+ state . isDefined ( lvalue ) &&
1604+ state . kind ( lvalue ) . kind === ValueKind . Context
1605+ ) ,
1606+ {
1607+ reason : 'Unexpected LoadLocal with context lvalue' ,
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