The `projection` flag indicates that `index_addr` projects an element address from an array base address, as opposed to being used for general pointer arithmetic.
When this flag is set, the result address can only reach the single element at the given index — it is not possible to chain multiple `index_addr` instructions to reach other array elements from the result.
Without this flag, the result may be used as the base of another `index_addr`, allowing arithmetic across element boundaries (e.g. an `index_addr` with index 1 followed by an `index_addr` with index 2 reaches the element at offset 3).
An `index_addr [projection]` is mandatory to go from an array base address to an element - even if it's the first element, i.e. the index is zero.
This means that the optimizer must not remove `index_addr [projection]` with a zero index.
Remove the now unused SILBuilder::createDebugValueAddr function. Passes
must always update existing debug value instructions rather than
recreating new ones, and emitDebugDescription has been updated to just
prepend an op_deref. This was the last remnant of DebugValueAddrInst.
Since salvageDebugInfo now uses debug reconstruction basic blocks,
the plus, minus, and constant SILDebugInfoExpression operators were
left unused. This commit removes them, and updates some of their tests
to use debug basic blocks.
Assisted-by: Claude
Add a new --enable-caching option that enables compilation caching for both
C/C++ (via clang-cache as compiler launcher) and Swift code (via
-cache-compile-job flags when bootstrapping=hosttools).
New options:
- --enable-caching: main toggle, incompatible with --sccache/--distcc
- --caching-cas-path: CAS directory (default: $BUILD_ROOT/cas)
- --caching-depscan-socket: depscan daemon socket path
- --caching-plugin-path: CAS plugin library path
- --caching-plugin-option: CAS plugin options (repeatable)
- --caching-prefix-map: enable source/SDK/toolchain prefix mapping
- --caching-remote-service-path: remote caching service with auto
plugin inference from Xcode and implied prefix mapping
The build script starts a clang-cache depscan daemon with reliable cleanup
via atexit and SIGTERM handlers. Per-product build directories get .cas-config
and compilation-prefix-map.json files written automatically.
Caching flags are applied to all Swift host compilation targets: compiler
sources, pure-swift host libraries (ASTGen, macros), swift-syntax, and
the new runtime build when --build-runtime-with-host-compiler is used.
When not using --caching-remote-service-path, enables CAS backend
(-Xfrontend -cas-backend -Xllvm -cas-friendly-debug-info) unless
SWIFT_CACHE_DISABLE_MCCAS is set.
A ninja wrapper is generated at build/<subdir>/build-utils/ninja for
cached incremental builds outside the build-script.
rdar://155876033
Assisted-By: Claude
Explanation: Documentation for WebAssembly: adjust WASI stdlib test execution command. Add `swift-*/bin` to `PATH`, since WASI tests require `sil-opt`.
Scope: documentation only
Risk: no risk, just updating documentation
Testing: Executed WASI stdlib tests locally on Ubuntu.
We cannot use spare bits or other overlapping storage layout tricks with fundamentally
address-only enums, and we can take advantage of this to do borrowing switches or other
in-place projections without copying the value. However, for resilient enums, the
implementation may use spare bit packing, but the type must be handled address-only
outside of its defining module, and we didn't have a way to express that with
borrowing switch. Optimization passes have also been running into problems with the
complexity that we were using `unchecked_take_enum_data_addr` sometimes as a pure
operation. This patch splits the instruction into three:
- `unchecked_inplace_enum_data_addr` represents a nondestructive in-place enum
projection. It is only allowed for enums whose projection operation is
nondestructive.
- `unchecked_take_enum_data_addr` represents a destructive enum projection,
invalidating the enum and leaving the payload to be further consumed.
This matches the current instruction's semantics.
- `unchecked_borrow_enum_data_addr` represents a borrowing enum projection.
The instruction takes a second operand for "scratch" space, which the
enum representation may be copied into in order to avoid invalidating the
enum value, so the result is dependent on the lifetime of both the
original enum and the scratch buffer. This allows for borrowing switches
over resilient enums.
`unchecked_borrow_enum_data_addr` is implemented by taking advantage of the
"address-only enums can't do spare bit optimization" property at runtime.
We inspect the operand type's bitwise-borrowability from its metadata. If
the type is bitwise-borrowable, then we are allowed to bitwise-copy the
enum to the scratch space and apply the projection to the scratch space,
preserving the original value. If the type is not bitwise-borrowable, then
we cannot use spare bit optimization in its layout, so we apply the
projection in-place.
Fixes rdar://174952822.
Ordinary base protocols use fixed-indexing to access the base index.
That means adding another base protocol to an existing protocol
can break the order of the entries, and thus clients, because we
otherwise order the base entires with TypeDecl::compare.
Reparentable protocols are meant to be resilient to that, so we
order them at the end of the base entries list, just before the
other resilient entries in the witness table.
This patch completes the picture, by having the reparentable
protocol entries be indexed resiliently, in the same manner as
associated conformances.
The difference is that we can skip the call to
`swift_getAssociatedConformanceWitness`
and compute the index directly by finding the distance of the
descriptors, because we know all base protocol witness table
entries are eagarly instantiated.
Using this distance protects us from the ordering problems
of entries among all of the reparentable base protocols.
resolves rdar://173409851
With this option enabled the DiagnosticVerifier enforces a strict child
note hierarchy: if a note has a parent diagnostic (which it should), it
can only be matched by an expected-note matcher in the {{children:}}
block of the matcher of its parent diagnostic. This makes it clear when
reviewing which note belongs to which diagnostic, and lets
update-verify-tests keep that structure (support in update-verify-tests
not yet added). If the note is far away from the parent it can be
matched with a line marker (#foo on the line of the emitted note).
Without this option enabled (default behavior) {{children:}} blocks are
an error.
Additionally, change the verification error sort order to use buffer
ID as the primary key (address within buffer as secondary), so that
error output is stable across source files in multi-file compilations.
Disambiguation for future Emscripten support.
`grep -riI --exclude-dir=".git" "wasmstd" .`
and
`grep -riI --exclude-dir=".git" "wasm-std" .`
both did not find anything after these changes.
The `@export(interface)` and `@export(implementation)` attributes
SE-0497 are queried directly on AST nodes in several places within the
SIL pipeline. However, they don't persist when SIL functions are
serialized, meaning that clients of the original module might make
different assumptions about the availability of a given function's
definition.
Represent these attributes in a SIL function (as an optional
CodeGenerationModel), (de-)serialize them into the module, and add a
textual representation as SIL function attributes `[export_interface]`
and `[export_implementation]`.
Previously, it was possible to specify different debug formats for C/C++
and Swift code. In practice, binaries with both C/C++ and Swift code
would end up only having one format over the other, depending on the
exact project configuration. Since there is little value in having
separate debug information format, this changes the build configuration
to only have one debug format for both C/C++ and Swift code.
This also changes the default debug format to codeview. This is because
some of the toolchain binaries now exceed 4 GiB of dwarf debug
information, resulting in a build failure.
Conformance entries are used for fast conformance lookup, which doesn't need to query the runtime's conformance lookup table.
A conformance entry specifies if the class conforms or does not conform to a protocol.
At runtime, a type cast instruction to an existential can directly load the witness table pointer from the VTable.
If null, the class does not conform to the protocol.
Adjust compile command for building WebAssembly without building the
toolchain beforehand.
---------
Co-authored-by: Max Desiatov <m_desiatov@apple.com>
Add support for named location markers in the diagnostic verifier's
-verify mode. A marker is defined by placing `// #name` in a comment
and referenced with `@#name` in expected-diagnostic comments.
This enables stable references to diagnostic locations that don't break
when lines are added or removed, and supports cross-file references
where an expected-error in one file references a marker in another.
Also update to latest download URL, require a prebuilt compiler, and
remove a now unneeded bootstrapping flag.
These are flags I regularly use to build and test a trunk toolchain on
macOS, linux, and natively on Android, as can be seen in [step 4 of this
forum
post](https://forums.swift.org/t/building-a-linux-aarch64-toolchain-on-macos-with-containerization/84347),
though I left off the internal testing flags here.
Add an option so that when the backtracer starts in a crashing process
it will close all unnecessary file descriptors before it tries to start
gathering the backtrace as that may take time.
rdar://144402533
- Replace "Please feel free to add..." with professional contributor
guidance
- Replace "Well, this is not quite true..." aside with a clear note
about -Onone behavior
- Fix "When using swift LLDB REPL" to "When using the Swift REPL"
- Rewrite first-person informal narration in the LSAN section to
objective voice
Convert all 4-space-indented code blocks to fenced code blocks with
appropriate language tags:
- ```sh for shell commands
- ```lldb for LLDB sessions
- ```vim for vim configuration
- Plain ``` for output/logs and other content
This improves readability and enables syntax highlighting in
Markdown renderers.