Skip to content
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

import failure for pkg #856

Open
pjebs opened this issue Sep 19, 2020 · 10 comments
Open

import failure for pkg #856

pjebs opened this issue Sep 19, 2020 · 10 comments
Labels
area/core bug Something isn't working question Further information is requested

Comments

@pjebs
Copy link

pjebs commented Sep 19, 2020

 import "github.com/rocketlaunchr/dataframe-go"                   

1:21: import "github.com/rocketlaunchr/dataframe-go" error: /Users/x/GOPATH/src/github.com/rocketlaunchr/dataframe-go/series_defaults.go:8:2: import "github.com/google/go-cmp/cmp" error: /Users/x/GOPATH/src/github.com/google/go-cmp/cmp/compare.go:36:2: import "github.com/google/go-cmp/cmp/internal/value" error: /Users/x/GOPATH/src/github.com/google/go-cmp/cmp/internal/value/pointer_unsafe.go:11:2: import "unsafe" error: unable to find source related to: "unsafe"

The dataframe package is designed to be safe to run in environments that prohibit "unsafe" package.

It uses a built tag called safe. How can I import and specify the build tag?

@mvertes
Copy link
Member

mvertes commented Sep 20, 2020

If you can edit the source file, you can insert a comment prior to the import statement such as:

// yaegi:tags safe
import "github.com/rocketlaunchr/dataframe-go"

More details at https://pkg.go.dev/github.com/containous/yaegi/interp#hdr-Custom_build_tags.

Alternatively, you can pass build tags to yaegi executable using the -tags flag:

$ yaegi  -tags safe [...]

@mvertes mvertes added the question Further information is requested label Sep 20, 2020
@pjebs
Copy link
Author

pjebs commented Sep 20, 2020

There seems to be a more serious bug:

yaegi  -tags safe -tags purego

(I also tried just yaegi -tags purego)

I ran this command:

import "github.com/rocketlaunchr/dataframe-go"

I got this massive error:

runtime error: invalid memory address or nil pointer dereference
goroutine 21 [running]:
runtime/debug.Stack(0x1, 0xc000111400, 0x40)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/traefik/yaegi/interp.(*Interpreter).eval.func1(0xc00053ff78)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:451 +0xbc
panic(0x199e120, 0x2271750)
	/usr/local/go/src/runtime/panic.go:969 +0x166
