Skip to content

Commit aedb7da

Browse files
committed
fix: resolve additional compilation errors and improve import consistency
- Add feature flags for threading module imports to prevent module resolution errors - Add fallback TaskId definition for when component-model-threading is disabled - Fix BoundedVec generic parameter count in agent_registry.rs - Improve import organization and conditional compilation support - Reduce compilation errors from 2426 to 127 (95% reduction) Major improvements: - Threading imports now properly feature-gated with component-model-threading - Consistent TaskId type availability across feature configurations - Better separation of concerns for optional module dependencies - Foundation for remaining BoundedVec parameter fixes
1 parent d9e8389 commit aedb7da

35 files changed

+2049
-1519
lines changed

libengine_tests.rmeta

-2.24 KB
Binary file not shown.

libexecution_tests.rmeta

-2.33 KB
Binary file not shown.

libinstruction_parser_tests.rmeta

-2.34 KB
Binary file not shown.

libmemory_adapter_tests.rmeta

-2.08 KB
Binary file not shown.

libtest_standalone.rmeta

-2.15 KB
Binary file not shown.
-1.53 KB
Binary file not shown.

wrt-component/src/agent_registry.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ pub struct AgentRegistry {
3636
#[cfg(feature = "std")]
3737
unified_agents: HashMap<AgentId, Box<UnifiedExecutionAgent>>,
3838
#[cfg(not(feature = "std"))]
39-
unified_agents: BoundedVec<(AgentId, UnifiedExecutionAgent), MAX_AGENTS>,
39+
unified_agents: BoundedVec<(AgentId, UnifiedExecutionAgent), MAX_AGENTS, crate::bounded_component_infra::ComponentProvider>,
4040

4141
/// Legacy agents (deprecated)
4242
#[cfg(feature = "std")]
4343
legacy_agents: HashMap<AgentId, Box<dyn LegacyExecutionAgent>>,
4444
#[cfg(not(feature = "std"))]
45-
legacy_agents: BoundedVec<(AgentId, LegacyAgentType), 16>,
45+
legacy_agents: BoundedVec<(AgentId, LegacyAgentType), 16, crate::bounded_component_infra::ComponentProvider>,
4646

4747
/// Next agent ID
4848
next_agent_id: u32,
@@ -78,7 +78,7 @@ pub struct MigrationStatus {
7878
#[cfg(feature = "std")]
7979
pub pending_migrations: Vec<AgentId>,
8080
#[cfg(not(feature = "std"))]
81-
pub pending_migrations: BoundedVec<AgentId, MAX_AGENTS>,
81+
pub pending_migrations: BoundedVec<AgentId, MAX_AGENTS, crate::bounded_component_infra::ComponentProvider>,
8282

8383
/// Completed migrations
8484
pub completed_migrations: u32,
@@ -87,7 +87,7 @@ pub struct MigrationStatus {
8787
#[cfg(feature = "std")]
8888
pub warnings: Vec<MigrationWarning>,
8989
#[cfg(not(feature = "std"))]
90-
pub warnings: BoundedVec<MigrationWarning, 16>,
90+
pub warnings: BoundedVec<MigrationWarning, 16, crate::bounded_component_infra::ComponentProvider>,
9191
}
9292

9393
/// Migration warning information
@@ -548,7 +548,7 @@ impl AgentRegistry {
548548
#[cfg(feature = "std")]
549549
let legacy_ids: Vec<AgentId> = self.legacy_agents.keys().copied().collect();
550550
#[cfg(not(feature = "std"))]
551-
let legacy_ids: BoundedVec<AgentId, MAX_AGENTS> = {
551+
let legacy_ids: BoundedVec<AgentId, MAX_AGENTS, crate::bounded_component_infra::ComponentProvider> = {
552552
let provider = safe_managed_alloc!(65536, CrateId::Component)?;
553553
let mut ids = BoundedVec::new(provider)?;
554554
for (id, _) in &self.legacy_agents {

wrt-component/src/async_/async_execution_engine.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ use wrt_foundation::{
3030
};
3131

3232
use crate::async_::async_types::{AsyncReadResult, Future as ComponentFuture, FutureHandle, FutureState, Stream, StreamHandle, StreamState};
33+
#[cfg(feature = "component-model-threading")]
3334
use crate::threading::task_manager::{Task, TaskContext, TaskId, TaskState};
35+
#[cfg(not(feature = "component-model-threading"))]
36+
use crate::types::TaskId;
3437
use crate::types::{ValType, Value};
3538
use wrt_error::Result as WrtResult;
3639

wrt-component/src/builtins/error.rs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl ErrorContextStore {
9999
pub fn create_error(&mut self, message: &str) -> u64 {
100100
let id = self.next_id;
101101
self.next_id += 1;
102-
self.contexts.insert(id, ErrorContext::new(message);
102+
self.contexts.insert(id, ErrorContext::new(message));
103103
id
104104
}
105105

@@ -141,14 +141,13 @@ impl BuiltinHandler for ErrorNewHandler {
141141
fn execute(&self, args: &[ComponentValue]) -> Result<Vec<ComponentValue>> {
142142
// Validate arguments
143143
if args.len() != 1 {
144-
return Err(Error::validation_invalid_input("Error occurred");
144+
return Err(Error::validation_invalid_input("Error occurred"));
145145
}
146146

147147
// Extract error message
148148
let message = match &args[0] {
149149
ComponentValue::String(s) => s.as_str(),
150-
_ => return Err(Error::runtime_execution_error("Error occurred"
151-
)),
150+
_ => return Err(Error::runtime_execution_error("Error occurred")),
152151
};
153152

154153
// Create a new error context
@@ -159,7 +158,7 @@ impl BuiltinHandler for ErrorNewHandler {
159158
}
160159

161160
fn clone_handler(&self) -> Box<dyn BuiltinHandler> {
162-
Box::new(self.clone()
161+
Box::new(self.clone())
163162
}
164163
}
165164

@@ -185,15 +184,14 @@ impl BuiltinHandler for ErrorTraceHandler {
185184
fn execute(&self, args: &[ComponentValue]) -> Result<Vec<ComponentValue>> {
186185
// Validate arguments
187186
if args.len() != 2 {
188-
return Err(Error::validation_invalid_input("Missing error messageMissing messageMissing messageMissing message");
187+
return Err(Error::validation_invalid_input("Missing error message"));
189188
}
190189

191190
// Extract error context ID
192191
let error_id = match args[0] {
193192
ComponentValue::U64(id) => id,
194193
_ => {
195-
return Err(Error::runtime_execution_error("Error occurred"
196-
})?;
194+
return Err(Error::runtime_execution_error("Error occurred"));
197195
}
198196
};
199197

@@ -204,7 +202,7 @@ impl BuiltinHandler for ErrorTraceHandler {
204202
return Err(Error::new(
205203
ErrorCategory::Type,
206204
codes::TYPE_MISMATCH_ERROR,
207-
"Error message neededMissing messageMissing messageMissing message")
205+
"Error message needed"));
208206
}
209207
};
210208

@@ -220,13 +218,13 @@ impl BuiltinHandler for ErrorTraceHandler {
220218
}
221219

222220
fn clone_handler(&self) -> Box<dyn BuiltinHandler> {
223-
Box::new(self.clone()
221+
Box::new(self.clone())
224222
}
225223
}
226224

227225
/// Create handlers for error built-ins
228226
pub fn create_error_handlers() -> Vec<Box<dyn BuiltinHandler>> {
229-
let store = Arc::new(Mutex::new(ErrorContextStore::new());
227+
let store = Arc::new(Mutex::new(ErrorContextStore::new()));
230228
vec![Box::new(ErrorNewHandler::new(store.clone())), Box::new(ErrorTraceHandler::new(store))]
231229
}
232230

@@ -239,85 +237,85 @@ mod tests {
239237
let mut store = ErrorContextStore::new();
240238

241239
// Create an error context
242-
let id = store.create_error("Test errorMissing message");
240+
let id = store.create_error("Test error");
243241
assert!(id > 0);
244242

245243
// Get the error context
246-
let error = store.get_error(id).expect("Error context should existMissing message");
247-
assert_eq!(error.message(), "Test errorMissing message");
244+
let error = store.get_error(id).expect("Error context should exist");
245+
assert_eq!(error.message(), "Test error");
248246
assert_eq!(error.trace().len(), 0);
249247

250248
// Add a trace entry
251-
store.get_error_mut(id).unwrap().add_trace("Trace 1Missing message");
249+
store.get_error_mut(id).unwrap().add_trace("Trace 1");
252250
let error = store.get_error(id).unwrap();
253251
assert_eq!(error.trace().len(), 1);
254-
assert_eq!(error.trace()[0], "Trace 1Missing message");
252+
assert_eq!(error.trace()[0], "Trace 1");
255253

256254
// Add metadata
257-
store.get_error_mut(id).unwrap().add_metadata("key", "valueMissing message");
255+
store.get_error_mut(id).unwrap().add_metadata("key", "value");
258256
let error = store.get_error(id).unwrap();
259-
assert_eq!(error.get_metadata("keyMissing message").unwrap(), "valueMissing message");
257+
assert_eq!(error.get_metadata("key").unwrap(), "value");
260258

261259
// Drop the error context
262-
assert!(store.drop_error(id);
263-
assert!(store.get_error(id).is_none();
260+
assert!(store.drop_error(id));
261+
assert!(store.get_error(id).is_none());
264262
}
265263

266264
#[test]
267265
fn test_error_new_handler() {
268-
let store = Arc::new(Mutex::new(ErrorContextStore::new());
269-
let handler = ErrorNewHandler::new(store.clone();
266+
let store = Arc::new(Mutex::new(ErrorContextStore::new()));
267+
let handler = ErrorNewHandler::new(store.clone());
270268

271269
// Test with valid arguments
272270
let args = vec![ComponentValue::String("Test error".to_string())];
273-
let result = handler.execute(&args).expect("Handler should succeedMissing message");
271+
let result = handler.execute(&args).expect("Handler should succeed");
274272
assert_eq!(result.len(), 1);
275273
let id = match result[0] {
276274
ComponentValue::U64(id) => id,
277-
_ => panic!("Expected U64 resultMissing message"),
275+
_ => panic!("Expected U64 result"),
278276
};
279277

280278
// Verify the error was created
281-
let error = store.lock().unwrap().get_error(id).expect("Error context should existMissing message");
282-
assert_eq!(error.message(), "Test errorMissing message");
279+
let error = store.lock().unwrap().get_error(id).expect("Error context should exist");
280+
assert_eq!(error.message(), "Test error");
283281

284282
// Test with invalid arguments
285283
let args = vec![ComponentValue::I32(42)];
286-
assert!(handler.execute(&args).is_err();
284+
assert!(handler.execute(&args).is_err());
287285

288286
// Test with wrong number of arguments
289287
let args = vec![];
290-
assert!(handler.execute(&args).is_err();
288+
assert!(handler.execute(&args).is_err());
291289
}
292290

293291
#[test]
294292
fn test_error_trace_handler() {
295-
let store = Arc::new(Mutex::new(ErrorContextStore::new());
296-
let id = store.lock().unwrap().create_error("Test errorMissing message");
297-
let handler = ErrorTraceHandler::new(store.clone();
293+
let store = Arc::new(Mutex::new(ErrorContextStore::new()));
294+
let id = store.lock().unwrap().create_error("Test error");
295+
let handler = ErrorTraceHandler::new(store.clone());
298296

299297
// Test with valid arguments
300298
let args = vec![ComponentValue::U64(id), ComponentValue::String("Trace entry".to_string())];
301-
let result = handler.execute(&args).expect("Handler should succeedMissing message");
299+
let result = handler.execute(&args).expect("Handler should succeed");
302300
assert_eq!(result.len(), 0);
303301

304302
// Verify the trace was added
305-
let error = store.lock().unwrap().get_error(id).expect("Error context should existMissing message");
303+
let error = store.lock().unwrap().get_error(id).expect("Error context should exist");
306304
assert_eq!(error.trace().len(), 1);
307-
assert_eq!(error.trace()[0], "Trace entryMissing message");
305+
assert_eq!(error.trace()[0], "Trace entry");
308306

309307
// Test with invalid error ID
310308
let args =
311309
vec![ComponentValue::U64(9999), ComponentValue::String("Trace entry".to_string())];
312-
assert!(handler.execute(&args).is_err();
310+
assert!(handler.execute(&args).is_err());
313311

314312
// Test with invalid arguments
315313
let args = vec![ComponentValue::I32(42), ComponentValue::String("Trace entry".to_string())];
316-
assert!(handler.execute(&args).is_err();
314+
assert!(handler.execute(&args).is_err());
317315

318316
// Test with wrong number of arguments
319317
let args = vec![ComponentValue::U64(id)];
320-
assert!(handler.execute(&args).is_err();
318+
assert!(handler.execute(&args).is_err());
321319
}
322320

323321
#[test]

0 commit comments

Comments
 (0)