Skip to content

Go 1.9 support (version bump to GopherJS 1.9-1). #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
15a2eea
Target Go 1.9 Beta 1, update version to GopherJS 1.9-wip.
dmitshur Jun 23, 2017
72e0b64
compiler/natives/src/runtime: Keep throw accessible for Go code to use.
dmitshur Jun 23, 2017
0927aef
compiler/natives/src/runtime: Add noop implementation of CallersFrames.
dmitshur Jun 23, 2017
0cbbd7f
compiler/natives/src/sync: Update SemacquireMutex, Semrelease signatu…
dmitshur Jun 23, 2017
c5eec2e
compiler/natives/src/time: Update now signature for monotonic time.
dmitshur Jun 23, 2017
7b4a889
compiler/natives/src/reflect: Update signatures.
dmitshur Jun 23, 2017
9212049
compiler/natives: Regenerate.
dmitshur Jun 23, 2017
981eddd
compiler/natives/src/os/signal: Create no-op implementation.
dmitshur Jun 24, 2017
b946d67
compiler/natives/src/testing: Use a basic but working callerName.
dmitshur Jun 24, 2017
956dce4
compiler/natives/src/internal/poll: Create no-op I/O poller implement…
dmitshur Jun 24, 2017
38f3fb7
compiler/natives: Regenerate.
dmitshur Jun 24, 2017
9ffc87e
WIP: nosync: Implement sync.Map.
dmitshur Jun 24, 2017
640751f
compiler: Set anonymous bit for struct fields correctly.
dmitshur Jun 24, 2017
44d151d
compiler/natives/src/reflect: Set pkgPath for new implements checks.
dmitshur Jun 24, 2017
15ab3c0
compiler: Fix panic due to type aliases.
dmitshur Jun 24, 2017
c8a99bb
compiler/natives/src/math/big: Remove bitLen, override Word.
dmitshur Jun 24, 2017
67e7e39
compiler/natives: Regenerate.
dmitshur Jun 24, 2017
b9c0354
CI: Don't minify when running tests.
dmitshur Jun 24, 2017
dd65c22
compiler/natives/src/math: Implement missing functions.
dmitshur Jun 24, 2017
c7683d9
compiler/natives/src/net: Implement missing private helpers.
dmitshur Jun 24, 2017
fbf0086
compiler/natives/src/encoding/gob: Disable broken test case.
dmitshur Jun 24, 2017
41a477d
compiler/natives: Regenerate.
dmitshur Jun 24, 2017
d8a12c0
compiler/natives/src/sync: Add missing private helper.
dmitshur Jun 25, 2017
63f374f
compiler/natives/src/time: Add initial support for monotonic clock.
dmitshur Jun 25, 2017
576b4d7
compiler/natives: Regenerate.
dmitshur Jun 25, 2017
dcc17c5
tests: Classify new Go 1.9 tests.
dmitshur Jun 25, 2017
e39dba4
compiler/natives/src/crypto/x509: Update package and tests for Go 1.9.
dmitshur Jun 26, 2017
ce54604
CI: Use --verbose flag with gopherjs test command.
dmitshur Jun 26, 2017
ffae93c
compiler/natives: Regenerate.
dmitshur Jun 26, 2017
8b8c47a
CI: Update to Go 1.9 Beta 2.
dmitshur Jun 26, 2017
cc16cdc
CI: Update to Go 1.9 RC 1.
dmitshur Jul 25, 2017
b0dc25e
compiler/natives/src/internal/poll: Add pollDesc.pollable method.
dmitshur Jul 25, 2017
99fd1ff
compiler/natives: Regenerate.
dmitshur Jul 25, 2017
49ee3df
compiler/natives/src/math/big: Use math_big_pure_go build tag.
dmitshur Jul 25, 2017
355d52e
compiler/natives/src/sync: Implement newly referenced test helpers.
dmitshur Jul 25, 2017
052972b
compiler/natives: Add missing // +build js build constraint.
dmitshur Jul 25, 2017
cc693ed
compiler/natives: Regenerate.
dmitshur Jul 25, 2017
208c5eb
Address remaining code review comments.
dmitshur Jul 25, 2017
f6209e7
compiler/natives: Regenerate.
dmitshur Jul 25, 2017
6759a49
CI: Fix check for forgotten // +build js constraints in natives.
dmitshur Jul 25, 2017
00a3767
build: Don't use cgo for "os/user", "crypto/x509".
dmitshur Jul 27, 2017
ba3e852
CI: Update to Go 1.9 RC 2.
dmitshur Aug 8, 2017
07ee55b
CI: Update to Go 1.9 final release.
dmitshur Aug 25, 2017
7e6a73a
Add math/bits to supported package list.
dmitshur Aug 25, 2017
91dd575
compiler: Restore previous behavior of skipping unsafe import.
dmitshur Aug 25, 2017
62cb4ed
CI: Prefer --minify flag for all tests.
dmitshur Aug 25, 2017
be67827
compiler: Replace old importer with x/tools/go/gcimporter15.
dmitshur Aug 26, 2017
61693e9
compiler: Simplify type alias handling.
dmitshur Aug 26, 2017
34e2783
compiler: Skip type aliases in all named type considerations.
dmitshur Aug 26, 2017
fe63fb1
compiler: Bump GopherJS version to 1.9-1.
dmitshur Aug 26, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,23 @@ func Import(path string, mode build.ImportMode, installSuffix string, buildTags
}

