Commit Graph

294 Commits

Author SHA1 Message Date
Slava Pestov
41ff7383d9 IRGen: Clean up opaque type specialization wrappers 2025-10-23 15:36:54 -04:00
Joe Groff
b4d7e98a58 IRGen: Don't hide noncopyable metadata from access functions in load-bearing mangled names.
There is a compatibility hack where fallback metadata access functions
used in field type metadata lie and say a field's type is the empty
tuple when it's noncopyable and the runtime doesn't advertise compatibility
with noncopyable types. Unfortunately, this hack applied to *all* fallback
metadata access functions, causing us to return wrong metadata in situations
we really need the correct metadata, such as in associated type substitutions.
Constrain the hack to only apply to reflection metadata. Fixes rdar://161562839.
2025-10-07 08:56:53 -07:00
Dario Rexin
7ad918280e Merge pull request #84187 from drexin/wip-159310652
[IRGen] Only emit AssociatedTypeInProtocolContextByte for default ass…
2025-09-26 19:21:56 -07:00
Dario Rexin
495a86dd0e [IRGen] Only emit AssociatedTypeInProtocolContextByte for default associated type witnesses
rdar://159310652

This was causing the runtime to try to get types by mangled names for types of which the mangling was not supported by the target runtime, which led to runtime crashes.
2025-09-09 14:41:40 -07:00
Slava Pestov
831043c132 IRGen: Fix crash trying to emit capture descriptor involving element archetype
We could encode local archetypes in reflection info by performing the
local archetype transform, to get an extended generic signature together
with substitutions for the added generic parameters.

However, for now, let's just not crash. This generalizes an earlier hack
for opened existential archetypes. Instead of replacing them with
nonsensical type parameters though, let's just not emit the whole
descriptor.

- Fixes https://github.com/swiftlang/swift/issues/83539.
- Fixes rdar://157554723.
2025-08-25 12:42:49 -04:00
Doug Gregor
badba55bf1 [IRGen] Mangling of nonisolated(nonsending) function types was introduced in Swift 6.2
We can't use mangled named when back-deploying earlier.
2025-07-11 14:24:54 -07:00
Doug Gregor
f3eca93e7f [IRGen] Don't use mangled names for metadata including Span et al when back-deploying
If back-deploying prior to the introduction of name mangling and
runtime support for invertible constraints (~Copyable, ~Escapable),
don't use mangled names to access metadata. The code already existed
for this, but had a carve-out that still used mangled names for
standard library types that have always existed but got generalized to
support non-copyable & non-escapable types.

Tweak that carve-out to not apply to types like Span that come from a
back-deployment library. Fixes crashes when using metadata for Span et
al on older platforms.

Fixes rdar://155639204.
2025-07-11 14:24:53 -07:00
susmonteiro
72b13b3b48 [cxx-interop] Fix metadata mismatch regarding fields of structs 2025-05-20 10:15:14 +01:00
Slava Pestov
a209ff8869 AST: Remove origType parameter from ProtocolConformanceRef::subst() 2025-04-03 17:35:33 -04:00
Tony Allevato
d94bd80c62 Add support for raw identifiers.
Raw identifiers are backtick-delimited identifiers that can contain any
non-identifier character other than the backtick itself, CR, LF, or other
non-printable ASCII code units, and which are also not composed entirely
of operator characters.
2025-03-11 17:18:43 -04:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Tim Kientzle
10f554f5a6 Remove tabs 2025-01-27 15:26:23 -08:00
Tim Kientzle
e5be7657f8 Fix field count in emitted reflection data
PR #78467 omitted certain fields from the FieldDescriptor list,
but did not update the count of fields that's emitted
just before that list.

Update the count so it matches the number of field descriptors
we actually emit.

Resolves rdar://143402921
2025-01-27 14:41:15 -08:00
John McCall
12bdfbf589 Fix a pair of IRGen bugs around materializing function type metadata
with sending results:

- The sending result mangling was added in the 6.0 runtime, so demangling
  cannot be used to produce this metadata when targeting an earlier
  runtime.

- The combination of a sending result with isolation requires the 6.1
  runtime to successfully demangle, due to a bug in the 6.0 demangler.
