Commit Graph

12848 Commits

Author SHA1 Message Date
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
Dario Rexin
0aebbeada8 [IRGen] Fix SignatureExpansion::expandAsyncReturnType()
rdar://141962253

This fixes an issue that caused parameters to be dropped when a typed error in an async closure was too big to be returned directly.
2025-01-06 12:21:51 -08:00
Arnold Schwaighofer
abbe36a1e9 LoadableByAddress: Replace some magic constants
NFC intended. Although there is a little fix in setNumRegisters.
2025-01-06 11:57:37 -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
Arnold Schwaighofer
5b89d2c834 IRGen: OutliningCollector's bindPolymorphicParameters needs to disambiguate between Formal and Representational metadata types
A recent change removed the usage of LocalTypeDataKind when populating the local
type metadata cache. This change reintroduces it.

rdar://141961121
2025-01-03 09:13:59 -08:00
Arnold Schwaighofer
97b154875d Merge pull request #78321 from aschwaighofer/propagate_large
LargeLoadable types: propagate large type property along projections
2025-01-02 07:32:28 -08:00
Finagolfin
c69a12ce39 [android] Use emulated thread-local storage for API 28 and earlier
Android before API 29 and a few other platforms don't support native TLS, so
fall back to LLVM's emulated TLS there, just like clang does. Also, make sure
`-Xcc -f{no-,}emulated-tls` flags passed in are applied to control what the
Swift compiler does.
2024-12-30 23:07:58 +05:30
Augusto Noronha
d75bde3852 [DebugInfo] Fix debug info round tripping of types inside functions
Types with @_originallyDefinedIn cannot be round tripped,

Types declared inside functions have their mangling affected by the
function signature. If the generic signature mentions an
@_originallyDefinedIn type, the type inside the function cannot be round
tripped either.

This commit disables round tripping for this scenario.
2024-12-20 14:13:17 -08:00
Arnold Schwaighofer
be5223f0fa LargeLoadable types: propagate large type property along projections
Back propagate the isLargeType property along projections. This is
neccessary because c union types can "hide" largeness.

rdar://141775951
2024-12-20 09:09:42 -08:00
Anthony Latsis
cd1ef24c49 Merge pull request #78309 from AnthonyLatsis/nymphaea
Assortment of small fixes and cleanups
2024-12-20 06:51:19 +00:00
Anthony Latsis
7793f638d5 [NFC] AST: Consolidate some repeated DependentMemberType logic in Type methods 2024-12-20 02:47:29 +00:00
Egor Zhdan
fe5b047bdc [cxx-interop] NFC: Remove unused variable
This fixes a `-Wunused-variable` warning that got introduced in 57c7ecd2.
2024-12-19 16:50:44 +00:00
Saleem Abdulrasool
ddfb26b1c6 Merge pull request #78226 from compnerd/standard-standards
IRGen: simplify the stdlib special casing for Windows
2024-12-18 14:35:01 -08:00
Augusto Noronha
dccc52d07e Merge pull request #78104 from augusto2112/orig-defined-in
[DebugInfo] Fix handling of @_originallyDefinedIn types
2024-12-18 13:38:55 -08:00
Dario Rexin
5efb6df3c0 [IRGen] Indirectly pass typed errors for closures with indirect results
rdar://141575655

In partial application forwarder emission, we were missing a check for indirect results.
When results are being returned indirectly, we have to return the error indirectly as well.
2024-12-17 15:09:50 -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
Augusto Noronha
72b0120b43 [DebugInfo] Fix handling of @_originallyDefinedIn types
Emit an imported declaration for @_originallyDefinedIn under the
real module that these types live in.

This patch also changes the mangling for the debugger to respect
@_originallyDefinedIn, and fixes a bug where @_originallyDefinedIn
that should be ignored was still being used when mangling.

rdar://137146961
2024-12-16 10:28:18 -08:00
Egor Zhdan
57c7ecd244 [cxx-interop] Fix memory layout for structs with out-of-order base types
In C++, a primary base class that is placed in the beginning of the type's memory layout isn't always the type that is the first in the list of bases – the base types might be laid out in memory in a different order.

