Skip to content

Commit 34c90f1

Browse files
committed
Merge remote-tracking branch 'upstream/main' into swift-lexical-lookup-validation
2 parents f4a5069 + 91d8abb commit 34c90f1

File tree

129 files changed

+1814
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1814
-667
lines changed

SwiftCompilerSources/Sources/Optimizer/Analysis/AliasAnalysis.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,23 @@ private struct FindBeginBorrowWalker : ValueUseDefWalker {
696696
if value == beginBorrow {
697697
return .abortWalk
698698
}
699+
if value.ownership != .guaranteed {
700+
// If value is owned then it cannot be the borrowed value.
701+
return .continueWalk
702+
}
699703
return walkUpDefault(value: value, path: path)
700704
}
701705

702706
mutating func rootDef(value: Value, path: SmallProjectionPath) -> WalkResult {
703-
return .continueWalk
707+
switch value {
708+
case is FunctionArgument,
709+
// Loading a value from memory cannot be the borrowed value.
710+
// Note that we exclude the "regular" `load` by checking for guaranteed ownership in `walkUp`.
711+
is LoadBorrowInst:
712+
return .continueWalk
713+
default:
714+
return .abortWalk
715+
}
704716
}
705717
}
706718

cmake/modules/SwiftUtils.cmake

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -190,33 +190,27 @@ endfunction()
190190
# we create a `swift-driver` symlink adjacent to the `swift` and `swiftc` executables
191191
# to ensure that `swiftc` forwards to the standalone driver when invoked.
192192
function(swift_create_early_driver_copies target)
193-
# Early swift-driver is built adjacent to the compiler (swift build dir)
194-
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
195-
set(driver_package_configuration_dir "release")
196-
else()
197-
set(driver_package_configuration_dir "debug")
198-
endif()
199-
200-
set(driver_bin_dir "${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/${driver_package_configuration_dir}/bin")
201-
set(swift_bin_dir "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
202-
# If early swift-driver wasn't built, nothing to do here.
203-
if(NOT EXISTS "${driver_bin_dir}/swift-driver" OR NOT EXISTS "${driver_bin_dir}/swift-help")
204-
message(STATUS "Skipping creating early SwiftDriver symlinks - no early SwiftDriver build found at: ${driver_bin_dir}.")
205-
return()
193+
set(SWIFT_EARLY_SWIFT_DRIVER_BUILD "" CACHE PATH "Path to early swift-driver build")
194+
195+
if(NOT SWIFT_EARLY_SWIFT_DRIVER_BUILD)
196+
return()
206197
endif()
207198

208-
message(STATUS "Copying over early SwiftDriver executable.")
209-
message(STATUS "From: ${driver_bin_dir}/swift-driver")
210-
message(STATUS "To: ${swift_bin_dir}/swift-driver")
211-
# Use configure_file instead of file(COPY...) to establish a dependency.
212-
# Further Changes to `swift-driver` will cause it to be copied over.
213-
configure_file(${driver_bin_dir}/swift-driver ${swift_bin_dir}/swift-driver COPYONLY)
214-
215-
message(STATUS "From: ${driver_bin_dir}/swift-help")
216-
message(STATUS "To: ${swift_bin_dir}/swift-help")
217-
# Use configure_file instead of file(COPY...) to establish a dependency.
218-
# Further Changes to `swift-driver` will cause it to be copied over.
219-
configure_file(${driver_bin_dir}/swift-help ${swift_bin_dir}/swift-help COPYONLY)
199+
if(EXISTS ${SWIFT_EARLY_SWIFT_DRIVER_BUILD}/swift-driver${CMAKE_EXECUTABLE_SUFFIX})
200+
message(STATUS "Creating early SwiftDriver symlinks")
201+
202+
# Use `configure_file` instead of `file(COPY ...)` to establish a
203+
# dependency. Further changes to `swift-driver` will cause it to be copied
204+
# over.
205+
configure_file(${SWIFT_EARLY_SWIFT_DRIVER_BUILD}/swift-driver${CMAKE_EXECUTABLE_SUFFIX}
206+
${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-driver${CMAKE_EXECUTABLE_SUFFIX}
207+
COPYONLY)
208+
configure_file(${SWIFT_EARLY_SWIFT_DRIVER_BUILD}/swift-help${CMAKE_EXECUTABLE_SUFFIX}
209+
${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-help${CMAKE_EXECUTABLE_SUFFIX}
210+
COPYONLY)
211+
else()
212+
message(STATUS "Not creating early SwiftDriver symlinks (swift-driver not found)")
213+
endif()
220214
endfunction()
221215

222216
function(dump_swift_vars)

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5105,7 +5105,8 @@ ERROR(unknown_case_must_be_last,none,
51055105
"'@unknown' can only be applied to the last case in a switch", ())
51065106

51075107
WARNING(where_on_one_item, none,
5108-
"'where' only applies to the second pattern match in this case", ())
5108+
"'where' only applies to the second pattern match in this "
5109+
"'%select{case|catch}0'", (bool))
51095110

51105111
NOTE(add_where_newline, none,
51115112
"disambiguate by adding a line break between them if this is desired", ())

include/swift/Option/Options.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,15 @@ def omit_extension_block_symbols: Flag<["-"], "omit-extension-block-symbols">,
16701670
NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
16711671
HelpText<"Directly associate members and conformances with the extended nominal when generating symbol graphs instead of emitting 'swift.extension' symbols for extensions to external types">;
16721672

1673+
// swift-synthesize-interface-only options
1674+
def include_submodules : Flag<["-"], "include-submodules">,
1675+
Flags<[NoDriverOption, SwiftSynthesizeInterfaceOption]>,
1676+
HelpText<"Also print the declarations synthesized for any Clang submodules">;
1677+
1678+
def print_fully_qualified_types : Flag<["-"], "print-fully-qualified-types">,
1679+
Flags<[NoDriverOption, SwiftSynthesizeInterfaceOption]>,
1680+
HelpText<"Always print fully qualified type names">;
1681+
16731682
// swift-symbolgraph-extract-only options
16741683
def output_dir : Separate<["-"], "output-dir">,
16751684
Flags<[NoDriverOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption,

lib/ASTGen/Sources/ASTGen/Exprs.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ extension ASTGenVisitor {
161161
return self.generate(subscriptCallExpr: node).asExpr
162162
case .superExpr(let node):
163163
return self.generate(superExpr: node).asExpr
164-
case .switchExpr:
165-
break
164+
case .switchExpr(let node):
165+
return self.generate(switchExpr: node).asExpr
166166
case .ternaryExpr:
167167
preconditionFailure("TernaryExprSyntax only appear after operator folding")
168168
case .tryExpr(let node):
@@ -1063,6 +1063,18 @@ extension ASTGenVisitor {
10631063
return .createParsed(self.ctx, superLoc: self.generateSourceLoc(node))
10641064
}
10651065

1066+
func generate(switchExpr node: SwitchExprSyntax) -> BridgedSingleValueStmtExpr {
1067+
let stmt = self.generateSwitchStmt(switchExpr: node)
1068+
1069+
// Wrap in a SingleValueStmtExpr to embed as an expression.
1070+
return .createWithWrappedBranches(
1071+
ctx,
1072+
stmt: stmt.asStmt,
1073+
declContext: declContext,
1074+
mustBeExpr: true
1075+
)
1076+
}
1077+
10661078
func generate(tryExpr node: TryExprSyntax) -> BridgedExpr {
10671079
let tryLoc = self.generateSourceLoc(node.tryKeyword)
10681080
let subExpr = self.generate(expr: node.expression)

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,15 +552,8 @@ bool ClangImporter::getHeaderDependencies(
552552
auto swiftBinaryDeps = targetModuleInfo.getAsSwiftBinaryModule();
553553
if (!swiftBinaryDeps->headerImport.empty()) {
554554
auto clangModuleDependencies = scanHeaderDependencies(swiftBinaryDeps->headerImport);
555-
if (!clangModuleDependencies) {
556-
// FIXME: Route this to a normal diagnostic.
557-
llvm::logAllUnhandledErrors(clangModuleDependencies.takeError(),
558-
llvm::errs());
559-
Impl.SwiftContext.Diags.diagnose(
560-
SourceLoc(), diag::clang_dependency_scan_error,
561-
"failed to scan header dependencies");
555+
if (!clangModuleDependencies)
562556
return true;
563-
}
564557
}
565558
}
566559

lib/DriverTool/swift_synthesize_interface_main.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,19 @@ int swift_synthesize_interface_main(ArrayRef<const char *> Args,
200200
return EXIT_FAILURE;
201201
}
202202

203-
StreamPrinter printer(fs);
204203
PrintOptions printOpts =
205204
PrintOptions::printModuleInterface(/*printFullConvention=*/true);
206-
ide::printModuleInterface(M, /*GroupNames=*/{},
207-
/*TraversalOptions=*/std::nullopt, printer,
205+
if (ParsedArgs.hasArg(OPT_print_fully_qualified_types)) {
206+
printOpts.FullyQualifiedTypes = true;
207+
}
208+
209+
swift::OptionSet<swift::ide::ModuleTraversal> traversalOpts = std::nullopt;
210+
if (ParsedArgs.hasArg(OPT_include_submodules)) {
211+
traversalOpts = swift::ide::ModuleTraversal::VisitSubmodules;
212+
}
213+
214+
StreamPrinter printer(fs);
215+
ide::printModuleInterface(M, /*GroupNames=*/{}, traversalOpts, printer,
208216
printOpts, /*PrintSynthesizedExtensions=*/false);
209217

210218
return EXIT_SUCCESS;

lib/IRGen/GenDecl.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6192,13 +6192,18 @@ IRGenModule::getAddrOfContinuationPrototype(CanSILFunctionType fnType) {
61926192
/// Should we be defining the given helper function?
61936193
static llvm::Function *shouldDefineHelper(IRGenModule &IGM,
61946194
llvm::Constant *fn,
6195-
bool setIsNoInline) {
6195+
bool setIsNoInline,
6196+
IRLinkage *linkage) {
61966197
auto *def = dyn_cast<llvm::Function>(fn);
61976198
if (!def) return nullptr;
61986199
if (!def->empty()) return nullptr;
61996200

62006201
def->setAttributes(IGM.constructInitialAttributes());
6201-
ApplyIRLinkage(IRLinkage::InternalLinkOnceODR).to(def);
6202+
if (!linkage)
6203+
ApplyIRLinkage(IRLinkage::InternalLinkOnceODR).to(def);
6204+
else
6205+
ApplyIRLinkage(*linkage).to(def);
6206+
62026207
def->setDoesNotThrow();
62036208
def->setCallingConv(IGM.DefaultCC);
62046209
if (setIsNoInline)
@@ -6220,15 +6225,17 @@ IRGenModule::getOrCreateHelperFunction(StringRef fnName, llvm::Type *resultTy,
62206225
llvm::function_ref<void(IRGenFunction &IGF)> generate,
62216226
bool setIsNoInline,
62226227
bool forPrologue,
6223-
bool isPerformanceConstraint) {
6228+
bool isPerformanceConstraint,
6229+
IRLinkage *optionalLinkageOverride) {
62246230
llvm::FunctionType *fnTy =
62256231
llvm::FunctionType::get(resultTy, paramTys, false);
62266232

62276233
llvm::Constant *fn =
62286234
cast<llvm::Constant>(
62296235
Module.getOrInsertFunction(fnName, fnTy).getCallee());
62306236

6231-
if (llvm::Function *def = shouldDefineHelper(*this, fn, setIsNoInline)) {
6237+
if (llvm::Function *def = shouldDefineHelper(*this, fn, setIsNoInline,
6238+
optionalLinkageOverride)) {
62326239
IRGenFunction IGF(*this, def, isPerformanceConstraint);
62336240
if (DebugInfo && !forPrologue)
62346241
DebugInfo->emitArtificialFunction(IGF, def);

lib/IRGen/IRGenModule.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ namespace irgen {
147147
class StructLayout;
148148
class IRGenDebugInfo;
149149
class IRGenFunction;
150+
struct IRLinkage;
150151
class LinkEntity;
151152
class LoadableTypeInfo;
152153
class MetadataLayout;
@@ -1221,7 +1222,8 @@ class IRGenModule {
12211222
llvm::function_ref<void(IRGenFunction &IGF)> generate,
12221223
bool setIsNoInline = false,
12231224
bool forPrologue = false,
1224-
bool isPerformanceConstraint = false);
1225+
bool isPerformanceConstraint = false,
1226+
IRLinkage *optionalLinkage = nullptr);
12251227

12261228
llvm::Constant *getOrCreateRetainFunction(const TypeInfo &objectTI, SILType t,
12271229
llvm::Type *llvmType, Atomicity atomicity);

lib/IRGen/Outlining.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "swift/AST/IRGenOptions.h"
3131
#include "swift/Basic/Assertions.h"
3232
#include "swift/IRGen/GenericRequirement.h"
33+
#include "swift/IRGen/Linking.h"
3334
#include "swift/SIL/SILModule.h"
3435

3536
using namespace swift;
@@ -489,6 +490,22 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction(
489490
paramTys.push_back(ptrTy);
490491
collector.addPolymorphicParameterTypes(paramTys);
491492

493+
IRLinkage *linkage = nullptr;
494+
IRLinkage privateLinkage = {
495+
llvm::GlobalValue::PrivateLinkage,
496+
llvm::GlobalValue::DefaultVisibility,
497+
llvm::GlobalValue::DefaultStorageClass,
498+
};
499+
auto &TL =
500+
getSILModule().Types.getTypeLowering(T, TypeExpansionContext::minimal());
501+
// Opaque result types might lead to different expansions in different files.
502+
// The default hidden linkonce_odr might lead to linking an implementation
503+
// from another file that head a different expansion/different
504+
// signature/different implementation.
505+
if (TL.getRecursiveProperties().isTypeExpansionSensitive()) {
506+
linkage = &privateLinkage;
507+
}
508+
492509
return getOrCreateHelperFunction(funcName, ptrTy, paramTys,
493510
[&](IRGenFunction &IGF) {
494511
auto params = IGF.collectParameters();
@@ -500,7 +517,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction(
500517
},
501518
true /*setIsNoInline*/,
502519
false /*forPrologue*/,
503-
collector.IGF.isPerformanceConstraint);
520+
collector.IGF.isPerformanceConstraint,
521+
linkage);
504522
}
505523

506524
void TypeInfo::callOutlinedDestroy(IRGenFunction &IGF,
@@ -544,6 +562,22 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedDestroyFunction(
544562
auto funcName = mangler.mangleOutlinedDestroyFunction(manglingBits.first,
545563
manglingBits.second, collector.IGF.isPerformanceConstraint);
546564

565+
IRLinkage *linkage = nullptr;
566+
IRLinkage privateLinkage = {
567+
llvm::GlobalValue::PrivateLinkage,
568+
llvm::GlobalValue::DefaultVisibility,
569+
llvm::GlobalValue::DefaultStorageClass,
570+
};
571+
auto &TL =
572+
getSILModule().Types.getTypeLowering(T, TypeExpansionContext::minimal());
573+
// Opaque result types might lead to different expansions in different files.
574+
// The default hidden linkonce_odr might lead to linking an implementation
575+
// from another file that head a different expansion/different
576+
// signature/different implementation.
577+
if (TL.getRecursiveProperties().isTypeExpansionSensitive()) {
578+
linkage = &privateLinkage;
579+
}
580+
547581
auto ptrTy = ti.getStorageType()->getPointerTo();
548582
llvm::SmallVector<llvm::Type *, 4> paramTys;
549583
paramTys.push_back(ptrTy);
@@ -565,7 +599,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedDestroyFunction(
565599
},
566600
true /*setIsNoInline*/,
567601
false /*forPrologue*/,
568-
collector.IGF.isPerformanceConstraint);
602+
collector.IGF.isPerformanceConstraint,
603+
linkage);
569604
}
570605

571606
llvm::Constant *IRGenModule::getOrCreateRetainFunction(const TypeInfo &ti,

0 commit comments

Comments
 (0)