summaryrefslogtreecommitdiffstats
path: root/src/net/netip/inlining_test.go
blob: b521eeebfd8f38cbcf3b2951523f2ba4c725d79d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package netip

import (
	"internal/testenv"
	"os/exec"
	"regexp"
	"runtime"
	"strings"
	"testing"
)

func TestInlining(t *testing.T) {
	testenv.MustHaveGoBuild(t)
	t.Parallel()
	out, err := exec.Command(
		testenv.GoToolPath(t),
		"build",
		"--gcflags=-m",
		"net/netip").CombinedOutput()
	if err != nil {
		t.Fatalf("go build: %v, %s", err, out)
	}
	got := map[string]bool{}
	regexp.MustCompile(` can inline (\S+)`).ReplaceAllFunc(out, func(match []byte) []byte {
		got[strings.TrimPrefix(string(match), " can inline ")] = true
		return nil
	})
	wantInlinable := []string{
		"(*uint128).halves",
		"Addr.BitLen",
		"Addr.hasZone",
		"Addr.Is4",
		"Addr.Is4In6",
		"Addr.Is6",
		"Addr.IsLoopback",
		"Addr.IsMulticast",
		"Addr.IsInterfaceLocalMulticast",
		"Addr.IsValid",
		"Addr.IsUnspecified",
		"Addr.Less",
		"Addr.Unmap",
		"Addr.Zone",
		"Addr.v4",
		"Addr.v6",
		"Addr.v6u16",
		"Addr.withoutZone",
		"AddrPortFrom",
		"AddrPort.Addr",
		"AddrPort.Port",
		"AddrPort.IsValid",
		"Prefix.IsSingleIP",
		"Prefix.Masked",
		"Prefix.IsValid",
		"PrefixFrom",
		"Prefix.Addr",
		"Prefix.Bits",
		"AddrFrom4",
		"IPv6LinkLocalAllNodes",
		"IPv6Unspecified",
		"MustParseAddr",
		"MustParseAddrPort",
		"MustParsePrefix",
		"appendDecimal",
		"appendHex",
		"uint128.addOne",
		"uint128.and",
		"uint128.bitsClearedFrom",
		"uint128.bitsSetFrom",
		"uint128.isZero",
		"uint128.not",
		"uint128.or",
		"uint128.subOne",
		"uint128.xor",
	}
	switch runtime.GOARCH {
	case "amd64", "arm64":
		// These don't inline on 32-bit.
		wantInlinable = append(wantInlinable,
			"Addr.Next",
			"Addr.Prev",
		)
	}

	for _, want := range wantInlinable {
		if !got[want] {
			t.Errorf("%q is no longer inlinable", want)
			continue
		}
		delete(got, want)
	}
	for sym := range got {
		if strings.Contains(sym, ".func") {
			continue
		}
		t.Logf("not in expected set, but also inlinable: %q", sym)

	}
}