goose icon indicating copy to clipboard operation
goose copied to clipboard

var wg sync.WaitGroup doesn't properly link

Open sanjit-bhat opened this issue 1 year ago • 2 comments

var wg sync.WaitGroup
wg.Wait()

translates to

let: "wg" := ref (zero_val (struct.t sync.WaitGroup)) in
sync.WaitGroup__Wait (![struct.t sync.WaitGroup] "wg");

This results in Error: The reference sync.WaitGroup__Wait was not found in the current environment.

The current workaround is to switch the allocation to

wg := new(sync.WaitGroup)
wg.Wait()

which translates to

let: "wg" := waitgroup.New #() in
waitgroup.Wait "wg";

We should eventually fix this. CC @upamanyus.

sanjit-bhat avatar Aug 18 '23 18:08 sanjit-bhat

This is also a problem for code like

var l sync.Mutex
l.Lock()

It might be that the selectorType in https://github.com/tchajed/goose/blob/5b963b0f176ab516683e173558207814fae66f03/goose.go#L465-L468 is not a types.Pointer as expected by https://github.com/tchajed/goose/blob/5b963b0f176ab516683e173558207814fae66f03/types.go#L231-L232

upamanyus avatar Aug 18 '23 19:08 upamanyus

Indeed, was just poking at this, and it's easy enough to get Goose to emit the right code for this case (and even avoid changing any of our existing Goose'd code!): https://github.com/tchajed/goose/compare/master...zeldovich:goose:stack-mutex

Haven't thought about it enough to figure out if this might mean we will incorrectly Goose something in a way that is unsound..

zeldovich avatar Aug 18 '23 19:08 zeldovich