Skip to content

Commit

Permalink
Fix recursive anon_target promises
Browse files Browse the repository at this point in the history
Summary: Before recursive promises wouldn't get traversed - so if you had a promise wrapping a promise, you wouldn't see the provider collection. Fix that.

Reviewed By: krallin

Differential Revision: D42076206

fbshipit-source-id: c517de06136b823090e6f8f0af4a72c1a986adf7
  • Loading branch information
ndmitchell authored and facebook-github-bot committed Dec 16, 2022
1 parent 8a8ce6a commit 37dbffd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ impl<'v, V: ValueLike<'v>> ProviderCollectionGen<V> {
mut value: Value<'v>,
) -> anyhow::Result<SmallMap<Arc<ProviderId>, Value<'v>>> {
// Sometimes we might have a resolved promise here, in which case see through that
if let Some(promise) = StarlarkPromise::from_value(value) {
if let Some(x) = promise.get() {
value = x;
}
}
value = StarlarkPromise::get_recursive(value);

let list = match List::from_value(value) {
Some(v) => v,
Expand Down
15 changes: 15 additions & 0 deletions buck2_interpreter/src/starlark_promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ impl<'v> StarlarkPromise<'v> {
}
}

/// A recursive version of [`StarlarkPromise::get`], which continues to see through
/// promises while they are resolved.
/// The returned value will either be an unresolved promise, or not a promise.
pub fn get_recursive(mut value: Value<'v>) -> Value<'v> {
while let Some(promise) = StarlarkPromise::from_value(value) {
if let Some(x) = promise.get() {
value = x;
} else {
// We have an unresolved promise, stop looping
break;
}
}
value
}

fn apply(
f: Value<'v>,
x: Value<'v>,
Expand Down

0 comments on commit 37dbffd

Please sign in to comment.