Commit Graph

166 Commits

Author SHA1 Message Date
Nate Chandler
f7dea2fc8e [IRGen] Fix LinkEntity::isTypeKind.
There are numerous entity kinds declared after
`ProtocolWitnessTableLazyAccessFunction` which aren't type kinds.  Group
all those which are type kinds together for now.  In the fullness of
time it would probably we wise to replace this implementation with a
switch statement so that when new kinds are added there is a chance that
the type-ness of that kind can be considered.
2025-04-02 11:53:37 -07:00
Nate Chandler
0c2a38b10b [CoroutineAccessors] Directly reference allocators
Replace the call to a runtime function that looks up the allocator with
a direct reference to a just-emittedd sought-after global allocator.
2025-03-26 08:35:35 -07:00
Nate Chandler
9fcd15108b [Gardening] Detypo'd. 2025-03-26 08:35:35 -07:00
Erik Eckstein
5fbaf0fad3 Revert "IRGen: convert two asserts to ASSERT to check the conditions also in a release-built compiler"
This fails in TBD generation in embedded swift.
A temporary workaround until we disable TBD generation in embedded swift.
rdar://146864959
2025-03-12 19:53:22 +01:00
Erik Eckstein
ecfa808425 IRGen: convert two asserts to ASSERT to check the conditions also in a release-built compiler 2025-03-11 11:20:16 +01:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Nate Chandler
dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Nate Chandler
3d655f58a2 [IRGen] Add coroutine fp link entities.
Duplicative boilerplate copying what was done for async function
pointers which these have the same characteristics as.
2025-02-27 07:53:13 -08:00
Kuba Mracek
b2f87e7614 [embedded] Add an experimental -Xfrontend -mergeable-symbols to allow linking multiple .o modules in Embedded Swift 2025-02-08 11:56:09 -08:00
Saleem Abdulrasool
59e7c1b538 IRGen: special case VWT emission linkage computation
The well known builtin and structural types are strongly defined in the
runtime which is compacted into the standard library. Given that the VWT
is defined in the runtime, it is not visible to the Swift compilation
process and as we do not provide a Swift definition, we would previously
compute the linkage as being module external (`dllimport` for shared
library builds). This formed incorrect references to these variables and
would require thunking to adjust the references.

One special case that we add here is the "any function" type
representation (`@escaping () -> ()`) as we do use the VWT for this type
in the standard library but do not consider it part of the well known
builtin or structural type enumeration.

These errors were previously being swallowed by the build system and
thus escaped from being fixed when the other cases of incorrect DLL
storage were.
2025-01-07 10:45:13 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Allan Shortlidge
d70091f5a1 IRGen: Omit property descriptors from #_hasSymbol checks for static properties.
Property descriptors for static properties were only recently introduced with
SE-438. Since these symbols are not present in Swift libraries that were
compiled with earlier versions of the compiler, it is not safe for
`#_hasSymbol` to check for the property descriptor symbols, since they can be
absent at either link time or runtime.

Resolves rdar://139749275.
2024-11-13 16:00:56 -08:00
Erik Eckstein
2950e4521e SIL: representation for specialized witness tables
The main change here is to associate a witness table with a `ProtocolConformance` instead of a `RootProtocolConformance`.
A `ProtocolConformance` is the base class and can be a `RootProtocolConformance` or a `SpecializedProtocolConformance`.
2024-09-25 19:32:08 +02:00
Kuba Mracek
6b9a3051e3 [embedded] Introduce class-bound existentials into Embedded Swift
Motivated by need for protocol-based dynamic dispatch, which hasn't been possible in Embedded Swift due to a full ban on existentials. This lifts that restriction but only for class-bound existentials: Class-bound existentials are already (even in desktop Swift) much more lightweight than full existentials, as they don't need type metadata, their containers are typically 2 words only (reference + wtable pointer), don't incur copies (only retains+releases).

Included in this PR:
[x] Non-generic class-bound existentials, executable tests for those.
[x] Extension methods on protocols and using those from a class-bound existential.
[x] RuntimeEffects now differentiate between Existential and ExistentialClassBound.
[x] PerformanceDiagnostics don't flag ExistentialClassBound in Embedded Swift.
[x] WTables are generated in IRGen when needed.

