Commit Graph

1457 Commits

Author SHA1 Message Date
Evan Wilde
bb2fe7e4ec Add missing compat libraries to bootstrapping
The bootstrapping stages were missing dependencies on the Concurrency
and Swift 5.6 backdeployment compatibility libraries resulting in
failing builds.
2022-08-08 17:08:40 -07:00
Alex Hoppen
c096c7e975 [CMake] Use CMAKE_CURRENT_SOURCE_DIR as base for includes in SwiftCompilerSources
When using a unified LLVM + Swift build (using `LLVM_EXTERNAL_PROJECTS=swift`),
`CMAKE_SOURCE_DIR` is `llvm-project/llvm`, and appending `include/swift` to that directory doesn’t result in the directory that contains Swift’s header files.

Instead, look up the header files relative to `CMAKE_CURRENT_SOURCE_DIR`.
2022-08-02 22:08:11 +02:00
Erik Eckstein
e796fc8680 cmake: add a hack to get correct dependencies from C++ header files -> Swift compiler sources 2022-07-29 10:55:13 +02:00
Egor Zhdan
0e2d438c5b [cxx-interop][SwiftCompilerSources] Use llvm::StringRef instead of BridgedStringRef
rdar://83361000
2022-07-21 16:32:16 +01:00
eeckstein
d1220fd4f7 Merge pull request #60072 from eeckstein/walkers-in-release-devirtualizer
Some improvements in WalkUtils and use the ValueUseDefWalker in the ReleaseDevirtualizer pass
2022-07-20 16:14:01 +02:00
Alex Hoppen
d68aa2d89e Merge pull request #60091 from ahoppen/pr/current-binary-dir-for-tooling-libs
[CMake] Use CMAKE_CURRENT_BINARY_DIR as base for generated C header for SwiftCompilerSources
2022-07-20 14:07:11 +02:00
Erik Eckstein
872ded9341 ReleaseDevirtualizer: use the ValueUseDefWalker instead of the manual use-def walking implementation 2022-07-20 13:50:18 +02:00
Erik Eckstein
b52297bb79 Swift SIL: some improvements for WalkUtils and EscapeInfo
* "merge" the `Path` and `State` in WalkUtils into a single `WalkingPath`. This makes it simpler for clients to configure a path and additional state variables. EscapeInfo now defines `EscapePath` which includes the projection path and EscapeInfo's specific state variables.
* Make the `WalkerCache` part of the WalkUtils, so that not all clients have to re-implement it.
* Rename `walkDownResults` -> `walkDownAllResults` and `walkUpOperands` -> `walkUpAllOperands` and make these functions client configurable.
2022-07-20 13:50:18 +02:00
zoecarver
12933bf3b4 Mark a few API uses in Swift Compiler Sources as unsafe. 2022-07-18 20:06:43 -04:00
Alex Hoppen
259c1b7148 [CMake] Use CMAKE_CURRENT_BINARY_DIR as base for generated C header for SwiftCompilerSources
When using a unified LLVM + Swift build (using `LLVM_EXTERNAL_PROJECTS=swift`), swift is installed into `build_dir/tools/swift`. Thus, we also need to find the generated headers inside the `tools/swift/include` directory and not at the top-level `build_dir/include` directory.
2022-07-18 14:24:38 +02:00
Egor Zhdan
5a33fc951a Merge pull request #60045 from apple/egorzhdan/scs-diagnostic-engine
[cxx-interop][SwiftCompilerSources] Use `swift::DiagnosticEngine` instead of `BridgedDiagnosticEngine`
2022-07-15 14:55:54 +01:00
Egor Zhdan
e9dedf3c27 [cxx-interop][SwiftCompilerSources] Use swift::DiagnosticEngine instead of BridgedDiagnosticEngine
This also removes `BridgedOptionalDiagnosticEngine`.

rdar://83361087
2022-07-14 11:06:31 +01:00
eeckstein
d128d81ea5 Merge pull request #60035 from eeckstein/silnode-set
SIL: add efficient Set data structures for SILValue and SILInstruction, similar to BasicBlockSet.
2022-07-14 10:56:21 +02:00
Egor Zhdan
53986b6b40 [cxx-interop][SwiftCompilerSources] Use swift::DiagnosticArgument instead of BridgedDiagnosticArgument
This also removes `BridgedDiagnosticArgumentKind` in favor of `swift::DiagnosticArgumentKind`, bringing us one step closer to bridging the entire diagnostic engine via C++ interop.

