chore: Convert Schema to class (2nd attempt)#1105
Merged
Merged
Conversation
jbelkins
commented
Jun 23, 2026
| } | ||
|
|
||
| private var _containerType: ShapeType? | ||
| private let _containerType: ShapeType? |
Collaborator
Author
There was a problem hiding this comment.
it was an oversight for this property to be mutable, changed to let
jbelkins
commented
Jun 23, 2026
jbelkins
commented
Jun 23, 2026
jbelkins
commented
Jun 23, 2026
jbelkins
commented
Jun 23, 2026
jbelkins
commented
Jun 23, 2026
jbelkins
commented
Jun 23, 2026
dayaffe
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
In the original PR #1082, schemas were converted from value types that are created on demand using computed properties, to lazy globals that are created and retained on first use, then reused.
However, the change started causing compiler OOMs in the build system. That change was reverted in #1104 so that we could determine the cause of the OOMs and try the feature over again.
The cause was found to be that: member schemas were previously declared inline in the
membersarray property of the parent schema. Sometimes (i.e. in the case of enums with hundreds of cases), this resulted in code-generated Swift literal expressions that were thousands of lines long. When these expressions were used in computed properties, they were handled by the compiler without problems.However, when we instead tried to use these same large literal expressions as the RHS of an assignment, they started to consume a lot of time and RAM at type checking time. It has been noted before that very large arrays of complex literal expressions (i.e. structures like our schemas) cause high times & memory usage to type-check. See: swiftlang/swift#60549
Member schemas are now declared as their own separate schemas, assigned to a variable in the global namespace, and included by reference in the parent schema's
membersinstead of being declared inline. This breaks up large composite schemas into much smaller expressions that are type-checked much easier.Another change from the first attempt is that the schema global vars have explicit typing of
Swift.Schema. Not providing explicit type info causes the compiler to incorrectly detect a circular reference when schema targets form a reference cycle. This discovery allows us to avoid the extra code-generated getters that we were using before, reducing the volume of code-generated expressions. (In reality, the circular reference chain is broken by the use of@autoclosureon the schema's target property, so the compiler is correct to not flag the reference.)Scope
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.