Handle more shapes of template instantiations by recursively computing nullability annotations.

This change has to do with propagating nullability information through template instantiations. Previously, we used if-statements to "pattern match" over method calls of template instantiated classes and propagate their nullability information. However, this pattern matching only handled very specific expression shapes.

We are replacing the type pattern-matching with a recursive algorithm that can handle many type shapes, including templates with arguments that have more than one pointer type (e.g. a nested pointer or pair of pointers), or have no pointer at all (e.g., an integer argument). We are also adding support for propagating the nullability of templated member calls (e.g, x.f, where x is a template-instantiated class).

We have added test cases to cover the new functionality. We test member call expressions from structs with varying number of typename and int arguments. We have also added a test case with a struct that uses another struct template in a member variable. Nested member calls (for example, x.f.g) are commented out as the current implementation does not handle them.

PiperOrigin-RevId: 490708002
2 files changed
tree: 93a0a4cde14b1182fe7258849d0d2e8a92b5e953
  1. .bazelci/
  2. bazel/
  3. cc_bindings_from_rs/
  4. cc_import/
  5. cc_template/
  6. common/
  7. docs/
  8. lifetime_analysis/
  9. lifetime_annotations/
  10. migrator/
  11. nullability_verification/
  12. rs_bindings_from_cc/
  13. .bazelrc
  14. .gitignore
  15. BUILD
  16. Cargo.Bazel.lock
  17. CODE_OF_CONDUCT
  18. CONTRIBUTING
  19. LICENSE
  20. README.md
  21. WORKSPACE
README.md

Crubit: C++/Rust Bidirectional Interop Tool

Build status

Extremely experimental interop tooling for C++ and Rust.

Please don‘t use, this is an experiment and we don’t yet know where will it take us. There will be breaking changes without warning. Unfortunately, we can't take contributions at this point.

Building Crubit

$ apt install clang lld bazel
$ git clone git@github.com:google/crubit.git
$ cd crubit
$ bazel build --linkopt=-fuse-ld=/usr/bin/ld.lld //rs_bindings_from_cc:rs_bindings_from_cc_impl

Using a prebuilt LLVM tree

$ git clone https://github.com/llvm/llvm-project
$ cd llvm-project
$ CC=clang CXX=clang++ cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install
$ cmake --build build -j
$ # wait...
$ cmake --install build
$ cd ../crubit
$ LLVM_INSTALL_PATH=../llvm-project/install bazel build //rs_bindings_from_cc:rs_bindings_from_cc_impl