Skip to content

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

Merged
merged 1 commit into from
Nov 15, 2016

Conversation

emilio
Copy link
Contributor

@emilio emilio commented Nov 14, 2016

This doesn't completely fix #251, but fixes other related problems.

r? @fitzgen

Copy link
Member

@fitzgen fitzgen left a 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) &&
Copy link
Member

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.

Copy link
Contributor Author

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());
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

@emilio
Copy link
Contributor Author

emilio commented Nov 15, 2016

Ok, I fixed the regression explicitly looking for TypeRefs. I'll try to land a patch in libclang to expose the specialized template parameters.

@emilio
Copy link
Contributor Author

emilio commented Nov 15, 2016

Libclang patch to eventually fix this hackery: https://reviews.llvm.org/D26663

@emilio
Copy link
Contributor Author

emilio commented Nov 15, 2016

@bors-servo r=fitzgen

@bors-servo
Copy link

📌 Commit 2003f9c has been approved by fitzgen

@bors-servo
Copy link

⚡ Test exempted - status

@bors-servo bors-servo merged commit 2003f9c into rust-lang:master Nov 15, 2016
bors-servo pushed a commit that referenced this pull request Nov 15, 2016
Template alias full and partial specialization improvements.

This doesn't completely fix #251, but fixes other related problems.

r? @fitzgen
@emilio emilio deleted the type-alias branch November 15, 2016 18:12
luser pushed a commit to luser/rust-bindgen that referenced this pull request Mar 27, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

With replacements, we can generate a use of a type w/ no definition for that type
4 participants