Commit Graph

260 Commits

Author SHA1 Message Date
John McCall
0e932329c3 Fix fulfillments for type metadata and witness table packs
A lot of the fixes here are adjustments to compensate in the
fulfillment and metadata-path subsystems for the recent pack
substitutions representation change.  I think these adjustments
really make the case for why the change was the right one to make:
the code was clearly not considering the possibility of packs
in these positions, and the need to handle packs makes everything
work out much more cleanly.

There's still some work that needs to happen around type packs;
in particular, we're not caching them or fulfilling them as a
whole, and we do have the setup to do that properly now.
2023-03-10 12:52:37 -05:00
Slava Pestov
7d779a9b36 IRGen: Fulfillment of pack shapes from nominal type metadata 2023-03-10 12:15:55 -05:00
Sophia Poirier
70cffb06f3 [Variadic Generics] type parameter pack syntax change: T... -> each T 2023-03-02 14:42:28 -08:00
nate-chandler
87459d61b9 Merge pull request #63665 from nate-chandler/variadic-generics/irgen/full_metadata_binding
[GenPack] Emit all element signature requirements.
2023-02-16 15:16:24 -08:00
Nate Chandler
1624167889 [IRGen] Fixed GenericRequirement::isPack.
And updated the isMetadata and isWitnessTable predicates to count packs
of either.
2023-02-14 20:53:33 -08:00
Alex Lorenz
c9f9d9025b [interop][SwiftToCxx] fix offset computation for 32 bit platforms for vtable dispatch 2023-02-13 10:30:38 -08:00
Alex Lorenz
540202fed8 [interop][SwiftToCxx] dispatch virtual Swift methods using a relative offset into the vtable for classes deriving from resilient classes 2023-02-13 10:30:32 -08:00
Alex Lorenz
981e828b2a [interop][SwiftToCxx] dispatch swift class methods using signed isa and signed method pointer on arm64e 2023-02-11 14:05:59 -08:00
Alex Lorenz
9e32761578 [interop][SwiftToCxx] dispatch virtual calls via thunks for resilient classes 2023-02-10 16:32:54 -08:00
Alex Lorenz
b7007cb748 [interop][SwiftToCxx] dispatch Swift class methods correctly using the vtable 2023-02-09 20:20:53 -08:00
Konrad `ktoso` Malawski
12d1ebc4e7 fix the linkage of async func ptr to distributed accessors 2023-02-06 18:39:58 +09:00
Nate Chandler
6a44de214d [GenericRequirement] Added pack variants.
Added pack flavors of requirement kinds for metadata and witness tables.

Fixes the function signatures for variadic generic functions which
previously used %swift.type* for variadic generic parameters--those are
lists of metadata and should actually be %swift.type**.
2023-02-02 12:48:39 -08:00
Nate Chandler
28c8c6e0b1 [NFC] GenericRequirement vends an llvm::Type *.
The mapping from requirement kind to llvm::Type is repeated several
places.  Pull it into a helper.
2023-02-02 12:48:39 -08:00
Pavel Yaskevich
b8819373d9 [IRGen] RuntimeMetadata: Add linking record for runtime discoverable attrs
Utilize newly added `Ha` postfix mangling for the entry.
2022-12-20 09:45:01 -08:00
Allan Shortlidge
5c13523216 IRGen: Generate #_hasSymbol helpers for dynamic and @_dynamicReplacement(for:) functions.
Resolves rdar://103404707
2022-12-19 14:22:10 -05:00
Slava Pestov
0c3a9d8d55 IRGen: Replace FulfillmentKey with GenericRequirement 2022-12-11 22:14:37 -05:00
Slava Pestov
65d2d4d621 IRGen: Encapsulate fields of GenericRequirement better 2022-12-11 22:14:37 -05: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
Allan Shortlidge
38779f32c1 SILGen/IRGen: Delegate decision to skip @_silgen_name functions to TBDGenVisitor.
This allows SILGen for `#_hasSymbol` conditions to visit them and emit a declaration of the function appropriately.
2022-11-02 21:38:33 -07:00
Allan Shortlidge
a44b54b818 NFC: Refactor the logic of TBDGenVisitor into two helper classes; SILSymbolVisitor and IRSymbolVisitor. 2022-10-30 09:14:29 -07:00
Allan Shortlidge
41269e6895 TBDGen: Merge TBDGen library into IRGen.
The relationship between the code in these two libraries was fundamentally circular, indicating that they should not have been split. With other changes that I'm making to remove circular dependencies from the CMake build graph I eventually uncovered that these two libraries were required to link each other circularly, but that had been hidden by other cycles in the build graph previously.
2022-10-27 11:28:02 -07:00
Becca Royal-Gordon
ba1ec90419 Generate IR for @_objcImpls
This commit begins to generate correct metadata for @_objcImplementation extensions:

