Repository: bytecodealliance/wasmtime
Pull request #5603 (2023-01-20 01:33:30)

fix issue 5525.
this fix issue #5525 


Patch:
diff --git a/README.md b/README.md
index 3f7c30213..d59c36806 100644
--- a/README.md
+++ b/README.md
@@ -108,7 +108,9 @@ Hello, world!
 ## Language Support
 
 You can use Wasmtime from a variety of different languages through embeddings of
-the implementation:
+the implementation.
+
+Languages supported by the Bytecode Alliance:
 
 * **[Rust]** - the [`wasmtime` crate]
 * **[C]** - the [`wasm.h`, `wasi.h`, and `wasmtime.h` headers][c-headers], [CMake](crates/c-api/CMakeLists.txt) or [`wasmtime` Conan package]
@@ -118,6 +120,10 @@ the implementation:
 * **[Go]** - the [`wasmtime-go` repository]
 * **[Ruby]** - the [`wasmtime` gem]
 
+Languages supported by the community:
+
+* **[Elixir]** - the [`wasmex` hex package]
+
 [Rust]: https://bytecodealliance.github.io/wasmtime/lang-rust.html
 [C]: https://bytecodealliance.github.io/wasmtime/examples-c-embed.html
 [`wasmtime` crate]: https://crates.io/crates/wasmtime
@@ -133,6 +139,8 @@ the implementation:
 [`wasmtime-cpp` Conan package]: https://conan.io/center/wasmtime-cpp
 [Ruby]: https://bytecodealliance.github.io/wasmtime/lang-ruby.html
 [`wasmtime` gem]: https://rubygems.org/gems/wasmtime
+[Elixir]: https://docs.wasmtime.dev/lang-elixir.html
+[`wasmex` hex package]: https://hex.pm/packages/wasmex
 
 ## Documentation
 
diff --git a/RELEASES.md b/RELEASES.md
index 30f6cd11a..8e7f581f4 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -12,7 +12,7 @@ Unreleased.
 
 ## 5.0.0
 
-Unreleased.
+Released 2023-01-20
 
 ### Added
 
diff --git a/cranelift/codegen/src/isa/riscv64/inst.isle b/cranelift/codegen/src/isa/riscv64/inst.isle
index 31fdad31a..2031cf924 100644
--- a/cranelift/codegen/src/isa/riscv64/inst.isle
+++ b/cranelift/codegen/src/isa/riscv64/inst.isle
@@ -1028,7 +1028,7 @@
     ((tmp Reg (gen_extend r $true from_bits 64))
       (tmp2 Reg (alu_rrr (AluOPRRR.Slt) tmp (zero_reg)))
       (high Reg (gen_extend tmp2 $true 1 64)))
-    (value_regs (gen_move2 r $I64 $I64) high)))
+    (value_regs (gen_move2 tmp $I64 $I64) high)))
 
 
 ;;;; for I128 unsigned extend.
