Skip to content

Merge main 2023-05-24 #5469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
db9e286
[CMake] Don't add an extraneous rpath to the swift-frontend
finagolfin Mar 4, 2023
d76b52f
[update-checkout] Bump swift-certificates to 0.6.0
yim-lee May 11, 2023
aa490ea
Bump swift-asn1 to 0.8.0
yim-lee May 11, 2023
359c37e
[EmitPCH] Do not cache PCH in memory during emit-pch action
cachemeifyoucan May 12, 2023
8bd4ac8
[CachedDiags] Don't cache diagnostics if command-line failed
cachemeifyoucan May 12, 2023
68db1b4
[ClangImporter] Don't add cxx shim module map when not needed
cachemeifyoucan May 12, 2023
cc01780
[ClangImporter] Don't add clang path when creating from cc1 commands
cachemeifyoucan May 12, 2023
f4569a6
[Module] Simplify explicit clang module loading
cachemeifyoucan May 12, 2023
c976dfb
Move modulemap to header search directory. NFC intended.
vsapsai May 19, 2023
51c62ae
[benchmark] add `removeAll(keepingCapacity: true)` non-unique test
oxy May 23, 2023
d489ba2
[benchmark] check results only once in ArrayRemoveAll
oxy May 23, 2023
008ed2f
[benchmark] clean up setup for ArrayRemoveAll
oxy May 23, 2023
1864f12
Merge pull request #65850 from yim-lee/swift-certificates-0.6.0
shahmishal May 23, 2023
c2c2414
Merge pull request #65925 from cachemeifyoucan/eng/PR-swift-frontend-…
cachemeifyoucan May 23, 2023
ec28aa4
[move-only] Ban destructuring of noncopyable address only types like …
gottesmm May 23, 2023
6a1129f
[benchmark] rename `Array.removeAll` benchmarks
oxy May 24, 2023
53aac94
Merge pull request #66037 from vsapsai/move-modulemap
vsapsai May 24, 2023
32745c3
[benchmark] half `Array.removeAll` bench size
oxy May 24, 2023
631a3ef
Merge pull request #66092 from gottesmm/pr-6e8d5b3eecd4d51d09bf0be496…
gottesmm May 24, 2023
caa497a
Merge pull request #66087 from oxy/gh56321-benchmark
swift-ci May 24, 2023
ccae422
Merge pull request #64103 from finagolfin/rpath
edymtt May 24, 2023
7e4d476
Merge remote-tracking branch 'origin/main' into root/merge-main-2023-…
kateinoigakukun May 24, 2023
d4d5a3b
[wasm] sync update-checkout-config.json
kateinoigakukun May 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(SWIFT_BENCH_MODULES
single-source/ArrayOfGenericRef
single-source/ArrayOfPOD
single-source/ArrayOfRef
single-source/ArrayRemoveAll
single-source/ArraySetElement
single-source/ArraySubscript
single-source/BinaryFloatingPointConversionFromBinaryInteger
Expand Down
55 changes: 55 additions & 0 deletions benchmark/single-source/ArrayRemoveAll.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This test checks the performance of removeAll
// on a non-uniquely referenced array.

import TestsUtils

public let benchmarks = [
BenchmarkInfo(
name: "Array.removeAll.keepingCapacity.Int",
runFunction: run_ArrayRemoveAll_Class,
tags: [.validation, .api, .Array],
setUpFunction: { blackHole(inputArray_Class) }
),
BenchmarkInfo(
name: "Array.removeAll.keepingCapacity.Object",
runFunction: run_ArrayRemoveAll_Int,
tags: [.validation, .api, .Array],
setUpFunction: { blackHole(inputArray_Int) }
)
]

class Slow {
public var num: Int

init(num: Int) {
self.num = num
}
}

let inputArray_Int: [Int] = Array(0..<500_000)
let inputArray_Class: [Slow] = (0..<50_000).map(Slow.init(num:))

@inline(never)
func removeAll<T>(_ arr: [T]) -> [T] {
var copy = arr
copy.removeAll(keepingCapacity: true)
return copy
}

@inline(never)
func run_ArrayRemoveAll_Class(_ n: Int) {
var copy = removeAll(inputArray_Class);
for _ in 1..<n {
copy = removeAll(inputArray_Class)
}
check(copy.capacity == inputArray_Class.capacity)
}

@inline(never)
func run_ArrayRemoveAll_Int(_ n: Int) {
var copy = removeAll(inputArray_Int);
for _ in 1..<n {
copy = removeAll(inputArray_Int)
}
check(copy.capacity == inputArray_Int.capacity)
}
2 changes: 2 additions & 0 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ArrayOfGenericPOD
import ArrayOfGenericRef
import ArrayOfPOD
import ArrayOfRef
import ArrayRemoveAll
import ArraySetElement
import ArraySubscript
import BinaryFloatingPointConversionFromBinaryInteger
Expand Down Expand Up @@ -217,6 +218,7 @@ register(ArrayOfGenericPOD.benchmarks)
register(ArrayOfGenericRef.benchmarks)
register(ArrayOfPOD.benchmarks)
register(ArrayOfRef.benchmarks)
register(ArrayRemoveAll.benchmarks)
register(ArraySetElement.benchmarks)
register(ArraySubscript.benchmarks)
register(BinaryFloatingPointConversionFromBinaryInteger.benchmarks)
Expand Down
48 changes: 48 additions & 0 deletions include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module BasicBridging {
header "swift/Basic/BridgedSwiftObject.h"
header "swift/Basic/BasicBridging.h"
header "swift/Basic/SourceLoc.h"
requires cplusplus
export *
}

module CBasicBridging {
header "swift/Basic/CBasicBridging.h"
}

module ASTBridging {
header "swift/AST/AnyFunctionRef.h"
header "swift/AST/ASTBridging.h"
header "swift/AST/Builtins.h"
header "swift/AST/DiagnosticEngine.h"
header "swift/AST/DiagnosticConsumer.h"
header "swift/AST/ForeignAsyncConvention.h"
header "swift/AST/ForeignErrorConvention.h"
header "swift/AST/SubstitutionMap.h"

textual header "swift/AST/Builtins.def"

requires cplusplus
export *
}

module CASTBridging {
header "swift/AST/CASTBridging.h"
}

module SILBridging {
header "swift/SIL/SILBridging.h"
header "swift/SIL/SILLocation.h"
requires cplusplus
export *
}

module OptimizerBridging {
header "swift/SILOptimizer/OptimizerBridging.h"
export *
}

module _RegexParserBridging {
header "swift/Parse/RegexParserBridging.h"
export *
}
5 changes: 3 additions & 2 deletions include/swift/ClangImporter/ClangImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ class ClangImporter final : public ClangModuleLoader {
/// replica.
///
/// \sa clang::GeneratePCHAction
bool emitBridgingPCH(StringRef headerPath, StringRef outputPCHPath);
bool emitBridgingPCH(StringRef headerPath, StringRef outputPCHPath,
bool cached);

/// Returns true if a clang CompilerInstance can successfully read in a PCH,
/// assuming it exists, with the current options. This can be used to find out
Expand Down Expand Up @@ -529,7 +530,7 @@ class ClangImporter final : public ClangModuleLoader {

Optional<std::string>
getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
StringRef SwiftPCHHash);
StringRef SwiftPCHHash, bool Cached);
Optional<std::string>
/// \param isExplicit true if the PCH filename was passed directly
/// with -import-objc-header option.
Expand Down
48 changes: 0 additions & 48 deletions include/swift/module.modulemap

This file was deleted.

47 changes: 28 additions & 19 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ namespace {
Importer.addSearchPath(path, /*isFramework*/false, /*isSystem=*/false);
}

auto PCH = Importer.getOrCreatePCH(ImporterOpts, SwiftPCHHash);
auto PCH =
Importer.getOrCreatePCH(ImporterOpts, SwiftPCHHash, /*Cached=*/true);
if (PCH.has_value()) {
Impl.getClangInstance()->getPreprocessorOpts().ImplicitPCHInclude =
PCH.value();
Expand Down Expand Up @@ -582,8 +583,10 @@ importer::getNormalInvocationArguments(
});
}

