695 Commits

Author SHA1 Message Date
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Yuta Saito
c994500d82 [Driver] Use WebAssembly toolchain for WASI target
The toolchain was introduced in 710816d3e0
but was not used. Test cases now use fake resource dir to lookup
static-executable-args.lnk file, which is required by the toolchain but
is not present when not building stdlib for WASI.
2023-06-08 11:40:10 +00:00
Steven Wu
86927ef39c Merge pull request #65288 from cachemeifyoucan/eng/PR-swift-cache-backend
[CAS] Teach swift compiler to compute cache key and store outputs into CAS
2023-04-25 09:23:15 -07:00
Steven Wu
c153210505 [CAS] Add test case for cache key computation
Add tool swift-cache-tool for caching related testing and inspection.
2023-04-24 13:56:33 -07:00
Steven Wu
c7d66b8845 Teach swift to compute cache key for compiler outputs
Teach swift how to serialize its input into CAS to create a cache key
for compiler outputs. To compute the cache key for the output, it first
needs to compute a base-key for the compiler invocation. The base key is
computed from: swift compiler version and the command-line arguments for
the invocation.

Each compiler output from swift will gets its own key. The key for the
output is computed from: the base key for the compiler invocation + the
primary input for the output + the output type.
2023-04-24 13:55:38 -07:00
Erik Eckstein
e7af73e2de Replace the swift-llvm-opt binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:53:12 +02:00
Erik Eckstein
2b2bc45e08 Replace the swift-dependency-tool binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:51:04 +02:00
Erik Eckstein
8ce6038a42 Replace the sil-passpipeline-dumper binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:49:33 +02:00
Erik Eckstein
e3a174b85e Replace the sil-llvm-gen binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:48:23 +02:00
Erik Eckstein
bc7b632d3e Replace the sil-nm binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:47:13 +02:00
Erik Eckstein
b6132d10e5 Replace the sil-func-extractor binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:45:22 +02:00
Erik Eckstein
2e9c241034 Replace the sil-opt binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:44:04 +02:00
Saleem Abdulrasool
19c7bb5a22 Driver: add support for baremetal targets
This allows building the Swift standard library for targets which may
not have an actual OS running.  This is identified by the OS field in
the target triple being set to `none`.
2023-03-20 17:59:13 -04:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Robert Widmann
37e7052c68 Remove -emit-syntax and -verify-syntax-tree 2022-11-16 15:07:48 -08:00
Matt Jacobson
028fcd09cf driver: on FreeBSD, use lld, not gold
This is equivalent to passing `-use-ld=lld` to the driver.
2022-11-01 21:27:49 -04:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Artem Chikin
b1fee939f1 Add supplementary output path handling for extracted compile-time-known values 2022-07-19 16:24:26 -07:00
David Goldman
c232ed2913 Support hermetic indexing information
Swiftc port of https://github.com/apple/llvm-project/pull/4207.

