Skip to content

TBDGen: Refactor symbol enumeration into SIL and IRGen utilities #61685

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 3 commits into from
Oct 31, 2022

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Oct 22, 2022

TBDGen enumerates all the symbols in a file or module and emits a list of linkable symbols that will be present in the resulting library binary. SILGen and IRGen for if #_hasSymbol(...) have similar requirements; given a declaration, we need to enumerate each of the public symbols associated with that declaration to emit a runtime check for that symbol.

Given the overlap in requirements, I have factored the core logic of TBDGenVisitor into a couple of new visitor classes located in libswiftSIL and libswiftIRGen and then reimplemented TBDGenVisitor on top of the new abstractions. The new SILSymbolVisitor class is responsible for the core enumeration of linkable entities. Entities that can be represented as a SILDeclRef are enumerated as such, but many other entities do not have a conceptual representation at the SIL layer. The responsibility of representing these is delegated to IRSymbolVisitor which turns entities into LinkEntity instances where possible. Finally, a small number of remaining entities cannot be represented by LinkEntity and are passed through directly.

For the moment, I've tried to reduce the risk of this change by preserving the behavior of TBDGenVisitor as much as possible in the new factoring. In the future, though, it's possible that there could be further refactoring and simplification. For instance, some features like Swift API extraction and symbol source map generation could be implemented directly on top of IRSymbolVisitor instead of being mixed into the responsibilities of TBDGenVisitor. As much as possible, I'd also like to close the gaps where linkable entities cannot be represented by SILDeclRef or LinkEntity.

@tshortli tshortli force-pushed the refactor-tbdgen-visitor branch 4 times, most recently from 438e1ab to 860de29 Compare October 24, 2022 16:39
@tshortli tshortli changed the title TBDGen: Refactor logic to share with SIL and IRGen TBDGen: Refactor symbol enumeration into SIL and IRGen utilities Oct 24, 2022
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

@tshortli tshortli marked this pull request as ready for review October 24, 2022 17:06
Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

Thank you for layering these two symbol collectors properly!

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Neat!

@tshortli tshortli force-pushed the refactor-tbdgen-visitor branch 2 times, most recently from fa73442 to 45f5963 Compare October 26, 2022 05:49
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli tshortli force-pushed the refactor-tbdgen-visitor branch 3 times, most recently from 4a7d42c to 38adf3f Compare October 28, 2022 16:52
@tshortli
Copy link
Contributor Author

Once all of the following blocking PRs are merged this should build cleanly on Linux:

#61753
#61758
#61767
#61770
#61774
#61776
#61779
#61784
#61792

@tshortli tshortli force-pushed the refactor-tbdgen-visitor branch from 38adf3f to cbc4890 Compare October 30, 2022 01:28
@tshortli tshortli force-pushed the refactor-tbdgen-visitor branch from cbc4890 to fc20262 Compare October 30, 2022 16:14
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test and merge

@nkcsgexi
Copy link
Contributor

🎉

@tshortli
Copy link
Contributor Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit c36ddc2 into swiftlang:main Oct 31, 2022
@tshortli tshortli deleted the refactor-tbdgen-visitor branch October 31, 2022 15:24
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.

4 participants