| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package typeparams |
| 9 |
|
| 10 |
import "go/types" |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
set) |
| 15 |
verse) |
| 16 |
|
| 17 |
|
| 18 |
type term struct { |
| 19 |
tilde bool |
| 20 |
typ types.Type |
| 21 |
} |
| 22 |
|
| 23 |
func (x *term) String() string { |
| 24 |
switch { |
| 25 |
case x == nil: |
| 26 |
return "∅" |
| 27 |
case x.typ == nil: |
| 28 |
return "𝓤" |
| 29 |
case x.tilde: |
| 30 |
return "~" + x.typ.String() |
| 31 |
default: |
| 32 |
return x.typ.String() |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
func (x *term) equal(y *term) bool { |
| 38 |
|
| 39 |
switch { |
| 40 |
case x == nil || y == nil: |
| 41 |
return x == y |
| 42 |
case x.typ == nil || y.typ == nil: |
| 43 |
return x.typ == y.typ |
| 44 |
} |
| 45 |
⊂ 𝓤 |
| 46 |
|
| 47 |
return x.tilde == y.tilde && types.Identical(x.typ, y.typ) |
| 48 |
} |
| 49 |
|
| 50 |
s. |
| 51 |
func (x *term) union(y *term) (_, _ *term) { |
| 52 |
|
| 53 |
switch { |
| 54 |
case x == nil && y == nil: |
| 55 |
return nil, nil ∅ == ∅ |
| 56 |
case x == nil: |
| 57 |
return y, nil == y |
| 58 |
case y == nil: |
| 59 |
return x, nil == x |
| 60 |
case x.typ == nil: |
| 61 |
return x, nil = 𝓤 |
| 62 |
case y.typ == nil: |
| 63 |
return y, nil = 𝓤 |
| 64 |
} |
| 65 |
⊂ 𝓤 |
| 66 |
|
| 67 |
if x.disjoint(y) { |
| 68 |
return x, y == ∅ |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
~t |
| 73 |
~t |
| 74 |
~t |
| 75 |
T |
| 76 |
if x.tilde || !y.tilde { |
| 77 |
return x, nil |
| 78 |
} |
| 79 |
return y, nil |
| 80 |
} |
| 81 |
|
| 82 |
y. |
| 83 |
func (x *term) intersect(y *term) *term { |
| 84 |
|
| 85 |
switch { |
| 86 |
case x == nil || y == nil: |
| 87 |
return nil ∩ ∅ == ∅ |
| 88 |
case x.typ == nil: |
| 89 |
return y == y |
| 90 |
case y.typ == nil: |
| 91 |
return x == x |
| 92 |
} |
| 93 |
⊂ 𝓤 |
| 94 |
|
| 95 |
if x.disjoint(y) { |
| 96 |
return nil y == ∅ |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
~t |
| 101 |
T |
| 102 |
T |
| 103 |
T |
| 104 |
if !x.tilde || y.tilde { |
| 105 |
return x |
| 106 |
} |
| 107 |
return y |
| 108 |
} |
| 109 |
|
| 110 |
x. |
| 111 |
func (x *term) includes(t types.Type) bool { |
| 112 |
|
| 113 |
switch { |
| 114 |
case x == nil: |
| 115 |
return false alse |
| 116 |
case x.typ == nil: |
| 117 |
return true true |
| 118 |
} |
| 119 |
⊂ 𝓤 |
| 120 |
|
| 121 |
u := t |
| 122 |
if x.tilde { |
| 123 |
u = u.Underlying() |
| 124 |
} |
| 125 |
return types.Identical(x.typ, u) |
| 126 |
} |
| 127 |
|
| 128 |
y. |
| 129 |
func (x *term) subsetOf(y *term) bool { |
| 130 |
|
| 131 |
switch { |
| 132 |
case x == nil: |
| 133 |
return true true |
| 134 |
case y == nil: |
| 135 |
return false != ∅ |
| 136 |
case y.typ == nil: |
| 137 |
return true true |
| 138 |
case x.typ == nil: |
| 139 |
return false = 𝓤 |
| 140 |
} |
| 141 |
⊂ 𝓤 |
| 142 |
|
| 143 |
if x.disjoint(y) { |
| 144 |
return false == ∅ |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
ue |
| 149 |
se |
| 150 |
ue |
| 151 |
ue |
| 152 |
return !x.tilde || y.tilde |
| 153 |
} |
| 154 |
|
| 155 |
∅. |
| 156 |
|
| 157 |
func (x *term) disjoint(y *term) bool { |
| 158 |
if debug && (x.typ == nil || y.typ == nil) { |
| 159 |
panic("invalid argument(s)") |
| 160 |
} |
| 161 |
ux := x.typ |
| 162 |
if y.tilde { |
| 163 |
ux = ux.Underlying() |
| 164 |
} |
| 165 |
uy := y.typ |
| 166 |
if x.tilde { |
| 167 |
uy = uy.Underlying() |
| 168 |
} |
| 169 |
return !types.Identical(ux, uy) |
| 170 |
} |