Skip to content

Commit e1a3cc2

Browse files
DougGregoretcwilde
authored andcommitted
Build compiler and runtimes without Swift
Remove dependency on macros from compiler and stdlib build when bootstrapping the compiler without Swift available.
1 parent 17ee434 commit e1a3cc2

7 files changed

+35
-1
lines changed

Diff for: lib/AST/ASTScope.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ void ASTScope::unqualifiedLookup(
148148
if (auto *s = SF->getASTContext().Stats)
149149
++s->getFrontendCounters().NumASTScopeLookups;
150150

151+
#if SWIFT_BUILD_SWIFT_SYNTAX
151152
// Perform validation of SwiftLexicalLookup if option
152153
// Feature::UnqualifiedLookupValidation is enabled and lookup was not
153154
// performed in a macro.
@@ -171,6 +172,9 @@ void ASTScope::unqualifiedLookup(
171172
} else {
172173
ASTScopeImpl::unqualifiedLookup(SF, loc, consumer);
173174
}
175+
#else
176+
ASTScopeImpl::unqualifiedLookup(SF, loc, consumer);
177+
#endif
174178
}
175179

176180
llvm::SmallVector<LabeledStmt *, 4> ASTScope::lookupLabeledStmts(

Diff for: lib/Parse/ParseExpr.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -3473,6 +3473,20 @@ ParserResult<Expr> Parser::parseExprMacroExpansion(bool isExprBasic) {
34733473
if (!macroNameRef)
34743474
return status;
34753475

3476+
#if !SWIFT_BUILD_SWIFT_SYNTAX
3477+
// If we don't have swift-syntax and therefore have no support for macros,
3478+
// recognize #isolation as special and route it through
3479+
// CurrentContextIsolationExpr.
3480+
if (macroNameRef.getBaseName().userFacingName() == "isolation" &&
3481+
genericArgs.empty() &&
3482+
(!argList || argList->empty())) {
3483+
return makeParserResult(
3484+
status,
3485+
new (Context) CurrentContextIsolationExpr(
3486+
macroNameLoc.getStartLoc(), Type()));
3487+
}
3488+
#endif
3489+
34763490
return makeParserResult(
34773491
status,
34783492
MacroExpansionExpr::create(

Diff for: lib/Sema/TypeChecker.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ std::pair<bool, bool> EvaluateIfConditionRequest::evaluate(
755755
Evaluator &evaluator, SourceFile *sourceFile, SourceRange conditionRange,
756756
bool shouldEvaluate
757757
) const {
758+
#if SWIFT_BUILD_SWIFT_SYNTAX
758759
// FIXME: When we migrate to SwiftParser, use the parsed syntax tree.
759760
ASTContext &ctx = sourceFile->getASTContext();
760761
auto &sourceMgr = ctx.SourceMgr;
@@ -775,4 +776,7 @@ std::pair<bool, bool> EvaluateIfConditionRequest::evaluate(
775776
bool isActive = (evalResult & 0x01) != 0;
776777
bool allowSyntaxErrors = (evalResult & 0x02) != 0;
777778
return std::pair(isActive, allowSyntaxErrors);
779+
#else
780+
llvm_unreachable("Must not be used in C++-only build");
781+
#endif
778782
}

Diff for: stdlib/public/core/Availability.swift

+8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public func _stdlib_isOSVersionAtLeast(
5252
@_semantics("availability.osversion")
5353
@_effects(readnone)
5454
@_unavailableInEmbedded
55+
#if hasFeature(Macros)
5556
@_noLocks
57+
#endif
5658
public func _stdlib_isOSVersionAtLeast(
5759
_ major: Builtin.Word,
5860
_ minor: Builtin.Word,
@@ -65,7 +67,9 @@ public func _stdlib_isOSVersionAtLeast(
6567
@_semantics("availability.osversion")
6668
@_effects(readnone)
6769
@_alwaysEmitIntoClient
70+
#if hasFeature(Macros)
6871
@_noLocks
72+
#endif
6973
public func _stdlib_isOSVersionAtLeast_AEIC(
7074
_ major: Builtin.Word,
7175
_ minor: Builtin.Word,
@@ -110,7 +114,9 @@ public func _stdlib_isOSVersionAtLeast_AEIC(
110114
@_semantics("availability.osversion")
111115
@_effects(readnone)
112116
@available(macOS 10.15, iOS 13.0, *)
117+
#if hasFeature(Macros)
113118
@_noLocks
119+
#endif
114120
public func _stdlib_isVariantOSVersionAtLeast(
115121
_ major: Builtin.Word,
116122
_ minor: Builtin.Word,
@@ -153,7 +159,9 @@ public func _stdlib_isVariantOSVersionAtLeast(
153159
@_semantics("availability.osversion")
154160
@_effects(readnone)
155161
@_unavailableInEmbedded
162+
#if hasFeature(Macros)
156163
@_noLocks
164+
#endif
157165
public func _stdlib_isOSVersionAtLeastOrVariantVersionAtLeast(
158166
_ major: Builtin.Word,
159167
_ minor: Builtin.Word,

Diff for: stdlib/public/core/ObjectIdentifier+DebugDescription.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if !$Embedded
13+
#if !$Embedded && hasFeature(Macros)
1414
@DebugDescription
1515
extension ObjectIdentifier {
1616
var lldbDescription: String {

Diff for: stdlib/public/core/StringBridge.swift

+2
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ extension StringProtocol {
752752

753753
public // SPI(Foundation)
754754
func _toUTF16Indices(_ range: Range<Int>) -> Range<Index> {
755+
#if hasFeature(Macros)
755756
if Self.self == String.self {
756757
let s = unsafe unsafeBitCast(self, to: String.self)
757758
return s.utf16._indexRange(for: range, from: s.startIndex)
@@ -760,6 +761,7 @@ extension StringProtocol {
760761
let s = unsafe unsafeBitCast(self, to: Substring.self)
761762
return s._slice._base.utf16._indexRange(for: range, from: s.startIndex)
762763
}
764+
#endif
763765
let lowerbound = _toUTF16Index(range.lowerBound)
764766
let upperbound = _toUTF16Index(range.upperBound)
765767
return unsafe Range(uncheckedBounds: (lower: lowerbound, upper: upperbound))

Diff for: stdlib/public/core/SwiftifyImport.swift

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public enum _SwiftifyInfo {
5858
///
5959
/// Parameter paramInfo: information about how the function uses the pointer passed to it. The
6060
/// safety of the generated wrapper function depends on this info being extensive and accurate.
61+
#if hasFeature(Macros)
6162
@attached(peer, names: overloaded)
6263
public macro _SwiftifyImport(_ paramInfo: _SwiftifyInfo..., typeMappings: [String: String] = [:]) =
6364
#externalMacro(module: "SwiftMacros", type: "SwiftifyImportMacro")
65+
#endif

0 commit comments

Comments
 (0)