This makes sure that IRGen handles base types of C++ structs in the correct order.

This fixes an assertion in asserts-enabled compilers, and an out-of-memory error in asserts-disabled compilers. The issue was happening for both value types and foreign reference types. This change also includes a small refactoring to reuse the logic between the two code paths.

rdar://140848603
2024-12-16 15:53:43 +00:00
nate-chandler
911e29e805 Merge pull request #78130 from nate-chandler/rdar141228350
[BitwiseCopyable] Fix resilient enum type info.
2024-12-13 11:25:26 -08:00
Nate Chandler
96a1c0c322 [BitwiseCopyable] Fix resilient enum type info.
Like other `EnumTypeInfo`s, the `TypeInfo` subclasses `EnumTypeInfoBase`
and store the `EnumImplStrategy`.
2024-12-11 17:54:17 -08:00
Kuba Mracek
af6b24b542 [embedded] Don't emit metadata references from C++ interop 2024-12-10 15:56:37 -08:00
Arnold Schwaighofer
fe00d20db2 Merge pull request #78017 from aschwaighofer/anon_context_desc
IRGen: Fix anonymous context descriptors of alwaysEmitIntoClient functions
2024-12-10 11:19:45 -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
Arnold Schwaighofer
d31e4a5745 IRGen: Fix anonymous context descriptors of alwaysEmitIntoClient functions
Relative references from context descriptors to types outside of the
current module need to use indirect relative references

rdar://140356479
2024-12-06 09:16:38 -08:00
Gábor Horváth
72846769f1 Merge pull request #77893 from swiftlang/gaborh/remove-rdar 2024-12-05 21:42:21 -08:00
Dario Rexin
38e36784d0 [IRGen] Check if type is empty instead of void in CallEmission::emitToUnmappedExplosionWithDirectTypedError
rdar://140573912

This caused assertions to fail when using other empty types, like `Never` as the result type on typed throwing functions.
2024-12-04 13:57:48 -10:00
Konrad `ktoso` Malawski
ed5007f6b1 Merge pull request #77584 from ktoso/wip-check-array-calls 2024-12-04 21:01:36 +09:00
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Gabor Horvath
f1ac9af3f9 [cxx-interop] Remove stale reference to rdar
There is no reason to require a body for move/copy ctors to use them.
2024-12-03 10:58:26 +00:00
Konrad `ktoso` Malawski
7189aded61 [Distributed] minor cleanups, remove dump=always from tests 2024-12-03 14:59:16 +09:00
Konrad `ktoso` Malawski
138f145ab9 [Distributed] @Resolvable now handles primary associated types in protocols
Previously we would not propagate those into the generated distributed
actor, making a lot of generic distributed actor protocols impossible to
express.

We indeed cannot handle protocols WITHOUT primary associated types, but
we certainly can handle them with!

This resolves rdar://139332556
2024-12-03 14:59:15 +09:00
Pavel Yaskevich
8a0a083a45 Merge pull request #77797 from xedin/locatable-types
[AST/Sema]  Introduce a new type that has associated location in source
2024-12-02 16:33:43 -08:00
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Gábor Horváth
04de3492d2 Merge pull request #77855 from swiftlang/gaborh/refactor-findctors
[cxx-interop] Simplify finding copy/move ctors in IRGen
2024-12-02 10:42:22 +00:00
Erik Eckstein
6a0b7d1f8c ObjectOutliner: create outlined arrays as let variables
This will allow load-simplification to replace a load of such an array.
2024-11-28 09:40:12 +01:00
Gabor Horvath
179786b784 [cxx-interop] Simplify finding copy/move ctors in IRGen 2024-11-27 15:51:57 +00:00
Allan Shortlidge
ad7383499b Merge pull request #77758 from tshortli/available-attr-conveniences
AST: `AvailableAttr` cleanup
2024-11-21 13:03:07 -08:00
Hamish Knight
23e3f5f5de Merge pull request #77666 from hamishknight/lets-try-this-again
[AST] Remove `ModuleDecl::addFile`
2024-11-21 20:15:58 +00:00
Pavel Yaskevich
0fe4cea7d7 [AST] Introduce a new type that has associated location in source
This type is intended to be used to wrap compiler synthesized nodes
(i.e. variables) to make it easier for diagnostic to diagnose precise
failure locations.

