rust/compiler
Tyler Mandry 934127cca5
Rollup merge of #76003 - richkadel:llvm-coverage-map-gen-6b.4, r=wesleywiser
Adds two source span utility functions used in source-based coverage

`span.is_empty()` - returns true if `lo()` and `hi()` are equal. This is
not only a convenience, but makes it clear that a `Span` can be empty
(that is, retrieving the source for an empty `Span` will return an empty
string), and codifies the (otherwise undocumented--in the rustc_span
package, at least) fact that `Span` is a half-open interval (where
`hi()` is the open end).

`source_map.lookup_file_span()` - returns an enclosing `Span`
representing the start and end positions of the file enclosing the given
`BytePos`. This gives developers a clear way to quickly determine if any
any other `BytePos` or `Span` is also from the same file (for example,
by simply calling `file_span.contains(span)`).

This results in much simpler code and is much more runtime efficient
compared with the obvious alternative: calling `source_map.lookup_line()`
for any two `Span`'s byte positions, handle both arms of the `Result`
(both contain the file), and then compare files. It is also more
efficient than the non-public method `lookup_source_file_idx()` for each
`BytePos`, because, while comparing the internal source file indexes
would be efficient, looking up the source file index for every `BytePos`
or `Span` to be compared requires a binary search (worst case
performance being O(log n) for every lookup).

`source_map.lookup_file_span()` performs the binary search only once, to
get the `file_span` result that can be used to compare to any number of
other `BytePos` or `Span` values and those comparisons are always O(1).

This PR was split out from PR #75828 .

r? @tmandry
FYI: @wesleywiser
2020-08-31 19:18:16 -07:00
..
rustc cleanup: Remove duplicate library names from Cargo.tomls 2020-08-30 22:57:54 +03:00
rustc_apfloat mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_arena mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_ast mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_ast_lowering mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_ast_passes mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_ast_pretty mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_attr mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_builtin_macros Use string literal directly when available in format 2020-08-30 22:09:58 +02:00
rustc_codegen_llvm cg_llvm: fewer_names in uncached_llvm_type 2020-08-31 11:20:52 +01:00
rustc_codegen_ssa Rollup merge of #76002 - richkadel:llvm-coverage-map-gen-6b.3, r=tmandry 2020-08-31 19:18:14 -07:00
rustc_data_structures datastructures: replace once_cell crate with an impl from std 2020-08-30 20:06:14 +01:00
rustc_driver datastructures: replace once_cell crate with an impl from std 2020-08-30 20:06:14 +01:00
rustc_error_codes mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_errors mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_expand Rollup merge of #76050 - matklad:pos, r=petrochenkov 2020-08-31 15:22:40 +02:00
rustc_feature mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_fs_util mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_graphviz mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_hir mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_hir_pretty mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_incremental mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_index mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_infer mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_interface Rollup merge of #76075 - marmeladema:remove-once-cell-crate, r=matklad 2020-08-31 15:22:42 +02:00
rustc_lexer Rollup merge of #76050 - matklad:pos, r=petrochenkov 2020-08-31 15:22:40 +02:00
rustc_lint mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_macros mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_metadata mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_middle Rollup merge of #76002 - richkadel:llvm-coverage-map-gen-6b.3, r=tmandry 2020-08-31 19:18:14 -07:00
rustc_mir Rollup merge of #76002 - richkadel:llvm-coverage-map-gen-6b.3, r=tmandry 2020-08-31 19:18:14 -07:00
rustc_mir_build mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_parse Rollup merge of #76115 - calebcartwright:parser-fn-visibility, r=matklad 2020-08-31 15:22:43 +02:00
rustc_parse_format mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_passes mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_plugin_impl mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_privacy mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_query_system mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_resolve Suggest if let x = y when encountering if x = y 2020-08-30 15:01:06 -07:00
rustc_save_analysis mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_serialize mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_session Rollup merge of #76002 - richkadel:llvm-coverage-map-gen-6b.3, r=tmandry 2020-08-31 19:18:14 -07:00
rustc_span Adds two source span utility functions used in source-based coverage 2020-08-31 18:41:57 -07:00
rustc_symbol_mangling mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_target mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_trait_selection mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_traits mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_ty mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_typeck Suggest if let x = y when encountering if x = y 2020-08-30 15:01:06 -07:00