Skip to content

Commit 9929926

Browse files
authored
Merge pull request #4235 from swiftwasm/main
2 parents 6eb688a + 3d4953c commit 9929926

File tree

192 files changed

+3618
-2392
lines changed

Some content is hidden

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

192 files changed

+3618
-2392
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ option(SWIFT_SIL_VERIFY_ALL
363363
"Run SIL verification after each transform when building Swift files in the build process"
364364
FALSE)
365365

366+
option(SWIFT_SIL_VERIFY_ALL_MACOS_ONLY
367+
"Run SIL verification after each transform when building the macOS stdlib"
368+
FALSE)
369+
366370
option(SWIFT_EMIT_SORTED_SIL_OUTPUT
367371
"Sort SIL output by name to enable diffing of output"
368372
FALSE)

cmake/modules/SwiftComponents.cmake

Lines changed: 3 additions & 1 deletion
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.

docs/DebuggingTheCompiler.md

Lines changed: 25 additions & 33 deletions
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

Lines changed: 10 additions & 0 deletions
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/SIL.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,69 @@ The current list of interior pointer SIL instructions are:
23642364
(*) We still need to finish adding support for project_box, but all other
23652365
interior pointers are guarded already.
23662366

2367+
Variable Lifetimes
2368+
~~~~~~~~~~~~~~~~~~
2369+
2370+
In order for programmer intended lifetimes to be maintained under optimization,
2371+
the lifetimes of SIL values which correspond to named source-level values can
2372+
only be modified in limited ways. Generally, the behavior is that the lifetime
2373+
of a named source-level value cannot _observably_ end before the end of the
2374+
lexical scope in which that value is defined. Specifically, code motion may
2375+
not move the ends of these lifetimes across a **deinit barrier**.
2376+
2377+
A few sorts of SIL value have lifetimes that are constrained that way:
2378+
2379+
1: `begin_borrow [lexical]`
2380+
2: `move_value [lexical]`
2381+
3: @owned function arguments
2382+
4: `alloc_stack [lexical]`
2383+
2384+
That these three have constrained lifetimes is encoded in ValueBase::isLexical,
2385+
which should be checked before changing the lifetime of a value.
2386+
2387+
The reason that only @owned function arguments are constrained is that a
2388+
@guaranteed function argument is guaranteed by the function's caller to live for
2389+
the full duration of the function already. Optimization of the function alone
2390+
can't shorten it. When such a function is inlined into its caller, though, a
2391+
lexical borrow scope is added for each of its @guaranteed arguments, ensuring
2392+
that the lifetime of the corresponding source-level value is not shortened in a
2393+
way that doesn't respect deinit barriers.
2394+
2395+
Unlike the other sorts, `alloc_stack [lexical]` isn't a SILValue. Instead, it
2396+
constrains the lifetime of an addressable variable. Since the constraint is
2397+
applied to the in-memory representation, no additional lexical SILValue is
2398+
required.
2399+
2400+
Deinit Barriers
2401+
```````````````
2402+
2403+
Deinit barriers (see swift::isDeinitBarrier) are instructions which would be
2404+
affected by the side effects of deinitializers. To maintain the order of
2405+
effects that is visible to the programmer, destroys of lexical values cannot be
2406+
reordered with respect to them. There are three kinds:
2407+
2408+
1. synchronization points (locks, memory barriers, syscalls, etc.)
2409+
2. loads of weak or unowned values
2410+
3. accesses of pointers
2411+
2412+
Examples:
2413+
2414+
1. Given an instance of a class which owns a file handle and closes the file
2415+
handle on deinit, writing to the file handle and then deallocating the
2416+
instance would result in changes being written. If the destroy of the
2417+
instance were hoisted above the call to write to the file handle, an error
2418+
would be raised instead.
2419+
2. Given an instance `c` of a class `C` which weakly references an instance `d`
2420+
of a second class `D`, if `d` is referenced via a local variable `v`, then
2421+
loading that weak reference from `c` within the variable scope should return
2422+
a non-nil reference to `d`. Hoisting the destroy of `v` above the weak load
2423+
from `c`, however, would result in the destruction of `d` before that load
2424+
and a nil weak reference to `D`.
2425+
3. Given an instance of a class which owns a buffer and deallocates it on
2426+
deinitialization, accessing the pointer and then deallocating the instance
2427+
is defined behavior. Hoisting the destroy of the instance above the access
2428+
to the memory would result in accessing a freed pointer.
2429+
23672430
Memory Lifetime
23682431
~~~~~~~~~~~~~~~
23692432

Lines changed: 35 additions & 0 deletions
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

Lines changed: 0 additions & 77 deletions
This file was deleted.

include/swift-c/DependencyScan/CommonString.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 10 additions & 6 deletions
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)