From 307c62c25ebf5055d7b557b1fda1b7e754e606b6 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 22 Nov 2024 12:30:21 -0800 Subject: [PATCH 01/11] Only add SwiftMacros dependencies when we are building with swift-syntax enabled --- stdlib/cmake/modules/SwiftSource.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/cmake/modules/SwiftSource.cmake b/stdlib/cmake/modules/SwiftSource.cmake index ed57a7eadedfc..1fda7fe863a7b 100644 --- a/stdlib/cmake/modules/SwiftSource.cmake +++ b/stdlib/cmake/modules/SwiftSource.cmake @@ -886,8 +886,11 @@ function(_compile_swift_files # cross-compiling the compiler. list(APPEND swift_compiler_tool_dep "swift-frontend${target_suffix}") - # If we aren't cross compiling, also depend on SwiftMacros. - list(APPEND swift_compiler_tool_dep SwiftMacros) + # If we aren't cross compiling and have swift-syntax, also depend on + # SwiftMacros. + if(SWIFT_BUILD_SWIFT_SYNTAX) + list(APPEND swift_compiler_tool_dep SwiftMacros) + endif() endif() # If there are more than one output files, we assume that they are specified From 524a446cac02147c57afa9c64ff4fa41a0eca32e Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 22 Nov 2024 12:40:40 -0800 Subject: [PATCH 02/11] Make sure EvaluateIfConditionRequest isn't using Swift code in C++-only mode --- lib/Sema/TypeChecker.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp index 38c61b4893ed5..d6fdee1c97f60 100644 --- a/lib/Sema/TypeChecker.cpp +++ b/lib/Sema/TypeChecker.cpp @@ -755,6 +755,7 @@ std::pair EvaluateIfConditionRequest::evaluate( Evaluator &evaluator, SourceFile *sourceFile, SourceRange conditionRange, bool shouldEvaluate ) const { +#if SWIFT_BUILD_SWIFT_SYNTAX // FIXME: When we migrate to SwiftParser, use the parsed syntax tree. ASTContext &ctx = sourceFile->getASTContext(); auto &sourceMgr = ctx.SourceMgr; @@ -775,4 +776,7 @@ std::pair EvaluateIfConditionRequest::evaluate( bool isActive = (evalResult & 0x01) != 0; bool allowSyntaxErrors = (evalResult & 0x02) != 0; return std::pair(isActive, allowSyntaxErrors); +#else + llvm_unreachable("Must not be used in C++-only build"); +#endif } From 0367e8cb4f5140de7675d3cb4ac0ab3c8382246b Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 22 Nov 2024 13:45:00 -0800 Subject: [PATCH 03/11] Parse `#isolation` as CurrentContextIsolationExpr when we don't have swift-syntax When building without swift-syntax, we don't have the ability to handle macros. However, the concurrency runtime makes use of `#isolation` in a number of places. To continue supporting building without swift-syntax, parse `#isolation` directly into the otherwise-unspellable CurrentContextIsolationExpr but *only* when swift-syntax is not available. --- lib/Parse/ParseExpr.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 4fe20428b6c42..2f09ea4b257c0 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -3471,6 +3471,20 @@ ParserResult Parser::parseExprMacroExpansion(bool isExprBasic) { if (!macroNameRef) return status; +#if !SWIFT_BUILD_SWIFT_SYNTAX + // If we don't have swift-syntax and therefore have no support for macros, + // recognize #isolation as special and route it through + // CurrentContextIsolationExpr. + if (macroNameRef.getBaseName().userFacingName() == "isolation" && + genericArgs.empty() && + (!argList || argList->empty())) { + return makeParserResult( + status, + new (Context) CurrentContextIsolationExpr( + macroNameLoc.getStartLoc(), Type())); + } +#endif + return makeParserResult( status, MacroExpansionExpr::create( From a4b2ca802945ac9fbd6f27da52e2bceafe8b75a1 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 22 Nov 2024 13:48:32 -0800 Subject: [PATCH 04/11] Block the use of @DebugDescription behind hasFeature(Macros) --- stdlib/public/core/ObjectIdentifier+DebugDescription.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/core/ObjectIdentifier+DebugDescription.swift b/stdlib/public/core/ObjectIdentifier+DebugDescription.swift index 2acd0358b0194..51f969e60f15e 100644 --- a/stdlib/public/core/ObjectIdentifier+DebugDescription.swift +++ b/stdlib/public/core/ObjectIdentifier+DebugDescription.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -#if !$Embedded +#if !$Embedded && hasFeature(Macros) @DebugDescription extension ObjectIdentifier { var lldbDescription: String { From 0b36e13100b8d6cfa7d459e0f11f265313a828e7 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 22 Nov 2024 13:56:58 -0800 Subject: [PATCH 05/11] [build-script] Add buildbot_linux,without_host_swift preset Based on a patch from Evan Wilde, introduce a new preset that disables the features that require Swift host tools. This involves disabling early swift-syntax (used in the compiler for macros et al) and early swift-driver. --- utils/build-presets.ini | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 27223b02310fa..4c28da9972e8b 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -935,6 +935,13 @@ mixin-preset= skip-test-swiftdocc +[preset: buildbot_linux,without_host_swift] +mixin-preset= + buildbot_linux + +skip-early-swiftsyntax +skip-early-swift-driver + [preset: buildbot_linux_crosscompile_wasm] mixin-preset=buildbot_linux From 2d931cc458d564d9f37db524992e642edc13e97a Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 22 Nov 2024 22:23:35 -0800 Subject: [PATCH 06/11] Disable bootstrapping when we aren't building SwiftSyntax --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbe9842a73583..9404c41e8ff6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -943,6 +943,13 @@ if (NOT BOOTSTRAPPING_MODE) message(FATAL_ERROR "turning off bootstrapping is not supported anymore") endif() +endif() + +# Disable bootstrapping when we aren't building SwiftSyntax +if(NOT SWIFT_BUILD_SWIFT_SYNTAX) + set(BOOTSTRAPPING_MODE "OFF") +endif() + set(SWIFT_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin") set(SWIFT_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib") if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "") From aa8fdb6e9a7b225d70130fb8ab01e49ac68844f3 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 22 Nov 2024 22:41:09 -0800 Subject: [PATCH 07/11] Disable @_noLocks annotations when we don't have a host Swift compiler These annotations require optimization passes that are written in Swift, so we need a host Swift compiler to properly process them. Use `hasFeature(Macros)` as a way to gate the annotations. --- stdlib/public/core/Availability.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stdlib/public/core/Availability.swift b/stdlib/public/core/Availability.swift index 924ef7dc1a3a4..0ed46931dd2ca 100644 --- a/stdlib/public/core/Availability.swift +++ b/stdlib/public/core/Availability.swift @@ -52,7 +52,9 @@ public func _stdlib_isOSVersionAtLeast( @_semantics("availability.osversion") @_effects(readnone) @_unavailableInEmbedded +#if hasFeature(Macros) @_noLocks +#endif public func _stdlib_isOSVersionAtLeast( _ major: Builtin.Word, _ minor: Builtin.Word, @@ -65,7 +67,9 @@ public func _stdlib_isOSVersionAtLeast( @_semantics("availability.osversion") @_effects(readnone) @_alwaysEmitIntoClient +#if hasFeature(Macros) @_noLocks +#endif public func _stdlib_isOSVersionAtLeast_AEIC( _ major: Builtin.Word, _ minor: Builtin.Word, @@ -110,7 +114,9 @@ public func _stdlib_isOSVersionAtLeast_AEIC( @_semantics("availability.osversion") @_effects(readnone) @available(macOS 10.15, iOS 13.0, *) +#if hasFeature(Macros) @_noLocks +#endif public func _stdlib_isVariantOSVersionAtLeast( _ major: Builtin.Word, _ minor: Builtin.Word, @@ -153,7 +159,9 @@ public func _stdlib_isVariantOSVersionAtLeast( @_semantics("availability.osversion") @_effects(readnone) @_unavailableInEmbedded +#if hasFeature(Macros) @_noLocks +#endif public func _stdlib_isOSVersionAtLeastOrVariantVersionAtLeast( _ major: Builtin.Word, _ minor: Builtin.Word, From d332b271f732efd45dfbad3f44481637960c35b8 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Sat, 23 Nov 2024 07:50:25 -0800 Subject: [PATCH 08/11] [C++-only build] Disable fast paths that require SIL optimizer pieces written in Swift --- stdlib/public/core/StringBridge.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/public/core/StringBridge.swift b/stdlib/public/core/StringBridge.swift index d3cf810c9f738..8d3ab76dffd37 100644 --- a/stdlib/public/core/StringBridge.swift +++ b/stdlib/public/core/StringBridge.swift @@ -751,6 +751,7 @@ extension StringProtocol { public // SPI(Foundation) func _toUTF16Indices(_ range: Range) -> Range { +#if hasFeature(Macros) if Self.self == String.self { let s = unsafeBitCast(self, to: String.self) return s.utf16._indexRange(for: range, from: s.startIndex) @@ -759,6 +760,7 @@ extension StringProtocol { let s = unsafeBitCast(self, to: Substring.self) return s._slice._base.utf16._indexRange(for: range, from: s.startIndex) } +#endif let lowerbound = _toUTF16Index(range.lowerBound) let upperbound = _toUTF16Index(range.upperBound) return Range(uncheckedBounds: (lower: lowerbound, upper: upperbound)) From 1afce805fe67235c1bf6a53568ba23afc3c7c68f Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Sat, 30 Nov 2024 22:14:09 -0800 Subject: [PATCH 09/11] Skip testing when building without host Swift --- utils/build-presets.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 4c28da9972e8b..61398b2aba4a2 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -941,6 +941,7 @@ mixin-preset= skip-early-swiftsyntax skip-early-swift-driver +skip-test [preset: buildbot_linux_crosscompile_wasm] mixin-preset=buildbot_linux From 70b1c3bb137d0646665bdd5fdeb62f83bd891360 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Sun, 1 Dec 2024 11:11:50 -0800 Subject: [PATCH 10/11] Disable testing with no_test --- utils/build-presets.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 61398b2aba4a2..48ca98ebe3264 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -937,11 +937,10 @@ skip-test-swiftdocc [preset: buildbot_linux,without_host_swift] mixin-preset= - buildbot_linux + buildbot_linux,no_test skip-early-swiftsyntax skip-early-swift-driver -skip-test [preset: buildbot_linux_crosscompile_wasm] mixin-preset=buildbot_linux From 04ce3fee1c74330b016f1aecc90858693c48d2d2 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 14 Feb 2025 22:05:38 -0800 Subject: [PATCH 11/11] Fix up compiler and standard library build when there's no host Swift --- lib/AST/ASTScope.cpp | 4 ++++ stdlib/public/core/SwiftifyImport.swift | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lib/AST/ASTScope.cpp b/lib/AST/ASTScope.cpp index e8248ba9082fa..f1d4c13901e86 100644 --- a/lib/AST/ASTScope.cpp +++ b/lib/AST/ASTScope.cpp @@ -148,6 +148,7 @@ void ASTScope::unqualifiedLookup( if (auto *s = SF->getASTContext().Stats) ++s->getFrontendCounters().NumASTScopeLookups; +#if SWIFT_BUILD_SWIFT_SYNTAX // Perform validation of SwiftLexicalLookup if option // Feature::UnqualifiedLookupValidation is enabled and lookup was not // performed in a macro. @@ -171,6 +172,9 @@ void ASTScope::unqualifiedLookup( } else { ASTScopeImpl::unqualifiedLookup(SF, loc, consumer); } +#else + ASTScopeImpl::unqualifiedLookup(SF, loc, consumer); +#endif } llvm::SmallVector ASTScope::lookupLabeledStmts( diff --git a/stdlib/public/core/SwiftifyImport.swift b/stdlib/public/core/SwiftifyImport.swift index e52c8989b5afa..3efd0a645098a 100644 --- a/stdlib/public/core/SwiftifyImport.swift +++ b/stdlib/public/core/SwiftifyImport.swift @@ -58,6 +58,8 @@ public enum _SwiftifyInfo { /// /// Parameter paramInfo: information about how the function uses the pointer passed to it. The /// safety of the generated wrapper function depends on this info being extensive and accurate. +#if hasFeature(Macros) @attached(peer, names: overloaded) public macro _SwiftifyImport(_ paramInfo: _SwiftifyInfo..., typeMappings: [String: String] = [:]) = #externalMacro(module: "SwiftMacros", type: "SwiftifyImportMacro") +#endif