Disallows nil context and fixes linters (#754)

staticcheck linters broke until recent golangci-lint. Now, normal
behaviour of enforcing no nil context works again. Ex.
```
assemblyscript/assemblyscript_example_test.go:16:25: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck)
	r := wazero.NewRuntime(nil)
```

Since default lint already checks for nil context, this removes our
permission of nil context args. The original reason we permitted nil is
no longer valid: we once allowed context to be stashed in config, and
removed that as it caused bugs. We forgot to undo allowing nil
explicitly.

Note: this doesn't particularly check in our code for nil context,
similar as we don't particularly check in our code for nil anything
else. End users should use linters as none of our parameters should be
nil anyway.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-08-19 14:52:50 +08:00
committed by GitHub
parent 5b2c25cfed
commit 57a705e594
19 changed files with 22 additions and 121 deletions

View File

@@ -157,7 +157,7 @@ type Module interface {
ExportedGlobal(name string) Global
// CloseWithExitCode releases resources allocated for this Module. Use a non-zero exitCode parameter to indicate a
// failure to ExportedFunction callers. When the context is nil, it defaults to context.Background.
// failure to ExportedFunction callers.
//
// The error returned here, if present, is about resource de-allocation (such as I/O errors). Only the last error is
// returned, so a non-nil return means at least one error happened. Regardless of error, this module instance will
@@ -175,7 +175,7 @@ type Module interface {
//
// Note: This is an interface for decoupling, not third-party implementations. All implementations are in wazero.
type Closer interface {
// Close closes the resource. When the context is nil, it defaults to context.Background.
// Close closes the resource.
Close(context.Context) error
}
@@ -267,7 +267,7 @@ type Function interface {
// Call invokes the function with parameters encoded according to ParamTypes. Up to one result is returned,
// encoded according to ResultTypes. An error is returned for any failure looking up or invoking the function
// including signature mismatch. When the context is nil, it defaults to context.Background.
// including signature mismatch.
//
// If Module.Close or Module.CloseWithExitCode were invoked during this call, the error returned may be a
// sys.ExitError. Interpreting this is specific to the module. For example, some "main" functions always call a
@@ -298,7 +298,7 @@ type Global interface {
// Type describes the numeric type of the global.
Type() ValueType
// Get returns the last known value of this global. When the context is nil, it defaults to context.Background.
// Get returns the last known value of this global.
//
// See Type for how to encode this value from a Go type.
Get(context.Context) uint64
@@ -308,7 +308,7 @@ type Global interface {
type MutableGlobal interface {
Global
// Set updates the value of this global. When the context is nil, it defaults to context.Background.
// Set updates the value of this global.
//
// See Global.Type for how to decode this value to a Go type.
Set(ctx context.Context, v uint64)
@@ -318,7 +318,6 @@ type MutableGlobal interface {
//
// # Notes
//
// - All functions accept a context.Context, which when nil, default to context.Background.
// - This is an interface for decoupling, not third-party implementations. All implementations are in wazero.
// - This includes all value types available in WebAssembly 1.0 (20191205) and all are encoded little-endian.
//