Commit Graph

576 Commits

Author SHA1 Message Date
Allan Shortlidge
2990c65457 NFC: Address some unused variable warnings. 2024-02-12 12:23:42 -08:00
Alastair Houghton
76f2389fd9 [IRGen][Test] Use the new availability support.
We need to only generate references to `_swift_exceptionPersonality`
if we're building for a new enough runtime.  The previous code was
good on Darwin, but would have resulted in build problems on Linux.

rdar://120952971
2024-02-06 16:21:11 +00:00
Alastair Houghton
143a473aa4 [Runtime][IRGen] Trap C++ exceptions on *throw*, not catch.
The previous approach was effectively to catch the exception and then
run a trap instruction.  That has the unfortunate feature that we end
up with a crash at the catch site, not at the throw site, which leaves
us with very little information about which exception was thrown or
where from.

(Strictly we do have the exception pointer and could obtain exception
information, but it still won't tell us what threw it.)

Instead of that, set a personality function for Swift functions that
call potentially throwing code, and have that personality function
trap the exception during phase 1 (i.e. *before* the original stack
has been unwound).

rdar://120952971
2024-02-06 16:19:17 +00:00
Arnold Schwaighofer
2f94890e5f IRGen: Remove supportsTypedPointers, getNonOpaquePointerElementType, isOpaqueOrPointeeTypeMatches
Typed pointers are no longer supported by llvm.

rdar://121083958
2024-01-17 07:33:30 -08:00
Arnold Schwaighofer
b4ef029fe6 IRGen: Add support for typed throws to thunk code generation
rdar://119725769
2023-12-15 15:39:29 -08:00
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Arnold Schwaighofer
e3a27a13d9 IRGen: Allocate an address for the result of zero sized typed error results
rdar://118657904
2023-11-28 11:37:09 -08:00
Konrad `ktoso` Malawski
5546f4da7b Rename ExecutorRef to SerialExecutorRef 2023-11-01 18:39:44 +09:00
Mishal Shah
3594f8ecaf Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	test/IRGen/opaque-pointer-llvm.swift
2023-10-15 23:49:40 -07:00
Kuba (Brecka) Mracek
7e9013dd52 Merge pull request #69090 from kubamracek/embedded-actors-and-async-let
[embedded] Add support for actors and async let into the embedded Concurrency runtime
2023-10-15 13:37:35 -07:00
Arnold Schwaighofer
9482b0c86b Preliminary SIL and IRGen support for error_indirect
IRGen lowering of non-fixed-sized typed errors and the SIL support necessary to
spell out IRGen test cases.
2023-10-12 18:09:52 -07:00
swift-ci
46c67c20cf Merge remote-tracking branch 'origin/main' into rebranch 2023-10-10 02:35:18 -07:00
Kuba Mracek
90e1d2006f [embedded] Add support for actors and async let into the embedded Concurrency runtime 2023-10-09 22:43:50 -07:00
Hamish Knight
ccd32eb452 NFC: Remove ClangModuleLoader.h include from ExtInfo.h
This was unnecessarily pulling in a whole bunch
of Clang headers when all was needed was a
forward declaration.
2023-10-09 20:29:03 +01:00
swift-ci
d253b717d2 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-07 19:35:15 -07:00
Kuba Mracek
5d8c55eacb [embedded] Initial Swift Concurrency for embedded Swift 2023-10-06 20:04:03 -07:00
swift-ci
00db9cadd6 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-02 08:55:02 -07:00
Arnold Schwaighofer
6b74f511d0 Preliminary IRGen support for typed throws
Typed errors are returned indirectly in this version.
No support for non-loadable typed errors
2023-09-29 08:54:49 -07:00
Evan Wilde
700aa8aa70 Merge remote-tracking branch 'upstream/main' into rebranch
Merge conflict while removing `nocapture` from
`s21move_function_dbginfo20addressOnlyValueTestyyxAA1PRzlF`. Resolution
was to remove nocapture from the expected output in both cases:
```
// CHECK-LABEL: define swiftcc void @"$s21move_function_dbginfo20addressOnlyValueTestyyxAA1PRzlF"(ptr noalias[-nocapture-] %0, ptr %T, ptr %T.P)
```

Conflict cause: 4858cb6225
This is the same as the original change to this file. The conflict seems
to be due to the next line changing, when moving from llvm.dbg.addr to
llvm.dbg.value.

Conflicts:
  test/DebugInfo/move_function_dbginfo.swift
2023-09-26 13:36:57 -07:00
Alex Lorenz
6ecea1ac09 Merge pull request #68481 from hyp/eng/no-nocapture
[IRGen][interop] do not add 'nocapture' to not bitwise takable types
2023-09-26 07:52:05 -07:00
Alex Lorenz
4858cb6225 [IRGen][interop] do not add 'nocapture' to not bitwise takable types
The use of 'nocapture' for parameters and return values is incorrect for C++ types, as they can actually capture a pointer into its own value (e.g. std::string in libstdc++)

rdar://115062687
2023-09-25 17:43:34 -07:00
swift-ci
1b6470ca9c Merge remote-tracking branch 'origin/main' into rebranch 2023-09-20 15:07:15 -07:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07:00
Nate Chandler
6ccd08b4e0 Merge branch 'main' into rebranch.
Resolve conflicts introduced in
https://github.com/apple/swift/pull/67944 as follows:

```
diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def
index 3c973b5884b..44cde707d17 100644
--- a/include/swift/Runtime/RuntimeFunctions.def
+++ b/include/swift/Runtime/RuntimeFunctions.def
@@ -2537,16 +2537,10 @@ FUNCTION(AutoDiffCreateLinearMapContextWithType,
          swift_autoDiffCreateLinearMapContextWithType, SwiftCC,
          DifferentiationAvailability,
          RETURNS(RefCountedPtrTy),
-<<<<<<< HEAD
-         ARGS(SizeTy),
+         ARGS(TypeMetadataPtrTy),
          ATTRS(NoUnwind),
          EFFECT(AutoDiff),
          MEMEFFECTS(ArgMemOnly))
-=======
-         ARGS(TypeMetadataPtrTy),
-         ATTRS(NoUnwind, ArgMemOnly),
-         EFFECT(AutoDiff))
->>>>>>> public-github/main

 // void *swift_autoDiffProjectTopLevelSubcontext(AutoDiffLinearMapContext *);
 FUNCTION(AutoDiffProjectTopLevelSubcontext,
@@ -2563,16 +2557,10 @@ FUNCTION(AutoDiffAllocateSubcontextWithType,
          swift_autoDiffAllocateSubcontextWithType, SwiftCC,
          DifferentiationAvailability,
          RETURNS(Int8PtrTy),
-<<<<<<< HEAD
-         ARGS(RefCountedPtrTy, SizeTy),
+         ARGS(RefCountedPtrTy, TypeMetadataPtrTy),
          ATTRS(NoUnwind),
          EFFECT(AutoDiff),
          MEMEFFECTS(ArgMemOnly))
-=======
-         ARGS(RefCountedPtrTy, TypeMetadataPtrTy),
-         ATTRS(NoUnwind, ArgMemOnly),
-         EFFECT(AutoDiff))
->>>>>>> public-github/main
```
2023-08-24 16:24:32 -07:00
Kshitij Jain
d5a3e2e630 [AutoDiff] Fixes memory leaks in autodiff linear map context allocation builtins (#67944)
When the differentiating a function containing loops, we allocate a linear map context object on the heap. This context object may store non-trivial objects, such as closures, that need to be released explicitly. Fix the autodiff linear map context allocation builtins to correctly release such objects and not just free the memory they occupy.
2023-08-24 13:57:10 -07:00
swift-ci
c5f45eb8e3 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-16 07:18:10 -07:00
Alejandro Alonso
44198d16a4 Merge pull request #67611 from Azoy/raw-types-are-cool!
[WIP] Implement dependent layouts for raw types
2023-08-16 06:55:42 -07:00
swift-ci
c1e2a8a93a Merge remote-tracking branch 'origin/main' into rebranch 2023-08-08 12:13:56 -07:00
Alex Lorenz
8d81f5e3f7 [cxx-interop][windows] Pass trivial indirect result after 'this' when invoking C++ MSVC ABI method 2023-08-07 11:15:20 -07:00
Alex Lorenz
8449b21d62 [cxx-interop][windows] additional fix for indirect return in methods for MSVC ABI
Fixes https://github.com/apple/swift/pull/67685
2023-08-03 15:07:22 -07:00
Alejandro Alonso
df17f7be90 Implement dependent layouts for raw types
Update raw_layout.swift

Allow for concrete specializations of raw layout

Make test platform agnostic
2023-08-01 14:09:23 -07:00
Evan Wilde
f4946e9718 Updating more alignment APIs
Adding a few more updates to places where the ABI Alignment functions
changed. `getABITypeAlignment` was replaced with `getABITypeAlign`,
which returns an `llvm::Align` instead of an unsigned int.
2023-07-25 12:28:28 -07:00
swift_jenkins
81614b11ec Merge remote-tracking branch 'origin/main' into next 2023-07-21 07:09:38 -07:00
Evan Wilde
bc904880d0 Handle new builtin cases: AArch64SVcount, WASMRefType
Clang and LLVM added some new builtins.

LLVM added IITDescriptor::AArch64Svcount, which I set to not be
decodable since Swift can't represent those at the moment.

Also added handling for the WASM reference type builtins in the Clang
type converter.
2023-07-17 10:55:57 -07:00
Evan Wilde
8ce6ee8dd1 Updating API usages
LLVM deprecated, renamed, and removed a bunch of APIs. This patch
contains a lot of the changes needed to deal with that.

The SetVector type changed the template parameters.

APInt updated multiple names, countPopulation became popcount,
getAllOnesValue became getAllOnes, getNullValue became getZero, etc...

Clang type nullability check stopped taking a clang AST context.

The LLVM IRGen Function type stopped exposing basic block list directly,
but gained enough API surface that the translation isn't too bad.
(GenControl.cpp, LLVMMergeFunctions.cpp)

llvm::Optional had a transform function. That was being used in a couple
of places, so I've added a new implementation under STLExtras that
transforms valid optionals, otherwise it returns nullopt.
2023-07-17 10:53:42 -07:00
Alex Lorenz
c09135b8f3 [cxx-interop] Fix the windows ABI for returning indirect values out of methods
Fixes https://github.com/apple/swift/issues/66326

This allows us to reneable Windows method tests. Note that Windows still has
a broken convention for non-trivial record with non-trivial destructor but
trivial copy-constructor, so classes in the methods.swift test need an explicit
copy constructor.

Fixes rdar://88391102
2023-07-14 15:56:05 -07:00
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
Rauhul Varma
6b9fb171bf Address rewview feedback
- Renames ExperimentalPlatformCCallingConvention to
  PlatformCCallingConvention.
- Removes non-arm calling convention support as this feature is working
  around a clang bug for some arm triples which we hope to see resolved.
- Removes misleading MetaVarName from platform-c-calling-convention
  argument.
- Replaces other uses of LLVM::CallingConv::C with
  IGM.getOptions().PlatformCCallingConvention().
2023-06-15 22:06:43 -07:00
Rauhul Varma
19f74e22e6 Add frontend flag for explicitly setting ccc
Adds a new swift-frontend flag to allow users to choose which calling
convention is used to make c function calls. This hidden flag is called
`-experimental-platform-c-calling-convention`.

This behavior is needed to workaround rdar://109431863 (Swift-frontend
produces trapping llvm ir for non-trapping sil). The root cause of this
issue is that IRGen always emits c function calls with llvm's default C
calling convention. However clang may select a different (incompatible)
calling convention for the function, eventually resulting--via
InstCombine and SimplifyCFG--in a trap instead of the function call.
This failure mode is most readily seen with the triple
`armv7em-apple-none-macho` when attempting to call functions taking
struct arguments. Example unoptimized ir below:

```llvm-ir
call void @bar([4 x i32] %17, i32 2), !dbg !109
...
define internal arm_aapcs_vfpcc void @bar(
  [4 x i32] %bar.coerce, i32 noundef %x)
```

In the future it would be better to use the clang importer or some other
tool to determine the calling convention for each function instead of
setting the calling convention frontend invocation wide.

Note: I don't know for sure whether or not clang should be explicitly
annotating these functions with a calling convention instead of
aliasing C to mean ARM_AAPCS_VFP for this particular combination of
`-target`, `-mfloat-abi`, and `-mcpu`.
2023-06-15 21:52:03 -07:00
Alex Lorenz
138def7627 Merge pull request #65922 from hyp/eng/excp-cons-spec
[cxx-interop] evaluate default constructor's unevaluated exception sp…
2023-06-08 15:35:23 -07:00
Alex Lorenz
b0dab0b48c [cxx-interop] evaluate default constructor's unevaluated exception spec if needed when emitting C++ constructor call
Fixes https://github.com/apple/swift/issues/65891
2023-06-08 11:02:29 -07:00
Erik Eckstein
24837b4d10 IRGen: change a few enum utility functions to be able to create enums in static initializers
Instead of passing `IRGenFunction`, pass the `IRGenModule` and the `IRBuilder`.
This makes enum creation not dependent on the presence of a function.

NFC, just refactoring.
2023-05-25 16:28:41 +02:00
Arnold Schwaighofer
27731bd61a IRGen: Another fix for compiling LLVM opaque pointers
Use the signature to get the function type when getting Swift function pointer callees.
This is okay because there is a previous call to cast to that type using the Signature
2023-05-10 13:40:33 -07:00
swift-ci
6a6e06f04d Merge remote-tracking branch 'origin/main' into rebranch 2023-02-23 19:53:16 -08:00
Alex Lorenz
355f00c5bd [interop] ensure that call to a C++ constructor traps on uncaught exception 2023-02-22 10:59:58 -08:00
Alex Lorenz
8998f9769a [interop] trap on uncaught C++ copy constructor exceptions 2023-02-22 10:59:53 -08:00
Alex Lorenz
1dc0f019bf [interop] add initial support for trapping on uncaught exceptions when making a foreign call 2023-02-21 13:30:18 -08:00
swift-ci
0b49ac49d7 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-29 10:33:27 -08:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00