Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Towards Wasm Component Model #5

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

Closed
wants to merge 41 commits into from
Closed

Towards Wasm Component Model #5

wants to merge 41 commits into from

Conversation

tanishiking
Copy link

@tanishiking tanishiking commented Dec 6, 2024

WIT support progress (for myself)

Type store stack store memory load stack load memory
bool ✅ import roundtrip ✅ export tupled values ✅ import roundtirp ✅ import tupled values
u8 - u64 ✅ import roundtrip ✅ export tupled values ✅ import roundtirp ✅ import tupled values
s8 - s64 ✅ import roundtrip ✅ export tupled values ✅ import roundtirp ✅ import tupled values
f32 ✅ import roundtrip ✅ export tupled values ✅ import roundtirp ✅ import tupled values
f64 ✅ import roundtrip ✅ export tupled values ✅ import roundtirp ✅ import tupled values
char ✅ import roundtrip ✅ export tupled values ✅ import roundtirp ✅ import tupled values
string ✅ import roundtrip export roundtrip export roundtrip ✅ import roundtrip
list ☐ import roundtrip export roundtrip export roundtrip ☐ import roundtrip
record ✅ import roundtrip export roundtrip export roundtrip ✅ import roundtrip
tuple ✅ import roundtrip export roundtrip export roundtrip ✅ import roundtrip
variant ✅ import roundtrip export roundtrip export roundtrip ✅ import roundtrip
enum ✅ import roundtrip export roundtrip export roundtrip ✅ import roundtrip
option ✅ import roundtrip export roundtrip export roundtrip ✅ import roundtrip
result ✅ import roundtrip export roundtrip export roundtrip ✅ import roundtrip
flags ✅ import roundtrip ✅ export tupled values ✅ import roundtirp ✅ import tupled values
resource ☐ import roundtrip ☐ import roundtirp

To enable running `println("Hello world")` on stand-alone Wasm with WASIp2,
commented out the transformation cases for IR nodes related to JS interop
in `wasmemitter` so that any JS-related IR would result in a linking error.
Additionally, converted several standard library implementations with JS
dependencies into pure Scala.
Also removed js-string-builtins imports
concat is so slow, we need to make string concat to be just pointer
moving
Now, there's no global imports

- Derive boxed float/double/boolean/integer
- Derive boxed unit (for undef)
- Stub idHashCode (we need a proper impl)
This fmod implementation doesn't conform the spec
- Swap the arguments of `==` in `TestImports`. It seems we encountered a cast failure when casting the itables of `Variants`. This needs to be fixed later.
- Add a function to dump memory content for debugging.
- Fix `relloc` to prevent freeing memory when `newSize <= 0`. We shouldn't free the memory segment, for example, when the host tries to allocate an empty string.
- `genLoadMemory` now no longer moves `ptr`; it simply copies the pointer value and moves it locally. Moving the pointer globally was error-prone.
- Avoid storing `VoidType` in variants.
Instead of using malloc/free for dynamic memory allocation, this change introduces
a simple and efficient memory management model based on a global stack pointer.

- Memory allocation is done by incrementing `stackPointer`
  by the requested size, (ensuring 8-byte alignment for now).
- Memory deallocation is performed by restoring `stackPointer`
  to its previous value.
This approach avoids fragmentation and simplifies memory management.
Represents bitflags in the Component Model using a final case class
where all fields are of type `Boolean`.

For example:

```scala
@ComponentFlags
final case class F1(
  b0: Boolean, b1: Boolean, b2: Boolean, b3: Boolean,
  b4: Boolean, b5: Boolean, b6: Boolean, b7: Boolean
)
```

Is there a better alternative bitflags representation in Scala?
Note that these interfaces must also be usable in `javalib`,
meaning Scala libs (e.g. Scala's `Enumeration`) cannot be used.

A possible workaround is to define a type alias:

```scala
type Flags = Int
```

This allows function signatures to use `Flags`, which will be interpreted as a flag in the Component Model.
For example:

```scala
def roundtripFlags(a: Flags): Flags = cm.native
```

When an `Int` is passed as an argument, it will be serialized/deserialized as a flag according to the Component Model's specifications.
Enabling GC causes an illegal instruction error,
bytecodealliance/wasmtime#10181
and in rare cases, the content of array/struct changes unexpectedly
during execution (though I haven't been able to create a
reproducible test case for this).
For now, continue development with `-C collector=null`.
Still, methods on Long needs to use non-RuntimeLong methods though
constructor - `apply` method in companion object
static methods - methods in companion object
@tanishiking tanishiking closed this Apr 6, 2025
@tanishiking tanishiking deleted the component branch April 6, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant