feat(tvix/eval): implement unsafeDiscardOutputDependency
This builtin only transforms any `NixContextElement::Derivation` into the trivial `NixContextElement::Plain`. This is a forgetful functor on derivation-deep context strings. The test coverage of this change is done in cl/11264. Change-Id: Icd00778c97766be6db8a6bdabaa59e9724353ec5 Signed-off-by: Ryan Lahfa <tvl@lahfa.xyz> Reviewed-on: https://cl.tvl.fyi/c/depot/+/11262 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
94185f7560
commit
8bccc9dca9
3 changed files with 43 additions and 7 deletions
|
@ -120,7 +120,7 @@ The `impl` column indicates implementation status in tvix:
|
|||
| true | true | | | |
|
||||
| tryEval | false | | | |
|
||||
| typeOf | false | | | |
|
||||
| unsafeDiscardOutputDependency | false | | | context |
|
||||
| unsafeDiscardOutputDependency | false | | | |
|
||||
| unsafeDiscardStringContext | false | | | |
|
||||
| unsafeGetAttrPos | false | | | todo |
|
||||
| valueSize | false | | | todo |
|
||||
|
|
|
@ -1575,12 +1575,42 @@ mod placeholder_builtins {
|
|||
co: GenCo,
|
||||
s: Value,
|
||||
) -> Result<Value, ErrorKind> {
|
||||
generators::emit_warning_kind(
|
||||
&co,
|
||||
WarningKind::NotImplemented("builtins.unsafeDiscardOutputDependency"),
|
||||
)
|
||||
.await;
|
||||
Ok(s)
|
||||
let span = generators::request_span(&co).await;
|
||||
let mut v = s
|
||||
.coerce_to_string(
|
||||
co,
|
||||
// It's weak because
|
||||
// lists, integers, floats and null are not
|
||||
// accepted as parameters.
|
||||
CoercionKind {
|
||||
strong: false,
|
||||
import_paths: true,
|
||||
},
|
||||
span,
|
||||
)
|
||||
.await?
|
||||
.to_contextful_str()?;
|
||||
|
||||
// If there's any context, we will swap any ... by a path one.
|
||||
if let Some(ctx) = v.context_mut() {
|
||||
let new_context: tvix_eval::NixContext = ctx
|
||||
.iter()
|
||||
.map(|elem| match elem {
|
||||
// FUTUREWORK(performance): ideally, we should either:
|
||||
// (a) do interior mutation of the existing context.
|
||||
// (b) let the structural sharing make those clones cheap.
|
||||
crate::NixContextElement::Derivation(drv_path) => {
|
||||
crate::NixContextElement::Plain(drv_path.to_string())
|
||||
}
|
||||
elem => elem.clone(),
|
||||
})
|
||||
.collect::<HashSet<_>>()
|
||||
.into();
|
||||
|
||||
*ctx = new_context;
|
||||
}
|
||||
|
||||
Ok(Value::from(v))
|
||||
}
|
||||
|
||||
#[builtin("addErrorContext")]
|
||||
|
|
|
@ -48,6 +48,12 @@ impl From<NixContextElement> for NixContext {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<HashSet<NixContextElement>> for NixContext {
|
||||
fn from(value: HashSet<NixContextElement>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl NixContext {
|
||||
/// Creates an empty context that can be populated
|
||||
/// and passed to form a contextful [NixString], albeit
|
||||
|
|
Loading…
Reference in a new issue