GoPLS Viewer

Home|gopls/internal/typeparams/typeterm.go
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Code generated by copytermlist.go DO NOT EDIT.
6
7package typeparams
8
9import "go/types"
10
11// A term describes elementary type sets:
12//
13//   βˆ…:  (*term)(nil)     == βˆ…                      // set of no types (empty set)
14//   π“€:  &term{}          == π“€                      // set of all types (𝓀niverse)
15//   T:  &term{false, T}  == {T}                    // set of type T
16//  ~t:  &term{true, t}   == {t' | under(t') == t}  // set of types with underlying type t
17//
18type term struct {
19    tilde bool // valid if typ != nil
20    typ   types.Type
21}
22
23func (x *termString() 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// equal reports whether x and y represent the same type set.
37func (x *termequal(y *termbool {
38    // easy cases
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    // βˆ… βŠ‚ x, y βŠ‚ π“€
46
47    return x.tilde == y.tilde && types.Identical(x.typy.typ)
48}
49
50// union returns the union x βˆͺ y: zero, one, or two non-nil terms.
51func (x *termunion(y *term) (__ *term) {
52    // easy cases
53    switch {
54    case x == nil && y == nil:
55        return nilnil // βˆ… βˆͺ βˆ… == βˆ…
56    case x == nil:
57        return ynil // βˆ… βˆͺ y == y
58    case y == nil:
59        return xnil // x βˆͺ βˆ… == x
60    case x.typ == nil:
61        return xnil // π“€ βˆͺ y == π“€
62    case y.typ == nil:
63        return ynil // x βˆͺ π“€ == π“€
64    }
65    // βˆ… βŠ‚ x, y βŠ‚ π“€
66
67    if x.disjoint(y) {
68        return xy // x βˆͺ y == (x, y) if x βˆ© y == βˆ…
69    }
70    // x.typ == y.typ
71
72    // ~t βˆͺ ~t == ~t
73    // ~t βˆͺ  T == ~t
74    //  T βˆͺ ~t == ~t
75    //  T βˆͺ  T ==  T
76    if x.tilde || !y.tilde {
77        return xnil
78    }
79    return ynil
80}
81
82// intersect returns the intersection x βˆ© y.
83func (x *termintersect(y *term) *term {
84    // easy cases
85    switch {
86    case x == nil || y == nil:
87        return nil // βˆ… βˆ© y == βˆ… and βˆ© βˆ… == βˆ…
88    case x.typ == nil:
89        return y // π“€ βˆ© y == y
90    case y.typ == nil:
91        return x // x βˆ© π“€ == x
92    }
93    // βˆ… βŠ‚ x, y βŠ‚ π“€
94
95    if x.disjoint(y) {
96        return nil // x βˆ© y == βˆ… if x βˆ© y == βˆ…
97    }
98    // x.typ == y.typ
99
100    // ~t βˆ© ~t == ~t
101    // ~t βˆ©  T ==  T
102    //  T βˆ© ~t ==  T
103    //  T βˆ©  T ==  T
104    if !x.tilde || y.tilde {
105        return x
106    }
107    return y
108}
109
110// includes reports whether t βˆˆ x.
111func (x *termincludes(t types.Typebool {
112    // easy cases
113    switch {
114    case x == nil:
115        return false // t βˆˆ βˆ… == false
116    case x.typ == nil:
117        return true // t βˆˆ π“€ == true
118    }
119    // βˆ… βŠ‚ x βŠ‚ π“€
120
121    u := t
122    if x.tilde {
123        u = under(u)
124    }
125    return types.Identical(x.typu)
126}
127
128// subsetOf reports whether x βІ y.
129func (x *termsubsetOf(y *termbool {
130    // easy cases
131    switch {
132    case x == nil:
133        return true // βˆ… βІ y == true
134    case y == nil:
135        return false // x βІ βˆ… == false since x != βˆ…
136    case y.typ == nil:
137        return true // x βІ π“€ == true
138    case x.typ == nil:
139        return false // π“€ βІ y == false since y != π“€
140    }
141    // βˆ… βŠ‚ x, y βŠ‚ π“€
142
143    if x.disjoint(y) {
144        return false // x βІ y == false if x βˆ© y == βˆ…
145    }
146    // x.typ == y.typ
147
148    // ~t βІ ~t == true
149    // ~t βІ T == false
150    //  T βІ ~t == true
151    //  T βІ  T == true
152    return !x.tilde || y.tilde
153}
154
155// disjoint reports whether x βˆ© y == βˆ….
156// x.typ and y.typ must not be nil.
157func (x *termdisjoint(y *termbool {
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 = under(ux)
164    }
165    uy := y.typ
166    if x.tilde {
167        uy = under(uy)
168    }
169    return !types.Identical(uxuy)
170}
171
MembersX
term.includes.x
term.includes.u
term.subsetOf
term.disjoint.ux
term.intersect.x
term.includes.t
term.subsetOf.y
term
term.typ
term.String.x
term.equal.y
term.union
term.disjoint.y
term.disjoint.uy
term.equal
term.union.x
term.union.y
term.intersect
term.intersect.y
term.disjoint.x
term.disjoint
term.tilde
term.String
term.equal.x
term.includes
term.subsetOf.x
Members
X