-
Notifications
You must be signed in to change notification settings - Fork 747
Template alias full and partial specialization improvements. #255
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me if we can fix the regression and other nitpicks
@@ -630,15 +634,29 @@ impl<'ctx> BindgenContext<'ctx> { | |||
// argument names don't matter in the global context. | |||
if (declaration.kind() == CXCursor_ClassTemplate || | |||
declaration.kind() == | |||
CXCursor_ClassTemplatePartialSpecialization) && | |||
CXCursor_ClassTemplatePartialSpecialization || | |||
declaration.kind() == CXCursor_TypeAliasTemplateDecl) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we would benefit from a Cursor::is_template()
method here, that we would use like declaration.is_template()
and replace all these kind comparisons.
As it is right now, this condition is super intense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I agree, but we special-case ClassTemplate/ClassTemplatePartialSpecialization in a few places, but TypeAliasTemplateDecl only here. I'll try to organize it better.
// This is _tricky_, I know :( | ||
if declaration.kind() == CXCursor_TypeAliasTemplateDecl && | ||
ty.canonical_type().is_valid_and_exposed() { | ||
println!("{:?}", ty.canonical_type()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use warn!
or debug!
instead of println!
. Also, a diagnostic message is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, that should've gone away, sorry, will clean it up when I'm in front of my computer.
@@ -7,7 +7,8 @@ | |||
#[repr(C)] | |||
#[derive(Debug, Copy, Clone)] | |||
pub struct Rooted<T> { | |||
pub ptr: MaybeWrapped<T>, | |||
pub ptr: ::std::os::raw::c_int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression. We used to correctly have MaybeWrapped<T>
, but now we have c_int
. I don't think we should land this patch until this regression is fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite a regression since it's really an int
. Unfortunately there's no way to grab the specialized members from clang. I might take some time to make numTemplateArgs work for this, but until that this is the best we can do.
This was working just by chance, because MaybeWrapped
's template argument just happened to be T
, and we grabbed the top-level type. If instead of that it was Rooted<U>
-> MaybeWrapped<U>
, it'd failed (there's a test-case for that).
I guess I can special-case if the spellings are equal to keep the original type, but that's... not really ideal.
Ok, I fixed the regression explicitly looking for |
Libclang patch to eventually fix this hackery: https://reviews.llvm.org/D26663 |
@bors-servo r=fitzgen |
📌 Commit 2003f9c has been approved by |
⚡ Test exempted - status |
Instead of generating a enum like this: ``` pub enum Enum_CUipcMem_flags_enum { CU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS = 1, } ``` Which is a compiler error because repr can't be used with univariant enums. See rust-lang/rust#10292 We generate a two variant enum with a dummy variant. ``` pub enum Enum_CUipcMem_flags_enum { CU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS = 1, __DUMMY, } ``` Which is the recommend workaround to the previous compiler error. closes rust-lang#255
This doesn't completely fix #251, but fixes other related problems.
r? @fitzgen