2025-01-23 02:24:51 -05:00
Egor Zhdan
18be5e862d Merge pull request #78467 from swiftlang/egorzhdan/sizeof-incomplete
[cxx-interop] Skip type metadata for C++ types that are only used in private C++ fields
2025-01-13 16:58:08 +00:00
Egor Zhdan
738c8fb6c6 [cxx-interop] Skip type metadata for C++ types that are only used in private C++ fields
This fixes compiler errors for C++ types that use pimpl idiom:
```
invalid application of 'sizeof' to an incomplete type
```

rdar://141960396
2025-01-13 12:03:35 +00:00
Alejandro Alonso
445824dda0 Don't emit builtin metadata in the stdlib if it's generic 2025-01-08 10:37:16 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Hamish Knight
91ae5d6345 [AST] NFC: Rename getArgumentInterfaceType -> getPayloadInterfaceType
IMO this is a slightly clearer name, many of its
uses already use the term "payload".
2024-09-29 17:05:14 +01:00
Joe Groff
57a56e5804 IRGen: Set a "not bitwise borrowable" bit in value witnesses for @_rawLayout types.
For types like `Atomic` and `Mutex`, we want to know that even though they are
technically bitwise-takable, they differ from other bitwise-takable types until
this point because they are not also "bitwise-borrowable"; while borrowed,
they are pinned in memory, so they cannot be passed by value as a borrowed
parameter, unlike copyable bitwise-takable types. Add a bit to the value witness
table flags to record this.

Note that this patch does not include any accompanying runtime support for
propagating the flag into runtime-instantiated type metadata. There isn't yet
any runtime functionality that varies based on this flag, so that can
be implemented separately.

rdar://136396806
2024-09-24 19:08:50 -07:00
Alejandro Alonso
9906db37c7 Fix closures capturing value generics 2024-09-04 15:13:50 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Kavon Farvardin
afe1fa0c09 Merge pull request #75989 from kavon/reflection-fix-existentials
IRGen: metadata for noncopyable exist. metatype
2024-08-21 18:53:36 -07:00
Kavon Farvardin
cd09269187 IRGen: metadata for noncopyable exist. metatype
Missed a case when determining the strategy to use for obtaining the
metadata for a noncopyable existential metatype. Without this patch,
trying to use a metatype like `any ~Copyable.Type` can cause a crash at
runtime when setting a deployment target that predates Swift 6.0, due to
that runtime not knowing how to demangle inverses.

resolves rdar://134280902
2024-08-21 09:54:26 -07:00
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
Kavon Farvardin
d755e90236 NCGenerics: limit field metadata heuristic
We have had a heuristic that lets you reflect fields of types, where
the field's type is conditionally Copyable, despite the reflection
infrastructure always copying a field. That heuristic was added to allow
ubiquitous types like Optional in the stdlib to continue to be
reflected, even if the Optional at runtime really isn't Copyable.

As a consequence, we were also allowing reflection of fields containing
user-defined conditionally copyable types, when that's unsafe for no
real benefit, yielding runtime crashes!

I think in that case it's better to fall-back on the non-crashy case of
reflection seeing it as the EmptyTupleType, which isn't inhabited, so it
won't try to copy the field and instead basically skip-over it until a
future runtime supports the reflection safely.

So, this patch limits the dangerous reflection to only stdlib-defined
types, until Mirror and friends are updated.
2024-07-15 22:10:17 -07:00
Kavon Farvardin
76bb266624 NCGenerics: fix runtime demangling strategy
We generally should use the open-coded, metadata function "accessor"
strategy when targeting older runtimes, but if the type is part of
the stdlib, assume the runtime demangler will produce correct
metadata, as the retrofitting of Optional, etc, was done Carefully.

resolves rdar://131337585
2024-07-15 22:10:17 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Kuba Mracek
70781b2dc4 [embedded] Avoid DropAllSILPass, reuse StopOptimizationAfterSerialization instead 2024-03-28 15:32:19 -07:00
Kuba Mracek
90e7595df5 [embedded] Add a frontend flag to drop all code from a module and emit an empty object file 2024-03-28 11:03:50 -07:00
Doug Gregor
73552d0a1b Emit reflection metadata for noncopyable fields more often
When emitting reflection metadata for fields that have noncopyable
type with deployment targets that predate support for noncopyable
types, we introduce some indirection to make sure that these fields
are only visible to reflection clients (e.g., mirrors) when running on
a sufficiently-new Swift runtime. However, this indirection has the
downside that out-of-process clients (such as LLDB) can no longer
reflect the fields.

