Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt-in Stable Trait VTables #2955

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion text/0000-trait_stable_vtable.md
Expand Up @@ -108,7 +108,7 @@ struct VTable{
size: usize,
align: usize,
drop_in_place: Option<unsafe extern"C" fn(*mut ())->()>,
reserved: *mut ()
dealloc:Option<unsafe extern"C" fn(*mut ())->()>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dealloc:Option<unsafe extern"C" fn(*mut ())->()>,
dealloc: Option<unsafe extern "C" fn(*mut ())>,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the other pointers, I'd want to leave the explicit return type. In particular I'd like to have the return type on the virtual fns to show that there is a return type, its just been erased.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dealloc and drop_in_place don't need an erased return type. For the rest using something like struct ErasedVtableFunction(()); *const ErasedVtableFunction instead would make more sense to prevent accidentally calling it with the wrong signature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #[repr(transparent)] struct ErasedVTableFn(unsafe extern "C" fn()); ... virtual_fns: [ErasedVTableFn] would be better, since on some targets (MS-DOS is an example, though rust doesn't currently support that target) function pointers and data pointers aren't the same size.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is for exposition-only. The type does not actually exist in the RFC, as part of the core language or standard library. If I actually defined the type, I'd definately put something like enum Empty{} in the parameter list to prevent it being called. The intent is simply to express the layout of the type.

virtual_fns: [unsafe extern "C" fn(*mut ())->()]
}
```
Expand Down