Debian Codegraph @

internal/typeparams/typeterm.go

raw symbols SCIP
1 // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
2 // Source: ../../cmd/compile/internal/types2/typeterm.go
3
4 // Copyright 2021 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
7
8 // Code generated by copytermlist.go DO NOT EDIT.
9
10 package typeparams
11
12 import "go/types"
13
14 // A term describes elementary type sets:
15 //
16 // βˆ…: (*term)(nil) == βˆ… // set of no types (empty set)
17 // 𝓀: &term{} == 𝓀 // set of all types (𝓀niverse)
18 // T: &term{false, T} == {T} // set of type T
19 // ~t: &term{true, t} == {t' | under(t') == t} // set of types with underlying type t
20 type term struct {
21 tilde bool // valid if typ != nil
22 typ types.Type
23 }
24
25 func (x *term) String() string {
26 switch {
27 case x == nil:
28 return "βˆ…"
29 case x.typ == nil:
30 return "𝓀"
31 case x.tilde:
32 return "~" + x.typ.String()
33 default:
34 return x.typ.String()
35 }
36 }
37
38 // equal reports whether x and y represent the same type set.
39 func (x *term) equal(y *term) bool {
40 // easy cases
41 switch {
42 case x == nil || y == nil:
43 return x == y
44 case x.typ == nil || y.typ == nil:
45 return x.typ == y.typ
46 }
47 // βˆ… βŠ‚ x, y βŠ‚ 𝓀
48
49 return x.tilde == y.tilde && types.Identical(x.typ, y.typ)
50 }
51
52 // union returns the union x βˆͺ y: zero, one, or two non-nil terms.
53 func (x *term) union(y *term) (_, _ *term) {
54 // easy cases
55 switch {
56 case x == nil && y == nil:
57 return nil, nil // βˆ… βˆͺ βˆ… == βˆ…
58 case x == nil:
59 return y, nil // βˆ… βˆͺ y == y
60 case y == nil:
61 return x, nil // x βˆͺ βˆ… == x
62 case x.typ == nil:
63 return x, nil // 𝓀 βˆͺ y == 𝓀
64 case y.typ == nil:
65 return y, nil // x βˆͺ 𝓀 == 𝓀
66 }
67 // βˆ… βŠ‚ x, y βŠ‚ 𝓀
68
69 if x.disjoint(y) {
70 return x, y // x βˆͺ y == (x, y) if x ∩ y == βˆ…
71 }
72 // x.typ == y.typ
73
74 // ~t βˆͺ ~t == ~t
75 // ~t βˆͺ T == ~t
76 // T βˆͺ ~t == ~t
77 // T βˆͺ T == T
78 if x.tilde || !y.tilde {
79 return x, nil
80 }
81 return y, nil
82 }
83
84 // intersect returns the intersection x ∩ y.
85 func (x *term) intersect(y *term) *term {
86 // easy cases
87 switch {
88 case x == nil || y == nil:
89 return nil // βˆ… ∩ y == βˆ… and ∩ βˆ… == βˆ…
90 case x.typ == nil:
91 return y // 𝓀 ∩ y == y
92 case y.typ == nil:
93 return x // x ∩ 𝓀 == x
94 }
95 // βˆ… βŠ‚ x, y βŠ‚ 𝓀
96
97 if x.disjoint(y) {
98 return nil // x ∩ y == βˆ… if x ∩ y == βˆ…
99 }
100 // x.typ == y.typ
101
102 // ~t ∩ ~t == ~t
103 // ~t ∩ T == T
104 // T ∩ ~t == T
105 // T ∩ T == T
106 if !x.tilde || y.tilde {
107 return x
108 }
109 return y
110 }
111
112 // includes reports whether t ∈ x.
113 func (x *term) includes(t types.Type) bool {
114 // easy cases
115 switch {
116 case x == nil:
117 return false // t ∈ βˆ… == false
118 case x.typ == nil:
119 return true // t ∈ 𝓀 == true
120 }
121 // βˆ… βŠ‚ x βŠ‚ 𝓀
122
123 u := t
124 if x.tilde {
125 u = under(u)
126 }
127 return types.Identical(x.typ, u)
128 }
129
130 // subsetOf reports whether x βŠ† y.
131 func (x *term) subsetOf(y *term) bool {
132 // easy cases
133 switch {
134 case x == nil:
135 return true // βˆ… βŠ† y == true
136 case y == nil:
137 return false // x βŠ† βˆ… == false since x != βˆ…
138 case y.typ == nil:
139 return true // x βŠ† 𝓀 == true
140 case x.typ == nil:
141 return false // 𝓀 βŠ† y == false since y != 𝓀
142 }
143 // βˆ… βŠ‚ x, y βŠ‚ 𝓀
144
145 if x.disjoint(y) {
146 return false // x βŠ† y == false if x ∩ y == βˆ…
147 }
148 // x.typ == y.typ
149
150 // ~t βŠ† ~t == true
151 // ~t βŠ† T == false
152 // T βŠ† ~t == true
153 // T βŠ† T == true
154 return !x.tilde || y.tilde
155 }
156
157 // disjoint reports whether x ∩ y == βˆ….
158 // x.typ and y.typ must not be nil.
159 func (x *term) disjoint(y *term) bool {
160 if debug && (x.typ == nil || y.typ == nil) {
161 panic("invalid argument(s)")
162 }
163 ux := x.typ
164 if y.tilde {
165 ux = under(ux)
166 }
167 uy := y.typ
168 if x.tilde {
169 uy = under(uy)
170 }
171 return !types.Identical(ux, uy)
172 }