-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Implement lazy loading of external crates' sources. #42593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
70fa1fb
Added a `StableHasherResult` impl for `u128`.
ibabushkin 3d2cff0
Added source hashes to FileMap
ibabushkin dd8f7cd
Moved FileMap construction to it's own constructor.
ibabushkin c2c31b2
Added external crates' sources to FileMap.
ibabushkin c04aa4e
Improved lazy external source loading and inserted calls.
ibabushkin a5b8851
Added consumption logic for external sources in FileMap
ibabushkin 9a8bbe9
Added hash verification to external source loading.
ibabushkin 634cd2c
Updated UI tests to include rendered external spans.
ibabushkin afe8415
External spans: fixed unit tests and addressed review.
ibabushkin 271133b
External spans: address review.
ibabushkin d11973a
External spans: added lazy source loading elsewhere
ibabushkin bd4fe45
External spans: Added a test for #38875.
ibabushkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added consumption logic for external sources in FileMap
We now fetch source lines from the `external_src` member as a secondary fallback if no regular source is present, that is, if the file map belongs to an external crate and the source has been fetched from disk.
- Loading branch information
commit a5b8851e220d7a80222ea04d242603dd3392d17b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
#![cfg_attr(stage0, feature(rustc_private))] | ||
#![cfg_attr(stage0, feature(staged_api))] | ||
|
||
use std::borrow::Cow; | ||
use std::cell::{Cell, RefCell}; | ||
use std::ops::{Add, Sub}; | ||
use std::rc::Rc; | ||
|
@@ -605,24 +606,33 @@ impl FileMap { | |
|
||
/// get a line from the list of pre-computed line-beginnings. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, I can see where you got the bad style from though (this is very old code). |
||
/// line-number here is 0-based. | ||
pub fn get_line(&self, line_number: usize) -> Option<&str> { | ||
match self.src { | ||
Some(ref src) => { | ||
let lines = self.lines.borrow(); | ||
lines.get(line_number).map(|&line| { | ||
let begin: BytePos = line - self.start_pos; | ||
let begin = begin.to_usize(); | ||
// We can't use `lines.get(line_number+1)` because we might | ||
// be parsing when we call this function and thus the current | ||
// line is the last one we have line info for. | ||
let slice = &src[begin..]; | ||
match slice.find('\n') { | ||
Some(e) => &slice[..e], | ||
None => slice | ||
} | ||
}) | ||
pub fn get_line(&self, line_number: usize) -> Option<Cow<str>> { | ||
fn get_until_newline(src: &str, begin: usize) -> &str { | ||
// We can't use `lines.get(line_number+1)` because we might | ||
// be parsing when we call this function and thus the current | ||
// line is the last one we have line info for. | ||
let slice = &src[begin..]; | ||
match slice.find('\n') { | ||
Some(e) => &slice[..e], | ||
None => slice | ||
} | ||
None => None | ||
} | ||
|
||
let lines = self.lines.borrow(); | ||
let line = if let Some(line) = lines.get(line_number) { | ||
line | ||
} else { | ||
return None; | ||
}; | ||
let begin: BytePos = *line - self.start_pos; | ||
let begin = begin.to_usize(); | ||
|
||
if let Some(ref src) = self.src { | ||
Some(Cow::from(get_until_newline(src, begin))) | ||
} else if let Some(src) = self.external_src.borrow().get_source() { | ||
Some(Cow::Owned(String::from(get_until_newline(src, begin)))) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
|
@@ -641,7 +651,7 @@ impl FileMap { | |
} | ||
|
||
pub fn is_imported(&self) -> bool { | ||
self.src.is_none() // TODO: change to something more sensible | ||
self.src.is_none() | ||
} | ||
|
||
pub fn byte_length(&self) -> u32 { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a single method on
FileMap
. I'd even put the attempt to load the external source in that method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do that, since said method would have to be defined in a place where the
FileLoader
doesn't exist.