Commit Graph

764 Commits

Author SHA1 Message Date
Anthony Latsis
f8577a2731 IRGen: Address llvm::Type::getPointerTo deprecation
See https://github.com/llvm/llvm-project/pull/113331.
2025-07-21 12:37:15 +01:00
Doug Gregor
7789a0ce64 [SE-0371] Back-deploy support for main-actor-isolated deinit
When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
2025-06-30 17:38:08 -07:00
Arnold Schwaighofer
7ddf75c791 Merge pull request #82107 from tobias-stadler/remarks-fix-llvm-setup
[IRGen] Setup LLVMRemarkStreamer using existing RemarkStreamer
2025-06-30 13:50:31 -07:00
Daniil Kovalev
644f364d3d [AutoDiff] Use LinkEntity::SecondaryPointer for diff witness (#82412)
If `LinkEntity::isTypeKind()` is true, `IRGenModule::getAddrOfLLVMVariable` assumes that we can safely call
`LinkEntity::getType()`, which does `reinterpret_cast` of `LinkEntity::Pointer` to `TypeBase *`. However, for SIL
differentiability witness, the pointer has `SILDifferentiabilityWitness *` type, which is not derived from `TypeBase`. So, such a cast is not allowed.

Just as with `ProtocolWitnessTableLazyAccessFunction` and `ProtocolWitnessTableLazyCacheVariable` link entity kinds (which are also type kinds), we should use `SecondaryPointer` instead of `Pointer` for storing payload here, while setting `Pointer` to `nullptr`.
2025-06-23 16:18:07 -07:00
Tobias Stadler
76568372f4 [IRGen] Setup LLVMRemarkStreamer using existing RemarkStreamer
Calling setupLLVMOptimizationRemarks overwrites the MainRemarkStreamer
in the LLVM context. This prevents LLVM from serializing the remark meta
information for the already emitted SIL remarks into the object file.
Without the meta information bitstream remarks don't work correctly.

Instead, emit SIL remarks and LLVM remarks to the same RemarkSerializer,
and keep the file stream alive until after CodeGen.
2025-06-12 18:31:41 +01:00
Saleem Abdulrasool
c0993d466d IRGen: honour -static-libclosure in block creation
When creating a block, ensure that we correctly associate the DLL
Storage on the `_NSConcreteStackBlock` root object declaration based
upon whether we are generating code with `-static-libclosure` being
passed to the clang importer or not.
2025-05-24 08:23:42 -07:00
Nate Chandler
ce61e2ea11 [IRGen] Fix type of deleted coro error func.
It was previously erroneously an async function pointer.  Also fix the
name.
2025-04-04 18:18:11 -07:00
Slava Pestov
9148ae32bd Merge pull request #80482 from slavapestov/abstract-conformance-cleanup
AST: Simplify ProtocolConformanceRef operations a little bit
2025-04-04 10:37:49 -04:00
Slava Pestov
e475b08011 AST: Remove AssociatedType 2025-04-03 17:35:35 -04:00
Nate Chandler
41fa97f62d [IRGen] Add convenience to define transient types.
Expose the createStructType helper to clients of IRGenModule which want
to define types which won't ever be used elsewhere.  This is just a
convenience--such clients could already have directly used the API on
llvm::Module directly.
2025-03-31 13:48:39 -07:00
Nate Chandler
f7540284b0 [NFC] IRGen: Fix field of task.
It doesn't have a status after the resume context.
2025-03-31 13:47:13 -07:00
Nate Chandler
191749651b [CoroutineAccessors] Fall back to DefaultCC.
The fallback should be DefaultCC which is not necessarily SwiftCC.
2025-03-27 19:23:09 -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
2cdbfa77bf [DefaultOverrides] IRGen. 2025-03-25 07:22:43 -07:00
Steven Wu
279787e6a9 [IRGen] Remove a static variable that caches pointer value
Remove a static variable that caches pointer value from ASTContext that
will become invalid if the same process is re-used for compilation using
a second ASTContext. This configuration is used under
`-enable-deterministic-check` option for output detertiminism checking.

rdar://147438789
2025-03-20 11:31:59 -07:00
nate-chandler
c0ba520fac Merge pull request #79781 from nate-chandler/general-coro/20250227/1
[CoroutineAccessors] Dispatch and PtrAuth.
2025-03-07 20:08:42 -08:00
Konrad `ktoso` Malawski
fda7f539fb Reapply "Task names" (#79562) (#79600) 2025-03-08 10:58:49 +09:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Nate Chandler
d1f1b4c86b [CoroutineAccessors] Use swiftcorocc if available.
When it's available, use an open-coded allocator function that returns
an alloca without popping if the allocator is nullptr and otherwise
calls swift_coro_alloc.  When it's not available, use the malloc
allocator in the synchronous context.
2025-02-27 18:20:53 -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
fdd3eb0fce [IRGen] Define coroutine function pointer types.
They're isomorphic to async function pointers.  Even so, having this
distinction will be clearer than reusing AFPs for this other purpose.
2025-02-27 07:53:13 -08:00
Konrad `ktoso` Malawski
09003d6f11 Revert "Merge pull request #77609 from ktoso/wip-task-names" (#79562)
This reverts commit 4ab5d2604f.
2025-02-23 22:59:21 -08:00
Konrad `ktoso` Malawski
4ab5d2604f Merge pull request #77609 from ktoso/wip-task-names
[Concurrency] Task names
2025-02-21 22:28:33 +09:00
Saleem Abdulrasool
9c85fbc8da AST,DependencyScan,IRGen,Serialization,Tooling: track library style (#78777)
Track if the dependency is static or dynamic. This is in preparation for
helping rename the static library to differentiate it from import
libraries.
2025-02-06 13:22:56 -08:00
Saleem Abdulrasool
5770d59e4d Merge pull request #78427 from compnerd/internals
IRGen: special case VWT emission linkage computation
2025-01-25 08:51:06 -08:00
Allan Shortlidge
e50b27f088 Merge pull request #78766 from tshortli/warnings
IRGen/Runtime: Suppress some warnings
2025-01-21 00:19:29 -08:00
Allan Shortlidge
47273273f5 IRGen: Remove unused function isStandardLibrary(). 2025-01-20 20:20:12 -08:00
Saleem Abdulrasool
370cbca889 IRGen: repair a small regression on Windows (#78689)
Correct the IRGen for the standard library. The thinko here assumed that the else case would be evaluated for the standard library build. We ended up incorrectly handling the well-known VWTs from the runtime when building the standard library.
2025-01-20 19:00:05 -08:00
Saleem Abdulrasool
ec70054c93 IRGen: further generalise runtime function generation
This adjusts the runtime function declaration handling to track the
owning module for the well known functions. This allows us to ensure
that we are able to properly identify if the symbol should be imported
or not when building the shared libraries. This will require a
subsequent tweak to allow for checking for static library linkage to
ensure that we do not mark the symbol as DLLImport when doing static
linking.
2025-01-15 13:54:34 -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
Allan Shortlidge
d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Saleem Abdulrasool
c052d1b935 IRGen: simplify the stdlib special casing for Windows
Remove `IRGenModule::useDllStorage()` as there is a standalone version
that is available and the necessary information is public from the
`IRGenModule` type. Additionally, avoid the wrapped `isStandardLibrary`
preferring to use the same method off of the public accessors. This
works towards removing some of the standard library special casing so
that it is possible to support both static and dynamic standard
libraries on Windows.
2024-12-16 14:46:38 -08:00
Saleem Abdulrasool
8473d40f50 lib: use CXX_MODULE_NAME constant for module identifier (NFC)
Use the well known specifier for explicit references to the `Cxx` module
rather than re-spelling the name at the various sites.
2024-12-09 13:34:06 -08:00
Ben Barham
746517c9f2 Merge remote-tracking branch 'origin/main' into manually-merge-main-to-rebranch
Conflicts:
  - `test/IRGen/has_symbol.swift` test updates in rebranch. The new test
    will fail, will fix in the next commit.
2024-10-24 14:20:17 -07:00
Artem Chikin
d0ff56b345 Merge pull request #70564 from artemcm/ExplicitBuildClangTargetIRGen
[Explicit Module Builds] Initialize `ClangImporter`'s `CodeGenerator` using Swift compilation Target Triple.
2024-10-24 09:45:51 -07:00
Joe Groff
8242110bbe Merge pull request #76831 from jckarter/builtin-vector
Builtin.FixedArray
2024-10-23 05:20:21 -10:00
Joe Groff
a184782a38 Introduce a Builtin.FixedArray type.
`Builtin.FixedArray<let N: Int, T: ~Copyable & ~Escapable>` has the layout of `N` elements of type `T` laid out
sequentially in memory (with the tail padding of every element occupied by the array). This provides a primitive
on which the standard library `Vector` type can be built.
2024-10-22 16:21:45 -07:00
Artem Chikin
0fbbba5154 [Explicit Module Builds] Initialize ClangImporter's 'CodeGenerator' using Swift compilation Target Triple.
As per #65930, the Clang importer's Clang instance may be configured with a different (higher) OS version than the compilation target itself in order to be able to load pre-compiled Clang modules that are aligned with the broader SDK, and match the SDK deployment target against which Swift modules are also built. Code-generation, however, must use the actual compilation target triple. This matches how Swift itself loads Swift module dependencies as well: dependency '.swiftinterface' files are type-checked against the availability epoch and code-generated against the actual compilation triple.

Resolves rdar://113712186
2024-10-21 14:12:23 -07:00
swift-ci
ffb7eef5ab Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 05:15:25 -07:00
Arnold Schwaighofer
8ebb3ec473 IRGen: Add the ability to mark certain generic entry points in back traces
Mark generic function calls with concrete parameters, generic v-table calls and
generic witness table calls where self is generic.
2024-10-14 14:06:10 -07:00
Ben Barham
c15bc19946 Merge remote-tracking branch 'origin/main' into main-to-rebranch
Conflicts:
  - `lib/Serialization/ModuleFileSharedCore.cpp` new headers on main
2024-09-26 16:01:56 -07:00
Erik Eckstein
401a602b23 IRGen: support emitting specialized witness tables 2024-09-25 19:32:14 +02:00
swift-ci
658a00ce26 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-20 14:14:24 -07: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
Ben Barham
a7b50f357f Merge remote-tracking branch 'origin/main' into manual-main-merge
Conflicts:
  - `lib/Driver/ToolChains.cpp` conflicting with the `addAllArgs` rename
    for multiple options
2024-09-16 13:53:18 -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
swift-ci
da55e84c74 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-05 15:35:33 -07:00
Alejandro Alonso
f2f82a7de6 Add initRawStructMetadata2 for safety 2024-09-04 15:13:51 -07:00
Ben Barham
467e528200 Merge remote-tracking branch 'origin/main' into manual-rebranch-merge
Conflicts:
  - `lib/Serialization/ModuleFormat.h` bumped version to account for
    differences between main and rebranch.
2024-08-09 15:22:39 -07:00
Egor Zhdan
bfe72b4be9 Merge pull request #75589 from swiftlang/egorzhdan/linux-libcxx-interop
[cxx-interop] Allow compiling with libc++ on Linux
2024-08-09 13:42:29 +01:00