Giter Site home page Giter Site logo

Comments (8)

adetaylor avatar adetaylor commented on May 22, 2024

There seem to be three problems here:

  • Sometimes bindgen correctly emits the templated type as a Rust generic. We weren't handling that correctly; we were passing such types onto cxx::bridge as type aliases and that resulted in errors. Fixed in #107 . Note that this doesn't allow us to use such types in client code, but it means they no longer break usage of downstream types (e.g. Origin in the above example).
  • bindgen does not handle types with associated types. This may be a known limitation. Issue reported here in case it's do-able. rust-lang/rust-bindgen#1924
  • Our suppression of std::string is causing trouble when it's used in templated types. Maybe there's some way we can make it more opaque but still allow it.

from autocxx.

adetaylor avatar adetaylor commented on May 22, 2024

To be specific on the last point: we are expunging all mention of std::string from bindgen output by means of a prelude and a blocklist. So, when we encounter a type (base::StringPiece) which fundamentally depends on std::string (or specifically std::string::value_type) - shock - it doesn't work!

I am planning to see if I can persuade bindgen to output enough of std::string for this to work, without so much that everything breaks.

from autocxx.

adetaylor avatar adetaylor commented on May 22, 2024

It turns out bindgen does a creditable job of producing bindings for std::string. I doubt they truly represent the real layout in memory, and of course they don't represent the pinned nature of it, but they are internally consistent and build. However, the arrangement of types generated by bindgen is predictably fragile, and our various alterations break everything. That being the case, here are some options:

  1. Allow bindgen bindings to pass through to the resulting code untouched. Use them as a guide to generate extra bindings, both in the bindgen output mod, and elsewhere (in the cxx::bridge mod and the top level mod), but don't change anything.
  2. As above, but do alter types to be non-POD unless the user has specifically asked for them to be POD. This is fiddly.
  3. As above, but switch from a POD allowlist to a POD blocklist, and pass that blocklist to bindgen such that it can make types opaque.
  4. Continue to meddle with bindgen bindings as we do now, but allow the user to mark some types as opaque.

from autocxx.

adetaylor avatar adetaylor commented on May 22, 2024

Current state of play:

  • bindgen doesn't correctly identify that some types are templated, per rust-lang/rust-bindgen#1924. I'm working on this in the background. For such types, we don't really stand a chance - we inevitably tell C++ that this is a plain old type not a templated type, and that results in compilation failures. That accounts for the need to block! some types in my current real-world experiments e.g. https://twitter.com/adehohum/status/1334732132522967041. In general though bindgen does a really remarkable job of passing on the generic-ness of types to us.
  • cxx does not understand generic types (as far as I understand it) with the exception of those it knows about - std::vector, etc. So for other generic types we have to squash them down to a flat type on their way between bindgen and cxx.
  • So, since #161, we now recognize the impending doom, and generate a typedef in C++ to turn each concrete instance into a type of its own.
  • We do not attach methods to such types. This could be achieved relatively easily. The same applies to constructors.
  • Such types are always opaque.
  • So at the moment, such types are only useful if they're returned by one function and then you pass them to another. You can't interact with them in any other way.
  • #162 says we don't even test that properly 👍

Next steps here:

  • Consider whether we can allow cxx to understand generic types. This would be a big lift but would make things much better.
  • Otherwise, consider attaching methods and constructors to our synthesized concrete types.
  • In parallel, continue to work on that bindgen stuff.

from autocxx.

dtolnay avatar dtolnay commented on May 22, 2024

cxx does not understand generic types (as far as I understand it) with the exception of those it knows about - std::vector, etc. So for other generic types we have to squash them down to a flat type on their way between bindgen and cxx.

It would be good to get this implemented upstream as extern "C++" { type Container<T>; }.

from autocxx.

adetaylor avatar adetaylor commented on May 22, 2024

Current state of play here with respect to Chromium:

from autocxx.

adetaylor avatar adetaylor commented on May 22, 2024

I posted a status update to rust-lang/rust-bindgen#1924

from autocxx.

adetaylor avatar adetaylor commented on May 22, 2024

I'm removing the "bug" label here since we now gracefully avoid mis-generations in such cases. As such this now becomes a C++ feature for which we need to add support.

from autocxx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.