Skip to content
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

stringconsts #1

Closed
wants to merge 553 commits into from
Closed

stringconsts #1

wants to merge 553 commits into from
This pull request is big! We’re only showing the most recent 250 commits.

Commits on Apr 29, 2024

  1. Configuration menu
    Copy the full SHA
    4e4cb62 View commit details
    Browse the repository at this point in the history
  2. [Strings] Work around ref.cast not working on string views, and add f…

    …uzzing (WebAssembly#6549)
    
    As suggested in WebAssembly#6434 (comment) , lower ref.cast of string views
    to ref.as_non_null in binary writing. It is a simple hack that avoids the
    problem of V8 not allowing them to be cast.
    
    Add fuzzing support for the last three core string operations, after which
    that problem becomes very frequent.
    
    Also add yet another makeTrappingRefUse that was missing in that
    fuzzer code.
    kripken authored Apr 29, 2024
    Configuration menu
    Copy the full SHA
    63d308f View commit details
    Browse the repository at this point in the history
  3. Re-enable fuzzing of text round trips (WebAssembly#6560)

    The bug that had been preventing this fuzzing no longer reproduces.
    tlively authored Apr 29, 2024
    Configuration menu
    Copy the full SHA
    dcc5b7b View commit details
    Browse the repository at this point in the history
  4. [Parser] Re-use blocks instead of wrapping where possible (WebAssembl…

    …y#6552)
    
    When the input has branches to block scope, IR builder generally has to add a
    wrapper block with a label name for the branch to target. To reduce the parsed
    IR size, add a special case for when the wrapped expression is already an
    unnamed block. In that case we can simply add the label to the existing block
    instead of creating a new wrapper block.
    tlively authored Apr 29, 2024
    Configuration menu
    Copy the full SHA
    be001f7 View commit details
    Browse the repository at this point in the history
  5. Use the new wat parser in tests (WebAssembly#6556)

    Some of the example and gtest tests parse wat. Update them to use the new wat
    parser, fixing problems with their text input. In one case, comment out an
    outlining test entirely for now because the new parser produces different IR
    that changes the test output, but it is not obvious how to understand and fix
    the test.
    tlively authored Apr 29, 2024
    Configuration menu
    Copy the full SHA
    85a8600 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    8c99af0 View commit details
    Browse the repository at this point in the history
  7. [Strings] Limit string allocations like we do arrays (WebAssembly#6562)

    When we concat strings, check if their length exceeds a reasonable
    limit. (We do not need to do this for string.new as that reads from an
    array, which is already properly limited.)
    
    This avoids very slow pauses in the fuzzer (that sometimes OOM).
    kripken authored Apr 29, 2024
    Configuration menu
    Copy the full SHA
    497ffe2 View commit details
    Browse the repository at this point in the history

Commits on Apr 30, 2024

  1. J2CLOpts: Add "precompute" and "remove-unused-brs" as additional cleanup

    This makes the cleanup of bodies of functions that have had constants hoisted from them more effective.
    rluble authored Apr 30, 2024
    Configuration menu
    Copy the full SHA
    049ff7a View commit details
    Browse the repository at this point in the history

Commits on May 1, 2024

  1. [StackIR] Support source maps and DWARF with StackIR (WebAssembly#6564)

    Helping WebAssembly#6509, this fixes debugging support for StackIR, which makes it more
    possible to use StackIR in more places.
    
    The fix is basically just to pass around some more state, and then to call the
    parent with "please write debug info" at the correct times, mirroring the
    similar calls in BinaryenIRWriter.
    
    The relevant Emscripten tests pass, and the source map test modified
    here produces identical output in StackIR and non-StackIR modes (the
    test is also simplified to remove --new-wat-parser which is no longer
    needed, after which the test can clearly show that StackIR has the same
    output as BinaryenIR).
    kripken authored May 1, 2024
    Configuration menu
    Copy the full SHA
    7d9e4a8 View commit details
    Browse the repository at this point in the history
  2. Respect the Web limitation on Table size (WebAssembly#6567)

    Without this the fuzzer can error on differences in behavior between V8 and us.
    
    Also move the limitations constants to their own header.
    kripken authored May 1, 2024
    Configuration menu
    Copy the full SHA
    58753f4 View commit details
    Browse the repository at this point in the history

Commits on May 2, 2024

  1. Source map fixes (WebAssembly#6550)

    * Keep debug locations at function start
    
    The `fn_prolog_epilog.debugInfo` test is failing otherwise, since there
    was debug information associated to the nop instruction at the beginning
    of the function.
    
    * Do not clear the debug information when reaching the end of the source map
    
    The last segment should extend to the end of the function.
    
    * Propagate debug location from the function prolog to its first instruction
    
    * Fix printing of epilogue location
    
    The text parser no longer propagates locations to the epilogue, so we
    should always print the location if there is one.
    
    * Fix debug location smearing
    
    The debug location of the last instruction should not smear into the
    function epilogue, and a debug location from a previous function should
    not smear into the prologue of the current function.
    vouillon authored May 2, 2024
    Configuration menu
    Copy the full SHA
    d58c546 View commit details
    Browse the repository at this point in the history

Commits on May 6, 2024

  1. Allow DWARF and multivalue together (WebAssembly#6570)

    This allows writing of binaries with DWARF info when multivalue is
    enabled. Currently we just crash when both are enabled together. This
    just assumes, unless we have run DWARF-invalidating passes, all locals
    added for tuples or scratch locals would have been added at the end of
    the local list, so just printing all locals in order would preserve the
    DWARF info. Tuple locals are expanded in place and scratch locals are
    added at the end.
    aheejin authored May 6, 2024
    Configuration menu
    Copy the full SHA
    4b7c610 View commit details
    Browse the repository at this point in the history

Commits on May 8, 2024

  1. wasm-split: Handle RefFuncs (WebAssembly#6513)

    When we have a ref.func that refers to the secondary module then make a trampoline
    that calls it directly. The trampoline's call is then fixed up like all direct calls to the
    secondary module.
    kripken authored May 8, 2024
    Configuration menu
    Copy the full SHA
    ed2cec4 View commit details
    Browse the repository at this point in the history
  2. Fuzzer: Stop emitting nullable stringviews (WebAssembly#6574)

    As of
    
    https://chromium-review.googlesource.com/c/v8/v8/+/5471674
    
    V8 requires stringviews to be non-nullable. It might be possible to make that
    change in our IR, or to remove views entirely, but for now this PR makes the
    fuzzer stop emitting nullable stringviews as a workaround to allow us to fuzz
    current V8.
    
    There are still rare corner cases where this pattern is emitted, that we have
    not tracked down, and so this also makes the fuzzer ignore the error for now.
    kripken authored May 8, 2024
    Configuration menu
    Copy the full SHA
    a288a73 View commit details
    Browse the repository at this point in the history

Commits on May 9, 2024

  1. Fix CFGWalker issue in single-threaded mode (WebAssembly#6573)

    In that mode a walk on an entire module will reuse the same CFGWalker
    instance, so we must manually clear some fields, and we forgot some
    before.
    XMadrid authored May 9, 2024
    Configuration menu
    Copy the full SHA
    712ad9d View commit details
    Browse the repository at this point in the history
  2. [J2Cl] Make J2clOpts more effective with transitive deps in constant …

    …intialization (WebAssembly#6571)
    
    Constants that need to be hoisted sometimes are initialized by calling
    getters of other constants that need to be hoisted. These getters are
    non-trivial, e.g.
    
      (func $getConst1_<once>_@X (result (ref null $A))
        (block (result (ref null $A))
          (if (i32.eqz (ref.is_null (global.get $$const1@X)))
            (then
              (return (global.get $$const1@X))
            )
          )
          (global.set $$const1@X (struct.new $A (i32.const 2)))
          (global.get $$const1@X)
        )
    
      (func $getConst2_<once>_@X (result (ref null $A))
        (block (result (ref null $A))
          (if (i32.eqz (ref.is_null (global.get $$const2@X)))
            (then
              (return (global.get $$const2@X))
            )
          )
          (global.set $$const2@X  .... expression with (call $getConst1_<once>_@X)  ....))
          (global.get $$const2@X)
        )
    
    and can only be simplified after the constants they initialize are hoisted. After
    the constant is hoisted the getter can be inlined and constants that depend on
    it for their initialization can now be hoisted.
    
    Before this pass, inlining would happen after the pass was run by a subsequent
    run of the inliner (likely as part of -O3), requiring as many runs of this pass,
    interleaved with the inliner, as the depth in the call sequence.
    
    By having a simpler inliner run as part of the loop in this pass, the pass becomes
    more effective and more independent of the call depths.
    rluble authored May 9, 2024
    Configuration menu
    Copy the full SHA
    a816627 View commit details
    Browse the repository at this point in the history
  3. [validator] Remove indexType helper function (WebAssembly#6576)

    It seems like that each of the callsites already has looked up the
    `Memory` object so this helper is not doing anything useful.
    sbc100 authored May 9, 2024
    Configuration menu
    Copy the full SHA
    006181b View commit details
    Browse the repository at this point in the history
  4. [StackIR] Run StackIR during binary writing and not as a pass (WebAss…

    …embly#6568)
    
    Previously we had passes --generate-stack-ir, --optimize-stack-ir, --print-stack-ir
    that could be run like any other passes. After generating StackIR it was stashed on
    the function and invalidated if we modified BinaryenIR. If it wasn't invalidated then
    it was used during binary writing. This PR switches things so that we optionally
    generate, optimize, and print StackIR only during binary writing. It also removes
    all traces of StackIR from wasm.h - after this, StackIR is a feature of binary writing
    (and printing) logic only.
    
    This is almost NFC, but there are some minor noticeable differences:
    
    1.  We no longer print has StackIR in the text format when we see it is there. It
        will not be there during normal printing, as it is only present during binary writing.
        (but --print-stack-ir still works as before; as mentioned above it runs during writing).
    2.  --generate/optimize/print-stack-ir change from being passes to being flags that
        control that behavior instead. As passes, their order on the commandline mattered,
        while now it does not, and they only "globally" affect things during writing.
    3.  The C API changes slightly, as there is no need to pass it an option "optimize" to
        the StackIR APIs. Whether we optimize is handled by --optimize-stack-ir which is
        set like other optimization flags on the PassOptions object, so we don't need the
        old option to those C APIs.
    
    The main benefit here is simplifying the code, so we don't need to think about
    StackIR in more places than just binary writing. That may also allow future
    improvements to our usage of StackIR.
    kripken authored May 9, 2024
    Configuration menu
    Copy the full SHA
    7b2e019 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    1cc1501 View commit details
    Browse the repository at this point in the history

Commits on May 10, 2024

  1. Configuration menu
    Copy the full SHA
    9975b56 View commit details
    Browse the repository at this point in the history
  2. [memory64] Add table64 to existing memory64 support (WebAssembly#6577)

    Tests is still very limited.  Hopefully we can use the upstream spec
    tests soon and avoid having to write our own tests for
    `.set/.set/.fill/etc`.
    
    See WebAssembly/memory64#51
    sbc100 authored May 10, 2024
    Configuration menu
    Copy the full SHA
    abc430b View commit details
    Browse the repository at this point in the history

Commits on May 13, 2024

  1. Configuration menu
    Copy the full SHA
    5b46a5b View commit details
    Browse the repository at this point in the history
  2. [Parser] Parse wast scripts (WebAssembly#6581)

    The spec tests use an extension of the standard text format that includes
    various commands and assertions used to test WebAssembly implementations. Add a
    utility to parse this extended WebAssembly script format and use it in
    wasm-shell to check that it parses our spec tests without error. Fix a few
    errors the new parser found in our spec tests.
    
    A future PR will rewrite wasm-shell to interpret the results of the new parser,
    but for now to keep the diff smaller, do not do anything with the new parser
    except check for errors.
    tlively authored May 13, 2024
    Configuration menu
    Copy the full SHA
    924533f View commit details
    Browse the repository at this point in the history

Commits on May 14, 2024

  1. Simplify scratch local calculation (WebAssembly#6583)

    Change `countScratchLocals` to return the count and type of necessary scratch
    locals. It used to encode them as keys in the global map from scratch local
    types to local indices, which could not handle having more than one scratch
    local of a given type and was generally harder to reason about due to its use of
    global state. Take the opportunity to avoid emitting unnecessary scratch locals
    for `TupleExtract` expressions that will be optimized to not use them.
    
    Also simplify and better document the calculation of the mapping from IR indices
    to binary indices for all locals, scratch and non-scratch.
    tlively authored May 14, 2024
    Configuration menu
    Copy the full SHA
    020d08e View commit details
    Browse the repository at this point in the history
  2. LocalCSE: Check effects/generativity early (WebAssembly#6587)

    Previously we checked late, and as a result might end up failing to optimize when
    a sub-pattern could have worked. E.g.
    
    (call
      (A)
    )
    (call
      (A)
    )
    
    The call cannot be optimized, but the A pattern repeats. Before this PR we'd
    greedily focus on the entire call and then fail. After this PR we skip the call
    before we commit to which patterns to try to optimize, so we succeed.
    
    Add a isShallowlyGenerative helper here as we compute this step by step as
    we go. Also remove a parameter to the generativity code (it did not use the
    features it was passed).
    kripken authored May 14, 2024
    Configuration menu
    Copy the full SHA
    4ca05f7 View commit details
    Browse the repository at this point in the history
  3. LocalCSE: Ignore traps of code in between (WebAssembly#6588)

    Given:
    
    (ORIGINAL)
    (in between)
    (COPY)
    
    We want to change that to
    
    (local.tee $temp (ORIGINAL))
    (in between)
    (local.get $temp)
    
    It is fine if "in between" traps: then we never reach the new local.get. This is a safer
    situation than most optimizations because we are not reordering anything, only
    replacing known-equivalent code.
    kripken authored May 14, 2024
    Configuration menu
    Copy the full SHA
    76a2c64 View commit details
    Browse the repository at this point in the history
  4. [NFC] Add printing for EffectAnalyzer (WebAssembly#6586)

    With this you can do std::cout << effects and get something like
    
    EffectAnalyzer {
      writesMemory
      hasSideEffects
    }
    kripken authored May 14, 2024
    Configuration menu
    Copy the full SHA
    55f33b5 View commit details
    Browse the repository at this point in the history
  5. Source maps: Allow specifying that an expression has no debug info in…

    … text (WebAssembly#6520)
    
    ;;@
    
    with nothing else (no source:line) can be used to specify that the following
    expression does not have any debug info associated to it. This can be used
    to stop the automatic propagation of debug info in the text parsers.
    
    The text printer has also been updated to output this comment when needed.
    vouillon authored May 14, 2024
    Configuration menu
    Copy the full SHA
    140386e View commit details
    Browse the repository at this point in the history

Commits on May 15, 2024

  1. Remove redundant ptrType from MemorySize/Grow instructions. NFC (WebA…

    …ssembly#6590)
    
    I recently add TableSize/Grow and noticed I didn't need these.  It seems
    they are superfluous.
    sbc100 authored May 15, 2024
    Configuration menu
    Copy the full SHA
    940f457 View commit details
    Browse the repository at this point in the history
  2. LocalCSE: Fix regression from WebAssembly#6587 by accumulating genera…

    …tivity (WebAssembly#6591)
    
    WebAssembly#6587 was incorrect: It checked generativity early in an incremental manner, but
    it did not accumulate that information as we do with hashes. As a result we
    could end up optimizing something with a generative child, and sadly we lacked
    testing for that case.
    
    This adds incremental generativity computation alongside hashes. It also splits
    out this check from isRelevant.
    
    Also add a test for nested effects (as opposed to generativity), but that already
    worked before this PR (as we compute effects and invalidation as we go, already).
    kripken authored May 15, 2024
    Configuration menu
    Copy the full SHA
    8a5dc18 View commit details
    Browse the repository at this point in the history
  3. [Strings] Remove stringview types and instructions (WebAssembly#6579)

    The stringview types from the stringref proposal have three irregularities that
    break common invariants and require pervasive special casing to handle properly:
    they are supertypes of `none` but not subtypes of `any`, they cannot be the
    targets of casts, and they cannot be used to construct nullable references. At
    the same time, the stringref proposal has been superseded by the imported
    strings proposal, which does not have these irregularities. The cost of
    maintaing and improving our support for stringview types is no longer worth the
    benefit of supporting them.
    
    Simplify the code base by entirely removing the stringview types and related
    instructions that do not have analogues in the imported strings proposal and do
    not make sense in the absense of stringviews.
    
    Three remaining instructions, `stringview_wtf16.get_codeunit`,
    `stringview_wtf16.slice`, and `stringview_wtf16.length` take stringview operands
    in the stringref proposal but cannot be removed because they lower to operations
    from the imported strings proposal. These instructions are changed to take
    stringref operands in Binaryen IR, and to allow a graceful upgrade path for
    users of these instructions, the text and binary parsers still accept but ignore
    `string.as_wtf16`, which is the instruction used to convert stringrefs to
    stringviews. The binary writer emits code sequences that use scratch locals and `string.as_wtf16` to keep the output valid.
    
    Future PRs will further align binaryen with the imported strings proposal
    instead of the stringref proposal, for example by making `string` a subtype of
    `extern` instead of a subtype of `any` and by removing additional instructions
    that do not have analogues in the imported strings proposal.
    tlively authored May 15, 2024
    Configuration menu
    Copy the full SHA
    ef4b57c View commit details
    Browse the repository at this point in the history
  4. [Strings] Remove operations not included in imported strings (WebAsse…

    …mbly#6589)
    
    The stringref proposal has been superseded by the imported JS strings proposal,
    but the former has many more operations than the latter. To reduce complexity,
    remove all operations that are part of stringref but not part of imported
    strings.
    tlively authored May 15, 2024
    Configuration menu
    Copy the full SHA
    6b43a5e View commit details
    Browse the repository at this point in the history
  5. Debug location parser: accept arbitrary paths (WebAssembly#6594)

    The whole annotation was parsed as a keyword, which prevented file paths with non-ascii characters or paths starting with `/` or `.`.
    
    Also, there was a typo: one was comparing `fileSize` rather than `lineSize` to `contents->npos`.
    vouillon authored May 15, 2024
    Configuration menu
    Copy the full SHA
    b70d8df View commit details
    Browse the repository at this point in the history
  6. [EH] Rename option/pass names for new EH (exnref) (WebAssembly#6592)

    We settled on the name `WASM_EXNREF` for the new setting in Emscripten
    for the name for the new EH option.
    https://github.com/emscripten-core/emscripten/blob/2bc5e3156f07e603bc4f3580cf84c038ea99b2df/src/settings.js#L782-L786
    "New EH" sounds vague and I'm not sure if "experimental" is really
    necessary anyway, given that the potential users of this option is aware
    that this is a new spec that has been adopted recently.
    
    To make the option names consistent, this renames `--translate-to-eh`
    (the option that only runs the translator) to `--translate-to-exnref`,
    and `--experimental-new-eh` to `--emit-exnref` (the option that runs the
    translator at the end of the whole pipeline), and renames the pass and
    variable names in the code accordingly as well.
    
    In case anyone is using the old option names (and also to make the
    Chromium CI pass), this does not delete the old options.
    aheejin authored May 15, 2024
    Configuration menu
    Copy the full SHA
    ae94994 View commit details
    Browse the repository at this point in the history
  7. OptimizeInstructions: Add missing invalidation check in consecutive e…

    …quality test (WebAssembly#6596)
    
    This existed before WebAssembly#6495 but became noticeable there. We only looked at
    the fallthrough values in the later part of areConsecutiveInputsEqual, but
    there can be invalidation due to the non-fallthrough part:
    
    (i32.add
      (local.get $x)
      (block
        (local.set $x ..)
        (local.get $x)
      )
    )
    
    The set can cause the local.get to differ the second time. To fix this,
    check if the non-fallthrough part invalidates the fallthrough (but only
    on the right hand side).
    
    Fixes WebAssembly#6593
    kripken authored May 15, 2024
    Configuration menu
    Copy the full SHA
    2cc5e06 View commit details
    Browse the repository at this point in the history
  8. Add table64 lowering pass (WebAssembly#6595)

    Changes to wasm-validator.cpp here are mostly for consistency between
    elem and data segment validation.
    sbc100 authored May 15, 2024
    Configuration menu
    Copy the full SHA
    2b60f8a View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    268feb9 View commit details
    Browse the repository at this point in the history

Commits on May 16, 2024

  1. Fix binary emitting of br_if with a refined value by emitting a cast (W…

    …ebAssembly#6510)
    
    This makes us compliant with the wasm spec by adding a cast: we use the refined
    type for br_if fallthrough values, and the wasm spec uses the branch target. If the
    two differ, we add a cast after the br_if to make things match.
    
    Alternatively we could match the wasm spec's typing in our IR, but we hope the wasm
    spec will improve here, and so this is will only be temporary in that case. Even if not,
    this is useful because by using the most refined type in the IR we optimize in the best
    way possible, and only suffer when we emit fixups in the binary, but in practice those
    cases are very rare: br_if is almost always dropped rather than used, in real-world
    code (except for fuzz cases and exploits).
    
    We check carefully when a br_if value is actually used (and not dropped) and its type
    actually differs, and it does not already have a cast. The last condition ensures that
    we do not keep adding casts over repeated roundtripping.
    kripken authored May 16, 2024
    Configuration menu
    Copy the full SHA
    e5f2edf View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    85f677a View commit details
    Browse the repository at this point in the history
  3. [Table64Lowering] Don't assume that all segments are from 64-bit tabl…

    …es (WebAssembly#6599)
    
    This allows modules to contains both 32-bit and 64-bit segment.
    
    In order to check the table/memory state when visiting segments we need
    to ensure that memories/tables are visited only after their segments.
    
    The comments in visitTable/visitMemory already assumed this but it
    wasn't true in practice.
    sbc100 authored May 16, 2024
    Configuration menu
    Copy the full SHA
    fab6649 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    669bc06 View commit details
    Browse the repository at this point in the history

Commits on May 17, 2024

  1. [cmake] Remove redundant binaryen_emscripten_SOURCES (WebAssembly#6602

    )
    
    This list is identical to `binaryen_SOURCES` above.
    sbc100 authored May 17, 2024
    Configuration menu
    Copy the full SHA
    f4a83dd View commit details
    Browse the repository at this point in the history
  2. Fix GlobalRefining's handling of gets in module code and add missing …

    …validation (WebAssembly#6603)
    
    GlobalRefining did not traverse module code, so it did not update global.gets
    in other globals.
    
    Add missing validation that actually errors on that: We did not check global.get
    types.
    
    These could be separate PRs but it would be difficult to test them separately.
    kripken authored May 17, 2024
    Configuration menu
    Copy the full SHA
    4e9f495 View commit details
    Browse the repository at this point in the history

Commits on May 18, 2024

  1. Configuration menu
    Copy the full SHA
    369cddf View commit details
    Browse the repository at this point in the history
  2. Rewrite wasm-shell to use new wast parser (WebAssembly#6601)

    Use the new wast parser to parse a full script up front, then traverse the
    parsed script data structure and execute the commands. wasm-shell had previously
    used the new wat parser for top-level modules, but it now uses the new parser
    for module assertions as well. Fix various bugs this uncovered.
    
    After this change, wasm-shell supports all the assertions used in the upstream
    spec tests (although not new kinds of assertions introduced in any proposals).
    Uncomment various `assert_exhaustion` tests that we can now execute.
    
    Other kinds of assertions remain commented out in our tests: wasm-shell now
    supports `assert_unlinkable`, but the interpreter does not eagerly check for the
    existence of imports, so those tests do not pass. Tests that check for NaNs also
    remain commented out because they do not yet use the standard syntax that
    wasm-shell now supports for canonical and arithmetic NaN results, and our
    interpreter would not pass all of those tests even if they did use the standard
    syntax.
    tlively authored May 18, 2024
    Configuration menu
    Copy the full SHA
    921644c View commit details
    Browse the repository at this point in the history

Commits on May 20, 2024

  1. Configuration menu
    Copy the full SHA
    5d64afa View commit details
    Browse the repository at this point in the history
  2. SimplifyGlobals: Do not switch a get to use a global of another type (W…

    …ebAssembly#6605)
    
    If we wanted to switch types in such cases we'd need to refinalize (which is likely
    worth doing, though other passes should refine globals anyhow).
    kripken authored May 20, 2024
    Configuration menu
    Copy the full SHA
    3e33605 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    5999c99 View commit details
    Browse the repository at this point in the history

Commits on May 21, 2024

  1. Fuzzer: Better fuzzing of globals (WebAssembly#6611)

    With this PR we generate global.gets in globals, which we did not do before.
    We do that by replacing makeConst (the only thing we did before, for the
    contents of globals) with makeTrivial, and add code to makeTrivial to sometimes
    make a global.get. When no suitable global exists, makeGlobalGet will emit a
    constant, so there is no danger in trying.
    
    Also raise the number of globals a little.
    
    Also explicitly note the current limitation of requiring all tuple globals to contain
    tuple.make and nothing else, including not global.get, and avoid adding such
    invalid global.gets in tuple globals in the fuzzer.
    kripken authored May 21, 2024
    Configuration menu
    Copy the full SHA
    326bfcd View commit details
    Browse the repository at this point in the history
  2. Fix TableFill bounds checking (WebAssembly#6621)

    The offsets are unsigned.
    kripken authored May 21, 2024
    Configuration menu
    Copy the full SHA
    772e572 View commit details
    Browse the repository at this point in the history

Commits on May 22, 2024

  1. Configuration menu
    Copy the full SHA
    06cbe01 View commit details
    Browse the repository at this point in the history

Commits on May 23, 2024

  1. Fix fuzzer generation of a DataSegment + add validation that would ha…

    …ve caught it (WebAssembly#6626)
    
    The DataSegment was manually added to .dataSegments, but we need to add it
    using addDataSegment so the maps are updated and getDataSegment(name)
    works.
    
    Also add validation that would have caught this earlier: check that each item in
    the item lists can be fetched by name.
    kripken authored May 23, 2024
    Configuration menu
    Copy the full SHA
    9b61eb3 View commit details
    Browse the repository at this point in the history

Commits on May 28, 2024

  1. Configuration menu
    Copy the full SHA
    f9ce00b View commit details
    Browse the repository at this point in the history
  2. [EH] Rename old EH tests from -old to -legacy (WebAssembly#6627)

    This renames old EH tests in the form of `-eh-old.wast` to
    `-eh-legacy.wast`, to be clearer in names.
    aheejin authored May 28, 2024
    Configuration menu
    Copy the full SHA
    13f3fd2 View commit details
    Browse the repository at this point in the history
  3. OptimizeInstructions: Push StructNew down to help it fold away Struct…

    …Sets (WebAssembly#6584)
    
    Heap stores (struct.set) are optimized into the struct.new when they are adjacent
    in a statement list.
    
    Pushing struct.new down past irrelevant instructions increases the likelihood that
    it ends up adjacent to sets.
    rluble authored May 28, 2024
    Configuration menu
    Copy the full SHA
    fc48efe View commit details
    Browse the repository at this point in the history

Commits on May 29, 2024

  1. Run RemoveUnneededModuleElements early (WebAssembly#6620)

    Doing it before anything else can help a lot if there is a significant amount of
    dead code that can be removed, as it saves work for all the later passes. We
    did run this pass if GC was enabled just a few passes later down, but even so
    it is worthwhile to run it an additional time, and it makes sense to do even
    without GC (though in typical optimized LLVM outputs there will be little
    dead code).
    
    If there is no dead code then this is wasted work, but this is a fairly fast pass,
    and I measure no significant slowdown due to this. E.g. on the 35 MB clang.wasm
    (which is already optimized, so little dead code) it takes around a second, while
    all of -O2 takes almost two minutes, so the difference is just 1%.
    
    On J2CL I measure a 15% speedup in -O3 --closed-world -tnh, and also the
    binary is 2.5% smaller, which means there is less work for later cycles of -O3.
    kripken authored May 29, 2024
    Configuration menu
    Copy the full SHA
    525f076 View commit details
    Browse the repository at this point in the history
  2. Use new wast parser in wasm2js (WebAssembly#6606)

    When generating assertions, traverse the `WASTScript` data structure rather than
    interleaving assertion parsing with emitting.
    tlively authored May 29, 2024
    Configuration menu
    Copy the full SHA
    f622b8e View commit details
    Browse the repository at this point in the history
  3. Remove obsolete parser code (WebAssembly#6607)

    Remove `SExpressionParser`, `SExpressionWasmBuilder`, and `cashew::Parser`.
    Simplify gen-s-parser.py. Remove the --new-wat-parser and
    --deprecated-wat-parser flags.
    tlively authored May 29, 2024
    Configuration menu
    Copy the full SHA
    d844d2e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    56fe062 View commit details
    Browse the repository at this point in the history
  5. SignaturePruning: Properly handle public types (WebAssembly#6630)

    The SignaturePruning pass optimizes away parameters that it proves are safe to
    remove. It turns out that that does not always match the definition of private
    types, which is more restrictive. Specifically, if say all the types are in one big
    rec group and one of them is used on an exported function then all of them are
    considered public (as the rec group is). However, in closed world, it would be ok
    to leave that rec group unchanged but to create a pruned version of that type
    and use it, in cases where we see it is safe to remove a parameter. (See the
    testcase for a concrete example.)
    
    To put it another way, SignaturePruning already proves that a parameter is
    safe to remove in all the ways that matter. Before this PR, however, the testcase
    in this PR would error - so this PR is not an optimization but a bugfix, really -
    because SignaturePruning would see that a parameter is safe to remove but
    then TypeUpdating would see the type is public and so it would leave it alone,
    leading to a broken module.
    
    This situation is in fact not that rare, and happens on real-world Java code.
    The reason we did not notice it before is that typically there are no remaining
    SignaturePruning opportunities late in the process (when other closed world
    optimizations have typically led to a single big rec group).
    
    The concrete fix here is to add additionalPrivateTypes to a few more places
    in TypeUpdating. We already supported that for cases where a pass knew
    better than the general logic what can be modified, and this adds that
    ability to the signature-rewriting logic there. Then SignaturePruning can
    send in all the types it has proven are safe to modify.
    
     *  Also necessary here is to only add from additionalPrivateTypes if the type
        is not already in our list (or we'd end up with duplicates in the final rec
        group).
    *   Also move newSignatures in SignaturePruning out of the top level, which
        was confusing (the pass has multiple iterations, and we want each to have
        a fresh instance).
    kripken authored May 29, 2024
    Configuration menu
    Copy the full SHA
    b85197c View commit details
    Browse the repository at this point in the history
  6. Fix Vacuuming of code leading up to an infinite loop (WebAssembly#6632)

    We had that logic right in other places, but the specific part of Vacuum that
    looks at code that leads up to an unreachable did not check for infinite loops,
    so it could remove them.
    kripken authored May 29, 2024
    Configuration menu
    Copy the full SHA
    5d90167 View commit details
    Browse the repository at this point in the history

Commits on May 30, 2024

  1. Configuration menu
    Copy the full SHA
    0148db0 View commit details
    Browse the repository at this point in the history
  2. Avoid duplicate type names (WebAssembly#6633)

    If we replace a type with another, use the original name for the new type,
    and give the old a unique name (for the rare cases in which it has uses).
    kripken authored May 30, 2024
    Configuration menu
    Copy the full SHA
    18bb1f5 View commit details
    Browse the repository at this point in the history

Commits on May 31, 2024

  1. LogExecution: Optionally take a module name for the logger function (W…

    …ebAssembly#6629)
    
    --log-execution=NAME will use NAME as the module for the logger
    function import, rather than infer it.
    
    If the name is not provided (--log-execution as before this PR) then we
    will try to automatically decide which to use ("env", unless we see
    another module name is used, which can be the case in optimized
    modules).
    yamt authored May 31, 2024
    Configuration menu
    Copy the full SHA
    0c23394 View commit details
    Browse the repository at this point in the history
  2. Optimize ReorderGlobals ordering with a new algorithm (WebAssembly#6625)

    The old ordering in that pass did a topological sort while sorting by uses
    both within topological groups and between them. That could be unoptimal
    in some cases, however, and actually on J2CL output this pass made the
    binary larger, which is how we noticed this.
    
    The problem is that such a toplogical sort keeps topological groups in
    place, but it can be useful to interleave them sometimes. Imagine this:
    
         $c - $a
        /
      $e
        \
         $d - $b
    
    Here $e depends on $c, etc. The optimal order may interleave the two
    arms here, e.g. $a, $b, $d, $c, $e. That is because the dependencies define
    a partial order, and so the arms here are actually independent.
    
    Sorting by toplogical depth first might help in some cases, but also is not
    optimal in general, as we may want to mix toplogical depths:
    $a, $c, $b, $d, $e does so, and it may be the best ordering.
    
    This PR implements a natural greedy algorithm that picks the global with
    the highest use count at each step, out of the set of possible globals, which
    is the set of globals that have no unresolved dependencies. So we start by
    picking the first global with no dependencies and add at at the front; then
    that unlocks anything that depended on it and we pick from that set, and
    so forth.
    
    This may also not be optimal, but it is easy to make it more flexible by
    customizing the counts, and we consider 4 sorts here:
    
    *   Set all counts to 0. This means we only take into account dependencies,
        and we break ties by the original order, so this is as close to the original
        order as we can be.
    *   Use the actual use counts. This is the simple greedy algorithm.
    *   Set the count of each global to also contain the counts of its children,
        so the count is the total that might be unlocked. This gives more weight
        to globals that can unlock more later, so it is less greedy.
    *   As last, but weight children's counts lower in an exponential way, which
        makes sense as they may depend on other globals too.
    
    In practice it is simple to generate cases where 1, 2, or 3 is optimal (see
    new tests), but on real-world J2CL I see that 4 (with a particular exponential
    coefficient) is best, so the pass computes all 4 and picks the best. As a
    result it will never worsen the size and it has a good chance of
    improving.
    
    The differences between these are small, so in theory we could pick any
    of them, but given they are all modifications of a single algorithm it is
    very easy to compute them all with little code complexity.
    
    The benefits are rather small here, but this can save a few hundred
    bytes on a multi-MB Java file. This comes at a tiny compile time cost, but
    seems worth it for the new guarantee to never regress size.
    kripken authored May 31, 2024
    Configuration menu
    Copy the full SHA
    f8086ad View commit details
    Browse the repository at this point in the history
  3. Make Emscripten CMake build more configurable (WebAssembly#6638)

    This makes several changes to make the Emscripten build more configurable and
    convenient for testing:
    
    1) Remove ERROR_ON_WASM_CHANGES_AFTER_LINK from ENABLE_BIGINT: this makes the
    setting composable with optimized builds
    2) Add EMSCRIPTEN_ENABLE_MEMORY64 to build with the memory64 option
    3) Add EMSCRIPTEN_ENABLE_SINGLE_FILE to allow disabling the single-file build
    (to make it easier to analyze binary output)
    dschuff authored May 31, 2024
    Configuration menu
    Copy the full SHA
    1f2cd4f View commit details
    Browse the repository at this point in the history

Commits on Jun 3, 2024

  1. Fix binary parser of declarative element segments (WebAssembly#6618)

    The parser was incorrectly handling the parsing of declarative element segments whose `init` is a `vec(expr)`.
    https://webassembly.github.io/spec/core/binary/modules.html#element-section
    Binry parser was simply reading a single `u32LEB` value for `init`
    instead of parsing a expression regardless `usesExpressions = true`.
    
    This commit updates the `WasmBinaryReader::readElementSegments` function
    to correctly parse the expressions for declarative element segments by
    calling `readExpression` instead of `getU32LEB` when `usesExpressions = true`.
    
    Resolves the parsing exception:
    "[parse exception: bad section size, started at ... not being equal to new position ...]"
    
    Related discussion: tanishiking/scala-wasm#136
    tanishiking authored Jun 3, 2024
    Configuration menu
    Copy the full SHA
    9347a22 View commit details
    Browse the repository at this point in the history
  2. Effects: Add missing combining logic for MayNotReturn (WebAssembly#6635)

    Without that logic we could end up dropping that particular effect. This actually
    made a test pass when it should not: the modified test here has a function with
    effects that are ok to remove, but it had a loop which adds MayNotReturn which
    we should actually not remove, so it was removed erroneously.
    
    To fix the test, add other effects there (local ones) that we can see are removable.
    Also add a function with a loop to test that we do not remove an infinite loop,
    which adds coverage for the fix here.
    kripken authored Jun 3, 2024
    Configuration menu
    Copy the full SHA
    ea4d9e4 View commit details
    Browse the repository at this point in the history

Commits on Jun 5, 2024

  1. Fix stack-use-after-scope on Windows in Precompute (WebAssembly#6643)

    Create a temp var to store the ChildIterator.
    
    Fixes WebAssembly#6639
    mtb0x1 authored Jun 5, 2024
    Configuration menu
    Copy the full SHA
    76d1ac3 View commit details
    Browse the repository at this point in the history

Commits on Jun 10, 2024

  1. wasm2js: Add basic reference operations (WebAssembly#6648)

    This adds ref.eq, ref.null, ref.is_null, ref.func.
    kripken authored Jun 10, 2024
    Configuration menu
    Copy the full SHA
    0a1a59a View commit details
    Browse the repository at this point in the history
  2. [Strings] Keep public and private types separate in StringLowering (W…

    …ebAssembly#6642)
    
    We need StringLowering to modify even public types, as it must replace every
    single stringref with externref, even if that modifies the ABI. To achieve that
    we told it that all string-using types were private, which let TypeUpdater update
    them, but the problem is that it moves all private types to a new single
    rec group, which meant public and private types ended up in the same group.
    As a result, a single public type would make it all public, preventing optimizations
    and breaking things as in WebAssembly#6630 WebAssembly#6640.
    
    Ideally TypeUpdater would modify public types while keeping them in the same
    rec groups, but this may be a very specific issue for StringLowering, and that
    might be a lot of work. Instead, just make StringLowering handle public types of
    functions in a manual way, which is simple and should handle all cases that
    matter in practice, at least in J2Wasm.
    kripken authored Jun 10, 2024
    Configuration menu
    Copy the full SHA
    3d0e687 View commit details
    Browse the repository at this point in the history

Commits on Jun 11, 2024

  1. Fix scratch local optimizations when emitting string slice (WebAssemb…

    …ly#6649)
    
    The binary writing of `stringview_wtf16.slice` requires scratch locals to store
    the `start` and `end` operands while the string operand is converted to a
    stringview. To avoid unbounded binary bloat when round-tripping, we detect the
    case that `start` and `end` are already `local.get`s and avoid using scratch
    locals by deferring the binary writing of the `local.get` operands until after
    the stringview conversoins is emitted.
    
    We previously optimized the scratch locals for `start` and `end` independently,
    but this could produce incorrect code in the case where the `local.get` for
    `start` is deferred but its value is changed by a `local.set` in the code for
    `end`. Fix the problem by only optimizing to avoid scratch locals in the case
    where both `start` and `end` are already `local.get`s, so they will still be
    emitted in the original relative order and they cannot interfere with each other
    anyway.
    tlively authored Jun 11, 2024
    Configuration menu
    Copy the full SHA
    cdd94a0 View commit details
    Browse the repository at this point in the history
  2. wasm2js: Add Table operations (WebAssembly#6650)

    TableGet, Set, Size, Grow, Fill, Copy.
    
    Also move "null" into shared-constants, to make the code
    more consistent overall.
    kripken authored Jun 11, 2024
    Configuration menu
    Copy the full SHA
    2dcf670 View commit details
    Browse the repository at this point in the history
  3. Fix wasm-split bug in absence of active element segments (WebAssembly…

    …#6651)
    
    The module splitting code incorrectly assumed that there would be at least one
    active element segment and failed to initialize the table slot manager with a
    function table if that was not the case. Fix the bug by setting the table even
    when there are no active segments and add a test.
    
    Fixes WebAssembly#6572 and WebAssembly#6637.
    tlively authored Jun 11, 2024
    Configuration menu
    Copy the full SHA
    425ecc6 View commit details
    Browse the repository at this point in the history

Commits on Jun 12, 2024

  1. [Parser][NFC] Split parser into multiple compilation units (WebAssemb…

    …ly#6653)
    
    Because the parser has five stages, it requires instantiating all of the
    templates in parsers.h with up to five different contexts. Instantiating all
    those templates in a single compilation unit takes a long time. On my machine, a
    release build of wat-parser.cpp.o took 32 seconds. To reduce the time of
    incremental rebuilds on machines with many cores, split the code across several
    compilation units so that the templates need to be instantiated for just a
    single context in each unit. On my machine the longest compilation time after
    this splitting is 17 seconds. The time for a full release build also drops from
    42 seconds to 33 seconds. On machines with fewer cores, the benefit may be
    smaller or even negative, though.
    tlively authored Jun 12, 2024
    Configuration menu
    Copy the full SHA
    475841d View commit details
    Browse the repository at this point in the history
  2. [DebugInfo] Copy debug info in call-utils.h (WebAssembly#6652)

    We automatically copy debuginfo in replaceCurrent(), but there are a few
    places that do other operations than simple replacements. call-utils.h will
    turn a call_ref with a select target into two direct calls, and we were missing
    the logic to copy debuginfo from the call_ref to the calls.
    
    To make this work, refactor out the copying logic from wasm-traversal, into
    debuginfo.h, and use it in call-utils.h.
    
    debuginfo.h itself is renamed from debug.h (as now this needs to be included
    from wasm-traversal, which nearly everything does, and it turns out some files
    have internal stuff like a debug() helper that ends up conflicing with the old
    debug namespace).
    
    Also rename the old copyDebugInfo function to copyDebugInfoBetweenFunctions
    which is more explicit. That is also moved from the header to a cpp file because
    it depends on wasm-traversal (so we'd end up with recursive headers otherwise).
    That is fine, as that method is called after copying a function, which is not that
    frequent. The new copyDebugInfoToReplacement (which was refactored out of
    wasm-traversal) is in the header because it can be called very frequently (every
    single instruction we optimize) and we want it to get inlined.
    kripken authored Jun 12, 2024
    Configuration menu
    Copy the full SHA
    ac21c8c View commit details
    Browse the repository at this point in the history
  3. [threads] Parse, build, and print shared composite types (WebAssembly…

    …#6654)
    
    Parse the text format for shared composite types as described in the
    shared-everything thread proposal. Update the parser to use 'comptype' instead
    of 'strtype' to match the final GC spec and add the new syntactic class
    'sharecomptype'.
    
    Update the type canonicalization logic to take sharedness into account to avoid
    merging shared and unshared types. Make the same change in the TypeMerging pass.
    Ensure that shared and unshared types cannot be in a subtype relationship with
    each other.
    
    Follow-up PRs will add shared abstract heap types, binary parsing and emitting
    for shared types, and fuzzer support for shared types.
    tlively authored Jun 12, 2024
    Configuration menu
    Copy the full SHA
    0e11876 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    3468619 View commit details
    Browse the repository at this point in the history

Commits on Jun 13, 2024

  1. Add local.set/tee local type annotations to BINARYEN_PRINT_FULL (WebA…

    …ssembly#6657)
    
    With this we now print e.g.
    
    (local.set $temp (; local type: i32 ;)
      ...
    
    This can be nice in large functions to avoid needing to scroll up to
    see the local type, e.g. when debugging why unsubtyping doesn't
    work somewhere.
    
    Also avoid [ ] in this mode, in favor of the standard (; ;), and put those
    at the end rather than at the start.
    kripken authored Jun 13, 2024
    Configuration menu
    Copy the full SHA
    66610d8 View commit details
    Browse the repository at this point in the history
  2. wasm2js: Generalize global initializer code to use the main codegen l…

    …ogic (WebAssembly#6659)
    
    This avoids special-casing particular global init forms. After this we should
    support everything in global inits that we support anywhere else.
    kripken authored Jun 13, 2024
    Configuration menu
    Copy the full SHA
    000fa2a View commit details
    Browse the repository at this point in the history

Commits on Jun 14, 2024

  1. [threads] Add a "shared-everything" feature (WebAssembly#6658)

    Add the feature and flags to enable and disable it. Require the new feature to
    be enabled for shared heap types to validate. To make the test work, update the
    validator to actually check features for global types.
    tlively authored Jun 14, 2024
    Configuration menu
    Copy the full SHA
    0fa99fb View commit details
    Browse the repository at this point in the history
  2. [NFC] Add constexpr HeapTypes for basic heap types (WebAssembly#6662)

    Since the BasicHeapTypes are in an enum, calling HeapType methods on them
    requires something like `HeapType(HeapType::func).someMethod()`. This is
    unnecessarily verbose, so add a new `HeapTypes` namespace that contains
    constexpr HeapType globals that can be used instead, shorting this to
    `HeapTypes::func.someMethod()`.
    tlively authored Jun 14, 2024
    Configuration menu
    Copy the full SHA
    027128d View commit details
    Browse the repository at this point in the history
  3. [Parser][NFC] Make typeidx and maybeTypeidx return consistent types (W…

    …ebAssembly#6663)
    
    Since the BasicHeapTypes are in an enum, calling HeapType methods on them
    requires something like `HeapType(HeapType::func).someMethod()`. This is
    unnecessarily verbose, so add a new `HeapTypes` namespace that contains
    constexpr HeapType globals that can be used instead, shorting this to
    `HeapTypes::func.someMethod()`.
    tlively authored Jun 14, 2024
    Configuration menu
    Copy the full SHA
    eacea80 View commit details
    Browse the repository at this point in the history
  4. [threads] Binary reading and writing of shared composite types (WebAs…

    …sembly#6664)
    
    Also update the parser so that implicit type uses are not matched with shared
    function types.
    tlively authored Jun 14, 2024
    Configuration menu
    Copy the full SHA
    881fe6a View commit details
    Browse the repository at this point in the history
  5. [Parser] Update requirements for implicit type uses (WebAssembly#6665)

    As an abbreviation, a `typeuse` can be given as just a list of parameters and
    results, in which case it corresponds to the index of the first function type
    with the same parameters and results. That function type must also be an MVP
    function type, i.e. it cannot have a nontrivial rec group, be non-final, or have
    a declared supertype. The parser did not previously implement all of these rules.
    tlively authored Jun 14, 2024
    Configuration menu
    Copy the full SHA
    2c758c5 View commit details
    Browse the repository at this point in the history
  6. [Parser] Fix error message on required reftype (WebAssembly#6666)

    Not all uses of the `reftype` parser handled the fact that it returned a
    `MaybeResult`. Change its name to `maybeReftype`, add a new `reftype`
    parser
    that returns an error if there is no reftype, and update all the use
    sites.
    
    Fixes WebAssembly#6655.
    tlively authored Jun 14, 2024
    Configuration menu
    Copy the full SHA
    cf2725b View commit details
    Browse the repository at this point in the history

Commits on Jun 17, 2024

  1. Enable more spec tests (WebAssembly#6669)

    Re-triage all the disabled spec tests and re-enable many of them.
    Improve the module splitting logic to correctly handle (by skipping)
    quoted modules and their associated assertions.
    tlively authored Jun 17, 2024
    Configuration menu
    Copy the full SHA
    d849a43 View commit details
    Browse the repository at this point in the history
  2. wasm2js: Support arbitrary temp variable types (WebAssembly#6661)

    Previously only basic types were allowed.
    
    Generalizing this to arbitrary types means we use a map instead of a vector,
    which is slower, but I can't measure any noticeable difference. Temp vars are
    pretty rare, and there are just much slower parts of wasm2js, I think.
    kripken authored Jun 17, 2024
    Configuration menu
    Copy the full SHA
    1dd0520 View commit details
    Browse the repository at this point in the history
  3. Fix DataSegment name handling (WebAssembly#6673)

    The code used i instead of index, as in this pseudocode:
    
    for i in range(num_names):
      index = readU32LEB() # index of the data segment to name
      name = readName()    # name to give that segment
      data[i] = name       # XXX 'i' should be 'index'
    
    That (funnily enough) happened to always work before since we write names in
    order. That is, normally given segments A,B,C we'd write then in the names section
    as A,B,C. Then the reader, which had the bug, would always have i and index
    identical in value anyhow. But if a wasm producer used different indexes, a
    problem could happen.
    
    To test this, add a binary file that has a reversed name section.
    
    Fixes WebAssembly#6672
    kripken authored Jun 17, 2024
    Configuration menu
    Copy the full SHA
    b377b6f View commit details
    Browse the repository at this point in the history
  4. GlobalStructInference: Optimize globals too (WebAssembly#6674)

    This is achieved by simply replacing the Literal with PossibleConstantValues, which
    supports both Literals and Globals.
    kripken authored Jun 17, 2024
    Configuration menu
    Copy the full SHA
    0f9f2dc View commit details
    Browse the repository at this point in the history

Commits on Jun 18, 2024

  1. Reject invalid section IDs (WebAssembly#6675)

    Rather than treating them as custom sections. Also fix UB where invalid
    `Section` enum values could be used as keys in a map. Use the raw `uint8_t`
    section IDs as keys instead. Re-enable a disabled spec test that was failing
    because of this bug and UB.
    tlively authored Jun 18, 2024
    Configuration menu
    Copy the full SHA
    c3b9cde View commit details
    Browse the repository at this point in the history
  2. fix(WebAssembly#6671): fix possible stack buffer overflow in gen-s-pa…

    …rser.inc (WebAssembly#6678)
    
    The stack buffer overflow is occurring because memcpy(buf, op.data(),
    op.size()); can write up to op.size() bytes into buf, but buf is only 33
    bytes long. If op.size() is greater than 33, this will result in a
    buffer overflow.
    mtb0x1 authored Jun 18, 2024
    Configuration menu
    Copy the full SHA
    408bc7f View commit details
    Browse the repository at this point in the history

Commits on Jun 19, 2024

  1. [Parser] Fix bug in unreachable fallback logic (WebAssembly#6676)

    When popping past an unreachable instruction would lead to popping from an empty
    stack or popping an incorrect type, we need to avoid popping and produce new
    Unreachable instructions instead to ensure we parse valid IR. The logic for
    this was flawed and made the synthetic Unreachable come before the popped
    unreachable child, which was not correct in the case that that popped
    unreachable was a branch or other non-trapping instruction. Fix and simplify the
    logic and re-enable the spec test that uncovered the bug.
    tlively authored Jun 19, 2024
    Configuration menu
    Copy the full SHA
    829e228 View commit details
    Browse the repository at this point in the history
  2. [threads] Shared basic heap types (WebAssembly#6667)

    Implement binary and text parsing and printing of shared basic heap types and
    incorporate them into the type hierarchy.
    
    To avoid the massive amount of code duplication that would be necessary if we
    were to add separate enum variants for each of the shared basic heap types, use
    bit 0 to indicate whether the type is shared and replace `getBasic()` with
    `getBasic(Unshared)`, which clears that bit. Update all the use sites to record
    whether the original type was shared and produce shared or unshared output
    without code duplication.
    tlively authored Jun 19, 2024
    Configuration menu
    Copy the full SHA
    2df678e View commit details
    Browse the repository at this point in the history
  3. Re-enable binary.wast spec test (WebAssembly#6677)

    Fix the wast parser to accept IDs on quoted modules, remove tests that are
    invalidated by the multimemory proposal, and add validation that the total
    number of variables in a function is less than 2^32 and that the code section is
    present if there is a non-empty function section.
    tlively authored Jun 19, 2024
    Configuration menu
    Copy the full SHA
    02c4c3c View commit details
    Browse the repository at this point in the history
  4. Check malformed mutability on imported globals (WebAssembly#6679)

    And re-enable the globals.wast spec test, which checks this.
    tlively authored Jun 19, 2024
    Configuration menu
    Copy the full SHA
    eceb0fb View commit details
    Browse the repository at this point in the history
  5. Fix validation of unused LEB128 bits (WebAssembly#6680)

    The unused bits must be a sign extension of the significant value, but we were
    previously only validating that unsigned LEBs had their unused bytes set to
    zero. Re-enable the spec test that checks for proper validation.
    tlively authored Jun 19, 2024
    Configuration menu
    Copy the full SHA
    3acacac View commit details
    Browse the repository at this point in the history
  6. Validate that names are valid UTF-8 (WebAssembly#6682)

    Add an `isUTF8` utility and use it in both the text and binary parsers.
    Add missing checks for overlong encodings and overlarge code points in
    our WTF8 reader, which the new utility uses. Re-enable the spec tests
    that test UTF-8 validation.
    tlively authored Jun 19, 2024
    Configuration menu
    Copy the full SHA
    765c614 View commit details
    Browse the repository at this point in the history

Commits on Jun 20, 2024

  1. [NFC] Add pragma to ignore maybe-uninitialized in strings.cpp (WebAss…

    …embly#6686)
    
    This will hopefully fix the build on the coverage builder.
    tlively authored Jun 20, 2024
    Configuration menu
    Copy the full SHA
    98da69f View commit details
    Browse the repository at this point in the history
  2. Validate memarg offsets (WebAssembly#6683)

    For 32-bit memories, the offset value must be in the u32 range. Update
    the address.wast spec test to assert that a module with an overlarge
    offset value is invalid rather than malformed.
    tlively authored Jun 20, 2024
    Configuration menu
    Copy the full SHA
    45f6bdd View commit details
    Browse the repository at this point in the history
  3. Re-enable spec tests requiring multivalue (WebAssembly#6684)

    And delete tests that no longer pass now that multivalue is standard.
    tlively authored Jun 20, 2024
    Configuration menu
    Copy the full SHA
    1079a9e View commit details
    Browse the repository at this point in the history
  4. GlobalStructInference: Un-nest struct.news in globals when that is he…

    …lpful (WebAssembly#6688)
    
    If we have
    
    (global $g (struct.new $S
      (i32.const 1)
      (struct.new $T ..)
      (ref.func $f)
    ))
    
    then before this PR if we wanted to read the middle field we'd stop, as it is non-constant.
    However, we can un-nest it, making it constant:
    
    (global $g.unnested (struct.new $T ..))
    (global $g (struct.new $S
      (i32.const 1)
      (global.get $g.unnested)
      (ref.func $f)
    ))
    
    Now the field is a global.get of an immutable global, which is constant. Using this
    technique we can handle anything in a struct field, constant or not. The cost of adding
    a global is likely offset by the benefit of being able to refer to it directly, as that opens
    up more opportunities later.
    
    Concretely, this replaces the constant values we look for in GSI with a variant over
    constants or expressions (we do still want to group constants, as multiple globals
    with the same constant field can be treated as a whole). And we note cases where we
    need to un-nest, and handle those at the end.
    kripken authored Jun 20, 2024
    Configuration menu
    Copy the full SHA
    c3089b3 View commit details
    Browse the repository at this point in the history

Commits on Jun 21, 2024

  1. wasm2js: Fix the names of temp vars with named reference types (WebAs…

    …sembly#6689)
    
    We were missing code to mangle such names for JS. Without that, the name
    of a temp var for the type `(ref $foo)` would end up with `(`, `)` in
    the name, which is not valid in JS.
    kripken authored Jun 21, 2024
    Configuration menu
    Copy the full SHA
    0262515 View commit details
    Browse the repository at this point in the history
  2. Add TraceCalls pass (WebAssembly#6619)

    This pass receives a list of functions to trace, and then wraps them in calls to
    imports. This can be useful for tracing malloc/free calls, for example, but is
    generic.
    
    Fixes WebAssembly#6548
    loganek authored Jun 21, 2024
    Configuration menu
    Copy the full SHA
    a27d952 View commit details
    Browse the repository at this point in the history

Commits on Jun 24, 2024

  1. Add a proper error for bad select results (WebAssembly#6697)

    The result cannot be `none` or `unreachable` etc.
    
    Fixes WebAssembly#6694
    kripken authored Jun 24, 2024
    Configuration menu
    Copy the full SHA
    ed35193 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    78b3c40 View commit details
    Browse the repository at this point in the history

Commits on Jun 25, 2024

  1. [NFC] Remove a minor compile-time optimization in Heap2Local (WebAsse…

    …mbly#6699)
    
    We tracked which expressions we saw an allocated struct/array reach, and then
    quickly exited when another one did (as when two allocations mix, we can
    optimize neither). It turns out that this helps very little in actual measurements
    (looks like within noise - likely we are ruling out the un-optimizable cases early
    otherwise anyhow). Also the complexity it adds is a problem for an improvement
    I want to make to the pass, so remove it.
    kripken authored Jun 25, 2024
    Configuration menu
    Copy the full SHA
    4e07d86 View commit details
    Browse the repository at this point in the history
  2. Add a missing binary reading check for BrOn's reference child's type (W…

    …ebAssembly#6700)
    
    That child must be a reference, as `finalize()` assumes so. To avoid an
    assertion, error early.
    
    Fixes WebAssembly#6696
    kripken authored Jun 25, 2024
    Configuration menu
    Copy the full SHA
    a9f6bc0 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0a0ee6f View commit details
    Browse the repository at this point in the history
  4. [threads] Validate shared-to-unshared edges in heap types (WebAssembl…

    …y#6698)
    
    Add spec tests checking validation for structs and arrays.
    tlively authored Jun 25, 2024
    Configuration menu
    Copy the full SHA
    4cd8b61 View commit details
    Browse the repository at this point in the history
  5. [threads] Validate shared-polymorphic instructions (WebAssembly#6702)

    Such as `ref.eq`, `i31.get_{s,u}`, and `array.len`. Also validate that
    struct and array operations work on shared structs and arrays.
    tlively authored Jun 25, 2024
    Configuration menu
    Copy the full SHA
    654ee6e View commit details
    Browse the repository at this point in the history

Commits on Jun 26, 2024

  1. [WasmGC] Heap2Local: Optimize RefEq (WebAssembly#6703)

    If an allocation does not escape, then we can compute ref.eq for it: when
    compared to itself the result is 1, and when compared to anything else it
    is 0 (since it did not escape, anything else must be different).
    kripken authored Jun 26, 2024
    Configuration menu
    Copy the full SHA
    d6b4f01 View commit details
    Browse the repository at this point in the history
  2. [threads] Fuzz shared types in type fuzzer (WebAssembly#6704)

    Give the type fuzzer the ability to generate shared heap types when the
    shared-everything feature is enabled. It correctly ensures that shared
    structs and arrays cannot reference unshared heap types, but that
    unshared heap types can reference any heap type.
    
    Update the main fuzzer so that for the time being it never uses the
    shared-everything feature when generating additional heap types, so it
    never generates shared types. We can lift this restriction once the main
    fuzzer has been updated to properly handle shared types.
    
    As a drive-by, fix some logic for subtracting feature sets from each
    other that is used in this commit.
    tlively authored Jun 26, 2024
    Configuration menu
    Copy the full SHA
    ff8095d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    636d1b2 View commit details
    Browse the repository at this point in the history

Commits on Jun 27, 2024

  1. Configuration menu
    Copy the full SHA
    53712b6 View commit details
    Browse the repository at this point in the history
  2. ConstantFieldPropagation: Add a variation that picks between 2 values…

    … using RefTest (WebAssembly#6692)
    
    CFP focuses on finding when a field always contains a constant, and then replaces
    a struct.get with that constant. If we find there are two constant values, then in some
    cases we can still optimize, if we have a way to pick between them. All we have is the
    struct.get and its reference, so we must use a ref.test:
    
       (struct.get $T x (..ref..))
         =>
       (select
         (..constant1..)
         (..constant2..)
         (ref.test $U (..ref..))
       )
    
    This is valid if, of all the subtypes of $T, those that pass the test have
    constant1 in that field, and those that fail the test have constant2. For
    example, a simple case is where $T has two subtypes, $T is never created
    itself, and each of the two subtypes has a different constant value.
    
    This is a somewhat risky operation, as ref.test is not necessarily cheap.
    To mitigate that, this is a new pass, --cfp-reftest that is not run by
    default, and also we only optimize when we can use a ref.test on what
    we think will be a final type (because ref.test on a final type can be
    faster in VMs).
    kripken authored Jun 27, 2024
    Configuration menu
    Copy the full SHA
    cdf8139 View commit details
    Browse the repository at this point in the history

Commits on Jul 2, 2024

  1. [DebugInfo] Add debug info to the values emitted in GlobalStructInfer…

    …ence (WebAssembly#6709)
    
    Previously the replacement select got the debug info, but we should also copy it
    to the values, as often optimizations lead to one of those values remaining by
    itself.
    
    Similar to WebAssembly#6652 in general form.
    kripken authored Jul 2, 2024
    Configuration menu
    Copy the full SHA
    9792f2c View commit details
    Browse the repository at this point in the history

Commits on Jul 8, 2024

  1. Rename external conversion instructions (WebAssembly#6716)

    Rename instructions `extern.internalize` into `any.convert_extern` and
    `extern.externalize` into `extern.convert_any` to follow more closely
    the spec. This was changed in
    WebAssembly/gc#432.
    
    The legacy name is still accepted in text inputs and in the C and JS
    APIs.
    vouillon authored Jul 8, 2024
    Configuration menu
    Copy the full SHA
    81f8f77 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4179603 View commit details
    Browse the repository at this point in the history
  3. StackIR: Optimize away a drop before an unreachable (WebAssembly#6719)

    Anything else right before an unreachable is removed by the main DCE
    pass anyhow, but because of the structured form of BinaryenIR we can't remove
    a drop. That is, this is the difference between
    
    (i32.eqz
      (i32.const 42)
      (unreachable)
    )
    
    and
    
    (drop
      (call $foo)
    )
    (unreachable)
    
    In both cases the unreachable is preceded by something we don't need,
    but in the latter case it must remain in BinaryenIR for validation.
    
    To optimize this, add a rule in StackIR.
    
    Fixes WebAssembly#6715
    kripken authored Jul 8, 2024
    Configuration menu
    Copy the full SHA
    e93babc View commit details
    Browse the repository at this point in the history

Commits on Jul 9, 2024

  1. [tests] Remove use of CHECK-SAME (WebAssembly#6717)

    The `filecheck` command used for tests does not support `CHECK-SAME`, so
    use should be avoided.
    AntonLydike authored Jul 9, 2024
    Configuration menu
    Copy the full SHA
    081f28b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0750bdb View commit details
    Browse the repository at this point in the history

Commits on Jul 10, 2024

  1. Allow --keepfuncs and --splitfuncs to be use alongside a profile data (

    …WebAssembly#6322)
    
    There are times after collecting a profile, we wish to manually include
    specific functions into the primary module.
    It could be due to non-deterministic profiling or functions for error
    scenarios (e.g. _trap).
    
    This PR helps to unlock this workflow by honoring both the
    `--keep-funcs` flag as well as the `--profile` flag
    Mintyboi authored Jul 10, 2024
    Configuration menu
    Copy the full SHA
    76f6612 View commit details
    Browse the repository at this point in the history
  2. [StackIR] Allow StackIR to be disabled from the commandline (WebAssem…

    …bly#6725)
    
    Normally we use it when optimizing (above a certain level). This lets the user
    prevent it from being used even then.
    
    Also add optimization options to wasm-metadce so that this is possible
    there as well and not just in wasm-opt (this also opens the door to running
    more passes in metadce, which may be useful later).
    kripken authored Jul 10, 2024
    Configuration menu
    Copy the full SHA
    37a86d5 View commit details
    Browse the repository at this point in the history

Commits on Jul 11, 2024

  1. Configuration menu
    Copy the full SHA
    e05f762 View commit details
    Browse the repository at this point in the history
  2. Monomorphization: Optimize constants (WebAssembly#6711)

    Previously the pass would monomorphize a call when we were sending more
    refined types than the target expects. This generalizes the pass to also consider
    the case where we send a constant in a parameter.
    
    To achieve that, this refactors the pass to explicitly define the "call context",
    which is the code around the call (inputs and outputs) that may end up leading
    to optimization opportunities when combined with the target function. Also
    add comments about the overall design + roadmap.
    
    The existing test is mostly unmodified, and the diff there is smaller when
    ignoring whitespace. We do "regress" those tests by adding more local.set
    operations, as in the refactoring that makes things a lot simpler, that is, to
    handle the general case of an operand having either a refined type or be a
    constant, we copy it inside the function, which works either way. This
    "regression" is only in the testing version of the pass (the normal version
    runs optimizations, which would remove that extra code).
    
    This also enables the pass when GC is disabled. Previously we only handled
    refined types, so only GC could benefit. Add a test for MVP content
    specifically to show we operate there as well.
    kripken authored Jul 11, 2024
    Configuration menu
    Copy the full SHA
    5a1daf7 View commit details
    Browse the repository at this point in the history
  3. Heap2Local: Drop RefEq's two arms (WebAssembly#6729)

    This is a tiny bit more code but it is more consistent with other
    operations, and it saves work later.
    kripken authored Jul 11, 2024
    Configuration menu
    Copy the full SHA
    5613981 View commit details
    Browse the repository at this point in the history
  4. [WasmGC] Heap2Local: Optimize RefCast failures (WebAssembly#6727)

    Previously we just did not optimize cases where our escape analysis showed an
    allocation flowed into a cast that failed. However, after inlining there can be
    real-world cases where that happens, even in traps-never-happen mode (if the
    cast is behind a conditional branch), so it seems worth optimizing.
    kripken authored Jul 11, 2024
    Configuration menu
    Copy the full SHA
    020e6cc View commit details
    Browse the repository at this point in the history
  5. [wasm-split] Use a fresh table when reference types are enabled (WebA…

    …ssembly#6726)
    
    Rather than trying to trampoline primary-to-secondary calls through an
    existing table, just create a fresh table for this purpose. This ensures
    that modifications to the existing tables cannot interfere with
    primary-to-secondary calls and conversely that loading the secondary
    module cannot overwrite modifications to the tables.
    tlively authored Jul 11, 2024
    Configuration menu
    Copy the full SHA
    c64ac5d View commit details
    Browse the repository at this point in the history
  6. [threads] Shared polymorphism for extern conversions (WebAssembly#6730)

    `any.convert_extern` and `extern.convert_any` return references to
    shared heap types iff their operands are references to shared heap
    types.
    tlively authored Jul 11, 2024
    Configuration menu
    Copy the full SHA
    ae4800b View commit details
    Browse the repository at this point in the history
  7. Monomorphize: Use -O3 over -O1 + tweaks (WebAssembly#6732)

    Eventually we will need to do some tuning of compile time speed, but for
    now it is going to be simpler to do all the opts, in particular because it makes
    writing tests simpler.
    kripken authored Jul 11, 2024
    Configuration menu
    Copy the full SHA
    6d2f101 View commit details
    Browse the repository at this point in the history
  8. Convert memory64 lowering test to lit. NFC (WebAssembly#6731)

    Test was converted using port_passes_tests_to_lit.py.
    sbc100 authored Jul 11, 2024
    Configuration menu
    Copy the full SHA
    363edc7 View commit details
    Browse the repository at this point in the history
  9. Memory64Lowering: Handle -1 return value from memory.grow (WebAssembl…

    …y#6733)
    
    This edge case make the lowering a little more tricky.
    sbc100 authored Jul 11, 2024
    Configuration menu
    Copy the full SHA
    22c28bd View commit details
    Browse the repository at this point in the history

Commits on Jul 12, 2024

  1. Do not abbreviate items in element segments (WebAssembly#6737)

    The full syntax for an expression in an element syntax looks like
    `(item (ref.null none))`, but we have been printing the abbreviated
    version, which omits the `(item ...)`. This abbreviation is only valid
    when the item has only a single instruction, so it is not always correct
    to use it. Rather than determining whether or not to use the
    abbreviation on a case-by-case basis, always print the full syntax.
    tlively authored Jul 12, 2024
    Configuration menu
    Copy the full SHA
    c0286b6 View commit details
    Browse the repository at this point in the history
  2. SafeHeap: Handle overflows when adding the pointer and the size (WebA…

    …ssembly#6409)
    
    E.g. loading 4 bytes from 2^32 - 2 should error: 2 bytes are past the maximum
    address. Before this PR we added 2^32 - 2 + 4 and overflowed to 2, which we
    saw as a low and safe address. This PR adds an extra check for an overflow in
    that add.
    
    Also add unreachables after calls to segfault(), which reduces the overhead of
    the extra check here (the unreachable apparently allows VMs to see that
    control flow ends, after the segfault() which is truly no-return).
    
    Fixes emscripten-core/emscripten#21557
    kripken authored Jul 12, 2024
    Configuration menu
    Copy the full SHA
    0e0e08d View commit details
    Browse the repository at this point in the history
  3. [threads] ref.i31_shared (WebAssembly#6735)

    Implement `ref.i31_shared` the new instruction for creating references
    to shared i31s. Implement binary and text parsing and emitting as well
    as interpretation. Copy the upstream spec test for i31 and modify it so
    that all the heap types are shared. Comment out some parts that we do
    not yet support.
    tlively authored Jul 12, 2024
    Configuration menu
    Copy the full SHA
    eda6530 View commit details
    Browse the repository at this point in the history
  4. Remove non-standard i31.new (WebAssembly#6736)

    The standard name for the instruction is `ref.i31`. Remove support for
    the non-standard name and update tests that were still using it.
    tlively authored Jul 12, 2024
    Configuration menu
    Copy the full SHA
    20c10df View commit details
    Browse the repository at this point in the history
  5. Monomorphize dropped functions (WebAssembly#6734)

    We now consider a drop to be part of the call context: If we see
    
    (drop
      (call $foo)
    )
    
    (func $foo (result i32)
      (i32.const 42)
    )
    
    Then we'd monomorphize to this:
    
    (call $foo_1)  ;; call the specialized function instead
    
    (func $foo_1   ;; the specialized function returns nothing
      (drop        ;; the drop was moved into here
        (i32.const 42)
      )
    )
    
    With the drop now in the called function, we may be able to optimize out unused work.
    
    Refactor a bit of code out of DAE that we can reuse here, into a new return-utils.h.
    kripken authored Jul 12, 2024
    Configuration menu
    Copy the full SHA
    d2a48af View commit details
    Browse the repository at this point in the history

Commits on Jul 13, 2024

  1. Configuration menu
    Copy the full SHA
    65ee5b9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    aec516f View commit details
    Browse the repository at this point in the history

Commits on Jul 15, 2024

  1. Allow different arguments for multiple instances of a pass (WebAssemb…

    …ly#6687)
    
    Each pass instance can now store an argument for it, which can be different.
    
    This may be a breaking change for the corner case of running a pass multiple
    times and setting the pass's argument multiple times as well (before, the last
    pass argument affected them all; now, it affects the last instance only). This
    only affects arguments with the name of a pass; others remain global, as
    before (and multiple passes can read them, in fact). See the CHANGELOG for
    details.
    
    Fixes WebAssembly#6646
    DirtyHairy authored Jul 15, 2024
    Configuration menu
    Copy the full SHA
    fd8b2bd View commit details
    Browse the repository at this point in the history
  2. [NFC] Fix changelog order after WebAssembly#6687 (WebAssembly#6748)

    We made a release since it was written, which this is not included in.
    kripken authored Jul 15, 2024
    Configuration menu
    Copy the full SHA
    503fc4b View commit details
    Browse the repository at this point in the history

Commits on Jul 16, 2024

  1. Simplify fuzzer generation of function references (WebAssembly#6745)

    When creating a reference to `func`, fix the probability of choosing to
    continue on to choose some function other than the last one rather than
    making it depend on the number of functions. Then, do not eagerly pick
    from the rest of the candidate functions. Instead, fall through to the
    more general logic that will already pick a random candidate function.
    Also move the logic for coming up with a concrete signature down to
    where it is needed.
    
    These simplifications will make it easier to update the code to handle
    shared types.
    tlively authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    5bdc0f4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0964a6a View commit details
    Browse the repository at this point in the history
  3. Remove extra space printed in empty structs (WebAssembly#6750)

    When we switched to the new type printing machinery, we inserted this
    extra space to minimize the diff in the test output compared with the
    previous type printer. Improve the quality of the printed output by
    removing it.
    tlively authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    afef6d3 View commit details
    Browse the repository at this point in the history
  4. [NFC] Clarify and standardize order in flexibleCopy (WebAssembly#6749)

    flexibleCopy always visited parents before children, but it visited
    vector children in reverse order:
    
    (call        ;; 1
      (call $a)  ;; 3
      (call $b)  ;; 2
    )
    
    The order of children happened to not matter in any user of this code,
    and that's just what you get when you iterate over children in a vector
    and push them to a stack before visiting them, so this odd ordering
    was not noticed.
    
    For a new user I will introduce soon, however, it would be nice to have
    the normal pre-order:
    
    (call        ;; 1
      (call $a)  ;; 2
      (call $b)  ;; 3
    )
    (2 & 3 swapped).
    
    This cannot be tested in the current code as it is NFC, but the later PR
    will depend on it and test it heavily.
    kripken authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    ee43476 View commit details
    Browse the repository at this point in the history
  5. [threads] Allow i31refs of mixed shareability to compare equal (WebAs…

    …sembly#6752)
    
    Normally, values of different types can never compare equal to each
    other, but since i31refs are not actually allocations, `ref.eq` has no
    way to differentiate a shared i31ref and an unshared i31ref with the
    same value, so it will report them as equal. Update the implementation
    of value equality to reflect this correctly.
    tlively authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    9de9d05 View commit details
    Browse the repository at this point in the history
  6. [threads] Update TypeSSA for shared types (WebAssembly#6753)

    When creating a new subtype, make sure to copy the supertype's
    shareability.
    tlively authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    53b7dd1 View commit details
    Browse the repository at this point in the history
  7. Add C and JS APIs to control more pass options (WebAssembly#6713)

    Add functions to:
    
    * Set and get the trapsNeverHappen, closedWorld, generateStackIR and optimizeStackIR flags
    * Manage the list of passes to skip.
    vouillon authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    43e8809 View commit details
    Browse the repository at this point in the history
  8. [NFC][threads] Ignore type-ssa-shared.wast in fuzzer (WebAssembly#6754)

    The fuzzer does not yet properly handle initial contents containing
    shared types.
    tlively authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    a8df0bf View commit details
    Browse the repository at this point in the history
  9. [threads] Fix feature detection for shared basic heap types (WebAssem…

    …bly#6756)
    
    The logic for adding the shared-everything feature was not previously
    executed for shared basic heap types.
    tlively authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    d91f1c4 View commit details
    Browse the repository at this point in the history
  10. [threads] Validate all features required by ref.null (WebAssembly#6757)

    `ref.null` of shared types should only be allowed when shared-everything
    is enabled, but we were previously checking only that reference types
    were enabled when validating `ref.null`. Update the code to check all
    features required by the null type and factor out shared logic for
    printing lists of missing feature options in error messages.
    tlively authored Jul 16, 2024
    Configuration menu
    Copy the full SHA
    6d2bef3 View commit details
    Browse the repository at this point in the history

Commits on Jul 17, 2024

  1. Make it possible to skip several passes (WebAssembly#6714)

    --skip-pass can now be specified more than once on the commandline.
    vouillon authored Jul 17, 2024
    Configuration menu
    Copy the full SHA
    994d8d3 View commit details
    Browse the repository at this point in the history
  2. [threads] Validate all features required by ref.null (WebAssembly#6758)

    `ref.null` of shared types should only be allowed when shared-everything
    is enabled, but we were previously checking only that reference types
    were enabled when validating `ref.null`. Update the code to check all
    features required by the null type and factor out shared logic for
    printing lists of missing feature options in error messages.
    tlively authored Jul 17, 2024
    Configuration menu
    Copy the full SHA
    55d888a View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    9cee7d0 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    ddf919b View commit details
    Browse the repository at this point in the history
  5. [threads][NFC] Do not include cont in shared types test (WebAssembly#…

    …6759)
    
    Once the fuzzer is updated to be able to handle initial contents with
    shared types, it still will not be able to handle initial contents with
    continuation types. To avoid future issues, remove continuations from
    lit/basic/shared-types.wast.
    tlively authored Jul 17, 2024
    Configuration menu
    Copy the full SHA
    a9758b8 View commit details
    Browse the repository at this point in the history
  6. Revert "[threads] Allow i31refs of mixed shareability to compare equal (

    WebAssembly#6752)" (WebAssembly#6761)
    
    Allowing Literals with different types to compare equal causes problems
    for passes that want equality to mean real equality, e.g. because they
    are using literals as map keys or because they otherwise need to use
    them interchangeably.
    
    At a minimum, we would need to differentiate a `refEq` operation where
    mixed-shareability i31refs can compare equal from physical equality on
    Literals, but there is also appetite to disallow mixed-shareability
    ref.eq at the spec level. See
    WebAssembly/shared-everything-threads#76.
    tlively authored Jul 17, 2024
    Configuration menu
    Copy the full SHA
    4dee6fe View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    1e7be1e View commit details
    Browse the repository at this point in the history
  8. [threads] Fix shared ref.eq and disallow mixed-shareability (WebAssem…

    …bly#6763)
    
    Update the validator to reject mixed-shareability ref.eq, although this
    is still under discussion in
    WebAssembly/shared-everything-threads#76. Fix
    the implementation of `Literal::operator==` to work properly with shared
    i31ref.
    tlively authored Jul 17, 2024
    Configuration menu
    Copy the full SHA
    1434591 View commit details
    Browse the repository at this point in the history
  9. [threads] Simplify and generalize heap type writing without GC (WebAs…

    …sembly#6765)
    
    We represent `ref.null`s as having bottom heap types, even when GC is
    not enabled. Bottom heap types are a feature of the GC proposal, so in
    that case the binary writer needs to write the corresponding top type
    instead. We previously had separate logic for this for each type
    hierarchy in the binary writer, but that did not handle shared types and
    would not have automatically handled other new types, either. Simplify
    and generalize the implementation and test that we can write `ref.null`s
    of shared types without GC enabled.
    tlively authored Jul 17, 2024
    Configuration menu
    Copy the full SHA
    29746f1 View commit details
    Browse the repository at this point in the history
  10. binaryen.js: Avoid catching exit, which confuses Node error reporting (

    …WebAssembly#6764)
    
    Fixes emscripten-core/emscripten#17228
    
    This seems the right default in binaryen.js which is used as a library through
    npm mostly. We aren't a main program that wants to control node exclusively.
    kripken authored Jul 17, 2024
    Configuration menu
    Copy the full SHA
    6b93a84 View commit details
    Browse the repository at this point in the history

Commits on Jul 18, 2024

  1. [threads] Simplify and generalize reftype writing without GC (WebAsse…

    …mbly#6766)
    
    Similar to WebAssembly#6765, but for types instead of heap types. Generalize the
    logic for transforming written reference types to types that are
    supported without GC so that it will automatically handle shared types
    and other new types correctly.
    tlively authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    0843618 View commit details
    Browse the repository at this point in the history
  2. Monomorphize all the things (WebAssembly#6760)

    Previously call operands were monomorphized (considered as part of the
    call context, so we can create a specialized function with those operands
    fixed) if they were constant or had a different type than the function
    parameter's type. This generalizes that to pull in pretty much all the code
    we possibly can, including nested code. For example:
    
    (call $foo
      (struct.new $struct
        (i32.const 10)
        (local.get $x)
        (local.get $y)
      )
    )
    
    This can turn into
    
    (call $foo_mono
      (local.get $x)
      (local.get $y)
    )
    
    The struct.new and even one of the struct.new's children is moved into the
    called function, replacing the original ref argument with two other ones. If the
    original called function was this:
    
    (func $foo (param $ref (ref ..))
      ..
    )
    
    then the monomorphized function then looks like this:
    
    (func $foo_mono (param $x i32) (param $y i32)
      (local $ref (ref ..))
      (local.set $ref
        (struct.new $struct
          (i32.const 10)
          (local.get $x)
          (local.get $y)
        )
      )
      ..
    )
    
    The struct.new and its constant child appear here, and we read the
    parameters.
    
    To do this, generalize the code that creates the call context to accept
    everything that is impossible to copy (like a local.get) or that would be
    tricky and likely unworthwhile (like another call or a tuple). Also check
    for effect interactions, as this code motion does some reordering.
    
    For this to work, we need to adjust how we compute the costs we
    compare when deciding what to monomorphize. Before we just
    compared the called function to the monomorphized called function,
    which was good enough when the call context only contained consts,
    but now it can contain arbitrarily nested code. The proper comparison
    is between these two:
    
    * Old function + call context
    * New monomorphized function
    
    Including the call context makes this a fair comparison. In the example
    above, the struct.new and the i32.const are part of the call context,
    and so they are in the monomorphized function, so if we didn't count
    them in other function we'd decide not to optimize anything with a large
    context.
    
    The new functionality is tested in a new file. A few parts of existing
    tests needed changes to not become pointless after this improvement,
    namely by replacing stuff that we now optimize with things that we
    don't like replacing an i32.eqz with a local.get. There are also a
    handful of test outcomes that change in CAREFUL mode due to the
    new cost analysis.
    kripken authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    b91966f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    fd867a3 View commit details
    Browse the repository at this point in the history
  4. Validate features for types used in tables (WebAssembly#6768)

    We previously special-cased things like GC types, but switch to a more
    general solution of detecting what features a table's type requires.
    tlively authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    a744bec View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    7b1ef0c View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    5a6eb16 View commit details
    Browse the repository at this point in the history
  7. [threads] Update the fuzzer for shared types (WebAssembly#6771)

    Update the fuzzer to both handle shared types in initial contents and
    create and use new shared types without crashing or producing invalid
    modules. Since V8 does not have a complete implementation of
    shared-everything-threads yet, disable fuzzing V8 when shared-everything
    is enabled. To avoid losing too much coverage of V8, disable
    shared-everything in the fuzzer more frequently than other features.
    tlively authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    848a289 View commit details
    Browse the repository at this point in the history
  8. [NFC] Add HeapType::isMaybeShared(BasicHeapType) utility (WebAssembly…

    …#6773)
    
    This abbreviates a common pattern where we first had to check whether a
    heap type was basic, then if it was, get its unshared version and
    compare it to some expected BasicHeapType.
    
    Suggested in
    
    WebAssembly#6771 (comment).
    tlively authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    84daeca View commit details
    Browse the repository at this point in the history
  9. Heap2Local: Properly handle failing array casts (WebAssembly#6772)

    Followup to WebAssembly#6727 which added support for failing casts in Struct2Local, but it
    turns out that it required Array2Struct changes as well. Specifically, when we
    turn an array into a struct then casts can look like they behave differently
    (what used to be an array input, becomes a struct), so like with RefTest that we
    already handled, check if the cast succeeds in the original form and handle
    that.
    kripken authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    a8066e6 View commit details
    Browse the repository at this point in the history

Commits on Jul 23, 2024

  1. Make FunctionInfo's assignment operator argument const (WebAssembly#6780

    )
    
    Aside from the fact that there's no need for this to be non-const and
    this is the usual way to write an assignment operator, this is also
    needed because of a recent change to std::pair
    (llvm/llvm-project#89652). This seems to be
    forcing pair to want the const version of the assignment operator of its
    members.
    dschuff authored Jul 23, 2024
    Configuration menu
    Copy the full SHA
    0973589 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    538c528 View commit details
    Browse the repository at this point in the history
  3. Properly validate ref.cast when lacking a common supertype (WebAssemb…

    …ly#6741)
    
    
    
    When lacking a common supertype the GLB operation makes the type of the cast
    unreachable, which errors on getHeapType in the later code.
    
    Fixes WebAssembly#6738
    kripken authored Jul 23, 2024
    Configuration menu
    Copy the full SHA
    353e19e View commit details
    Browse the repository at this point in the history

Commits on Jul 24, 2024

  1. Configuration menu
    Copy the full SHA
    017b473 View commit details
    Browse the repository at this point in the history

Commits on Jul 25, 2024

  1. TupleOptimization: Properly handle subtyping in copies (WebAssembly#6786

    )
    
    We used the target's type for the read from the source, but due to
    subtyping those might be different.
    
    Found by the fuzzer.
    kripken authored Jul 25, 2024
    Configuration menu
    Copy the full SHA
    d903dd3 View commit details
    Browse the repository at this point in the history
  2. Cost analysis: Remove "Unacceptable" hack (WebAssembly#6782)

    We marked various expressions as having cost "Unacceptable", fixed at 100, to
    ensure we never moved them out from an If arm, etc. Giving them such a high
    cost avoids that problem - the cost is higher than the limit we have for moving
    code from conditional to unconditional execution - but it also means the total
    cost is unrealistic. For example, a function with one such instruction + an add
    (cost 1) would end up with cost 101, and removing the add would look
    insignificant, which causes issues for things that want to compare costs
    (like Monomorphization).
    
    To fix this, adjust some costs. The main change here is to give casts a cost of 5.
    I measured this in depth, see the attached benchmark scripts, and it looks
    clear that in both V8 and SpiderMonkey the cost of a cast is high enough to
    make it not worth turning an if with ref.test arm into a select (which would
    always execute the test).
    
    Other costs adjusted here matter a lot less, because they are on operations
    that have side effects and so the optimizer will anyhow not move them from
    conditional to unconditional execution, but I tried to make them a bit more
    realistic while I was removing "Unacceptable":
    
    *   Give most atomic operations the 10 cost we've been using for atomic loads/
        stores. Perhaps wait and notify should be slower, however, but it seems like
        assuming fast switching might be more relevant.
    *   Give growth operations a cost of 20, and throw operations a cost of 10. These
        numbers are entirely made up as I am not even sure how to measure them in
        a useful way (but, again, this should not matter much as they have side
        effects).
    kripken authored Jul 25, 2024
    Configuration menu
    Copy the full SHA
    9cc1cb1 View commit details
    Browse the repository at this point in the history

Commits on Jul 26, 2024

  1. [wasm-reduce] Do not crash on non-func element segments (WebAssembly#…

    …6778)
    
    Generalize the code for simplifying element segments to handle more than
    just null and funcref elements.
    tlively authored Jul 26, 2024
    Configuration menu
    Copy the full SHA
    f938154 View commit details
    Browse the repository at this point in the history

Commits on Jul 29, 2024

  1. Configuration menu
    Copy the full SHA
    eac0846 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6645f0c View commit details
    Browse the repository at this point in the history

Commits on Jul 30, 2024

  1. Add a Tarjan's Strongly Connected Component utilty (WebAssembly#6790)

    Implement a non-recursive version of Tarjan's Strongly Connected
    Component algorithm that consumes and produces iterators for maximum
    flexibility.
    
    This will be used in an optimization that transforms the heap type graph
    to use minimal recursion groups, which correspond to the strongly
    connected components of the type graph.
    tlively authored Jul 30, 2024
    Configuration menu
    Copy the full SHA
    e2f666a View commit details
    Browse the repository at this point in the history
  2. Add a customizable title to Metrics reporting (WebAssembly#6792)

    Before the PR:
    
    $ bin/wasm-opt test/hello_world.wat --metrics
    total
     [exports]      : 1       
     [funcs]        : 1       
     [globals]      : 0       
     [imports]      : 0       
     [memories]     : 1       
     [memory-data]  : 0       
     [tables]       : 0       
     [tags]         : 0       
     [total]        : 3       
     [vars]         : 0       
     Binary         : 1       
     LocalGet       : 2       
    
    After the PR:
    
    $ bin/wasm-opt test/hello_world.wat --metrics
    Metrics
    total
     [exports]      : 1       
     [funcs]        : 1       
    ...
    
    Note the "Metrics" addition at the top. And the title can be customized:
    
    $ bin/wasm-opt test/hello_world.wat --metrics=text
    Metrics: text
    total
     [exports]      : 1       
     [funcs]        : 1       
    
    The custom title can be helpful when multiple invocations of metrics are used
    at once, e.g. --metrics=before -O3 --metrics=after.
    kripken authored Jul 30, 2024
    Configuration menu
    Copy the full SHA
    5078d4d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e6bbff7 View commit details
    Browse the repository at this point in the history

Commits on Jul 31, 2024

  1. Use Names::getValidNameGivenExisting in binary reading (WebAssembly#6793

    )
    
    We had a TODO to use it once Names was optimized, which it has been.
    
    The Names version is also far faster. When building
    https://github.com/JetBrains/kotlinconf-app it saves 70 seconds(!).
    kripken authored Jul 31, 2024
    Configuration menu
    Copy the full SHA
    c689781 View commit details
    Browse the repository at this point in the history

Commits on Aug 1, 2024

  1. [NFC] Avoid a temp local (WebAssembly#6800)

    The local was only used once, so it didn't really add much. And, it was
    causing some compilers to error on "unused variable" (when building without
    assertions, the use was removed).
    kripken authored Aug 1, 2024
    Configuration menu
    Copy the full SHA
    705c28d View commit details
    Browse the repository at this point in the history
  2. Add a disjoint sets (union-find) utility (WebAssembly#6797)

    This will be used in an upcoming type optimization pass and may be
    generally useful.
    tlively authored Aug 1, 2024
    Configuration menu
    Copy the full SHA
    2a7c093 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    8d2c9ff View commit details
    Browse the repository at this point in the history

Commits on Aug 5, 2024

  1. Configuration menu
    Copy the full SHA
    53d54d7 View commit details
    Browse the repository at this point in the history
  2. Add a utility for iterating over all topological orders (WebAssembly#…

    …6801)
    
    Use an extension of Kahn's algorithm for finding topological orders that
    iteratively makes every possible choice at every step to find all the
    topological orders. The order being constructed and the set of possible
    choices are managed in-place in the same buffer, so the algorithm takes
    linear time and space plus amortized constant time per generated order.
    
    This will be used in an upcoming type optimization.
    tlively authored Aug 5, 2024
    Configuration menu
    Copy the full SHA
    5573cdb View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d9c44af View commit details
    Browse the repository at this point in the history
  4. WasmBinaryReader: Use helper function to create names for items. NFC (W…

    …ebAssembly#6810)
    
    As a followup we could probably make these more consistent. For example,
    we could use a single char prefix for defined functions/tables/globals
    (e.g. f0/t0/g0)
    sbc100 authored Aug 5, 2024
    Configuration menu
    Copy the full SHA
    e2e5b9c View commit details
    Browse the repository at this point in the history

Commits on Aug 6, 2024

  1. Make source parser consistent with binary parser when naming things. …

    …NFC (WebAssembly#6813)
    
    The `timport$` prefix is already used for tables, so the binary parser
    currently uses `eimport$` to name tags (I guess because they are
    normally exception tags?).
    sbc100 authored Aug 6, 2024
    Configuration menu
    Copy the full SHA
    6fe3d88 View commit details
    Browse the repository at this point in the history
  2. [NFC] Add HeapType::getKind returning a new HeapTypeKind enum (WebAss…

    …embly#6804)
    
    The HeapType API has functions like `isBasic()`, `isStruct()`,
    `isSignature()`, etc. to test the classification of a heap type. Many
    users have to call these functions in sequence and handle all or most of
    the possible classifications. When we add a new kind of heap type,
    finding and updating all these sites is a manual and error-prone
    process.
    
    To make adding new heap type kinds easier, introduce a new API that
    returns an enum classifying the heap type. The enum can be used in
    switch statements and the compiler's exhaustiveness checker will flag
    use sites that need to be updated when we add a new kind of heap type.
    
    This commit uses the new enum internally in the type system, but
    follow-on commits will add new uses and convert uses of the existing
    APIs to use `getKind` instead.
    tlively authored Aug 6, 2024
    Configuration menu
    Copy the full SHA
    bae0da0 View commit details
    Browse the repository at this point in the history
  3. Fix sharedness bug in inhabitable type fuzzer (WebAssembly#6807)

    The code for collecting inhabitable types incorrectly considered shared,
    non-nullable externrefs to be inhabitable, which disagreed with the code
    for rewriting types to be inhabitable, which was correct, causing the
    type fuzzer to report an error.
    tlively authored Aug 6, 2024
    Configuration menu
    Copy the full SHA
    1c3578c View commit details
    Browse the repository at this point in the history
  4. [Source maps] Handle single-segment entries in source map header deco…

    …der (WebAssembly#6794)
    
    Single-segment mappings were already handled in readNextDebugLocation,
    but not in readSourceMapHeader.
    osa1 authored Aug 6, 2024
    Configuration menu
    Copy the full SHA
    a985e16 View commit details
    Browse the repository at this point in the history
  5. Restore isString type methods (WebAssembly#6815)

    PR #WebAssembly#6803 proposed removing Type::isString and HeapType::isString in
    favor of more explicit, verbose callsites. There was no consensus to
    make this change, but it was accidentally committed as part of WebAssembly#6804.
    
    Revert the accidental change, except for the useful, noncontroversial
    parts, such as fixing the `isString` implementation and a few other
    locations to correctly handle shared types.
    tlively authored Aug 6, 2024
    Configuration menu
    Copy the full SHA
    d5a5425 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    0c26948 View commit details
    Browse the repository at this point in the history

Commits on Aug 7, 2024

  1. [parser] Fix bug when printing type builder errors (WebAssembly#6817)

    The type index from the TypeBuilder error was mapped to a file location
    incorrectly, resulting in an assertion failure.
    
    Fixes WebAssembly#6816.
    tlively authored Aug 7, 2024
    Configuration menu
    Copy the full SHA
    23a1a1a View commit details
    Browse the repository at this point in the history
  2. [NFC][parser] Rename deftype and subtype (WebAssembly#6819)

    Match the current spec and clarify terminology by renaming the old
    `deftype` to `rectype` and renaming the old `subtype` to `typedef`. Also
    split the parser for actual `subtype` out of the parser for the newly
    named `typedef`.
    tlively authored Aug 7, 2024
    Configuration menu
    Copy the full SHA
    9163e0d View commit details
    Browse the repository at this point in the history
  3. GTO: Remove minor optimization of avoiding ChildLocalizer sometimes (W…

    …ebAssembly#6818)
    
    The optimization is to only use ChildLocalizer, which moves children to
    locals, if we actually have a reason to use it. It is simple enough to see if
    we are removing fields with side effects here, and only call ChildLocalizer
    if we are not. However, this will become much more complicated in a
    subsequent PR which will reorder fields, which allows removing yet more
    of them (without reordering, we can only remove fields at the end, if any
    subtype needs the field).
    
    This is a pretty minor optimization, as it avoids adding a few locals in the rare
    case of struct.new operands having side effects. We run --gto at the
    start of the pipeline, so later opts will clean that up anyhow. (Though, this
    might make us a little less efficient, but the following PR will justify this
    regression.)
    kripken authored Aug 7, 2024
    Configuration menu
    Copy the full SHA
    dc87572 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    fb6ead8 View commit details
    Browse the repository at this point in the history

Commits on Aug 8, 2024

  1. Add a utility for comparing and hashing rec group shapes (WebAssembly…

    …#6808)
    
    This is very similar to the internal utilities for canonicalizing rec
    groups in the type system implementation, except that the new utility
    also supports ordered comparison of rec groups, and of course the new
    utility only uses the public type API.
    
    A follow-up PR will replace the internal implementation of rec group
    comparison and hashing in the type system with this one.
    
    Another follow-up PR will use this new utility in a type optimization.
    tlively authored Aug 8, 2024
    Configuration menu
    Copy the full SHA
    2397f2a View commit details
    Browse the repository at this point in the history
  2. Simplify TopologicalOrders (WebAssembly#6811)

    Make `TopologicalOrders` its own iterator rather than having a separate
    iterator class that wraps a pointer to `TopologicalOrders`. This
    simplifies usage in cases where an iterator needs to be persistently
    stored. Notably, all of the tests continue working as they are.
    tlively authored Aug 8, 2024
    Configuration menu
    Copy the full SHA
    c9fd92c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d945aa4 View commit details
    Browse the repository at this point in the history

Commits on Aug 9, 2024

  1. Configuration menu
    Copy the full SHA
    b3e22d2 View commit details
    Browse the repository at this point in the history
  2. Typed continuations: update syntax of handler clauses (WebAssembly#6824)

    The syntax for handler clauses in `resume` instructions has recently
    changed, using `on` instead of `tag` now.
    
    Instead of 
    ```
    (resume $ct (tag $tag0 $block0) ...  (tag $tagn $blockn))
    ```
    
    we now have
    
    ```
    (resume $ct (on $tag0 $block0) ...  (on $tagn $blockn))
    ```
    
    This PR adapts parsing, printing, and some tests accordingly.
    
    (Note that this PR deliberately makes none of the other changes that
    will arise from implementing the new, combined stack switching proposal,
    yet.)
    frank-emrich authored Aug 9, 2024
    Configuration menu
    Copy the full SHA
    3386e64 View commit details
    Browse the repository at this point in the history
  3. Set hasExplicitName for thunks generated in FuncCastEmulation. NFC (W…

    …ebAssembly#6826)
    
    Without this all the newly created thunks lack names in the name
    section.
    sbc100 authored Aug 9, 2024
    Configuration menu
    Copy the full SHA
    e729e01 View commit details
    Browse the repository at this point in the history

Commits on Aug 12, 2024

  1. GlobalTypeOptimization: Reorder fields in order to remove them (WebAs…

    …sembly#6820)
    
    Before, we only removed fields from the end of a struct. If we had, say
    
    struct Foo {
      int x;
      int y;
      int z;
    };
    
    // Add no fields but inherit the parent's.
    struct Bar : Foo {};
    
    If y is only used in Bar, but never Foo, then we still kept it around, because
    if we removed it from Foo we'd end up with Foo = {x, z}, Bar = {x, y, z} which
    is invalid - Bar no longer extends Foo. But we can do this if we first reorder
    the two:
    
    struct Foo {
      int x;
      int z;
      int y; // now y is at the end
    };
    
    struct Bar : Foo {};
    
    And the optimized form is
    
    struct Foo {
      int x;
      int z;
    };
    
    struct Bar : Foo {
      int y; // now y is added in Bar
    };
    
    This lets us remove all fields possible in all cases AFAIK.
    
    This situation is not super-common, as most fields are actually used both
    up and down the hierarchy (if they are used at all), but testing on some
    large real-world codebases, I see 10 fields removed in Java, 45 in Kotlin,
    and 31 in Dart testcases.
    
    The NFC change to src/wasm-type-ordering.h was needed for this to
    compile.
    kripken authored Aug 12, 2024
    Configuration menu
    Copy the full SHA
    a4f9128 View commit details
    Browse the repository at this point in the history

Commits on Aug 13, 2024

  1. Add a TypeBuilder API for copying a heap type (WebAssembly#6828)

    Given a function that maps the old child heap types to new child heap
    types, the new API takes care of copying the rest of the structure of a
    given heap type into a TypeBuilder slot.
    
    Use the new API in GlobalTypeRewriter::rebuildTypes. It will also be
    used in an upcoming type optimization. This refactoring also required
    adding the ability to clear the supertype of a TypeBuilder slot, which
    was previously not possible.
    tlively authored Aug 13, 2024
    Configuration menu
    Copy the full SHA
    d7955a3 View commit details
    Browse the repository at this point in the history
  2. [NFC] Separate out GlobalTypeRewriter::mapTypeNames (WebAssembly#6829)

    Previously a module's type names were updated in
    `GlobalTypeRewriter::rebuildTypes`, which builds new versions of the
    existing types, rather than `GlobalTypeRewriter::mapTypes`, which
    otherwise handles replacing old types with new types everywhere in a
    module, but should not necessarily replace names. So that users of
    `mapTypes` who are building their own versions of existing types can
    also easily update type names, split type name mapping logic out into a
    new method `GlobalTypeRewriter::mapTypeNames`.
    tlively authored Aug 13, 2024
    Configuration menu
    Copy the full SHA
    9ce4b8a View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    6dc5b90 View commit details
    Browse the repository at this point in the history
  4. Heap2Local: Track interactions in detail (WebAssembly#6834)

    Previously we tracked only whether an expression was relevant to analysis, that is,
    whether it interacted with the allocation we were tracing the behavior of. That is
    not enough for all cases, though, so also track the form of the interaction, namely
    whether the allocation flows through or is fully consumed. An example where that
    matters:
    
    (ref.eq
      (struct.get $A 0
        (local.tee $x
          (struct.new_default $A)
        )
      )
      (local.get $x)
    )
    
    Here the local.get flows out the allocation, but the struct.get only fully consumes
    it. Before this PR we thought the struct.get flowed the allocation, and we misoptimized
    this to 1.
    
    To make this possible, do a bunch of minor refactoring:
    
     * Move ParentChildInteraction out of the class.
     * Add a "None" interaction there.
     * Replace the set of reached expressions with a map of them to their interactions.
     * Add helper functions to get an expression's interaction or to update it when replacing.
    
    The new testcase here shows the main fix. The new assertions are covered by existing
    testcases.
    kripken authored Aug 13, 2024
    Configuration menu
    Copy the full SHA
    0c84afe View commit details
    Browse the repository at this point in the history

Commits on Aug 14, 2024

  1. Monomorphization: Add a flag to control the required improvement (Web…

    …Assembly#6837)
    
    The argument is the minimum benefit we must see for us to decide to optimize, e.g.
    
    --monomorphize --pass-arg=monomorphize-min-benefit@50
    
    When the minimum benefit is 50% then if we reduce the cost by 50% through
    monomorphization then we optimize there. 95% would only optimize when we
    remove almost all the cost, etc.
    
    In practice I see 95% will actually tend to reduce code size overall, as while we add
    monomorphized versions of functions, we only do so when we remove a lot of
    work and size, and after inlining we gain benefits. However, 50% or even lower can
    lead to better benchmark results, in return for larger code size, just like with
    inlining. To be careful, the default is set to 95%.
    
    Previously we optimized whenever we saw any benefit at all, which is the same
    as requiring a minimum benefit of 0%. Old tests have the flag applied in this PR
    to set that value, so they do not change.
    kripken authored Aug 14, 2024
    Configuration menu
    Copy the full SHA
    39553a0 View commit details
    Browse the repository at this point in the history
  2. Count supertypes when collecting module types (WebAssembly#6838)

    Previously we included supertypes, but did not increase their count.
    This was done so that the output for the nominal type system, which
    introduced explicitly supertypes, would more closely match the output
    with the old equirecursive types system. Neither type system exists
    anymore and we only support the single, standard isorecursive type
    system, so we can now properly count supertypes. It turns out it doesn't
    make much of a difference in the test outputs anyway.
    tlively authored Aug 14, 2024
    Configuration menu
    Copy the full SHA
    bcb83fd View commit details
    Browse the repository at this point in the history
  3. Heap type none requires GC (WebAssembly#6840)

    Since reference types only introduced function and extern references,
    all of the types in the `any` hierarchy require GC, including `none`.
    
    Fixes WebAssembly#6839.
    tlively authored Aug 14, 2024
    Configuration menu
    Copy the full SHA
    cde2a52 View commit details
    Browse the repository at this point in the history

Commits on Aug 15, 2024

  1. Configuration menu
    Copy the full SHA
    ad08022 View commit details
    Browse the repository at this point in the history
  2. [NFC] Clean up Literal copy constructor (WebAssembly#6841)

    Diff without whitespace is smaller.
    
    * HeapType::ext was handled in two places. The second place was wrong, but not reached.
    * Near the end all we have left are refs, so no need to check isRef etc.
    * Simplify the code to get the heap type once.
    kripken authored Aug 15, 2024
    Configuration menu
    Copy the full SHA
    d567578 View commit details
    Browse the repository at this point in the history
  3. Simplify validation of stale types (WebAssembly#6842)

    The previous rules for stale types were complicated and hard to
    remember: in general it was ok for result types to be further refinable
    as long as they were not refinable all the way to `unreachable`, but
    control flow structures had a carve-out and it was ok for them to be
    refinable all the way to unreachable.
    
    Simplify the rules so that further refinable result types are always ok,
    no matter what they can be refined to and no matter what kind of
    instruction is being validated. This will be much easier to remember and
    reason about.
    
    This relaxation of the rules strictly increases the set of valid IR, so
    no passes or tests need to be updated. It does make it possible for us
    to miss type refinement opportunities that previously would have been
    validation errors, but only in cases where non-control-flow instructions
    could have been refined all the way to unreachable, so the risk seems
    small.
    tlively authored Aug 15, 2024
    Configuration menu
    Copy the full SHA
    033a16e View commit details
    Browse the repository at this point in the history
  4. [NFC] Avoid v128 in rec groups with no other v128 uses (WebAssembly#6843

    )
    
    We don't properly validate that yet. E.g.:
    
    (module
     (rec
      (type $func (func))
      (type $unused (sub (struct (field v128))))
     )
     (func $func (type $func))
    )
    
    That v128 is not used, but it ends up in the output because it is in a rec group that is used.
    Atm we do not require that SIMD be enabled in such a case, which can trip up the fuzzer.
    
    Context: WebAssembly#6820. For now, modify the test that uncovered this.
    kripken authored Aug 15, 2024
    Configuration menu
    Copy the full SHA
    c2b4380 View commit details
    Browse the repository at this point in the history

Commits on Aug 16, 2024

  1. Testing: Add an env var to pick the V8 binary (WebAssembly#6836)

    Also we had a mix of os.environ.get and os.getenv. Prefer the former, as the default
    value does actual work, so it's a little more efficient to not run it unnecessarily. That is,
    os.getenv('X', work()) is less efficient than os.environ.get('X') or work().
    kripken authored Aug 16, 2024
    Configuration menu
    Copy the full SHA
    7209629 View commit details
    Browse the repository at this point in the history
  2. Implement table.init (WebAssembly#6827)

    Also use TableInit in the interpreter to initialize module's table
    state, which will now handle traps properly, fixing WebAssembly#6431
    kripken authored Aug 16, 2024
    Configuration menu
    Copy the full SHA
    958ff41 View commit details
    Browse the repository at this point in the history
  3. Fix direct comparisons with unshared basic heap types (WebAssembly#6845)

    Audit the remaining ocurrences of `== HeapType::` and fix those that did
    not handle shared types correctly. Add tests for some of the fixes;
    others are NFC but clarify the code.
    tlively authored Aug 16, 2024
    Configuration menu
    Copy the full SHA
    95a4d5d View commit details
    Browse the repository at this point in the history

Commits on Aug 17, 2024

  1. Add a pass for minimizing recursion groups (WebAssembly#6832)

    Most of our type optimization passes emit all non-public types as a
    single large rec group, which trivially ensures that different types
    remain different, even if they are optimized to have the same structure.
    Usually emitting a single large rec group is fine, but it also means
    that if the module is split, all of the types will need to be repeated
    in all of the split modules. To better support this use case, add a pass
    that can split the large rec group back into minimal rec groups, taking
    care to preserve separate type identities by emitting different
    permutations of the same group where possible or by inserting unused
    brand types to differentiate them.
    tlively authored Aug 17, 2024
    Configuration menu
    Copy the full SHA
    e058bfb View commit details
    Browse the repository at this point in the history

Commits on Aug 19, 2024

  1. [NFC] Use HeapType::getKind more broadly (WebAssembly#6846)

    Replace code that checked `isStruct()`, `isArray()`, etc. in sequence
    with uses of `HeapType::getKind()` and switch statements. This will make
    it easier to find the code that needs updating if/when we add new heap
    type kinds in the future. It also makes it much easier to find code that
    already needs updating to handle continuation types by grepping for
    "TODO: cont".
    tlively authored Aug 19, 2024
    Configuration menu
    Copy the full SHA
    0b05a3e View commit details
    Browse the repository at this point in the history
  2. Print explicit typeuses for non-MVP function types (WebAssembly#6851)

    We previously printed explicit typeuses (e.g. `(type $f)`) in function
    signatures when GC was enabled. But even when GC is not enabled,
    function types may use non-MVP features that require the explicit
    typeuse to be printed. Fix the printer to always print the explicit type
    use for such types.
    
    Fixes WebAssembly#6850.
    tlively authored Aug 19, 2024
    Configuration menu
    Copy the full SHA
    127844c View commit details
    Browse the repository at this point in the history
  3. Validate array.init_elem segment in IRBuilder (WebAssembly#6852)

    IRBuilder is responsible for validation involving type annotations on GC
    instructions because those type annotations may not be preserved in the
    built IR to be used by the main validator. For `array.init_elem`, we
    were not using the type annotation to validate the element segment,
    which allowed us to parse invalid modules when the reference operand was
    a nullref. Add the missing validation in IRBuilder and fix a relevant
    spec test.
    tlively authored Aug 19, 2024
    Configuration menu
    Copy the full SHA
    2c9c74d View commit details
    Browse the repository at this point in the history

Commits on Aug 20, 2024

  1. [Exceptions] Finish interpreter + optimizer support for try_table. (W…

    …ebAssembly#6814)
    
    * Add interpreter support for exnref values.
    * Fix optimization passes to support try_table.
    * Enable the interpreter (but not in V8, see code) on exceptions.
    sjrd authored Aug 20, 2024
    Configuration menu
    Copy the full SHA
    340ad71 View commit details
    Browse the repository at this point in the history

Commits on Aug 21, 2024

  1. Add the upstream spec testsuite as a submodule (WebAssembly#6853)

    Run the upstream tests by default, except for a large list of them that
    do not successfully run. Remove the local version of those that do
    successfully run where the local version is entirely subsumed by the
    upstream version.
    tlively authored Aug 21, 2024
    Configuration menu
    Copy the full SHA
    435eeea View commit details
    Browse the repository at this point in the history
  2. Fix encoding of heap type definitions (WebAssembly#6856)

    The leading bytes that indicate what kind of heap type is being defined
    are bytes, but we were previously treating them as SLEB128-encoded
    values. Since we emit the smallest LEB encodings possible, we were
    writing the correct bytes in output files, but we were also improperly
    accepting binaries that used more than one byte to encode these values.
    This was caught by an upstream spec test.
    tlively authored Aug 21, 2024
    Configuration menu
    Copy the full SHA
    9772dc6 View commit details
    Browse the repository at this point in the history
  3. [NFC] Triage spec test problems (WebAssembly#6857)

    Add comments to the spec test skip list briefly explaining why each
    skipped spec test must be skipped.
    tlively authored Aug 21, 2024
    Configuration menu
    Copy the full SHA
    adf53b3 View commit details
    Browse the repository at this point in the history
  4. Support ref.extern n in spec tests (WebAssembly#6858)

    Spec tests pass the value `ref.extern n`, where `n` is some integer,
    into exported functions that expect to receive externrefs and receive
    such values back out as return values. The payload serves to distinguish
    externrefs so the test can assert that the correct one was returned.
    
    Parse these values in wast scripts and represent them as externalized
    i31refs carrying the payload. We will need a different representation
    eventually, since some tests explicitly expect these externrefs to not
    be i31refs, but this suffices to get several new tests passing.
    
    To get the memory64 version of table_grow.wast passing, additionally fix
    the interpreter to handle growing 64-bit tables correctly.
    
    Delete the local versions of the upstream tests that can now be run
    successfully.
    tlively authored Aug 21, 2024
    Configuration menu
    Copy the full SHA
    7889abf View commit details
    Browse the repository at this point in the history
  5. [NFC] hash constant string as void* (WebAssembly#6863)

    possible-contents.h hashes the location for caught exnrefs by hashing an
    arbitrary string, "caught-exnref-location". It previously used
    `std::hash<const char*>` for this, but some standard library
    implementations report an error when this template instantiation is used
    because hashing the location of a string is almost never correct. In
    this case it is fine, so switch to using `std::hash<const void*>`.
    tlively authored Aug 21, 2024
    Configuration menu
    Copy the full SHA
    21ddb85 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    99db0d9 View commit details
    Browse the repository at this point in the history
  7. Add a string lowering mode disallowing non-UTF-8 strings (WebAssembly…

    …#6861)
    
    The best way to lower strings is via the "magic imports" API that uses
    the names of imported string globals as their values. This approach only
    works for valid UTF-8 strings, though. The existing
    string-lowering-magic-imports pass falls back to putting non-UTF-8
    strings in a JSON custom section, but this requires the runtime to
    support that custom section for correctness. To help catch errors early
    when runtimes do not support the strings custom section, add a new pass
    that uses magic imports and raises an error if there are any invalid
    strings.
    tlively authored Aug 21, 2024
    Configuration menu
    Copy the full SHA
    692e55c View commit details
    Browse the repository at this point in the history
  8. [NFC] Avoid quadratic time in StackIROptimizer::removeUnneededBlocks() (

    WebAssembly#6859)
    
    This is in quite ancient code, so it's a long-standing issue, but it got worse
    when we enabled StackIR in more situations (WebAssembly#6568), which made it more
    noticeable, I think.
    
    For example, testing on test_biggerswitch in Emscripten, the LLVM part
    is pretty slow too so the Binaryen slowdown didn't stand out hugely, but
    just doing
    
    wasm-opt --optimize-level=2 input.wasm -o output.wasm
    
    (that is, do no work, but set the optimize level to 2 so that StackIR opts
    are run) used to take 28 seconds (!). With this PR that goes down to less
    than 1.
    kripken authored Aug 21, 2024
    Configuration menu
    Copy the full SHA
    60bd610 View commit details
    Browse the repository at this point in the history
  9. [NFC] Avoid quadratic time when precomputing blocks (WebAssembly#6862)

    When precomputing fails on a child block of a parent block, there is no point
    to precompute the parent, as that will fail as well.
    
    This makes --precompute on Emscripten's test_biggerswitch go from 1.44
    seconds to 0.02 seconds (not a typo, that is 72x faster). The absolute number
    is not that big, but we do run this pass more than once, so it saves a noticeable
    chunk of time.
    kripken authored Aug 21, 2024
    Configuration menu
    Copy the full SHA
    2d99e10 View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2024

  1. [FP16] Add a feature flag for FP16. (WebAssembly#6864)

    Ensure the "fp16" feature is enabled for FP16 instructions.
    brendandahl authored Aug 22, 2024
    Configuration menu
    Copy the full SHA
    95a280f View commit details
    Browse the repository at this point in the history

Commits on Aug 26, 2024

  1. Support more reference constants in wast scripts (WebAssembly#6865)

    Spec tests use constants like `ref.array` and `ref.eq` to assert that
    exported function return references of the correct types. Support more
    such constants in the wast parser.
    
    Also fix a bug where the interpretation of `array.new_data` for arrays
    of packed fields was not properly truncating the packed data. Move the
    function for reading fields from memory from literal.cpp to
    wasm-interpreter.h, where the function for truncating packed data lives.
    
    Other bugs prevent us from enabling any more spec tests as a result of
    this change, but we can get farther through several of them before
    failing. Update the comments about the failures accordingly.
    tlively authored Aug 26, 2024
    Configuration menu
    Copy the full SHA
    dacc6e5 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b7af8da View commit details
    Browse the repository at this point in the history
  3. Fix null dereference in FunctionValidator (WebAssembly#6849)

    visitBlock() and validateCallParamsAndResult() both assumed they were
    running inside a function, but might be called on global code too. Calls
    and blocks are invalid in global positions, so we should error there, but
    must do so properly without a null deref.
    
    Fixes WebAssembly#6847
    Fixes WebAssembly#6848
    mtb0x1 authored Aug 26, 2024
    Configuration menu
    Copy the full SHA
    5018114 View commit details
    Browse the repository at this point in the history
  4. [NFC] Optimize ParamUtils::getUsedParams() (WebAssembly#6866)

    This constructed a LocalGraph, which computes the sets that reach each get. But
    all we need to know is which params are live, so instead we can do a liveness
    computation (which is just a boolean, not the list of sets). Also, it is simple to get
    the liveness computation to only work on the parameters and not all the locals,
    as a further optimization.
    
    Existing tests cover this, though I did find that the case of unreachability needed
    a new test.
    
    On a large testcase I am looking at, this makes --dae 17% faster.
    kripken authored Aug 26, 2024
    Configuration menu
    Copy the full SHA
    459bc07 View commit details
    Browse the repository at this point in the history

Commits on Aug 27, 2024

  1. Configuration menu
    Copy the full SHA
    6c2d0e2 View commit details
    Browse the repository at this point in the history
  2. Check for required actions when parsing wast (WebAssembly#6874)

    The parser function for `action` returned a `MaybeResult`, but we were
    treating it as returning a normal `Result` and not checking that it had
    contents in several places. Replace the current `action()` with
    `maybeAction()` and add a new `action()` that requires the action to be
    present.
    
    Fixes WebAssembly#6872.
    tlively authored Aug 27, 2024
    Configuration menu
    Copy the full SHA
    52118e5 View commit details
    Browse the repository at this point in the history
  3. Rename relaxed SIMD fma instructions to match spec. (WebAssembly#6876)

    The instructions relaxed_fma and relaxed_fnma have been renamed to
    relaxed_madd and relaxed_nmadd.
    
    
    https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md#binary-format
    brendandahl authored Aug 27, 2024
    Configuration menu
    Copy the full SHA
    e2ceaa5 View commit details
    Browse the repository at this point in the history

Commits on Aug 28, 2024

  1. [NFC] Refactor LocalGraph's core getSets API (WebAssembly#6877)

    Before we just had a map that people would access with localGraph.getSetses[get],
    while now it is a call localGraph.getSets(get), which more nicely hides the internal
    implementation details.
    
    Also rename getSetses => getSetsMap.
    
    This will allow a later PR to optimize the internals of this API.
    
    This is performance-neutral as far as I can measure. (We do replace a direct read
    from a data structure with a call, but the call is in a header and should always get
    inlined.)
    kripken authored Aug 28, 2024
    Configuration menu
    Copy the full SHA
    95ddd05 View commit details
    Browse the repository at this point in the history

Commits on Aug 29, 2024

  1. Ignore fp16 in the fuzzer (WebAssembly#6881)

    Add the feature flag in V8 invocations, but also disable the feature as it
    isn't quite ready yet.
    kripken authored Aug 29, 2024
    Configuration menu
    Copy the full SHA
    9924683 View commit details
    Browse the repository at this point in the history
  2. Move lit test temporary files to out/test/ (WebAssembly#6887)

    Previously for in-tree builds, they were put directly into test/, which
    unnecessarily pollutes the tree.
    tlively authored Aug 29, 2024
    Configuration menu
    Copy the full SHA
    aa75698 View commit details
    Browse the repository at this point in the history
  3. Add a utility for finding minimal topological sorts (WebAssembly#6884)

    Reuse the code implementing Kahn's topological sort algorithm with a new
    configuration that uses a min-heap to always choose the best available
    element.
    
    Also add wrapper utilities that can find topological sorts of graphs
    with arbitrary element types, not just indices.
    tlively authored Aug 29, 2024
    Configuration menu
    Copy the full SHA
    b63aead View commit details
    Browse the repository at this point in the history
  4. Simplify ReorderGlobals using new topological sort utils (WebAssembly…

    …#6885)
    
    Use the new TopologicalSort and MinTopologicalSortOf utilities instead
    of the old CRTP topological sort utility and a bespoke heap-based
    topological sort in ReorderGlobals. Since there is no longer a heap to
    pop from, the direction of the custom comparator is now much more
    intuitive.
    
    Further simplify the code by switching from tracking the new order of
    globals using a sequence of new indices to tracking the order using a
    sequence of old indices.
    
    This change also makes the pass about 20% faster on a large real-world
    module.
    tlively authored Aug 29, 2024
    Configuration menu
    Copy the full SHA
    871ff0d View commit details
    Browse the repository at this point in the history

Commits on Aug 31, 2024

  1. Configuration menu
    Copy the full SHA
    bc55a3e View commit details
    Browse the repository at this point in the history