Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 55 additions & 31 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,14 @@ void {snake}_context_set_1(void* value);
uint32_t {snake}_thread_yield_cancellable(void);
uint32_t {snake}_thread_index(void);
uint32_t {snake}_thread_new_indirect(void (*start_function)(void*), void* arg);
void {snake}_thread_switch_to(uint32_t thread);
uint32_t {snake}_thread_switch_to_cancellable(uint32_t thread);
void {snake}_thread_resume_later(uint32_t thread);
void {snake}_thread_yield_to(uint32_t thread);
uint32_t {snake}_thread_yield_to_cancellable(uint32_t thread);
void {snake}_thread_suspend_to(uint32_t thread);
uint32_t {snake}_thread_suspend_to_cancellable(uint32_t thread);
void {snake}_thread_suspend_to_suspended(uint32_t thread);
uint32_t {snake}_thread_suspend_to_suspended_cancellable(uint32_t thread);
void {snake}_thread_unsuspend(uint32_t thread);
_Noreturn void {snake}_thread_exit();
void {snake}_thread_yield_to_suspended(uint32_t thread);
uint32_t {snake}_thread_yield_to_suspended_cancellable(uint32_t thread);
void {snake}_thread_suspend(void);
uint32_t {snake}_thread_suspend_cancellable(void);
"
Expand Down Expand Up @@ -776,39 +779,60 @@ uint32_t {snake}_thread_new_indirect(void (*start_function)(void*), void* arg) {
);
}}

__attribute__((__import_module__("$root"), __import_name__("[thread-switch-to]")))
extern uint32_t __thread_switch_to(uint32_t);
__attribute__((__import_module__("$root"), __import_name__("[thread-suspend-to-suspended]")))
extern uint32_t __thread_suspend_to_suspended(uint32_t);

void {snake}_thread_switch_to(uint32_t thread) {{
__thread_switch_to(thread);
void {snake}_thread_suspend_to_suspended(uint32_t thread) {{
__thread_suspend_to_suspended(thread);
}}

__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-switch-to]")))
extern uint32_t __thread_switch_to_cancellable(uint32_t);
__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-suspend-to-suspended]")))
extern uint32_t __thread_suspend_to_suspended_cancellable(uint32_t);