rdar://83361087
2022-07-13 17:29:21 +01:00
Erik Eckstein
ce5e2fb637 Swift SIL: use InstructionSet (instead of Set<Instruction>) in InstructionRange 2022-07-13 14:27:50 +02:00
Erik Eckstein
49a5b3ebdc Swift SIL: add ValueSet and InstructionSet utilities.
These sets are _much_ more efficient than `Set<Value>` and `Set<Instruction>` because they bridge to the efficient `NodeSet`.
Insertions/deletions are just bit operations.
2022-07-13 14:27:50 +02:00
Erik Eckstein
6760dc420c SIL: add a utility which can manage per-value and per-instruction bitfields and flags efficiently.
It's used to implement `InstructionSet` and `ValueSet`: sets of SILValues and SILInstructions.
Just like `BasicBlockSet` for basic blocks, the set is implemented by setting bits directly in SILNode.
This is super efficient because insertion and deletion to/from the set are basic bit operations.

The cost is an additional word in SILNode. But this is basically negligible: it just adds ~0.7% of memory used for SILInstructions.
In my experiments, I didn't see any relevant changes in memory consumption or compile time.
2022-07-13 14:27:50 +02:00
Egor Zhdan
f63b6d8284 Merge pull request #60018 from apple/egorzhdan/scs-diagnostic-fixit
[cxx-interop][SwiftCompilerSources] Use `DiagnosticInfo::FixIt` instead of `BridgedDiagnosticFixIt`
2022-07-13 10:42:38 +01:00
Egor Zhdan
1ae44e77a5 [cxx-interop][SwiftCompilerSources] Use DiagnosticInfo::FixIt instead of BridgedDiagnosticFixIt
This removes some of the bridging code and replaces it with C++ calls.

rdar://83361087
2022-07-12 16:54:16 +01:00
Erik Eckstein
c871197e1a Swift SIL: fix ApplySite.callerArgIndex
It needs to return nil in case the callee argument is not really applied by the ApplySite.
This fixes a crash in EscapeInfo when handling "escaping-to" effects:
If the callee operand of an apply instruction is a `partial_apply` of a `function_ref`, the callee-analysis looks through the `partial_apply` and we get the referenced function as a callee.
In this case there are less apply arguments than callee arguments, because the `partial_apply` already "applies" some of the callee arguments.

rdar://96830171
2022-07-12 17:53:27 +02:00
Egor Zhdan
7f9e39c22c Merge pull request #59907 from apple/egorzhdan/scs-charsourcerange
[cxx-interop][SwiftCompilerSources] Use `swift::CharSourceRange` instead of `BridgedCharSourceRange`
2022-07-08 10:47:32 +01:00
Anxhelo Xhebraj
03e4e5cdb2 Merge pull request #59729 from Angelogeb/apple/walkutils
Swift Optimizer: add def-use/use-def walker utilities
2022-07-07 08:44:31 -07:00
Egor Zhdan
220d95e3d9 [cxx-interop][SwiftCompilerSources] Use swift::CharSourceRange instead of BridgedCharSourceRange
This removes some of the bridging code and replaces it with C++ calls.

rdar://83361087
2022-07-07 12:00:12 +01:00
Egor Zhdan
38edc7f377 [cxx-interop][SwiftCompilerSources] Remove getCopiedBridgedStringRef and freeBridgedStringRef
`std::string`s can now be passed directly between Swift and C++.

rdar://83361087
2022-07-06 12:57:50 +01:00
Anxhelo Xhebraj
c3ccbde52b Swift Optimizer: update EscapeInfo to use the generic walker utilities
`EscapeInfo` now conforms to the generic protocols defined in `WalkUtils`.
This simplifies the implementation a bit, since trivial instructions are handled
by `WalkUtils` and `EscapeInfo` only has to handle a subset of instructions
inherent to escape information.
Passes using `EscapeInfo` are updated accordingly to become visitors that
customize the `EscapeInfo` walk.
2022-07-05 11:28:49 -07:00
Anxhelo Xhebraj
50a7e25e31 Swift Optimizer: add projection path DefUse/UseDef walkers
Introduces a set of protocols useful to perform def-use and use-def
traversals to find uses and definitions of values.

This logic was originally baked into `EscapeInfo` directly.
Here we extract it into general utilities, namely:
- `ValueDefUseWalker`: visit uses of a value walking down value-value projections/constructions.
- `AddressDefUseWalker`: visit uses of an address walking down addr-addr projections/constructions.
- `ValueUseDefWalker`: visit definitions of a value walking up value-value projections/constructions.
- `AddressUseDefWalker`: visit definitions of an address walking up addr-addr projections/constructions.

