-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
A-parallel-compilerArea: parallel compilerArea: parallel compilerC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
librustc_span contains a concurrency bug. Even though, rustc works without any problem.
(I guess rustc process does not use multiples threads to load file to sourcemap.)
rust/src/librustc_span/source_map.rs
Lines 216 to 261 in 0176a9e
| 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 | |
| // include files, so it must be before remapping. | |
| // Note that filename may not be a valid path, eg it may be `<anon>` etc, | |
| // but this is okay because the directory determined by `path.pop()` will | |
| // be empty, so the working directory will be used. | |
| let unmapped_path = filename.clone(); | |
| let (filename, was_remapped) = match filename { | |
| FileName::Real(filename) => { | |
| let (filename, was_remapped) = self.path_mapping.map_prefix(filename); | |
| (FileName::Real(filename), was_remapped) | |
| } | |
| other => (other, false), | |
| }; | |
| let file_id = | |
| StableSourceFileId::new_from_pieces(&filename, was_remapped, Some(&unmapped_path)); | |
| 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( | |
| filename, | |
| was_remapped, | |
| unmapped_path, | |
| src, | |
| Pos::from_usize(start_pos), | |
| )?); | |
| let mut files = self.files.borrow_mut(); | |
| files.source_files.push(source_file.clone()); | |
| files.stable_id_to_source_file.insert(file_id, source_file.clone()); | |
| source_file | |
| } | |
| }; | |
| Ok(lrc_sf) | |
| } |
When multiple threads invoked this method at a time, it results in overlapping spans.
(Because the lock is released while analyzing the source file)
Meta
Simple fix: https://github.com/swc-project/swc/pull/672/files#diff-8d69cef1163ff9667c130830b15da62bL181-L188
Metadata
Metadata
Assignees
Labels
A-parallel-compilerArea: parallel compilerArea: parallel compilerC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.