Consider the situation like:

```
protocol P {}

extension Array: P where Element: P {}

func test<T: P>() -> T {
  $_a = ...
  $_b = ...
  return [$_a, $_b]
}
```

This is a common pattern with result builders.

In this case if one of the elements don't conform to `P` the best
user experience would be to attach diagnostic to the element otherwise
the developers would have to figure out where in result expression
the error occured before attempting to fix it.
2024-11-21 11:01:13 -08:00
Joe Groff
5822bc3685 Merge pull request #77605 from jckarter/capture-metadata-for-fixed-box-to-run-deinit
IRGen: Capture NecessaryBindings in fixed boxes that may invoke deinits.
2024-11-21 09:59:51 -08:00
Allan Shortlidge
36230cd9c6 AST: Use an accessor to get the PlatformKind from an AvailableAttr. 2024-11-21 09:10:36 -08:00
Dario Rexin
86377b32b1 Merge pull request #76743 from swiftlang/coro-pa-context
Fix partial apply forwarder emission for coroutines that are methods of structs with type parameters
2024-11-21 03:05:25 -08:00
Arnold Schwaighofer
c5463bdf92 Merge pull request #68985 from antoniofrighetto/feature/load-pass-plugin
[Driver][Frontend] Introduce `load-pass-plugin` option
2024-11-20 14:22:12 -08:00
Joe Groff
b5e79d5590 IRGen: Capture NecessaryBindings in fixed boxes that may invoke deinits.
Noncopyable types may have user-defined code in their `deinit`s that requires
passing the type's generic parameters, so a box for a captured noncopyable type
needs to capture the generic environment even when the captured type is fixed-
layout. Fixes rdar://138958210.
2024-11-20 11:19:10 -08:00
Nate Chandler
79c62dd5a0 [CoroutineAccessors] Rewrite allocs in LBA.
When replacing a `begin_apply` with an allocation, replace uses of the
old allocation with uses of the new.
2024-11-19 12:57:49 -08:00
Erik Eckstein
4241a2cbfd embedded: Don't emit SILProperties in embedded swift
SILProperties are only needed for resilient builds.

Fixes a crash in IRGen
https://github.com/swiftlang/swift/issues/77682
2024-11-19 10:10:56 +01:00
Felipe de Azevedo Piovezan
3dfee33174 Merge pull request #77655 from felipepiovezan/felipe/fix_code_gen_debug_info
[DebugInfo] Change lowering of SIL instructions to use line 0 when appropriate
2024-11-18 16:31:11 -08:00
Felipe de Azevedo Piovezan
f7f869c88d [DebugInfo] Don't inherit debug location of previous instruction
Prior to this commit, when lowering SIL instructions that should are
"hidden" for the purposes of debugging, the compiler just attaches the
location of the previous instruction in the name of keeping a simpler
line table.

However, this is wrong for many reasons. One such reason is this: at the
start of a basic block, inheriting the previous debug location will
almost certainly cause the instruction to have a random location in the
code, as it will depend on whatever BB was visited previously.

Other examples can be seen in the tests affect by this commit, which
changes lowering to use Line 0 instead of the line number of the
previous instruction.

CodeView doesn't handle line 0 the same way DWARF does, so this commit
preserves the old behavior for the CodeView path.

The test changes here are effectively undoing some of the diffs from
158772c2ab.

rdar://139826231&110187845
2024-11-18 10:23:41 -08:00
Hamish Knight
4946c799af [AST] Remove ModuleDecl::addFile
Rather than exposing an `addFile` member on
ModuleDecl, have the `create` members take a
lambda that populates the files for the module.
Once module construction has finished, the files
are immutable.
2024-11-17 14:17:20 +00:00