rust/compiler/rustc_metadata/src
Yuki Okushi 3500e76330
Rollup merge of #85889 - denismerigoux:master, r=petrochenkov
Restoring the `num_def_ids` function in the CStore API

## The context

I am the maintainer of https://github.com/hacspec/hacspec, an embedded Rust DSL aimed at cryptographic specifications. As it is normal for an embedded DSL, Hacspec's compiler relies on being plugged to the internal API of the Rust compiler, which is unstable and subject to changes.

## The problem

The Hacspec compiler features its own typechecker, that performs an additional, more restrictive typechecking pass over the Rust code of a crate. To complete this typechecking, the Hacspec compiler needs to retrieve the signature of functions defined in non-local imported crates. Rather than retrieving these signatures on-demand, the Hacspec compiler pre-populates its typechecking context with all the Hacspec-compatible symbols defined in non-local crates first. This requires having a way to iterate over all the definitions in a non-local crate.

I used to do this with `CrateMetadata::all_def_path_hashes_and_def_ids`, but this function was deleted in 908bf5a310. Then, I fellback on `CStore::num_def_ids`, exploiting the fact that all the `DefIds` for a crate have the same `krate_num` and range from `0` to `num_def_ids(krate_num)`. But `num_def_ids` was deleted in b6120bfb35.

I looked to the `Cstore::item_children_untracked` function to replicate the feature of traversing through all the `DefId` for a crate, using `CRATE_DEF_INDEX` as the root, but this does not work as recursive `Cstore::item_children_untracked` calls do not reach all the symbols I was able to reach using the two previous methods.

## Description of this PR

This PR simply restores in the public API of `CStore` the `num_def_ids` function, giving the size of the definition table for a given crate.
2021-06-04 13:42:56 +09:00
..
dynamic_lib
rmeta Rollup merge of #85889 - denismerigoux:master, r=petrochenkov 2021-06-04 13:42:56 +09:00
creader.rs Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
dependency_format.rs Collapse all uses of target.options.foo into target.foo 2020-11-08 17:29:13 +03:00
dynamic_lib.rs Change 'NULL' to 'null' 2021-05-02 17:46:00 -06:00
foreign_modules.rs Only store a LocalDefId in hir::ForeignItem. 2021-02-15 19:32:29 +01:00
lib.rs Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
locator.rs Merge CrateDisambiguator into StableCrateId 2021-05-30 12:51:34 +02:00
native_libs.rs Implement RFC 2951: Native link modifiers 2021-05-05 16:04:25 -07:00