Skip to content

SILGen: Forward declare SIL functions referenced by #_hasSymbol query helpers #61886

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 8 commits into from
Nov 3, 2022

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Nov 2, 2022

For a #_hasSymbol condition check, such as the following:

if #_hasSymbol(foo) { ... }

the compiler will generate a binary that implements something roughly equivalent to this pseudo-code:

// Call to helper function (and branch on its result) emitted during SILGen
if hasSymbolHelperForFoo() { ... }

func hasSymbolHelperForFoo() -> Bool {
  // Return true if the address of each linkable symbol associated with
  // the declaration `foo()` is non-null. This body is emitted by IRGen.
}

This pull request establishes the preconditions necessary for IRGen to do its part, which is to emit the function bodies for each #_hasSymbol helper function required by the program. Each unique declaration that needs an associated helper function is recorded on SILModule during SILGen and any SIL function prototypes that will be referenced by the helper function implementations are also emitted.

@tshortli
Copy link
Contributor Author

tshortli commented Nov 2, 2022

@swift-ci please test

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.

Super cool! I can now see how the proper layering of TBDGen could help this implementation.

@tshortli
Copy link
Contributor Author

tshortli commented Nov 2, 2022

@swift-ci please test Windows

@tshortli tshortli force-pushed the silgen-has-symbol-forward-decls branch from 26387d4 to 38779f3 Compare November 3, 2022 04:38
@tshortli
Copy link
Contributor Author

tshortli commented Nov 3, 2022

@swift-ci please smoke test and merge

@tshortli
Copy link
Contributor Author

tshortli commented Nov 3, 2022

@swift-ci please smoke test macOS

Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

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

Very nice!

@tshortli tshortli merged commit 23fe168 into swiftlang:main Nov 3, 2022
@tshortli tshortli deleted the silgen-has-symbol-forward-decls branch November 3, 2022 20:06
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.

3 participants