SmallSense__UnionType.st
changeset 179 e444be9de40a
parent 174 3e08d765d86f
child 249 8bc64027b189
--- a/SmallSense__UnionType.st	Thu Feb 27 10:15:47 2014 +0000
+++ b/SmallSense__UnionType.st	Sat Mar 01 23:34:40 2014 +0000
@@ -5,7 +5,7 @@
 Type subclass:#UnionType
 	instanceVariableNames:'types trustfullness trustfullnessBonus'
 	classVariableNames:''
-	poolDictionaries:''
+	poolDictionaries:'SmallSense::SmalltalkInferencerParameters'
 	category:'SmallSense-Smalltalk-Types'
 !
 
@@ -196,10 +196,27 @@
     types size < 1 ifTrue:[ ^ self ].
 
     "Experimental - remove those with trustfullness less than mine"    
-    types := types reject:[:type|type trustfullness < trustfullness ].
+    types := types reject:[:type|type trustfullness < trustfullness ].      
+
+
+    (UnionTypeReduceThreshold notNil or:[types size > UnionTypeMaxSize]) ifTrue:[
+        "/ Try to find common superclass...
+        types size > (UnionTypeReduceThreshold ? 5) ifTrue:[
+            | reduced |    
+            reduced := types reduce:[ :a :b | ClassType new klass: (a klass commonSuperclass: b klass)].
+            ((reduced klass ~~ Object) and:[reduced klass ~~ Object class]) ifTrue:[ 
+                types  := OrderedCollection with: reduced. 
+            ] ifFalse:[ 
+                "/ If the size of types exeeds limit, make it Object anyway.
+                types size > UnionTypeMaxSize ifTrue:[ 
+                    types  := OrderedCollection with: reduced. 
+                ].
+            ].
+        ].     
+    ].
 
     "Created: / 17-05-2012 / 19:38:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 24-09-2013 / 15:31:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 01-03-2014 / 23:28:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 updateTrustfullness