Skip to content
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

Make CodeMap and FileMap thread-safe #48904

Merged
merged 5 commits into from
Mar 17, 2018
Merged

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Mar 10, 2018

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 10, 2018
Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @Zoxc! The code looks correct to me. What we really should do though is make FileMap immutable. Except for the external_src business, a FileMap should only ever be modified during parsing. Maybe we can refactor things so that the parser works with a &mut FileMap?

// This is used to apply the file path remapping as specified via
// --remap-path-prefix to all FileMaps allocated within this CodeMap.
path_mapping: FilePathMapping,
stable_id_to_filemap: RefCell<FxHashMap<StableFilemapId, Lrc<FileMap>>>,
stable_id_to_filemap: Lock<FxHashMap<StableFilemapId, Lrc<FileMap>>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to put stable_id_to_filemap into the same Lock as files since they should be modified atomically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably also remove files altogether since stable_id_to_filemap seems to contain the same information?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We address FileMaps by their index in the files array quite a bit. For now, I would just keep both data structures.

/// Width of characters that are not narrow in the source code
pub non_narrow_chars: RefCell<Vec<NonNarrowChar>>,
pub non_narrow_chars: Lock<Vec<NonNarrowChar>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines, multibyte_chars, and non_narrow_chars should probably be within the same Lock too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields aren't atomically updated, but incrementally updated during parsing. So they aren't really thread-safe until after parsing. We should probably split them out of FileMap and atomically update them after parsing, or pass &mut FileMap to the parser, so no one can observe them changing. We could also use compute them lazily with a query. That may be a performance win if they are unused when no diagnostics are emitted.

Copy link
Member

@michaelwoerister michaelwoerister Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use compute them lazily with a query. That may be a performance win if they are unused when no diagnostics are emitted.

I think they are used almost always because we need them for debuginfo and panic messages.

I would like FileMap to be immutable if possible. The parser could keep it's own mutable version and only register it with the CodeMap when it is finished (at which point the codemap could apply the relevant offsets), or the parser could reserve the address range beforehand if that's much more performant.

@michaelwoerister
Copy link
Member

@Zoxc, will you be looking into making FileMap immutable as part of this PR or should we do it in a subsequent one?

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 14, 2018

I'd prefer to do that in a separate PR. I added it to my list of things to fix.

@michaelwoerister
Copy link
Member

OK. The issue with stable_id_to_filemap and files being in separate mutexes should be solved in this PR though. Can you look into it? Otherwise this is good to go, I think!

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 14, 2018

I added a commit which addresses that.

@michaelwoerister
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 15, 2018

📌 Commit 65b4990 has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 15, 2018
@bors
Copy link
Contributor

bors commented Mar 17, 2018

⌛ Testing commit 65b4990 with merge c3fd5d0...

bors added a commit that referenced this pull request Mar 17, 2018
@bors
Copy link
Contributor

bors commented Mar 17, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: michaelwoerister
Pushing c3fd5d0 to master...

@bors bors merged commit 65b4990 into rust-lang:master Mar 17, 2018
@Zoxc Zoxc deleted the code-and-file-maps branch March 17, 2018 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants