Skip to content

Conversation

d-ronnqvist
Copy link
Contributor

Bug/issue #, if applicable:

Summary

Now that DocumentationContext is known have exactly one inputs/bundle, types and methods don't need both a context parameter and a inputs/bundle parameter.

This PR goes through various types one-by-one and removes the bundle parameters and updates all the callers to stop passing it.

The main benefit of this is that it's no longer possible to pass a bundle/inputs that don't belong to the context.

Another outcome of this is that many tests who call the context loading test helpers now ignore the bundle. A follow up PR, after this is merged, will clean up the test helpers and have the caller access the bundle/inputs from the context where needed.

Dependencies

None.

Testing

Nothing in particular. This isn't a user-facing change.

Checklist

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

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

@d-ronnqvist d-ronnqvist added the code cleanup Code cleanup *without* user facing changes label Sep 30, 2025
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist force-pushed the remove-redundant-bundle-params branch from 9283b45 to 1cfcdd0 Compare September 30, 2025 13:14
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist force-pushed the remove-redundant-bundle-params branch from 1cfcdd0 to 299719a Compare September 30, 2025 14:14
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist force-pushed the remove-redundant-bundle-params branch from 556de91 to 83fe89f Compare October 7, 2025 16:38
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@patshaughnessy patshaughnessy left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Question: Is there a longer term plan to remove DocumentationBundle entirely? Here you remove passing the bundle into many call sites, but we still have other places that reference DocumentationBundle itself.

let documentationContext = self.documentationContext

let renderContentFor: (ResolvedTopicReference) -> RenderReferenceStore.TopicContent = { reference in
let renderContentFor: (ResolvedTopicReference) -> RenderReferenceStore.TopicContent = { [renderer, documentationContext] reference in
Copy link
Contributor

Choose a reason for hiding this comment

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

This is new Swift syntax for me - does this destructure renderer and documentationContext from the reference value passed into the closure? Why isn't this written the other way around? Like this:

... = { reference [renderer, documentationContext]  in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The variables within angle brackets is a Swift closure is a "capture list".

The same way that the previous code was shadowing renderer and documentationContext with local variables to avoid strongly capturing self in the closure, the capture list captures renderer and documentationContext explicitly as their own variables instead of them referring to self.renderer and self.documentationContext which would capture self.

let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { url in
try? FileManager.default.copyItem(at: asidesSGFURL, to: url.appendingPathComponent("Asides.symbols.json"))
}
defer {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this needed any more? testBundleAndContext no longer creates an actual bundle/file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It hasn't been needed since somewhere 2021/2022 because testBundleAndContext(copying:...) already clears up any temporary files that it creates.

includeTaskGroups: Bool = true
) -> [LinkDestinationSummary] {
let bundle = context.bundle
let bundle = context.inputs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let bundle = context.inputs
let inputs = context.inputs

Why not rename the local variable to match? And throughout the PR I see you retain the identifier bundle aren't we trying to move away from using bundle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did most of the renaming using IDE renaming actions which doesn't catch locally scoped variables. I can remove this one variable since I need to rebase the PR anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found another similarly named variable and updated both in e1c04b7

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist
Copy link
Contributor Author

Is there a longer term plan to remove DocumentationBundle entirely? Here you remove passing the bundle into many call sites, but we still have other places that reference DocumentationBundle itself.

Not to remove it completely but to rename it to better reflect the information that it represents (a collection of input files for the context). There is already a package access typealias for this; DocumentationContext.Inputs. There is still value having some abstraction that groups together input files from different sources so that the context doesn't need to know all the details around where those inputs files come from.

@d-ronnqvist d-ronnqvist merged commit eb5ba13 into swiftlang:main Oct 10, 2025
2 checks passed
@d-ronnqvist d-ronnqvist deleted the remove-redundant-bundle-params branch October 10, 2025 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Code cleanup *without* user facing changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants