Skip to content

Instantly share code, notes, and snippets.

[package]
name = "fannkuch"
version = "0.1.0"
edition = "2021"
[profile.release]
lto = "yes"
panic = "abort"
opt-level = "s"

Trying to avoid quadratic work in 1b

(context: WebAssembly/function-references#44)

An idea I've had is to annotate validated branches. The key thing is that the set of validated branch targets is monotonic - just like the set of set locals. That is, once we see that a branch to $b validates, any subsequent branch must also validate, since we can only add more locals that are set. So as an optimization, the validator could track those until the end of the current block. That basically means to handle the set of valid branch targets in a 1a-like manner, and could be a nice speedup on stuff like this:

  (br_if $b ..) ;; Linear time here.
  (br_if $b ..) ;; But constant time here
  (br_if $b ..) ;; and here!

Example of Wasm GC non-nullable variations on the "defer" option

Imagine this source code:

func foo() {
  var ref: A = ..some non-null result..;
  bar(ref, ref);
}
@kripken
kripken / NonNullableLocals.markdown
Last active July 26, 2022 07:53
Options for Non-Nullable Locals in Wasm GC

Options for Non-Nullable Locals in Wasm GC

This document attempts to summarize the current state of discussions around non-nullable locals in Wasm GC, as of late June 2022. To do so I re-read in their entirety the main thread on this topic as well as adjacent ones, and this document is an attempt to compare the main options being discussed and their tradeoffs, with links to the relevant parts of those discussions. This is far from a perfect document, in particular because I do not completely grasp some of the more subtle points being debated. But hopefully this document is helpful as a summary of where we are at a high level. Please let me know if I missed or misunderstood anything!

Background (that might be mostly useful for people not already involved in the discussions): Why do we want non-nullabile locals in wasm at all? In theo

=================================================================
==2342311==ERROR: AddressSanitizer: heap-use-after-free on address 0x6030004541e4 at pc 0x7ff218ebce95 bp 0x7ff1fe2bc850 sp 0x7ff1fe2bc848
READ of size 4 at 0x6030004541e4 thread T6
#0 0x7ff218ebce94 in wasm::Type::isTuple() const (/bin/../lib/libbinaryen.so+0x125e0e94)
#1 0x7ff218fa852b in wasm::TypeBuilder::build() (/bin/../lib/libbinaryen.so+0x126cc52b)
#2 0x7ff218fbda5f in wasm::Type::getLeastUpperBound(wasm::Type, wasm::Type) (/bin/../lib/libbinaryen.so+0x126e1a5f)
#3 0x7ff2186f5006 in wasm::If::finalize() (/bin/../lib/libbinaryen.so+0x11e19006)
#4 0x56004b397f60 in wasm::Walker<wasm::ReFinalize, wasm::OverriddenVisitor<wasm::ReFinalize, void> >::walk(wasm::Expression*&) (/bin/wasm-opt+0xce3f60)
#5 0x7ff2178918ed in wasm::RemoveUnusedBrs::doWalkFunction(wasm::Function*) (/bin/../lib/libbinaryen.so+0x10fb58ed)
#6 0x7ff2178973ec in wasm::WalkerPass<wasm::PostWalker<wasm::RemoveUnusedBrs, wasm::Visitor<wasm::Remove
#include "a.h"
void a() {
data = 42;
}
commit 972d6299672f4508c805af5efd886bb87b0a22fe
Author: Alon Zakai <azakai@google.com>
Date: Tue Apr 5 16:50:33 2022 -0700
wip
diff --git a/src/passes/ConstantFieldPropagation.cpp b/src/passes/ConstantFieldPropagation.cpp
index e4e01dc0e..76f64535c 100644
--- a/src/passes/ConstantFieldPropagation.cpp
+++ b/src/passes/ConstantFieldPropagation.cpp

Emscripten as a linker for Zig and C

This shows how to build a nontrivial program using Zig+Emscripten or C+Emscripten. In both cases Emscripten is only used as a linker, that is the frontend is either zig or clang.

"Nontrivial" here means the program uses interesting Emscripten features:

  • Asyncify
  • Full GLES3 support
  • GLFW3 support
/*
* Copyright 2011 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
//
// Build with
//
// -pthread -s PROXY_TO_PTHREAD -s EXIT_RUNTIME
//
#include <stdlib.h>
#include <emscripten.h>
#include <emscripten/threading.h>