Commit Graph

34 Commits

Author SHA1 Message Date
Urgau 8cbfb26383 Overhaul filename handling for cross-compiler consistency
This commit refactors `SourceMap` and most importantly `RealFileName` to
make it self-contained in order to achieve cross-compiler consistency.

This is achieved:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
 - by also making `RealFileName` holds it's working directory,
   it's embeddable name and the remapped scopes
 - by making most `FileName` and `RealFileName` methods take a scope as
   an argument

In order for `SourceMap::to_real_filename` to know which scopes to apply
`FilePathMapping` now takes the current remapping scopes to apply, which
makes `FileNameDisplayPreference` and company useless and are removed.

The scopes type `RemapPathScopeComponents` was moved from
`rustc_session::config` to `rustc_span`.

The previous system for scoping the local/remapped filenames
`RemapFileNameExt::for_scope` is no longer useful as it's replaced by
methods on `FileName` and `RealFileName`.
2025-12-12 07:33:09 +01:00
Weihang Lo cf57b9b292 fix(span): track unnormalized source len for dep-info
Add `unnormalized_source_len` field to track the byte length
of source files before normalization (the original length).

`unnormalized_source_len` is for writing the correct file length
to dep-info for `-Zchecksum-hash-algorithm`
2025-11-15 09:05:08 -05:00
Weihang Lo 5f385829e2 refactor(span): rename source_len to normalized_source_len
This is a preparation for introducing a unnormalized source length field
2025-11-15 09:05:08 -05:00
Urgau 6a7996e303 Take into-account -Zremap-path-scope when embedding filenames 2025-05-05 19:45:34 +02:00
Askar Safin 0a21f1d0a2 tree-wide: parallel: Fully removed all Lrc, replaced with Arc 2025-02-03 13:25:57 +03:00
Nicholas Nethercote 4547c0a990 Avoid another &Lrc<..> in a return value. 2024-10-07 13:59:50 +11:00
Jacob Kiesel bb5a8276be add unstable support for outputting file checksums for use in cargo 2024-10-01 21:23:20 -06:00
Esteban Küber 2d7795dfb9 Be more accurate about calculating display_col from a BytePos
No longer track "zero-width" chars in `SourceMap`, read directly from the line when calculating the `display_col` of a `BytePos`. Move `char_width` to `rustc_span` and use it from the emitter.

This change allows the following to properly align in terminals (depending on the font, the replaced control codepoints are rendered as 1 or 2 width, on my terminal they are rendered as 1, on VSCode text they are rendered as 2):

```
error: this file contains an unclosed delimiter
  --> $DIR/issue-68629.rs:5:17
   |
LL | ␜␟ts␀![{i
   |       -- unclosed delimiter
   |       |
   |       unclosed delimiter
LL | ␀␀  fn rݻoa>rݻm
   |                ^
```
2024-07-18 20:08:38 +00:00
Vadim Petrochenkov b40ea03f8a rustc_index: Add a ZERO constant to index types
It is commonly used.
2024-04-03 19:06:22 +03:00
surechen a61126cef6 By tracking import use types to check whether it is scope uses or the other situations like module-relative uses, we can do more accurate redundant import checking.
fixes #117448

For example unnecessary imports in std::prelude that can be eliminated:

```rust
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
```
2024-02-18 16:38:11 +08:00
r0cky c7519d42c2 Update tests 2024-02-07 10:42:01 +08:00
Vadim Petrochenkov 90d11d6448 rustc_span: Optimize syntax context comparisons
Including comparisons with root context
2024-01-06 01:25:20 +03:00
Michael Woerister fa8ef25372 Unify SourceFile::name_hash and StableSourceFileId 2023-12-19 22:34:26 +01:00
surechen 40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Urgau eccc9e6628 [RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopes 2023-10-17 10:11:30 +02:00
Ben Kimock 5f33647fb3 Add unit tests based on files that return odd sizes to stat 2023-09-20 21:01:13 -04:00
John Kåre Alsaker f49382c050 Use Freeze for SourceFile.lines 2023-09-07 13:05:05 +02:00
Camille GILLOT 548ba13265 Register the file while computing its start position. 2023-09-03 15:02:46 +00:00
Camille GILLOT 258ace613d Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
bors 65d2f2a5f9 Auto merge of #106810 - oli-obk:resolver_reverse_plumbing, r=petrochenkov
Various cleanups around pre-TyCtxt queries and functions

part of #105462

based on https://github.com/rust-lang/rust/pull/106776 (everything starting at [0e2b39f](https://github.com/rust-lang/rust/pull/106810/commits/0e2b39fd1ffde51b50d45ccbe41de52b85136b8b) is new in this PR)

r? `@petrochenkov`

I think this should be most of the uncontroversial part of #105462.
2023-01-19 05:23:40 +00:00
Oli Scherer 1355559367 Avoid an unnecessary allocation 2023-01-16 14:46:44 +00:00
Tim Neumann 869df76764 Heuristically undo path prefix mappings.
Because the compiler produces better diagnostics if it can find the
source of (potentially remapped) dependencies.
2023-01-14 12:49:37 +00:00
yukang 6d455296fd Fix #103451, find_width_of_character_at_span return width with 1 when reaching end 2022-10-25 21:16:12 +08:00
yukang eb8aa9759d Add testcase for next_point, fix more trivial issues in find_width_of_character_at_span 2022-10-19 21:08:00 +08:00
Camille GILLOT 0d41f9145c Remove unused parameter. 2022-08-08 21:12:04 +02:00
Camille GILLOT f20ceb1c6f Encode index of SourceFile along with span. 2022-08-06 22:33:06 +02:00
Michael Woerister 9e7b0ff2e1 Add tests for FilePathMapping::to_embeddable_absolute_path(). 2022-05-18 11:42:43 +02:00
Michael Woerister 3614bd3c45 Fix duplicate directory separator in --remap-path-prefix. 2022-04-29 21:09:12 +02:00
Andy Wang 37dbe868c9 Split span_to_string into span_to_diagnostic/embeddable_string 2021-05-11 00:04:12 +01:00
Andy Wang 6720a37042 Rename RealFileName::Named to LocalPath and Devirtualized to Remapped 2021-05-05 15:10:50 +01:00
Joshua Nelson 620ecc01a2 Move some test-only code to test files
This also relaxes the bounds on some structs and moves them to the impl
block instead.
2021-03-17 10:31:30 -04:00
Eduard-Mihai Burtescu 6165d1cc72 Print -Ztime-passes (and misc stats/logs) on stderr, not stdout. 2021-02-18 14:13:38 +02:00
LingMan a56bffb4f9 Use Option::map_or instead of .map(..).unwrap_or(..) 2021-01-14 19:23:59 +01:00
mark 9e5f7d5631 mv compiler to compiler/ 2020-08-30 18:45:07 +03:00