• Swift-specific metadata and symbols are not generated.
• For main-class @_objcImpls, we visit the class to emit metadata, but visit the extension’s members.
• Includes both IR tests and executable tests, including coverage of same-module @objc subclasses, different-module @objc subclasses, and clang subclasses.

The test cases do not yet cover stored properties.
2022-10-18 17:21:56 -07:00
Alex Lorenz
661ae6bd1a [interop][SwiftToCxx] cleanup the function signature stuff 2022-09-07 14:06:28 -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
0592894e33 [interop][SwiftToCxx] move generic additional type parameters into lowered function signature 2022-09-07 12:22:04 -07:00
Alex Lorenz
4520c52ac6 [interop][SwiftToCxx] handle indirect result values as part of parameter list 2022-09-07 11:59:25 -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
45d209fe1c [interop][SwiftToCxx] initial generic struct support 2022-08-31 14:02:15 -07:00
Tongjie Wang
ff28b56e15 [Interop][SwiftToCxx] add support for resilient enum 2022-08-08 14:37:13 -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
Roberto Rosmaninho
ff222acebc Setting hardcode SWIFT_NOEXCEPT and noexcept flags only to
non-throwing functions.
Activating swift-functions-errors tests
Inserting macros and additional parameters in C and C++ functions following the pattern to lowering to LLVM IR.
2022-07-14 12:34:53 -03:00
Tongjie Wang
23d60acbc2 sort cases based on their assigned tag indices before printing 2022-07-06 12:46:11 -07:00
Tongjie Wang
7ebcb7b33a [Interop][SwiftToCxx] Implement enum case switching 2022-06-30 22:41:15 -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
9254c47b2c [interop][SwiftToCxx] emit swift type metadata access function declaration for structs 2022-06-13 09:16:17 -07:00
Alex Lorenz
132729906c [interop][SwiftToCxx] pass / return Swift struct values between C/C++ and Swift 2022-06-08 07:03:24 -07:00
Saleem Abdulrasool
7960b03f8f Update IRABIDetailsProvider.h
Add missing include, prefer C++ include over C include for standard integer types.
2022-06-03 09:52:34 -07:00
Alex Lorenz
42c6ff63b8 [interop][SwiftToCxx] Gather initial struct layout information and emit struct stubs with storage in C++
This change extends the clang header printer to start emitting C++ classes for Swift struct types with the correct struct layout in them (size + alignment)
2022-06-01 14:06:25 -07: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
John McCall
6385934d7e Metadata emission for extended existential type shapes 2022-04-12 14:52:47 -04:00
Saleem Abdulrasool
d526dcf309 Merge pull request #41431 from compnerd/externally-consumed-internally
IRGen: internalize symbols with `-static`
2022-02-21 09:12:11 -08:00
Michael Gottesman
487234cd09 Merge pull request #41458 from gottesmm/pr-d179a548962e72bacc7ac8a564a69f32567839be
[sil-opt] Propagate to IRGenOptions whether we have debug info and or optimizations enabled.
2022-02-19 12:51:37 -08:00
Michael Gottesman
6dde338a11 [sil-opt] Actually pass down IRGenOptions to irgen::createIRGenModule().
Otherwise the options from our invocation that we specialized in sil-opt's main
function will not take effect.
2022-02-18 12:56:36 -08:00
Saleem Abdulrasool
98bd2dba57 IRGen: internalize symbols with -static
This pipes the `-static` flag when building a static library into IRGen.
This should have no impact on non-Windows targets as the usage of the
information simply removes the `dllexport` attribute on the generated
interfaces.  This ensures that a library built with `-static` will not
re-export its interfaces from the consumer.  This is important to ensure
that the consumer does not vend the API surface when it statically links
a library.  In conjunction with the removal of the force load symbol,
this allows the generation of static libraries which may be linked
against on Windows.  However, a subsequent change is needed to ensure
that the consumer does not mark the symbol as being imported from a
foreign module (i.e. `dllimport`).
2022-02-18 19:42:08 +00:00
Saleem Abdulrasool
547b2efd1c IRGen: tweak spacing in comment (NFC)
Comments are not rendered as justified by spacing. This corrects the
spacing of the comment to match the style of the codebase.
2022-02-18 09:55:21 -08:00
Slava Pestov
a1c03db381 AST: Generalize ProtocolDecl::getRequirementSignature() to a new RequirementSignature type
The RequirementSignature generalizes the old ArrayRef<Requirement>
which stores the minimal requirements that a conforming type's
witnesses must satisfy, to also record the protocol typealiases
defined in the protocol.
2022-02-13 00:24:23 -05:00