about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2019-06-17 11:35:26 +0300
committerAleksey Kladov <aleksey.kladov@gmail.com>2019-06-17 19:34:47 +0300
commitccb2dfbfec812d1502626992a8856df27c4fa950 (patch)
tree42a95f16caa5f4b40e32e5ce672ddf85d383fece /src/libsyntax
parent70456a6cbd67c0547d22997007afaaed0819767e (diff)
downloadrust-ccb2dfbfec812d1502626992a8856df27c4fa950.tar.gz
rust-ccb2dfbfec812d1502626992a8856df27c4fa950.zip
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.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/source_map.rs19
1 files changed, 16 insertions, 3 deletions
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<SourceFile> {
+        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<Lrc<SourceFile>, 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