From bb009fe4c684774b0e193ddab879aa78edca1d10 Mon Sep 17 00:00:00 2001 From: Mikko Ylinen Date: Tue, 3 Mar 2020 11:51:18 +0200 Subject: [PATCH] drop legacy Go support Go 1.9 was released in August 2017 so it's safe to make a claim that projects are already using new enough Go version. Tested with: $ go version go version go1.13.8 linux/amd64 $ GO111MODULE=off ./test.sh ok github.com/modern-go/reflect2-tests 0.005s coverage: 12.3% of statements in github.com/modern-go/reflect2 ok github.com/modern-go/reflect2-tests/test15 0.004s coverage: 6.4% of statements in github.com/modern-go/reflect2 ok github.com/modern-go/reflect2-tests/tests 0.010s coverage: 65.4% of statements in github.com/modern-go/reflect2 Signed-off-by: Mikko Ylinen --- .travis.yml | 2 +- Gopkg.lock | 8 +------- Gopkg.toml | 4 ---- go_above_17.go | 8 -------- go_above_19.go | 3 +++ go_below_17.go | 9 --------- go_below_19.go | 14 -------------- reflect2.go | 6 +++--- type_map.go | 49 ++----------------------------------------------- 9 files changed, 10 insertions(+), 93 deletions(-) delete mode 100644 go_above_17.go delete mode 100644 go_below_17.go delete mode 100644 go_below_19.go diff --git a/.travis.yml b/.travis.yml index fbb4374..b097728 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.8.x + - 1.9.x - 1.x before_install: diff --git a/Gopkg.lock b/Gopkg.lock index 2a3a698..10ef811 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,15 +1,9 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. -[[projects]] - name = "github.com/modern-go/concurrent" - packages = ["."] - revision = "e0a39a4cb4216ea8db28e22a69f4ec25610d513a" - version = "1.0.0" - [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "daee8a88b3498b61c5640056665b8b9eea062006f5e596bbb6a3ed9119a11ec7" + input-imports = [] solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 2f4f4db..a9bc506 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -26,10 +26,6 @@ ignored = [] -[[constraint]] - name = "github.com/modern-go/concurrent" - version = "1.0.0" - [prune] go-tests = true unused-packages = true diff --git a/go_above_17.go b/go_above_17.go deleted file mode 100644 index 5c1cea8..0000000 --- a/go_above_17.go +++ /dev/null @@ -1,8 +0,0 @@ -//+build go1.7 - -package reflect2 - -import "unsafe" - -//go:linkname resolveTypeOff reflect.resolveTypeOff -func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer diff --git a/go_above_19.go b/go_above_19.go index c7e3b78..974f768 100644 --- a/go_above_19.go +++ b/go_above_19.go @@ -6,6 +6,9 @@ import ( "unsafe" ) +//go:linkname resolveTypeOff reflect.resolveTypeOff +func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer + //go:linkname makemap reflect.makemap func makemap(rtype unsafe.Pointer, cap int) (m unsafe.Pointer) diff --git a/go_below_17.go b/go_below_17.go deleted file mode 100644 index 65a93c8..0000000 --- a/go_below_17.go +++ /dev/null @@ -1,9 +0,0 @@ -//+build !go1.7 - -package reflect2 - -import "unsafe" - -func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer { - return nil -} diff --git a/go_below_19.go b/go_below_19.go deleted file mode 100644 index b050ef7..0000000 --- a/go_below_19.go +++ /dev/null @@ -1,14 +0,0 @@ -//+build !go1.9 - -package reflect2 - -import ( - "unsafe" -) - -//go:linkname makemap reflect.makemap -func makemap(rtype unsafe.Pointer) (m unsafe.Pointer) - -func makeMapWithSize(rtype unsafe.Pointer, cap int) unsafe.Pointer { - return makemap(rtype) -} diff --git a/reflect2.go b/reflect2.go index 92318ca..c43c8b9 100644 --- a/reflect2.go +++ b/reflect2.go @@ -1,9 +1,9 @@ package reflect2 import ( - "github.com/modern-go/concurrent" "reflect" "runtime" + "sync" "unsafe" ) @@ -131,13 +131,13 @@ var ConfigSafe = Config{UseSafeImplementation: true}.Froze() type frozenConfig struct { useSafeImplementation bool - cache *concurrent.Map + cache *sync.Map } func (cfg Config) Froze() *frozenConfig { return &frozenConfig{ useSafeImplementation: cfg.UseSafeImplementation, - cache: concurrent.NewMap(), + cache: new(sync.Map), } } diff --git a/type_map.go b/type_map.go index 38abcbf..4b13c31 100644 --- a/type_map.go +++ b/type_map.go @@ -4,16 +4,10 @@ package reflect2 import ( "reflect" - "runtime" - "strings" "sync" "unsafe" ) -// typelinks1 for 1.5 ~ 1.6 -//go:linkname typelinks1 reflect.typelinks -func typelinks1() [][]unsafe.Pointer - // typelinks2 for 1.7 ~ //go:linkname typelinks2 reflect.typelinks func typelinks2() (sections []unsafe.Pointer, offset [][]int32) @@ -29,49 +23,10 @@ func discoverTypes() { types = make(map[string]reflect.Type) packages = make(map[string]map[string]reflect.Type) - ver := runtime.Version() - if ver == "go1.5" || strings.HasPrefix(ver, "go1.5.") { - loadGo15Types() - } else if ver == "go1.6" || strings.HasPrefix(ver, "go1.6.") { - loadGo15Types() - } else { - loadGo17Types() - } -} - -func loadGo15Types() { - var obj interface{} = reflect.TypeOf(0) - typePtrss := typelinks1() - for _, typePtrs := range typePtrss { - for _, typePtr := range typePtrs { - (*emptyInterface)(unsafe.Pointer(&obj)).word = typePtr - typ := obj.(reflect.Type) - if typ.Kind() == reflect.Ptr && typ.Elem().Kind() == reflect.Struct { - loadedType := typ.Elem() - pkgTypes := packages[loadedType.PkgPath()] - if pkgTypes == nil { - pkgTypes = map[string]reflect.Type{} - packages[loadedType.PkgPath()] = pkgTypes - } - types[loadedType.String()] = loadedType - pkgTypes[loadedType.Name()] = loadedType - } - if typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Ptr && - typ.Elem().Elem().Kind() == reflect.Struct { - loadedType := typ.Elem().Elem() - pkgTypes := packages[loadedType.PkgPath()] - if pkgTypes == nil { - pkgTypes = map[string]reflect.Type{} - packages[loadedType.PkgPath()] = pkgTypes - } - types[loadedType.String()] = loadedType - pkgTypes[loadedType.Name()] = loadedType - } - } - } + loadGoTypes() } -func loadGo17Types() { +func loadGoTypes() { var obj interface{} = reflect.TypeOf(0) sections, offset := typelinks2() for i, offs := range offset {