rta: do not try to remove things from a set in iteration
authorJean Privat <jean@pryen.org>
Wed, 16 Apr 2014 17:28:13 +0000 (13:28 -0400)
committerJean Privat <jean@pryen.org>
Fri, 25 Apr 2014 13:16:57 +0000 (09:16 -0400)
Instead, register the things to remove then remove them once the
iteration is over,

Signed-off-by: Jean Privat <jean@pryen.org>

src/rapid_type_analysis.nit

index 4916889..a40ca22 100644 (file)
@@ -164,6 +164,9 @@ class RapidTypeAnalysis
        # Methods that are still candidate to the try_send
        private var totry_methods = new HashSet[MMethod]
 
+       # Methods that are are no more candidate to the try_send
+       private var totry_methods_to_remove = new Array[MMethod]
+
        # Methods that are or were candidate to the try_send
        # Used to ensure that try_send is only used once
        private var try_methods = new HashSet[MMethod]
@@ -330,6 +333,10 @@ class RapidTypeAnalysis
                for p in totry_methods do try_send(mtype, p)
                for p in live_super_sends do try_super_send(mtype, p)
 
+               # Remove cleared ones
+               for p in totry_methods_to_remove do totry_methods.remove(p)
+               totry_methods_to_remove.clear
+
                var bound_mtype = mtype.anchor_to(mainmodule, recv)
                for cd in bound_mtype.collect_mclassdefs(mainmodule)
                do
@@ -378,7 +385,7 @@ class RapidTypeAnalysis
                        if not live_methoddefs.has(d) then return
                end
                #print "full property: {mpropdef.mproperty} for {mpropdef.mproperty.mpropdefs.length} definitions"
-               totry_methods.remove(mpropdef.mproperty)
+               totry_methods_to_remove.add(mpropdef.mproperty)
        end
 
        fun add_send(recv: MType, mproperty: MMethod)