Skip to content

Commit

Permalink
Rename moduleName() -> module(), fieldName() -> name() (#537)
Browse files Browse the repository at this point in the history
Follow up to #527.

Using `fieldName` might cause confusion now (a "field" in a module to me
sounds like a "global" value, not a function) and in the future; e.g.
[fields](https://webassembly.github.io/gc/core/syntax/types.html#syntax-fieldtype)
are the fields in a `Structure` (see WasmGC);

Signed-off-by: Edoardo Vacchi <[email protected]>

---------

Signed-off-by: Edoardo Vacchi <[email protected]>
  • Loading branch information
evacchi authored Sep 24, 2024
1 parent 700de87 commit cd15e52
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

public class ExternalFunction implements ExternalValue {
private final WasmFunctionHandle handle;
private final String moduleName;
private final String fieldName;
private final String module;
private final String name;
private final List<ValueType> paramTypes;
private final List<ValueType> returnTypes;

public ExternalFunction(
String moduleName,
String fieldName,
String module,
String name,
WasmFunctionHandle handle,
List<ValueType> paramTypes,
List<ValueType> returnTypes) {
this.handle = handle;
this.moduleName = moduleName;
this.fieldName = fieldName;
this.module = module;
this.name = name;
this.paramTypes = paramTypes;
this.returnTypes = returnTypes;
}
Expand All @@ -28,13 +28,13 @@ public WasmFunctionHandle handle() {
}

@Override
public String moduleName() {
return moduleName;
public String module() {
return module;
}

@Override
public String fieldName() {
return fieldName;
public String name() {
return name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

public class ExternalGlobal implements ExternalValue {
private final GlobalInstance instance;
private final String moduleName;
private final String fieldName;
private final String module;
private final String name;

public ExternalGlobal(String moduleName, String fieldName, GlobalInstance instance) {
public ExternalGlobal(String module, String name, GlobalInstance instance) {
this.instance = instance;
this.moduleName = moduleName;
this.fieldName = fieldName;
this.module = module;
this.name = name;
}

public GlobalInstance instance() {
return instance;
}

@Override
public String moduleName() {
return moduleName;
public String module() {
return module;
}

@Override
public String fieldName() {
return fieldName;
public String name() {
return name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.dylibso.chicory.runtime;

public class ExternalMemory implements ExternalValue {
private final String moduleName;
private final String fieldName;
private final String module;
private final String name;
private final Memory memory;

public ExternalMemory(String moduleName, String fieldName, Memory memory) {
this.moduleName = moduleName;
this.fieldName = fieldName;
public ExternalMemory(String module, String name, Memory memory) {
this.module = module;
this.name = name;
this.memory = memory;
}

@Override
public String moduleName() {
return moduleName;
public String module() {
return module;
}

@Override
public String fieldName() {
return fieldName;
public String name() {
return name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import java.util.Map;

public class ExternalTable implements ExternalValue {
private final String moduleName;
private final String fieldName;
private final String module;
private final String name;
private final TableInstance table;

public ExternalTable(String moduleName, String fieldName, TableInstance table) {
this.moduleName = moduleName;
this.fieldName = fieldName;
public ExternalTable(String module, String name, TableInstance table) {
this.module = module;
this.name = name;
this.table = table;
}

public ExternalTable(String moduleName, String fieldName, Map<Integer, Integer> funcRefs) {
this.moduleName = moduleName;
this.fieldName = fieldName;
public ExternalTable(String module, String name, Map<Integer, Integer> funcRefs) {
this.module = module;
this.name = name;

long maxFuncRef = 0;
for (var k : funcRefs.keySet()) {
Expand All @@ -33,13 +33,13 @@ public ExternalTable(String moduleName, String fieldName, Map<Integer, Integer>
}

@Override
public String moduleName() {
return moduleName;
public String module() {
return module;
}

@Override
public String fieldName() {
return fieldName;
public String name() {
return name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ enum Type {
TABLE
}

String moduleName();
String module();

String fieldName();
String name();

ExternalValue.Type type();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
public class HostFunction extends ExternalFunction {
public HostFunction(
String moduleName,
String fieldName,
String symbolName,
WasmFunctionHandle handle,
List<ValueType> paramTypes,
List<ValueType> returnTypes) {
super(moduleName, fieldName, handle, paramTypes, returnTypes);
super(moduleName, symbolName, handle, paramTypes, returnTypes);
}
}
30 changes: 14 additions & 16 deletions runtime/src/main/java/com/dylibso/chicory/runtime/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,19 +400,19 @@ private void validateExternalFunctionSignature(FunctionImport imprt, ExternalFun
|| expectedType.returns().size() != f.returnTypes().size()) {
throw new UnlinkableException(
"incompatible import type for host function "
+ f.moduleName()
+ f.module()
+ "."
+ f.fieldName());
+ f.name());
}
for (int i = 0; i < expectedType.params().size(); i++) {
var expected = expectedType.params().get(i);
var got = f.paramTypes().get(i);
if (expected != got) {
throw new UnlinkableException(
"incompatible import type for host function "
+ f.moduleName()
+ f.module()
+ "."
+ f.fieldName());
+ f.name());
}
}
for (int i = 0; i < expectedType.returns().size(); i++) {
Expand All @@ -421,9 +421,9 @@ private void validateExternalFunctionSignature(FunctionImport imprt, ExternalFun
if (expected != got) {
throw new UnlinkableException(
"incompatible import type for host function "
+ f.moduleName()
+ f.module()
+ "."
+ f.fieldName());
+ f.name());
}
}
}
Expand All @@ -449,9 +449,9 @@ private void validateHostTableType(TableImport i, ExternalTable t) {
+ ", current: "
+ t.table().limits()
+ " on table: "
+ t.moduleName()
+ t.module()
+ "."
+ t.fieldName());
+ t.name());
}
}

Expand All @@ -478,16 +478,16 @@ private void validateHostMemoryType(MemoryImport i, ExternalMemory m) {
+ ", host: "
+ m.memory().limits()
+ " on memory: "
+ m.moduleName()
+ m.module()
+ "."
+ m.fieldName());
+ m.name());
}
}

private void validateNegativeImportType(
String moduleName, String name, ExternalValue[] external) {
for (var fh : external) {
if (fh.moduleName().equals(moduleName) && fh.fieldName().equals(name)) {
if (fh.module().equals(moduleName) && fh.name().equals(name)) {
throw new UnlinkableException("incompatible import type");
}
}
Expand Down Expand Up @@ -558,14 +558,12 @@ private ExternalValues mapHostImports(
int cnt;
for (var impIdx = 0; impIdx < imports.length; impIdx++) {
var i = imports[impIdx];
var name = i.moduleName() + "." + i.name();
var name = i.module() + "." + i.name();
var found = false;
validateNegativeImportType(
i.moduleName(), i.name(), i.importType(), externalValues);
validateNegativeImportType(i.module(), i.name(), i.importType(), externalValues);
Function<ExternalValue, Boolean> checkName =
(ExternalValue fh) ->
i.moduleName().equals(fh.moduleName())
&& i.name().equals(fh.fieldName());
i.module().equals(fh.module()) && i.name().equals(fh.name());
switch (i.importType()) {
case FUNCTION:
cnt = externalValues.functionCount();
Expand Down
24 changes: 12 additions & 12 deletions runtime/src/main/java/com/dylibso/chicory/runtime/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Store() {}
*/
public Store addFunction(ExternalFunction... function) {
for (var f : function) {
functions.put(new QualifiedName(f.moduleName(), f.fieldName()), f);
functions.put(new QualifiedName(f.module(), f.name()), f);
}
return this;
}
Expand All @@ -33,7 +33,7 @@ public Store addFunction(ExternalFunction... function) {
*/
public Store addGlobal(ExternalGlobal... global) {
for (var g : global) {
globals.put(new QualifiedName(g.moduleName(), g.fieldName()), g);
globals.put(new QualifiedName(g.module(), g.name()), g);
}
return this;
}
Expand All @@ -43,7 +43,7 @@ public Store addGlobal(ExternalGlobal... global) {
*/
public Store addMemory(ExternalMemory... memory) {
for (var m : memory) {
memories.put(new QualifiedName(m.moduleName(), m.fieldName()), m);
memories.put(new QualifiedName(m.module(), m.name()), m);
}
return this;
}
Expand All @@ -53,7 +53,7 @@ public Store addMemory(ExternalMemory... memory) {
*/
public Store addTable(ExternalTable... table) {
for (var t : table) {
tables.put(new QualifiedName(t.moduleName(), t.fieldName()), t);
tables.put(new QualifiedName(t.module(), t.name()), t);
}
return this;
}
Expand Down Expand Up @@ -138,12 +138,12 @@ public Instance instantiate(String name, Module m) {
* QualifiedName is internally used to use pairs (moduleName, name) as keys in the store.
*/
static class QualifiedName {
private final String moduleName;
private final String fieldName;
private final String module;
private final String name;

public QualifiedName(String moduleName, String fieldName) {
this.moduleName = moduleName;
this.fieldName = fieldName;
public QualifiedName(String module, String name) {
this.module = module;
this.name = name;
}

@Override
Expand All @@ -155,13 +155,13 @@ public boolean equals(Object o) {
return false;
}
QualifiedName qualifiedName = (QualifiedName) o;
return Objects.equals(moduleName, qualifiedName.moduleName)
&& Objects.equals(fieldName, qualifiedName.fieldName);
return Objects.equals(module, qualifiedName.module)
&& Objects.equals(name, qualifiedName.name);
}

@Override
public int hashCode() {
return Objects.hash(moduleName, fieldName);
return Objects.hash(module, name);
}
}
}
16 changes: 8 additions & 8 deletions wasm/src/main/java/com/dylibso/chicory/wasm/types/Import.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
* reference.
*/
public abstract class Import {
private final String moduleName;
private final String module;
private final String name;

Import(String moduleName, String name) {
this.moduleName = requireNonNull(moduleName, "moduleName");
Import(String module, String name) {
this.module = requireNonNull(module, "moduleName");
this.name = requireNonNull(name, "name");
}

/**
* @return the module name to import from
*/
public String moduleName() {
return moduleName;
public String module() {
return module;
}

/**
Expand All @@ -44,16 +44,16 @@ public boolean equals(Object obj) {
}

public boolean equals(Import other) {
return other != null && moduleName.equals(other.moduleName) && name.equals(other.name);
return other != null && module.equals(other.module) && name.equals(other.name);
}

@Override
public int hashCode() {
return Objects.hash(moduleName, name);
return Objects.hash(module, name);
}

public StringBuilder toString(StringBuilder b) {
return b.append('<').append(moduleName).append('.').append(name).append('>');
return b.append('<').append(module).append('.').append(name).append('>');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void shouldParseFile() throws IOException {
var importSection = module.importSection();
assertEquals(1, importSection.importCount());
assertEquals(ExternalType.FUNCTION, importSection.getImport(0).importType());
assertEquals("env", importSection.getImport(0).moduleName());
assertEquals("env", importSection.getImport(0).module());
assertEquals("gotit", importSection.getImport(0).name());

// check data section
Expand Down

0 comments on commit cd15e52

Please sign in to comment.