@@ -69,23 +69,34 @@ type namedType struct {
6969 DataType string
7070}
7171
72+ type equalsI interface {
73+ equals (equalsI ) bool
74+ }
75+
7276type funcData struct {
7377 Params []namedType
7478 Results []namedType
7579}
7680
77- type equalsI interface {
78- equals (equalsI ) bool
79- }
80-
8181func (x funcData ) equals (yI equalsI ) bool {
8282 y := yI .(funcData )
83- return len (x .Params ) == len (y .Params ) &&
84- len (x .Results ) == len (y .Results ) &&
85- slices .Equal (x .Params , y .Params ) &&
83+ return slices .Equal (x .Params , y .Params ) &&
8684 slices .Equal (x .Results , y .Results )
8785}
8886
87+ type genericFuncData struct {
88+ Params []namedType
89+ Results []namedType
90+ TypeParams []string
91+ }
92+
93+ func (x genericFuncData ) equals (yI equalsI ) bool {
94+ y := yI .(genericFuncData )
95+ return slices .Equal (x .Params , y .Params ) &&
96+ slices .Equal (x .Results , y .Results ) &&
97+ slices .Equal (x .TypeParams , y .TypeParams )
98+ }
99+
89100type typeData struct {
90101 Underlying string
91102}
@@ -102,6 +113,17 @@ func (x structDef) equals(yI equalsI) bool {
102113 return slices .Equal (x .Fields , yI .(structDef ).Fields )
103114}
104115
116+ type genericStructDef struct {
117+ Fields []namedType
118+ TypeParams []string
119+ }
120+
121+ func (x genericStructDef ) equals (yI equalsI ) bool {
122+ y := yI .(genericStructDef )
123+ return slices .Equal (x .Fields , y .Fields ) &&
124+ slices .Equal (x .TypeParams , y .TypeParams )
125+ }
126+
105127type alias struct {
106128 Target string
107129}
@@ -117,30 +139,36 @@ func (x iface) equals(yI equalsI) bool {
117139}
118140
119141type pkgData struct {
120- Funcs map [string ]funcData
121- Types map [string ]typeData
122- Structs map [string ]structDef
123- Aliases map [string ]alias
124- Interfaces map [string ]iface
142+ Funcs map [string ]funcData
143+ GenericFuncs map [string ]genericFuncData
144+ Types map [string ]typeData
145+ Structs map [string ]structDef
146+ GenericStructs map [string ]genericStructDef
147+ Aliases map [string ]alias
148+ Interfaces map [string ]iface
125149}
126150
127151func newPkgData () * pkgData {
128152 return & pkgData {
129- Funcs : make (map [string ]funcData ),
130- Types : make (map [string ]typeData ),
131- Structs : make (map [string ]structDef ),
132- Aliases : make (map [string ]alias ),
133- Interfaces : make (map [string ]iface ),
153+ Funcs : make (map [string ]funcData ),
154+ GenericFuncs : make (map [string ]genericFuncData ),
155+ Types : make (map [string ]typeData ),
156+ Structs : make (map [string ]structDef ),
157+ GenericStructs : make (map [string ]genericStructDef ),
158+ Aliases : make (map [string ]alias ),
159+ Interfaces : make (map [string ]iface ),
134160 }
135161}
136162
137163func (pkgD * pkgData ) Clone () * pkgData {
138164 return & pkgData {
139- Funcs : maps .Clone (pkgD .Funcs ),
140- Types : maps .Clone (pkgD .Types ),
141- Structs : maps .Clone (pkgD .Structs ),
142- Aliases : maps .Clone (pkgD .Aliases ),
143- Interfaces : maps .Clone (pkgD .Interfaces ),
165+ Funcs : maps .Clone (pkgD .Funcs ),
166+ GenericFuncs : maps .Clone (pkgD .GenericFuncs ),
167+ Types : maps .Clone (pkgD .Types ),
168+ Structs : maps .Clone (pkgD .Structs ),
169+ GenericStructs : maps .Clone (pkgD .GenericStructs ),
170+ Aliases : maps .Clone (pkgD .Aliases ),
171+ Interfaces : maps .Clone (pkgD .Interfaces ),
144172 }
145173}
146174
@@ -171,19 +199,23 @@ func MapAndIn[V equalsI](x, y map[string]V) {
171199// get pkgData with definitions existing in both pkg And y
172200func (pkg * pkgData ) And (y * pkgData ) * pkgData {
173201 return & pkgData {
174- Funcs : MapAnd (pkg .Funcs , y .Funcs ),
175- Types : MapAnd (pkg .Types , y .Types ),
176- Structs : MapAnd (pkg .Structs , y .Structs ),
177- Aliases : MapAnd (pkg .Aliases , y .Aliases ),
178- Interfaces : MapAnd (pkg .Interfaces , y .Interfaces ),
202+ Funcs : MapAnd (pkg .Funcs , y .Funcs ),
203+ GenericFuncs : MapAnd (pkg .GenericFuncs , y .GenericFuncs ),
204+ Types : MapAnd (pkg .Types , y .Types ),
205+ Structs : MapAnd (pkg .Structs , y .Structs ),
206+ GenericStructs : MapAnd (pkg .GenericStructs , y .GenericStructs ),
207+ Aliases : MapAnd (pkg .Aliases , y .Aliases ),
208+ Interfaces : MapAnd (pkg .Interfaces , y .Interfaces ),
179209 }
180210}
181211
182212// in-place and
183213func (pkg * pkgData ) AndIn (y * pkgData ) {
184214 MapAndIn (pkg .Funcs , y .Funcs )
215+ MapAndIn (pkg .GenericFuncs , y .GenericFuncs )
185216 MapAndIn (pkg .Types , y .Types )
186217 MapAndIn (pkg .Structs , y .Structs )
218+ MapAndIn (pkg .GenericStructs , y .GenericStructs )
187219 MapAndIn (pkg .Aliases , y .Aliases )
188220 MapAndIn (pkg .Interfaces , y .Interfaces )
189221}
@@ -210,19 +242,23 @@ func MapAndNotIn[V equalsI](x, y map[string]V) {
210242// return map with key-value pairs from pkg that do not have an equal pair in y
211243func (pkg * pkgData ) AndNot (y * pkgData ) * pkgData {
212244 return & pkgData {
213- Funcs : MapAndNot (pkg .Funcs , y .Funcs ),
214- Types : MapAndNot (pkg .Types , y .Types ),
215- Structs : MapAndNot (pkg .Structs , y .Structs ),
216- Aliases : MapAndNot (pkg .Aliases , y .Aliases ),
217- Interfaces : MapAndNot (pkg .Interfaces , y .Interfaces ),
245+ Funcs : MapAndNot (pkg .Funcs , y .Funcs ),
246+ GenericFuncs : MapAndNot (pkg .GenericFuncs , y .GenericFuncs ),
247+ Types : MapAndNot (pkg .Types , y .Types ),
248+ Structs : MapAndNot (pkg .Structs , y .Structs ),
249+ GenericStructs : MapAndNot (pkg .GenericStructs , y .GenericStructs ),
250+ Aliases : MapAndNot (pkg .Aliases , y .Aliases ),
251+ Interfaces : MapAndNot (pkg .Interfaces , y .Interfaces ),
218252 }
219253}
220254
221255// in-place version of andNot
222256func (pkg * pkgData ) AndNotIn (y * pkgData ) {
223257 MapAndNotIn (pkg .Funcs , y .Funcs )
258+ MapAndNotIn (pkg .GenericFuncs , y .GenericFuncs )
224259 MapAndNotIn (pkg .Types , y .Types )
225260 MapAndNotIn (pkg .Structs , y .Structs )
261+ MapAndNotIn (pkg .GenericStructs , y .GenericStructs )
226262 MapAndNotIn (pkg .Aliases , y .Aliases )
227263 MapAndNotIn (pkg .Interfaces , y .Interfaces )
228264}
@@ -236,19 +272,23 @@ func MapMerge[T any](x, y map[string]T) map[string]T {
236272// return merged map with both x and y
237273func (pkg * pkgData ) Merge (y * pkgData ) * pkgData {
238274 return & pkgData {
239- Funcs : MapMerge (pkg .Funcs , y .Funcs ),
240- Types : MapMerge (pkg .Types , y .Types ),
241- Structs : MapMerge (pkg .Structs , y .Structs ),
242- Aliases : MapMerge (pkg .Aliases , y .Aliases ),
243- Interfaces : MapMerge (pkg .Interfaces , y .Interfaces ),
275+ Funcs : MapMerge (pkg .Funcs , y .Funcs ),
276+ GenericFuncs : MapMerge (pkg .GenericFuncs , y .GenericFuncs ),
277+ Types : MapMerge (pkg .Types , y .Types ),
278+ Structs : MapMerge (pkg .Structs , y .Structs ),
279+ GenericStructs : MapMerge (pkg .GenericStructs , y .GenericStructs ),
280+ Aliases : MapMerge (pkg .Aliases , y .Aliases ),
281+ Interfaces : MapMerge (pkg .Interfaces , y .Interfaces ),
244282 }
245283}
246284
247285// in-place version of merge
248286func (pkg * pkgData ) MergeIn (y * pkgData ) {
249287 maps .Copy (pkg .Funcs , y .Funcs )
288+ maps .Copy (pkg .GenericFuncs , y .GenericFuncs )
250289 maps .Copy (pkg .Types , y .Types )
251290 maps .Copy (pkg .Structs , y .Structs )
291+ maps .Copy (pkg .GenericStructs , y .GenericStructs )
252292 maps .Copy (pkg .Aliases , y .Aliases )
253293 maps .Copy (pkg .Interfaces , y .Interfaces )
254294}
@@ -273,22 +313,26 @@ func mapNotIn[T any](x, y map[string]T) {
273313// remove keys existing in y from pkg
274314func (pkg * pkgData ) Not (y * pkgData ) * pkgData {
275315 return & pkgData {
276- Funcs : mapNot (pkg .Funcs , y .Funcs ),
277- Types : mapNot (pkg .Types , y .Types ),
278- Structs : mapNot (pkg .Structs , y .Structs ),
279- Aliases : mapNot (pkg .Aliases , y .Aliases ),
280- Interfaces : mapNot (pkg .Interfaces , y .Interfaces ),
316+ Funcs : mapNot (pkg .Funcs , y .Funcs ),
317+ GenericFuncs : mapNot (pkg .GenericFuncs , y .GenericFuncs ),
318+ Types : mapNot (pkg .Types , y .Types ),
319+ Structs : mapNot (pkg .Structs , y .Structs ),
320+ GenericStructs : mapNot (pkg .GenericStructs , y .GenericStructs ),
321+ Aliases : mapNot (pkg .Aliases , y .Aliases ),
322+ Interfaces : mapNot (pkg .Interfaces , y .Interfaces ),
281323 }
282324}
283325
284326func (pkg * pkgData ) NotIn (y * pkgData ) {
285327 mapNotIn (pkg .Funcs , y .Funcs )
328+ mapNotIn (pkg .GenericFuncs , y .GenericFuncs )
286329 mapNotIn (pkg .Types , y .Types )
287330 mapNotIn (pkg .Structs , y .Structs )
331+ mapNotIn (pkg .GenericStructs , y .GenericStructs )
288332 mapNotIn (pkg .Aliases , y .Aliases )
289333 mapNotIn (pkg .Interfaces , y .Interfaces )
290334}
291335
292336func (pkg * pkgData ) empty () bool {
293- return (len (pkg .Funcs ) + len (pkg .Types ) + len (pkg .Structs ) + len (pkg .Aliases ) + len (pkg .Interfaces )) == 0
337+ return (len (pkg .Funcs ) + len (pkg .GenericFuncs ) + len ( pkg . Types ) + len (pkg .Structs ) + len ( pkg . GenericStructs ) + len (pkg .Aliases ) + len (pkg .Interfaces )) == 0
294338}
0 commit comments