summary refs log tree commit diff
path: root/compiler/rustc_span/src/source_map.rs
AgeCommit message (Collapse)AuthorLines
2022-10-20fix rust-lang#101880: suggest let for assignment, and some code refactoryukang-0/+20
2022-10-19Add testcase for next_point, fix more trivial issues in ↵yukang-6/+13
find_width_of_character_at_span
2022-10-18Fix the bug of next_point in spanyukang-3/+4
2022-09-01tracing::instrument cleanupOli Scherer-5/+5
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+0
by module
2022-08-23Remove generate_fn_name_span and generate_local_type_param_snippet.Camille GILLOT-87/+0
2022-08-22Show absolute line numbers if span is outside relative spanNilstrieb-1/+1
In the MIR pretty printing, it can sometimes happen that the span of the statement is outside the span of the body (for example through inlining). In this case, don't display a relative span but an absolute span. This will make the mir-opt-tests a little more prone to diffs again, but the impact should be small.
2022-08-19Auto merge of #100209 - cjgillot:source-file-index, r=estebankbors-3/+2
Lazily decode SourceFile from metadata Currently, source files from foreign crates are decoded up-front from metadata. Spans from those crates were matched with the corresponding source using binary search among those files. This PR changes the strategy by matching spans to files during encoding. This allows to decode source files on-demand, instead of up-front. The on-disk format for spans becomes: `<tag> <position from start of file> <length> <file index> <crate (if foreign file)>`.
2022-08-13fix span_extend_to_next_char docsGoldstein-1/+1
2022-08-08Remove unused parameter.Camille GILLOT-1/+0
2022-08-07Only encode position from start of file.Camille GILLOT-3/+1
2022-08-06Encode index of SourceFile along with span.Camille GILLOT-0/+2
2022-07-28Use line numbers relative to function in mir opt testsNilstrieb-0/+27
This adds a new option, `-Zmir-pretty-relative-line-numbers`, that is then used in compiletest for the mir-opt tests.
2022-07-25remove `is_local_span` as it is no longer usedTakayuki Maeda-11/+0
2022-07-20span: add `span_extend_to_line` helperDavid Wood-0/+5
Adds a simple helper function to the `SourceMap` for extending a `Span` to encompass the entire line it is on - useful for suggestions where removing a line is the suggested action. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-11rename a methodTakayuki Maeda-1/+1
2022-07-11implement `is_accessible_span`Takayuki Maeda-0/+7
2022-06-28fix ice for associated constant genericsTakayuki Maeda-1/+1
2022-06-02Address review comments.Nicholas Nethercote-2/+2
2022-06-01Lazify `SourceFile::lines`.Nicholas Nethercote-3/+10
`SourceFile::lines` is a big part of metadata. It's stored in a compressed form (a difference list) to save disk space. Decoding it is a big fraction of compile time for very small crates/programs. This commit introduces a new type `SourceFileLines` which has a `Lines` form and a `Diffs` form. The latter is used when the metadata is first read, and it is only decoded into the `Lines` form when line data is actually needed. This avoids the decoding cost for many files, especially in `std`. It's a performance win of up to 15% for tiny crates/programs where metadata decoding is a high part of compilation costs. A `Lock` is needed because the methods that access lines data (which can trigger decoding) take `&self` rather than `&mut self`. To allow for this, `SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather than returning the lines slice.
2022-05-26Avoid adjusting file positions twice.Nicholas Nethercote-7/+14
`imported_source_files` adjusts lots of file positions, and then calls `new_imported_source_file`, which then adjust them all again. This commit combines the two adjustments into one, for a small perf win.
2022-05-18Properly apply path prefix remapping paths emitted into debuginfo.Michael Woerister-0/+2
2022-05-18Move logic for making potentially remapped paths absolute into helper method.Michael Woerister-0/+79
2022-05-18Add debug tracing to FilePathMapping::map_prefixMichael Woerister-19/+34
2022-05-02fix most compiler/ doctestsElliot Roberts-4/+5
2022-04-29Fix duplicate directory separator in --remap-path-prefix.Michael Woerister-1/+13
2022-01-31Make `span_extend_to_prev_str()` more robustFabian Wolff-13/+27
2021-11-16Add SourceMap::indentation_before.Mara Bos-7/+12
2021-10-15Guess semicolon span for macro statementsCameron Steffen-0/+38
2021-09-20Add some more tracingOli Scherer-2/+3
2021-09-10Keep a parent LocalDefId in SpanData.Camille GILLOT-1/+1
2021-09-03Auto merge of #88363 - michaelwoerister:remapped-diagnostics, r=estebankbors-6/+17
Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix. This PR fixes a regression (#87745) with `--remap-path-prefix` where the flag stopped causing diagnostic messages to be remapped as well. The regression was introduced in https://github.com/rust-lang/rust/pull/83813 where we erroneously assumed that remapping of diagnostic messages was not desired anymore (because #70642 partially undid that functionality with nobody objecting). The issue is fixed by making `--remap-path-prefix` remap diagnostic messages again, including for paths that have been remapped in upstream crates (e.g. the standard library). This means that "sysroot-localization" (implemented in #70642) is also disabled if `rustc` is invoked with `--remap-path-prefix`. The assumption is that once someone starts explicitly remapping paths they also don't want paths to their local Rust installation in their build output. In the future we might want to give more fine-grained control over this behavior via compiler flags (see https://github.com/rust-lang/rfcs/pull/3127 for a related RFC). For now this PR is intended as a regression fix. This PR is an alternative to https://github.com/rust-lang/rust/pull/88191, which makes diagnostic messages be remapped unconditionally. That approach, however, would effectively revert #70642. Fixes https://github.com/rust-lang/rust/issues/87745. cc `@cbeuw` r? `@ghost`
2021-08-27Don't use `guess_head_span` in `predicates_of` for foreign spanAaron Hill-0/+11
Previously, the result of `predicates_of` for a foreign trait would depend on the *current* state of the corresponding source file in the foreign crate. This could lead to ICEs during incremental compilation, since the on-disk contents of the upstream source file could potentially change without the upstream crate being recompiled. Additionally, this ensure that that the metadata we produce for a crate only depends on its *compiled* upstream dependencies (e.g an rlib or rmeta file), *not* the current on-disk state of the upstream crate source files.
2021-08-27Path remapping: Make behavior of diagnostics output dependent on presence of ↵Michael Woerister-6/+17
--remap-path-prefix.
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-20/+15
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-07-01Avoid byte to char position conversions in is_multilineTomasz Miąsko-3/+7
Converting a byte position into a char position is currently linear in the number of multibyte characters in the source code. Avoid it when checking if a range spans across lines. This makes it feasible to compile source files with a large number of multibyte characters.
2021-06-21Encode SourceFile source crate as StableCrateId in incr. comp. OnDiskCache.Michael Woerister-2/+2
2021-06-21Disambiguate between SourceFiles from different crates even if they have the ↵Michael Woerister-10/+31
same path.
2021-06-09Print dummy spans as `no-location`Tomasz Miąsko-1/+1
2021-05-12Auto merge of #83813 - cbeuw:remap-std, r=michaelwoeristerbors-69/+43
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-11Split span_to_string into span_to_diagnostic/embeddable_stringAndy Wang-2/+14
2021-05-07Use `path.exists()` instead of `fs::metadata(path).is_ok()`Chris Denton-1/+1
It's more explicit and allows platforms to optimize the existence check.
2021-05-05Use local and remapped paths where appropriateAndy Wang-6/+1
2021-05-05Make local_path in RealFileName::Remapped Option to be removed in exported ↵Andy Wang-19/+16
metadata
2021-05-05Rename RealFileName::Named to LocalPath and Devirtualized to RemappedAndy Wang-61/+31
2021-03-17Move some test-only code to test filesJoshua Nelson-42/+0
This also relaxes the bounds on some structs and moves them to the impl block instead.
2021-02-17Rollup merge of #81860 - osa1:issue81800, r=estebankDylan DPC-12/+30
Fix SourceMap::start_point `start_point` needs to return the *first* character's span, but it would previously call `find_width_of_character_at_span` which returns the span of the *last* character. The implementation is now fixed. Other changes: - Docs for start_point, end_point, find_width_of_character_at_span updated - Minor simplification in find_width_of_character_at_span code Fixes #81800
2021-02-07Fix SourceMap::start_pointÖmer Sinan Ağacan-12/+30
`start_point` needs to return the *first* character's span, but it would previously call `find_width_of_character_at_span` which returns the span of the *last* character. The implementation is now fixed. Other changes: - Docs for start_point, end_point, find_width_of_character_at_span updated - Minor simplification in find_width_of_character_at_span code Fixes #81800
2021-02-04faster spansklensy-8/+9