Commit Graph

7 Commits

Author SHA1 Message Date
eNV25
01497d22b0 nocmp_test: fix spelling in comment (#114) 2022-08-05 22:46:25 -07:00
eNV25
976602f5dc all: go fmt ./... with go1.19 (#110) 2022-08-05 09:14:45 -07:00
Abhinav Gupta
9c79392530 nomcmp/test: Only set HOME (#84)
After some more digging into #83, the issue was actually lack of HOME.
We need to specify GOPATH and GOCACHE because we haven't specified a
HOME.

Given the setup,

```
cd $(mktemp -d)
echo "module example.com/demo" > go.mod
echo "package demo" > demo.go
eval $(gimme 1.16rc1)
GO=$(which go)
```

If we run `go build` with an empty environment, it fails as expected.

```
$ env -i $GO build
missing $GOPATH
```

Setting HOME gives it a good default place for GOPATH, GOCACHE, and
friends.

```
$ env -i HOME=$(pwd)/home $GO build  # succeeds
```
2021-02-02 14:19:09 -08:00
Abhinav Gupta
d17779fa59 nocmp/test: Test with Go modules (#83)
The nocmp integration test creates a temporary directory with a copy of
nocmp.go and a Go file that should not compile if our implementation of
nocmp is correct.

This worked fine without a GOPATH set previously, but with Go 1.16, it
seems that we need to have the GOPATH environment variable set (ref
https://github.com/golang/go/commit/cdbd4d49d8b).

Change the nocmp integration test to rely on Go modules for the test.
We can point GOPATH to an arbitrary temporary directory because we don't
rely on anything in it.

Fixes #82
2021-02-02 10:07:29 -08:00
Abhinav Gupta
f64e592f7f staticcheck: Fix unused fields
The embedded `nocmp` field and other similar fields are unused in tests
and the rest of our code.

We can get the effect of `nocmp` without embedding the fields by using
`_ nocmp` as a field.
2020-09-11 11:24:56 -07:00
Abhinav Gupta
746c19c0c5 TestNocmpSize: Test with correct struct
`staticcheck` caught the following issue.

    nocmp_test.go:84:7: type y is unused (U1000)

Test was intended to evaluate the size of the new `type y` but due to a
typo, we were testing with `x`.
2020-09-11 11:24:56 -07:00
Abhinav Gupta
982a2dde23 Disallow non-atomic comparisons of atomics (#74)
It is currently possible to make non-atomic comparisons of atomic
values:

    x := atomic.NewInt32(1)
    y := atomic.NewInt32(1)
    fmt.Println(*x == *y)

This is undesirable because it loads the value in a non-atomic way. The
correct method is,

    x := atomic.NewInt32(1)
    y := atomic.NewInt32(1)
    fmt.Println(x.Load() == y.Load())

To prevent this, disallow comparison of atomic values by embedding an
uncomparable array into atomics. The empty array adds no runtime cost,
and does not increase the in-memory size of the structs. Inspired by
[go4.org/mem#RO][1].

  [1]: 3dbcd07079/mem.go (L42)

Note that the Value struct, which embeds `"sync/atomic".Value` was also
changed. This will break usages in the following form, but that's
acceptable because unkeyed struct literals are among the exceptions
stated in the [Go 1 compatibility expectations][2].

    import (
      syncatomic "sync/atomic"
      "go.uber.org/atomic"
    )

    atomic.Value{syncatomic.Value{..}}

  [2]: https://golang.org/doc/go1compat#expectations

Resolves #72
2020-05-12 13:57:19 -07:00