-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: code templates can declare required go langage level #357
Conversation
In certain cases, it is not practical to write aspects using go syntax that is known to work with all go versions. While this is in general not an issue (since `orchestrion` only supports the latest 2 go releases), it can still cause issues when injecting code into modules with a `go.mod` file that declares an antiquated `go` version (e.g: `go 1.13`). In such cases, go 1.22 and newer toolchains will instruct the compiler to process the source code in a way that ensures compatibility with that antiquated language level, prohibiting use of newer language features. To protect ourselves from this issue, the `template` objects can now be configured to demand a certain minimum language level to be available, which will cause compile units into which that template generated code to have the compiler's `-lang` flag set to that level (unless it was already set at a higher level). This might have consequences on the behavior of the compiled code (e.g, the change of `for range` variable bindings introduced in go 1.22); but we currently do not deal with this particular issue, as we assume it will seldom have any practical impact in our use-cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, just working with the go version strings can be simplified using go/version
package instead of golang.org/x/mod/semver
.
@@ -44,15 +44,29 @@ imports: | |||
tracer: gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer | |||
``` | |||
|
|||
### Links |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is Links
disappearing? is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was never there to begin with! It's only supported for inject-declarations
...
e69e70c
to
9910926
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #357 +/- ##
==========================================
+ Coverage 58.50% 58.63% +0.13%
==========================================
Files 158 159 +1
Lines 11333 11423 +90
==========================================
+ Hits 6630 6698 +68
- Misses 4232 4249 +17
- Partials 471 476 +5
|
In certain cases, it is not practical to write aspects using go syntax that is known to work with all go versions. While this is in general not an issue (since
orchestrion
only supports the latest 2 go releases), it can still cause issues when injecting code into modules with ago.mod
file that declares an antiquatedgo
version (e.g:go 1.13
).In such cases, go 1.22 and newer toolchains will instruct the compiler to process the source code in a way that ensures compatibility with that antiquated language level, prohibiting use of newer language features.
To protect ourselves from this issue, the
template
objects can now be configured to demand a certain minimum language level to be available, which will cause compile units into which that template generated code to have the compiler's-lang
flag set to that level (unless it was already set at a higher level).This might have consequences on the behavior of the compiled code (e.g, the change of
for range
variable bindings introduced in go 1.22); but we currently do not deal with this particular issue, as we assume it will seldom have any practical impact in our use-cases.