uint32_t {snake}_thread_switch_to_cancellable(uint32_t thread) {{
return __thread_switch_to_cancellable(thread);
uint32_t {snake}_thread_suspend_to_suspended_cancellable(uint32_t thread) {{
return __thread_suspend_to_suspended_cancellable(thread);
}}

__attribute__((__import_module__("$root"), __import_name__("[thread-resume-later]")))
extern void __thread_resume_later(uint32_t);
__attribute__((__import_module__("$root"), __import_name__("[thread-suspend-to]")))
extern uint32_t __thread_suspend_to(uint32_t);

void {snake}_thread_resume_later(uint32_t thread) {{
__thread_resume_later(thread);
void {snake}_thread_suspend_to(uint32_t thread) {{
__thread_suspend_to(thread);
}}

__attribute__((__import_module__("$root"), __import_name__("[thread-yield-to]")))
extern uint32_t __thread_yield_to(uint32_t);
__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-suspend-to]")))
extern uint32_t __thread_suspend_to_cancellable(uint32_t);

void {snake}_thread_yield_to(uint32_t thread) {{
__thread_yield_to(thread);
uint32_t {snake}_thread_suspend_to_cancellable(uint32_t thread) {{
return __thread_suspend_to_cancellable(thread);
}}

__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield-to]")))
extern uint32_t __thread_yield_to_cancellable(uint32_t);
__attribute__((__import_module__("$root"), __import_name__("[thread-unsuspend]")))
extern void __thread_unsuspend(uint32_t);

uint32_t {snake}_thread_yield_to_cancellable(uint32_t thread) {{
return __thread_yield_to_cancellable(thread);
void {snake}_thread_unsuspend(uint32_t thread) {{
__thread_unsuspend(thread);
}}

__attribute__((__import_module__("$root"), __import_name__("[thread-exit]")))
_Noreturn extern void __thread_exit();

_Noreturn void {snake}_thread_exit() {{
__thread_exit();
}}

__attribute__((__import_module__("$root"), __import_name__("[thread-yield-to-suspended]")))
extern uint32_t __thread_yield_to_suspended(uint32_t);

void {snake}_thread_yield_to_suspended(uint32_t thread) {{
__thread_yield_to_suspended(thread);
}}

__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield-to-suspended]")))
extern uint32_t __thread_yield_to_suspended_cancellable(uint32_t);

uint32_t {snake}_thread_yield_to_suspended_cancellable(uint32_t thread) {{
return __thread_yield_to_suspended_cancellable(thread);
}}

__attribute__((__import_module__("$root"), __import_name__("[thread-suspend]")))
Expand Down Expand Up @@ -1066,7 +1090,7 @@ fn is_prim_type_id(resolve: &Resolve, id: TypeId) -> bool {
| TypeDefKind::Future(_)
| TypeDefKind::Stream(_)
| TypeDefKind::Unknown => false,
TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
}
}
Expand Down Expand Up @@ -1152,7 +1176,7 @@ pub fn push_ty_name(resolve: &Resolve, ty: &Type, src: &mut String) {
push_ty_name(resolve, &Type::Id(*resource), src);
}
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
}
}
Expand Down Expand Up @@ -1366,7 +1390,7 @@ impl Return {

TypeDefKind::Resource => todo!("return_single for resource"),
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
}

Expand Down Expand Up @@ -2012,7 +2036,7 @@ impl InterfaceGenerator<'_> {
self.free(&Type::Id(*id), "*ptr");
}
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
}
if c_helpers_body_start == self.src.c_helpers.len() {
Expand Down Expand Up @@ -2706,7 +2730,7 @@ void {name}_return({return_ty}) {{
TypeDefKind::Type(ty) => self.contains_droppable_borrow(ty),

TypeDefKind::Unknown => false,
TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
}
} else {
Expand Down Expand Up @@ -4076,7 +4100,7 @@ pub fn is_arg_by_pointer(resolve: &Resolve, ty: &Type) -> bool {
TypeDefKind::Stream(_) => false,
TypeDefKind::Resource => todo!("is_arg_by_pointer for resource"),
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
},
Type::String => true,
Expand Down
14 changes: 7 additions & 7 deletions crates/core/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ fn needs_deallocate(resolve: &Resolve, ty: &Type, what: Deallocate) -> bool {
TypeDefKind::Flags(_) | TypeDefKind::Enum(_) => false,
TypeDefKind::Future(_) | TypeDefKind::Stream(_) => what.handles(),
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(t, _) => needs_deallocate(resolve, t, what),
TypeDefKind::FixedLengthList(t, _) => needs_deallocate(resolve, t, what),
TypeDefKind::Map(..) => todo!(),
},

Expand Down Expand Up @@ -1597,7 +1597,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
});
}
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(ty, size) => {
TypeDefKind::FixedLengthList(ty, size) => {
self.emit(&FixedLengthListLower {
element: ty,
size: *size,
Expand Down Expand Up @@ -1795,7 +1795,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
});
}
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(ty, size) => {
TypeDefKind::FixedLengthList(ty, size) => {
let temp = flat_types(self.resolve, ty, None).unwrap();
let flat_per_elem = temp.to_vec().len();
let flatsize = flat_per_elem * (*size as usize);
Expand Down Expand Up @@ -1995,7 +1995,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
}

TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(element, size) => {
TypeDefKind::FixedLengthList(element, size) => {
// resembles write_list_to_memory
self.push_block();
self.emit(&IterElem { element });
Expand Down Expand Up @@ -2197,7 +2197,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
}

TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(ty, size) => {
TypeDefKind::FixedLengthList(ty, size) => {
self.push_block();
self.emit(&IterBasePointer);
let elemaddr = self.stack.pop().unwrap();
Expand Down Expand Up @@ -2398,7 +2398,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
TypeDefKind::Resource => unreachable!(),
TypeDefKind::Unknown => unreachable!(),

TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
},
}
Expand Down Expand Up @@ -2520,7 +2520,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
TypeDefKind::Future(_) => unreachable!(),
TypeDefKind::Stream(_) => unreachable!(),
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(_, _) => {}
TypeDefKind::FixedLengthList(_, _) => {}
TypeDefKind::Map(..) => todo!(),
},
}
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub trait InterfaceGenerator<'a> {
TypeDefKind::Future(t) => self.type_future(id, name, t, &ty.docs),
TypeDefKind::Stream(t) => self.type_stream(id, name, t, &ty.docs),
TypeDefKind::Handle(_) => panic!("handle types do not require definition"),
TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
TypeDefKind::Unknown => unreachable!(),
}
Expand Down Expand Up @@ -219,7 +219,7 @@ pub trait AnonymousTypeGenerator<'a> {
TypeDefKind::Future(f) => self.anonymous_type_future(id, f, &ty.docs),
TypeDefKind::Stream(s) => self.anonymous_type_stream(id, s, &ty.docs),
TypeDefKind::Handle(handle) => self.anonymous_type_handle(id, handle, &ty.docs),
TypeDefKind::FixedSizeList(t, size) => {
TypeDefKind::FixedLengthList(t, size) => {
self.anonymous_type_fixed_length_list(id, t, *size, &ty.docs)
}
TypeDefKind::Map(..) => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Types {
// should use the same ownership semantics as `own<T>`
info.has_own_handle = true;
}
TypeDefKind::FixedSizeList(ty, _) => {
TypeDefKind::FixedLengthList(ty, _) => {
info = self.type_info(resolve, ty);
}
TypeDefKind::Map(..) => todo!(),
Expand Down
4 changes: 2 additions & 2 deletions crates/cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ impl CppInterfaceGenerator<'_> {
TypeDefKind::Future(_) => todo!("generate for future"),
TypeDefKind::Stream(_) => todo!("generate for stream"),
TypeDefKind::Handle(_) => todo!("generate for handle"),
TypeDefKind::FixedSizeList(_, _) => todo!(),
TypeDefKind::FixedLengthList(_, _) => todo!(),
TypeDefKind::Map(_, _) => todo!(),
TypeDefKind::Unknown => unreachable!(),
}
Expand Down Expand Up @@ -1702,7 +1702,7 @@ impl CppInterfaceGenerator<'_> {
TypeDefKind::Future(_) => todo!(),
TypeDefKind::Stream(_) => todo!(),
TypeDefKind::Type(ty) => self.type_name(ty, from_namespace, flavor),
TypeDefKind::FixedSizeList(ty, size) => {
TypeDefKind::FixedLengthList(ty, size) => {
self.r#gen.dependencies.needs_array = true;
format!(
"std::array<{}, {size}>",
Expand Down
2 changes: 1 addition & 1 deletion crates/markdown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl InterfaceGenerator<'_> {
self.push_str(">");
}
TypeDefKind::Unknown => unreachable!(),
TypeDefKind::FixedSizeList(..) => todo!(),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::Map(..) => todo!(),
}
}
Expand Down
70 changes: 37 additions & 33 deletions tests/runtime-async/async/threading-builtins/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,51 @@
//@ ldflags = "-Wl,--export-table"

#include <assert.h>
#include <test.h>
#include <stdio.h>
#include <test.h>

test_subtask_status_t exports_test_f() {
return TEST_CALLBACK_CODE_YIELD;
}
test_subtask_status_t exports_test_f() { return TEST_CALLBACK_CODE_YIELD; }

uint32_t main_tid = 0;
uint32_t spawned_tid = 0;

void thread_start(void* arg) {
// Call all the threading builtins; the main thread will do the right thing
// to resume us.
test_thread_yield();
test_thread_yield_cancellable();
test_thread_suspend();
test_thread_suspend_cancellable();
test_thread_yield_to(main_tid);
test_thread_yield_to_cancellable(main_tid);
test_thread_switch_to(main_tid);
test_thread_switch_to_cancellable(main_tid);
test_thread_resume_later(main_tid);
void thread_start(void *arg) {
// Call all the threading builtins; the main thread will do the right thing
// to resume us.
test_thread_yield();
test_thread_yield_cancellable();
test_thread_suspend();
test_thread_suspend_cancellable();
test_thread_yield_to_suspended(main_tid);
test_thread_yield_to_suspended_cancellable(main_tid);
test_thread_suspend_to_suspended(main_tid);
test_thread_suspend_to_suspended_cancellable(main_tid);
test_thread_suspend_to(main_tid);
test_thread_suspend_to_cancellable(main_tid);
test_thread_unsuspend(main_tid);
test_thread_exit();
}

test_subtask_status_t exports_test_f_callback(test_event_t *event) {
assert(event->event == TEST_EVENT_NONE);
assert(event->waitable == 0);
assert(event->code == 0);
main_tid = test_thread_index();
spawned_tid = test_thread_new_indirect(thread_start, &main_tid);
assert(event->event == TEST_EVENT_NONE);
assert(event->waitable == 0);
assert(event->code == 0);
main_tid = test_thread_index();
spawned_tid = test_thread_new_indirect(thread_start, &main_tid);

// Now drive the other thread to completion by switching/yielding to it
test_thread_yield_to(spawned_tid); // other yields
test_thread_yield(); // other yields
test_thread_yield(); // other suspends
test_thread_yield_to(spawned_tid); // other suspends
test_thread_switch_to(spawned_tid); // other yields to me
test_thread_suspend(); // other yields to me
test_thread_suspend(); // other switches to me
test_thread_switch_to(spawned_tid); // other switches to me
test_thread_switch_to(spawned_tid); // other resumes me later and terminates
exports_test_f_return();
return TEST_CALLBACK_CODE_EXIT;
// Now drive the other thread to completion by switching/yielding to it
test_thread_yield_to_suspended(spawned_tid); // other yields
test_thread_yield(); // other yields
test_thread_yield(); // other suspends
test_thread_yield_to_suspended(spawned_tid); // other suspends
test_thread_suspend_to_suspended(spawned_tid); // other yields to me
test_thread_suspend(); // other yields to me
test_thread_suspend(); // other suspends to me
test_thread_suspend_to_suspended(spawned_tid); // other suspends to me
test_thread_suspend_to_suspended(spawned_tid); // other suspends to me
test_thread_suspend_to_suspended(spawned_tid); // other suspends to me
test_thread_suspend_to_suspended(
spawned_tid); // other unsuspends me and terminates
exports_test_f_return();
return TEST_CALLBACK_CODE_EXIT;
}
Loading