Skip to content

Commit 909dd4a

Browse files
authored
rlp/rlpgen: remove build tag (#28106)
* rlp/rlpgen: remove build tag This tag was supposed to prevent unstable output when types reference each other. Imagine there are two struct types A and B, where a reference to type B is in A. If I run rlpgen on type B first, and then on type A, the generator will see the B.EncodeRLP method and call it. However, if I run rlpgen on type A first, it will inline the encoding of B. The solution I chose for the initial release of rlpgen was to just ignore methods generated by rlpgen using a build tag. But there is a problem with this: if any code in the package calls EncodeRLP explicitly, the package can't be loaded without errors anymore in rlpgen, because the loader ignores it. Would be nice if there was a way to just make it ignore invalid functions during type checking (they're not necessary for rlpgen), but golang.org/x/tools/go/packages does not provide a way of ignoring them. Luckily, the types we use rlpgen with do not reference each other right now, so we can just remove the build tags for now.
1 parent ee65462 commit 909dd4a

File tree

5 files changed

+2
-17
lines changed

5 files changed

+2
-17
lines changed

core/types/gen_account_rlp.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/gen_header_rlp.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/gen_log_rlp.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/gen_withdrawal_rlp.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rlp/rlpgen/main.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ type Config struct {
7373
func (cfg *Config) process() (code []byte, err error) {
7474
// Load packages.
7575
pcfg := &packages.Config{
76-
Mode: packages.NeedName | packages.NeedTypes | packages.NeedImports | packages.NeedDeps,
77-
Dir: cfg.Dir,
78-
BuildFlags: []string{"-tags", "norlpgen"},
76+
Mode: packages.NeedName | packages.NeedTypes,
77+
Dir: cfg.Dir,
7978
}
8079
ps, err := packages.Load(pcfg, pathOfPackageRLP, ".")
8180
if err != nil {
@@ -117,8 +116,6 @@ func (cfg *Config) process() (code []byte, err error) {
117116
// This is done here to avoid processing these lines with gofmt.
118117
var header bytes.Buffer
119118
fmt.Fprint(&header, "// Code generated by rlpgen. DO NOT EDIT.\n\n")
120-
fmt.Fprint(&header, "//go:build !norlpgen\n")
121-
fmt.Fprint(&header, "// +build !norlpgen\n\n")
122119
return append(header.Bytes(), code...), nil
123120
}
124121

0 commit comments

Comments
 (0)