func importWithSrcDir(path string, srcDir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
buildContext := NewBuildContext(installSuffix, buildTags)
if path == "syscall" { // syscall needs to use a typical GOARCH like amd64 to pick up definitions for _Socklen, BpfInsn, IFNAMSIZ, Timeval, BpfStat, SYS_FCNTL, Flock_t, etc.
buildContext.GOARCH = runtime.GOARCH
buildContext.InstallSuffix = "js"
bctx := NewBuildContext(installSuffix, buildTags)
switch path {
case "syscall":
// syscall needs to use a typical GOARCH like amd64 to pick up definitions for _Socklen, BpfInsn, IFNAMSIZ, Timeval, BpfStat, SYS_FCNTL, Flock_t, etc.
bctx.GOARCH = runtime.GOARCH
bctx.InstallSuffix = "js"
if installSuffix != "" {
buildContext.InstallSuffix += "_" + installSuffix
bctx.InstallSuffix += "_" + installSuffix
}
case "math/big":
// Use pure Go version of math/big; we don't want non-Go assembly versions.
bctx.BuildTags = append(bctx.BuildTags, "math_big_pure_go")
case "crypto/x509", "os/user":
// These stdlib packages have cgo and non-cgo versions (via build tags); we want the latter.
bctx.CgoEnabled = false
}
pkg, err := buildContext.Import(path, srcDir, mode)
pkg, err := bctx.Import(path, srcDir, mode)
if err != nil {
return nil, err
}
Expand All @@ -93,17 +101,17 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install

switch path {
case "os":
pkg.GoFiles = stripExecutable(pkg.GoFiles) // Need to strip executable implementation files, because some of them contain package scope variables that perform (indirectly) syscalls on init.
pkg.GoFiles = excludeExecutable(pkg.GoFiles) // Need to exclude executable implementation files, because some of them contain package scope variables that perform (indirectly) syscalls on init.
case "runtime":
pkg.GoFiles = []string{"error.go"}
case "runtime/internal/sys":
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"}
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", bctx.GOOS), "zversion.go"}
case "runtime/pprof":
pkg.GoFiles = nil
case "internal/poll":
pkg.GoFiles = exclude(pkg.GoFiles, "fd_poll_runtime.go")
case "crypto/rand":
pkg.GoFiles = []string{"rand.go", "util.go"}
case "crypto/x509":
pkg.CgoFiles = nil
}

if len(pkg.CgoFiles) > 0 {
Expand Down Expand Up @@ -131,9 +139,9 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
}

// stripExecutable strips all executable implementation .go files.
// excludeExecutable excludes all executable implementation .go files.
// They have "executable_" prefix.
func stripExecutable(goFiles []string) []string {
func excludeExecutable(goFiles []string) []string {
var s []string
for _, f := range goFiles {
if strings.HasPrefix(f, "executable_") {
Expand All @@ -144,6 +152,21 @@ func stripExecutable(goFiles []string) []string {
return s
}

// exclude returns files, excluding specified files.
func exclude(files []string, exclude ...string) []string {
var s []string
Outer:
for _, f := range files {
for _, e := range exclude {
if f == e {
continue Outer
}
}
s = append(s, f)
}
return s
}

// ImportDir is like Import but processes the Go package found in the named
// directory.
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
Expand Down
9 changes: 7 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ machine:

dependencies:
pre:
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
post:
- mv ./gopherjs $HOME/bin
- npm install --global node-gyp
Expand All @@ -17,8 +17,10 @@ test:
- diff -u <(echo -n) <(gofmt -d .)
- go tool vet *.go # Go package in root directory.
- for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party".
- diff -u <(echo -n) <(go list ./compiler/natives/src/...) # All those packages should have // +build js.
- gopherjs install -v net/http # Should build successfully (can't run tests, since only client is supported).
- >
gopherjs test --short --minify
gopherjs test --minify -v --short
github.com/gopherjs/gopherjs/tests
github.com/gopherjs/gopherjs/tests/main
github.com/gopherjs/gopherjs/js
Expand Down Expand Up @@ -96,6 +98,7 @@ test:
io/ioutil
math
math/big
math/bits
math/cmplx
math/rand
mime
Expand All @@ -107,6 +110,7 @@ test:
net/rpc/jsonrpc
net/textproto
net/url
os/user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this list be better maintained as an exclusion list? Not that there are many new packages added to core... but still.

Copy link
Member Author

@dmitshur dmitshur Aug 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that'd be better. Not as part of this PR, but let's make a follow up enhancement PR after this one is merged.

Edit: Filed #686 to track it.

path
path/filepath
reflect
Expand All @@ -127,3 +131,4 @@ test:
unicode/utf16
unicode/utf8
- go test -v -race ./...
- gopherjs test -v fmt # No minification should work.
6 changes: 3 additions & 3 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"strings"

"github.com/gopherjs/gopherjs/compiler/prelude"
"github.com/gopherjs/gopherjs/third_party/importer"
"golang.org/x/tools/go/gcimporter15"
)

var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
var reservedKeywords = make(map[string]bool)
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_8___ // Compile error on other Go versions, because they're not supported.
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_9___ // Compile error on other Go versions, because they're not supported.

func init() {
for _, keyword := range []string{"abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "undefined", "var", "void", "volatile", "while", "with", "yield"} {
Expand Down Expand Up @@ -239,7 +239,7 @@ func ReadArchive(filename, path string, r io.Reader, packages map[string]*types.
}

var err error
_, packages[path], err = importer.ImportData(packages, a.ExportData)
_, packages[path], err = gcimporter.BImportData(token.NewFileSet(), packages, a.ExportData, path)
if err != nil {
return nil, err
}
Expand Down
281 changes: 170 additions & 111 deletions compiler/natives/fs_vfsdata.go

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions compiler/natives/src/crypto/x509/x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

package x509

import "os"
import "errors"

func loadSystemRoots() (*CertPool, error) {
// no system roots
return NewCertPool(), nil
}

func execSecurityRoots() (*CertPool, error) {
return nil, os.ErrNotExist
return nil, errors.New("crypto/x509: system root pool is not available in GopherJS")
}
8 changes: 8 additions & 0 deletions compiler/natives/src/crypto/x509/x509_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ package x509

import "testing"

func TestSystemCertPool(t *testing.T) {
t.Skip("no system roots")
}

func TestSystemRoots(t *testing.T) {
t.Skip("no system roots")
}

func TestEnvVars(t *testing.T) {
t.Skip("no system roots")
}

func TestSystemVerify(t *testing.T) {
t.Skip("no system")
}
Expand Down
100 changes: 100 additions & 0 deletions compiler/natives/src/encoding/gob/gob_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// +build js

package gob

import (
"bytes"
"reflect"
"testing"
)

// TODO: TestEndToEnd override can be removed once the bug with Marr field is fixed.
func TestEndToEnd(t *testing.T) {
type T2 struct {
T string
}
type T3 struct {
X float64
Z *int
}
type T1 struct {
A, B, C int
M map[string]*float64
M2 map[int]T3
Mstring map[string]string
Mintptr map[int]*int
Mcomp map[complex128]complex128
Marr map[[2]string][2]*float64
EmptyMap map[string]int // to check that we receive a non-nil map.
N *[3]float64
Strs *[2]string
Int64s *[]int64
RI complex64
S string
Y []byte
T *T2
}
pi := 3.14159
e := 2.71828
two := 2.0
meaning := 42
fingers := 5
s1 := "string1"
s2 := "string2"
var comp1 complex128 = complex(1.0, 1.0)
var comp2 complex128 = complex(1.0, 1.0)
var arr1 [2]string
arr1[0] = s1
arr1[1] = s2
var arr2 [2]string
arr2[0] = s2
arr2[1] = s1
var floatArr1 [2]*float64
floatArr1[0] = &pi
floatArr1[1] = &e
var floatArr2 [2]*float64
floatArr2[0] = &e
floatArr2[1] = &two
t1 := &T1{
A: 17,
B: 18,
C: -5,
M: map[string]*float64{"pi": &pi, "e": &e},
M2: map[int]T3{4: T3{X: pi, Z: &meaning}, 10: T3{X: e, Z: &fingers}},
Mstring: map[string]string{"pi": "3.14", "e": "2.71"},
Mintptr: map[int]*int{meaning: &fingers, fingers: &meaning},
Mcomp: map[complex128]complex128{comp1: comp2, comp2: comp1},
// TODO: Fix this problem:
// TypeError: dst.$set is not a function
// at typedmemmove (/github.com/gopherjs/gopherjs/reflect.go:487:3)
//Marr: map[[2]string][2]*float64{arr1: floatArr1, arr2: floatArr2},
EmptyMap: make(map[string]int),
N: &[3]float64{1.5, 2.5, 3.5},
Strs: &[2]string{s1, s2},
Int64s: &[]int64{77, 89, 123412342134},
RI: 17 - 23i,
S: "Now is the time",
Y: []byte("hello, sailor"),
T: &T2{"this is T2"},
}
b := new(bytes.Buffer)
err := NewEncoder(b).Encode(t1)
if err != nil {
t.Error("encode:", err)
}
var _t1 T1
err = NewDecoder(b).Decode(&_t1)
if err != nil {
t.Fatal("decode:", err)
}
if !reflect.DeepEqual(t1, &_t1) {
t.Errorf("encode expected %v got %v", *t1, _t1)
}
// Be absolutely sure the received map is non-nil.
if t1.EmptyMap == nil {
t.Errorf("nil map sent")
}
if _t1.EmptyMap == nil {
t.Errorf("nil map received")
}
}
57 changes: 57 additions & 0 deletions compiler/natives/src/internal/poll/fd_poll_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// +build js

package poll

import "time"

// pollDesc is a no-op implementation of an I/O poller for GOARCH=js.
//
// Its implementation is based on NaCL in gc compiler (see GOROOT/src/internal/poll/fd_poll_nacl.go),
// but it does even less.
type pollDesc struct {
closing bool
}

func (pd *pollDesc) init(fd *FD) error { return nil }

func (pd *pollDesc) close() {}

func (pd *pollDesc) evict() { pd.closing = true }

func (pd *pollDesc) prepare(mode int, isFile bool) error {
if pd.closing {
return errClosing(isFile)
}
return nil
}

func (pd *pollDesc) prepareRead(isFile bool) error { return pd.prepare('r', isFile) }

func (pd *pollDesc) prepareWrite(isFile bool) error { return pd.prepare('w', isFile) }

func (pd *pollDesc) wait(mode int, isFile bool) error {
if pd.closing {
return errClosing(isFile)
}
return ErrTimeout
}

func (pd *pollDesc) waitRead(isFile bool) error { return pd.wait('r', isFile) }

func (pd *pollDesc) waitWrite(isFile bool) error { return pd.wait('w', isFile) }

func (*pollDesc) waitCanceled(mode int) {}

func (*pollDesc) pollable() bool { return true }

func (*FD) SetDeadline(t time.Time) error { return nil }

func (*FD) SetReadDeadline(t time.Time) error { return nil }

func (*FD) SetWriteDeadline(t time.Time) error { return nil }

// PollDescriptor returns the descriptor being used by the poller,
// or ^uintptr(0) if there isn't one. This is only used for testing.
func PollDescriptor() uintptr {
return ^uintptr(0)
}
39 changes: 3 additions & 36 deletions compiler/natives/src/math/big/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,6 @@

package big

func mulWW(x, y Word) (z1, z0 Word) {
return mulWW_g(x, y)
}
func divWW(x1, x0, y Word) (q, r Word) {
return divWW_g(x1, x0, y)
}
func addVV(z, x, y []Word) (c Word) {
return addVV_g(z, x, y)
}
func subVV(z, x, y []Word) (c Word) {
return subVV_g(z, x, y)
}
func addVW(z, x []Word, y Word) (c Word) {
return addVW_g(z, x, y)
}
func subVW(z, x []Word, y Word) (c Word) {
return subVW_g(z, x, y)
}
func shlVU(z, x []Word, s uint) (c Word) {
return shlVU_g(z, x, s)
}
func shrVU(z, x []Word, s uint) (c Word) {
return shrVU_g(z, x, s)
}
func mulAddVWW(z, x []Word, y, r Word) (c Word) {
return mulAddVWW_g(z, x, y, r)
}
func addMulVVW(z, x []Word, y Word) (c Word) {
return addMulVVW_g(z, x, y)
}
func divWVW(z []Word, xn Word, x []Word, y Word) (r Word) {
return divWVW_g(z, xn, x, y)
}
func bitLen(x Word) (n int) {
return bitLen_g(x)
}
// TODO: This is a workaround for https://github.com/gopherjs/gopherjs/issues/652.
// Remove after that issue is resolved.
type Word uintptr
Loading