748
case 'Alias':
749
case 'Capture': {
750
CompilerError.invariant(
751
- effect.kind === 'Capture' || initialized.has(effect.into.identifier.id),
751
+ effect.kind === 'Capture' ||
752
+ effect.kind === 'MaybeAlias' ||
753
+ initialized.has(effect.into.identifier.id),
754
{
753
- reason: `Expected destination value to already be initialized within this instruction for Alias effect`,
754
- description: `Destination ${printPlace(effect.into)} is not initialized in this instruction`,
755
+ reason: `Expected destination to already be initialized within this instruction`,
756
+ description:
757
+ `Destination ${printPlace(effect.into)} is not initialized in this ` +
758
+ `instruction for effect ${printAliasingEffect(effect)}`,
759
details: [
760
{
761
kind: 'error',
771
* copy-on-write semantics, then we can prune the effect
772
*/
773
const intoKind = state.kind(effect.into).kind;
770
- let isMutableDesination: boolean;
774
+ let destinationType: 'context' | 'mutable' | null = null;
775
switch (intoKind) {
772
- case ValueKind.Context:
773
- case ValueKind.Mutable:
774
- case ValueKind.MaybeFrozen: {
775
- isMutableDesination = true;
776
+ case ValueKind.Context: {
777
+ destinationType = 'context';
778
break;
779
}
778
- default: {
779
- isMutableDesination = false;
780
+ case ValueKind.Mutable:
781
+ case ValueKind.MaybeFrozen: {
782
+ destinationType = 'mutable';
783
break;
784
}
785
}
786
const fromKind = state.kind(effect.from).kind;
784
- let isMutableReferenceType: boolean;
787
+ let sourceType: 'context' | 'mutable' | 'frozen' | null = null;
788
switch (fromKind) {
789
+ case ValueKind.Context: {
790
+ sourceType = 'context';
791
+ break;
792
+ }
793
case ValueKind.Global:
794
case ValueKind.Primitive: {
788
- isMutableReferenceType = false;
795
break;
796
}
797
case ValueKind.Frozen: {
792
- isMutableReferenceType = false;
793
- applyEffect(
794
- context,
795
- state,
796
- {
797
- kind: 'ImmutableCapture',
798
- from: effect.from,
799
- into: effect.into,
800
- },
801
- initialized,
802
- effects,
803
- );
798
+ sourceType = 'frozen';
799
break;
800
}
801
default: {
807
- isMutableReferenceType = true;
802
+ sourceType = 'mutable';
803
break;
804
}
805
}
811
- if (isMutableDesination && isMutableReferenceType) {
806
+
807
+ if (sourceType === 'frozen') {
808
+ applyEffect(
809
+ context,
810
+ state,
811
+ {
812
+ kind: 'ImmutableCapture',
813
+ from: effect.from,
814
+ into: effect.into,
815
+ },
816
+ initialized,
817
+ effects,
818
+ );
819
+ } else if (
820
+ (sourceType === 'mutable' && destinationType === 'mutable') ||
821
+ effect.kind === 'MaybeAlias'
822
+ ) {
823
effects.push(effect);
824
+ } else if (
825
+ (sourceType === 'context' && destinationType != null) ||
826
+ (sourceType === 'mutable' && destinationType === 'context')
827
+ ) {
828
+ applyEffect(
829
+ context,
830
+ state,
831
+ {kind: 'MaybeAlias', from: effect.from, into: effect.into},
832
+ initialized,
833
+ effects,
834
+ );
835
}
836
break;
837
}