fix(tvix/eval): handle builtins.split matching the empty string

This prevents the following statements from looping endlessly:

```
builtins.split "(.*)" ""
builtins.split "([abc]*)" "abc"
builtins.split "(.*)" "abc"
builtins.split ".*" ""
```

Cover these (and some more examples) in the test suite.

Co-Authored-By: Florian Klink <flokli@flokli.de>
Change-Id: Ibd339f971e0f4e3e5c229816e2be5a8e3836fec9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11743
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
binarycat 2024-06-02 19:58:54 +02:00 committed by clbot
parent 154e0d71e0
commit beb7f57c73
4 changed files with 15 additions and 1 deletions

View file

@ -1286,6 +1286,9 @@ mod pure_builtins {
}) })
.collect(); .collect();
ret.push_back(Value::List(NixList::from(v))); ret.push_back(Value::List(NixList::from(v)));
if pos == text.len() {
break;
}
pos = thematch.end(); pos = thematch.end();
} }

View file

@ -0,0 +1 @@
[ [ "" [ "a" ] "c" ] [ "" [ "a" ] "b" [ "c" ] "" ] [ "" [ "a" null ] "b" [ null "c" ] "" ] [ " " [ "FOO" ] " " ] [ "" [ "abc" ] "" [ "" ] "" ] [ "" [ "abc" ] "" [ "" ] "" ] [ "" [ ] "" ] ]

View file

@ -0,0 +1,10 @@
[
(builtins.split "(a)b" "abc")
(builtins.split "([ac])" "abc")
(builtins.split "(a)|(c)" "abc")
(builtins.split "([[:upper:]]+)" " FOO ")
(builtins.split "(.*)" "abc")
(builtins.split "([abc]*)" "abc")
(builtins.split ".*" "")
]

View file

@ -71,7 +71,7 @@ in
(builtins.hasAttr "allOutputs" (builtins.getContext drv.drvPath)."${builtins.unsafeDiscardStringContext drv.drvPath}") (builtins.hasAttr "allOutputs" (builtins.getContext drv.drvPath)."${builtins.unsafeDiscardStringContext drv.drvPath}")
(legit-context == desired-context) # FIXME(raitobezarius): this should not use `builtins.seq`, this is a consequence of excessive laziness of Tvix, I believe. (legit-context == desired-context) # FIXME(raitobezarius): this should not use `builtins.seq`, this is a consequence of excessive laziness of Tvix, I believe.
(reconstructed-path == combo-path) (reconstructed-path == combo-path)
# Those are too slow? # These still fail with an internal error
# (etaRule' "foo") # (etaRule' "foo")
# (etaRule' combo-path) # (etaRule' combo-path)
(etaRule "foo") (etaRule "foo")