Left for follow-up PRs:
[ ] Generic classes support
2024-09-19 07:49:50 -07:00
Allan Shortlidge
02dbb96b94 AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it
encapsulates more than it does. Really it just augments `VersionRange` with
additional set algebra operations that are useful for availability
computations. The `AvailabilityContext` name should be reserved for something
pulls together more than just a single version.
2024-09-13 16:25:18 -07:00
Konrad `ktoso` Malawski
eb675c222e [Distributed] Correct tbd handling for distributed thunks (#74935) 2024-07-26 16:52:18 +09:00
Erik Eckstein
09d2e8f685 IRGen: add forceShared flag to LinkeEntity for type metadata 2024-05-21 18:04:10 +02:00
Pavel Yaskevich
0f41071fe6 [IRGen] Distributed: Switch DistributedAccessor linking to reference underlying thunks
Preparing to start emitting distributed requirement accessors
that don't have `SILFunction *` because they are associated with
protocol requirements.
2024-03-01 17:12:23 -08:00
Konrad `ktoso` Malawski
c56a1e8be7 [Distributed] Handle mangling thunks in extensions with generic AS and $Stubs (#71914) 2024-02-29 04:22:00 -08:00
Konrad `ktoso` Malawski
e9c7f3c382 [Distributed] Target identifiers for protocol calls (#70928) 2024-02-16 07:19:20 -08:00
Alex Lorenz
57f3d2386f [IRGen][WMO] type descriptors generated for an imported Clang types are always known local declarations
This fixes a LNK4217 linker warning when building code on Windows
2024-01-19 08:01:50 -08:00
Cyndy Ishida
331b11f39c [TBDGen] Determine whether symbols belong in TEXT/DATA to record in tbd
files
2023-11-10 08:48:28 -08:00
Kuba Mracek
0663246daf [embedded] Allow metadata for DynamicSelfType to support using Self in classes 2023-10-18 19:52:50 -07:00
Kuba Mracek
5d8c55eacb [embedded] Initial Swift Concurrency for embedded Swift 2023-10-06 20:04:03 -07:00
Kuba Mracek
d0c2a4ccf8 [embedded] Initial support for generic classes in embedded Swift
- VTableSpecializer, a new pass that synthesizes a new vtable per each observed concrete type used
- Don't use full type metadata refs in embedded Swift
- Lazily emit specialized class metadata (LazySpecializedClassMetadata) in IRGen
- Don't emit regular class metadata for a class decl if it's generic (only emit the specialized metadata)
2023-09-12 09:44:54 -07:00
Kuba Mracek
ae63e7549b [embedded] Add support for (non-generic) classes in embedded Swift
- In embedded Swift, classes get a simplified metadata: Basically just a vtable + destructor + superclass pointer.
- Only non-resilient (intended as permanent restriction), non-generic classes (for now) supported.
- Relax the check that prohibits metadata emission and usage to allow classes.
2023-09-11 11:22:11 -07:00
zoecarver
349d37ab24 [embedded] Start fencing parts of IRGen that are not compatible with embedded Swift. 2023-09-06 10:48:17 -07:00
Zak Kent
6aafeec181 [Immediate] [SILGen] Implement on-demand compilation of globals 2023-08-17 11:03:11 -07:00
Pavel Yaskevich
eee923bc42 [IRGen] [AST] NFC: Remove @runtimeMetadata related code and metadata records 2023-08-15 12:17:31 -07:00
Tony Allevato
52e216e6eb Force LinkEntity to be zero-initialized to avoid use-of-uninitialized-value problems. 2023-08-02 15:43:15 -04:00
Saleem Abdulrasool
c8f88175d8 IRGen: attribute correct linkage to Windows DSO handle
Partially address the incorrect handling for the `#dsohandle` on
Windows.

We were previously emitting a local definition for this external
constant, and worse yet, not marking the definition for COMDAT.  It is
unclear what definition would win ultimately (implementation defined),
as we had a definition as well as the linker synthesized value. We can
change the SIL linkage for this type to `DefaultForDeclaration` which
will give it `available_externally` and default visibility and storage
which is closer to what we desire.  However, because we do not track the
LLVM variables and apply heuristics for lowering the
`SILGlobalVariable`, we would attribute it with imported DLL Storage.
This would then cause us to fail at link time (amusingly enough link.exe
will report a LNK1000).  Special case the variable and track that we are
targeting a windows environment in the `UniversalLinkageInfo` so that we
do not special case this on other platforms.

This also has the nice side effect of allowing us to remove the special
case in the TBD handling.

Fixes: #64741
2023-04-02 10:08:16 -07:00
Konrad `ktoso` Malawski
12d1ebc4e7 fix the linkage of async func ptr to distributed accessors 2023-02-06 18:39:58 +09: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
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
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
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
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
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
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
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
2179db3607 [IRGen] Linking: Make it possible to form async pointers to distributed method accessors 2021-12-17 10:52:55 -08:00
Pavel Yaskevich
9ebdf36ca6 [IRGen] Add skeleton implementation of distributed method accessor 2021-12-17 10:52:55 -08:00
Kuba (Brecka) Mracek
d6bc48acde Merge pull request #39313 from kubamracek/conditional
Implement conditional stripping of type descriptors, protocols and protocol conformances via !llvm.used.conditional
2021-10-01 09:18:41 -07:00