-
Notifications
You must be signed in to change notification settings - Fork 777
Implement Garbage Collector type system #2607
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
base: main
Are you sure you want to change the base?
Conversation
243ec44 to
68fe37e
Compare
| }; | ||
| using TypeMutVector = std::vector<TypeMut>; | ||
|
|
||
| // Garbage Collector specific type information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a core part of the patch. It contains the (sub ...) part of the type. It is declared as a structure, because it is not mandatory.
include/wabt/binary-reader.h
Outdated
| virtual Result OnTypeCount(Index count) = 0; | ||
| virtual Result OnRecursiveRange(Index start_index, Index type_count) = 0; | ||
| virtual Result OnFuncType(Index index, | ||
| GCTypeExtension* gc_ext, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This structure is passed as a second argument, because it is a header, but it could go to the last argument since it is an extra (and optional) information. Which one you prefer?
| struct RecursiveRange { | ||
| Index start_index; | ||
| Index type_count; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another core structure to encode (rec ...) constructs. It represents the range.
| std::vector<FuncType> func_types; | ||
| std::vector<StructType> struct_types; | ||
| std::vector<ArrayType> array_types; | ||
| std::vector<RecursiveRange> recursive_ranges; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is stored in an ordered array. It cannot be stored as part of the types, because zero length (rec) range is allowed for whatever reason.
e0ce7f8 to
adcbdf7
Compare
|
I have reworked the type validation system of the patch. Now it is capable of detecting the first type index for all equal types. This first type index is called canonical index. If I have two types ( |
75bdfe5 to
890a316
Compare
|
The |
|
It sounds like you are canonicalising wrt type indices. But type indices are meaningless in any program that consists of more than one module. Type canonicalisation must happen globally, across module boundaries, based on the types' structure. I suspect that is the reason for the link/run-time tests failing. |
|
The link tests are not failing, although the interpreter do a slow type comparison for import/exports. As far as I understand the interpreter here is just a demonstration, so this is probably ok. The runtime tests fail because the operations (such as The global type canonicalisation sounds like a very good idea! A high performance engine should do that! |
cc8e21f to
097046d
Compare
|
@sbc100 there is a fuzzer issue in the code. The code is correct though. https://github.com/WebAssembly/wabt/blob/main/src/interp/binary-reader-interp.cc#L772 https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/fuzzer/FuzzerLoop.cpp What shall I do? |
We don't tend to have time to worry about fixing all the fuzz tests issues, unless they could conceivable show up in real world programs. i.e. we tend to assume trusted and save inputs, since we don't have the resources the harden wabt against other things. Having said that we obviously would be happy to accept fixes for such issues if folks come up with them. |
|
There is nothing to fix here, the code is correct (and not related to this patch). It is simply a limitation of the fuzzer, it assumes too much memory allocation is likely a bug. |
68c749c to
b7fc45c
Compare
0af19a5 to
ffdf723
Compare
|
Is there a compile time define (or can be defined during build in some way) to detect that the fuzzer is active? Then I could guard out the failing |
f694b94 to
21a32fa
Compare
|
I have checked the type hashing system in the whole test system. It performs 45157 comparisons, and the hash/type_count is equal 513 times. From that, 467 times the types are really equal, and 46 times they are not. Overall the efficiency is 99.9%. I could not improve the hash by using more complex hashes. However, Edit: Now the efficiency is 100%. It does not mean it is perfect or anything. The missing cases were valid, worth improving the code. |
a4981a8 to
ee17d2b
Compare
0e0a846 to
508ab52
Compare
|
@sbc100 This is the first patch of the GC support. It triggers a fuzzer fail I described above. Reserving memory is correct for valid wasm files. However, a random value generated by a fuzzer causes a large memory allocation, which is considered as an error by the fuzzer. The fuzzer has an option to raise this allocation limit. What do you suggest? |
This patch supports parsing the new GC types - Abstract types - Recursive types - Composite types The patch also improves type comparison.
|
Note: the issue is visible on the fuzzer backtrace: The OnDataCount gets a huge number, runs the |
This patch supports parsing the new GC types
The patch also improves type comparison.