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

Bindgen panics in Stylo on master #584

Closed
fitzgen opened this issue Mar 15, 2017 · 5 comments · Fixed by #623
Closed

Bindgen panics in Stylo on master #584

fitzgen opened this issue Mar 15, 2017 · 5 comments · Fixed by #623
Assignees

Comments

@fitzgen
Copy link
Member

fitzgen commented Mar 15, 2017

See https://bugzilla.mozilla.org/show_bug.cgi?id=1336013

 0:17.10 thread '<unnamed>' panicked at 'C'mon: Continue', C:\bot\slave\stable-dist-rustc-win-msvc-64\build\src\libcore\result.rs:837
...
 0:17.10    7:     0x7ff63f888a2f - core::result::unwrap_failed<bindgen::parse::ParseError>
 0:17.10                         at C:\bot\slave\stable-dist-rustc-win-msvc-64\build\src\libcore\macros.rs:29
 0:17.10    8:     0x7ff63f8d46d0 - bindgen::ir::ty::Type::from_clang_ty
 0:17.10                         at S:\blue\third_party\rust\bindgen\src\ir\ty.rs:1024
...
0:17.11 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any', C:\bot\slave\stable-dist-rustc-win-msvc-64\build\src\libcore\result.rs:837

There's a couple places where I think we should stop asserting that we can always generate an IR item, and instead fall back to generating opaque items when we inevitably fail on something.

@upsuper
Copy link
Contributor

upsuper commented Mar 20, 2017

I've had a patch to fix this.

@emilio
Copy link
Contributor

emilio commented Apr 4, 2017

This wasn't completely fixed by that commit AFAIK.

@emilio emilio reopened this Apr 4, 2017
fitzgen pushed a commit to fitzgen/rust-bindgen that referenced this issue Apr 4, 2017
@fitzgen
Copy link
Member Author

fitzgen commented Apr 7, 2017

Making this issue about getting Stylo working with master bindgen again. The libclang 4.0 stuff is tracked in #585

@fitzgen fitzgen self-assigned this Apr 7, 2017
@fitzgen
Copy link
Member Author

fitzgen commented Apr 7, 2017

After much patience, creduce gives us this reduction of the panic I was getting when generating bindings for stylo with master bindgen:

template <class> class RefPtr;
class b;
class A {
  typedef b a;
};
template <class c> class e { RefPtr<c> d; };
template <class> class f {};
class g {
  f<e<int>> h;
};
class b : g {};
A Servo_Element_GetSnapshot();

@fitzgen fitzgen changed the title Bindgen panics in Stylo build when using libclang >= 4.0 Bindgen panics in Stylo on master Apr 7, 2017
@fitzgen
Copy link
Member Author

fitzgen commented Apr 7, 2017

Ok, this is an interaction between blacklisting and the template analysis.

fitzgen added a commit to fitzgen/rust-bindgen that referenced this issue Apr 7, 2017
The template analysis operates on whitelisted items, and uses our tracing
infrastructure to move between them. Usually, that means we can only reach other
whitelisted items by tracing, because the set of whitelisted items is the
transitive closure of all the items explicitly whitelisted. The exception is
when some type is explicitly blacklisted. It could still be reachable via
tracing from a whitelisted item, but is not considered whitelisted due to the
blacklisting.

The easy fix is to run the template analysis on the whole IR graph rather than
just the whitelisted set. This is an approximately one line change in the
analysis, however is not desirable due to performance concerns. The whole point
of whitelisting is that there may be *many* types in a header, but only a *few*
the user cares about, or there might be types that aren't explicitly needed and
that are too complicated for bindgen to handle generally (often in
`<type_traits>`). In these situations, we don't want to waste cycles or even
confuse ourselves by considering such types!

Instead, we keep the whitelisted item set around and check by hand whether any
given item is in it during the template type parameter analysis.

Additionally, we make the decision that blacklisted template definitions use all
of their type parameters. This seems like a reasonable choice because the type
will likely be ported to Rust manually by the bindgen user, and they will be
looking at the C++ definition with all of its type parameters. They can always
insert `PhantomData`s manually, so it also gives the most flexibility.

Fixes rust-lang#584
fitzgen added a commit to fitzgen/rust-bindgen that referenced this issue Apr 10, 2017
The template analysis operates on whitelisted items, and uses our tracing
infrastructure to move between them. Usually, that means we can only reach other
whitelisted items by tracing, because the set of whitelisted items is the
transitive closure of all the items explicitly whitelisted. The exception is
when some type is explicitly blacklisted. It could still be reachable via
tracing from a whitelisted item, but is not considered whitelisted due to the
blacklisting.

The easy fix is to run the template analysis on the whole IR graph rather than
just the whitelisted set. This is an approximately one line change in the
analysis, however is not desirable due to performance concerns. The whole point
of whitelisting is that there may be *many* types in a header, but only a *few*
the user cares about, or there might be types that aren't explicitly needed and
that are too complicated for bindgen to handle generally (often in
`<type_traits>`). In these situations, we don't want to waste cycles or even
confuse ourselves by considering such types!

Instead, we keep the whitelisted item set around and check by hand whether any
given item is in it during the template type parameter analysis.

Additionally, we make the decision that blacklisted template definitions use all
of their type parameters. This seems like a reasonable choice because the type
will likely be ported to Rust manually by the bindgen user, and they will be
looking at the C++ definition with all of its type parameters. They can always
insert `PhantomData`s manually, so it also gives the most flexibility.

Fixes rust-lang#584
bors-servo pushed a commit that referenced this issue Apr 10, 2017
…-analysis, r=emilio

Correctly handle blacklisted items in the template analysis

The template analysis operates on whitelisted items, and uses our tracing
infrastructure to move between them. Usually, that means we can only reach other
whitelisted items by tracing, because the set of whitelisted items is the
transitive closure of all the items explicitly whitelisted. The exception is
when some type is explicitly blacklisted. It could still be reachable via
tracing from a whitelisted item, but is not considered whitelisted due to the
blacklisting.

The easy fix is to run the template analysis on the whole IR graph rather than
just the whitelisted set. This is an approximately one line change in the
analysis, however is not desirable due to performance concerns. The whole point
of whitelisting is that there may be *many* types in a header, but only a *few*
the user cares about, or there might be types that aren't explicitly needed and
that are too complicated for bindgen to handle generally (often in
`<type_traits>`). In these situations, we don't want to waste cycles or even
confuse ourselves by considering such types!

Instead, we keep the whitelisted item set around and check by hand whether any
given item is in it during the template type parameter analysis.

Additionally, we make the decision that blacklisted template definitions use all
of their type parameters. This seems like a reasonable choice because the type
will likely be ported to Rust manually by the bindgen user, and they will be
looking at the C++ definition with all of its type parameters. They can always
insert `PhantomData`s manually, so it also gives the most flexibility.

Fixes #584

r? @emilio
Kowasaki pushed a commit to Kowasaki/rust-bindgen that referenced this issue May 2, 2017
Kowasaki pushed a commit to Kowasaki/rust-bindgen that referenced this issue May 2, 2017
The template analysis operates on whitelisted items, and uses our tracing
infrastructure to move between them. Usually, that means we can only reach other
whitelisted items by tracing, because the set of whitelisted items is the
transitive closure of all the items explicitly whitelisted. The exception is
when some type is explicitly blacklisted. It could still be reachable via
tracing from a whitelisted item, but is not considered whitelisted due to the
blacklisting.

The easy fix is to run the template analysis on the whole IR graph rather than
just the whitelisted set. This is an approximately one line change in the
analysis, however is not desirable due to performance concerns. The whole point
of whitelisting is that there may be *many* types in a header, but only a *few*
the user cares about, or there might be types that aren't explicitly needed and
that are too complicated for bindgen to handle generally (often in
`<type_traits>`). In these situations, we don't want to waste cycles or even
confuse ourselves by considering such types!

Instead, we keep the whitelisted item set around and check by hand whether any
given item is in it during the template type parameter analysis.

Additionally, we make the decision that blacklisted template definitions use all
of their type parameters. This seems like a reasonable choice because the type
will likely be ported to Rust manually by the bindgen user, and they will be
looking at the C++ definition with all of its type parameters. They can always
insert `PhantomData`s manually, so it also gives the most flexibility.

Fixes rust-lang#584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants