@@ -25,6 +25,7 @@ trait TypeSimplifier { self: Typer =>
2525    println(s " allVarPols:  ${printPols(allVarPols)}" )
2626
2727    val  renewed  =  MutMap .empty[TypeVariable , TypeVariable ]
28+     val  renewedtsc  =  MutMap .empty[TupleSetConstraints , TupleSetConstraints ]
2829
2930    def  renew (tv : TypeVariable ):  TypeVariable  = 
3031      renewed.getOrElseUpdate(tv,
@@ -78,8 +79,17 @@ trait TypeSimplifier { self: Typer =>
7879              ).map(process(_, S (false  ->  tv)))
7980                .reduceOption(_ &-  _).filterNot(_.isTop).toList
8081            else  Nil 
82+           if  (noApproximateOverload)
83+             nv.tsc ++=  tv.tsc.iterator.map { case  (tsc, i) =>  renewedtsc.get(tsc) match  {
84+               case  S (tsc) =>  (tsc, i)
85+               case  N  if  inPlace =>  (tsc, i)
86+               case  N  => 
87+                 val  t  =  new  TupleSetConstraints (tsc.constraints, tsc.tvs)
88+                 renewedtsc +=  tsc ->  t
89+                 t.tvs =  t.tvs.map(x =>  (x._1, process(x._2, N )))
90+                 (t, i)
91+             }}
8192        }
82-         
8393        nv
8494
8595      case  ComposedType (true , l, r) => 
@@ -549,9 +559,17 @@ trait TypeSimplifier { self: Typer =>
549559                analyzed1.setAndIfUnset(tv ->  pol(tv).getOrElse(false )) { apply(pol)(ty) }
550560              case  N  => 
551561                if  (pol(tv) =/=  S (false ))
552-                   analyzed1.setAndIfUnset(tv ->  true ) { tv.lowerBounds.foreach(apply(pol.at(tv.level, true ))) }
562+                   analyzed1.setAndIfUnset(tv ->  true ) {
563+                     tv.lowerBounds.foreach(apply(pol.at(tv.level, true )))
564+                     if  (noApproximateOverload)
565+                       tv.tsc.keys.flatMap(_.tvs).foreach(u =>  apply(pol.at(tv.level,u._1))(u._2))
566+                   }
553567                if  (pol(tv) =/=  S (true ))
554-                   analyzed1.setAndIfUnset(tv ->  false ) { tv.upperBounds.foreach(apply(pol.at(tv.level, false ))) }
568+                   analyzed1.setAndIfUnset(tv ->  false ) {
569+                     tv.upperBounds.foreach(apply(pol.at(tv.level, false )))
570+                     if  (noApproximateOverload)
571+                       tv.tsc.keys.flatMap(_.tvs).foreach(u =>  apply(pol.at(tv.level,u._1))(u._2))
572+                   }
555573            }
556574          case  _ => 
557575            super .apply(pol)(st)
@@ -643,8 +661,11 @@ trait TypeSimplifier { self: Typer =>
643661            case  tv : TypeVariable  => 
644662              pol(tv) match  {
645663                case  S (pol_tv) => 
646-                   if  (analyzed2.add(pol_tv ->  tv))
664+                   if  (analyzed2.add(pol_tv ->  tv)) { 
647665                    processImpl(st, pol, pol_tv)
666+                     if  (noApproximateOverload)
667+                       tv.tsc.keys.flatMap(_.tvs).foreach(u =>  processImpl(u._2,pol.at(tv.level,u._1),pol_tv))
668+                   }
648669                case  N  => 
649670                  if  (analyzed2.add(true  ->  tv))
650671                    //  * To compute the positive co-occurrences
@@ -690,6 +711,7 @@ trait TypeSimplifier { self: Typer =>
690711                case  S (p) => 
691712                  (if  (p) tv2.lowerBounds else  tv2.upperBounds).foreach(go)
692713                  //  (if (p) getLbs(tv2) else getUbs(tv2)).foreach(go)
714+                   if  (noApproximateOverload) tv2.tsc.keys.flatMap(_.tvs).foreach(u =>  go(u._2))
693715                case  N  => 
694716                  trace(s " Analyzing invar-occ of  $tv2" ) {
695717                    analyze2(tv2, pol)
@@ -789,7 +811,7 @@ trait TypeSimplifier { self: Typer =>
789811
790812    //  * Remove variables that are 'dominated' by another type or variable
791813    //  *  A variable v dominated by T if T is in both of v's positive and negative cooccurrences
792-     allVars.foreach { case  v =>  if  (v.assignedTo.isEmpty &&  ! varSubst.contains(v)) {
814+     allVars.foreach { case  v =>  if  (v.assignedTo.isEmpty &&  ! varSubst.contains(v)  &&  v.tsc.isEmpty ) {
793815      println(s " 2[v]  $v  ${coOccurrences.get(true  ->  v)}  ${coOccurrences.get(false  ->  v)}" )
794816
795817      coOccurrences.get(true  ->  v).iterator.flatMap(_.iterator).foreach {
@@ -807,6 +829,7 @@ trait TypeSimplifier { self: Typer =>
807829
808830        case  w : TV  if  ! (w is v) &&  ! varSubst.contains(w) &&  ! varSubst.contains(v) &&  ! recVars(v)
809831          &&  coOccurrences.get(false  ->  v).exists(_(w))
832+           &&  w.tsc.isEmpty
810833        => 
811834          //  * Here we know that v is 'dominated' by w, so v can be inlined.
812835          //  * Note that we don't want to unify the two variables here
@@ -833,7 +856,7 @@ trait TypeSimplifier { self: Typer =>
833856
834857    //  * Unify equivalent variables based on polar co-occurrence analysis:
835858    allVars.foreach { case  v => 
836-       if  (! v.assignedTo.isDefined &&  ! varSubst.contains(v)) //  TODO also handle v.assignedTo.isDefined?
859+       if  (! v.assignedTo.isDefined &&  ! varSubst.contains(v)  &&  v.tsc.isEmpty ) //  TODO also handle v.assignedTo.isDefined?
837860        trace(s " 3[v]  $v + ${coOccurrences.get(true  ->  v).mkString} - ${coOccurrences.get(false  ->  v).mkString}" ) {
838861
839862        def  go (pol : Bool ):  Unit  =  coOccurrences.get(pol ->  v).iterator.flatMap(_.iterator).foreach {
@@ -850,6 +873,7 @@ trait TypeSimplifier { self: Typer =>
850873              )
851874              &&  (v.level ===  w.level)
852875              //  ^ Don't merge variables of differing levels
876+               &&  w.tsc.isEmpty
853877            => 
854878            trace(s " [w]  $w  ${printPol(S (pol))}${coOccurrences.get(pol ->  w).mkString}" ) {
855879
@@ -923,6 +947,7 @@ trait TypeSimplifier { self: Typer =>
923947    println(s " [rec]  ${recVars}" )
924948
925949    val  renewals  =  MutMap .empty[TypeVariable , TypeVariable ]
950+     val  renewaltsc  =  MutMap .empty[TupleSetConstraints , TupleSetConstraints ]
926951
927952    val  semp  =  Set .empty[TV ]
928953
@@ -999,7 +1024,7 @@ trait TypeSimplifier { self: Typer =>
9991024              nv
10001025            })
10011026            pol(tv) match  {
1002-               case  S (p) if  inlineBounds &&  ! occursInvariantly(tv) &&  ! recVars.contains(tv) => 
1027+               case  S (p) if  inlineBounds &&  ! occursInvariantly(tv) &&  ! recVars.contains(tv) &&  tv.tsc.isEmpty  => 
10031028                //  * Inline the bounds of non-rec non-invar-occ type variables
10041029                println(s " Inlining [ ${printPol(p)}] bounds of  $tv (~>  $res) " )
10051030                //  if (p) mergeTransform(true, pol, tv, Set.single(tv), canDistribForall) | res
@@ -1017,6 +1042,15 @@ trait TypeSimplifier { self: Typer =>
10171042                          res.lowerBounds =  tv.lowerBounds.map(transform(_, pol.at(tv.level, true ), Set .single(tv)))
10181043                        if  (occNums.contains(false  ->  tv))
10191044                          res.upperBounds =  tv.upperBounds.map(transform(_, pol.at(tv.level, false ), Set .single(tv)))
1045+                         if  (noApproximateOverload)
1046+                           res.tsc ++=  tv.tsc.map { case  (tsc, i) =>  renewaltsc.get(tsc) match  {
1047+                             case  S (tsc) =>  (tsc, i)
1048+                             case  N  => 
1049+                               val  t  =  new  TupleSetConstraints (tsc.constraints, tsc.tvs)
1050+                               renewaltsc +=  tsc ->  t
1051+                               t.tvs =  t.tvs.map(x =>  (x._1, transform(x._2, PolMap .neu, Set .empty)))
1052+                               (t, i)
1053+                           }}
10201054                    }
10211055                    res
10221056                  }()
0 commit comments