equal
deleted
inserted
replaced
714 IncorporationAction(UndetVar uv, Type t) { |
714 IncorporationAction(UndetVar uv, Type t) { |
715 this.uv = uv; |
715 this.uv = uv; |
716 this.t = t; |
716 this.t = t; |
717 } |
717 } |
718 |
718 |
|
719 public abstract IncorporationAction dup(UndetVar that); |
|
720 |
719 /** |
721 /** |
720 * Incorporation action entry-point. Subclasses should define the logic associated with |
722 * Incorporation action entry-point. Subclasses should define the logic associated with |
721 * this incorporation action. |
723 * this incorporation action. |
722 */ |
724 */ |
723 abstract void apply(InferenceContext ic, Warner warn); |
725 abstract void apply(InferenceContext ic, Warner warn); |
760 BiPredicate<InferenceContext, Type> typeFilter, InferenceBound from) { |
762 BiPredicate<InferenceContext, Type> typeFilter, InferenceBound from) { |
761 super(uv, t); |
763 super(uv, t); |
762 this.from = from; |
764 this.from = from; |
763 this.typeFunc = typeFunc; |
765 this.typeFunc = typeFunc; |
764 this.optFilter = typeFilter; |
766 this.optFilter = typeFilter; |
|
767 } |
|
768 |
|
769 @Override |
|
770 public IncorporationAction dup(UndetVar that) { |
|
771 return new CheckBounds(that, t, typeFunc, optFilter, from); |
765 } |
772 } |
766 |
773 |
767 @Override |
774 @Override |
768 void apply(InferenceContext inferenceContext, Warner warn) { |
775 void apply(InferenceContext inferenceContext, Warner warn) { |
769 t = typeFunc.apply(inferenceContext, t); |
776 t = typeFunc.apply(inferenceContext, t); |
830 EqCheckLegacy(UndetVar uv, Type t, InferenceBound from) { |
837 EqCheckLegacy(UndetVar uv, Type t, InferenceBound from) { |
831 super(uv, t, InferenceContext::asInstType, InferenceContext::free, from); |
838 super(uv, t, InferenceContext::asInstType, InferenceContext::free, from); |
832 } |
839 } |
833 |
840 |
834 @Override |
841 @Override |
|
842 public IncorporationAction dup(UndetVar that) { |
|
843 return new EqCheckLegacy(that, t, from); |
|
844 } |
|
845 |
|
846 @Override |
835 EnumSet<InferenceBound> boundsToCheck() { |
847 EnumSet<InferenceBound> boundsToCheck() { |
836 return (from == InferenceBound.EQ) ? |
848 return (from == InferenceBound.EQ) ? |
837 EnumSet.allOf(InferenceBound.class) : |
849 EnumSet.allOf(InferenceBound.class) : |
838 EnumSet.of(InferenceBound.EQ); |
850 EnumSet.of(InferenceBound.EQ); |
839 } |
851 } |
845 class CheckInst extends CheckBounds { |
857 class CheckInst extends CheckBounds { |
846 |
858 |
847 EnumSet<InferenceBound> to; |
859 EnumSet<InferenceBound> to; |
848 |
860 |
849 CheckInst(UndetVar uv, InferenceBound ib, InferenceBound... rest) { |
861 CheckInst(UndetVar uv, InferenceBound ib, InferenceBound... rest) { |
|
862 this(uv, EnumSet.of(ib, rest)); |
|
863 } |
|
864 |
|
865 CheckInst(UndetVar uv, EnumSet<InferenceBound> to) { |
850 super(uv, uv.getInst(), InferenceBound.EQ); |
866 super(uv, uv.getInst(), InferenceBound.EQ); |
851 this.to = EnumSet.of(ib, rest); |
867 this.to = to; |
|
868 } |
|
869 |
|
870 @Override |
|
871 public IncorporationAction dup(UndetVar that) { |
|
872 return new CheckInst(that, to); |
852 } |
873 } |
853 |
874 |
854 @Override |
875 @Override |
855 EnumSet<InferenceBound> boundsToCheck() { |
876 EnumSet<InferenceBound> boundsToCheck() { |
856 return to; |
877 return to; |
866 * Replace undetvars in bounds and check that the inferred type conforms to all bounds. |
887 * Replace undetvars in bounds and check that the inferred type conforms to all bounds. |
867 */ |
888 */ |
868 class SubstBounds extends CheckInst { |
889 class SubstBounds extends CheckInst { |
869 SubstBounds(UndetVar uv) { |
890 SubstBounds(UndetVar uv) { |
870 super(uv, InferenceBound.LOWER, InferenceBound.EQ, InferenceBound.UPPER); |
891 super(uv, InferenceBound.LOWER, InferenceBound.EQ, InferenceBound.UPPER); |
|
892 } |
|
893 |
|
894 @Override |
|
895 public IncorporationAction dup(UndetVar that) { |
|
896 return new SubstBounds(that); |
871 } |
897 } |
872 |
898 |
873 @Override |
899 @Override |
874 void apply(InferenceContext inferenceContext, Warner warn) { |
900 void apply(InferenceContext inferenceContext, Warner warn) { |
875 for (Type undet : inferenceContext.undetvars) { |
901 for (Type undet : inferenceContext.undetvars) { |
905 */ |
931 */ |
906 class CheckUpperBounds extends IncorporationAction { |
932 class CheckUpperBounds extends IncorporationAction { |
907 |
933 |
908 public CheckUpperBounds(UndetVar uv, Type t) { |
934 public CheckUpperBounds(UndetVar uv, Type t) { |
909 super(uv, t); |
935 super(uv, t); |
|
936 } |
|
937 |
|
938 @Override |
|
939 public IncorporationAction dup(UndetVar that) { |
|
940 return new CheckUpperBounds(that, t); |
910 } |
941 } |
911 |
942 |
912 @Override |
943 @Override |
913 void apply(InferenceContext inferenceContext, Warner warn) { |
944 void apply(InferenceContext inferenceContext, Warner warn) { |
914 List<Type> boundList = uv.getBounds(InferenceBound.UPPER).stream() |
945 List<Type> boundList = uv.getBounds(InferenceBound.UPPER).stream() |
956 public PropagateBounds(UndetVar uv, Type t, InferenceBound ib) { |
987 public PropagateBounds(UndetVar uv, Type t, InferenceBound ib) { |
957 super(uv, t); |
988 super(uv, t); |
958 this.ib = ib; |
989 this.ib = ib; |
959 } |
990 } |
960 |
991 |
|
992 @Override |
|
993 public IncorporationAction dup(UndetVar that) { |
|
994 return new PropagateBounds(that, t, ib); |
|
995 } |
|
996 |
961 void apply(InferenceContext inferenceContext, Warner warner) { |
997 void apply(InferenceContext inferenceContext, Warner warner) { |
962 Type undetT = inferenceContext.asUndetVar(t); |
998 Type undetT = inferenceContext.asUndetVar(t); |
963 if (undetT.hasTag(UNDETVAR) && !((UndetVar)undetT).isCaptured()) { |
999 if (undetT.hasTag(UNDETVAR) && !((UndetVar)undetT).isCaptured()) { |
964 UndetVar uv2 = (UndetVar)undetT; |
1000 UndetVar uv2 = (UndetVar)undetT; |
965 //symmetric propagation |
1001 //symmetric propagation |