github.com/traefik/yaegi/interp._append(0xc000d95100)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/run.go:2492 +0x458
github.com/traefik/yaegi/interp.setExec.func1(0xc000d95100)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2337 +0xb2
github.com/traefik/yaegi/interp.setExec.func1(0xc000d95700)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d95800)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d95300)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d95400)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d94e00)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d94200)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d94300)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d94400)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d94500)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93a00)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93b00)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93c00)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93d00)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d92d00)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d92f00)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93000)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93200)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93400)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93600)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d93700)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d91100)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d91200)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2334 +0x189
github.com/traefik/yaegi/interp.setExec.func1(0xc000d91300)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec.func1(0xc000d91400)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2326 +0x25d
github.com/traefik/yaegi/interp.setExec(0xc000d91400)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:2340 +0xf5
github.com/traefik/yaegi/interp.genRun.func1(0xc000d90300, 0xc00053e201)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:1893 +0x87
github.com/traefik/yaegi/interp.(*node).Walk(0xc000d90300, 0xc00053e288, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:211 +0xc9
github.com/traefik/yaegi/interp.(*node).Walk(0xc000d8bc00, 0xc00053e288, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:215 +0x70
github.com/traefik/yaegi/interp.(*node).Walk(0xc000cbfd00, 0xc00053e288, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:215 +0x70
github.com/traefik/yaegi/interp.genRun(0xc000cbfd00, 0xc000280bd0, 0xc000036c01)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/cfg.go:1885 +0x60
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc0002e0000, 0x0, 0x0, 0xc000036c01, 0x1c, 0x1c89501, 0xc00139e778, 0x118b44e, 0x1c84e20, 0xc000a1c400)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/src.go:142 +0x927
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000cbc400, 0xc00139efb0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/gta.go:219 +0x1351
github.com/traefik/yaegi/interp.(*node).Walk(0xc000cbc400, 0xc00053efb0, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:211 +0xc9
github.com/traefik/yaegi/interp.(*node).Walk(0xc000cbc100, 0xc00053efb0, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:215 +0x70
github.com/traefik/yaegi/interp.(*node).Walk(0xc000cb3f00, 0xc00053efb0, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:215 +0x70
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0002e0000, 0xc000cb3f00, 0xc0008bb020, 0x25, 0xc0000ae1e1, 0x25, 0xc0004f7c50, 0x9, 0xc000cb3f00, 0x0, ...)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/gta.go:20 +0x1e8
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc0002e0000, 0x0, 0x0, 0xc0000ae1e1, 0x25, 0x1, 0xc0000b2840, 0xc0002e0000, 0xc0001403d0, 0x82)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/src.go:105 +0xf34
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0000da800, 0xc0000b2808)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/gta.go:219 +0x1351
github.com/traefik/yaegi/interp.(*node).Walk(0xc0000da800, 0xc00053fd20, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:211 +0xc9
github.com/traefik/yaegi/interp.(*node).Walk(0xc0000da700, 0xc00053fd20, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:215 +0x70
github.com/traefik/yaegi/interp.(*node).Walk(0xc0000da500, 0xc00053fd20, 0x0)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:215 +0x70
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0002e0000, 0xc0000da500, 0xc0000b4858, 0x4, 0xc0000b4858, 0x4, 0x0, 0xc00010e080, 0x0, 0x0, ...)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/gta.go:20 +0x1e8
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0xc0002e0000, 0xc00053fee0, 0x1, 0x1, 0xc0000b4858, 0x4, 0xc0000b4858, 0x4)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/gta.go:302 +0x13a
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0002e0000, 0xc0000ae180, 0x2f, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:473 +0x28f
github.com/traefik/yaegi/interp.(*Interpreter).Eval(...)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:376
github.com/traefik/yaegi/interp.(*Interpreter).EvalWithContext.func1(0xc00008e2a0, 0xc0002e0000, 0xc0000ae180, 0x2f, 0xc0000a8dc0, 0xc000140310)
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:572 +0x84
created by github.com/traefik/yaegi/interp.(*Interpreter).EvalWithContext
	/Users/pj/GOPATH/src/github.com/traefik/yaegi/interp/interp.go:570 +0x14d

@mvertes
Copy link
Member

mvertes commented Sep 20, 2020

Thanks, this one needs to be investigated by us.

Note that you should provide multiple tags in comma separated list as -tags=safe,purego. I tested on your package and got a different panic, still to be investigated.

@mvertes mvertes added area/core bug Something isn't working labels Sep 20, 2020
@mvertes
Copy link
Member

mvertes commented Sep 20, 2020

As your package is quite large and has many dependencies, it may be advantageous to wrap it in a pre-compiled package and build a custom interpreter. This would avoid all issues where yaegi fails to interpret some patterns, avoid all the interpreter overhead on your package, and be transparent for users.

See yaegi extract command to build a custom wrapper, then build a custom interpreter, importing your wrapper, and provided to the interpreter using the Interpreter.Use method.

Sorry this whole process is not fully yet documented, we need to write a complete example on that.

@pjebs
Copy link
Author

pjebs commented Sep 20, 2020

does that mean it can't work natively and the custom wrapper technique is the only way?

@pjebs
Copy link
Author

pjebs commented Sep 20, 2020

I was hoping to fork this project and make it work seamelessly with my https://github.com/rocketlaunchr/dataframe-go package and also igo (https://github.com/rocketlaunchr/igo)

@pjebs
Copy link
Author

pjebs commented Sep 20, 2020

Can the custom wrapper technique be used to integrate igo (which isn't actually a package) natively?

@mvertes
Copy link
Member

mvertes commented Sep 20, 2020

Hopefully it should be possible to run your package natively in yaegi, once the issues resolved.

Forking this project to provide access to pre-compiled dataframe-go (as we do ourselves when we provide access to the Go stdlib) still makes sense in your case.

yaegi extract operate on packages, not executables.

@pjebs
Copy link
Author

pjebs commented Sep 20, 2020

igo modifies the ast. How can I intercept the new line, inspect it and potentially modify it to add syntax features such as fordefer (Defers for for-loops) and Address Operator (&) for constants and functions?

@mvertes
Copy link
Member

mvertes commented Sep 20, 2020

You have to study how interpreter.REPL and its dependencies operate internally, as it performs incremental evaluation. Good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants