summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2017-04-24Auto merge of #656 - emilio:fn-collision, r=fitzgenbors-servo
codegen: Change forward-declared types to avoid collisions with functions. Fixes #654
2017-04-23codegen: Change forward-declared types to avoid collisions with functions.Emilio Cobos Álvarez
Fixes #654
2017-04-19Resolve blacklisted instantiations' args through refs and aliasesNick Fitzgerald
When resolving a template argument in an instantiation of a blacklisted template, we should resolve through type references and aliases so that we don't accidentally lose template parameter usage information. Basically, this case should have been in bce1330, but slipped through the cracks. Fixes #645.
2017-04-19Make the test-one.sh script use the test's bindgen flagsNick Fitzgerald
Previously, the test-one.sh script hard coded common bindgen flags to run the specified test with. Now, it parses the `// bindgen-flags:` comment in the test header and uses those flags when running bindgen.
2017-04-19ir: consider all nested definitions inside structs to be inner types.Emilio Cobos Álvarez
Fixes #643
2017-04-18Auto merge of #641 - emilio:anon-struct-typedef, r=fitzgenbors-servo
ir: Ensure we check for typedefs of anonymous structs at the right time. They appear later in the clang AST, so we need to check for them as a special-case before flushing the new field.
2017-04-18ir: Ensure we check for typedefs of anonymous structs at the right time.Emilio Cobos Álvarez
They appear later in the clang AST, so we need to check for them as a special-case before flushing the new field. Fixes #639
2017-04-17Resolve through type refs and aliases when marking type params usedNick Fitzgerald
In stylo bindings generation, we were hitting bugs where the analysis saw a template type parameter behind a type ref to a type alias, and this was then used as an argument to a template instantiation. Because of the indirection, the analysis got confused and ignored the template argument because it was "not" a named template type, and therefore we didn't care about its usage. This commit makes sure that we keep resolving through type references and aliases to find the inner named template type parameter to add to the current item's usage set. Fixes #638.
2017-04-17Add more diagnostic output to the test-one.sh scriptNick Fitzgerald
This commit makes the test-one.sh script log the input header as well as the emitted bindings to stdout.
2017-04-12Add a Stylo bindings sanity testNick Fitzgerald
This commit adds a sanity test that we can generate bindings for Stylo without any errors. I tried to make this a `#[bench]` but each iteration takes 36 seconds on my machine, which made the `#[bench]` take *way* too long. Instead, there is a commented out `panic!` that can be uncommented to get a log of how long it took.
2017-04-10Auto merge of #623 - ↵bors-servo
fitzgen:issue-584-stylo-blacklisting-in-template-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
2017-04-10Correctly handle blacklisted items in the template analysisNick Fitzgerald
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
2017-04-08Omit accessor functions for large bitfieldsDominik Boehi
2017-04-05Add a test explicitly for default type parametersNick Fitzgerald
This is exercised in other tests, but in a round about fashion. It is nice to have a test that explicitly exercises default type parameters, without any cruft.
2017-04-04Use opaque types rather than continuing when template instantiation failsNick Fitzgerald
2017-04-04Ignore builtin template when parsing.Xidorn Quan
This should fix #584.
2017-04-04ir: Handle char in a more cross-platform way when possible.Emilio Cobos Álvarez
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
2017-04-04tests: Add negative tests for constructor/destructor generation behavior.Emilio Cobos Álvarez
2017-04-04codegen: Simplify method implementations.Emilio Cobos Álvarez
2017-04-04codegen: Rename the destructor methods to "destruct".Emilio Cobos Álvarez
2017-04-04options: Allow configuring destructors via CLI.Emilio Cobos Álvarez
2017-04-04Refactor a bit and do not generate virtual destructors.Emilio Cobos Álvarez
2017-04-04Add codegen for destructors.Nikhil Shagrithaya
2017-04-03options: Allow configuring the generation of constructors.Emilio Cobos Álvarez
2017-03-31Merge pull request #602 from emilio/clang-5Emilio Cobos Álvarez
clang: Fix most of the clang 5.0 regressions in our tests.
2017-03-30 clang: Fix most of the clang 5.0 regressions in our tests.Emilio Cobos Álvarez
2017-03-27Auto merge of #601 - luser:string-input, r=emiliobors-servo
Add a `Builder::header_contents` method to allow passing source code as a string to a Builder Currently the Builder API requires input as header files on disk. This allows passing C source directly to clang using the existing UnsavedFile struct. I'm going to take a shot at implementing a webapp that lets users paste in C source and get the bindgen output. It would make life easier if I didn't have to write the source out to a temp file. This patch allows passing the source in as a `&str`. I wasn't quite sure where to put the new test, but it seems to work in tests.rs.
2017-03-27Add a `Builder::header_contents` method to allow passing source code as a ↵Ted Mielczarek
string to a Builder Currently the Builder API requires input as header files on disk. This allows passing C source directly to clang using the existing UnsavedFile struct.
2017-03-27Auto merge of #600 - emilio:fwd-enum, r=upsuperbors-servo
ir: Prefer the enum definition instead of the declaration when looking for variants. Fixes #599
2017-03-23ir: Prefer the enum definition instead of the declaration when looking for ↵Emilio Cobos Álvarez
variants.
2017-03-21Make vtables non-zero-size to fix a rustc warning.Simon Sapin
``` warning: found non-foreign-function-safe member in struct marked #[repr(C)]: found zero-size struct in foreign module, consider adding a member to this struct ```
2017-03-21Do not derive Default on vtable typesSimon Sapin
https://github.com/servo/rust-bindgen/pull/597#issuecomment-288006557
2017-03-20options: Allow force-generating inline functions.Emilio Cobos Álvarez
2017-03-16Resolve namespace clashes between methods and generated bitfield accessorsNick Fitzgerald
This commit makes bitfields' accessor codegen detect conflicting method names and generate alternative, non-conflicting names instead.
2017-03-15Add a script to test bindings generation and layout for one header at a timeNick Fitzgerald
2017-03-15Refactor fallibility of conversions from IR to Rust typesNick Fitzgerald
The old ToRustTy and ItemToRustTy conversion traits were problematic in that they assumed infallibity. That assumption is problematic because we are often dealing with C++ constructs for which Rust has no equivalent *and* we don't have a usable layout from which to generate an opaque blob in its stead. But, a usable layout is often "up the stack" if only we had a way to get up there. For example, Rust does not currently have an equivalent of const value template parameters, and libclang will not give us a layout for template definitions with const value template parameters. However, libclang will give us the layout for an instantiation of such a template definition. First, this commit separates the concepts of generating an equivalent Rust type from generating an opaque blob of the same size and alignment as an IR thing. This consolidates and DRYs up a *ton* of code involved in falling back to an opaque blob (and doing our best to get a Layout for the blob) when we can't generate an equivalent Rust type for some IR thing. Second, it separates fallible and infallible conversions, and provides a nice little framework for when to choose which. This gives us one single place where we do this whole dance: if could not generate equivalent Rust type: if we have a layout: return opaque blob based on layout else: return opaque blob based on a wish and a prayer The ToRustTy trait is replaced by the TryToOpaque, ToOpaque, TryToRustTyOrOpaque, and ToRustTyOrOpaque traits. The ItemToRustTy helper was just a way to avoid ToRustTy's Self::Extra parameter when it was not needed, and is simply removed without a replacement. We suck it up and pass `&()` at call sites now. We *could* introduce ItemTryToOpaque, ItemToOpaque, etc... traits, but the cost of the added boiler plate would outweigh the benefits of not passing `&()` at call sites, IMHO. In addition to being a nice code cleanup, this also fixes #573.
2017-03-15ir: Generate non-finite floating point constants properly.Emilio Cobos Álvarez
2017-03-10Allow anonymous template typesNick Fitzgerald
We have various assertions that the only way that some template parameter related methods will return `None` is if the template definition is marked opaque. These assertions fail in the presence of test cases with unnamed template types, because we never save an IR item for the template type, and subsequently think that the template definition has no template parameters. The assertions are in fact sound and correct, so it doesn't make sense to remove them. Instead it is more correct to save IR items for the anonymous template types and simply let the template usage analysis prevent them from getting codegen'd. Fixes #574
2017-03-09Auto merge of #565 - framlog:master, r=fitzgenbors-servo
automatically allow non rust naming conventions + related issue: #562 I just added those attributes at the root mod. And I'm not sure whether it should be better if we could set this setting in `build.rs`.
2017-03-09Generate better opaque blobs in the face of non-type parametersNick Fitzgerald
When instantiating templates whose definitions have non-type generic parameters, prefer the layout of the instantiation type to the garbage we get from the definition's layout. In general, an instantiation's layout will always be a better choice than the definition's layout, regardless of non-type parameters. Fixes #569
2017-03-09Reintroduce bitfield accessorsNick Fitzgerald
This commit reintroduces accessor methods for bitfields in the generated bindings. Fixes #519
2017-03-08automatically allow non rust naming conventionsHuxley
2017-03-07objc: Implement class methodsMikko Lehtonen
2017-03-07Auto merge of #544 - fitzgen:cleanups-without-anon-types, r=emiliobors-servo
All the template parameters!! The major changes in this PR are: * De-duplication of named template type parameters (this is probably the biggest part of the PR, and nastiest because it is the part that deals with libclang) * Removing the `signature_contains_named_type` stuff, and enabling the more sound template type parameter usage analysis that has been landing in bits here and there. * **LOTS** of new tests for template type parameter usage @emilio: can you also test this on the stylo bindings? I tested on the SpiderMonkey bindings and found a bug and fixed a bug related to instantiations of partially specialized templates. I'd like to make sure that there aren't any latent bugs uncovered in Stylo. This is NOT ready to merge quite yet, but is ready for some more eyeballs that are not mine. Still TODO: * [x] Rebase so that these changes will merge cleanly -- I'll get on this ASAP * [x] Time SpiderMonkey bindings generation with and without these changes to see what the overhead of the new analysis is (if any!) on Large and Real World bindings * [x] Test theses changes on Stylo (thanks @emilio!) * [ ] (optional) and time Stylo bindings generation with and without these changes as well (only if you want to, @emilio) Thanks!
2017-03-07Completely rework templatesNick Fitzgerald
* Find each item's used template parameters when we begin the codegen phase * Add TemplateDeclaration::used_template_params() This method is available during the codegen phase, and uses the information gleaned by the `ir::named::UsedTemplateParameters` analysis. * Remove Item::{applicable_template_args,signature_contains_named_type} They are replaced by the template parameter usage analysis and TemplateDeclaration::used_template_params. * Parse and de-duplicate named template type parameters * Do not attempt to determine template parameter usage when not recursively whitelisting * Add a proper TemplateInstantiation type This makes it so that CompInfo is always either a compound type definition, or a template compound type definition, never an instantiation of a template. It also pulls out TypeKind::TemplateInstantiation(<inline stuff>) to a proper ir::TemplateInstantiation type, and TypeKind::TemplateInstantiation just wraps ir::TemplateInstantiation into TypeKind. * Allow template definitions to lack template parameters because of opaque template definitions * Detect and ignore cycles deriving Copy/Debug and whether a type has a vtable * Bail out early in the face of partial template specialization We don't support it, and shouldn't continue trying to parse a type from this cursor. * Do not consider inner type's parameter usage as our own parameter usage * Do not require a parent_id for template instantiations It is not necessary, and in fact was preventing us from creating template instantiations in some places, resulting in such nonsense as a generic template definition as a base for another type. * Only join if this is NOT a named template type or a template instantiation Otherwise, we'll always consider all of a template instantiation's arguments as used, when they should only be considered used if the template definition uses that template parameter. * Consider function return and parameter types as used Although we should not follow class method edges because we cannot create new monomorphizations of methods, code can create aliases of function pointers whose return or parameter types are template parameters, and those template parameters should be considered used. * Add the AsNamed trait for things which might be a named template type This sees through ResolvedTypeReferences to get at the final named type and its canonical item id. By using this in the named template parameter usage analysis, we ensure we don't have bugs where there are ResolvedTypeReferences in the usage sets rather than the canonical named item id, which could cause template parameters to be ignored accidentally. * Do not consider an inner var's template parameter usage as our own * Make the expectations' tests less noisy * Use opaque blobs for unknown template definition types When we don't know how to generate a Rust type from a template definition (eg because it uses non-type template parameters), then we should fall back to using the instantiation's layout to generate the opaque blob. * Implement CanDeriveDebug for TemplateInstantiation We need the template instantiation's layout to determine if we can derive debug for it when the instantiation's template definition has non-type parameters. * Stop thrashing malloc when unioning ItemSets in UsedTemplateParameters Previously, we were cloning an ItemSet, which requires a malloc for non-empty sets, when taking its union with our current id's set. Now, instead of doing that, we wrap each ItemSet in an Option, and take the set out of the hash map when modifying it. This allows us to side-step the borrow checker and HashMap's lack of an analog to `slice::split_at_mut` and mutate what is logically a value in the hash map while also using immutable references of values that are physically in the hash map. * Add some tests explicitly about template parameter usage * Updated test expectations now that we are inferring template parameter usage * Reinstate the layout tests for template instantiations * Generate opaque blobs for uses of partially specialized templates This adds `TypeKind::Opaque` which signifies that we do not understand anything about the given type and that we should just generate an opaque blob based on the type's layout. It explicitly uses the opaque type kind for partially specialized templates. * Add note about None vs Some([]) in TemplateDeclaration * Do not rely on TypeKind implementing PartialEq * Prefer assert_eq!(lhs, rhs) to assert!(lhs == rhs) * Expand some comments for ir::named::UsedTemplateParameters * Expand Item::is_opaque to consider TypeKind::Opaque * Use opaque types instead of panicking Use opaque types as our last resort when resolving type references after we have collected unresolved type references instead of panicking. * Find template definitions that don't want to be found * Recognize associated template types and make them opaque
2017-03-06codegen: Don't assume unsized structs have address.Emilio Cobos Álvarez
Per C semantics, they may not.
2017-03-05Use c_schar instead of c_charTristan Bruns
The signedness of the C type 'char' is implementation defined. The rust type c_schar exists for this reason. Use it.
2017-03-04objc: Whitelisting testMikko Lehtonen
2017-03-01tests: Mark the new test as unstable, since it seems to fail in 3.8.Emilio Cobos Álvarez
And I don't want nor have the time to debug it right now.
2017-03-01Follow proper derive rules for function pointers.Emilio Cobos Álvarez