Commit Graph

902 Commits

Author SHA1 Message Date
swift-ci
c2dea376a3 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-02 08:53:44 -08:00
Arnold Schwaighofer
bb80f10ecc Revert "Merge pull request #62275 from aschwaighofer/rdar102481054"
This reverts commit 3617b7603c, reversing
changes made to 58a519a5c1.

This causes issues for the linker and branches accross sections if
addresses are too far apart.
2022-12-01 11:36:04 -08:00
swift-ci
e45db33b8d Merge remote-tracking branch 'origin/main' into rebranch 2022-11-29 14:54:58 -08:00
Arnold Schwaighofer
082349ebc7 Revert "Merge pull request #62203 from apple/revert-61984-colocate_instantiation"
This reverts commit 1f3e159cfe, reversing
changes made to 103b4a89c2.

Re-applies "IRGen: Co-locate metadata instatiation/completions/accessor
functions in a special section" for MachO only. The original change broke lldb
on aarch64 linux.

rdar://102481054
2022-11-28 06:27:12 -08:00
swift-ci
69b7f934d6 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-18 23:53:31 -08:00
Mishal Shah
a0a8881012 Revert "IRGen: Co-locate metadata instatiation/completions/accessor functions in a special section" 2022-11-18 21:04:21 -08:00
Rintaro Ishizaki
d458c8b74a Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	include/swift/Sema/ConstraintSystem.h
	include/swift/Syntax/AbsoluteRawSyntax.h
	include/swift/Syntax/Syntax.h
	include/swift/Syntax/SyntaxData.h
	lib/DependencyScan/ModuleDependencyCacheSerialization.cpp
	lib/Syntax/SyntaxFactory.cpp.gyb
	lib/Syntax/SyntaxNodes.cpp.gyb
	tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
	tools/swift-syntax-test/swift-syntax-test.cpp
2022-11-18 09:37:38 -08:00
Allan Shortlidge
ae32b8e148 IRGen: Implement lowering of has_symbol SIL instruction. 2022-11-16 16:07:29 -08:00
swift-ci
b96dbfdcb8 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-16 06:54:48 -08:00
Arnold Schwaighofer
6a853fa91b IRGen: Co-locate metadata instatiation/completions/accessor functions in a special section
For spatial locality on startup.

rdar://101593202
2022-11-14 06:18:00 -08: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
Allan Shortlidge
7f20380f0b IRGen: Generate #_hasSymbol query functions.
For each decl that needs a `#_hasSymbol()` query function, emit the corresponding helper function body during IRGen. Use `IRSymbolVisitor` to collect linkable symbols associated with the decl and return true from the helper function if the address of every associated symbol is non-null.

Resolves rdar://101884587
2022-11-04 11:19:29 -07:00
Arnold Schwaighofer
ba9578d6ce IRGen: Use clang's codegen for protocol decls
There are certain protocol method decls types that swift does not import
today.

```
@protocol Incomplete
- (id)getObjectFromVarArgs:(id)first, ...;
@end
```

Furthermore, the old method also emitted duplicate entries for protocols
methods when Swift synthesized methods for diagnosics.

We won't import this method into Swift. So if we emit protocol metadata
from swift delcs we would generate incomplete records.

rdar://60888524
2022-10-26 12:34:25 -07:00
Arnold Schwaighofer
3905955589 Merge pull request #61232 from aschwaighofer/wip_opaque_ptr_2
IRGen: Pass the elementType of pointers through to operations
2022-10-04 10:56:41 -07: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
Hamish Knight
01c7c16c18 [IRGen] Allow lazy emission of coverage mapped functions
We previously eagerly emitted such functions to
ensure that their name data is emitted through the
profiler increment. Now that are able to emit the
profile name data separately, this is unnecessary,
and we can avoid emitting their definitions.
2022-09-16 15:47:17 +01:00
Arnold Schwaighofer
2b556bc64b IRGen: Don't emit duplicate defintions for opaque type decls
rdar://99874281
2022-09-15 06:20:07 -07:00
Alex Lorenz
4c7015ad68 [interop][SwiftToCxx] ensure LoadableByAddress lowering is done on the SILFunction for while we're lowering the signature for
This correctly now passes self parameters for direct values that are too large to be direct
2022-09-07 17:42:50 -07:00
Ben Barham
6de34f37e5 [NFC] Revert SmallVector<T> -> SmallVector<T, N> fixes
With the change to include `SmallVector.h` directly in `LLVM.h` rather
than forward declaring in the only case it matters (ie. Clang <= 5),
these fixes are no longer needed. Since defaulted version is preferred
when there's no better choice (which is presumably the case if that's
how they were originally added), use it instead. Some uses were instead
changed to add `llvm::` so remove that too.
2022-08-05 21:25:55 -07:00
Arnold Schwaighofer
0379719052 IRGen: Add option to enable stack protector
Adds frontend option -enable-stack-protector to enable emission of a
stack protector.

Disabled by default.

When enabled enables LLVM's strong stack protection mode.

rdar://93677524
2022-08-02 09:05:37 -07:00
Arnold Schwaighofer
78f5e0b0fd Merge pull request #60231 from aschwaighofer/generic_objc_method_list_section
IRGen: Add a list of class_ro_t referenced from generic class metadata patterns to a section __swift_rodatas
2022-08-02 08:23:52 -07:00
Arnold Schwaighofer
6ce452b928 IRGen: Add a list of class_ro_t referenced from generic class metadata patterns to a section __swift_rodatas
Put pointers to class_ro_t referenced from generic class patterns in a section __swift_rodatas such that they are discoverable by the linker.
The linker can then make the method lists contained in the class_ro_t relative like it can for objective c class metadata from non-generic swift classes.

rdar://66634459
2022-07-29 11:38:20 -07:00
Alex Lorenz
e66e4caa1b NFC, move GenericRequirement struct out of lib/IRGen to include/AST
This will permit the use of GenericRequirement in PrintAsClang.
This will allow the C++ bindings printer to print generic function signatures
correctly, by passing information about emitted GenericRequirement values
for a signature from IRGen using IRGenABIDetailsProvider to PrintAsClang
2022-07-26 18:28:32 +01:00
zoecarver
c9f54e1417 [nfc] Rename CxxCustom -> Custom and fix comments based on review feedback. 2022-07-21 10:25:57 -04:00
zoecarver
4021082a55 [wip][cxx-interop] Support for custom reference counting operations. 2022-07-21 10:25:57 -04:00
Pavel Yaskevich
76ab70c3a8 [IRGen] Emit opaque type descriptors into client for @_alwaysInlineIntoClient decls
If opaque result type has availability conditions and is associated with
an `@_alwaysInlineIntoClient` declaration, its metadata descriptor has to
be emitted into a client module because the body of the inlined function
depends on it for the runtime information about the underlying type.

Resolves: rdar://82791712
2022-07-12 11:36:38 -07:00
Erik Eckstein
24d077e78b IRGen: re-enable generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998

This reverts the revert commit df353ff3c0.
Also, I added a frontend option to disable this optimization: `-disable-readonly-static-objects`
2022-06-21 18:30:42 +02:00
Erik Eckstein
df353ff3c0 Revert "IRGen: generate static arrays in read-only data sections."
This reverts commit aca0d8358b.

I need to fix a problem before this can actually land.
2022-06-17 20:32:32 +02:00
Erik Eckstein
aca0d8358b IRGen: generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998
2022-06-17 11:21:29 +02:00
Alex Lorenz
f78f226e19 NFC, extract param & return type for type metadata access function to accessors for reuse
They will be reused to provide information about the signature of the type metadata access function to the Clang printer for C++ interop
2022-06-10 07:14:59 -07:00
Max Desiatov
950792a260 IRGen: fix swifterror attribute mismatch for WebAssembly 2022-05-28 17:31:44 +09:00
John McCall
bd77714537 Unique extended existential shapes using the generalized AST type.
I wrote out this whole analysis of why different existential types
might have the same logical content, and then I turned around and
immediately uniqued existential shapes purely by logical content
rather than the (generalized) formal type.  Oh well.  At least it's
not too late to make ABI changes like this.

