293
place.loc
294
);
295
}
296
- place.effect = effectKind === Effect.Mutate ? Effect.Mutate : Effect.Read;
296
+ place.effect =
297
+ effectKind === Effect.ConditionallyMutate
298
+ ? Effect.ConditionallyMutate
299
+ : Effect.Read;
300
return;
301
}
302
let valueKind: ValueKind | null = this.kind(place);
316
}
317
break;
318
}
316
- case Effect.Mutate: {
319
+ case Effect.ConditionallyMutate: {
320
if (
321
valueKind === ValueKind.Mutable ||
322
valueKind === ValueKind.Context
323
) {
321
- effect = Effect.Mutate;
324
+ effect = Effect.ConditionallyMutate;
325
} else {
326
if (shouldError) {
327
CompilerError.invalidInput(
357
// valueKind === ValueKind.Mutable,
358
// `expected valueKind to be 'Mutable' but found to be '${valueKind}'`
359
// );
357
- effect = isObjectType(place.identifier) ? Effect.Store : Effect.Mutate;
360
+ effect = isObjectType(place.identifier)
361
+ ? Effect.Store
362
+ : Effect.ConditionallyMutate;
363
break;
364
}
365
case Effect.Capture: {
621
for (const instr of block.instructions) {
622
const instrValue = instr.value;
623
let effectKind: Effect | null = null;
619
- let lvalueEffect = Effect.Mutate;
624
+ let lvalueEffect = Effect.ConditionallyMutate;
625
let valueKind: ValueKind;
626
switch (instrValue.kind) {
627
case "BinaryExpression": {
639
}
640
case "NewExpression": {
641
valueKind = ValueKind.Mutable;
637
- effectKind = Effect.Mutate;
642
+ effectKind = Effect.ConditionallyMutate;
643
break;
644
}
645
case "ObjectExpression": {
674
}
675
case "TaggedTemplateExpression": {
676
valueKind = ValueKind.Mutable;
672
- effectKind = Effect.Mutate;
677
+ effectKind = Effect.ConditionallyMutate;
678
break;
679
}
680
case "TemplateLiteral": {
687
case "RegExpLiteral": {
688
// RegExp instances are mutable objects
689
valueKind = ValueKind.Mutable;
685
- effectKind = Effect.Mutate;
690
+ effectKind = Effect.ConditionallyMutate;
691
break;
692
}
693
case "Debugger":
760
state.referenceAndCheckError(place, effects[i]);
761
}
762
} else {
758
- state.reference(place, Effect.Mutate);
763
+ state.reference(place, Effect.ConditionallyMutate);
764
}
765
}
766
if (signature !== null) {
769
signature.calleeEffect
770
);
771
} else {
767
- state.reference(instrValue.callee, Effect.Mutate);
772
+ state.reference(instrValue.callee, Effect.ConditionallyMutate);
773
}
774
775
state.initialize(instrValue, returnValueKind);
776
state.define(instr.lvalue, instrValue);
772
- instr.lvalue.effect = Effect.Mutate;
777
+ instr.lvalue.effect = Effect.ConditionallyMutate;
778
continue;
779
}
780
case "MethodCall": {
799
// mutating effects
800
state.referenceAndCheckError(place, effects[i]);
801
} else {
797
- state.reference(place, Effect.Mutate);
802
+ state.reference(place, Effect.ConditionallyMutate);
803
}
804
}
805
if (signature !== null) {
808
signature.calleeEffect
809
);
810
} else {
806
- state.reference(instrValue.receiver, Effect.Mutate);
811
+ state.reference(instrValue.receiver, Effect.ConditionallyMutate);
812
}
813
814
state.initialize(instrValue, ValueKind.Mutable);
815
state.define(instr.lvalue, instrValue);
811
- instr.lvalue.effect = Effect.Mutate;
816
+ instr.lvalue.effect = Effect.ConditionallyMutate;
817
continue;
818
}
819
case "PropertyStore": {
820
const effect =
821
state.kind(instrValue.object) === ValueKind.Context
817
- ? Effect.Mutate
822
+ ? Effect.ConditionallyMutate
823
: Effect.Capture;
824
state.reference(instrValue.value, effect);
825
state.reference(instrValue.object, Effect.Store);
832
case "PropertyDelete": {
833
// `delete` returns a boolean (immutable) and modifies the object
834
valueKind = ValueKind.Immutable;
830
- effectKind = Effect.Mutate;
835
+ effectKind = Effect.ConditionallyMutate;
836
break;
837
}
838
case "PropertyLoad": {
839
state.reference(instrValue.object, Effect.Read);
840
const lvalue = instr.lvalue;
836
- lvalue.effect = Effect.Mutate;
841
+ lvalue.effect = Effect.ConditionallyMutate;
842
state.initialize(instrValue, state.kind(instrValue.object));
843
state.define(lvalue, instrValue);
844
continue;
846
case "ComputedStore": {
847
const effect =
848
state.kind(instrValue.object) === ValueKind.Context
844
- ? Effect.Mutate
849
+ ? Effect.ConditionallyMutate
850
: Effect.Capture;
851
state.reference(instrValue.value, effect);
852
state.reference(instrValue.property, Effect.Capture);
858
continue;
859
}
860
case "ComputedDelete": {
856
- state.reference(instrValue.object, Effect.Mutate);
861
+ state.reference(instrValue.object, Effect.ConditionallyMutate);
862
state.reference(instrValue.property, Effect.Read);
863
state.initialize(instrValue, ValueKind.Immutable);
859
- state.reference(instr.lvalue, Effect.Mutate);
864
+ state.reference(instr.lvalue, Effect.ConditionallyMutate);
865
continue;
866
}
867
case "ComputedLoad": {
868
state.reference(instrValue.object, Effect.Read);
869
state.reference(instrValue.property, Effect.Read);
870
const lvalue = instr.lvalue;
866
- lvalue.effect = Effect.Mutate;
871
+ lvalue.effect = Effect.ConditionallyMutate;
872
state.initialize(instrValue, state.kind(instrValue.object));
873
state.define(lvalue, instrValue);
874
continue;
878
// Awaiting a value causes it to change state (go from unresolved to resolved or error)
879
// It also means that any side-effects which would occur as part of the promise evaluation
880
// will occur.
876
- state.reference(instrValue.value, Effect.Mutate);
881
+ state.reference(instrValue.value, Effect.ConditionallyMutate);
882
const lvalue = instr.lvalue;
878
- lvalue.effect = Effect.Mutate;
883
+ lvalue.effect = Effect.ConditionallyMutate;
884
state.alias(lvalue, instrValue.value);
885
continue;
886
}
895
state.initialize(instrValue, state.kind(instrValue.value));
896
state.reference(instrValue.value, Effect.Read);
897
const lvalue = instr.lvalue;
893
- lvalue.effect = Effect.Mutate;
898
+ lvalue.effect = Effect.ConditionallyMutate;
899
state.alias(lvalue, instrValue.value);
900
continue;
901
}
903
const lvalue = instr.lvalue;
904
const effect =
905
state.isDefined(lvalue) && state.kind(lvalue) === ValueKind.Context
901
- ? Effect.Mutate
906
+ ? Effect.ConditionallyMutate
907
: Effect.Capture;
908
state.reference(instrValue.place, effect);
904
- lvalue.effect = Effect.Mutate;
909
+ lvalue.effect = Effect.ConditionallyMutate;
910
// direct aliasing: `a = b`;
911
state.alias(lvalue, instrValue.place);
912
continue;
914
case "LoadContext": {
915
state.reference(instrValue.place, Effect.Capture);
916
const lvalue = instr.lvalue;
912
- lvalue.effect = Effect.Mutate;
917
+ lvalue.effect = Effect.ConditionallyMutate;
918
const valueKind = state.kind(instrValue.place);
919
invariant(
920
valueKind === ValueKind.Mutable || valueKind === ValueKind.Context,
943
const effect =
944
state.isDefined(instrValue.lvalue.place) &&
945
state.kind(instrValue.lvalue.place) === ValueKind.Context
941
- ? Effect.Mutate
946
+ ? Effect.ConditionallyMutate
947
: Effect.Capture;
948
state.reference(instrValue.value, effect);
949
955
continue;
956
}
957
case "StoreContext": {
953
- state.reference(instrValue.value, Effect.Mutate);
954
- state.reference(instrValue.lvalue.place, Effect.Mutate);
958
+ state.reference(instrValue.value, Effect.ConditionallyMutate);
959
+ state.reference(instrValue.lvalue.place, Effect.ConditionallyMutate);
960
961
const lvalue = instr.lvalue;
962
state.alias(lvalue, instrValue.value);
970
state.isDefined(place) &&
971
state.kind(place) === ValueKind.Context
972
) {
968
- effect = Effect.Mutate;
973
+ effect = Effect.ConditionallyMutate;
974
break;
975
}
976
}
1017
state.isDefined(operand) &&
1018
state.kind(operand) === ValueKind.Context
1019
) {
1015
- effect = Effect.Mutate;
1020
+ effect = Effect.ConditionallyMutate;
1021
} else {
1022
effect = Effect.Freeze;
1023
}