fix(tvix/composition): include typeid in recursion check
Change-Id: Icc279d41a4980d4b57acbb4243bbd509039b753f Reviewed-on: https://cl.tvl.fyi/c/depot/+/12000 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
ba38883a4f
commit
a805a80b48
1 changed files with 13 additions and 5 deletions
|
@ -274,7 +274,7 @@ pub fn add_default_services(reg: &mut Registry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CompositionContext<'a> {
|
pub struct CompositionContext<'a> {
|
||||||
stack: Vec<String>,
|
stack: Vec<(TypeId, String)>,
|
||||||
composition: Option<&'a Composition>,
|
composition: Option<&'a Composition>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,8 +291,14 @@ impl<'a> CompositionContext<'a> {
|
||||||
entrypoint: String,
|
entrypoint: String,
|
||||||
) -> Result<Arc<T>, Box<dyn std::error::Error + Send + Sync + 'static>> {
|
) -> Result<Arc<T>, Box<dyn std::error::Error + Send + Sync + 'static>> {
|
||||||
// disallow recursion
|
// disallow recursion
|
||||||
if self.stack.contains(&entrypoint) {
|
if self
|
||||||
return Err(CompositionError::Recursion(self.stack.clone()).into());
|
.stack
|
||||||
|
.contains(&(TypeId::of::<T>(), entrypoint.clone()))
|
||||||
|
{
|
||||||
|
return Err(CompositionError::Recursion(
|
||||||
|
self.stack.iter().map(|(_, n)| n.clone()).collect(),
|
||||||
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
match self.composition {
|
match self.composition {
|
||||||
Some(comp) => Ok(comp.build_internal(self.stack.clone(), entrypoint).await?),
|
Some(comp) => Ok(comp.build_internal(self.stack.clone(), entrypoint).await?),
|
||||||
|
@ -390,7 +396,7 @@ impl Composition {
|
||||||
|
|
||||||
fn build_internal<T: ?Sized + Send + Sync + 'static>(
|
fn build_internal<T: ?Sized + Send + Sync + 'static>(
|
||||||
&self,
|
&self,
|
||||||
stack: Vec<String>,
|
stack: Vec<(TypeId, String)>,
|
||||||
entrypoint: String,
|
entrypoint: String,
|
||||||
) -> BoxFuture<'_, Result<Arc<T>, CompositionError>> {
|
) -> BoxFuture<'_, Result<Arc<T>, CompositionError>> {
|
||||||
let mut stores = self.stores.lock().unwrap();
|
let mut stores = self.stores.lock().unwrap();
|
||||||
|
@ -422,7 +428,9 @@ impl Composition {
|
||||||
stack: stack.clone(),
|
stack: stack.clone(),
|
||||||
composition: Some(self),
|
composition: Some(self),
|
||||||
};
|
};
|
||||||
new_context.stack.push(entrypoint.clone());
|
new_context
|
||||||
|
.stack
|
||||||
|
.push((TypeId::of::<T>(), entrypoint.clone()));
|
||||||
let res = config
|
let res = config
|
||||||
.build(&entrypoint, &new_context)
|
.build(&entrypoint, &new_context)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in a new issue