Skip to content

Commit 095ac0a

Browse files
committed
refactor(core): apply widespread updates and fixes across WRT modules
1 parent 2a4ff54 commit 095ac0a

File tree

239 files changed

+6533
-5447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+6533
-5447
lines changed

example/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use std::fs;
2-
use std::path::Path;
1+
use std::{fs, path::Path};
32

43
fn main() {
54
// Tell Cargo to rerun this build script if the WIT files change

example/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![warn(clippy::missing_panics_doc)]
66

77
use std::cell::{Cell, RefCell};
8+
89
use wit_bindgen::generate;
910

1011
generate!({

test-control-instructions/src/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ extern crate std;
77
extern crate alloc;
88

99
// Import appropriate types based on environment
10-
#[cfg(feature = "std")]
11-
use std::vec::Vec;
12-
1310
#[cfg(all(not(feature = "std"), feature = "alloc"))]
1411
use alloc::vec::Vec;
12+
#[cfg(feature = "std")]
13+
use std::vec::Vec;
1514

1615
use wrt_decoder::instructions::{encode_instruction, parse_instruction};
1716
use wrt_test_registry::{assert_eq_test, assert_test, register_test};

wrt-component/examples/component_graph_view.rs

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
use std::env;
2-
use std::fmt::Write as FmtWrite;
3-
use std::fs;
4-
use std::io;
1+
use std::{env, fmt::Write as FmtWrite, fs, io};
52

3+
use crossterm::{
4+
event::{self, Event, KeyCode, KeyEventKind},
5+
terminal::{disable_raw_mode, enable_raw_mode},
6+
};
7+
use ratatui::{
8+
layout::{Alignment, Constraint, Direction, Layout, Rect},
9+
prelude::*,
10+
style::{Color, Modifier, Style, Stylize},
11+
widgets::{Block, Borders, List, ListItem, Paragraph, StatefulWidget, Widget},
12+
};
13+
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};
14+
use tui_nodes::{Connection, LineType, NodeGraph, NodeLayout};
615
use wrt_component::component::{
716
AliasInfo, Component, ComponentSummary, CoreInstanceInfo, CoreModuleInfo, ExtendedExportInfo,
817
ExtendedImportInfo, ModuleExportInfo, ModuleImportInfo,
918
};
1019
use wrt_decoder::ProducersSection;
1120
use wrt_error::{Error, Result};
12-
13-
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
14-
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
15-
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
16-
use ratatui::prelude::*;
17-
use ratatui::style::{Color, Modifier, Style, Stylize};
18-
use ratatui::widgets::{Block, Borders, List, ListItem, Paragraph, StatefulWidget, Widget};
19-
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};
20-
use tui_nodes::{Connection, LineType, NodeGraph, NodeLayout};
2121
use wrt_format::module::ImportDesc;
2222

2323
/// Main state struct for the application
@@ -760,7 +760,8 @@ impl App {
760760
graph
761761
}
762762

763-
/// Build the details graph showing detailed information about a specific entity
763+
/// Build the details graph showing detailed information about a specific
764+
/// entity
764765
fn build_details_graph(&self, width: u16, height: u16) -> NodeGraph<'static> {
765766
let mut nodes = Vec::new();
766767
let mut connections = Vec::new();
@@ -948,7 +949,8 @@ impl App {
948949

949950
// Create detailed debug content
950951
let component_info = format!(
951-
"Component file size: {}\nModules: {}\nInstances: {}\nImports: {}\nExports: {}\nAliases: {}",
952+
"Component file size: {}\nModules: {}\nInstances: {}\nImports: {}\nExports: \
953+
{}\nAliases: {}",
952954
self.component_bytes.as_ref().map_or(0, |b| b.len()),
953955
self.component_summary.core_modules_count,
954956
self.component_summary.core_instances_count,
@@ -1113,7 +1115,8 @@ impl App {
11131115
% if self.debug_mode {
11141116
SelectedView::iter().count()
11151117
} else {
1116-
SelectedView::iter().count() - 1 // Skip Debug view when not in debug mode
1118+
SelectedView::iter().count() - 1 // Skip Debug view when
1119+
// not in debug mode
11171120
};
11181121
self.selected_view =
11191122
SelectedView::from_repr(next_idx).unwrap_or(self.selected_view);
@@ -1123,7 +1126,8 @@ impl App {
11231126
let max_idx = if self.debug_mode {
11241127
SelectedView::iter().count()
11251128
} else {
1126-
SelectedView::iter().count() - 1 // Skip Debug view when not in debug mode
1129+
SelectedView::iter().count() - 1 // Skip Debug view when not
1130+
// in debug mode
11271131
};
11281132
let prev_idx = if current_idx == 0 { max_idx - 1 } else { current_idx - 1 };
11291133
self.selected_view =
@@ -1257,20 +1261,28 @@ impl App {
12571261

12581262
// Render status bar
12591263
let mut status_text = match self.selected_view {
1260-
SelectedView::Overview =>
1261-
"1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode | q: Quit".to_string(),
1262-
SelectedView::Modules =>
1263-
"1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode | ↑↓: Select Module | Enter: Details | q: Quit".to_string(),
1264-
SelectedView::Imports =>
1265-
"1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode | ↑↓: Select Import | Enter: Details | q: Quit".to_string(),
1266-
SelectedView::Exports =>
1267-
"1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode | ↑↓: Select Export | Enter: Details | q: Quit".to_string(),
1268-
SelectedView::Producers =>
1269-
"1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode | ↑↓: Select Producer | Enter: View Producer Details (Languages, Tools, SDKs) | q: Quit".to_string(),
1270-
SelectedView::Details =>
1271-
"1-6: Switch Views | Tab/←→: Navigate Views | q: Quit".to_string(),
1272-
SelectedView::Debug =>
1273-
"1-7: Switch Views | Tab/←→: Navigate Views | q: Quit".to_string(),
1264+
SelectedView::Overview => {
1265+
"1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode | q: Quit".to_string()
1266+
}
1267+
SelectedView::Modules => "1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode \
1268+
| ↑↓: Select Module | Enter: Details | q: Quit"
1269+
.to_string(),
1270+
SelectedView::Imports => "1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode \
1271+
| ↑↓: Select Import | Enter: Details | q: Quit"
1272+
.to_string(),
1273+
SelectedView::Exports => "1-6: Switch Views | Tab/←→: Navigate Views | f: Focus Mode \
1274+
| ↑↓: Select Export | Enter: Details | q: Quit"
1275+
.to_string(),
1276+
SelectedView::Producers => "1-6: Switch Views | Tab/←→: Navigate Views | f: Focus \
1277+
Mode | ↑↓: Select Producer | Enter: View Producer Details \
1278+
(Languages, Tools, SDKs) | q: Quit"
1279+
.to_string(),
1280+
SelectedView::Details => {
1281+
"1-6: Switch Views | Tab/←→: Navigate Views | q: Quit".to_string()
1282+
}
1283+
SelectedView::Debug => {
1284+
"1-7: Switch Views | Tab/←→: Navigate Views | q: Quit".to_string()
1285+
}
12741286
};
12751287

12761288
// Modify status bar text to include debug key when debug mode is enabled
@@ -1386,7 +1398,8 @@ fn main() -> io::Result<()> {
13861398
return Ok(());
13871399
}
13881400

1389-
// Find the component path (first argument that's not a flag or the program name)
1401+
// Find the component path (first argument that's not a flag or the program
1402+
// name)
13901403
let component_path = match args
13911404
.iter()
13921405
.find(|arg| !arg.starts_with('-') && !arg.ends_with("component_graph_view"))
@@ -1520,7 +1533,11 @@ fn main() -> io::Result<()> {
15201533
println!(" No producers section found in module #{}", idx);
15211534
}
15221535
Err(e) => {
1523-
println!(" Error extracting producers section from module #{}: {}", idx, e);
1536+
println!(
1537+
" Error extracting producers section from module \
1538+
#{}: {}",
1539+
idx, e
1540+
);
15241541
}
15251542
}
15261543
}

wrt-component/examples/component_info_simple.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
//! A detailed WebAssembly analyzer using wrt ecosystem
22
//!
3-
//! This example demonstrates how to use wrt-decoder, wrt-component, and wrt-format
4-
//! to analyze WebAssembly modules and components in depth.
5-
6-
use std::env;
7-
use std::fs;
8-
use std::path::Path;
9-
use std::str;
10-
use wrt_decoder::component::{
11-
analyze_component, analyze_component_extended, extract_embedded_modules, is_valid_module,
12-
ComponentAnalyzer, ComponentSummary, ExtendedExportInfo, ExtendedImportInfo, ModuleExportInfo,
13-
ModuleImportInfo,
3+
//! This example demonstrates how to use wrt-decoder, wrt-component, and
4+
//! wrt-format to analyze WebAssembly modules and components in depth.
5+
6+
use std::{env, fs, path::Path, str};
7+
8+
use wrt_decoder::{
9+
component::{
10+
analyze_component, analyze_component_extended, extract_embedded_modules, is_valid_module,
11+
ComponentAnalyzer, ComponentSummary, ExtendedExportInfo, ExtendedImportInfo,
12+
ModuleExportInfo, ModuleImportInfo,
13+
},
14+
Module,
1415
};
15-
use wrt_decoder::Module;
1616
use wrt_error::Result;
17-
use wrt_format::binary;
18-
use wrt_format::wasmparser::SectionId;
17+
use wrt_format::{binary, wasmparser::SectionId};
1918

2019
/// Displays a hexadecimal dump of a portion of a binary slice.
2120
fn hex_dump(data: &[u8], offset: usize, len: usize) {
@@ -246,7 +245,8 @@ fn analyze_module(binary: &[u8]) -> Result<()> {
246245
Ok(())
247246
}
248247

249-
/// Parses and displays information from the name section of a WebAssembly module.
248+
/// Parses and displays information from the name section of a WebAssembly
249+
/// module.
250250
fn parse_name_section(module: &Module) -> Result<()> {
251251
println!("\n=== Name Section Analysis ===");
252252

wrt-component/examples/interceptor_example.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use std::sync::Arc;
2+
23
use wrt_component::{Component, ComponentType};
34
use wrt_error::Result;
45
use wrt_host::{function::CloneableFn, CallbackRegistry};
5-
use wrt_intercept::strategies::{FirewallBuilder, StatisticsStrategy};
6-
use wrt_intercept::{strategies::LoggingStrategy, LinkInterceptor};
6+
use wrt_intercept::{
7+
strategies::{FirewallBuilder, LoggingStrategy, StatisticsStrategy},
8+
LinkInterceptor,
9+
};
710
use wrt_runtime::RuntimeInstance;
811
use wrt_types::values::Value;
912

wrt-component/src/builtins/async_ops.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@
66
// - async.poll: Poll an async value for completion
77
// - async.wait: Wait for an async value to complete
88

9-
#[cfg(feature = "component-model-async")]
10-
use wrt_error::{kinds::AsyncError, Error, Result};
11-
#[cfg(feature = "component-model-async")]
12-
use wrt_types::builtin::BuiltinType;
13-
#[cfg(feature = "component-model-async")]
14-
use wrt_types::component_value::ComponentValue;
15-
9+
#[cfg(all(feature = "component-model-async", not(feature = "std"), feature = "alloc"))]
10+
use alloc::{boxed::Box, collections::HashMap, sync::Arc, vec::Vec};
1611
#[cfg(all(feature = "component-model-async", feature = "std"))]
1712
use std::{
1813
boxed::Box,
@@ -24,8 +19,12 @@ use std::{
2419
vec::Vec,
2520
};
2621

27-
#[cfg(all(feature = "component-model-async", not(feature = "std"), feature = "alloc"))]
28-
use alloc::{boxed::Box, collections::HashMap, sync::Arc, vec::Vec};
22+
#[cfg(feature = "component-model-async")]
23+
use wrt_error::{kinds::AsyncError, Error, Result};
24+
#[cfg(feature = "component-model-async")]
25+
use wrt_types::builtin::BuiltinType;
26+
#[cfg(feature = "component-model-async")]
27+
use wrt_types::component_value::ComponentValue;
2928

3029
#[cfg(feature = "component-model-async")]
3130
use crate::builtins::BuiltinHandler;
@@ -213,7 +212,8 @@ impl Future for AsyncValueFuture {
213212

214213
match store.get_status(id) {
215214
Ok(AsyncStatus::Ready) => Poll::Ready(store.get_result(id)),
216-
Ok(AsyncStatus::Failed) => Poll::Ready(store.get_result(id)), // This will return the error
215+
Ok(AsyncStatus::Failed) => Poll::Ready(store.get_result(id)), // This will return
216+
// the error
217217
Ok(AsyncStatus::Pending) => {
218218
// Register the waker and return Pending
219219
let _ = store.set_waker(id, cx.waker().clone());

wrt-component/src/builtins/error.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
// - error.new: Create a new error context
55
// - error.trace: Get the trace from an error context
66

7-
use wrt_error::{codes, kinds::ValidationError, Error, ErrorCategory, Result, WrtError};
8-
use wrt_types::builtin::BuiltinType;
9-
use wrt_types::component_value::ComponentValue;
10-
7+
#[cfg(all(not(feature = "std"), feature = "alloc"))]
8+
use alloc::{boxed::Box, collections::HashMap, string::String, sync::Arc, vec::Vec};
119
#[cfg(feature = "std")]
1210
use std::{
1311
boxed::Box,
@@ -17,8 +15,8 @@ use std::{
1715
vec::Vec,
1816
};
1917

20-
#[cfg(all(not(feature = "std"), feature = "alloc"))]
21-
use alloc::{boxed::Box, collections::HashMap, string::String, sync::Arc, vec::Vec};
18+
use wrt_error::{codes, kinds::ValidationError, Error, ErrorCategory, Result, WrtError};
19+
use wrt_types::{builtin::BuiltinType, component_value::ComponentValue};
2220

2321
use super::BuiltinHandler;
2422

wrt-component/src/builtins/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
// Component Model built-ins, including resource handling, async operations,
55
// error contexts, and threading.
66

7-
use wrt_error::{Error, Result};
8-
use wrt_intercept::{BeforeBuiltinResult, BuiltinInterceptor, InterceptContext};
9-
use wrt_types::builtin::BuiltinType;
10-
use wrt_types::component_value::ComponentValue;
11-
7+
#[cfg(all(not(feature = "std"), feature = "alloc"))]
8+
use alloc::{boxed::Box, sync::Arc, vec::Vec};
129
#[cfg(feature = "std")]
1310
use std::{
1411
boxed::Box,
1512
sync::{Arc, Mutex},
1613
vec::Vec,
1714
};
1815

19-
#[cfg(all(not(feature = "std"), feature = "alloc"))]
20-
use alloc::{boxed::Box, sync::Arc, vec::Vec};
16+
use wrt_error::{Error, Result};
17+
use wrt_intercept::{BeforeBuiltinResult, BuiltinInterceptor, InterceptContext};
18+
use wrt_types::{builtin::BuiltinType, component_value::ComponentValue};
2119

2220
use crate::resources::ResourceManager;
2321

@@ -301,9 +299,10 @@ impl Clone for BuiltinRegistry {
301299

302300
#[cfg(test)]
303301
mod tests {
302+
use wrt_types::component_value::ComponentValue;
303+
304304
use super::*;
305305
use crate::resources::ResourceManager;
306-
use wrt_types::component_value::ComponentValue;
307306

308307
// Simple test handler implementation
309308
struct TestHandler {

wrt-component/src/builtins/resource.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
// - resource.rep: Get the representation of a resource
77
// - resource.get: Get a resource handle
88

9-
use wrt_error::{Error, Result};
10-
use wrt_types::builtin::BuiltinType;
11-
use wrt_types::component_value::ComponentValue;
12-
9+
#[cfg(all(not(feature = "std"), feature = "alloc"))]
10+
use alloc::{boxed::Box, sync::Arc, vec::Vec};
1311
#[cfg(feature = "std")]
1412
use std::{
1513
boxed::Box,
1614
sync::{Arc, Mutex},
1715
vec::Vec,
1816
};
1917

20-
#[cfg(all(not(feature = "std"), feature = "alloc"))]
21-
use alloc::{boxed::Box, sync::Arc, vec::Vec};
18+
use wrt_error::{Error, Result};
19+
use wrt_types::{builtin::BuiltinType, component_value::ComponentValue};
2220

23-
use crate::builtins::BuiltinHandler;
24-
use crate::resources::{ResourceId, ResourceManager};
21+
use crate::{
22+
builtins::BuiltinHandler,
23+
resources::{ResourceId, ResourceManager},
24+
};
2525

2626
/// Handler for the resource.create built-in function
2727
pub struct ResourceCreateHandler {

0 commit comments

Comments
 (0)