if (auto path = getCxxShimModuleMapPath(searchPathOpts, triple)) {
invocationArgStrs.push_back((Twine("-fmodule-map-file=") + *path).str());
if (LangOpts.EnableCXXInterop) {
if (auto path = getCxxShimModuleMapPath(searchPathOpts, triple)) {
invocationArgStrs.push_back((Twine("-fmodule-map-file=") + *path).str());
}
}

// Set C language options.
Expand Down Expand Up @@ -996,8 +999,9 @@ ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
return PCHFilename.str().str();
}

Optional<std::string> ClangImporter::getOrCreatePCH(
const ClangImporterOptions &ImporterOptions, StringRef SwiftPCHHash) {
Optional<std::string>
ClangImporter::getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
StringRef SwiftPCHHash, bool Cached) {
bool isExplicit;
auto PCHFilename = getPCHFilename(ImporterOptions, SwiftPCHHash,
isExplicit);
Expand All @@ -1013,8 +1017,8 @@ Optional<std::string> ClangImporter::getOrCreatePCH(
<< EC.message();
return None;
}
auto FailedToEmit =
emitBridgingPCH(ImporterOptions.BridgingHeader, PCHFilename.value());
auto FailedToEmit = emitBridgingPCH(ImporterOptions.BridgingHeader,
PCHFilename.value(), Cached);
if (FailedToEmit) {
return None;
}
Expand All @@ -1026,9 +1030,10 @@ Optional<std::string> ClangImporter::getOrCreatePCH(
std::vector<std::string>
ClangImporter::getClangArguments(ASTContext &ctx, bool ignoreClangTarget) {
std::vector<std::string> invocationArgStrs;
// Clang expects this to be like an actual command line. So we need to pass in
// "clang" for argv[0]
invocationArgStrs.push_back(ctx.ClangImporterOpts.clangPath);
// When creating from driver commands, clang expects this to be like an actual
// command line. So we need to pass in "clang" for argv[0]
if (!ctx.ClangImporterOpts.DirectClangCC1ModuleBuild)
invocationArgStrs.push_back(ctx.ClangImporterOpts.clangPath);
if (ctx.ClangImporterOpts.ExtraArgsOnly) {
invocationArgStrs.insert(invocationArgStrs.end(),
ctx.ClangImporterOpts.ExtraArgs.begin(),
Expand Down Expand Up @@ -1777,13 +1782,13 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
}

bool ClangImporter::emitBridgingPCH(
StringRef headerPath, StringRef outputPCHPath) {
StringRef headerPath, StringRef outputPCHPath, bool cached) {
auto emitInstance = cloneCompilerInstanceForPrecompiling();
auto &invocation = emitInstance->getInvocation();

auto LangOpts = invocation.getLangOpts();
LangOpts->NeededByPCHOrCompilationUsesPCH = true;
LangOpts->CacheGeneratedPCH = true;
LangOpts->CacheGeneratedPCH = cached;

auto language = getLanguageFromOptions(LangOpts);
auto inputFile = clang::FrontendInputFile(headerPath, language);
Expand Down Expand Up @@ -2034,12 +2039,16 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
auto &clangHeaderSearch = getClangPreprocessor().getHeaderSearchInfo();
auto realModuleName = SwiftContext.getRealModuleName(path.front().Item).str();

// Look up the top-level module first, to see if it exists at all.
clang::Module *clangModule = clangHeaderSearch.lookupModule(
realModuleName, /*ImportLoc=*/clang::SourceLocation(),
/*AllowSearch=*/true, /*AllowExtraModuleMapSearch=*/true);
if (!clangModule)
return nullptr;
// For explicit module build, module should always exist but module map might
// not be exist. Go straight to module loader.
if (Instance->getInvocation().getLangOpts()->ImplicitModules) {
// Look up the top-level module first, to see if it exists at all.
clang::Module *clangModule = clangHeaderSearch.lookupModule(
realModuleName, /*ImportLoc=*/clang::SourceLocation(),
/*AllowSearch=*/true, /*AllowExtraModuleMapSearch=*/true);
if (!clangModule)
return nullptr;
}

// Convert the Swift import path over to a Clang import path.
SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4>
Expand Down Expand Up @@ -2094,7 +2103,7 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(

// Now load the top-level module, so that we can check if the submodule
// exists without triggering a fatal error.
clangModule = loadModule(clangPath.front(), clang::Module::AllVisible);
auto clangModule = loadModule(clangPath.front(), clang::Module::AllVisible);
if (!clangModule)
return nullptr;

Expand Down
10 changes: 8 additions & 2 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,13 @@ static bool precompileBridgingHeader(const CompilerInstance &Instance) {
if (!PCHOutDir.empty()) {
// Create or validate a persistent PCH.
auto SwiftPCHHash = Invocation.getPCHHash();
auto PCH = clangImporter->getOrCreatePCH(ImporterOpts, SwiftPCHHash);
auto PCH = clangImporter->getOrCreatePCH(ImporterOpts, SwiftPCHHash,
/*cached=*/false);
return !PCH.has_value();
}
return clangImporter->emitBridgingPCH(
opts.InputsAndOutputs.getFilenameOfFirstInput(),
opts.InputsAndOutputs.getSingleOutputFilename());
opts.InputsAndOutputs.getSingleOutputFilename(), /*cached=*/false);
}

static bool precompileClangModule(const CompilerInstance &Instance) {
Expand Down Expand Up @@ -2072,6 +2073,11 @@ int swift::performFrontend(ArrayRef<const char *> Args,
auto finishDiagProcessing = [&](int retValue, bool verifierEnabled) -> int {
FinishDiagProcessingCheckRAII.CalledFinishDiagProcessing = true;
PDC.setSuppressOutput(false);
if (auto *CDP = Instance->getCachingDiagnosticsProcessor()) {
// Don't cache if build failed.
if (retValue)
CDP->endDiagnosticCapture();
}
bool diagnosticsError = Instance->getDiags().finishProcessing();
// If the verifier is enabled and did not encounter any verification errors,
// return 0 even if the compile failed. This behavior isn't ideal, but large
Expand Down
12 changes: 12 additions & 0 deletions lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,18 @@ bool GatherUsesVisitor::visitUse(Operand *op) {
if (!leafRange)
return false;

// Now check if we have a destructure through deinit. If we do, emit an
// error.
unsigned numDiagnostics =
moveChecker.diagnosticEmitter.getDiagnosticCount();
checkForDestructureThroughDeinit(markedValue, op, *leafRange,
diagnosticEmitter);
if (numDiagnostics != moveChecker.diagnosticEmitter.getDiagnosticCount()) {
LLVM_DEBUG(llvm::dbgs()
<< "Emitting destructure through deinit error!\n");
return true;
}

LLVM_DEBUG(llvm::dbgs() << "Pure consuming use: " << *user);
useState.takeInsts.insert({user, *leafRange});
return true;
Expand Down
6 changes: 3 additions & 3 deletions test/CAS/loc-directive-diagnostics.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: not %target-swift-frontend -emit-module -emit-module-path %t/test.module \
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/test.module \
// RUN: -enable-cas -cas-path %t/cas -allow-unstable-cache-key-for-testing %s 2>&1 | %FileCheck %s
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/test.module -enable-cas -cas-path %t/cas \
Expand All @@ -9,7 +9,7 @@
// RUN: -allow-unstable-cache-key-for-testing %s 2>&1 | %FileCheck %s

#sourceLocation(file: "anything.swift", line: 1)
func 1() {}
#warning("this is a warning")
#sourceLocation()

// CHECK: anything.swift:1:6: error: function name
// CHECK: anything.swift:1:10: warning: this is a warning
4 changes: 2 additions & 2 deletions test/ClangImporter/pcm-emit-direct-cc1-mode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// CHECK-DUMP: Module map file: {{.*[/\\]}}Inputs{{/|\\}}custom-modules{{/|\\}}module.map

// Verify that the clang command-line used is cc1
// RUN: %FileCheck -check-prefix CHECK-CLANG %s < %t.diags.txt
// CHECK-CLANG: '{{.*[/\\]}}clang'{{.*}}'-fmodules'
// RUN: %FileCheck -check-prefix CHECK-CLANG -DTRIPLE=%target-triple %s < %t.diags.txt
// CHECK-CLANG: '{{.*[/\\]}}module.map' '-o' '{{.*[/\\]}}script.pcm' '-fmodules' '-triple' '[[TRIPLE]]' '-x' 'objective-c'

import script
var _ : ScriptTy
Loading