-
Notifications
You must be signed in to change notification settings - Fork 786
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
vouillon
wants to merge
19
commits into
WebAssembly:main
Choose a base branch
from
vouillon:type-imports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c066fcd
Type imports
vouillon 48cc48e
Add tests
vouillon 9e527ef
Test updates
vouillon 7e56d35
More test updates
vouillon df60079
Fix hashing and comparison
vouillon f098ced
Fuzzing updates
vouillon fce76ff
Validation fixes
vouillon e316807
Reuse the type-sorting code from ModuleUtils in wasm-merge
vouillon 982ab07
Comment updates
vouillon 6dfcdb9
Tests: name functions
vouillon 22e093b
Rename Import to TypeImport
vouillon 60bd789
Unnecessary include
vouillon bc7c3f8
Fix Subtypes::getMaxDepths
vouillon 1541147
Merge remote-tracking branch 'origin/main' into type-imports
vouillon 7da566f
fix
vouillon c989d27
Put type exports with other exports
vouillon ad45a6d
Fix tool options
vouillon aa1e4ae
format
vouillon 682ab0f
Fix tool outputs
vouillon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -935,6 +935,10 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx { | |||||
std::vector<DefPos> dataDefs; | ||||||
std::vector<DefPos> tagDefs; | ||||||
|
||||||
// Type imports: name, positions of type and import names. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
std::vector<std::tuple<Name, std::vector<Name>, ImportNames, Index>> | ||||||
typeImports; | ||||||
|
||||||
// Positions of export definitions. | ||||||
std::vector<Index> exportDefs; | ||||||
|
||||||
|
@@ -957,6 +961,7 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx { | |||||
|
||||||
// Used to verify that all imports come before all non-imports. | ||||||
bool hasNonImport = false; | ||||||
bool hasTypeDefinition = false; | ||||||
|
||||||
Result<> checkImport(Index pos, ImportNames* import) { | ||||||
if (import) { | ||||||
|
@@ -978,9 +983,10 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx { | |||||
void setOpen() {} | ||||||
void setShared() {} | ||||||
Result<> addSubtype(HeapTypeT) { return Ok{}; } | ||||||
void finishTypeDef(Name name, Index pos) { | ||||||
void finishTypeDef(Name name, const std::vector<Name>& exports, Index pos) { | ||||||
// TODO: type annotations | ||||||
typeDefs.push_back({name, pos, Index(typeDefs.size()), {}}); | ||||||
hasTypeDefinition = true; | ||||||
} | ||||||
size_t getRecGroupStartIndex() { return 0; } | ||||||
void addRecGroup(Index, size_t) {} | ||||||
|
@@ -1092,10 +1098,28 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx { | |||||
TypeUseT type, | ||||||
Index pos); | ||||||
|
||||||
Result<> addTypeImport(Name name, | ||||||
const std::vector<Name>& exports, | ||||||
ImportNames* import, | ||||||
Index pos, | ||||||
Index typePos) { | ||||||
if (hasTypeDefinition) { | ||||||
return in.err(pos, "type import after type definitions"); | ||||||
} | ||||||
typeDefs.push_back({name, pos, Index(typeDefs.size()), {}}); | ||||||
typeImports.push_back({name, exports, *import, typePos}); | ||||||
return Ok{}; | ||||||
} | ||||||
|
||||||
Result<> addExport(Index pos, Ok, Name, ExternalKind) { | ||||||
exportDefs.push_back(pos); | ||||||
return Ok{}; | ||||||
} | ||||||
|
||||||
Result<> addTypeExport(Index pos, Ok, Name) { | ||||||
exportDefs.push_back(pos); | ||||||
return Ok{}; | ||||||
} | ||||||
}; | ||||||
|
||||||
// Phase 2: Parse type definitions into a TypeBuilder. | ||||||
|
@@ -1108,12 +1132,15 @@ struct ParseTypeDefsCtx : TypeParserCtx<ParseTypeDefsCtx> { | |||||
// Parse the names of types and fields as we go. | ||||||
std::vector<TypeNames> names; | ||||||
|
||||||
// Keep track of type exports | ||||||
std::vector<std::vector<Name>> typeExports; | ||||||
|
||||||
// The index of the subtype definition we are parsing. | ||||||
Index index = 0; | ||||||
|
||||||
ParseTypeDefsCtx(Lexer& in, TypeBuilder& builder, const IndexMap& typeIndices) | ||||||
: TypeParserCtx<ParseTypeDefsCtx>(typeIndices), in(in), builder(builder), | ||||||
names(builder.size()) {} | ||||||
names(builder.size()), typeExports(builder.size()) {} | ||||||
|
||||||
TypeT makeRefType(HeapTypeT ht, Nullability nullability) { | ||||||
return builder.getTempRefType(ht, nullability); | ||||||
|
@@ -1154,7 +1181,18 @@ struct ParseTypeDefsCtx : TypeParserCtx<ParseTypeDefsCtx> { | |||||
return Ok{}; | ||||||
} | ||||||
|
||||||
void finishTypeDef(Name name, Index pos) { names[index++].name = name; } | ||||||
void finishTypeDef(Name name, const std::vector<Name>& exports, Index pos) { | ||||||
typeExports[index] = exports; | ||||||
names[index++].name = name; | ||||||
} | ||||||
|
||||||
Result<> addTypeImport(Name name, | ||||||
const std::vector<Name>& exports, | ||||||
ImportNames* import, | ||||||
Index pos, | ||||||
Index typePos) { | ||||||
return Ok{}; | ||||||
} | ||||||
|
||||||
size_t getRecGroupStartIndex() { return index; } | ||||||
|
||||||
|
@@ -1403,6 +1441,14 @@ struct ParseModuleTypesCtx : TypeParserCtx<ParseModuleTypesCtx>, | |||||
t->type = use.type; | ||||||
return Ok{}; | ||||||
} | ||||||
|
||||||
Result<> addTypeImport(Name name, | ||||||
const std::vector<Name>& exports, | ||||||
ImportNames* import, | ||||||
Index pos, | ||||||
Index typePos) { | ||||||
return Ok{}; | ||||||
} | ||||||
}; | ||||||
|
||||||
// Phase 5: Parse module element definitions, including instructions. | ||||||
|
@@ -1757,14 +1803,30 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { | |||||
return Ok{}; | ||||||
} | ||||||
|
||||||
Result<> addTypeImport(Name, | ||||||
const std::vector<Name> exports, | ||||||
ImportNames* import, | ||||||
Index pos, | ||||||
Index typePos) { | ||||||
return Ok{}; | ||||||
} | ||||||
|
||||||
Result<> addExport(Index pos, Name value, Name name, ExternalKind kind) { | ||||||
if (wasm.getExportOrNull(name)) { | ||||||
if (wasm.getTypeExportOrNull(name) || wasm.getExportOrNull(name)) { | ||||||
return in.err(pos, "duplicate export"); | ||||||
} | ||||||
wasm.addExport(builder.makeExport(name, value, kind)); | ||||||
return Ok{}; | ||||||
} | ||||||
|
||||||
Result<> addTypeExport(Index pos, HeapType heaptype, Name name) { | ||||||
if (wasm.getTypeExportOrNull(name) || wasm.getTypeExportOrNull(name)) { | ||||||
return in.err(pos, "duplicate export"); | ||||||
} | ||||||
wasm.addTypeExport(builder.makeTypeExport(name, heaptype)); | ||||||
return Ok{}; | ||||||
} | ||||||
|
||||||
Result<Index> addScratchLocal(Index pos, Type type) { | ||||||
if (!func) { | ||||||
return in.err(pos, | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.