From ccb2dfbfec812d1502626992a8856df27c4fa950 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Jun 2019 11:35:26 +0300 Subject: don't ICE on large files This is an extremely marginal error, so the cost of properly threading `Handler` everywhere just not seemed justified. However, it's useful to panic when we create a file, and not when we slice strings with overflown indexes somewhere in the guts of the compiler. For this reason, while we provide safe `try_new_source_file`, we don't change the existing public interface and just panic more or less cleanly. --- src/libsyntax/source_map.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/libsyntax/source_map.rs') diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index a21d2df4162..c0307263387 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -191,6 +191,18 @@ impl SourceMap { /// If a file already exists in the source_map with the same id, that file is returned /// unmodified pub fn new_source_file(&self, filename: FileName, src: String) -> Lrc { + self.try_new_source_file(filename, src) + .unwrap_or_else(|OffsetOverflowError| { + eprintln!("fatal error: rustc does not support files larger than 4GB"); + errors::FatalError.raise() + }) + } + + fn try_new_source_file( + &self, + filename: FileName, + src: String + ) -> Result, OffsetOverflowError> { let start_pos = self.next_start_pos(); // The path is used to determine the directory for loading submodules and @@ -212,7 +224,7 @@ impl SourceMap { was_remapped, Some(&unmapped_path)); - return match self.source_file_by_stable_id(file_id) { + let lrc_sf = match self.source_file_by_stable_id(file_id) { Some(lrc_sf) => lrc_sf, None => { let source_file = Lrc::new(SourceFile::new( @@ -221,7 +233,7 @@ impl SourceMap { unmapped_path, src, Pos::from_usize(start_pos), - )); + )?); let mut files = self.files.borrow_mut(); @@ -230,7 +242,8 @@ impl SourceMap { source_file } - } + }; + Ok(lrc_sf) } /// Allocates a new SourceFile representing a source file from an external -- cgit 1.4.1-3-g733a5