Only save one version of tag info per epoch (#6429)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-04-23 09:22:52 +12:00
committed by GitHub
parent 9730e3f5b3
commit 3d22f6cd66
11 changed files with 11511 additions and 6 deletions

View File

@ -95,8 +95,7 @@ pub struct DefaultPlanes {
pub struct TagIdentifier {
pub value: String,
// Multi-version representation of info about the tag. Kept ordered. The usize is the epoch at which the info
// was written. Note that there might be multiple versions of tag info from the same epoch, the version with
// the higher index will be the most recent.
// was written.
#[serde(skip)]
pub info: Vec<(usize, TagEngineInfo)>,
#[serde(skip)]
@ -123,10 +122,16 @@ impl TagIdentifier {
/// Add info from a different instance of this tag.
pub fn merge_info(&mut self, other: &TagIdentifier) {
assert_eq!(&self.value, &other.value);
'new_info: for (oe, ot) in &other.info {
for (e, _) in &self.info {
if e > oe {
continue 'new_info;
for (oe, ot) in &other.info {
if let Some((e, t)) = self.info.last_mut() {
// If there is newer info, then skip this iteration.
if *e > *oe {
continue;
}
// If we're in the same epoch, then overwrite.
if e == oe {
*t = ot.clone();
continue;
}
}
self.info.push((*oe, ot.clone()));

View File

@ -2600,3 +2600,24 @@ mod import_async {
super::execute(TEST_NAME, true).await
}
}
mod loop_tag {
const TEST_NAME: &str = "loop_tag";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}