Skip to content

Commit 54cfe21

Browse files
committed
Turbopack: add flags to AvailabilityInfo
1 parent 2d37732 commit 54cfe21

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ workspace = true
1616
anyhow = { workspace = true }
1717
async-trait = { workspace = true }
1818
auto-hash-map = { workspace = true }
19+
bitfield = { workspace = true }
1920
browserslist-rs = { workspace = true }
2021
bytes-str = { workspace = true }
2122
const_format = { workspace = true }
Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
use anyhow::Result;
2+
use bitfield::bitfield;
23
use serde::{Deserialize, Serialize};
3-
use turbo_rcstr::{RcStr, rcstr};
4+
use turbo_rcstr::RcStr;
45
use turbo_tasks::{NonLocalValue, ResolvedVc, TaskInput, Vc, trace::TraceRawVcs};
56

67
use super::available_modules::{AvailableModules, AvailableModulesSet};
78

9+
bitfield! {
10+
#[derive(Clone, Copy, Default, TaskInput, TraceRawVcs, NonLocalValue, Serialize, Deserialize, PartialEq, Eq, Hash)]
11+
pub struct AvailabilityFlags(u8);
12+
impl Debug;
13+
}
14+
815
#[derive(
916
Eq,
1017
PartialEq,
@@ -18,49 +25,48 @@ use super::available_modules::{AvailableModules, AvailableModulesSet};
1825
Serialize,
1926
Deserialize,
2027
)]
21-
pub enum AvailabilityInfo {
22-
/// Availability of modules is tracked, but no modules are available
23-
Root,
28+
pub struct AvailabilityInfo {
29+
flags: AvailabilityFlags,
2430
/// There are modules already available.
25-
Complete {
26-
available_modules: ResolvedVc<AvailableModules>,
27-
},
31+
available_modules: Option<ResolvedVc<AvailableModules>>,
2832
}
2933

3034
impl AvailabilityInfo {
3135
pub fn root() -> Self {
32-
AvailabilityInfo::Root
36+
Self {
37+
flags: AvailabilityFlags::default(),
38+
available_modules: None,
39+
}
3340
}
3441

3542
pub fn available_modules(&self) -> Option<ResolvedVc<AvailableModules>> {
36-
match self {
37-
Self::Root => None,
38-
Self::Complete {
39-
available_modules, ..
40-
} => Some(*available_modules),
41-
}
43+
self.available_modules
4244
}
4345

4446
pub async fn with_modules(self, modules: Vc<AvailableModulesSet>) -> Result<Self> {
45-
Ok(match self {
46-
AvailabilityInfo::Root => AvailabilityInfo::Complete {
47-
available_modules: AvailableModules::new(modules).to_resolved().await?,
48-
},
49-
AvailabilityInfo::Complete { available_modules } => AvailabilityInfo::Complete {
50-
available_modules: available_modules
51-
.with_modules(modules)
52-
.to_resolved()
53-
.await?,
54-
},
47+
Ok(if let Some(available_modules) = self.available_modules {
48+
Self {
49+
flags: self.flags,
50+
available_modules: Some(
51+
available_modules
52+
.with_modules(modules)
53+
.to_resolved()
54+
.await?,
55+
),
56+
}
57+
} else {
58+
Self {
59+
flags: self.flags,
60+
available_modules: Some(AvailableModules::new(modules).to_resolved().await?),
61+
}
5562
})
5663
}
5764

5865
pub async fn ident(&self) -> Result<Option<RcStr>> {
59-
Ok(match self {
60-
AvailabilityInfo::Root => None,
61-
AvailabilityInfo::Complete { available_modules } => {
62-
Some(available_modules.hash().await?.to_string().into())
63-
}
66+
Ok(if let Some(available_modules) = self.available_modules {
67+
Some(available_modules.hash().await?.to_string().into())
68+
} else {
69+
None
6470
})
6571
}
6672
}

0 commit comments

Comments
 (0)