summaryrefslogtreecommitdiff
path: root/src/ir/function.rs
AgeCommit message (Collapse)Author
2017-09-19DerivePartialEq → DerivePartialEqOrPartialOrdSergey Pepyakin
2017-09-07Use `quote` instead of `syntex` for Rust code generationNick Fitzgerald
The `syntex` crate is unmaintained. It is slow to build, and additionally it requires that we pre-process `src/codegen/mod.rs` before we build the `bindgen` crate. The `quote` crate provides similar quasi-quoting functionality, is maintained, and builds faster. It doesn't have a typed API or builders, however; it only deals with tokens. Before this commit: ``` $ cargo clean; cargo build <snip> Finished dev [unoptimized + debuginfo] target(s) in 98.75 secs ``` After this commit: ``` $ cargo clean; cargo build <snip> Finished dev [unoptimized + debuginfo] target(s) in 46.26 secs ``` Build time is cut in half! But what about run time? Before this commit: ``` Generated Stylo bindings in: Duration { secs: 3, nanos: 521105668 } ``` After this commit: ``` Generated Stylo bindings in: Duration { secs: 3, nanos: 548797242 } ``` So it appears to be about 20ms slower at generating Stylo bindings, but I suspect this is well within the noise. Finally, this also lets us remove that nasty `mem::transmute` inside `bindgen::ir::BindgenContext::gen` that was used for the old `syntex` context. Now `BindgenContext` doesn't have a lifetime parameter either. This should make it easier to revisit doing our analyses in parallel with `rayon`, since that context was one of the things that made it hard for `BindgenContext` to implement `Sync`. Fixes #925
2017-08-21Rename `TypeKind::Named` to `TypeKind::TypeParam`Anna Liao
Also renames a bunch of other things referring to named types to refer to type parameters. Fixes #915
2017-08-14Can derive PartialEq analysisZhiting Zhu
2017-08-09Can derive Hash analysiszzhu
2017-08-02Clean up trivially derive debugzzhu
2017-07-25s/servo/rust-lang-nursery/ \o/Nick Fitzgerald
Fixes #852
2017-07-20Only whitelist items which we intend to generate code forNick Fitzgerald
This makes only generating certain kinds of items more robust, since we don't need to keep checking whether codegen is enabled for different kinds of items all over the place, and can do it the once. It should also reduce the number of items we have to consider in our various analyses for which we don't ultimately care about the answer. Fixes #826
2017-07-20Escape mangled function namesNick Fitzgerald
Windows uses non-ascii and non-visual characters in mangled names T.T
2017-07-20Use fix point analysis to implement the can_derive_debugzzhu
2017-07-18Stop Rust from prepending underscore before '?' for win32Xidorn Quan
2017-07-10codegen: Make comments indentation-aware.Emilio Cobos Álvarez
This commit moves comment processing to a central place (well, two, because of field docs, but that's fine). Also, it makes comments indentation aware, so multiline comments don't appear garbled. Finally, it also fixes an out-of-bounds panic when processing an empty multiline comment.
2017-07-08Intelligently convert C/C++ comments to RustDylan McKay
With this change, we can correctly parse C++ block comments. ``` /** * Does a thing * * More documentation. This test does something * useful. */ ``` into ``` /// Does a thing /// /// More documentation. This test does something /// useful. ``` Fixes servo/rust-bindgen#426.
2017-06-16Correct mangling hack for win32Xidorn Quan
2017-06-15ir: Correct mac target check.Emilio Cobos Álvarez
Because I'm stupid.
2017-06-02ir: Give a better error message for unknown ABI.Emilio Cobos Álvarez
Fixes #727
2017-06-01ir: Use the mangling hack in win32 too.Emilio Cobos Álvarez
Fixes #593 Fixes #728
2017-05-26ir: Don't panic when finding an unknown calling convention until code ↵Emilio Cobos Álvarez
generation.
2017-05-24Fix osx mangling hackzzhu
Rust automatically adds one _ in the symbol. If we don't remove it, we will endup getting three _.
2017-05-03objc: Fix infinite recursionMikko Lehtonen
While parsing a Objective C property with function pointer type, bindgen hanged and died. This is still not generating valid code function signature for the property, but at least it is not dying. The actual fix was proposed by emilio.
2017-04-23ir: Try to get C++ manglings with the appropriate API first.Emilio Cobos Álvarez
As pointed out in #653, clang 3.8 asserts when trying to mangle a C++ constructor or a destructor. The following patch tries to use the `clang_Cursor_getCXXManglings` function first. This assumes that the last mangling we're interested in is the proper one, which seems to be true looking at LLVM, and on trunk on my machine.
2017-04-04ir: Add a note about cpp_demangle.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-04ir: Force the D1 destructor symbol even in older libclang versions.Emilio Cobos Álvarez
2017-03-20options: Allow force-generating inline functions.Emilio Cobos Álvarez
2017-03-07objc: Implement class methodsMikko Lehtonen
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-01Follow proper derive rules for function pointers.Emilio Cobos Álvarez
2017-02-23Auto merge of #532 - emilio:random-bugfixes, r=fitzgenbors-servo
Add a workaround for #528, and fix #527 r? @fitzgen
2017-02-21Add more `EdgeKind`sNick Fitzgerald
2017-02-19Add an option to distrust clang mangling.Emilio Cobos Álvarez
2017-02-17Implement DotAttribute for a bunch of typesNick Fitzgerald
This gives us more debug information in the emitted graphviz dot files.
2017-02-13Run `cargo fmt`Nick Fitzgerald
2017-02-13Refactor IR graph traversal infrastructureNick Fitzgerald
This makes the IR traversal infrastructure generic. It makes it so we can use the same traversal code for whitelisting traversals and asserting no dangling item references. Therefore the queue of items to visit is generic (whitelisting uses DFS, while asserting against dangling uses BFS), the storage for the seen set (whitelisting uses a simple set, asserting against dangling uses a map from item to the item from which it was discovered). It also introduces the concept of different kinds of edges in the IR graph, and the ability to choose which edges to follow. This means we can simplify non-transitive whitelisting to a simple function that always returns "no do not follow this edge". It plays an important part for future analysis of which template declaration type parameters are used or not.
2017-02-13Rename ir::traversal::TypeCollector to ir::traversal::TraceNick Fitzgerald
And its `collect_types` method to `trace`.
2017-02-13Move TypeCollector to the ir::traversal moduleNick Fitzgerald
2017-02-13Rename WhitelistedItemsIter to ItemTraversalNick Fitzgerald
Also moves it out to its own ir::traversal module, and moves ItemSet to the ir::item module.
2017-02-08Run `cargo fmt`Nick Fitzgerald
2017-02-06Make abi optional for FunctionSigMikko Lehtonen
2017-02-05objc: Support method argumentsMikko Lehtonen
2017-02-03Run `cargo fmt`Nick Fitzgerald
2017-02-02ir: Fix is_in_non_fully_specialized_template check.Emilio Cobos Álvarez
Fixes https://github.com/servo/rust-bindgen/issues/462
2017-01-24Make it work in rust stable, and incidentally fix #425Emilio Cobos Álvarez
The problem with #425 was the following: We were parsing the methods after reaching the JS::Value definition. Those methods contained a JSWhyMagic that we hadn't seen, so we parsed it as being in the JS:: module.
2017-01-23Unify under the `bindgen` name.Emilio Cobos Álvarez
2016-11-16Transition to libbindgen sub-crateJeff Waugh
- The root crate is the `bindgen` binary - Rust-ify the test suite, no more subprocesses! - Update Travis config to test both crates
2016-11-15ir: Make the id local to the context.Emilio Cobos Álvarez
2016-11-14Clean up TypeCollector implementationsNick Fitzgerald
Rather than making `TypeCollector` implementations recursively call `type_collector` on their subtypes, just gather immediate subtypes into the `ItemSet`. The subtypes' `TypeCollector` implementation will be recursively called by `WhitelistedItemsIter`. This makes it less likely we will "skip" a layer by recursively calling `collect_types` on some subtypes without adding the subtypes themselves to the set.
2016-11-03clang: Simplify visiting code.Emilio Cobos Álvarez
It has always been a mess.
2016-11-01Run `cargo fmt`.Emilio Cobos Álvarez