[Frontend] Add option to explicitly import Builtin #63734
Merged
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.
This PR adds a new frontend option,
-enable-builtin-module
, that enables a module to explicitlyimport Builtin
when needed. As part of this, the explicit import gets emitted into interface files so that we no longer implicitly import this module.Motivation for this new flag includes the fact that standard library modules who are not the core sometimes need to access these builtins, but can only do so via
-parse-stdlib
who in itself bring along lots of other quirks that don't apply to these modules. The biggest is that the standard library is unconditionally built with-assert-config Debug
even in release modes of the standard library. Modules using this flag and using stdlib APIs who have_debugPrecondition
s must incur the code size and branch of these preconditions even though they may not want them in opaque parts of their libraries. With this new flag, those modules can explicitlyimport Builtin
and remove their dependence on-parse-stdlib
allowing them to 1. implicitly getimport Swift
like normal Swift code and 2. be built as normal Swift code. It would be nice if one day we sunsetted-parse-stdlib
and all of the unique flags that come along with it were explicit in the stdlib's build settings.