Skip to content

Add Maybe[T].toArray and fix DelimiterTextParser array aliasing - #1720

Merged
olabusayoT merged 1 commit into
apache:mainfrom
olabusayoT:daf-3065-misc-cleanup
Sep 4, 2026
Merged

Add Maybe[T].toArray and fix DelimiterTextParser array aliasing#1720
olabusayoT merged 1 commit into
apache:mainfrom
olabusayoT:daf-3065-misc-cleanup

Conversation

@olabusayoT

Copy link
Copy Markdown
Contributor

Added Maybe[T].toArray, replacing seven hand-rolled .toList.toArray call sites across the runtimeDependencies migration to Array (EvElement, EvEscapeSchemes, EvFieldDFA, StringLiteralForUnparser, SpecifiedLength2, ElementUnparser x2) with a single reusable method.

DelimiterTextParser.runtimeDependencies now .clone()s EncodingRuntimeData's array instead of aliasing the same mutable instance: Array is invariant and mutable, unlike the Vector this used to be, so sharing the identical instance would let a future in-place mutation (e.g. dedupe or append) silently corrupt every sibling delimiter parser's dependency list along with EncodingRuntimeData's own.

DAFFODIL-3065

@stevedlawrence stevedlawrence left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Good cleanup, but probably won't help with runtime performance much since runtimeDependencies are all calculated at compile time

// .clone(), not the same reference: Array is mutable, unlike the
// Vector this used to be, so sharing the instance would let a future
// in-place mutation corrupt every sibling delimiter parser's list too.
override val runtimeDependencies = rd.encodingInfo.runtimeDependencies.clone()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this clone is really necessary. Although runtimeDependencies are mutable Arrays, I don't think we ever actually mutate them.

And even if encodingInfo.runtimeDependencies did change, it's probably more correct for this runtimeDependencies to also update, so there's an argument that cloning is actually the wrong behavior. But we don't have that behavior for other runtimeDependnecies, so I don't think we're really consistent with that behavior.

If we wanted to ensure it's never mutated we could change the type to Scala 3's IArray (immutable array), but I'm not sure if the churn is worth it. It's not too hard to inspect all the runtimeDependnecies and verify they never change.

@jadams-tresys jadams-tresys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@olabusayoT
olabusayoT force-pushed the daf-3065-misc-cleanup branch from 4276f0e to 14f0ca7 Compare September 3, 2026 17:59
Added Maybe[T].toArray, replacing seven hand-rolled .toList.toArray
call sites across the runtimeDependencies migration to Array (EvElement,
EvEscapeSchemes, EvFieldDFA, StringLiteralForUnparser, SpecifiedLength2,
ElementUnparser x2) with a single reusable method.

DAFFODIL-3065
@olabusayoT
olabusayoT force-pushed the daf-3065-misc-cleanup branch from 14f0ca7 to d0ce3ae Compare September 3, 2026 18:01
@olabusayoT
olabusayoT merged commit 4f18086 into apache:main Sep 4, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants