Closed L-jasmine closed 11 months ago
Hello, I am a code review bot on flows.network. Here are my reviews of code commits in this PR.
Overall Summary:
In general, the pull request titled "Refactor/sdk preview" includes a variety of changes across different files. The change sets include adding attributes, fixing memory leaks, removing unused code, adding new files and functionality, modifying existing code, and making adjustments to dependencies.
Important Findings:
There are several potential issues and errors that need to be addressed, such as typos, misuse of attributes, unhandled error cases, and unclear changes without proper context or explanation.
There are significant refactorings throughout the codebase. It is important to carefully review these changes to ensure correctness and avoid introducing new bugs.
Some changes result in the introduction of new functionality, like managing socket writability and handling socket events, implementing a virtual file system, and adding timeout functionality. However, there are potential problems and lack of documentation to understand these changes fully.
The commit messages and pull request descriptions often lack context and explanation, making it difficult to understand the purpose and motivation behind the changes. It is recommended to provide more detailed information in the commit messages or pull request description.
Overall, the pull request shows a mix of potential issues, important findings, and new functionality. Addressing the potential problems and providing more documentation will be crucial for a comprehensive review.
Key changes:
#[form]
attribute to the Core
, Store
, Vm
, Func
, Mem
, Global
, Table
, Import
, Export
, Instance
, and Plugin
variants of the WasmEdgeError
enum.Potential problems:
Add #[form] for subtypes of WasmEdgeError
. It should be Add #[from] for subtypes of WasmEdgeError
.#[form]
attribute should be #[from]
.The key changes in this patch include:
One potential problem is the deletion of the Drop
implementation for ExportType
and Module
. This may cause memory leaks if the inner
field is not properly freed.
Another potential problem is the removal of code related to Externals
, including functions, globals, memory, and tables. This may impact the functionality of the codebase if these features were being used.
It is also worth noting that there are changes in a large number of files, indicating significant refactorings throughout the codebase. It would be important to review these changes in detail to ensure they are correct and do not introduce new bugs.
Key changes in the patch:
SocketWritable
to handle checking and setting socket writability.SocketWritableFuture
as a future for checking socket writability.writable()
method to SocketWritable
to asynchronously wait for the socket to become writable.writable()
method to AsyncWasiSocket
to set the socket as writable and await for it to become writable.readable()
method in AsyncWasiSocket
to use the readable()
method from AsyncWasiSocketInner
.readable()
method in AsyncWasiSocket
to return Ok(())
instead of Ok(None)
.readable()
method in AsyncWasiSocket
to clear the ready state of the socket after reading.writable
of type SocketWritable
to AsyncWasiSocket
.Potential problems:
readable()
method of AsyncWasiSocket
, the match
expression on r
does not handle the case when r
is Err(e)
.wait_fd()
function, the handler
closure does not properly handle the case when the Result
is an error. The current implementation sets the error
field of __wasi_event_t
but does not handle it in the return value.AsyncWasiSocket
struct now has a new field writable
which is not used in the existing code. It is unclear how this field is intended to be used.AsyncWasiSocket::readable()
to clear the ready state of the socket after reading may have unintended consequences if the clearing of ready state is not necessary or if it is done at the wrong time.Overall, the changes seem to introduce new functionality for managing socket writability and handle socket events. However, there are potential problems that need to be addressed and more information is needed to understand the use case for the new writable
field in AsyncWasiSocket
.
Key changes:
socket.writable.set_writable();
to the code.Potential problems:
Overall, the changes seem simple and isolated to one file in the project. However, without further information, it is difficult to assess the impact of this change and whether it is necessary or if there might be any unintended side effects. It is recommended to ask the author for more details about the change.
Key Changes:
args_get
function and two lines in the environ_get
function.Potential Problems:
len
argument should be the length of the copied slice plus one for the null terminator. This might cause incorrect behavior or buffer overflows.Key changes in this GitHub patch:
async_tokio.rs
, the state
field of the AsyncWasiSocket
struct has been changed from WasiSocketState
to Box<WasiSocketState>
.sync.rs
, the seek
method of the WasiFile
struct has been refactored to set the seek position before reading or writing to the file.mod.rs
, the WasiCtx
struct was modified. The vfs
field was changed from an Arc<RwLock<ObjectPool<VFD>>>
to an ObjectPool<VFD>
. The push_preopen
, insert_vfd
, remove_closed
, remove
, get
, and get_mut
methods were modified to use the new vfs
field directly instead of the RwLock
. The vfs
field initialization was also modified to directly assign the vfs
parameter value.Potential problems:
state
field in AsyncWasiSocket
is changed to a Box<WasiSocketState>
. This change could have impacts on other parts of the codebase that rely on this field being directly accessible without indirection.sync.rs
could introduce bugs if the seek
position is not correctly set before reading or writing to the file.WasiCtx
struct and related methods could introduce synchronization issues since the Arc<RwLock<ObjectPool<VFD>>>
has been replaced with a direct ObjectPool<VFD>
. This change could impact the thread-safety of the code if multiple threads access the vfs
field simultaneously.Key changes:
Potential problems:
Key changes:
WasiStdin
struct has been modified to store a boxed trait object (Read + Send
) instead of a plain struct. The Debug
trait implementation has also been changed.WasiStdout
struct has been modified similarly to WasiStdin
.WasiStdin
and WasiStdout
.Potential problems:
WasiStdin
and WasiStdout
introduce new traits (WasiVirtualFile
and WasiVirtualNode
) and methods, but there is no explanation or documentation provided for what these traits represent or how they are intended to be used. It would be helpful to add some comments or documentation to clarify their purpose.WasiStdin
and WasiStdout
seem to be incomplete. Some methods have been implemented, but others (like fd_read
in WasiStdout
and fd_tell
and fd_seek
in WasiStdin
) are stubbed out and return error codes. It's important to ensure that all required methods are implemented correctly and consistently.WasiVirtualFile
and WasiVirtualNode
implementations and the behavior of the WasiStdin
and WasiStdout
structs.Key changes in the patch:
run_func_with_timeout
and run_func_async_with_timeout
functions have been updated.timeout_sec
argument has been replaced with deadline
argument of type std::time::SystemTime
.timeout
argument in call_func_with_timeout
function has been changed to std::time::Duration
.Potential problems:
Key changes:
registered
field in the Validator
struct has been removed.registered
field is no longer checked in the Drop
implementation.Potential problems:
registered
field may have unintended consequences. It is possible that the registered
field was used somewhere else in the codebase, and its removal could lead to unexpected behavior or bugs. It would be good to review the codebase and ensure that there are no dependencies on this field before merging this patch.registered
in the Drop
implementation could result in a double deletion of the inner
resource if the validator is not registered but the inner
resource is non-null. This could lead to memory corruption or crashes. It's important to ensure that the inner
resource is properly managed and that this change does not introduce any memory management issues.Key changes in the patch:
Potential problems:
Key changes:
wasmedge-sys
crate.Potential problems:
Overall, the code changes seem reasonable, but further clarification and tests would be beneficial.
Key Changes:
run_func_with_timeout
method in the Vm
struct has been modified.Potential Problems:
run_func_with_timeout
method for musl libc when the target OS is Linux.Suggestions for Improvement:
Key changes in the patch:
crates/wasmedge-sys/src/async/module.rs
, commented out the creation of an async function.crates/wasmedge-sys/src/frame.rs
, added a new method memory_mut
to retrieve a mutable reference to a memory instance by its index.crates/wasmedge-sys/src/store.rs
, updated the documentation comment to clarify the purpose of the Store
struct.src/async/import.rs
and src/import.rs
, updated the documentation comment to clarify the purpose of the ImportObjectBuilder
struct.src/store.rs
, updated the documentation comment to clarify the purpose of the Store
struct.Potential problems:
crates/wasmedge-sys/src/async/module.rs
suggests that an async function was commented out. If this function is needed, its removal may cause functionality issues.memory_mut
in crates/wasmedge-sys/src/frame.rs
is not documented or explained further. It would be helpful to provide more context and examples for its usage.src/async/import.rs
, src/import.rs
, and src/store.rs
could be more detailed and provide more examples to help users understand their purpose and usage.Key changes:
From<&ffi::WasmEdge_String> for String
implementation in the types.rs
file has been refactored.&ffi::WasmEdge_String
directly to &std::ffi::CStr
and then used to_string_lossy()
to convert it to an owned String
.s.Buf
pointer to a raw byte slice and uses String::from_utf8()
to convert it to a String
.Potential problems:
unsafe
code to directly manipulate raw pointers.s.Buf
pointer is not valid or if the slice length does not match the actual length of the string.String::from_utf8().unwrap_or_default()
which returns an empty string if the conversion fails. It might be worth considering whether this is the desired behavior or if a different error handling approach should be used.Overall, the refactoring seems reasonable, but it is important to carefully evaluate the safety and correctness of the unsafe
code and consider error handling.
Key changes:
wrap_sync_wasi_fn
and wrap_async_wasi_fn
functions have been removed.HostFn
type has been removed.Potential problems:
wrap_sync_wasi_fn
and wrap_async_wasi_fn
functions may impact functionality. It's important to review the changes related to these functions and ensure that any new implementations are correct.HostFn
type may also impact functionality. Review any changes related to the HostFn
type and ensure that any new implementations are correct.src/import.rs
. Make sure the removal of this file is intentional and doesn't affect the project's functionality.Key changes in this patch include:
WasiModule
struct is changed from using composition to using a tuple struct with an Instance
field.Drop
implementation for WasiModule
is removed.AsRef
and AsMut
trait implementations are added for WasiModule
.WasiModule
implementation are modified to use the Instance
field instead of the inner
field.Potential problems:
WasiModule
struct's Clone
trait implementation is removed. It should be verified if this is intentional or if it needs to be re-implemented.Drop
implementation for WasiModule
is removed, which means that the underlying InnerInstance
may not be properly cleaned up. This change should be reviewed to ensure that there are no memory leaks.WasiModule
struct now exposes the Instance
field directly, which could potentially lead to misuse or unintended modifications. This change should be reviewed to ensure that it doesn't introduce any issues related to encapsulation or safety.WasiModule
implementation are modified to use the Instance
field directly. This change should be reviewed to ensure that it doesn't introduce any logic errors or unexpected behavior.Overall, the changes seem to be focused on refactoring the WasiModule
struct and its usage. It is important to thoroughly review the changes to ensure that they don't introduce any issues or regressions.
Key Changes:
use crate::AsInstance;
in the test_plugin_wasmedge_process
and test_plugin_wasi_crypto
functions.result.is_some()
assertions with result.is_ok()
assertions.unwrap()
instead of is_some()
.Potential Problems:
use crate::AsInstance;
import may not be necessary in the test_plugin_wasmedge_process
and test_plugin_wasi_crypto
functions. The reviewer should verify if this import is required for the tests to function correctly.unwrap()
method, assuming the results will always be Some
. There is no error handling for cases where the results may be None
. The reviewer should consider adding appropriate error handling or validating the assumptions made in the tests.Key Changes:
.github/workflows/ci-build.yml
file, the command cargo test
has been modified to include the --skip test_vmbuilder
flag.Potential Problems:
test_vmbuilder
test on Fedora. This change might have been made for a valid reason, but it's unclear from the provided patch why this test is being skipped. It would be helpful to have some additional context or a justification for skipping this test.Overall, this change seems to be a minor adjustment to the CI workflow.
Key changes in the patch:
FuncRef
has been changed.externref
.Potential problems:
FuncRef
extraction is not complete and is using externref
instead.Suggestions:
FuncRef
extraction and ensure it aligns with the project requirements.externref
, make sure this temporary implementation is properly documented and communicated with other developers.FuncRef
extraction or removing the unused code.The key changes in this pull request are:
examples/wasmedge-sys
directorysrc/async/vm.rs
filesrc/compiler.rs
filesrc/executor.rs
filesrc/module.rs
filesrc/vm.rs
filePotential problems that can be found in this patch are:
Overall, a clearer explanation of the changes, their purpose, and their impact would be beneficial for a thorough review of this pull request.
Refactor the SDK to resolve memory-unsafe bugs caused by its usage.
See https://github.com/WasmEdge/wasmedge-rust-sdk/pull/83