We now store a reference to a mangling of the generalized formal
type directly in the shape.  This type alone is sufficient to unique
the shape:

- By the nature of the generalization algorithm, every type parameter
  in the generalization signature should be mentioned in the
  generalized formal type in a deterministic order.

- By the nature of the generalization algorithm, every other
  requirement in the generalization signature should be implied
  by the positions in which generalization type parameters appear
  (e.g. because the formal type is C<T> & P, where C constrains
  its type parameter for well-formedness).

- The requirement signature and type expression are extracted from
  the existential type.

As a result, we no longer rely on computing a unique hash at
compile time.

Storing this separately from the requirement signature potentially
allows runtimes with general shape support to work with future
extensions to existential types even if they cannot demangle the
generalized formal type.

Storing the generalized formal type also allows us to easily and
reliably extract the formal type of the existential.  Otherwise,
it's quite a heroic endeavor to match requirements back up with
primary associated types.  Doing so would also only allows us to
extract *some* matching formal type, not necessarily the *right*
formal type.  So there's some good synergy here.
2022-04-21 23:47:01 -04:00
Josh Soref
9fa14ca215 Spelling irgen (#42470)
* spelling: abstractable

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

* spelling: across

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

* spelling: clazz

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

* spelling: command

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

* spelling: components

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

* spelling: current

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

* spelling: declared

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

* spelling: discrimination

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

* spelling: entities

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

* spelling: except

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

* spelling: existential

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

* spelling: generic

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

* spelling: initialization

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

* spelling: initialize

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

* spelling: inserted

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

* spelling: instantiate

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

* spelling: instantiation

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

* spelling: interfere

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

* spelling: interferes

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

* spelling: intrinsic

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

* spelling: metadata

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

* spelling: might

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

* spelling: multiple

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

* spelling: necessary

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

* spelling: objective

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

* spelling: occurrences

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

* spelling: outlined

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

* spelling: parameters

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

* spelling: payload

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

* spelling: rearchitecting

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

* spelling: replaceable

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

* spelling: reverse

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

* spelling: rewritable

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

* spelling: shareably

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

* spelling: specializations

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

* spelling: speedup

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

* spelling: template

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

* spelling: that

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

* spelling: the

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

* spelling: transferred

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

* spelling: uninitialized

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

* spelling: witness

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

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 14:02:03 -07:00
John McCall
f7290c9bfd [NFC] Add a utility to easily emit lazy variable definitions 2022-04-11 22:26:01 -04:00
Joe Groff
15c21920a1 Merge pull request #42101 from jckarter/async-let-reabstraction
SILGen: Emit async let entry points at correct abstraction level.
2022-03-31 10:07:01 -07:00
Joe Groff
d451203b7f SILGen: Emit async let entry points at correct abstraction level.
Avoid a reabstraction thunk every time an async let entry point is emitted,
by setting the context abstraction level while we emit the implicit closure.
Adjust some surrounding logic that breaks when we do this:

- When lowering a non-throwing function type against a throwing abstraction
  pattern, include the error type in the lowered substituted type. Async
  throwing and nonthrowing functions would require another thunk to convert
  away the throwingness of the async context, which would defeat the purpose.
- Adjust the code in IRGen that pads the initial context size for `async let`
  entry points so that it works when the entry point has not yet emitted, by
  marking the async function pointer to be padded later if it isn't defined
  yet.
2022-03-30 14:51:46 -07:00
Arnold Schwaighofer
3930fc4cfe IRGen: Fix enable-testing of internal with resilient super class
Enable testing makes `internal` types visible from outside the module.
We can no longer treat super classes as resilient.

Follow-up to #41044.

rdar://90489618
2022-03-30 07:12:14 -07:00
Joe Groff
6f68eae7ba IRGen: Artificially pad async let entry point contexts.
We fixed a bug in the concurrency runtime (rdar://problem/90357994) that would
lead to memory corruption when a new `async let` child task tried to use the
last 16 bytes of the preallocated slab from its parent to seed its own task
allocator. To work around this bug in older OSes that shipped with the bug,
artificially pad the async coroutine context size for any async functions
used as an `async let` entry point, which will prevent the runtime from
going down the path of trying to use the preallocated storage at all.
rdar://90506708
2022-03-25 16:06:00 -07:00
Tim Kientzle
4d91b45988 [RemoteMirror] Get spare bit info from reflection records (#40906)
This adds a new reflection record type carrying spare bit information for multi-payload enums.

The compiler includes this for any type that might need it in order to accurately reflect the contents of the enum. The RemoteMirror library will use this if present to determine how to project the contents of the enum. If not present (for example, in older binaries), the RemoteMirror library falls back on an internal calculation of the spare bitmask.

A few notes:
 * The internal calculation is not perfect.  In particular, it does not support MPEs that contain other enums (e.g., optionals).  It should accurately refuse to project any MPE that it does not correctly support.
 * The new reflection field is designed to be expandable; this might someday avoid the need for a new section.

Resolves rdar://61158214
2022-02-21 17:06:14 -08: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
Pavel Yaskevich
2bd7a49d75 [IRGen] Record generic environment associated with accessible function
Without this piece of information it wouldn't be possible to form
a call to the recorded function at runtime if it's generic.
2022-01-24 10:17:59 -08:00
Konrad `ktoso` Malawski
9438cf6b2e [Distributed] Func metadata operations and implement executeDistributedTarget entry (#40605)
* [Distributed] Implement func metadata and executeDistributedTarget

dont expose new entrypoints

able to get all the way to calling _execute

* [Distributed] reimplement distributed get type info impls

* [Distributed] comment out distributed_actor_remoteCall for now

* [Distributed] disable test on linux for now
2022-01-09 23:55:06 +09:00
Pavel Yaskevich
1c9bcc9092 Merge pull request #40699 from xedin/rename-dist-accessor-apis
[Distributed] NFC: Remove `Method` from accessor APIs
2022-01-06 01:03:45 -08:00
Kuba (Brecka) Mracek
243141e8b5 [IRGen] When emitting llvm.used.conditional list, strip all pointer casts in dependencies (#40678) 2022-01-04 19:32:45 -08:00
Pavel Yaskevich
d516281da9 [Distributed] NFC: Remove Method from accessor APIs
The API is not constrained to methods only, it should support
computed properties as well.
2021-12-23 14:10:05 -08:00
Pavel Yaskevich
7ac42e11b6 [Distributed] IRGen: Store async function pointer to distributed accessor
Direct pointer to the accessor cannot be called at runtime,
so here is how everything is stored:

- For `distributed` and `async` functions -> async function pointer;
- For regular functions -> function pointer.
2021-12-17 10:52:56 -08:00
Pavel Yaskevich
a83101787d [IRGen] Implement accessible function section/record emission
Uses a dedicated section in the binary to emit records about
functions that can be looked up by name at the runtime, and
then called through a fully-abstracted entry point whose
arguments can be constructed in code.
2021-12-17 10:52:56 -08:00
Pavel Yaskevich
ef4e94ef23 [Distributed] IRGen: Define a runtime record for accessible functions
A "accessible" function that can be looked up based on a string key,
and then called through a fully-abstracted entry point whose arguments
can be constructed in code.
2021-12-17 10:52:56 -08:00
Pavel Yaskevich
9ebdf36ca6 [IRGen] Add skeleton implementation of distributed method accessor 2021-12-17 10:52:55 -08:00
Kuba (Brecka) Mracek
f043a48a3d Merge pull request #34400 from apple/thinlto-fixes
Add an end-to-end test for ThinLTO (-lto=llvm-thin flag), fix compiler crashes
2021-12-14 09:24:31 -08:00