These utilities can then be used in other passes or to create
new utilities by composing them. For example to find a definition
passing through both address projections and value extractions,
it's enough to implement a visitor conforming to both
`AddressUseDefWalker` and `ValueUseDefWalker`.
2022-07-05 11:26:13 -07:00
Egor Zhdan
71706d8bd2 Merge pull request #59102 from apple/egorzhdan/libswift-no-backport
[SwiftCompilerSources][build] Fix build with `SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT=NO`
2022-07-05 11:47:14 +01:00
Alexis Laferrière
e7b1434ed2 [SwiftCompilerSources] Add missing import 2022-06-30 12:56:46 -07:00
Egor Zhdan
b8e2f2eacc Merge pull request #58699 from apple/egorzhdan/libswift-sourceloc
[cxx-interop][SwiftCompilerSources] Use `swift::SourceLoc` instead of `BridgedSourceLoc`
2022-06-22 10:54:59 +01:00
Zoe Carver
59a9e282cd Merge pull request #59510 from zoecarver/remove-enable-interop-pt-2 2022-06-16 21:40:21 -07:00
zoecarver
57f721a2f1 [cxx-interop] Remove "enable-cxx-interop" flag again. 2022-06-16 18:02:24 -07:00
Egor Zhdan
f476f6245c [cxx-interop][SwiftCompilerSources] Workaround for std::string crash on arm64 Linux
`std::string` constructor crashes when called from `SILBridging.cpp`, likely due to a miscompile. This is a workaround that fixes the crash.
2022-06-15 15:54:45 +01:00
Richard Wei
3396ede366 Merge pull request #42611 from rxwei/string-processing-default
Enable string processing by default.
2022-06-13 11:16:05 -07:00
Richard Wei
94e8f5393e Enable string processing by default.
Make frontend flag `-enable-experimental-string-processing` default to true.
2022-06-12 20:25:16 -07:00
Egor Zhdan
5768aebeee [cxx-interop][SwiftCompilerSources] Add LLVM headers to the include paths
This allows the Swift compiler to find headers like `llvm/Support/Compiler.h` that are used by Swift headers.
2022-06-11 00:13:39 +01:00
Egor Zhdan
038a4f0b80 [cxx-interop][SwiftCompilerSources] Use swift::SourceLoc instead of BridgedSourceLoc
C++ interop is now enabled in SwiftCompilerSources, so we can remove some of the C bridging layer and use C++ classes directly from Swift.

rdar://83361087
2022-06-11 00:13:39 +01:00
Egor Zhdan
d00c0f5ded Merge pull request #59353 from apple/egorzhdan/reland-libswift-string-init
Revert "Revert "[cxx-interop][SwiftCompilerSources] Fix conversion between `std::string` and `Swift.String`""
2022-06-10 20:46:11 +01:00
Egor Zhdan
aeec2eb2b4 Merge pull request #59316 from apple/egorzhdan/hosttools-require-recent-swift
[SwiftCompilerSources] Require very recent Swift compiler in `HOSTTOOLS` mode
2022-06-10 20:45:41 +01:00
Egor Zhdan
ffb9ee9422 Revert "Revert "[cxx-interop][SwiftCompilerSources] Fix conversion between std::string and Swift.String""
This reverts commit 9542837a18.
2022-06-09 23:40:51 +01:00
eeckstein
b3d9b873a9 Merge pull request #58888 from eeckstein/objc-string-opt
Optimizer: add the ObjCBridgingOptimization to optimize ObjectiveC bridging operations.
2022-06-09 06:48:36 +02:00
Rintaro Ishizaki
e1412a0978 Merge pull request #59209 from rintaro/syntaxparser-libswift
[SwiftCompilerModules] Link lib_InternalSwiftSyntaxParser to libswift
2022-06-08 15:36:21 -07:00
Erik Eckstein
ec3d9dd9c7 Optimizer: add the ObjCBridgingOptimization to optimize ObjectiveC bridging operations.
Removes redundant ObjectiveC <-> Swift bridging calls.
Basically, if a value is bridged from ObjectiveC to Swift an then back to ObjectiveC again, then just re-use the original ObjectiveC value.

Also in this commit: add an additional DCE pass before ownership elimination. It can cleanup dead code which is left behind by the ObjCBridgingOptimization.

