Skip to content

Commit 80638ff

Browse files
committed
Update docs regarding Go upgrades
1 parent 0bdbd2f commit 80638ff

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

docs/dev-notes.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Developer Notes
2+
===============
3+
4+
Go Upgrades
5+
------------
6+
7+
The mockery project supports the most recent TWO stable Go versions. Testing matrices will only run on the two most recent stable Go versions. However, given the [Go backwards-compatibility guarantee](https://go.dev/blog/compat), it's very likely projects built off of older Go 1.x syntax will continue to work in perpetuity.(1)
8+
{ .annotate }
9+
10+
1. The caveat, being noted, is the same as the above linked backwards compatibility guarantee:
11+
12+
> There are a few qualifications to that. First, compatibility means source compatibility. When you update to a new version of Go, you do have to recompile your code. Second, we can add new APIs, but not in a way that breaks existing code.
13+
14+
> The end of the document warns, “[It] is impossible to guarantee that no future change will break any program.” Then it lays out a number of reasons why programs might still break.
15+
16+
> For example, it makes sense that if your program depends on a buggy behavior and we fix the bug, your program will break. But we try very hard to break as little as possible and keep Go boring. There are two main approaches we’ve used so far: API checking and testing.
17+
18+
19+
20+
Go Syntax Updates
21+
------------------
22+
23+
When Go releases new syntax, there are two approaches that the mockery project will take:
24+
25+
### Mockery does not need to interact with the new syntax
26+
27+
In such cases, the mockery project _only_ needs to upgrade its `golang.org/x/tools` dependency. This is necessary for the parsing step to simply not fail if it encounters new syntax. If mockery does not need to interact or understand this syntax, this dependency upgrade is likely all that's needed.
28+
29+
Take for example the problems mentioned [here] when mockery upgraded to `go 1.24` in its `go.mod` file. In this situation, the project maintainers wanted to allow mockery to not crash when it parses syntax containing generic type alias syntax. However, the project did not _parse_ this syntax, so the only thing we needed to do was upgrade `golang.org/x/tools`.
30+
31+
### Mockery _does_ need to interact with the new syntax
32+
33+
This situation was encountered in Go 1.18 when generics were introduced. [In this case](https://github.com/vektra/mockery/pull/456/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6), the project needed to be upgraded to `go 1.18` because mockery now had to directly parse and interpret generic types through the `go/ast` package. This was needed in conjunction with an upgrade of `golang.org/x/tools` that handles the actual parsing into `go/ast` data.
34+
35+
It's possible in future versions of Go that only the `toolchain` directive needs to be upgraded to allow mockery to use a more recent `go/ast` package. The purposes of the `go` directive is supposed to inform the compiler what features of the Go language the module uses in its own syntax, so in this case as long as mockery does not itself use generics, it can parse generic type information from _other_ projects without needing to pin its `go` directive to the relevant version.

docs/stylesheets/extra.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
}
1212

1313
.md-grid {
14-
max-width: none;
14+
max-width: 200em;
1515
}

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
13591359
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
13601360
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
13611361
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
1362+
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
13621363
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
13631364
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
13641365
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -1400,6 +1401,7 @@ golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14001401
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14011402
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14021403
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1404+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14031405
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457 h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk=
14041406
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
14051407
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ nav:
7272
- Notes:
7373
- faq.md
7474
- v3.md
75+
- dev-notes.md
7576

7677
extra_css:
7778
- stylesheets/extra.css

0 commit comments

Comments
 (0)