fix(tvix/eval/versions): preserve the Number string exactly

This is relevant for builtins.splitVersion:

    nix-repl> builtins.splitVersion "unstable-2022-02-21"
    [ "unstable" "2022" "02" "21" ]

Change-Id: I0a0add178d95d5a82e112b41ed5f3ca5a19608f8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6710
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
sterni 2022-09-20 12:51:02 +02:00
parent 6e6edcce6a
commit 834fe833e5
2 changed files with 5 additions and 6 deletions

View file

@ -220,8 +220,7 @@ fn pure_builtins() -> Vec<Builtin> {
let parts = s let parts = s
.map(|s| { .map(|s| {
Value::String(match s { Value::String(match s {
// TODO(sterni): we should avoid converting back and forth here VersionPart::Number(n) => n.into(),
VersionPart::Number(n) => format!("{n}").into(),
VersionPart::Word(w) => w.into(), VersionPart::Word(w) => w.into(),
}) })
}) })

View file

@ -6,7 +6,7 @@ use std::ops::RangeInclusive;
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
pub enum VersionPart<'a> { pub enum VersionPart<'a> {
Word(&'a str), Word(&'a str),
Number(u64), Number(&'a str),
} }
/// Type used to hold information about a VersionPart during creation /// Type used to hold information about a VersionPart during creation
@ -46,7 +46,7 @@ impl<'a> Iterator for VersionPartsIter<'a> {
match cached_part { match cached_part {
InternalPart::Break => return None, InternalPart::Break => return None,
InternalPart::Number { range } => { InternalPart::Number { range } => {
return Some(VersionPart::Number(self.version[range].parse().unwrap())) return Some(VersionPart::Number(&self.version[range]))
} }
InternalPart::Word { range } => { InternalPart::Word { range } => {
return Some(VersionPart::Word(&self.version[range])) return Some(VersionPart::Word(&self.version[range]))
@ -61,7 +61,7 @@ impl<'a> Iterator for VersionPartsIter<'a> {
let cached_part = std::mem::replace(&mut self.cached_part, InternalPart::Break); let cached_part = std::mem::replace(&mut self.cached_part, InternalPart::Break);
match cached_part { match cached_part {
InternalPart::Number { range } => { InternalPart::Number { range } => {
Some(VersionPart::Number(self.version[range].parse().unwrap())) Some(VersionPart::Number(&self.version[range]))
} }
InternalPart::Word { range } => Some(VersionPart::Word(&self.version[range])), InternalPart::Word { range } => Some(VersionPart::Word(&self.version[range])),
InternalPart::Break => self.next(), InternalPart::Break => self.next(),
@ -98,7 +98,7 @@ impl<'a> Iterator for VersionPartsIter<'a> {
self.next() self.next()
} }
InternalPart::Number { range } => { InternalPart::Number { range } => {
Some(VersionPart::Number(self.version[range].parse().unwrap())) Some(VersionPart::Number(&self.version[range]))
} }
InternalPart::Break => self.next(), InternalPart::Break => self.next(),
} }