Skip to content
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

x/tools/cmd/eg: take better care with pointers, maintain addressability of expressions #10326

Open
josharian opened this issue Apr 3, 2015 · 0 comments

Comments

Projects
None yet
3 participants
@josharian
Copy link
Contributor

commented Apr 3, 2015

Given this package:

package egbug

var Imap = map[*T]int{}

type T struct {
    I int
}

func main() {
    var t T
    p := &t.I
    _ = p
}

and this template:

package p

import "egbug"

func before(t *egbug.T) int { return t.I }
func after(t *egbug.T) int  { return egbug.Imap[t] }

applying eg generates uncompilable code:

package egbug

var Imap = map[*T]int{}

type T struct {
    I int
}

func main() {
    var t T
    p := &Imap[t]
    _ = p
}
$ go build
# egbug
./x.go:11: cannot use t (type T) as type *T in map index
./x.go:11: cannot take the address of Imap[t]

There are two separate bugs here--T vs *T and breaking addressability.

This is a real life example, from attempting to use eg to instrument the gc compiler to find correlations in Node field usage.

@josharian josharian added the repo-tools label Apr 3, 2015

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc changed the title cmd/eg: take better care with pointers, maintain addressability of expressions x/tools/cmd/eg: take better care with pointers, maintain addressability of expressions Apr 14, 2015

@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015

@rsc rsc removed the repo-tools label Apr 14, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.