This introduces a new flag, `-file-prefix-map` which can be used
instead of the existing `-debug-prefix-map` and `-coverage-prefix-map`
flags, and also remaps paths in index information currently.
2022-05-16 11:00:14 -04:00
Josh Soref
66d267e6ff Spelling driver (#42516)
* spelling: associated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: change

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declaration

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependents

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deterministically

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: embedded

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: exclude

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: filesystem

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: given

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: grained

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: incrementality

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: invoke

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: locals

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preexisting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: should

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: supplementary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: suppress

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-22 09:10:43 -07:00
Alex Lorenz
2e3aa87737 Revert "Revert "Merge pull request #41831 from hyp/unify-header""
This reverts commit 4c9582c295.
2022-03-19 13:36:28 -07:00
Alex Lorenz
4c9582c295 Revert "Merge pull request #41831 from hyp/unify-header"
This reverts commit cd93d23bac, reversing
changes made to f9f5476e9a.
2022-03-18 10:03:07 -07:00
Alex Lorenz
9d52099d5b [cxx-interop] start to emitting a unified header file for a Swift module
This change removes the -emit-cxx-header option, and adds a new -emit-clang-header-path option instead. It's aliased to -emit-objc-header-path for now, but in the future, -emit-objc-header-path will alias to it. After this change Swift can start emitting a single header file that can be expose declarations to C, Objective-C, or C++. For now C++ interface is generated (for all public decls) only when -enable-cxx-interop flag is passed, but that behavior will change once  attribute is supported.
2022-03-17 10:34:47 -07:00
Alex Lorenz
683224acd4 Revert "Separate the C++ and Objective-C generated header output types."
This reverts commit c7a5049a28.
2022-03-15 17:00:51 -07:00
Jacob Clayden
e05fa1893e Add missing newline character in Driver.cpp 2022-01-31 00:07:37 +00:00
Doug Gregor
c7a5049a28 Separate the C++ and Objective-C generated header output types.
Otherwise, when an output file map is provided, we'll use the same
path for both. Fixes rdar://87987062.
2022-01-25 22:53:03 -08:00
swift-ci
a496a9490a Merge remote-tracking branch 'origin/main' into rebranch 2021-12-16 08:39:25 -08:00
Xi Ge
28eef324d0 Frontend: support emitting ABI descriptor when specifying the path in supplementary output map. rdar://86559811 2021-12-15 22:42:15 -08:00
Ben Barham
22b91621d7 [rebranch] Immediately release OptTable parsed argument
I had missed that `A` was used after `Args->append`. Just release the
`unique_ptr` straight away and use it in the rest of the function.
2021-11-17 13:08:54 +10:00
Ben Barham
edfe2cb4cc [rebranch] OptTable::ParseOneArg now returns a std::unique_ptr 2021-11-13 17:04:29 +10:00
Kuba (Brecka) Mracek
94f23942db Add a -experimental-hermetic-seal-at-link flag that triggers aggressive LTO-based dead-stripping (VFE, WME, conditional runtime records, internalization) (#39793) 2021-10-20 07:30:43 -07:00
swift-ci
18ae4b937b Merge remote-tracking branch 'origin/main' into rebranch 2021-08-19 21:13:14 -07:00
Kuba (Brecka) Mracek
8cf6c2e71b [Driver] -c with LTO should still emit bitcode (#35026) 2021-08-19 21:05:35 -07:00
swift-ci
53147b2ccb Merge remote-tracking branch 'origin/main' into rebranch 2021-08-06 14:13:40 -07:00
Artem Chikin
9429136112 [Dependency Scanning] Split the ModuleDependencyCache into two: current scan cache & global.
This change causes the cache to be layered with a local "cache" that wraps the global cache, which will serve as the source of truth. The local cache persists only for the duration of a given scanning action, and has a store of references to dependencies resolved as a part of the current scanning action only, while the global cache is the one that persists across scanning actions (e.g. in `DependencyScanningTool`) and stores actual module dependency info values.

Only the local cache can answer dependency lookup queries, checking current scanning action results first, before falling back to querying the global cache, with queries disambiguated by the current scannning action's search paths, ensuring we never resolve a dependency lookup query with a module info that could not be found in the current action's search paths.

This change is required because search-path disambiguation can lead to false-negatives: for example, the Clang dependency scanner may find modules relative to the compiler's path that are not on the compiler's direct search paths. While such false-negative query responses should be functionally safe, we rely on the current scanning action's results being always-present-in-the-cache for the scanner's functionality. This layering ensures that the cache use-sites remain unchanged and that we get both: preserved global state which can be queried disambiguated with the search path details, and an always-consistent local (current action) cache state.
2021-08-06 09:13:42 -07:00
swift-ci
078613b15d Merge remote-tracking branch 'origin/main' into rebranch 2021-07-14 20:54:49 -07:00
Evan Wilde
685ebd4660 Fix PrintName calls
OptTable::PrintName was renamed 'printName' in commit f1e2d5851bf86.
2021-07-08 16:42:34 -07:00
Jeremy Legendre
35735e7d0c [LTO] Driver support for -lto_library flag
This commit adds support for the -lto_library flag, allowing users to specify a custom LTO library on Darwin. This also fixes an issue where the default LTO library is used even if Driver is run from inside an alternate toolchain.
2021-07-05 18:01:40 -04:00
Evan Wilde
9bd93db2be Update all the APInt toStrings
Just went through and updated the rest of the APInt toString calls.
This should take care of them, I hope.
2021-06-25 10:44:13 -07:00
Artem Chikin
23fcb4944b Merge pull request #37585 from artemcm/SerializeModuleDepCache
[Dependency Scanning] Add a binary serialization format for the Inter-Module Dependencies Cache
2021-06-01 13:13:53 -07:00
Robert Widmann
f6b2294d5a Undo Force Load + Incremental Ban on Darwin Platforms
Gather 'round to hear tell of the saga of autolinking in incremental
mode.

In the beginning, there was Swift code, and there was Objective-C code.
To make one import bind two languages, a twinned Swift module named the same as an
Objective-C module could be imported as an overlay. But all was not
well, for an overlay could be created which had no Swift content, yet
required Swift symbols. And there was much wailing and gnashing of teeth
as loaders everywhere disregarded loading these content-less Swift
libraries.

So, a solution was found - a magical symbol _swift_FORCE_LOAD_$_<MODULE>
that forced the loaders to heed the dependency on a Swift library
regardless of its content. It was a constant with common linkage, and it
was good. But, along came COFF which needed to support autolinking but
had no support for such matters. It did, however, have support for
COMDAT sections into which we placed the symbol. Immediately, a darkness
fell across the land as the windows linker loudly proclaimed it had
discovered a contradiction: "_swift_FORCE_LOAD_$_<MODULE> cannot be
a constant!", it said, gratingly, "for this value requires rebasing."
Undeterred, we switched to a function instead, and the windows linker
happily added a level of indirection to its symbol resolution procedure
and all was right with the world.

But this definition was not all right. In order to support multiple
translation units emitting it, and to prevent the linker from dead
stripping it, Weak ODR linkage was used. Weak ODR linkage has the nasty
side effect of pessimizing load times since the dynamic linker must
assume that loading a later library could produce a more definitive
definition for the symbol.

A compromise was drawn up: To keep load times low, external linkage was
used. To keep the linker from complaining about multiple strong
definitions for the same symbol, the first translation unit in the
module was nominated to recieve the magic symbol. But one final problem
remained:

Incremental builds allow for files to be added or removed during the
build procedure. The placement of the symbol was therefore dependent
entirely upon the order of files passed at the command line. This was no
good, so a decree was set forth that using -autolink-force-load and
-incremental together was a criminal offense.

So we must compromise once more: Return to a symbol with common linkage,
but only on Mach-O targets. Preserve the existing COMDAT-friendly
approach everywhere else.

This concludes our tale.

rdar://77803299
2021-05-24 15:53:13 -07:00
Artem Chikin
14229f13b0 [Dependency Scanning] Add a binary serialization format for the Inter-Module Dependencies Cache
- Adds serialization format based on the LLVM Bitcode File Format (https://llvm.org/docs/BitCodeFormat.html).
- Adds Serialization and Deserialization code.
2021-05-21 14:31:00 -07:00
Alex Hoppen
285cea4670 Merge pull request #37512 from ahoppen/pr/allow-driver-errors
[SourceKit] Recover if compiler arguments have errors
2021-05-21 09:17:01 +02:00
Saleem Abdulrasool
1f11627f09 Driver: do not generate a dSYM bundle for static archives
When building a static library with debug information, do not create a
dSYM generation job as it cannot be executed on a non-image target.
This is important for the case where the single invocation is both the
compile and link job.

This was detected in conjunction with @gottesmm.
2021-05-20 11:09:03 -07:00
Alex Hoppen
44f8e195ef [SourceKit] Recover if compiler arguments have errors
If the compiler arguments have errors in them (e.g. because a file with the same name is used twice), we can often still fulfill SourceKit requests because the compiler argument errors are only relevant for later stages of the compilation process.

Instead of bailing out early, do a best effor retrieving the compiler arguments that are valid and ignoring the errors.

Fixes rdar://77618144
2021-05-19 22:31:15 +02:00
QuietMisdreavus
419483863f Revert "[Driver][Frontend] add the symbol graph dir to the supplementary file map" 2021-04-22 12:20:14 -06:00
Varun Gandhi
cc14992281 [Frontend] Add -emit-irgen option to driver and frontend.
Fixes SR-14389, fixes rdar://75715690.
2021-03-31 11:56:36 -07:00
Victoria Mitchell
d6b071d367 don't use braces for single-line if-blocks 2021-03-24 09:48:13 -05:00
Victoria Mitchell
97a4cba250 add the symbol graph dir to the supplementary file map
rdar://75582169
2021-03-24 09:44:23 -05:00