Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 24 additions & 23 deletions epsilon/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type resolvedImports struct {
globals []*Global
}

// resolveImports resolves the imports declared in the given module against
// the provided map of available imports.
// resolveImports resolves the imports declared in the given module against the
// provided map of available imports.
func resolveImports(
module *moduleDefinition,
instance *ModuleInstance,
Expand Down Expand Up @@ -86,7 +86,18 @@ func findImport(
return obj, nil
}
}
return nil, fmt.Errorf("%s.%s not found in imports", module, name)
return nil, fmt.Errorf("unknown import %s.%s", module, name)
}

// incompatibleImport reports an import that was found but whose provided value
// does not match the type the importing module declares.
func incompatibleImport(imp moduleImport, detail string) error {
return fmt.Errorf(
"incompatible import type for %s.%s: %s",
imp.moduleName,
imp.name,
detail,
)
}

func resolveFunctionImport(
Expand All @@ -103,9 +114,7 @@ func resolveFunctionImport(
}

if !f.GetType().Equal(functionType) {
return nil, fmt.Errorf(
"type mismatch for %s.%s", imp.moduleName, imp.name,
)
return nil, incompatibleImport(imp, "signature mismatch")
}

return f, nil
Expand All @@ -119,7 +128,7 @@ func resolveFunctionImport(
}, nil
}

return nil, fmt.Errorf("%s.%s not a function", imp.moduleName, imp.name)
return nil, incompatibleImport(imp, "not a function")
}

func resolveGlobalImport(
Expand All @@ -130,7 +139,7 @@ func resolveGlobalImport(
) (*Global, error) {
global, ok := obj.(*Global)
if !ok {
return nil, fmt.Errorf("%s.%s not a global", imp.moduleName, imp.name)
return nil, incompatibleImport(imp, "not a global")
}

if global.owner != instance.vm {
Expand All @@ -140,14 +149,10 @@ func resolveGlobalImport(
}

if global.Mutable != globalType.IsMutable {
return nil, fmt.Errorf(
"mutability mismatch for %s.%s", imp.moduleName, imp.name,
)
return nil, incompatibleImport(imp, "mutability mismatch")
}
if global.Type != globalType.ValueType {
return nil, fmt.Errorf(
"value type mismatch for %s.%s", imp.moduleName, imp.name,
)
return nil, incompatibleImport(imp, "value type mismatch")
}
return global, nil
}
Expand All @@ -160,7 +165,7 @@ func resolveMemoryImport(
) (*Memory, error) {
memory, ok := obj.(*Memory)
if !ok {
return nil, fmt.Errorf("%s.%s not a memory", imp.moduleName, imp.name)
return nil, incompatibleImport(imp, "not a memory")
}

if memory.owner != instance.vm {
Expand All @@ -171,7 +176,7 @@ func resolveMemoryImport(

provided := Limits{Min: uint32(memory.Size()), Max: memory.Limits.Max}
if !limitsMatch(provided, memoryType.Limits) {
return nil, fmt.Errorf("limit mismatch for %s.%s", imp.moduleName, imp.name)
return nil, incompatibleImport(imp, "limit mismatch")
}
return memory, nil
}
Expand All @@ -184,7 +189,7 @@ func resolveTableImport(
) (*Table, error) {
table, ok := obj.(*Table)
if !ok {
return nil, fmt.Errorf("%s.%s not a table", imp.moduleName, imp.name)
return nil, incompatibleImport(imp, "not a table")
}

if table.owner != instance.vm {
Expand All @@ -194,16 +199,12 @@ func resolveTableImport(
}

if table.Type.ReferenceType != tableType.ReferenceType {
return nil, fmt.Errorf(
"reference type mismatch for %s.%s", imp.moduleName, imp.name,
)
return nil, incompatibleImport(imp, "reference type mismatch")
}

provided := Limits{Min: uint32(table.Size()), Max: table.Type.Limits.Max}
if !limitsMatch(provided, tableType.Limits) {
return nil, fmt.Errorf(
"limit mismatch for %s.%s", imp.moduleName, imp.name,
)
return nil, incompatibleImport(imp, "limit mismatch")
}
return table, nil
}
Expand Down
11 changes: 5 additions & 6 deletions epsilon/numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

var (
errIntegerDivideByZero = errors.New("integer divide by zero")
errIntegerDivideOverflow = errors.New("integer divide overflow")
errIntegerOverflow = errors.New("integer overflow")
errInvalidConversionToInteger = errors.New("invalid conversion to integer")
)
Expand All @@ -48,7 +47,7 @@ func divS32(a, b int32) (int32, error) {
return 0, errIntegerDivideByZero
}
if a == math.MinInt32 && b == -1 {
return 0, errIntegerDivideOverflow
return 0, errIntegerOverflow
}
return a / b, nil
}
Expand All @@ -58,7 +57,7 @@ func divS64(a, b int64) (int64, error) {
return 0, errIntegerDivideByZero
}
if a == math.MinInt64 && b == -1 {
return 0, errIntegerDivideOverflow
return 0, errIntegerOverflow
}
return a / b, nil
}
Expand Down Expand Up @@ -138,9 +137,9 @@ func sqrt[T wasmFloat](a T) T {

// minF32 returns the wasm minimum of a and b. Go's min propagates an operand
// NaN unchanged, which leaves a signaling NaN signaling and varies across
// architectures; the spec requires an arithmetic NaN, and the canonical NaN
// is one. Go's min also cannot be used for the zeros, where the sign decides
// the result rather than the comparison.
// architectures; the spec requires an arithmetic NaN, and the canonical NaN is
// one. Go's min also cannot be used for the zeros, where the sign decides the
// result rather than the comparison.
func minF32(a, b float32) float32 {
if a != a || b != b {
return math.Float32frombits(canonicalNaNF32)
Expand Down
Loading
Loading