Skip to content

Stop boxing types that recurse only through an array or dictionary#910

Open
eyupcanakman wants to merge 1 commit into
apple:mainfrom
eyupcanakman:fix/recursive-boxing-containers
Open

Stop boxing types that recurse only through an array or dictionary#910
eyupcanakman wants to merge 1 commit into
apple:mainfrom
eyupcanakman:fix/recursive-boxing-containers

Conversation

@eyupcanakman
Copy link
Copy Markdown

Motivation

The generator boxes a type whose only self-reference is reached through an array or dictionary. Swift arrays and dictionaries keep their elements in heap-allocated storage, so a reference reached only through them cannot form a value-type cycle and the type does not need a CopyOnWriteBox. Supporting-recursive-types.md already notes that arrays and dictionaries can be considered boxed, so the containing type does not require boxing. Fixes #682.

Modifications

  • In ExistingTypeDescription.referencedSchemaComponentName, return nil for .array and .dictionaryValue instead of recursing into them. .optional and .any still recurse.

Result

A type that recurses only through an array or dictionary is generated as a plain struct with stored properties, not a boxed type.

Test Plan

Added two snippet reference tests covering recursion through an array and through a dictionary.

Arrays and dictionaries already break the reference cycle, so a type that reaches itself only through one of them does not need CopyOnWriteBox storage. The recursion detector now skips array and dictionary references when collecting cycle-forming edges, which matches the behavior described in Supporting-recursive-types.md. Direct and optional self-references are still boxed.

Closes apple#682
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.

The generator is boxing properties of recursive types that do not need boxing

1 participant