-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fixes the double execution when generated files didn't exist yet #3093
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use std::{ | ||
collections::{hash_map::Entry, HashMap}, | ||
hash::Hash, | ||
marker::PhantomData, | ||
}; | ||
|
||
use parking_lot::Mutex; | ||
use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
use turbo_tasks::event::Event; | ||
|
||
pub struct MutexMap<K> { | ||
map: Mutex<HashMap<K, Option<(Event, usize)>>>, | ||
} | ||
|
||
impl<K> Default for MutexMap<K> { | ||
fn default() -> Self { | ||
Self { | ||
map: Mutex::new(HashMap::new()), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, K: Eq + Hash + Clone> MutexMap<K> { | ||
pub async fn lock(&'a self, key: K) -> MutexMapGuard<'a, K> { | ||
let listener = { | ||
let mut map = self.map.lock(); | ||
match map.entry(key.clone()) { | ||
Entry::Occupied(mut e) => { | ||
let state = e.get_mut(); | ||
Some(match state { | ||
Some((event, count)) => { | ||
*count += 1; | ||
event.listen() | ||
} | ||
None => { | ||
let event = Event::new(|| "MutexMap".to_string()); | ||
let listener = event.listen(); | ||
*state = Some((event, 0)); | ||
listener | ||
} | ||
}) | ||
} | ||
Entry::Vacant(e) => { | ||
e.insert(None); | ||
None | ||
} | ||
} | ||
}; | ||
if let Some(listener) = listener { | ||
listener.await; | ||
} | ||
MutexMapGuard { | ||
map: self, | ||
key: Some(key), | ||
} | ||
} | ||
} | ||
|
||
pub struct MutexMapGuard<'a, K: Eq + Hash> { | ||
map: &'a MutexMap<K>, | ||
key: Option<K>, | ||
} | ||
|
||
impl<'a, K: Eq + Hash> Drop for MutexMapGuard<'a, K> { | ||
fn drop(&mut self) { | ||
if let Some(key) = self.key.take() { | ||
let mut map = self.map.map.lock(); | ||
if let Entry::Occupied(mut e) = map.entry(key) { | ||
let value = e.get_mut(); | ||
match value { | ||
Some((event, count)) => { | ||
event.notify(1); | ||
if *count == 0 { | ||
*value = None; | ||
} else { | ||
*count -= 1; | ||
} | ||
} | ||
None => { | ||
e.remove(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<K> Serialize for MutexMap<K> { | ||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
serializer.serialize_unit() | ||
} | ||
} | ||
|
||
impl<'de, K> Deserialize<'de> for MutexMap<K> { | ||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
struct Visitor<K>(PhantomData<MutexMap<K>>); | ||
impl<'de, K> serde::de::Visitor<'de> for Visitor<K> { | ||
type Value = MutexMap<K>; | ||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
formatter.write_str("a unit") | ||
} | ||
fn visit_unit<E: serde::de::Error>(self) -> Result<Self::Value, E> { | ||
Ok(MutexMap::default()) | ||
} | ||
} | ||
deserializer.deserialize_unit(Visitor(std::marker::PhantomData)) | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -25,10 +25,10 @@ impl CompletionVc { | |
/// new invalidation. | ||
pub fn unchanged() -> Self { | ||
// This is the same code that CompletionVc::cell uses except that it | ||
// in fact compares the cell (CompletionVc::cell opted-out of | ||
// only updates the cell when it is empty (CompletionVc::cell opted-out of | ||
// that via `#[turbo_tasks::value(cell = "new")]`) | ||
let cell = turbo_tasks::macro_helpers::find_cell_by_type(*COMPLETIONS_VALUE_TYPE_ID); | ||
cell.compare_and_update_shared(Completion); | ||
let cell = turbo_tasks::macro_helpers::find_cell_by_type(*COMPLETION_VALUE_TYPE_ID); | ||
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. The bug was here. -COMPLETIONS_VALUE_TYPE_ID
+COMPLETION_VALUE_TYPE_ID So annoying... |
||
cell.conditional_update_shared(|old| old.is_none().then_some(Completion)); | ||
let raw: RawVc = cell.into(); | ||
raw.into() | ||
} | ||
|
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.
Why not just skip the field?
But the whole map is also already skipped in the
DiskFileSystem