Skip to content

refactors: turn RenderBlockContent's per-case data into separate structs #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 9, 2022

Conversation

QuietMisdreavus
Copy link
Contributor

Bug/issue #, if applicable: rdar://97382349

Summary

This PR is a collection of refactors to RenderBlockContent that change any associated data in its enum cases to a separate struct. Without this change, any new data being added to these cases would become a source-breaking change to anything that used Swift-DocC as a library. As several of these are in the pipeline (swiftlang/swift-cmark#46, #53, etc), i wanted to introduce One Big Breaking Change ahead of time, so that any further changes are much easier to adopt.

Dependencies

None

Testing

This should not affect the behavior of Swift-DocC. Any testing should ensure that behavior remains the same.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • [ n/a ] Added tests
  • Ran the ./bin/test script and it succeeded
  • [ n/a ] Updated documentation if necessary

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus
Copy link
Contributor Author

After some discussion offline, i'm going to scrap this branch and try something else. The kinds of changes proposed in this forums thread would still create breaking changes after this refactor, so we'll need to create a different architecture for RenderBlockContent to prevent them from being too disruptive.

@QuietMisdreavus
Copy link
Contributor Author

I tinkered around with an alternate design (turning RenderBlockContent into a protocol), but shortcomings in the language prevented that from being feasible. I instead opted to keep the enum structure and add a fake case that only serves to "unfreeze" the enum. This will allow us to expand the enum without waiting for swiftlang/swift#55110 to be fixed, or Library Evolution to be allowed for Swift Packages (rdar://78773361). With that in mind, i'm reopening this PR to keep the original implementation.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@ethan-kusters ethan-kusters left a comment

Choose a reason for hiding this comment

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

Looks really good! I think this is going to be really nice moving forward. All my feedback is non-blocking.

return blocks.rawIndexableTextContent(references: references)
case let .orderedList(items):
return items.map {
case let .aside(a):
Copy link
Contributor

@ethan-kusters ethan-kusters Aug 26, 2022

Choose a reason for hiding this comment

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

Nit: We don't have a lot of single-letter variable names in the codebase thus far. I think it probably fits in a little better to spell out the name of these types instead? (Throughout this PR)

Suggested change
case let .aside(a):
case let .aside(aside):

Comment on lines +64 to +66
// Warning: If you add a new case to this enum, make sure to handle it in the Codable
// conformance at the bottom of this file, and in the `rawIndexableTextContent` method in
// RenderBlockContent+TextIndexing.swift!
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm I hadn't considered this. I guess ideally we wouldn't want to mark the the _nonfrozenEnum_useDefaultCase case as deprecated internally and only extenrally so that we can still switch on it within the library and make sure SwiftDocC itself is covering all of bases.

What do you think of the trade-off here? Should we consider not deprecating it so we can switch over it internally? Then we would move the deprecation message into a documentation comment instead.

@ethan-kusters
Copy link
Contributor

@swift-ci please test

@ethan-kusters ethan-kusters merged commit 3673ec3 into swiftlang:main Sep 9, 2022
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.

2 participants