-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(turbo-tasks): Move OutputContent from memory backend into tu…
…rbo-tasks, represent Empty as None
- Loading branch information
Showing
4 changed files
with
58 additions
and
42 deletions.
There are no files selected for viewing
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
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,40 @@ | ||
use std::{ | ||
borrow::Cow, | ||
fmt::{self, Display}, | ||
}; | ||
|
||
use anyhow::anyhow; | ||
|
||
use crate::{util::SharedError, RawVc}; | ||
|
||
/// A helper type representing the output of a resolved task. | ||
#[derive(Clone, Debug)] | ||
pub enum OutputContent { | ||
Link(RawVc), | ||
Error(SharedError), | ||
Panic(Option<Box<Cow<'static, str>>>), | ||
} | ||
|
||
impl OutputContent { | ||
/// INVALIDATION: Be careful with this, it will not track dependencies, so | ||
/// using it could break cache invalidation. | ||
pub fn read_untracked(&self) -> anyhow::Result<RawVc> { | ||
match &self { | ||
Self::Error(err) => Err(anyhow::Error::new(err.clone())), | ||
Self::Link(raw_vc) => Ok(*raw_vc), | ||
Self::Panic(Some(message)) => Err(anyhow!("A task panicked: {message}")), | ||
Self::Panic(None) => Err(anyhow!("A task panicked")), | ||
} | ||
} | ||
} | ||
|
||
impl Display for OutputContent { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::Link(raw_vc) => write!(f, "link {:?}", raw_vc), | ||
Self::Error(err) => write!(f, "error {}", err), | ||
Self::Panic(Some(message)) => write!(f, "panic {}", message), | ||
Self::Panic(None) => write!(f, "panic"), | ||
} | ||
} | ||
} |