Tweak the heuristic to only introduce the indirection if the field is
*guaranteed* to have noncopyable type. If it somehow could be
copyable, e.g., based on the properties of its generic arguments, then
still emit the normal metadata. This eliminates regressions when
existing generic types like Optional become conditionally Copyable
(based on their Wrapped functions).
2024-03-07 14:24:00 -08:00
John McCall
0f076c0702 Fix metadata availability testing for parameterized existentials
and implement it for @isolated(any) function types.

The existing testing was pretty broken: we were diagnosing all sorts
of things that don't require type metadata (like using a tuple with
an extended existential in a value position in an API signature)
and not diagnosing several things that do (like covariant function
conversions that erase types).  There's therefore some risk to this
patch, but I'm not too worried because needing metadata like this is
pretty uncommon, and it's likely that programs won't build correctly
anyway --- it'll just get caught by the linker instead of the compiler.
2024-02-29 22:14:49 -05:00
Mishal Shah
cb96ec2893 Merge remote-tracking branch 'origin/main' into bump-swift-version-to-6 2024-02-22 09:44:44 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Mishal Shah
af112c1591 Update the Swift version to 6.0 from 5.11 2024-02-19 17:47:16 -08:00
Augusto Noronha
9c6dfd4c03 [NFC] Move MultiPayloadEnum spare bits mask calculation into a function
In preparation to emit the spare bits mask of a MultiPayloadEnum into
DWARF debug info, move the calculation of it into its own function, so
it can be reused later on.
2024-02-07 16:48:39 -08:00
Augusto Noronha
91ed1a076a [NFC] Separate special builtin types into a lazily initialized vector
In preparation for future patches where debug info generation will need
to access the special builtin types, lazily emit them into a separate
lazily initialized vector.
2024-02-01 17:22:12 -08:00
Kuba Mracek
6fb57d8792 [embedded] Don't emit __swift_reflection_version symbol 2024-01-05 14:40:09 +01:00
swift-ci
6532b23b3e Merge pull request #69591 from kavon/noncopyable-generics-pt3
[NoncopyableGenerics] Basic end-to-end testing (without stdlib).
2023-11-03 13:06:43 -07:00
Kavon Farvardin
575f033fdd [IRGen] update isNoncopyable query
resolves rdar://117594962
2023-11-01 16:49:35 -07:00
Doug Gregor
40e07cf900 [Typed throws] IR generation and runtime support for function type metadata
Extend function type metadata with an entry for the thrown error type,
so that thrown error types are represented at runtime as well. Note
that this required the introduction of "extended" function type
flags into function type metadata, because we would have used the last
bit. Do so, and define one extended flag bit as representing typed
throws.

Add `swift_getExtendedFunctionTypeMetadata` to the runtime to build
function types that have the extended flags and a thrown error type.
Teach IR generation to call this function to form the metadata, when
appropriate.

Introduce all of the runtime mangling/demangling support needed for
thrown error types.
2023-10-29 09:12:32 -07:00
swift-ci
6637cc5a27 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 12:13:50 -07:00
Kavon Farvardin
f1142d5da4 [nfc] rename or eliminate isPureMoveOnly APIs
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.

Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
2023-09-20 15:23:17 -07:00
swift-ci
190021146d Merge remote-tracking branch 'origin/main' into rebranch 2023-09-13 21:59:05 -07:00
Alejandro Alonso
ab143ee3ee Some fixes for raw layout types and noncopyable types in the stdlib 2023-09-11 20:45:09 -07:00
swift-ci
d4bb2bb86b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-06 10:14:39 -07:00
Allan Shortlidge
ca8bf981a4 NFC: Hoist queries for unavailable decl optimizations into the AST library.
Moving the query implementation up to the AST library from SIL will allow
conveniences to be written on specific AST element classes. For instance, this
will allow `EnumDecl` to expose a convenience that enumerates element decls
that are available during lowering.

Also, improve naming and documentation for these queries.
2023-08-04 17:39:26 -07:00
Evan Wilde
58c00b1130 Merge pull request #67568 from etcwilde/ewilde/final-fixes
[🌲] Get the frontend building
2023-07-27 10:57:37 -07:00
Evan Wilde
768a86641d Remove ambiguous ReflectionMetadataBuilder overload
`std::optional` implicitly converts the underlying type to an optional,
unlike `llvm::Optional`, so the overload that did the conversion
manually was causing ambiguity issues. It's no longer needed, so
removing it now.
2023-07-26 22:01:43 -07:00
Joe Groff
aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00