rdar://89987440
2022-06-08 22:51:57 +02:00
Erik Eckstein
a17ee435b6 Swift SIL: fix var ApplySite.arguments
In case of type-dependent operands, not all operands are part of the arguments
2022-06-08 22:51:57 +02:00
Egor Zhdan
a8ae273a52 [SwiftCompilerSources] Require very recent Swift compiler in HOSTTOOLS mode
To use new C++ interop features in SwiftCompilerSources, we need a very recent Swift compiler when building with host tools.

This does not affect non-HOSTTOOLS builds.
2022-06-08 17:08:00 +01:00
Egor Zhdan
9542837a18 Revert "[cxx-interop][SwiftCompilerSources] Fix conversion between std::string and Swift.String"
This reverts commit be711e387f.
2022-06-08 14:10:04 +01:00
Egor Zhdan
c6a95c6fb6 Merge pull request #59152 from apple/egorzhdan/libswift-string-init
[cxx-interop][SwiftCompilerSources] Fix conversion between `std::string` and `Swift.String`
2022-06-08 12:52:09 +01:00
Rintaro Ishizaki
9f4ce612a2 [SwiftCompilerModules] Link lib_InternalSwiftSyntaxParser to libswift
To use _RegexParser from SwiftSyntax.

* Create 'libswiftCompilerModules_SwiftSyntax.a' which is a subset of
  'libswiftCompilerModules.a'
* Link 'lib_InternalSwiftSyntaxParser' to
  'libswiftCompilerModules_SwiftSyntax.a'
* Factor out swift runtime linking logic in CMake so that dynamic
  libraries can link to Swift runtime, in addition to executables
* Link 'lib_InternalSwiftSyntaxParser' to swift runtime
2022-06-02 12:23:03 -07:00
Egor Zhdan
2b3980b3e2 [SwiftCompilerSources][build] Require recent Swift compiler in HOSTTOOLS mode
Some code in SwiftCompilerSources, especially the parts that use C++ interop, triggers bugs in older versions of the Swift compiler. To make sure that `HOSTTOOLS` builds don't produce obscure compiler errors or crashes, let's require a relatively new Swift compiler for `HOSTTOOLS` build.
2022-05-31 13:35:58 +01:00
Egor Zhdan
be711e387f [cxx-interop][SwiftCompilerSources] Fix conversion between std::string and Swift.String
This fixes a dangling pointer issue when creating a `Swift.String` from `std::string`.

Also fixes a warning:
```
warning: variable 's' was never mutated; consider changing to 'let' constant
    var s = SILBasicBlock_debugDescription(bridged)
    ~~~ ^
    let
```

rdar://92963081
rdar://93053488
2022-05-30 20:06:36 +01:00
Egor Zhdan
b07a0abba0 [SwiftCompilerSources][build] Fix build with SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT=NO
This allows building SwiftCompilerSources with stdlib compatibility disabled.

Fixes errors like this:
```
[699/716] Building swift module Basic
FAILED: bootstrapping1/SwiftCompilerSources/Basic.o /Users/egorzh/Builds.noindex/swift/swift-release/bootstrapping1/SwiftCompilerSources/Basic.o
cd /Volumes/Projects/swift/swift/SwiftCompilerSources && /Users/egorzh/Builds.noindex/swift/swift-release/bootstrapping0/bin/swiftc -c -o /Users/egorzh/Builds.noindex/swift/swift-release/bootstrapping1/SwiftCompilerSources/Basic.o -sdk /Applications/Xcodes/XcodeSummit.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -target x86_64-apple-macosx10.9 -module-name Basic -emit-module -emit-module-path /Users/egorzh/Builds.noindex/swift/swift-release/bootstrapping1/SwiftCompilerSources/Basic.swiftmodule -parse-as-library /Volumes/Projects/swift/swift/SwiftCompilerSources/Sources/Basic/SourceLoc.swift /Volumes/Projects/swift/swift/SwiftCompilerSources/Sources/Basic/Utils.swift -wmo -Xfrontend -validate-tbd-against-ir=none -Xfrontend -enable-cxx-interop -Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable -O -cross-module-optimization -Xcc -I -Xcc /Volumes/Projects/swift/swift/include -Xcc -I -Xcc /Users/egorzh/Builds.noindex/swift/swift-release/include -I /Users/egorzh/Builds.noindex/swift/swift-release/bootstrapping1/SwiftCompilerSources
<unknown>:0: error: IR generation failure: Cannot read legacy layout file at '/Users/egorzh/Builds.noindex/swift/swift-release/bootstrapping0/lib/swift/macosx/layouts-x86_64.yaml'
ninja: build stopped: subcommand failed.
```
2022-05-26 14:52:54 +01:00