Commit Graph

34 Commits

Author SHA1 Message Date
Akira Hatanaka
b3f302b96b [IRGen] Fix a bug where an argument wasn't annotated with sret (#71459)
Fix a bug in expandExternalSignatureTypes where it wasn't annotating a function call parameter type with sret when the result was being returned indirectly.

The bug was causing calls to ObjC methods that return their results indirectly to crash.

Additionally, fix the return type for C++ constructors computed in expandExternalSignatureTypes. Previously, the return type was always void even on targets that require constructors to return this (e.g., Apple arm64), which was causing C++ constructor thunks to be emitted needlessly.

Resolves rdar://121618707
2024-02-22 14:14:47 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
swift-ci
6a6e06f04d Merge remote-tracking branch 'origin/main' into rebranch 2023-02-23 19:53:16 -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
666222d379 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-11 23:54:48 -08:00
Slava Pestov
65d2d4d621 IRGen: Encapsulate fields of GenericRequirement better 2022-12-11 22:14:37 -05: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
Erik Eckstein
4c65062bdf rebranch: change some uses of Optional to the new API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

This change does not cover all uses of the old API. Other warnings are worked around in llvm by https://github.com/apple/llvm-project/pull/5618

rdar://102362022
2022-11-15 17:23:07 +01:00
Arnold Schwaighofer
d68dc2d06e IRGen: objc_direct method calls have a different convention
objc_direct methods no longer have the CMD argument.

rdar://102151993
2022-11-10 12:55:51 -08:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Alex Lorenz
e1989dd1f5 [interop][SwiftToCxx] verify that lowered function signature represented all LLVM IR params 2022-09-07 13:06:11 -07:00
Alex Lorenz
c351f3a550 [interop][SwiftToCxx] error result param should be handled by lowered function signature 2022-09-07 12:55:12 -07:00
Alex Lorenz
f4de75ae2c [interop][SwiftToCxx] 'self' param should be handled by type param visitor 2022-09-07 12:45:38 -07:00
Alex Lorenz
1696f94223 [interop][SwiftToCxx] reimplement function lowering to correctly distinguish between direct/indirect return values and parameters 2022-09-07 11:43:38 -07:00
Alex Lorenz
a5043c354d [interop][SwiftToCxx] add support for invoking methods in generic structs 2022-08-31 20:19:19 -07:00
Alex Lorenz
32723f7e67 [interop][SwiftToCxx] initial generic function support: pass generic parameters
Only primitive types are supported at the moment from C++ as the type traits aren't emitted for all types yet
2022-07-28 22:52:21 +01:00
John McCall
58fe89f359 [NFC] Split up the "special convention" for runtime async functions
The special convention currently means three things:

1. There is no async FP symbol for the function.  Calls should go directly
to the function symbol, and an async context of fixed static size should be
allocated.  This is mandatory for calling runtime-provided async functions.

2. The callee context should be allocated but not initialized.  The main
context pointer passed should be the caller's context, and the continuation
function pointer and callee context should be passed as separate arguments.
The function will resume the continuation function pointer with the caller's
context.  This is a micro-optimization appropriate for functions that are
expected to frequently return immediately; other functions shouldn't bother.

3. Generic arguments should be suppressed.  This is a microoptimization for
certain specific runtime functions where we happen to know that the runtime
already stores the appropriate information internally.  Other functions
probably don't want this.

Obviously, these different treatments should be split into different
predicates so that functions can opt in to different subsets of them.

I've also set the code up so that runtime functions can more easily
request a specific static async context size.  Previously, it was a
confusingly embedded assumption that the static context size was always
exactly two pointers more than the header.
2022-02-15 04:12:05 -05:00
Arnold Schwaighofer
10e3d2e3af Change _wait(_throwing) ABIs to reduce code size
Changes the task, taskGroup, asyncLet wait funtion call ABIs.

To reduce code size pass the context parameters and resumption function
as arguments to the wait function.

