Skip to content

Commit fe070c8

Browse files
authored
Merge branch 'main' into tbkka-remoteMirror-MPE-spareBits-v2
2 parents b5d31d0 + 46bfbde commit fe070c8

File tree

359 files changed

+12322
-4592
lines changed

Some content is hidden

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

359 files changed

+12322
-4592
lines changed

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
192192
option only affects the tools that run on the host (the compiler), and has
193193
no effect on the target libraries (the standard library and the runtime).")
194194

195+
option(SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS
196+
"When building ThinLTO using ld64 on Darwin, controls whether to opt out of
197+
LLVM IR optimizations when linking targets that will get
198+
little benefit from it (e.g. tools for bootstrapping or
199+
debugging Swift)"
200+
FALSE)
201+
195202
option(BOOTSTRAPPING_MODE [=[
196203
How to build the swift compiler modules. Possible values are
197204
OFF: build without swift modules

cmake/modules/AddSwift.cmake

+14-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ macro(add_swift_lib_subdirectory name)
636636
endmacro()
637637

638638
function(add_swift_host_tool executable)
639-
set(options HAS_SWIFT_MODULES)
639+
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
640640
set(single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
641641
set(multiple_parameter_options LLVM_LINK_COMPONENTS)
642642

@@ -859,6 +859,19 @@ function(add_swift_host_tool executable)
859859
endif()
860860
endif()
861861

862+
if(ASHT_THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
863+
string(CONCAT lto_codegen_only_link_options
864+
"$<"
865+
"$<AND:"
866+
"$<BOOL:${LLVM_LINKER_IS_LD64}>,"
867+
"$<BOOL:${SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS}>,"
868+
"$<STREQUAL:${SWIFT_TOOLS_ENABLE_LTO},thin>"
869+
">:"
870+
"LINKER:-flto-codegen-only"
871+
">")
872+
target_link_options(${executable} PRIVATE "${lto_codegen_only_link_options}")
873+
endif()
874+
862875
if(NOT ${ASHT_SWIFT_COMPONENT} STREQUAL "no_component")
863876
add_dependencies(${ASHT_SWIFT_COMPONENT} ${executable})
864877
swift_install_in_component(TARGETS ${executable}

cmake/modules/SwiftComponents.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@
6464
# Swift code.
6565
# * toolchain-tools -- a subset of tools that we will install to the OSS toolchain.
6666
# * testsuite-tools -- extra tools required to run the Swift testsuite.
67+
# * parser-lib -- Build the syntax parser library used by SwiftSyntax.
68+
# * static-mirror-lib -- Build the static mirror library used by SwiftStaticMirror.
6769
# * toolchain-dev-tools -- install development tools useful in a shared toolchain
6870
# * llvm-toolchain-dev-tools -- install LLVM development tools useful in a shared toolchain
6971
# * dev -- headers and libraries required to use Swift compiler as a library.
7072
set(_SWIFT_DEFINED_COMPONENTS
71-
"autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;parser-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;llvm-toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
73+
"autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;parser-lib;static-mirror-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;llvm-toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
7274

7375
# The default install components include all of the defined components, except
7476
# for the following exceptions.

cmake/modules/UnixCompileRules.cmake

+17
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,20 @@ set(CMAKE_C_ARCHIVE_FINISH "")
1111
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <LINK_FLAGS> <OBJECTS>")
1212
set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qs <TARGET> <LINK_FLAGS> <OBJECTS>")
1313
set(CMAKE_CXX_ARCHIVE_FINISH "")
14+
15+
# When archiving LTO-based .o files with ar/ranlib/libtool on Darwin, the tools
16+
# use libLTO.dylib to inspect the bitcode files. However, by default the
17+
# "host" libLTO.dylib is loaded, which might be too old and not understand our
18+
# just-built bitcode format. So let's instead ask ar/ranlib/libtool to use the
19+
# just-built libLTO.dylib from the toolchain that we're using to build.
20+
if(APPLE AND SWIFT_NATIVE_CLANG_TOOLS_PATH)
21+
set(liblto_path "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/../lib/libLTO.dylib")
22+
23+
set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_COMMAND} -E env LIBLTO_PATH=${liblto_path} <CMAKE_AR> crs <TARGET> <LINK_FLAGS> <OBJECTS>")
24+
set(CMAKE_C_ARCHIVE_APPEND "${CMAKE_COMMAND} -E env LIBLTO_PATH=${liblto_path} <CMAKE_AR> qs <TARGET> <LINK_FLAGS> <OBJECTS>")
25+
set(CMAKE_C_ARCHIVE_FINISH "")
26+
27+
set(CMAKE_CXX_ARCHIVE_CREATE "${CMAKE_COMMAND} -E env LIBLTO_PATH=${liblto_path} <CMAKE_AR> crs <TARGET> <LINK_FLAGS> <OBJECTS>")
28+
set(CMAKE_CXX_ARCHIVE_APPEND "${CMAKE_COMMAND} -E env LIBLTO_PATH=${liblto_path} <CMAKE_AR> qs <TARGET> <LINK_FLAGS> <OBJECTS>")
29+
set(CMAKE_CXX_ARCHIVE_FINISH "")
30+
endif()

docs/DebuggingTheCompiler.md

+25-33
Original file line numberDiff line numberDiff line change
@@ -714,39 +714,31 @@ which causes the miscompile.
714714
Currently there is no tool to automatically identify the bad optimization, but
715715
it's quite easy to do this manually:
716716

717-
1. Find the offending optimization with bisecting:
718-
719-
a. Add the compiler option `-Xllvm -sil-opt-pass-count=<n>`, where `<n>`
720-
is the number of optimizations to run.
721-
722-
b. Bisect: find n where the executable crashes, but does not crash
723-
with n-1. First just try n = 10, 100, 1000, 10000, etc. to find
724-
an upper bound). Then can either bisect the invocation by hand or
725-
place the invocation into a script and use
726-
`./llvm-project/llvm/utils/bisect` to automatically bisect
727-
based on the scripts error code. Example invocation:
728-
729-
bisect --start=0 --end=10000 ./invoke_swift_passing_N.sh "%(count)s"
730-
731-
c. Once one finds `n`, Add another option `-Xllvm -sil-print-pass-name`. The output can be
732-
large, so it's best to redirect stderr to a file (`2> output`).
733-
In the output search for the last pass before `stage Address Lowering`.
734-
It should be the `Run #<n-1>`. This line tells you the name of the bad
735-
optimization pass and on which function it run.
736-
737-
2. Get the SIL before and after the bad optimization.
738-
739-
a. Add the compiler option
740-
`-Xllvm -sil-print-function='<function>'`
741-
where `<function>` is the function name (including the preceding `$`).
742-
For example:
743-
`-Xllvm -sil-print-function='$s4test6testityS2iF'`.
744-
Again, the output can be large, so it's best to redirect stderr to a file.
745-
b. From the output, copy the SIL of the function *before* the bad
746-
run into a separate file and the SIL *after* the bad run into a file.
747-
c. Compare both SIL files and try to figure out what the optimization pass
748-
did wrong. To simplify the comparison, it's sometimes helpful to replace
749-
all SIL values (e.g. `%27`) with a constant string (e.g. `%x`).
717+
1. Add the compiler option `-Xllvm -sil-opt-pass-count=<n>`, where `<n>`
718+
is the number of optimizations to run.
719+
720+
2. Bisect: find n where the executable crashes, but does not crash
721+
with n-1. First just try n = 10, 100, 1000, 10000, etc. to find
722+
an upper bound). Then can either bisect the invocation by hand or
723+
place the invocation into a script and use
724+
`./llvm-project/llvm/utils/bisect` to automatically bisect
725+
based on the scripts error code. Example invocation:
726+
727+
bisect --start=0 --end=10000 ./invoke_swift_passing_N.sh "%(count)s"
728+
729+
3. Add another option `-Xllvm -sil-print-last`. The output can be
730+
large, so it's best to redirect stderr to a file (`2> output`).
731+
The output contains the SIL before and after the bad optimization.
732+
733+
4. Copy the two functions from the output into separate files and
734+
compare both files. Try to figure out what the optimization pass
735+
did wrong. To simplify the comparison, it's sometimes helpful to replace
736+
all SIL values (e.g. `%27`) with a constant string (e.g. `%x`).
737+
738+
5. If the bad optimization is SILCombine or SimplifyCFG (which do a lot of
739+
transformations in a single run) it's helpful to continue bisecting on
740+
the sub-pass number. The option `-Xllvm -sil-opt-pass-count=<n>.<m>`
741+
can be used for that, where `m` is the sub-pass number.
750742

751743
### Using git-bisect in the presence of branch forwarding/feature branches
752744

docs/Lexicon.md

+10
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,16 @@ of `Optional<Int>`.) Sugared types preserve information about the form
594594
and use of the type even though the behavior usually does not change
595595
(except for things like access control). Contrast with [canonical type](#canonical-type).
596596

597+
## TBD
598+
599+
Text-based dynamic library files (TBDs) are a textual representation of
600+
the information in a dynamic library / shared library that is required
601+
by the static linker.
602+
603+
Apple’s SDKs originally used Mach-O Dynamic Library Stubs. Mach-O Dynamic
604+
Library Stubs are dynamic library files, but with all the text and data
605+
stripped out.
606+
597607
## thunk
598608

599609
In the Swift compiler, a synthesized function whose only purpose is to

docs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ documentation, please create a thread on the Swift forums under the
102102
- [DependencyAnalysis.md](/docs/DependencyAnalysis.md):
103103
Describes different kinds of dependencies across files in the same module,
104104
important for understanding incremental builds.
105+
- [DifferentiableProgrammingImplementation.md](/docs/DifferentiableProgrammingImplementation.md):
106+
Describes how automatic differentiation is implemented in the Swift compiler.
105107
- C and ObjC interoperability: Clang Importer and PrintAsClang
106108
- [CToSwiftNameTranslation.md](/docs/CToSwiftNameTranslation.md):
107109
Describes how C and ObjC entities are imported into Swift

docs/ReferenceGuides/UnderscoredAttributes.md

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ Most notably, default argument expressions are implicitly
3939
`@_alwaysEmitIntoClient`, which means that adding a default argument to a
4040
function which did not have one previously does not break ABI.
4141

42+
## `@_backDeploy(availabilitySpec ...)`
43+
44+
Causes the body of a function to be emitted into the module interface to be
45+
available for inlining in clients with deployment targets lower than the formal
46+
availability of the function. When inlined, the body of the function is
47+
transformed such that it calls the library's copy of the function if it is
48+
available at runtime. Otherwise, the copy of the original function body is
49+
executed.
50+
4251
## `@_assemblyVision`
4352

4453
Forces emission of assembly vision remarks for a function or method, showing

docs/SIL.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ called a "forwarding instruction" and any use with such a user instruction a
20652065
"forwarding use". This inference generally occurs upon instruction construction
20662066
and as a result:
20672067

2068-
* When manipulating forwarding instructions programatically, one must manually
2068+
* When manipulating forwarding instructions programmatically, one must manually
20692069
update their forwarded ownership since most of the time the ownership is
20702070
stored in the instruction itself. Don't worry though because the SIL verifier
20712071
will catch this error for you if you forget to do so!
@@ -2075,7 +2075,7 @@ and as a result:
20752075
parsed operand.
20762076
In some cases the forwarding ownership kind is different from the ownership kind
20772077
of its operand. In such cases, textual SIL represents the forwarding ownership kind
2078-
explicity.
2078+
explicitly.
20792079
Eg: ::
20802080

20812081
%cast = unchecked_ref_cast %val : $Klass to $Optional<Klass>, forwarding: @unowned
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--- CommonString.h - C API for Swift Dependency Scanning ---*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_C_LIB_SWIFT_COMMON_STRING_H
14+
#define SWIFT_C_LIB_SWIFT_COMMON_STRING_H
15+
16+
#include <stdbool.h>
17+
#include <stddef.h>
18+
#include <stdint.h>
19+
20+
/**
21+
* A character string used to pass around dependency scan result metadata.
22+
* Lifetime of the string is strictly tied to the object whose field it
23+
* represents. When the owning object is released, string memory is freed.
24+
*/
25+
typedef struct {
26+
const void *data;
27+
size_t length;
28+
} swiftscan_string_ref_t;
29+
30+
typedef struct {
31+
swiftscan_string_ref_t *strings;
32+
size_t count;
33+
} swiftscan_string_set_t;
34+
35+
#endif // SWIFT_C_LIB_SWIFT_COMMON_STRING_H

include/swift-c/DependencyScan/BinaryScan.h

-77
This file was deleted.

include/swift-c/DependencyScan/CommonString.h

-41
This file was deleted.

include/swift-c/DependencyScan/DependencyScan.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@
1515
//
1616
//===----------------------------------------------------------------------===//
1717

18-
#include "DependencyScanMacros.h"
19-
#include "CommonString.h"
20-
2118
#ifndef SWIFT_C_DEPENDENCY_SCAN_H
2219
#define SWIFT_C_DEPENDENCY_SCAN_H
2320

21+
#include "DependencyScanMacros.h"
22+
#include "swift-c/CommonString/CommonString.h"
23+
24+
/// The version constants for the SwiftDependencyScan C API.
25+
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
26+
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
27+
#define SWIFTSCAN_VERSION_MAJOR 0
28+
#define SWIFTSCAN_VERSION_MINOR 2
29+
2430
SWIFTSCAN_BEGIN_DECLS
2531

26-
//=== Public Dependency Scanner Data Types -------------------------------===//
32+
//=== Public Scanner Data Types -------------------------------------------===//
2733

2834
typedef enum {
2935
// This dependency info encodes two ModuleDependencyKind types:
@@ -345,8 +351,6 @@ swiftscan_scanner_cache_load(swiftscan_scanner_t scanner,
345351
SWIFTSCAN_PUBLIC void
346352
swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
347353

348-
//=== Experimental compiler invocation operations -------------------------===//
349-
350354
/// An entry point to invoke the compiler via a library call.
351355
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);
352356

0 commit comments

Comments
 (0)