Skip to content

Commit 317be62

Browse files
committed
feat: bump canonical refernces to latest version
update ContextLocalStorage LENGTH and adjust related tests refactor cmcpp namespace to cmcpp::spec and update related documentation Implement thread-local storage for context management and update related tests Enhance thread management with new yield and resume functionalities Implement new thread management functions and update related tests Add tests for thread and stream functionalities - Implement tests for thread spawning and parallelism checks. - Add tests to verify stream cancellation behavior and synchronization. - Introduce future-related tests to ensure proper async handling and cancellation. - Enhance existing tests to improve coverage and correctness of stream and future operations.
1 parent 72f9cda commit 317be62

29 files changed

+2206
-495
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ install(TARGETS cmcpp
5858

5959
install(EXPORT cmcppTargets
6060
FILE cmcppTargets.cmake
61-
NAMESPACE cmcpp::
61+
NAMESPACE cmcpp::spec::
6262
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmcpp
6363
)

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,27 @@ This library is a header only library. To use it in your project, you can:
206206
Most host interactions begin by materialising an `InstanceContext`. This container wires together the host trap callback, string conversion routine, and the guest `realloc` export. Use `createInstanceContext` to capture those dependencies once:
207207

208208
```cpp
209-
cmcpp::HostTrap trap = [](const char *msg) {
209+
cmcpp::spec::HostTrap trap = [](const char *msg) {
210210
throw std::runtime_error(msg ? msg : "trap");
211211
};
212-
cmcpp::HostUnicodeConversion convert = {}; // see test/host-util.cpp for an ICU-backed example
213-
cmcpp::GuestRealloc realloc = [&](int ptr, int old_size, int align, int new_size) {
212+
cmcpp::spec::HostUnicodeConversion convert = {}; // see test/host-util.cpp for an ICU-backed example
213+
cmcpp::spec::GuestRealloc realloc = [&](int ptr, int old_size, int align, int new_size) {
214214
return guest_realloc(ptr, old_size, align, new_size);
215215
};
216216

217-
auto icx = cmcpp::createInstanceContext(trap, convert, realloc);
217+
auto icx = cmcpp::spec::createInstanceContext(trap, convert, realloc);
218218
```
219219

220220
When preparing to lift or lower values, create a `LiftLowerContext` from the instance. Pass the guest memory span and any canonical options you need:
221221

222222
```cpp
223-
cmcpp::Heap heap(4096);
224-
cmcpp::CanonicalOptions options;
225-
options.memory = cmcpp::GuestMemory(heap.memory.data(), heap.memory.size());
226-
options.string_encoding = cmcpp::Encoding::Utf8;
223+
cmcpp::spec::Heap heap(4096);
224+
cmcpp::spec::CanonicalOptions options;
225+
options.memory = cmcpp::spec::GuestMemory(heap.memory.data(), heap.memory.size());
226+
options.string_encoding = cmcpp::spec::Encoding::Utf8;
227227
options.realloc = icx->realloc;
228228
options.post_return = [] { /* guest cleanup */ };
229-
options.callback = [](cmcpp::EventCode code, uint32_t index, uint32_t payload) {
229+
options.callback = [](cmcpp::spec::EventCode code, uint32_t index, uint32_t payload) {
230230
std::printf("async event %u for handle %u (0x%x)\n",
231231
static_cast<unsigned>(code), index, payload);
232232
};
@@ -251,16 +251,16 @@ The Component Model runtime is cooperative: hosts advance work by draining a pen
251251
A minimal async call looks like this:
252252
253253
```cpp
254-
cmcpp::Store store;
254+
cmcpp::spec::Store store;
255255
256-
cmcpp::FuncInst guest = [](cmcpp::Store &store,
257-
cmcpp::SupertaskPtr,
258-
cmcpp::OnStart on_start,
259-
cmcpp::OnResolve on_resolve) {
256+
cmcpp::spec::FuncInst guest = [](cmcpp::spec::Store &store,
257+
cmcpp::spec::SupertaskPtr,
258+
cmcpp::spec::OnStart on_start,
259+
cmcpp::spec::OnResolve on_resolve) {
260260
auto args = std::make_shared<std::vector<std::any>>(on_start());
261261
auto ready = std::make_shared<std::atomic<bool>>(false);
262262
263-
auto thread = cmcpp::Thread::create(
263+
auto thread = cmcpp::spec::Thread::create(
264264
store,
265265
[ready] { return ready->load(); },
266266
[args, on_resolve](bool cancelled) {
@@ -270,7 +270,7 @@ cmcpp::FuncInst guest = [](cmcpp::Store &store,
270270
/*notify_on_cancel=*/true,
271271
[ready] { ready->store(true); });
272272
273-
return cmcpp::Call::from_thread(thread);
273+
return cmcpp::spec::Call::from_thread(thread);
274274
};
275275
276276
auto call = store.invoke(

docs/spec-alignment.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Spec alignment tracker
2+
3+
This document tracks alignment between the upstream Component Model spec/reference (in `ref/component-model`) and this library’s C++ entrypoints.
4+
5+
- Upstream references:
6+
- `ref/component-model/design/mvp/CanonicalABI.md`
7+
- `ref/component-model/design/mvp/Concurrency.md`
8+
- `ref/component-model/design/mvp/canonical-abi/definitions.py`
9+
- C++ namespace: `cmcpp::spec`
10+
11+
## Canonical built-ins inventory
12+
13+
| Spec built-in | C++ entrypoint | Status | Notes |
14+
|---|---|---|---|
15+
| `context.get` | `cmcpp::spec::canon_context_get` | implemented | |
16+
| `context.set` | `cmcpp::spec::canon_context_set` | implemented | |
17+
| `backpressure.inc` | `cmcpp::spec::canon_backpressure_inc` | implemented | |
18+
| `backpressure.dec` | `cmcpp::spec::canon_backpressure_dec` | implemented | |
19+
| `backpressure.set` | `cmcpp::spec::canon_backpressure_set` | implemented | Spec notes this as deprecated in favor of `backpressure.{inc,dec}`. |
20+
| `thread.yield` | `cmcpp::spec::canon_thread_yield` | implemented | |
21+
| `thread.yield-to` | `cmcpp::spec::canon_thread_yield_to` | implemented | |
22+
| `thread.resume-later` | `cmcpp::spec::canon_thread_resume_later` | implemented | |
23+
| `thread.index` | `cmcpp::spec::canon_thread_index` | implemented | |
24+
| `thread.suspend` | `cmcpp::spec::canon_thread_suspend` | implemented | |
25+
| `task.return` | `cmcpp::spec::canon_task_return` | implemented | |
26+
| `task.cancel` | `cmcpp::spec::canon_task_cancel` | implemented | |
27+
| `task.wait` | `cmcpp::spec::canon_task_wait` | implemented | |
28+
| `waitable-set.new` | `cmcpp::spec::canon_waitable_set_new` | implemented | |
29+
| `waitable-set.drop` | `cmcpp::spec::canon_waitable_set_drop` | implemented | |
30+
| `waitable-set.wait` | `cmcpp::spec::canon_waitable_set_wait` | implemented | |
31+
| `waitable-set.poll` | `cmcpp::spec::canon_waitable_set_poll` | implemented | |
32+
| `waitable.join` | `cmcpp::spec::canon_waitable_join` | implemented | |
33+
| `stream.new` | `cmcpp::spec::canon_stream_new` | implemented | |
34+
| `stream.read` | `cmcpp::spec::canon_stream_read` | implemented | |
35+
| `stream.write` | `cmcpp::spec::canon_stream_write` | implemented | |
36+
| `stream.cancel-read` | `cmcpp::spec::canon_stream_cancel_read` | implemented | |
37+
| `stream.cancel-write` | `cmcpp::spec::canon_stream_cancel_write` | implemented | |
38+
| `stream.drop-readable` | `cmcpp::spec::canon_stream_drop_readable` | implemented | |
39+
| `stream.drop-writable` | `cmcpp::spec::canon_stream_drop_writable` | implemented | |
40+
| `future.new` | `cmcpp::spec::canon_future_new` | implemented | |
41+
| `future.read` | `cmcpp::spec::canon_future_read` | implemented | |
42+
| `future.write` | `cmcpp::spec::canon_future_write` | implemented | |
43+
| `future.cancel-read` | `cmcpp::spec::canon_future_cancel_read` | implemented | |
44+
| `future.cancel-write` | `cmcpp::spec::canon_future_cancel_write` | implemented | |
45+
| `future.drop-readable` | `cmcpp::spec::canon_future_drop_readable` | implemented | |
46+
| `future.drop-writable` | `cmcpp::spec::canon_future_drop_writable` | implemented | |
47+
| `resource.new` | `cmcpp::spec::canon_resource_new` | implemented | |
48+
| `resource.rep` | `cmcpp::spec::canon_resource_rep` | implemented | |
49+
| `resource.drop` | `cmcpp::spec::canon_resource_drop` | implemented | |
50+
| `error-context.new` | `cmcpp::spec::canon_error_context_new` | implemented | |
51+
| `error-context.debug-message` | `cmcpp::spec::canon_error_context_debug_message` | implemented | |
52+
| `error-context.drop` | `cmcpp::spec::canon_error_context_drop` | implemented | |
53+
54+
## Thread built-ins (upstream)
55+
56+
These are referenced by the upstream spec/reference but do not currently have direct C++ canonical built-in entrypoints in this repo:
57+
58+
- `thread.new_ref` / `thread.new-ref` (implemented: `cmcpp::spec::canon_thread_new_ref`)
59+
- `thread.new-indirect` (implemented: `cmcpp::spec::canon_thread_new_indirect`)
60+
- `thread.spawn-ref` (implemented: `cmcpp::spec::canon_thread_spawn_ref`)
61+
- `thread.spawn-indirect` (implemented: `cmcpp::spec::canon_thread_spawn_indirect`)
62+
- `thread.switch-to` (implemented: `cmcpp::spec::canon_thread_switch_to`)
63+
- `thread.available-parallelism` (implemented: `cmcpp::spec::canon_thread_available_parallelism`)

0 commit comments

Comments
 (0)