This means that the suspend point does not need to store parent context
and resumption to the suspend point's context.

```
  void swift_task_future_wait_throwing(
    OpaqueValue * result,
    SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
    AsyncTask *task,
    ThrowingTaskFutureWaitContinuationFunction *resume,
    AsyncContext *callContext);
```

The runtime passes the caller context to the resume entry point saving
the load of the parent context in the resumption function.

This patch adds a `Metadata *` field to `GroupImpl`. The await entry
pointer no longer pass the metadata pointer and there is a path through
the runtime where the task future is no longer available.
2021-06-08 10:41:26 -07:00
Arnold Schwaighofer
3bdd5cb99a IRGen: async error ABI
Throwing functions pass the error result in `swiftself` to the resume
partial function.
Therefore, `() async -> ()` to `() async throws -> ()` is not ABI compatible.

TODO: go through remaining failing IRGen async tests and replace the
illegal convert_functions.
2021-03-17 17:17:12 -07:00
Arnold Schwaighofer
f75fbb7594 IRGen: Async ABI passing parameter and results directly
The error is still passed in the async context. I will fix this in a
follow-up.
2021-03-17 07:41:01 -07:00
John McCall
2012195cd5 Alter the runtime interface for awaiting futures and task groups.
First, just call an async -> T function instead of forcing the caller
to piece together which case we're in and perform its own copy.  This
ensures that the task is actually kept alive properly.

Second, now that we no longer implicitly depend on the waiting tasks
being run synchronously, go ahead and schedule them to run on the
global executor.

This solves some problems which were blocking the work on TLS-ifying
the task/executor state.
2021-02-21 23:48:13 -05:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
swift-ci
d549147e43 Merge remote-tracking branch 'origin/master' into master-next 2017-07-31 18:48:50 -07:00
John McCall
4dd0e039d7 Sundry minor code improvements, NFC. 2017-07-31 20:42:47 -04:00
Arnold Schwaighofer
f4a810f7e4 IRGen: AttributeList related fixes for master next 2017-07-31 11:17:51 -07:00
John McCall
d4d2145ad8 Merge branch 'master' into master-next 2017-07-29 15:48:00 -04:00
John McCall
a0f20f673d Switch all of the indirect-call code in IRGen to FunctionPointer.
To make this stick, I've disallowed direct use of that overload of
CreateCall.  I've left the Constant overloads available, but eventually
we might want to consider fixing those, too, just to get all of this
code out of the business of manually remembering to pass around
attributes and calling conventions.

The test changes reflect the fact that we weren't really setting
attributes consistently at all, in this case on value witnesses.
2017-07-28 23:26:35 -04:00
Bob Wilson
ef838e8af1 [master-next] Fix an instance of llvm::AttributeSet that I missed
The merge in 5f02db4d3e had a bunch of conflicts. I fixed a few references
to llvm::AttributeSet that needed to be llvm::AttributeList but I missed
this one.
2017-07-20 22:54:28 -07:00
Bob Wilson
5f02db4d3e Merge remote-tracking branch 'origin/master' into master-next 2017-07-20 21:59:23 -07:00
John McCall
750d397909 Substantially rework how IRGen handles function pointers.
The goals here are four-fold:
  - provide cleaner internal abstractions
  - avoid IR bloat from extra bitcasts
  - avoid recomputing function-type lowering information
  - allow more information to be propagated from the function
    access site (e.g. class_method) to the call site

Use this framework immediately for class and protocol methods.
2017-07-20 14:33:18 -04:00
Saleem Abdulrasool
15565c116a Adjust for SVN r298393 2017-03-22 07:44:03 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
John McCall
52cd8718de Split GenFunc.cpp in three: GenFunc for function types and blocks,
GenCall for function signatures, calls, and prologue/epilogue, and
GenBuiltin for builtin operations.

NFC.
2016-04-04 23:52:14 -07:00