diff --git a/crates/component-macro/src/bindgen.rs b/crates/component-macro/src/bindgen.rs
index 435abbb42..d9caff8f3 100644
--- a/crates/component-macro/src/bindgen.rs
+++ b/crates/component-macro/src/bindgen.rs
@@ -226,9 +226,23 @@ impl Parse for Opt {
 }
 
 fn trappable_error_field_parse(input: ParseStream<'_>) -> Result<(String, String, String)> {
-    let interface = input.parse::<Ident>()?.to_string();
+    // Accept a Rust identifier or a string literal. This is required
+    // because not all wit identifiers are Rust identifiers, so we can
+    // smuggle the invalid ones inside quotes.
+    fn ident_or_str(input: ParseStream<'_>) -> Result<String> {
+        let l = input.lookahead1();
+        if l.peek(syn::LitStr) {
+            Ok(input.parse::<syn::LitStr>()?.value())
+        } else if l.peek(syn::Ident) {
+            Ok(input.parse::<syn::Ident>()?.to_string())
+        } else {
+            Err(l.error())
+        }
+    }
+
+    let interface = ident_or_str(input)?;
     input.parse::<Token![::]>()?;
-    let type_ = input.parse::<Ident>()?.to_string();
+    let type_ = ident_or_str(input)?;
     input.parse::<Token![:]>()?;
     let rust_type = input.parse::<Ident>()?.to_string();
     Ok((interface, type_, rust_type))
diff --git a/docs/lang-elixir.md b/docs/lang-elixir.md
new file mode 100644
index 000000000..d961f2ede
--- /dev/null
+++ b/docs/lang-elixir.md
@@ -0,0 +1,43 @@
+# Using WebAssembly from Elixir
+
+Wasmtime [is available on Hex](https://hex.pm/packages/wasmex) and can
+be used programmatically to interact with Wasm modules. This guide will go over
+installing the wasmex package and running a simple Wasm module from Elixir.
+
+## Getting started and simple example
+
+First, copy this example WebAssembly text module into the current directory. It exports
+a function for calculating the greatest common denominator of two numbers.
+
+```wat
+{{#include ../examples/gcd.wat}}
+```
+
+The library has a Rust-based native extension, but thanks to `rustler_precompiled`, you
+should not have to compile anything. It'll just work!
+
+This WAT file can be executed in `iex`:
+
+```elixir
+Mix.install([:wasmex])
+bytes = File.read!("gcd.wat")
+{:ok, pid} = Wasmex.start_link(%{bytes: bytes}) # starts a GenServer running a WASM instance
+Wasmex.call_function(pid, "gcd", [27, 6])
+```
+
+The last command should output:
+
+```elixir
+iex(5)> Wasmex.call_function(pid, "gcd", [27, 6])
+{:ok, [3]}
+```
+
+If this is the output you see, congrats! You've successfully ran your first
+WebAssembly code in Elixir!
+
+## More examples and contributing
+
+To learn more, check out an [another example](https://github.com/tessi/wasmex#example)
+and the [API documentation](https://hexdocs.pm/wasmex/Wasmex.html).
+If you have any questions, do not hesitate to open an issue on the
+[GitHub repository](https://github.com/tessi/wasmex).
diff --git a/docs/lang.md b/docs/lang.md
index ae3d0a13c..94e38d1b0 100644
--- a/docs/lang.md
+++ b/docs/lang.md
@@ -11,3 +11,4 @@ through a C API for a number of other languages too:
 * [Go](lang-go.md)
 * [Bash](lang-bash.md)
 * [Ruby](lang-ruby.md)
+* [Elixir](lang-elixir.md)


Test patch:
diff --git a/cranelift/filetests/filetests/isa/riscv64/extend-op.clif b/cranelift/filetests/filetests/isa/riscv64/extend-op.clif
index 595ef6a8d..9dfc4f2c4 100644
--- a/cranelift/filetests/filetests/isa/riscv64/extend-op.clif
+++ b/cranelift/filetests/filetests/isa/riscv64/extend-op.clif
@@ -66,8 +66,8 @@ block0(v0: i32):
 }
 
 ; block0:
-;   sext.w t2,a0
-;   slt a1,t2,zero
+;   sext.w a0,a0
+;   slt a1,a0,zero
 ;   sext.b1 a1,a1
 ;   ret
 
@@ -89,8 +89,8 @@ block0(v0: i16):
 }
 
 ; block0:
-;   sext.h t2,a0
-;   slt a1,t2,zero
+;   sext.h a0,a0
+;   slt a1,a0,zero
 ;   sext.b1 a1,a1
 ;   ret
 
@@ -112,8 +112,8 @@ block0(v0: i8):
 }
 
 ; block0:
-;   sext.b t2,a0
-;   slt a1,t2,zero
+;   sext.b a0,a0
+;   slt a1,a0,zero
 ;   sext.b1 a1,a1
 ;   ret
 
diff --git a/cranelift/filetests/filetests/runtests/issue5525.clif b/cranelift/filetests/filetests/runtests/issue5525.clif
new file mode 100644
index 000000000..1b34da2cb
--- /dev/null
+++ b/cranelift/filetests/filetests/runtests/issue5525.clif
@@ -0,0 +1,12 @@
+test interpret
+test run
+target riscv64
+
+function %a(i16) -> i128 system_v {
+block0(v0: i16):
+    v1 = rotl v0, v0
+    v2 = sextend.i128 v1
+    return v2
+}
+
+; run: %a(-32718) == 202
\ No newline at end of file
diff --git a/tests/all/component_model/bindgen/results.rs b/tests/all/component_model/bindgen/results.rs
index 995a2e528..82e318948 100644
--- a/tests/all/component_model/bindgen/results.rs
+++ b/tests/all/component_model/bindgen/results.rs
@@ -373,7 +373,9 @@ mod record_error {
                 record-error: func(a: float64) -> result<float64, e2>
             }
         }",
-        trappable_error_type: { imports::e2: TrappableE2 }
+        // Literal strings can be used for the interface and typename fields instead of
+        // identifiers, because wit identifiers arent always Rust identifiers.
+        trappable_error_type: { "imports"::"e2": TrappableE2 }
     });
 
     #[test]