7716 Commits

Author SHA1 Message Date
d1e46312e6 install libbinaryen.so to private path 2025-04-08 18:13:13 +03:00
d8fd31f06d disable check 2025-04-08 18:01:04 +03:00
c35168209c test 2025-04-08 17:50:20 +03:00
c9665bde22 test 2025-04-08 17:46:56 +03:00
5522ffb9aa test 2025-04-08 17:32:30 +03:00
71cc4d0235 test 2025-04-08 17:30:05 +03:00
f7eb23c449 update gear rules 2025-04-08 17:29:57 +03:00
193db1759e add patch for build with system gtest 2025-04-08 17:29:04 +03:00
b3e6dc095d test 2025-04-08 17:25:56 +03:00
Konstantin Kozoriz
eff3fbe0ce 123-alt1
* Tue Apr 01 2025 Konstantin Kozoriz <kozorizki@altlinux.org> 123-alt1
 - Initial RPM package for Binaryen
2025-04-08 17:22:14 +03:00
Konstantin Kozoriz
66628d6626 gear-remotes-save 2025-04-08 17:22:07 +03:00
Alon Zakai
6a6e08057c
Release version 123 (#7394)
Given the big speedup in our official release binaries for Linux, this
seems useful to get to users quickly.
2025-03-25 11:13:08 -07:00
Alon Zakai
52a15b3e0e
[NFC] Fix help text for tools that emit binary (#7398)
Our tools all stated that if -o is not provided, we write to stdout by
default. But that is not true - we do nothing in that case. I believe the
rationale is that we write text to stdout by default in say wasm2js, but
for wasm-opt etc. we don't want to write binary to stdout (as that is
dangerous).
2025-03-25 11:12:29 -07:00
Thomas Lively
def4095995
[NFC] Use a lambda instead of a macro in gtest (#7395)
The length macro used in a type test in type-builder.cpp was causing
extremely long compile times in some compilers. Use a lambda instead to
fix it. This makes the error messages less useful when a test fails, but
under normal circumstances the test should not be failing, so this is a
good trade off.

Fixes #7383.
2025-03-24 20:48:44 -07:00
Thomas Lively
8958df4115
Validate descriptor declarations (#7392)
To ensure soundness, there are very particular rules about how described
and descriptor type declarations must relate to one another and their
supertypes. Implement and test these rules.
2025-03-24 11:06:01 -07:00
Thomas Lively
7508e81f0d
Parsing and binary writing for custom descriptors (#7387)
Implement text and binary parsing as well as binary writing for
`descriptor` and `describes` clauses, as specified in the
custom-descriptors proposal. Also simplify some neighboring code dealing
with shared types as a drive-by.
2025-03-21 17:06:43 -07:00
Thomas Lively
835a178ae4
Fix RefFunc type updating in I64ToI32Lowering (#7390)
We recently started updating RefFunc types in I64ToI32Lowering to ensure
that their types matched the updated types of their functions. But the
way we updated the types of RefFunc expressions and Functions were not
the same. When updating Functions that return i64, we replace the result
type with i32 and use a global to propagate the remaining bits to the
caller. Previously when updating RefFunc result types, we would instead
split i64s into pairs of i32s, depending on multivalue to lower the
type. Update the logic for updating RefFunc results to match the
existing logic for updating Functions.
2025-03-21 14:39:35 -07:00
Thomas Lively
cd3b26d6e2
Require RefFunc to have the proper type (#7376)
As a holdout from before GC was implemented, we previously allowed
RefFunc expressions to have type `funcref` rather than a specific
signature type matching that of the referenced function. Remove this
allowance and start requiring the types to be correct and precise to
eliminate the possibility of stale types inhibiting (or invalidating!)
optimizations.

Update various older passes to update the types of RefFuncs, including
those in tables, to keep their output passing validation. Also update
the kitchen sink example test to construct RefFunc expressions with the
correct type via the C API.
2025-03-21 10:03:53 -07:00
Derek Schuff
3f341e5019
Exclude the mimalloc files from the Binaryen install (#7386)
Since mimalloc is linked statically into the Binaryen tools, none of its
files need to be installed with Binaryen.

Also use CMAKE_SYSTEM_NAME instead of LINUX, as the latter was
introduced in CMake 3.25
2025-03-20 16:42:31 -07:00
Sam Clegg
d98e3c46bc
[test] Use test-specific filename when running spec tests (#7384)
These means that the intermediate files don't conflict with each other
and you can inspect them by name after the test run.
2025-03-20 21:27:17 +00:00
Daniel Lehmann
adfdb1bebd
Do not pass C++-only flag to C compiler [NFC] (#7382)
And some minor drive-by fixes: gitignore Ninja in-tree build file,
update mimalloc to latest stable release.

This gets rid of warnings in the mimalloc cmake/make step. See
https://github.com/microsoft/mimalloc/issues/1031#issuecomment-2740351301
and https://github.com/microsoft/mimalloc/issues/1038.
2025-03-20 12:03:45 -07:00
Alon Zakai
087c6138e0
[Strings] Make string a subtype of ext, not any (#7373)
StringLowering converts strings to externs, which makes sense as we
lower stringrefs to imported JS strings. For the reverse transform it is
convenient to just have strings be subtypes of ext, see #7370 - that makes it
simple to switch stringref to externref and vice versa.

This also adds support for internalizing externref strings, which we
represent as anyref literals (basically a hidden subtype of anyref).
2025-03-20 09:49:39 -07:00
Alon Zakai
2639074506
Fix fuzztest compiler warnings [NFC] (#7380)
First is an unused variable, second is an unneeded move.
2025-03-19 15:17:54 -07:00
Alon Zakai
2a84e5a108
[Docs] Add slides that explain GUFA ("Just Flow Stuff") (#7379)
Simplified slides from a talk I gave, perhaps useful as docs.
2025-03-19 09:51:28 -07:00
Daniel Lehmann
d79639a355
Use mimalloc allocator for Linux static build (#7378)
The new CMake flag MIMALLOC_STATIC controls this.

mimalloc fixes perf problems, especially on heavily multi-threaded
workloads (many functions, high core count machines) on the musl
allocator, see #5561.
2025-03-19 09:25:54 -07:00
Congcong Cai
f3d100e0f0
Fix compile error when enable WASM_INTERPRETER_DEBUG [NFC] (#7375) 2025-03-18 13:31:37 -07:00
Ashley Nelson
9b161a9bf9
[Interpreter] Instance (#7343)
Adds an instance struct to encapsulate the runtime representation of a
module, as seen in the
[spec](https://webassembly.github.io/spec/core/exec/runtime.html#module-instances).
Also adds an instantiate method, which runs the initialization
expressions of globals in the module.
2025-03-14 04:20:02 +00:00
Thomas Lively
db9d68fac5
Fix clang-format on CI (#7374)
Make it print the diff again. Previously, when there was a formatting
problem, the script would exit the first time it ran `git clang-format`
without printing the results. Update the script to ignore errors on that
first run to ensure it makes it to the part where the results are
printed.
2025-03-13 20:15:40 -07:00
Thomas Lively
0402784e33
Support describes and descriptor clauses in the type system (#7369)
Update HeapTypeInfo, the rec group hashing and equality comparison
utilities, the type canonicalization algorithm, and the TypeBuilder
interface to support `describes` and `descriptor` clauses on heap type
definitions.

Parsing, the binary format, and validation for these clauses is left to
future PRs.
2025-03-13 18:59:18 -07:00
Thomas Lively
425d7c88aa
Type ref.null as exact (#7371)
`RefNull` expression now have type `(ref exact null bot)`, allowing them
to be used wherever a nullable exact reference is expected. Update the
fuzzer and fix a few bugs with exactness propagation this uncovers.
2025-03-13 15:37:06 -07:00
Jérôme Vouillon
83d8edbe8d
Prepare for type exports (#7335)
Change the type of the field `value` in class `Export` to
`std::variant<Name, HeapType>`, since a type export references a heap
type and not a named component.
2025-03-13 11:57:12 -07:00
Alon Zakai
b4bdcc3311
[Wasm GC] Fix GUFA on trampled params in TrapsNeverHappens mode (#7368)
GUFA in TNH mode will infer that this will trap:

(func $foo (param $x)
  (ref.cast $T (local.get $x))
)

(func $bar
  (call $foo (X))
)

If X's type will cause a trap when cast to T, then we infer that the call
will trap, and optimize. However, we were missing a check for the
param being trampled,

(func $foo (param $x)
  (local.set $x (Y))     ;; !!!!!!!!!!
  (ref.cast $T (local.get $x))
)

Then if Y can be cast, we should not actually trap.

Fix this by just tracking which params are written to. We only look
in the first basic block anyhow, and traverse it in order, so that is
enough.

Fixes #7366
2025-03-12 23:47:44 +00:00
Alon Zakai
a1758cf1f5
[Parsing] Emit better errors when binary parser encounters a bad code (#7367)
Noticed in #7363
2025-03-12 12:42:08 -07:00
Thomas Lively
8b47ebf8ad
Fix optimization of casts to exact null types (#7365)
The logic for optimizing ref.casts that are known to succeed did not
account for possible casts to exact null types, leading to it producing
invalid IR. Fix it and add a test.
2025-03-12 00:05:15 +00:00
Alon Zakai
b29abbe095
Fuzzer: Do not error on hashMemory() already existing (#7364) 2025-03-11 16:13:02 -07:00
Thomas Lively
2bddedc624
Update RemoveUnusedBrs for exact references (#7360)
When optimizing branching casts, RemoveUnusedBrs previously assumed that
if a source reference type was not a subtype of another target reference
type, but the source's heap type was a subtype of the target's heap
type, then it could use ref.as_non_null to convert from the source to
the target. This is no longer true now that we have exact types because
the types may differ in their exactness rather than in their nullness.

Update the check guarding the use of ref.as_non_null to specifically
check that a non-nullable version of the source type is a subtype of the
destination type and add a test.
2025-03-11 11:35:05 -07:00
Thomas Lively
3f59a7d796
[NFC] Add type.with(...) API to update reference types (#7359)
There are many places where we have to copy a reference type with some
modification, for example to make it refer to a different heap type or
to make it non-nullable or nullable. Previously the only way to do this
was with the `Type` constructor, retrieving and passing in the
unmodified fields of the old type explicitly.

With the addition of exact types, all of these sites have to be updated
to additionally propagate the old type's exactness. To simplify these
call sites and make them more robust against future additions to the
structure of reference types, introduce new APIs to update just a single
part of a reference type at a time.
2025-03-11 11:34:34 -07:00
Oscar Spencer
626e212f9a
[C API] Add all features (#7362)
Also reorders existing ones to match wasm-features.h.

Fixes #7361
2025-03-11 11:21:09 -07:00
Thomas Lively
0472ba2cf6
Handle exact references when fixing non-defaultable locals (#7357)
Some passes leave non-defaultable locals in an invalid state where not
all the gets of the local are structurally dominated by sets. To fix
this, the pass runner automatically calls
`TypeUpdating::handleNonDefaultableLocals` to find the problematic
locals and make them nullable. This function did not previously preserve
exactness in the updated local types. Fix it and add a test.
2025-03-10 21:42:17 -07:00
Thomas Lively
f0a8b6f985
Fix TypeUpdating for exact references in heap types (#7356)
Update the locations in wasm-type.h and type-updating.cpp responsible
for propagating exactness from references in heap types from the old
types to the new types and add a test. Leave updating other parts of
type-updating to later PRs with further tests that will exercise them.
2025-03-10 21:41:27 -07:00
Thomas Lively
7d2f80dd67
Update LocalSubtyping for exact references (#7355)
After calculating the best possible type for a local, LocalSubtyping
then checks to see whether the local can be non-nullable based on
whether all of its gets are dominated by sets. If it cannot be
non-nullable, the new type is adjusted to be nullable. This adjustment
did not previously preserve exactness, causing an assertion that the
optimization improves the type to fail. Fix the adjustment and add a
test.
2025-03-10 21:40:40 -07:00
Thomas Lively
894c770460
Fix assertion in OptimizeInstructions for exact refs (#7354)
When optimizing a cast to an exact reference to a bottom type,
OptimizeInstructions previously triggered an assertion that expected the
cast type to be inexact. Fix the assertion and surrounding code to be
more robust to the presence of exact reference types and add a test.
2025-03-10 21:39:48 -07:00
Thomas Lively
f9b7876ac1
Update finalization for exact references (#7353)
Update the finalization of all instructions whose types (or sent types)
depend on their operand reference types to handle exact references
correctly. Specifically, update `ref.as_non_null`, `br_on_null`,
`br_on_non_null`, `br_on_cast`, and `br_on_cast_fail`. Also add TODOs on
all instructions that allocate new heap objects to remind us to make
their types exact in the future.
2025-03-10 17:32:46 -07:00
Alon Zakai
a4966d76a3
[NFC] Document that PossibleContents is not a distributive lattice (#7349)
As proven in

https://github.com/WebAssembly/binaryen/pull/7331#discussion_r1979927844
2025-03-07 16:03:44 -08:00
Derek Schuff
9ae16af990
Gate LTO in the Emscripten build behind the BYN_ENABLE_LTO CMake flag (#7352)
Make it default to ON when using emscripten
2025-03-07 15:08:07 -08:00
Thomas Lively
84023b05b0
Do not fuzz on V8 with custom descriptors enabled (#7351)
V8 does not yet support custom descriptors, so update all fuzz handlers
that use it to avoid running when the feature is enabled. Since running
V8 is important, though, disable the feature most of the time, just like
we do for shared-everything.
2025-03-07 13:49:51 -08:00
Thomas Lively
bd59ac636a
Binary encoding and decoding of exact casts (#7347)
The binary format for casts needs to be extended to support exact
references. In particular, add new opcodes for `ref.test` and `ref.cast`
that take reference type immediates instead of heap type immediates. Use
two more bits in the flags immediate of `br_on_cast` and
`br_on_cast_fail` to encode the source and destination exactness.
2025-03-07 11:18:54 -08:00
Cheng Shao
d81f5bb4ec
MergeSimilarFunctions: Do a return_call when possible (#7350)
This patch makes MergeSimilarFunctions do a return_call when the module
has tail-call enabled. This is not merely an optimization, but is
crucial for correctness when optimizing wasm modules produced by GHC
that relies on tail-call to do control flow transfers. Previously, -Oz
would break tail-call enabled modules by making the control stack grow
where it shouldn't.
2025-03-07 10:45:54 -08:00
Thomas Lively
bc47696bdc
Validate that allocations produce non-nullable references (#7346)
For `struct.new`, `array.new`, `ref.func`, `ref.i31`, `cont.new`, and
`cont.bind`, check in the validator that the result type is a
non-nullable reference. This ensures that we have the most precise
possible type information for these instructions. The generic stale type
checker does not check this because finalizing these expressions does
not change their types.
2025-03-05 11:29:04 -08:00
Alon Zakai
dc055a8eba
GUFA: Fix a nondeterminism bug by pre-filtering (#7331)
The repeated "merge new content in, and filter based on the location it
arrives to" operation is non-commutative, and it turns out there was a
corner case we missed. Filtering before and after is enough to make us
return the same result with the ordering swapped.

This does make GUFA 5% slower, unfortunately. But this does result
in better code in some cases aside from fixing the nondeterminism.

Also add clearer comments about the problem here. We likely need to
just make the order of operations here deterministic (though a downside
of that is that the fuzzer wouldn't find bugs like this, and it would be
slower).
2025-03-05 09:27:06 -08:00