Skip to content

Implement type imports and exports #7330

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Comment updates
  • Loading branch information
vouillon committed Feb 27, 2025
commit 982ab076ad6dca6a3e58a22d9db3a26e7f1b6dd8
2 changes: 1 addition & 1 deletion src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
std::vector<DefPos> dataDefs;
std::vector<DefPos> tagDefs;

// Type imports: name, positions of type and import names.
// Type imports: name, export names, import names, and positions.
std::vector<std::tuple<Name, std::vector<Name>, ImportNames, Index>>
typeImports;

Expand Down
1 change: 0 additions & 1 deletion src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,6 @@ class WasmBinaryReader {
Name getMemoryName(Index index);
Name getGlobalName(Index index);
Name getTagName(Index index);
Name getTypeName(Index index);
Name getDataName(Index index);
Name getElemName(Index index);

Expand Down
8 changes: 7 additions & 1 deletion src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,9 @@ void WasmBinaryReader::read() {
// appear more than once, and verify those that shouldn't do not.
// We can have a import section containing type imports before the
// type section.
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to add a TODO for more specific validation here.

// TODO: We should check that the sections are ordered properly and
// that there is at most two import sections (one with only type
// imports, the other with no type imports).
if (sectionCode != BinaryConsts::Section::Custom &&
sectionCode != BinaryConsts::Section::Import &&
!seenSections.insert(sectionCode).second) {
Expand Down Expand Up @@ -2760,7 +2763,10 @@ void WasmBinaryReader::readImports() {
if (seenSections.count(BinaryConsts::Section::Type)) {
throwError("type import after type section");
}
getInt8(); // Reserved 'kind' field
auto kind = getInt8(); // Reserved 'kind' field
if (kind != 0) {
throwError("type import with non-zero kind");
}
int64_t htCode = getS64LEB(); // TODO: Actually s33
auto share = Unshared;
if (htCode == BinaryConsts::EncodedType::Shared) {
Expand Down