#call to atomic.(* Value).Store doesn't got (inlined), but why?

9 messages · Page 1 of 1 (latest)

rare night
#
package main

import (
    "sync/atomic"
)

type Object struct{}

func main() {
    println(test1())
    println(test2())
    println(test3())
    println(test4())
}

//go:noinline
func test1() int {
    var x atomic.Int32
    x.Store(1)
    return int(x.Load())
}

//go:noinline
func test2() string {
    var x atomic.Value
    x.Store("foo")
    return x.Load().(string)
}

//go:noinline
func test3() *Object {
    var x atomic.Value
    x.Store(&Object{})
    return x.Load().(*Object)
}

//go:noinline
func test4() bool {
    var x atomic.Bool
    x.Store(true)
    return x.Load()
}
# command-line-arguments
./main.go:19:9: inlining call to atomic.(*Int32).Store
./main.go:20:19: inlining call to atomic.(*Int32).Load
./main.go:27:15: inlining call to atomic.(*Value).Load   <-- here 
./main.go:34:15: inlining call to atomic.(*Value).Load   <-- here too
./main.go:40:9: inlining call to atomic.(*Bool).Store
./main.go:41:15: inlining call to atomic.(*Bool).Load
./main.go:40:9: inlining call to atomic.b32
./main.go:18:6: moved to heap: x
./main.go:25:6: moved to heap: x
./main.go:26:10: "foo" escapes to heap
./main.go:32:6: moved to heap: x
./main.go:33:10: &Object{} escapes to heap
./main.go:39:6: moved to heap: x
1
foo
0x50fdc0
true

tiny sphinx
#

inlining means it's inlined I don't understand the question

vocal raven
#

i think they're asking about the two calls to (*atomic.Value).Store that are not inlined, in test2 and test3

#

i'm inferring from the relative line numbers and the presence of Int32 and Bool

tiny sphinx
#

I see you can use -m=4 to see more information

vocal raven
#

just for some very basic intuition as you're starting down that road: (*atomic.Int32).Store and (*atomic.Bool).Store are both one line, while (*atomic.Value).Store is almost 40

#

that may have something to do with it. 😁

#

not saying that you should take that as the full explanation and abandon looking into it more, but it's certainly something to keep in the back of your head

tiny sphinx