[embedded] Build an initial embedded Swift standard library

This isn't a "complete" port of the standard library for embedded Swift, but
something that should serve as a starting point for further iterations on the
stdlib.

- General CMake logic for building a library as ".swiftmodule only" (ONLY_SWIFTMODULE).
- CMake logic in stdlib/public/core/CMakeLists.txt to start building the embedded stdlib for a handful of hardcoded target triples.
- Lots of annotations throughout the standard library to make types, functions, protocols unavailable in embedded Swift (@_unavailableInEmbedded).
- Mainly this is about stdlib functionality that relies on existentials, type erasure, metatypes, reflection, string interpolations.
- We rely on function body removal of unavailable functions to eliminate the actual problematic SIL code (existentials).
- Many .swift files are not included in the compilation of embedded stdlib at all, to simplify the scope of the annotations.
- EmbeddedStubs.swift is used to stub out (as unavailable and fatalError'd) the missing functionality.
This commit is contained in:
Kuba Mracek
2023-09-13 20:32:53 -07:00
parent 7014fcf12a
commit ae2e903574
61 changed files with 1365 additions and 252 deletions

View File

@@ -185,12 +185,15 @@ void CompilerInvocation::setDefaultBlocklistsIfNecessary() {
}
static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
llvm::Triple &Triple) {
LangOptions &LangOpts) {
llvm::Triple &Triple = LangOpts.Target;
llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath);
StringRef LibSubDir = getPlatformNameForTriple(Triple);
if (tripleIsMacCatalystEnvironment(Triple))
LibSubDir = "maccatalyst";
if (LangOpts.hasFeature(Feature::Embedded))
LibSubDir = "embedded";
llvm::sys::path::append(LibPath, LibSubDir);
SearchPathOpts.RuntimeLibraryPaths.clear();
@@ -294,7 +297,7 @@ setBridgingHeaderFromFrontendOptions(ClangImporterOptions &ImporterOpts,
void CompilerInvocation::setRuntimeResourcePath(StringRef Path) {
SearchPathOpts.RuntimeResourcePath = Path.str();
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts);
}
void CompilerInvocation::setTargetTriple(StringRef Triple) {
@@ -303,12 +306,12 @@ void CompilerInvocation::setTargetTriple(StringRef Triple) {
void CompilerInvocation::setTargetTriple(const llvm::Triple &Triple) {
LangOpts.setTarget(Triple);
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts);
}
void CompilerInvocation::setSDKPath(const std::string &Path) {
SearchPathOpts.setSDKPath(Path);
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts);
}
bool CompilerInvocation::setModuleAliasMap(std::vector<std::string> args,
@@ -1318,6 +1321,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (Opts.hasFeature(Feature::Embedded)) {
Opts.UnavailableDeclOptimizationMode = UnavailableDeclOptimization::Complete;
Opts.DisableImplicitStringProcessingModuleImport = true;
if (FrontendOpts.EnableLibraryEvolution) {
Diags.diagnose(SourceLoc(), diag::evolution_with_embedded);
@@ -3098,7 +3102,7 @@ bool CompilerInvocation::parseArgs(
return true;
}
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts);
setDefaultPrebuiltCacheIfNecessary();
setDefaultBlocklistsIfNecessary();